Ignore:
Timestamp:
Apr 20, 2016, 11:07:46 PM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
7f185f9
Parents:
785d89
git-author:
Frederik Heber <heber@…> (04/12/16 08:51:06)
git-committer:
Frederik Heber <heber@…> (04/20/16 23:07:46)
Message:

Only GLWorldScene creates stuff, GLMoleculeObject_.. are just visual reps.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r785d89 rf1b5ca  
    4343
    4444#include "CodePatterns/MemDebug.hpp"
    45 
    46 #include <boost/assign.hpp>
    4745
    4846#include "CodePatterns/Assert.hpp"
     
    6159#include "World.hpp"
    6260
    63 using namespace boost::assign;
    64 
    65 static Observable::channels_t getAllAtomicChangesChannels()
    66 {
    67   Observable::channels_t channels;
    68   channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
    69   return channels;
    70 }
    71 
    72 const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    73 
    7461static QGLSceneNode *createMoleculeMesh(const QGeometryData &_geo)
    7562{
     
    8370GLMoleculeObject_molecule::GLMoleculeObject_molecule(
    8471    QObject *parent,
    85     QtObservedInstanceBoard &_board,
    8672    QtObservedMolecule::ptr &_ObservedMolecule) :
    8773  GLMoleculeObject((QGLSceneNode *)NULL, parent),
    88   owner(NULL),
    8974  hoverAtomId(-1),
    90   board(_board),
    9175  ObservedMolecule(_ObservedMolecule)
    9276{
     
    9781    QGLSceneNode *mesh[],
    9882    QObject *parent,
    99     QtObservedInstanceBoard &_board,
    10083    QtObservedMolecule::ptr &_ObservedMolecule) :
    10184  GLMoleculeObject(mesh, parent),
    102   owner(NULL),
    10385  hoverAtomId(-1),
    104   board(_board),
    10586  ObservedMolecule(_ObservedMolecule)
    10687{
     
    11899  m_visible = false;
    119100
    120   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    121   connect (this, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    122101  connect (ObservedMolecule.get(), SIGNAL(tesselationhullChanged()), this, SLOT(resetTesselationHull()));
    123102  connect (ObservedMolecule.get(), SIGNAL(boundingboxChanged()), this, SLOT(resetBoundingBox()));
     
    130109//      this, SLOT(atomRemoved(const atomId_t)) );
    131110  connect (ObservedMolecule.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
    132 
    133   connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
    134111}
    135112
     
    152129  // check minimum bond radius in molecule
    153130  double minlength = std::numeric_limits<double>::max();
     131  size_t NoAtoms = 0;
    154132  for (molecule::const_iterator iter = molref->begin();
    155133      iter != molref->end(); ++iter) {
     
    160138      minlength = std::min(bond_distance, minlength);
    161139    }
     140    ++NoAtoms;
    162141  }
    163142  minradius = std::max( std::max(minradius, minlength), 1.);
    164143
    165144  // we need at least three points for tesselation
    166   if (AtomsinSceneMap.size() >= 3) {
     145  if (NoAtoms >= 3) {
    167146    // Tesselate the points.
    168147    Tesselation T;
     
    218197void GLMoleculeObject_molecule::resetTesselationHull()
    219198{
    220   if (owner != NULL) {
    221     TesselationHull = updateTesselationHull();
    222     updateMesh(createMoleculeMesh(TesselationHull));
    223   }
     199  TesselationHull = updateTesselationHull();
     200  updateMesh(createMoleculeMesh(TesselationHull));
    224201}
    225202
     
    334311}
    335312
    336 /** Adds an atom of this molecule to the scene.
    337  *
    338  * @param _atom atom to add
    339  */
    340 void GLMoleculeObject_molecule::atomInserted(QtObservedAtom::ptr _atom)
    341 {
    342   const ObservedValue_Index_t atomid = _atom->getIndex();
    343   LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomInserted for atom "
    344       << _atom->getAtomIndex());
    345 
    346   if (_atom) {
    347     GLMoleculeObject_atom *atomObject =
    348         new GLMoleculeObject_atom(
    349             GLMoleculeObject::meshSphere,
    350             this,
    351             _atom);
    352     ASSERT( atomObject != NULL,
    353         "GLMoleculeObject_molecule::atomInserted - could not create atom object for "
    354         +toString(_atom->getAtomIndex()));
    355     AtomNodeMap::iterator iter = AtomsinSceneMap.find(atomid);
    356     ASSERT(iter == AtomsinSceneMap.end(),
    357         "GLMoleculeObject_molecule::atomInserted - same atom with id "
    358         +toString(_atom->getAtomIndex())+" added again.");
    359     AtomsinSceneMap.insert( make_pair(atomid, atomObject) );
    360 
    361     qRegisterMetaType<atomId_t>("atomId_t");
    362     qRegisterMetaType<GLMoleculeObject_bond::SideOfBond>("GLMoleculeObject_bond::SideOfBond");
    363     connect (atomObject, SIGNAL(clicked(atomId_t)), this, SIGNAL(atomClicked(atomId_t)));
    364     connect (atomObject, SIGNAL(changed()), this, SIGNAL(changed()));
    365     connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SIGNAL(changed()));
    366     connect (atomObject, SIGNAL(hoverChanged(GLMoleculeObject *)), this, SLOT(hoverChangedSignalled(GLMoleculeObject *)));
    367 
    368     if (m_objectId  == -1)
    369       setObjectId(_atom->getAtomIndex());
    370 
    371     emit changed();
    372     emit changeOccured();
    373   }
    374 }
    375 
    376 /** Removes an atom of this molecule from the scene.
    377  *
    378  * We just the id as the atom might have already been destroyed.
    379  *
    380  * @param _id id of atom to remove
    381  */
    382 void GLMoleculeObject_molecule::atomRemoved(ObservedValue_Index_t _id)
    383 {
    384   LOG(3, "INFO: GLMoleculeObject_molecule: Received signal atomRemoved for atom "+toString(_id)+".");
    385   // bonds are removed by signal coming from ~bond
    386 
    387   // remove atoms
    388   AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
    389   ASSERT(iter != AtomsinSceneMap.end(),
    390       "GLMoleculeObject_molecule::atomRemoved() - atom "+toString(_id)+" not on display.");
    391   GLMoleculeObject_atom *atomObject = iter->second;
    392   AtomsinSceneMap.erase(iter);
    393   atomObject->disconnect();
    394   delete atomObject;
    395 
    396   emit changed();
    397   emit changeOccured();
    398 
    399   if (AtomsinSceneMap.empty())
    400     emit moleculeEmptied(ObservedMolecule);
    401 }
    402 
    403 void GLMoleculeObject_molecule::hoverChangedSignalled(GLMoleculeObject *ob)
    404 {
    405   // Find the atom, ob corresponds to.
    406   hoverAtomId = -1;
    407   GLMoleculeObject_atom *atomObject = dynamic_cast<GLMoleculeObject_atom *>(ob);
    408   if (atomObject){
    409     for (AtomNodeMap::iterator iter = AtomsinSceneMap.begin();iter != AtomsinSceneMap.end(); ++ iter){
    410       if (iter->second == atomObject)
    411         hoverAtomId = iter->second->objectId();
    412     }
    413 
    414     // Propagate signal.
    415     emit hoverChanged(hoverAtomId);
    416   } else {
    417     // Find the atom, ob corresponds to.
    418     GLMoleculeObject_molecule *moleculeObject = dynamic_cast<GLMoleculeObject_molecule *>(ob);
    419     if (moleculeObject == this){
    420       // Propagate signal.
    421       emit hoverChanged(ObservedMolecule->getMolIndex(), 0);
    422     }
    423   }
    424 }
    425 
    426 /** Adds a bond to the scene.
    427  *
    428  * @param _bond bond to add
    429  */
    430 void GLMoleculeObject_molecule::bondInserted(
    431     QtObservedBond::ptr _bond)
    432 {
    433   static const std::vector< GLMoleculeObject_bond::SideOfBond > bondsides =
    434       boost::assign::list_of<GLMoleculeObject_bond::SideOfBond>
    435           (GLMoleculeObject_bond::left)
    436           (GLMoleculeObject_bond::right);
    437   LOG(3, "INFO: GLWorldScene::bondInserted() - Adding bonds " << _bond->getBondIndex());
    438   //LOG(4, "INFO: Currently present bonds " << BondsinSceneMap << ".");
    439 
    440   const ObservedValue_Index_t bondid = _bond->getIndex();
    441   const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
    442       BondsinSceneMap.equal_range(bondid);
    443   if (iters.first == iters.second) {
    444     for (size_t i=0;i<2;++i) {
    445       GLMoleculeObject_bond * bondObject =
    446           new GLMoleculeObject_bond(GLMoleculeObject::meshCylinder, this, _bond, bondsides[i]);
    447       connect (bondObject, SIGNAL(changed()), this, SIGNAL(changed()));
    448       BondsinSceneMap.insert( std::make_pair(bondid, bondObject) );
    449     }
    450   } else {
    451     for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
    452       iter->second->resetPosition();
    453       iter->second->resetWidth();
    454     }
    455   }
    456   emit changed();
    457   emit changeOccured();
    458 }
    459 
    460 /** Removes a bond from the scene.
    461  *
    462  * @param _bond bond to remove
    463  */
    464 void GLMoleculeObject_molecule::bondRemoved(ObservedValue_Index_t _id)
    465 {
    466   LOG(3, "INFO: GLWorldScene::bondRemoved() - Removing bond to id " << _id);
    467   {
    468     // left bond
    469     const std::pair<BondNodeMap::iterator, BondNodeMap::iterator> iters =
    470         BondsinSceneMap.equal_range(_id);
    471     for (BondNodeMap::iterator iter = iters.first; iter != iters.second; ++iter) {
    472       GLMoleculeObject_bond *bondObject = iter->second;
    473       bondObject->disconnect();
    474       delete bondObject; // is done by signal from bond itself
    475       //LOG(4, "INFO: Still present bonds " << BondsinSceneMap << ".");
    476     }
    477     BondsinSceneMap.erase(_id);
    478   }
    479 
    480   emit changed();
    481   emit changeOccured();
    482 }
    483 
    484313void GLMoleculeObject_molecule::setVisible(bool value)
    485314{
     
    499328  return ost;
    500329}
    501 
    502 void GLMoleculeObject_molecule::wasClicked()
    503 {
    504   LOG(4, "INFO: GLMoleculeObject_molecule: atom "
    505       << ObservedMolecule->getMolIndex() << " has been clicked");
    506   emit moleculeClicked(ObservedMolecule->getMolIndex());
    507 }
Note: See TracChangeset for help on using the changeset viewer.