Пример #1
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;
            }
        }
Пример #2
0
 private void AddNodeTemplate(string templateName, string nameTemplate, GraphNodeShape shape,
                              float width, float height, Color backColor, Color lineColor, Color selectedLineColor, Color textColor, Color hatchedColor, Type tagType)
 {
     if (typeof(BaseNodeConfig).IsAssignableFrom(tagType))
     {
         _templates[templateName] = new GraphNodeTemplate(nameTemplate, shape,
                                                          width, height, backColor, lineColor, selectedLineColor, textColor, hatchedColor, tagType);
     }
     else
     {
         throw new ArgumentException("Invalid node config type for editor template");
     }
 }
Пример #3
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);
        }