protected MyNodeView(MyNodeConfig nodeInfo, GraphControl owner) : base("") { NodeInfo = nodeInfo; Owner = owner; m_icon = nodeInfo.BigImage; m_iconItem = new NodeImageItem(m_icon, 48, 48, false, false); m_iconItem.Tag = 0; m_descItem = new NodeLabelItem(""); AddItem(m_iconItem); AddItem(m_descItem); }
public void LoadGraph(GraphControl graph, String filename) { try { using (StreamReader sr = new StreamReader(filename)) { var tempFields = (CGraphFields)m_serializer.Deserialize(sr, typeof(CGraphFields)); m_graphFields = tempFields; } } catch(Exception ex) { m_log.WriteLine("Could not load file " + filename + " : " + ex.Message + "\n" + ex.StackTrace); return; } rebuildGraph(graph); m_log.WriteLine("Loaded " + filename); }
protected MyNodeView(MyNodeConfig nodeConfig, GraphControl owner) : base("") { Owner = owner; Config = nodeConfig; m_icon = nodeConfig.BigImage; m_iconItem = new NodeImageItem(m_icon, 48, 48, false, false) { IsPassive = true, Tag = 0 }; m_descItem = new NodeLabelItem("") { IsPassive = true }; AddItem(m_iconItem); AddItem(m_descItem); }
public static MyNodeView CreateNodeView(MyNode node, GraphControl owner) { MyNodeView nodeView = CreateNodeView(node.GetType(), owner); nodeView.Node = node; return nodeView; }
public static MyNodeView CreateNodeView(Type nodeType, GraphControl owner) { MyNodeConfig config = MyConfiguration.KnownNodes[nodeType]; if (typeof(MyUserInput).IsAssignableFrom(nodeType)) { return new MyUserInputView(config, owner); } if (typeof(DeviceInput).IsAssignableFrom(nodeType)) { return new DeviceInputView(config, owner); } if (typeof(MyGateInput).IsAssignableFrom(nodeType)) { return new MyGateInputView(config, owner); } else if (typeof(MyNodeGroup).IsAssignableFrom(nodeType)) { return new MyNodeGroupView(config, owner); } else if (typeof(MyFork).IsAssignableFrom(nodeType) || typeof(IMyVariableBranchViewNodeBase).IsAssignableFrom(nodeType)) { return new MyVariableBranchView(config, owner); } else { return new MyNodeView(config, owner); } }
void Desktop_PanZoomPerformed(object sender, GraphControl.PanZoomEventArgs e) { StoreLayoutProperties(); }
public MyUserInputView(MyNodeConfig nodeInfo, GraphControl owner) : base(nodeInfo, owner) { }
public void SaveGraph(GraphControl graph, String filename) { try { using (StreamWriter sw = new StreamWriter(filename)) { writeGraph(graph, sw); } } catch (Exception ex) { m_log.WriteLine("Could not save file " + filename + " : " + ex.Message + "\n" + ex.StackTrace); } m_log.WriteLine("Saved " + filename); }
public DeviceInputView(MyNodeConfig nodeConfig, GraphControl owner) : base(nodeConfig, owner) { }
private void writeGraph(GraphControl graph, StreamWriter stream) { CGraphFields graphFields = new CGraphFields(graph, m_idGen); m_serializer.Serialize(stream, graphFields); }
private void rebuildGraph(GraphControl graph) { Dictionary<String, CConnectionFields> inputs = new Dictionary<String, CConnectionFields>(); Dictionary<String, CConnectionFields> outputs = new Dictionary<String, CConnectionFields>(); foreach(CNodeFields node in m_graphFields.Nodes) { m_idNameMap.Add(node.id, node.name); Node n = new Node(node.Title); n.Location = node.Location; foreach(CNodeItemFields item in node.Items) { String name = ""; if(item.name != null) name = item.name.Split(':')[1]; if (item.Input != null) { foreach (CConnectionFields conn in item.Input) { if (!inputs.ContainsKey(conn.id)) inputs.Add(conn.id, conn); } } if (item.Output != null) { foreach (CConnectionFields conn in item.Output) { if (!outputs.ContainsKey(conn.id)) outputs.Add(conn.id, conn); } } switch (item.ItemType) { case "Graph.Items.NodeCompositeItem": { NodeCompositeItem temp = new NodeCompositeItem(item.IOMode); temp.Name = name; foreach(CItemPartFields part in item.ItemParts) { switch(part.PartType) { case "Graph.Items.ItemTextBoxPart": { ItemTextBoxPart p = new ItemTextBoxPart(part.Text); p.Name = part.name; temp.AddPart(p); } break; default: { } break; } } if (item.Tag != null) temp.Tag = TagFactory.GetTagObject(item.Tag); if (temp.Name.Contains("button_")) temp.Clicked += m_parentForm.GetConvMouseHandler(); m_itemMap.Add(item.id, temp); m_idNameMap.Add(item.id, name); n.AddItem(temp); } break; case "Graph.Items.NodeTextBoxItem": { NodeTextBoxItem temp = new NodeTextBoxItem(item.Text, item.IOMode); temp.Name = name; if (item.Tag != null) temp.Tag = TagFactory.GetTagObject(item.Tag); m_itemMap.Add(item.id, temp); m_idNameMap.Add(item.id, name); n.AddItem(temp); } break; case "Graph.Items.NodeLabelItem": { NodeLabelItem temp = new NodeLabelItem(item.Text, item.IOMode); temp.Name = name; if (item.Tag != null) temp.Tag = TagFactory.GetTagObject(item.Tag); m_itemMap.Add(item.id, temp); m_idNameMap.Add(item.id, name); if (temp.Name == "EditNodeItem") temp.Clicked += m_parentForm.GetEditMouseHandler(); n.AddItem(temp); } break; default: { //NodeItem temp = new NodeItem(item.IOMode); } break; } } graph.AddNode(n); } rebuildConnections(graph, inputs, outputs); }
private void rebuildConnections(GraphControl graph, Dictionary<string, CConnectionFields> inputs, Dictionary<string, CConnectionFields> outputs) { foreach(String key in inputs.Keys) { CConnectionFields inputFields = inputs[key]; NodeConnection conn = new NodeConnection(); conn.Tag = TagFactory.GetTagObject(inputFields.Tag); conn.Name = inputFields.name; String[] fromNameParts = inputFields.From.Split(':'); String fromNodeName = fromNameParts[0]; String fromItemName = fromNameParts[1]; String[] toNameParts = inputFields.To.Split(':'); String toNodeName = toNameParts[0]; String toItemName = toNameParts[1]; Node fromNode = findNode(graph, fromNodeName); NodeItem fromItem = findItem(fromNode, fromItemName); Node toNode = findNode(graph, toNodeName); NodeItem toItem = findItem(toNode, toItemName); graph.Connect(fromItem.Output, toItem.Input); conn.FromItem = fromItemName; conn.ToItem = toItemName; } foreach (String key in outputs.Keys) { CConnectionFields outputFields = outputs[key]; NodeConnection conn = new NodeConnection(); conn.Tag = TagFactory.GetTagObject(outputFields.Tag); conn.Name = outputFields.name; String[] fromNameParts = outputFields.From.Split(':'); String fromNodeName = fromNameParts[0]; String fromItemName = fromNameParts[1]; String[] toNameParts = outputFields.To.Split(':'); String toNodeName = toNameParts[0]; String toItemName = toNameParts[1]; Node fromNode = findNode(graph, fromNodeName); NodeItem fromItem = findItem(fromNode, fromItemName); Node toNode = findNode(graph, toNodeName); NodeItem toItem = findItem(toNode, toItemName); graph.Connect(fromItem.Output, toItem.Input); conn.FromItem = fromItemName; conn.ToItem = toItemName; } graph.Refresh(); }
private Node findNode(GraphControl ctrl, String name) { foreach(Node n in ctrl.Nodes) { foreach (NodeItem i in n.Items) { if (i.Name == "NodeName") { if(i.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem item = i as NodeTextBoxItem; if (item.Text == name) return n; } if(i.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem item = i as NodeLabelItem; if (item.Text == name) return n; } } } } return null; }
public void Initialize(GraphControl ctrl, CLog log) { m_graphCtrl = ctrl; m_log = log; String homeFolder = @Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); m_iniPath = homeFolder + @"\Roostertail Games\T3DConvoEditor\"; String iniFile = m_iniPath + "TSWriterPlugin.ini"; m_log.WriteLine("Attempting to load " + iniFile); if (File.Exists(iniFile)) m_settings = new CSettings(m_iniPath + "TSWriterPlugin.ini"); else { m_iniPath = Path.GetFullPath(".\\"); iniFile = m_iniPath + @"Plugins\TSWriterPlugin.ini"; m_log.WriteLine("Attempting to load " + iniFile); m_settings = new CSettings(iniFile); } if (!m_settings.LoadSettings()) m_log.WriteLine("Failed to locate TSWriterPlugin.ini"); else m_log.WriteLine("TSWriterPlugin settings loaded"); }
public CGraphFields(GraphControl control, ObjectIDGenerator idGen) { Dictionary<String, CNodeItemFields> idFieldMap = new Dictionary<String, CNodeItemFields>(); Dictionary<NodeItem, String> idItemMap = new Dictionary<NodeItem, String>(); bool first = false; id = idGen.GetId(control, out first).ToString(); name = control.Name; Nodes = new List<CNodeFields>(); List<Node> nodes = (List<Node>)control.Nodes; foreach (Node node in nodes) { CNodeFields nFields = new CNodeFields(); nFields.Title = node.Title; nFields.name = getNodeName(node); nFields.Location = node.Location; nFields.Items = new List<CNodeItemFields>(); bool nfirst = false; nFields.id = idGen.GetId(nFields, out nfirst).ToString(); foreach(NodeItem item in node.Items) { CNodeItemFields iFields = new CNodeItemFields(); bool ifirst = false; iFields.id = idGen.GetId(iFields, out ifirst).ToString(); String fName = nFields.name + ":" + (item.Name == null ? iFields.id : item.Name); idFieldMap.Add(fName, iFields); idItemMap.Add(item, fName); iFields.Input = new List<CConnectionFields>(); iFields.Output = new List<CConnectionFields>(); iFields.ItemParts = new List<CItemPartFields>(); iFields.name = fName; iFields.ParentNode = nFields.id; if(item.Tag != null) iFields.Tag = item.Tag.GetType().ToString(); iFields.IOMode = getIOMode(item); iFields.ItemType = item.GetType().ToString(); switch(iFields.ItemType) { case "Graph.Items.NodeTextBoxItem": { NodeTextBoxItem temp = item as NodeTextBoxItem; iFields.Text = temp.Text; } break; case "Graph.Items.NodeLabelItem": { NodeLabelItem temp = item as NodeLabelItem; iFields.Text = temp.Text; } break; case "Graph.Items.NodeCompositeItem": { NodeCompositeItem temp = item as NodeCompositeItem; foreach(ItemPart part in temp.Parts) { CItemPartFields pFields = new CItemPartFields(); bool pfirst = false; pFields.id = idGen.GetId(pFields, out pfirst).ToString(); pFields.name = part.Name; pFields.PartType = part.GetType().ToString(); switch(pFields.PartType) { case "Graph.Items.ItemTextBoxPart": { ItemTextBoxPart tempPart = part as ItemTextBoxPart; pFields.Text = tempPart.Text; } break; default: break; } iFields.ItemParts.Add(pFields); } } break; } nFields.Items.Add(iFields); } foreach(NodeItem item in node.Items) { // now get connection info String iid = idItemMap[item]; if (item.Input.Enabled && item.Input.HasConnection) { foreach (NodeConnection conn in item.Input.Connectors) { CConnectionFields cFields = new CConnectionFields(); bool cfirst = false; cFields.id = idGen.GetId(cFields, out cfirst).ToString(); Node nFrom = conn.From.Node; String fromName = ""; foreach(NodeItem nItem in nFrom.Items) { if(nItem.Name == "NodeName") { if(nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; fromName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; fromName = i.Text; } } } Node nTo = conn.To.Node; String toName = ""; foreach (NodeItem nItem in nTo.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; toName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; toName = i.Text; } } } if (conn.Tag != null) cFields.Tag = conn.Tag.GetType().ToString(); else if (item.Tag != null) cFields.Tag = item.Tag.GetType().ToString(); cFields.name = (conn.Name == null ? cFields.id : conn.Name); cFields.From = fromName + ":" + conn.From.Item.Name; cFields.To = toName + ":" + conn.To.Item.Name; idFieldMap[iid].Input.Add(cFields); } } if (item.Output.Enabled && item.Output.HasConnection) { foreach (NodeConnection conn in item.Output.Connectors) { CConnectionFields cFields = new CConnectionFields(); bool cfirst = false; cFields.id = idGen.GetId(cFields, out cfirst).ToString(); Node nFrom = conn.From.Node; String fromName = ""; foreach (NodeItem nItem in nFrom.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; fromName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; fromName = i.Text; } } } Node nTo = conn.To.Node; String toName = ""; foreach (NodeItem nItem in nTo.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; toName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; toName = i.Text; } } } if (conn.Tag != null) cFields.Tag = conn.Tag.GetType().ToString(); else if (item.Tag != null) cFields.Tag = item.Tag.GetType().ToString(); cFields.name = (conn.Name == null ? cFields.id : conn.Name); cFields.From = fromName + ":" + conn.From.Item.Name; cFields.To = toName + ":" + conn.To.Item.Name; idFieldMap[iid].Input.Add(cFields); } } } Nodes.Add(nFields); } }
public MyVariableBranchView(MyNodeConfig nodeInfo, GraphControl owner) : base(nodeInfo, owner) { }
public MyNodeGroupView(MyNodeConfig nodeInfo, GraphControl owner) : base(nodeInfo, owner) { }
public void FillInToGraphControl(GraphControl gc) { gc.AddNodes(NodeIdentifierDict.Keys); foreach (NodeConnection NC in NodeConnections) { gc.Connect(NC.From.Item, NC.To.Item); } }