コード例 #1
0
        public void ExtrudedCircularProfilesTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\15 - Swept pipes.ifc", null, null, true, true);
                    foreach (
                        var cp in
                            m.Instances.OfType<IfcExtrudedAreaSolid>().Where(e => e.SweptArea is IfcCircleProfileDef))
                    {
                        Assert.IsTrue(cp != null, "No Extruded Solid found");
                        Assert.IsTrue(cp.SweptArea is IfcCircleProfileDef, "Incorrect profiledef found");

                        var solid = xbimGeometryCreator.CreateSolid(cp);
                        Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                        IfcCsgTests.GeneralTest(solid);

                    }

                    //Assert.IsTrue(solid.Faces.Count() == 10, "T Shaped profiles should have 10 faces");
                }
            }
        }
コード例 #2
0
 public void ConvertCoBieLiteToJson()
 {
     using (var m = new XbimModel())
     {
         var IfcTestFile = "2012-03-23-Duplex-Handover.ifc";
         //IfcTestFile = @"D:\Users\steve\My Documents\DPoW\001 NBS Lakeside Restaurant 2014.ifc";
         var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim");
         var JsonFile = Path.ChangeExtension(IfcTestFile, "json");
         m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true);
         var helper = new CoBieLiteHelper(m,"UniClass");
         var facilities = helper.GetFacilities();
         foreach (var facilityType in facilities)
         {
             Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified);
             using (var fs = new StreamWriter(JsonFile))
             {
                 CoBieLiteHelper.WriteJson(fs, facilityType);
                 fs.Close();
             }
             
         }
     }
 }
コード例 #3
0
        private static XbimModel ParseModelFile(string inFileName, string xbimFileName, bool caching)
        {
            XbimModel model = new XbimModel();

            //create a callback for progress
            switch (Path.GetExtension(inFileName).ToLowerInvariant())
            {
            case ".ifc":
            case ".ifczip":
            case ".ifcxml":
                model.CreateFrom(
                    inFileName,
                    xbimFileName,
                    delegate(int percentProgress, object userState)
                {
                    if (!arguments.IsQuiet)
                    {
                        Console.Write(string.Format("{0:D2}% Parsed", percentProgress));
                        ResetCursor(Console.CursorTop);
                    }
                }, true, caching
                    );
                break;

            case ".xbim":

                model = new XbimModel();
                break;

            default:
                throw new NotImplementedException(String.Format("XbimConvert does not support {0} file formats currently", Path.GetExtension(inFileName)));
            }

            return(model);
        }
コード例 #4
0
        //private void Add_Click(object sender, RoutedEventArgs e)
        //{
        //    XbimModel model = DataContext as XbimModel;
        //    if (model != null)
        //    {
        //        AddFederatedModel fdlg = new AddFederatedModel();
        //        bool? done = fdlg.ShowDialog();
        //        if (done.HasValue && done.Value == true)
        //        {
        //            string fileName = fdlg.FileName;
        //            string ext = System.IO.Path.GetExtension(fileName);
        //            using (XbimModel refM = new XbimModel())
        //            {
        //                if (string.Compare(ext, ".xbim", true) != 0)
        //                {
        //                    refM.CreateFrom(fileName, null, null, true);
        //                    XbimMesher.GenerateGeometry(refM);
        //                    fileName = System.IO.Path.ChangeExtension(fileName, "xbim");
        //                }
        //            }
        //            IfcRole role = fdlg.Role;
        //            if (role == IfcRole.UserDefined)
        //                model.AddModelReference(fileName, fdlg.OrganisationName, fdlg.RoleName);
        //            else
        //                model.AddModelReference(fileName, fdlg.OrganisationName, role);
        //        }
        //    }
        //}


        private void Add_Click(object sender, RoutedEventArgs e)
        {
            XbimModel model = DataContext as XbimModel;

            if (model != null)
            {
                AddFederatedModel fdlg = new AddFederatedModel();
                bool?done = fdlg.ShowDialog();
                if (done.HasValue && done.Value == true)
                {
                    string fileName = fdlg.FileName;
                    string ext      = System.IO.Path.GetExtension(fileName);
                    using (XbimModel refM = new XbimModel())
                    {
                        if (string.Compare(ext, ".xbim", true) != 0)
                        {
                            refM.CreateFrom(fileName, null, null, true);
                            var m3D = new Xbim3DModelContext(refM);
                            m3D.CreateContext();
                            fileName = System.IO.Path.ChangeExtension(fileName, "xbim");
                        }
                    }
                    IfcRole role = fdlg.Role;
                    if (role == IfcRole.UserDefined)
                    {
                        model.AddModelReference(fileName, fdlg.OrganisationName, fdlg.RoleName);
                    }
                    else
                    {
                        model.AddModelReference(fileName, fdlg.OrganisationName, role);
                    }
                }
            }
        }
コード例 #5
0
        private void Modify_Click(object sender, RoutedEventArgs e)
        {
            XbimModel model = DataContext as XbimModel;

            foreach (var item in FederatedList.SelectedItems)
            {
                if (item is XbimReferencedModel)
                {
                    var rItem = item as XbimReferencedModel;
                    AddFederatedModel fdlg = new AddFederatedModel(rItem);

                    bool?done = fdlg.ShowDialog();
                    if (done.HasValue && done.Value == true)
                    {
                        string fileName = fdlg.FileName;
                        string ext      = System.IO.Path.GetExtension(fileName);
                        using (XbimModel refM = new XbimModel())
                        {
                            if (string.Compare(ext, ".xbim", true) != 0)
                            {
                                refM.CreateFrom(fileName, null, null, true);
                                var m3D = new Xbim3DModelContext(refM);
                                m3D.CreateContext();
                                fileName = System.IO.Path.ChangeExtension(fileName, "xbim");
                            }
                        }
                        using (var txn = model.BeginTransaction())
                        {
                            rItem.DocumentInformation.Name = fileName;
                            txn.Commit();
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void IfcToCoBieLiteUkTest()
        {
            using (var m = new XbimModel())
            {
                const string ifcTestFile  = @"Lakeside_Restaurant.ifc";
                var          xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                var          jsonFile     = Path.ChangeExtension(ifcTestFile, "json");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List <Facility>();

                OutPutFilters rolefilters = new OutPutFilters();
                RoleFilter    reqRoles    = RoleFilter.Unknown; //RoleFilter.Architectural |  RoleFilter.Mechanical | RoleFilter.Electrical | RoleFilter.FireProtection | RoleFilter.Plumbing;
                rolefilters.ApplyRoleFilters(reqRoles);

                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities, null, rolefilters);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    string msg;
                    facilityType.WriteJson(jsonFile, true);
                    facilityType.WriteCobie("..\\..\\Lakeside_Restaurant.xlsx", out msg, rolefilters, "UK2012", true);


                    break;
                }
            }
        }
コード例 #7
0
ファイル: ModelUtility.cs プロジェクト: weijx-xa/test
        private static XbimModel GetModel(string fileName)
        {
            XbimModel openModel = null;
            var       extension = Path.GetExtension(fileName);

            if (string.IsNullOrWhiteSpace(extension))
            {
                if (File.Exists(Path.ChangeExtension(fileName, "xbim"))) //use xBIM if exists
                {
                    fileName = Path.ChangeExtension(fileName, "xbim");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifc"))) //use ifc if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifc");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifczip"))) //use ifczip if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifczip");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifcxml"))) //use ifcxml if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifcxml");
                }
            }

            if (File.Exists(fileName))
            {
                extension = Path.GetExtension(fileName).TrimStart('.');
                if (String.Compare(extension, "xbim", StringComparison.OrdinalIgnoreCase) == 0) //just open xbim
                {
                    try
                    {
                        var model = new XbimModel();
                        Log.Info("Opening " + fileName);
                        model.Open(fileName, XbimDBAccess.ReadWrite);
                        //delete any geometry
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Log.Error("无法打开文件:" + fileName, e);
                    }
                }
                else //we need to create the xBIM file
                {
                    var model = new XbimModel();
                    try
                    {
                        Log.Info("Creating " + Path.ChangeExtension(fileName, ".xBIM"));
                        model.CreateFrom(fileName, null, null, true);
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Log.Error("无法打开文件:" + fileName, e);
                    }
                }
            }
            return(openModel);
        }
コード例 #8
0
        private BimModel BuildModel(string modelName, bool refresh = false)
        {
            var ifcModel = Path.Combine(DataDir, modelName);

            string geometryFileName = Path.ChangeExtension(ifcModel, ".wexbim");
            string xbimFileName     = Path.ChangeExtension(ifcModel, ".xbim");

            if (refresh)
            {
                Clean(xbimFileName, geometryFileName);
            }

            using (var model = new XbimModel())
            {
                if (!Cached(xbimFileName))
                {
                    //Parse IFC to xbim
                    model.CreateFrom(ifcModel, xbimFileName, null, true);
                }
                // Generate Geometry
                BuildGeometry(model, geometryFileName);
            }

            return(new BimModel(modelName, Path.GetFileName(geometryFileName)));
        }
コード例 #9
0
 public void ConvertCoBieLiteToBson()
 {
     using (var m = new XbimModel())
     {
         var IfcTestFile = "2012-03-23-Duplex-Handover.ifc";
         // IfcTestFile = @"C:\Data\dev\XbimTeam\XbimExchange\Tests\TestFiles\Standard_Classroom_CIC_6_Project_mod2.ifc";
         var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim");
         m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true);
         var helper     = new CoBieLiteHelper(m, "UniClass");
         var facilities = helper.GetFacilities();
         foreach (var facilityType in facilities)
         {
             Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified);
             using (var sw = new FileStream("facility.bson", FileMode.Create))
             {
                 using (var bw = new BinaryWriter(sw))
                 {
                     CoBieLiteHelper.WriteBson(bw, facilityType);
                 }
             }
         }
     }
 }
コード例 #10
0
        private static Facility GetFacilityFromIfc(Stream file, string extension)
        {
            var temp = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);

            try
            {
                //store temporarily
                using (var fileStream = File.OpenWrite(temp))
                {
                    file.CopyTo(fileStream);
                    fileStream.Flush();
                    fileStream.Close();
                }

                using (var model = new XbimModel())
                {
                    model.CreateFrom(temp, null, null, true);

                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);

                    return(ifcToCoBieLiteUkExchanger.Convert().FirstOrDefault());
                }
            }
            //tidy up
            finally
            {
                if (File.Exists(temp))
                {
                    File.Delete(temp);
                }
            }
        }
コード例 #11
0
        public void EscapeHeaderTests()
        {
            const string path   = @"x:\path1\path2\filename.ifc";
            const string umlaut = "name with umlaut ü";

            using (var model = XbimModel.CreateTemporaryModel())
            {
                model.Initialise("Creating Author", " Creating Organisation", "This Application", "This Developer", "v1.1");
                using (var txn = model.BeginTransaction())
                {
                    model.IfcProject.Name = "Project Name";
                    txn.Commit();
                }

                model.Header.FileName.Name = path;
                model.Header.FileName.Organization.Add(umlaut);
                model.SaveAs("testOutput.ifc");
            }
            using (var model = new XbimModel())
            {
                model.CreateFrom("testOutput.ifc", null, null, true);
                Assert.IsTrue(model.Header.FileName.Name == path);
                Assert.IsTrue(model.Header.FileName.Organization.FirstOrDefault() == umlaut);
                model.Close();
            }
        }
コード例 #12
0
        public void IfcToCoBieLiteUkTest()
        {
            string[] testFiles = new string[] { "Lakeside_Restaurant.ifc", "001-Kenton_High_School_Model.ifc", "001 Hello Wall.ifc", "Duplex_A_20110907_optimized.ifc", "NBS_LakesideRestaurant_small_optimized.ifc", "Office_A_20110811_optimized.ifc" };

            foreach (var ifcTestFile in testFiles)
            {
                using (var m = new XbimModel())
                {
                    var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                    var jsonFile     = Path.ChangeExtension(ifcTestFile, "json");
                    m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                    var facilities = new List <Facility>();
                    var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                    facilities = ifcToCoBieLiteUkExchanger.Convert();

                    foreach (var facilityType in facilities)
                    {
                        var log = new StringWriter();
                        facilityType.ValidateUK2012(log, true);

                        string msg;
                        facilityType.WriteJson(jsonFile, true);
                        facilityType.WriteCobie("..\\..\\" + System.IO.Path.ChangeExtension(ifcTestFile, ".xlsx"), out msg, "UK2012", true);


                        break;
                    }
                }
            }
        }
コード例 #13
0
        public void EscapeHeaderTests()
        {
            const string path = @"x:\path1\path2\filename.ifc";
            const string umlaut = "name with umlaut ü";
            using (var model = XbimModel.CreateTemporaryModel())
            {

                model.Initialise("Creating Author", " Creating Organisation", "This Application", "This Developer", "v1.1");
                using (var txn = model.BeginTransaction())
                {
                    model.IfcProject.Name = "Project Name";
                    txn.Commit();
                }

                model.Header.FileName.Name = path;
                model.Header.FileName.Organization.Add(umlaut); 
                model.SaveAs("testOutput.ifc");
            }
            using (var model = new XbimModel())
            {
                model.CreateFrom("testOutput.ifc", null, null, true);
                Assert.IsTrue(model.Header.FileName.Name == path);
                Assert.IsTrue(model.Header.FileName.Organization.FirstOrDefault() == umlaut);
                model.Close();
            }
        }
コード例 #14
0
ファイル: XbimModelTest.cs プロジェクト: bnaand/xBim-Toolkit
 public void Importing_Missing_File_Throws_FileNotFoundException()
 {
     using (XbimModel modelServer = new XbimModel())
     {
         modelServer.CreateFrom("DoesNotExist.ifc");
     }
 }
コード例 #15
0
ファイル: XbimModelTest.cs プロジェクト: bnaand/xBim-Toolkit
 public void Importing_From_Missing_Folder_Throws_DirectoryNotFoundException()
 {
     using (XbimModel modelServer = new XbimModel())
     {
         modelServer.CreateFrom("/BadPath/DoesNotExist.ifc");
     }
 }
コード例 #16
0
        public void IfcToCoBieLiteUkTestSingleFile()
        {
            string ifcTestFile = "001 BTK Sample.ifc";

            using (var m = new XbimModel())
            {
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                var jsonFile     = Path.ChangeExtension(ifcTestFile, "json");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();

                foreach (var facilityType in facilities)
                {
                    var log = new StringWriter();
                    facilityType.ValidateUK2012(log, true);

                    string msg;
                    facilityType.WriteJson(jsonFile, true);
                    facilityType.WriteCobie("..\\..\\" + System.IO.Path.ChangeExtension(ifcTestFile, ".xlsx"), out msg, "UK2012", true);


                    break;
                }
            }
        }
コード例 #17
0
        public void ExtrudedCircularProfilesTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\15 - Swept pipes.ifc", null, null, true, true);
                    foreach (
                        var cp in
                        m.Instances.OfType <IfcExtrudedAreaSolid>().Where(e => e.SweptArea is IfcCircleProfileDef))
                    {
                        Assert.IsTrue(cp != null, "No Extruded Solid found");
                        Assert.IsTrue(cp.SweptArea is IfcCircleProfileDef, "Incorrect profiledef found");

                        var solid = xbimGeometryCreator.CreateSolid(cp);
                        Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                        IfcCsgTests.GeneralTest(solid);
                    }

                    //Assert.IsTrue(solid.Faces.Count() == 10, "T Shaped profiles should have 10 faces");
                }
            }
        }
コード例 #18
0
 public void ConvertCoBieLiteToXml()
 {
     using (var m = new XbimModel())
     {
         var IfcTestFile = "2012-03-23-Duplex-Handover.ifc";
         // var IfcTestFile = @"D:\Users\steve\xBIM\Test Models\BimAlliance BillEast\Model 1 Duplex Apartment\Duplex_MEP_20110907.ifc";
         var xbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim");
         m.CreateFrom(IfcTestFile, xbimTestFile, null, true, true);
         var helper     = new CoBieLiteHelper(m, "UniClass");
         var facilities = helper.GetFacilities();
         var i          = 1;
         foreach (var facilityType in facilities)
         {
             Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified);
             var outName = string.Format("Facility{0}.xml", i++);
             var f       = new FileInfo(outName);
             Debug.WriteLine("Writing to " + f.FullName);
             using (TextWriter writer = File.CreateText(outName))
             {
                 CoBieLiteHelper.WriteXml(writer, facilityType);
             }
             CoBieLiteHelper.WriteXml(Console.Out, facilityType);
         }
     }
 }
コード例 #19
0
        public void IfcExtrudedArea_With_IfcArbritraryClosedProfileDef_And_IfcCompositeCurve()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\2- IfcExtrudedAreaSolid-IfcArbitraryClosedProfileDef-IfcCompositeCurve.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault();
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IfcArbitraryClosedProfileDef, "Incorrect profile definition");
                    Assert.IsTrue(((IfcArbitraryClosedProfileDef)eas.SweptArea).OuterCurve is IfcCompositeCurve, "Incorrect SweptArea type");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);

                    //now make the extrusion invalid
                    eas.Depth = 0;
                    solid     = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 1, "An expected error was not raised raised in geometry conversion"); //we should have an event here
                    Assert.IsTrue(Math.Abs(solid.Volume) < m.ModelFactors.Precision);
                    Assert.IsTrue(solid.BoundingBox.IsEmpty);
                    Assert.IsFalse(solid.IsValid);
                }
            }
        }
コード例 #20
0
        public void RectangleProfileDefTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\1- IfcExtrudedAreaSolid-IfcProfileDef-Parameterised.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea.GetType() == typeof(IfcRectangleProfileDef));
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IfcRectangleProfileDef, "Incorrect profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 6, "Rectangular profiles should have six faces");

                    ////now make the extrusion invalid
                    //eas.Depth = 0;
                    //solid = XbimGeometryCreator.CreateSolid(eas);
                    //Assert.IsTrue(eventTrace.Events.Count == 1); //we should have an event here
                    //Assert.IsTrue(Math.Abs(solid.Volume) < m.ModelFactors.Precision);
                    //Assert.IsTrue(solid.BoundingBox.IsEmpty);
                    //Assert.IsFalse(solid.IsValid);
                }
            }
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: jv112602/XbimGeometry
        private static XbimModel GetModel(string fileName)
        {
            XbimModel openModel = null;
            var       extension = Path.GetExtension(fileName);

            if (string.IsNullOrWhiteSpace(extension))
            {
                if (File.Exists(Path.ChangeExtension(fileName, "xbim"))) //use xBIM if exists
                {
                    fileName = Path.ChangeExtension(fileName, "xbim");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifc"))) //use ifc if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifc");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifczip"))) //use ifczip if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifczip");
                }
                else if (File.Exists(Path.ChangeExtension(fileName, "ifcxml"))) //use ifcxml if exists
                {
                    fileName = Path.ChangeExtension(fileName, "ifcxml");
                }
            }

            if (File.Exists(fileName))
            {
                extension = Path.GetExtension(fileName);
                if (String.Compare(extension, ".xbim", StringComparison.OrdinalIgnoreCase) == 0) //just open xbim
                {
                    try
                    {
                        var model = new XbimModel();
                        model.Open(fileName, XbimDBAccess.ReadWrite);
                        //delete any geometry
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Unable to open model {0}, {1}", fileName, e.Message);
                        Console.WriteLine(String.Format("Unable to open model {0}, {1}", fileName, e.Message));
                    }
                }
                else //we need to create the xBIM file
                {
                    var model = new XbimModel();
                    try
                    {
                        model.CreateFrom(fileName, null, null, true);
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Unable to open model {0}, {1}", fileName, e.Message);
                        Console.WriteLine(String.Format("Unable to open model {0}, {1}", fileName, e.Message));
                    }
                }
            }
            return(openModel);
        }
コード例 #22
0
 public void OpenIfcXmlFile()
 {
     using (var model = new XbimModel())
     {
         model.CreateFrom("4walls1floorSite.ifcxml");
         model.Close();
     }
 }
コード例 #23
0
        public static void ConvertFile(string ifcFileFullName, string destinationFolder, string wexBimFileName, string xbimFile)
        {
            string workingDir = destinationFolder;

            if (string.IsNullOrWhiteSpace(destinationFolder))
            {
                workingDir = Path.GetDirectoryName(ifcFileFullName);
            }
            else
            {
                workingDir = destinationFolder;
            }
            if (string.IsNullOrWhiteSpace(workingDir))
            {
                throw new ApplicationException("The destination folder not specified.");
            }
            if (!Path.IsPathRooted(workingDir))
            {
                throw new ApplicationException("The destination folder not rooted.");
            }
            if (!Directory.Exists(workingDir))
            {
                throw new ApplicationException("The destination folder not found.");
            }
            string fileName = Path.GetFileName(ifcFileFullName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            string coreDestinationFileName  = Path.Combine(workingDir, fileNameWithoutExtension);

            if (string.IsNullOrWhiteSpace(wexBimFileName))
            {
                wexBimFileName = Path.ChangeExtension(coreDestinationFileName, "wexbim");
            }
            else
            {
                wexBimFileName = Path.Combine(workingDir, Path.GetFileName(wexBimFileName));
            }
            if (string.IsNullOrWhiteSpace(xbimFile))
            {
                xbimFile = Path.ChangeExtension(coreDestinationFileName, "xbim");
            }
            else
            {
                xbimFile = Path.Combine(workingDir, Path.GetFileName(xbimFile));
            }
            using (FileStream wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(wexBimFile))
                {
                    using (XbimModel model = new XbimModel())
                    {
                        model.CreateFrom(ifcFileFullName, xbimFile, null, true, false);
                        Xbim3DModelContext geomContext = new Xbim3DModelContext(model);
                        geomContext.CreateContext(XbimGeometryType.PolyhedronBinary); // System.OutOfMemoryException Exception
                        geomContext.Write(binaryWriter);
                    }
                }
            }
        }
コード例 #24
0
        public void OpenIfcXmlFile()
        {
            using (var model = new XbimModel())
            {
                model.CreateFrom("4walls1floorSite.ifcxml");
                model.Close();
            }

        }
コード例 #25
0
ファイル: Program.cs プロジェクト: bnaand/xBim-Toolkit
 private static void CreateXbimFile(string fileName)
 {
     string xbimFileName = Path.ChangeExtension(fileName, ".xbim");
     XbimModel model = new XbimModel();
     model.CreateFrom(fileName, xbimFileName, null);
     model.Open(xbimFileName, XbimDBAccess.ReadWrite);
     XbimScene.ConvertGeometry(model.Instances.OfType<IfcProduct>().Where(t => !(t is IfcFeatureElement)),null, false);
     model.Close();
 }
コード例 #26
0
 public IModel OpenIfcModel()
 {
     IModel model = new XbimModel();
     string xbimName = Path.ChangeExtension(TestSourceFileIfc, "xbim");
     model.CreateFrom(TestSourceFileIfc, xbimName);
     model.Close();
     model = new XbimModel();
     model.Open(xbimName);
     return model;
 }
コード例 #27
0
        private void OpenFile(object s, DoWorkEventArgs args)
        {
            var worker = s as BackgroundWorker;
            var model  = new XbimModel();

            try
            {
                if (worker != null)
                {
                    IsLoading              = true;
                    _openedModelFileName   = _ifcFilename;
                    _temporaryXbimFileName = Path.GetTempFileName();
                    model.CreateFrom(_ifcFilename,
                                     _temporaryXbimFileName,
                                     worker.ReportProgress,
                                     true);

                    //upgrade to new geometry represenation, uses the default 3D model
                    var context = new Xbim3DModelContext(model);
                    context.CreateContext(XbimGeometryType.PolyhedronBinary, worker.ReportProgress, false);

                    if (worker.CancellationPending)
                    {
                        try
                        {
                            model.Close();
                            if (File.Exists(_temporaryXbimFileName))
                            {
                                File.Delete(_temporaryXbimFileName);
                                _temporaryXbimFileName = null;
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
                args.Result = model;
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Error reading " + _ifcFilename);
                var indent = "\t";
                while (ex != null)
                {
                    sb.AppendLine(indent + ex.Message);
                    ex      = ex.InnerException;
                    indent += "\t";
                }

                args.Result = new Exception(sb.ToString());
            }
        }
コード例 #28
0
        private void OpenIfcFile(object s, DoWorkEventArgs args)
        {
            var worker      = s as BackgroundWorker;
            var ifcFilename = args.Argument as string;

            var model = new XbimModel();

            try
            {
                _temporaryXbimFileName = Path.GetTempFileName();
                SetOpenedModelFileName(ifcFilename);


                if (worker != null)
                {
                    model.CreateFrom(ifcFilename, _temporaryXbimFileName, worker.ReportProgress, true);
                    var context = new Xbim3DModelContext(model);//upgrade to new geometry represenation, uses the default 3D model
                    context.CreateContext(geomStorageType: XbimGeometryType.PolyhedronBinary, progDelegate: worker.ReportProgress, adjustWCS: false);

                    if (worker.CancellationPending) //if a cancellation has been requested then don't open the resulting file
                    {
                        try
                        {
                            model.Close();
                            if (File.Exists(_temporaryXbimFileName))
                            {
                                File.Delete(_temporaryXbimFileName); //tidy up;
                            }
                            _temporaryXbimFileName = null;
                            SetOpenedModelFileName(null);
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                        }
                        return;
                    }
                }
                args.Result = model;
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Error reading " + ifcFilename);
                var indent = "\t";
                while (ex != null)
                {
                    sb.AppendLine(indent + ex.Message);
                    ex      = ex.InnerException;
                    indent += "\t";
                }

                args.Result = new Exception(sb.ToString());
            }
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: hejiquan/XbimGeometry
        private static XbimModel GetModel(string fileName)
        {
            XbimModel openModel = null;
            var extension = Path.GetExtension(fileName);
            if (string.IsNullOrWhiteSpace(extension))
            {
                if (File.Exists(Path.ChangeExtension(fileName, "xbim"))) //use xBIM if exists
                    fileName = Path.ChangeExtension(fileName, "xbim");
                else if (File.Exists(Path.ChangeExtension(fileName, "ifc"))) //use ifc if exists
                    fileName = Path.ChangeExtension(fileName, "ifc");
                else if (File.Exists(Path.ChangeExtension(fileName, "ifczip"))) //use ifczip if exists
                    fileName = Path.ChangeExtension(fileName, "ifczip");
                else if (File.Exists(Path.ChangeExtension(fileName, "ifcxml"))) //use ifcxml if exists
                    fileName = Path.ChangeExtension(fileName, "ifcxml");
            }

            if (File.Exists(fileName))
            {
                extension = Path.GetExtension(fileName);
                if (String.Compare(extension, ".xbim", StringComparison.OrdinalIgnoreCase) == 0) //just open xbim
                {

                    try
                    {
                        var model = new XbimModel();
                        model.Open(fileName, XbimDBAccess.ReadWrite);
                        //delete any geometry
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Unable to open model {0}, {1}", fileName, e.Message);
                        Console.WriteLine(String.Format("Unable to open model {0}, {1}", fileName, e.Message));
                    }

                }
                else //we need to create the xBIM file
                {
                    var model = new XbimModel();
                    try
                    {
                        model.CreateFrom(fileName, null, null, true);
                        openModel = model;
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Unable to open model {0}, {1}", fileName, e.Message);
                        Console.WriteLine(String.Format("Unable to open model {0}, {1}", fileName, e.Message));
                    }

                }
            }
            return openModel;
        }
コード例 #30
0
ファイル: Federate.cs プロジェクト: tnesser/XbimExchange
        /// <summary>
        /// Create xbim file on selection of ifc files
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateXBimFile(object sender, DoWorkEventArgs e)
        {
            string filename = e.Argument as string;
            var    xbimFile = Path.ChangeExtension(filename, "xbim");

            _worker.ReportProgress(0, string.Format("Creating {0}", Path.GetFileName(xbimFile)));
            using (var model = new XbimModel())
            {
                model.CreateFrom(filename, xbimFile, _worker.ReportProgress, true, true);
            }
        }
コード例 #31
0
 public void OpenIfcXmlFileFromStream()
 {
     using (var fileStream = new FileStream("4walls1floorSite.ifcxml", FileMode.Open, FileAccess.Read))
     {
         using (var model = new XbimModel())
         {
             model.CreateFrom(fileStream, XbimStorageType.IFC, "4walls1floorSite.xbim");
             model.Close();
         }
         fileStream.Close();
     }
 }
コード例 #32
0
 public void OpenIfcZipFileFromStream()
 {
     using (var fileStream = new FileStream("4walls1floorSite.ifczip", FileMode.Open, FileAccess.Read))
     {
         using (var model = new XbimModel())
         {
             model.CreateFrom(fileStream, XbimStorageType.IFC, "4walls1floorSite.xbim");
             model.Close();
         }
         fileStream.Close();
     }
 }
コード例 #33
0
        public void ExtractIfcGeometryEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {
                    if (typeof(IfcProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "ObjectPlacement" || prop.PropertyInfo.Name == "Representation")
                        {
                            return(null);
                        }
                    }
                    if (typeof(IfcTypeProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "RepresentationMaps")
                        {
                            return(null);
                        }
                    }
                    return(prop.PropertyInfo.GetValue(toCopy, null));//just pass through the value
                };

                //source.Open("BIM Logo-LetterM.xBIM");
                //source.SaveAs("WithGeometry.ifc");
                string modelName     = @"4walls1floorSite";
                string xbimModelName = Path.ChangeExtension(modelName, "xbim");

                source.CreateFrom(Path.ChangeExtension(modelName, "ifc"), null, null, true);

                using (var target = XbimModel.CreateModel(Path.ChangeExtension(modelName + "_NoGeom", "xbim")))
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances.OfType <IfcRoot>())
                        {
                            target.InsertCopy(item, copied, txn, propTransform, false);
                        }
                        txn.Commit();
                    }

                    target.SaveAs(Path.ChangeExtension(modelName + "_NoGeom", "ifc"));
                    target.Close();
                }

                source.Close();
                // XbimModel.Compact(Path.ChangeExtension(modelName + "_NoGeom", "xbim"), Path.ChangeExtension(modelName + "_NoGeom_Compacted", "xbim"));
                //the two files should be the same
            }
        }
コード例 #34
0
        private void OnClick_LoadModel(object sender, RoutedEventArgs e)
        {
            string fileName = string.Empty;
            string saveTxt  = txtDBName.Text;

            txtDBName.SetCurrentValue(TextBlock.TextProperty, "Loading file, please wait...");

            using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog())
            {
                dlg.Title         = "Select Model";
                dlg.Filter        = "All XBim Files|*.ifc;*.ifcxml;*.ifczip;*.xbim;*.xbimf|IFC Files|*.ifc;*.ifcxml;*.ifczip|Xbim Files|*.xbim|Xbim Federated Files|*.xbimf";
                dlg.FilterIndex   = 0;
                dlg.ValidateNames = true;
                System.Windows.Forms.DialogResult dlgresult = dlg.ShowDialog();
                if (dlgresult == System.Windows.Forms.DialogResult.OK)
                {
                    fileName = dlg.FileName;
                }
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                txtDBName.SetCurrentValue(TextBlock.TextProperty, "Loading file, please wait...");
                if (Model != null)
                {
                    Model.Close();
                }
                XbimModel model   = new XbimModel();
                string    fileExt = System.IO.Path.GetExtension(fileName);
                if ((fileExt.Equals(".xbim", StringComparison.OrdinalIgnoreCase)) ||
                    (fileExt.Equals(".xbimf", StringComparison.OrdinalIgnoreCase))
                    )
                {
                    model.Open(fileName, XbimDBAccess.ReadWrite);
                    //model.CacheStart();
                }
                else //ifc file
                {
                    string xbimFile = System.IO.Path.ChangeExtension(fileName, "xBIM");
                    //ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState)
                    //{
                    //    progressBar.Value = percentProgress;
                    //};
                    model.CreateFrom(fileName, xbimFile, null, true, false);
                }
                Model = model;
            }
            else
            {
                txtDBName.SetCurrentValue(TextBlock.TextProperty, saveTxt);
            }
        }
コード例 #35
0
        public void ReadIfc(string filepath)
        {
            var ifcFileName = filepath;

            var tempFilename = Path.GetTempFileName();
            var model = new XbimModel();

            model.CreateFrom(ifcFileName, tempFilename);
            model.Open(tempFilename);

            var products = model.Instances.OfType<IfcProduct>();
            var storeys = model.Instances.OfType<IfcBuildingStorey>().ToList();
        }
コード例 #36
0
        private static void IfcFeaturesClassificationIsCorrect(string ifcFileFullName)
        {
            var xbimFileFullName = Path.ChangeExtension(ifcFileFullName, ".xbim");

            using (var m = new XbimModel())
            {
                m.CreateFrom(ifcFileFullName, xbimFileFullName, null, true, true);
                var context = new Xbim3DModelContext(m);
                context.CreateContext(XbimGeometryType.PolyhedronBinary);
                TestForClassificationOfIfcFeatureElements(context);
                m.Close();
            }
        }
コード例 #37
0
        public void ExtractIfcGeometryEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {

                    if (typeof(IfcProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "ObjectPlacement" || prop.PropertyInfo.Name == "Representation")
                            return null;
                    }   
                    if(typeof(IfcTypeProduct).IsAssignableFrom(toCopy.GetType()))
                    {
                        if (prop.PropertyInfo.Name == "RepresentationMaps" )
                            return null;
                    }
                    return prop.PropertyInfo.GetValue(toCopy, null);//just pass through the value               
                };

                //source.Open("BIM Logo-LetterM.xBIM");
                //source.SaveAs("WithGeometry.ifc");
                string modelName = @"4walls1floorSite";
                string xbimModelName = Path.ChangeExtension(modelName,"xbim");
                
                source.CreateFrom( Path.ChangeExtension(modelName,"ifc"), null, null, true);
               
                using (var target = XbimModel.CreateModel(Path.ChangeExtension(modelName + "_NoGeom", "xbim")))
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances.OfType<IfcRoot>())
                        {
                            target.InsertCopy(item, copied, txn, propTransform, false);
                        }
                        txn.Commit();
                    }
                    
                    target.SaveAs(Path.ChangeExtension(modelName + "_NoGeom", "ifc"));
                    target.Close();
                    
                }
                
                source.Close();
               // XbimModel.Compact(Path.ChangeExtension(modelName + "_NoGeom", "xbim"), Path.ChangeExtension(modelName + "_NoGeom_Compacted", "xbim"));
                //the two files should be the same
            }
        }
コード例 #38
0
        private void OpenIfcFile(object s, DoWorkEventArgs args)
        {
            var worker      = s as BackgroundWorker;
            var ifcFilename = args.Argument as string;

            var model = new XbimModel();

            try
            {
                _temporaryXbimFileName = Path.GetTempFileName();
                _openedModelFileName   = ifcFilename;

                if (worker != null)
                {
                    model.CreateFrom(ifcFilename, _temporaryXbimFileName, worker.ReportProgress, true);
                    if (worker.CancellationPending) // if a cancellation has been requested then don't open the resulting file
                    {
                        try
                        {
                            model.Close();
                            if (File.Exists(_temporaryXbimFileName))
                            {
                                File.Delete(_temporaryXbimFileName);
                            }
                            _temporaryXbimFileName = null;
                            _openedModelFileName   = null;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        return;
                    }
                }
                args.Result = model;
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Error reading " + ifcFilename);
                var indent = "\t";
                while (ex != null)
                {
                    sb.AppendLine(indent + ex.Message);
                    ex      = ex.InnerException;
                    indent += "\t";
                }
                args.Result = new Exception(sb.ToString());
            }
        }
コード例 #39
0
        private void OpenIfcFile(object s, DoWorkEventArgs args)
        {
            BackgroundWorker worker      = s as BackgroundWorker;
            string           ifcFilename = args.Argument as string;

            XbimModel model = new XbimModel();

            try
            {
                _temporaryXbimFileName = Path.GetTempFileName();
                _openedModelFileName   = ifcFilename;

                model.CreateFrom(ifcFilename, _temporaryXbimFileName, worker.ReportProgress, true, false);
                Xbim3DModelContext context = new Xbim3DModelContext(model);//upgrade to new geometry represenation, uses the default 3D model
                context.CreateContext(progDelegate: worker.ReportProgress);

                if (worker.CancellationPending == true) //if a cancellation has been requested then don't open the resulting file
                {
                    try
                    {
                        model.Close();
                        if (File.Exists(_temporaryXbimFileName))
                        {
                            File.Delete(_temporaryXbimFileName); //tidy up;
                        }
                        _temporaryXbimFileName = null;
                        _openedModelFileName   = null;
                    }
                    catch (Exception)
                    { }
                    return;
                }
                args.Result = model;
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Error reading " + ifcFilename);
                string indent = "\t";
                while (ex != null)
                {
                    sb.AppendLine(indent + ex.Message);
                    ex      = ex.InnerException;
                    indent += "\t";
                }

                args.Result = new Exception(sb.ToString());
            }
        }
コード例 #40
0
 public void ConvertCoBieLiteToIfc()
 {
     using (var m = new XbimModel())
     {
         m.CreateFrom("2012-03-23-Duplex-Handover.ifc", "2012-03-23-Duplex-Handover.xbim", null, true, true);
         var helper     = new CoBieLiteHelper(m, "UniClass");
         var facilities = helper.GetFacilities();
         foreach (var facilityType in facilities)
         {
             using (var sw = new FileStream("facility.bson", FileMode.Create))
             {
                 helper.WriteIfc(Console.Out, facilityType);
             }
         }
     }
 }
コード例 #41
0
ファイル: SceneTests.cs プロジェクト: jv112602/XbimGeometry
        private static void WriteWexBim(string fnameIn)
        {
            var fNameOut = Path.ChangeExtension(fnameIn, "wexbim");

            using (var m = new XbimModel())
            {
                m.CreateFrom(fnameIn, null, null, true, true);
                var m3D = new Xbim3DModelContext(m);
                m3D.CreateContext(XbimGeometryType.PolyhedronBinary);
                using (var bw = new BinaryWriter(new FileStream(fNameOut, FileMode.Create)))
                {
                    m3D.Write(bw);
                    bw.Close();
                }
            }
        }
コード例 #42
0
 public void SimpleIfcElementSignatureTest()
 {
     using (var model = new XbimModel())
     {
         model.CreateFrom("Standard Classroom CIC 6.ifc", null, null, true);
         var geomContext = new Xbim3DModelContext(model);
         geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);
         var summary = new IfcElementSignatureSummary();
         foreach (var elem in model.Instances.OfType <IfcElement>())
         {
             var signature = new IfcElementSignature(elem, geomContext);
             summary.Add(signature);
             Debug.WriteLine(signature.ToCSV());
         }
         Debug.WriteLine(summary.ToString());
     }
 }
コード例 #43
0
        public void CreateFederation()
        {
            using (XbimModel fedModel = XbimModel.CreateTemporaryModel())
            {
                fedModel.Initialise("Federation Creating Author", "Federation Creating Organisation", "This Application", "This Developer", "v1.1");
                using (var txn = fedModel.BeginTransaction())
                {
                    fedModel.IfcProject.Name = "Federation Project Name";
                    txn.Commit();
                }
                //now add federated models
                fedModel.AddModelReference(ModelA, "The Architects Name", IfcRole.Architect);
                fedModel.AddModelReference(ModelB, "The Owners Name", IfcRole.BuildingOwner);
                fedModel.AddModelReference(ModelC, "The Cost Consultants Name", "Cost Consultant");
                fedModel.SaveAs("Federated Model", XbimStorageType.IFC);
            } //close and automatically delete the temporary database
            //Now open the Ifc file and see what we have
            using (XbimModel fed = new XbimModel())
            {
                fed.CreateFrom("Federated Model.ifc", "Federated Model.xBIMF"); //use xBIMF to help us distinguish
                fed.Open("Federated Model.xBIMF", XbimExtensions.XbimDBAccess.Read);

                //check the various ways of access objects give consistent results.
                long localInstances = fed.InstancesLocal.Count;
                long totalInstances = fed.Instances.Count;
                long refInstancesCount = 0;
                foreach (var refModel in fed.RefencedModels)
                {
                    refInstancesCount += refModel.Model.Instances.Count;
                }

                Assert.IsTrue(totalInstances == refInstancesCount + localInstances);

                long enumeratingInstancesCount = 0;
                foreach (IPersistIfcEntity item in fed.Instances)
                {
                    enumeratingInstancesCount++;
                }
                Assert.IsTrue(totalInstances == enumeratingInstancesCount);

                long fedProjectCount = fed.Instances.OfType<IfcProject>().Count();
                long localProjectCount = fed.InstancesLocal.OfType<IfcProject>().Count();
                Assert.IsTrue(fedProjectCount == 4);
                Assert.IsTrue(localProjectCount == 1);
            }
        }
コード例 #44
0
        public void IfcFaceBasedSurfaceModelTest()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\17 - IfcFaceBasedSurfaceModel.ifc", null, null, true, true);
                    var fbsm = m.Instances[29] as IfcFaceBasedSurfaceModel;
                    Assert.IsTrue(fbsm != null, "No IfcFaceBasedSurfaceModel found");

                    _xbimGeometryCreator.CreateSurfaceModel(fbsm);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warning or Error events were raised");
                        //we should have no warnings

                }
            }
        }
コード例 #45
0
        public void IfcRevolvedArea_With_IfcCircleHollowProfileDef()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\5- IfcRevolvedAreaSolid-IfcCircularHollowProfileDef.ifc", null, null, true, true);
                    var ss = m.Instances.OfType<IfcRevolvedAreaSolid>().FirstOrDefault(e => e.SweptArea is IfcCircleHollowProfileDef);
                    Assert.IsTrue(ss != null, "No Revolved Area found");
                    Assert.IsTrue(ss.SweptArea is IfcCircleHollowProfileDef, "Incorrect profiledef found");

                    var solid = _xbimGeometryCreator.CreateSolid(ss);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 4, "Circle Hollow profiles should have 4 faces");
                }
            }
        }
コード例 #46
0
        public void IfcSurfaceCurveSweptAreaSolid()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\11- IfcSurfaceCurveSweptAreaSolid.ifc", null, null, true, true);
                    var ss = m.Instances.OfType<IfcSurfaceCurveSweptAreaSolid>().FirstOrDefault();
                    Assert.IsTrue(ss != null, "No Swept Disk found");

                    var solid = _xbimGeometryCreator.CreateSolid(ss);

                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 6, "This IfcSurfaceCurveSweptAreaSolid with hollow circular profile def should have 6 faces");
                }
            }
        }
コード例 #47
0
 public void CutNonSolidBrep()
 {
     using (var eventTrace = LoggerFactory.CreateEventTrace())
     {
         using (var m = new XbimModel())
         {
             m.CreateFrom("SolidTestFiles\\Complex_BRep_Boolean.ifc", null, null, true, true);
             var fbr = m.Instances[35] as IfcFacetedBrep;
             Assert.IsTrue(fbr != null, "No IfcFacetedBRep found");
             var bodyShape = (IXbimShell)((IXbimGeometryObjectSet)_xbimGeometryCreator.Create(fbr)).First();
             Assert.IsTrue(bodyShape.IsValid, "Invalid IfcFacetedBRep");
             var opening = m.Instances[133218] as IfcExtrudedAreaSolid;
             Assert.IsTrue(opening != null, "No IfcExtrudedAreaSolid found");
             var window = m.Instances[133212] as IfcOpeningElement;
             var cutShape = (IXbimSolid)_xbimGeometryCreator.Create(opening, (IfcAxis2Placement3D)((IfcLocalPlacement)window.ObjectPlacement).RelativePlacement);
             var result =  bodyShape.Cut(cutShape, m.ModelFactors.OneMilliMetre);
         }
     }
 }
コード例 #48
0
        public void ConverIfcToWexBim()
        {
            const string ifcFileFullName = @"Lakeside_Restaurant.ifc";

            var fileName = Path.GetFileName(ifcFileFullName);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            var workingDir = Directory.GetCurrentDirectory();
            var coreFileName = Path.Combine(workingDir, fileNameWithoutExtension);
            var wexBimFileName = Path.ChangeExtension(coreFileName, "wexbim");
            var xbimFile = Path.ChangeExtension(coreFileName, "xbim");
            try
            {

                using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                {
                    using (var binaryWriter = new BinaryWriter(wexBimFile))
                    {

                        using (var model = new XbimModel())
                        {
                            try
                            {
                                model.CreateFrom(ifcFileFullName, xbimFile, null, true);
                                var geomContext = new Xbim3DModelContext(model);
                                geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                model.Close();
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }

                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Failed to process " + ifcFileFullName + " - " + e.Message);
            }
        }
コード例 #49
0
        public void IfcSweptDisk_With_IfcComposite()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\6- IfcSweptDiskSolid_With_BooleanResult.ifc", null, null, true, true);
                    var ss = m.Instances.OfType<IfcSweptDiskSolid>().FirstOrDefault(e => e.Directrix is IfcCompositeCurve);
                    Assert.IsTrue(ss != null, "No Swept Disk found");
                    Assert.IsTrue(ss.Directrix is IfcCompositeCurve, "Incorrect sweep found");

                    var solid = _xbimGeometryCreator.CreateSolid(ss);

                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 4, "Swept disk solids along a this composite curve should have 4 faces");
                }
            }
        }
コード例 #50
0
        public void CompositeProfileDefTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\IfcCompositeProfileDefTest.ifc", null, null, true, true);
                    var eas = m.Instances.OfType<IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea.GetType() == typeof(IfcCompositeProfileDef));
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IfcCompositeProfileDef, "Incorrect profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 40, "IfcCompositeProfileDef profile should have six faces");

                }
            }
        }
コード例 #51
0
        private static Facility GetValidated(string requirementFile)
        {
            const string ifcTestFile = @"Lakeside_Restaurant_fabric_only.ifczip";
            Facility sub = null;

            //create validation file from IFC
            using (var m = new XbimModel())
            {
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List<Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
                sub = facilities.FirstOrDefault();
            }
            Assert.IsTrue(sub!=null);
            var vd = new FacilityValidator();
            var req = Facility.ReadJson(requirementFile);
            var validated = vd.Validate(req, sub);
            return validated;
        }
コード例 #52
0
        public void ValidIdentityInFederation()
        {
            using (var fedModel = XbimModel.CreateTemporaryModel())
            {
                fedModel.Initialise("Federation Creating Author", "Federation Creating Organisation", "This Application", "This Developer", "v1.1");
                using (var txn = fedModel.BeginTransaction())
                {
                    fedModel.IfcProject.Name = "Federation Project Name";
                    txn.Commit();
                }
                //now add federated models
                fedModel.AddModelReference(ModelFedP1, "The Architects Name", IfcRole.Architect);
                fedModel.AddModelReference(ModelFedP2, "The Owners Name", IfcRole.BuildingOwner);
                fedModel.SaveAs("P1P2Federation", XbimStorageType.IFC);
            } //close and automatically delete the temporary database
            //Now open the Ifc file and see what we have
            using (var fed = new XbimModel())
            {
                fed.CreateFrom("P1P2Federation.ifc", "P1P2Federation.xBIMF"); //use xBIMF to help us distinguish
                fed.Open("P1P2Federation.xBIMF", XbimExtensions.XbimDBAccess.Read);
                fed.EnsureUniqueUserDefinedId();

                var mustDiffer =
                    fed.Instances.OfType<IfcGeometricRepresentationSubContext>()
                        .Where(x => x.ContextIdentifier == @"Body").ToArray();
                
                // we are expecting two items (one body from each model loaded)
                // they happen to share the same entitylabel, but they have different models.

                var first = mustDiffer[0];
                var second = mustDiffer[1];

                Assert.IsFalse(first == second);

                var tst = new HashSet<IfcGeometricRepresentationContext>();
                tst.Add(first);
                tst.Add(second);
            }
        }
コード例 #53
0
        public void IfcRevolvedArea_To_Sphere()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom(@"SolidTestFiles\BIM Logo-Coordination View 2 - No M.ifc", null, null, true, true);
                    var ss = m.Instances.OfType<IfcRevolvedAreaSolid>().FirstOrDefault(e => e.EntityLabel==290);
                    Assert.IsTrue(ss != null, "No Revolved Area found");
                  //  m.ModelFactors.DeflectionAngle = 0.1;
                  //  m.ModelFactors.DeflectionTolerance = 0.1;
                    var solid = _xbimGeometryCreator.CreateSolid(ss);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call
                    var facetedSphere = _xbimGeometryCreator.CreateFacetedBrep(m, solid);
                    var shell = _xbimGeometryCreator.CreateShell(facetedSphere.Outer);
                    var xbimFacetedSphere = _xbimGeometryCreator.CreateSolidSet(facetedSphere);
                    Assert.IsTrue(xbimFacetedSphere.Count==1);
                    //_xbimGeometryCreator.WriteTriangulation(Console.Out,solid, 0.001,0.5);

                }
            }
        }
コード例 #54
0
        public void IfcFacetedBRepTest()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\12 - Multiple FacetedBrep.ifc", null, null, true, true);
                    var fbr = m.Instances[780] as IfcFacetedBrep;
                    Assert.IsTrue(fbr != null, "No IfcFacetedBRep found");
                    int faceCount = fbr.Outer.CfsFaces.Count;

                    var solids = _xbimGeometryCreator.CreateSolidSet(fbr);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warning or Error events were raised"); //we should have no warnings

                    Assert.IsTrue(solids.Count == 1, "Expected 11 solids");

                    IfcCsgTests.GeneralTest(solids.First);

                    Assert.IsTrue(solids.First.Faces.Count() == faceCount, "Failed to convert all faces");
                }
            }
        }
コード例 #55
0
        public void IfcFacetedBRepTubeModelTest()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\IfcFacetedBRepWithIncorrectlyOrientedFaces.ifc", null, null, true, true);
                    var fbr = m.Instances[98711] as IfcFacetedBrep;
                    Assert.IsTrue(fbr != null, "No IfcFacetedBRep found");
                    int faceCount = fbr.Outer.CfsFaces.Count;

                    var compound = _xbimGeometryCreator.Create(fbr);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warning or Error events were raised"); //we should have no warnings
                    var bw = new BinaryWriter(new MemoryStream());
                    _xbimGeometryCreator.WriteTriangulation(bw,compound, m.ModelFactors.Precision,m.ModelFactors.DeflectionTolerance);
                    //Assert.IsTrue(solids.Count == 1, "Expected 1 solid");

                    //IfcCsgTests.GeneralTest(solids.First);

                    //Assert.IsTrue(solids.First.Faces.Count() == faceCount, "Failed to convert all faces");
                }
            }
        }
コード例 #56
0
        public void BIM_Logo_LetterM_Test()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\BIM Logo-LetterM.ifc", null, null, true, true);
                    var eas = m.Instances[57] as IfcSurfaceCurveSweptAreaSolid;
                    Assert.IsTrue(eas != null, "No IfcSurfaceCurveSweptArea Solid found");

                    var solid = (IXbimSolid)xbimGeometryCreator.Create(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 26, "Letter M should have 26 faces");
                    var xbimTessellator = new XbimTessellator(m, XbimGeometryType.PolyhedronBinary);
                    // Assert.IsTrue(xbimTessellator.CanMesh(solid));//if we can mesh the shape directly just do it
                    // var shapeGeom = xbimTessellator.Mesh(solid);
                    var shapeGeom = xbimGeometryCreator.CreateShapeGeometry(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, m.ModelFactors.DeflectionAngle, XbimGeometryType.PolyhedronBinary);

                }
            }
        }
コード例 #57
0
ファイル: Program.cs プロジェクト: AlexBradley1990/Xbim.RDF
        static private bool OpenIfcFile(XbimModel model, string filename)
        {

            try
            {
                model.CreateFrom(filename, null, null, true);
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Error reading " + filename);
                var indent = "\t";
                while (ex != null)
                {
                    sb.AppendLine(indent + ex.Message);
                    ex = ex.InnerException;
                    indent += "\t";
                }

                Console.WriteLine(sb.ToString());
                return false;
            }
            return true;
        }
コード例 #58
0
        public void IfcShellBasedSurfaceModelTest()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\16 - IfcShellBasedSurfaceModel.ifc", null, null, true, true);
                    var sbsm = m.Instances[38] as IfcShellBasedSurfaceModel;
                    Assert.IsTrue(sbsm != null, "No IfcShellBasedSurfaceModel found");
                    Assert.IsTrue(sbsm.SbsmBoundary.First is IfcOpenShell, "ifc OpenShell not found");

                    _xbimGeometryCreator.CreateSurfaceModel(sbsm);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warning or Error events were raised");
                        //we should have no warnings

                }
            }
        }
コード例 #59
0
 private static XbimModel ParseModelFile(string ifcFileName,bool caching)
 {
     XbimModel model = new XbimModel();
     //create a callback for progress
     switch (Path.GetExtension(ifcFileName).ToLowerInvariant())
     {
         case ".ifc":
         case ".ifczip":
         case ".ifcxml":
             model.CreateFrom(ifcFileName, BuildFileName(ifcFileName, ".xBIM"), null, true, caching);
             break;
         default:
             throw new NotImplementedException(String.Format("XbimConvert does not support converting {0} file formats currently", Path.GetExtension(ifcFileName)));
     }
     return model;
 }
コード例 #60
0
        public void IfcFacetedBRepWithMultipleSolids()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\12 - Multiple FacetedBrep.ifc", null, null, true, true);
                    var fbr = m.Instances[25] as IfcFacetedBrep;
                    Assert.IsTrue(fbr != null, "No IfcFacetedBRep found");
                    int faceCount = fbr.Outer.CfsFaces.Count;

                    var solids = _xbimGeometryCreator.CreateSolidSet(fbr);

                    Assert.IsTrue(solids.Count == 11, "Expected 11 solids");
                    foreach (var solid in solids)
                    {
                        IfcCsgTests.GeneralTest(solid, true);
                    }
                }
            }
        }