예제 #1
0
        void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
        {
            bool isHidden = (Control.ModifierKeys & Keys.Shift) != 0;

            MyNode fromNode = (e.Connection.From.Node as MyNodeView).Node;
            MyNode toNode   = (e.Connection.To.Node as MyNodeView).Node;

            int fromIndex = (int)e.Connection.From.Item.Tag;
            int toIndex   = (int)e.Connection.To.Item.Tag;

            if (toNode.AcceptsConnection(fromNode, fromIndex, toIndex))
            {
                MyConnection newConnection = new MyConnection(fromNode, toNode, fromIndex, toIndex);
                newConnection.Connect();

                newConnection.IsHidden = isHidden;
                e.Connection.Tag       = newConnection;
                (e.Connection as MyNodeViewConnection).Hidden = isHidden;


                m_mainForm.RefreshConnections(this);
                m_mainForm.ProjectStateChanged("Connection added");
            }
            else
            {
                // Make the graph library drop the connection.
                e.Cancel = true;
            }
        }
예제 #2
0
        public int UpdateAfterDeserialization(int topId, MyProject parentProject)
        {
            if (topId < this.Id)
            {
                topId = this.Id;
            }

            this.Owner = parentProject;

            Dictionary <int, MyNode> nodes = new Dictionary <int, MyNode>();

            topId = CollectNodesAndUpdate(this, nodes, topId);

            parentProject.ReadOnly = false;

            MyNodeGroup.IteratorAction findUnknownAction = delegate(MyNode node)
            {
                if (!MyConfiguration.KnownNodes.ContainsKey(node.GetType()))
                {
                    MyLog.WARNING.WriteLine("Unknown node type in loaded project: " + node.GetType());
                    parentProject.ReadOnly = true;

                    try
                    {
                        MyNodeConfig nodeConfig = new MyNodeConfig()
                        {
                            NodeType     = node.GetType(),
                            NodeTypeName = node.GetType().FullName
                        };

                        nodeConfig.InitIcons(Assembly.GetExecutingAssembly());
                        nodeConfig.AddObservers(Assembly.GetExecutingAssembly());

                        MyConfiguration.KnownNodes[nodeConfig.NodeType] = nodeConfig;
                    }
                    catch (Exception e)
                    {
                        MyLog.ERROR.WriteLine("Node type loading failed: " + e.Message);
                    }
                }
            };

            Iterate(true, findUnknownAction);

            foreach (MyConnectionProxy cp in m_connections)
            {
                try
                {
                    MyConnection connection = new MyConnection(nodes[cp.From], nodes[cp.To], cp.FromIndex, cp.ToIndex);
                    connection.Connect();
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Error during connection deserialization: From id " + cp.From + " to id " + cp.To);
                }
            }

            return(topId);
        }
예제 #3
0
        public MyConnection Connect(MyNode fromNode, MyNode toNode, int fromIndex = 0, int toIndex = 0)
        {
            var connection = new MyConnection(fromNode, toNode, fromIndex, toIndex);

            connection.Connect();

            return(connection);
        }
예제 #4
0
        // TODO(HonzaS): test the special subclasses of MyNode (Input/Output nodes etc.)

        public NodeConnectionTests()
        {
            m_node1 = new TestNode();
            m_node2 = new TestNode();

            m_connection = new MyConnection(m_node1, m_node2, 0, 0);
            m_connection.Connect();
        }
        // TODO(HonzaS): test the special subclasses of MyNode (Input/Output nodes etc.)
        public NodeConnectionTests()
        {
            m_node1 = new TestNode();
            m_node2 = new TestNode();

            m_connection = new MyConnection(m_node1, m_node2, 0, 0);
            m_connection.Connect();
        }
        public void SimulationStateChangedOnNodesTest()
        {
            var simulation = TypeMap.GetInstance <MySimulation>();
            var handler    = new MySimulationHandler(simulation);

            MyProject project = new MyProject
            {
                Network = new MyNetwork()
            };

            project.CreateWorld(typeof(MyTestingWorld));

            var node = project.CreateNode <TestingNode>();

            node.Event = new AutoResetEvent(false);
            project.Network.AddChild(node);
            var connection = new MyConnection(project.Network.GroupInputNodes[0], project.Network.Children[0]);

            connection.Connect();

            project.Network.PrepareConnections();

            handler.Project = project;
            handler.UpdateMemoryModel();

            handler.StartSimulation();
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.CurrentState);

            handler.PauseSimulation();
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState);

            handler.StartSimulation(stepCount: 1u);
            node.Event.WaitOne();   // Here the sim goes from paused to RUNNING_STEP.
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.CurrentState);
            node.Event.WaitOne();   // Here it goes to PAUSED.
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState);

            handler.StopSimulation();
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.CurrentState);

            handler.Finish();
        }
예제 #7
0
        void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
        {
            MyNode fromNode = (e.Connection.From.Node as MyNodeView).Node;
            MyNode toNode   = (e.Connection.To.Node as MyNodeView).Node;

            int fromIndex = (int)e.Connection.From.Item.Tag;
            int toIndex   = (int)e.Connection.To.Item.Tag;

            MyConnection newConnection = new MyConnection(fromNode, toNode, fromIndex, toIndex);

            newConnection.Connect();

            e.Connection.Tag = newConnection;
        }
        public void SimulationStateChangedOnNodesTest()
        {
            var simulation = new MyLocalSimulation();
            var handler = new MySimulationHandler(simulation);

            MyProject project = new MyProject
            {
                Network = new MyNetwork()
            };
            project.CreateWorld(typeof(MyTestingWorld));

            var node = project.CreateNode<TestingNode>();
            node.Event = new AutoResetEvent(false);
            project.Network.AddChild(node);
            var connection = new MyConnection(project.Network.GroupInputNodes[0], project.Network.Children[0]);
            connection.Connect();

            project.Network.PrepareConnections();

            handler.Project = project;
            handler.UpdateMemoryModel();

            handler.StartSimulation(oneStepOnly: false);
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.CurrentState);

            handler.PauseSimulation();
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState);

            handler.StartSimulation(oneStepOnly: true);
            node.Event.WaitOne();   // Here the sim goes from paused to RUNNING_STEP.
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.CurrentState);
            node.Event.WaitOne();   // Here it goes to PAUSED.
            Assert.Equal(MySimulationHandler.SimulationState.RUNNING_STEP, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.CurrentState);

            handler.StopSimulation();
            node.Event.WaitOne();
            Assert.Equal(MySimulationHandler.SimulationState.PAUSED, node.PreviousState);
            Assert.Equal(MySimulationHandler.SimulationState.STOPPED, node.CurrentState);

            handler.Finish();
        }
예제 #9
0
        private void ConnectWorld()
        {
            if (Network != null && World != null)
            {
                if (Network.InputBranches != World.OutputBranches)
                {
                    Network.InputBranches = World.OutputBranches;
                    Network.InitInputNodes();
                }

                for (int i = 0; i < World.OutputBranches; i++)
                {
                    Network.GroupInputNodes[i].Name = ShortenMemoryBlockName(World.GetOutput(i).Name);
                }

                if (Network.OutputBranches != World.InputBranches)
                {
                    Network.OutputBranches = World.InputBranches;
                    Network.InitOutputNodes();
                }

                for (int i = 0; i < World.InputBranches; i++)
                {
                    Network.GroupOutputNodes[i].Name = ShortenMemoryBlockName(MyNodeInfo.Get(World.GetType()).InputBlocks[i].Name);
                }

                for (int i = 0; i < World.OutputBranches; i++)
                {
                    MyConnection worldToNetwork = new MyConnection(World, Network, i, i);
                    worldToNetwork.Connect();
                }

                for (int i = 0; i < World.InputBranches; i++)
                {
                    MyConnection networkToWorld = new MyConnection(Network, World, i, i);
                    networkToWorld.Connect();
                }
            }
        }
예제 #10
0
        void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
        {
            MyNode fromNode = (e.Connection.From.Node as MyNodeView).Node;
            MyNode toNode = (e.Connection.To.Node as MyNodeView).Node;

            int fromIndex = (int)e.Connection.From.Item.Tag;
            int toIndex = (int)e.Connection.To.Item.Tag;

            MyConnection newConnection = new MyConnection(fromNode, toNode, fromIndex, toIndex);
            newConnection.Connect();

            e.Connection.Tag = newConnection;
        }
예제 #11
0
        void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
        {
            MyNode fromNode = (e.Connection.From.Node as MyNodeView).Node;
            MyNode toNode = (e.Connection.To.Node as MyNodeView).Node;

            int fromIndex = (int)e.Connection.From.Item.Tag;
            int toIndex = (int)e.Connection.To.Item.Tag;

            if (toNode.AcceptsConnection(fromNode, fromIndex, toIndex))
            {
                MyConnection newConnection = new MyConnection(fromNode, toNode, fromIndex, toIndex);
                newConnection.Connect();

                e.Connection.Tag = newConnection;

                m_mainForm.RefreshConnections(this);
            }
            else
            {
                // Make the graph library drop the connection.
                e.Cancel = true;
            }
        }
예제 #12
0
        public int UpdateAfterDeserialization(int topId, MyProject parentProject)
        {
            if (topId < this.Id)
            {
                topId = this.Id;
            }

            this.Owner = parentProject;

            Dictionary<int, MyNode> nodes = new Dictionary<int,MyNode>();
            topId = CollectNodesAndUpdate(this, nodes, topId);

            parentProject.ReadOnly = false;

            MyNodeGroup.IteratorAction findUnknownAction = delegate(MyNode node)
            {
                if (!MyConfiguration.KnownNodes.ContainsKey(node.GetType()))
                {
                    MyLog.WARNING.WriteLine("Unknown node type in loaded project: " + node.GetType());
                    parentProject.ReadOnly = true;

                    try
                    {
                        MyNodeConfig nodeConfig = new MyNodeConfig()
                        {
                            NodeType = node.GetType(),
                            NodeTypeName = node.GetType().FullName
                        };

                        nodeConfig.InitIcons(Assembly.GetExecutingAssembly());
                        nodeConfig.AddObservers(Assembly.GetExecutingAssembly());

                        MyConfiguration.KnownNodes[nodeConfig.NodeType] = nodeConfig;
                    }
                    catch (Exception e)
                    {
                        MyLog.ERROR.WriteLine("Node type loading failed: " + e.Message);
                    }
                }
            };

            Iterate(true, findUnknownAction);

            foreach (MyConnectionProxy cp in m_connections)
            {
                try
                {
                    MyConnection connection = new MyConnection(nodes[cp.From], nodes[cp.To], cp.FromIndex, cp.ToIndex);
                    connection.Connect();
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Error during connection deserialization: From id " + cp.From +" to id " + cp.To);
                }
            }

            return topId;
        }
예제 #13
0
        void OnConnectionAdded(object sender, AcceptNodeConnectionEventArgs e)
        {
            bool isHidden = (Control.ModifierKeys & Keys.Shift) != 0;

            MyNode fromNode = (e.Connection.From.Node as MyNodeView).Node;
            MyNode toNode = (e.Connection.To.Node as MyNodeView).Node;

            int fromIndex = (int) e.Connection.From.Item.Tag;
            int toIndex = (int) e.Connection.To.Item.Tag;

            if (toNode.AcceptsConnection(fromNode, fromIndex, toIndex))
            {
                MyConnection newConnection = new MyConnection(fromNode, toNode, fromIndex, toIndex);
                newConnection.Connect();

                newConnection.IsHidden = isHidden;
                e.Connection.Tag = newConnection;
                (e.Connection as MyNodeViewConnection).Hidden = isHidden;

                m_mainForm.RefreshConnections(this);
                m_mainForm.ProjectStateChanged("Connection added");
            }
            else
            {
                // Make the graph library drop the connection.
                e.Cancel = true;
            }
        }