source: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp@ 585f78

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 585f78 was e8c636, checked in by Michael Ankele <ankele@…>, 13 years ago

REFACTORING: moved drawDomainBox()/drawDreiBein() from GLWorldScene to GLWorldView

  • Property mode set to 100644
File size: 9.1 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * GLWorldScene.cpp
10 *
11 * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
12 *
13 * Created on: Aug 17, 2011
14 * Author: heber
15 */
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "GLWorldScene.hpp"
23#include <Qt3D/qglview.h>
24
25#include "GLMoleculeObject.hpp"
26#include "GLMoleculeObject_atom.hpp"
27#include "GLMoleculeObject_bond.hpp"
28#include "GLMoleculeObject_molecule.hpp"
29
30#include "CodePatterns/MemDebug.hpp"
31
32#include "CodePatterns/Log.hpp"
33
34#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
35#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
36#include "Atom/atom.hpp"
37#include "Bond/bond.hpp"
38#include "Descriptors/AtomIdDescriptor.hpp"
39#include "Helpers/helpers.hpp"
40#include "molecule.hpp"
41#include "World.hpp"
42
43#include <iostream>
44
45using namespace MoleCuilder;
46
47std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t)
48{
49 ost << t.first << "," << t.second;
50 return ost;
51}
52
53GLWorldScene::GLWorldScene(QObject *parent)
54 : QObject(parent)
55{
56 init();
57}
58
59GLWorldScene::~GLWorldScene()
60{
61 // remove all elements
62 GLMoleculeObject::cleanMaterialMap();
63}
64
65/** Initialise the WorldScene with molecules and atoms from World.
66 *
67 */
68void GLWorldScene::init()
69{
70 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
71
72 if (molecules.size() > 0) {
73 for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
74 Runner != molecules.end();
75 Runner++) {
76
77 for (molecule::const_iterator atomiter = (*Runner)->begin();
78 atomiter != (*Runner)->end();
79 ++atomiter) {
80 // create atom objects in scene
81 atomInserted(*atomiter);
82
83 // create bond objects in scene
84 const BondList &bondlist = (*atomiter)->getListOfBonds();
85 for (BondList::const_iterator bonditer = bondlist.begin();
86 bonditer != bondlist.end();
87 ++bonditer) {
88 const bond *_bond = *bonditer;
89 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == *atomiter) ?
90 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
91 bondInserted(_bond, side);
92 }
93 }
94 }
95 }
96}
97
98/** Adds an atom to the scene.
99 *
100 * @param _atom atom to add
101 */
102void GLWorldScene::atomInserted(const atom *_atom)
103{
104 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_atom->getId())+".");
105 GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(this, _atom);
106 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
107 ASSERT(iter == AtomsinSceneMap.end(),
108 "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
109 AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
110 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
111 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
112 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
113 connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
114 connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)));
115 //bondsChanged(_atom);
116 emit changeOccured();
117}
118
119/** Removes an atom from the scene.
120 *
121 * @param _atom atom to remove
122 */
123void GLWorldScene::atomRemoved(const atom *_atom)
124{
125 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atom->getId())+".");
126 // bonds are removed by signal coming from ~bond
127 // remove atoms
128 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atom->getId());
129 ASSERT(iter != AtomsinSceneMap.end(),
130 "GLWorldScene::atomRemoved() - atom "+_atom->getName()+" not on display.");
131 GLMoleculeObject_atom *atomObject = iter->second;
132 atomObject->disconnect();
133 AtomsinSceneMap.erase(iter);
134 delete atomObject;
135 emit changeOccured();
136}
137
138/** ....
139 *
140 */
141void GLWorldScene::worldSelectionChanged()
142{
143 LOG(3, "INFO: GLWorldScene: Received signal selectionChanged.");
144
145 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules();
146
147 if (molecules.size() > 0) {
148 for (std::vector<molecule*>::const_iterator Runner = molecules.begin();
149 Runner != molecules.end();
150 Runner++) {
151
152 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId());
153 bool isSelected = World::getInstance().isSelected(*Runner);
154
155 // molecule selected but not in scene?
156 if (isSelected && (iter == MoleculesinSceneMap.end())){
157 // -> create new mesh
158 GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(this, *Runner);
159 MoleculesinSceneMap.insert( make_pair((*Runner)->getId(), molObject) );
160 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
161 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
162 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
163 emit changed();
164 emit changeOccured();
165 }
166
167 // molecule not selected but in scene?
168 if (!isSelected && (iter != MoleculesinSceneMap.end())){
169 // -> remove from scene
170 moleculeRemoved(*Runner);
171 }
172
173 }
174 }
175}
176
177/** Removes a molecule from the scene.
178 *
179 * @param _molecule molecule to remove
180 */
181void GLWorldScene::moleculeRemoved(const molecule *_molecule)
182{
183 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+".");
184 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId());
185
186 // only remove if the molecule is in the scene
187 // (= is selected)
188 if (iter != MoleculesinSceneMap.end()){
189 GLMoleculeObject_molecule *molObject = iter->second;
190 molObject->disconnect();
191 MoleculesinSceneMap.erase(iter);
192 delete molObject;
193 emit changed();
194 emit changeOccured();
195 }
196}
197
198/** Adds a bond to the scene.
199 *
200 * @param _bond bond to add
201 * @param side which side of the bond (left or right)
202 */
203void GLWorldScene::bondInserted(const bond *_bond, const enum GLMoleculeObject_bond::SideOfBond side)
204{
205 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
206 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
207
208 BondIds ids;
209 switch (side) {
210 case GLMoleculeObject_bond::left:
211 ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
212 break;
213 case GLMoleculeObject_bond::right:
214 ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
215 break;
216 }
217#ifndef NDEBUG
218 BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
219 ASSERT(iter == BondsinSceneMap.end(),
220 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
221#endif
222 GLMoleculeObject_bond *bondObject =
223 new GLMoleculeObject_bond(this, _bond, side);
224 connect (
225 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
226 this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
227 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
228 BondsinSceneMap.insert( make_pair(ids, bondObject) );
229// BondIdsinSceneMap.insert( Leftids );
230 emit changeOccured();
231}
232
233/** Removes a bond from the scene.
234 *
235 * @param _bond bond to remove
236 */
237void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
238{
239 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
240 {
241 // left bond
242 const BondIds Leftids( make_pair(leftnr, rightnr) );
243 BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
244 ASSERT(leftiter != BondsinSceneMap.end(),
245 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
246 +toString(rightnr)+" not on display.");
247 //GLMoleculeObject_bond *bondObject = leftiter->second;
248 BondsinSceneMap.erase(leftiter);
249 //delete bondObject; // is done by signal from bond itself
250 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
251 }
252
253 emit changeOccured();
254}
255
256void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
257{
258 // Initialize all of the mesh objects that we have as children.
259 foreach (QObject *obj, children()) {
260 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
261 if (meshobj)
262 meshobj->initialize(view, painter);
263 }
264}
265
266void GLWorldScene::draw(QGLPainter *painter) const
267{
268 // Draw all of the mesh objects that we have as children.
269 foreach (QObject *obj, children()) {
270 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
271 if (meshobj)
272 meshobj->draw(painter);
273 }
274}
275
276void GLWorldScene::atomClicked(atomId_t no)
277{
278 LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
279 const atom *Walker = World::getInstance().getAtom(AtomById(no));
280 if (!World::getInstance().isSelected(Walker))
281 SelectionAtomById(no);
282 else
283 SelectionNotAtomById(no);
284 emit clicked(no);
285}
286
Note: See TracBrowser for help on using the repository browser.