Changeset 917659


Ignore:
Timestamp:
Sep 29, 2013, 11:40:49 AM (11 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:
c60665
Parents:
beadd0
git-author:
Frederik Heber <heber@…> (09/05/13 07:07:45)
git-committer:
Frederik Heber <heber@…> (09/29/13 11:40:49)
Message:

FIX: GLMoleculeObject_atom just stores the atom's id, now ptr.

Location:
src/UIElements/Views/Qt4/Qt3D
Files:
3 edited

Legend:

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

    rbeadd0 r917659  
    5353#include "WorldTime.hpp"
    5454
    55 GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atom *atomref) :
     55GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t _id) :
    5656  GLMoleculeObject(mesh, parent),
    57   Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())),
    58   _atom(atomref)
     57  Observer(std::string("GLMoleculeObject_atom")+toString(_id)),
     58  atomicid(_id)
    5959{
    6060  // sign on as observer (obtain non-const instance before)
    61   atomref->signOn(this, AtomObservable::IndexChanged);
    62   atomref->signOn(this, AtomObservable::PositionChanged);
    63   atomref->signOn(this, AtomObservable::ElementChanged);
    64   atomref->signOn(this, AtomObservable::BondsAdded);
     61  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     62  if (_atom != NULL) {
     63    _atom->signOn(this, AtomObservable::IndexChanged);
     64    _atom->signOn(this, AtomObservable::PositionChanged);
     65    _atom->signOn(this, AtomObservable::ElementChanged);
     66    _atom->signOn(this, AtomObservable::BondsAdded);
     67  } else {
     68    ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
     69  }
    6570  World::getInstance().signOn(this, World::SelectionChanged);
    6671  WorldTime::getInstance().signOn(this, WorldTime::TimeChanged);
     
    6974  resetProperties();
    7075
    71   LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
     76  LOG(2, "INFO: Created sphere for atom " << atomicid << ".");
    7277
    7378  connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
     
    7681GLMoleculeObject_atom::~GLMoleculeObject_atom()
    7782{
    78   if (_atom){
     83  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     84  if (_atom != NULL){
    7985    _atom->signOff(this, AtomObservable::IndexChanged);
    8086    _atom->signOff(this, AtomObservable::PositionChanged);
     
    8995{
    9096#ifdef LOG_OBSERVER
    91   observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(_atom->getId())+".";
     97  observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(static_cast<Observer *>(this)) << " from atom "+toString(atomicid)+".";
    9298#endif
    9399  resetProperties();
     
    96102void GLMoleculeObject_atom::resetPosition()
    97103{
    98   const Vector Position = _atom->getPosition();
    99   LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
    100   setPosition(QVector3D(Position[0], Position[1], Position[2]));
     104  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     105  if (_atom != NULL) {
     106    const Vector Position = _atom->getPosition();
     107    LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
     108    setPosition(QVector3D(Position[0], Position[1], Position[2]));
     109  } else {
     110    ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
     111  }
    101112}
    102113
     
    104115{
    105116  size_t elementno = 0;
    106   if (_atom->getType() != NULL) {
    107     elementno = _atom->getType()->getAtomicNumber();
    108   } else { // if no element yet, set to hydrogen
    109     elementno = 1;
    110   }
    111   LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
    112 
    113   // set materials
    114   QGLMaterial *elementmaterial = getMaterial(elementno);
    115   ASSERT(elementmaterial != NULL,
    116       "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
    117   setMaterial(elementmaterial);
    118 
    119   // set scale
    120   double radius = 0.;
    121   if (_atom->getType() != NULL) {
    122     radius = _atom->getType()->getVanDerWaalsRadius();
    123   } else {
    124     radius = 0.5;
    125   }
    126   setScale( radius / 4. );
     117  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     118  if (_atom != NULL) {
     119    const element *_type = _atom->getType();
     120    if (_type != NULL) {
     121      elementno = _type->getAtomicNumber();
     122    } else { // if no element yet, set to hydrogen
     123      elementno = 1;
     124    }
     125    LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
     126
     127    // set materials
     128    QGLMaterial *elementmaterial = getMaterial(elementno);
     129    ASSERT(elementmaterial != NULL,
     130        "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
     131    setMaterial(elementmaterial);
     132
     133    // set scale
     134    double radius = 0.;
     135    if (_type != NULL) {
     136      radius = _type->getVanDerWaalsRadius();
     137    } else {
     138      radius = 0.5;
     139    }
     140    setScale( radius / 4. );
     141  } else {
     142    ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
     143  }
    127144}
    128145
     
    130147{
    131148  int oldId = objectId();
    132   const size_t atomno = _atom->getId();
    133   LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
    134   setObjectId(atomno);
    135 
    136   emit indexChanged(this, oldId, atomno);
     149  LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomicid)+".");
     150  setObjectId(atomicid);
     151
     152  emit indexChanged(this, oldId, atomicid);
    137153}
    138154
     
    149165
    150166  // selected?
    151   setSelected(World::getInstance().isSelected(_atom));
     167  setSelected(World::getInstance().isAtomSelected(atomicid));
    152168}
    153169
    154170void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
    155171{
    156   _atom = NULL;
     172  // remove id such that we don't sign off accidentally from a different atom
     173  const_cast<atomId_t &>(atomicid) = -1;
    157174}
    158175
    159176void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
    160177{
     178  const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
    161179  if (publisher == dynamic_cast<const Observable*>(_atom)){
    162180    // notofication from atom
     
    180198      case AtomObservable::BondsAdded:
    181199      {
     200        const atom *_atom = World::getInstance().getAtom(AtomById(atomicid));
     201        if (_atom != NULL) {
    182202          ASSERT(!_atom->getListOfBonds().empty(),
    183203              "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
     
    186206              GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
    187207          emit BondsInserted(_bond, side);
    188           break;
     208        } else {
     209          ELOG(2, "Atom with id "+toString(atomicid)+" is already gone.");
    189210        }
     211        break;
     212      }
    190213      default:
    191214        //setProperties();
     
    226249void GLMoleculeObject_atom::wasClicked()
    227250{
    228   LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
    229   emit clicked(_atom->getId());
    230 }
     251  LOG(4, "INFO: GLMoleculeObject_atom: atom " << atomicid << " has been clicked");
     252  emit clicked(atomicid);
     253}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    rbeadd0 r917659  
    1919
    2020#include "Bond/bond.hpp"
    21 #include "GLMoleculeObject_bond.hpp"
    22 
    23 class atom;
     21#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
     22#include "types.hpp"
    2423
    2524class GLMoleculeObject_atom : public GLMoleculeObject, public Observer
     
    2726  Q_OBJECT
    2827public:
    29   GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atom *atomref);
     28  GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atomId_t id);
    3029  virtual ~GLMoleculeObject_atom();
    3130
     
    5150  void resetProperties();
    5251
    53   const atom *_atom;
     52  const atomId_t atomicid;
    5453};
    5554
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    rbeadd0 r917659  
    145145{
    146146  LOG(3, "INFO: GLWorldScene: Received signal atomInserted for atom "+toString(_id)+".");
    147   const atom *_atom = World::getInstance().getAtom(AtomById(_id));
    148   GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(meshSphere, this, _atom);
     147  GLMoleculeObject_atom *atomObject = new GLMoleculeObject_atom(meshSphere, this, _id);
    149148  AtomNodeMap::iterator iter = AtomsinSceneMap.find(_id);
    150149  ASSERT(iter == AtomsinSceneMap.end(),
    151       "GLWorldScene::atomAdded() - same atom "+_atom->getName()+" added again.");
     150      "GLWorldScene::atomAdded() - same atom "+toString(_id)+" added again.");
    152151  AtomsinSceneMap.insert( make_pair(_id, atomObject) );
    153152
Note: See TracChangeset for help on using the changeset viewer.