- Timestamp:
- Mar 16, 2024, 10:22:34 AM (20 months ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 19832d
- Parents:
- ad0929
- git-author:
- Frederik Heber <frederik.heber@…> (03/16/24 09:26:59)
- git-committer:
- Frederik Heber <frederik.heber@…> (03/16/24 10:22:34)
- Location:
- src
- Files:
-
- 6 edited
-
Actions/AtomAction/BondifyAction.cpp (modified) (12 diffs)
-
Actions/AtomAction/BondifyAction.def (modified) (2 diffs)
-
Actions/UndoRedoHelpers.cpp (modified) (1 diff)
-
Actions/UndoRedoHelpers.hpp (modified) (1 diff)
-
Bond/BondInfo.cpp (modified) (1 diff)
-
Bond/BondInfo.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/BondifyAction.cpp
rad0929 r9782e20 41 41 42 42 #include "Actions/AtomAction/BondifyAction.hpp" 43 //#include "Actions/UndoRedoHelpers.hpp"43 #include "Actions/UndoRedoHelpers.hpp" 44 44 #include "Atom/atom.hpp" 45 #include "Atom/AtomicInfo.hpp" 45 46 #include "Bond/bond.hpp" 47 #include "Bond/BondInfo.hpp" 46 48 #include "Descriptors/AtomsWithinDistanceOfDescriptor.hpp" 47 49 #include "Graph/BondGraph.hpp" … … 59 61 60 62 typedef std::vector< std::pair<atom *, int> > candidates_t; 63 64 const double MAX_DISTANCE = 5.0; 61 65 62 66 static int getNumberOfHydrogenAtoms( … … 77 81 { 78 82 const std::vector< atom *> atoms_in_vicinity = World::getInstance().getAllAtoms( 79 AtomsWithinDistanceOf( 5., Walker->getPosition()));83 AtomsWithinDistanceOf(MAX_DISTANCE, Walker->getPosition())); 80 84 candidates_t candidates; 81 85 for (std::vector<atom *>::const_iterator iter = atoms_in_vicinity.begin(); … … 88 92 if (OtherWalker->IsBondedTo(Walker)) 89 93 continue; 90 double distance = OtherWalker->getPosition().distance(Walker->getPosition());94 const double distance = OtherWalker->getPosition().distance(Walker->getPosition()); 91 95 range<double> typical_distance = BG.getMinMaxDistance(Walker, OtherWalker); 92 96 if (typical_distance.isInRange(distance)) { … … 126 130 all_candidates_t operator()( 127 131 const int open_valence, 128 const std::multimap<int, atom*>& sorted_candidates) const132 const num_hydrogens_atom_map_t& sorted_candidates) const 129 133 { 130 134 all_candidates_t all_candidates; … … 137 141 */ 138 142 int remaining_valence = open_valence; 139 std::multimap<int, atom*>::const_iterator iter = sorted_candidates.begin();143 num_hydrogens_atom_map_t::const_iterator iter = sorted_candidates.begin(); 140 144 candidates_hydrogens_to_remove_t candidate_set; 141 145 exploreCandidateSetRecursively( … … 229 233 230 234 if (open_valence <= 0) { 231 STATUS("Nothing selected, we need some unoccupied valence orbitals to have something to work on.");235 STATUS("Nothing to do. Atom is saturated already, we need some unoccupied valence orbitals to have something to work on."); 232 236 return Action::success; 233 237 } … … 238 242 239 243 /** We revert the map's key and values, as we want the entries 240 * sorted by the valence.244 * sorted by the number of hydrogens. 241 245 */ 242 246 std::multimap<int, atom*> sorted_candidates; … … 273 277 274 278 // execute that 279 std::vector<AtomicInfo> removedHydrogens; 280 std::vector<BondInfo> addedBonds; 275 281 int removed_hydrogens = 0; 276 282 int added_bonds = 0; … … 306 312 LOG(2, "DEBUG: Removing hydrogen at distance " << removeiter->first 307 313 << " to Walker at " << Walker->getPosition()); 314 removedHydrogens.push_back(AtomicInfo(*removeiter->second)); 308 315 world.destroyAtom(removeiter->second); 309 316 removeiter->second = NULL; … … 314 321 // add the bond 315 322 bond::ptr new_bond = Walker->addBond(other_walker); 323 addedBonds.push_back(BondInfo(new_bond)); 316 324 new_bond->setDegree(num_hydrogens); 317 325 ++added_bonds; … … 325 333 << added_bonds << " new bonds."); 326 334 327 return Action::success; 328 // return ActionState::ptr(new AtomBondifyState(addedHydrogens, params)); 335 return ActionState::ptr(new AtomBondifyState(removedHydrogens, addedBonds, params)); 329 336 } 330 337 331 338 ActionState::ptr AtomBondifyAction::performUndo(ActionState::ptr _state) { 332 // AtomBondifyState *state = assert_cast<AtomBondifyState*>(_state.get()); 333 334 // remove all added hydrogen atoms 335 // RemoveAtomsFromAtomicInfo(state->addedHydrogens); 336 337 // return ActionState::ptr(_state); 338 return Action::success; 339 AtomBondifyState *state = assert_cast<AtomBondifyState*>(_state.get()); 340 341 AddAtomsFromAtomicInfo(state->removedHydrogens); 342 RemoveBondsFromBondInfo(state->addedBonds); 343 344 return ActionState::ptr(_state); 339 345 } 340 346 341 347 ActionState::ptr AtomBondifyAction::performRedo(ActionState::ptr _state){ 342 // AtomBondifyState *state = assert_cast<AtomBondifyState*>(_state.get()); 343 344 // re-add all added hydrogen atoms 345 // AddAtomsFromAtomicInfo(state->addedHydrogens); 346 347 // return ActionState::ptr(_state); 348 return Action::success; 348 AtomBondifyState *state = assert_cast<AtomBondifyState*>(_state.get()); 349 350 RemoveAtomsFromAtomicInfo(state->removedHydrogens); 351 AddBondsFromBondInfo(state->addedBonds); 352 353 return ActionState::ptr(_state); 349 354 } 350 355 351 356 bool AtomBondifyAction::canUndo() { 352 return false;357 return true; 353 358 } 354 359 355 360 bool AtomBondifyAction::shouldUndo() { 356 return false;361 return true; 357 362 } 358 363 /** =========== end of function ====================== */ -
src/Actions/AtomAction/BondifyAction.def
rad0929 r9782e20 8 8 // all includes and forward declarations necessary for non-integral types below 9 9 #include "Atom/AtomicInfo.hpp" 10 #include "Bond/BondInfo.hpp" 10 11 #include "Parameters/Validators/DummyValidator.hpp" 11 12 … … 21 22 (DummyValidator<unsigned int>()) 22 23 23 #define statetypes (std::vector<AtomicInfo>) 24 #define statereferences ( addedHydrogens)24 #define statetypes (std::vector<AtomicInfo>)(std::vector<BondInfo>) 25 #define statereferences (removedHydrogens)(addedBonds) 25 26 26 27 // some defines for all the names, you may use ACTION, STATE and PARAMS -
src/Actions/UndoRedoHelpers.cpp
rad0929 r9782e20 144 144 return status; 145 145 } 146 147 bool MoleCuilder::RemoveBondsFromBondInfo(const std::vector< BondInfo > &bonds) 148 { 149 bool status = true; 150 std::vector< BondInfo >::const_iterator iter = bonds.begin(); 151 for(;iter != bonds.end(); ++iter) { 152 if (!(*iter).RemoveBond()) { 153 status = false; 154 break; 155 } 156 } 157 if (!status) { 158 // remove all added bonds again 159 for(std::vector< BondInfo >::const_iterator removeiter = bonds.begin(); 160 removeiter != iter; ++removeiter) { 161 removeiter->RecreateBond(); 162 } 163 } 164 return status; 165 } 166 146 167 147 168 void MoleCuilder::SetAtomsFromAtomicInfo( -
src/Actions/UndoRedoHelpers.hpp
rad0929 r9782e20 58 58 */ 59 59 bool AddBondsFromBondInfo(const std::vector< BondInfo > &bonds); 60 61 /** Removes bonds from information stored in \a bonds. 62 * 63 * @param bonds bond state information 64 * @return true - all bonds removed, false - at least one bond could not be removed 65 */ 66 bool RemoveBondsFromBondInfo(const std::vector< BondInfo > &bonds); 60 67 61 68 /** Sets atoms to state information stored as AtomicInfo. -
src/Bond/BondInfo.cpp
rad0929 r9782e20 85 85 } 86 86 87 voidBondInfo::RemoveBond() const87 bool BondInfo::RemoveBond() const 88 88 { 89 89 atom * const leftatom = World::getInstance().getAtom(AtomById(leftid)); 90 90 atom * const rightatom = World::getInstance().getAtom(AtomById(rightid)); 91 leftatom->removeBond(rightatom); 91 if (leftatom->IsBondedTo(rightatom)) { 92 leftatom->removeBond(rightatom); 93 return true; 94 } 95 return false; 92 96 } -
src/Bond/BondInfo.hpp
rad0929 r9782e20 39 39 /** Removes the bond whose state is contained in this BondInfo. 40 40 * 41 * @return true - bond removed, false - bond does not exist 41 42 */ 42 voidRemoveBond() const;43 bool RemoveBond() const; 43 44 44 45 //!> id of left bond partner
Note:
See TracChangeset
for help on using the changeset viewer.
