Ejemplo n.º 1
0
        private bool IsIfcProperty(string elementName, out int index, out IfcMetaProperty prop)
        {
            IfcType   ifcType;
            XmlEntity xmlEntity = _currentNode as XmlEntity;

            if (xmlEntity != null && !IfcMetaData.TryGetIfcType(elementName.ToUpper(), out ifcType))
            {
                IfcType t = IfcMetaData.IfcType(xmlEntity.Entity);

                foreach (KeyValuePair <int, IfcMetaProperty> p in t.IfcProperties)
                {
                    int propIndex = p.Key;
                    if (p.Value.PropertyInfo.Name == elementName)
                    //this is the property to set
                    {
                        prop  = p.Value;
                        index = p.Key;
                        return(true);
                    }
                }
            }
            prop  = null;
            index = -1;
            return(false);
        }
Ejemplo n.º 2
0
        internal static void AddParent(IfcType child)
        {
            Type baseParent = child.Type.BaseType;

            if (typeof(object) == baseParent || typeof(ValueType) == baseParent)
            {
                return;
            }
            IfcType ifcParent;

            if (!TypeToIfcTypeLookup.Contains(baseParent))
            {
                TypeToIfcTypeLookup.Add(ifcParent = new IfcType {
                    Type = baseParent
                });
                string typeLookup = baseParent.Name.ToUpper();
                if (!TypeNameToIfcTypeLookup.ContainsKey(typeLookup))
                {
                    TypeNameToIfcTypeLookup.Add(typeLookup, ifcParent);
                }
                ifcParent.IfcSubTypes.Add(child);
                child.IfcSuperType = ifcParent;
                AddParent(ifcParent);
                AddProperties(ifcParent);
            }
            else
            {
                ifcParent          = TypeToIfcTypeLookup[baseParent];
                child.IfcSuperType = ifcParent;
                if (!ifcParent.IfcSubTypes.Contains(child))
                {
                    ifcParent.IfcSubTypes.Add(child);
                }
            }
        }
Ejemplo n.º 3
0
        internal void BeginNestedType(string typeName)
        {
            IfcType ifcType = IfcMetaData.IfcType(typeName);

            _currentInstance = new Part21Entity((IPersistIfc)Activator.CreateInstance(ifcType.Type));
            _processStack.Push(_currentInstance);
        }
Ejemplo n.º 4
0
        public void AddInclude(string ifcEntityName, params int[] propertyIndices)
        {
            IfcType   ifcType = IfcInstances.IfcTypeLookup[ifcEntityName];
            IfcFilter flt     = new IfcFilter(ifcType, propertyIndices);

            Included.Add(flt);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a new entity of the specified type, the entity will be blank, all properties with default values
        /// The entity label will be as specified, an exception will be raised if the label is already in use
        /// </summary>
        /// <param name="type">Type of entity to create, this must support IPersistIfcEntity</param>
        /// <returns>A handle to the entity</returns>
        internal XbimInstanceHandle AddEntity(Type type, int entityLabel)
        {
            IfcType            ifcType = IfcMetaData.IfcType(type);
            XbimInstanceHandle h       = new XbimInstanceHandle(this.model, entityLabel, ifcType.TypeId);

            AddEntity(h.EntityLabel, h.EntityTypeId, null, null, ifcType.IndexedClass);
            return(h);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds an entity, assumes a valid transaction is running
        /// </summary>
        /// <param name="toWrite"></param>
        internal void AddEntity(IPersistIfcEntity toWrite)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            toWrite.WriteEntity(bw);
            IfcType ifcType = IfcMetaData.IfcType(toWrite);

            AddEntity(toWrite.EntityLabel, ifcType.TypeId, ifcType.GetIndexedValues(toWrite), ms.ToArray(), ifcType.IndexedClass);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a new entity of the specified type, the entity will be blank, all properties with default values
        /// </summary>
        /// <param name="type">Type of entity to create, this must support IPersistIfcEntity</param>
        /// <returns>A handle to the entity</returns>
        internal XbimInstanceHandle AddEntity(Type type)
        {
            //System.Diagnostics.Debug.Assert(typeof(IPersistIfcEntity).IsAssignableFrom(type));
            int                highest = RetrieveHighestLabel();
            IfcType            ifcType = IfcMetaData.IfcType(type);
            XbimInstanceHandle h       = new XbimInstanceHandle(this.model, highest + 1, ifcType.TypeId);

            AddEntity(h.EntityLabel, h.EntityTypeId, null, null, ifcType.IndexedClass);
            return(h);
        }
Ejemplo n.º 8
0
 private void AddNonAbstractTypes(IfcType ifcType, List <Type> nonAbstractTypes)
 {
     if (!ifcType.Type.IsAbstract) //this is a concrete type so add it
     {
         nonAbstractTypes.Add(ifcType.Type);
     }
     foreach (IfcType subType in ifcType.IfcSubTypes)
     {
         AddNonAbstractTypes(subType, nonAbstractTypes);
     }
 }
 public void AddExclude(IfcType ifcType)
 {
     if (!Excluded.Contains(ifcType))
     {
         IfcFilter flt = new IfcFilter(ifcType);
         Excluded.Add(flt);
     }
     foreach (IfcType subType in ifcType.IfcSubTypes)
     {
         AddExclude(subType);
     }
 }
Ejemplo n.º 10
0
 public void AddExclude(IfcType ifcType)
 {
     if (!Excluded.Contains(ifcType))
     {
         IfcFilter flt = new IfcFilter(ifcType);
         Excluded.Add(flt);
     }
     foreach (IfcType subType in ifcType.IfcSubTypes)
     {
         AddExclude(subType);
     }
 }
Ejemplo n.º 11
0
        private bool IsIfcType(string elementName, out IfcType ifcType)
        {
            bool ok = IfcMetaData.TryGetIfcType(elementName.ToUpper(), out ifcType);

            if (!ok)
            {
                if (elementName.Contains("-wrapper") && elementName.StartsWith(_expressNamespace) == false) // we have an inline type definition
                {
                    string inputName = elementName.Substring(0, elementName.LastIndexOf("-"));
                    ok = IfcMetaData.TryGetIfcType(inputName.ToUpper(), out ifcType);
                }
            }
            return(ok && typeof(ExpressType).IsAssignableFrom(ifcType.Type));
        }
Ejemplo n.º 12
0
        private void Write(XbimModel model, int handle, XmlWriter output, int pos = -1)
        {
            if (_written.Contains(handle)) //we have already done it
            {
                return;
            }
            //int nextId = _written.Count + 1;
            _written.Add(handle);

            IPersistIfcEntity entity  = model.GetInstanceVolatile(handle); //load either the cache or a volatile version of the entity
            IfcType           ifcType = IfcMetaData.IfcType(entity);

            output.WriteStartElement(ifcType.Type.Name);

            output.WriteAttributeString("id", string.Format("i{0}", handle));
            if (pos > -1) //we are writing out a list element
            {
                output.WriteAttributeString("pos", pos.ToString());
            }

            IEnumerable <IfcMetaProperty> toWrite;

            if (WriteInverses)
            {
                List <IfcMetaProperty> l = new List <IfcMetaProperty>(ifcType.IfcProperties.Values);
                l.AddRange(ifcType.IfcInverses);
                toWrite = l;
            }
            else
            {
                toWrite = ifcType.IfcProperties.Values;
            }

            foreach (IfcMetaProperty ifcProperty in toWrite) //only write out persistent attributes, ignore inverses
            {
                if (ifcProperty.IfcAttribute.State != IfcAttributeState.DerivedOverride)
                {
                    Type   propType = ifcProperty.PropertyInfo.PropertyType;
                    object propVal  = ifcProperty.PropertyInfo.GetValue(entity, null);

                    WriteProperty(model, ifcProperty.PropertyInfo.Name, propType, propVal, entity, output, -1,
                                  ifcProperty.IfcAttribute);
                }
            }
            output.WriteEndElement();
        }
Ejemplo n.º 13
0
        private bool IsConcreteClassOf(string name, IfcType candidate)
        {
            IfcType st = candidate;

            while (st != null)
            {
                if (st.Type.Name == name)
                {
                    return(true);
                }
                else
                {
                    st = st.IfcSuperType;
                }
            }
            return(false);
        }
        /// <summary>
        /// returns all handles that of of type to include
        /// </summary>
        /// <param name="include"></param>
        /// <returns></returns>
        public IEnumerable <XbimGeometryHandle> Include(params IfcEntityNameEnum[] include)
        {
            HashSet <IfcEntityNameEnum> includeSet = new HashSet <IfcEntityNameEnum>(include);

            foreach (var inc in include)
            {
                IfcType ifcType = IfcMetaData.IfcType((short)inc);
                foreach (var sub in ifcType.IfcSubTypes)
                {
                    includeSet.Add(sub.IfcTypeEnum);
                }
            }
            foreach (var h in this)
            {
                if (includeSet.Contains((IfcEntityNameEnum)h.IfcTypeId))
                {
                    yield return(h);
                }
            }
        }
Ejemplo n.º 15
0
        internal static void AddProperties(IfcType ifcType)
        {
            PropertyInfo[] properties =
                ifcType.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            foreach (PropertyInfo propInfo in properties)
            {
                int            attributeIdx  = -1;
                IfcAttribute[] ifcAttributes =
                    (IfcAttribute[])propInfo.GetCustomAttributes(typeof(IfcAttribute), false);
                if (ifcAttributes.GetLength(0) > 0) //we have an ifc property
                {
                    if (ifcAttributes[0].Order > 0)
                    {
                        // SUPPORT: if the code breaks here there's a problem with the order attribut in a class property
                        ifcType.IfcProperties.Add(ifcAttributes[0].Order,
                                                  new IfcMetaProperty {
                            PropertyInfo = propInfo, IfcAttribute = ifcAttributes[0]
                        });
                        attributeIdx = ifcAttributes[0].Order;
                    }

                    else
                    {
                        ifcType.IfcInverses.Add(new IfcMetaProperty {
                            PropertyInfo = propInfo, IfcAttribute = ifcAttributes[0]
                        });
                    }
                }
                IndexedProperty[] ifcIndexes =
                    (IndexedProperty[])propInfo.GetCustomAttributes(typeof(IndexedProperty), false);
                if (ifcIndexes.GetLength(0) > 0) //we have an index
                {
                    Debug.Assert(typeof(IPersistIfcEntity).IsAssignableFrom(propInfo.PropertyType) ||
                                 typeof(IEnumerable <IPersistIfcEntity>).IsAssignableFrom(propInfo.PropertyType)); //only handles to IPersistIfcEntitiess or collecctions of IPersistIfcEntities are indexable
                    ifcType.AddIndexedAttribute(propInfo, attributeIdx);
                }
            }
        }
Ejemplo n.º 16
0
        public static void WriteEntity(this IPersistIfcEntity entity, BinaryWriter entityWriter)
        {
            IfcType ifcType = IfcMetaData.IfcType(entity);

            // entityWriter.Write(Convert.ToByte(P21ParseAction.NewEntity));
            entityWriter.Write(Convert.ToByte(P21ParseAction.BeginList));
            foreach (IfcMetaProperty ifcProperty in ifcType.IfcProperties.Values)
            //only write out persistent attributes, ignore inverses
            {
                if (ifcProperty.IfcAttribute.State == IfcAttributeState.DerivedOverride)
                {
                    entityWriter.Write(Convert.ToByte(P21ParseAction.SetOverrideValue));
                }
                else
                {
                    Type   propType = ifcProperty.PropertyInfo.PropertyType;
                    object propVal  = ifcProperty.PropertyInfo.GetValue(entity, null);
                    WriteProperty(propType, propVal, entityWriter);
                }
            }
            entityWriter.Write(Convert.ToByte(P21ParseAction.EndList));
            entityWriter.Write(Convert.ToByte(P21ParseAction.EndEntity));
        }
        /// <summary>
        /// Returns all handles that are not of type to exclude
        /// </summary>
        /// <param name="exclude"></param>
        /// <returns></returns>
        public IEnumerable <XbimGeometryHandle> Exclude(params IfcEntityNameEnum[] exclude)
        {
            HashSet <IfcEntityNameEnum> excludeSet = new HashSet <IfcEntityNameEnum>(exclude);

            foreach (var ex in exclude)
            {
                IfcType ifcType = IfcMetaData.IfcType((short)ex);
                // bugfix here: loop did not use to include all implementations, but only first level down.
                foreach (var sub in ifcType.NonAbstractSubTypes)
                {
                    var ifcSub = IfcMetaData.IfcType(sub);
                    excludeSet.Add(ifcSub.IfcTypeEnum);
                }
            }

            foreach (var h in this)
            {
                if (!excludeSet.Contains((IfcEntityNameEnum)h.IfcTypeId))
                {
                    yield return(h);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Writes the entity to a TextWriter in the Part21 format
        /// </summary>
        /// <param name="entityWriter">The TextWriter</param>
        /// <param name="entity">The entity to write</param>
        internal static void WriteEntity(this IPersistIfcEntity entity, TextWriter entityWriter, IDictionary <int, int> map = null)
        {
            if (map != null && map.Keys.Contains(entity.EntityLabel))
            {
                return;                                                       //if the entity is replaced in the map do not write it
            }
            entityWriter.Write(string.Format("#{0}={1}(", entity.EntityLabel, entity.GetType().Name.ToUpper()));
            IfcType ifcType = IfcMetaData.IfcType(entity);
            bool    first   = true;

            foreach (IfcMetaProperty ifcProperty in ifcType.IfcProperties.Values)
            //only write out persistent attributes, ignore inverses
            {
                if (ifcProperty.IfcAttribute.State == IfcAttributeState.DerivedOverride)
                {
                    if (!first)
                    {
                        entityWriter.Write(',');
                    }
                    entityWriter.Write('*');
                    first = false;
                }
                else
                {
                    Type   propType = ifcProperty.PropertyInfo.PropertyType;
                    object propVal  = ifcProperty.PropertyInfo.GetValue(entity, null);
                    if (!first)
                    {
                        entityWriter.Write(',');
                    }
                    WriteProperty(propType, propVal, entityWriter, map);
                    first = false;
                }
            }
            entityWriter.WriteLine(");");
        }
Ejemplo n.º 19
0
 public IfcFilter(IfcType type)
 {
     _type = type;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Trys to get the specified Ifc Type with the typeName, if the ifcType does not exist false is returned
 /// </summary>
 /// <param name="typeName"></param>
 /// <param name="ifcType"></param>
 /// <returns></returns>
 public static bool TryGetIfcType(string typeName, out IfcType ifcType)
 {
     return(TypeNameToIfcTypeLookup.TryGetValue(typeName, out ifcType));
 }
Ejemplo n.º 21
0
 private void ChildTree(IfcType ot, TextHighliter sb, string indentationHeader, int Indent)
 {
     string sSpace = new string(' ', Indent * 2);
     // sSpace = sSpace.Replace(new string[] { " " }, "  ");
     foreach (var item in ot.IfcSubTypes)
     {
         string isAbstract = item.Type.IsAbstract ? " (abstract)" : "";
         sb.AppendFormat(indentationHeader + sSpace + "- {0} {1}", item, isAbstract);
         ChildTree(item, sb, indentationHeader, Indent + 1);
     }
 }
Ejemplo n.º 22
0
 public IfcFilter(IfcType type, params int[] propertyIndices)
     : this(type)
 {
     _propertyIndices = propertyIndices;
 }
Ejemplo n.º 23
0
 private bool IsIfcEntity(string elementName, out IfcType ifcType)
 {
     return(IfcMetaData.TryGetIfcType(elementName.ToUpper(), out ifcType));
 }
Ejemplo n.º 24
0
        public static IEnumerable <T> Where <T>(this IfcInstances instances, Expression <Func <T, bool> > expr)
        {
            Type    type    = typeof(T);
            IfcType ifcType = IfcInstances.IfcEntities[type];

            foreach (Type itemType in ifcType.NonAbstractSubTypes)
            {
                ICollection <long> entities;

                if (instances.TryGetValue(itemType, out entities))
                {
                    bool noIndex = true;
                    XbimIndexedCollection <long> indexColl =
                        entities as XbimIndexedCollection <long>;
                    if (indexColl != null)
                    {
                        //our indexes work from the hash values of that which is indexed, regardless of type
                        object hashRight = null;

                        //indexes only work on equality expressions here
                        if (expr.Body.NodeType == ExpressionType.Equal)
                        {
                            //Equality is a binary expression
                            BinaryExpression binExp = (BinaryExpression)expr.Body;
                            //Get some aliases for either side
                            Expression leftSide  = binExp.Left;
                            Expression rightSide = binExp.Right;

                            hashRight = GetRight(leftSide, rightSide);

                            //if we were able to create a hash from the right side (likely)
                            MemberExpression returnedEx = GetIndexablePropertyOnLeft <T>(leftSide);
                            if (returnedEx != null)
                            {
                                //cast to MemberExpression - it allows us to get the property
                                MemberExpression propExp  = returnedEx;
                                string           property = propExp.Member.Name;
                                if (indexColl.HasIndex(property))
                                {
                                    IEnumerable <long> values = indexColl.GetValues(property, hashRight);
                                    if (values != null)
                                    {
                                        foreach (T item in values.Cast <T>())
                                        {
                                            yield return(item);
                                        }
                                        noIndex = false;
                                    }
                                }
                            }
                        }
                        else if (expr.Body.NodeType == ExpressionType.Call)
                        {
                            MethodCallExpression callExp = (MethodCallExpression)expr.Body;
                            if (callExp.Method.Name == "Contains")
                            {
                                Expression keyExpr = callExp.Arguments[0];
                                if (keyExpr.NodeType == ExpressionType.Constant)
                                {
                                    ConstantExpression constExp = (ConstantExpression)keyExpr;
                                    object             key      = constExp.Value;
                                    if (callExp.Object.NodeType == ExpressionType.MemberAccess)
                                    {
                                        MemberExpression memExp = (MemberExpression)callExp.Object;

                                        string property = memExp.Member.Name;
                                        if (indexColl.HasIndex(property))
                                        {
                                            IEnumerable <long> values = indexColl.GetValues(property, key);
                                            if (values != null)
                                            {
                                                foreach (T item in values.Cast <T>())
                                                {
                                                    yield return(item);
                                                }
                                                noIndex = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (noIndex)
                    {
                        Func <T, bool> predicate = expr.Compile();
                        // IEnumerable<T> result = sourceEnum.Where<T>(expr.Compile());
                        foreach (long handle in entities)
                        {
                            T resultItem = (T)instances.GetOrCreateEntity(handle);
                            if (predicate(resultItem))
                            {
                                yield return(resultItem);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
        private void AddEntity(IfcType ifcType, params int[] idx)
        {
            int[] includedProperties = idx;

            if (!Excluded.Contains(ifcType) && !_parseFilter.Contains(ifcType) &&
                !typeof(ExpressType).IsAssignableFrom(ifcType.Type))
            {
                if (!ifcType.Type.IsAbstract)
                {
                    IfcType superType = ifcType;
                    while (superType != null)
                    {
                        if (Included.Contains(superType))
                        {
                            IfcFilter flt         = Included[superType];
                            IfcFilter parseFilter = new IfcFilter(ifcType, flt.PropertyIndices);
                            _parseFilter.Add(parseFilter);
                            includedProperties = parseFilter.PropertyIndices;
                            break;
                        }
                        else
                        {
                            superType = superType.IfcSuperType;
                        }
                    }

                    if (superType == null)
                    {
                        _parseFilter.Add(new IfcFilter(ifcType, idx));
                    }
                }

                foreach (Type subType in ifcType.NonAbstractSubTypes)
                {
                    if (subType != ifcType.Type)
                    {
                        AddEntity(IfcInstances.IfcEntities[subType]);
                    }
                }

                foreach (IfcMetaProperty prop in ifcType.IfcProperties.Values)
                {
                    if (includedProperties == null || includedProperties.Length == 0 ||
                        includedProperties.Contains(prop.IfcAttribute.Order - 1))
                    {
                        Type propType = prop.PropertyInfo.PropertyType;
                        if (typeof(ExpressEnumerable).IsAssignableFrom(propType))  //its a list
                        {
                            Type genType = GetGenericType(propType);
                            if (genType != null && IfcInstances.IfcEntities.Contains(genType))
                            {
                                AddEntity(IfcInstances.IfcEntities[genType]);
                            }
                            if (genType.IsInterface)
                            {
                                //get the types that are like this
                                foreach (IfcType ent in IfcInstances.IfcEntities)
                                {
                                    if (genType.IsAssignableFrom(ent.Type))
                                    {
                                        AddEntity(ent);
                                    }
                                }
                            }
                        }
                        else if (propType.IsInterface) //its a select type
                        {
                            //get the types that are like this
                            foreach (IfcType ent in IfcInstances.IfcEntities)
                            {
                                if (propType.IsAssignableFrom(ent.Type))
                                {
                                    AddEntity(ent);
                                }
                            }
                        }
                        else if (typeof(IPersistIfc).IsAssignableFrom(propType) &&
                                 IfcInstances.IfcEntities.Contains(propType)) //its a normal entity
                        {
                            IfcType ifcPropType = IfcInstances.IfcEntities[propType];
                            AddEntity(ifcPropType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public void AddExclude(string ifcEntityName)
        {
            IfcType ifcType = IfcInstances.IfcTypeLookup[ifcEntityName];

            AddExclude(ifcType);
        }
Ejemplo n.º 27
0
        static IfcMetaData()
        {
            Module ifcModule = typeof(IfcActor).Module;
            IEnumerable<Type> typesToProcess =
                ifcModule.GetTypes().Where(
                    t =>
                    typeof(IPersistIfc).IsAssignableFrom(t) && t != typeof(IPersistIfc) && !t.IsEnum && !t.IsAbstract &&
                    t.IsPublic && !typeof(ExpressHeaderType).IsAssignableFrom(t));

            TypeNameToIfcTypeLookup = new Dictionary<string, IfcType>(typesToProcess.Count());
            TypeToIfcTypeLookup = new IfcTypeDictionary();
            InterfaceToIfcTypesLookup = new Dictionary<Type, List<IfcType>>();
            try
            {
                // System.Diagnostics.Debug.Write(typesToProcess.Count());
                foreach (Type typeToProcess in typesToProcess)
                {
                    // Debug.WriteLine(typeToProcess.ToString());
                    IfcType ifcTypeToProcess;
                    if (TypeToIfcTypeLookup.Contains(typeToProcess))
                        ifcTypeToProcess = TypeToIfcTypeLookup[typeToProcess];
                    else
                    {
                        IndexedClass[] ifcTypeIndex = (IndexedClass[])typeToProcess.GetCustomAttributes(typeof(IndexedClass), true);
                        ifcTypeToProcess = new IfcType { Type = typeToProcess, IndexedClass = (ifcTypeIndex.GetLength(0) > 0) };
                    }

                    string typeLookup = typeToProcess.Name.ToUpperInvariant();
                    if (!TypeNameToIfcTypeLookup.ContainsKey(typeLookup))
                        TypeNameToIfcTypeLookup.Add(typeLookup, ifcTypeToProcess);

                    if (!TypeToIfcTypeLookup.Contains(ifcTypeToProcess))
                    {
                        TypeToIfcTypeLookup.Add(ifcTypeToProcess);
                        AddParent(ifcTypeToProcess);
                        AddProperties(ifcTypeToProcess);
                    }

                    // populate the dictionary lookup by interface
                    //
                    foreach (Type interfaceFound in typeToProcess.GetInterfaces())
                    {
                        if (!interfaceFound.Namespace.StartsWith("Xbim"))
                            continue;
                        if (interfaceFound.Name == "IfcMaterialSelect")
                        {
                        }
                        if (!InterfaceToIfcTypesLookup.ContainsKey(interfaceFound))
                        {
                            // add to dictionary
                            InterfaceToIfcTypesLookup.Add(interfaceFound, new List<IfcType>());
                        }
                        InterfaceToIfcTypesLookup[interfaceFound].Add(ifcTypeToProcess);
                    }
                }

                // add the index property to abstract types
                //
                foreach (IfcType ifcType in TypeToIfcTypeLookup.Where(t => t.Type.IsAbstract))
                {
                    IndexedClass[] ifcTypeIndex = (IndexedClass[])ifcType.Type.GetCustomAttributes(typeof(IndexedClass), true);
                    ifcType.IndexedClass = (ifcTypeIndex.GetLength(0) > 0);
                }

                foreach (var entityValue in Enum.GetValues(typeof(IfcEntityNameEnum)))
                    TypeIdToTypeNameLookup.Add((short)entityValue, entityValue.ToString());

                //add the Type Ids to each of the IfcTypes
                foreach (var item in TypeIdToTypeNameLookup)
                {
                    // in case the code fails here make sure he class where the code breaks is marked public
                    //
                    IfcType ifcType = TypeNameToIfcTypeLookup[item.Value];
                    TypeIdToIfcTypeLookup.Add(item.Key, ifcType);
                    ifcType.TypeId = item.Key;
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error reading Ifc Entity Meta Data", e);
            }
            //foreach (var item in TypeNameToIfcTypeLookup)
            //{
            //    if (!item.Value.Type.IsAbstract && !item.Value.Type.IsValueType && !typeof(Xbim.Ifc2x3.GeometryResource.IfcRepresentationItem).IsAssignableFrom( item.Value.Type))
            //    {
            //        if (!item.Value.IndexedClass) Debug.WriteLine(item.Key + " = " + item.Value.IndexedClass);
            //    }
            //}
        }
Ejemplo n.º 28
0
        private bool IsIfcType(string elementName, out IfcType ifcType)
        {
            bool ok = IfcMetaData.TryGetIfcType(elementName.ToUpper(), out ifcType);
            if (!ok)
            {

                if (elementName.Contains("-wrapper") && elementName.StartsWith(_expressNamespace) == false) // we have an inline type definition
                {
                    string inputName = elementName.Substring(0, elementName.LastIndexOf("-"));
                    ok = IfcMetaData.TryGetIfcType(inputName.ToUpper(), out ifcType);
                }
            }
            return ok && typeof(ExpressType).IsAssignableFrom(ifcType.Type);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Trys to get the specified Ifc Type with the typeName, if the ifcType does not exist false is returned
 /// </summary>
 /// <param name="typeName"></param>
 /// <param name="ifcType"></param>
 /// <returns></returns>
 public static bool TryGetIfcType(string typeName, out IfcType ifcType)
 {
     return TypeNameToIfcTypeLookup.TryGetValue(typeName, out ifcType);
 }
Ejemplo n.º 30
0
 internal static void AddParent(IfcType child)
 {
     Type baseParent = child.Type.BaseType;
     if (typeof(object) == baseParent || typeof(ValueType) == baseParent)
         return;
     IfcType ifcParent;
     if (!TypeToIfcTypeLookup.Contains(baseParent))
     {
         TypeToIfcTypeLookup.Add(ifcParent = new IfcType { Type = baseParent });
         string typeLookup = baseParent.Name.ToUpper();
         if (!TypeNameToIfcTypeLookup.ContainsKey(typeLookup))
             TypeNameToIfcTypeLookup.Add(typeLookup, ifcParent);
         ifcParent.IfcSubTypes.Add(child);
         child.IfcSuperType = ifcParent;
         AddParent(ifcParent);
         AddProperties(ifcParent);
     }
     else
     {
         ifcParent = TypeToIfcTypeLookup[baseParent];
         child.IfcSuperType = ifcParent;
         if (!ifcParent.IfcSubTypes.Contains(child))
             ifcParent.IfcSubTypes.Add(child);
     }
 }
Ejemplo n.º 31
0
        internal static void AddProperties(IfcType ifcType)
        {
            PropertyInfo[] properties =
                ifcType.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            foreach (PropertyInfo propInfo in properties)
            {
                int attributeIdx = -1;
                IfcAttribute[] ifcAttributes =
                    (IfcAttribute[])propInfo.GetCustomAttributes(typeof(IfcAttribute), false);
                if (ifcAttributes.GetLength(0) > 0) //we have an ifc property
                {
                    if (ifcAttributes[0].Order > 0)
                    {
                        // SUPPORT: if the code breaks here there's a problem with the order attribut in a class property
                        ifcType.IfcProperties.Add(ifcAttributes[0].Order,
                                                    new IfcMetaProperty { PropertyInfo = propInfo, IfcAttribute = ifcAttributes[0] });
                        attributeIdx = ifcAttributes[0].Order;                     
                    }

                    else
                        ifcType.IfcInverses.Add(new IfcMetaProperty { PropertyInfo = propInfo, IfcAttribute = ifcAttributes[0] });
                }
                IndexedProperty[] ifcIndexes =
                    (IndexedProperty[])propInfo.GetCustomAttributes(typeof(IndexedProperty), false);
                if (ifcIndexes.GetLength(0) > 0) //we have an index
                {
                    Debug.Assert(typeof(IPersistIfcEntity).IsAssignableFrom(propInfo.PropertyType)
                        || typeof(IEnumerable<IPersistIfcEntity>).IsAssignableFrom(propInfo.PropertyType)); //only handles to IPersistIfcEntitiess or collecctions of IPersistIfcEntities are indexable
                    ifcType.AddIndexedAttribute(propInfo, attributeIdx);
                }
            }
        }
Ejemplo n.º 32
0
        private bool IsIfcEntity(string elementName, out IfcType ifcType)
        {

            return IfcMetaData.TryGetIfcType(elementName.ToUpper(), out ifcType);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Returns true if the named entities attribute is indexed
        /// </summary>
        /// <param name="entityTypeName">the name of the Ifc Entity</param>
        /// <param name="attributeIndex">the index offset of the attribute to check, nb this is a 1 based index</param>
        /// <returns></returns>
        public static bool IsIndexedIfcAttribute(string entityTypeName, int attributeIndex)
        {
            IfcType ifcType = IfcType(entityTypeName);

            return(ifcType.IsIndexedIfcAttribute(attributeIndex));
        }
Ejemplo n.º 34
0
        static IfcMetaData()
        {
            Module             ifcModule      = typeof(IfcActor).Module;
            IEnumerable <Type> typesToProcess =
                ifcModule.GetTypes().Where(
                    t =>
                    typeof(IPersistIfc).IsAssignableFrom(t) && t != typeof(IPersistIfc) && !t.IsEnum && !t.IsAbstract &&
                    t.IsPublic && !typeof(ExpressHeaderType).IsAssignableFrom(t));

            TypeNameToIfcTypeLookup   = new Dictionary <string, IfcType>(typesToProcess.Count());
            TypeToIfcTypeLookup       = new IfcTypeDictionary();
            InterfaceToIfcTypesLookup = new Dictionary <Type, List <IfcType> >();
            try
            {
                // System.Diagnostics.Debug.Write(typesToProcess.Count());
                foreach (Type typeToProcess in typesToProcess)
                {
                    // Debug.WriteLine(typeToProcess.ToString());
                    IfcType ifcTypeToProcess;
                    if (TypeToIfcTypeLookup.Contains(typeToProcess))
                    {
                        ifcTypeToProcess = TypeToIfcTypeLookup[typeToProcess];
                    }
                    else
                    {
                        IndexedClass[] ifcTypeIndex = (IndexedClass[])typeToProcess.GetCustomAttributes(typeof(IndexedClass), true);
                        ifcTypeToProcess = new IfcType {
                            Type = typeToProcess, IndexedClass = (ifcTypeIndex.GetLength(0) > 0)
                        };
                    }

                    string typeLookup = typeToProcess.Name.ToUpperInvariant();
                    if (!TypeNameToIfcTypeLookup.ContainsKey(typeLookup))
                    {
                        TypeNameToIfcTypeLookup.Add(typeLookup, ifcTypeToProcess);
                    }

                    if (!TypeToIfcTypeLookup.Contains(ifcTypeToProcess))
                    {
                        TypeToIfcTypeLookup.Add(ifcTypeToProcess);
                        AddParent(ifcTypeToProcess);
                        AddProperties(ifcTypeToProcess);
                    }

                    // populate the dictionary lookup by interface
                    //
                    foreach (Type interfaceFound in typeToProcess.GetInterfaces())
                    {
                        if (!interfaceFound.Namespace.StartsWith("Xbim"))
                        {
                            continue;
                        }
                        if (interfaceFound.Name == "IfcMaterialSelect")
                        {
                        }
                        if (!InterfaceToIfcTypesLookup.ContainsKey(interfaceFound))
                        {
                            // add to dictionary
                            InterfaceToIfcTypesLookup.Add(interfaceFound, new List <IfcType>());
                        }
                        InterfaceToIfcTypesLookup[interfaceFound].Add(ifcTypeToProcess);
                    }
                }

                // add the index property to abstract types
                //
                foreach (IfcType ifcType in TypeToIfcTypeLookup.Where(t => t.Type.IsAbstract))
                {
                    IndexedClass[] ifcTypeIndex = (IndexedClass[])ifcType.Type.GetCustomAttributes(typeof(IndexedClass), true);
                    ifcType.IndexedClass = (ifcTypeIndex.GetLength(0) > 0);
                }

                foreach (var entityValue in Enum.GetValues(typeof(IfcEntityNameEnum)))
                {
                    TypeIdToTypeNameLookup.Add((short)entityValue, entityValue.ToString());
                }

                //add the Type Ids to each of the IfcTypes
                foreach (var item in TypeIdToTypeNameLookup)
                {
                    // in case the code fails here make sure he class where the code breaks is marked public
                    //
                    IfcType ifcType = TypeNameToIfcTypeLookup[item.Value];
                    TypeIdToIfcTypeLookup.Add(item.Key, ifcType);
                    ifcType.TypeId = item.Key;
                }
            }
            catch (Exception e)
            {
                throw new Exception("Error reading Ifc Entity Meta Data", e);
            }
            //foreach (var item in TypeNameToIfcTypeLookup)
            //{
            //    if (!item.Value.Type.IsAbstract && !item.Value.Type.IsValueType && !typeof(Xbim.Ifc2x3.GeometryResource.IfcRepresentationItem).IsAssignableFrom( item.Value.Type))
            //    {
            //        if (!item.Value.IndexedClass) Debug.WriteLine(item.Key + " = " + item.Value.IndexedClass);
            //    }
            //}
        }
Ejemplo n.º 35
0
 private void AddNonAbstractTypes(IfcType ifcType, List<Type> nonAbstractTypes)
 {
     if (!ifcType.Type.IsAbstract) //this is a concrete type so add it
         nonAbstractTypes.Add(ifcType.Type);
     foreach (IfcType subType in ifcType.IfcSubTypes)
         AddNonAbstractTypes(subType, nonAbstractTypes);
 }
Ejemplo n.º 36
0
 private bool IsConcreteClassOf(string name, IfcType candidate)
 {
     IfcType st = candidate;
     while (st != null)
     {
         if (st.Type.Name == name)
             return true;
         else
             st = st.IfcSuperType;
     }
     return false;
 }
Ejemplo n.º 37
0
 public IfcFilter(IfcType type)
 {
     _type = type;
 }
Ejemplo n.º 38
0
        private void AddEntity(IfcType ifcType, params int[] idx)
        {
            int[] includedProperties = idx;

            if (!Excluded.Contains(ifcType) && !_parseFilter.Contains(ifcType)
                && !typeof (ExpressType).IsAssignableFrom(ifcType.Type))
            {
                if (!ifcType.Type.IsAbstract)
                {
                    IfcType superType = ifcType;
                    while (superType != null)
                    {
                        if (Included.Contains(superType))
                        {
                            IfcFilter flt = Included[superType];
                            IfcFilter parseFilter = new IfcFilter(ifcType, flt.PropertyIndices);
                            _parseFilter.Add(parseFilter);
                            includedProperties = parseFilter.PropertyIndices;
                            break;
                        }
                        else
                            superType = superType.IfcSuperType;
                    }

                    if (superType == null)
                        _parseFilter.Add(new IfcFilter(ifcType, idx));
                }

                foreach (Type subType in ifcType.NonAbstractSubTypes)
                {
                    if (subType != ifcType.Type) AddEntity(IfcInstances.IfcEntities[subType]);
                }

                foreach (IfcMetaProperty prop in ifcType.IfcProperties.Values)
                {
                    if (includedProperties == null || includedProperties.Length == 0 ||
                        includedProperties.Contains(prop.IfcAttribute.Order - 1))
                    {
                        Type propType = prop.PropertyInfo.PropertyType;
                        if (typeof (ExpressEnumerable).IsAssignableFrom(propType)) //its a list
                        {
                            Type genType = GetGenericType(propType);
                            if (genType != null && IfcInstances.IfcEntities.Contains(genType))
                                AddEntity(IfcInstances.IfcEntities[genType]);
                            if (genType.IsInterface)
                            {
                                //get the types that are like this
                                foreach (IfcType ent in IfcInstances.IfcEntities)
                                {
                                    if (genType.IsAssignableFrom(ent.Type))
                                        AddEntity(ent);
                                }
                            }
                        }
                        else if (propType.IsInterface) //its a select type
                        {
                            //get the types that are like this
                            foreach (IfcType ent in IfcInstances.IfcEntities)
                            {
                                if (propType.IsAssignableFrom(ent.Type))
                                    AddEntity(ent);
                            }
                        }
                        else if (typeof (IPersistIfc).IsAssignableFrom(propType) &&
                                 IfcInstances.IfcEntities.Contains(propType)) //its a normal entity
                        {
                            IfcType ifcPropType = IfcInstances.IfcEntities[propType];
                            AddEntity(ifcPropType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 39
0
 public IfcFilter(IfcType type, params int[] propertyIndices)
     : this(type)
 {
     _propertyIndices = propertyIndices;
 }