private bool HandleCreateFunctionNode(GraphCommand command)
        {
            double mouseX        = ((double)command.GetArgument(0));
            double mouseY        = ((double)command.GetArgument(1));
            string assembly      = command.GetArgument(2) as string;
            string qualifiedName = command.GetArgument(3) as string;
            string argumentTypes = command.GetArgument(4) as string;

            FunctionNode node = new FunctionNode(this, assembly, qualifiedName, argumentTypes);

            this.CreateNodeInternal(node, mouseX, mouseY);
            return(true);
        }
        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);
        }
        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);
        }
        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");
        }
        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;
        }
        public void TestHandleSaveGraphAndLoadGraph()
        {
            try
            {
                GraphController graphController1 = new GraphController(null);
                IVisualNode node1 = new CodeBlockNode(graphController1, "Double Click and Type");
                IVisualNode node2 = new DriverNode(graphController1, Configurations.DriverInitialTextValue);
                IVisualNode node3 = new FunctionNode(graphController1, "", "-", "double,double");
                IVisualNode node4 = new IdentifierNode(graphController1, "c");

                string filePath = Path.GetTempPath() + "test.bin";
                graphController1.DoSaveGraph(filePath);
                GraphController graphController2 = new GraphController(null, filePath);

                Assert.AreEqual(4, graphController2.GetVisualNodes().Count);
            }
            finally
            {
                File.Delete(Path.GetTempPath() + "test.bin");
            }
        }
示例#7
0
        public void TestCreate02()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();
            IVisualNode node = new FunctionNode(graphController, "", "-", "double,double");
            ISlot slot1 = new Slot(graphController, SlotType.Input, node);

            slot1.Serialize(storage);
            storage.Seek(0, SeekOrigin.Begin);
            ISlot slot2 = Slot.Create(graphController, storage);

            Assert.AreEqual(SlotType.Input, slot2.SlotType);
            Assert.AreEqual(slot1.SlotId, slot2.SlotId);
            Assert.AreEqual(slot1.Owners[0], slot2.Owners[0]);
            Assert.AreEqual(slot1.ConnectingSlots, slot2.ConnectingSlots);
        }
示例#8
0
        public void TestSerializeNullException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = null;
            IVisualNode node = new FunctionNode(graphController, "", "-", "double,double");
            ISlot slot = new Slot(graphController, SlotType.Input, node);

            Assert.Throws<ArgumentNullException>(() =>
            {
                slot.Serialize(storage);
            });
        }
示例#9
0
        public void TestDeserilaizeOperationException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();
            IVisualNode node = new FunctionNode(graphController, "", "-", "double,double");
            ISlot slot = new Slot(graphController, SlotType.Input, node);

            storage.WriteUnsignedInteger(FieldCode.SlotSignature, 21);
            storage.Seek(0, SeekOrigin.Begin);

            Assert.Throws<InvalidOperationException>(() =>
            {
                slot.Deserialize(storage);
            });
        }
示例#10
0
        public static IVisualNode Create(IGraphController graphController, IStorage storage)
        {
            if (graphController == null || storage == null)
                throw new ArgumentNullException("graphcontroller, storage");

            storage.Seek(12, SeekOrigin.Current); //Skip NodeSignature
            NodeType type = (NodeType)storage.ReadInteger(FieldCode.NodeType);
            storage.Seek(-24, SeekOrigin.Current); //Shift cursor back to the start point of reading NodeSignature
            VisualNode node = null;
            switch (type)
            {
                case NodeType.CodeBlock:
                    node = new CodeBlockNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Condensed:
                    node = new CondensedNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Driver:
                    node = new DriverNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Function:
                    node = new FunctionNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Identifier:
                    node = new IdentifierNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Property:
                    node = new PropertyNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Render:
                    node = new RenderNode(graphController);
                    node.Deserialize(storage);
                    break;
                default:
                    throw new ArgumentException("Invalid 'nodeType'");
            }

            return node;
        }
        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);
        }
        private FunctionNode CreateMethodNode(double mouseX, double mouseY, string assembly, string qualifiedName, string argumentTypes)
        {
            FunctionNode node = new FunctionNode(this, assembly, qualifiedName, argumentTypes);
            node.X = mouseX - Configurations.NodeCreationOffset;
            node.Y = mouseY - Configurations.NodeCreationOffset;

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

            return node;
        }