public double AddConduitClosureBlock(DiagramBuilder builder, ConduitClosureInfo conduitClosureInfo, double minBlockWidth, double offsetY) { double labelSectionWidth = 40; double sideMargin = 20; LineBlock leftLabelBlock = new LineBlock(0, offsetY, LineBlockTypeEnum.Simple); leftLabelBlock.MinWidth = labelSectionWidth; LineBlock rightLabelBlock = new LineBlock(minBlockWidth + labelSectionWidth, offsetY, LineBlockTypeEnum.Simple); rightLabelBlock.MinWidth = labelSectionWidth; ////////////////////////////////////////////////////////// /// conduit closure block /// LineBlock conduitClosureBlock = new LineBlock(labelSectionWidth, offsetY); conduitClosureBlock.SetReference(conduitClosureInfo.Id, "ConduitClosure"); conduitClosureBlock.MinWidth = minBlockWidth; conduitClosureBlock.MinHeight = 100; conduitClosureBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(conduitClosureBlock); Dictionary <BlockPort, ConduitClosurePortInfo> blockPortToConduitClosurePort = new Dictionary <BlockPort, ConduitClosurePortInfo>(); // Add ports foreach (var side in conduitClosureInfo.Sides) { foreach (var conduitClosurePort in side.Ports) { var nTerminals = conduitClosurePort.Terminals.Count; var blockPort = AddMultiConduitPort(conduitClosureBlock, Convert(side.Position), conduitClosurePort.Terminals, conduitClosurePort.MultiConduitSegment.Conduit.Color.ToString(), -1, -1, 10); blockPort.SetReference(conduitClosurePort.MultiConduitSegment.Id, "MultiConduitSegment"); blockPortToConduitClosurePort.Add(blockPort, conduitClosurePort); // Add left label blocks if (side.Position == ConduitClosureInfoSide.Left) { // Add left west label port AddBigConduitPort(leftLabelBlock, BlockSideEnum.Vest, nTerminals, null, -1, -1, 10); // Add left east label port AddBigConduitPort(leftLabelBlock, BlockSideEnum.East, nTerminals, null, -1, -1, 10); foreach (var terminal in conduitClosurePort.Terminals) { var lineInfo = _traversalHelper.CreateTraversalInfoFromSegment(terminal.LineSegment); leftLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, blockPort.Index, terminal.Position, BlockSideEnum.East, blockPort.Index, terminal.Position, lineInfo.StartRouteNode.Name, "LabelMediumText"); } } // Add right label block if (side.Position == ConduitClosureInfoSide.Right) { // Add right west label port AddBigConduitPort(rightLabelBlock, BlockSideEnum.Vest, nTerminals, null, -1, -1, 10); // Add right east label port AddBigConduitPort(rightLabelBlock, BlockSideEnum.East, nTerminals, null, -1, -1, 10); foreach (var terminal in conduitClosurePort.Terminals) { var lineInfo = _traversalHelper.CreateTraversalInfoFromSegment(terminal.LineSegment); rightLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, blockPort.Index, terminal.Position, BlockSideEnum.East, blockPort.Index, terminal.Position, lineInfo.EndRouteNode.Name, "LabelMediumText"); } } } } conduitClosureBlock.SetSideCenterAllignment(BlockSideEnum.North, true); // Connect ports foreach (var portEntry in blockPortToConduitClosurePort) { var blockPort = portEntry.Key; var conduitClosurePort = portEntry.Value; if ((blockPort.Side == BlockSideEnum.Vest || blockPort.Side == BlockSideEnum.North) && conduitClosurePort.ConnectionKind == ConduitClosureInternalConnectionKindEnum.PassThrough) { var portConnection = conduitClosureBlock.AddPortConnection(blockPort.Side, blockPort.Index, Convert(conduitClosurePort.ConnectedToSide), conduitClosurePort.ConnectedToPort, null, "MultiConduit" + conduitClosurePort.MultiConduitSegment.Conduit.Color.ToString()); portConnection.SetReference(conduitClosurePort.MultiConduitSegment.ConduitId, "Conduit"); } } // Connect terminals HashSet <ConduitClosureTerminalInfo> terminalAlreadyProcessed = new HashSet <ConduitClosureTerminalInfo>(); foreach (var portEntry in blockPortToConduitClosurePort) { var blockPort = portEntry.Key; var conduitClosurePort = portEntry.Value; foreach (var terminal in conduitClosurePort.Terminals) { if (!terminalAlreadyProcessed.Contains(terminal)) { terminalAlreadyProcessed.Add(terminal); if (terminal.ConnectionKind == ConduitClosureInternalConnectionKindEnum.PassThrough || terminal.ConnectionKind == ConduitClosureInternalConnectionKindEnum.Connected) { string color = "Red"; if (terminal.LineSegment is ConduitSegmentInfo) { var conduitSegmentInfo = terminal.LineSegment as ConduitSegmentInfo; color = conduitSegmentInfo.Conduit.Color.ToString(); } var terminalConnection = conduitClosureBlock.AddTerminalConnection(blockPort.Side, blockPort.Index, terminal.Position, Convert(terminal.ConnectedToSide), terminal.ConnectedToPort, terminal.ConnectedToTerminal, null, "InnerConduit" + color, LineShapeTypeEnum.Polygon); terminalConnection.SetReference(terminal.LineId, "InnerConduit"); // make sure we don't connect the other way too var connectedToTerminal = conduitClosureInfo.Sides.Find(s => s.Position == terminal.ConnectedToSide).Ports.Find(p => p.Position == terminal.ConnectedToPort).Terminals.Find(t => t.Position == terminal.ConnectedToTerminal); terminalAlreadyProcessed.Add(connectedToTerminal); } } } } // Add label blocks leftLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(leftLabelBlock); rightLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(rightLabelBlock); return(conduitClosureBlock.DesiredSize.Height); }