Changes in / [53059e:c0ed1e]
- Location:
- src
- Files:
-
- 4 deleted
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Element/element.hpp
r53059e rc0ed1e 90 90 double CovalentRadius; //!< covalent radius 91 91 double Electronegativity; //!< electronegativity in Pauling units 92 double VanDerWaalsRadius; //!< van-der-Waals radius92 double VanDerWaalsRadius; //!< can-der-Waals radius 93 93 atomicNumber_t Z; //!< atomic number 94 94 std::string period; //!< period: n quantum number -
src/UIElements/Makefile.am
r53059e rc0ed1e 199 199 UIElements/Views/Qt4/QtWorldView.cpp \ 200 200 UIElements/Views/Qt4/QtMoleculeView.cpp \ 201 UIElements/Views/Qt4/QtElementList.cpp \202 201 UIElements/Views/Qt4/QtStatusBar.cpp \ 203 202 UIElements/Views/Qt4/Qt3D/GLWorldView.cpp \ … … 205 204 UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp \ 206 205 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp \ 207 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp \ 208 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp 206 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp 209 207 # UIElements/Views/Qt4/dialoglight.cpp 210 208 … … 232 230 UIElements/Views/Qt4/QtWorldView.hpp \ 233 231 UIElements/Views/Qt4/QtMoleculeView.hpp \ 234 UIElements/Views/Qt4/QtElementList.hpp \235 232 UIElements/Views/Qt4/QtStatusBar.hpp \ 236 233 UIElements/Views/Qt4/Qt3D/GLWorldView.hpp \ … … 238 235 UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp \ 239 236 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp \ 240 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp \ 241 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp 237 UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp 242 238 243 239 QTUIUI_UIFILES = \ -
src/UIElements/Qt4/Pipe/BooleanQtQueryPipe.cpp
r53059e rc0ed1e 25 25 #include "CodePatterns/MemDebug.hpp" 26 26 27 BooleanQtQueryPipe::BooleanQtQueryPipe( bool *_content, QtDialog *_dialog, QCheckBox *_booleanCheckBox) :27 BooleanQtQueryPipe::BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox) : 28 28 content(_content), 29 29 dialog(_dialog), 30 booleanC heckBox(_booleanCheckBox)30 booleanComboBox(_booleanComboBox) 31 31 {} 32 32 … … 34 34 {} 35 35 36 void BooleanQtQueryPipe::update(int state) { 37 (*content) = (state == Qt::Checked); 36 void BooleanQtQueryPipe::update() { 38 37 dialog->update(); 39 38 } -
src/UIElements/Qt4/Pipe/BooleanQtQueryPipe.hpp
r53059e rc0ed1e 18 18 19 19 class QtDialog; 20 class QC heckBox;20 class QComboBox; 21 21 22 22 class BooleanQtQueryPipe : public QWidget { 23 23 Q_OBJECT 24 24 public: 25 BooleanQtQueryPipe( bool *_content, QtDialog *_dialog, QCheckBox *_booleanCheckBox);25 BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox); 26 26 virtual ~BooleanQtQueryPipe(); 27 27 28 28 public slots: 29 void update( int state);29 void update(); 30 30 31 31 private: 32 bool *content;32 const bool *content; 33 33 QtDialog *dialog; 34 QC heckBox *booleanCheckBox;34 QComboBox *booleanComboBox; 35 35 }; 36 36 -
src/UIElements/Qt4/Pipe/BoxQtQueryPipe.cpp
r53059e rc0ed1e 34 34 { 35 35 tmpM = new RealSpaceMatrix(); 36 tmpM->set Identity();36 tmpM->setZero(); 37 37 } 38 38 -
src/UIElements/Qt4/Pipe/VectorQtQueryPipe.cpp
r53059e rc0ed1e 35 35 {} 36 36 37 void VectorQtQueryPipe::updateX(double newDouble) { 38 (*content)[0] = newDouble; 37 void VectorQtQueryPipe::update() { 39 38 dialog->update(); 40 39 } 41 40 42 void VectorQtQueryPipe::updateY(double newDouble) {43 (*content)[1] = newDouble;44 dialog->update();45 }46 47 void VectorQtQueryPipe::updateZ(double newDouble) {48 (*content)[2] = newDouble;49 dialog->update();50 }51 -
src/UIElements/Qt4/Pipe/VectorQtQueryPipe.hpp
r53059e rc0ed1e 29 29 30 30 public slots: 31 void updateX(double); 32 void updateY(double); 33 void updateZ(double); 31 void update(); 34 32 35 33 private: -
src/UIElements/Qt4/QtMainWindow.cpp
r53059e rc0ed1e 33 33 #include "Menu/Qt4/QtMenu.hpp" 34 34 #include "Views/Qt4/QtWorldView.hpp" 35 #include "Views/Qt4/QtElementList.hpp"36 35 #include "Views/Qt4/QtMoleculeView.hpp" 37 36 #include "Views/Qt4/QtStatusBar.hpp" … … 52 51 QSplitter *splitter1 = new QSplitter (Qt::Horizontal, this ); 53 52 QSplitter *splitter2 = new QSplitter (Qt::Vertical, splitter1 ); 54 QTabWidget *worldTab = new QTabWidget(splitter2);55 53 56 worldDisplay = new QtWorldView(worldTab); 57 elementList = new QtElementList(worldTab); 54 worldDisplay = new QtWorldView(splitter2); 58 55 59 56 moleculeDisplay = new QtMoleculeView(); … … 71 68 splitter1->addWidget(moleculeDisplay); 72 69 splitter2->addWidget(molecule3dDisplay); 73 splitter2->addWidget(worldTab); 74 worldTab->addTab(worldDisplay, "Molecules"); 75 worldTab->addTab(elementList, "All Elements"); 70 splitter2->addWidget(worldDisplay); 76 71 77 72 statusBar = new QtStatusBar(this); -
src/UIElements/Qt4/QtMainWindow.hpp
r53059e rc0ed1e 24 24 25 25 class QtWorldView; 26 class QtElementList;27 26 class StringView; 28 27 class GLWorldView; … … 45 44 QApplication *theApp; 46 45 QtWorldView *worldDisplay; 47 QtElementList *elementList;48 46 GLWorldView *molecule3dDisplay; 49 47 QtMoleculeView *moleculeDisplay; -
src/UIElements/Qt4/Query/BooleanQtQuery.cpp
r53059e rc0ed1e 19 19 20 20 #include <Qt/qboxlayout.h> 21 #include <Qt/qc heckbox.h>21 #include <Qt/qcombobox.h> 22 22 #include <Qt/qlabel.h> 23 23 … … 32 32 parent(_parent) 33 33 { 34 thisLayout = new QHBoxLayout();35 34 titleLabel = new QLabel(QString(getTitle().c_str()),_dialog); 36 booleanCheckBox = new QCheckBox(QString(getTitle().c_str()), _dialog); 35 booleanComboBox = new QComboBox(_dialog); 36 booleanComboBox->insertItem(1, QString("true")); 37 booleanComboBox->insertItem(0, QString("false")); 37 38 38 39 parent->addLayout(thisLayout); 39 40 thisLayout->addWidget(titleLabel); 40 thisLayout->addWidget(booleanC heckBox);41 thisLayout->addWidget(booleanComboBox); 41 42 42 pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanC heckBox);43 connect(booleanC heckBox, SIGNAL(stateChanged(int)), pipe, SLOT(update(int)));43 pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanComboBox); 44 connect(booleanComboBox, SIGNAL(currentIndexChanged()), pipe, SLOT(update())); 44 45 } 45 46 -
src/UIElements/Qt4/Query/QtQuery.hpp
r53059e rc0ed1e 29 29 class QTextEdit; 30 30 class QComboBox; 31 class QCheckBox;32 31 33 32 // Forward declarations for plumbing … … 92 91 QBoxLayout *thisLayout; 93 92 QLabel *titleLabel; 94 QC heckBox *booleanCheckBox;93 QComboBox *booleanComboBox; 95 94 96 95 BooleanQtQueryPipe *pipe; … … 326 325 QBoxLayout *coordLayout; 327 326 QLabel *coordLabel; 328 QDoubleSpinBox *coordInputX; 329 QDoubleSpinBox *coordInputY; 330 QDoubleSpinBox *coordInputZ; 327 QDoubleSpinBox *coordInput; 331 328 332 329 VectorQtQueryPipe *pipe; -
src/UIElements/Qt4/Query/VectorQtQuery.cpp
r53059e rc0ed1e 43 43 coordLabel = new QLabel(QString("x,y,z")); 44 44 coordLayout->addWidget(coordLabel); 45 coordInputX = new QDoubleSpinBox(); 46 coordInputX->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 47 // coordInputX->setRange(0,M.at(i,i)); 48 coordInputX->setDecimals(3); 49 coordLayout->addWidget(coordInputX); 50 coordInputY = new QDoubleSpinBox(); 51 coordInputY->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 52 // coordInputY->setRange(0,M.at(i,i)); 53 coordInputY->setDecimals(3); 54 coordLayout->addWidget(coordInputY); 55 coordInputZ = new QDoubleSpinBox(); 56 coordInputZ->setRange(-std::numeric_limits<double>::max(),std::numeric_limits<double>::max()); 57 // coordInputZ->setRange(0,M.at(i,i)); 58 coordInputZ->setDecimals(3); 59 coordLayout->addWidget(coordInputZ); 45 coordInput = new QDoubleSpinBox(); 46 // coordInput->setRange(0,M.at(i,i)); 47 coordInput->setDecimals(3); 48 coordLayout->addWidget(coordInput); 60 49 pipe = new VectorQtQueryPipe(&(tmp),_dialog,inputBox); 61 50 //pipe->update(coordInput->value()); 62 connect(coordInputX,SIGNAL(valueChanged(double)),pipe,SLOT(updateX(double))); 63 connect(coordInputY,SIGNAL(valueChanged(double)),pipe,SLOT(updateY(double))); 64 connect(coordInputZ,SIGNAL(valueChanged(double)),pipe,SLOT(updateZ(double))); 51 connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double))); 65 52 parent->addLayout(mainLayout); 66 53 } -
src/UIElements/Query/BooleanQuery.cpp
r53059e rc0ed1e 25 25 // Bool Queries 26 26 Dialog::BooleanQuery::BooleanQuery(std::string title,std::string description) : 27 Query(title, description), 28 tmp(false) 27 Query(title, description) 29 28 {} 30 29 -
src/UIElements/Query/DoubleQuery.cpp
r53059e rc0ed1e 25 25 // Double Queries 26 26 Dialog::DoubleQuery::DoubleQuery(std::string title, std::string _description) : 27 Query(title, _description), 28 tmp(0) 27 Query(title, _description) 29 28 {} 30 29 -
src/UIElements/Query/IntQuery.cpp
r53059e rc0ed1e 25 25 // Int Queries 26 26 Dialog::IntQuery::IntQuery(std::string title, std::string description) : 27 Query(title, description), 28 tmp(0) 27 Query(title, description) 29 28 {} 30 29 -
src/UIElements/Query/UnsignedIntQuery.cpp
r53059e rc0ed1e 25 25 // UnsignedInt Queries 26 26 Dialog::UnsignedIntQuery::UnsignedIntQuery(std::string title, std::string description) : 27 Query(title, description), 28 tmp(0) 27 Query(title, description) 29 28 {} 30 29 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
r53059e rc0ed1e 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 48 44 49 45 GLMoleculeObject::GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent) 50 46 : QObject(parent) 51 47 { 52 m_mesh = GLMoleculeObject; 48 m_mesh = 0; 49 m_GLMoleculeObject = GLMoleculeObject; 53 50 m_scale = 1.0f; 54 m_scaleZ = 1.0f;55 51 m_rotationAngle = 0.0f; 56 52 m_effect = 0; 57 53 m_objectId = -1; 58 54 m_hovering = false; 59 m_selected = false;60 55 m_material = 0; 61 initStaticMaterials();56 m_hoverMaterial = 0; 62 57 } 63 58 … … 66 61 { 67 62 scene->setParent(this); 68 m_mesh = scene->mainNode(); 63 m_mesh = 0; 64 m_GLMoleculeObject = scene->mainNode(); 69 65 m_scale = 1.0f; 70 m_scaleZ = 1.0f;71 66 m_rotationAngle = 0.0f; 72 67 m_effect = 0; 73 68 m_objectId = -1; 74 69 m_hovering = false; 75 m_selected = false;76 70 m_material = 0; 77 initStaticMaterials();71 m_hoverMaterial = 0; 78 72 } 79 73 80 74 GLMoleculeObject::~GLMoleculeObject() 81 75 { 76 delete m_mesh; 82 77 } 83 78 … … 87 82 if (m_objectId != -1) 88 83 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);117 84 } 118 85 … … 126 93 if (m_rotationAngle != 0.0f) 127 94 painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector); 128 if (m_scaleZ != 1.0f)129 painter->modelViewMatrix().scale(1.0f, 1.0f, m_scaleZ);130 95 131 96 // Apply the material and effect to the painter. … … 133 98 if (m_hovering) 134 99 material = m_hoverMaterial; 135 else if (m_selected)136 material = m_selectionMaterial;137 100 else 138 101 material = m_material; 139 140 ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");141 142 102 painter->setColor(material->diffuseColor()); 143 103 painter->setFaceMaterial(QGL::AllFaces, material); … … 153 113 154 114 // Draw the geometry mesh. 155 m_mesh->draw(painter); 156 157 // Draw a box around the mesh, if selected. 158 if (m_selected) 159 drawSelectionBox(painter); 115 if (m_GLMoleculeObject) 116 m_GLMoleculeObject->draw(painter); 117 else 118 m_mesh->draw(painter); 160 119 161 120 // Turn off the user effect, if present. … … 205 164 QGLMaterial* GLMoleculeObject::getMaterial(size_t no) 206 165 { 207 ASSERT( (no > 0) && (no < MAX_ELEMENTS),166 ASSERT( (no >= 0) && (no < MAX_ELEMENTS), 208 167 "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid."); 209 168 if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){ … … 215 174 QGLMaterial *newmaterial = new QGLMaterial(NULL); 216 175 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]) ); 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 } 225 187 newmaterial->setSpecularColor( QColor(60, 60, 60) ); 226 188 newmaterial->setShininess( 128 ); … … 228 190 229 191 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) );255 192 } 256 193 } … … 268 205 } 269 206 } 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
r53059e rc0ed1e 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 52 49 qreal rotationAngle() const { return m_rotationAngle; } 53 50 void setRotationAngle(qreal value) { m_rotationAngle = value; } … … 57 54 58 55 QGLMaterial *material() const { return m_material; } 59 void setMaterial(QGLMaterial *value) { m_material = value; } 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; } 60 61 61 62 QGLAbstractEffect *effect() const { return m_effect; } … … 65 66 void setObjectId(int id) { m_objectId = id; } 66 67 67 bool selected() const { return m_selected; }68 void setSelected(bool value);69 70 void initStaticMaterials();71 68 void initialize(QGLView *view, QGLPainter *painter); 72 69 void draw(QGLPainter *painter); 73 void drawSelectionBox(QGLPainter *painter);74 70 75 71 signals: … … 79 75 void doubleClicked(); 80 76 void hoverChanged(); 81 void selectionChanged();82 void changed();83 77 84 78 protected: … … 94 88 95 89 QGLSceneNode *m_mesh; 90 QGLSceneNode *m_GLMoleculeObject; 96 91 QGLAbstractScene *m_scene; 97 92 QVector3D m_position; 98 93 qreal m_scale; 99 qreal m_scaleZ;100 94 qreal m_rotationAngle; 101 95 QVector3D m_rotationVector; 102 96 QGLMaterial *m_material; 103 static QGLMaterial *m_hoverMaterial; 104 static QGLMaterial *m_selectionMaterial; 105 static QGLMaterial *m_selectionBoxMaterial; 97 QGLMaterial *m_hoverMaterial; 106 98 QGLAbstractEffect *m_effect; 107 99 int m_objectId; 108 100 bool m_hovering; 109 bool m_selected;110 101 }; 111 102 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp
r53059e rc0ed1e 41 41 { 42 42 QGLBuilder builder; 43 builder << QGLSphere( 2.0);43 builder << QGLSphere(0.5); 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);60 59 61 60 // set the object's id … … 73 72 _atom->signOff(this, AtomObservable::ElementChanged); 74 73 _atom->signOff(this, AtomObservable::BondsAdded); 75 World::getInstance().signOff(this, World::SelectionChanged);76 74 } 77 75 … … 106 104 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL."); 107 105 setMaterial(elementmaterial); 106 QGLMaterial *hovermaterial = getMaterial(0); // 0 is the hover material 107 ASSERT(hovermaterial != NULL, 108 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function for hover is NULL."); 109 setHoverMaterial(hovermaterial); 108 110 109 111 // set scale … … 114 116 radius = 0.5; 115 117 } 116 setScale( radius / 4.);118 setScale( radius ); 117 119 } 118 120 … … 134 136 // set the object's id 135 137 resetIndex(); 136 137 // selected?138 setSelected(World::getInstance().isSelected(_atom));139 138 } 140 139 … … 144 143 void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification) 145 144 { 146 if (publisher == dynamic_cast<const Observable*>(_atom)){147 // notofication from atom148 145 #ifdef LOG_OBSERVER 149 150 151 146 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this) 147 << " received notification from atom " << _atom->getId() << " for channel " 148 << notification->getChannelNo() << "."; 152 149 #endif 153 switch (notification->getChannelNo()) { 154 case AtomObservable::ElementChanged: 155 resetElement(); 156 emit changed(); 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: 161 { 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); 157 168 break; 158 case AtomObservable::IndexChanged: 159 resetIndex(); 160 break; 161 case AtomObservable::PositionChanged: 162 resetPosition(); 163 emit changed(); 164 break; 165 case AtomObservable::BondsAdded: 166 { 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 } 169 } 170 default: 171 //setProperties(); 172 break; 193 173 } 194 174 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
r53059e rc0ed1e 39 39 #include "LinearAlgebra/Vector.hpp" 40 40 41 static QGLSceneNode *createBond(QObject *parent )41 static QGLSceneNode *createBond(QObject *parent, double distance) 42 42 { 43 43 QGLBuilder builder; 44 QGLCylinder cylinder(.25,.25,1.0,16); 44 QGLCylinder cylinder(.25,.25,.25); 45 cylinder.setHeight(distance); 45 46 builder << cylinder; 46 47 QGLSceneNode *n = builder.finalizedSceneNode(); … … 49 50 } 50 51 51 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side) :52 GLMoleculeObject(createBond(parent ), parent),52 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side) : 53 GLMoleculeObject(createBond(parent, distance), parent), 53 54 Observer(std::string("GLMoleculeObject_bond") 54 55 +toString(bondref->leftatom->getId()) … … 60 61 // sign on as observer (obtain non-const instance before) 61 62 _bond->signOn(this, BondObservable::BondRemoved); 62 _bond->leftatom->signOn(this, AtomObservable::PositionChanged);63 _bond->rightatom->signOn(this, AtomObservable::PositionChanged);64 63 64 Vector Position; 65 Vector OtherPosition; 65 66 size_t elementno = 0; 66 67 switch (BondSide) { 67 68 case left: 69 Position = _bond->leftatom->getPosition(); 70 OtherPosition = _bond->rightatom->getPosition(); 68 71 if (_bond->leftatom->getType() != NULL) { 69 72 elementno = _bond->leftatom->getType()->getAtomicNumber(); … … 73 76 break; 74 77 case right: 78 Position = _bond->rightatom->getPosition(); 79 OtherPosition = _bond->leftatom->getPosition(); 75 80 if (_bond->rightatom->getType() != NULL) { 76 81 elementno = _bond->rightatom->getType()->getAtomicNumber(); … … 89 94 setMaterial(elementmaterial); 90 95 91 resetPosition(); 96 // calculate position 97 Vector Z(0.,0.,1.); 98 Vector zeroVec(0.,0.,0.); 99 Vector a,b; 100 Vector OtherAxis; 101 double alpha; 102 a = Position - OtherPosition; 103 // construct rotation axis 104 b = a; 105 b.VectorProduct(Z); 106 Line axis(zeroVec, b); 107 // calculate rotation angle 108 alpha = a.Angle(Z); 109 // construct other axis to check right-hand rule 110 OtherAxis = b; 111 OtherAxis.VectorProduct(Z); 112 // assure right-hand rule for the rotation 113 if (a.ScalarProduct(OtherAxis) < MYEPSILON) 114 alpha = M_PI-alpha; 115 // check 116 Vector a_rotated = axis.rotateVector(a, alpha); 117 LOG(3, "INFO: Created cylinder from "// << Position << " to " << OtherPosition 118 << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively."); 119 120 // set position 121 setPosition(QVector3D(Position[0], Position[1], Position[2])); 122 setRotationVector(QVector3D(b[0], b[1], b[2])); 123 setRotationAngle(alpha/M_PI*180.); 92 124 } 93 125 … … 96 128 // sign on as observer (obtain non-const instance before) 97 129 _bond->signOff(this, BondObservable::BondRemoved); 98 _bond->leftatom->signOff(this, AtomObservable::PositionChanged);99 _bond->rightatom->signOff(this, AtomObservable::PositionChanged);100 130 101 131 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << "."); … … 134 164 << notification->getChannelNo() << "."; 135 165 #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 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; 166 185 } 167 186 } 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);190 191 // calculate position192 Vector Z(0.,0.,1.);193 Vector zeroVec(0.,0.,0.);194 Vector a,b;195 Vector OtherAxis;196 double alpha;197 a = Position - OtherPosition;198 // construct rotation axis199 b = a;200 b.VectorProduct(Z);201 Line axis(zeroVec, b);202 // calculate rotation angle203 alpha = a.Angle(Z);204 // construct other axis to check right-hand rule205 OtherAxis = b;206 OtherAxis.VectorProduct(Z);207 // assure right-hand rule for the rotation208 if (a.ScalarProduct(OtherAxis) < MYEPSILON)209 alpha = M_PI-alpha;210 // check211 Vector a_rotated = axis.rotateVector(a, alpha);212 LOG(3, "INFO: Created cylinder from "// << Position << " to " << OtherPosition213 << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively.");214 215 // set position216 setPosition(QVector3D(Position[0], Position[1], Position[2]));217 setRotationVector(QVector3D(b[0], b[1], b[2]));218 setRotationAngle(alpha/M_PI*180.);219 } -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
r53059e rc0ed1e 28 28 enum SideOfBond { left, right }; 29 29 30 GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side);30 GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side); 31 31 virtual ~GLMoleculeObject_bond(); 32 32 … … 40 40 41 41 private: 42 void resetPosition();43 42 const bond *_bond; 44 43 const enum SideOfBond BondSide; -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp
r53059e rc0ed1e 25 25 #include "GLMoleculeObject_atom.hpp" 26 26 #include "GLMoleculeObject_bond.hpp" 27 #include "GLMoleculeObject_molecule.hpp"28 27 29 28 #include "CodePatterns/MemDebug.hpp" … … 75 74 Runner != molecules.end(); 76 75 Runner++) { 77 76 // create molecule 78 77 for (molecule::const_iterator atomiter = (*Runner)->begin(); 79 78 atomiter != (*Runner)->end(); … … 110 109 AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) ); 111 110 connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t))); 112 connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));113 111 connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed())); 114 connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));115 112 connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond))); 116 113 //bondsChanged(_atom); … … 137 134 } 138 135 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 mesh159 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 scene171 moleculeRemoved(*Runner);172 }173 174 }175 }176 }177 178 /** Removes a molecule from the scene.179 *180 * @param _molecule molecule to remove181 */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 scene188 // (= 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 199 136 /** Adds a bond to the scene. 200 137 * … … 206 143 LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+"."); 207 144 //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << "."); 145 const double distance = 146 _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.; 208 147 209 148 BondIds ids; … … 222 161 #endif 223 162 GLMoleculeObject_bond *bondObject = 224 new GLMoleculeObject_bond(this, _bond, side);163 new GLMoleculeObject_bond(this, _bond, distance, side); 225 164 connect ( 226 165 bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)), 227 166 this, SLOT(bondRemoved(const atomId_t, const atomId_t))); 228 connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));229 167 BondsinSceneMap.insert( make_pair(ids, bondObject) ); 230 168 // BondIdsinSceneMap.insert( Leftids ); -
src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp
r53059e rc0ed1e 23 23 24 24 #include "GLMoleculeObject_bond.hpp" 25 #include "GLMoleculeObject_molecule.hpp"26 25 27 26 class atom; 28 class molecule;29 27 30 28 class QGLPainter; … … 34 32 class GLMoleculeObject; 35 33 class GLMoleculeObject_atom; 36 class GLMoleculeObject_molecule;37 34 38 35 /** This class contains a list of all molecules in the world. … … 52 49 void changeMaterials(bool perPixel); 53 50 QGLSceneNode* getAtom(size_t); 54 QGLSceneNode* getMolecule(size_t);55 51 QGLSceneNode* getBond(size_t, size_t); 56 52 … … 72 68 void atomInserted(const atom *_atom); 73 69 void atomRemoved(const atom *_atom); 74 void moleculeRemoved(const molecule *_molecule);75 void worldSelectionChanged();76 70 void bondInserted(const bond *_bond, const GLMoleculeObject_bond::SideOfBond side); 77 71 void bondRemoved(const atomId_t leftnr, const atomId_t rightnr); … … 86 80 typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap; 87 81 typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap; 88 typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap;89 82 AtomNodeMap AtomsinSceneMap; 90 83 BondNodeMap BondsinSceneMap; 91 MoleculeNodeMap MoleculesinSceneMap;92 84 }; 93 85 -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp
r53059e rc0ed1e 26 26 #include "CodePatterns/MemDebug.hpp" 27 27 28 #include "Atom/AtomObserver.hpp"29 #include "Atom/atom_observable.hpp"30 28 #include "CodePatterns/Log.hpp" 31 29 #include "CodePatterns/Observer/Notification.hpp" … … 44 42 connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *))); 45 43 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 *)));48 44 connect(this, SIGNAL(changed()), this, SLOT(updateGL())); 49 45 … … 52 48 World::getInstance().signOn(this, World::AtomInserted); 53 49 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);58 50 } 59 51 … … 63 55 World::getInstance().signOff(this, World::AtomInserted); 64 56 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);69 57 delete worldscene; 70 58 } … … 91 79 void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification) 92 80 { 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; 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; 142 90 } 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; 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; 157 99 } 158 } else 159 ASSERT(0, "GLWorldView::recieveNotification() - received notification from unknown source."); 100 default: 101 ASSERT(0, "GLWorldView::recieveNotification() - we cannot get here."); 102 break; 103 } 160 104 } 161 105 -
src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp
r53059e rc0ed1e 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();52 49 53 50 protected: … … 60 57 61 58 bool changesPresent; 62 bool processingSelectionChanged; // workaround to prevent a loop in (atom_iterator <-> observer)63 59 }; 64 60 -
src/UIElements/Views/Qt4/QtWorldView.cpp
r53059e rc0ed1e 28 28 #include "molecule.hpp" 29 29 #include "MoleculeListClass.hpp" 30 #include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"31 #include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"32 30 33 31 using namespace std; … … 38 36 // these attributes are skiped so far 39 37 const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX; 40 const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula" ,"Occurrence"/*,"Size"*/};38 const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula"/*,"Size"*/}; 41 39 42 40 QtWorldView::QtWorldView(QWidget * _parent) : 43 QT reeWidget (_parent),41 QTableWidget (_parent), 44 42 Observer("QtWorldView") 45 43 { 44 setRowCount(0); 46 45 setColumnCount(COLUMNCOUNT); 47 setSelectionMode(QAbstractItemView::MultiSelection);48 46 49 QStringList header; 50 for(int i=0; i<COLUMNCOUNT;++i) 51 header << COLUMNNAMES[i]; 52 setHeaderLabels(header); 47 for(int i=0; i<COLUMNCOUNT;++i) { 48 QTableWidgetItem *heading = new QTableWidgetItem(); 49 std::cout << "Creating heading item " << heading << "." << std::endl; 50 heading->setText(QString(COLUMNNAMES[i])); 51 setHorizontalHeaderItem(i,heading); 52 } 53 53 54 54 molecules = World::getInstance().getMolecules(); 55 55 molecules->signOn(this); 56 update(molecules); 56 57 57 dirty = true; 58 refill(); 59 60 //connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int))); 61 connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected())); 58 connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int))); 59 connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int))); 62 60 63 61 } … … 69 67 70 68 void QtWorldView::update(Observable *publisher) { 71 72 dirty = true;73 74 // force an update from Qt...75 clear();76 }77 78 void QtWorldView::refill() {79 69 int numMolecules = molecules->ListOfMolecules.size(); 80 clear();70 setRowCount(numMolecules); 81 71 molSelection.resize(numMolecules); 82 83 // list of (unique) formulas in the world84 std::vector<Formula> formula;85 86 72 int i; 87 73 MoleculeList::iterator iter; … … 90 76 ++i,++iter) { 91 77 92 // find group if already in list 93 QTreeWidgetItem *groupItem = NULL; 94 for (unsigned int j=0;j<formula.size();j++) 95 if ((*iter)->getFormula() == formula[j]){ 96 groupItem = topLevelItem(j); 97 break; 98 } 78 const int index = (*iter)->IndexNr; 79 QTableWidgetItem *indexWidget = new QTableWidgetItem(); 80 //std::cout << "Creating index item " << indexWidget << "." << std::endl; 81 indexWidget->setText(QString::number(index)); 82 indexWidget->setData(Qt::UserRole,QVariant(index)); 83 setVerticalHeaderItem(i,indexWidget); 99 84 100 // new molecule type -> create new group 101 if (!groupItem){ 102 formula.push_back((*iter)->getFormula()); 103 groupItem = new QTreeWidgetItem(this); 104 groupItem->setText(0, QString((*iter)->getName().c_str())); 105 groupItem->setText(1, QString::number((*iter)->getAtomCount())); 106 groupItem->setText(2, QString((*iter)->getFormula().toString().c_str())); 107 groupItem->setText(3, "0"); 108 } 85 const string name = (*iter)->getName(); 86 QTableWidgetItem *nameWidget = new QTableWidgetItem(); 87 //std::cout << "Creating name item " << nameWidget << " at " << i << "," << NAME << "." << std::endl; 88 nameWidget->setText(QString(name.c_str())); 89 setItem(i,NAME,nameWidget); 109 90 110 // add molecule 111 QTreeWidgetItem *molItem = new QTreeWidgetItem(groupItem); 112 molItem->setText(0, QString((*iter)->getName().c_str())); 113 molItem->setText(1, QString::number((*iter)->getAtomCount())); 114 molItem->setText(2, QString((*iter)->getFormula().toString().c_str())); 115 const int index = (*iter)->IndexNr; 116 molItem->setData(0, Qt::UserRole, QVariant(index)); 117 molItem->setSelected(World::getInstance().isSelected(*iter)); 91 const int atomCount = (*iter)->getAtomCount(); 92 QTableWidgetItem *countWidget= new QTableWidgetItem(); 93 //std::cout << "Creating count item " << countWidget << " at " << i << "," << ATOMCOUNT << "." << std::endl; 94 countWidget->setText(QString::number(atomCount)); 95 countWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 96 setItem(i,ATOMCOUNT,countWidget); 118 97 98 const Formula formula = (*iter)->getFormula(); 99 QTableWidgetItem *formulaWidget= new QTableWidgetItem(); 100 //std::cout << "Creating formula item " << formulaWidget << " at " << i << "," << FORMULA << "." << std::endl; 101 formulaWidget->setText(QString(formula.toString().c_str())); 102 formulaWidget->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); 103 setItem(i,FORMULA,formulaWidget); 119 104 120 // increase group occurrence 121 int count = groupItem->text(3).toInt() + 1; 122 groupItem->setText(3, QString::number(count)); 123 124 //molSelection[i]=nameWidget->isSelected(); 105 molSelection[i]=nameWidget->isSelected(); 125 106 } 126 dirty = false;127 }128 129 void QtWorldView::paintEvent(QPaintEvent * event)130 {131 if (dirty)132 refill();133 QTreeWidget::paintEvent(event);134 107 } 135 108 … … 137 110 } 138 111 139 void QtWorldView::moleculeChanged( ) {140 /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();112 void QtWorldView::moleculeChanged(int row, int column) { 113 int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt(); 141 114 molecule *mol = molecules->ReturnIndex(idx); 142 115 string cellValue = item(row,NAME)->text().toStdString(); … … 146 119 else if(cellValue==""){ 147 120 item(row,NAME)->setText(QString(mol->getName().c_str())); 148 } */121 } 149 122 } 150 123 151 124 152 void QtWorldView::rowSelected(){ 153 154 // lookup all molecules in the treeWidget 155 for (int i=0;i<topLevelItemCount();i++){ 156 QTreeWidgetItem *top = topLevelItem(i); 157 for (int j=0;j<top->childCount();j++){ 158 159 // molecules are 1 level below the top 160 QTreeWidgetItem *molItem = top->child(j); 161 162 // molecule index stored as user data 163 int index = molItem->data(0, Qt::UserRole).toInt(); 164 molecule *mol = molecules->ReturnIndex(index); 165 ASSERT(mol, "QtWorldView::rowSelected()"); 166 167 // selection changed by user? 168 bool molSelectedWorld = World::getInstance().isSelected(mol); 169 bool molSelectedList = molItem->isSelected(); 170 //std::cout << molSelectedWorld << " " << molSelectedList << std::endl; 171 172 if (molSelectedWorld != molSelectedList){ 173 174 // apply new selection state 175 if (molSelectedList){ 176 //std::cout << "select molecule" << std::endl; 177 MoleCuilder::SelectionMoleculeById(mol->getId()); 178 }else{ 179 //std::cout << "unselect molecule" << std::endl; 180 MoleCuilder::SelectionNotMoleculeById(mol->getId()); 181 } 125 void QtWorldView::cellSelected(int row, int column){ 126 //std::cout << "Selection in (" << row << "," << column << "): " << item(row,column) << std::endl; 127 bool state = item(row,column)->isSelected(); 128 for(int i = 0; i<COLUMNCOUNT; i++){ 129 //std::cout << "Setting " << i << "-th item " << item(row,i) << " in row " << row << " to state selected." << std::endl; 130 item(row,i)->setSelected(state); 131 } 132 // figure out which rows have changed 133 for(int i=0; i<rowCount();++i){ 134 state = item(i,0)->isSelected(); 135 if(molSelection[i]!=state){ 136 int idx = verticalHeaderItem(i)->data(Qt::UserRole).toInt(); 137 molecule *mol = molecules->ReturnIndex(idx); 138 if(state){ 139 emit moleculeSelected(mol); 182 140 } 141 else{ 142 emit moleculeUnSelected(mol); 143 } 144 molSelection[i]=state; 183 145 } 184 146 } -
src/UIElements/Views/Qt4/QtWorldView.hpp
r53059e rc0ed1e 15 15 16 16 17 #include <QtGui/QT reeWidget>17 #include <QtGui/QTableWidget> 18 18 #include "CodePatterns/Observer/Observer.hpp" 19 19 … … 21 21 class MoleculeListClass; 22 22 23 class QtWorldView : public QT reeWidget, public Observer23 class QtWorldView : public QTableWidget, public Observer 24 24 { 25 25 Q_OBJECT … … 32 32 virtual void update(Observable *publisher); 33 33 virtual void subjectKilled(Observable *publisher); 34 virtual void paintEvent(QPaintEvent * event);35 void refill();36 34 37 35 static const int COLUMNCOUNT; 38 enum {NAME,ATOMCOUNT,FORMULA, OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;36 enum {NAME,ATOMCOUNT,FORMULA,COLUMNTYPES_MAX} COLUMNTYPES; 39 37 static const char *COLUMNNAMES[]; 40 38 41 39 private slots: 42 void moleculeChanged( );40 void moleculeChanged(int row, int column); 43 41 44 void rowSelected();42 void cellSelected(int row, int column); 45 43 46 44 signals: … … 51 49 std::vector<bool> molSelection; //!< needed to determine when a selection changes 52 50 MoleculeListClass *molecules; 53 bool dirty;54 51 }; 55 52 -
src/World.cpp
r53059e rc0ed1e 414 414 415 415 void World::clearAtomSelection(){ 416 OBSERVE;417 NOTIFY(SelectionChanged);418 416 selectedAtoms.clear(); 419 417 } … … 435 433 436 434 void World::selectAtom(const atom *_atom){ 437 OBSERVE;438 NOTIFY(SelectionChanged);439 435 // atom * is unchanged in this function, but we do store entity as changeable 440 436 ASSERT(_atom,"Invalid pointer in selection of atom"); … … 443 439 444 440 void World::selectAtom(const atomId_t id){ 445 OBSERVE;446 NOTIFY(SelectionChanged);447 441 ASSERT(atoms.count(id),"Atom Id selected that was not in the world"); 448 442 selectedAtoms[id]=atoms[id]; … … 450 444 451 445 void World::selectAllAtoms(AtomDescriptor descr){ 452 OBSERVE;453 NOTIFY(SelectionChanged);454 446 internal_AtomIterator begin = getAtomIter_internal(descr); 455 447 internal_AtomIterator end = atomEnd_internal(); … … 459 451 460 452 void World::selectAtomsOfMolecule(const molecule *_mol){ 461 OBSERVE;462 NOTIFY(SelectionChanged);463 453 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); 464 454 // need to make it const to get the fast iterators … … 469 459 470 460 void World::selectAtomsOfMolecule(const moleculeId_t id){ 471 OBSERVE;472 NOTIFY(SelectionChanged);473 461 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); 474 462 selectAtomsOfMolecule(molecules[id]); … … 476 464 477 465 void World::unselectAtom(const atom *_atom){ 478 OBSERVE;479 NOTIFY(SelectionChanged);480 466 ASSERT(_atom,"Invalid pointer in unselection of atom"); 481 467 unselectAtom(_atom->getId()); … … 483 469 484 470 void World::unselectAtom(const atomId_t id){ 485 OBSERVE;486 NOTIFY(SelectionChanged);487 471 ASSERT(atoms.count(id),"Atom Id unselected that was not in the world"); 488 472 selectedAtoms.erase(id); … … 490 474 491 475 void World::unselectAllAtoms(AtomDescriptor descr){ 492 OBSERVE;493 NOTIFY(SelectionChanged);494 476 internal_AtomIterator begin = getAtomIter_internal(descr); 495 477 internal_AtomIterator end = atomEnd_internal(); … … 499 481 500 482 void World::unselectAtomsOfMolecule(const molecule *_mol){ 501 OBSERVE;502 NOTIFY(SelectionChanged);503 483 ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule"); 504 484 // need to make it const to get the fast iterators … … 509 489 510 490 void World::unselectAtomsOfMolecule(const moleculeId_t id){ 511 OBSERVE;512 NOTIFY(SelectionChanged);513 491 ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule"); 514 492 unselectAtomsOfMolecule(molecules[id]); … … 543 521 544 522 void World::clearMoleculeSelection(){ 545 OBSERVE;546 NOTIFY(SelectionChanged);547 523 selectedMolecules.clear(); 548 524 } … … 565 541 566 542 void World::selectMolecule(const molecule *_mol){ 567 OBSERVE;568 NOTIFY(SelectionChanged);569 543 // molecule * is unchanged in this function, but we do store entity as changeable 570 544 ASSERT(_mol,"Invalid pointer to molecule in selection"); … … 573 547 574 548 void World::selectMolecule(const moleculeId_t id){ 575 OBSERVE;576 NOTIFY(SelectionChanged);577 549 ASSERT(molecules.count(id),"Molecule Id selected that was not in the world"); 578 550 selectedMolecules[id]=molecules[id]; … … 580 552 581 553 void World::selectAllMolecules(MoleculeDescriptor descr){ 582 OBSERVE;583 NOTIFY(SelectionChanged);584 554 internal_MoleculeIterator begin = getMoleculeIter_internal(descr); 585 555 internal_MoleculeIterator end = moleculeEnd_internal(); … … 589 559 590 560 void World::selectMoleculeOfAtom(const atom *_atom){ 591 OBSERVE;592 NOTIFY(SelectionChanged);593 561 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); 594 562 molecule *mol=_atom->getMolecule(); … … 600 568 601 569 void World::selectMoleculeOfAtom(const atomId_t id){ 602 OBSERVE;603 NOTIFY(SelectionChanged);604 570 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ 605 571 selectMoleculeOfAtom(atoms[id]); … … 607 573 608 574 void World::unselectMolecule(const molecule *_mol){ 609 OBSERVE;610 NOTIFY(SelectionChanged);611 575 ASSERT(_mol,"invalid pointer in unselection of molecule"); 612 576 unselectMolecule(_mol->getId()); … … 614 578 615 579 void World::unselectMolecule(const moleculeId_t id){ 616 OBSERVE;617 NOTIFY(SelectionChanged);618 580 ASSERT(molecules.count(id),"No such molecule with ID in unselection"); 619 581 selectedMolecules.erase(id); … … 621 583 622 584 void World::unselectAllMolecules(MoleculeDescriptor descr){ 623 OBSERVE;624 NOTIFY(SelectionChanged);625 585 internal_MoleculeIterator begin = getMoleculeIter_internal(descr); 626 586 internal_MoleculeIterator end = moleculeEnd_internal(); … … 630 590 631 591 void World::unselectMoleculeOfAtom(const atom *_atom){ 632 OBSERVE;633 NOTIFY(SelectionChanged);634 592 ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom"); 635 593 molecule *mol=_atom->getMolecule(); … … 641 599 642 600 void World::unselectMoleculeOfAtom(const atomId_t id){ 643 OBSERVE;644 NOTIFY(SelectionChanged);645 601 ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\ 646 602 unselectMoleculeOfAtom(atoms[id]); -
src/World.hpp
r53059e rc0ed1e 115 115 MoleculeInserted, 116 116 MoleculeRemoved, 117 SelectionChanged,118 117 NotificationType_MAX 119 118 }; -
src/molecule.cpp
r53059e rc0ed1e 729 729 void molecule::SetNameFromFilename(const char *filename) 730 730 { 731 OBSERVE;732 731 int length = 0; 733 732 const char *molname = strrchr(filename, '/');
Note:
See TracChangeset
for help on using the changeset viewer.