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); } } }
/// <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; } }
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(); } }
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); } } }