Changeset e6a9c1


Ignore:
Timestamp:
Mar 4, 2010, 10:40:52 AM (15 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, 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:
63b56a7
Parents:
6a661c (diff), 66e95e (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 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am

Location:
src
Files:
8 added
18 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/Actions/Calculation.hpp

    r6a661c re6a9c1  
    1111#include "Actions/Process.hpp"
    1212
     13/**
     14 * A calculation is a Process that has some kind of result.
     15 *
     16 * This class can be used in the same way as any other Action or Process, but has some special methods
     17 * for inspecting the result of the calculation.
     18 */
    1319template<typename T>
    1420class Calculation : public Process
     
    1824  virtual ~Calculation();
    1925
     26  /**
     27   * Reimplemented call method for Action Base class.
     28   * Resets the result and then redoes the calculation. Can be used to retrigger calculations
     29   * from menu Items or other places.
     30   */
    2031  virtual void call();
    2132  virtual void undo();
    2233  virtual bool canUndo();
    2334
     35  /**
     36   * Does the actual calculation and returns the result.
     37   * When the calculation has been done before it is not redone, but the previous cached result is returned.
     38   * Call reset to delete the cached value.
     39   */
    2440  virtual T operator()();
     41
     42  /**
     43   * Check if a cached result is available.
     44   */
    2545  virtual bool hasResult();
     46
     47  /**
     48   * Get the cached result.
     49   * Fails if there is no cached result.
     50   */
    2651  virtual T getResult();
     52
     53  /**
     54   * Delete a previously calculated result from the cache.
     55   */
    2756  virtual void reset();
    2857
    2958protected:
    3059  T* result;
     60
     61  /**
     62   * Pure virtual method for implementation of the actual calculation procedure.
     63   */
    3164  virtual T* doCalc()=0;
    3265private:
  • src/Actions/Process.cpp

    r6a661c re6a9c1  
    7272  {
    7373    OBSERVE;
    74     active = true;
    7574    currStep=0;
    7675  }
    7776  starts = false;
     77  active = true;
    7878}
    7979
     
    8484
    8585void Process::stop(){
     86  active=false;
    8687  stops = true;
    8788  {
    8889    OBSERVE;
    8990    currStep=0;
    90     active=false;
    9191  }
    9292  {
  • src/Actions/Process.hpp

    r6a661c re6a9c1  
    1919#include "Actions/Action.hpp"
    2020
     21/**
     22 * A Process is an Action that might take some time and therefore has special
     23 * methods to allow communication with progress indicators. Indicators
     24 * can sign on at a global place and will be notified when any process is doing
     25 * a calculation.
     26 *
     27 * A Process has four states:
     28 *  - starting: It is in the process of setting itself up, and wants everybody to know that it will start
     29 *              the calculation soon. Indicators should set up anything they need for displaying the progress
     30 *              when they are notified by a process in this state.
     31 *  - active:   The process is currently doing it's thing and wants any indicator to know it's status, i.e.
     32 *              the percentage done.
     33 *  - stopping: The process has fullfilled it's purpose and is shutting down. Indicators recieving this status
     34 *              should also use it to shut down their indication mechanism and delete any objects allocated for
     35 *              this Process
     36 *  - inactive: This Process is currently sleeping. If a Process is sending out any signals in this state, there
     37 *              is something seriously wrong.
     38 */
    2139class Process : public Action, public Observable
    2240{
  • src/Descriptors/AtomDescriptor.hpp

    r6a661c re6a9c1  
    2121class AtomDescripter_impl;
    2222
     23/**
     24 * An AtomDescriptor describes a Set of Atoms from the World. Can be used for any method that needs to work on
     25 * a specific set of Atoms.
     26 *
     27 * This Class is implemented using the PIMPL-Idion, i.e. this class only contains an abstract structure
     28 * that forwards any request to a wrapped pointer-to-implementation. This way operators and calculations
     29 * on Descriptors are possible.
     30 *
     31 * Concrete Implementation Objects can be shared between multiple Wrappers, so make sure that
     32 * any Implementation remainst constant during lifetime.
     33 */
    2334class AtomDescriptor {
    2435  // close coupling to the world to allow access
     
    3243
    3344public:
    34   typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr;
     45  typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type
    3546
    3647  AtomDescriptor(impl_ptr);
     48
     49  /**
     50   * Copy constructor.
     51   * Takes the Implementation from the copied object and sets it's own pointer to link there.
     52   * This way the actuall implementation object is shared between copy and original
     53   */
    3754  AtomDescriptor(const AtomDescriptor&);
    3855  ~AtomDescriptor();
    3956
     57  /**
     58   * Assignment Operator.
     59   *
     60   * Implemented by setting the pointer to the new Implementation.
     61   */
    4062  AtomDescriptor &operator=(AtomDescriptor &);
    4163
    4264protected:
     65  /**
     66   * forward Method to implementation
     67   */
    4368  atom* find();
     69
     70  /**
     71   * forward Method to implementation
     72   */
    4473  std::vector<atom*> findAll();
     74
     75  /**
     76   * Return the implementation this Wrapper currently points to.
     77   * Used for copying, assignment and in Iterators over subsets of the World.
     78   */
    4579  impl_ptr get_impl() const;
    4680
     
    4983};
    5084
    51 // Functions to construct actual descriptors
     85/**
     86 * produce an Atomdescriptor that at the point of construction contains an implementation that matches all Atoms
     87 */
    5288AtomDescriptor AllAtoms();
     89
     90/**
     91 * produce an Atomdescriptor that at the point of construction contains an implementation that matches no Atoms
     92 */
    5393AtomDescriptor NoAtoms();
    5494
    55 // no true short circuit, but the test of the second descriptor wont be done
     95/**
     96 * Set Intersection for two Atomdescriptors. The resulting Atomdescriptor will only match an Atom if both
     97 * given Atomdescriptors also match. Uses short circuit inside, so the second predicate wont be called
     98 * when the first one failed.
     99 */
    56100AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     101
     102/**
     103 * Set Union for two AtomDescriptors. The resulting AtomDescriptor will match an Atom if at least one of
     104 * the two given AtomDescriptors does match. Used short circuit inside, so the second predicate wont
     105 * be called when the first one failed.
     106 */
    57107AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     108
     109/**
     110 * Set inversion for an AtomDescriptor. Matches an Atom if the given AtomDescriptor did not match.
     111 */
    58112AtomDescriptor operator!(const AtomDescriptor &arg);
    59113
  • src/Descriptors/AtomDescriptor_impl.hpp

    r6a661c re6a9c1  
    55
    66/************************ Declarations of implementation Objects ************************/
     7
     8/**
     9 * This class implements a general Base class for AtomDescriptors using the PIMPL-Idiom
     10 *
     11 * The predicate for this class is empty and should be implemented by derived classes.
     12 * By the predicate it is described which atoms should be picked for a given descriptor.
     13 */
    714
    815class AtomDescriptor_impl
     
    1421  virtual ~AtomDescriptor_impl();
    1522
     23  /**
     24   * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms
     25   */
    1626  virtual bool predicate(std::pair<atomId_t,atom*>)=0;
    1727
    1828protected:
     29
     30  /**
     31   * This method is called when the Descriptor is used to find the first matching
     32   * Atom. Walks through all Atoms and stops on the first match. Can be implemented
     33   * when the searched Atom can be found in a more efficient way. Calculated
     34   * Atomdescriptors will always use this method, so no improvement there.
     35   */
    1936  virtual atom* find();
     37
     38  /**
     39   * This method is called when the Descriptor is used to find all matching Atoms.
     40   * Walks through all Atoms and tests the predicate on each one. A vector of all
     41   * matching Atoms is returned.
     42   */
    2043  virtual std::vector<atom*> findAll();
     44
     45  /**
     46   * This method is used internally to query the Set of Atoms from the world.
     47   * By using this method derived classes can also access the Internal World Datastructre.
     48   * Implemented in full in the Base Descriptor Implementation, so only this one method
     49   * needs to be friend with the World class.
     50   */
    2151  World::AtomSet& getAtoms();
    2252};
     
    2454/************************** Universe and Emptyset *****************/
    2555
     56/**
     57 * A simple AtomDescriptor that will always match all Atoms present in the World.
     58 */
    2659class AtomAllDescriptor_impl : public AtomDescriptor_impl {
    2760public:
    2861  AtomAllDescriptor_impl();
    2962  virtual ~AtomAllDescriptor_impl();
     63
     64  /**
     65   * Always returns true for any Atom
     66   */
    3067  virtual bool predicate(std::pair<atomId_t,atom*>);
    3168};
    3269
     70
     71/**
     72 * An AtomDescriptor that never matches any Atom in the World.
     73 */
    3374class AtomNoneDescriptor_impl : public AtomDescriptor_impl {
    3475public:
    3576  AtomNoneDescriptor_impl();
    3677  virtual ~AtomNoneDescriptor_impl();
     78
     79  /**
     80   * Always returns false for any Atom
     81   */
    3782  virtual bool predicate(std::pair<atomId_t,atom*>);
    3883};
     
    4085/************************** Operator stuff ************************/
    4186
     87/**
     88 * Intersection of two AtomDescriptors
     89 */
    4290class AtomAndDescriptor_impl : public AtomDescriptor_impl
    4391{
     
    4593  AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    4694  ~AtomAndDescriptor_impl();
     95
     96  /**
     97   * This predicate uses the predicate from the first && the predicate from the
     98   * second Descriptor to decide if an Atom should be selected.
     99   */
    47100  virtual bool predicate(std::pair<atomId_t,atom*>);
    48101
     
    52105};
    53106
     107/**
     108 * Union of two AtomDescriptors
     109 */
    54110class AtomOrDescriptor_impl : public AtomDescriptor_impl
    55111{
     
    57113  AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    58114  virtual ~AtomOrDescriptor_impl();
     115
     116  /**
     117   * This predicate uses the predicate form the first || the predicate from the
     118   * second Descriptor to decide if an Atom should be selected.
     119   */
    59120  virtual bool predicate(std::pair<atomId_t,atom*>);
    60121
     
    64125};
    65126
     127/**
     128 * Set Inversion of a Descriptor
     129 */
    66130class AtomNotDescriptor_impl : public AtomDescriptor_impl
    67131{
     
    70134  virtual ~AtomNotDescriptor_impl();
    71135
     136  /**
     137   * Opposite of the given descriptor predicate.
     138   */
    72139  virtual bool predicate(std::pair<atomId_t,atom*>);
    73140
  • src/Makefile.am

    r6a661c re6a9c1  
    4141QTUIMOC_TARGETS = QTMainWindow.moc.cpp QTMenu.moc.cpp QTDialog.moc.cpp QTMoleculesView.moc.cpp GLMoleculeView.moc.cpp QTStatusBar.moc.cpp
    4242
    43 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp
    44 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp
     43DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp \
     44                                   Descriptors/AtomIdDescriptor.cpp \
     45                                   Descriptors/AtomTypeDescriptor.cpp \
     46                                   Descriptors/MoleculeDescriptor.cpp \
     47                                   Descriptors/MoleculeIdDescriptor.cpp
     48                                   
     49DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \
     50                                   Descriptors/AtomIdDescriptor.hpp \
     51                                   Descriptors/AtomTypeDescriptor.hpp \
     52                                   Descriptors/MoleculeDescriptor.hpp \
     53                                   Descriptors/MoleculeIdDescriptor.hpp
    4554
    4655QTUISOURCE = ${QTUIMOC_TARGETS} UIElements/QT4/QTMainWindow.cpp UIElements/QT4/QTDialog.cpp UIElements/QT4/QTUIFactory.cpp Menu/QT4/QTMenu.cpp Views/QT4/QTMoleculesView.cpp Views/QT4/GLMoleculeView.cpp Views/QT4/QTStatusBar.cpp
  • src/Patterns/Observer.hpp

    r6a661c re6a9c1  
    3030class Observable;
    3131
     32/**
     33 * An Observer is notified by all Observed objects, when anything changes.
     34 *
     35 * If a simple change is done to an Object the Obervable will call the update() method
     36 * of all signed on observers, passing itself as a parameter for identification. The
     37 * Observers should then react to the changes and update themselves accordingly.
     38 *
     39 * If an observed Object is destroyed it will call the subjectKilled() method
     40 * of all signed on Observers, again passing itself as a parameter for identification.
     41 * The Observers should handle the destruction of an observed Object gracefully, i.e.
     42 * set themselves inactive, display something else, etc. There is no need
     43 * to sign of from the dying object, since this will be handled by the Observable destructor.
     44 */
    3245class Observer
    3346{
     
    3851
    3952protected:
     53  /**
     54   * This method is called upon changes of the Observable
     55   */
    4056  virtual void update(Observable *publisher)=0;
     57
     58  /**
     59   * This method is called when the observed object is destroyed.
     60   */
    4161  virtual void subjectKilled(Observable *publisher)=0;
    4262};
    4363
     64/**
     65 * An Observable implements all neccessary method for being observed.
     66 *
     67 * That is, it provides methods for signing on and of from an
     68 * Observable that can be used by any observer. The actual
     69 * observer-mechanism is handled at a central static place
     70 * to avoid memory issues when many observable are around but only few
     71 * are actually observed.
     72 */
    4473class Observable : public Observer {
    4574public:
     
    4776  virtual ~Observable();
    4877
     78  /**
     79   * Sign an Observer on to this Observable. The Observer will be notified
     80   * whenever something inside the Observable changes. The Observer can
     81   * assign itself a priority for the changes in the range of -20:+20.
     82   * The Observer with lower priority will be called before the others,
     83   * same as with Unix nice-levels. This can be used when an Object
     84   * contains other objects that observe it (derived values), and these objects have
     85   * to recalculate their states before the changes should be propageted to the
     86   * UI. A default priority of 0 should be fine in most cases, since there is
     87   * ussually no need to order the update sequence.
     88   */
    4989  virtual void signOn(Observer *target, int priority=0);
     90
     91  /**
     92   * Sign of a previously signed on Observer. After this no more
     93   * updates will be recieved from that observer.
     94   */
    5095  virtual void signOff(Observer *target);
    5196
     
    76121  // Structure for RAII-Style notification
    77122protected:
     123  /**
     124   * This structure implements the Observer-mechanism RAII-Idiom.
     125   * It triggers certain functions on creation and destruction so that
     126   * Observer mechanisms can be linked to scope block.
     127   */
    78128  class _Observable_protector {
    79129  public:
  • src/UIElements/MainWindow.hpp

    r6a661c re6a9c1  
    2525};
    2626
     27/**
     28 * The type of menuPopulators
     29 */
    2730typedef void (*MenuMaker)(Menu*,MoleculeListClass*, config*, periodentafel*);
    2831
     32/**
     33 * This contains all Functions that are used to create the menus.
     34 * Needs a specific funtion for each menu. All populators will be called
     35 * by the UIFactory upon creation of the main menu. Thus the actuall construction
     36 * of the Menus can be kept independent of the concrete type of UI that is being
     37 * built.
     38 */
    2939struct menuPopulaters{
    3040  MenuMaker MakeEditMoleculesMenu;
  • src/UIElements/UIFactory.hpp

    r6a661c re6a9c1  
    1717
    1818struct menuPopulaters;
    19 
     19/**
     20 * Abstract Factory to create any kind of User interface object needed by the programm.
     21 *
     22 * The factory can be created and has to be set to a certain type upon creation. It will then
     23 * only create UIelements of that certain type, so that all UIElements match. This way different
     24 * UIs can be handled in a concise abstract way.
     25 */
    2026class UIFactory
    2127{
     
    3036  virtual ~UIFactory();
    3137
    32   // methods for creating UIElements
     38  /**
     39   * Produce some kind of main window, of whichever type was chosen when the factory was created
     40   */
    3341  virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *)=0;
     42
     43  /**
     44   * Produce a User Interaction Dialog, that can query values from the User.
     45   * Again the type is determined upon factory creation.
     46   */
    3447  virtual Dialog* makeDialog()=0;
    3548
     
    4255
    4356public:
     57  /**
     58   * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory
     59   */
    4460  static void makeUserInterface(InterfaceTypes type);
     61
     62  /**
     63   * get the previously created factory
     64   */
    4565  static UIFactory* get();
     66
     67  /**
     68   * Destroy the created factory.
     69   *
     70   * Make sure that all UIElements that were created by the factory are destroyed before calling this method.
     71   */
    4672  static void purgeInstance();
    4773};
  • src/World.cpp

    r6a661c re6a9c1  
    1313#include "Descriptors/AtomDescriptor.hpp"
    1414#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Descriptors/MoleculeDescriptor.hpp"
     16#include "Descriptors/MoleculeDescriptor_impl.hpp"
    1517#include "Actions/ManipulateAtomsProcess.hpp"
    1618
     
    2224}
    2325
     26// Atoms
     27
    2428atom* World::getAtom(AtomDescriptor descriptor){
    2529  return descriptor.find();
     
    3640int World::numAtoms(){
    3741  return atoms.size();
     42}
     43
     44// Molecules
     45
     46molecule *World::getMolecule(MoleculeDescriptor descriptor){
     47  return descriptor.find();
     48}
     49
     50std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
     51  return descriptor.findAll();
    3852}
    3953
     
    7286atom *World::createAtom(){
    7387  OBSERVE;
    74   atom *res = NewAtom();
    75   assert(!atoms.count(currAtomId));
    76   res->setId(currAtomId++);
     88  atomId_t id = getNextAtomId();
     89  atom *res = NewAtom(id);
    7790  res->setWorld(this);
    7891  // store the atom by ID
     
    8396int World::registerAtom(atom *atom){
    8497  OBSERVE;
    85   assert(!atoms.count(currAtomId));
    86   atom->setId(currAtomId++);
     98  atomId_t id = getNextAtomId();
     99  atom->setId(id);
    87100  atom->setWorld(this);
    88101  atoms[atom->getId()] = atom;
     
    102115  DeleteAtom(atom);
    103116  atoms.erase(id);
     117  releaseAtomId(id);
     118}
     119
     120bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
     121  OBSERVE;
     122  // in case this call did not originate from inside the atom, we redirect it,
     123  // to also let it know that it has changed
     124  if(!target){
     125    target = atoms[oldId];
     126    assert(target && "Atom with that ID not found");
     127    return target->changeId(newId);
     128  }
     129  else{
     130    if(reserveAtomId(newId)){
     131      atoms.erase(oldId);
     132      atoms.insert(pair<atomId_t,atom*>(newId,target));
     133      return true;
     134    }
     135    else{
     136      return false;
     137    }
     138  }
    104139}
    105140
     
    122157  proc->signOff(this);
    123158}
     159/******************************* IDManagement *****************************/
     160
     161// Atoms
     162
     163atomId_t World::getNextAtomId(){
     164  // see if we can reuse some Id
     165  if(atomIdPool.empty()){
     166    return currAtomId++;
     167  }
     168  else{
     169    // we give out the first ID from the pool
     170    atomId_t id = *(atomIdPool.begin());
     171    atomIdPool.erase(id);
     172  }
     173}
     174
     175void World::releaseAtomId(atomId_t id){
     176  atomIdPool.insert(id);
     177  // defragmentation of the pool
     178  set<atomId_t>::reverse_iterator iter;
     179  // go through all Ids in the pool that lie immediately below the border
     180  while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){
     181    atomIdPool.erase(--currAtomId);
     182  }
     183}
     184
     185bool World::reserveAtomId(atomId_t id){
     186  if(id>=currAtomId ){
     187    // add all ids between the new one and current border as available
     188    for(atomId_t pos=currAtomId; pos<id; ++pos){
     189      atomIdPool.insert(pos);
     190    }
     191    currAtomId=id+1;
     192    return true;
     193  }
     194  else if(atomIdPool.count(id)){
     195    atomIdPool.erase(id);
     196    return true;
     197  }
     198  else{
     199    // this ID could not be reserved
     200    return false;
     201  }
     202}
     203
     204// Molecules
    124205
    125206/******************************* Iterators ********************************/
     
    135216World::AtomSet::iterator World::atomEnd(){
    136217  return atoms.end();
     218}
     219
     220World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
     221  return MoleculeIterator(descr,this);
     222}
     223
     224World::MoleculeSet::iterator World::moleculeEnd(){
     225  return molecules.end();
    137226}
    138227
  • src/World.hpp

    r6a661c re6a9c1  
    2727class AtomDescriptor;
    2828class AtomDescriptor_impl;
     29class MoleculeDescriptor;
     30class MoleculeDescriptor_impl;
    2931class ManipulateAtomsProcess;
    3032template<typename T>
     
    3638friend class AtomDescriptor_impl;
    3739friend class AtomDescriptor;
     40friend class MoleculeDescriptor_impl;
     41friend class MoleculeDescriptor;
    3842
    3943// Actions, calculations etc associated with the World
     
    7781
    7882  /**
     83   * returns the first molecule that matches a given descriptor.
     84   * Do not rely on ordering for descriptors that match more than one molecule.
     85   */
     86  molecule *getMolecule(MoleculeDescriptor descriptor);
     87
     88  /**
     89   * returns a vector containing all molecules that match a given descriptor
     90   */
     91  std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
     92
     93  /**
    7994   * get the number of molecules in the World
    8095   */
     
    117132
    118133  /**
     134   * used when changing an atom Id.
     135   * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
     136   *
     137   * Return value indicates wether the change could be done or not.
     138   */
     139  bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
     140
     141  /**
    119142   * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
    120143   * called at this time, so it can be passed around, stored inside menuItems etc.
     
    125148protected:
    126149  /**** Iterators to use internal data structures */
     150
     151  // Atoms
     152
    127153  class AtomIterator {
    128154  public:
     
    163189  AtomSet::iterator atomEnd();
    164190
     191  // Molecules
     192
     193  class MoleculeIterator {
     194  public:
     195    MoleculeIterator();
     196    MoleculeIterator(MoleculeDescriptor, World*);
     197    MoleculeIterator(const MoleculeIterator&);
     198    MoleculeIterator& operator=(const MoleculeIterator&);
     199    MoleculeIterator& operator++();     // prefix
     200    MoleculeIterator  operator++(int);  // postfix with dummy parameter
     201    bool operator==(const MoleculeIterator&);
     202    bool operator==(const MoleculeSet::iterator&);
     203    bool operator!=(const MoleculeIterator&);
     204    bool operator!=(const MoleculeSet::iterator&);
     205    molecule* operator*();
     206
     207    int getCount();
     208  protected:
     209    void advanceState();
     210    MoleculeSet::iterator state;
     211    boost::shared_ptr<MoleculeDescriptor_impl>  descr;
     212    int index;
     213
     214    World* world;
     215  };
     216
     217  /**
     218   * returns an iterator over all Molecules matching a given descriptor.
     219   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     220   */
     221  MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     222
     223  /**
     224   * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
     225   * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
     226   * Thus it can be used to detect when such an iterator is at the end of the list.
     227   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     228   */
     229  MoleculeSet::iterator moleculeEnd();
     230
     231
    165232  /******* Internal manipulation routines for double callback and Observer mechanism ******/
    166233  void doManipulate(ManipulateAtomsProcess *);
    167234
    168235private:
     236
     237  atomId_t getNextAtomId();
     238  void releaseAtomId(atomId_t);
     239  bool reserveAtomId(atomId_t);
     240
    169241  periodentafel *periode;
    170242  AtomSet atoms;
     243  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
    171244  atomId_t currAtomId; //!< stores the next available Id for atoms
    172245  MoleculeSet molecules;
  • src/WorldIterators.cpp

    r6a661c re6a9c1  
    88#include "Descriptors/AtomDescriptor.hpp"
    99#include "Descriptors/AtomDescriptor_impl.hpp"
     10#include "Descriptors/MoleculeDescriptor.hpp"
     11#include "Descriptors/MoleculeDescriptor_impl.hpp"
    1012#include "atom.hpp"
     13#include "molecule.hpp"
    1114#include "World.hpp"
     15
     16/********************** Atoms *************************/
    1217
    1318World::AtomIterator::AtomIterator(){
     
    7681
    7782void World::AtomIterator::advanceState(){
     83  // go forward until we have a matching atom or the end is reached
    7884  while((state!=world->atoms.end()) && (!descr->predicate(*state))){
    7985    ++state;
     
    8591  return index;
    8692}
     93
     94/*********************************** Molecules ************************/
     95
     96World::MoleculeIterator::MoleculeIterator(){
     97  state = World::get()->moleculeEnd();
     98}
     99
     100World::MoleculeIterator::MoleculeIterator(MoleculeDescriptor _descr, World* _world) :
     101    descr(_descr.get_impl()),
     102    index(0),
     103    world(_world)
     104{
     105  state = world->molecules.begin();
     106  advanceState();
     107}
     108
     109World::MoleculeIterator::MoleculeIterator(const MoleculeIterator& rhs) :
     110    state(rhs.state),
     111    descr(rhs.descr),
     112    index(rhs.index),
     113    world(rhs.world)
     114  {}
     115
     116World::MoleculeIterator& World::MoleculeIterator::operator=(const MoleculeIterator& rhs)
     117{
     118  if(&rhs!=this){
     119    state=rhs.state;
     120    descr=rhs.descr;
     121    index=rhs.index;
     122    world=rhs.world;
     123  }
     124  return *this;
     125}
     126
     127World::MoleculeIterator& World::MoleculeIterator::operator++(){
     128  ++state;
     129  ++index;
     130  advanceState();
     131  return *this;
     132}
     133
     134World::MoleculeIterator World::MoleculeIterator::operator++(int){
     135  MoleculeIterator res(*this);
     136  ++(*this);
     137  return res;
     138}
     139
     140bool World::MoleculeIterator::operator==(const MoleculeIterator& rhs){
     141  return state==rhs.state;
     142}
     143
     144bool World::MoleculeIterator::operator==(const World::MoleculeSet::iterator& rhs){
     145  return state==rhs;
     146}
     147
     148bool World::MoleculeIterator::operator!=(const MoleculeIterator& rhs){
     149  return state!=rhs.state;
     150}
     151
     152bool World::MoleculeIterator::operator!=(const World::MoleculeSet::iterator& rhs){
     153  return state!=rhs;
     154}
     155
     156molecule* World::MoleculeIterator::operator*(){
     157  return (*state).second;
     158}
     159
     160void World::MoleculeIterator::advanceState(){
     161  while((state!=world->molecules.end()) && (!descr->predicate(*state))){
     162    ++state;
     163    ++index;
     164  }
     165}
     166
     167int World::MoleculeIterator::getCount(){
     168  return index;
     169}
     170
  • src/atom.cpp

    r6a661c re6a9c1  
    290290}
    291291
    292 void atom::setId(int _id) {
     292bool atom::changeId(atomId_t newId){
     293  // first we move ourselves in the world
     294  // the world lets us know if that succeeded
     295  if(world->changeAtomId(id,newId,this)){
     296    id = newId;
     297    return true;
     298  }
     299  else{
     300    return false;
     301  }
     302}
     303
     304void atom::setId(atomId_t _id) {
    293305  id=_id;
    294306}
    295307
    296 int atom::getId() {
     308atomId_t atom::getId() {
    297309  return id;
    298310}
    299311
    300 atom* NewAtom(){
    301   return new atom();
    302 }
    303 
    304 void  DeleteAtom(atom* atom){
     312atom* NewAtom(atomId_t _id){
     313  atom * res =new atom();
     314  res->setId(_id);
     315  return res;
     316}
     317
     318void DeleteAtom(atom* atom){
    305319  delete atom;
    306320}
  • src/atom.hpp

    r6a661c re6a9c1  
    4040 */
    4141class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo {
    42   friend atom* NewAtom();
     42  friend atom* NewAtom(atomId_t);
    4343  friend void  DeleteAtom(atom*);
    4444  public:
     
    7979  void setWorld(World*);
    8080
    81   virtual int getId();
    82   virtual void setId(int);
     81  virtual atomId_t getId();
     82  virtual bool changeId(atomId_t newId);
     83
     84  /**
     85   * this function sets the Id without notifying the world. Only use it, if the world has already
     86   * gotten an ID for this Atom.
     87   */
     88   virtual void setId(atomId_t);
     89
    8390  protected:
    8491    /**
     
    101108  private:
    102109    World* world;
    103     int id;
     110    atomId_t id;
    104111};
    105112
     
    109116 * Use World::createAtom() instead.
    110117 */
    111 atom* NewAtom();
     118atom* NewAtom(atomId_t _id);
    112119
    113120/**
  • src/molecule_template.hpp

    r6a661c re6a9c1  
    1616#endif
    1717
     18#include "atom.hpp"
    1819/********************************************** declarations *******************************/
    1920
  • src/unittests/AtomDescriptorTest.cpp

    r6a661c re6a9c1  
    66 */
    77
    8 #include "DescriptorUnittest.hpp"
     8#include "AtomDescriptorTest.hpp"
    99
    1010#include <cppunit/CompilerOutputter.h>
     
    2525/********************************************** Test classes **************************************/
    2626// Registers the fixture into the 'registry'
    27 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
     27CPPUNIT_TEST_SUITE_REGISTRATION( AtomDescriptorTest );
    2828
    2929// set up and tear down
    30 void DescriptorUnittest::setUp(){
     30void AtomDescriptorTest::setUp(){
    3131  World::get();
    3232  for(int i=0;i<ATOM_COUNT;++i){
    3333    atoms[i]= World::get()->createAtom();
    34     atomIds[i] = atoms[i]->getId();
     34    atomIds[i]= atoms[i]->getId();
    3535  }
    3636}
    37 void DescriptorUnittest::tearDown(){
     37
     38void AtomDescriptorTest::tearDown(){
    3839  World::destroy();
    3940}
    4041
    4142// some helper functions
    42 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){
     43static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){
    4344  for(int i=0;i<ATOM_COUNT;++i){
    44     int id = ids[i];
     45    atomId_t id = ids[i];
    4546    if(!excluded.count(id)){
    4647      std::vector<atom*>::iterator iter;
     
    5859}
    5960
    60 bool hasNoDuplicates(std::vector<atom*> atoms){
    61   std::set<int> found;
     61static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){
     62  std::set<atomId_t> found;
    6263  std::vector<atom*>::iterator iter;
    6364  for(iter=atoms.begin();iter!=atoms.end();++iter){
     
    7172
    7273
    73 void DescriptorUnittest::AtomBaseSetsTest(){
     74void AtomDescriptorTest::AtomBaseSetsTest(){
    7475  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    75   CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds));
    76   CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
     76  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
     77  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
    7778
    7879  std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms());
    7980  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    8081}
    81 void DescriptorUnittest::AtomIdTest(){
     82void AtomDescriptorTest::AtomIdTest(){
    8283  // test Atoms from boundaries and middle of the set
    8384  atom* testAtom;
     
    9394
    9495  // find some ID that has not been created
    95   int outsideId =-1;
     96  atomId_t outsideId=0;
    9697  bool res = false;
    97   while(!res) {
    98     ++outsideId;
     98  for(outsideId=0;!res;++outsideId) {
    9999    res = true;
    100100    for(int i = 0; i < ATOM_COUNT; ++i){
     
    106106  CPPUNIT_ASSERT(!testAtom);
    107107}
    108 void DescriptorUnittest::AtomCalcTest(){
     108void AtomDescriptorTest::AtomCalcTest(){
    109109  // test some elementary set operations
    110110  {
    111111    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
    112     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    113     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
     112    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
     113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    114114  }
    115115
    116116  {
    117117    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
    118     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    119     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
     118    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
     119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    120120  }
    121121
     
    137137  {
    138138    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
    139     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    140     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
     139    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
     140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    141141  }
    142142
     
    144144  {
    145145    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    146     std::set<int> excluded;
     146    std::set<atomId_t> excluded;
    147147    excluded.insert(atomIds[ATOM_COUNT/2]);
    148     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded));
    149     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
     148    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds,excluded));
     149    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
    150150    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
    151151  }
  • src/unittests/AtomDescriptorTest.hpp

    r6a661c re6a9c1  
    11/*
    2  * DescriptorUnittest.hpp
     2 * AtomDescriptorTest.hpp
    33 *
    44 *  Created on: Feb 9, 2010
     
    66 */
    77
    8 #ifndef DESCRIPTORUNITTEST_HPP_
    9 #define DESCRIPTORUNITTEST_HPP_
     8#ifndef ATOMDESCRIPTORTEST_HPP_
     9#define ATOMDESCRIPTORTEST_HPP_
    1010
    1111#include <cppunit/extensions/HelperMacros.h>
     12
     13#include "defs.hpp"
    1214
    1315#define ATOM_COUNT (10)
     
    1517class atom;
    1618
    17 class DescriptorUnittest : public CppUnit::TestFixture
     19class AtomDescriptorTest : public CppUnit::TestFixture
    1820{
    19   CPPUNIT_TEST_SUITE( DescriptorUnittest );
     21  CPPUNIT_TEST_SUITE( AtomDescriptorTest );
    2022  CPPUNIT_TEST ( AtomBaseSetsTest );
    2123  CPPUNIT_TEST ( AtomIdTest );
     
    3335private:
    3436  atom *atoms [ATOM_COUNT];
    35   int atomIds [ATOM_COUNT];
     37  atomId_t atomIds [ATOM_COUNT];
    3638};
    3739
    38 #endif /* DESCRIPTORUNITTEST_HPP_ */
     40#endif /* ATOMDESCRIPTORTEST_HPP_ */
  • src/unittests/Makefile.am

    r6a661c re6a9c1  
    1313  AnalysisCorrelationToSurfaceUnitTest \
    1414  AnalysisPairCorrelationUnitTest \
     15  atomsCalculationTest \
     16  AtomDescriptorTest \
    1517  BondGraphUnitTest \
     18  CacheableTest \
    1619  GSLMatrixSymmetricUnitTest \
    1720  GSLMatrixUnitTest \
     
    2124  ListOfBondsUnitTest \
    2225  LogUnitTest \
     26  manipulateAtomsTest \
    2327  MemoryUsageObserverUnitTest \
    2428  MemoryAllocatorUnitTest \
     29  MoleculeDescriptorTest \
     30  ObserverTest \
    2531  StackClassUnitTest \
    2632  TesselationUnitTest \
     
    2834  Tesselation_InOutsideUnitTest \
    2935  VectorUnitTest \
    30   ObserverTest \
    31   CacheableTest \
    32   DescriptorUnittest \
    33   manipulateAtomsTest \
    34   atomsCalculationTest \
    3536  ${MENUTESTS}
    3637 
     
    4445TESTSOURCES = \
    4546  ActOnAllUnitTest.cpp \
     47  ActionSequenceTest.cpp \
    4648  analysisbondsunittest.cpp \
    4749  AnalysisCorrelationToPointUnitTest.cpp \
    4850  AnalysisCorrelationToSurfaceUnitTest.cpp  \
    4951  AnalysisPairCorrelationUnitTest.cpp \
     52  AtomDescriptorTest.cpp \
     53  atomsCalculationTest.cpp \
    5054  bondgraphunittest.cpp \
     55  CacheableTest.cpp \
    5156  gslmatrixsymmetricunittest.cpp \
    5257  gslmatrixunittest.cpp \
     
    5661  listofbondsunittest.cpp \
    5762  logunittest.cpp \
     63  manipulateAtomsTest.cpp \
    5864  memoryallocatorunittest.cpp  \
    5965  memoryusageobserverunittest.cpp \
     66  MoleculeDescriptorTest.cpp \
     67  ObserverTest.cpp \
    6068  stackclassunittest.cpp \
    6169  tesselationunittest.cpp \
    6270  tesselation_boundarytriangleunittest.cpp \
    6371  tesselation_insideoutsideunittest.cpp \
    64   vectorunittest.cpp \
    65   ObserverTest.cpp \
    66   CacheableTest.cpp \
    67   DescriptorUnittest.cpp \
    68   manipulateAtomsTest.cpp \
    69   atomsCalculationTest.cpp \
    70   ActionSequenceTest.cpp
     72  vectorunittest.cpp
    7173
    7274TESTHEADERS = \
     
    118120MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS}
    119121
     122MoleculeDescriptorTest_SOURCES = UnitTestMain.cpp MoleculeDescriptorTest.cpp MoleculeDescriptorTest.hpp
     123MoleculeDescriptorTest_LDADD = ${ALLLIBS}
     124
    120125StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
    121126StackClassUnitTest_LDADD = ${ALLLIBS}
     
    142147CacheableTest_LDADD = ${ALLLIBS}
    143148
    144 DescriptorUnittest_SOURCES = UnitTestMain.cpp DescriptorUnittest.cpp DescriptorUnittest.hpp
    145 DescriptorUnittest_LDADD = ${ALLLIBS}
     149AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp
     150AtomDescriptorTest_LDADD = ${ALLLIBS}
    146151
    147152manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
  • src/unittests/atomsCalculationTest.cpp

    r6a661c re6a9c1  
    3030class AtomStub : public atom {
    3131public:
    32   AtomStub(int _id) :
     32  AtomStub(atomId_t _id) :
    3333  atom(),
    3434  id(_id),
     
    3636  {}
    3737
    38   virtual int getId(){
     38  virtual atomId_t getId(){
    3939    return id;
    4040  }
     
    4646  bool manipulated;
    4747private:
    48   int id;
     48  atomId_t id;
    4949};
    5050
  • src/unittests/manipulateAtomsTest.cpp

    r6a661c re6a9c1  
    3434  {}
    3535
    36   virtual int getId(){
     36  virtual atomId_t getId(){
    3737    return id;
    3838  }
     
    4444  bool manipulated;
    4545private:
    46   int id;
     46  atomId_t id;
    4747};
    4848
Note: See TracChangeset for help on using the changeset viewer.