Esempio n. 1
0
        static ModelFactory()
        {
            FileProviders.Add((path) =>
            {
                return(MemoryModel.OpenRead(path));
            });
            FileProviders.Add((path) =>
            {
                // return Esent DB
                return(Ifc.IfcStore.Open(path, null, 0, (pct, o) => { }));
            });

            FileProviders.Add((path) =>
            {
                // return Memory DB
                return(Ifc.IfcStore.Open(path, null, null, (pct, o) => { }));
            });

            ModelProviders.Add((factory) =>
            {
                return(new MemoryModel(factory));
            });
            ModelProviders.Add((factory) =>
            {
                return(EsentModel.CreateTemporaryModel(factory));
            });
        }
        public void EsentInOuterScope()
        {
            //creating esent model in outer scope for better control
            using (var esent = EsentModel.CreateModel(new EntityFactoryCobieExpress(), "test2.xbim"))
            {
                using (var model = new CobieModel(esent))
                {
                    using (var txn = model.BeginTransaction("Creation"))
                    {
                        var wall = model.Instances.New <CobieComponent>(w => w.Name = "Wall A");
                        txn.Commit();
                    }
                }

                //we can close Esent model or do anything we need with it
                esent.Close();
            }

            using (var model = CobieModel.OpenEsent("test2.xbim"))
            {
                var wall = model.Instances.FirstOrDefault <CobieComponent>();
                Assert.IsNotNull(wall);
                Assert.IsTrue(wall.Name == "Wall A");
            }
        }
        /// <summary>
        /// Creates a new Persistent model store
        /// </summary>
        /// <param name="ifcVersion"></param>
        /// <param name="storagePath"></param>
        /// <returns></returns>
        public override IModel Create(XbimSchemaVersion ifcVersion, string dbPath)
        {
            var factory = GetFactory(ifcVersion);
            var model   = EsentModel.CreateModel(factory, dbPath);

            return(model);
        }
Esempio n. 4
0
        public void EsentMultiTransactionTest()
        {
            const string file = "test.ifc";

            using (var model = EsentModel.CreateTemporaryModel(new EntityFactory()))
            {
                IfcCurtainWall wall;
                using (var txn = model.BeginTransaction("New wall"))
                {
                    wall = model.Instances.New <IfcCurtainWall>(w => w.Name = "Name");
                    txn.Commit();
                }
                using (var txn = model.BeginTransaction("Edit wall"))
                {
                    wall.Description = "Description";
                    txn.Commit();
                }
                model.SaveAs(file);
            }

            using (var model = EsentModel.CreateTemporaryModel(new EntityFactory()))
            {
                model.CreateFrom(file, null, null, true, true);
                var wall = model.Instances.FirstOrDefault <IfcCurtainWall>();
                Assert.IsTrue(wall.Name == "Name");
                Assert.IsTrue(wall.Description == "Description");
            }
        }
        public void CanUpgradeDbStucture()
        {
            using (var m = new EsentModel(new EntityFactoryIfc4()))
            {
                m.Open(@"GeometryCacheTestFiles\Monolith_v10.xBIM", XbimDBAccess.Exclusive);
                Assert.AreEqual(1, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v10 should be 1");

                var updated = m.EnsureGeometryTables();
                Assert.AreEqual(updated, true, "Should complete returning true");

                m.DeleteGeometryCache();
                Assert.AreEqual(0, m.GeometrySupportLevel,
                                "GeometrySupportLevel for Monolith_v10 should be 0 after removing it.");

                m.Close();
            }

            using (var store = IfcStore.Open(@"GeometryCacheTestFiles\Monolith_v10.xBIM"))
            {
                var geometryStore = store.GeometryStore;

                if (geometryStore == null)
                {
                    throw new System.Exception("Invalid store");
                }

                using (var geometryTransaction = geometryStore.BeginInit())
                {
                    // nothing to do here.
                }
                store.Close();
            }
        }
Esempio n. 6
0
        public static CobieModel OpenEsent(string esentDB)
        {
            var model = new EsentModel(new EntityFactory());

            model.Open(esentDB, XbimDBAccess.ReadWrite);
            return(new CobieModel(model));
        }
        private EsentModel CreateEsentModel(XbimSchemaVersion schema, int codePageOverride)
        {
            var factory = GetFactory(schema);
            var model   = new EsentModel(factory)
            {
                CodePageOverride = codePageOverride
            };

            return(model);
        }
        /// <summary>
        /// Creates a new model store, with the consumer choosing the implementation
        /// </summary>
        /// <param name="ifcVersion"></param>
        /// <param name="storageType"></param>
        /// <returns></returns>
        public override IModel Create(XbimSchemaVersion ifcVersion, XbimStoreType storageType)
        {
            var factory = GetFactory(ifcVersion);

            if (storageType == XbimStoreType.EsentDatabase)
            {
                return(EsentModel.CreateTemporaryModel(factory));
            }

            return(new MemoryModel(factory));
        }
Esempio n. 9
0
        public CobieModel(bool esentDB)
        {
            _esentDB = esentDB;
            if (esentDB)
            {
                _model = EsentModel.CreateTemporaryModel(new EntityFactory());
            }
            else
            {
                _model = new MemoryModel(new EntityFactory());
            }

            InitEvents();
        }
Esempio n. 10
0
        public void SearchTypeHandling()
        {
            using (var model = EsentModel.CreateTemporaryModel(new EntityFactory()))
            {
                InitModel(model);
                AssertModel(model);
            }

            using (var model = new MemoryModel(new EntityFactory()))
            {
                InitModel(model);
                AssertModel(model);
            }
        }
Esempio n. 11
0
        public static CobieModel OpenStep21(Stream input, long streamSize, bool esentDB = false)
        {
            if (esentDB)
            {
                var esent = new EsentModel(new EntityFactory());
                esent.CreateFrom(input, streamSize, IfcStorageType.Stp, "temp.xbim", null, true);
                return(new CobieModel(esent));
            }

            var model = new MemoryModel(new EntityFactory());

            model.LoadStep21(input, streamSize);
            return(new CobieModel(model));
        }
Esempio n. 12
0
        public void SaveAsStep21Zip(string file)
        {
            if (_esentDB)
            {
                EsentModel.SaveAs(file, IfcStorageType.StpZip);
                return;
            }

            using (var stream = File.Create(file))
            {
                MemoryModel.SaveAsStep21Zip(stream);
                stream.Close();
            }
        }
Esempio n. 13
0
        public static CobieModel OpenStep21(string input, bool esentDB = false)
        {
            if (esentDB)
            {
                var db    = Path.ChangeExtension(input, ".xbim");
                var esent = new EsentModel(new EntityFactory());
                esent.CreateFrom(input, db, null, true, true, IfcStorageType.Stp);
                return(new CobieModel(esent));
            }

            var model = new MemoryModel(new EntityFactory());

            model.LoadStep21(input);
            return(new CobieModel(model));
        }
Esempio n. 14
0
 public void SaveAsEsent(string dbName)
 {
     if (EsentModel != null && string.Equals(EsentModel.DatabaseName, dbName, StringComparison.OrdinalIgnoreCase))
     {
         //it is ESENT model already and all changes are persisted automatically.
     }
     else
     {
         using (var esent = new EsentModel(new EntityFactory()))
         {
             esent.CreateFrom(_model, dbName);
             esent.Close();
         }
     }
 }
        public void FileVersionIsCorrect()
        {
            var m = new EsentModel(new EntityFactoryIfc4());

            m.Open("GeometryCacheTestFiles\\Monolith-NoGeomTables.xBIM", XbimDBAccess.ReadWrite);
            Assert.AreEqual(0, m.GeometrySupportLevel, "GeometrySupportLevel should be 0");
            m.Close();

            m.Open("GeometryCacheTestFiles\\Monolith_Nogeom_Version1Schema.xBIM");
            Assert.AreEqual(0, m.GeometrySupportLevel, "GeometrySupportLevel should be 0");
            m.Close();

            m.Open("GeometryCacheTestFiles\\Monolith_v10.xBIM");
            Assert.AreEqual(1, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v10 should be 1");
            m.Close();

            m.Open("GeometryCacheTestFiles\\Monolith_v20.xBIM");
            Assert.AreEqual(2, m.GeometrySupportLevel, "GeometrySupportLevel for Monolith_v20 should be 2");
            m.Close();
        }
Esempio n. 16
0
        public void EsentDataRetrieval()
        {
            using (var model = new EsentModel(new EntityFactory()))
            {
                model.CreateFrom("4walls1floorSite.ifc", null, null, true);

                var walls = model.Instances.Where <IIfcWall>(w => w.Name != null);
                Assert.AreEqual(4, walls.Count());

                //this is correct now (fixed to search for interface implementations)
                var entities = model.Instances.Where <IPersistEntity>(i => true).ToList();

                //this doesn't bring in non-indexed classes
                var entities2 = model.Instances.OfType <IPersistEntity>().ToList();

                var totalCount = model.Instances.Count;
                Assert.AreEqual(totalCount, entities.Count);
                Assert.AreEqual(totalCount, entities2.Count);
            }
        }
        /// <summary>
        /// Gets the IFC Schema version for a model
        /// </summary>
        /// <param name="modelPath">Path to a model in any supported format (IFC, IfcXml, IfcZip, or XBIM)</param>
        /// <returns></returns>
        public override XbimSchemaVersion GetXbimSchemaVersion(string modelPath)
        {
            var storageType = modelPath.StorageType();

            if (storageType == StorageType.Invalid)
            {
                return(XbimSchemaVersion.Unsupported);
            }
            if (storageType != StorageType.Xbim)
            {
                return(MemoryModel.GetSchemaVersion(modelPath));
            }

            // Have to use Esent for internal format
            var            stepHeader       = EsentModel.GetStepFileHeader(modelPath);
            IList <string> schemas          = stepHeader.FileSchema.Schemas;
            var            schemaIdentifier = string.Join(", ", schemas);

            foreach (var schema in schemas)
            {
                if (string.Compare(schema, "Ifc4", StringComparison.OrdinalIgnoreCase) == 0 ||
                    schema.StartsWith("Ifc4RC", StringComparison.OrdinalIgnoreCase))
                {
                    return(XbimSchemaVersion.Ifc4);
                }
                if (string.Compare(schema, "Ifc4x1", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc4x1);
                }
                if (string.Compare(schema, "Ifc2x3", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
                if (schema.StartsWith("Ifc2x", StringComparison.OrdinalIgnoreCase)) //return this as 2x3
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
            }

            return(XbimSchemaVersion.Unsupported);
        }
        /// <summary>
        /// Persists the model to a permanent store
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fileName"></param>
        /// <param name="progDelegate"></param>
        public override void Persist(IModel model, string fileName, ReportProgressDelegate progDelegate = null)
        {
            if (model is EsentModel esentModel)
            {
                var fullSourcePath = Path.GetFullPath(esentModel.DatabaseName);
                var fullTargetPath = Path.GetFullPath(fileName);
                if (string.Compare(fullSourcePath, fullTargetPath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return; // do nothing - don't save on top of self
                }
            }

            // Create a new Esent model for this Model => Model copy
            var factory = GetFactory(model.SchemaVersion);

            using (var esentDb = new EsentModel(factory))
            {
                esentDb.CreateFrom(model, fileName, progDelegate);
                esentDb.Close();
            }
        }
Esempio n. 19
0
        public static void Run()
        {
            const string   file    = "SampleModel.ifc";
            const string   db      = "sample.xbim";
            var            schema  = MemoryModel.GetSchemaVersion(file);
            IEntityFactory factory = null;

            switch (schema)
            {
            case XbimSchemaVersion.Ifc4:
                factory = new Xbim.Ifc4.EntityFactoryIfc4();
                break;

            case XbimSchemaVersion.Ifc4x1:
                factory = new Xbim.Ifc4.EntityFactoryIfc4x1();
                break;

            case XbimSchemaVersion.Ifc2X3:
                factory = new Xbim.Ifc2x3.EntityFactoryIfc2x3();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(schema));
            }
            using (var model = new EsentModel(factory))
            {
                model.CreateFrom(file, db);
                model.Close();
            }

            IfcStore.ModelProviderFactory.UseEsentModelProvider();
            using (var model = IfcStore.Open(db))
            {
                // ... do anything you need to do ...
            }
        }