Exemplo n.º 1
0
        private void InsertNode(Node node)
        {
            Task.Factory.StartNew(() =>
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
                {
                    _host.AddNode(node, Canvas.GetLeft(this), Canvas.GetTop(this));

                    node.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
                    {
                        if (_host.TemExecPort != null && node.InExecPorts.Count > 0)
                        {
                            if (_host.TemExecPort.ConnectedConnectors.Count > 0)
                            {
                                string id1 = Guid.NewGuid().ToString(), id2 = Guid.NewGuid().ToString();

                                var thirdNode = _host.TemExecPort.ConnectedConnectors[0].EndPort.ParentNode;
                                NodesManager.CreateExecutionConnector(_host, _host.TemExecPort, node.InExecPorts[0],
                                                                      id1);
                                NodesManager.CreateExecutionConnector(_host, node.OutExecPorts[0],
                                                                      thirdNode.InExecPorts[0], id2);
                            }
                            else
                            {
                                NodesManager.CreateExecutionConnector(_host, _host.TemExecPort, node.InExecPorts[0]);
                            }
                        }
                        else if (_host.TemObjectPort != null && node.InputPorts.Count > 0)
                        {
                            NodesManager.CreateObjectConnector(_host, _host.TemObjectPort, node.InputPorts[0]);
                        }
                    }));
                }));
            });
        }
Exemplo n.º 2
0
        private void OnPreviewMouseUp(object o, MouseButtonEventArgs mouseButtonEventArgs)
        {
            if (Host.WireMode != WireMode.FirstPortSelected)
            {
                return;
            }
            if (LinkingPossiblity() != 0)
            {
                if (Host.TemExecPort.ConnectedConnectors.Count == 0)
                {
                    NodesManager.CreateExecutionConnector(Host, Host.TemExecPort, this);
                }
                else
                {
                    var thirdNode = Host.TemExecPort.ConnectedConnectors[0].EndPort.ParentNode;

                    if (thirdNode.OutExecPorts[0].ConnectedConnectors.Count > 0 &&
                        thirdNode.OutExecPorts[0].ConnectedConnectors[0].EndPort.ParentNode == ParentNode)
                    {
                        NodesManager.MiddleMan(Host, Host.TemExecPort.ParentNode, ParentNode, thirdNode);
                    }
                    NodesManager.CreateExecutionConnector(Host, Host.TemExecPort, this);
                    NodesManager.CreateExecutionConnector(Host, ParentNode.OutExecPorts[0],
                                                          thirdNode.InExecPorts[0]);
                }
            }
            Host.Children.Remove(Host.TempConn);
            Host.TemExecPort = null;
            Host.WireMode    = WireMode.Nothing;
            Host.MouseMode   = MouseMode.Nothing;
            Host.HideLinkingPossiblity();
        }
Exemplo n.º 3
0
        private void UpdateWires()
        {
            var varListSelectedItem = (VariableItem)_varList.SelectedItem;

            if (varListSelectedItem != null)
            {
                foreach (var id in varListSelectedItem.DsOfNodes)
                {
                    foreach (var node in Host.Nodes)
                    {
                        if (node.Id == id)
                        {
                            if (node.OutputPorts.Count > 0)
                            {
                                foreach (var conn in node.OutputPorts[0].ConnectedConnectors)
                                {
                                    var xConn = conn;
                                    NodesManager.TryCast(ref xConn);
                                }
                            }
                            else if (node.InputPorts.Count > 0)
                            {
                                foreach (var conn in node.InputPorts[0].ConnectedConnectors)
                                {
                                    var xConn = conn;
                                    NodesManager.TryCast(ref xConn);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public override void Delete(bool deletedByBrain = false)
 {
     try
     {
         Types = NodeTypes.Basic;
         if (InputPorts[0].ConnectedConnectors.Count > 0)
         {
             InputPorts[0].ConnectedConnectors[0].Wire.Visibility = Visibility.Collapsed;
         }
         if (InputPorts[0].ConnectedConnectors.Count > 0)
         {
             InputPorts[0].ConnectedConnectors[0].Wire.Visibility = Visibility.Collapsed;
         }
         InputPorts[0].ConnectedConnectors.Remove(Connector);
         InputPorts[0].ConnectedConnectors.ClearConnectors();
         if (Host.Children.Contains(Start.ParentNode))
         {
             if (Host.Children.Contains(End.ParentNode))
             {
                 if (End.ConnectedConnectors.Count == 0)
                 {
                     NodesManager.CreateObjectConnector(Host, Start, End);
                 }
             }
         }
         Host.Children.Remove(this);
         Host.Nodes.Remove(this);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 5
0
        public void UpdateType(string nameOfType)
        {
            var    varListSelectedItem = (VariableItem)_varList.SelectedItem;
            RTypes rtype;

            switch (nameOfType)
            {
            case "Generic":
                rtype = RTypes.Generic;
                break;

            case "Character":
                rtype = RTypes.Character;
                break;

            case "Logical":
                rtype = RTypes.Logical;
                break;

            case "Numeric":
                rtype = RTypes.Numeric;
                break;

            case "DataFrame":
                rtype = RTypes.DataFrame;
                break;

            default:
                rtype = RTypes.ArrayOrFactorOrListOrMatrix;
                break;
            }
            if (varListSelectedItem != null)
            {
                varListSelectedItem.Type = nameOfType;

                foreach (var id in varListSelectedItem.DsOfNodes)
                {
                    foreach (var node in Host.Nodes)
                    {
                        if (node.Id == id)
                        {
                            if (node.InExecPorts.Count == 0)
                            {
                                node.OutputPorts[0].Data.Type = rtype;
                                NodesManager.ChangeColorOfVariableNode(node.OutputPorts[0], nameOfType);
                            }

                            else if (node.InputPorts != null)
                            {
                                NodesManager.ChangeColorOfVariableNode(node.InputPorts[0], nameOfType);
                                node.InputPorts[0].Data.Type = rtype;
                            }
                        }
                    }
                }
                Application.Current.Dispatcher.BeginInvoke(new Action(UpdateWires));
            }
        }
Exemplo n.º 6
0
        public SelectionManager(NodesManager inManager)
        {
            Manager = inManager;

            if (Selection.Count > 0)
            {
                DeselectAll();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create new node
        /// </summary>
        /// <param name="nodeType"></param>
        /// <param name="name"></param>
        public Node CreateNode(Main.Nodes.NodeType nodeType, string name = null)
        {
            var newNode = NodesManager.CreateNode(nodeType, name);

            if (NodeCreated != null)
            {
                NodeCreated(newNode);
            }
            return(newNode);
        }
Exemplo n.º 8
0
        public SpaghettiDivider(VirtualControl host, Connector connector, bool spontaneousAddition = true) : base(host,
                                                                                                                  NodeTypes.SpaghettiDivider, spontaneousAddition)
        {
            ObjectConnector = connector as ObjectsConnector;
            Host            = host;
            Connector       = connector;
            Start           = connector.StartPort as ObjectPort;
            End             = connector.EndPort as ObjectPort;
            connector.Delete();
            Title = "";
            var inPort  = Connector.EndPort as ObjectPort;
            var outPort = Connector.StartPort as ObjectPort;

            if (outPort != null)
            {
                AddObjectPort(this, "", PortTypes.Input, outPort.Data.Type, true);
            }
            Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
            {
                NodesManager.CreateObjectConnector(host, InputPorts[0], outPort);
                NodesManager.CreateObjectConnector(host, inPort, InputPorts[0]);
                if (Host.NodesTree.IsVisible)
                {
                    Host.NodesTree.Remove();
                }
                InputPorts[0].IsEnabled = false;
                if (InputPorts.Count > 0)
                {
                    if (InputPorts[0].ConnectedConnectors.Count > 0)
                    {
                        Connector.StartPort = InputPorts[0].ConnectedConnectors[0].StartPort;
                    }
                }
                InputPorts[0].DataChanged += (ss, ee) =>
                {
                    End.Data.Value = InputPorts[0].Data.Value;
                    foreach (var c in InputPorts[0].ConnectedConnectors)
                    {
                        c.Wire.HeartBeatsAnimation(false);
                    }
                };
                InputPorts[0].ConnectedConnectors.CollectionChanged += (ss, ee) => { };
                var hint = Template.FindName("NodeHint", this) as Path;
                if (hint != null)
                {
                    hint.Visibility = Visibility.Collapsed;
                }
                Height -= 33;
                Width  -= 13;
                Canvas.SetTop(InputPortsPanel, -8);
                Canvas.SetLeft(InputPortsPanel, 3);
            }));
        }
Exemplo n.º 9
0
 public Get(VirtualControl host, VariableItem variable, bool spontaneousAddition) : base(host,
                                                                                         NodeTypes.VariableGet,
                                                                                         spontaneousAddition)
 {
     Host  = host;
     Title = string.Empty;
     AddObjectPort(this, "Return " + variable.Name, PortTypes.Output, RTypes.Generic, true);
     Description = @"Gets the value of " + variable.Name + ".";
     OutputPorts[0].Data.Value = variable.Name;
     if (variable.Type != null)
     {
         NodesManager.ChangeColorOfVariableNode(OutputPorts[0], variable.Type);
     }
     _item = variable;
     _item.Gets++;
     _item.DsOfNodes.Add(Id);
 }
Exemplo n.º 10
0
        public Set(VirtualControl host, VariableItem variable, bool spontaneousAddition) : base(host,
                                                                                                NodeTypes.VariableSet,
                                                                                                spontaneousAddition)
        {
            Title = "Set";
            Host  = host;

            AddExecPort(this, "", PortTypes.Input, "");
            AddExecPort(this, "", PortTypes.Output, "");
            AddObjectPort(this, variable.Name, PortTypes.Input, RTypes.Generic, false);
            Description = @"Sets the value of " + variable.Name + ".";
            if (variable.Type != null)
            {
                NodesManager.ChangeColorOfVariableNode(InputPorts[0], variable.Type);
            }
            variable.Sets++;
            _item = variable;
            _item.DsOfNodes.Add(Id);
            Console.WriteLine("Sets: " + variable.Gets);
        }
Exemplo n.º 11
0
        private void OnMouseUp(object o, MouseButtonEventArgs e)
        {
            var sport = Host.TemObjectPort;

            if (Host.WireMode != WireMode.FirstPortSelected)
            {
                return;
            }
            if (LinkingPossiblity() != 0)
            {
                for (var index = 0; index < ConnectedConnectors.Count; index++)
                {
                    var conn = ConnectedConnectors[index];
                    if (conn.EndPort.ParentNode.Types == NodeTypes.SpaghettiDivider)
                    {
                        conn.EndPort.ParentNode.Delete();
                    }
                    else if (conn.StartPort.ParentNode.Types == NodeTypes.SpaghettiDivider)
                    {
                        conn.StartPort.ParentNode.Delete();
                    }
                }
                NodesManager.CreateObjectConnector(Host, sport, this);
                OnLinkChanged();
            }
            else
            {
                Control.Focus();
            }


            Host.Children.Remove(Host.TempConn);
            Host.TemObjectPort = null;
            Host.WireMode      = WireMode.Nothing;
            Host.MouseMode     = MouseMode.Nothing;
            Host.HideLinkingPossiblity();
            ParentNode.Refresh();
            e.Handled = true;
        }
Exemplo n.º 12
0
 public void Init(string inPath, NodesManager inManager)
 {
     nodesLayout1.Init(inPath, inManager, inputsPad, outputsPad, BreadCrumbs);
 }
Exemplo n.º 13
0
        public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            var      socketId = WebSocketConnectionManager.GetId(socket);
            var      message  = $"{Encoding.UTF8.GetString(buffer, 0, result.Count)}";
            EventDto input;

            try
            {
                input = JsonConvert.DeserializeObject <EventDto>(message);
            }
            catch (Exception)
            {
                input = new EventDto {
                };
            }

            switch (input.@event)
            {
            case NodesEvents.OnConnected:
            {
                NodesManager manager = new NodesManager();

                string output = JsonConvert.SerializeObject(new EventDto {
                        @event = NodesEvents.OnConnected, d1 = "Node " + input.d1 + " is now connected with address " + socketId
                    });

                if (input.d1 != "WebClient")
                {
                    manager.Insert(new Node {
                            Id = input.d1, Name = input.d1, SocketId = socketId
                        });
                }

                await SendMessageAsync(socketId, output);

                break;
            }

            case NodesEvents.OnToggle:
            {
                string clientId = input.d2;

                NodesManager mgr = new NodesManager();

                var node = mgr.Get(input.d2);

                if (node != null)
                {
                    clientId = node.SocketId;
                }

                string output = JsonConvert.SerializeObject(new EventDto {
                        @event = NodesEvents.OnToggle, d1 = input.d1, d2 = socketId, d3 = input.d3
                    });

                await SendMessageAsync(clientId, output);

                break;
            }

            default:
                break;
            }

            await Task.FromResult(0);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Clear scene
 /// </summary>
 public void Clear()
 {
     NodesManager.Clear();
 }