Exemplo n.º 1
0
        public mvdXML GetMvd(XbimSchemaVersion schema, string languageCode, string name, string definition, string code, string classificationProperty,
                             Func <IContextEntity, bool> contextFilter = null,
                             Func <IfcPropertySetTemplate, bool> requirementSetFilter = null,
                             Func <IfcPropertyTemplate, bool> requirementsFilter      = null)
        {
            var converter = new Mvd.Converter(schema, languageCode, contextFilter, requirementSetFilter, requirementsFilter);

            return(converter.Convert(this, name, definition, code, classificationProperty));
        }
Exemplo n.º 2
0
        /// <summary>
        /// You can use this function to open IFC model from a <see cref="Stream"/>.
        /// You need to know file type (IFC, IFCZIP, IFCXML) and schema type (IFC2x3 or IFC4) to be able to use this function.
        /// If you don't know, you should the overloaded <see cref="Open(string, XbimEditorCredentials, double?, ReportProgressDelegate, XbimDBAccess, int)"/>
        /// method which takes file paths as an argument, and can automatically detect schema and file type.
        /// If are opening an *.xbim file you should also use the path-based overload because Esent database needs to operate
        /// on the file and this function will have to create temporal file if it is not a file stream.
        /// If the input is a FileStream, be aware this method may call <see cref="Stream.Close"/> on it to keep exclusive access.
        /// </summary>
        /// <param name="stream">Stream of data</param>
        /// <param name="dataType">Type of data (*.ifc, *.ifcxml, *.ifczip)</param>
        /// <param name="schema">IFC schema (IFC2x3, IFC4). Other schemas are not supported by this class.</param>
        /// <param name="modelType">Type of model to be used. You can choose between EsentModel and MemoryModel</param>
        /// <param name="editorDetails">Optional details. You should always pass these if you are going to change the data.</param>
        /// <param name="accessMode">Access mode to the stream. This is only important if you choose EsentModel. MemoryModel is completely in memory so this is not relevant</param>
        /// <param name="progDelegate">Progress reporting delegate</param>
        /// <param name="codePageOverride">
        /// A CodePage that will be used to read implicitly encoded one-byte-char strings. If -1 is specified the default ISO8859-1
        /// encoding will be used accoring to the Ifc specification. </param>
        /// <returns></returns>
        public static IfcStore Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimEditorCredentials editorDetails = null,
                                    XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1)
        {
            var newStore = new IfcStore();
            var model    = newStore.ModelProvider.Open(stream, dataType, schema, modelType, accessMode, progDelegate, codePageOverride);

            newStore.AssignModel(model, editorDetails, schema);
            return(newStore);
        }
Exemplo n.º 3
0
        public override IModel Create(XbimSchemaVersion ifcVersion, XbimStoreType storageType)
        {
            var factory = GetFactory(ifcVersion);

            if (storageType == XbimStoreType.EsentDatabase)
            {
                return(EsentModel.CreateTemporaryModel(factory));
            }
            throw new NotSupportedException($"{storageType} is not a supported Storage Type");
        }
        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));
        }
Exemplo n.º 6
0
        public static IModel Create(XbimSchemaVersion schema, Action <IModel> creation)
        {
            var f     = MemoryModel.GetFactory(schema);
            var model = new MemoryModel(f);

            using (var txn = model.BeginTransaction("Creation"))
            {
                creation(model);
                txn.Commit();
            }
            return(model);
        }
Exemplo n.º 7
0
        private static void PixelTextureTestCode(XbimSchemaVersion version)
        {
            var data = new List <byte[]>()
            {
                new byte[] { 0, 0, 255, 255 }, new byte[] { 0, 255, 255, 255 }, new byte[] { 255, 0, 255, 255 }, new byte[] { 255, 0, 0, 255 }
            };

            using (var model = new MemoryModel(new EntityFactoryIfc4()))
            {
                var create = new Create(model);
                using (var txn = model.BeginTransaction(""))
                {
                    var pt = create.PixelTexture(t => {
                        t.Height           = 2;
                        t.Width            = 2;
                        t.ColourComponents = 4;
                        t.RepeatS          = true;
                        t.RepeatT          = true;
                        t.Pixel.AddRange(data.Select(d => new IfcBinary(d)));
                    });
                    txn.Commit();
                }

                using (var stepFile = File.Create("XbimPixelTexture.ifc"))
                {
                    model.SaveAsStep21(stepFile);
                }
                using (var xmlFile = File.Create("XbimPixelTexture.ifcxml"))
                {
                    model.SaveAsXml(xmlFile, new XmlWriterSettings {
                        Indent = false
                    });
                }
            }

            Action <IModel> test = model => {
                var txt = model.Instances.FirstOrDefault <IIfcPixelTexture>();
                Assert.IsNotNull(txt);

                var pixels = txt.Pixel;
                AssertByteArrays(data, pixels);
            };

            using (var models = new ModelFactory("XbimPixelTexture.ifc"))
            {
                models.Do(test);
            }

            using (var models = new ModelFactory("XbimPixelTexture.ifcxml"))
            {
                models.Do(test);
            }
        }
Exemplo n.º 8
0
        private void AssignModel(IModel model, XbimEditorCredentials editorDetails, XbimSchemaVersion schema)
        {
            Model                 = model;
            Model.EntityNew      += Model_EntityNew;
            Model.EntityDeleted  += Model_EntityDeleted;
            Model.EntityModified += Model_EntityModified;
            FileName              = Model.Header.FileName.Name;
            SetupEditing(editorDetails);

            LoadReferenceModels();
            IO.Memory.MemoryModel.CalculateModelFactors(model);
        }
        /// <summary>
        /// Opens a model from the provided path, inferring model implementation based on format and model size
        /// </summary>
        /// <param name="path">Path to the model file, in any support IFC or XBIM format</param>
        /// <param name="schemaVersion"></param>
        /// <param name="ifcDatabaseSizeThreshHold"></param>
        /// <param name="progDelegate"></param>
        /// <param name="accessMode"></param>
        /// <param name="codePageOverride"></param>
        /// <returns></returns>
        public override IModel Open(string path, XbimSchemaVersion schemaVersion, double?ifcDatabaseSizeThreshHold = null,
                                    ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1)
        {
            var storageType = path.StorageType();

            if (storageType == StorageType.Xbim) //open the XbimFile
            {
                var model = CreateEsentModel(schemaVersion, codePageOverride);
                model.Open(path, accessMode, progDelegate);
                return(model);
            }
            else //it will be an IFC file if we are at this point
            {
                var    fInfo        = new FileInfo(path);
                double ifcMaxLength = (ifcDatabaseSizeThreshHold ?? DefaultIfcDatabaseSizeThreshHoldMb) * 1024 * 1024;
                // we need to make an Esent database, if ifcMaxLength<0 we use in memory
                if (ifcMaxLength >= 0 && fInfo.Length > ifcMaxLength)
                {
                    var tmpFileName = Path.GetTempFileName();
                    var model       = CreateEsentModel(schemaVersion, codePageOverride);
                    // We delete the XBIM on close as the consumer is not controlling the generation of the XBIM file
                    if (model.CreateFrom(path, tmpFileName, progDelegate, keepOpen: true, deleteOnClose: true))
                    {
                        return(model);
                    }

                    throw new FileLoadException(path + " file was not a valid IFC format");
                }
                else //we can use a memory model
                {
                    var model = CreateMemoryModel(schemaVersion);
                    if (storageType.HasFlag(StorageType.IfcZip) || storageType.HasFlag(StorageType.Zip) || storageType.HasFlag(StorageType.StpZip))
                    {
                        model.LoadZip(path, progDelegate);
                    }
                    else if (storageType.HasFlag(StorageType.Ifc) || storageType.HasFlag(StorageType.Stp))
                    {
                        model.LoadStep21(path, progDelegate);
                    }
                    else if (storageType.HasFlag(StorageType.IfcXml))
                    {
                        model.LoadXml(path, progDelegate);
                    }

                    // if we are looking at a memory model loaded from a file it might be safe to fix the file name in the
                    // header with the actual file loaded
                    FileInfo f = new FileInfo(path);
                    model.Header.FileName.Name = f.FullName;
                    return(model);
                }
            }
        }
        public void StampXbimApplication(XbimSchemaVersion schemaVersion, IModel model)
        {
            var assembly = model.GetType().GetTypeInfo().Assembly; //get the assembly that has created th emodel

            FileDescription = new StepFileDescription("2;1");
            FileName        = new StepFileName(DateTime.Now)
            {
                PreprocessorVersion =
                    string.Format("Processor version {0}",
                                  assembly.GetName().Version),
                OriginatingSystem = assembly.GetName().Name
            };
            FileSchema = new StepFileSchema(schemaVersion);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public static IEntityFactory GetFactory(XbimSchemaVersion schema)
        {
            switch (schema)
            {
            case XbimSchemaVersion.Ifc4:
                return(new Ifc4.EntityFactoryIfc4());

            case XbimSchemaVersion.Ifc4x1:
                return(new Ifc4.EntityFactoryIfc4x1());

            case XbimSchemaVersion.Ifc2X3:
                return(new Ifc2x3.EntityFactoryIfc2x3());

            case XbimSchemaVersion.Cobie2X4:
            case XbimSchemaVersion.Unsupported:
            default:
                throw new NotSupportedException($"Schema '{schema}' is not supported");
            }
        }
Exemplo n.º 13
0
        protected IEntityFactory GetFactory(XbimSchemaVersion type)
        {
            switch (type)
            {
            case XbimSchemaVersion.Ifc4:
                return(new Ifc4.EntityFactoryIfc4());

            case XbimSchemaVersion.Ifc4x1:
                return(new Ifc4.EntityFactoryIfc4x1());

            case XbimSchemaVersion.Ifc2X3:
                return(new Ifc2x3.EntityFactoryIfc2x3());

            case XbimSchemaVersion.Cobie2X4:
            case XbimSchemaVersion.Unsupported:
            default:
                throw new NotSupportedException("Schema '" + type + "' is not supported");
            }
        }
Exemplo n.º 14
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,
                           XbimSchemaVersion ifcVersion = XbimSchemaVersion.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();
            }
        }
Exemplo n.º 15
0
        public override IModel Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType,
                                    XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1)
        {
            if (modelType != XbimModelType.MemoryModel)
            {
                throw new ArgumentOutOfRangeException(nameof(modelType), "MemoryModelProvider only supports MemoryModel");
            }
            switch (dataType)
            {
            case StorageType.Xbim:
                throw new NotSupportedException("MemoryModelProvider cannot support opening XBIM Streams");

            case StorageType.IfcXml:
            {
                var model = CreateMemoryModel(schema);
                model.LoadXml(stream, stream.Length, progDelegate);
                return(model);
            }

            case StorageType.Stp:
            case StorageType.Ifc:
            {
                var model = CreateMemoryModel(schema);
                model.LoadStep21(stream, stream.Length, progDelegate);
                return(model);
            }

            case StorageType.IfcZip:
            case StorageType.StpZip:
            case StorageType.Zip:
            {
                var model = CreateMemoryModel(schema);
                model.LoadZip(stream, progDelegate);
                return(model);
            }

            default:
                throw new ArgumentOutOfRangeException("dataType");
            }
        }
Exemplo n.º 16
0
        private static List <string> CreateModels <T>(XbimSchemaVersion schema, XbimEditorCredentials credentials, bool useXbimFormat)
            where T : IInstantiableEntity, IIfcProject
        {
            var modelsNames = new List <string>();

            // write the files to disk so that the federation finds them
            //
            for (int i = 1; i < 3; i++)
            {
                var esentFileName = string.Format("model{0}{1}.xbim", i, schema);
                var ifcFileName   = Path.ChangeExtension(esentFileName, ".ifc");

                using (var model = IfcStore.Create(esentFileName, credentials, schema))
                {
                    using (var txn = model.BeginTransaction("Hello Wall"))
                    {
                        //there should always be one project in the model
                        var project = model.Instances.New <T>(p => p.Name = "Basic Creation");
                        //our shortcut to define basic default units
                        project.Initialize(ProjectUnits.SIUnitsUK);
                        txn.Commit();
                    }
                    model.SaveAs(ifcFileName, StorageType.Ifc);
                    model.Close();
                }
                if (useXbimFormat)
                {
                    modelsNames.Add(esentFileName);
                    File.Delete(ifcFileName);
                }
                else
                {
                    modelsNames.Add(ifcFileName);
                    File.Delete(esentFileName);
                }
            }
            return(modelsNames);
        }
Exemplo n.º 17
0
 public static IfcStore Create(XbimEditorCredentials editorDetails, XbimSchemaVersion ifcVersion, XbimStoreType storageType)
 {
     return(new IfcStore(storageType, ifcVersion, editorDetails));
 }
        private MemoryModel CreateMemoryModel(XbimSchemaVersion schema)
        {
            var factory = GetFactory(schema);

            return(new MemoryModel(factory));
        }
Exemplo n.º 19
0
 public abstract IModel Open(Stream data, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1);
Exemplo n.º 20
0
 public abstract IModel Open(string path, XbimSchemaVersion schema, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1);
        /// <summary>
        /// Opens a model from the provided stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="dataType"></param>
        /// <param name="schema"></param>
        /// <param name="modelType"></param>
        /// <param name="accessMode"></param>
        /// <param name="progDelegate"></param>
        /// <param name="codePageOverride"></param>
        /// <returns></returns>
        public override IModel Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType,
                                    XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1)
        {
            //any Esent model needs to run from the file so we need to create a temporal one
            var xbimFilePath = Path.GetTempFileName();

            xbimFilePath = Path.ChangeExtension(xbimFilePath, ".xbim");

            switch (dataType)
            {
            case StorageType.Xbim:
                //xBIM file has to be opened from the file so we need to create temporary file if it is not a local file stream
                var localFile  = false;
                var fileStream = stream as FileStream;
                if (fileStream != null)
                {
                    var name = fileStream.Name;
                    //if it is an existing local file, just use it
                    if (File.Exists(name))
                    {
                        xbimFilePath = name;
                        //close the stream from argument to have an exclusive access to the file
                        stream.Close();
                        localFile = true;
                    }
                }
                if (!localFile)
                {
                    using (var tempFile = File.Create(xbimFilePath))
                    {
                        stream.CopyTo(tempFile);
                        tempFile.Close();
                    }
                }
                // Scope to avoid name clashes
                {
                    var model = CreateEsentModel(schema, codePageOverride);
                    model.Open(xbimFilePath, accessMode, progDelegate);
                    return(model);
                }

            case StorageType.IfcXml:
                if (modelType == XbimModelType.EsentModel)
                {
                    var model = CreateEsentModel(schema, codePageOverride);
                    if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, keepOpen: true, cacheEntities: true))
                    {
                        return(model);
                    }
                    else
                    {
                        throw new XbimException("Failed to create Esent model");
                    }
                }
                if (modelType == XbimModelType.MemoryModel)
                {
                    var model = CreateMemoryModel(schema);
                    model.LoadXml(stream, stream.Length, progDelegate);
                    return(model);
                }
                throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel");

            case StorageType.Stp:
            case StorageType.Ifc:
                if (modelType == XbimModelType.EsentModel)
                {
                    var model = CreateEsentModel(schema, codePageOverride);
                    if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, keepOpen: true, cacheEntities: true))
                    {
                        return(model);
                    }
                    else
                    {
                        throw new XbimException("Failed to create Esent model");
                    }
                }
                if (modelType == XbimModelType.MemoryModel)
                {
                    var model = CreateMemoryModel(schema);
                    model.LoadStep21(stream, stream.Length, progDelegate);
                    return(model);
                }
                throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel");

            case StorageType.IfcZip:
            case StorageType.StpZip:
            case StorageType.Zip:
                if (modelType == XbimModelType.EsentModel)
                {
                    var model = CreateEsentModel(schema, codePageOverride);
                    if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, true, true))
                    {
                        return(model);
                    }
                    else
                    {
                        throw new XbimException("Failed to create Esent model");
                    }
                }
                if (modelType == XbimModelType.MemoryModel)
                {
                    var model = CreateMemoryModel(schema);
                    model.LoadZip(stream, progDelegate);
                    return(model);
                }
                throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel");

            default:
                throw new ArgumentOutOfRangeException("dataType");
            }
        }
Exemplo n.º 22
0
 public override IModel Create(XbimSchemaVersion ifcVersion, string dbPath)
 {
     throw new NotImplementedException("The MemoryModelProvider does not support creation of XBIM models");
 }
Exemplo n.º 23
0
        public override IModel Create(XbimSchemaVersion ifcVersion, string dbPath)
        {
            var factory = GetFactory(ifcVersion);

            return(EsentModel.CreateModel(factory, dbPath));
        }
Exemplo n.º 24
0
        public override IModel Create(XbimSchemaVersion ifcVersion, XbimStoreType storageType)
        {
            var factory = GetFactory(ifcVersion);

            return(new MemoryModel(factory));
        }
 public StepFileSchema(XbimSchemaVersion schemaVersion)
 {
     _schemas.Add(schemaVersion.ToString().ToUpper());
     Init();
 }
Exemplo n.º 26
0
        /// <summary>
        /// Constructor used to create a new model for edit
        /// </summary>
        /// <param name="storageType"></param>
        /// <param name="ifcVersion"></param>
        /// <param name="editorDetails"></param>
        protected IfcStore(XbimStoreType storageType, XbimSchemaVersion ifcVersion, XbimEditorCredentials editorDetails) : this()
        {
            var model = ModelProvider.Create(ifcVersion, storageType);

            AssignModel(model, editorDetails, ifcVersion);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Constructor used to create a new persistent model with specified path
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="ifcVersion"></param>
        /// <param name="editorDetails"></param>
        protected IfcStore(string filepath, XbimSchemaVersion ifcVersion, XbimEditorCredentials editorDetails) : this()
        {
            var model = ModelProvider.Create(ifcVersion, filepath);

            AssignModel(model, editorDetails, ifcVersion);
        }
Exemplo n.º 28
0
 public static IfcStore Create(XbimSchemaVersion ifcVersion, XbimStoreType storageType)
 {
     return(new IfcStore(storageType, ifcVersion, null));
 }
Exemplo n.º 29
0
        /// <summary>
        /// New builder wrapping a new in-memory IFC model.
        /// </summary>
        /// <param name="c">The editor's credentials</param>
        /// <param name="version">The schema version</param>
        /// <param name="loggerFactory">A logger factory</param>
        /// <returns>A builder instance</returns>
        public static IfcBuilder WithCredentials(XbimEditorCredentials c, XbimSchemaVersion version = XbimSchemaVersion.Ifc4, ILoggerFactory loggerFactory = null)
        {
            var newStore = IfcStore.Create(version, XbimStoreType.InMemoryModel);

            return(WrapStore(newStore, loggerFactory));
        }
Exemplo n.º 30
0
 /// <summary>
 /// Creates a Database store at the specified location
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="editorDetails"></param>
 /// <param name="ifcVersion"></param>
 /// <returns></returns>
 public static IfcStore Create(string filePath, XbimEditorCredentials editorDetails, XbimSchemaVersion ifcVersion)
 {
     return(new IfcStore(filePath, ifcVersion, editorDetails));
 }