Пример #1
0
        protected void Init(IEntityFactory factory)
        {
            _factory       = factory;
            InstanceCache  = new PersistedEntityInstanceCache(this, factory);
            InstancesLocal = new XbimInstanceCollection(this);
            var r = new Random();

            UserDefinedId = (short)r.Next(short.MaxValue); // initialise value at random to reduce chance of duplicates
            Metadata      = ExpressMetaData.GetMetadata(factory.GetType().Module);
            ModelFactors  = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5);
        }
Пример #2
0
        public MemoryModel(IEntityFactory entityFactory, int labelFrom = 0)
        {
            if (entityFactory == null)
            {
                throw new ArgumentNullException("entityFactory");
            }

            _entityFactory = entityFactory;
            _instances     = new EntityCollection(this, labelFrom);
            Header         = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults);
            foreach (var schemasId in _instances.Factory.SchemasIds)
            {
                Header.FileSchema.Schemas.Add(schemasId);
            }
            ModelFactors    = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5);
            Metadata        = ExpressMetaData.GetMetadata(entityFactory.GetType().Module);
            IsTransactional = true;
        }
Пример #3
0
        public override string ToString()
        {
            ExpressMetaData md = null;

            if (Model != null)
            {
                md = Model.Metadata;
            }
            else
            {
                md = ExpressMetaData.GetMetadata(GetType().Module);
            }

            using (var sw = new StringWriter())
            {
                Part21Writer.WriteEntity(this, sw, md);
                return(sw.ToString());
            }
        }
        private void PopulateTree()
        {
            // this is done through the metadata in order to ensure that class relationships are loaded
            var module4  = (typeof(Xbim.Ifc4.Kernel.IfcProduct)).Module;
            var meta4    = ExpressMetaData.GetMetadata(module4);
            var product4 = meta4.ExpressType("IFCPRODUCT");

            TypesTree.Items.Add(new ObjectViewModel()
            {
                Header = "Ifc4.IfcProduct", Tag = new ExpressTypeExpander(product4, Model), IsChecked = true
            });

            // this is done through the metadata in order to ensure that class relationships are loaded
            var module2X3  = (typeof(Xbim.Ifc2x3.Kernel.IfcProduct)).Module;
            var meta2X3    = ExpressMetaData.GetMetadata(module2X3);
            var product2X3 = meta2X3.ExpressType("IFCPRODUCT");

            TypesTree.Items.Add(new ObjectViewModel()
            {
                Header = "Ifc2x3.IfcProduct", Tag = new ExpressTypeExpander(product2X3, Model), IsChecked = true
            });
        }
Пример #5
0
        public static void Export()
        {
            var valType = typeof(IfcValue);
            var types   = valType.Assembly.GetTypes()
                          .Where(t => t.IsValueType && valType.IsAssignableFrom(t))
                          .OrderBy(t => t.Name);

            using (var w = File.CreateText("MeasureTypeEnum.csv"))
            {
                // header
                w.WriteLine($"Identifier, Name");

                foreach (var t in types)
                {
                    w.WriteLine($"{t.Name}, {Format(t.Name)}");
                }
            }

            types = valType.Assembly.GetTypes()
                    .Where(t => !t.IsAbstract && typeof(IfcObjectReferenceSelect).IsAssignableFrom(t))
                    .OrderBy(t => t.Name);
            using (var w = File.CreateText("ReferenceTypeEnum.csv"))
            {
                // header
                w.WriteLine($"Identifier, Name");

                foreach (var t in types)
                {
                    w.WriteLine($"{t.Name}, {Format(t.Name)}");
                }
            }

            var meta        = ExpressMetaData.GetMetadata(valType.Module);
            var product     = meta.ExpressType("IFCPRODUCT");
            var element     = meta.ExpressType("IFCELEMENT");
            var spatial     = meta.ExpressType("IFCSPATIALELEMENT");
            var stack       = new Stack <ExpressType>(new [] { element, spatial });
            var enumCounter = 5000;

            using (var w = File.CreateText("ApplicableIfcTypes.csv"))
            {
                // header
                w.WriteLine($"ID, Identifier, Name, Parent");

                // root
                w.WriteLine($"{product.TypeId}, {product.Name}, {Format(product.Name)}, NULL");

                while (stack.Count != 0)
                {
                    var type = stack.Pop();
                    if (type.SubTypes != null && type.SubTypes.Any())
                    {
                        foreach (var t in type.SubTypes)
                        {
                            stack.Push(t);
                        }
                    }
                    w.WriteLine($"{type.TypeId}, {type.Name}, {Format(type.Name)}, {type.SuperType.TypeId}");

                    // predefined types
                    var pdt = type.Properties.Select(kvp => kvp.Value).FirstOrDefault(p => string.Equals(p.Name, "PredefinedType"));
                    if (pdt == null)
                    {
                        continue;
                    }
                    var pdtType = pdt.PropertyInfo.PropertyType;
                    if (pdtType.IsGenericType)
                    {
                        pdtType = Nullable.GetUnderlyingType(pdtType);
                    }
                    var values = Enum.GetNames(pdtType);
                    foreach (var value in values)
                    {
                        w.WriteLine($"{++enumCounter}, {value}, {value}, {type.TypeId}");
                    }
                }
            }
        }
Пример #6
0
        public void Can_skip_entities_while_parsing()
        {
            using (var strm = File.OpenRead(@"4walls1floorSite.ifc"))
            {
                var ifc2x3MetaData = ExpressMetaData.GetMetadata((new Xbim.Ifc2x3.EntityFactoryIfc2x3()).GetType().GetTypeInfo().Module);
                var ifc4MetaData   = ExpressMetaData.GetMetadata((new Xbim.Ifc4.EntityFactoryIfc4()).GetType().GetTypeInfo().Module);
                var allTypes       = new HashSet <string>(
                    ifc2x3MetaData.Types().Where(et => typeof(IPersistEntity).IsAssignableFrom(et.Type) && !et.Type.IsAbstract).Select(et => et.ExpressNameUpper)
                    .Concat(ifc2x3MetaData.Types().Where(et => typeof(IPersistEntity).IsAssignableFrom(et.Type) && !et.Type.IsAbstract).Select(et => et.ExpressNameUpper)));
                var requiredTypes = new HashSet <string>();
                foreach (var metadata in new[] { ifc2x3MetaData })
                {
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcProject)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcAsset)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcSystem)).Where(t => !typeof(IIfcStructuralAnalysisModel).IsAssignableFrom(t.Type)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcActor)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcElement)).Where(t => !typeof(IIfcFeatureElement).IsAssignableFrom(t.Type) &&
                                                                                                   !typeof(IIfcVirtualElement).IsAssignableFrom(t.Type)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcSpatialElement)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcProxy)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }

                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcTypeProduct)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcPropertySetDefinitionSelect)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcRelDefinesByProperties)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcSimpleProperty)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcElementQuantity)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcPhysicalSimpleQuantity)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcRelDefinesByType)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcUnitAssignment)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcNamedUnit)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcMeasureWithUnit)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcDimensionalExponents)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcRelAssociatesClassification)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcClassificationReference)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcClassification)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    // foreach (var t in metadata.ExpressTypesImplementing(typeof(Xbim.Ifc2x3.DateTimeResource.IfcCalendarDate))) requiredTypes.Add(t.ExpressNameUpper);
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcActorSelect)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcAddress)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcApplication)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcActorRole)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                    foreach (var t in metadata.ExpressTypesImplementing(typeof(IIfcDocumentSelect)))
                    {
                        requiredTypes.Add(t.ExpressNameUpper);
                    }
                }
                var unwantedTypes = allTypes.Except(requiredTypes);
                var unwanted      = new HashSet <string>(unwantedTypes);
                using (var mm = MemoryModel.OpenReadStep21(strm, null, null, unwantedTypes.ToList()))
                {
                    foreach (var instance in mm.Instances)
                    {
                        Assert.IsFalse(unwanted.Contains(instance.ExpressType.ExpressNameUpper));
                    }
                }
            }
        }
Пример #7
0
        private static void Main()
        {
            //load IFC4 as a template for most of the settings
            var conf = configuration.LoadFromFile(@"..\..\..\Xbim.IO\Xml\BsConf\IFC4_config.xml");

            //change global settings to be COBieExpress specific
            conf.id = "COBieExpress";
            conf.Schema.targetNamespace = "http://www.openbim.org/COBieExpress/1.0";
            conf.Namespace.prefix       = "cb";
            conf.Namespace.alias        = "http://www.openbim.org/COBieExpress/1.0";
            conf.RootElement.name       = "COBie";

            //remove all IFC4 entities
            foreach (var entity in conf.Entities.ToList())
            {
                conf.Items.Remove(entity);
            }

            //remove all IFC4 types
            foreach (var type in conf.Types.ToList())
            {
                conf.Items.Remove(type);
            }

            //add mapping for NUMBER type (<cnf:type select="NUMBER" map="xs:double" />)
            conf.Items.Add(new type {
                select = new List <string> {
                    "NUMBER"
                }, map = "xs:double"
            });

            //set all COBieExpress non-agregate and non-select attributes to be "exp-attribute="attribute-tag""
            var metadata = ExpressMetaData.GetMetadata(typeof(CobieExternalObject).Module);

            foreach (var expType in metadata.Types())
            {
                var type      = expType.Type;
                var instProps = type.GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);

                //all explicit non-enumerable own properties
                var expProps =
                    expType.Properties.Where(p =>
                                             p.Value.IsExplicit &&
                                             p.Value.EnumerableType != null &&
                                             instProps.Any(i => i.Name == p.Value.Name))
                    .Select(kv => kv.Value).ToList();
                if (!expProps.Any())
                {
                    continue;
                }

                var entity = conf.GetOrCreatEntity(expType.ExpressName);
                foreach (var attribute in expProps.Select(prop => entity.GetOrCreateAttribute(prop.Name)))
                {
                    attribute.expattribute          = expattribute.attributetag;
                    attribute.expattributeSpecified = true;
                }
            }

            //manual inverse changes
            foreach (var invertedInverse in InvertedInverses)
            {
                var path       = invertedInverse.Split('.');
                var entityName = path[0];
                var propName   = path[1];

                var expType = metadata.ExpressType(entityName.ToUpperInvariant());
                var expProp = expType.Inverses.First(p => p.Name == propName);

                var invType = expProp.PropertyInfo.PropertyType;
                while (invType.IsGenericType)
                {
                    invType = invType.GetGenericArguments()[0];
                }
                var invExpType = metadata.ExpressType(invType);
                var invExpProp =
                    invExpType.Properties.FirstOrDefault(
                        p => p.Value.Name == expProp.InverseAttributeProperty.RemoteProperty).Value;

                var invertedEntity     = conf.GetOrCreatEntity(expType.ExpressName);
                var invertedEntityAttr = invertedEntity.GetOrCreateInverse(expProp.Name);
                invertedEntityAttr.expattribute          = expattribute.doubletag;
                invertedEntityAttr.expattributeSpecified = true;

                var origEntity    = conf.GetOrCreatEntity(invExpType.ExpressName);
                var origAttribute = origEntity.GetOrCreateAttribute(invExpProp.Name);
                origAttribute.keep = false;
            }

            conf.SaveToFile(@"..\..\..\Xbim.IO\Xml\BsConf\COBieExpress_config.xml");
        }