private string HeaderAsString(IIfcFileHeader header) { StringBuilder headerStr = new StringBuilder(); headerStr.AppendLine("ISO-10303-21;"); headerStr.AppendLine("HEADER;"); //FILE_DESCRIPTION headerStr.Append("FILE_DESCRIPTION (("); int i = 0; if (header.FileDescription.Description.Count == 0) { headerStr.Append(@"''"); } else { foreach (string item in header.FileDescription.Description) { headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item)); i++; } } headerStr.AppendFormat(@"), '{0}');", header.FileDescription.ImplementationLevel); headerStr.AppendLine(); //FileName headerStr.Append("FILE_NAME ("); headerStr.AppendFormat(@"'{0}'", (header.FileName != null && header.FileName.Name != null)? IfcText.Escape(header.FileName.Name):""); headerStr.AppendFormat(@", '{0}'", header.FileName != null? header.FileName.TimeStamp:""); headerStr.Append(", ("); i = 0; if (header.FileName.AuthorName.Count == 0) { headerStr.Append(@"''"); } else { foreach (string item in header.FileName.AuthorName) { headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item)); i++; } } headerStr.Append("), ("); i = 0; if (header.FileName.Organization.Count == 0) { headerStr.Append(@"''"); } else { foreach (string item in header.FileName.Organization) { headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item)); i++; } } headerStr.AppendFormat(@"), '{0}', '{1}', '{2}');", IfcText.Escape(header.FileName.PreprocessorVersion), IfcText.Escape(header.FileName.OriginatingSystem), IfcText.Escape(header.FileName.AuthorizationName)); headerStr.AppendLine(); //FileSchema headerStr.AppendFormat("FILE_SCHEMA (('{0}'));", header.FileSchema.Schemas.FirstOrDefault()); headerStr.AppendLine(); headerStr.AppendLine("ENDSEC;"); headerStr.AppendLine("DATA;"); return(headerStr.ToString()); }
private List <IIfcObjectDefinition> PrintHierarchy(IIfcObjectDefinition Object, int level) { var Hierarchy = new List <IIfcObjectDefinition>(); //var TypeObjects = Model.Instances.Where<IIfcTypeObject>(s=>s.EntityLabel > 0); var Spaces = Model.Instances.Where <IIfcSpace>(s => s.EntityLabel > 0); var Zones = Model.Instances.Where <IIfcZone>(s => s.EntityLabel > 0); //var Doors = Model.Instances.Where<IIfcDoor>(s => s.EntityLabel > 0); //var Windows = Model.Instances.Where<IIfcWindow>(s => s.EntityLabel > 0); //var Walls = Model.Instances.Where<IIfcWall>(s => s.EntityLabel > 0); //var Roofs = Model.Instances.Where<IIfcRoof>(s => s.EntityLabel > 0); //var SlabTypes = Model.Instances.Where<IIfcSlabType>(s => s.EntityLabel > 0); IIfcValue DefaultNominalValue = new IfcText(""); foreach (IIfcSpace Space in Spaces) { Console.WriteLine($"Space: {Space.LongName} {Space.Name}"); Space.ObjectType = new IfcLabel(""); var Props = GetPropsForProduct(Space); foreach (IIfcPropertySingleValue Prop in Props) { if (Prop.NominalValue != null && Prop.NominalValue.Value != null) { Console.WriteLine($"{Prop.Name} {Prop.NominalValue.Value}"); } } } foreach (IIfcZone Zone in Zones) { Console.WriteLine($"Zone: {Zone.LongName} {Zone.Name}"); var Props = GetPropsForProduct(Zone); foreach (IIfcPropertySingleValue Prop in Props) { if (Prop.NominalValue != null && Prop.NominalValue.Value != null) { Console.WriteLine($"{Prop.Name} {Prop.NominalValue.Value}"); } } } IIfcElement Element = Object as IIfcElement; // If we're dealing with an element: Wall, Door, Window.. // Then we'll have a direct connection to the Spatial Structure that it's contained in if (Element != null) { var Relation = Element.ContainedInStructure.FirstOrDefault() as IIfcRelContainedInSpatialStructure; var RelatingStructure = Relation.RelatingStructure; Hierarchy.Add(RelatingStructure); Console.WriteLine(); } // Only spatial elements can contain building elements IIfcSpatialStructureElement SpatialElement = Object as IIfcSpatialStructureElement; if (SpatialElement != null) { //using IfcRelContainedInSpatialElement to get contained elements var ContainedElements = SpatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements); foreach (var ContainedElement in ContainedElements) { } } if (Object != null) { // ifcRelAggregates to get spatial decomposition of spatial structure elements IEnumerable <IIfcObjectDefinition> ifcRelAggregates = Object.IsDecomposedBy.SelectMany(r => r.RelatedObjects); if (ifcRelAggregates != null) { foreach (var SpatialStructure in ifcRelAggregates) { } } } return(Hierarchy); }
/// <summary> /// True if the string is empty or any white space /// </summary> /// <param name="label"></param> /// <returns></returns> public static bool IsEmpty(this IfcText label) { return(string.IsNullOrWhiteSpace(label)); }
/// <summary> /// Writes the value of a property to the TextWriter in the Part 21 format /// </summary> /// <param name="pInfoType"></param> /// <param name="pVal"></param> /// <param name="entityWriter"></param> private static void WriteValueType(Type pInfoType, object pVal, TextWriter entityWriter) { if (pInfoType == typeof(Double)) { entityWriter.Write(string.Format(new Part21Formatter(), "{0:R}", pVal)); } else if (pInfoType == typeof(String)) //convert string { if (pVal == null) { entityWriter.Write('$'); } else { entityWriter.Write('\''); entityWriter.Write(IfcText.Escape((string)pVal)); entityWriter.Write('\''); } } else if (pInfoType == typeof(Int16) || pInfoType == typeof(Int32) || pInfoType == typeof(Int64)) { entityWriter.Write(pVal.ToString()); } else if (pInfoType.IsEnum) //convert enum { entityWriter.Write(string.Format(".{0}.", pVal.ToString().ToUpper())); } else if (pInfoType == typeof(Boolean)) { bool b = false; if (pVal != null) { b = (bool)pVal; entityWriter.Write(string.Format(".{0}.", b ? "T" : "F")); } } else if (pInfoType == typeof(DateTime)) //convert TimeStamp { entityWriter.Write(string.Format(new Part21Formatter(), "{0:T}", pVal)); } else if (pInfoType == typeof(Guid)) //convert Guid string { if (pVal == null) { entityWriter.Write('$'); } else { entityWriter.Write(string.Format(new Part21Formatter(), "{0:G}", pVal)); } } else if (pInfoType == typeof(bool?)) //convert logical { bool?b = (bool?)pVal; entityWriter.Write(!b.HasValue ? ".U." : string.Format(".{0}.", b.Value ? "T" : "F")); } else { throw new ArgumentException(string.Format("Invalid Value Type {0}", pInfoType.Name), "pInfoType"); } }