static void Main(string[] args) { Console.WriteLine(" --- PointCloud 2 IfcBridge Model --- \n"); // --- Model Setup --- // create new Ifc4x2 Model var toolkit = new ModelSetupService(); var model = toolkit.CreateModel("PT2IFC_Prototype", "Esser", "Sebastian"); // create Site toolkit.CreateIfcSite(ref model, "SampleSite"); // create bridge toolkit.CreateIfcBridgeEntity(ref model, "PTBridge", "ToolChain PT > Enrichment > IFC4x2 Model"); // create Bridge Parts toolkit.CreateIfcBridgePartEntities(ref model); // get all files in the geometry folder var path = "geometryFiles/"; var files = System.IO.Directory.GetFiles(path, "*.off").ToList(); // init product service var productService = new ProductService(); foreach (var file in files) { Console.WriteLine("add new product: " + file); // load geometry var offGeom = new OffGeometry(file); // add product to model productService.AddBuildingElement(ref model, offGeom, file, "IfcBuildingElementProxy", "local", "Superstructure"); } Console.WriteLine("Save Model... \n"); // set time stamp in file name var date = DateTime.Now; var dateStr = date.ToString("yy-MM-dd", CultureInfo.CreateSpecificCulture("en-US")); var timeStr = date.ToString("hh-mm", CultureInfo.CreateSpecificCulture("de-DE")); var fileName = dateStr + "_" + timeStr + "_" + "PT2IFC_bridge_v01.ifc"; Console.WriteLine("Filename is: " + fileName); // save model model.SaveAs(fileName); // modify header toolkit.ModifyHeader(fileName); Console.WriteLine("Finished. Press button to exit. \n"); var input = Console.ReadKey(); }
/// <summary> /// Maps a given Off-Geometry into an IFC Representation /// </summary> /// <param name="model"></param> /// <param name="offGeometry"></param> /// <returns></returns> public static IfcProductDefinitionShape OffToIfc_TFS(ref IfcStore model, OffGeometry offGeometry) { var pointList = model.Instances.New <IfcCartesianPointList3D>(); int i = 0; // map off geom points into Ifc point list foreach (var vertex in offGeometry.Vertices) { pointList.CoordList.GetAt(i).AddRange(new IfcLengthMeasure[] { vertex.X, vertex.Y, vertex.Z }); i++; } // create TFS var tfs = model.Instances.New <IfcTriangulatedFaceSet>(fs => { fs.Closed = false; fs.Coordinates = pointList; }); // map off faces to IFC int j = 0; foreach (var face in offGeometry.Faces) { // var indices = face. var indices = face.VertexIds; tfs.CoordIndex.GetAt(j).AddRange(indices.Select(k => new IfcPositiveInteger(k))); j++; } // https://github.com/xBimTeam/XbimEssentials/issues/182 // https://github.com/xBimTeam/XbimEssentials/issues/70 // https://github.com/xBimTeam/XbimEssentials/issues/182 var ifcShapeRepresentation = model.Instances.New <IfcShapeRepresentation>(); var context = model.Instances.OfType <IfcGeometricRepresentationContext>().FirstOrDefault(); ifcShapeRepresentation.ContextOfItems = context; ifcShapeRepresentation.RepresentationIdentifier = "Tessellation"; ifcShapeRepresentation.RepresentationType = "Tessellation"; ifcShapeRepresentation.Items.Add(tfs); //Erstellt IfcProductDefinitionShape var ifcProductDefinitonShape = model.Instances.New <IfcProductDefinitionShape>(); ifcProductDefinitonShape.Representations.Add(ifcShapeRepresentation); return(ifcProductDefinitonShape); }
/// <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, OffGeometry 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, new IfcBridgeToolKit_DataLayer.GeometryConnector.Point3D(0, 0, 0)); 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.OffToIfc_TFS(ref model, rawGeometry); // add product to spatial structure AddToSpatialStructure(ref model, buildingElement, spatialStructure); txn.Commit(); } }