Ejemplo n.º 1
0
        private int LoadNodeEditors(string file)
        {
            var doc = new XmlDocument();

            NodeEditor activeEditor = null;
            var        editorCount  = 0;

            if (!File.Exists(file))
            {
                return(editorCount);
            }
            doc.Load(file);

            var editors = doc.SelectNodes("//editors/editor");

            if (editors == null)
            {
                return(editorCount);
            }

            foreach (XmlNode editor in editors)
            {
                var editorInfo = LoadNodeEditor(editor, editorCount);
                if (editorInfo.Editor != null)
                {
                    if (editorInfo.Active)
                    {
                        activeEditor = editorInfo.Editor;
                    }
                    editorCount++;
                }
            }

            if (editorCount > 0)
            {
                _dock.Documents.FirstOrDefault(d => d.DockHandler.Content == activeEditor)?.DockHandler.Activate();
            }

            return(editorCount);
        }
Ejemplo n.º 2
0
        private NodeEditorInfo LoadNodeEditor(XmlNode editor, int number)
        {
            var instances = new Dictionary <string, GraphNode>();

            var nodes = editor.SelectNodes("graphnodes/graphnode");

            if (nodes == null)
            {
                return new NodeEditorInfo {
                           Editor = null, Active = false
                }
            }
            ;

            var nodeEditor = new NodeEditor();

            var factorySettings = editor.SelectNodes("factory");

            foreach (var setting in factorySettings.OfType <XmlNode>())
            {
                var fid = Guid.Parse(setting.TryGetAttribute("guid", Guid.Empty.ToString()));

                var fac = GlobalSettings.Instance.MetricManager.Factories.FirstOrDefault(f => f.Id.Equals(fid));

                if (fac != null)
                {
                    fac.SetFactorySettings(nodeEditor.Graph, setting);
                }
            }

            var zoom = float.Parse(editor.TryGetAttribute("zoom", otherwise: "1"), CultureInfo.InvariantCulture);

            var xy = new System.Drawing.Point(
                int.Parse(editor.TryGetAttribute("x", otherwise: "0")),
                int.Parse(editor.TryGetAttribute("y", otherwise: "0"))
                );

            nodeEditor.NodeView.Center = xy;

            nodeEditor.Text = editor.TryGetAttribute("title", otherwise: $"Editor {number}");

            var clockSyncGuidString = editor.TryGetAttribute("clocksync", otherwise: "");

            if (clockSyncGuidString == "")
            {
                clockSyncGuidString = Guid.Empty.ToString();
            }
            var clockSyncId = Guid.Parse(clockSyncGuidString);

            var activeEditor = (editor.TryGetAttribute("active", otherwise: "0") == "1");

            foreach (XmlNode node in nodes)
            {
                var formNode = GraphNode.FromXml(node, nodeEditor.Graph);
                if (formNode == null)
                {
                    continue;
                }
                nodeEditor.NodeView.Nodes.Add(formNode);
                instances.Add(formNode.InstanceId.ToString(), formNode);

                //if (formNode.InstanceId.Equals(clockSyncId)) {
                //    nodeEditor.Graph.ClockSynchronizationNode = formNode.Node;
                //}
            }

            nodeEditor.OnRunningStatusChanged += Editor_OnRunningStatusChanged;
            nodeEditor.Show(GlobalSettings.Instance.DockPanelInstance, DockState.Document);

            var links = editor.SelectNodes("links/link");

            if (links == null)
            {
                return new NodeEditorInfo {
                           Editor = nodeEditor, Active = activeEditor
                }
            }
            ;

            foreach (XmlNode link in links)
            {
                if (link.Attributes == null)
                {
                    continue;
                }

                var targetOwnerId = link.TryGetAttribute("targetOwnerId", otherwise: "");

                var sourceOwnerId = link.TryGetAttribute("sourceOwnerId", otherwise: "");
                var targetName    = link.TryGetAttribute("targetInputName", otherwise: "");
                var sourceName    = link.TryGetAttribute("sourceOutputName", otherwise: "");

                if (targetOwnerId == "" || sourceOwnerId == "" || targetName == "" || sourceName == "")
                {
                    continue;
                }

                if (instances.ContainsKey(sourceOwnerId) && instances.ContainsKey(targetOwnerId))
                {
                    var pIn  = instances[sourceOwnerId].InputPorts.First(c => c.Name == sourceName);
                    var pOut = instances[targetOwnerId].OutputPorts.First(c => c.Name == targetName);
                    nodeEditor.NodeView.CreateConnection(pIn, pOut);
                }
            }

            return(new NodeEditorInfo {
                Editor = nodeEditor, Active = activeEditor
            });
        }