public IfcColourRgb(IfcLabel?__Name, IfcNormalisedRatioMeasure __Red, IfcNormalisedRatioMeasure __Green, IfcNormalisedRatioMeasure __Blue) : base(__Name) { this.Red = __Red; this.Green = __Green; this.Blue = __Blue; }
/// <summary> /// Write the model to IFC. /// </summary> /// <param name="model"></param> /// <param name="path">The path to the generated IFC STEP file.</param> internal static void ToIFC(Model model, string path) { var ifc = new Document("Elements", "Elements", Environment.UserName, null, null, null, "Elements", null, null, null, null, null, null, null, null ); var proj = ifc.AllInstancesOfType <IfcProject>().FirstOrDefault(); // Add a site var site = new IfcSite(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Hypar Site", "The default site generated by Hypar", null, null, null, null, IfcElementCompositionEnum.ELEMENT, new IfcCompoundPlaneAngleMeasure(new List <int> { 0, 0 }), new IfcCompoundPlaneAngleMeasure(new List <int> { 0, 0 }), 0, null, null); var projAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), proj, new List <IfcObjectDefinition> { site }); // Add building and building storey var building = new IfcBuilding(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Default Building", "The default building generated by Hypar.", null, null, null, null, IfcElementCompositionEnum.ELEMENT, 0, 0, null); var storey = new IfcBuildingStorey(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Default Storey", "The default storey generated by Hypar", null, null, null, null, IfcElementCompositionEnum.ELEMENT, 0); var aggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), building, new List <IfcObjectDefinition> { storey }); // Aggregate the building into the site var siteAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), site, new List <IfcObjectDefinition> { building }); ifc.AddEntity(site); ifc.AddEntity(projAggregate); ifc.AddEntity(building); ifc.AddEntity(storey); ifc.AddEntity(aggregate); ifc.AddEntity(siteAggregate); var products = new List <IfcProduct>(); var context = ifc.AllInstancesOfType <IfcGeometricRepresentationContext>().FirstOrDefault(); // IfcRelAssociatesMaterial // IfcMaterialDefinitionRepresentation // https://forums.buildingsmart.org/t/where-and-how-will-my-colors-be-saved-in-ifc/1806/12 var styleAssignments = new Dictionary <Guid, List <IfcStyleAssignmentSelect> >(); var white = Colors.White.ToIfcColourRgb(); ifc.AddEntity(white); // TODO: Fix color support in all applications. // https://forums.buildingsmart.org/t/why-is-it-so-difficult-to-get-colors-to-show-up/2312/12 foreach (var m in model.AllElementsOfType <Material>()) { var material = new IfcMaterial(m.Name, null, "Hypar"); ifc.AddEntity(material); var color = m.Color.ToIfcColourRgb(); ifc.AddEntity(color); var transparency = new IfcNormalisedRatioMeasure(1.0 - m.Color.Alpha); var shading = new IfcSurfaceStyleShading(color, transparency); ifc.AddEntity(shading); var styles = new List <IfcSurfaceStyleElementSelect> { new IfcSurfaceStyleElementSelect(shading), }; var surfaceStyle = new IfcSurfaceStyle(material.Name, IfcSurfaceSide.BOTH, styles); ifc.AddEntity(surfaceStyle); var styleAssign = new IfcStyleAssignmentSelect(surfaceStyle); var assignments = new List <IfcStyleAssignmentSelect>() { styleAssign }; styleAssignments.Add(m.Id, assignments); } foreach (var e in model.Elements.Values.Where(e => { var t = e.GetType(); return(((e is GeometricElement && !((GeometricElement)e).IsElementDefinition) || e is ElementInstance) && t != typeof(ModelCurve) && t != typeof(ModelPoints) && t != typeof(AnalysisMesh)); })) { try { products.AddRange(e.ToIfcProducts(context, ifc, styleAssignments)); } catch (Exception ex) { Console.WriteLine($"There was an error writing an element of type {e.GetType()} to IFC: " + ex.Message); Console.WriteLine(ex.StackTrace); continue; } } var spatialRel = new IfcRelContainedInSpatialStructure(IfcGuid.ToIfcGuid(Guid.NewGuid()), products, storey); ifc.AddEntity(spatialRel); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, ifc.ToSTEP(path)); }