Пример #1
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall
        /// </summary>
        static int Main()
        {
            //first create and initialise a model called Hello Wall
            Console.WriteLine("Initialising the IFC Project....");
            using (var model = CreateandInitModel("HelloWall"))
            {
                if (model != null)
                {
                    IfcBuilding         building = CreateBuilding(model, "Default Building");
                    IfcBuildingStorey   storey   = CreateStorey(building);
                    IfcWallStandardCase wall     = CreateWall(model, 4000, 300, 2400);

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

                    if (wall != null)
                    {
                        try
                        {
                            Console.WriteLine("Standard Wall successfully created....");
                            //write the Ifc File
                            model.SaveAs("HelloWallIfc4.ifc", IfcStorageType.Ifc);
                            Console.WriteLine("HelloWallIfc4.ifc has been successfully written");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to save HelloWall.ifc");
                            Console.WriteLine(e.Message);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Failed to initialise the model");
                }
            }
            Console.WriteLine("Press any key to exit to view the IFC file....");
            Console.ReadKey();
            LaunchNotepad("HelloWallIfc4.ifc");
            return(0);
        }
Пример #2
0
        public ActionResult SubmitBlahBlah(List <int> axesIds, SubmissionStages subItem)
        {
            List <string>      files = Directory.GetFiles(FileStruc.CurrentVersion).ToList();
            List <IIfcProduct> Axes;

            List <IIfcProduct> lstProductSubmission;
            List <Line>        lstAxesLines = new List <Line>();
            string             ifcFile      = files.Where(a => Path.GetExtension(a) == ".ifc").FirstOrDefault();

            using (var model = IfcStore.Open(ifcFile))
            {
                Axes = model.Instances.OfType <IIfcProduct>().Where(b => axesIds.Contains(b.EntityLabel)).ToList();
                List <IIfcProduct> lstProduct = model.Instances.OfType <IIfcProduct>().Where(p => lstProductId.Contains(p.EntityLabel)).ToList();

                List <Line> lstLines = IFCHelper.AxesLinesGet(Axes);


                //Axes Boundaries
                LinearPath linPathSubmittal = MathHelper.LinPathAxesIntersection(lstLines);

                Dictionary <int, LinearPath> dicElement = IFCHelper.DicLinPathOfProductsGet(lstProduct);

                //get products within the axes boundary
                Dictionary <int, LinearPath> elementsWithinAxesBoundary = CadHelper.SubmittedElementsGet(linPathSubmittal, dicElement);

                //reinforcement IFC file
                using (IfcStore subModelRFT = IFCHelper.CreateandInitModel("Reinforcement File", model.Instances.OfType <IfcProject>().FirstOrDefault().UnitsInContext))
                {
                    IfcBuilding bldng = IFCHelper.CreateBuilding(subModelRFT, "bldngRFT", new Point3D(0, 0, 0));
                    using (var txn = subModelRFT.BeginTransaction("I"))
                    {
                        IfcBuildingStorey storey = subModelRFT.Instances.New <IfcBuildingStorey>();
                        bldng.AddToSpatialDecomposition(storey);
                        switch (subItem)
                        {
                        case SubmissionStages.FormWork:
                            for (int i = 0; i < elementsWithinAxesBoundary.Values.ToList().Count; i++)
                            {
                                IIfcProduct            product = lstProduct.FirstOrDefault(p => p.EntityLabel == elementsWithinAxesBoundary.Keys.ToList()[i]);
                                IIfcRepresentationItem repItem = product.Representation.Representations.First.Items.First;
                                double height = (repItem as IIfcExtrudedAreaSolid).Depth;

                                IfcOpeningElement open;
                                XbimCreateBuilding.CreateFormWork(subModelRFT, elementsWithinAxesBoundary.Values.ToList()[i], DefaultValues.FormWorkThickness,
                                                                  height, out open, "", false, false, false);
                            }
                            //switch (elemTypeFormwork)
                            //{
                            //    case ElementType.PCF:
                            //        break;
                            //    case ElementType.RCF:
                            //        break;
                            //    case ElementType.SEM:
                            //        break;
                            //    case ElementType.SHW:
                            //        break;
                            //    case ElementType.RTW:
                            //        break;
                            //    case ElementType.COL:
                            //        for (int i = 0; i < elementsWithinAxesBoundary.Values.ToList().Count; i++)
                            //        {
                            //            Column col = new Column(elementsWithinAxesBoundary.Values.ToList()[i]);
                            //            ReinforcedCadColumn rftCol = new ReinforcedCadColumn(col, 0);

                            //            IIfcProduct product = lstProduct.FirstOrDefault(p => p.EntityLabel == elementsWithinAxesBoundary.Keys.ToList()[i]);
                            //            IIfcRepresentationItem repItem = product.Representation.Representations.First.Items.First;
                            //            double height = (repItem as IIfcExtrudedAreaSolid).Depth;

                            //            IfcOpeningElement open;
                            //            XbimCreateBuilding.CreateFormWork(subModelRFT, rftCol.CadColumn.ColPath, DefaultValues.FormWorkThickness,
                            //                height, out open, false, false, false);

                            //        }
                            //        break;
                            //    case ElementType.SLB:
                            //        break;
                            //    default:
                            //        break;
                            //}

                            break;

                        case SubmissionStages.Concrete:
                            lstProductSubmission = lstProduct.Where(p => elementsWithinAxesBoundary.ContainsKey(p.EntityLabel)).ToList();
                            var map = new XbimInstanceHandleMap(model, subModelRFT);
                            for (int i = 0; i < lstProductSubmission.Count; i++)
                            {
                                IIfcProduct product = subModelRFT.InsertCopy(lstProductSubmission[i], map, null, false, false);
                                storey.AddElement(product as IfcProduct);
                            }
                            break;

                        case SubmissionStages.Reinforcement:
                            Enum.TryParse(ElementTypeSubmitted, out ElementType elemType);

                            switch (elemType)
                            {
                            case ElementType.PCF:
                                break;

                            case ElementType.RCF:
                                break;

                            case ElementType.SEM:
                                break;

                            case ElementType.SHW:
                                break;

                            case ElementType.RTW:
                                break;

                            case ElementType.COL:
                                for (int i = 0; i < elementsWithinAxesBoundary.Values.ToList().Count; i++)
                                {
                                    Column col = new Column(elementsWithinAxesBoundary.Values.ToList()[i]);
                                    ReinforcedCadColumn rftCol = new ReinforcedCadColumn(col, 0);

                                    IIfcProduct            product = lstProduct.FirstOrDefault(p => p.EntityLabel == elementsWithinAxesBoundary.Keys.ToList()[i]);
                                    IIfcRepresentationItem repItem = product.Representation.Representations.First.Items.First;
                                    double height = (repItem as IIfcExtrudedAreaSolid).Depth;

                                    XbimCreateBuilding.CreateColumnRft(rftCol, storey, subModelRFT, height, "");
                                }
                                break;

                            case ElementType.SLB:
                                break;

                            default:
                                break;
                            }
                            break;

                        default:
                            break;
                        }

                        txn.Commit();
                        subModelRFT.SaveAs(@"E:\01. Work\demo.ifc");
                        var context = new Xbim3DModelContext(subModelRFT);
                        context.CreateContext();

                        //var wexBimFilename = Path.ChangeExtension(, "wexBIM");
                        using (var wexBiMfile = System.IO.File.Create((@"E:\01. Work\demo.wexBIM")))
                        {
                            using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                            {
                                subModelRFT.SaveAsWexBim(wexBimBinaryWriter);
                                wexBimBinaryWriter.Close();
                            }
                            wexBiMfile.Close();
                        }
                    }
                }
            }

            return(new EmptyResult());
        }
Пример #3
0
        private static void CreateStorey(XbimModel model, IfcBuilding building, float levelHeight, List <List <IfcProduct> > productsLists)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create Storey"))
            {
                int floorNumber = 0;
                if (productsLists != null)
                {
                    foreach (List <IfcProduct> ProductsStorey in productsLists)
                    {
                        var storey = model.Instances.New <IfcBuildingStorey>();
                        storey.Name = "Level " + ++floorNumber;
                        storey.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                        storey.OwnerHistory.OwningApplication = model.DefaultOwningApplication;
                        storey.Elevation       = levelHeight;
                        storey.CompositionType = IfcElementCompositionEnum.ELEMENT;
                        //storey.GlobalId = new Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId();

                        storey.ObjectPlacement = model.Instances.New <IfcLocalPlacement>();
                        var localPlacement = storey.ObjectPlacement as IfcLocalPlacement;

                        if (localPlacement != null && localPlacement.RelativePlacement == null)
                        {
                            localPlacement.RelativePlacement = model.Instances.New <IfcAxis2Placement3D>();
                            var placement = localPlacement.RelativePlacement as IfcAxis2Placement3D;
                            placement.SetNewLocation(0.0, 0.0, floorNumber * levelHeight);
                        }


                        IfcRelContainedInSpatialStructure RelationSpatial = model.Instances.New <IfcRelContainedInSpatialStructure>();


                        foreach (IfcProduct item in ProductsStorey)
                        {
                            //storey.AddElement(item);
                            RelationSpatial.RelatedElements.Add(item);
                            ///=============================
                            //IfcRelContainedInSpatialStructure RelationSpatial = model.Instances.New<IfcRelContainedInSpatialStructure>();
                            //RelationSpatial.RelatedElements.Add(item);
                            //RelationSpatial.RelatingStructure = storey;
                        }

                        RelationSpatial.RelatingStructure = storey;

                        building.AddToSpatialDecomposition(storey);
                    }
                }

                //validate and commit changes
                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                }
                else
                {
                    using (StreamWriter str = new StreamWriter("E:\\storey " + floorNumber + " Errors"))
                    {
                        model.Validate(txn.Modified(), str);
                    }
                }
            }
        }