source: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp@ 42c6a47

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 42c6a47 was 5a2a06, checked in by Frederik Heber <heber@…>, 13 years ago

GL: sending more signals to redraw

  • atoms send changed() to scene when element or position changed
  • atoms send selectionChanged() to scene when (un)selected
  • bonds send changed() to scene when an atom changes its position
  • Property mode set to 100644
File size: 7.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
24#include "GLMoleculeObject.hpp"
25#include "GLMoleculeObject_atom.hpp"
26#include "GLMoleculeObject_bond.hpp"
27
28#include "CodePatterns/MemDebug.hpp"
29
30#include "CodePatterns/Log.hpp"
31
32#include "Actions/SelectionAction/Atoms/AtomByIdAction.hpp"
33#include "Actions/SelectionAction/Atoms/NotAtomByIdAction.hpp"
34#include "Atom/atom.hpp"
35#include "Bond/bond.hpp"
36#include "Descriptors/AtomIdDescriptor.hpp"
37#include "Helpers/helpers.hpp"
38#include "molecule.hpp"
39#include "World.hpp"
40
41#include <iostream>
42
43using namespace MoleCuilder;
44
45std::ostream &operator<<(std::ostream &ost, const GLWorldScene::BondIds &t)
46{
47 ost << t.first << "," << t.second;
48 return ost;
49}
50
51GLWorldScene::GLWorldScene(QObject *parent)
52 : QObject(parent)
53{
54 init();
55
56 //changeMaterials(false);
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 // create molecule
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/** Adds a bond to the scene.
139 *
140 * @param _bond bond to add
141 * @param side which side of the bond (left or right)
142 */
143void GLWorldScene::bondInserted(const bond *_bond, const enum GLMoleculeObject_bond::SideOfBond side)
144{
145 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
146 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
147
148 BondIds ids;
149 switch (side) {
150 case GLMoleculeObject_bond::left:
151 ids = std::make_pair(_bond->leftatom->getId(), _bond->rightatom->getId());
152 break;
153 case GLMoleculeObject_bond::right:
154 ids = std::make_pair(_bond->rightatom->getId(), _bond->leftatom->getId());
155 break;
156 }
157#ifndef NDEBUG
158 BondNodeMap::iterator iter = BondsinSceneMap.find(ids);
159 ASSERT(iter == BondsinSceneMap.end(),
160 "GLWorldScene::bondAdded() - same left-sided bond "+toString(*_bond)+" added again.");
161#endif
162 GLMoleculeObject_bond *bondObject =
163 new GLMoleculeObject_bond(this, _bond, side);
164 connect (
165 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
166 this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
167 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
168 BondsinSceneMap.insert( make_pair(ids, bondObject) );
169// BondIdsinSceneMap.insert( Leftids );
170 emit changeOccured();
171}
172
173/** Removes a bond from the scene.
174 *
175 * @param _bond bond to remove
176 */
177void GLWorldScene::bondRemoved(const atomId_t leftnr, const atomId_t rightnr)
178{
179 LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond between "+toString(leftnr)+" and "+toString(rightnr)+".");
180 {
181 // left bond
182 const BondIds Leftids( make_pair(leftnr, rightnr) );
183 BondNodeMap::iterator leftiter = BondsinSceneMap.find( Leftids );
184 ASSERT(leftiter != BondsinSceneMap.end(),
185 "GLWorldScene::bondRemoved() - bond "+toString(leftnr)+"-"
186 +toString(rightnr)+" not on display.");
187 //GLMoleculeObject_bond *bondObject = leftiter->second;
188 BondsinSceneMap.erase(leftiter);
189 //delete bondObject; // is done by signal from bond itself
190 //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
191 }
192
193 emit changeOccured();
194}
195
196void GLWorldScene::initialize(QGLView *view, QGLPainter *painter) const
197{
198 // Initialize all of the mesh objects that we have as children.
199 foreach (QObject *obj, children()) {
200 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
201 if (meshobj)
202 meshobj->initialize(view, painter);
203 }
204}
205
206void GLWorldScene::draw(QGLPainter *painter) const
207{
208 // Draw all of the mesh objects that we have as children.
209 foreach (QObject *obj, children()) {
210 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
211 if (meshobj)
212 meshobj->draw(painter);
213 }
214}
215
216void GLWorldScene::atomClicked(atomId_t no)
217{
218 LOG(3, "INFO: GLWorldScene - atom " << no << " has been clicked.");
219 const atom *Walker = World::getInstance().getAtom(AtomById(no));
220 if (!World::getInstance().isSelected(Walker))
221 SelectionAtomById(no);
222 else
223 SelectionNotAtomById(no);
224 emit clicked(no);
225}
226
Note: See TracBrowser for help on using the repository browser.