Пример #1
0
        void factory_DirtyChanged(object sender, EventArgs e)
        {
            BaseNodeConfig    config       = sender as BaseNodeConfig;
            ILinkedNodeConfig linkedConfig = config as ILinkedNodeConfig;

            if (linkedConfig != null)
            {
                if (linkedConfig.LinkedNode == null)
                {
                    GraphNode n = netEditor.GetNodeByTag(linkedConfig);

                    netEditor.RemoveLinkLine(n);
                }
                else
                {
                    GraphNode src  = netEditor.GetNodeByTag(linkedConfig);
                    GraphNode dest = netEditor.GetNodeByTag(linkedConfig.LinkedNode);

                    netEditor.RemoveLinkLine(src);
                    netEditor.RemoveLinkLine(dest);
                    AddLinkLine(src, dest);
                }

                netEditor.Invalidate();
            }

            netEditor.Dirty = true;
        }
Пример #2
0
        private void PopulateDocumentFromGraph()
        {
            if (!_populatingControl)
            {
                List <BaseNodeConfig> nodes = new List <BaseNodeConfig>();
                List <LineConfig>     lines = new List <LineConfig>();
                GraphData             graph = netEditor.Graph;

                foreach (var n in graph.Nodes)
                {
                    BaseNodeConfig node = (BaseNodeConfig)n.Tag;
                    node.X = n.Center.X;
                    node.Y = n.Center.Y;
                    node.Z = n.Z;

                    nodes.Add(node);
                }

                foreach (var l in graph.Lines)
                {
                    bool isWeak = false;
                    if (l.Tag != null)
                    {
                        isWeak = (bool)l.Tag;
                    }
                    LineConfig line = new LineConfig((BaseNodeConfig)l.SourceShape.Tag,
                                                     (BaseNodeConfig)l.DestShape.Tag, l.BiDirection, l.Label, isWeak);

                    lines.Add(line);
                }

                _document.UpdateGraph(nodes.ToArray(), lines.ToArray());
            }
        }
Пример #3
0
        /// <summary>
        /// Add an edge to the document
        /// </summary>
        /// <param name="label">The label for the edge</param>
        /// <param name="sourceNode">The source node for the edge</param>
        /// <param name="destNode">The destination node for the edge</param>
        /// <returns>The edge config, or a pre-existing one if it already exists</returns>
        public LineConfig AddEdge(string label, BaseNodeConfig sourceNode, BaseNodeConfig destNode)
        {
            foreach (LineConfig edge in sourceNode.EdgesFrom)
            {
                if (IsEqual(edge.DestNode, destNode) && IsEqual(edge.SourceNode, sourceNode))
                {
                    return(edge);
                }

                if (edge.BiDirection)
                {
                    if (IsEqual(edge.DestNode, sourceNode) && IsEqual(edge.SourceNode, destNode))
                    {
                        return(edge);
                    }
                }
            }

            LineConfig newedge = new LineConfig(sourceNode, destNode, false, label, false);

            List <LineConfig> edges = new List <LineConfig>(_lines);

            edges.Add(newedge);

            UpdateEdges(edges);

            return(newedge);
        }
Пример #4
0
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Clipboard.ContainsData(NODECONFIG_DATA))
            {
                try
                {
                    BaseNodeConfig config = Clipboard.GetData(NODECONFIG_DATA) as BaseNodeConfig;

                    if (config != null)
                    {
                        // Create a new ID
                        config.Id = Guid.NewGuid();
                        GraphNode n = AddNode(config, _currMousePos, 0.0f);

                        if (config is MasterLayerNodeConfig)
                        {
                            MasterLayerNodeConfig masterConfig = config as MasterLayerNodeConfig;
                            AddLinkLine(n, AddNode(masterConfig.Slave, new PointF(_currMousePos.X + 50.0f, _currMousePos.Y + 50.0f), 0.0f));
                        }
                    }
                }
                catch (SerializationException ex)
                {
                    MessageBox.Show(this, ex.Message, "Error Pasting", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #5
0
        private void netEditor_SelectedObjectChanged(object sender, EventArgs e)
        {
            deleteSelectedToolStripMenuItem.Enabled = (netEditor.SelectedObject != null);

            if (netEditor.SelectedObject != null)
            {
                if (netEditor.SelectedObject is GraphNode)
                {
                    BaseNodeConfig config = ((GraphNode)netEditor.SelectedObject).Tag as BaseNodeConfig;

                    if (config is SlaveLayerNodeConfig)
                    {
                        config = ((SlaveLayerNodeConfig)config).Master;
                    }

                    propertyGrid.SelectedObject = config;
                }
                else if (netEditor.SelectedObject is GraphLine)
                {
                    propertyGrid.SelectedObject = new LineContainer((GraphLine)netEditor.SelectedObject, netEditor);
                }
                else
                {
                    propertyGrid.SelectedObject = _document;
                }
            }
            else
            {
                propertyGrid.SelectedObject = _document;
            }
        }
Пример #6
0
        private void DeleteByConfig(BaseNodeConfig config)
        {
            GraphNode n = netEditor.GetNodeByTag(config);

            if (n != null)
            {
                netEditor.DeleteNode(n);
            }
        }
Пример #7
0
        /// <summary>
        /// Add a node at the current location with a new pipe node
        /// </summary>
        /// <param name="templateName"></param>
        private void AddNode(string templateName)
        {
            GraphNodeTemplate template = _templates[templateName];
            BaseNodeConfig    config   = null;
            string            label    = null;

            if (template.TagType == typeof(LibraryNodeConfig))
            {
                using (SelectLibraryNodeForm frm = new SelectLibraryNodeForm())
                {
                    if (frm.ShowDialog(this) == DialogResult.OK)
                    {
                        NodeLibraryManager.NodeLibraryType type = frm.Node;
                        object nodeConfig = null;

                        if (type.ConfigType != null)
                        {
                            nodeConfig = Activator.CreateInstance(type.ConfigType);
                        }

                        config = new LibraryNodeConfig(type.Type, type.Name, nodeConfig);

                        if (!String.IsNullOrWhiteSpace(type.NodeName))
                        {
                            label = type.NodeName;
                        }
                    }
                }
            }
            else
            {
                config = (BaseNodeConfig)Activator.CreateInstance(template.TagType);
            }

            if (config != null)
            {
                if (label != null)
                {
                    config.Label = label;
                }
                else
                {
                    config.Label = template.GetNewName();
                }

                GraphNode n = AddNode(config, _currMousePos, 0.0f);

                if (config is MasterLayerNodeConfig)
                {
                    MasterLayerNodeConfig masterConfig = config as MasterLayerNodeConfig;
                    masterConfig.Slave.Label = config.Label + "-Slave";
                    AddLinkLine(n, AddNode(masterConfig.Slave, new PointF(_currMousePos.X + 75.0f, _currMousePos.Y), 0.0f));
                }

                netEditor.SelectedObject = n;
            }
        }
Пример #8
0
        private void toggleEnableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if (node != null)
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;
                config.Enabled = !config.Enabled;
            }
        }
Пример #9
0
        /// <summary>
        /// Add an existing configuration node to the graph
        /// </summary>
        /// <param name="node">The node to add</param>
        /// <returns>The passed node</returns>
        public BaseNodeConfig AddNode(BaseNodeConfig node)
        {
            List <BaseNodeConfig> nodes = new List <BaseNodeConfig>(_nodes);

            nodes.Add(node);

            UpdateGraph(nodes.ToArray(), Lines);

            return(node);
        }
Пример #10
0
        private void centreOnNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if (node != null)
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                netEditor.CenterViewOnNode(node);
            }
        }
Пример #11
0
        private void copyPropertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if (node != null)
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                Clipboard.SetData(NODEPROPERTIES_DATA, config.Properties);
            }
        }
Пример #12
0
        private void copyFiltersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if (node != null)
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                Clipboard.SetData(NODEFILTER_DATA, config.Filters);
            }
        }
Пример #13
0
        void config_EnabledChanged(object sender, EventArgs e)
        {
            BaseNodeConfig config = sender as BaseNodeConfig;

            GraphNode node = netEditor.GetNodeByTag(config);

            if (node != null)
            {
                node.Hatched = !config.Enabled;
                netEditor.Invalidate();
            }
        }
Пример #14
0
        /// <summary>
        /// Copy a node config, used to allow external applications to create a suitable node
        /// </summary>
        /// <param name="node"></param>
        public static void CopyNode(BaseNodeConfig config)
        {
            SlaveLayerNodeConfig slaveConfig = config as SlaveLayerNodeConfig;

            if (slaveConfig != null)
            {
                // Copy the master, not slave
                config = slaveConfig.Master;
            }

            Clipboard.SetData(NODECONFIG_DATA, config);
        }
Пример #15
0
        /// <summary>
        /// Add an existing node to the editor
        /// </summary>
        /// <param name="config">The node entry</param>
        /// <param name="p">The point to set</param>
        /// <param name="z">The z co-ordinate</param>
        private GraphNode AddNode(BaseNodeConfig config, PointF p, float z)
        {
            GraphNodeTemplate template = _templates[config.GetNodeName()];

            GraphNode n = netEditor.AddNode(p, z, config.Id, config.Label, template.Shape,
                                            template.Width, template.Height, template.BackColor, template.LineColor, template.SelectedLineColor,
                                            template.TextColor, template.HatchedColor, config);

            SetNode(n);

            netEditor.SelectedObject = n;

            return(n);
        }
Пример #16
0
 public static void RemoveFilter(dynamic filterFunc, BaseNodeConfig config)
 {
     foreach (IDataFrameFilterFactory filter in config.Filters)
     {
         ScriptDataFrameFilterFactory scriptFilter = filter as ScriptDataFrameFilterFactory;
         if (scriptFilter != null)
         {
             if (filterFunc == scriptFilter._filterFunc)
             {
                 config.RemoveFilter(filter);
                 break;
             }
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Setup the node factory object
        /// </summary>
        /// <param name="n">The node to configure</param>
        private void SetNode(GraphNode n)
        {
            BaseNodeConfig config = n.Tag as BaseNodeConfig;

            if (config != null)
            {
                n.Hatched = !config.Enabled;
                n.Label   = config.Label;

                config.LabelChanged      += new EventHandler(factory_LabelChanged);
                config.DirtyChanged      += new EventHandler(factory_DirtyChanged);
                config.EnabledChanged    += new EventHandler(config_EnabledChanged);
                config.PropertiesChanged += new EventHandler(config_PropertiesChanged);
            }
        }
Пример #18
0
        private void pastePropertiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if ((node != null) && Clipboard.ContainsData(NODEPROPERTIES_DATA))
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                Dictionary <string, string> props = (Dictionary <string, string>)Clipboard.GetData(NODEPROPERTIES_DATA);

                if (props != null)
                {
                    config.Properties = props;
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Remove a node from the document
        /// </summary>
        /// <param name="node">The node to remove</param>
        public void RemoveNode(BaseNodeConfig node)
        {
            List <BaseNodeConfig> nodes = new List <BaseNodeConfig>(_nodes);

            foreach (LineConfig config in node.EdgesFrom)
            {
                config.RemoveEdge();
            }

            foreach (LineConfig config in node.EdgesTo)
            {
                config.RemoveEdge();
            }

            nodes.RemoveAll(n => IsEqual(n, node));

            UpdateGraph(nodes, _lines);
        }
Пример #20
0
        void factory_LabelChanged(object sender, EventArgs e)
        {
            BaseNodeConfig config = sender as BaseNodeConfig;

            GraphNode node = netEditor.GetNodeByTag(config);

            if (node != null)
            {
                node.Label = config.Label;
                MasterLayerNodeConfig masterConfig = config as MasterLayerNodeConfig;
                if (masterConfig != null)
                {
                    masterConfig.Slave.Label = config.Label + "-Slave";
                }

                netEditor.Invalidate();
            }
        }
Пример #21
0
        private void netEditor_NodeDeleted(object sender, NodeDeletedEventArgs e)
        {
            BaseNodeConfig config = e.Node.Tag as BaseNodeConfig;

            if (config != null)
            {
                config.Delete();
                if (config is MasterLayerNodeConfig)
                {
                    MasterLayerNodeConfig masterConfig = config as MasterLayerNodeConfig;
                    DeleteByConfig(masterConfig.Slave);
                }
                else if (config is SlaveLayerNodeConfig)
                {
                    SlaveLayerNodeConfig slaveConfig = config as SlaveLayerNodeConfig;
                    DeleteByConfig(slaveConfig.Master);
                }
            }
        }
Пример #22
0
        private void pasteFiltersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GraphNode node = netEditor.SelectedObject as GraphNode;

            if ((node != null) && Clipboard.ContainsData(NODEFILTER_DATA))
            {
                BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                DataFrameFilterFactory[] filters = (DataFrameFilterFactory[])Clipboard.GetData(NODEFILTER_DATA);

                if (filters != null)
                {
                    bool overwrite = true;

                    if (config.Filters.Length > 0)
                    {
                        if (MessageBox.Show(this, "Node already contains filters, do you want to overwrite? (Clicking No will append to the list)",
                                            "Overwrite Filters?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                        {
                            overwrite = false;
                        }
                    }

                    if (overwrite)
                    {
                        config.Filters = filters;
                    }
                    else
                    {
                        IDataFrameFilterFactory[] oldFilters = config.Filters;
                        int len = oldFilters.Length;
                        Array.Resize(ref oldFilters, len + filters.Length);
                        Array.Copy(filters, 0, oldFilters, len, filters.Length);
                        config.Filters = oldFilters;
                    }
                }
            }
        }
Пример #23
0
 private static bool IsEqual(BaseNodeConfig a, BaseNodeConfig b)
 {
     return(a.Id == b.Id);
 }
Пример #24
0
        private void netEditor_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                GraphNode node = netEditor.SelectedObject as GraphNode;

                if (node != null)
                {
                    BaseNodeConfig config = (BaseNodeConfig)node.Tag;

                    PropertyDescriptorCollection coll = TypeDescriptor.GetProperties(config);

                    foreach (PropertyDescriptor desc in coll)
                    {
                        if (typeof(IDocumentObject).IsAssignableFrom(desc.PropertyType))
                        {
                            object o = config;
                            ICustomTypeDescriptor custom = config as ICustomTypeDescriptor;
                            if (custom != null)
                            {
                                o = custom.GetPropertyOwner(desc);
                            }

                            IDocumentObject document = (IDocumentObject)desc.GetValue(o);
                            if (document == null)
                            {
                                if (MessageBox.Show(this, Resources.ResourceManager.GetString("NetGraphDocumentControl_NoDocumentSet", GeneralUtils.GetCurrentCulture()),
                                                    Resources.ResourceManager.GetString("NetGraphDocumentControl_NoDocumentSetCaption", GeneralUtils.GetCurrentCulture()),
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    // Create document
                                    if (desc.PropertyType == typeof(ScriptDocument))
                                    {
                                        using (SelectScriptTemplateForm frm = new SelectScriptTemplateForm())
                                        {
                                            if (frm.ShowDialog(this) == DialogResult.OK)
                                            {
                                                ScriptDocument script = CANAPEProject.CurrentProject.CreateDocument <ScriptDocument>(frm.Template.TypeName);
                                                script.Script = frm.Template.GetText();
                                                document      = script;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        document = CANAPEProject.CurrentProject.CreateDocument(desc.PropertyType);
                                    }
                                }
                            }

                            if (document != null)
                            {
                                DocumentControl.Show(document);
                                desc.SetValue(o, document);

                                // Reset selected objects
                                propertyGrid.SelectedObjects = propertyGrid.SelectedObjects;
                            }

                            break;
                        }
                    }
                }
            }
        }