Example #1
0
        internal static void AttchOpening(this IfcSlab slab, IfcStore model, IfcOpeningElement opening)
        {
            IfcRelVoidsElement relVoids = model.Instances.New <IfcRelVoidsElement>();

            relVoids.RelatedOpeningElement   = opening;
            relVoids.RelatingBuildingElement = slab;
        }
        private static IfcSlab ToIfc(this Floor floor, Guid id,
                                     IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape)
        {
            var slab = new IfcSlab(IfcGuid.ToIfcGuid(id), null, null, null,
                                   null, localPlacement, shape, null, IfcSlabTypeEnum.FLOOR);

            return(slab);
        }
Example #3
0
        private IfcSlab CreateIfcLanding(IfcStore model, LinearPath landingPline, double landingThickness)
        {
            //begin a transaction
            using (var trans = model.BeginTransaction("Create Wall"))
            {
                IfcSlab landing = model.Instances.New <IfcSlab>();


                IfcDirection extrusionDir = model.Instances.New <IfcDirection>();
                extrusionDir.SetXYZ(0, 0, -1);

                //Create a Definition shape to hold the geometry of the Stair 3D body
                IfcShapeRepresentation shape = IFCHelper.ShapeRepresentationCreate(model, "SweptSolid", "Body");


                IfcArbitraryClosedProfileDef stepProfile = IFCHelper.ArbitraryClosedProfileCreate(model, (landingPline.Vertices /*.Select(v => v * 1000)*/).ToList());

                IfcExtrudedAreaSolid body = IFCHelper.ProfileSweptSolidCreate(model, landingThickness, stepProfile, extrusionDir);


                body.BodyPlacementSet(model, 0, 0, 0);

                shape.Items.Add(body);

                //Create a Product Definition and add the model geometry to the wall
                IfcProductDefinitionShape prDefShape = model.Instances.New <IfcProductDefinitionShape>();
                prDefShape.Representations.Add(shape);

                landing.Representation = prDefShape;

                //Create Local axes system and assign it to the column
                IfcCartesianPoint location3D = model.Instances.New <IfcCartesianPoint>();
                location3D.SetXYZ(0, 0, 0);

                //var uvColLongDir = MathHelper.UnitVectorPtFromPt1ToPt2(cadSlab.CenterPt, cadSlab.PtLengthDir);

                IfcDirection localXDir = model.Instances.New <IfcDirection>();
                localXDir.SetXYZ(1, 0, 0);

                IfcDirection localZDir = model.Instances.New <IfcDirection>();
                localZDir.SetXYZ(0, 0, 1);

                IfcAxis2Placement3D ax3D = IFCHelper.LocalAxesSystemCreate(model, location3D, localXDir, localZDir);

                //now place the slab into the model
                IfcLocalPlacement lp = IFCHelper.LocalPlacemetCreate(model, ax3D);
                landing.ObjectPlacement = lp;
                trans.Commit();
                return(landing);
            }
        }
Example #4
0
        /// <summary>
        /// Returns the Gross Footprint Area, if the element base quantity GrossFloorArea is defined
        /// </summary>
        /// <returns></returns>
        public static IfcAreaMeasure GrossFootprintArea(this IfcSlab slab)
        {
            IfcQuantityArea qArea = slab.GetQuantity <IfcQuantityArea>("BaseQuantities", "GrossFootprintArea");

            if (qArea == null)
            {
                qArea = slab.GetQuantity <IfcQuantityArea>("GrossFootprintArea");               //just look for any area
            }
            if (qArea == null)
            {
                qArea = slab.GetQuantity <IfcQuantityArea>("CrossArea");               //just look for any area if revit has done it
            }
            if (qArea != null)
            {
                return(qArea.AreaValue);
            }
            //try none schema defined properties

            return(null);
        }
Example #5
0
        private static Floor ToFloor(this IfcSlab slab, IEnumerable <IfcOpeningElement> openings)
        {
            var transform = new Transform();

            transform.Concatenate(slab.ObjectPlacement.ToTransform());

            // Check if the slab is contained in a building storey
            foreach (var cis in slab.ContainedInStructure)
            {
                transform.Concatenate(cis.RelatingStructure.ObjectPlacement.ToTransform());
            }

            var repItems = slab.Representation.Representations.SelectMany(r => r.Items);

            if (!repItems.Any())
            {
                throw new Exception("The provided IfcSlab does not have any representations.");
            }

            var solid = slab.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault();

            if (solid == null)
            {
                return(null);
                // throw new Exception("No IfcExtrudedAreaSolid could be found in the provided IfcSlab.");
            }

            var floorType = new FloorType($"{Guid.NewGuid().ToString()}_floor_type", new List <MaterialLayer> {
                new MaterialLayer(new Material("slab", Colors.Green), (IfcLengthMeasure)solid.Depth)
            });
            var outline        = (Polygon)solid.SweptArea.ToICurve();
            var solidTransform = solid.Position.ToTransform();
            var floor          = new Floor(new Profile(outline), solidTransform, solid.ExtrudedDirection.ToVector3(),
                                           floorType, 0, transform);

            floor.Name = slab.Name;

            return(floor);
        }
Example #6
0
        internal static Floor ToFloor(this IfcSlab slab, IEnumerable <IfcOpeningElement> openings)
        {
            var transform = new Transform();

            transform.Concatenate(slab.ObjectPlacement.ToTransform());
            // Console.WriteLine($"IfcSlab transform:\n{transform}\n");

            // Check if the slab is contained in a building storey
            foreach (var cis in slab.ContainedInStructure)
            {
                transform.Concatenate(cis.RelatingStructure.ObjectPlacement.ToTransform());
            }

            var repItems = slab.Representation.Representations.SelectMany(r => r.Items);

            if (!repItems.Any())
            {
                throw new Exception("The provided IfcSlab does not have any representations.");
            }

            var solid = slab.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault();

            if (solid == null)
            {
                return(null);
            }

            var outline        = (Polygon)solid.SweptArea.ToCurve();
            var solidTransform = solid.Position.ToTransform();

            solidTransform.Concatenate(transform);
            var floor = new Floor(new Profile(outline), (IfcLengthMeasure)solid.Depth,
                                  solidTransform, BuiltInMaterials.Concrete, null, false, IfcGuid.FromIfcGUID(slab.GlobalId));

            floor.Openings.AddRange(openings.Select(o => o.ToOpening()));

            return(floor);
        }
Example #7
0
        private IfcSlab CreateIfcSlopedSlab(IfcStore model, SlopedSlab cadSlab)
        {
            //for (int i = 0; i < cadSlab.LstFacePt.Count; i++)
            //{
            //    cadSlab.LstFacePt[i] *= 1000;
            //}
            //cadSlab.Thickness *= 1000;

            //begin a transaction
            using (ITransaction trans = model.BeginTransaction("Create Slab"))
            {
                IfcSlab slabToCreate = model.Instances.New <IfcSlab>();
                slabToCreate.Name = " Slab - Slab:UC305x305x97:" + random.Next(1000, 10000);

                //represent Element as a rectangular profile
                IfcArbitraryClosedProfileDef profile = IFCHelper.ArbitraryClosedProfileCreate(model, cadSlab.LstFacePt);

                //Profile insertion point


                //model as a swept area solid
                IfcDirection extrusionDir = model.Instances.New <IfcDirection>();
                extrusionDir.SetXYZ(0, 0, -1);

                IfcExtrudedAreaSolid body = IFCHelper.ProfileSweptSolidCreate(model, cadSlab.Thickness, profile, extrusionDir);


                //parameters to insert the geometry in the model
                body.BodyPlacementSet(model, 0, 0, 0);


                //Create a Definition shape to hold the geometry
                IfcShapeRepresentation shape = IFCHelper.ShapeRepresentationCreate(model, "SweptSolid", "Body");
                shape.Items.Add(body);



                //Create a Product Definition and add the model geometry to the wall
                IfcProductDefinitionShape prDefRep = model.Instances.New <IfcProductDefinitionShape>();
                prDefRep.Representations.Add(shape);
                slabToCreate.Representation = prDefRep;

                //Create Local axes system and assign it to the column
                IfcCartesianPoint location3D = model.Instances.New <IfcCartesianPoint>();
                location3D.SetXYZ(0, 0, 0);

                //var uvColLongDir = MathHelper.UnitVectorPtFromPt1ToPt2(cadSlab.CenterPt, cadSlab.PtLengthDir);

                IfcDirection localXDir = model.Instances.New <IfcDirection>();
                localXDir.SetXYZ(1, 0, 0);

                IfcDirection localZDir = model.Instances.New <IfcDirection>();
                localZDir.SetXYZ(0, 0, 1);

                IfcAxis2Placement3D ax3D = IFCHelper.LocalAxesSystemCreate(model, location3D, localXDir, localZDir);

                //now place the slab into the model
                IfcLocalPlacement lp = IFCHelper.LocalPlacemetCreate(model, ax3D);
                slabToCreate.ObjectPlacement = lp;


                trans.Commit();
                return(slabToCreate);
            }
        }
Example #8
0
        public XbimCreateBuilding(Building cadBuilding, string pathToSave)
        {
            using (var model = CreateandInitModel("Demo1"))
            {
                List <IFloor> lstSortedFloors = cadBuilding.Floors.OrderByDescending(f => f.Level).ToList();

                if (model != null)
                {
                    IfcBuilding building = CreateBuilding(model, "Default Building");

                    for (int i = 0; i < lstSortedFloors.Count; i++)
                    {
                        Floor floor = lstSortedFloors[i] as Floor;
                        if (floor != null)
                        {
                            if (i + 1 == lstSortedFloors.Count)
                            {
                                break;
                            }
                            double lvlDifference = lstSortedFloors[i].Level - lstSortedFloors[i + 1].Level;
                            double wallHeight    = lvlDifference - floor.Slabs[0].Thickness;
                            foreach (Wall cadWall in floor.Walls)
                            {
                                IfcWallStandardCase wall = CreateIfcWall(model, cadWall, wallHeight);

                                if (wall != null)
                                {
                                    AddPropertiesToWall(model, wall);
                                }
                                using (var txn = model.BeginTransaction("Add Wall"))
                                {
                                    building.AddElement(wall);
                                    txn.Commit();
                                }
                            }

                            foreach (RectColumn cadCol in floor.Columns)
                            {
                                IfcColumn column = CreateIfcColumn(model, cadCol, lvlDifference);

                                using (var txn = model.BeginTransaction("Add column"))
                                {
                                    building.AddElement(column);
                                    txn.Commit();
                                }
                            }

                            foreach (Slab cadSlab in floor.Slabs)
                            {
                                slab = CreateIfcSlab(model, cadSlab);
                                using (var trans = model.BeginTransaction("Add Slab"))
                                {
                                    building.AddElement(slab);
                                    trans.Commit();
                                }
                            }



                            IfcOpeningElement opening = null;
                            foreach (var cadOpening in floor.Openings)
                            {
                                opening = CreateIfcOpening(model, cadOpening, floor.Slabs[0].Thickness);
                                using (var trans = model.BeginTransaction("Add Opening"))
                                {
                                    building.AddElement(opening);
                                    //attach opening
                                    slab.AttchOpening(model, opening);
                                    trans.Commit();
                                }
                            }

                            //Create stairs
                            foreach (Stair cadStair in floor.Stairs)
                            {
                                IfcStair stair = CreateIfcStair(model, cadStair);

                                using (var txn = model.BeginTransaction("Add Stair"))
                                {
                                    building.AddElement(stair);
                                    txn.Commit();
                                }
                            }
                            foreach (LinearPath cadLanding in floor.Landings)
                            {
                                IfcSlab landing = CreateIfcLanding(model, cadLanding, DefaultValues.SlabThinkess);

                                using (var txn = model.BeginTransaction("Add Landing"))
                                {
                                    building.AddElement(landing);
                                    txn.Commit();
                                }
                            }
                        }
                        else
                        {
                            Foundation foundation = lstSortedFloors[i] as Foundation;
                            foreach (PCRectFooting cadFooting in foundation.PCFooting)
                            {
                                IfcFooting footing = CreateIfcFooting(model, cadFooting);

                                using (var txn = model.BeginTransaction("Add Footing"))
                                {
                                    building.AddElement(footing);
                                    txn.Commit();
                                }
                            }
                            foreach (RCRectFooting cadFooting in foundation.RCFooting)
                            {
                                IfcFooting footing = CreateIfcFooting(model, cadFooting);

                                using (var txn = model.BeginTransaction("Add Footing"))
                                {
                                    building.AddElement(footing);
                                    txn.Commit();
                                }
                            }
                            foreach (SlopedSlab cadRamp in foundation.Ramps)
                            {
                                IfcSlab ramp = CreateIfcSlopedSlab(model, cadRamp);

                                using (var txn = model.BeginTransaction("Add Ramp"))
                                {
                                    building.AddElement(ramp);
                                    txn.Commit();
                                }
                            }
                        }
                    }

                    try
                    {
                        Console.WriteLine("Standard Wall successfully created....");
                        //write the Ifc File
                        model.SaveAs(pathToSave + @"\Demo1.ifc", IfcStorageType.Ifc);
                        Console.WriteLine("WallIfc4.ifc has been successfully written");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to save!");
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }