public IXbimGeometryObject Create(IfcGeometricRepresentationItem ifcRepresentation, IfcAxis2Placement3D objectLocation) { try { return(_engine.Create(ifcRepresentation, objectLocation)); } catch (AccessViolationException e) { Logger.ErrorFormat("EE001: Failed to create geometry #{0} of type {1}, {2]", ifcRepresentation.EntityLabel, ifcRepresentation.GetType().Name, e.Message); return(null); } }
public IXbimGeometryObject Create(IfcGeometricRepresentationItem ifcRepresentation) { try { return _engine.Create(ifcRepresentation); } catch (AccessViolationException e) { Logger.ErrorFormat("EE001: Failed to create geometry #{0} of type {1}, {2]", ifcRepresentation.EntityLabel, ifcRepresentation.GetType().Name, e.Message); return null; } }
private static IfcProductDefinitionShape ToIfcProductDefinitionShape(this IfcGeometricRepresentationItem geom, IfcRepresentationContext context, Document doc) { var rep = new IfcShapeRepresentation(context, "Body", "SweptSolid", new List <IfcRepresentationItem> { geom }); var shape = new IfcProductDefinitionShape(new List <IfcRepresentation> { rep }); doc.AddEntity(rep); return(shape); }
public override void IfcParse(int propIndex, XbimExtensions.Interfaces.IPropertyValue value) { switch (propIndex) { case 0: _item = (IfcGeometricRepresentationItem)value.EntityVal; break; case 1: _textureCoordinates = (IfcTextureCoordinate)value.EntityVal; break; default: this.HandleUnexpectedAttribute(propIndex, value); break; } }
public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex) { switch (propIndex) { case 0: _item = (IfcGeometricRepresentationItem)(value.EntityVal); return; case 1: _textureCoordinates = (IfcTextureCoordinate)(value.EntityVal); return; default: throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper())); } }
public override void IfcParse(int propIndex, XbimExtensions.Interfaces.IPropertyValue value) { switch (propIndex) { case 0: _item = (IfcGeometricRepresentationItem)value.EntityVal; break; case 1: _textureCoordinates = (IfcTextureCoordinate)value.EntityVal; break; default: this.HandleUnexpectedAttribute(propIndex, value); break; } }
public static void SetSurfaceColor(IfcStore m, IfcGeometricRepresentationItem geoitem, double red, double green, double blue, double transparency = 0) { var styleditem = m.Instances.New <IfcStyledItem>(si => { si.Item = geoitem; si.Styles.Add(m.Instances.New <IfcSurfaceStyle>(ss => { ss.Side = IfcSurfaceSide.POSITIVE; ss.Styles.Add(m.Instances.New <IfcSurfaceStyleRendering>(ssha => { ssha.SurfaceColour = m.Instances.New <IfcColourRgb>(c => { c.Red = red; c.Green = green; c.Blue = blue; }); ssha.Transparency = transparency; })); })); }); }
private static IfcShapeRepresentation createShapeRepresentation(IfcStore model, IfcGeometricRepresentationItem item, RepresentationIdentifier identifier, RepresentationType type) { // //begin a transaction using (var txn = model.BeginTransaction("Create Shaperepresentation")) { //Create a Definition shape to hold the geometry var shape = model.Instances.New <IfcShapeRepresentation>(s => { s.ContextOfItems = model.Instances.OfType <IfcGeometricRepresentationContext>().FirstOrDefault(); s.RepresentationType = type.ToString(); s.RepresentationIdentifier = identifier.ToString(); s.Items.Add(item); }); txn.Commit(); return(shape); } }
public IfcAnnotationSurface(IfcGeometricRepresentationItem __Item, IfcTextureCoordinate __TextureCoordinates) { this._Item = __Item; this._TextureCoordinates = __TextureCoordinates; }
public IXbimGeometryObject Create(IfcGeometricRepresentationItem ifcRepresentation) { return(Create(ifcRepresentation, null)); }
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); }
internal static List <IfcProduct> ToIfcProducts(this Element e, IfcRepresentationContext context, Document doc, Dictionary <Guid, List <IfcStyleAssignmentSelect> > styleAssignments) { var products = new List <IfcProduct>(); IfcProductDefinitionShape shape = null; GeometricElement geoElement = null; Transform trans = null; Guid id; if (e is ElementInstance) { // If we're using an element instance, get the transform // and the id and use those to uniquely position and // identify the element. var instance = (ElementInstance)e; geoElement = instance.BaseDefinition; id = instance.Id; trans = instance.Transform; } else if (e is GeometricElement) { // If we've go a geometric element, use its properties as-is. geoElement = (GeometricElement)e; id = geoElement.Id; trans = geoElement.Transform; } geoElement.UpdateRepresentations(); var localPlacement = trans.ToIfcLocalPlacement(doc); doc.AddEntity(localPlacement); var geoms = new List <IfcRepresentationItem>(); if (geoElement is Topography) { var topo = (Topography)geoElement; var lengths = topo.Mesh.Vertices.Select(v => v.Position.ToArray().Select(vi => new IfcLengthMeasure(vi)).ToList()).ToList(); var pts = new IfcCartesianPointList3D(lengths); doc.AddEntity(pts); var indices = topo.Mesh.Triangles.Select(t => t.Vertices.Select(vx => new IfcPositiveInteger(vx.Index + 1)).ToList()).ToList(); var idxs = new List <List <IfcPositiveInteger> >(indices); var geom = new IfcTriangulatedFaceSet(pts, indices); geom.Closed = false; doc.AddEntity(geom); geoms.Add(geom); shape = ToIfcProductDefinitionShape(geoms, "Tessellation", context, doc); } else { foreach (var op in geoElement.Representation.SolidOperations) { IfcGeometricRepresentationItem geom = null; if (op is Sweep) { var sweep = (Sweep)op; geom = sweep.ToIfcSurfaceCurveSweptAreaSolid(doc); // geom = sweep.ToIfcFixedReferenceSweptAreaSolid(e.Transform, doc); } else if (op is Extrude) { var extrude = (Extrude)op; geom = extrude.ToIfcExtrudedAreaSolid(doc); } else if (op is Lamina) { var lamina = (Lamina)op; geom = lamina.ToIfcShellBasedSurfaceModel(doc); } else { throw new Exception("Only IExtrude, ISweepAlongCurve, and ILamina representations are currently supported."); } doc.AddEntity(geom); geoms.Add(geom); } shape = ToIfcProductDefinitionShape(geoms, "SolidModel", context, doc); } doc.AddEntity(shape); // Can we use IfcMappedItem? // https://forums.buildingsmart.org/t/can-tessellation-typed-representation-hold-items-from-another-group/1621 // var rep = new IfcShapeRepresentation(context, "Body", "Solids", geoms); // doc.AddEntity(rep); // var axisPt = Vector3.Origin.ToIfcCartesianPoint(); // doc.AddEntity(axisPt); // var axis = new IfcAxis2Placement2D(axisPt); // doc.AddEntity(axis); // var repMap = new IfcRepresentationMap(new IfcAxis2Placement(axis), rep); // doc.AddEntity(repMap); // var x = trans.XAxis.ToIfcDirection(); // var y = trans.YAxis.ToIfcDirection(); // var z = trans.ZAxis.ToIfcDirection(); // var origin = trans.Origin.ToIfcCartesianPoint(); // var cart = new IfcCartesianTransformationOperator3D(x, y, origin, trans.XAxis.Length(), z); // doc.AddEntity(x); // doc.AddEntity(y); // doc.AddEntity(z); // doc.AddEntity(origin); // doc.AddEntity(cart); // var mappedItem = new IfcMappedItem(repMap, cart); // doc.AddEntity(mappedItem); // var shapeRep= new IfcShapeRepresentation(context, new List<IfcRepresentationItem>(){mappedItem}); // doc.AddEntity(shapeRep); // shape = new IfcProductDefinitionShape(new List<IfcRepresentation>(){shapeRep}); // doc.AddEntity(shape); var product = ConvertElementToIfcProduct(id, geoElement, localPlacement, shape); products.Add(product); doc.AddEntity(product); var ifcOpenings = doc.AllEntities.Where(ent => ent.GetType() == typeof(IfcOpeningElement)).Cast <IfcOpeningElement>(); // If the element has openings, make opening relationships in // the IfcElement. if (e is IHasOpenings) { var openings = (IHasOpenings)e; if (openings.Openings.Count > 0) { foreach (var o in openings.Openings) { var element = (IfcElement)product; // TODO: Find the opening that we've already created that relates here var opening = ifcOpenings.First(ifcO => ifcO.GlobalId == IfcGuid.ToIfcGuid(o.Id)); var voidRel = new IfcRelVoidsElement(IfcGuid.ToIfcGuid(Guid.NewGuid()), element, opening); element.HasOpenings.Add(voidRel); doc.AddEntity(voidRel); } } } foreach (var geom in geoms) { var styledItem = new IfcStyledItem(geom, styleAssignments[geoElement.Material.Id], null); doc.AddEntity(styledItem); } return(products); }
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); }
private static List <IfcProduct> ToIfcProducts(this Element e, IfcRepresentationContext context, Document doc) { var products = new List <IfcProduct>(); if (e is IAggregateElements) { // TODO: Create the IFC aggregation relationship foreach (var subEl in ((IAggregateElements)e).Elements) { products.AddRange(subEl.ToIfcProducts(context, doc)); } return(products); } IfcProductDefinitionShape shape = null; var localPlacement = e.Transform.ToIfcLocalPlacement(doc); IfcGeometricRepresentationItem geom = null; if (e is ISweepAlongCurve) { var sweep = (ISweepAlongCurve)e; geom = sweep.ToIfcSurfaceCurveSweptAreaSolid(e.Transform, doc); } else if (e is IExtrude) { var extrude = (IExtrude)e; geom = extrude.ToIfcExtrudedAreaSolid(e.Transform, doc); } else if (e is ILamina) { var lamina = (ILamina)e; geom = lamina.ToIfcShellBasedSurfaceModel(e.Transform, doc); } else { throw new Exception("Only IExtrude, ISweepAlongCurve, and ILamina representations are currently supported."); } shape = ToIfcProductDefinitionShape(geom, context, doc); doc.AddEntity(shape); doc.AddEntity(localPlacement); doc.AddEntity(geom); var product = ConvertElementToIfcProduct(e, localPlacement, shape); products.Add(product); doc.AddEntity(product); // If the element has openings, // Make opening relationships in // the IfcElement. if (e is IHasOpenings) { var openings = (IHasOpenings)e; if (openings.Openings.Count > 0) { foreach (var o in openings.Openings) { var element = (IfcElement)product; var opening = o.ToIfcOpeningElement(context, doc, localPlacement); var voidRel = new IfcRelVoidsElement(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, element, opening); element.HasOpenings.Add(voidRel); doc.AddEntity(opening); doc.AddEntity(voidRel); } } } IfcStyledItem style = null; if (e is IMaterial) { var m = (IMaterial)e; style = m.Material.ToIfcStyledItem(geom, doc); } if (e is IElementType <StructuralFramingType> ) { var m = (IElementType <StructuralFramingType>)e; style = m.ElementType.Material.ToIfcStyledItem(geom, doc); } else if (e is IElementType <WallType> ) { var m = (IElementType <WallType>)e; style = m.ElementType.MaterialLayers[0].Material.ToIfcStyledItem(geom, doc); } else if (e is IElementType <FloorType> ) { var m = (IElementType <FloorType>)e; style = m.ElementType.MaterialLayers[0].Material.ToIfcStyledItem(geom, doc); } // Associate the style with the element style.Item = geom; geom.StyledByItem = new List <IfcStyledItem> { style }; doc.AddEntity(style); return(products); }
public IXbimGeometryObject Create(IfcGeometricRepresentationItem ifcRepresentation) { return Create(ifcRepresentation, null); }