public override bool undoTool() { node.setValues(oldX, oldY, oldScale); if (newX != oldX || newY != oldY) { foreach (Trajectory.Side side in trajectory.getSides()) { if (side.getIDEnd().Equals(node.getID()) || side.getIDStart().Equals(node.getID())) { Node start = trajectory.getNodeForId(side.getIDStart()); Node end = trajectory.getNodeForId(side.getIDEnd()); float x = start.getX() - end.getX(); float y = start.getY() - end.getY(); side.setRealLength((float)Mathf.Sqrt(Mathf.Pow(x, 2) + Mathf.Pow(y, 2))); } float temp = oldLengths[side.getIDStart() + ";" + side.getIDEnd()]; if (temp != null) { side.setLenght(temp); } } } Controller.getInstance().updatePanel(); return(true); }
public override bool redoTool() { Node temp = (Node)oldNodeDataControl.getContent(); trajectory.removeNode(temp.getX(), temp.getY()); trajectoryDataControl.getNodes().Remove(oldNodeDataControl); if (wasInitial) { trajectory.setInitial(null); trajectoryDataControl.initialNode = null; trajectory.setInitial(trajectory.getNodes()[0].getID()); trajectoryDataControl.initialNode = trajectoryDataControl.getNodes()[0]; } foreach (SideDataControl side in trajectoryDataControl.getSides()) { if (!trajectory.getSides().Contains((Side)side.getContent())) { oldSides.Add(side); } } foreach (SideDataControl side in oldSides) { trajectoryDataControl.getSides().Remove(side); } Controller.Instance.updatePanel(); return(true); }
public override bool undoTool() { node.setValues(oldX, oldY, oldScale); bool isEnd; if (newX != oldX || newY != oldY) { foreach (Trajectory.Side side in trajectory.getSides()) { isEnd = side.getIDEnd().Equals(node.getID()); if (side.getIDEnd().Equals(node.getID()) || side.getIDStart().Equals(node.getID())) { Node start = trajectory.getNodeForId(side.getIDStart()); Node end = trajectory.getNodeForId(side.getIDEnd()); float x = start.getX() - end.getX(); float y = start.getY() - end.getY(); side.setRealLength(new Vector2(x, y).magnitude); side.setLenght(isEnd ? oldLength[side.getIDStart()] : oldLength[side.getIDEnd()]); } } } Controller.Instance.updatePanel(); return(true); }
public override bool redoTool() { node.setValues(newX, newY, newScale); if (newX != oldX || newY != oldY) { foreach (Trajectory.Side side in trajectory.getSides()) { if (side.getIDEnd().Equals(node.getID()) || side.getIDStart().Equals(node.getID())) { Node start = trajectory.getNodeForId(side.getIDStart()); Node end = trajectory.getNodeForId(side.getIDEnd()); float x = start.getX() - end.getX(); float y = start.getY() - end.getY(); var newLength = new Vector2(x, y).magnitude; if (Mathf.Approximately(side.getLength(), side.getRealLength())) { side.setLenght(newLength); } side.setRealLength(newLength); } } } Controller.Instance.updatePanel(); return(true); }
public SetNodeValuesTool(Node node, Trajectory trajectory, int newX, int newY, float newScale) { this.newX = newX; this.newY = newY; this.newScale = newScale; this.oldX = node.getX(); this.oldY = node.getY(); this.oldScale = node.getScale(); this.node = node; this.trajectory = trajectory; this.oldLengths = new Dictionary <string, float>(); }
public SetNodeValuesTool(Node node, Trajectory trajectory, int newX, int newY, float newScale) { this.newX = newX; this.newY = newY; this.newScale = newScale; this.oldX = node.getX(); this.oldY = node.getY(); this.oldScale = node.getScale(); this.oldLength = new Dictionary <string, float>(); bool isEnd; foreach (Trajectory.Side side in trajectory.getSides()) { isEnd = side.getIDEnd().Equals(node.getID()); if (isEnd || side.getIDStart().Equals(node.getID())) { oldLength.Add(isEnd ? side.getIDStart() : side.getIDEnd(), side.getLength()); } } this.node = node; this.trajectory = trajectory; }