private bool HandleSetReplicationGuideText(GraphCommand command)
        {
            uint   nodeId           = (uint)command.GetArgument(0);
            int    replicationIndex = (int)command.GetArgument(1);
            string text             = ((string)command.GetArgument(2));

            VisualNode node = GetVisualNode(nodeId);

            if (node.VisualType != NodeType.Function)
            {
                throw new InvalidOperationException("Node must be FunctionNode");
            }

            DeltaNodes  deltaNodes = new DeltaNodes();
            IVisualNode iNode      = this.GetVisualNode(nodeId);

            deltaNodes.AppendToModifiedNodes(iNode);

            FunctionNode fNode = node as FunctionNode;

            undoRedoRecorder.BeginGroup();
            undoRedoRecorder.RecordNodeModificationForUndo(deltaNodes.ModifiedNodes);
            undoRedoRecorder.EndGroup();
            fNode.SetReplicationText(replicationIndex, text);
            //if(!fNode.SetReplicationText(replicationIndex,text))
            //    undoRedoRecorder.PopRecordFromUndoStorage();
            node.DisableEdit();
            node.Dirty = true;
            node.Compose();
            this.SynchronizeToLiveRunner(deltaNodes);
            return(true);
        }
        public void PreviewSelectComponent(uint componentId, ModifierKeys modifiers)
        {
            IVisualNode selectedNode = null;

            nodeCollection.TryGetValue(componentId, out selectedNode);

            if (selectedNode != null)
            {
                VisualNode node = (VisualNode)selectedNode;

                if (modifiers.HasFlag(ModifierKeys.Control))//toggle
                {
                    node.PreviewSelected = !node.PreviewSelected;
                }
                else
                {
                    node.PreviewSelected = true;
                }

                node.Compose(); // Optionally redraw the node.
            }
            else
            {
                edgeController.PreviewSelectComponent(componentId, modifiers);
            }
        }
Esempio n. 3
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 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 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);
        }
        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);
        }
        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.
                }
            }
        }
        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);
        }