internal override void ParseXml(XmlElement xml) { base.ParseXml(xml); foreach (XmlNode child in xml.ChildNodes) { string name = child.Name; if (string.Compare(name, "Item") == 0) { Item = mDatabase.ParseXml <IfcRepresentationItem>(child as XmlElement); } else if (string.Compare(name, "Styles") == 0) { foreach (XmlNode cn in child.ChildNodes) { IfcStyleAssignmentSelect s = mDatabase.ParseXml <IfcStyleAssignmentSelect>(cn as XmlElement); if (s != null) { addStyle(s); } } } } if (xml.HasAttribute("Name")) { Name = xml.Attributes["Name"].Value; } }
/// <summary> /// Write the model to IFC. /// </summary> /// <param name="model"></param> /// <param name="path">The path to the generated IFC STEP file.</param> public static void ToIFC(this 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, 0 }), new IfcCompoundPlaneAngleMeasure(new List <int> { 0, 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)); }
public static IfcShapeRepresentation NewIfc4RepresentationItem(this IModel s, IfcProduct product, IfcGeometricRepresentationItem geometryItem, IfcStyleAssignmentSelect style) { if (null != style) { s.Instances.New <IfcStyledItem>(i => { i.Item = geometryItem; i.Styles.Add(style); }); } var shapeRepresentation = s.NewIfc4ShapeRepresentation(product); shapeRepresentation.Items.Add(geometryItem); return(shapeRepresentation); }
public IfcShapeRepresentation NewGeometricRepresentation(IfcProduct product, IfcGeometricRepresentationItem representationItem, IfcStyleAssignmentSelect style = null, string representationContext = "Model", string representationContextId = "Body") { if (Store != product.Model || Store != representationItem.Model) { throw new ArgumentException("Model mismatch"); } IfcShapeRepresentation shapeRepresentation = null; Wrap(s => { var productDefinitionShape = product.Representation; if (null == productDefinitionShape) { productDefinitionShape = s.Instances.New <IfcProductDefinitionShape>(); } if (null != style) { s.Instances.New <IfcStyledItem>(i => { i.Item = representationItem; i.Styles.Add(style); }); } product.Representation = productDefinitionShape; shapeRepresentation = s.Instances.New <IfcShapeRepresentation>(); productDefinitionShape.Representations.Add(shapeRepresentation); var project = Scopes.OfType <IfcProject>().FirstOrDefault(); var contexts = project .RepresentationContexts .Where <IfcGeometricRepresentationContext>(c => c.ContextType == representationContext); IfcGeometricRepresentationContext context = null; if (contexts.Count() > 1) { context = contexts.Where(c => c.ContextIdentifier == representationContextId).FirstOrDefault(); } else { context = contexts.FirstOrDefault(); } if (null == context) { context = Store.NewIfc4GeometricContext(representationContextId, representationContext); } shapeRepresentation.ContextOfItems = context; shapeRepresentation.Items.Add(representationItem); }); return(shapeRepresentation); }
public IfcStyledItem(IfcStyleAssignmentSelect style, string name) : base(style.Database) { Name = name; mStyles.Add(style.Index); }