Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/CopyAction.cpp

    rbe21fa r8ea3e7  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include "Actions/UndoRedoHelpers.hpp"
    2223#include "CodePatterns/Log.hpp"
    2324#include "CodePatterns/Verbose.hpp"
     
    3132#include <fstream>
    3233#include <string>
     34#include <vector>
    3335
    3436#include "Actions/MoleculeAction/CopyAction.hpp"
     
    4042#include "Action_impl_pre.hpp"
    4143/** =========== define the function ====================== */
    42 Action::state_ptr MoleculeCopyAction::performCall() {
    43   molecule *copy = NULL;
     44Action::state_ptr MoleculeCopyAction::performCall()
     45{
     46  std::vector<moleculeId_t> molecules;
     47  for (World::MoleculeSelectionConstIterator iter = World::getInstance().beginMoleculeSelection();
     48      iter != World::getInstance().endMoleculeSelection(); ++iter) {
     49    molecule * const copy = (iter->second)->CopyMolecule();
     50    Vector *Center = (iter->second)->DetermineCenterOfAll();
     51    *Center *= -1.;
     52    *Center += params.position.get();
     53    copy->Translate(Center);
     54    delete(Center);
     55    molecules.push_back(copy->getId());
     56  }
    4457
    45   copy = params.mol->CopyMolecule();
    46   Vector *Center = params.mol->DetermineCenterOfAll();
    47   *Center *= -1.;
    48   *Center += params.position;
    49   copy->Translate(Center);
    50   delete(Center);
    51 
    52   return Action::state_ptr(new MoleculeCopyState(copy,params));
     58  return Action::state_ptr(new MoleculeCopyState(molecules,params));
    5359}
    5460
     
    5662  MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
    5763
    58   state->copy->removeAtomsinMolecule();
    59   World::getInstance().destroyMolecule(state->copy);
     64  RemoveMoleculesWithAtomsByIds(state->copies);
    6065
    6166  return Action::state_ptr(_state);
     
    6368
    6469Action::state_ptr MoleculeCopyAction::performRedo(Action::state_ptr _state){
    65   MoleculeCopyState *state = assert_cast<MoleculeCopyState*>(_state.get());
    66 
    67   molecule *copy = state->params.mol->CopyMolecule();
    68   Vector *Center = state->params.mol->DetermineCenterOfAll();
    69   *Center *= -1.;
    70   *Center += state->params.position;
    71   copy->Translate(Center);
    72   delete(Center);
    73 
    74   return Action::state_ptr(new MoleculeCopyState(copy,state->params));
     70  return performCall();
    7571}
    7672
Note: See TracChangeset for help on using the changeset viewer.