Ejemplo n.º 1
0
 /// <summary>
 /// Set update = flag to all outputs of this node and do it for all conencted
 /// </summary>
 private static void PaintOutputs(Main.Nodes.Node node, bool flag, bool recursively)
 {
     foreach (Main.Ports.Port output in node.PortManager.GetPorts(Main.Ports.PortType.Output))
     {
         PaintPort(output, flag, recursively);
     }
 }
Ejemplo n.º 2
0
        public NodeViewModel(Main.Nodes.Node model, double left, double top, WorkAreaViewModel parent)
        {
            Parent       = parent;
            NodeModel    = model;
            Name         = NodeModel.Name;
            NodeTypeName = model.GetType().GetField("typeName").GetValue(null) as string;
            IsUpToDate   = false;
            // Get ports
            var _ports = NodeModel.PortManager.GetPorts();

            InputPorts  = new ObservableCollection <InputPortViewModel>();
            OutputPorts = new ObservableCollection <OutputPortViewModel>();
            foreach (Main.Ports.Port p in _ports)
            {
                switch (p.PortType)
                {
                case Main.Ports.PortType.Input:
                    InputPortViewModel inst = new InputPortViewModel(p, this);
                    inst.Port.ValueManager.UpToDateChanged += ValueManager_UpToDateChanged;
                    InputPorts.Add(inst);
                    break;

                case Main.Ports.PortType.Output:
                    OutputPortViewModel inst2 = new OutputPortViewModel(p, this);
                    inst2.Port.ValueManager.UpToDateChanged += ValueManager_UpToDateChanged;
                    OutputPorts.Add(inst2);
                    break;
                }
            }
            Left = left;
            Top  = top;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Return if find is connected with cur(maybe recursively)
        /// </summary>
        public static void LoopVerify(Main.Nodes.Node find, Main.Nodes.Node cur, ref bool loop)
        {
            if (find == cur)
            {
                // Initialy the same node was given
                loop = true;
                return;
            }
            var outputs = cur.PortManager.GetPorts(PortType.Output);

            foreach (Port t in outputs)
            {
                if (loop)
                {
                    return;
                }
                if (!Connected(t))
                {
                    continue;
                }
                foreach (Port z in GetAllConnections(t))
                {
                    if (z.Parent == find)
                    {
                        loop = true;
                        return;
                    }
                    else
                    {
                        LoopVerify(find, z.Parent, ref loop);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 internal PortManager(Main.Nodes.Node parent)
 {
     _parent = parent;
 }
Ejemplo n.º 5
0
        public bool ParseCommand(string command, Main.Nodes.NodeTypesManager nodeTypes, Main.Sceme.Scheme scheme, EndPoint _remote)
        {
            Regex reg   = new Regex(@"^create ([^ ]+)(?: -([^ ]+)){0,1}$");
            Match match = reg.Match(command);
            bool  flag  = false;

            if (match.Success)
            {
                flag = true;
                try
                {
                    string nodeName;
                    if (match.Groups[3].Value != "")
                    {
                        nodeName = match.Groups[3].Value;
                    }
                    else
                    {
                        nodeName = null;
                    }
                    var newNode = scheme.CreateNode(nodeTypes.GetNodeType(match.Groups[1].ToString()), nodeName);
                    PrintSuccess(string.Format("Node '{0}' created", newNode.Name), _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^print(?: -([^ ]+)){0,1}$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    var nodes = scheme.Nodes;
                    foreach (Main.Nodes.Node node in nodes)
                    {
                        if (match.Groups[1].Value != "")
                        {
                            if (node.Name != match.Groups[1].Value)
                            {
                                continue;
                            }
                        }
                        Print(string.Format(">>'{0}' of type '{1}'", node.Name, node.NodeType.Name), _remote);
                        Print("inputs:", _remote);
                        var ports = node.PortManager.GetPorts(Main.Ports.PortType.Input);
                        foreach (Main.Ports.Port port in ports)
                        {
                            if (Main.Connections.ConnectionManager.Connected(port))
                            {
                                Main.Ports.Port _conenctedTo = Main.Connections.ConnectionManager.GetAllConnections(port)[0];
                                Print(string.Format("   {0} : connected to '{1}.{2}'",
                                                    port.Name, _conenctedTo.Parent.Name, _conenctedTo.Name), _remote);
                            }
                            else
                            {
                                Print(string.Format("   {0} : value = {1}", port.Name, Main.Values.ValueManager.GetVal(port)), _remote);
                            }
                        }
                        Print("outputs:", _remote);
                        var outputs = node.PortManager.GetPorts(Main.Ports.PortType.Output);
                        foreach (Main.Ports.Port port in outputs)
                        {
                            Print(string.Format("   {0} : value(calculated) = {1}", port.Name, Main.Values.ValueManager.GetVal(port)), _remote);
                        }
                    }
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^connect ([^ .]+).([^ .]+) ([^ .]+).([^ .]+)$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    Main.Nodes.Node node1 = scheme.Nodes.Find((x) => x.Name == match.Groups[1].Value);
                    Main.Ports.Port port1 = node1.PortManager.GetPort(match.Groups[2].Value);
                    Main.Nodes.Node node2 = scheme.Nodes.Find((x) => x.Name == match.Groups[3].Value);
                    Main.Ports.Port port2 = node2.PortManager.GetPort(match.Groups[4].Value);
                    scheme.Connect(port1, port2);
                    PrintSuccess(string.Format("Conenction between '{0}.{1}' and '{2}.{3}' created",
                                               node1.Name, port1.Name, node2.Name, port2.Name), _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^set ([^ .]+).([^ .]+) (True|False|true|false)$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    Main.Nodes.Node node1 = scheme.Nodes.Find((x) => x.Name == match.Groups[1].Value);
                    Main.Ports.Port port1 = node1.PortManager.GetPort(match.Groups[2].Value);
                    Main.Values.ValueManager.SetValue(port1, Convert.ToBoolean(match.Groups[3].Value));
                    PrintSuccess("Value changed", _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^help$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                PrintHelp(nodeTypes, _remote);
            }

            if (!flag)
            {
                PrintError("No such command", _remote);
            }
            return(true);
        }