Example #1
0
        public void ConvertCobieLiteToIfc()
        {
            var facility = FacilityType.ReadJson("COBieLite.json");

            var credentials = new XbimEditorCredentials()
            {
                ApplicationDevelopersName = "XbimTeam",
                ApplicationFullName       = "Xbim.Exchanger",
                EditorsOrganisationName   = "Xbim Development Team",
                EditorsFamilyName         = "Xbim Tester",
                ApplicationVersion        = "3.0"
            };

            using (var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
            {
                using (var txn = model.BeginTransaction("Convert from COBieLite"))
                {
                    var exchanger = new CoBieLiteToIfcExchanger(facility, model);
                    exchanger.Convert();
                    txn.Commit();
                    //var err = model.Validate(model.Instances, Console.Out);
                }
                model.SaveAs(@"ConvertedFromCOBieLite.ifc", StorageType.Ifc);
            }
        }
Example #2
0
        private static void TestFederation <T>(XbimSchemaVersion schema, XbimEditorCredentials credentials, bool useXbimFormat) where  T : IInstantiableEntity, IIfcProject
        {
            var d = new DirectoryInfo(".");

            Debug.WriteLine("Working directory is {0}", d.FullName);

            var modelsNames = CreateModels <T>(schema, credentials, useXbimFormat);
            var fedName     = CreateFederation(schema, credentials, modelsNames);

            using (var ifcStore = IfcStore.Open(fedName))
            {
                Assert.IsTrue(ifcStore.IsFederation, "Federation not created");
                Assert.AreEqual(ifcStore.ReferencedModels.Count(), 2, "Should have two federated models.");
                foreach (var ifcStoreReferencedModel in ifcStore.ReferencedModels)
                {
                    Debug.WriteLine(ifcStoreReferencedModel.Name);
                }
                ifcStore.Close();
            }

            // clean all
            File.Delete(fedName);
            foreach (var model in modelsNames)
            {
                File.Delete(model);
            }
        }
Example #3
0
        public static void CreateLog()
        {
            var editor = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "You",
                ApplicationFullName       = "Your app",
                ApplicationIdentifier     = "Your app ID",
                ApplicationVersion        = "4.0",
                //your user
                EditorsFamilyName       = "Santini Aichel",
                EditorsGivenName        = "Johann Blasius",
                EditorsOrganisationName = "Independent Architecture"
            };

            using (var model = IfcStore.Open("SampleHouse.ifc", editor))
            {
                using (var txn = model.BeginTransaction("Modification"))
                {
                    using (var log = new TransactionLog(txn))
                    {
                        //change to existing wall
                        var wall = model.Instances.FirstOrDefault <IIfcWall>();
                        wall.Name        = "Unexpected name";
                        wall.GlobalId    = Guid.NewGuid().ToPart21();
                        wall.Description = "New and more descriptive description";

                        //print all changes caused by this
                        PrintChanges(log);
                        txn.Commit();
                    }
                    Console.WriteLine();
                }
            }
        }
Example #4
0
        private static IfcStore CreateAndInitModel(string projectName)
        {
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "xbim developer",
                ApplicationFullName       = "T-Rex",
                ApplicationIdentifier     = "T-Rex",
                ApplicationVersion        = "0.2",
                EditorsFamilyName         = "Team",
                EditorsGivenName          = "xbim",
                EditorsOrganisationName   = "xbim developer"
            };

            var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4x1, XbimStoreType.InMemoryModel);

            using (ITransaction transaction = model.BeginTransaction("Initialise Model"))
            {
                IfcProject project = model.Instances.New <IfcProject>();
                project.Initialize(ProjectUnits.SIUnitsUK);
                project.Name = projectName;
                transaction.Commit();
            }

            return(model);
        }
Example #5
0
        public static void CreateFederation()
        {
            var editor = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "You",
                ApplicationFullName       = "Your app",
                ApplicationIdentifier     = "Your app ID",
                ApplicationVersion        = "4.0",
                //your user
                EditorsFamilyName       = "Santini Aichel",
                EditorsGivenName        = "Johann Blasius",
                EditorsOrganisationName = "Independent Architecture"
            };

            using (var federation = IfcStore.Create(editor, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel))
            {
                federation.AddModelReference("SampleHouse.ifc", "Bob The Builder", "Original Constructor"); //IFC4
                federation.AddModelReference("SampleHouseExtension.ifc", "Tyna", "Extensions Builder");     //IFC2x3

                Console.WriteLine($"Model is federation: {federation.IsFederation}");
                Console.WriteLine($"Number of overall entities: {federation.FederatedInstances.Count}");
                Console.WriteLine($"Number of walls: {federation.FederatedInstances.CountOf<IIfcWall>()}");
                foreach (var refModel in federation.ReferencedModels)
                {
                    Console.WriteLine();
                    Console.WriteLine($"    Referenced model: {refModel.Name}");
                    Console.WriteLine($"    Referenced model organization: {refModel.OwningOrganisation}");
                    Console.WriteLine($"    Number of walls: {refModel.Model.Instances.CountOf<IIfcWall>()}");
                }

                //you can save information about the federation for a future use
                federation.SaveAs("federation.ifc");
            }
        }
Example #6
0
        /// <summary>
        /// Open federated file
        /// </summary>
        /// <param name="file">FileInfo</param>
        /// <returns>bool</returns>
        public bool Open(FileInfo file)
        {
            if (_fedModel != null)
            {
                _fedModel.Close();
            }
            if (!file.Exists)
            {
                return(false);
            }
            var creds = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "xBIM",
                ApplicationDevelopersName = "xBIM Team",
                EditorsFamilyName         = "undefined",
                EditorsOrganisationName   = "undefined",
                ApplicationVersion        = "1.0"
            };

            try
            {
                _fedModel = IfcStore.Open(file.FullName, creds, 0);
                return(true);
            }
            catch (Exception)
            {
                //just return false;
            }
            return(false);
        }
Example #7
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case cube
        /// </summary>
        public static void Run()
        {
            Log.Information("Initialising the IFC Project....");

            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "xBimTeam",
                ApplicationFullName       = "Cube Example",
                ApplicationIdentifier     = "CE",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "Team",
                EditorsGivenName          = "xBIM",
                EditorsOrganisationName   = "xBimTeam"
            };

            using (var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel))
            {
                using (var txn = model.BeginTransaction("Creating content"))
                {
                    var project  = InitializeProject(model, "The Cube Project");
                    var building = CreateBuilding(model, project, "Building for the Cube");
                    var cube     = CreateCubeFurniture(model, 4000, building);
                    txn.Commit();
                }

                //write the Ifc File
                model.SaveAs("TheCube.ifc", StorageType.Ifc);
            }
            Log.Information("TheCube.ifc file created and saved.");
        }
Example #8
0
        /// <summary>
        ///  Initialisiert ein leeres Projekt
        /// </summary>
        private static IfcStore createandInitModel(string projectName,
                                                   string editorsFamilyName,
                                                   string editorsGivenName,
                                                   string editorsOrganisationName,
                                                   out IfcProject project)
        {
            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "HTW Dresden for DDBIM",
                ApplicationFullName       = System.Reflection.Assembly.GetExecutingAssembly().FullName,
                ApplicationIdentifier     = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name,
                ApplicationVersion        = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
                EditorsFamilyName         = editorsFamilyName,
                EditorsGivenName          = editorsGivenName,
                EditorsOrganisationName   = editorsOrganisationName
            };

            var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc2X3, XbimStoreType.EsentDatabase);

            //Begin a transaction as all changes to a model are ACID
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //create a project
                project = model.Instances.New <IfcProject>();
                //set the units to SI (metres)
                project.Initialize(ProjectUnits.SIUnitsUK);
                project.Name = projectName;
                project.UnitsInContext.SetOrChangeSiUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE, null);
                //now commit the changes, else they will be rolled back at the end of the scope of the using statement
                txn.Commit();
            }
            return(model);
        }
Example #9
0
        private IfcStore CreateAndInitModel(string projectname)
        {
            //first we need register essential information for the project
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "fzm",
                ApplicationFullName       = "IFC Model_Alignment for Buiding",
                ApplicationIdentifier     = "",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "FU",
                EditorsGivenName          = "Zhongmin",
                EditorsOrganisationName   = "TJU"
            };
            //create model by using method in IfcStore class,using memory mode,and IFC4x1 format
            var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4x1, XbimStoreType.InMemoryModel);

            //begin a transition when do any change in a model
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //add new IfcProject item to a certain container
                var project = model.Instances.New <IfcProject>
                                  (p =>
                {
                    //Set the units to SI (mm and metres)
                    p.Initialize(ProjectUnits.SIUnitsUK);
                    p.Name = projectname;
                });
                // Now commit the changes, else they will be rolled back
                // at the end of the scope of the using statement
                txn.Commit();
            }
            return(model);
        }
        [TestMethod]        public void IfcStoreInitialisationTest()
        {
            var credentials = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "XbimTest1",
                ApplicationDevelopersName = "Tester",
                EditorsOrganisationName   = "XbimTeam"
            };

            using (var store = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4, XbimStoreType.EsentDatabase))
            {
                using (var txn = store.BeginTransaction())
                {
                    var project = store.Instances.New <Ifc4.Kernel.IfcProject>();
                    project.Initialize(ProjectUnits.SIUnitsUK);
                    txn.Commit();
                }
                store.SaveAs("esent4.ifc");
                store.Close();
            }

            using (var store = IfcStore.Create(credentials, XbimSchemaVersion.Ifc2X3, XbimStoreType.EsentDatabase))
            {
                using (var txn = store.BeginTransaction())
                {
                    var project = store.Instances.New <Ifc2x3.Kernel.IfcProject>();
                    project.Initialize(ProjectUnits.SIUnitsUK);
                    txn.Commit();
                }
                store.SaveAs("esent2x3.ifc");
                store.Close();
            }
        }
        /// <summary>
        /// Creates a model
        /// </summary>
        /// <param name="projectName">desired project name</param>
        /// <param name="credentials">XBIM Credentials, used inside the Dyn package</param>
        /// <returns></returns>
        public IfcStore CreateModel(string projectName, XbimEditorCredentials credentials)
        {
            // extract names and call internal method
            var model = CreateModel(projectName, credentials.EditorsFamilyName, credentials.EditorsGivenName);

            return(model);
        }
Example #12
0
        /// <summary>
        /// Sets up the basic parameters any model must provide, units, ownership etc
        /// </summary>
        /// <param name="projectName">Name of the project</param>
        /// <returns></returns>
        private static IfcStore CreateandInitModel(string projectName)
        {
            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "Zhu Xi",
                ApplicationFullName       = "Create DSM System for Jiangya Dam",
                ApplicationIdentifier     = "DSMSystem.exe",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "Zhu",
                EditorsGivenName          = "Xi",
                EditorsOrganisationName   = "xBimTeam"
            };
            //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database
            //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required

            var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

            //Begin a transaction as all changes to a model are ACID
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //create a project
                var project = model.Instances.New <IfcProject>();
                //set the units to SI (mm and metres)
                //project.Initialize(ProjectUnits.SIUnitsUK);
                project.Name = projectName;
                //now commit the changes, else they will be rolled back at the end of the scope of the using statement
                txn.Commit();
            }
            return(model);
        }
        public static void Update()
        {
            const string fileName = "SampleHouse.ifc";
            var          editor   = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "xBIM Team",
                ApplicationFullName       = "xBIM Toolkit",
                ApplicationIdentifier     = "xBIM",
                ApplicationVersion        = "4.0",
                EditorsFamilyName         = "Santini Aichel",
                EditorsGivenName          = "Johann Blasius",
                EditorsOrganisationName   = "Independent Architecture"
            };

            using (var model = IfcStore.Open(fileName, editor))
            {
                //get existing door from the model
                var id      = "3cUkl32yn9qRSPvBJVyWYp";
                var theDoor = model.Instances.FirstOrDefault <IfcDoor>(d => d.GlobalId == id);

                //open transaction for changes
                using (var txn = model.BeginTransaction("Doors update"))
                {
                    //create new property set with two properties
                    var pSetRel = model.Instances.New <IfcRelDefinesByProperties>(r =>
                    {
                        r.GlobalId = Guid.NewGuid();
                        r.RelatingPropertyDefinition = model.Instances.New <IfcPropertySet>(pSet =>
                        {
                            pSet.Name = "New property set";
                            //all collections are always initialized
                            pSet.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                            {
                                p.Name         = "First property";
                                p.NominalValue = new IfcLabel("First value");
                            }));
                            pSet.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>(p =>
                            {
                                p.Name         = "Second property";
                                p.NominalValue = new IfcLengthMeasure(156.5);
                            }));
                        });
                    });

                    //change the name of the door
                    theDoor.Name += "_checked";
                    //add properties to the door
                    pSetRel.RelatedObjects.Add(theDoor);

                    //commit changes
                    txn.Commit();
                }
            }
        }
Example #14
0
        public static IfcStore CreateandInitModel()
        {
            var credentials = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "Construction Software inc.",
                ApplicationFullName       = "Ifc sample programme",
                ApplicationDevelopersName = "Construction Programmers Ltd",
                EditorsOrganisationName   = "XbimTeam",
                EditorsFamilyName         = "Bloggs",
                EditorsGivenName          = "Jo",
                ApplicationVersion        = "2.0.1"
            };


            var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel); //create an empty model

            //Begin a transaction as all changes to a model are transacted
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //set up a project and initialise the defaults
                var project = model.Instances.New <IfcProject>();
                project.Initialize(ProjectUnits.SIUnitsUK);
                model.CalculateModelFactors(); //need to recalculate model factors
                project.Name = "Test";
                //create a building
                var building = model.Instances.New <IfcBuilding>();
                building.Name = "Building";
                //building.ElevationOfRefHeight = elevHeight;
                building.CompositionType = IfcElementCompositionEnum.ELEMENT;

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

                if (localPlacement != null && localPlacement.RelativePlacement == null)
                {
                    localPlacement.RelativePlacement = model.Instances.New <IfcAxis2Placement3D>();
                }
                if (localPlacement != null)
                {
                    var placement = localPlacement.RelativePlacement as IfcAxis2Placement3D;
                    if (placement != null)
                    {
                        placement.Location = model.Instances.New <IfcCartesianPoint>(p => p.SetXYZ(0.0, 0.0, 0.0));
                    }
                }
                project.AddBuilding(building);
                //commit changes

                txn.Commit();
            }
            return(model);
        }
 public bool Convert(FacilityType facility, IfcStore model = null)
 {
     if (model == null)
     {
         var credentials = new XbimEditorCredentials();
         _model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.EsentDatabase);
     }
     else
     {
         _model = model;
     }
     return(WriteFacility(facility));
 }
Example #16
0
        public static CostModel Convert(TeSoupis soupis)
        {
            unitCache.Clear();

            // information about the application, person and organisation
            // who created the file
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "Martin Cerny",
                ApplicationFullName       = soupis.Zdroj.ToString(),
                ApplicationIdentifier     = soupis.Zdroj.ToString(),
                ApplicationVersion        = "1.0",
                //your user
                EditorsFamilyName       = Environment.UserName,
                EditorsGivenName        = "",
                EditorsOrganisationName = Environment.UserDomainName
            };

            var stavba = soupis.STAVBA.FirstOrDefault();
            var model  = new CostModel(credentials, stavba.Nazev);

            using (var txn = model.BeginTransaction())
            {
                // currency
                var costUnit = model.Create.MonetaryUnit(u => u.Currency = soupis.Mena.ToString());
                model.Project.Units.Add(costUnit);

                // project information
                model.Project.LongName = stavba.SPOPIS;
                model.Project.Address  = model.Create.PostalAddress(a => a.AddressLines.Add(stavba.Misto));

                var jkso = ProcessJKSO(model, soupis);

                // process all sites
                foreach (var s in soupis.STAVBA)
                {
                    // root element
                    var schedule = new CostSchedule(model, s.Cislo);

                    // subjects (client, supplier)
                    ProcessActors(model, schedule, s.SUBJEKT);

                    // schedule items and classification
                    ProcessObjects(model, schedule, s.OBJEKT, jkso);
                }

                // commit changes
                txn.Commit();
                return(model);
            }
        }
Example #17
0
        private static string CreateFederation(XbimSchemaVersion schema, XbimEditorCredentials credentials, List <string> modelsNames)
        {
            var fedName = string.Format(@"federation{0}.xbim", schema);

            using (var ifcStore = IfcStore.Create(fedName, credentials, schema))
            {
                foreach (var modelName in modelsNames)
                {
                    ifcStore.AddModelReference(modelName, "Organisation", "Role");
                }
                ifcStore.Close();
            }
            return(fedName);
        }
        public static Dictionary <string, object> AddDirectShapeComponents(
            IfcStore model,
            XbimEditorCredentials credentials,
            List <Element> elements,
            string ifcElementType,
            string ifcSpatialStructure)
        {
            var counter = 0;

            // Note: no transaction is required -> will be opened in the toolkit function
            foreach (var element in elements)
            {
                // init transporter for each element geometry
                var transporter = new DirectShapeToIfc();

                // --- add geometry to transporter ---
                InsertShape(element, ref transporter);

                // --- add placement to transporter ---
                var location = element.Solids?.FirstOrDefault()?.Centroid();
                if (location != null)
                {
                    transporter.location.Position = new Point3D(location.X, location.Y, location.Z); // insert Revit coordinates into transporter
                }
                else
                {
                    transporter.location.Position = new Point3D(0, 0, 0);
                }

                // use IfcBridgeToolKit to generate a new IfcBuildingElement instance in the current model
                var productService = new ProductService();
                productService.AddBuildingElement(
                    ref model,                               // the Ifc Model
                    transporter,                             // the container for all geometry-related content
                    "BuildingElement " + counter.ToString(), // the bldElement's name
                    ifcElementType,                          // desired IfcBuildingElement subclass
                    "local",                                 // placement method
                    ifcSpatialStructure);                    // spatial structure element the component should belong to


                // increase counter
                counter++;
            }
            //  return model;
            return(new Dictionary <string, object>
            {
                { "IfcModel", model }
            });
        }
Example #19
0
        /// <summary>
        /// Make a model containing a project and a building
        /// </summary>
        /// <returns></returns>
        private IfcStore InitializeModel(BaseUnits units = BaseUnits.Meters)
        {
            var creds = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "Digital Alchemy",
                ApplicationFullName       = "Simergy/Pegasus",
                ApplicationIdentifier     = "hello.exe",
                ApplicationVersion        = "1.0",
            };

            IfcStore model = IfcStore.Create(creds, XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

            CreateProject(model, units);
            return(model);
        }
Example #20
0
        public void CreateFederationFromStore()
        {
            //Xbim.IO.

            var credentials = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "TestApp",
                ApplicationDevelopersName = "TestApp",
                EditorsOrganisationName   = "Test"
            };

            TestFederation <Ifc4.Kernel.IfcProject>(XbimSchemaVersion.Ifc4, credentials, true);
            TestFederation <Ifc2x3.Kernel.IfcProject>(XbimSchemaVersion.Ifc2X3, credentials, true);
            TestFederation <Ifc4.Kernel.IfcProject>(XbimSchemaVersion.Ifc4, credentials, false);
            TestFederation <Ifc2x3.Kernel.IfcProject>(XbimSchemaVersion.Ifc2X3, credentials, false);
        }
        public static Dictionary <string, object> Credentials(string FamilyName, string FirstName, string organization)
        {
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "IfcBridgeToolKit",
                ApplicationFullName       = "TUM_CMS_IfcBridgeToolkit",
                ApplicationVersion        = "1.1",
                EditorsFamilyName         = FamilyName,
                EditorsGivenName          = FirstName,
                EditorsOrganisationName   = organization
            };

            return(new Dictionary <string, object>
            {
                { "credentials", credentials }
            });
        }
        public void ReadIfcHeaderTest()
        {
            var modelStore = new HeuristicModelProvider();

            var schemaVersion = modelStore.GetXbimSchemaVersion("TestFiles\\SampleHouse4.ifc");

            Assert.IsTrue(schemaVersion == XbimSchemaVersion.Ifc4);
            schemaVersion = modelStore.GetXbimSchemaVersion("TestFiles\\4walls1floorSite.ifc");
            Assert.IsTrue(schemaVersion == XbimSchemaVersion.Ifc2X3);

            //first run with a memory model opeing Ifc4 file
            long count;
            var  credentials = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "XbimTest1",
                ApplicationDevelopersName = "Tester",
                EditorsOrganisationName   = "XbimTeam"
            };

            using (var store = IfcStore.Open("TestFiles\\SampleHouse4.ifc"))
            {
                count = store.Instances.Count;
                Assert.IsTrue(count > 0, "Should have more than zero instances");
                store.Close();
            }
            //create esent files and check them , a size of 1MB will cause Esent to be used
            using (var store = IfcStore.Open("TestFiles\\SampleHouse4.ifc", credentials, 1.0))
            {
                Assert.IsTrue(count == store.Instances.Count, "Should have the same number of instances as the memory model");
                store.Close();
            }

            //now repeat for Ifc2x3
            using (var store = IfcStore.Open("TestFiles\\4walls1floorSite.ifc"))
            {
                count = store.Instances.Count;
                Assert.IsTrue(count > 0, "Should have more than zero instances");
                store.Close();
            }
            //create xbim files and check them , a size of 1MB will cause Esent to be used
            using (var store = IfcStore.Open("TestFiles\\4walls1floorSite.ifc", null, 0.1))
            {
                Assert.IsTrue(count == store.Instances.Count, "Should have the same number of instances as the memory model");
                store.Close();
            }
        }
Example #23
0
        public void Dpow2CobieLite2Ifc()
        {
            var          pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "..\\..\\Export";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var d2C      = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                d2C.Convert();

                var outputIfc       = Path.Combine(dir, stage.Name + ".DPoW.ifc");
                var outputCobieJson = Path.Combine(dir, stage.Name + ".DPoW.json");
                var outputCobieXml  = Path.Combine(dir, stage.Name + ".DPoW.xml");
                facility.WriteJson(outputCobieJson);
                facility.WriteXml(outputCobieXml);
                var credentials = new XbimEditorCredentials()
                {
                    ApplicationDevelopersName = "XbimTeam",
                    ApplicationFullName       = "Xbim.Exchanger",
                    EditorsOrganisationName   = "Xbim Development Team",
                    EditorsFamilyName         = "Xbim Tester",
                    ApplicationVersion        = "3.0"
                };
                using (var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
                {
                    using (var txn = model.BeginTransaction("Convert from COBieLite"))
                    {
                        var c2Ifc = new CoBieLiteToIfcExchanger(facility, model);
                        c2Ifc.Convert();
                        txn.Commit();
                    }
                    model.SaveAs(outputIfc, IfcStorageType.Ifc);

                    if (facility.AssetTypes != null)
                    {
                        Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType <IfcTypeObject>().Count());
                    }
                }
            }
        }
        public void NoHeaderTest()
        {
            var editor = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "You",
                ApplicationFullName       = "Your app",
                ApplicationIdentifier     = "Your app ID",
                ApplicationVersion        = "4.0",
                //your user
                EditorsFamilyName       = "Santini Aichel",
                EditorsGivenName        = "Johann Blasius",
                EditorsOrganisationName = "Independent Architecture"
            };

            const string file    = "header_test.ifc";
            const string xmlfile = "header_test.ifcxml";

            //normal way to create and save with memory model
            using (var model = IfcStore.Create(editor, XbimSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
            {
                CreateWall(model);
                model.SaveAs(file);
                model.SaveAs(xmlfile);
                var c = Directory.GetCurrentDirectory();
            }
            using (var model = IfcStore.Open(file))
            {
                CheckWall(model);
            }

            //nullified header schema in memory model
            using (var model = IfcStore.Create(editor, XbimSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
            {
                CreateWall(model);
                model.Header.FileSchema = null;
                Assert.IsNull(model.Header.FileSchema);
                model.SaveAs(file);
            }
            using (var model = IfcStore.Open(file))
            {
                CheckWall(model);
            }
        }
Example #25
0
        public static IfcStore CreateandInitModel(string projectName, IfcUnitAssignment unitType)
        {
            IfcSIUnit unit = unitType.Units.FirstOrDefault(u => (u as IfcSIUnit).UnitType == IfcUnitEnum.LENGTHUNIT) as IfcSIUnit;

            if (unit.Name == IfcSIUnitName.METRE)
            {
                CADConfig.Units = linearUnitsType.Meters;
            }
            else
            {
                CADConfig.Units = linearUnitsType.Millimeters;
            }

            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "Cad2Bim",
                ApplicationFullName       = "CadTo3D Application",
                ApplicationIdentifier     = "ThinkDev.exe",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "Team",
                EditorsGivenName          = "ThinkDev",
                EditorsOrganisationName   = "ThinkDevTeam"
            };
            //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database
            //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required

            var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);

            //Begin a transaction as all changes to a model are ACID
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //create a project
                var project = model.Instances.New <IfcProject>();
                //set the units to SI (mm and metres)
                project.InitProject(CADConfig.Units);
                project.Name = projectName;
                //now commit the changes, else they will be rolled back at the end of the scope of the using statement
                txn.Commit();
            }
            return(model);
        }
        public static Dictionary <string, object> AddBridgeStructure(IfcStore model, XbimEditorCredentials credentials, string bridgeName, string bridgeDescription)
        {
            try
            {
                var bridgeCreator = new ModelSetupService();
                bridgeCreator.CreateIfcBridgeEntity(ref model, bridgeName, bridgeDescription);
                bridgeCreator.CreateIfcBridgePartEntities(ref model);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            // return model; // return directory to Ifc Model
            return(new Dictionary <string, object>
            {
                { "IfcModel", model }
            });
        }
Example #27
0
        /// <summary>
        /// Creat the federated file
        /// </summary>
        /// <param name="author">Author name</param>
        /// <param name="organisation">Orgsnisation Name</param>
        /// <param name="prjName">Project Name</param>
        /// <param name="ifcVersion">Ifc schema version</param>
        /// <param name="storage">Type of xbim file store</param>
        public void Create(string author, string organisation, string prjName = null,
                           IfcSchemaVersion ifcVersion = IfcSchemaVersion.Ifc4, XbimStoreType storage = XbimStoreType.InMemoryModel
                           )
        {
            var creds = new XbimEditorCredentials
            {
                ApplicationIdentifier     = "xBIM",
                ApplicationDevelopersName = "xBIM Team",
                EditorsFamilyName         = author,
                EditorsOrganisationName   = organisation,
                ApplicationVersion        = "1.0"
            };

            _fedModel = IfcStore.Create(creds, ifcVersion, storage); //create in memory
            using (var txn = _fedModel.BeginTransaction())
            {
                var project = _fedModel.Instances.New <IfcProject>();
                project.Name = prjName ?? "Undefined";
                txn.Commit();
            }
        }
Example #28
0
        public static IfModel New(string projectName, string buildingName, bool save, string filepath = "Untitled")
        {
            //first we need to set up some credentials for ownership of data in the new model
            var credentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "ITI ",
                ApplicationFullName       = " ",
                ApplicationIdentifier     = " ",
                ApplicationVersion        = "1.0",
                EditorsFamilyName         = "ITI ",
                EditorsGivenName          = "ITI ",
                EditorsOrganisationName   = " ITI"
            };
            //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database
            //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required

            var     model   = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);
            IfModel ifModel = new IfModel(model);

            //Begin a transaction as all changes to a model are ACID
            using (var txn = model.BeginTransaction("Initialise Model"))
            {
                //create a project
                var project = model.Instances.New <IfcProject>();

                //set the units to SI (mm and metres)
                project.Initialize(ProjectUnits.SIUnitsUK);
                project.Name = projectName;
                //now commit the changes, else they will be rolled back at the end of the scope of the using statement
                txn.Commit();
            }
            if (save)
            {
                model.SaveAs(filepath);
            }

            ifModel.IfBuildings.Add(IfBuilding.New(ifModel, buildingName));

            return(ifModel);
        }
        public static Dictionary <string, object> InitIfcModel(string projectName, XbimEditorCredentials credentials)
        {
            IfcStore model;

            try
            {
                var modelCreator = new ModelSetupService();
                model = modelCreator.CreateModel(projectName, credentials);
                modelCreator.CreateIfcSite(ref model, "BridgeSite");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            // return model; // return Ifc Model
            return(new Dictionary <string, object>
            {
                { "IfcModel", model }
            });
        }
Example #30
0
        public void IfcStoreRegionWorldCoordTest()
        {
            XbimMatrix3D WorldCoord = new XbimMatrix3D(-0.228171504575237, -0.973620955248947, 0, 0, 0.973620955248947, -0.228171504575237, 0, 0, 0, 0, 1, 0, 543188712, 259041729, 16000, 1);
            var          creds      = new XbimEditorCredentials();

            using (IfcStore model = IfcStore.Create(@"RegionTest.xbim", creds, XbimSchemaVersion.Ifc2X3))
            {
                var geomStore = model.GeometryStore;
                using (var txn = geomStore.BeginInit())
                {
                    //ADD A REGIONCOLLECTION
                    var regions = new XbimRegionCollection();
                    regions.ContextLabel = 50;
                    var bb = new XbimRect3D(new XbimPoint3D(1, 1, 1), new XbimVector3D(10, 20, 30));
                    regions.Add(new XbimRegion("region1", bb, 100, WorldCoord));
                    txn.AddRegions(regions);

                    txn.Commit();
                }
                model.Close();
            }

            using (var model = IfcStore.Open(@"RegionTest.xbim"))
            {
                var geomStore = model.GeometryStore;
                Assert.IsFalse(geomStore.IsEmpty);
                using (var reader = geomStore.BeginRead())
                {
                    Assert.IsTrue(reader.ContextIds.Any());
                    var regioncoll = reader.ContextRegions.First();
                    var region     = regioncoll.FirstOrDefault();
                    Assert.AreEqual(WorldCoord.OffsetX, region.WorldCoordinateSystem.OffsetX, 1.0);
                    Assert.AreEqual(WorldCoord.OffsetY, region.WorldCoordinateSystem.OffsetY, 1.0);
                    Assert.AreEqual(WorldCoord.OffsetZ, region.WorldCoordinateSystem.OffsetZ, 1.0);
                }
                model.Close();
            }
        }