Changes in / [c0ed1e:53059e]


Ignore:
Location:
src
Files:
4 added
30 edited

Legend:

Unmodified
Added
Removed
  • src/Element/element.hpp

    rc0ed1e r53059e  
    9090    double CovalentRadius;  //!< covalent radius
    9191    double Electronegativity; //!< electronegativity in Pauling units
    92     double VanDerWaalsRadius;  //!< can-der-Waals radius
     92    double VanDerWaalsRadius;  //!< van-der-Waals radius
    9393    atomicNumber_t Z;          //!< atomic number
    9494    std::string period;    //!< period: n quantum number
  • src/UIElements/Makefile.am

    rc0ed1e r53059e  
    199199  UIElements/Views/Qt4/QtWorldView.cpp \
    200200  UIElements/Views/Qt4/QtMoleculeView.cpp \
     201  UIElements/Views/Qt4/QtElementList.cpp \
    201202  UIElements/Views/Qt4/QtStatusBar.cpp \
    202203  UIElements/Views/Qt4/Qt3D/GLWorldView.cpp \
     
    204205        UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp \
    205206        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp \
    206         UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp
     207        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp \
     208        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
    207209#  UIElements/Views/Qt4/dialoglight.cpp
    208210             
     
    230232  UIElements/Views/Qt4/QtWorldView.hpp \
    231233  UIElements/Views/Qt4/QtMoleculeView.hpp \
     234  UIElements/Views/Qt4/QtElementList.hpp \
    232235  UIElements/Views/Qt4/QtStatusBar.hpp \
    233236  UIElements/Views/Qt4/Qt3D/GLWorldView.hpp \
     
    235238        UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp \
    236239        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp \
    237         UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp
     240        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp \
     241        UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp
    238242
    239243QTUIUI_UIFILES = \
  • src/UIElements/Qt4/Pipe/BooleanQtQueryPipe.cpp

    rc0ed1e r53059e  
    2525#include "CodePatterns/MemDebug.hpp"
    2626
    27 BooleanQtQueryPipe::BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox) :
     27BooleanQtQueryPipe::BooleanQtQueryPipe(bool *_content, QtDialog *_dialog, QCheckBox *_booleanCheckBox) :
    2828  content(_content),
    2929  dialog(_dialog),
    30   booleanComboBox(_booleanComboBox)
     30  booleanCheckBox(_booleanCheckBox)
    3131{}
    3232
     
    3434{}
    3535
    36 void BooleanQtQueryPipe::update() {
     36void BooleanQtQueryPipe::update(int state) {
     37  (*content) = (state == Qt::Checked);
    3738  dialog->update();
    3839}
  • src/UIElements/Qt4/Pipe/BooleanQtQueryPipe.hpp

    rc0ed1e r53059e  
    1818
    1919class QtDialog;
    20 class QComboBox;
     20class QCheckBox;
    2121
    2222class BooleanQtQueryPipe : public QWidget {
    2323  Q_OBJECT
    2424public:
    25   BooleanQtQueryPipe(const bool *_content, QtDialog *_dialog, QComboBox *_booleanComboBox);
     25  BooleanQtQueryPipe(bool *_content, QtDialog *_dialog, QCheckBox *_booleanCheckBox);
    2626  virtual ~BooleanQtQueryPipe();
    2727
    2828public slots:
    29   void update();
     29  void update(int state);
    3030
    3131private:
    32   const bool *content;
     32  bool *content;
    3333  QtDialog *dialog;
    34   QComboBox *booleanComboBox;
     34  QCheckBox *booleanCheckBox;
    3535};
    3636
  • src/UIElements/Qt4/Pipe/BoxQtQueryPipe.cpp

    rc0ed1e r53059e  
    3434{
    3535  tmpM = new RealSpaceMatrix();
    36   tmpM->setZero();
     36  tmpM->setIdentity();
    3737}
    3838
  • src/UIElements/Qt4/Pipe/VectorQtQueryPipe.cpp

    rc0ed1e r53059e  
    3535{}
    3636
    37 void VectorQtQueryPipe::update() {
     37void VectorQtQueryPipe::updateX(double newDouble) {
     38  (*content)[0] = newDouble;
    3839  dialog->update();
    3940}
    4041
     42void VectorQtQueryPipe::updateY(double newDouble) {
     43  (*content)[1] = newDouble;
     44  dialog->update();
     45}
     46
     47void VectorQtQueryPipe::updateZ(double newDouble) {
     48  (*content)[2] = newDouble;
     49  dialog->update();
     50}
     51
  • src/UIElements/Qt4/Pipe/VectorQtQueryPipe.hpp

    rc0ed1e r53059e  
    2929
    3030public slots:
    31   void update();
     31  void updateX(double);
     32  void updateY(double);
     33  void updateZ(double);
    3234
    3335private:
  • src/UIElements/Qt4/QtMainWindow.cpp

    rc0ed1e r53059e  
    3333#include "Menu/Qt4/QtMenu.hpp"
    3434#include "Views/Qt4/QtWorldView.hpp"
     35#include "Views/Qt4/QtElementList.hpp"
    3536#include "Views/Qt4/QtMoleculeView.hpp"
    3637#include "Views/Qt4/QtStatusBar.hpp"
     
    5152  QSplitter *splitter1 = new QSplitter (Qt::Horizontal, this );
    5253  QSplitter *splitter2 = new QSplitter (Qt::Vertical, splitter1 );
     54  QTabWidget *worldTab = new QTabWidget(splitter2);
    5355
    54   worldDisplay = new QtWorldView(splitter2);
     56  worldDisplay = new QtWorldView(worldTab);
     57  elementList = new QtElementList(worldTab);
    5558
    5659  moleculeDisplay = new QtMoleculeView();
     
    6871  splitter1->addWidget(moleculeDisplay);
    6972  splitter2->addWidget(molecule3dDisplay);
    70   splitter2->addWidget(worldDisplay);
     73  splitter2->addWidget(worldTab);
     74  worldTab->addTab(worldDisplay, "Molecules");
     75  worldTab->addTab(elementList, "All Elements");
    7176
    7277  statusBar = new QtStatusBar(this);
  • src/UIElements/Qt4/QtMainWindow.hpp

    rc0ed1e r53059e  
    2424
    2525class QtWorldView;
     26class QtElementList;
    2627class StringView;
    2728class GLWorldView;
     
    4445  QApplication *theApp;
    4546  QtWorldView *worldDisplay;
     47  QtElementList *elementList;
    4648  GLWorldView *molecule3dDisplay;
    4749  QtMoleculeView *moleculeDisplay;
  • src/UIElements/Qt4/Query/BooleanQtQuery.cpp

    rc0ed1e r53059e  
    1919
    2020#include <Qt/qboxlayout.h>
    21 #include <Qt/qcombobox.h>
     21#include <Qt/qcheckbox.h>
    2222#include <Qt/qlabel.h>
    2323
     
    3232    parent(_parent)
    3333{
     34  thisLayout = new QHBoxLayout();
    3435  titleLabel = new QLabel(QString(getTitle().c_str()),_dialog);
    35   booleanComboBox = new QComboBox(_dialog);
    36   booleanComboBox->insertItem(1, QString("true"));
    37   booleanComboBox->insertItem(0, QString("false"));
     36  booleanCheckBox = new QCheckBox(QString(getTitle().c_str()), _dialog);
    3837
    3938  parent->addLayout(thisLayout);
    4039  thisLayout->addWidget(titleLabel);
    41   thisLayout->addWidget(booleanComboBox);
     40  thisLayout->addWidget(booleanCheckBox);
    4241
    43   pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanComboBox);
    44   connect(booleanComboBox, SIGNAL(currentIndexChanged()), pipe, SLOT(update()));
     42  pipe = new BooleanQtQueryPipe(&tmp,_dialog,booleanCheckBox);
     43  connect(booleanCheckBox, SIGNAL(stateChanged(int)), pipe, SLOT(update(int)));
    4544}
    4645
  • src/UIElements/Qt4/Query/QtQuery.hpp

    rc0ed1e r53059e  
    2929class QTextEdit;
    3030class QComboBox;
     31class QCheckBox;
    3132
    3233// Forward declarations for plumbing
     
    9192  QBoxLayout *thisLayout;
    9293  QLabel *titleLabel;
    93   QComboBox *booleanComboBox;
     94  QCheckBox *booleanCheckBox;
    9495
    9596  BooleanQtQueryPipe *pipe;
     
    325326  QBoxLayout *coordLayout;
    326327  QLabel *coordLabel;
    327   QDoubleSpinBox *coordInput;
     328  QDoubleSpinBox *coordInputX;
     329  QDoubleSpinBox *coordInputY;
     330  QDoubleSpinBox *coordInputZ;
    328331
    329332  VectorQtQueryPipe *pipe;
  • src/UIElements/Qt4/Query/VectorQtQuery.cpp

    rc0ed1e r53059e  
    4343  coordLabel = new QLabel(QString("x,y,z"));
    4444  coordLayout->addWidget(coordLabel);
    45   coordInput = new QDoubleSpinBox();
    46 //  coordInput->setRange(0,M.at(i,i));
    47   coordInput->setDecimals(3);
    48   coordLayout->addWidget(coordInput);
     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);
    4960  pipe = new VectorQtQueryPipe(&(tmp),_dialog,inputBox);
    5061  //pipe->update(coordInput->value());
    51   connect(coordInput,SIGNAL(valueChanged(double)),pipe,SLOT(update(double)));
     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)));
    5265  parent->addLayout(mainLayout);
    5366}
  • src/UIElements/Query/BooleanQuery.cpp

    rc0ed1e r53059e  
    2525// Bool Queries
    2626Dialog::BooleanQuery::BooleanQuery(std::string title,std::string description) :
    27     Query(title, description)
     27    Query(title, description),
     28    tmp(false)
    2829{}
    2930
  • src/UIElements/Query/DoubleQuery.cpp

    rc0ed1e r53059e  
    2525// Double Queries
    2626Dialog::DoubleQuery::DoubleQuery(std::string title, std::string _description) :
    27     Query(title, _description)
     27    Query(title, _description),
     28    tmp(0)
    2829{}
    2930
  • src/UIElements/Query/IntQuery.cpp

    rc0ed1e r53059e  
    2525// Int Queries
    2626Dialog::IntQuery::IntQuery(std::string title, std::string description) :
    27     Query(title, description)
     27    Query(title, description),
     28    tmp(0)
    2829{}
    2930
  • src/UIElements/Query/UnsignedIntQuery.cpp

    rc0ed1e r53059e  
    2525// UnsignedInt Queries
    2626Dialog::UnsignedIntQuery::UnsignedIntQuery(std::string title, std::string description) :
    27     Query(title, description)
     27    Query(title, description),
     28    tmp(0)
    2829{}
    2930
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp

    rc0ed1e r53059e  
    4242#include "CodePatterns/MemDebug.hpp"
    4343
     44QGLMaterial *GLMoleculeObject::m_hoverMaterial = NULL;
     45QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL;
     46QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL;
     47
    4448
    4549GLMoleculeObject::GLMoleculeObject(QGLSceneNode *GLMoleculeObject, QObject *parent)
    4650   : QObject(parent)
    4751{
    48    m_mesh = 0;
    49    m_GLMoleculeObject = GLMoleculeObject;
     52   m_mesh = GLMoleculeObject;
    5053   m_scale = 1.0f;
     54   m_scaleZ = 1.0f;
    5155   m_rotationAngle = 0.0f;
    5256   m_effect = 0;
    5357   m_objectId = -1;
    5458   m_hovering = false;
     59   m_selected = false;
    5560   m_material = 0;
    56    m_hoverMaterial = 0;
     61   initStaticMaterials();
    5762}
    5863
     
    6166{
    6267   scene->setParent(this);
    63    m_mesh = 0;
    64    m_GLMoleculeObject = scene->mainNode();
     68   m_mesh = scene->mainNode();
    6569   m_scale = 1.0f;
     70   m_scaleZ = 1.0f;
    6671   m_rotationAngle = 0.0f;
    6772   m_effect = 0;
    6873   m_objectId = -1;
    6974   m_hovering = false;
     75   m_selected = false;
    7076   m_material = 0;
    71    m_hoverMaterial = 0;
     77   initStaticMaterials();
    7278}
    7379
    7480GLMoleculeObject::~GLMoleculeObject()
    7581{
    76    delete m_mesh;
    7782}
    7883
     
    8287   if (m_objectId != -1)
    8388       view->registerObject(m_objectId, this);
     89}
     90
     91
     92/** Draws a box around the mesh.
     93 *
     94 */
     95void 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);
    84117}
    85118
     
    93126   if (m_rotationAngle != 0.0f)
    94127       painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
     128   if (m_scaleZ != 1.0f)
     129       painter->modelViewMatrix().scale(1.0f, 1.0f, m_scaleZ);
    95130
    96131   // Apply the material and effect to the painter.
     
    98133   if (m_hovering)
    99134       material = m_hoverMaterial;
     135   else if (m_selected)
     136       material = m_selectionMaterial;
    100137   else
    101138       material = m_material;
     139
     140   ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
     141
    102142   painter->setColor(material->diffuseColor());
    103143   painter->setFaceMaterial(QGL::AllFaces, material);
     
    113153
    114154   // 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);
    119160
    120161   // Turn off the user effect, if present.
     
    164205QGLMaterial* GLMoleculeObject::getMaterial(size_t no)
    165206{
    166   ASSERT( (no >= 0) && (no < MAX_ELEMENTS),
     207  ASSERT( (no > 0) && (no < MAX_ELEMENTS),
    167208      "GLMoleculeView::getMaterial() - Element no "+toString(no)+" is invalid.");
    168209  if (ElementNoMaterialMap.find(no) != ElementNoMaterialMap.end()){
     
    174215    QGLMaterial *newmaterial = new QGLMaterial(NULL);
    175216
    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]) );
    187225    newmaterial->setSpecularColor( QColor(60, 60, 60) );
    188226    newmaterial->setShininess( 128 );
     
    190228
    191229    return newmaterial;
     230  }
     231}
     232
     233/** Create the 3 materials shared by all objects.
     234 *
     235 */
     236void 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) );
    192255  }
    193256}
     
    205268  }
    206269}
     270
     271
     272void 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  
    4747   void setScale(qreal value) { m_scale = value; }
    4848
     49   qreal scaleZ() const { return m_scaleZ; }
     50   void setScaleZ(qreal value) { m_scaleZ = value; }
     51
    4952   qreal rotationAngle() const { return m_rotationAngle; }
    5053   void setRotationAngle(qreal value) { m_rotationAngle = value; }
     
    5457
    5558   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; }
    6160
    6261   QGLAbstractEffect *effect() const { return m_effect; }
     
    6665   void setObjectId(int id) { m_objectId = id; }
    6766
     67   bool selected() const { return m_selected; }
     68   void setSelected(bool value);
     69
     70   void initStaticMaterials();
    6871   void initialize(QGLView *view, QGLPainter *painter);
    6972   void draw(QGLPainter *painter);
     73   void drawSelectionBox(QGLPainter *painter);
    7074
    7175signals:
     
    7579   void doubleClicked();
    7680   void hoverChanged();
     81   void selectionChanged();
     82   void changed();
    7783
    7884protected:
     
    8894
    8995   QGLSceneNode *m_mesh;
    90    QGLSceneNode *m_GLMoleculeObject;
    9196   QGLAbstractScene *m_scene;
    9297   QVector3D m_position;
    9398   qreal m_scale;
     99   qreal m_scaleZ;
    94100   qreal m_rotationAngle;
    95101   QVector3D m_rotationVector;
    96102   QGLMaterial *m_material;
    97    QGLMaterial *m_hoverMaterial;
     103   static QGLMaterial *m_hoverMaterial;
     104   static QGLMaterial *m_selectionMaterial;
     105   static QGLMaterial *m_selectionBoxMaterial;
    98106   QGLAbstractEffect *m_effect;
    99107   int m_objectId;
    100108   bool m_hovering;
     109   bool m_selected;
    101110};
    102111
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    rc0ed1e r53059e  
    4141{
    4242  QGLBuilder builder;
    43   builder << QGLSphere(0.5);
     43  builder << QGLSphere(2.0);
    4444  QGLSceneNode *n = builder.finalizedSceneNode();
    4545  n->setParent(parent);
     
    5757  atomref->signOn(this, AtomObservable::ElementChanged);
    5858  atomref->signOn(this, AtomObservable::BondsAdded);
     59  World::getInstance().signOn(this, World::SelectionChanged);
    5960
    6061  // set the object's id
     
    7273  _atom->signOff(this, AtomObservable::ElementChanged);
    7374  _atom->signOff(this, AtomObservable::BondsAdded);
     75  World::getInstance().signOff(this, World::SelectionChanged);
    7476}
    7577
     
    104106      "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
    105107  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);
    110108
    111109  // set scale
     
    116114    radius = 0.5;
    117115  }
    118   setScale( radius );
     116  setScale( radius / 4. );
    119117}
    120118
     
    136134  // set the object's id
    137135  resetIndex();
     136
     137  // selected?
     138  setSelected(World::getInstance().isSelected(_atom));
    138139}
    139140
     
    143144void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
    144145{
     146  if (publisher == dynamic_cast<const Observable*>(_atom)){
     147    // notofication from atom
    145148#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:
    161166      {
    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    }
    173193  }
    174194}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    rc0ed1e r53059e  
    3939#include "LinearAlgebra/Vector.hpp"
    4040
    41 static QGLSceneNode *createBond(QObject *parent, double distance)
     41static QGLSceneNode *createBond(QObject *parent)
    4242{
    4343   QGLBuilder builder;
    44    QGLCylinder cylinder(.25,.25,.25);
    45    cylinder.setHeight(distance);
     44   QGLCylinder cylinder(.25,.25,1.0,16);
    4645   builder << cylinder;
    4746   QGLSceneNode *n = builder.finalizedSceneNode();
     
    5049}
    5150
    52 GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side) :
    53   GLMoleculeObject(createBond(parent, distance), parent),
     51GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side) :
     52  GLMoleculeObject(createBond(parent), parent),
    5453  Observer(std::string("GLMoleculeObject_bond")
    5554      +toString(bondref->leftatom->getId())
     
    6160  // sign on as observer (obtain non-const instance before)
    6261  _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
    6665  size_t elementno = 0;
    6766  switch (BondSide) {
    6867    case left:
    69       Position = _bond->leftatom->getPosition();
    70       OtherPosition = _bond->rightatom->getPosition();
    7168      if (_bond->leftatom->getType() != NULL) {
    7269        elementno = _bond->leftatom->getType()->getAtomicNumber();
     
    7673      break;
    7774    case right:
    78       Position = _bond->rightatom->getPosition();
    79       OtherPosition = _bond->leftatom->getPosition();
    8075      if (_bond->rightatom->getType() != NULL) {
    8176        elementno = _bond->rightatom->getType()->getAtomicNumber();
     
    9388  QGLMaterial *elementmaterial = getMaterial(elementno);
    9489  setMaterial(elementmaterial);
     90
     91  resetPosition();
     92}
     93
     94GLMoleculeObject_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
     104void 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
     111void 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
     129void 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
     169void 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);
    95190
    96191  // calculate position
     
    123218  setRotationAngle(alpha/M_PI*180.);
    124219}
    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_OBSERVER
    137   observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << ".";
    138 #endif
    139 }
    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_OBSERVER
    162   observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
    163       << " received notification from bond " << *_bond << " for channel "
    164       << notification->getChannelNo() << ".";
    165 #endif
    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;
    185   }
    186 }
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp

    rc0ed1e r53059e  
    2828  enum SideOfBond { left, right };
    2929
    30   GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side);
     30  GLMoleculeObject_bond(QObject *parent, const bond *bondref, const enum SideOfBond side);
    3131  virtual ~GLMoleculeObject_bond();
    3232
     
    4040
    4141private:
     42  void resetPosition();
    4243  const bond *_bond;
    4344  const enum SideOfBond BondSide;
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    rc0ed1e r53059e  
    2525#include "GLMoleculeObject_atom.hpp"
    2626#include "GLMoleculeObject_bond.hpp"
     27#include "GLMoleculeObject_molecule.hpp"
    2728
    2829#include "CodePatterns/MemDebug.hpp"
     
    7475        Runner != molecules.end();
    7576        Runner++) {
    76       // create molecule
     77
    7778      for (molecule::const_iterator atomiter = (*Runner)->begin();
    7879          atomiter != (*Runner)->end();
     
    109110  AtomsinSceneMap.insert( make_pair(_atom->getId(), atomObject) );
    110111  connect (atomObject, SIGNAL(clicked(atomId_t)), this, SLOT(atomClicked(atomId_t)));
     112  connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    111113  connect (atomObject, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
     114  connect (atomObject, SIGNAL(selectionChanged()), this, SIGNAL(changed()));
    112115  connect (atomObject, SIGNAL(BondsInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)), this, SLOT(bondInserted(const bond *, const GLMoleculeObject_bond::SideOfBond)));
    113116  //bondsChanged(_atom);
     
    134137}
    135138
     139/** ....
     140 *
     141 */
     142void 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 */
     182void 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
    136199/** Adds a bond to the scene.
    137200 *
     
    143206  LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bond "+toString(*_bond)+".");
    144207  //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
    145   const double distance =
    146       _bond->leftatom->getPosition().distance(_bond->rightatom->getPosition())/2.;
    147208
    148209  BondIds ids;
     
    161222#endif
    162223  GLMoleculeObject_bond *bondObject =
    163       new GLMoleculeObject_bond(this, _bond, distance, side);
     224      new GLMoleculeObject_bond(this, _bond, side);
    164225  connect (
    165226      bondObject, SIGNAL(BondRemoved(const atomId_t, const atomId_t)),
    166227      this, SLOT(bondRemoved(const atomId_t, const atomId_t)));
     228  connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    167229  BondsinSceneMap.insert( make_pair(ids, bondObject) );
    168230//    BondIdsinSceneMap.insert( Leftids );
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.hpp

    rc0ed1e r53059e  
    2323
    2424#include "GLMoleculeObject_bond.hpp"
     25#include "GLMoleculeObject_molecule.hpp"
    2526
    2627class atom;
     28class molecule;
    2729
    2830class QGLPainter;
     
    3234class GLMoleculeObject;
    3335class GLMoleculeObject_atom;
     36class GLMoleculeObject_molecule;
    3437
    3538/** This class contains a list of all molecules in the world.
     
    4952  void changeMaterials(bool perPixel);
    5053  QGLSceneNode* getAtom(size_t);
     54  QGLSceneNode* getMolecule(size_t);
    5155  QGLSceneNode* getBond(size_t, size_t);
    5256
     
    6872  void atomInserted(const atom *_atom);
    6973  void atomRemoved(const atom *_atom);
     74  void moleculeRemoved(const molecule *_molecule);
     75  void worldSelectionChanged();
    7076  void bondInserted(const bond *_bond, const GLMoleculeObject_bond::SideOfBond side);
    7177  void bondRemoved(const atomId_t leftnr, const atomId_t rightnr);
     
    8086  typedef std::map< atomId_t, GLMoleculeObject_atom* > AtomNodeMap;
    8187  typedef std::map< BondIds , GLMoleculeObject_bond* > BondNodeMap;
     88  typedef std::map< moleculeId_t , GLMoleculeObject_molecule* > MoleculeNodeMap;
    8289  AtomNodeMap AtomsinSceneMap;
    8390  BondNodeMap BondsinSceneMap;
     91  MoleculeNodeMap MoleculesinSceneMap;
    8492};
    8593
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.cpp

    rc0ed1e r53059e  
    2626#include "CodePatterns/MemDebug.hpp"
    2727
     28#include "Atom/AtomObserver.hpp"
     29#include "Atom/atom_observable.hpp"
    2830#include "CodePatterns/Log.hpp"
    2931#include "CodePatterns/Observer/Notification.hpp"
     
    4244  connect(this, SIGNAL(atomInserted(const atom *)), worldscene, SLOT(atomInserted(const atom *)));
    4345  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 *)));
    4448  connect(this, SIGNAL(changed()), this, SLOT(updateGL()));
    4549
     
    4852  World::getInstance().signOn(this, World::AtomInserted);
    4953  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);
    5058}
    5159
     
    5563  World::getInstance().signOff(this, World::AtomInserted);
    5664  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);
    5769  delete worldscene;
    5870}
     
    7991void GLWorldView::recieveNotification(Observable *publisher, Notification_ptr notification)
    8092{
    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;
    90142    }
    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;
    99157    }
    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.");
    104160}
    105161
  • src/UIElements/Views/Qt4/Qt3D/GLWorldView.hpp

    rc0ed1e r53059e  
    4747  void atomInserted(const atom *_atom);
    4848  void atomRemoved(const atom *_atom);
     49  void moleculeInserted(const molecule *_molecule);
     50  void moleculeRemoved(const molecule *_molecule);
     51  void worldSelectionChanged();
    4952
    5053protected:
     
    5760
    5861  bool changesPresent;
     62  bool processingSelectionChanged; // workaround to prevent a loop in (atom_iterator <-> observer)
    5963};
    6064
  • src/UIElements/Views/Qt4/QtWorldView.cpp

    rc0ed1e r53059e  
    2828#include "molecule.hpp"
    2929#include "MoleculeListClass.hpp"
     30#include "Actions/SelectionAction/Molecules/MoleculeByIdAction.hpp"
     31#include "Actions/SelectionAction/Molecules/NotMoleculeByIdAction.hpp"
    3032
    3133using namespace std;
     
    3638// these attributes are skiped so far
    3739const int QtWorldView::COLUMNCOUNT = COLUMNTYPES_MAX;
    38 const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula"/*,"Size"*/};
     40const char *QtWorldView::COLUMNNAMES[QtWorldView::COLUMNCOUNT]={"Name","Atoms","Formula","Occurrence"/*,"Size"*/};
    3941
    4042QtWorldView::QtWorldView(QWidget * _parent) :
    41   QTableWidget (_parent),
     43  QTreeWidget (_parent),
    4244  Observer("QtWorldView")
    4345{
    44   setRowCount(0);
    4546  setColumnCount(COLUMNCOUNT);
     47  setSelectionMode(QAbstractItemView::MultiSelection);
    4648
    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   }
     49  QStringList header;
     50  for(int i=0; i<COLUMNCOUNT;++i)
     51    header << COLUMNNAMES[i];
     52  setHeaderLabels(header);
    5353
    5454  molecules = World::getInstance().getMolecules();
    5555  molecules->signOn(this);
    56   update(molecules);
    5756
    58   connect(this,SIGNAL(cellChanged(int,int)),this,SLOT(moleculeChanged(int,int)));
    59   connect(this,SIGNAL(cellClicked(int,int)),this,SLOT(cellSelected(int,int)));
     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()));
    6062
    6163}
     
    6769
    6870void QtWorldView::update(Observable *publisher) {
     71
     72  dirty = true;
     73
     74  // force an update from Qt...
     75  clear();
     76}
     77
     78void QtWorldView::refill() {
    6979  int numMolecules = molecules->ListOfMolecules.size();
    70   setRowCount(numMolecules);
     80  clear();
    7181  molSelection.resize(numMolecules);
     82
     83  // list of (unique) formulas in the world
     84  std::vector<Formula> formula;
     85
    7286  int i;
    7387  MoleculeList::iterator iter;
     
    7690      ++i,++iter) {
    7791
     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      }
     99
     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    }
     109
     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()));
    78115    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);
     116    molItem->setData(0, Qt::UserRole, QVariant(index));
     117    molItem->setSelected(World::getInstance().isSelected(*iter));
    84118
    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);
    90119
    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);
     120    // increase group occurrence
     121    int count = groupItem->text(3).toInt() + 1;
     122    groupItem->setText(3, QString::number(count));
    97123
    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);
     124    //molSelection[i]=nameWidget->isSelected();
     125  }
     126  dirty = false;
     127}
    104128
    105     molSelection[i]=nameWidget->isSelected();
    106   }
     129void QtWorldView::paintEvent(QPaintEvent * event)
     130{
     131  if (dirty)
     132    refill();
     133  QTreeWidget::paintEvent(event);
    107134}
    108135
     
    110137}
    111138
    112 void QtWorldView::moleculeChanged(int row, int column) {
    113   int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
     139void QtWorldView::moleculeChanged() {
     140  /*int idx = verticalHeaderItem(row)->data(Qt::UserRole).toInt();
    114141  molecule *mol = molecules->ReturnIndex(idx);
    115142  string cellValue = item(row,NAME)->text().toStdString();
     
    119146  else if(cellValue==""){
    120147    item(row,NAME)->setText(QString(mol->getName().c_str()));
    121   }
     148  }*/
    122149}
    123150
    124151
    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);
     152void 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        }
    140182      }
    141       else{
    142         emit moleculeUnSelected(mol);
    143       }
    144       molSelection[i]=state;
    145183    }
    146184  }
  • src/UIElements/Views/Qt4/QtWorldView.hpp

    rc0ed1e r53059e  
    1515
    1616
    17 #include <QtGui/QTableWidget>
     17#include <QtGui/QTreeWidget>
    1818#include "CodePatterns/Observer/Observer.hpp"
    1919
     
    2121class MoleculeListClass;
    2222
    23 class QtWorldView : public QTableWidget, public Observer
     23class QtWorldView : public QTreeWidget, public Observer
    2424{
    2525  Q_OBJECT
     
    3232  virtual void update(Observable *publisher);
    3333  virtual void subjectKilled(Observable *publisher);
     34  virtual void paintEvent(QPaintEvent * event);
     35  void refill();
    3436
    3537  static const int COLUMNCOUNT;
    36   enum {NAME,ATOMCOUNT,FORMULA,COLUMNTYPES_MAX} COLUMNTYPES;
     38  enum {NAME,ATOMCOUNT,FORMULA,OCCURRENCE,COLUMNTYPES_MAX} COLUMNTYPES;
    3739  static const char *COLUMNNAMES[];
    3840
    3941private slots:
    40   void moleculeChanged(int row, int column);
     42  void moleculeChanged();
    4143
    42   void cellSelected(int row, int column);
     44  void rowSelected();
    4345
    4446signals:
     
    4951  std::vector<bool> molSelection; //!< needed to determine when a selection changes
    5052  MoleculeListClass *molecules;
     53  bool dirty;
    5154};
    5255
  • src/World.cpp

    rc0ed1e r53059e  
    414414
    415415void World::clearAtomSelection(){
     416  OBSERVE;
     417  NOTIFY(SelectionChanged);
    416418  selectedAtoms.clear();
    417419}
     
    433435
    434436void World::selectAtom(const atom *_atom){
     437  OBSERVE;
     438  NOTIFY(SelectionChanged);
    435439  // atom * is unchanged in this function, but we do store entity as changeable
    436440  ASSERT(_atom,"Invalid pointer in selection of atom");
     
    439443
    440444void World::selectAtom(const atomId_t id){
     445  OBSERVE;
     446  NOTIFY(SelectionChanged);
    441447  ASSERT(atoms.count(id),"Atom Id selected that was not in the world");
    442448  selectedAtoms[id]=atoms[id];
     
    444450
    445451void World::selectAllAtoms(AtomDescriptor descr){
     452  OBSERVE;
     453  NOTIFY(SelectionChanged);
    446454  internal_AtomIterator begin = getAtomIter_internal(descr);
    447455  internal_AtomIterator end = atomEnd_internal();
     
    451459
    452460void World::selectAtomsOfMolecule(const molecule *_mol){
     461  OBSERVE;
     462  NOTIFY(SelectionChanged);
    453463  ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
    454464  // need to make it const to get the fast iterators
     
    459469
    460470void World::selectAtomsOfMolecule(const moleculeId_t id){
     471  OBSERVE;
     472  NOTIFY(SelectionChanged);
    461473  ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
    462474  selectAtomsOfMolecule(molecules[id]);
     
    464476
    465477void World::unselectAtom(const atom *_atom){
     478  OBSERVE;
     479  NOTIFY(SelectionChanged);
    466480  ASSERT(_atom,"Invalid pointer in unselection of atom");
    467481  unselectAtom(_atom->getId());
     
    469483
    470484void World::unselectAtom(const atomId_t id){
     485  OBSERVE;
     486  NOTIFY(SelectionChanged);
    471487  ASSERT(atoms.count(id),"Atom Id unselected that was not in the world");
    472488  selectedAtoms.erase(id);
     
    474490
    475491void World::unselectAllAtoms(AtomDescriptor descr){
     492  OBSERVE;
     493  NOTIFY(SelectionChanged);
    476494  internal_AtomIterator begin = getAtomIter_internal(descr);
    477495  internal_AtomIterator end = atomEnd_internal();
     
    481499
    482500void World::unselectAtomsOfMolecule(const molecule *_mol){
     501  OBSERVE;
     502  NOTIFY(SelectionChanged);
    483503  ASSERT(_mol,"Invalid pointer to molecule in selection of Atoms of Molecule");
    484504  // need to make it const to get the fast iterators
     
    489509
    490510void World::unselectAtomsOfMolecule(const moleculeId_t id){
     511  OBSERVE;
     512  NOTIFY(SelectionChanged);
    491513  ASSERT(molecules.count(id),"No molecule with the given id upon Selection of atoms from molecule");
    492514  unselectAtomsOfMolecule(molecules[id]);
     
    521543
    522544void World::clearMoleculeSelection(){
     545  OBSERVE;
     546  NOTIFY(SelectionChanged);
    523547  selectedMolecules.clear();
    524548}
     
    541565
    542566void World::selectMolecule(const molecule *_mol){
     567  OBSERVE;
     568  NOTIFY(SelectionChanged);
    543569  // molecule * is unchanged in this function, but we do store entity as changeable
    544570  ASSERT(_mol,"Invalid pointer to molecule in selection");
     
    547573
    548574void World::selectMolecule(const moleculeId_t id){
     575  OBSERVE;
     576  NOTIFY(SelectionChanged);
    549577  ASSERT(molecules.count(id),"Molecule Id selected that was not in the world");
    550578  selectedMolecules[id]=molecules[id];
     
    552580
    553581void World::selectAllMolecules(MoleculeDescriptor descr){
     582  OBSERVE;
     583  NOTIFY(SelectionChanged);
    554584  internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
    555585  internal_MoleculeIterator end = moleculeEnd_internal();
     
    559589
    560590void World::selectMoleculeOfAtom(const atom *_atom){
     591  OBSERVE;
     592  NOTIFY(SelectionChanged);
    561593  ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
    562594  molecule *mol=_atom->getMolecule();
     
    568600
    569601void World::selectMoleculeOfAtom(const atomId_t id){
     602  OBSERVE;
     603  NOTIFY(SelectionChanged);
    570604  ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
    571605  selectMoleculeOfAtom(atoms[id]);
     
    573607
    574608void World::unselectMolecule(const molecule *_mol){
     609  OBSERVE;
     610  NOTIFY(SelectionChanged);
    575611  ASSERT(_mol,"invalid pointer in unselection of molecule");
    576612  unselectMolecule(_mol->getId());
     
    578614
    579615void World::unselectMolecule(const moleculeId_t id){
     616  OBSERVE;
     617  NOTIFY(SelectionChanged);
    580618  ASSERT(molecules.count(id),"No such molecule with ID in unselection");
    581619  selectedMolecules.erase(id);
     
    583621
    584622void World::unselectAllMolecules(MoleculeDescriptor descr){
     623  OBSERVE;
     624  NOTIFY(SelectionChanged);
    585625  internal_MoleculeIterator begin = getMoleculeIter_internal(descr);
    586626  internal_MoleculeIterator end = moleculeEnd_internal();
     
    590630
    591631void World::unselectMoleculeOfAtom(const atom *_atom){
     632  OBSERVE;
     633  NOTIFY(SelectionChanged);
    592634  ASSERT(_atom,"Invalid atom pointer in selection of MoleculeOfAtom");
    593635  molecule *mol=_atom->getMolecule();
     
    599641
    600642void World::unselectMoleculeOfAtom(const atomId_t id){
     643  OBSERVE;
     644  NOTIFY(SelectionChanged);
    601645  ASSERT(atoms.count(id),"No such atom with given ID in selection of Molecules of Atom");\
    602646  unselectMoleculeOfAtom(atoms[id]);
  • src/World.hpp

    rc0ed1e r53059e  
    115115    MoleculeInserted,
    116116    MoleculeRemoved,
     117    SelectionChanged,
    117118    NotificationType_MAX
    118119  };
  • src/molecule.cpp

    rc0ed1e r53059e  
    729729void molecule::SetNameFromFilename(const char *filename)
    730730{
     731  OBSERVE;
    731732  int length = 0;
    732733  const char *molname = strrchr(filename, '/');
Note: See TracChangeset for help on using the changeset viewer.