// Input instances // Output instances // IEvent implementation void IEvent.Execute() { newNode = CreateNewNode(); Utilities.ConnectToVirtualPort(newNode, "typeInput", typeInput); Utilities.ConnectToVirtualPort(newNode, "typesInput", typesInput); Utilities.ConnectToVirtualPort(newNode, "nameInput", nameInput); Utilities.ConnectToVirtualPort(newNode, "portsInput", portsInput); Utilities.ConnectToVirtualPort(newNode, "unnamedConstructorArgumentsInput", unnamedConstructorArgumentsInput); Utilities.ConnectToVirtualPort(newNode, "namedConstructorArgumentsInput", namedConstructorArgumentsInput); Utilities.ConnectToVirtualPort(newNode, "nodePropertiesInput", nodePropertiesInput); Utilities.ConnectToVirtualPort(newNode, "renderReady", renderReady); Utilities.ConnectToVirtualPort(newNode, "contextMenuInput", contextMenuInput); Utilities.ConnectToVirtualPort(newNode, "typeChanged", typeChanged); // newNode.WireTo(nodeEventHandlerConnector, "nodeEventHandlers"); // newNode.WireTo(portEventHandlerConnector, "portEventHandlers"); // Utilities.ConnectToVirtualPort(nodeEventHandlerConnector, "propagatedHandler", nodeBehaviour); // Utilities.ConnectToVirtualPort(portEventHandlerConnector, "propagatedHandler", portBehaviour); newNode.ActionPerformed += (source) => UndoHistory.Push(source); newNode.Initialise(); if (nodeOutput != null) { nodeOutput.Data = newNode; } }
private VisualPortGraphNode CreateNewNode() { // BEGIN AUTO-GENERATED INSTANTIATIONS FOR NewVisualPortGraphNode.xmind VisualPortGraphNode newNode = new VisualPortGraphNode() { InstanceName = "newNode", Graph = Graph, StateTransition = StateTransition, NodeStyle = NodeStyle, PortStyle = PortStyle, PositionX = 400, PositionY = 200 }; // END AUTO-GENERATED INSTANTIATIONS FOR NewVisualPortGraphNode.xmind // BEGIN AUTO-GENERATED WIRING FOR NewVisualPortGraphNode.xmind // END AUTO-GENERATED WIRING FOR NewVisualPortGraphNode.xmind // BEGIN MANUAL INSTANTIATIONS FOR NewVisualPortGraphNode.xmind // END MANUAL INSTANTIATIONS FOR NewVisualPortGraphNode.xmind // BEGIN MANUAL WIRING FOR NewVisualPortGraphNode.xmind // END MANUAL WIRING FOR NewVisualPortGraphNode.xmind return(newNode); }
public string GetInstantiationCode(VisualPortGraphNode node) { if (node.Render.Visibility != Visibility.Visible || node.Name.StartsWith("@")) { return(""); } var sb = new StringBuilder(); var obj = JObject.Parse(node.Serialise()); string type = obj.GetValue("Type").ToString(); string name = obj.GetValue("Name").ToString(); if (string.IsNullOrWhiteSpace(name)) { name = $"id_{obj.GetValue("Id")}"; } var constructorArgs = new List <string>(); var properties = new List <string>(); if (!name.StartsWith("id_")) { properties.Add($"InstanceName = \"{name}\""); } foreach (JObject parameter in obj.GetValue("NodeParameters")) { if (parameter["ParameterType"].ToString() == "Constructor") { constructorArgs.Add($"{parameter["Name"]}: {parameter["Value"]}"); } else if (parameter["ParameterType"].ToString() == "Property") { properties.Add($"{parameter["Name"]} = {parameter["Value"]}"); } } var constructorArgsSB = new StringBuilder(); if (constructorArgs.Count > 0) { constructorArgsSB.Append(constructorArgs[0]); if (constructorArgs.Count > 1) { foreach (var arg in constructorArgs.Skip(1)) { constructorArgsSB.Append($", {arg}"); } } } var propertiesSB = new StringBuilder(); if (properties.Count > 0) { propertiesSB.Append(properties[0]); if (properties.Count > 1) { foreach (var prop in properties.Skip(1)) { propertiesSB.Append($", {prop}"); } } } var unflattenedString = $"{type} {name} = new {type}({constructorArgsSB}) {{ {propertiesSB} }};"; // var flattenedString = unflattenedString.Replace(Environment.NewLine, ""); // Note: this does not handle when new lines are escaped var flattenedString = Regex.Replace(unflattenedString, @"[\t\n\r]", ""); // Note: this does not handle when new lines are escaped sb.Append(flattenedString); // return "//[" + Environment.NewLine + sb.ToString() + Environment.NewLine + "//]"; return(sb.ToString()); }