/// <summary> /// Get list of child object names from relatedObjects property of a ifcProduct asset and join with a " : " delimiter /// </summary> /// <returns>List of strings fixed to a string limit per string entry</returns> private ChildNamesList ConCatChildNamesList(ChildNamesList childNamesUnique, int fieldLength) { ChildNamesList childNames = new ChildNamesList(); int strCount = 0; List <string> fieldValueList = new List <string>(); //build field length strings foreach (string str in childNamesUnique) { if (fieldValueList.Count == 0) { strCount += str.Length; } else { strCount += str.Length + 3; //add 3 fro the " : " } if (strCount <= fieldLength) { fieldValueList.Add(str); } else { childNames.Add(COBieXBim.JoinStrings(':', fieldValueList)); strCount = str.Length; //reset strCount to the current value length fieldValueList.Clear(); fieldValueList.Add(str); } } if (fieldValueList.Count > 0) { childNames.Add(COBieXBim.JoinStrings(':', fieldValueList)); } return(childNames); }
/// <summary> /// Get the file information for the document attached to the ifcRelAssociatesDocument /// </summary> /// <param name="ifcRelAssociatesDocument">IfcRelAssociatesDocument object</param> /// <returns>FileInformation structure </returns> private FileInformation GetFileInformation(IfcRelAssociatesDocument ifcRelAssociatesDocument) { FileInformation DocInfo = new FileInformation() { Name = DEFAULT_STRING, Location = DEFAULT_STRING }; string value = ""; if (ifcRelAssociatesDocument != null) { //test for single document IfcDocumentReference ifcDocumentReference = ifcRelAssociatesDocument.RelatingDocument as IfcDocumentReference; if (ifcDocumentReference != null) { //this is possibly incorrect, think it references information within a document value = ifcDocumentReference.ItemReference.ToString(); if (!string.IsNullOrEmpty(value)) { DocInfo.Name = value; } value = ifcDocumentReference.Location.ToString(); if (!string.IsNullOrEmpty(value)) { DocInfo.Location = value; } } else //test for a document list { IfcDocumentInformation ifcDocumentInformation = ifcRelAssociatesDocument.RelatingDocument as IfcDocumentInformation; if (ifcDocumentInformation != null) { IEnumerable <IfcDocumentReference> ifcDocumentReferences = ifcDocumentInformation.DocumentReferences; if (ifcDocumentReferences != null) { List <string> strNameValues = new List <string>(); List <string> strLocationValues = new List <string>(); foreach (IfcDocumentReference docRef in ifcDocumentReferences) { //get file name value = docRef.ItemReference.ToString(); if (!string.IsNullOrEmpty(value)) { strNameValues.Add(value); } else { value = docRef.Name.ToString(); if (!string.IsNullOrEmpty(value)) { strNameValues.Add(value); } } //get file location value = docRef.Location.ToString(); if ((!string.IsNullOrEmpty(value)) && (!strNameValues.Contains(value))) { strLocationValues.Add(value); } } //set values to return if (strNameValues.Count > 0) { DocInfo.Name = COBieXBim.JoinStrings(':', strNameValues); } if (strLocationValues.Count > 0) { DocInfo.Location = COBieXBim.JoinStrings(':', strLocationValues); } } } } } return(DocInfo); }
/// <summary> /// Get the object IfcTypeObject name from the IfcTask object /// </summary> /// <param name="ifcTask">IfcTask object</param> /// <returns>string holding IfcTypeObject name</returns> private string GetObjectType(IfcTask ifcTask) { //first try IEnumerable <IfcTypeObject> ifcTypeObjects = ifcTask.OperatesOn.SelectMany(ratp => ratp.RelatedObjects.OfType <IfcTypeObject>()); //second try on IsDefinedBy.OfType<IfcRelDefinesByType> if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0)) { ifcTypeObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByType>().Select(idb => (idb as IfcRelDefinesByType).RelatingType); } //third try on IsDefinedBy.OfType<IfcRelDefinesByProperties> for DefinesType if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0)) { ifcTypeObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByProperties>().SelectMany(idb => (idb as IfcRelDefinesByProperties).RelatingPropertyDefinition.DefinesType); } //convert to string and return if all ok if ((ifcTypeObjects != null) || (ifcTypeObjects.Count() > 0)) { List <string> strList = new List <string>(); foreach (IfcTypeObject ifcTypeItem in ifcTypeObjects) { if ((ifcTypeItem != null) && (!string.IsNullOrEmpty(ifcTypeItem.Name.ToString()))) { if (!strList.Contains(ifcTypeItem.Name.ToString())) { strList.Add(ifcTypeItem.Name.ToString()); } } } return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING); } //last try on IsDefinedBy.OfType<IfcRelDefinesByProperties> for IfcObject if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0)) { IEnumerable <IfcObject> ifcObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByProperties>().SelectMany(idb => idb.RelatedObjects); List <string> strList = new List <string>(); foreach (IfcObject ifcObject in ifcObjects) { IEnumerable <IfcRelDefinesByType> ifcRelDefinesByTypes = ifcObject.IsDefinedBy.OfType <IfcRelDefinesByType>(); foreach (IfcRelDefinesByType ifcRelDefinesByType in ifcRelDefinesByTypes) { if ((ifcRelDefinesByType != null) && (ifcRelDefinesByType.RelatingType != null) && (!string.IsNullOrEmpty(ifcRelDefinesByType.RelatingType.Name.ToString())) ) { if (!strList.Contains(ifcRelDefinesByType.RelatingType.Name.ToString())) { strList.Add(ifcRelDefinesByType.RelatingType.Name.ToString()); } } } return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING); } return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING); } return(DEFAULT_STRING); //fail to get any types }
/// <summary> /// Fill sheet rows for Connection sheet /// </summary> /// <returns>COBieSheet</returns> public override COBieSheet <COBieConnectionRow> Fill() { ProgressIndicator.ReportMessage("Starting Connections..."); //Create new sheet COBieSheet <COBieConnectionRow> connections = new COBieSheet <COBieConnectionRow>(Constants.WORKSHEET_CONNECTION); // get all IfcRelConnectsElements objects from IFC file IEnumerable <IfcRelConnectsElements> ifcRelConnectsElements = Model.Instances.OfType <IfcRelConnectsElements>() .Where(rce => rce.RelatedElement != null && !Context.Exclude.ObjectType.Component.Contains(rce.RelatedElement.GetType()) && rce.RelatingElement != null && !Context.Exclude.ObjectType.Component.Contains(rce.RelatingElement.GetType()) ); //get ifcRelConnectsPorts only if we have ifcRelConnectsElements IEnumerable <IfcRelConnectsPorts> ifcRelConnectsPorts = Enumerable.Empty <IfcRelConnectsPorts>(); if (ifcRelConnectsElements.Count() > 0) { ifcRelConnectsPorts = Model.Instances.OfType <IfcRelConnectsPorts>(); } ProgressIndicator.Initialise("Creating Connections", ifcRelConnectsElements.Count()); int ids = 0; foreach (IfcRelConnectsElements ifcRelConnectsElement in ifcRelConnectsElements) { ProgressIndicator.IncrementAndUpdate(); IfcElement relatingElement = ifcRelConnectsElement.RelatingElement; IfcElement relatedElement = ifcRelConnectsElement.RelatedElement; COBieConnectionRow conn = new COBieConnectionRow(connections); //try and get the IfcRelConnectsPorts first for relatingElement then for relatedElement IEnumerable <IfcRelConnectsPorts> ifcRelConnectsPortsElement = ifcRelConnectsPorts.Where(rcp => (rcp.RealizingElement != null) && ((rcp.RealizingElement == relatingElement) || (rcp.RealizingElement == relatedElement))); string connectionName = ""; connectionName = (string.IsNullOrEmpty(ifcRelConnectsElement.Name)) ? "" : ifcRelConnectsElement.Name.ToString(); conn.CreatedBy = GetTelecomEmailAddress(ifcRelConnectsElement.OwnerHistory); conn.CreatedOn = GetCreatedOnDateAsFmtString(ifcRelConnectsElement.OwnerHistory); conn.ConnectionType = GetComponentDescription(ifcRelConnectsElement); conn.SheetName = GetSheetByObjectType(relatingElement.GetType()); conn.RowName1 = ((relatingElement != null) && (!string.IsNullOrEmpty(relatingElement.Name.ToString()))) ? relatingElement.Name.ToString() : DEFAULT_STRING; conn.RowName2 = ((relatedElement != null) && (!string.IsNullOrEmpty(relatedElement.Name.ToString()))) ? relatedElement.Name.ToString() : DEFAULT_STRING; //second attempt to get a name, if no IfcElement name then see if the associated type has a name //if (conn.RowName1 == DEFAULT_STRING) conn.RowName1 = GetTypeName(relatingElement); //if (conn.RowName2 == DEFAULT_STRING) conn.RowName2 = GetTypeName(relatedElement); //try and get IfcRelConnectsPorts by using relatingElement then relatedElement is the RelizingElement, but this is optional property, but the IfcRelConnectsPorts object document states //"Each of the port is being attached to the IfcElement by using the IfcRelConnectsPortToElement relationship" and the IfcRelConnectsPortToElement is a inverse reference to HasPorts //on the IfcElement, so if no IfcRelConnectsPorts found for either Element, then check the HasPosts property of each element. List <string> realizingElement = new List <string>(); List <string> relatedPort = new List <string>(); List <string> relatingPort = new List <string>(); foreach (IfcRelConnectsPorts port in ifcRelConnectsPortsElement) { if ((string.IsNullOrEmpty(connectionName)) && (string.IsNullOrEmpty(port.Name))) { connectionName = port.Name; } if ((port.RealizingElement != null) && (!string.IsNullOrEmpty(port.RealizingElement.ToString()))) //removed to allow export to xbim to keep sequence && (!realizingElement.Contains(port.RealizingElement.ToString())) { realizingElement.Add(port.RealizingElement.ToString()); } if ((port.RelatedPort != null) && (!string.IsNullOrEmpty(port.RelatedPort.Name.ToString()))) //removed to allow export to xbim to keep sequence && (!relatedPort.Contains(port.RelatedPort.Name.ToString())) { relatedPort.Add(port.RelatedPort.Name.ToString()); } if ((port.RelatingPort != null) && (!string.IsNullOrEmpty(port.RelatingPort.Name.ToString()))) //removed to allow export to xbim to keep sequence && (!relatingPort.Contains(port.RelatingPort.Name.ToString())) { relatingPort.Add(port.RelatingPort.Name.ToString()); } } conn.RealizingElement = (realizingElement.Count > 0) ? COBieXBim.JoinStrings(':', realizingElement) : DEFAULT_STRING; //no related port found so lets try and get from IfcElement.HasPorts if (relatedPort.Count == 0) { IEnumerable <IfcRelConnectsPortToElement> relatedPorts = relatedElement.HasPorts.Where(rcpe => rcpe.RelatingPort != null); foreach (IfcRelConnectsPortToElement port in relatedPorts) { if ((string.IsNullOrEmpty(connectionName)) && (string.IsNullOrEmpty(port.Name))) { connectionName = port.Name; } if ((port.RelatingPort != null) && (!string.IsNullOrEmpty(port.RelatingPort.Name.ToString())) && (!relatedPort.Contains(port.RelatingPort.Name.ToString()))) { relatedPort.Add(port.RelatingPort.Name.ToString()); } } } //no relating port found so lets try and get from IfcElement.HasPorts if (relatingPort.Count == 0) { IEnumerable <IfcRelConnectsPortToElement> relatingPorts = relatingElement.HasPorts.Where(rcpe => rcpe.RelatingPort != null); foreach (IfcRelConnectsPortToElement port in relatingPorts) { if ((string.IsNullOrEmpty(connectionName)) && (string.IsNullOrEmpty(port.Name))) { connectionName = port.Name; } if ((port.RelatingPort != null) && (!string.IsNullOrEmpty(port.RelatingPort.Name.ToString())) && (!relatedPort.Contains(port.RelatingPort.Name.ToString()))) { relatingPort.Add(port.RelatingPort.Name.ToString()); } } } conn.PortName1 = (relatingPort.Count > 0) ? COBieXBim.JoinStrings(':', relatingPort) : DEFAULT_STRING; conn.PortName2 = (relatedPort.Count > 0) ? COBieXBim.JoinStrings(':', relatedPort) : DEFAULT_STRING; conn.ExtSystem = GetExternalSystem(ifcRelConnectsElement); conn.ExtObject = ifcRelConnectsElement.GetType().Name; conn.ExtIdentifier = ifcRelConnectsElement.GlobalId; //if no ifcRelConnectsElement Name or Port names then revert to the index number conn.Name = (string.IsNullOrEmpty(connectionName)) ? ids.ToString() : connectionName; conn.Description = (string.IsNullOrEmpty(ifcRelConnectsElement.Description)) ? DEFAULT_STRING : ifcRelConnectsElement.Description.ToString(); connections.AddRow(conn); ids++; } connections.OrderBy(s => s.Name); ProgressIndicator.Finalise(); return(connections); }