public AnalyticElement(Element element) { Element = element; Parameter parInsTypeCheck = Element.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); if (parInsTypeCheck.HasValue) { Parameter parInsThickness = Element.get_Parameter(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); InsulationThk = (int)parInsThickness.AsDouble().FtToMm().Round(); } switch (Element) { case Pipe pipe: //Outside diameter oDia = Element.get_Parameter(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER).AsDouble().FtToMm(); //Wallthk DN = (int)pipe.Diameter.FtToMm().Round(); WallThk = MepUtils.pipeWallThkDict()[DN]; break; case FamilyInstance fi: //Outside diameter Cons cons = MepUtils.GetConnectors(fi); DN = (int)(cons.Primary.Radius * 2).FtToMm().Round(); oDia = MepUtils.outerDiaDict()[DN]; WallThk = MepUtils.pipeWallThkDict()[DN]; break; default: break; } }
public void AnalyzeBend() { Cons cons = MepUtils.GetConnectors(Element); XYZ P = cons.Primary.Origin; XYZ Q = cons.Secondary.Origin; double a = P.DistanceTo(Q) / 2; double angle = Element.LookupParameter("Angle").AsDouble(); double A = angle / 2; BendRadius = (a / (Math.Sin(A))).FtToMm(); }
public static int OletRefOwnerIdAsInt(this Element e) { var cons = MepUtils.GetConnectors(e); var refCons = MepUtils.GetAllConnectorsFromConnectorSet(cons.Primary.AllRefs); Connector refCon = refCons.Where(x => x.Owner.IsType <Pipe>()).FirstOrDefault(); if (refCon == null) { throw new Exception("Olet id " + e.Id.ToString() + " has no reference connector! Check connectivity."); } Element owner = refCon.Owner; return(owner.Id.IntegerValue); }
public void AnalyzeSystem() { //Deviously hard to follow (and debug) code be here //Start analysis var openEnds = detectOpenEnds(Model); Connector To = null; Connector From = null; Node FromNode = null; Node ToNode = null; Element curElem = null; AnalyticElement curAElem = null; AnalyticSequence curSequence = null; bool continueSequence = false; IList <Connector> branchEnds = new List <Connector>(); for (int i = 0; i < Model.AllElements.Count; i++) { if (!continueSequence) { if (branchEnds.Count > 0) { From = branchEnds.FirstOrDefault(); branchEnds = branchEnds.ExceptWhere(c => c.Equalz(From, _1mmTol)).ToList(); FromNode = (from Node n in Model.AllNodes where n.PreviousCon != null && n.PreviousCon.Equalz(From, _1mmTol) select n).FirstOrDefault(); FromNode.NextCon = From; } else { From = openEnds.FirstOrDefault(); openEnds = openEnds.ExceptWhere(c => c.Equalz(From, _1mmTol)).ToList(); FromNode = new Node(); FromNode.NextCon = From; Model.AllNodes.Add(FromNode); curSequence = new AnalyticSequence(); } ToNode = new Node(); curElem = From.Owner; curAElem = new AnalyticElement(curElem); continueSequence = true; } switch (curElem) { case Pipe pipe: To = (from Connector c in pipe.ConnectorManager.Connectors //End of the host/dummy pipe where c.Id != From.Id && (int)c.ConnectorType == 1 select c).FirstOrDefault(); //Test if the ToNode already exists //TODO: This test must be copied to all other elements Node existingToNode = (from Node n in Model.AllNodes where (n.PreviousCon != null && n.PreviousCon.Equalz(To, _1mmTol)) || (n.NextCon != null && n.NextCon.Equalz(To, _1mmTol)) select n).FirstOrDefault(); if (existingToNode != null) { ToNode = existingToNode; if (ToNode.PreviousCon == null) { ToNode.PreviousCon = To; } else if (ToNode.NextCon == null) { ToNode.NextCon = To; } } else { ToNode.PreviousCon = To; Model.AllNodes.Add(ToNode); } curAElem.From = FromNode; curAElem.To = ToNode; //Assign correct element type to analytic element curAElem.Type = ElemType.Pipe; curSequence.Sequence.Add(curAElem); break; case FamilyInstance fi: Cons cons = MepUtils.GetConnectors(fi); int cat = fi.Category.Id.IntegerValue; switch (cat) { case (int)BuiltInCategory.OST_PipeFitting: var mf = fi.MEPModel as MechanicalFitting; var partType = mf.PartType; switch (partType) { case PartType.Elbow: //First Analytic Element XYZ elbowLoc = ((LocationPoint)fi.Location).Point; ToNode.PreviousLoc = elbowLoc; //The node has only element Location point defining it - ToNode.NextLoc = elbowLoc; //and not two adjacent Connectors as element connection nodes ToNode.Type = ElemType.Elbow; Model.AllNodes.Add(ToNode); curAElem.From = FromNode; curAElem.To = ToNode; curAElem.Type = ElemType.Elbow; curAElem.AnalyzeBend(); curSequence.Sequence.Add(curAElem); //Second Analytic Element //First determine the To connector To = (from Connector c in MepUtils.GetALLConnectorsFromElements(curElem) where c.Id != From.Id select c).FirstOrDefault(); FromNode = ToNode; //Switch to next element ToNode = new Node(); Model.AllNodes.Add(ToNode); ToNode.PreviousCon = To; curAElem = new AnalyticElement(curElem); curAElem.From = FromNode; curAElem.To = ToNode; curAElem.Type = ElemType.Pipe; curSequence.Sequence.Add(curAElem); break; case PartType.Tee: //Junction logic Node primNode = null; Node secNode = null; Node tertNode = null; //First analytic element XYZ teeLoc = ((LocationPoint)fi.Location).Point; ToNode.PreviousLoc = teeLoc; //The node has only element Location point defining it - ToNode.NextLoc = teeLoc; //and not two adjacent Connectors as element connection nodes ToNode.Type = ElemType.Tee; Model.AllNodes.Add(ToNode); curAElem.From = FromNode; curAElem.To = ToNode; curAElem.Type = ElemType.Tee; curSequence.Sequence.Add(curAElem); //Logic to return correct node to next element if (From.GetMEPConnectorInfo().IsPrimary) { primNode = FromNode; } else if (From.GetMEPConnectorInfo().IsSecondary) { secNode = FromNode; } else { tertNode = FromNode; } //From node is common for next two elements FromNode = ToNode; //Second Analytic Element if (From.GetMEPConnectorInfo().IsPrimary) { To = cons.Secondary; } else if (From.GetMEPConnectorInfo().IsSecondary) { To = cons.Primary; } else { To = cons.Primary; } ToNode = new Node(); Model.AllNodes.Add(ToNode); ToNode.PreviousCon = To; curAElem = new AnalyticElement(curElem); curAElem.From = FromNode; curAElem.To = ToNode; curAElem.Type = ElemType.Pipe; curSequence.Sequence.Add(curAElem); //Logic to return correct node to next element if (From.GetMEPConnectorInfo().IsPrimary) { secNode = ToNode; } else if (From.GetMEPConnectorInfo().IsSecondary) { primNode = ToNode; } else { primNode = ToNode; } //Third Analytic Element if (From.GetMEPConnectorInfo().IsPrimary) { To = cons.Tertiary; } else if (From.GetMEPConnectorInfo().IsSecondary) { To = cons.Tertiary; } else { To = cons.Secondary; } ToNode = new Node(); Model.AllNodes.Add(ToNode); ToNode.PreviousCon = To; curAElem = new AnalyticElement(curElem); curAElem.From = FromNode; curAElem.To = ToNode; curAElem.Type = ElemType.Pipe; curSequence.Sequence.Add(curAElem); //Logic to return correct node to next element if (From.GetMEPConnectorInfo().IsPrimary) { tertNode = ToNode; } else if (From.GetMEPConnectorInfo().IsSecondary) { tertNode = ToNode; } else { secNode = ToNode; } //Continuation logic Connector candidate1; Connector candidate2; if (From.GetMEPConnectorInfo().IsPrimary) { candidate1 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Secondary, _1mmTol) select c).FirstOrDefault(); candidate2 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Tertiary, _1mmTol) select c).FirstOrDefault(); if (candidate1 != null) { To = cons.Secondary; ToNode = secNode; if (candidate2 != null) { branchEnds.Add(candidate2); } } else if (candidate2 != null) { To = cons.Tertiary; ToNode = tertNode; } } else if (From.GetMEPConnectorInfo().IsSecondary) { candidate1 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Primary, _1mmTol) select c).FirstOrDefault(); candidate2 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Tertiary, _1mmTol) select c).FirstOrDefault(); if (candidate1 != null) { To = cons.Primary; ToNode = primNode; if (candidate2 != null) { branchEnds.Add(candidate2); } } else if (candidate2 != null) { To = cons.Tertiary; ToNode = tertNode; } } else { candidate1 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Primary, _1mmTol) select c).FirstOrDefault(); candidate2 = (from Connector c in Model.AllConnectors where c.Equalz(cons.Secondary, _1mmTol) select c).FirstOrDefault(); if (candidate1 != null) { To = cons.Primary; ToNode = primNode; if (candidate2 != null) { branchEnds.Add(candidate2); } } else if (candidate2 != null) { To = cons.Secondary; ToNode = secNode; } } break; case PartType.Transition: To = (from Connector c in MepUtils.GetALLConnectorsFromElements(curElem) where c.Id != From.Id select c).FirstOrDefault(); ToNode.PreviousCon = To; Model.AllNodes.Add(ToNode); curAElem.From = FromNode; curAElem.To = ToNode; //Assign correct element type to analytic element curAElem.Type = ElemType.Transition; //Determine start dia and second dia curAElem.AnalyzeReducer(); curSequence.Sequence.Add(curAElem); break; case PartType.Cap: //Handles flanges because of the workaround PartType.Cap for flanges //Real Caps are ignored for now To = (from Connector c in MepUtils.GetALLConnectorsFromElements(curElem) where c.Id != From.Id select c).FirstOrDefault(); ToNode.PreviousCon = To; Model.AllNodes.Add(ToNode); curAElem.From = FromNode; curAElem.To = ToNode; //Assign correct element type to analytic element curAElem.Type = ElemType.Rigid; curSequence.Sequence.Add(curAElem); break; case PartType.Union: throw new NotImplementedException(); case PartType.SpudAdjustable: throw new NotImplementedException(); default: continue; } break; case (int)BuiltInCategory.OST_PipeAccessory: if (From.GetMEPConnectorInfo().IsPrimary) { To = cons.Secondary; } else if (From.GetMEPConnectorInfo().IsSecondary) { To = cons.Primary; } else { throw new Exception("Something went wrong with connectors of element " + curElem.Id.ToString()); } ToNode.PreviousCon = To; Model.AllNodes.Add(ToNode); curAElem.From = FromNode; curAElem.To = ToNode; //Assign correct element type to analytic element curAElem.Type = ElemType.Rigid; curSequence.Sequence.Add(curAElem); break; default: continue; } break; default: continue; } //Prepare to restart iteration Model.AllConnectors = Model.AllConnectors.ExceptWhere(c => c.Owner.Id.IntegerValue == curElem.Id.IntegerValue).ToList(); From = (from Connector c in Model.AllConnectors where c.Equalz(To, _1mmTol) select c).FirstOrDefault(); if (From != null) { curElem = From.Owner; FromNode = ToNode; FromNode.NextCon = From; ToNode = new Node(); curAElem = new AnalyticElement(curElem); } else { continueSequence = false; openEnds = openEnds.ExceptWhere(c => c.Equalz(To, _1mmTol)).ToList(); if (branchEnds.Count > 0 && To != null) { branchEnds = branchEnds.ExceptWhere(c => c.Equalz(To, _1mmTol)).ToList(); } if (branchEnds.Count < 1) { Model.Sequences.Add(curSequence); } } } //Reference ALL analytic elements in the collecting pool foreach (var sequence in Model.Sequences) { foreach (var item in sequence.Sequence) { Model.AllAnalyticElements.Add(item); } } //Loop over ALL nodes and populate coordinate information foreach (Node n in Model.AllNodes) { n.PopulateCoordinates(); } BuildingCoderUtilities.InfoMsg(Model.AllNodes.Count.ToString()); }