1
/***************************************************************************
2
* Copyright (C) 2006 by Carsten Niehaus <cniehaus@kde.org>
3
* Copyright (C) 2007-2008 by Marcus D. Hanwell <marcus@cryos.org>
4
***************************************************************************/
6
/***************************************************************************
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
***************************************************************************/
14
#include "kalziumglwidget.h"
18
#include <avogadro/primitive.h>
19
#include <avogadro/pluginmanager.h>
20
#include <avogadro/toolgroup.h>
21
#include <avogadro/engine.h>
23
#include "openbabel2wrapper.h"
25
#include <config-kalzium.h>
27
KalziumGLWidget::KalziumGLWidget(QWidget *parent) : Avogadro::GLWidget(parent),
28
m_lastEngine1(0), m_lastEngine2(0)
30
// work around a bug in OpenBabel: the chemical data files parsing
31
// is dependent on the LC_NUMERIC locale.
32
m_lc_numeric = QByteArray(setlocale(LC_NUMERIC, 0));
33
setlocale(LC_NUMERIC, "C");
35
// Prevent What's this from intercepting right mouse clicks
36
setContextMenuPolicy(Qt::PreventContextMenu);
37
// Load the tools and set navigate as the default
38
// first set the Avogadro plugin directory,
39
// avoiding overwriting an already set envvar
40
static bool s_pluginDirSet = false;
43
if (qgetenv("AVOGADRO_PLUGINS").isEmpty())
45
qputenv("AVOGADRO_PLUGINS", AVOGADRO_PLUGIN_DIR);
47
s_pluginDirSet = true;
49
Avogadro::PluginManager *manager = Avogadro::PluginManager::instance();
50
manager->loadFactories();
51
Avogadro::ToolGroup* tools = new Avogadro::ToolGroup(this);
52
tools->append(manager->tools(this));
53
tools->setActiveTool("Navigate");
55
// Set the default engine to be active
58
// Set the default quality level to high
61
setMolecule(new Avogadro::Molecule(this));
65
KalziumGLWidget::~KalziumGLWidget()
67
//restore the LC_NUMERIC locale.
68
setlocale(LC_NUMERIC, m_lc_numeric.constData());
71
bool KalziumGLWidget::openFile(const QString &file)
73
Avogadro::Molecule* mol = OpenBabel2Wrapper::readMolecule( file );
76
Avogadro::Molecule* oldmol = molecule();
78
oldmol->deleteLater();
84
void KalziumGLWidget::setStyle( int style )
86
foreach(Avogadro::Engine *engine, engines())
88
if((m_lastEngine1 == 0 && engine->identifier() == "Ball and Stick")
89
|| (m_lastEngine1 == 1 && engine->identifier() == "Stick")
90
|| (m_lastEngine1 == 2 && engine->identifier() == "Van der Waals Spheres")
91
|| (m_lastEngine1 == 3 && engine->identifier() == "Wireframe"))
93
engine->setEnabled(false);
95
if((style == 0 && engine->identifier() == "Ball and Stick")
96
|| (style == 1 && engine->identifier() == "Stick")
97
|| (style == 2 && engine->identifier() == "Van der Waals Spheres")
98
|| (style == 3 && engine->identifier() == "Wireframe"))
100
engine->setEnabled(true);
103
m_lastEngine1 = style;
107
void KalziumGLWidget::setStyle2( int style )
109
foreach(Avogadro::Engine *engine, engines())
111
if((m_lastEngine2 == 1 && engine->identifier() == "Ribbon")
112
|| (m_lastEngine2 == 2 && engine->identifier() == "Ring")
113
|| (m_lastEngine2 == 3 && engine->identifier() == "Orbitals"))
115
engine->setEnabled(false);
117
if((style == 1 && engine->identifier() == "Ribbon")
118
|| (style == 2 && engine->identifier() == "Ring")
119
|| (style == 3 && engine->identifier() == "Orbitals"))
121
engine->setEnabled(true);
124
m_lastEngine2 = style;
128
void KalziumGLWidget::setLabels(int style)
130
// Use the QSettings framework to configure the label engine
131
foreach(Avogadro::Engine *engine, engines())
133
if(engine->name() == "Label")
138
bool enabled = false;
142
case 0: // Display no labels
145
case 1: // Display the atom index
149
case 2: // Display the atom symbol
153
case 3: // Display the atom name
158
engine->setEnabled(false);
160
settings.setValue("atomLabel", atomType);
161
settings.setValue("bondLabel", bondType);
162
settings.setValue("enabled", enabled);
163
engine->readSettings(settings);
168
void KalziumGLWidget::setQuality(int quality)
170
// Set the global quality of the GLWidget, 0=min, 2=mid, 4=max
172
if(quality == 1) q = 2;
173
else if(quality == 2) q = 4;
174
GLWidget::setQuality(q);
179
#include "kalziumglwidget.moc"