private NodeVisual DeserializeNode(BinaryReader br) { var nv = new NodeVisual(); nv.GUID = br.ReadString(); nv.X = br.ReadSingle(); nv.Y = br.ReadSingle(); nv.Callable = br.ReadBoolean(); nv.ExecInit = br.ReadBoolean(); nv.Name = br.ReadString(); nv.Order = br.ReadInt32(); var customEditorAssembly = br.ReadString(); var customEditor = br.ReadString(); nv.Type = Context.GetType().GetMethod(br.ReadString()); var attribute = nv.Type.GetCustomAttributes(typeof(NodeAttribute), false) .Cast <NodeAttribute>() .FirstOrDefault(); if (attribute != null) { nv.CustomWidth = attribute.Width; nv.CustomHeight = attribute.Height; } (nv.GetNodeContext() as DynamicNodeContext).Deserialize(br.ReadBytes(br.ReadInt32())); var additional = br.ReadInt32(); //read additional data if (additional >= 4) { nv.Int32Tag = br.ReadInt32(); if (additional >= 8) { nv.NodeColor = Color.FromArgb(br.ReadInt32()); } } if (additional > 8) { br.ReadBytes(additional - 8); } if (customEditor != "") { nv.CustomEditor = Activator.CreateInstance(AppDomain.CurrentDomain, customEditorAssembly, customEditor).Unwrap() as Control; Control ctrl = nv.CustomEditor; if (ctrl != null) { ctrl.Tag = nv; Controls.Add(ctrl); } nv.LayoutEditor(); } return(nv); }
private void NodesControl_MouseClick(object sender, MouseEventArgs e) { lastMouseLocation = e.Location; if (Context == null) { return; } if (e.Button == MouseButtons.Right) { var methods = Context.GetType().GetMethods(); var nodes = methods.Select( x => new NodeToken() { Method = x, Attribute = x.GetCustomAttributes(typeof(NodeAttribute), false) .Cast <NodeAttribute>() .FirstOrDefault() }).Where(x => x.Attribute != null); var context = new ContextMenuStrip(); if (graph.Nodes.Exists(x => x.IsSelected)) { context.Items.Add("Delete Node(s)", null, ((o, args) => { DeleteSelectedNodes(); })); context.Items.Add("Duplicate Node(s)", null, ((o, args) => { DuplicateSelectedNodes(); })); context.Items.Add("Change Color ...", null, ((o, args) => { ChangeSelectedNodesColor(); })); if (graph.Nodes.Count(x => x.IsSelected) == 2) { var sel = graph.Nodes.Where(x => x.IsSelected).ToArray(); context.Items.Add("Check Impact", null, ((o, args) => { if (HasImpact(sel[0], sel[1]) || HasImpact(sel[1], sel[0])) { MessageBox.Show("One node has impact on other.", "Impact detected.", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("These nodes not impacts themselves.", "No impact.", MessageBoxButtons.OK, MessageBoxIcon.Information); } })); } context.Items.Add(new ToolStripSeparator()); } if (allContextItems.Values.Any(x => x > 0)) { var handy = allContextItems.Where(x => x.Value > 0 && !string.IsNullOrEmpty(((x.Key.Tag) as NodeToken).Attribute.Menu)).OrderByDescending(x => x.Value).Take(8); foreach (var kv in handy) { context.Items.Add(kv.Key); } context.Items.Add(new ToolStripSeparator()); } foreach (var node in nodes.OrderBy(x => x.Attribute.Path)) { AddToMenu(context.Items, node, node.Attribute.Path, (s, ev) => { var tag = (s as ToolStripMenuItem).Tag as NodeToken; var nv = new NodeVisual(); nv.X = lastMouseLocation.X; nv.Y = lastMouseLocation.Y; nv.Type = node.Method; nv.Callable = node.Attribute.IsCallable; nv.Name = node.Attribute.Name; nv.Order = graph.Nodes.Count; nv.ExecInit = node.Attribute.IsExecutionInitiator; nv.XmlExportName = node.Attribute.XmlExportName; nv.CustomWidth = node.Attribute.Width; nv.CustomHeight = node.Attribute.Height; if (node.Attribute.CustomEditor != null) { Control ctrl = null; nv.CustomEditor = ctrl = Activator.CreateInstance(node.Attribute.CustomEditor) as Control; if (ctrl != null) { ctrl.Tag = nv; Controls.Add(ctrl); } nv.LayoutEditor(); } graph.Nodes.Add(nv); Refresh(); needRepaint = true; }); } context.Show(MousePosition); } }