internal ObjectIfcProperties(IfcElement element) { bool readOnly = true; Add(new CustomProperty("GlobalId", element.GlobalId, typeof(string), true, true) { Group = "Element" }); Add(new CustomProperty("Name", element.Name, typeof(string), readOnly, true) { Group = "Element" }); Add(new CustomProperty("Description", element.Description, typeof(string), readOnly, true) { Group = "Element" }); Add(new CustomProperty("ObjectType", element.ObjectType, typeof(string), readOnly, true) { Group = "Element" }); Add(new CustomProperty("Type", element.GetType().Name, typeof(string), true, true) { Group = "Element" }); Add(new CustomProperty("Tag", element.Tag, typeof(string), readOnly, true) { Group = "Element" }); foreach (IfcPropertySet pset in element.IsDefinedBy.ToList().ConvertAll(x => x.RelatingPropertyDefinition).OfType <IfcPropertySet>()) { foreach (IfcPropertySingleValue psv in pset.HasProperties.Values.ToList().OfType <IfcPropertySingleValue>()) { IfcValue val = psv.NominalValue; if (val == null) { Add(new CustomProperty(psv.Name, "", typeof(string), readOnly, true) { Group = pset.Name }); } else { Object obj = val.Value; Add(new CustomProperty(psv.Name, obj, obj.GetType(), readOnly, true) { Group = pset.Name }); } } } }
internal ElementIfcProperties(IfcElement element) : base(element) { string keyword = element.KeyWord; bool readOnly = true; Add(new CustomProperty("ObjectType", element.ObjectType, typeof(string), readOnly, true) { Group = keyword }); Add(new CustomProperty("Type", element.GetType().Name, typeof(string), true, true) { Group = keyword }); Add(new CustomProperty("Tag", element.Tag, typeof(string), readOnly, true) { Group = keyword }); IfcElementType elementType = element.RelatingType as IfcElementType; if (elementType != null) { List.Add(new ElementTypeIfcProperties(elementType)); } foreach (IfcPropertySet pset in element.IsDefinedBy.ToList().ConvertAll(x => x.RelatingPropertyDefinition).OfType <IfcPropertySet>()) { foreach (IfcPropertySingleValue psv in pset.HasProperties.Values.ToList().OfType <IfcPropertySingleValue>()) { IfcValue val = psv.NominalValue; if (val == null) { Add(new CustomProperty(psv.Name, "", typeof(string), readOnly, true) { Group = pset.Name }); } else { Object obj = val.Value; Add(new CustomProperty(psv.Name, obj, obj.GetType(), readOnly, true) { Group = pset.Name }); } } } }
/// <summary> /// Fill sheet rows for Component sheet /// </summary> /// <returns>COBieSheet</returns> public override COBieSheet <COBieComponentRow> Fill() { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif ProgressIndicator.ReportMessage("Starting Components..."); //Create new sheet COBieSheet <COBieComponentRow> components = new COBieSheet <COBieComponentRow>(Constants.WORKSHEET_COMPONENT); IEnumerable <IfcRelAggregates> relAggregates = Model.FederatedInstances.OfType <IfcRelAggregates>(); IEnumerable <IfcRelContainedInSpatialStructure> relSpatial = Model.FederatedInstances.OfType <IfcRelContainedInSpatialStructure>(); IEnumerable <IfcObject> ifcElements = ((from x in relAggregates from y in x.RelatedObjects where !Context.Exclude.ObjectType.Component.Contains(y.GetType()) select y).Union(from x in relSpatial from y in x.RelatedElements where !Context.Exclude.ObjectType.Component.Contains(y.GetType()) select y)).OfType <IfcObject>(); //.GroupBy(el => el.Name).Select(g => g.First())//.Distinct().ToList(); COBieDataPropertySetValues allPropertyValues = new COBieDataPropertySetValues(); //properties helper class COBieDataAttributeBuilder attributeBuilder = new COBieDataAttributeBuilder(Context, allPropertyValues); attributeBuilder.InitialiseAttributes(ref _attributes); //set up filters on COBieDataPropertySetValues for the SetAttributes only attributeBuilder.ExcludeAttributePropertyNames.AddRange(Context.Exclude.Component.AttributesEqualTo); //we do not want listed properties for the attribute sheet so filter them out attributeBuilder.ExcludeAttributePropertyNamesWildcard.AddRange(Context.Exclude.Component.AttributesContain); //we do not want listed properties for the attribute sheet so filter them out attributeBuilder.RowParameters["Sheet"] = "Component"; ProgressIndicator.Initialise("Creating Components", ifcElements.Count()); foreach (var obj in ifcElements) { ProgressIndicator.IncrementAndUpdate(); COBieComponentRow component = new COBieComponentRow(components); IfcElement el = obj as IfcElement; if (el == null) { continue; } string name = el.Name.ToString(); if (string.IsNullOrEmpty(name)) { name = "Name Unknown " + UnknownCount.ToString(); UnknownCount++; } //set allPropertyValues to this element allPropertyValues.SetAllPropertyValues(el); //set the internal filtered IfcPropertySingleValues List in allPropertyValues component.Name = name; string createBy = allPropertyValues.GetPropertySingleValueValue("COBieCreatedBy", false); //support for COBie Toolkit for Autodesk Revit component.CreatedBy = ValidateString(createBy) ? createBy : GetTelecomEmailAddress(el.OwnerHistory); string createdOn = allPropertyValues.GetPropertySingleValueValue("COBieCreatedOn", false); //support for COBie Toolkit for Autodesk Revit component.CreatedOn = ValidateString(createdOn) ? createdOn : GetCreatedOnDateAsFmtString(el.OwnerHistory); component.TypeName = GetTypeName(el); component.Space = COBieHelpers.GetComponentRelatedSpace(el, Model, SpaceBoundingBoxInfo, Context); string description = allPropertyValues.GetPropertySingleValueValue("COBieDescription", false); //support for COBie Toolkit for Autodesk Revit component.Description = ValidateString(description) ? description : GetComponentDescription(el); string extSystem = allPropertyValues.GetPropertySingleValueValue("COBieExtSystem", false); //support for COBie Toolkit for Autodesk Revit component.ExtSystem = ValidateString(extSystem) ? extSystem : GetExternalSystem(el); component.ExtObject = el.GetType().Name; component.ExtIdentifier = el.GlobalId; //set from PropertySingleValues filtered via candidateProperties //set the internal filtered IfcPropertySingleValues List in allPropertyValues to this element set above component.SerialNumber = allPropertyValues.GetPropertySingleValueValue("SerialNumber", false); component.InstallationDate = GetDateFromProperty(allPropertyValues, "InstallationDate"); component.WarrantyStartDate = GetDateFromProperty(allPropertyValues, "WarrantyStartDate"); component.TagNumber = allPropertyValues.GetPropertySingleValueValue("TagNumber", false); component.BarCode = allPropertyValues.GetPropertySingleValueValue("BarCode", false); component.AssetIdentifier = allPropertyValues.GetPropertySingleValueValue("AssetIdentifier", false); components.AddRow(component); //fill in the attribute information attributeBuilder.RowParameters["Name"] = component.Name; attributeBuilder.RowParameters["CreatedBy"] = component.CreatedBy; attributeBuilder.RowParameters["CreatedOn"] = component.CreatedOn; attributeBuilder.RowParameters["ExtSystem"] = component.ExtSystem; attributeBuilder.PopulateAttributesRows(el); //fill attribute sheet rows } components.OrderBy(s => s.Name); ProgressIndicator.Finalise(); #if DEBUG timer.Stop(); Console.WriteLine("Time to generate Component data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3")); #endif return(components); }
/// <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); }
public IfcElementSignature(IfcElement elem, Xbim3DModelContext geometryContext) { XbimMatrix3D m3D = XbimMatrix3D.Identity; if (elem.ObjectPlacement != null) { m3D = elem.ObjectPlacement.ToMatrix3D(); } var geomManager = elem.ModelOf.GeometryManager; ShapeId = 0; //get the 3D shape var shapes = geometryContext.ShapeInstancesOf(elem); if (shapes.Any()) { XbimRect3D r3D = XbimRect3D.Empty; foreach (var shape in shapes) { if (r3D.IsEmpty) { r3D = shape.BoundingBox; } else { r3D.Union(shape.BoundingBox); } } XbimPoint3D p3D = r3D.Centroid(); p3D = m3D.Transform(p3D); BoundingSphereRadius = r3D.Length() / 2; CentroidX = p3D.X; CentroidY = p3D.Y; CentroidZ = p3D.Z; } //get the defining type IfcTypeObject ot = elem.GetDefiningType(); IfcMaterialSelect material = elem.GetMaterial(); //sort out property definitions List <IfcPropertySet> psets = elem.GetAllPropertySets(); PropertyCount = psets.SelectMany(p => p.HasProperties).Count(); psets.Sort(new PropertySetNameComparer()); foreach (var pset in psets) { PropertySetNamesKey ^= pset.Name.GetHashCode(); } List <IfcPropertySingleValue> props = psets.SelectMany(p => p.HasProperties).OfType <IfcPropertySingleValue>().ToList(); props.Sort(new PropertySingleValueNameComparer()); foreach (var prop in props) { PropertyNamesKey ^= prop.Name.GetHashCode(); } props.Sort(new PropertySingleValueValueComparer()); foreach (var prop in props) { PropertyValuesKey ^= prop.NominalValue.GetHashCode(); } ModelID = elem.EntityLabel; SchemaType = elem.GetType().Name; DefinedTypeId = (ot == null ? "" : ot.GlobalId.ToPart21); GlobalId = elem.GlobalId; OwningUser = elem.OwnerHistory.LastModifyingUser != null?elem.OwnerHistory.LastModifyingUser.ToString() : elem.OwnerHistory.OwningUser.ToString(); Name = elem.Name ?? ""; Description = elem.Description ?? ""; HasAssignmentsKey = elem.HasAssignments.Count(); IsDecomposedByKey = elem.IsDecomposedBy.Count(); DecomposesKey = elem.Decomposes.Count(); HasAssociationsKey = elem.HasAssociations.Count(); ObjectType = elem.ObjectType ?? ""; MaterialName = material == null ? "" : material.Name; ReferencedByKey = elem.ReferencedBy.Count(); Tag = elem.Tag ?? ""; HasStructuralMemberKey = elem.HasStructuralMember.Count(); FillsVoidsKey = elem.FillsVoids.Count(); ConnectedToKey = elem.ConnectedTo.Count(); HasCoveringsKey = elem.HasCoverings.Count(); HasProjectionsKey = elem.HasProjections.Count(); ReferencedInStructuresKey = elem.ReferencedInStructures.Count(); HasPortsKey = elem.HasPorts.Count(); HasOpeningsKey = elem.HasOpenings.Count(); IsConnectionRealizationKey = elem.IsConnectionRealization.Count(); ProvidesBoundariesKey = elem.ProvidesBoundaries.Count(); ConnectedFromKey = elem.ConnectedFrom.Count(); ContainedInStructureKey = elem.ContainedInStructure.Count(); }