コード例 #1
0
        private void goToNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyNode targetNode = null;

            if (Observer.GenericTarget is MyNode)
            {
                targetNode = Observer.GenericTarget as MyNode;
            }
            else if (Observer.GenericTarget is MyAbstractMemoryBlock)
            {
                targetNode = (Observer.GenericTarget as MyAbstractMemoryBlock).Owner;
            }

            if (targetNode != null)
            {
                if (targetNode is MyWorld)
                {
                    GraphLayoutForm graphForm = m_mainForm.OpenGraphLayout(targetNode.Owner.Network);
                    graphForm.worldButton_Click(sender, EventArgs.Empty);
                }
                else
                {
                    GraphLayoutForm graphForm = m_mainForm.OpenGraphLayout(targetNode.Parent);
                    graphForm.SelectNodeView(targetNode);
                }
            }
        }
コード例 #2
0
        private void CreateNetworkView()
        {
            NetworkView             = new GraphLayoutForm(this, Project.Network);
            NetworkView.FormClosed += GraphLayoutForm_FormClosed;

            GraphViews[Project.Network]    = NetworkView;
            NetworkView.CloseButton        = false;
            NetworkView.CloseButtonVisible = false;
        }
コード例 #3
0
 private void GoToNode(object sender, MyNode node)
 {
     if (node is MyWorld)
     {
         GraphLayoutForm graphForm = m_mainForm.OpenGraphLayout(node.Owner.Network);
         graphForm.worldButton_Click(sender, EventArgs.Empty);
     }
     else
     {
         GraphLayoutForm graphForm = m_mainForm.OpenGraphLayout(node.Parent);
         graphForm.SelectNodeView(node);
     }
 }
コード例 #4
0
        void SimulationHandler_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            if (SimulationHandler.State != MySimulationHandler.SimulationState.STOPPED)
            {
                statusStrip.BeginInvoke((MethodInvoker)(() => stepStatusLabel.Text = "(" + SimulationHandler.SimulationStep + ", " + SimulationHandler.SimulationSpeed + "/s)"));

                GraphLayoutForm activeLayout = dockPanel.ActiveDocument as GraphLayoutForm;
                activeLayout.Desktop.Invalidate();
            }
            else
            {
                statusStrip.Invoke((MethodInvoker)(() => stepStatusLabel.Text = String.Empty));
            }
        }
コード例 #5
0
        private void listView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listView.SelectedItems.Count > 0)
            {
                if (listView.SelectedItems[0].Tag is MyNode)
                {
                    MyNode node = listView.SelectedItems[0].Tag as MyNode;

                    if (node.Parent != null)
                    {
                        GraphLayoutForm parentLayoutForm = m_mainForm.OpenGraphLayout(node.Parent);
                        parentLayoutForm.SelectNodeView(node);
                    }
                }
            }
        }
コード例 #6
0
        public GraphLayoutForm OpenGraphLayout(MyNodeGroup target)
        {
            GraphLayoutForm graphForm;

            if (GraphViews.ContainsKey(target))
            {
                graphForm = GraphViews[target];
            }
            else
            {
                graphForm             = new GraphLayoutForm(this, target);
                graphForm.FormClosed += GraphLayoutForm_FormClosed;
                GraphViews.Add(target, graphForm);
            }

            graphForm.Show(dockPanel, DockState.Document);
            return(graphForm);
        }
コード例 #7
0
        public void CopySelectedNodesToClipboard()
        {
            if (dockPanel.ActiveContent is ConsoleForm)
            {
                Clipboard.SetText((dockPanel.ActiveContent as ConsoleForm).textBox.SelectedText);
                return;
            }

            if (dockPanel.ActiveDocument is GraphLayoutForm)
            {
                GraphLayoutForm activeLayout = dockPanel.ActiveDocument as GraphLayoutForm;

                NodeSelection selection = null;

                if (activeLayout.Desktop.FocusElement is NodeSelection)
                {
                    selection = activeLayout.Desktop.FocusElement as NodeSelection;
                }
                else if (activeLayout.Desktop.FocusElement is Node)
                {
                    selection = new NodeSelection(new Node[] { activeLayout.Desktop.FocusElement as Node });
                }

                if (selection != null)
                {
                    HashSet <int> approvedNodes    = new HashSet <int>();
                    MyNetwork     clipboardNetwork = Project.CreateNode <MyNetwork>();
                    clipboardNetwork.Name = "Clipboard";

                    foreach (MyNodeView nodeView in selection.Nodes)
                    {
                        MyNode selectedNode = nodeView.Node;

                        if (selectedNode is MyWorkingNode)
                        {
                            clipboardNetwork.Children.Add(nodeView.Node);
                            approvedNodes.Add(selectedNode.Id);
                        }

                        if (selectedNode is MyNodeGroup)
                        {
                            (selectedNode as MyNodeGroup).Iterate(true, true, node => approvedNodes.Add(node.Id));
                        }
                    }

                    if (approvedNodes.Count > 0)
                    {
                        clipboardNetwork.PrepareConnections();
                        clipboardNetwork.FilterPreparedCollection(approvedNodes);

                        YAXSerializer networkSerializer = new YAXSerializer(typeof(MyNetwork), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning, YAXSerializationOptions.DontSerializeNullObjects);
                        string        xml = networkSerializer.Serialize(clipboardNetwork);

                        Clipboard.SetText(xml);
                    }
                    else
                    {
                        MyLog.WARNING.WriteLine("Copying is not allowed");
                    }
                }
                else
                {
                    MyLog.WARNING.WriteLine("Selection is empty");
                }
            }
        }
コード例 #8
0
        public void PasteNodesFromClipboard()
        {
            if (Clipboard.ContainsText() && dockPanel.ActiveDocument is GraphLayoutForm)
            {
                string xml = Clipboard.GetText();

                try
                {
                    YAXSerializer networkSerializer = new YAXSerializer(typeof(MyNetwork), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);

                    MyNetwork networkToPaste = (MyNetwork)networkSerializer.Deserialize(xml);
                    networkToPaste.UpdateAfterDeserialization(0, Project);

                    GraphLayoutForm activeLayout = dockPanel.ActiveDocument as GraphLayoutForm;

                    activeLayout.Target.AppendGroupContent(networkToPaste);
                    activeLayout.ReloadContent();

                    HashSet <int> pastedNodes = new HashSet <int>();
                    networkToPaste.Children.ForEach(node => pastedNodes.Add(node.Id));

                    List <MyNodeView> pastedNodeViews = new List <MyNodeView>();
                    RectangleF?       pastedBounds    = null;
                    Graphics          context         = activeLayout.Desktop.CreateGraphics();

                    foreach (MyNodeView nodeView in activeLayout.Desktop.Nodes)
                    {
                        if (pastedNodes.Contains(nodeView.Node.Id))
                        {
                            pastedNodeViews.Add(nodeView);

                            SizeF      size   = GraphRenderer.Measure(context, nodeView);
                            RectangleF bounds = new RectangleF(nodeView.Location, size);

                            if (pastedBounds.HasValue)
                            {
                                pastedBounds = RectangleF.Union(pastedBounds.Value, bounds);
                            }
                            else
                            {
                                pastedBounds = bounds;
                            }
                        }
                    }

                    PointF pasteLocation = activeLayout.Desktop.UnprojectPoint(new PointF(20, 20));

                    if (pastedBounds.HasValue)
                    {
                        foreach (MyNodeView nodeView in pastedNodeViews)
                        {
                            nodeView.Node.Location = new MyLocation()
                            {
                                X = nodeView.Location.X - pastedBounds.Value.Left + pasteLocation.X,
                                Y = nodeView.Location.Y - pastedBounds.Value.Top + pasteLocation.Y
                            };
                            nodeView.UpdateView();
                        }
                    }


                    //select pasted nodes
                    activeLayout.Desktop.FocusElement = new NodeSelection(pastedNodeViews);
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Paste failed: " + e.Message);
                }
            }
        }
コード例 #9
0
        private void CreateNetworkView()
        {
            NetworkView = new GraphLayoutForm(this, Project.Network);
            NetworkView.FormClosed += GraphLayoutForm_FormClosed;

            GraphViews[Project.Network] = NetworkView;
            NetworkView.CloseButton = false;
            NetworkView.CloseButtonVisible = false;
        }
コード例 #10
0
        public void RefreshConnections(GraphLayoutForm form)
        {
            SimulationHandler.RefreshTopologicalOrder();

            // Refresh the forms of the form's target parents as well.
            // The connection types might have changed for group outputs.
            var nodesToRefresh = new List<MyNode>();
            var target = form.Target;
            while (target != null)
            {
                nodesToRefresh.Add(target);
                target = target.Parent;
            }

            foreach (var graph in GraphViews)
            {
                if (nodesToRefresh.Contains(graph.Key))
                    graph.Value.RefreshGraph();
            }
        }
コード例 #11
0
        public GraphLayoutForm OpenGraphLayout(MyNodeGroup target)
        {
            GraphLayoutForm graphForm;

            if (GraphViews.ContainsKey(target))
            {
                graphForm = GraphViews[target];
            }
            else
            {
                graphForm = new GraphLayoutForm(this, target);
                graphForm.FormClosed += GraphLayoutForm_FormClosed;
                GraphViews.Add(target, graphForm);
            }

            graphForm.Show(dockPanel, DockState.Document);

            RefreshConnections(graphForm);

            SimulationHandler.Simulation.ModelChanged += graphForm.OnModelChanged;

            return graphForm;
        }
コード例 #12
0
ファイル: MainForm_Ops.cs プロジェクト: Jlaird/BrainSimulator
        public GraphLayoutForm OpenGraphLayout(MyNodeGroup target)
        {
            GraphLayoutForm graphForm;

            if (GraphViews.ContainsKey(target))
            {
                graphForm = GraphViews[target];
            }
            else
            {
                graphForm = new GraphLayoutForm(this, target);
                graphForm.FormClosed += GraphLayoutForm_FormClosed;
                GraphViews.Add(target, graphForm);
            }

            graphForm.Show(dockPanel, DockState.Document);
            return graphForm;
        }