/*
 * History
 * Created on Oct 27, 2004 by kofke
 */
package etomica.action;

import etomica.Space;
import etomica.space.Vector;

/**
 * Action that moves (translates) all the atoms in a phase by a specified
 * (vector) amount.
 */

public final class PhaseTranslate extends PhaseActionAdapter implements Undoable {

	private final Vector translationVector;

	/**
	 * Constructor requires space instance to define a translation vector.
	 * 
	 * @param space
	 */
	public PhaseTranslate(Space space) {
		super("PhaseTranslate");
		translationVector = space.makeVector();
	}

	/**
	 * Sets vector specifying how atoms are to be moved. Vector is copied so to
	 * update it is necessary to invoke this method (cannot effect change simply
	 * by changing the coordinates of vector previously passed to this method).
	 */
	public void setTranslationVector(Vector v) {
		translationVector.E(v);
	}

	/**
	 * @return the translation vector. Changes to coordinates of the returned
	 *         vector will change the behavior of this action.
	 */
	public Vector getTranslationVector() {
		return translationVector;
	}

	/**
	 * Translates all atoms by the amount of the current tranlationVector.
	 */
	public void actionPerformed() {
		if (phase == null)
			return;
		phase.speciesMaster().coord.translateBy(translationVector);
	}

	/**
	 * Reverses the outcome of actionPerformed, moving the atoms an amount
	 * opposite to translationVector. Assumes translationVector and atom
	 * positions have not been changed since actionPerformed.
	 */
	public void undo() {
		translationVector.TE(-1);
		actionPerformed();
		translationVector.TE(-1);
	}
}
@@ -94,16 +94,68 @@
 .Space;%0A
+import etomica.atom.iterator.AtomIteratorLeafAtoms;%0A
 import e
@@ -175,16 +175,16 @@
 Vector;%0A
-
 %0A/**%0A * 
@@ -403,16 +403,66 @@
 nVector;
+%0A    private final AtomIteratorLeafAtoms iterator;
 %0A%0A%09/**%0A%09
@@ -666,16 +666,73 @@
 ctor();%0A
+        iterator = new AtomIteratorLeafAtoms();%0A        %0A
 %09%7D%0A%0A%09/**
@@ -1413,49 +1413,155 @@
 rn;%0A
-%09%09phase.speciesMaster().coord.translateBy
+        iterator.setPhase(phase);%0A        iterator.reset();%0A        while(iterator.hasNext()) %7B%0A            iterator.nextAtom().coord.position().PE
 (tra
@@ -1577,16 +1577,26 @@
 ector);%0A
+        %7D%0A
 %09%7D%0A%0A%09/**

update for space changes