source: src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp@ 25b3559

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 Candidate_v1.7.0 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 25b3559 was c67518, checked in by Frederik Heber <heber@…>, 14 years ago

GL: molecules show if they're selected (mostly dummy)

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