/// <summary>
        ///     converts direct shape representation into transporter container
        /// </summary>
        /// <param name="element"></param>
        /// <param name="transporter"></param>
        private static void InsertShape(Element element, ref DirectShapeToIfc transporter)
        {
            // every directShape consists of several faces. Each face has several corner points that are connected by a polyline
            foreach (var face in element.Faces)
            {
                var transporterFacet =
                    new Facet(); // face in IfcToolKit understanding, contains several boundaryPoints

                // error safety
                if (face == null)
                {
                    continue;
                }

                // convert each vertexPt from Revit into an Pt3D of IfcToolKit definition
                foreach (var revitVertex in face.Vertices)
                {
                    var pt3D = new Point3D(
                        revitVertex.PointGeometry.X,
                        revitVertex.PointGeometry.Y,
                        revitVertex.PointGeometry.Z
                        );
                    // add point to current face
                    transporterFacet.vertices.Add(pt3D);
                }

                // add face to transporter (remember: one shape has several faces
                transporter.Facets.Add(transporterFacet);
            }
        }
        /// <summary>
        /// Converts a DirectShapeMesh from Revit into an IfcFacetedBRep Entity
        /// </summary>
        /// <param name="model"></param>
        /// <param name="name"></param>
        /// <param name="ifcCartesianPoints"></param>
        /// <returns></returns>
        public static IfcProductDefinitionShape ConvertMyMeshToIfcFacetedBRep(ref IfcStore model, string name,
                                                                              DirectShapeToIfc ifcCartesianPoints)
        {
            var ifcFacetedBRep = model.Instances.New <IfcFacetedBrep>();
            var ifcClosedShell = model.Instances.New <IfcClosedShell>();

            ifcFacetedBRep.Outer = ifcClosedShell;

            foreach (var Point in ifcCartesianPoints.Facets)
            {
                var polyloop = model.Instances.New <IfcPolyLoop>();

                var pts = Point.vertices.ToList();

                // Übergibt Eckpunkte in den Polyloob
                foreach (var pt in pts)
                {
                    var ifcCartesianPoint = model.Instances.New <IfcCartesianPoint>(iCP =>
                    {
                        iCP.X = pt.X;
                        iCP.Y = pt.Y;
                        iCP.Z = pt.Z;
                    });
                    polyloop.Polygon.Add(ifcCartesianPoint);
                }

                var ifcFaceOuterBound = model.Instances.New <IfcFaceOuterBound>(iFOB => iFOB.Bound = polyloop);

                var ifcFace = model.Instances.New <IfcFace>(iF => iF.Bounds.Add(ifcFaceOuterBound));
                //var ifcClosedShell = model.Instances.New<IfcClosedShell>();
                ifcClosedShell.CfsFaces.Add(ifcFace);
                //ifcFacetedBRep.Outer = ifcClosedShell;

                ifcFacetedBRep.Outer = ifcClosedShell;
            }

            var ifcShapeRepresentation = model.Instances.New <IfcShapeRepresentation>();
            var context = model.Instances.OfType <IfcGeometricRepresentationContext>().FirstOrDefault();

            ifcShapeRepresentation.ContextOfItems           = context;
            ifcShapeRepresentation.RepresentationIdentifier = "Body";
            ifcShapeRepresentation.RepresentationType       = "Brep";
            ifcShapeRepresentation.Items.Add(ifcFacetedBRep);

            //Erstellt IfcProductDefinitionShape
            var ifcProductDefinitonShape = model.Instances.New <IfcProductDefinitionShape>();

            ifcProductDefinitonShape.Name = name;
            ifcProductDefinitonShape.Representations.Add(ifcShapeRepresentation);

            //  return ProductDefinitionShape
            return(ifcProductDefinitonShape);
        }
        public static Dictionary <string, object> AddDirectShapeComponents(
            IfcStore model,
            XbimEditorCredentials credentials,
            List <Element> elements,
            string ifcElementType,
            string ifcSpatialStructure)
        {
            var counter = 0;

            // Note: no transaction is required -> will be opened in the toolkit function
            foreach (var element in elements)
            {
                // init transporter for each element geometry
                var transporter = new DirectShapeToIfc();

                // --- add geometry to transporter ---
                InsertShape(element, ref transporter);

                // --- add placement to transporter ---
                var location = element.Solids?.FirstOrDefault()?.Centroid();
                if (location != null)
                {
                    transporter.location.Position = new Point3D(location.X, location.Y, location.Z); // insert Revit coordinates into transporter
                }
                else
                {
                    transporter.location.Position = new Point3D(0, 0, 0);
                }

                // use IfcBridgeToolKit to generate a new IfcBuildingElement instance in the current model
                var productService = new ProductService();
                productService.AddBuildingElement(
                    ref model,                               // the Ifc Model
                    transporter,                             // the container for all geometry-related content
                    "BuildingElement " + counter.ToString(), // the bldElement's name
                    ifcElementType,                          // desired IfcBuildingElement subclass
                    "local",                                 // placement method
                    ifcSpatialStructure);                    // spatial structure element the component should belong to


                // increase counter
                counter++;
            }
            //  return model;
            return(new Dictionary <string, object>
            {
                { "IfcModel", model }
            });
        }
Exemple #4
0
        /// <summary>
        /// Adds a product to the IFC file
        /// </summary>
        /// <param name="model">current XBIM model, must not be in running transaction</param>
        /// <param name="rawGeometry">product geometry</param>
        /// <param name="name">name of product</param>
        /// <param name="ifcElementType">desired Ifc class (choose one out of IfcBuildingElement</param>
        /// <param name="placementType">either "local", "linear" or "span"</param>
        /// <param name="spatialStructure">choose spatial container the product should be added to</param>
        public void AddBuildingElement(ref IfcStore model, DirectShapeToIfc rawGeometry, string name, string ifcElementType, string placementType, string spatialStructure)
        {
            // handle null inputs
            if (placementType == null)
            {
                placementType = "localPlacement";
            }


            // other services needed for this method:
            var placementService = new PlacementService();

            using (var txn = model.BeginTransaction("insert a product"))
            {
                IfcBuildingElement buildingElement;

                switch (ifcElementType) // ToDo: make use of enum
                {
                case "IfcBeam":
                {
                    buildingElement = model.Instances.New <IfcBeam>();
                    break;
                }

                case "IfcBearing":
                {
                    buildingElement = model.Instances.New <IfcBearing>();
                    break;
                }

                case "IfcChimney":
                {
                    buildingElement = model.Instances.New <IfcChimney>();
                    break;
                }

                case "IfcColumn":
                {
                    // call the bearing function in the toolkit
                    buildingElement = model.Instances.New <IfcColumn>();
                    break;
                }

                case "IfcCovering":
                {
                    // call the bearing function in the toolkit
                    buildingElement = model.Instances.New <IfcCovering>();
                    break;
                }

                case "IfcCurtainWall":
                {
                    // call the bearing function in the toolkit
                    buildingElement = model.Instances.New <IfcCurtainWall>();
                    break;
                }

                case "IfcDeepFoundation":
                {
                    buildingElement = model.Instances.New <IfcDeepFoundation>();
                    break;
                }

                case "IfcDoor":
                {
                    buildingElement = model.Instances.New <IfcDoor>();
                    break;
                }

                case "IfcFooting":
                {
                    buildingElement = model.Instances.New <IfcFooting>();
                    break;
                }

                case "IfcMember":
                {
                    buildingElement = model.Instances.New <IfcMember>();
                    break;
                }

                case "IfcPlate":
                {
                    buildingElement = model.Instances.New <IfcPlate>();
                    break;
                }

                case "IfcRailing":
                {
                    buildingElement = model.Instances.New <IfcRailing>();
                    break;
                }

                case "IfcRamp":
                {
                    buildingElement = model.Instances.New <IfcRamp>();
                    break;
                }

                case "IfcRampFlight":
                {
                    buildingElement = model.Instances.New <IfcRampFlight>();
                    break;
                }

                case "IfcRoof":
                {
                    buildingElement = model.Instances.New <IfcRoof>();
                    break;
                }

                case "IfcShadingDevice":
                {
                    buildingElement = model.Instances.New <IfcShadingDevice>();
                    break;
                }

                case "IfcSlab":
                {
                    buildingElement = model.Instances.New <IfcSlab>();
                    break;
                }

                case "IfcStair":
                {
                    buildingElement = model.Instances.New <IfcStair>();
                    break;
                }

                case "IfcWall":
                {
                    buildingElement = model.Instances.New <IfcWall>();
                    break;
                }

                case "IfcWindow":
                {
                    buildingElement = model.Instances.New <IfcWindow>();
                    break;
                }

                // if nothing fits, make an IfcBuildingElementProxy out of it
                default:
                    buildingElement = model.Instances.New <IfcBuildingElementProxy>();
                    break;
                }

                // fill name property
                buildingElement.Name = name;

                // add product placement (localPlacement or linearPlacement - Span is not supported by Ifc 4x2!)
                switch (placementType)
                {
                case "local":
                    buildingElement.ObjectPlacement = placementService.AddLocalPlacement(ref model, rawGeometry.location.Position);
                    break;

                case "linear":
                {
                    buildingElement.ObjectPlacement = placementService.AddLinearPlacement(ref model, null, 0);
                    break;
                }

                case "span":
                {
                    var e = new Exception("Span placement was not introduced by IfcBridge!");
                    throw e;
                }

                default:
                {
                    var e = new Exception("Placement method was not specified correctly .");
                    throw e;
                }
                }

                // add product representation
                buildingElement.Representation = ProdGeometryService.ConvertMyMeshToIfcFacetedBRep(ref model, "representation", rawGeometry);

                // add product to spatial structure
                AddToSpatialStructure(ref model, buildingElement, spatialStructure);

                txn.Commit();
            }
        }