source: src/UIElements/Views/Qt4/QtInfoBox.cpp@ 59eabc

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 59eabc was 1187c5, checked in by Frederik Heber <heber@…>, 9 years ago

FIX: QtObservedAtom's AtomMoleculeIndex was not informed of molecule index changes.

  • hence, we return the QtObservedMolecule of the molecule to which the atom is associated. And this reference is updated whenever the associated molecule changes.
  • getAtomMoleculeIndex() -> getAtomMolecule().
  • signal renamed moleculeIndexChanged -> moleculeChanged.
  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * QtInfoBox.cpp
25 *
26 * Created on: Mar 4, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/QtInfoBox.hpp"
36
37#include <iostream>
38#include <QAbstractItemView>
39
40#include "CodePatterns/MemDebug.hpp"
41
42#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
43
44#include <boost/thread/locks.hpp>
45
46#include "Element/element.hpp"
47#include "Element/periodentafel.hpp"
48#include "World.hpp"
49
50using namespace std;
51
52/***************** Basic structure for tab layout ***********/
53
54QtInfoBox::QtInfoBox(QtObservedInstanceBoard *_board, QWidget *_parent) :
55 QTabWidget(_parent),
56 curAtomId(-1), nextAtomId(-1),
57 curMoleculeId(-1), nextMoleculeId(-1),
58 page_mol(NULL), page_atom(NULL),
59 board(_board),
60 currentPage(0),
61 periode(World::getInstance().getPeriode())
62{
63 timer = new QTimer(this);
64 timer->setSingleShot(true);
65
66 setMinimumWidth(200);
67 setMinimumHeight(220);
68
69 connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
70}
71
72QtInfoBox::~QtInfoBox()
73{
74 clearAtomTab();
75 clearMoleculeTab();
76}
77
78void QtInfoBox::atomHover(const atomId_t _id)
79{
80 nextAtomId = _id;
81 timer->start(500);
82}
83
84void QtInfoBox::moleculeHover(const moleculeId_t _id)
85{
86 nextMoleculeId = _id;
87 timer->start(500);
88}
89
90void QtInfoBox::timerTimeout()
91{
92 if (nextAtomId != (atomId_t)-1)
93 showAtom(nextAtomId);
94 if (nextMoleculeId != (moleculeId_t)-1)
95 showMolecule(nextMoleculeId);
96}
97
98void QtInfoBox::clearAtomTab()
99{
100 boost::recursive_mutex::scoped_lock lock(tabs_mutex);
101 if (page_atom){
102 disconnect(page_atom->getAtom().get(), SIGNAL(atomRemoved()), this, SLOT(clearAtomTab()));
103 //removeTab(indexOf(page_atom));
104 delete(page_atom);
105 page_atom = NULL;
106 }
107}
108
109void QtInfoBox::clearMoleculeTab()
110{
111 boost::recursive_mutex::scoped_lock lock(tabs_mutex);
112 if (page_mol){
113 disconnect(page_mol->getMolecule().get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
114 //removeTab(indexOf(page_mol));
115 delete(page_mol);
116 page_mol = NULL;
117 }
118}
119
120void QtInfoBox::showAtom(const atomId_t _id)
121{
122 currentPage = currentIndex();
123
124 // Remove old tabs.
125 clearAtomTab();
126 clearMoleculeTab();
127
128 QtObservedAtom::ptr curAtom = board->getObservedAtom(_id);
129
130 // Show new tabs.
131 if (curAtom){
132 curAtomId = curAtom->getAtomIndex();
133 nextAtomId = -1;
134 nextMoleculeId = -1;
135
136 boost::recursive_mutex::scoped_lock lock(tabs_mutex);
137 page_atom = new QtAtomInfoPage(curAtom, periode, this);
138 addTab(page_atom, "Atom");
139 connect(curAtom.get(), SIGNAL(atomRemoved()), this, SLOT(clearAtomTab()));
140
141 QtObservedMolecule * const mol = curAtom->getAtomMolecule();
142 const moleculeId_t molid = mol->getMolIndex();
143 if (molid != (moleculeId_t)-1) {
144 QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(molid);
145 ASSERT( mol == curMolecule.get(),
146 "QtInfoBox::showAtom() - mol "+toString(mol)
147 +" obtained from atom does not match mol "+toString(curMolecule.get())
148 +" obtained via id "+toString(molid));
149 if (curMolecule) {
150 page_mol = new QtMoleculeInfoPage(curMolecule, this);
151 addTab(page_mol, "Molecule");
152 connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
153
154 if (currentPage > 0)
155 setCurrentIndex(currentPage);
156 }
157 }
158 }
159}
160
161void QtInfoBox::showMolecule(const moleculeId_t _id)
162{
163 currentPage = currentIndex();
164
165 // Remove old tabs.
166 clearAtomTab();
167 clearMoleculeTab();
168
169 QtObservedMolecule::ptr curMolecule = board->getObservedMolecule(_id);
170 nextAtomId = -1;
171 nextMoleculeId = -1;
172
173 // Show new tabs.
174 if (curMolecule){
175 boost::recursive_mutex::scoped_lock lock(tabs_mutex);
176 page_mol = new QtMoleculeInfoPage(curMolecule, this);
177 addTab(page_mol, "Molecule");
178 connect(curMolecule.get(), SIGNAL(moleculeRemoved()), this, SLOT(clearMoleculeTab()));
179
180 if (currentPage > 0)
181 setCurrentIndex(currentPage);
182 }
183}
184
185/************************ Tab for single Atoms ********************/
186
187static void addInfo(QTreeWidget *info, const QString &key, const QString &value)
188{
189 QTreeWidgetItem *treeItem = new QTreeWidgetItem(info);
190 treeItem->setText(0, key);
191 treeItem->setText(1, value);
192}
193
194QtAtomInfoPage::QtAtomInfoPage(
195 QtObservedAtom::ptr &_atom,
196 periodentafel *_periode,
197 QWidget *parent) :
198 QTreeWidget(parent),
199 atomRef(_atom),
200 periode(_periode)
201{
202 setColumnCount(2);
203 QStringList header;
204 header << "data";
205 header << "value";
206 setHeaderLabels(header);
207
208 updatePage();
209}
210
211void QtAtomInfoPage::updatePage()
212{
213 clear();
214
215 if (atomRef == NULL)
216 return;
217 const element * const _element = periode->FindElement(atomRef->getAtomElement());
218 addInfo(this, "Name", QString(atomRef->getAtomName().c_str()));
219 addInfo(this, "Element", QString(_element->getName().c_str()));
220 addInfo(this, "Mass", QString("%1").arg(_element->getMass()));
221 addInfo(this, "Charge", QString("%1").arg(_element->getCharge()));
222 addInfo(this, "Bonds", QString("%1").arg(atomRef->getAtomBonds().size()));
223 addInfo(this, "Position x", QString(toString(atomRef->getAtomPosition()[0]).c_str()));
224 addInfo(this, "Position y", QString(toString(atomRef->getAtomPosition()[1]).c_str()));
225 addInfo(this, "Position z", QString(toString(atomRef->getAtomPosition()[2]).c_str()));
226}
227
228QtAtomInfoPage::~QtAtomInfoPage()
229{}
230
231/************************ Tab for single Molecules *****************/
232
233QtMoleculeInfoPage::QtMoleculeInfoPage(
234 QtObservedMolecule::ptr &_mol,
235 QWidget *parent) :
236 QTreeWidget(parent),
237 mol(_mol)
238{
239 setColumnCount(2);
240 QStringList header;
241 header << "data";
242 header << "value";
243 setHeaderLabels(header);
244
245 updatePage();
246}
247
248void QtMoleculeInfoPage::updatePage()
249{
250 clear();
251
252 if (mol == NULL)
253 return;
254 addInfo(this, "Name", QString(mol->getMolName().c_str()));
255 addInfo(this, "Formula", QString(mol->getMolFormula().c_str()));
256 addInfo(this, "Atoms", QString("%1").arg(mol->getAtomCount()));
257 addInfo(this, "NonHydrogens", QString("%1").arg(mol->getNonHydrogenCount()));
258 addInfo(this, "Bonds", QString("%1").arg(mol->getBondCount()));
259 const Vector molCenter = mol->getMolCenter();
260 addInfo(this, "Center x", QString("%1").arg(molCenter[0]));
261 addInfo(this, "Center y", QString("%1").arg(molCenter[1]));
262 addInfo(this, "Center z", QString("%1").arg(molCenter[2]));
263}
264
265QtMoleculeInfoPage::~QtMoleculeInfoPage()
266{}
Note: See TracBrowser for help on using the repository browser.