1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
6 | *
|
---|
7 | *
|
---|
8 | * This file is part of MoleCuilder.
|
---|
9 | *
|
---|
10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation, either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * GLWorldScene.cpp
|
---|
26 | *
|
---|
27 | * This is based on the Qt3D example "teaservice", specifically parts of teaservice.cpp.
|
---|
28 | *
|
---|
29 | * Created on: Aug 17, 2011
|
---|
30 | * Author: heber
|
---|
31 | */
|
---|
32 |
|
---|
33 | // include config.h
|
---|
34 | #ifdef HAVE_CONFIG_H
|
---|
35 | #include <config.h>
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | #include "GLWorldScene.hpp"
|
---|
39 | #include <Qt3D/qglview.h>
|
---|
40 | #include <Qt3D/qglbuilder.h>
|
---|
41 | #include <Qt3D/qglscenenode.h>
|
---|
42 | #include <Qt3D/qglsphere.h>
|
---|
43 | #include <Qt3D/qglcylinder.h>
|
---|
44 |
|
---|
45 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp"
|
---|
46 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp"
|
---|
47 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
|
---|
48 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp"
|
---|
49 | #include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.hpp"
|
---|
50 |
|
---|
51 | #include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
|
---|
52 |
|
---|
53 | #include "CodePatterns/MemDebug.hpp"
|
---|
54 |
|
---|
55 | #include "CodePatterns/Log.hpp"
|
---|
56 |
|
---|
57 | #include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
|
---|
58 | #include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
|
---|
59 | #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
|
---|
60 | #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
|
---|
61 | #include "Atom/atom.hpp"
|
---|
62 | #include "Bond/bond.hpp"
|
---|
63 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
64 | #include "Descriptors/MoleculeIdDescriptor.hpp"
|
---|
65 | #include "Helpers/helpers.hpp"
|
---|
66 | #include "Shapes/ShapeRegistry.hpp"
|
---|
67 | #include "molecule.hpp"
|
---|
68 | #include "World.hpp"
|
---|
69 |
|
---|
70 | #include <iostream>
|
---|
71 |
|
---|
72 | using namespace MoleCuilder;
|
---|
73 |
|
---|
74 | GLWorldScene::GLWorldScene(
|
---|
75 | QtObservedInstanceBoard * _board,
|
---|
76 | QObject *parent) :
|
---|
77 | QObject(parent),
|
---|
78 | selectionMode(SelectAtom),
|
---|
79 | board(_board)
|
---|
80 | {
|
---|
81 | int sphereDetails[] = {5, 3, 2, 0};
|
---|
82 | int cylinderDetails[] = {16, 8, 6, 3};
|
---|
83 | for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
|
---|
84 | QGLBuilder emptyBuilder;
|
---|
85 | GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
|
---|
86 | QGLBuilder sphereBuilder;
|
---|
87 | sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
|
---|
88 | GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
|
---|
89 | GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
90 | QGLBuilder cylinderBuilder;
|
---|
91 | cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
|
---|
92 | GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
|
---|
93 | GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
|
---|
94 | }
|
---|
95 | connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
|
---|
96 | this, SLOT(moleculeSignOn(QtObservedMolecule::ptr)));
|
---|
97 | connect(board, SIGNAL(moleculeRemoved(const moleculeId_t)),
|
---|
98 | this, SLOT(moleculeSignOff(const moleculeId_t)));
|
---|
99 | connect(board, SIGNAL(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)),
|
---|
100 | this, SLOT(moleculeIndexChanged(const moleculeId_t, const moleculeId_t)));
|
---|
101 | connect(this, SIGNAL(insertMolecule(QtObservedMolecule::ptr)),
|
---|
102 | this, SLOT(moleculeInserted(QtObservedMolecule::ptr)) );
|
---|
103 | connect(this, SIGNAL(removeMolecule(const moleculeId_t)),
|
---|
104 | this, SLOT(moleculeRemoved(const moleculeId_t)) );
|
---|
105 |
|
---|
106 | // connect(this, SIGNAL(updated()), this, SLOT(update()));
|
---|
107 | }
|
---|
108 |
|
---|
109 | GLWorldScene::~GLWorldScene()
|
---|
110 | {
|
---|
111 | // remove all elements
|
---|
112 | GLMoleculeObject::cleanMaterialMap();
|
---|
113 | }
|
---|
114 |
|
---|
115 | void GLWorldScene::atomClicked(atomId_t no)
|
---|
116 | {
|
---|
117 | LOG(3, "INFO: GLMoleculeObject_molecule - atom " << no << " has been clicked.");
|
---|
118 | const atom * const Walker = const_cast<const World &>(World::getInstance()).
|
---|
119 | getAtom(AtomById(no));
|
---|
120 | ASSERT( Walker != NULL,
|
---|
121 | "GLWorldScene::atomClicked() - clicked atom has disappeared.");
|
---|
122 | if (selectionMode == SelectAtom){
|
---|
123 | if (!World::getInstance().isSelected(Walker))
|
---|
124 | SelectionAtomById(std::vector<atomId_t>(1,no));
|
---|
125 | else
|
---|
126 | SelectionNotAtomById(std::vector<atomId_t>(1,no));
|
---|
127 | }else if (selectionMode == SelectMolecule){
|
---|
128 | const molecule *mol = Walker->getMolecule();
|
---|
129 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
130 | molids_t ids(1, mol->getId());
|
---|
131 | if (!World::getInstance().isSelected(mol))
|
---|
132 | SelectionMoleculeById(ids);
|
---|
133 | else
|
---|
134 | SelectionNotMoleculeById(ids);
|
---|
135 | }
|
---|
136 | emit clicked(no);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void GLWorldScene::moleculeClicked(moleculeId_t no)
|
---|
140 | {
|
---|
141 | LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
|
---|
142 | const molecule * const mol= const_cast<const World &>(World::getInstance()).
|
---|
143 | getMolecule(MoleculeById(no));
|
---|
144 | ASSERT(mol, "Atom without molecule has been clicked.");
|
---|
145 | molids_t ids(1, mol->getId());
|
---|
146 | if (!World::getInstance().isSelected(mol))
|
---|
147 | SelectionMoleculeById(ids);
|
---|
148 | else
|
---|
149 | SelectionNotMoleculeById(ids);
|
---|
150 | emit clicked(no);
|
---|
151 | }
|
---|
152 |
|
---|
153 | /** Inserts an atom into the scene before molecule is present.
|
---|
154 | *
|
---|
155 | * @param _molid molecule to insert atom for
|
---|
156 | * @param _atomid atom to insert
|
---|
157 | */
|
---|
158 | void GLWorldScene::atomInserted(QtObservedAtom::ptr _atom)
|
---|
159 | {
|
---|
160 | ASSERT (_atom,
|
---|
161 | "GLWorldScene::moleculeInserted() - received shared_ptr for atom is empty?");
|
---|
162 | const atomId_t atomid = _atom->getAtomIndex();
|
---|
163 | const atomId_t molid = _atom->getAtomMoleculeIndex();
|
---|
164 | LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(atomid)+".");
|
---|
165 |
|
---|
166 | // check of molecule is already present
|
---|
167 | MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
|
---|
168 | if (moliter != MoleculesinSceneMap.end()) {
|
---|
169 | // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
|
---|
170 | } else {
|
---|
171 | // store signal for when it is instantiated
|
---|
172 | if (MoleculeMissedStateMap.count(molid) == 0)
|
---|
173 | MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
|
---|
174 | MoleculeMissedStateMap[molid].insert( std::make_pair(atomid, atomInsertedState) );
|
---|
175 | QtObservedAtomMap[atomid] = _atom;
|
---|
176 | connect(_atom.get(), SIGNAL(indexChanged(const atomId_t,const atomId_t)),
|
---|
177 | this, SLOT(atomIndexChanged(const atomId_t,const atomId_t)) );
|
---|
178 | LOG(3, "INFO: GLWorldScene: Placing atomInserted for atom " << atomid
|
---|
179 | << " and molecule " << molid << " into missed state map.");
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | /** Removes an atom into the scene before molecule is present.
|
---|
184 | *
|
---|
185 | * @param _molid molecule to insert atom for
|
---|
186 | * @param _atomid atom to insert
|
---|
187 | */
|
---|
188 | void GLWorldScene::atomRemoved(const atomId_t _atomid)
|
---|
189 | {
|
---|
190 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
191 |
|
---|
192 | LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
|
---|
193 |
|
---|
194 | // if atom is not in map, then GLMoleculeObject_molecule is already present anyway.
|
---|
195 | if (QtObservedAtomMap.count(_atomid)) {
|
---|
196 | const QtObservedAtom::ptr atom = QtObservedAtomMap[_atomid];
|
---|
197 | const moleculeId_t molid = atom->getAtomMoleculeIndex();
|
---|
198 | // check of molecule is already present
|
---|
199 | MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
|
---|
200 | if (moliter != MoleculesinSceneMap.end()) {
|
---|
201 | // no action, is also caught via QtObservedMolecule by GLMoleculeObject_molecule
|
---|
202 | } else {
|
---|
203 | // store signal for when it is instantiated
|
---|
204 | if (MoleculeMissedStateMap.count(molid) == 0)
|
---|
205 | MoleculeMissedStateMap.insert( std::make_pair(molid ,StateChangeMap_t()) );
|
---|
206 | MoleculeMissedStateMap[molid].insert( std::make_pair(_atomid, atomRemovedState) );
|
---|
207 | LOG(3, "INFO: GLWorldScene: Placing atomRemoved for atom " << _atomid
|
---|
208 | << " and molecule " << molid << " into missed state map.");
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | void GLWorldScene::moleculeSignOn(QtObservedMolecule::ptr _mol)
|
---|
214 | {
|
---|
215 | // sign on to QtObservedMolecule to get atomInserted/..Removed signals from same
|
---|
216 | // source as GLMoleculeObject_molecule would
|
---|
217 | connect(_mol.get(), SIGNAL(atomInserted(QtObservedAtom::ptr)),
|
---|
218 | this, SLOT(atomInserted(QtObservedAtom::ptr)) );
|
---|
219 | connect(_mol.get(), SIGNAL(atomRemoved(const atomId_t)),
|
---|
220 | this, SLOT(atomRemoved(const atomId_t)) );
|
---|
221 | const moleculeId_t molid = _mol->getMolIndex();
|
---|
222 | QtObservedMoleculeMap.insert( std::make_pair(molid, _mol) );
|
---|
223 |
|
---|
224 | LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOn for molecule "+toString(molid)+".");
|
---|
225 |
|
---|
226 | emit insertMolecule(_mol);
|
---|
227 | }
|
---|
228 |
|
---|
229 | void GLWorldScene::moleculeSignOff(const moleculeId_t _id)
|
---|
230 | {
|
---|
231 | ASSERT( QtObservedMoleculeMap.count(_id),
|
---|
232 | "GLWorldScene::moleculeSignOff() - cannot find id "+toString(_id)+" in map.");
|
---|
233 | const QtObservedMolecule::ptr mol = QtObservedMoleculeMap[_id];
|
---|
234 | mol->disconnect(this);
|
---|
235 | QtObservedMoleculeMap.erase(_id);
|
---|
236 |
|
---|
237 | LOG(3, "INFO: GLWorldScene: Received signal moleculeSignOff for molecule "+toString(_id)+".");
|
---|
238 |
|
---|
239 | emit removeMolecule(_id);
|
---|
240 | }
|
---|
241 |
|
---|
242 | /** Inserts a molecule into the scene.
|
---|
243 | *
|
---|
244 | * @param _mol molecule to insert
|
---|
245 | */
|
---|
246 | void GLWorldScene::moleculeInserted(QtObservedMolecule::ptr _mol)
|
---|
247 | {
|
---|
248 | ASSERT (_mol,
|
---|
249 | "GLWorldScene::moleculeInserted() - received shared_ptr for molecule is empty?");
|
---|
250 | const moleculeId_t molid = _mol->getMolIndex();
|
---|
251 | LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "+toString(molid)+".");
|
---|
252 |
|
---|
253 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
254 |
|
---|
255 | MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
|
---|
256 | ASSERT( iter == MoleculesinSceneMap.end(),
|
---|
257 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(molid)+" already present.");
|
---|
258 |
|
---|
259 | // check whether molecule is still present
|
---|
260 | if (RemovalMolecules.count(molid) != 0) {
|
---|
261 | RemovalMolecules.erase(molid);
|
---|
262 | return;
|
---|
263 | }
|
---|
264 |
|
---|
265 | // add new object
|
---|
266 | LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << molid);
|
---|
267 | GLMoleculeObject_molecule *molObject =
|
---|
268 | new GLMoleculeObject_molecule(
|
---|
269 | GLMoleculeObject::meshEmpty,
|
---|
270 | this,
|
---|
271 | *board,
|
---|
272 | _mol);
|
---|
273 | ASSERT( molObject != NULL,
|
---|
274 | "GLWorldScene::moleculeInserted - could not create molecule object for "+toString(molid));
|
---|
275 | #ifndef NDEBUG
|
---|
276 | std::pair<MoleculeNodeMap::iterator, bool> inserter =
|
---|
277 | #endif
|
---|
278 | MoleculesinSceneMap.insert( make_pair(molid, molObject) );
|
---|
279 | ASSERT(inserter.second,
|
---|
280 | "GLWorldScene::moleculeInserted() - molecule "+toString(molid)+" already present in scene.");
|
---|
281 |
|
---|
282 | // now handle all state changes that came up before the instantiation
|
---|
283 | if (MoleculeMissedStateMap.count(molid) != 0) {
|
---|
284 | // ASSERT( !MoleculeMissedStateMap[molid].empty(),
|
---|
285 | // "GLWorldScene::moleculeInserted() - we have an empty state change map for molecule with id "
|
---|
286 | // +toString(molid));
|
---|
287 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
288 | for (StateChangeMap_t::iterator iter = MoleculeMissedStateMap[molid].begin();
|
---|
289 | !MoleculeMissedStateMap[molid].empty();
|
---|
290 | iter = MoleculeMissedStateMap[molid].begin()) {
|
---|
291 | std::pair<StateChangeMap_t::iterator, StateChangeMap_t::iterator> rangeiter =
|
---|
292 | MoleculeMissedStateMap[molid].equal_range(iter->first);
|
---|
293 | const size_t StateCounts = std::distance(rangeiter.first, rangeiter.second);
|
---|
294 | if (StateCounts > 1) {
|
---|
295 | // more than one state change, have to combine
|
---|
296 | typedef std::map<StateChangeType, size_t> StateChangeAmounts_t;
|
---|
297 | StateChangeAmounts_t StateChangeAmounts;
|
---|
298 | for (StateChangeMap_t::const_iterator stateiter = rangeiter.first;
|
---|
299 | stateiter != rangeiter.second; ++stateiter)
|
---|
300 | ++StateChangeAmounts[stateiter->second];
|
---|
301 | ASSERT( StateChangeAmounts[atomInsertedState] >= StateChangeAmounts[atomRemovedState],
|
---|
302 | "GLWorldScene::moleculeInserted() - more atomRemoved states "
|
---|
303 | +toString(StateChangeAmounts[atomRemovedState])+" than atomInserted "
|
---|
304 | +toString(StateChangeAmounts[atomInsertedState])+" for atom "+toString(iter->first));
|
---|
305 | if (StateChangeAmounts[atomInsertedState] > StateChangeAmounts[atomRemovedState]) {
|
---|
306 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
307 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
308 | "atomInserted", // member name (no parameters here)
|
---|
309 | Qt::QueuedConnection, // connection type
|
---|
310 | Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters
|
---|
311 | } else {
|
---|
312 | LOG(1, "INFO: Atom " << iter->first << " has been inserted and removed already.");
|
---|
313 | }
|
---|
314 | // removed all state changes for this atom
|
---|
315 | MoleculeMissedStateMap[molid].erase(rangeiter.first, rangeiter.second);
|
---|
316 | } else {
|
---|
317 | // can only be an insertion
|
---|
318 | switch (rangeiter.first->second) {
|
---|
319 | case atomRemovedState:
|
---|
320 | ASSERT( 0,
|
---|
321 | "GLWorldScene::moleculeInserted() - atomRemoved state without atomInserted for atom "
|
---|
322 | +toString(iter->first));
|
---|
323 | break;
|
---|
324 | case atomInsertedState:
|
---|
325 | {
|
---|
326 | LOG(1, "INFO: invoking atomInserted for atom " << iter->first);
|
---|
327 | const QtObservedAtom::ptr walker = QtObservedAtomMap[iter->first];
|
---|
328 | QMetaObject::invokeMethod(molObject, // pointer to a QObject
|
---|
329 | "atomInserted", // member name (no parameters here)
|
---|
330 | Qt::QueuedConnection, // connection type
|
---|
331 | Q_ARG(QtObservedAtom::ptr, QtObservedAtomMap[iter->first])); // parameters
|
---|
332 | break;
|
---|
333 | }
|
---|
334 | default:
|
---|
335 | ASSERT( 0,
|
---|
336 | "GLWorldScene::moleculeInserted() - there are unknown change states.");
|
---|
337 | break;
|
---|
338 | }
|
---|
339 | // removed state changes for this atom
|
---|
340 | MoleculeMissedStateMap[molid].erase(iter);
|
---|
341 | }
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
|
---|
346 | connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
|
---|
347 | connect (molObject, SIGNAL(atomClicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
|
---|
348 | connect (molObject, SIGNAL(moleculeClicked(moleculeId_t)), this, SLOT(moleculeClicked(moleculeId_t)));
|
---|
349 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
350 | connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
|
---|
351 | connect (molObject, SIGNAL(hoverChanged(const atomId_t)), this, SIGNAL(hoverChanged(const atomId_t)));
|
---|
352 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
353 | connect (molObject, SIGNAL(hoverChanged(const moleculeId_t, int)), this, SIGNAL(hoverChanged(const moleculeId_t, int)));
|
---|
354 |
|
---|
355 | emit changed();
|
---|
356 | emit changeOccured();
|
---|
357 |
|
---|
358 | // remove state change map for the molecule
|
---|
359 | {
|
---|
360 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
361 | MoleculeMissedStateMap.erase(molid);
|
---|
362 | }
|
---|
363 | }
|
---|
364 |
|
---|
365 | /** Removes a molecule from the scene.
|
---|
366 | *
|
---|
367 | * @param _id id of molecule to remove
|
---|
368 | */
|
---|
369 | void GLWorldScene::moleculeRemoved(const moleculeId_t _id)
|
---|
370 | {
|
---|
371 | LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_id)+".");
|
---|
372 |
|
---|
373 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
374 |
|
---|
375 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
376 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
377 | RemovalMolecules.insert(_id);
|
---|
378 | } else {
|
---|
379 | LOG(1, "DEBUG: Removing GLMoleculeObject_molecule to id " << _id);
|
---|
380 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
381 | molObject->disconnect();
|
---|
382 | MoleculesinSceneMap.erase(iter);
|
---|
383 | delete molObject;
|
---|
384 | }
|
---|
385 |
|
---|
386 | // remove any possible state changes left
|
---|
387 | {
|
---|
388 | boost::recursive_mutex::scoped_lock lock(MoleculeMissedStateMap_mutex);
|
---|
389 | MoleculeMissedStateMap.erase(_id);
|
---|
390 | }
|
---|
391 |
|
---|
392 | emit changed();
|
---|
393 | emit changeOccured();
|
---|
394 | }
|
---|
395 |
|
---|
396 | void GLWorldScene::atomIndexChanged(const atomId_t _oldid, const atomId_t _newid)
|
---|
397 | {
|
---|
398 | if (QtObservedAtomMap.count(_oldid)) {
|
---|
399 | const QtObservedAtom::ptr atom = QtObservedAtomMap[_oldid];
|
---|
400 | QtObservedAtomMap.erase(_oldid);
|
---|
401 | QtObservedAtomMap.insert( std::make_pair(_newid, atom) );
|
---|
402 | }
|
---|
403 | }
|
---|
404 |
|
---|
405 | void GLWorldScene::moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid)
|
---|
406 | {
|
---|
407 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_oldid);
|
---|
408 | if ( iter == MoleculesinSceneMap.end()) {
|
---|
409 | RemovalMolecule_t::iterator removeiter =
|
---|
410 | RemovalMolecules.find(_oldid);
|
---|
411 | ASSERT( removeiter != RemovalMolecules.end(),
|
---|
412 | "GLWorldScene::moleculeIndexChanged() - cannot find id "+toString(_oldid)+" in any map.");
|
---|
413 | RemovalMolecules.erase(removeiter);
|
---|
414 | RemovalMolecules.insert(_newid);
|
---|
415 | if (QtObservedMoleculeMap.count(_oldid)) {
|
---|
416 | const QtObservedMolecule::ptr mol = QtObservedMoleculeMap[_oldid];
|
---|
417 | QtObservedMoleculeMap.erase(_oldid);
|
---|
418 | QtObservedMoleculeMap.insert( std::make_pair(_newid, mol) );
|
---|
419 | }
|
---|
420 | } else {
|
---|
421 | LOG(1, "DEBUG: Changing GLMoleculeObject_molecule from " << _oldid << " to id " << _newid);
|
---|
422 | GLMoleculeObject_molecule* molObject = iter->second;
|
---|
423 | MoleculesinSceneMap.erase(iter);
|
---|
424 | MoleculesinSceneMap.insert(
|
---|
425 | std::make_pair( _newid, molObject) );
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | void GLWorldScene::moleculesVisibilityChanged(const moleculeId_t _id, bool _visible)
|
---|
430 | {
|
---|
431 | boost::recursive_mutex::scoped_lock lock(MoleculeinSceneMap_mutex);
|
---|
432 | MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
|
---|
433 | ASSERT( iter != MoleculesinSceneMap.end(),
|
---|
434 | "GLWorldScene::moleculeInserted() - molecule's id "+toString(_id)+" is unknown.");
|
---|
435 |
|
---|
436 | GLMoleculeObject_molecule *molObject = iter->second;
|
---|
437 | molObject->setVisible(_visible);
|
---|
438 |
|
---|
439 | emit changed();
|
---|
440 | emit changeOccured();
|
---|
441 | }
|
---|
442 |
|
---|
443 | /** Adds a shape to the scene.
|
---|
444 | *
|
---|
445 | */
|
---|
446 | void GLWorldScene::addShape(const std::string &_name)
|
---|
447 | {
|
---|
448 | Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
|
---|
449 | if (shape != NULL) {
|
---|
450 | GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
|
---|
451 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
452 | ASSERT(iter == ShapesinSceneMap.end(),
|
---|
453 | "GLWorldScene::addShape() - same shape "+_name+" added again.");
|
---|
454 | ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
|
---|
455 | } else
|
---|
456 | ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
|
---|
457 |
|
---|
458 | emit changed();
|
---|
459 | }
|
---|
460 |
|
---|
461 | void GLWorldScene::removeShape(const std::string &_name)
|
---|
462 | {
|
---|
463 | ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
|
---|
464 | ASSERT(iter != ShapesinSceneMap.end(),
|
---|
465 | "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
|
---|
466 | ShapesinSceneMap.erase(iter);
|
---|
467 | delete(iter->second);
|
---|
468 |
|
---|
469 | emit changed();
|
---|
470 | }
|
---|
471 |
|
---|
472 | void GLWorldScene::updateSelectedShapes()
|
---|
473 | {
|
---|
474 | foreach (QObject *obj, children()) {
|
---|
475 | GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
|
---|
476 | if (shapeobj){
|
---|
477 | shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
|
---|
478 | }
|
---|
479 | }
|
---|
480 |
|
---|
481 | emit changed();
|
---|
482 | }
|
---|
483 |
|
---|
484 | void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
|
---|
485 | {
|
---|
486 | // Initialize all of the mesh objects that we have as children.
|
---|
487 | foreach (QObject *obj, children()) {
|
---|
488 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
489 | if (meshobj)
|
---|
490 | meshobj->initialize(view, painter);
|
---|
491 | }
|
---|
492 | }
|
---|
493 |
|
---|
494 | void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
|
---|
495 | {
|
---|
496 | // Draw all of the mesh objects that we have as children.
|
---|
497 | foreach (QObject *obj, children()) {
|
---|
498 | GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
|
---|
499 | if (meshobj)
|
---|
500 | meshobj->draw(painter, cameraPlane);
|
---|
501 | }
|
---|
502 | }
|
---|
503 |
|
---|
504 | void GLWorldScene::setSelectionMode(SelectionModeType mode)
|
---|
505 | {
|
---|
506 | selectionMode = mode;
|
---|
507 | // TODO send update to toolbar
|
---|
508 | }
|
---|
509 |
|
---|
510 | void GLWorldScene::setSelectionModeAtom()
|
---|
511 | {
|
---|
512 | setSelectionMode(SelectAtom);
|
---|
513 | }
|
---|
514 |
|
---|
515 | void GLWorldScene::setSelectionModeMolecule()
|
---|
516 | {
|
---|
517 | setSelectionMode(SelectMolecule);
|
---|
518 | }
|
---|
519 |
|
---|