private void UpdatePorts() { var guids = InPorts.Select(x => x.GUID).ToArray(); InPorts.Clear(); for (int input = 0; input < InputCount; input++) { var name = $"Port {input + 1}"; var pm = new PortModel(PortType.Input, this, new PortData(name, "")); InPorts.Add(pm); if (guids.Length == InputCount) { pm.GUID = guids[input]; } } guids = OutPorts.Select(x => x.GUID).ToArray(); OutPorts.Clear(); for (int output = 0; output < OutputCount; output++) { var name = $"Port {output + 1}"; var pm = new PortModel(PortType.Output, this, new PortData(name, "")); OutPorts.Add(pm); if (guids.Length == OutputCount) { pm.GUID = guids[output]; } } RegisterAllPorts(); }
protected override void SerializeCore(XmlElement element, SaveContext context) { base.SerializeCore(element, context); //Base implementation must be called Controller.SerializeCore(element, context); var xmlDoc = element.OwnerDocument; var outEl = xmlDoc.CreateElement("Name"); outEl.SetAttribute("value", NickName); element.AppendChild(outEl); outEl = xmlDoc.CreateElement("Description"); outEl.SetAttribute("value", Description); element.AppendChild(outEl); outEl = xmlDoc.CreateElement("Inputs"); foreach (string input in InPorts.Select(x => x.PortName)) { XmlElement inputEl = xmlDoc.CreateElement("Input"); inputEl.SetAttribute("value", input); outEl.AppendChild(inputEl); } element.AppendChild(outEl); outEl = xmlDoc.CreateElement("Outputs"); foreach (string output in OutPorts.Select(x => x.PortName)) { XmlElement outputEl = xmlDoc.CreateElement("Output"); outputEl.SetAttribute("value", output); outEl.AppendChild(outputEl); } element.AppendChild(outEl); }
private void UpdatePaintVars(Graphics e) { if (paint_cellSizeChanged || !paint_initialized) { paint_cellSize = FlowGraph.Grid.CurrentCellSize; } if (paint_cellSizeChanged || !paint_initialized) { paint_portFont = new Font(PortFontFamily, 20); while (paint_portFont.GetHeight() > paint_cellSize.Height) { paint_portFont = new Font(PortFontFamily, paint_portFont.Size - 0.5f); } } if (paint_cellSizeChanged || paint_portsChanged || paint_locationChanged || !paint_initialized) { string longestInPortName = InPorts.Select(c => c.PortName).Aggregate("", (max, cur) => max.Length > cur.Length ? max : cur); string longestOutPortName = OutPorts.Select(c => c.PortName).Aggregate("", (max, cur) => max.Length > cur.Length ? max : cur); float portGripSize = paint_cellSize.Height / 3; paint_inPortSize = e.MeasureString(longestInPortName, paint_portFont); paint_outPortSize = e.MeasureString(longestOutPortName, paint_portFont); float nodeWidth = (float)Math.Ceiling((paint_inPortSize.Width + paint_outPortSize.Width + (portGripSize * 2)) / paint_cellSize.Width) * paint_cellSize.Width; float nodeHeight = ((InPorts.Count > OutPorts.Count ? InPorts.Count : OutPorts.Count) + 1) * paint_cellSize.Height; //add two for the header and footer paint_nodeSize = new SizeF(nodeWidth, nodeHeight); for (int i = 0; i < InPorts.Count; i++) { InPorts[i].PortBounds = new RectangleF(0 + portGripSize, (i + 1) * paint_cellSize.Height, paint_inPortSize.Width, paint_inPortSize.Height); } for (int i = 0; i < OutPorts.Count; i++) { float portTextOffset = e.MeasureString(OutPorts[i].PortName, paint_portFont).Width + portGripSize; OutPorts[i].PortBounds = new RectangleF(paint_nodeSize.Width - portTextOffset, (i + 1) * paint_cellSize.Height, paint_outPortSize.Width, paint_outPortSize.Height); } UpdateLinks(); } if (paint_cellSizeChanged || !paint_initialized) { paint_headerFont = new Font(PortFontFamily, 20); while (paint_headerFont.GetHeight() > paint_cellSize.Height || e.MeasureString(NodeHeaderText, paint_headerFont).Width > paint_nodeSize.Width) { paint_headerFont = new Font(PortFontFamily, paint_headerFont.Size - 0.5f); } } if (paint_cellSizeChanged || !paint_initialized) { paint_clip = new Rectangle(0, 0, (int)paint_nodeSize.Width, (int)paint_nodeSize.Height); } paint_initialized = true; paint_cellSizeChanged = false; paint_portsChanged = false; paint_locationChanged = false; }