/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } RecordableCommand command = null; switch (element.Name) { case "CreateNodeCommand": command = CreateNodeCommand.DeserializeCore(element); break; case "SelectModelCommand": command = SelectModelCommand.DeserializeCore(element); break; case "CreateNoteCommand": command = CreateNoteCommand.DeserializeCore(element); break; case "SelectInRegionCommand": command = SelectInRegionCommand.DeserializeCore(element); break; case "DragSelectionCommand": command = DragSelectionCommand.DeserializeCore(element); break; case "MakeConnectionCommand": command = MakeConnectionCommand.DeserializeCore(element); break; case "DeleteModelCommand": command = DeleteModelCommand.DeserializeCore(element); break; case "UndoRedoCommand": command = UndoRedoCommand.DeserializeCore(element); break; case "UpdateModelValueCommand": command = UpdateModelValueCommand.DeserializeCore(element); break; } if (null != command) { command.IsInPlaybackMode = true; return(command); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }
public void CanUndoDragPin() { Open(@"UI/ConnectorPinTests.dyn"); var connectorViewModel = this.ViewModel.CurrentSpaceViewModel.Connectors.First(); //hard-coded position on wire connectorViewModel.PanelX = 292.66666; connectorViewModel.PanelY = 278; //deltas to move by double xMove = 250; double yMove = 150; //Action triggered when hovering over a connector connectorViewModel.FlipOnConnectorAnchor(); //Pin command connectorViewModel.PinConnectorCommand.Execute(null); Assert.AreEqual(connectorViewModel.ConnectorPinViewCollection.Count, 1); // add connectorpin to selection var connectorPin = connectorViewModel.ConnectorModel.ConnectorPinModels.First(); DynamoSelection.Instance.Selection.Add(connectorPin); //initial x, y position of pin double initialX = connectorPin.CenterX; double initialY = connectorPin.CenterY; var point = new Point2D(initialX, initialY); var operation = DragSelectionCommand.Operation.BeginDrag; //'begin drag' command defined var command = new DragSelectionCommand(point, operation); //execute 'begin drag' Model.ExecuteCommand(command); operation = DragSelectionCommand.Operation.EndDrag; point.X += xMove; point.Y += yMove; //'end drag' command defined command = new DragSelectionCommand(point, operation); //execute 'end drag' Model.ExecuteCommand(command); //assert initial position and end position is NOT the same Assert.AreNotEqual(initialX, connectorPin.CenterX); Assert.AreNotEqual(initialY, connectorPin.CenterY); //undo drag Model.ExecuteCommand(new UndoRedoCommand(UndoRedoCommand.Operation.Undo)); //assert that after undo initial position and end position IS the same Assert.AreEqual(initialX, connectorPin.CenterX); Assert.AreEqual(initialY, connectorPin.CenterY); }
private void DragSelectionImpl(DragSelectionCommand command) { if (DragSelectionCommand.Operation.BeginDrag == command.DragOperation) { CurrentSpaceViewModel.BeginDragSelection(command.MouseCursor); } else { CurrentSpaceViewModel.EndDragSelection(command.MouseCursor); } }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } switch (element.Name) { case "CreateNodeCommand": return(CreateNodeCommand.DeserializeCore(element)); case "SelectModelCommand": return(SelectModelCommand.DeserializeCore(element)); case "CreateNoteCommand": return(CreateNoteCommand.DeserializeCore(element)); case "SelectInRegionCommand": return(SelectInRegionCommand.DeserializeCore(element)); case "DragSelectionCommand": return(DragSelectionCommand.DeserializeCore(element)); case "MakeConnectionCommand": return(MakeConnectionCommand.DeserializeCore(element)); case "DeleteModelCommand": return(DeleteModelCommand.DeserializeCore(element)); case "UndoRedoCommand": return(UndoRedoCommand.DeserializeCore(element)); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }
private void DragSelectionImpl(DragSelectionCommand command) { if (DragSelectionCommand.Operation.BeginDrag == command.DragOperation) CurrentSpaceViewModel.BeginDragSelection(command.MouseCursor); else CurrentSpaceViewModel.EndDragSelection(command.MouseCursor); }
/// <summary> /// Call this static method to reconstruct a RecordableCommand-derived /// object given an XmlElement that was previously saved with Serialize /// method. This method simply redirects the XmlElement to respective /// RecordableCommand-derived classes based on its type. /// </summary> /// <param name="element">The XmlElement from which the RecordableCommand /// can be reconstructed.</param> /// <returns>Returns the reconstructed RecordableCommand object. If a /// RecordableCommand cannot be reconstructed, this method throws a /// relevant exception.</returns> /// internal static RecordableCommand Deserialize(XmlElement element) { if (string.IsNullOrEmpty(element.Name)) { throw new ArgumentException("XmlElement without name"); } RecordableCommand command = null; switch (element.Name) { case "OpenFileCommand": command = OpenFileCommand.DeserializeCore(element); break; case "PausePlaybackCommand": command = PausePlaybackCommand.DeserializeCore(element); break; case "RunCancelCommand": command = RunCancelCommand.DeserializeCore(element); break; case "CreateNodeCommand": command = CreateNodeCommand.DeserializeCore(element); break; case "SelectModelCommand": command = SelectModelCommand.DeserializeCore(element); break; case "CreateNoteCommand": command = CreateNoteCommand.DeserializeCore(element); break; case "SelectInRegionCommand": command = SelectInRegionCommand.DeserializeCore(element); break; case "DragSelectionCommand": command = DragSelectionCommand.DeserializeCore(element); break; case "MakeConnectionCommand": command = MakeConnectionCommand.DeserializeCore(element); break; case "DeleteModelCommand": command = DeleteModelCommand.DeserializeCore(element); break; case "UndoRedoCommand": command = UndoRedoCommand.DeserializeCore(element); break; case "ModelEventCommand": command = ModelEventCommand.DeserializeCore(element); break; case "UpdateModelValueCommand": command = UpdateModelValueCommand.DeserializeCore(element); break; case "ConvertNodesToCodeCommand": command = ConvertNodesToCodeCommand.DeserializeCore(element); break; case "CreateCustomNodeCommand": command = CreateCustomNodeCommand.DeserializeCore(element); break; case "SwitchTabCommand": command = SwitchTabCommand.DeserializeCore(element); break; } if (null != command) { command.IsInPlaybackMode = true; command.Tag = element.GetAttribute("Tag"); return(command); } string message = string.Format("Unknown command: {0}", element.Name); throw new ArgumentException(message); }