source: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp@ 50246c

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 50246c was bd6768, checked in by Frederik Heber <heber@…>, 9 years ago

GLWorldScene now properly reassigns parents of GLMoleculeObjects.

  • this is important for atoms and bonds such that they disappear when their associated molecule is visualized as a tesselated surface.
  • Property mode set to 100644
File size: 22.7 KB
RevLine 
[907636]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]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/>.
[907636]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"
[d1196d]39#include <Qt3D/qglview.h>
[bca99d]40#include <Qt3D/qglbuilder.h>
41#include <Qt3D/qglscenenode.h>
42#include <Qt3D/qglsphere.h>
43#include <Qt3D/qglcylinder.h>
[907636]44
[015f8c]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
[2f7988]51#include "UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp"
[907636]52
53#include "CodePatterns/MemDebug.hpp"
54
[7188b1]55#include "CodePatterns/Log.hpp"
56
[f1b5ca]57#include <boost/assign.hpp>
58
[0e9ffe]59#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
[89643d]60#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
[6966b7]61#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
62#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
[6f0841]63#include "Atom/atom.hpp"
[7188b1]64#include "Bond/bond.hpp"
[89643d]65#include "Descriptors/AtomIdDescriptor.hpp"
[8c001a]66#include "Descriptors/MoleculeIdDescriptor.hpp"
[37b2575]67#include "Helpers/helpers.hpp"
[85c36d]68#include "Shapes/ShapeRegistry.hpp"
[907636]69#include "molecule.hpp"
70#include "World.hpp"
71
[2ad1ec]72#include <iostream>
73
[ce7fdc]74using namespace MoleCuilder;
[907636]75
[15c8a9]76GLWorldScene::GLWorldScene(
[2f7988]77 QtObservedInstanceBoard * _board,
[15c8a9]78 QObject *parent) :
79 QObject(parent),
80 selectionMode(SelectAtom),
81 board(_board)
[907636]82{
[f1b5ca]83 qRegisterMetaType<atomId_t>("atomId_t");
84 qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
85
[72a4c1]86 int sphereDetails[] = {5, 3, 2, 0};
87 int cylinderDetails[] = {16, 8, 6, 3};
88 for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
89 QGLBuilder emptyBuilder;
[8c001a]90 GLMoleculeObject::meshEmpty[i] = emptyBuilder.finalizedSceneNode();
[72a4c1]91 QGLBuilder sphereBuilder;
92 sphereBuilder << QGLSphere(2.0, sphereDetails[i]);
[8c001a]93 GLMoleculeObject::meshSphere[i] = sphereBuilder.finalizedSceneNode();
94 GLMoleculeObject::meshSphere[i]->setOption(QGLSceneNode::CullBoundingBox, true);
[72a4c1]95 QGLBuilder cylinderBuilder;
96 cylinderBuilder << QGLCylinder(.25,.25,1.0,cylinderDetails[i]);
[8c001a]97 GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
98 GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
[72a4c1]99 }
[1b07b1]100 connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
[bd6768]101 this, SLOT(insertMolecule(QtObservedMolecule::ptr)));
[f91ef6]102 connect(board, SIGNAL(moleculeRemoved(ObservedValue_Index_t)),
[bd6768]103 this, SLOT(removeMolecule(ObservedValue_Index_t)));
104
[59f1bc]105 connect(board, SIGNAL(atomInserted(QtObservedAtom::ptr)),
[bd6768]106 this, SLOT(connectAtom(QtObservedAtom::ptr)), Qt::DirectConnection);
107 connect(this, SIGNAL(atomConnected(QtObservedAtom::ptr)),
108 this, SLOT(insertAtom(QtObservedAtom::ptr)));
[f91ef6]109 connect(board, SIGNAL(atomRemoved(ObservedValue_Index_t)),
[bd6768]110 this, SLOT(removeAtom(ObservedValue_Index_t)));
111
[96f14a]112 connect(board, SIGNAL(bondInserted(QtObservedBond::ptr)),
[bd6768]113 this, SLOT(connectBond(QtObservedBond::ptr)), Qt::DirectConnection);
114 connect(this, SIGNAL(bondConnected(QtObservedBond::ptr)),
115 this, SLOT(insertBond(QtObservedBond::ptr)));
[96f14a]116 connect(board, SIGNAL(bondRemoved(ObservedValue_Index_t)),
[bd6768]117 this, SLOT(removeBond(ObservedValue_Index_t)));
[0a6ff9]118
[f714763]119// connect(this, SIGNAL(updated()), this, SLOT(update()));
[907636]120}
121
122GLWorldScene::~GLWorldScene()
[7188b1]123{
124 // remove all elements
125 GLMoleculeObject::cleanMaterialMap();
126}
[907636]127
[bd6768]128void GLWorldScene::clickAtom(atomId_t no)
[8c001a]129{
[bd6768]130 LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
[f01769]131 const atom * const Walker = const_cast<const World &>(World::getInstance()).
132 getAtom(AtomById(no));
[369cb1]133 ASSERT( Walker != NULL,
[bd6768]134 "GLWorldScene::clickAtom() - clicked atom has disappeared.");
[8c001a]135 if (selectionMode == SelectAtom){
136 if (!World::getInstance().isSelected(Walker))
137 SelectionAtomById(std::vector<atomId_t>(1,no));
138 else
139 SelectionNotAtomById(std::vector<atomId_t>(1,no));
140 }else if (selectionMode == SelectMolecule){
141 const molecule *mol = Walker->getMolecule();
142 ASSERT(mol, "Atom without molecule has been clicked.");
[d7cad1]143 molids_t ids(1, mol->getId());
[8c001a]144 if (!World::getInstance().isSelected(mol))
[d7cad1]145 SelectionMoleculeById(ids);
[8c001a]146 else
[d7cad1]147 SelectionNotMoleculeById(ids);
[8c001a]148 }
149 emit clicked(no);
150}
151
[bd6768]152/** Prepares adding an atom to the scene
153 *
154 * We need to listen to moleculeChanged() in order to properly re-parent()
155 * this QObject
156 *
157 * @param _atom atom to connect
158 */
159void GLWorldScene::connectAtom(QtObservedAtom::ptr _atom)
160{
161 connect(_atom.get(), SIGNAL(moleculeChanged()), this, SLOT(reparentAtom()));
162
163 {
164 const ObservedValue_Index_t atomid = _atom->getIndex();
165 boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
166 AtomNodeParentMap[atomid] = static_cast<QObject *>(this);
167 }
168
169 emit atomConnected(_atom);
170}
171
[f1b5ca]172/** Adds an atom to the scene.
[59f1bc]173 *
[f1b5ca]174 * @param _atom atom to add
[9c259e]175 */
[bd6768]176void GLWorldScene::insertAtom(QtObservedAtom::ptr _atom)
[9c259e]177{
[f1b5ca]178 LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "
179 << _atom->getAtomIndex());
180
[f91ef6]181 const ObservedValue_Index_t atomid = _atom->getIndex();
[bd6768]182 QObject *parent = static_cast<QObject *>(this);
183 GLMoleculeObject_atom *atomObject = NULL;
184 {
185 boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
186 AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(atomid);
187 if (parentiter != AtomNodeParentMap.end())
188 parent = parentiter->second;
189 else
190 AtomNodeParentMap[atomid] = parent;
191
192 atomObject = new GLMoleculeObject_atom(
193 GLMoleculeObject::meshSphere,
194 parent,
195 _atom);
196 ASSERT( atomObject != NULL,
197 "GLWorldScene::atomInserted - could not create atom object for "
198 +toString(_atom->getAtomIndex()));
199 }
[f1b5ca]200 AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
201 ASSERT(iter == AtomsinSceneMap.end(),
[bd6768]202 "GLWorldScene::insertAtom - same atom with id "
[f1b5ca]203 +toString(_atom->getAtomIndex())+" added again.");
204 AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
205
[bd6768]206 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(clickAtom(atomId_t)));
[f1b5ca]207 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
208 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
209 connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
210
211 emit changed();
212 emit changeOccured();
[59f1bc]213}
214
[f1b5ca]215/** Removes an atom.
[59f1bc]216 *
[f1b5ca]217 * @param _atomid index of the atom that is removed
[59f1bc]218 */
[bd6768]219void GLWorldScene::removeAtom(ObservedValue_Index_t _atomid)
[59f1bc]220{
[f1b5ca]221 LOG(3, "INFO: GLWorldScene: Received signal atomRemoved for atom "+toString(_atomid)+".");
222 // bonds are removed by signal coming from ~bond
223
224 // remove atoms
225 AtomNodeMap::iterator iter = AtomsinSceneMap.find(_atomid);
226 ASSERT(iter != AtomsinSceneMap.end(),
[bd6768]227 "GLWorldScene::removeAtom() - atom "+toString(_atomid)+" not on display.");
[f1b5ca]228 GLMoleculeObject_atom *atomObject = iter->second;
229 AtomsinSceneMap.erase(iter);
230 delete atomObject;
[bd6768]231 {
232 boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
233 AtomNodeParentMap.erase(_atomid);
234 }
[f1b5ca]235 emit changed();
236 emit changeOccured();
[59f1bc]237}
238
[bd6768]239/** Prepares adding a bond to the scene
240 *
241 * We need to listen to moleculeChanged() in order to properly re-parent()
242 * this QObject
243 *
244 * @param _bond bond to connect
245 */
246void GLWorldScene::connectBond(QtObservedBond::ptr _bond)
247{
248 connect(_bond.get(), SIGNAL(leftmoleculeChanged()), this, SLOT(reparentBondLeft()));
249 connect(_bond.get(), SIGNAL(rightmoleculeChanged()), this, SLOT(reparentBondRight()));
250
251 {
252 const ObservedValue_Index_t bondid = _bond->getIndex();
253 boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
254 std::vector<QObject *> parents(2, static_cast<QObject *>(this));
255 if ((_bond->getLeftAtom() != NULL) && (_bond->getLeftAtom()->getMoleculeRef() != NULL)) {
256 const ObservedValue_Index_t molid = _bond->getLeftAtom()->getMoleculeRef()->getIndex();
257 const MoleculeNodeMap::iterator leftiter = MoleculesinSceneMap.find(molid);
258 if (leftiter != MoleculesinSceneMap.end())
259 parents[0] = leftiter->second;
260 }
261 if ((_bond->getRightAtom() != NULL) && (_bond->getRightAtom()->getMoleculeRef() != NULL)) {
262 const ObservedValue_Index_t molid = _bond->getRightAtom()->getMoleculeRef()->getIndex();
263 const MoleculeNodeMap::iterator leftiter = MoleculesinSceneMap.find(molid);
264 if (leftiter != MoleculesinSceneMap.end())
265 parents[1] = leftiter->second;
266 }
267 BondNodeParentMap.insert( std::make_pair(bondid, parents) );
268 }
269
270 emit bondConnected(_bond);
271}
272
[f1b5ca]273/** Adds a bond to the scene.
[96f14a]274 *
[f1b5ca]275 * @param _bond bond to add
[96f14a]276 */
[bd6768]277void GLWorldScene::insertBond(QtObservedBond::ptr _bond)
[96f14a]278{
[f1b5ca]279 static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
280 boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
281 (GLMoleculeObject_bond::left)
282 (GLMoleculeObject_bond::right);
[bd6768]283 LOG(3, "INFO: GLWorldScene::insertBond() - Adding bonds " << _bond->getBondIndex());
[f1b5ca]284
[96f14a]285 const ObservedValue_Index_t bondid = _bond->getIndex();
[bd6768]286 std::vector<QObject *> parents(2, static_cast<QObject *>(this));
287 {
288 boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
289 BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
290 if (parentiter != BondNodeParentMap.end()) {
291 parents = parentiter->second;
292 } else
293 BondNodeParentMap.insert( std::make_pair(bondid, parents) );
294
295 BondNodeMap::iterator iter = BondsinSceneMap.find(bondid);
296 ASSERT( iter == BondsinSceneMap.end(),
297 "GLWorldScene::insertBond() - bond "+toString(bondid)+" is already known.");
298 for (size_t i=0;i<2;++i) {
299 GLMoleculeObject_bond *bondObject = new GLMoleculeObject_bond(
300 GLMoleculeObject::meshCylinder,
301 parents[i],
302 _bond,
303 bondsides[i]);
304 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
305 BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
306 }
[96f14a]307 }
308
[f1b5ca]309 emit changed();
310 emit changeOccured();
[96f14a]311}
312
[f1b5ca]313/** Removes a bond.
[96f14a]314 *
[f1b5ca]315 * @param _bondid id of bond to remove
[96f14a]316 */
[bd6768]317void GLWorldScene::removeBond(ObservedValue_Index_t _bondid)
[96f14a]318{
[bd6768]319 LOG(3, "INFO: GLWorldScene::removedBond() - Removing bond to id " << _bondid);
[9c259e]320
[f1b5ca]321 // left bond
[bd6768]322 std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
323 BondsinSceneMap.equal_range(_bondid);
324 ASSERT( iters.first != iters.second,
325 "GLWorldScene::removedBond() - could not find bond to id "+toString(_bondid));
326 for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
327 GLMoleculeObject_bond *bondObject = iter->second;
328 delete bondObject; // is done by signal from bond itself
329 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
330 }
331 BondsinSceneMap.erase(_bondid);
332 {
333 boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
334 BondNodeParentMap.erase(_bondid);
335 }
[8281cc]336
[f1b5ca]337 emit changed();
338 emit changeOccured();
[9c259e]339}
340
[f1b5ca]341void GLWorldScene::hoverChangedSignalled(GLMoleculeObject *ob)
[96f14a]342{
[f1b5ca]343 // Find the atom, ob corresponds to.
344 hoverAtomId = -1;
345 GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
346 if (atomObject){
347 for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
348 if (iter->second == atomObject)
349 hoverAtomId = iter->second->objectId();
[96f14a]350 }
351
[f1b5ca]352 // Propagate signal.
353 emit hoverChanged(hoverAtomId);
[96f14a]354 } else {
[f1b5ca]355 // Find the atom, ob corresponds to.
356 GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
357 if (moleculeObject){
358 // Propagate signal.
359 emit hoverChanged(moleculeObject->objectId(), 0);
[96f14a]360 }
361 }
362}
363
[bd6768]364void GLWorldScene::clickMolecule(moleculeId_t no)
[8281cc]365{
[f1b5ca]366 LOG(3, "INFO: GLMoleculeObject_molecule - mol " << no << " has been clicked.");
367 const molecule * const mol= const_cast<const World &>(World::getInstance()).
368 getMolecule(MoleculeById(no));
369 ASSERT(mol, "Atom without molecule has been clicked.");
370 molids_t ids(1, mol->getId());
371 if (!World::getInstance().isSelected(mol))
372 SelectionMoleculeById(ids);
373 else
374 SelectionNotMoleculeById(ids);
375 emit clicked(no);
[8281cc]376}
377
[026bef]378/** Inserts a molecule into the scene.
[c67518]379 *
[8c001a]380 * @param _mol molecule to insert
[c67518]381 */
[bd6768]382void GLWorldScene::insertMolecule(QtObservedMolecule::ptr _mol)
[c67518]383{
[f91ef6]384 const ObservedValue_Index_t molid = _mol->getIndex();
385 LOG(3, "INFO: GLWorldScene: Received signal moleculeInserted for molecule "
386 << _mol->getMolIndex());
[7cf0eb]387
[1b07b1]388 MoleculeNodeMap::const_iterator iter = MoleculesinSceneMap.find(molid);
[8c001a]389 ASSERT( iter == MoleculesinSceneMap.end(),
[bd6768]390 "GLWorldScene::insertMolecule() - molecule's id "+toString(_mol->getMolIndex())
[f91ef6]391 +" already present.");
[8c001a]392
393 // add new object
[f91ef6]394 LOG(1, "DEBUG: Adding GLMoleculeObject_molecule to id " << _mol->getMolIndex());
[1b07b1]395 GLMoleculeObject_molecule *molObject =
396 new GLMoleculeObject_molecule(
397 GLMoleculeObject::meshEmpty,
398 this,
399 _mol);
400 ASSERT( molObject != NULL,
[bd6768]401 "GLWorldScene::insertMolecule - could not create molecule object for "
[f91ef6]402 +toString(_mol->getMolIndex()));
[1b07b1]403#ifndef NDEBUG
404 std::pair<MoleculeNodeMap::iterator, bool> inserter =
405#endif
406 MoleculesinSceneMap.insert( make_pair(molid, molObject) );
407 ASSERT(inserter.second,
[bd6768]408 "GLWorldScene::insertMolecule() - molecule "+toString(_mol->getMolIndex())
[f91ef6]409 +" already present in scene.");
[1b07b1]410
411 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed()));
412 connect (molObject, SIGNAL(changeOccured()), this, SIGNAL(changeOccured()));
413
414 emit changed();
415 emit changeOccured();
[c67518]416}
417
[7cf0eb]418/** Removes a molecule from the scene.
419 *
[f1b5ca]420 * @param _molid index of the molecule to remove
[7cf0eb]421 */
[bd6768]422void GLWorldScene::removeMolecule(ObservedValue_Index_t _molid)
[7cf0eb]423{
[f1b5ca]424 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molid)+".");
[7c7c4a]425
[f1b5ca]426 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molid);
[4a187d]427 ASSERT ( iter != MoleculesinSceneMap.end(),
[bd6768]428 "GLWorldScene::removeMolecule() - to be removed molecule "+toString(_molid)
[4a187d]429 +" is already gone.");
430 // check if it's already empty
[f1b5ca]431 GLMoleculeObject_molecule *molObject = iter->second;
432 delete molObject;
[4a187d]433 MoleculesinSceneMap.erase(iter);
[bcf9cd]434
[f1b5ca]435 emit changed();
436 emit changeOccured();
[ce4126]437}
438
[f91ef6]439void GLWorldScene::moleculesVisibilityChanged(ObservedValue_Index_t _id, bool _visible)
[739ee9]440{
441 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_id);
442 ASSERT( iter != MoleculesinSceneMap.end(),
[f91ef6]443 "GLWorldScene::moleculeInserted() - molecule's id "
444 +toString(board->getMoleculeIdToIndex(_id))+" is unknown.");
[739ee9]445
446 GLMoleculeObject_molecule *molObject = iter->second;
447 molObject->setVisible(_visible);
448
449 emit changed();
450 emit changeOccured();
451}
452
[bd6768]453/** Changes the parent of an object in the scene.
454 *
455 * \param _id index of the object whose parent to change
456 * \param _ob new parent
457 */
458void GLWorldScene::reparentAtom()
459{
460 QtObservedAtom *walker = dynamic_cast<QtObservedAtom *>(sender());
461 boost::recursive_mutex::scoped_lock lock(AtomNodeParentMap_mutex);
462 const ObservedValue_Index_t walkerid = walker->getIndex();
463 AtomNodeParentMap_t::iterator parentiter = AtomNodeParentMap.find(walkerid);
464 ASSERT( parentiter != AtomNodeParentMap.end(),
465 "GLWorldScene::reparentAtom() - could not find object to id "+toString(walkerid));
466 AtomNodeMap::iterator atomiter = AtomsinSceneMap.find(walkerid);
467 ASSERT( atomiter != AtomsinSceneMap.end(),
468 "GLWorldScene::reparentAtom() - could not find GLMoleculeObject to id "+toString(walkerid));
469 if (walker->getMoleculeRef() != NULL) {
470 const ObservedValue_Index_t molid = walker->getMoleculeRef()->getIndex();
471 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
472 if (moliter != MoleculesinSceneMap.end()) {
473 parentiter->second = moliter->second;
474 atomiter->second->setParent(moliter->second);
475 } else {
476 // associated molecule has not yet been instantiated, keep in mind
477 ASSERT(0,
478 "GLWorldScene::reparentAtom() - new molecule not present yet?");
479 }
480 } else {
481 parentiter->second = static_cast<QObject*>(this);
482 atomiter->second->setParent(this);
483 }
484}
485
486/** Changes the parent of an object in the scene.
487 *
488 * \param _id index of the object whose parent to change
489 * \param _ob new parent
490 */
491void GLWorldScene::reparentBondLeft()
492{
493 QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
494 boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
495 const ObservedValue_Index_t bondid = bond->getIndex();
496 BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
497 ASSERT( parentiter != BondNodeParentMap.end(),
498 "GLWorldScene::reparentBondLeft() - could not find object to id "+toString(bondid));
499 BondNodeMap::iterator bonditer = BondsinSceneMap.find(bondid);
500 ASSERT( bonditer != BondsinSceneMap.end(),
501 "GLWorldScene::reparentBondLeft() - could not find GLMoleculeObject to id "+toString(bondid));
502 if (bonditer->second->BondSide != GLMoleculeObject_bond::left)
503 ++bonditer;
504 ASSERT( (bonditer->first == bondid)
505 && (bonditer->second->BondSide == GLMoleculeObject_bond::left),
506 "GLWorldScene::reparentBondLeft() - could not find left-side bond.");
507 if ((bond->getLeftAtom() != NULL) && (bond->getLeftAtom()->getMoleculeRef() != NULL)) {
508 const ObservedValue_Index_t molid = bond->getLeftAtom()->getMoleculeRef()->getIndex();
509 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
510 if (moliter != MoleculesinSceneMap.end()) {
511 parentiter->second[0] = moliter->second;
512 bonditer->second->setParent(moliter->second);
513 } else {
514 // associated molecule has not yet been instantiated, keep in mind
515 ASSERT(0,
516 "GLWorldScene::reparentBondLeft() - new molecule not present yet?");
517 }
518 } else {
519 parentiter->second[0] = static_cast<QObject*>(this);
520 bonditer->second->setParent(this);
521 }
522}
523
524/** Changes the parent of an object in the scene.
525 *
526 * \param _id index of the object whose parent to change
527 * \param _ob new parent
528 */
529void GLWorldScene::reparentBondRight()
530{
531 QtObservedBond *bond = dynamic_cast<QtObservedBond *>(sender());
532 boost::recursive_mutex::scoped_lock lock(BondNodeParentMap_mutex);
533 const ObservedValue_Index_t bondid = bond->getIndex();
534 BondNodeParentMap_t::iterator parentiter = BondNodeParentMap.find(bondid);
535 ASSERT( parentiter != BondNodeParentMap.end(),
536 "GLWorldScene::reparentBondLeft() - could not find object to id "+toString(bondid));
537 BondNodeMap::iterator bonditer = BondsinSceneMap.find(bondid);
538 ASSERT( bonditer != BondsinSceneMap.end(),
539 "GLWorldScene::reparentBondLeft() - could not find GLMoleculeObject to id "+toString(bondid));
540 if (bonditer->second->BondSide != GLMoleculeObject_bond::right)
541 ++bonditer;
542 ASSERT( (bonditer->first == bondid)
543 && (bonditer->second->BondSide == GLMoleculeObject_bond::right),
544 "GLWorldScene::reparentBondLeft() - could not find right-side bond.");
545 if ((bond->getRightAtom() != NULL) && (bond->getRightAtom()->getMoleculeRef() != NULL)) {
546 const ObservedValue_Index_t molid = bond->getRightAtom()->getMoleculeRef()->getIndex();
547 MoleculeNodeMap::iterator moliter = MoleculesinSceneMap.find(molid);
548 if (moliter != MoleculesinSceneMap.end()) {
549 parentiter->second[1] = moliter->second;
550 bonditer->second->setParent(moliter->second);
551 } else {
552 // associated molecule has not yet been instantiated, keep in mind
553 ASSERT(0,
554 "GLWorldScene::reparentBondRight() - new molecule not present yet?");
555 }
556 } else {
557 parentiter->second[1] = static_cast<QObject*>(this);
558 bonditer->second->setParent(this);
559 }
560}
561
[f75491]562/** Adds a shape to the scene.
[4d6662]563 *
[f75491]564 */
[07136a]565void GLWorldScene::addShape(const std::string &_name)
[f75491]566{
[07136a]567 Shape * const shape = ShapeRegistry::getInstance().getByName(_name);
568 if (shape != NULL) {
569 GLMoleculeObject_shape *shapeObject = new GLMoleculeObject_shape(*shape, this);
570 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
571 ASSERT(iter == ShapesinSceneMap.end(),
572 "GLWorldScene::addShape() - same shape "+_name+" added again.");
573 ShapesinSceneMap.insert( make_pair(_name, shapeObject) );
574 } else
575 ELOG(2, "GLWorldScene::addShape() - shape disappeared before we could draw it.");
576
577 emit changed();
[284551]578}
579
[07136a]580void GLWorldScene::removeShape(const std::string &_name)
[85c36d]581{
[07136a]582 ShapeNodeMap::iterator iter = ShapesinSceneMap.find(_name);
[ba6b5c]583 ASSERT(iter != ShapesinSceneMap.end(),
[07136a]584 "GLWorldScene::removeShape() - shape "+_name+" not in scene.");
[148dde0]585 ShapesinSceneMap.erase(iter);
[85c36d]586 delete(iter->second);
[07136a]587
588 emit changed();
[85c36d]589}
590
591void GLWorldScene::updateSelectedShapes()
[284551]592{
593 foreach (QObject *obj, children()) {
594 GLMoleculeObject_shape *shapeobj = qobject_cast<GLMoleculeObject_shape *>(obj);
[85c36d]595 if (shapeobj){
596 shapeobj->enable(ShapeRegistry::getInstance().isSelected(shapeobj->getShape()));
597 }
[284551]598 }
[07136a]599
600 emit changed();
[f75491]601}
602
[7188b1]603void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
604{
605 // Initialize all of the mesh objects that we have as children.
606 foreach (QObject *obj, children()) {
607 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
608 if (meshobj)
609 meshobj->initialize(view, painter);
610 }
611}
612
[72a4c1]613void GLWorldScene::draw(QGLPainter *painter, const QVector4D &cameraPlane) const
[7188b1]614{
615 // Draw all of the mesh objects that we have as children.
616 foreach (QObject *obj, children()) {
617 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
618 if (meshobj)
[72a4c1]619 meshobj->draw(painter, cameraPlane);
[7188b1]620 }
[907636]621}
[06ebf5]622
[6966b7]623void GLWorldScene::setSelectionMode(SelectionModeType mode)
624{
625 selectionMode = mode;
626 // TODO send update to toolbar
627}
628
629void GLWorldScene::setSelectionModeAtom()
630{
631 setSelectionMode(SelectAtom);
632}
633
634void GLWorldScene::setSelectionModeMolecule()
635{
636 setSelectionMode(SelectMolecule);
637}
[20f9b5]638
Note: See TracBrowser for help on using the repository browser.