Changeset 53059e for src/UIElements/Views/Qt4/Qt3D
- Timestamp:
- Apr 11, 2012, 4:52:37 PM (13 years ago)
- Branches:
- 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
- Children:
- 3e93332
- Parents:
- c0ed1e (diff), 3927ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (04/06/12 11:59:28)
- git-committer:
- Frederik Heber <heber@…> (04/11/12 16:52:37)
- Location:
- src/UIElements/Views/Qt4/Qt3D
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
rc0ed1e r53059e 42 42 #include "CodePatterns/MemDebug.hpp" 43 43 44 QGLMaterial *GLMoleculeObject::m_hoverMaterial = NULL; 45 QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL; 46 QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL; 47 44 48 45 49 GLMoleculeObject::GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent) 46 50 : QObject(parent) 47 51 { 48 m_mesh = 0; 49 m_GLMoleculeObject = GLMoleculeObject; 52 m_mesh = GLMoleculeObject; 50 53 m_scale = 1.0f; 54 m_scaleZ = 1.0f; 51 55 m_rotationAngle = 0.0f; 52 56 m_effect = 0; 53 57 m_objectId = -1; 54 58 m_hovering = false; 59 m_selected = false; 55 60 m_material = 0; 56 m_hoverMaterial = 0;61 initStaticMaterials(); 57 62 } 58 63 … … 61 66 { 62 67 scene->setParent(this); 63 m_mesh = 0; 64 m_GLMoleculeObject = scene->mainNode(); 68 m_mesh = scene->mainNode(); 65 69 m_scale = 1.0f; 70 m_scaleZ = 1.0f; 66 71 m_rotationAngle = 0.0f; 67 72 m_effect = 0; 68 73 m_objectId = -1; 69 74 m_hovering = false; 75 m_selected = false; 70 76 m_material = 0; 71 m_hoverMaterial = 0;77 initStaticMaterials(); 72 78 } 73 79 74 80 GLMoleculeObject::~GLMoleculeObject() 75 81 { 76 delete m_mesh;77 82 } 78 83 … … 82 87 if (m_objectId != -1) 83 88 view->registerObject(m_objectId, this); 89 } 90 91 92 /** Draws a box around the mesh. 93 * 94 */ 95 void GLMoleculeObject::drawSelectionBox(QGLPainter *painter) 96 { 97 painter->setFaceMaterial(QGL::AllFaces, m_selectionBoxMaterial); 98 QVector3DArray array; 99 qreal radius = 1.0; 100 array.append(-radius, -radius, -radius); array.append( radius, -radius, -radius); 101 array.append( radius, -radius, -radius); array.append( radius, radius, -radius); 102 array.append( radius, radius, -radius); array.append(-radius, radius, -radius); 103 array.append(-radius, radius, -radius); array.append(-radius, -radius, -radius); 104 105 array.append(-radius, -radius, radius); array.append( radius, -radius, radius); 106 array.append( radius, -radius, radius); array.append( radius, radius, radius); 107 array.append( radius, radius, radius); array.append(-radius, radius, radius); 108 array.append(-radius, radius, radius); array.append(-radius, -radius, radius); 109 110 array.append(-radius, -radius, -radius); array.append(-radius, -radius, radius); 111 array.append( radius, -radius, -radius); array.append( radius, -radius, radius); 112 array.append(-radius, radius, -radius); array.append(-radius, radius, radius); 113 array.append( radius, radius, -radius); array.append( radius, radius, radius); 114 painter->clearAttributes(); 115 painter->setVertexAttribute(QGL::Position, array); 116 painter->draw(QGL::Lines, 24); 84 117 } 85 118 … … 93 126 if (m_rotationAngle != 0.0f) 94 127 painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector); 128 if (m_scaleZ != 1.0f) 129 painter->modelViewMatrix().scale(1.0f, 1.0f, m_scaleZ); 95 130 96 131 // Apply the material and effect to the painter. … … 98 133 if (m_hovering) 99 134 material = m_hoverMaterial; 135 else if (m_selected) 136 material = m_selectionMaterial; 100 137 else 101 138 material = m_material; 139 140 ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL"); 141 102 142 painter->setColor(material->diffuseColor()); 103 143 painter->setFaceMaterial(QGL::AllFaces, material); … … 113 153 114 154 // Draw the geometry mesh. 115 if (m_GLMoleculeObject) 116 m_GLMoleculeObject->draw(painter); 117 else 118 m_mesh->draw(painter); 155 m_mesh->draw(painter); 156 157 // Draw a box around the mesh, if selected. 158 if (m_selected) 159 drawSelectionBox(painter); 119 160 120 161 // Turn off the user effect, if present. … … 164 205 QGLMaterial* GLMoleculeObject::getMaterial(size_t no) 165 206 { 166 ASSERT( (no > =0) && (no < MAX_ELEMENTS),207 ASSERT( (no > 0) && (no < MAX_ELEMENTS), 167 208 "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid."); 168 209 if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){ … … 174 215 QGLMaterial *newmaterial = new QGLMaterial(NULL); 175 216 176 if (no == 0) { // create hover material 177 newmaterial->setAmbientColor( QColor(0, 128, 128) ); 178 } else { // create material for element 179 periodentafel *periode = World::getInstance().getPeriode(); 180 const element *desiredelement = periode->FindElement(no); 181 ASSERT(desiredelement != NULL, 182 "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel."); 183 const unsigned char* color = desiredelement->getColor(); 184 LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << "."); 185 newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) ); 186 } 217 // create material for element 218 periodentafel *periode = World::getInstance().getPeriode(); 219 const element *desiredelement = periode->FindElement(no); 220 ASSERT(desiredelement != NULL, 221 "GLMoleculeView::getMaterial() - desired element "+toString(no)+" not present in periodentafel."); 222 const unsigned char* color = desiredelement->getColor(); 223 LOG(1, "Creating new material with color " << (int)color[0] << "," << (int)color[1] << "," << (int)color[2] << "."); 224 newmaterial->setAmbientColor( QColor((int)color[0], (int)color[1], (int)color[2]) ); 187 225 newmaterial->setSpecularColor( QColor(60, 60, 60) ); 188 226 newmaterial->setShininess( 128 ); … … 190 228 191 229 return newmaterial; 230 } 231 } 232 233 /** Create the 3 materials shared by all objects. 234 * 235 */ 236 void GLMoleculeObject::initStaticMaterials() 237 { 238 if (!m_hoverMaterial){ 239 m_hoverMaterial = new QGLMaterial(NULL); 240 m_hoverMaterial->setAmbientColor( QColor(0, 128, 128) ); 241 m_hoverMaterial->setSpecularColor( QColor(60, 60, 60) ); 242 m_hoverMaterial->setShininess( 128 ); 243 } 244 if (!m_selectionMaterial){ 245 m_selectionMaterial = new QGLMaterial(NULL); 246 m_selectionMaterial->setAmbientColor( QColor(255, 50, 50) ); 247 m_selectionMaterial->setSpecularColor( QColor(60, 60, 60) ); 248 m_selectionMaterial->setShininess( 128 ); 249 } 250 if (!m_selectionBoxMaterial){ 251 m_selectionBoxMaterial = new QGLMaterial(NULL); 252 m_selectionBoxMaterial->setAmbientColor( QColor(0, 0, 0) ); 253 m_selectionBoxMaterial->setDiffuseColor( QColor(0, 0, 0) ); 254 m_selectionBoxMaterial->setEmittedLight( QColor(155, 50, 50) ); 192 255 } 193 256 } … … 205 268 } 206 269 } 270 271 272 void GLMoleculeObject::setSelected(bool value) 273 { 274 if (value != m_selected){ 275 m_selected = value; 276 emit selectionChanged(); 277 } 278 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp
rc0ed1e r53059e 47 47 void setScale(qreal value) { m_scale = value; } 48 48 49 qreal scaleZ() const { return m_scaleZ; } 50 void setScaleZ(qreal value) { m_scaleZ = value; } 51 49 52 qreal rotationAngle() const { return m_rotationAngle; } 50 53 void setRotationAngle(qreal value) { m_rotationAngle = value; } … … 54 57 55 58 QGLMaterial *material() const { return m_material; } 56 void setMaterial(QGLMaterial *value) 57 { m_material = value; m_hoverMaterial = value; } 58 59 QGLMaterial *hoverMaterial() const { return m_hoverMaterial; } 60 void setHoverMaterial(QGLMaterial *value) { m_hoverMaterial = value; } 59 void setMaterial(QGLMaterial *value) { m_material = value; } 61 60 62 61 QGLAbstractEffect *effect() const { return m_effect; } … … 66 65 void setObjectId(int id) { m_objectId = id; } 67 66 67 bool selected() const { return m_selected; } 68 void setSelected(bool value); 69 70 void initStaticMaterials(); 68 71 void initialize(QGLView *view, QGLPainter *painter); 69 72 void draw(QGLPainter *painter); 73 void drawSelectionBox(QGLPainter *painter); 70 74 71 75 signals: … … 75 79 void doubleClicked(); 76 80 void hoverChanged(); 81 void selectionChanged(); 82 void changed(); 77 83 78 84 protected: … … 88 94 89 95 QGLSceneNode *m_mesh; 90 QGLSceneNode *m_GLMoleculeObject;91 96 QGLAbstractScene *m_scene; 92 97 QVector3D m_position; 93 98 qreal m_scale; 99 qreal m_scaleZ; 94 100 qreal m_rotationAngle; 95 101 QVector3D m_rotationVector; 96 102 QGLMaterial *m_material; 97 QGLMaterial *m_hoverMaterial; 103 static QGLMaterial *m_hoverMaterial; 104 static QGLMaterial *m_selectionMaterial; 105 static QGLMaterial *m_selectionBoxMaterial; 98 106 QGLAbstractEffect *m_effect; 99 107 int m_objectId; 100 108 bool m_hovering; 109 bool m_selected; 101 110 }; 102 111 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
rc0ed1e r53059e 41 41 { 42 42 QGLBuilder builder; 43 builder << QGLSphere( 0.5);43 builder << QGLSphere(2.0); 44 44 QGLSceneNode *n = builder.finalizedSceneNode(); 45 45 n->setParent(parent); … … 57 57 atomref->signOn(this, AtomObservable::ElementChanged); 58 58 atomref->signOn(this, AtomObservable::BondsAdded); 59 World::getInstance().signOn(this, World::SelectionChanged); 59 60 60 61 // set the object's id … … 72 73 _atom->signOff(this, AtomObservable::ElementChanged); 73 74 _atom->signOff(this, AtomObservable::BondsAdded); 75 World::getInstance().signOff(this, World::SelectionChanged); 74 76 } 75 77 … … 104 106 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL."); 105 107 setMaterial(elementmaterial); 106 QGLMaterial *hovermaterial = getMaterial(0); // 0 is the hover material107 ASSERT(hovermaterial != NULL,108 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function for hover is NULL.");109 setHoverMaterial(hovermaterial);110 108 111 109 // set scale … … 116 114 radius = 0.5; 117 115 } 118 setScale( radius );116 setScale( radius / 4. ); 119 117 } 120 118 … … 136 134 // set the object's id 137 135 resetIndex(); 136 137 // selected? 138 setSelected(World::getInstance().isSelected(_atom)); 138 139 } 139 140 … … 143 144 void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification) 144 145 { 146 if (publisher == dynamic_cast<const Observable*>(_atom)){ 147 // notofication from atom 145 148 #ifdef LOG_OBSERVER 146 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 147 << " received notification from atom " << _atom->getId() << " for channel " 148 << notification->getChannelNo() << "."; 149 #endif 150 switch (notification->getChannelNo()) { 151 case AtomObservable::ElementChanged: 152 resetElement(); 153 break; 154 case AtomObservable::IndexChanged: 155 resetIndex(); 156 break; 157 case AtomObservable::PositionChanged: 158 resetPosition(); 159 break; 160 case AtomObservable::BondsAdded: 149 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 150 << " received notification from atom " << _atom->getId() << " for channel " 151 << notification->getChannelNo() << "."; 152 #endif 153 switch (notification->getChannelNo()) { 154 case AtomObservable::ElementChanged: 155 resetElement(); 156 emit changed(); 157 break; 158 case AtomObservable::IndexChanged: 159 resetIndex(); 160 break; 161 case AtomObservable::PositionChanged: 162 resetPosition(); 163 emit changed(); 164 break; 165 case AtomObservable::BondsAdded: 161 166 { 162 ASSERT(!_atom->getListOfBonds().empty(), 163 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty."); 164 const bond * _bond = *(_atom->getListOfBonds().rbegin()); 165 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ? 166 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 167 emit BondsInserted(_bond, side); 168 break; 169 } 170 default: 171 //setProperties(); 172 break; 167 ASSERT(!_atom->getListOfBonds().empty(), 168 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty."); 169 const bond * _bond = *(_atom->getListOfBonds().rbegin()); 170 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ? 171 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right; 172 emit BondsInserted(_bond, side); 173 break; 174 } 175 default: 176 //setProperties(); 177 break; 178 } 179 }else{ 180 // notification from world 181 #ifdef LOG_OBSERVER 182 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 183 << " received notification from world for channel " 184 << notification->getChannelNo() << "."; 185 #endif 186 switch (notification->getChannelNo()) { 187 case World::SelectionChanged: 188 setSelected(World::getInstance().isSelected(_atom)); 189 break; 190 default: 191 break; 192 } 173 193 } 174 194 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
rc0ed1e r53059e 39 39 #include "LinearAlgebra/Vector.hpp" 40 40 41 static QGLSceneNode *createBond(QObject *parent , double distance)41 static QGLSceneNode *createBond(QObject *parent) 42 42 { 43 43 QGLBuilder builder; 44 QGLCylinder cylinder(.25,.25,.25); 45 cylinder.setHeight(distance); 44 QGLCylinder cylinder(.25,.25,1.0,16); 46 45 builder << cylinder; 47 46 QGLSceneNode *n = builder.finalizedSceneNode(); … … 50 49 } 51 50 52 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, constenum SideOfBond side) :53 GLMoleculeObject(createBond(parent , distance), parent),51 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side) : 52 GLMoleculeObject(createBond(parent), parent), 54 53 Observer(std::string("GLMoleculeObject_bond") 55 54 +toString(bondref->leftatom->getId()) … … 61 60 // sign on as observer (obtain non-const instance before) 62 61 _bond->signOn(this, BondObservable::BondRemoved); 63 64 Vector Position;65 Vector OtherPosition; 62 _bond->leftatom->signOn(this, AtomObservable::PositionChanged); 63 _bond->rightatom->signOn(this, AtomObservable::PositionChanged); 64 66 65 size_t elementno = 0; 67 66 switch (BondSide) { 68 67 case left: 69 Position = _bond->leftatom->getPosition();70 OtherPosition = _bond->rightatom->getPosition();71 68 if (_bond->leftatom->getType() != NULL) { 72 69 elementno = _bond->leftatom->getType()->getAtomicNumber(); … … 76 73 break; 77 74 case right: 78 Position = _bond->rightatom->getPosition();79 OtherPosition = _bond->leftatom->getPosition();80 75 if (_bond->rightatom->getType() != NULL) { 81 76 elementno = _bond->rightatom->getType()->getAtomicNumber(); … … 93 88 QGLMaterial *elementmaterial = getMaterial(elementno); 94 89 setMaterial(elementmaterial); 90 91 resetPosition(); 92 } 93 94 GLMoleculeObject_bond::~GLMoleculeObject_bond() 95 { 96 // sign on as observer (obtain non-const instance before) 97 _bond->signOff(this, BondObservable::BondRemoved); 98 _bond->leftatom->signOff(this, AtomObservable::PositionChanged); 99 _bond->rightatom->signOff(this, AtomObservable::PositionChanged); 100 101 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << "."); 102 } 103 104 void GLMoleculeObject_bond::update(Observable *publisher) 105 { 106 #ifdef LOG_OBSERVER 107 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << "."; 108 #endif 109 } 110 111 void GLMoleculeObject_bond::subjectKilled(Observable *publisher) 112 { 113 LOG(2, "INFO: Received subjectKilled from " << *_bond << "."); 114 switch (BondSide) { 115 case left: 116 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId()); 117 break; 118 case right: 119 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId()); 120 break; 121 default: 122 ASSERT(0, 123 "GLMoleculeObject_bond::subjectKilled() - side is not a valid argument: "+toString(BondSide)+"."); 124 break; 125 } 126 delete this; 127 } 128 129 void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification) 130 { 131 #ifdef LOG_OBSERVER 132 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 133 << " received notification from bond " << *_bond << " for channel " 134 << notification->getChannelNo() << "."; 135 #endif 136 if (publisher == dynamic_cast<const Observable*>(_bond)){ 137 // from the bond 138 switch (notification->getChannelNo()) { 139 case BondObservable::BondRemoved: 140 LOG(2, "INFO: Received notification of BondRemoved from " << *_bond << "."); 141 switch (BondSide) { 142 case left: 143 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId()); 144 break; 145 case right: 146 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId()); 147 break; 148 default: 149 ASSERT(0, 150 "GLMoleculeObject_bond::recieveNotification() - side is not a valid argument: "+toString(BondSide)+"."); 151 break; 152 } 153 delete this; 154 break; 155 default: 156 break; 157 } 158 }else{ 159 // from an atom 160 switch (notification->getChannelNo()) { 161 case AtomObservable::PositionChanged: 162 LOG(2, "INFO: Received notification of PositionChanged."); 163 resetPosition(); 164 emit changed(); 165 } 166 } 167 } 168 169 void GLMoleculeObject_bond::resetPosition() 170 { 171 Vector Position; 172 Vector OtherPosition; 173 switch (BondSide) { 174 case left: 175 Position = _bond->leftatom->getPosition(); 176 OtherPosition = _bond->rightatom->getPosition(); 177 break; 178 case right: 179 Position = _bond->rightatom->getPosition(); 180 OtherPosition = _bond->leftatom->getPosition(); 181 break; 182 default: 183 ASSERT(0, 184 "GLMoleculeObject_bond::resetPosition() - side is not a valid argument: "+toString(BondSide)+"."); 185 break; 186 } 187 const double distance = 188 Position.distance(OtherPosition)/2.; 189 setScaleZ(distance); 95 190 96 191 // calculate position … … 123 218 setRotationAngle(alpha/M_PI*180.); 124 219 } 125 126 GLMoleculeObject_bond::~GLMoleculeObject_bond()127 {128 // sign on as observer (obtain non-const instance before)129 _bond->signOff(this, BondObservable::BondRemoved);130 131 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << ".");132 }133 134 void GLMoleculeObject_bond::update(Observable *publisher)135 {136 #ifdef LOG_OBSERVER137 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << ".";138 #endif139 }140 141 void GLMoleculeObject_bond::subjectKilled(Observable *publisher)142 {143 LOG(2, "INFO: Received subjectKilled from " << *_bond << ".");144 switch (BondSide) {145 case left:146 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());147 break;148 case right:149 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());150 break;151 default:152 ASSERT(0,153 "GLMoleculeObject_bond::subjectKilled() - side is not a valid argument: "+toString(BondSide)+".");154 break;155 }156 delete this;157 }158 159 void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification)160 {161 #ifdef LOG_OBSERVER162 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)163 << " received notification from bond " << *_bond << " for channel "164 << notification->getChannelNo() << ".";165 #endif166 switch (notification->getChannelNo()) {167 case BondObservable::BondRemoved:168 LOG(2, "INFO: Received notification of BondRemoved from " << *_bond << ".");169 switch (BondSide) {170 case left:171 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());172 break;173 case right:174 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());175 break;176 default:177 ASSERT(0,178 "GLMoleculeObject_bond::recieveNotification() - side is not a valid argument: "+toString(BondSide)+".");179 break;180 }181 delete this;182 break;183 default:184 break;185 }186 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
rc0ed1e r53059e 28 28 enum SideOfBond { left, right }; 29 29 30 GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, constenum SideOfBond side);30 GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side); 31 31 virtual ~GLMoleculeObject_bond(); 32 32 … … 40 40 41 41 private: 42 void resetPosition(); 42 43 const bond *_bond; 43 44 const enum SideOfBond BondSide; -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
rc0ed1e r53059e 25 25 #include "GLMoleculeObject_atom.hpp" 26 26 #include "GLMoleculeObject_bond.hpp" 27 #include "GLMoleculeObject_molecule.hpp" 27 28 28 29 #include "CodePatterns/MemDebug.hpp" … … 74 75 Runner != molecules.end(); 75 76 Runner++) { 76 // create molecule 77 77 78 for (molecule::const_iterator atomiter = (*Runner)->begin(); 78 79 atomiter != (*Runner)->end(); … … 109 110 AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) ); 110 111 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 112 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed())); 111 113 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed())); 114 connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 112 115 connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond))); 113 116 //bondsChanged(_atom); … … 134 137 } 135 138 139 /** .... 140 * 141 */ 142 void GLWorldScene::worldSelectionChanged() 143 { 144 LOG(3, "INFO: GLWorldScene: Received signal selectionChanged."); 145 146 const std::vector<molecule*> &molecules = World::getInstance().getAllMolecules(); 147 148 if (molecules.size() > 0) { 149 for (std::vector<molecule*>::const_iterator Runner = molecules.begin(); 150 Runner != molecules.end(); 151 Runner++) { 152 153 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find((*Runner)->getId()); 154 bool isSelected = World::getInstance().isSelected(*Runner); 155 156 // molecule selected but not in scene? 157 if (isSelected && (iter == MoleculesinSceneMap.end())){ 158 // -> create new mesh 159 GLMoleculeObject_molecule *molObject = new GLMoleculeObject_molecule(this, *Runner); 160 MoleculesinSceneMap.insert( make_pair((*Runner)->getId(), molObject) ); 161 connect (molObject, SIGNAL(changed()), this, SIGNAL(changed())); 162 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 163 connect (molObject, SIGNAL(selectionChanged()), this, SIGNAL(changed())); 164 emit changed(); 165 emit changeOccured(); 166 } 167 168 // molecule not selected but in scene? 169 if (!isSelected && (iter != MoleculesinSceneMap.end())){ 170 // -> remove from scene 171 moleculeRemoved(*Runner); 172 } 173 174 } 175 } 176 } 177 178 /** Removes a molecule from the scene. 179 * 180 * @param _molecule molecule to remove 181 */ 182 void GLWorldScene::moleculeRemoved(const molecule *_molecule) 183 { 184 LOG(3, "INFO: GLWorldScene: Received signal moleculeRemoved for molecule "+toString(_molecule->getId())+"."); 185 MoleculeNodeMap::iterator iter = MoleculesinSceneMap.find(_molecule->getId()); 186 187 // only remove if the molecule is in the scene 188 // (= is selected) 189 if (iter != MoleculesinSceneMap.end()){ 190 GLMoleculeObject_molecule *molObject = iter->second; 191 molObject->disconnect(); 192 MoleculesinSceneMap.erase(iter); 193 delete molObject; 194 emit changed(); 195 emit changeOccured(); 196 } 197 } 198 136 199 /** Adds a bond to the scene. 137 200 * … … 143 206 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+"."); 144 207 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << "."); 145 const double distance =146 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;147 208 148 209 BondIds ids; … … 161 222 #endif 162 223 GLMoleculeObject_bond *bondObject = 163 new GLMoleculeObject_bond(this, _bond, distance,side);224 new GLMoleculeObject_bond(this, _bond, side); 164 225 connect ( 165 226 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)), 166 227 this, SLOT(bondRemoved(const atomId_t, const atomId_t))); 228 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed())); 167 229 BondsinSceneMap.insert( make_pair(ids, bondObject) ); 168 230 // BondIdsinSceneMap.insert( Leftids ); -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
rc0ed1e r53059e 23 23 24 24 #include "GLMoleculeObject_bond.hpp" 25 #include "GLMoleculeObject_molecule.hpp" 25 26 26 27 class atom; 28 class molecule; 27 29 28 30 class QGLPainter; … … 32 34 class GLMoleculeObject; 33 35 class GLMoleculeObject_atom; 36 class GLMoleculeObject_molecule; 34 37 35 38 /** This class contains a list of all molecules in the world. … … 49 52 void changeMaterials(bool perPixel); 50 53 QGLSceneNode* getAtom(size_t); 54 QGLSceneNode* getMolecule(size_t); 51 55 QGLSceneNode* getBond(size_t, size_t); 52 56 … … 68 72 void atomInserted(const atom *_atom); 69 73 void atomRemoved(const atom *_atom); 74 void moleculeRemoved(const molecule *_molecule); 75 void worldSelectionChanged(); 70 76 void bondInserted(const bond *_bond, const GLMoleculeObject_bond::SideOfBond side); 71 77 void bondRemoved(const atomId_t leftnr, const atomId_t rightnr); … … 80 86 typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap; 81 87 typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap; 88 typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap; 82 89 AtomNodeMap AtomsinSceneMap; 83 90 BondNodeMap BondsinSceneMap; 91 MoleculeNodeMap MoleculesinSceneMap; 84 92 }; 85 93 -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp
rc0ed1e r53059e 26 26 #include "CodePatterns/MemDebug.hpp" 27 27 28 #include "Atom/AtomObserver.hpp" 29 #include "Atom/atom_observable.hpp" 28 30 #include "CodePatterns/Log.hpp" 29 31 #include "CodePatterns/Observer/Notification.hpp" … … 42 44 connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *))); 43 45 connect(this, SIGNAL(atomRemoved(const atom *)), worldscene, SLOT(atomRemoved(const atom *))); 46 connect(this, SIGNAL(worldSelectionChanged()), worldscene, SLOT(worldSelectionChanged())); 47 connect(this, SIGNAL(moleculeRemoved(const molecule *)), worldscene, SLOT(moleculeRemoved(const molecule *))); 44 48 connect(this, SIGNAL(changed()), this, SLOT(updateGL())); 45 49 … … 48 52 World::getInstance().signOn(this, World::AtomInserted); 49 53 World::getInstance().signOn(this, World::AtomRemoved); 54 World::getInstance().signOn(this, World::MoleculeInserted); 55 World::getInstance().signOn(this, World::MoleculeRemoved); 56 World::getInstance().signOn(this, World::SelectionChanged); 57 AtomObserver::getInstance().signOn(this, AtomObservable::PositionChanged); 50 58 } 51 59 … … 55 63 World::getInstance().signOff(this, World::AtomInserted); 56 64 World::getInstance().signOff(this, World::AtomRemoved); 65 World::getInstance().signOff(this, World::MoleculeInserted); 66 World::getInstance().signOff(this, World::MoleculeRemoved); 67 World::getInstance().signOff(this, World::SelectionChanged); 68 AtomObserver::getInstance().signOff(this, AtomObservable::PositionChanged); 57 69 delete worldscene; 58 70 } … … 79 91 void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification) 80 92 { 81 switch (notification->getChannelNo()) { 82 case World::AtomInserted: 83 { 84 const atom *_atom = World::getInstance().lastChanged<atom>(); 85 #ifdef LOG_OBSERVER 86 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been inserted."; 87 #endif 88 emit atomInserted(_atom); 89 break; 93 if (static_cast<World *>(publisher) == World::getPointer()) { 94 switch (notification->getChannelNo()) { 95 case World::AtomInserted: 96 { 97 const atom *_atom = World::getInstance().lastChanged<atom>(); 98 #ifdef LOG_OBSERVER 99 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been inserted."; 100 #endif 101 emit atomInserted(_atom); 102 break; 103 } 104 case World::AtomRemoved: 105 { 106 const atom *_atom = World::getInstance().lastChanged<atom>(); 107 #ifdef LOG_OBSERVER 108 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been removed."; 109 #endif 110 emit atomRemoved(_atom); 111 break; 112 } 113 case World::SelectionChanged: 114 { 115 #ifdef LOG_OBSERVER 116 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that selection has changed."; 117 #endif 118 emit worldSelectionChanged(); 119 break; 120 } 121 case World::MoleculeInserted: 122 { 123 const molecule *_molecule = World::getInstance().lastChanged<molecule>(); 124 #ifdef LOG_OBSERVER 125 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed."; 126 #endif 127 emit moleculeInserted(_molecule); 128 break; 129 } 130 case World::MoleculeRemoved: 131 { 132 const molecule *_molecule = World::getInstance().lastChanged<molecule>(); 133 #ifdef LOG_OBSERVER 134 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that molecule "+toString(_molecule->getId())+" has been removed."; 135 #endif 136 emit moleculeRemoved(_molecule); 137 break; 138 } 139 default: 140 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here."); 141 break; 90 142 } 91 case World::AtomRemoved: 92 { 93 const atom *_atom = World::getInstance().lastChanged<atom>(); 94 #ifdef LOG_OBSERVER 95 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has been removed."; 96 #endif 97 emit atomRemoved(_atom); 98 break; 143 } else if (dynamic_cast<AtomObservable *>(publisher) != NULL) { 144 switch (notification->getChannelNo()) { 145 case AtomObservable::PositionChanged: 146 { 147 const atom *_atom = dynamic_cast<const atom *>(publisher); 148 #ifdef LOG_OBSERVER 149 observerLog().addMessage() << "++ Observer " << observerLog().getName(this) << " received notification that atom "+toString(_atom->getId())+" has changed its position."; 150 #endif 151 emit changed(); 152 break; 153 } 154 default: 155 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here."); 156 break; 99 157 } 100 default: 101 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here."); 102 break; 103 } 158 } else 159 ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source."); 104 160 } 105 161 -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp
rc0ed1e r53059e 47 47 void atomInserted(const atom *_atom); 48 48 void atomRemoved(const atom *_atom); 49 void moleculeInserted(const molecule *_molecule); 50 void moleculeRemoved(const molecule *_molecule); 51 void worldSelectionChanged(); 49 52 50 53 protected: … … 57 60 58 61 bool changesPresent; 62 bool processingSelectionChanged; // workaround to prevent a loop in (atom_iterator <-> observer) 59 63 }; 60 64
Note:
See TracChangeset
for help on using the changeset viewer.