public void OnSearchElementClicked(NodeModel nodeModel, Point position) { bool useDeafultPosition = position.X == 0 && position.Y == 0; dynamoViewModel.ExecuteCommand(new DynamoModel.CreateNodeCommand( nodeModel, position.X, position.Y, useDeafultPosition, true)); OnRequestFocusSearch(); }
private void ExecuteElement(CustomNodeSearchElement element) { string name = element.Guid.ToString(); // create node var guid = Guid.NewGuid(); dynamoViewModel.ExecuteCommand( new DynamoModel.CreateNodeCommand(guid, name, 0, 0, true, true)); // select node var placedNode = dynamoViewModel.Model.Nodes.Find((node) => node.GUID == guid); if (placedNode != null) { DynamoSelection.Instance.ClearSelection(); DynamoSelection.Instance.Selection.Add(placedNode); } }
internal bool HandlePortClicked(PortViewModel portViewModel) { // We only entertain port clicking when the current state is idle, // or when it is already having a connector being established. if (currentState != State.None && (currentState != State.Connection)) { return(false); } PortModel portModel = portViewModel.PortModel; DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; WorkspaceViewModel workspaceViewModel = dynamoViewModel.CurrentSpaceViewModel; if (this.currentState != State.Connection) // Not in a connection attempt... { PortType portType = PortType.INPUT; Guid nodeId = portModel.Owner.GUID; int portIndex = portModel.Owner.GetPortIndex(portModel, out portType); dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand( nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.Begin)); if (owningWorkspace.IsConnecting) { this.currentState = State.Connection; } } else // Attempt to complete the connection { PortType portType = PortType.INPUT; Guid nodeId = portModel.Owner.GUID; int portIndex = portModel.Owner.GetPortIndex(portModel, out portType); dynamoViewModel.ExecuteCommand(new DynCmd.MakeConnectionCommand( nodeId, portIndex, portType, DynCmd.MakeConnectionCommand.Mode.End)); this.currentState = State.None; } return(true); }
internal bool HandleMouseMove(object sender, Point mouseCursor) { if (this.currentState == State.Connection) { // If we are currently connecting and there is an active // connector, redraw it to match the new mouse coordinates. owningWorkspace.UpdateActiveConnector(mouseCursor); } else if (this.currentState == State.WindowSelection) { // When the mouse is held down, reposition the drag selection box. double x = Math.Min(mouseDownPos.X, mouseCursor.X); double y = Math.Min(mouseDownPos.Y, mouseCursor.Y); double width = Math.Abs(mouseDownPos.X - mouseCursor.X); double height = Math.Abs(mouseCursor.Y - mouseDownPos.Y); // We perform cross selection (i.e. select a node whenever // it touches the selection box as opposed to only select // it when it is entirely within the selection box) when // mouse moves in the opposite direction (i.e. the current // mouse position is smaller than the point mouse-down // happened). // bool isCrossSelection = mouseCursor.X < mouseDownPos.X; SelectionBoxUpdateArgs args = null; args = new SelectionBoxUpdateArgs(x, y, width, height); args.SetSelectionMode(isCrossSelection); this.owningWorkspace.RequestSelectionBoxUpdate(this, args); var rect = new Rect(x, y, width, height); var command = new DynCmd.SelectInRegionCommand(rect, isCrossSelection); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; dynamoViewModel.ExecuteCommand(command); } else if (this.currentState == State.DragSetup) { // There are something in the selection, but none is ILocatable. if (!DynamoSelection.Instance.Selection.Any((x) => (x is ILocatable))) { SetCurrentState(State.None); return(false); } // Record and begin the drag operation for selected nodes. var operation = DynCmd.DragSelectionCommand.Operation.BeginDrag; var command = new DynCmd.DragSelectionCommand(mouseCursor, operation); DynamoViewModel dynamoViewModel = dynSettings.Controller.DynamoViewModel; dynamoViewModel.ExecuteCommand(command); SetCurrentState(State.NodeReposition); return(true); } else if (this.currentState == State.NodeReposition) { // Update the dragged nodes (note: this isn't recorded). owningWorkspace.UpdateDraggedSelection(mouseCursor); } return(false); // Mouse event not handled. }
private void DeleteNodeAndItsConnectors(object parameter) { var command = new DynamoModel.DeleteModelCommand(nodeLogic.GUID); DynamoViewModel.ExecuteCommand(command); }
public void OnSearchElementClicked(NodeModel nodeModel) { dynamoViewModel.ExecuteCommand(new DynamoModel.CreateNodeCommand(nodeModel, 0, 0, true, true)); }