Changeset 9782e20 for src/Actions/AtomAction/BondifyAction.cpp
- 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)
- File:
-
- 1 edited
-
src/Actions/AtomAction/BondifyAction.cpp (modified) (12 diffs)
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 ====================== */
Note:
See TracChangeset
for help on using the changeset viewer.
