private List <Guid> GetPassThroughNodes(ConduitSegmentInfo conduitSegment, WalkOfInterestInfo conduitWalkOfInterest) { List <Guid> result = new List <Guid>(); // Get pass through node candidates (the ones that the segment don't start or end at) HashSet <Guid> passThroughNodeCandidatess = new HashSet <Guid>(); foreach (var nodeId in conduitWalkOfInterest.AllNodeIds) { if (!(conduitSegment.FromRouteNodeId == nodeId || conduitSegment.ToRouteNodeId == nodeId)) { passThroughNodeCandidatess.Add(nodeId); } } var segmentWalkNodes = conduitWalkOfInterest.SubWalk2(conduitSegment.FromRouteNodeId, conduitSegment.ToRouteNodeId).AllNodeIds; foreach (var segmentWalkNode in segmentWalkNodes) { if (passThroughNodeCandidatess.Contains(segmentWalkNode)) { result.Add(segmentWalkNode); } } return(result); }
private BlockPort AddMultiConduitPort(LineBlock lineBlock, BlockSideEnum side, List <ConduitClosureTerminalInfo> terminals, string outerConduitColor, double spaceBetweenTerminals = -1, double terminalSize = -1, double portMargin = -1) { BlockPort port = new BlockPort(side, "MultiConduit" + outerConduitColor, null, spaceBetweenTerminals, terminalSize, portMargin); foreach (var terminal in terminals) { if (terminal.LineSegment is ConduitSegmentInfo) { ConduitSegmentInfo conduitSegment = terminal.LineSegment as ConduitSegmentInfo; bool visible = false; if (terminal.ConnectionKind == ConduitClosureInternalConnectionKindEnum.NotConnected) { visible = true; } var blockTerminal = new BlockPortTerminal(visible, "InnerConduit" + conduitSegment.Conduit.Color.ToString()); blockTerminal.SetReference(conduitSegment.Id, "InnerConduitSegment"); port.AddTerminal(blockTerminal); } } lineBlock.AddPort(port); return(port); }
private void ConnectTerminals(ConduitClosureInfo conduitClosure, ConduitInfo singleConduit, Guid pointOfInterestId, Guid junctionId, ConduitEndKindEnum endKind) { var relatedSegments = FindRelatedSegmentInfo(singleConduit, pointOfInterestId, endKind); if (relatedSegments.Count == 1) { var segment = relatedSegments[0].Segment; // Check if terminal with such segment exists if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id)))) { var side = conduitClosure.Sides.Find(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id))); var port = side.Ports.Find(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id)); var terminal = port.Terminals.Find(t => t.LineSegmentId == segment.Id); ConduitSegmentInfo connectedSegment = null; // Get the segment on the other side of the junction if (segment.FromNodeId == junctionId && segment.FromNode.NeighborElements.OfType <ConduitSegmentInfo>().Any(n => n != segment)) { connectedSegment = segment.FromNode.NeighborElements.OfType <ConduitSegmentInfo>().First(n => n != segment); } else if (segment.ToNodeId == junctionId && segment.ToNode.NeighborElements.OfType <ConduitSegmentInfo>().Any(n => n != segment)) { connectedSegment = segment.ToNode.NeighborElements.OfType <ConduitSegmentInfo>().First(n => n != segment); } // Check if terminal with related segment exisits if (connectedSegment != null && conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id)))) { var connectedSide = conduitClosure.Sides.Find(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id))); var connectedPort = connectedSide.Ports.Find(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id)); var connectedTerminal = connectedPort.Terminals.Find(t => t.LineSegmentId == connectedSegment.Id); // Okay, we're safe to connect the two terminals together terminal.ConnectionKind = ConduitClosureInternalConnectionKindEnum.Connected; terminal.ConnectedToSide = connectedSide.Position; terminal.ConnectedToPort = connectedPort.Position; terminal.ConnectedToTerminal = connectedTerminal.Position; connectedTerminal.ConnectionKind = ConduitClosureInternalConnectionKindEnum.Connected; connectedTerminal.ConnectedToSide = side.Position; connectedTerminal.ConnectedToPort = port.Position; connectedTerminal.ConnectedToTerminal = terminal.Position; } } } }
public double AddMultiConduitPassThroughBlock(DiagramBuilder builder, ConduitSegmentInfo conduitSegmentInfo, double minBlockWidth, double offsetY) { double labelSectionWidth = 40; double sideMargin = 20; ////////////////////////////////////////////////////////// /// conduit block /// LineBlock conduitBlock = new LineBlock(labelSectionWidth, offsetY, LineBlockTypeEnum.Simple); conduitBlock.MinWidth = minBlockWidth; var nTerminals = conduitSegmentInfo.Children.Count; var color = conduitSegmentInfo.Conduit.Color.ToString(); // Add vest ports AddMultiConduitPort(conduitBlock, BlockSideEnum.Vest, nTerminals, color, -1, -1, 10); // Add east ports AddMultiConduitPort(conduitBlock, BlockSideEnum.East, nTerminals, color, -1, -1, 10); // Connect ports var portConnection = conduitBlock.AddPortConnection(BlockSideEnum.Vest, 1, BlockSideEnum.East, 1, null, "MultiConduit" + color); portConnection.SetReference(conduitSegmentInfo.ConduitId, "Conduit"); // Connect west and east terminals foreach (var child in conduitSegmentInfo.Children.OfType <ConduitSegmentInfo>()) { var terminalConnection = conduitBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, child.Conduit.SequenceNumber, BlockSideEnum.East, 1, child.Conduit.SequenceNumber, null, "InnerConduit" + child.Conduit.Color.ToString(), LineShapeTypeEnum.Polygon); terminalConnection.SetReference(child.Conduit.Id, "SingleConduit"); } conduitBlock.SetSideMargin(sideMargin); conduitBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(conduitBlock); ////////////////////////////////////////////////////////// /// left label block LineBlock leftLabelBlock = new LineBlock(0, offsetY, LineBlockTypeEnum.Simple); leftLabelBlock.MinWidth = labelSectionWidth; // Add vest port AddBigConduitPort(leftLabelBlock, BlockSideEnum.Vest, nTerminals, null, -1, -1, 10); // Add east port AddBigConduitPort(leftLabelBlock, BlockSideEnum.East, nTerminals, null, -1, -1, 10); // Connect west and east terminals foreach (var child in conduitSegmentInfo.Children.OfType <ConduitSegmentInfo>()) { var lineInfo = _traversalHelper.CreateTraversalInfoFromSegment(conduitSegmentInfo); leftLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, child.Conduit.SequenceNumber, BlockSideEnum.East, 1, child.Conduit.SequenceNumber, lineInfo.StartRouteNode.Name, "LabelMediumText"); } leftLabelBlock.SetSideMargin(sideMargin); leftLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(leftLabelBlock); ////////////////////////////////////////////////////////// /// right label block LineBlock rightLabelBlock = new LineBlock(minBlockWidth + labelSectionWidth, offsetY, LineBlockTypeEnum.Simple); rightLabelBlock.MinWidth = labelSectionWidth; // Add vest port AddBigConduitPort(rightLabelBlock, BlockSideEnum.Vest, nTerminals, null, -1, -1, 10); // Add east port AddBigConduitPort(rightLabelBlock, BlockSideEnum.East, nTerminals, null, -1, -1, 10); // Connect west and east terminals foreach (var child in conduitSegmentInfo.Children.OfType <ConduitSegmentInfo>()) { var lineInfo = _traversalHelper.CreateTraversalInfoFromSegment(conduitSegmentInfo); var terminalConnection = rightLabelBlock.AddTerminalConnection(BlockSideEnum.Vest, 1, child.Conduit.SequenceNumber, BlockSideEnum.East, 1, child.Conduit.SequenceNumber, lineInfo.EndRouteNode.Name, "LabelMediumText"); } rightLabelBlock.SetSideMargin(sideMargin); rightLabelBlock.Measure(new Layout.Size()); builder.ContentObjects.Add(rightLabelBlock); return(conduitBlock.DesiredSize.Height); }
public static void CutConduit(ConduitInfo conduitInfo, WalkOfInterestInfo walkOfInterest, RouteNodeInfo nodeWhereToCut) { ConduitSegmentInfo newSegment = null; List <ISegment> newSegmentList = new List <ISegment>(); int newSequenceNumber = 1; var fromNodeId = conduitInfo.Segments[0].FromRouteNodeId; foreach (var existingSegment in conduitInfo.Segments) { List <Guid> segmentWalk = walkOfInterest.SubWalk(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); newSegmentList.Add(existingSegment); existingSegment.SequenceNumber = newSequenceNumber; existingSegment.FromRouteNodeId = fromNodeId; // If the segment is cut by point of interest, divide it if (segmentWalk.Contains(nodeWhereToCut.Id)) { // Create the segment newSequenceNumber++; if (conduitInfo.Kind != ConduitKindEnum.MultiConduit) { newSegment = new SingleConduitSegmentInfo(); } else { newSegment = new MultiConduitSegmentInfo(); } newSegment.Id = Guid.NewGuid(); newSegment.ConduitId = ((ConduitSegmentInfo)existingSegment).ConduitId; newSegment.SequenceNumber = newSequenceNumber; newSegment.FromRouteNodeId = nodeWhereToCut.Id; newSegment.ToRouteNodeId = existingSegment.ToRouteNodeId; // we need copy to side info newSegment.ToNodeId = existingSegment.ToNodeId; // we need copy to side info newSegment.ToNode = existingSegment.ToNode; // we need copy to side info // Update the existing segment existingSegment.ToRouteNodeId = nodeWhereToCut.Id; existingSegment.ToNodeId = Guid.Empty; // cannot possible have to junction anymore if it had so (transfered to new segment) existingSegment.ToNode = null; // cannot possible have to junction anymore if it had so (transfered to new segment) // Set from node on next segment to from node on inserted segment fromNodeId = newSegment.ToRouteNodeId; newSegmentList.Add(newSegment); } else { // set from node to this one to node fromNodeId = existingSegment.ToRouteNodeId; } newSequenceNumber++; } conduitInfo.Segments = newSegmentList; // Needed to wake up Marten conduitInfo.Name = conduitInfo.Name; }