Example #1
0
        public override List <Tuple <string, object> > Calculate()
        {
            List <Tuple <string, object> > res = new List <Tuple <string, object> >();

            Main.Ports.Port in1 = this.PortManager.GetPort("in1");
            res.Add(new Tuple <string, object>("out", !(bool)in1.GetValue()));
            return(res);
        }
Example #2
0
 public PortViewModel(Main.Ports.Port _model, NodeViewModel parent)
 {
     Parent                  = parent;
     Port                    = _model;
     PortName                = Port.Name;
     IsNotConnected          = true;
     Port.ConnectionChanged += Port_ConnectionChanged;
 }
Example #3
0
 /// <summary>
 /// Connect ports
 /// </summary>
 /// <param name="port1"></param>
 /// <param name="port2"></param>
 public void Connect(Main.Ports.Port port1, Main.Ports.Port port2)
 {
     port1.Parent.ConnectionManager.CreateConnection(port1, port2);
     if (ConnectionCreated != null)
     {
         ConnectionCreated(port1, port2);
     }
 }
Example #4
0
 /// <summary>
 /// Set UpToDate = flag to single port
 /// </summary>
 /// <param name="port"></param>
 /// <param name="recursively">Set recursively to all connected</param>
 private static void PaintPort(Main.Ports.Port port, bool flag, bool recursively)
 {
     port.ValueManager.UpToDate = flag;
     if (recursively)
     {
         foreach (Main.Ports.Port connected in Main.Connections.ConnectionManager.GetAllConnections(port))
         {
             PaintOutputs(connected.Parent, flag, true);
         }
     }
 }
Example #5
0
        /// <summary>
        /// Set value for input
        /// </summary>
        /// <param name="port"></param>
        /// <param name="val"></param>
        public static void SetValue(Main.Ports.Port port, object newVal)
        {
            switch (port.PortType)
            {
            case Main.Ports.PortType.Input:
                port.ValueManager.Value    = newVal;
                port.ValueManager.UpToDate = true;
                PaintOutputs(port.Parent, false, true);
                break;

            case Main.Ports.PortType.Output:
                port.ValueManager.Value = newVal;
                PaintPort(port, false, true);
                port.ValueManager.UpToDate = true;
                break;
            }
        }
Example #6
0
        /// <summary>
        /// Get value in port
        /// </summary>
        public static object GetVal(Main.Ports.Port port)
        {
            if (port.PortType == Main.Ports.PortType.Input)
            {
                if (Main.Connections.ConnectionManager.GetAllConnections(port).Count == 0)
                {
                    // If port is not connected we will return value in this input (Value property)
                    return(port.ValueManager.Value);
                }
                else
                {
                    // If port is connected we will calculate and return value in connected output
                    return(GetVal(Main.Connections.ConnectionManager.GetAllConnections(port)[0]));
                }
            }

            // If we don't need to update value, just return it
            if (port.ValueManager.UpToDate)
            {
                return(port.ValueManager.Value);
            }
            else
            {
                // If update = true we must calculate value. For calculation we need input ports, so let's update them
                foreach (Main.Ports.Port input in port.Parent.PortManager.GetPorts(Main.Ports.PortType.Input))
                {
                    GetVal(input);
                }
            }
            // Set calculated values
            foreach (Tuple <string, object> outp_val in port.Parent.Calculate())
            {
                SetValue(port.Parent.PortManager.GetPort(outp_val.Item1), outp_val.Item2);
            }
            // Now all output ports have right values. (We calculated them) Let's set UpToDate = true to them
            PaintOutputs(port.Parent, true, false);
            return(port.ValueManager.Value);
        }
Example #7
0
 /// <summary>
 /// Delete value if exists
 /// </summary>
 public static void DelValue(Main.Ports.Port port)
 {
     PaintOutputs(port.Parent, false, true);
     port.ValueManager.Value = null;
 }
Example #8
0
 public ValueManager(Main.Ports.Port parentPort)
 {
     Value      = null;
     UpToDate   = true;
     ParentPort = parentPort;
 }
Example #9
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);
        }
 public InputPortViewModel(Main.Ports.Port port1, NodeViewModel parent) : base(port1, parent)
 {
     Val = Port.GetValue();
 }
 public DataTypeException(Main.Ports.Port port1, Main.Ports.Port port2)
     : base(string.Format("To connect {0} and {1} their data types must be the same", port1, port2))
 {
     Port1 = port1;
     Port2 = port2;
 }
 public PortTypesException(Main.Ports.Port port1, Main.Ports.Port port2)
     : base(string.Format("Types of port {0} and {1} are incompatible", port1, port2))
 {
     Port1 = port1;
     Port2 = port2;
 }
 public InfiniteLoopException(Main.Ports.Port port1, Main.Ports.Port port2)
     : base(string.Format("Connected {0} and {1} will cause loop", port1, port2))
 {
     Port1 = port1;
     Port2 = port2;
 }
 public PortIsConnectedException(Main.Ports.Port port)
     : base(string.Format("{0} is already connected", port))
 {
     Port = port;
 }