public bool GetReplicationIndex(uint compId, Point mousePt, out int replicationIndex, out int slotIndex) { VisualNode node = GetVisualNode(compId); if (node.GetInputSlots().Count() > 1) { mousePt.X -= node.X; mousePt.Y -= node.Y; double centerLine = node.CenterLine; double deltaX = centerLine - mousePt.X; replicationIndex = (int)(deltaX / (Configurations.ReplicationGuideWidth + Configurations.TriangleHeight)); double slotCount = node.GetInputSlots().Count(); double slotHeight = (node.Height) / slotCount; slotIndex = (int)((mousePt.Y) / slotHeight); return(true); } else { replicationIndex = -1; slotIndex = -1; return(false); } }
private bool HandleEndNodeEdit(GraphCommand command) { uint nodeId = (uint)command.GetArgument(0); string text = command.GetArgument(1) as string; bool commit = (bool)command.GetArgument(2); VisualNode node = this.GetVisualNode(nodeId); bool setToPreviousValue = false; bool setToDefaultValue = false; bool recordAsCreation = false; bool recordAndDelete = false; bool validate = false; bool delete = false; text = node.PreprocessInputString(text); bool committingEmptyContent = text == string.Empty; bool committingSameContent = text == this.previousText; bool startedOffDefaultValueDriver = this.previousText == Configurations.DriverInitialTextValue; bool committingEmptyCodeBlock = text == string.Empty || text == Configurations.CodeBlockInitialMessage; bool startedOffEmptyCodeBlock = this.previousText == string.Empty || this.previousText == Configurations.CodeBlockInitialMessage; //Flow logic if (node.VisualType == NodeType.CodeBlock) { if (commit) { if (committingEmptyCodeBlock) { if (startedOffEmptyCodeBlock) { delete = true; } else { recordAndDelete = true; } } else //Not Empty { if (!committingSameContent) { validate = true; } if (startedOffEmptyCodeBlock) { recordAsCreation = true; } } } else //Not committing { if (startedOffEmptyCodeBlock) { delete = true; } } } else if (node.VisualType == NodeType.Driver) { if (commit) { if (committingEmptyContent) { if (node.IsEditingText) { setToDefaultValue = true; } else if (node.IsEditingCaption) { setToPreviousValue = true; } } else //Not Empty { if (!committingSameContent) { validate = true; } } } } else //Other nodes { if (commit) { if (committingEmptyContent) { setToPreviousValue = true; } else //Not empty { if (!committingSameContent) { validate = true; } } } } //Execution node.Edit(this.previousText, false); if (delete) { if (null != visualHost) { this.visualHost.RemoveDrawingVisual(node.NodeId); this.visualHost.RemoveDrawingVisual(node.GetErrorBubbleId()); this.visualHost.RemoveDrawingVisual(node.GetPreviewBubbleId()); this.visualHost.RemoveExtendedBubble(node.GetPreviewBubbleId()); } uint[] outputSlots = node.GetOutputSlots(); uint[] inputSlots = node.GetInputSlots(); if (inputSlots != null) { foreach (uint inputSlot in inputSlots) { this.slotCollection.Remove(inputSlot); } } if (outputSlots != null) { foreach (uint outputSlot in outputSlots) { this.slotCollection.Remove(outputSlot); } } this.nodeCollection.Remove(node.NodeId); this.bubbleCollection.Remove(node.GetErrorBubbleId()); this.bubbleCollection.Remove(node.GetPreviewBubbleId()); } if (recordAndDelete) { DeltaNodes deltaNodes = new DeltaNodes(); deltaNodes.AppendToRemovedNodes(node); deltaNodes.AppendToModifiedNodes(FindAssociatedNodesFromNodes(deltaNodes.RemovedNodes)); this.undoRedoRecorder.BeginGroup(); this.undoRedoRecorder.RecordRuntimeStatesForUndo(this.graphProperties.RuntimeStates); this.undoRedoRecorder.RecordNodeDeletionForUndo(deltaNodes.RemovedNodes); this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes); this.DeleteNodes(deltaNodes.RemovedNodes); this.undoRedoRecorder.EndGroup(); this.ValidateDefinedAndReferencedVariables(); this.UpdateSlotsVisiblity(); this.SynchronizeToLiveRunner(deltaNodes); } if (setToDefaultValue) { if (!startedOffDefaultValueDriver) { DeltaNodes deltaNodes = new DeltaNodes(); deltaNodes.AppendToModifiedNodes(node); this.undoRedoRecorder.BeginGroup(); this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes); this.undoRedoRecorder.EndGroup(); node.Edit(Configurations.DriverInitialTextValue, false); this.SynchronizeToLiveRunner(deltaNodes); } string warningMessage = "Field cannot be empty. Value will be set to 0."; node.SetErrorValue((object)warningMessage, ErrorType.Warning); } if (setToPreviousValue) { string warningMessage = "Field cannot be empty. Value will be reverted to previous state."; node.SetErrorValue((object)warningMessage, ErrorType.Warning); } if (validate) { DeltaNodes deltaNodes = new DeltaNodes(); List <IVisualNode> addedNodes = new List <IVisualNode>(); List <IVisualNode> modifiedNodes = new List <IVisualNode>(); addedNodes.Add(node); // deltaNodes.AppendToAddedNodes(node); // Start monitoring if we are going to undefine any variables. this.graphProperties.RuntimeStates.BeginDefinitionMonitor(); this.undoRedoRecorder.BeginGroup(); this.undoRedoRecorder.RecordRuntimeStatesForUndo(this.graphProperties.RuntimeStates); if (recordAsCreation) { this.undoRedoRecorder.RecordNodeCreationForUndo(addedNodes); } else //record edited node as modification { deltaNodes.AppendToModifiedNodes(node); deltaNodes.AppendToModifiedNodes(FindAssociatedNodesFromNodes(addedNodes)); this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes); } // These methods (especially the first two and last two) must be // called in this particular order (due to their dependencies). // // GC.ValidateNodesSyntax // RS.UpdateVariableDefinitionMap // GC.ValidateDefinedAndReferencedVariables // GC.UpdateSlotsVisiblity // GC.EstablishImplicitConnections // node.SetErrorValue(null, ErrorType.None); node.Edit(text, false); this.ValidateNodesSyntax(addedNodes); this.graphProperties.RuntimeStates.UpdateVariablesDefinedInNode(node, false); this.ValidateDefinedAndReferencedVariables(); this.UpdateSlotsVisiblity(); this.EstablishImplicitConnections(modifiedNodes); this.edgeController.DeleteUnnecessaryEdges(); this.undoRedoRecorder.EndGroup(); // Now all the modifications are over, see what we have undefined. Dictionary <uint, List <string> > undefinedVariables = null; this.graphProperties.RuntimeStates.EndDefinitionMonitor(out undefinedVariables); deltaNodes.AppendUndefinedVariables(undefinedVariables); if (recordAsCreation) { deltaNodes.AppendToAddedNodes(addedNodes); } deltaNodes.AppendToModifiedNodes(modifiedNodes); this.SynchronizeToLiveRunner(deltaNodes); } this.UpdateDirtyNodes(); this.edgeController.UpdateEdgeConnectTo(node); node.DisableEdit(); if (validate && visualHost != null) { visualHost.ScrollToVisual(visualHost.GetDrawingVisualForNode(node.NodeId)); } return(true); }
internal void UpdateEdgeConnectTo(VisualNode node) { uint[] inputs = node.GetInputSlots(); uint[] outputs = node.GetOutputSlots(); if (inputs != null) { foreach (uint slotId in inputs) { foreach (VisualEdge visualEdge in edgeCollection.Values) if (visualEdge.EndSlotId == slotId) visualEdge.UpdateControlPoint(); } } if (outputs != null) { foreach (uint slotId in outputs) { foreach (VisualEdge visualEdge in edgeCollection.Values) if (visualEdge.StartSlotId == slotId) visualEdge.UpdateControlPoint(); } } UpdateDirtyEdges(null); }
public bool GetNodePartRegion(uint compId, NodePart nodePart, Point mousePt, out Rect result, out NodeType type) { result = new Rect(); type = NodeType.None; IVisualNode iNode = GetVisualNode(compId); VisualNode node = ((VisualNode)iNode); if (null == node) { return(false); } type = node.VisualType; double centerLine = 0; double width = node.Width; double height = node.Height; if (nodePart == NodePart.None) { result.X = node.X; result.Y = node.Y; result.Width = node.Width; result.Height = node.Height; return(true); } if (nodePart == NodePart.North || nodePart == NodePart.South) { centerLine = node.CenterLine; result.X = node.X; result.Y = node.Y; result.Width = centerLine; result.Height = node.Height; } switch (node.VisualType) { case NodeType.Function: centerLine = node.CenterLine; if (nodePart == NodePart.Caption) { result = new Rect(new Point(node.X + centerLine, node.Y + 0), new Point(node.X + width, node.Y + height / 2)); return(true); } if (nodePart == NodePart.Text) { result = new Rect(new Point(node.X + centerLine, node.Y + height / 2), new Point(node.X + width, node.Y + height)); return(true); } if (nodePart == NodePart.ReplicationGuide) { FunctionNode fNode = node as FunctionNode; result = new Rect(new Size(Configurations.ReplicationGuideWidth, Configurations.SlotStripeSize)); mousePt.X -= node.X; mousePt.Y -= node.Y; double deltaX = centerLine - mousePt.X; int replicationIndex = (int)(deltaX / (Configurations.ReplicationGuideWidth + Configurations.TriangleHeight)); double slotCount = node.GetInputSlots().Count(); double slotHeight = (node.Height) / slotCount; int slotIndex = (int)((mousePt.Y) / slotHeight); result.Location = new Point(node.X + centerLine - fNode.GetMaxReplicationWidth(), node.Y + slotIndex * Configurations.SlotStripeSize + 1); return(true); } //take inputSlots into consideration break; case NodeType.Driver: centerLine = node.CenterLine; if (nodePart == NodePart.Caption) { result = new Rect(new Point(node.X + 0, node.Y + 0), new Point(node.X + centerLine, node.Y + height)); return(true); } if (nodePart == NodePart.Text) { result = new Rect(new Point(node.X + centerLine, node.Y + 0), new Point(node.X + width, node.Y + height)); return(true); } break; case NodeType.CodeBlock: if (nodePart == NodePart.Text) { result = new Rect(new Point(node.X + 0, node.Y + 0), new Point(node.X + width, node.Y + height)); return(true); } break; case NodeType.Identifier: if (nodePart == NodePart.Caption) { result = new Rect(new Point(node.X + 0, node.Y + 0), new Point(node.X + width, node.Y + height)); return(true); } break; case NodeType.Property: if (nodePart == NodePart.Caption) { result = new Rect(new Point(node.X, node.Y + 0), new Point(node.X + width, node.Y + height / 2)); return(true); } else if (nodePart == NodePart.Text) { result = new Rect(new Point(node.X, node.Y + height / 2), new Point(node.X + width, node.Y + height)); return(true); } break; default: result = new Rect(); return(false); } return(false); }
internal List<IVisualEdge> FindEdgeConnectTo(VisualNode node) { List<IVisualEdge> edgeList = new List<IVisualEdge>(); uint[] inputs = node.GetInputSlots(); uint[] outputs = node.GetOutputSlots(); if (inputs != null) { foreach (uint slotId in inputs) { foreach (VisualEdge visualEdge in edgeCollection.Values) if (visualEdge.EndSlotId == slotId) edgeList.Add(visualEdge); } } if (outputs != null) { foreach (uint slotId in outputs) { foreach (VisualEdge visualEdge in edgeCollection.Values) if (visualEdge.StartSlotId == slotId) edgeList.Add(visualEdge); } } return edgeList; }