Changeset 957c42 for src/World.cpp


Ignore:
Timestamp:
Feb 25, 2010, 11:15:22 AM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
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, Candidate_v1.7.0, 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:
5a7243
Parents:
0188ea (diff), 244d26 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'StructureRefactoring' into MenuRefactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    r0188ea r957c42  
    1212#include "periodentafel.hpp"
    1313#include "Descriptors/AtomDescriptor.hpp"
     14#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Actions/ManipulateAtomsProcess.hpp"
    1416
    1517using namespace std;
     
    2830}
    2931
     32vector<atom*> World::getAllAtoms(){
     33  return getAllAtoms(AllAtoms());
     34}
     35
    3036int World::numAtoms(){
    3137  return atoms.size();
     
    3642}
    3743
     44/******************** Methods to change World state *********************/
     45
    3846molecule* World::createMolecule(){
    3947  OBSERVE;
     
    4149  mol = new molecule(periode);
    4250  molecules_deprecated->insert(mol);
    43   molecules.insert(mol);
     51  assert(!molecules.count(currMoleculeId));
     52  // store the molecule by ID
     53  molecules[currMoleculeId++] = mol;
    4454  mol->signOn(this);
    4555  return mol;
    4656}
    4757
     58
     59atom *World::createAtom(){
     60  OBSERVE;
     61  atom *res = NewAtom();
     62  assert(!atoms.count(currAtomId));
     63  res->setId(currAtomId++);
     64  res->setWorld(this);
     65  // store the atom by ID
     66  atoms[res->getId()] = res;
     67  return res;
     68}
     69
     70int World::registerAtom(atom *atom){
     71  OBSERVE;
     72  assert(!atoms.count(currAtomId));
     73  atom->setId(currAtomId++);
     74  atom->setWorld(this);
     75  atoms[atom->getId()] = atom;
     76  return atom->getId();
     77}
     78
     79void World::destroyAtom(atom* atom){
     80  OBSERVE;
     81  int id = atom->getId();
     82  destroyAtom(id);
     83}
     84
     85void World::destroyAtom(int id) {
     86  OBSERVE;
     87  atom *atom = atoms[id];
     88  assert(atom);
     89  DeleteAtom(atom);
     90  atoms.erase(id);
     91}
     92
     93ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
     94  return new ManipulateAtomsProcess(op, descr,name,true);
     95}
     96
     97ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
     98  return manipulateAtoms(op,name,AllAtoms());
     99}
     100
     101/********************* Internal Change methods for double Callback and Observer mechanism ********/
     102
     103void World::doManipulate(ManipulateAtomsProcess *proc){
     104  proc->signOn(this);
     105  {
     106    OBSERVE;
     107    proc->doManipulate(this);
     108  }
     109  proc->signOff(this);
     110}
     111
     112/******************************* Iterators ********************************/
     113
     114/*
     115 * Actual Implementation of the iterators can be found in WorldIterators.cpp
     116 */
     117
     118World::AtomIterator World::getAtomIter(AtomDescriptor descr){
     119  return AtomIterator(descr,this);
     120}
     121
     122World::AtomSet::iterator World::atomEnd(){
     123  return atoms.end();
     124}
    48125
    49126/******************************* Singleton Stuff **************************/
     
    53130boost::mutex World::worldLock;
    54131
    55 
    56 
    57132World::World() :
    58     dummyId(0),
     133    currAtomId(0),
     134    currMoleculeId(0),
    59135    periode(new periodentafel),
    60     molecules_deprecated(new MoleculeListClass)
     136    molecules_deprecated(new MoleculeListClass),
     137    atoms(),
     138    molecules()
    61139{
    62140  molecules_deprecated->signOn(this);
     
    65143World::~World()
    66144{
     145  delete molecules_deprecated;
    67146  delete periode;
     147  AtomSet::iterator iter;
     148  for(iter=atoms.begin();iter!=atoms.end();++iter){
     149    DeleteAtom((*iter).second);
     150  }
     151  atoms.clear();
    68152}
    69153
     
    78162
    79163void World::destroy(){
    80   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    81   theWorld->destroyLegacy();
    82   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    83 
    84164  // boost supports RAII-Style locking, so we don't need to unlock
    85165  boost::mutex::scoped_lock guard(worldLock);
     
    89169
    90170World* World::reset(){
    91   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    92   theWorld->destroyLegacy();
    93   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    94 
    95171  World* oldWorld = 0;
    96172  {
     
    119195  return molecules_deprecated;
    120196}
    121 
    122 // some legacy stuff to let the World know about items created outside
    123 void World::registerAtom(atom *theAtom){
    124   OBSERVE;
    125   atoms[dummyId++] = theAtom;
    126 }
    127 
    128 void World::destroyLegacy(){
    129   //delete molecules_deprecated;
    130 }
    131 
    132 void World::unregisterAtom(atom *theAtom){
    133   OBSERVE;
    134   atoms.erase(theAtom->getId());
    135 }
Note: See TracChangeset for help on using the changeset viewer.