Пример #1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("No IIfc or xBim file specified");
                return;
            }
            var fileName = args[0];

            Console.WriteLine("Reading " + fileName);

            using (var model = GetModel(fileName))
            {
                if (model == null)
                {
                    Console.WriteLine("No model to process. Press any key to exit");
                    Console.Read();
                    return;
                }

                var context = new Xbim3DModelContext(model);
                context.CreateContext();
                var wexBimFilename = Path.ChangeExtension(fileName, "wexBIM");
                using (var wexBiMfile = new FileStream(wexBimFilename, FileMode.Create, FileAccess.Write))
                {
                    using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile))
                    {
                        Console.WriteLine("Creating " + wexBimFilename);
                        model.SaveAsWexBim(wexBimBinaryWriter);
                        wexBimBinaryWriter.Close();
                    }
                    wexBiMfile.Close();
                }
                //now do COBieExpress
                var cobie               = new MemoryModel(new EntityFactory());
                var cobieExpressFile    = Path.ChangeExtension(fileName, ".cobie");
                var cobieExpressXmlFile = Path.ChangeExtension(fileName, ".cobieXml");
                var cobieExpressZipFile = Path.ChangeExtension(fileName, ".cobieZip");
                var w = new Stopwatch();
                using (var txn = cobie.BeginTransaction("IFC data in"))
                {
                    var exchanger = new IfcToCoBieExpressExchanger(model, cobie);
                    w.Start();
                    exchanger.Convert();
                    w.Stop();
                    txn.Commit();
                }
                Console.WriteLine("COBieExpress model created in {0}ms", w.ElapsedMilliseconds);
                cobie.SaveAsStep21(File.Create(cobieExpressFile));
                cobie.SaveAsStep21Zip(File.Create(cobieExpressZipFile));
                cobie.SaveAsXml(File.Create(cobieExpressXmlFile), new XmlWriterSettings {
                    Indent = true, IndentChars = "\t"
                });


                //now do the DPoW files
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                var fileDirectoryName        = Path.GetDirectoryName(fileName);
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                var facilityNumber = 0;

                foreach (var facility in facilities)
                {
                    var dpow = "DPoW";
                    if (facilities.Count > 1)
                    {
                        dpow += ++facilityNumber;
                    }
                    // ReSharper disable AssignNullToNotNullAttribute
                    var dPoWFile = Path.Combine(fileDirectoryName, fileNameWithoutExtension + "_" + dpow);
                    // ReSharper restore AssignNullToNotNullAttribute
                    dPoWFile = Path.ChangeExtension(dPoWFile, "json");
                    Console.WriteLine("Creating " + dPoWFile);

                    facility.WriteJson(dPoWFile);
                    string cobieFile = Path.ChangeExtension(dPoWFile, "Xlsx");
                    Console.WriteLine("Creating " + cobieFile);
                    string error;
                    facility.WriteCobie(cobieFile, out error);
                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        Console.WriteLine("COBie Errors: " + error);
                    }

                    dPoWFile = Path.ChangeExtension(dPoWFile, "xml");
                    Console.WriteLine("Creating " + dPoWFile);
                    // facility.WriteXml(dPoWFile);
                    var req                 = Facility.ReadJson(@"..\..\Tests\ValidationFiles\Lakeside_Restaurant-stage6-COBie.json");
                    var validator           = new FacilityValidator();
                    var result              = validator.Validate(req, facility);
                    var verificationResults = Path.ChangeExtension(dPoWFile, "verified.xlsx");
                    Console.WriteLine("Creating " + verificationResults);
                    //create report
                    using (var stream = File.Create(verificationResults))
                    {
                        var report = new ExcelValidationReport();
                        report.Create(result, stream, ExcelValidationReport.SpreadSheetFormat.Xlsx);
                        stream.Close();
                    }

                    facility.ValidateUK2012(Console.Out, true);
                    string cobieValidatedFile = Path.ChangeExtension(dPoWFile, "Validated.Xlsx");
                    facility.WriteCobie(cobieValidatedFile, out error);
                    dPoWFile = Path.ChangeExtension(dPoWFile, "xbim");
                    var credentials = new XbimEditorCredentials()
                    {
                        ApplicationDevelopersName = "XbimTeam",
                        ApplicationFullName       = "Xbim.Exchanger",
                        EditorsOrganisationName   = "Xbim Development Team",
                        EditorsFamilyName         = "Xbim Tester",
                        ApplicationVersion        = "3.0"
                    };
                    Console.WriteLine("Creating " + dPoWFile);
                    using (
                        var ifcModel = IfcStore.Create(credentials, IfcSchemaVersion.Ifc2X3,
                                                       XbimStoreType.EsentDatabase))
                    {
                        using (var txn = ifcModel.BeginTransaction("Convert from COBieLiteUK"))
                        {
                            var coBieLiteUkToIIfcExchanger = new CoBieLiteUkToIfcExchanger(facility, ifcModel);
                            coBieLiteUkToIIfcExchanger.Convert();
                            txn.Commit();
                            //var err = model.Validate(model.Instances, Console.Out);
                        }
                        dPoWFile = Path.ChangeExtension(dPoWFile, "ifc");
                        Console.WriteLine("Creating " + dPoWFile);
                        ifcModel.SaveAs(dPoWFile, IfcStorageType.Ifc);
                        ifcModel.Close();
                    }
                }
                model.Close();
            }
            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Пример #2
0
        public void IfcPolygonalBoundedHalfspace_Test()
        {
            using (var m = new MemoryModel(new Ifc4.EntityFactoryIfc4()))
            {
                using (var txn = m.BeginTransaction(""))
                {
                    var polygonalBoundedHalfspace = m.Instances.New <IfcPolygonalBoundedHalfSpace>();
                    polygonalBoundedHalfspace.AgreementFlag = false;
                    var plane = m.Instances.New <IfcPlane>();
                    plane.Position          = m.Instances.New <IfcAxis2Placement3D>();
                    plane.Position.Location = m.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0));

                    polygonalBoundedHalfspace.BaseSurface = plane;
                    //create the polygonal bound
                    var polyLine = m.Instances.New <IfcPolyline>();
                    polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, 2.5)));
                    polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(5, 2.5)));
                    polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(5, -2.5)));
                    polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, -2.5)));
                    polyLine.Points.Add(m.Instances.New <IfcCartesianPoint>(c => c.SetXY(0, 2.5)));
                    polygonalBoundedHalfspace.PolygonalBoundary = polyLine;

                    var basePos = m.Instances.New <IfcAxis2Placement3D>();
                    basePos.Location = m.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0));
                    polygonalBoundedHalfspace.Position = basePos;
                    //make an extrusion
                    var profile        = IfcModelBuilder.MakeRectangleProfileDef(m, 20, 10);
                    var extrude        = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
                    var solid          = geomEngine.CreateSolid(extrude, logger);
                    var halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger);
                    var cut            = solid.Cut(halfSpaceSolid, 1e-5);

                    Assert.IsTrue(cut.Count > 0);
                    Assert.IsTrue(Math.Abs((solid.Volume) - cut.First.Volume - 1000) < 1e-5);

                    //reverse halfspace agreement
                    polygonalBoundedHalfspace.AgreementFlag = true;
                    halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger);
                    cut            = solid.Cut(halfSpaceSolid, 1e-5);
                    Assert.IsTrue(Math.Abs(solid.Volume - cut.First.Volume) < 1e-5);

                    //move the plane up
                    plane.Position.Location.Z = 20;
                    halfSpaceSolid            = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger);
                    cut = solid.Cut(halfSpaceSolid, 1e-5);
                    Assert.IsTrue(Math.Abs(solid.Volume - cut.First.Volume - 500) < 1e-5);

                    //some realistic data
                    polyLine.Points[0].SetXY(0, 0);
                    polyLine.Points[1].SetXY(0, 2850);
                    polyLine.Points[2].SetXY(-350, 2850);
                    polyLine.Points[3].SetXY(-350, 0);
                    polyLine.Points[4].SetXY(0, 0);
                    plane.Position.Location.SetXYZ(-5240.7742616303667, -33052.9790707385, 0.0);
                    plane.Position.Axis         = m.Instances.New <IfcDirection>(d => d.SetXYZ(0, -1, 0));
                    plane.Position.RefDirection = m.Instances.New <IfcDirection>(d => d.SetXYZ(1, 0, 0));
                    basePos.Location.SetXYZ(-5240.7742616303667, -33052.9790707385, 0);
                    basePos.Axis         = plane.Position.Axis;
                    basePos.RefDirection = plane.Position.RefDirection;

                    halfSpaceSolid = geomEngine.CreateSolid(polygonalBoundedHalfspace, logger);

                    profile.XDim = 350;
                    profile.YDim = 125;
                    profile.Position.Location.SetXY(-5415.7742616303676, -32932.529070738507);
                    extrude.Depth = 2850;
                    solid         = geomEngine.CreateSolid(extrude, logger);

                    cut = solid.Cut(halfSpaceSolid, 1e-5); //everything should be cut
                    Assert.IsTrue(cut.Count == 0);
                }
            }
        }