Ejemplo n.º 1
0
        private List <IVisualNode> RetrieveNodesFromStorage(IStorage storage)
        {
            DataHeader         header   = new DataHeader();
            List <IVisualNode> nodeList = new List <IVisualNode>();
            int nodeCount = storage.ReadInteger(FieldCode.NodeCount);

            for (int i = 0; i < nodeCount; i++)
            {
                header.Deserialize(storage);
                IVisualNode node = VisualNode.Create(this.graphController, storage);
                nodeList.Add(node);
            }
            return(nodeList);
        }
        public bool GetNodeType(uint nodeId, out string returnType)
        {
            VisualNode node = this.GetVisualNode(nodeId);

            returnType = string.Empty;
            if (node != null)
            {
                returnType = node.ReturnType;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool GetNodeState(uint nodeId, out States nodeState)
        {
            VisualNode node = this.GetVisualNode(nodeId);

            if (node != null)
            {
                nodeState = node.NodeStates;
                return(true);
            }
            else
            {
                nodeState = States.None;
                return(false);
            }
        }
        public bool GetReplicationText(uint compId, int index, out string text)
        {
            VisualNode node = GetVisualNode(compId);

            if (node.VisualType != NodeType.Function)
            {
                throw new InvalidOperationException("node must be function Node");
            }
            else
            {
                FunctionNode fNode = node as FunctionNode;
                text = fNode.GetReplicationText(index);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private void OnWarningTimeOut(object sender, EventArgs e)
        {
            VisualNode node = graphController.GetVisualNode(this.OwnerId);

            //Terminate DispatcherTimer
            this.timer.Stop();
            this.timer = null;

            //Clear state
            this.content = null;
            this.ErrType = ErrorType.None;

            //Redraw
            node.Dirty = true;
            node.Compose();
        }
        public bool TransientUpdateReplicationText(uint compId, string text, int replicationIndex)
        {
            VisualNode node = GetVisualNode(compId);

            if (node.VisualType != NodeType.Function)
            {
                throw new InvalidOperationException("Replication Guides can only be added to functio nodes");
            }
            else
            {
                FunctionNode fNode = node as FunctionNode;
                fNode.UpdateReplicationGuides(text, replicationIndex);
            }
            edgeController.UpdateEdgeConnectTo(node);
            return(true);
        }
        public void ClearPreviewSelection(uint componentId)
        {
            IVisualNode selectedNode = null;

            nodeCollection.TryGetValue(componentId, out selectedNode);
            VisualNode node = selectedNode as VisualNode;

            if (node != null)
            {
                node.PreviewSelected = node.Selected;
                node.Compose(); // Optionally redraw the node.
            }
            else
            {
                edgeController.ClearPreviewSelection(componentId);
            }
        }
        private bool HandleBeginNodeEdit(GraphCommand command)
        {
            uint       nodeId   = (uint)command.GetArgument(0);
            NodePart   nodePart = ((NodePart)command.GetArgument(1));
            VisualNode node     = this.GetVisualNode(nodeId);

            if (nodePart == NodePart.Text)
            {
                this.previousText = node.Text;
            }
            else if (nodePart == NodePart.Caption)
            {
                this.previousText = node.Caption;
            }
            node.EnableEdit(nodePart, -1);
            return(true);
        }
        private bool HandleTogglePreview(GraphCommand command)
        {
            uint bubbleId = (uint)command.GetArgument(0);

            if (bubbleId == uint.MaxValue)
            {
                return(ToggleAllPreviews());
            }

            PreviewBubble previewBubble = bubbleCollection[bubbleId] as PreviewBubble;

            if (previewBubble == null)
            {
                return(false);
            }

            VisualNode node = GetVisualNode(previewBubble.OwnerId);

            if (node == null)
            {
                return(false);
            }

            List <IVisualNode> nodeList = new List <IVisualNode>();

            nodeList.Add(node);

            undoRedoRecorder.BeginGroup();
            undoRedoRecorder.RecordNodeModificationForUndo(nodeList);
            undoRedoRecorder.EndGroup();

            if (node.NodeStates.HasFlag(States.PreviewHidden))
            {
                node.ClearState(States.PreviewHidden);
                CurrentSynchronizer.BeginQueryNodeValue(node.NodeId);
            }
            else
            {
                node.SetNodeState(States.PreviewHidden);
            }

            previewBubble.Collapse(node.NodeStates.HasFlag(States.PreviewHidden));

            return(true);
        }
Ejemplo n.º 10
0
        internal void UpdateVariablesDefinedInNode(VisualNode node, bool isPriority)
        {
            List <string> mappingToRemove = new List <string>();
            List <string> variables       = node.GetDefinedVariables(false);

            if (null != variables)
            {
                foreach (KeyValuePair <string, List <uint> > kvp in this.variableNodesMap)
                {
                    if (!variables.Contains(kvp.Key) && kvp.Value.Contains(node.NodeId))
                    {
                        mappingToRemove.Add(kvp.Key);
                    }
                }
            }

            foreach (string variable in mappingToRemove)
            {
                this.RemoveDefinition(variable, node.NodeId);
            }

            if (null != variables)
            {
                foreach (string variable in variables)
                {
                    this.AddDefinition(variable, node.NodeId, isPriority);
                }
            }

            if (null != undefinedVarsTracker && (mappingToRemove.Count > 0))
            {
                if (!undefinedVarsTracker.ContainsKey(node.NodeId))
                {
                    undefinedVarsTracker.Add(node.NodeId, new List <string>());
                }

                foreach (string variable in mappingToRemove)
                {
                    undefinedVarsTracker[node.NodeId].Add(variable);
                }
            }
        }
Ejemplo n.º 11
0
        private void GenerateMenuItems()
        {
            Dictionary <int, string> list = new Dictionary <int, string>();

            VisualNode node = graphController.GetVisualNode(nodeId);

            if (nodeId == uint.MaxValue)
            {
                libraryItemCollection = new Dictionary <int, LibraryItem>();
            }
            if (null == node)
            {
                return;
            }

            switch (node.VisualType)
            {
            case NodeType.Function:
                GetFunctionNodeMenuItems();
                break;

            case NodeType.Driver:
                GetDriverNodeMenuItems(list);
                break;

            case NodeType.CodeBlock:
                GetCodeBlockNodeMenuItems(list);
                break;

            case NodeType.Identifier:
                GetIdentifierNodeMenuItems();
                break;

            case NodeType.Property:
                GetPropertyNodeMenuItems();
                break;

            default:
                return;
            }
            return;
        }
Ejemplo n.º 12
0
        private void GetNodeOptions(uint nodeId, out Dictionary <int, string> nodeItems)
        {
            VisualNode node = this.graphController.GetVisualNode(nodeId);

            nodeItems = new Dictionary <int, string>();

            if (node.VisualType == NodeType.Function)
            {
                FunctionNode fNode = ((FunctionNode)node);
                if (fNode.GetAddReplicationState() == true)
                {
                    nodeItems.Add(Configurations.AddReplicationGuides, "Add Replication Guides");
                }
                if (fNode.GetRemoveReplicationState() == true)
                {
                    nodeItems.Add(Configurations.RemoveReplicationGuides, "Remove Replication Guides");
                }
            }
            nodeItems.Add(Configurations.DeleteNode, "Delete Node");
        }
Ejemplo n.º 13
0
        internal override void SetContent(object content)
        {
            this.content = content;
            previewType &= ~PreviewTypes.String;
            previewType &= ~PreviewTypes.Bitmap;
            previewType &= ~PreviewTypes.Unknown;
            VisualNode node = graphController.GetVisualNode(this.nodeId);

            DesignScriptStudio.Renderer.ThumbnailData thumbnailData = null;
            thumbnailData = content as DesignScriptStudio.Renderer.ThumbnailData;
            if (null != thumbnailData)
            {
                int stride = thumbnailData.width * 4;
                this.content = BitmapSource.Create(thumbnailData.width, thumbnailData.height,
                                                   96, 96, PixelFormats.Bgra32, null, thumbnailData.pixels, stride);

                previewType |= PreviewTypes.Bitmap;
            }
            else if (null != content as BitmapSource)
            {
                this.content = content as BitmapSource;
                previewType |= PreviewTypes.Bitmap;
            }
            else
            {
                if (content == null)
                {
                    condensedString = null;
                }
                else
                {
                    condensedString = Condense(content.ToString());
                }

                previewType |= PreviewTypes.String;
            }

            this.extendedBubbleWidth  = double.MinValue;
            this.extendedBubbleHeight = double.MinValue;
            node.Dirty = true;
        }
        public bool GetNodeText(uint compId, NodePart nodePart, out string text)
        {
            text = string.Empty;
            VisualNode newNode = this.GetVisualNode(compId);

            if (null == newNode)
            {
                return(false);
            }

            if (nodePart == NodePart.Caption)
            {
                text = newNode.Caption;
                return(true);
            }
            else if (nodePart == NodePart.Text)
            {
                text = newNode.Text;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 15
0
        // if it is node, once it is selected, it will be brought to the top
        // if it is bubble, if its selected, it will follow its owners' z-index, if unselected, send to back,
        // edge is different, when the edge is moving, it is drawn in another drawingVisual which is topmost,
        // when the edge moving is done, it will draw on the old/own drawingVisual
        //
        private void RearrangeNodeAndBubbleVisual(VisualNode node, bool bringToFront)
        {
            if (null == visualHost)
                return;

            uint errorBubbleId = node.GetErrorBubbleId();
            uint previewBubbleId = node.GetPreviewBubbleId();

            if (bringToFront)
            {
                visualHost.RearrangeDrawingVisual(node.NodeId, bringToFront, uint.MaxValue);

                if (errorBubbleId != uint.MaxValue)
                    visualHost.RearrangeDrawingVisual(errorBubbleId, bringToFront, node.NodeId);

                if (previewBubbleId != uint.MaxValue)
                    visualHost.RearrangeDrawingVisual(previewBubbleId, bringToFront, node.NodeId);
            }
            else
            {
                if (errorBubbleId != uint.MaxValue)
                    visualHost.RearrangeDrawingVisual(errorBubbleId, bringToFront, uint.MaxValue);

                if (previewBubbleId != uint.MaxValue)
                    visualHost.RearrangeDrawingVisual(previewBubbleId, bringToFront, uint.MaxValue);
            }
        }
Ejemplo n.º 16
0
        internal void UpdateVariablesDefinedInNode(VisualNode node, bool isPriority)
        {
            List<string> mappingToRemove = new List<string>();
            List<string> variables = node.GetDefinedVariables(false);

            if (null != variables)
            {
                foreach (KeyValuePair<string, List<uint>> kvp in this.variableNodesMap)
                {
                    if (!variables.Contains(kvp.Key) && kvp.Value.Contains(node.NodeId))
                        mappingToRemove.Add(kvp.Key);
                }
            }

            foreach (string variable in mappingToRemove)
                this.RemoveDefinition(variable, node.NodeId);

            if (null != variables)
            {
                foreach (string variable in variables)
                    this.AddDefinition(variable, node.NodeId, isPriority);
            }

            if (null != undefinedVarsTracker && (mappingToRemove.Count > 0))
            {
                if (!undefinedVarsTracker.ContainsKey(node.NodeId))
                    undefinedVarsTracker.Add(node.NodeId, new List<string>());

                foreach (string variable in mappingToRemove)
                    undefinedVarsTracker[node.NodeId].Add(variable);
            }
        }
Ejemplo n.º 17
0
        private void EstablishExplicitInputConnection(VisualNode endNode, Connection connection, List<IVisualNode> modifiedNodes)
        {
            VisualNode startNode = (VisualNode)nodeCollection[connection.OtherNode];
            uint startSlotId = startNode.GetOutputSlot(connection.OtherIndex);
            uint endSlotId = endNode.GetInputSlot(connection.LocalIndex);
            Slot outputSlot = GetSlot(startSlotId) as Slot;
            Slot inputSlot = GetSlot(endSlotId) as Slot;
            edgeController.CreateLinkingEdge(outputSlot, inputSlot);
            startNode.HandleNewConnection(startSlotId);
            endNode.HandleNewConnection(endSlotId);

            modifiedNodes.Add(startNode);
            modifiedNodes.Add(endNode);
        }
Ejemplo n.º 18
0
        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);
        }
        private bool HandleSelectedMenuItem(GraphCommand command)
        {
            int         menuItemId   = (int)command.GetArgument(0);
            double      mouseX       = ((double)command.GetArgument(1));
            double      mouseY       = ((double)command.GetArgument(2));
            uint        nodeId       = (uint)command.GetArgument(3);
            NodePart    part         = ((NodePart)command.GetArgument(4));
            LibraryItem selectedItem = new LibraryItem();

            VisualNode node = this.GetVisualNode(nodeId);

            if (itemsProvider != null)
            {
                selectedItem = this.itemsProvider.GetItem(menuItemId);
            }

            if (selectedItem == null) //No match in the library
            {
                if (part == NodePart.NorthWest)
                {
                    this.HandleTopLeftSelectedItem(menuItemId, nodeId);
                }
                else if (menuItemId == Configurations.ConvertNodeToCode)
                {
                    HandleConvertSelectionToCode();
                    return(true);
                }
                else if (menuItemId < Configurations.PropertyBase)
                {
                    // @TODO(Joy): Use switch-case for "menuItemId".
                    ProcessPreviewMenuItems(menuItemId, nodeId);
                    UpdateDirtyNodes();
                    return(true);
                }
            }
            else //Item found in library
            {
                if (selectedItem.Children != null && selectedItem.Children.Count > 0)
                {
                    selectedItem = selectedItem.Children[0];
                }

                LibraryItem.MemberType itemType   = this.GetItemType(menuItemId);
                DeltaNodes             deltaNodes = new DeltaNodes();
                VisualNode             newNode    = null;

                if (part == NodePart.NorthEast)
                {
                    if (selectedItem.Type == LibraryItem.MemberType.InstanceProperty)
                    {
                        if (selectedItem.ItemType == NodeType.Function)
                        {
                            newNode = this.CreateMethodNode(mouseX, mouseY, selectedItem.Assembly, selectedItem.QualifiedName, selectedItem.ArgumentTypes);
                        }
                        else
                        {
                            newNode = this.CreatePropertyNode(mouseX, mouseY, selectedItem.Assembly, selectedItem.QualifiedName, selectedItem.ArgumentTypes);
                        }

                        deltaNodes.AppendToAddedNodes(newNode);
                    }
                    else if (selectedItem.Type == LibraryItem.MemberType.InstanceMethod)
                    {
                        newNode = this.CreateMethodNode(mouseX, mouseY, selectedItem.Assembly, selectedItem.QualifiedName, selectedItem.ArgumentTypes);
                        deltaNodes.AppendToAddedNodes(newNode);
                    }

                    if (newNode != null && (null != deltaNodes.AddedNodes) && deltaNodes.AddedNodes.Count > 0)
                    {
                        // @keyu: If we are acessing its member function or
                        // property, there is no reason to mark this node as
                        // dirty. Comment it out to avoid to recreate object.
                        //
                        // deltaNodes.AppendToModifiedNodes(node);

                        Slot inputSlot  = this.GetSlot(newNode.GetInputSlot(0)) as Slot;
                        Slot outputSlot = this.GetSlot(node.GetOutputSlot(0)) as Slot;

                        this.undoRedoRecorder.BeginGroup();
                        this.undoRedoRecorder.RecordRuntimeStatesForUndo(this.graphProperties.RuntimeStates);
                        this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
                        this.graphProperties.RuntimeStates.AddVariablesDefinedInNode(newNode, false);
                        this.edgeController.CreateLinkingEdge(outputSlot, inputSlot);
                        this.undoRedoRecorder.RecordNodeCreationForUndo(deltaNodes.AddedNodes);
                        this.undoRedoRecorder.EndGroup();

                        //After EstablishLinkingConnection() is executed, the nodes in the nodeToModify would already be modified
                        this.SynchronizeToLiveRunner(deltaNodes);
                    }
                }
                else if (part == NodePart.North)
                {
                    if (itemType == LibraryItem.MemberType.Constructor)
                    {
                        deltaNodes.AppendToModifiedNodes(node);
                        deltaNodes.AppendToModifiedNodes(FindAssociatedNodesFromNodes(deltaNodes.ModifiedNodes));

                        this.undoRedoRecorder.BeginGroup();
                        this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
                        //this.undoRedoRecorder.RecordEdgeModificationForUndo(edgeController.FindEdgeConnectTo(node));
                        ((FunctionNode)node).ChangeConstructor(selectedItem.QualifiedName, selectedItem.ArgumentTypes, selectedItem.ArgumentNames);
                        this.undoRedoRecorder.EndGroup();
                        //After ChangeConstructor() is executed, the nodes in the nodeToModify would already be modified
                        this.SynchronizeToLiveRunner(deltaNodes);
                    }
                    else if (itemType == LibraryItem.MemberType.InstanceProperty)
                    {
                        deltaNodes.AppendToRemovedNodes(node);
                        deltaNodes.AppendToModifiedNodes(this.FindAssociatedNodesFromNodes(deltaNodes.RemovedNodes));

                        newNode = this.CreatePropertyNode(mouseX, mouseY, selectedItem.Assembly, selectedItem.QualifiedName, selectedItem.ArgumentTypes);
                        deltaNodes.AppendToAddedNodes(newNode);

                        this.undoRedoRecorder.BeginGroup();
                        this.undoRedoRecorder.RecordRuntimeStatesForUndo(this.graphProperties.RuntimeStates);
                        this.undoRedoRecorder.RecordNodeDeletionForUndo(deltaNodes.RemovedNodes);
                        this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
                        this.TransferInformationFromMethodToProperty(node, newNode);
                        this.undoRedoRecorder.RecordNodeCreationForUndo(deltaNodes.AddedNodes);
                        this.DeleteNodes(deltaNodes.RemovedNodes);
                        this.undoRedoRecorder.EndGroup();

                        //After DeleteNodes() is executed, the nodes in the nodeToModify would already be modified
                        this.SynchronizeToLiveRunner(deltaNodes);
                    }
                    else if (itemType == LibraryItem.MemberType.InstanceMethod)
                    {
                        deltaNodes.AppendToModifiedNodes(node);
                        deltaNodes.AppendToModifiedNodes(FindAssociatedNodesFromNodes(deltaNodes.ModifiedNodes));

                        this.undoRedoRecorder.BeginGroup();
                        this.undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
                        ((FunctionNode)node).ChangeMethod(selectedItem.QualifiedName, selectedItem.ArgumentTypes);
                        this.undoRedoRecorder.EndGroup();

                        //After ChangeConstructor() is executed, the nodes in the nodeToModify would already be modified
                        this.SynchronizeToLiveRunner(deltaNodes);
                    }
                }
            }

            this.UpdateDirtyNodes();
            edgeController.UpdateEdgeConnectTo(node);
            return(true);
        }
Ejemplo n.º 20
0
        internal void Compose()
        {
            GraphController  controller = graphController as GraphController;
            IGraphVisualHost visualHost = controller.GetVisualHost();

            if (null == visualHost)
            {
                return; // Running in headless mode, draw no further.
            }
            DrawingVisual  bubbleVisual   = visualHost.GetDrawingVisualForBubble(this.bubbleId);
            DrawingContext drawingContext = bubbleVisual.RenderOpen();

            string text = this.content as string;

            if (string.IsNullOrEmpty(text))
            {
                drawingContext.Close();
                return;
            }

            if (this.ErrType == ErrorType.None)
            {
                ErrorManager.HandleError(new InvalidOperationException("'errorType' is not set"));
            }

            VisualNode node = graphController.GetVisualNode(this.OwnerId);

            this.anchorPoint.X = node.Width / 2;
            this.anchorPoint.Y = -Configurations.InfoBubbleTopMargin;
            this.anchorPoint   = new Point((int)this.anchorPoint.X, (int)this.anchorPoint.Y);
            this.arrowLeft     = new Point((int)this.anchorPoint.X - Configurations.InfoBubbleArrowWidthHalf, (int)this.anchorPoint.Y - Configurations.InfoBubbleArrowHeight);
            this.arrowRight    = new Point((int)this.anchorPoint.X + Configurations.InfoBubbleArrowWidthHalf, (int)this.anchorPoint.Y - Configurations.InfoBubbleArrowHeight);
            this.arrowLeft.Offset(-1, -2);
            this.arrowRight.Offset(1, -2);

            double          textLength;
            int             textHorizontalMargin;
            int             textVerticalMargin;
            FormattedText   newText;
            SolidColorBrush textColor;
            SolidColorBrush backgroundColor;
            Pen             borderPen;

            if (this.ErrType == ErrorType.Warning)
            {
                textColor       = Configurations.ErrorBubbleWarningTextColor;
                borderPen       = Configurations.ErrorBubbleWarningBorderPen;
                backgroundColor = Configurations.ErrorBubbleWarningBackground;
            }
            else
            {
                textColor = Configurations.ErrorBubbleErrorTextColor;
                borderPen = Configurations.ErrorBubbleErrorBorderPen;
                //if (this.node.Selected == true)
                backgroundColor = Configurations.ErrorBubbleErrorBackgroundActive;
                //else
                //    backgroundColor = Configurations.ErrorBubbleErrorBackgroundNonActive;
            }

            textHorizontalMargin = Configurations.InfoBubbleMargin;
            textVerticalMargin   = Configurations.InfoBubbleMargin;

            newText = new FormattedText(text,
                                        Configurations.culture,
                                        FlowDirection.LeftToRight,
                                        Configurations.TypeFace,
                                        Configurations.InfoBubbleText,
                                        textColor);

            newText.LineHeight = Configurations.InfoBubbleText;
            textLength         = newText.WidthIncludingTrailingWhitespace;

            this.rectWidth  = (int)(textLength + textHorizontalMargin * 2);
            this.rectHeight = (int)(textVerticalMargin * 2 + newText.Height);
            if (this.rectWidth < Configurations.InfoBubbleMinWidth)
            {
                this.rectWidth = Configurations.InfoBubbleMinWidth;
            }

            this.rectPoint = new Point((int)(this.anchorPoint.X - this.rectWidth / 2) + 0.5, (int)(this.anchorPoint.Y - Configurations.InfoBubbleArrowHeight - this.rectHeight) + 0.5);

            //Draw Bubble
            base.DrawBubble(drawingContext, backgroundColor, borderPen, true);

            //Draw Text
            drawingContext.DrawText(newText, new Point(this.rectPoint.X + textHorizontalMargin, this.rectPoint.Y + textVerticalMargin));
            drawingContext.Close();

            TranslateTransform transform = bubbleVisual.Transform as TranslateTransform;

            transform.X = node.X;
            transform.Y = node.Y;
        }
        private bool HandleMouseUp(GraphCommand command)
        {
            MouseButton  button    = ((MouseButton)command.GetArgument(0));
            uint         compId    = ((uint)command.GetArgument(1));
            NodePart     nodePart  = ((NodePart)command.GetArgument(2));
            int          slotIndex = ((int)command.GetArgument(3));
            ModifierKeys modifiers = ((ModifierKeys)command.GetArgument(4));

            if (currentDragState == DragState.None)
            {
                IVisualNode node    = null;
                VisualNode  visNode = null;
                nodeCollection.TryGetValue(compId, out node);
                if (null != node)
                {
                    visNode = node as VisualNode;
                }

                switch (nodePart)
                {
                case NodePart.InputSlot:
                case NodePart.OutputSlot:
                case NodePart.NorthWest:
                case NodePart.South:
                case NodePart.Caption:
                case NodePart.Text:
                case NodePart.North:
                case NodePart.ReplicationGuide:
                case NodePart.InputLabel:
                    break;

                case NodePart.NorthEast:
                    visNode.ToggleContextualMenu(nodePart);
                    break;

                case NodePart.Preview:
                    //visNode.TogglePreview();
                    break;

                case NodePart.PreviewNorthEast:
                    //visNode.ToggleContextualMenu(nodePart);
                    break;

                default:
                    if (!modifiers.HasFlag(ModifierKeys.Control) && !modifiers.HasFlag(ModifierKeys.Shift))
                    {
                        ClearSelectionInternal();
                    }
                    break;
                }

                if (visualHost != null && visNode != null && visNode.Selected)
                {
                    visualHost.ScrollToVisual(visualHost.GetDrawingVisualForNode(visNode.NodeId));
                }
            }
            else if (currentDragState != DragState.CurveDrawing && currentDragState != DragState.EdgeReconnection) // for click and drag
            {
                currentDragState = DragState.None;                                                                 // it won't end when mouseup on the same slot
            }
            // IDE-1371
            selectionBox.UpdateSelectionBox(GetSelectedNodes());
            return(true);
        }
        public void SetMouseCursor(uint nodeId, NodePart nodePart, int index, ModifierKeys modifiers, bool isMouseButtonDown, double x, double y)
        {
            if (0 == nodeId)
            {
                // When the UI calls this method, we are only expecting two possible
                // value ranges for 'nodeId': a "uint.MaxValue" when the 'nodeId' is
                // invalid, or a positive number. This should not be zero, if it is,
                // do let me know. - Ben.
                throw new ArgumentException("121B20BE: Invalid argument!", "nodeId");
            }

            if (currentDragState == DragState.NodeRepositioning)
            {
                if (!isMouseButtonDown)
                {
                    return;
                }

                foreach (DraggedNode draggedNode in dragSet)
                {
                    if (visualHost != null)
                    {
                        VisualNode         node      = (VisualNode)draggedNode.node;
                        DrawingVisual      visual    = visualHost.GetDrawingVisualForNode(node.NodeId);
                        TranslateTransform transform = visual.Transform as TranslateTransform;

                        transform.X = x - draggedNode.DeltaX;
                        transform.Y = y - draggedNode.DeltaY;

                        node.X = transform.X;
                        node.Y = transform.Y;

                        this.TransformBubble(node, transform);
                    }
                }
                edgeController.UpdateSelectedEdges();

                selectionBox.UpdateSelectionBox(x, y);
            }
            else if ((currentDragState == DragState.CurveDrawing) || (currentDragState == DragState.EdgeReconnection))
            {
                if (nodePart != NodePart.None && nodeId == uint.MaxValue)
                {
                    throw new InvalidOperationException("Nodepard and NodeId are not in consistent (914C54A64BFD)");
                }

                VisualNode node = null;
                edgeConnection = EdgeConnectionFlag.None;

                if (nodePart != NodePart.None)
                {
                    node = GetVisualNode(nodeId);
                }
                else
                {
                    if (lastHoveredNodeId != uint.MaxValue && lastHoveredNodeId != edgeController.GetCurrentlySelectedNodeId())
                    {
                        node = GetVisualNode(lastHoveredNodeId);
                        node.PreviewSelected = node.Selected;//reset the original state of the node
                        RearrangeNodeAndBubbleVisual(node, false);
                    }
                }
                //verification
                List <IVisualNode> nodeToModify;
                edgeConnection = edgeController.AttemptConnectEdge(node, nodePart, index, out nodeToModify);

                if (nodePart != NodePart.None)
                {
                    if ((edgeConnection == EdgeConnectionFlag.NewEdge || edgeConnection == EdgeConnectionFlag.ReconnectEdge) &&
                        (nodePart == NodePart.InputSlot || nodePart == NodePart.InputLabel || nodePart == NodePart.ReplicationGuide))
                    {
                        node.SetHoveredIndex(index);
                    }

                    node.PreviewSelected = true;
                    RearrangeNodeAndBubbleVisual(node, true);
                }

                if (edgeConnection != EdgeConnectionFlag.None && edgeConnection != EdgeConnectionFlag.Illegal)
                {
                    edgeController.DrawConnectingEdgeTo();
                }
                else
                {
                    edgeController.DrawConnectingEdgeTo(new Point(x, y));
                }

                lastHoveredNodeId = nodeId;
                if (null != node)
                {
                    node.Compose(); // Optionally redraw the node.
                }
            }
        }
Ejemplo n.º 23
0
        internal EdgeConnectionFlag AttemptConnectEdge(VisualNode node, NodePart nodePart, int index, out List<IVisualNode> nodeToModify)
        {
            nodeToModify = new List<IVisualNode>();

            connectNodeId = uint.MaxValue;
            connectSlotId = uint.MaxValue;
            connectSlotType = SlotType.None;
            SlotType startSlotType = SlotType.None;

            if (node != null)
            {
                connectNodeId = node.NodeId;

                if (graphController.CurrentDragState == DragState.CurveDrawing)
                {
                    if (currentlySelectedNodeId == connectNodeId)
                        return EdgeConnectionFlag.None;

                    startSlotType = currentlySelectedSlotType;
                }
                else
                {
                    foreach (uint slotId in reconnectingSlots)   //try to connect any of the reconnecting node
                    {
                        if (connectNodeId == graphController.GetSlot(slotId).Owners.Last())
                            return EdgeConnectionFlag.None;
                    }

                    if (graphController.GetSlot(lastConnectedSlotId).SlotType == SlotType.Output)
                        startSlotType = SlotType.Input;
                    else
                        startSlotType = SlotType.Output;
                }

                if (nodePart == NodePart.InputSlot || nodePart == NodePart.InputLabel || nodePart == NodePart.ReplicationGuide)
                {
                    connectSlotType = SlotType.Input;
                    connectSlotId = node.GetInputSlot(index);
                }
                else if (nodePart == NodePart.OutputSlot || (nodePart == NodePart.Text && node.VisualType != NodeType.CodeBlock)) // user can only connect to the output slot of the CBN
                {
                    connectSlotType = SlotType.Output;
                    connectSlotId = node.GetOutputSlot(index);
                }
                else if (node.VisualType == NodeType.Identifier && nodePart == NodePart.Caption)
                {
                    if (startSlotType == SlotType.Output)
                    {
                        connectSlotType = SlotType.Input;
                        connectSlotId = node.GetInputSlot(0);
                    }
                    else if (startSlotType == SlotType.Input)
                    {
                        connectSlotType = SlotType.Output;
                        connectSlotId = node.GetOutputSlot(0);
                    }
                }
            }

            if (graphController.CurrentDragState == DragState.CurveDrawing)
            {
                if (connectSlotId == 0 || connectSlotId == uint.MaxValue)
                    return EdgeConnectionFlag.None;
                if (currentlySelectedSlotType == connectSlotType)
                    return EdgeConnectionFlag.Illegal;

                // Check if these is a edge between the two slots already
                if (startSlotType == SlotType.Input)
                {
                    this.inputSlotId = currentlySelectedSlotId;
                    this.outputSlotId = connectSlotId;
                }
                else
                {
                    this.inputSlotId = connectSlotId;
                    this.outputSlotId = currentlySelectedSlotId;
                }

                var entry = edgeCollection.FirstOrDefault(x => IsAdded(x.Value));
                if ((edgeCollection.Count() != 0) && (entry.Value != null))
                    return EdgeConnectionFlag.None;

                nodeToModify.Add(graphController.GetVisualNode(currentlySelectedNodeId));
                nodeToModify.Add(node);

                //check if it is a edge replace(the input slot is connect to other node already)
                if (FindEdgeToBeReplaced(out edgeToBeReplaced))
                {
                    nodeToModify.Add(graphController.GetVisualNode
                                            (graphController.GetSlot(edgeToBeReplaced.StartSlotId).Owners.Last()));
                    nodeToModify.Add(graphController.GetVisualNode
                                            (graphController.GetSlot(edgeToBeReplaced.EndSlotId).Owners.Last()));
                }
                return EdgeConnectionFlag.NewEdge;
            }
            else
            {
                nodeToModify.Add(graphController.GetVisualNode
                                            (graphController.GetSlot(lastConnectedSlotId).Owners.Last()));
                foreach (uint slotId in reconnectingSlots)
                {
                    nodeToModify.Add(graphController.GetVisualNode
                                        (graphController.GetSlot(slotId).Owners.Last()));
                }

                if (connectSlotId == 0 || connectSlotId == uint.MaxValue)
                    return EdgeConnectionFlag.None;
                if (connectSlotType != graphController.GetSlot(lastConnectedSlotId).SlotType)
                    return EdgeConnectionFlag.Illegal;

                if (lastConnectedSlotId == connectSlotId) // node modification is needed only when the it reconnect to different slot
                {
                    nodeToModify = new List<IVisualNode>();
                }
                else
                {
                    nodeToModify.Add(node);

                    //check if it is a edge replace(the input slot is connect to other node already)
                    if (FindEdgeToBeReplaced(reconnectingSlots[0], out edgeToBeReplaced))
                    {
                        if (!reconnectingEdges.Contains(edgeToBeReplaced.EdgeId))
                        {
                            nodeToModify.Add(graphController.GetVisualNode
                                                    (graphController.GetSlot(edgeToBeReplaced.StartSlotId).Owners.Last()));
                            nodeToModify.Add(graphController.GetVisualNode
                                                    (graphController.GetSlot(edgeToBeReplaced.EndSlotId).Owners.Last()));
                        }
                    }
                }

                return EdgeConnectionFlag.ReconnectEdge;
            }
        }
        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);
        }
Ejemplo n.º 25
0
        private void BeginDragSelectedNodes(double mouseX, double mouseY, VisualNode node)
        {
            if (node.Selected)
            {
                List<IVisualNode> nodeList = new List<IVisualNode>();
                foreach (IVisualNode visualNode in nodeCollection.Values)
                {
                    if (((VisualNode)visualNode).Selected)
                    {
                        nodeList.Add(visualNode);

                        DraggedNode draggedNode = new DraggedNode(visualNode);
                        draggedNode.DeltaX = mouseX - ((VisualNode)visualNode).X;
                        draggedNode.DeltaY = mouseY - ((VisualNode)visualNode).Y;
                        dragSet.Add(draggedNode);

                        edgeController.SelectEdges(visualNode);

                        //both node that the edge is connected to should be bring to front
                        foreach (VisualNode connectingNode in edgeController.GetNodesFromSelectedEdges())
                            RearrangeNodeAndBubbleVisual(connectingNode, true);
                    }
                }

                if (nodeList.Count > 0)
                {
                    this.undoRedoRecorder.BeginGroup();
                    this.undoRedoRecorder.RecordNodeModificationForUndo(nodeList);
                    edgeController.BeginUpdateEdge();
                    this.undoRedoRecorder.EndGroup();
                }
            }
            currentDragState = DragState.NodeRepositioning;

            selectionBox.SetRelativePositionToMouse(mouseX, mouseY);
        }
Ejemplo n.º 26
0
        private void CreateNodeInternal(VisualNode node, double x, double y)
        {
            if (null == node)
                throw new ArgumentNullException("node");

            if (CoreComponent.Instance.StudioSettings.SuppressPreview)
                node.SetNodeState(States.PreviewHidden);

            node.X = x;
            node.Y = y;
            node.Compose(); // Just to compute the dimension.

            DeltaNodes deltaNodes = new DeltaNodes();
            deltaNodes.AppendToAddedNodes(node);

            if (node.VisualType != NodeType.CodeBlock)
            {
                bool visualOnlyNode = (node.VisualType == NodeType.Condensed ||
                    (node.VisualType == NodeType.Render));

                this.undoRedoRecorder.BeginGroup();
                this.undoRedoRecorder.RecordRuntimeStatesForUndo(this.graphProperties.RuntimeStates);
                this.undoRedoRecorder.RecordNodeCreationForUndo(deltaNodes.AddedNodes);
                this.graphProperties.RuntimeStates.AddVariablesDefinedInNode(node, false);

                if (false == visualOnlyNode)
                {
                    List<IVisualNode> modifiedNodes = new List<IVisualNode>();
                    EstablishImplicitConnections(modifiedNodes);
                    deltaNodes.AppendToModifiedNodes(modifiedNodes);
                }

                this.undoRedoRecorder.EndGroup();

                if (false == visualOnlyNode)
                    this.SynchronizeToLiveRunner(deltaNodes);
            }

            this.UpdateDirtyNodes();
            node.PositionAtCenter(node.NodeId);
        }
Ejemplo n.º 27
0
 private bool IsInDragSet(VisualNode node, List<DraggedNode> dragSet)
 {
     foreach (DraggedNode draggedNode in dragSet)
     {
         if (draggedNode.node == node)
             return true;
     }
     return false;
 }
        private bool HandleMouseDown(GraphCommand command)
        {
            MouseButton  button    = ((MouseButton)command.GetArgument(0));
            uint         compId    = ((uint)command.GetArgument(1));
            NodePart     nodePart  = ((NodePart)command.GetArgument(2));
            int          slotIndex = ((int)command.GetArgument(3));
            ModifierKeys modifiers = ((ModifierKeys)command.GetArgument(4));

            if (nodePart != NodePart.None)
            {
                if (IdGenerator.GetType(compId) != ComponentType.Node)
                {
                    throw new InvalidOperationException("Component type mismatch!");
                }
                IVisualNode node = null;
                nodeCollection.TryGetValue(compId, out node);
                if (null == node)
                {
                    throw new ArgumentException("Invalid argument!", "compId");
                }
                VisualNode visualNode = node as VisualNode;

                switch (nodePart)
                {
                case NodePart.North:
                case NodePart.South:
                case NodePart.NorthEast:
                case NodePart.NorthWest:
                case NodePart.PreviewNorthEast:
                case NodePart.Preview:
                    ClearSelectionInternal();
                    RearrangeNodeAndBubbleVisual(visualNode, true);
                    visualNode.Selected = true;
                    break;

                case NodePart.Caption:
                case NodePart.Text:
                case NodePart.ReplicationGuide:
                case NodePart.InputLabel:
                    if (visualNode.Selected)
                    {
                        if (modifiers.HasFlag(ModifierKeys.Control))     //remove the selected node and update the edge
                        {
                            visualNode.Selected = false;
                        }
                    }
                    else
                    {
                        if (!modifiers.HasFlag(ModifierKeys.Control) && !modifiers.HasFlag(ModifierKeys.Shift))
                        {
                            ClearSelectionInternal();
                        }
                        RearrangeNodeAndBubbleVisual(visualNode, true);
                        visualNode.Selected = true;
                    }
                    break;

                case NodePart.InputSlot:
                case NodePart.OutputSlot:
                    break;
                }

                if (null != visualNode)
                {
                    visualNode.Compose(); // Redraw for selection change.
                }
            }

            selectionBox.UpdateSelectionBox(GetSelectedNodes());
            return(true);
        }
Ejemplo n.º 29
0
        private void TransformBubble(VisualNode node, TranslateTransform transform)
        {
            uint errorBubbleId = node.GetErrorBubbleId();
            uint previewBubbleId = node.GetPreviewBubbleId();

            if (errorBubbleId != uint.MaxValue)
            {
                DrawingVisual errorVisual = visualHost.GetDrawingVisualForBubble(errorBubbleId);
                //RearrangeVisual(errorBubbleId, true);
                errorVisual.Transform = transform;
            }

            if (previewBubbleId != uint.MaxValue)
            {
                DrawingVisual previewVisual = visualHost.GetDrawingVisualForBubble(previewBubbleId);
                //RearrangeVisual(previewBubbleId, true);
                previewVisual.Transform = transform;
            }
        }
        private bool HandleEndDrag(GraphCommand command)
        {
            MouseButton  button    = ((MouseButton)command.GetArgument(0));
            uint         compId    = ((uint)command.GetArgument(1));
            NodePart     nodePart  = ((NodePart)command.GetArgument(2));
            int          slotIndex = ((int)command.GetArgument(3));
            ModifierKeys modifiers = ((ModifierKeys)command.GetArgument(4));
            double       mouseX    = ((double)command.GetArgument(5));
            double       mouseY    = ((double)command.GetArgument(6));

            switch (currentDragState)
            {
            case DragState.NodeRepositioning:
                foreach (DraggedNode draggedNode in dragSet)
                {
                    ((VisualNode)draggedNode.node).X = mouseX - draggedNode.DeltaX;
                    ((VisualNode)draggedNode.node).Y = mouseY - draggedNode.DeltaY;
                }

                // both node that the edge is connected to should be bring to back
                //
                foreach (VisualNode connectingNode in edgeController.GetNodesFromSelectedEdges())
                {
                    if (!connectingNode.Selected)
                    {
                        RearrangeNodeAndBubbleVisual(connectingNode, false);
                    }
                }

                dragSet.Clear();
                edgeController.ResetAllEdges();
                break;

            case DragState.CurveDrawing:
            case DragState.EdgeReconnection:
                edgeConnection = EdgeConnectionFlag.None;

                VisualNode node = GetVisualNode(edgeController.GetConnectNodeId());
                if (null != node)
                {
                    node.PreviewSelected = node.Selected;
                    node.Compose();     // Optionally redraw the node.
                }
                node = GetVisualNode(edgeController.GetCurrentlySelectedNodeId());
                if (null != node)
                {
                    node.Selected = false;
                    node.Compose();     // reset highlighted node
                }

                node = GetVisualNode(compId);
                List <IVisualNode> modifiedNodes = null;
                edgeConnection = edgeController.AttemptConnectEdge(node, nodePart, slotIndex, out modifiedNodes);

                DeltaNodes deltaNodes = new DeltaNodes();
                deltaNodes.AppendToModifiedNodes(modifiedNodes.Distinct().ToList());

                //reset highlighted node
                foreach (IVisualNode visualNode in deltaNodes.ModifiedNodes)
                {
                    ((VisualNode)visualNode).Selected = false;
                }

                // Start tracking variables being undefined in this process.
                {
                    RuntimeStates runtimeStates = graphProperties.RuntimeStates;
                    runtimeStates.BeginDefinitionMonitor();

                    undoRedoRecorder.BeginGroup();
                    undoRedoRecorder.RecordRuntimeStatesForUndo(runtimeStates);
                    undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
                    edgeController.CreateEdge();

                    modifiedNodes.Clear();
                    this.EstablishImplicitConnections(modifiedNodes);
                    undoRedoRecorder.EndGroup();

                    Dictionary <uint, List <string> > undefinedVariables = null;
                    runtimeStates.EndDefinitionMonitor(out undefinedVariables);
                    deltaNodes.AppendUndefinedVariables(undefinedVariables);
                }

                deltaNodes.AppendToModifiedNodes(modifiedNodes);
                if (deltaNodes.ModifiedNodes.Count > 0)      //modification have been done
                {
                    SynchronizeToLiveRunner(deltaNodes);
                }
                else
                {
                    undoRedoRecorder.PopRecordFromUndoStorage();
                }

                edgeController.ResetParameters();
                edgeController.ResetAllEdges();
                currentDragState = DragState.None;
                edgeConnection   = EdgeConnectionFlag.None;
                break;

            case DragState.RegionSelection:
                if (visualHost != null)
                {
                    visualHost.EndDragSelection();
                }
                break;
            }
            //currentDragState = DragState.None;
            selectionBox.UpdateSelectionBox(GetSelectedNodes());
            return(true);
        }
Ejemplo n.º 31
0
        private void TransferInformationFromMethodToProperty(VisualNode sourceNode, VisualNode destinationNode)
        {
            if (sourceNode == null)
                throw new ArgumentNullException("sourceNode");
            if (sourceNode == null)
                throw new ArgumentNullException("destinationNode");

            destinationNode.Text = sourceNode.Text;

            Slot destinationInputSlot = this.GetSlot(destinationNode.GetInputSlot(0)) as Slot;
            Slot sourceInputSlot = this.GetSlot(sourceNode.GetInputSlot(0)) as Slot;
            if (sourceInputSlot.ConnectingSlots != null)
            {
                Slot outputSlot = this.GetSlot(sourceInputSlot.ConnectingSlots[0]) as Slot;
                this.edgeController.CreateLinkingEdge(outputSlot, destinationInputSlot);
            }

            Slot destinationOutputSlot = this.GetSlot(destinationNode.GetOutputSlot(0)) as Slot;
            Slot sourceOutputSlot = this.GetSlot(sourceNode.GetOutputSlot(0)) as Slot;
            if (sourceOutputSlot.ConnectingSlots != null)
            {
                foreach (uint slotId in sourceOutputSlot.ConnectingSlots)
                {
                    Slot inputSlot = this.GetSlot(slotId) as Slot;
                    this.edgeController.CreateLinkingEdge(destinationOutputSlot, inputSlot);
                }
            }

            List<string> defined = sourceNode.GetDefinedVariables(false);
            graphProperties.RuntimeStates.TransferVariableDefinitionMapping(
                defined, sourceNode.NodeId, destinationNode.NodeId);
        }
        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);
        }
Ejemplo n.º 33
0
        internal void AddVariablesDefinedInNode(VisualNode node, bool isPriority)
        {
            List<string> variables = node.GetDefinedVariables(false);
            if (variables == null || variables.Count <= 0)
                return;

            foreach (string variable in variables)
                this.AddDefinition(variable, node.NodeId, isPriority);
        }
Ejemplo n.º 34
0
        private void GetFunctionNodeMenuItems()
        {
            ObservableCollection <LibraryItem> libraryItems = new ObservableCollection <LibraryItem>();

            libraryItemCollection = new Dictionary <int, LibraryItem>();
            VisualNode               node              = graphController.GetVisualNode(this.nodeId);
            FunctionNode             fNode             = (FunctionNode)node;
            Dictionary <int, string> functionNodeItems = new Dictionary <int, string>();

            if (node.GetAssembly() == null || node.ReturnType == null)
            {
                return;
            }
            string[] assemblies  = (node.GetAssembly()).Split(',');
            string[] returnTypes = (node.ReturnType.Split(','));

            switch (nodePart)
            {
            case NodePart.NorthEast:
                //case NodePart.South:
                this.GetMethodsAndProperties(assemblies, returnTypes, libraryItems);
                break;

            case NodePart.North:
                if (fNode.MemberType == LibraryItem.MemberType.Constructor)
                {
                    libraryItems = CoreComponent.Instance.GetConstructors(fNode.Assembly, fNode.QualifiedName);
                }
                else if (fNode.MemberType == LibraryItem.MemberType.InstanceMethod)
                {
                    string   argumentTypes    = fNode.ArgumentTypes;
                    string[] tempArray        = argumentTypes.Split(',');
                    string   parentReturnType = tempArray[0];
                    if (parentReturnType == "this")
                    {
                        uint   slotId          = node.GetInputSlot(0);
                        ISlot  slot            = graphController.GetSlot(slotId);
                        uint[] connectingSlots = slot.ConnectingSlots;
                        if (connectingSlots != null)
                        {
                            ISlot      parentSlot = graphController.GetSlot(connectingSlots[0]);
                            VisualNode visualNode = graphController.GetVisualNode(parentSlot.Owners[0]);
                            parentReturnType = visualNode.ReturnType;
                            string[] tempParent = { parentReturnType };
                            this.GetMethodsAndProperties(assemblies, tempParent, libraryItems);
                            //libraryItems = CoreComponent.Instance.GetMethodsAndProperties(fNode.Assembly, parentReturnType);
                        }
                    }
                    else
                    {
                        libraryItems = CoreComponent.Instance.GetMethodsAndProperties(fNode.Assembly, parentReturnType);
                    }
                }
                break;

            case NodePart.NorthWest:
                Dictionary <int, string> temp = new Dictionary <int, string>();
                this.GetNodeOptions(this.nodeId, out temp);
                functionNodeItems = temp;
                break;

            default:
                break;
            }

            this.PopulateItems(libraryItems);
            return;
        }
Ejemplo n.º 35
0
        internal void RemoveVariablesDefinedInNode(VisualNode node)
        {
            List<string> variables = node.GetDefinedVariables(false);
            if (variables == null || variables.Count <= 0)
                return;

            foreach (string variable in variables)
                this.RemoveDefinition(variable, node.NodeId);
        }
Ejemplo n.º 36
0
        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;
        }
Ejemplo n.º 37
0
        private void EstablishExplicitOutputConnection(VisualNode startNode, Connection connection, List<IVisualNode> modifiedNodes)
        {
            VisualNode endNode = nodeCollection[connection.OtherNode] as VisualNode;
            List<uint> startSlotIds = (startNode as VisualNode).GetSlotIdsByName(SlotType.Output, connection.LocalName);
            uint startSlotId = startSlotIds.Last();
            uint endSlotId = endNode.GetInputSlot(connection.OtherIndex);
            Slot outputSlot = GetSlot(startSlotId) as Slot;
            Slot inputSlot = GetSlot(endSlotId) as Slot;
            edgeController.CreateLinkingEdge(outputSlot, inputSlot);
            (startNode as VisualNode).HandleNewConnection(startSlotId);
            endNode.HandleNewConnection(endSlotId);

            modifiedNodes.Add(startNode);
            modifiedNodes.Add(endNode);
        }