예제 #1
0
        internal bool AppliesTo(IPersistIfcEntity SelectedEntity)
        {
            IfcType ifcType = IfcMetaData.IfcType(ConceptRoot.applicableRootEntity.ToUpperInvariant());
            IfcType seltype = IfcMetaData.IfcType(SelectedEntity);

            return(ifcType == seltype || ifcType.IfcSubTypes.Contains(seltype));
        }
예제 #2
0
        public bool Resolve(ConcurrentDictionary <int, IPersistIfcEntity> references)
        {
            IPersistIfcEntity entity;

            if (references.TryGetValue(ReferenceEntityLabel, out entity))
            {
                PropertyValue pv = new PropertyValue();
                pv.Init(entity);
                try
                {
                    ReferencingEntity.IfcParse(ReferencingPropertyId, pv);
                    return(true);
                }
                catch (Exception)
                {
                    IfcType ifcType = IfcMetaData.IfcType(ReferencingEntity);

                    XbimModel.Logger.ErrorFormat("Data Error. Cannot set the property = {0} of entity #{1} = {2} to entity #{3}, schema violation. Ignored",
                                                 ifcType.IfcProperties[ReferencingPropertyId + 1].PropertyInfo.Name,
                                                 ReferencingEntity.EntityLabel,
                                                 ReferencingEntity.GetType().Name,
                                                 ReferenceEntityLabel);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
 internal bool TrySetObjectValue(IPersistIfc host, int paramIndex, int refID)
 {
     if (_deferListItems)
     {
         return(false);
     }
     try
     {
         IPersistIfc refEntity;
         if (_entities.TryGetValue(refID, out refEntity) && host != null)
         {
             _propertyValue.Init(refEntity);
             (host).IfcParse(paramIndex, _propertyValue);
             return(true);
         }
     }
     catch (Exception)
     {
         if (_errorCount > MaxErrorCount)
         {
             throw new Exception("Too many errors in file, parser execution terminated");
         }
         _errorCount++;
         IfcType ifcType      = IfcMetaData.IfcType(host);
         string  propertyName = paramIndex + 1 > ifcType.IfcProperties.Count ? "[UnknownProperty]" :
                                ifcType.IfcProperties[paramIndex + 1].PropertyInfo.Name;
         Logger.ErrorFormat("Entity #{0,-5} {1}, error at parameter {2}-{3}",
                            refID, ifcType.Type.Name.ToUpper(), paramIndex + 1,
                            propertyName);
     }
     return(false);
 }
        private void FillTypeData()
        {
            if (_typeProperties.Count > 0)
            {
                return;                            //don't fill unless empty
            }
            IfcObject ifcObj = _entity as IfcObject;

            if (ifcObj != null)
            {
                IfcTypeObject typeEntity = ifcObj.GetDefiningType();
                if (typeEntity != null)
                {
                    IfcType ifcType = IfcMetaData.IfcType(typeEntity);
                    _typeProperties.Add(new PropertyItem()
                    {
                        Name = "Type", Value = ifcType.Type.Name
                    });
                    _typeProperties.Add(new PropertyItem()
                    {
                        Name = "Ifc Label", Value = "#" + typeEntity.EntityLabel
                    });

                    _typeProperties.Add(new PropertyItem()
                    {
                        Name = "Name", Value = typeEntity.Name
                    });
                    _typeProperties.Add(new PropertyItem()
                    {
                        Name = "Description", Value = typeEntity.Description
                    });
                    _typeProperties.Add(new PropertyItem()
                    {
                        Name = "GUID", Value = typeEntity.GlobalId
                    });
                    _typeProperties.Add(new PropertyItem()
                    {
                        Name  = "Ownership",
                        Value = typeEntity.OwnerHistory.OwningUser.ToString() + " using " + typeEntity.OwnerHistory.OwningApplication.ApplicationIdentifier
                    });
                    //now do properties in further specialisations that are text labels
                    foreach (var pInfo in ifcType.IfcProperties.Where
                                 (p => p.Value.IfcAttribute.Order > 4 &&
                                 p.Value.IfcAttribute.State != IfcAttributeState.DerivedOverride)
                             ) //skip the first for of root, and derived and things that are objects
                    {
                        object val = pInfo.Value.PropertyInfo.GetValue(typeEntity, null);
                        if (val != null && val is ExpressType) //only do express types
                        {
                            PropertyItem pi = new PropertyItem()
                            {
                                Name = pInfo.Value.PropertyInfo.Name, Value = ((ExpressType)val).ToPart21
                            };
                            _typeProperties.Add(pi);
                        }
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IEnumerable <int> Run(XbimModel model)
        {
            foreach (var label in _entityLabelsToParse)
            {
                if (_transverse)
                {
                    yield return(label);
                }
                else if (_queryCommand.Trim() == "")
                {
                    yield return(label);
                }
                var entity = model.Instances[label];
                if (entity != null)
                {
                    IfcType ifcType = IfcMetaData.IfcType(entity);
                    // directs first
                    SquareBracketIndexer sbi = new SquareBracketIndexer(_queryCommand);

                    var prop = ifcType.IfcProperties.Where(x => x.Value.PropertyInfo.Name == sbi.Property).FirstOrDefault().Value;
                    if (prop == null) // otherwise test inverses
                    {
                        prop = ifcType.IfcInverses.Where(x => x.PropertyInfo.Name == sbi.Property).FirstOrDefault();
                    }
                    if (prop != null)
                    {
                        object propVal = prop.PropertyInfo.GetValue(entity, null);
                        if (propVal != null)
                        {
                            if (prop.IfcAttribute.IsEnumerable)
                            {
                                IEnumerable <object> propCollection = propVal as IEnumerable <object>;
                                if (propCollection != null)
                                {
                                    propCollection = sbi.GetItem(propCollection);
                                    foreach (var item in propCollection)
                                    {
                                        IPersistIfcEntity pe = item as IPersistIfcEntity;
                                        if (pe != null)
                                        {
                                            yield return(pe.EntityLabel);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                IPersistIfcEntity pe = propVal as IPersistIfcEntity;
                                if (pe != null && sbi.Index < 1) // index is negative (not specified) or 0
                                {
                                    yield return(pe.EntityLabel);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
        public static XbimMaterialProvider GetDefaultMaterial(string typeName)
        {
            Material mat;
            IfcType  elemType = IfcMetaData.IfcType(typeName.ToUpperInvariant());

            while (elemType != null)
            {
                if (_defaultMaterials.TryGetValue(elemType.Type.Name, out mat))
                {
                    return(new XbimMaterialProvider(mat));
                }
                elemType = elemType.IfcSuperType;
            }
            return(null);
        }
        public Int32 StartComparison(XbimModel baseline, XbimModel revision, string filter = "")
        {
            Baseline = baseline;
            Revision = revision;

            Int32 ret = 0;

            if (filter == "")
            {
                // default behaviour (maintained during code review) is to test only for IfcProducts
                //
                WorkingCopyBaseline = Baseline.Instances.OfType <IfcProduct>().ToList <IfcRoot>();
                WorkingCopyDelta    = Revision.Instances.OfType <IfcProduct>().ToList <IfcRoot>();

                //get guids into dictionary
                var MyTemp = WorkingCopyBaseline.Select(p => new baselineitem {
                    GUID = p.GlobalId, Label = p.EntityLabel, Name = p.Name, MyType = p.GetType()
                }).ToList();

                //list duplicate Guids in Model
                DuplicateBaseItems.AddRange(MyTemp.GroupBy(k => k.GUID).Where(g => g.Count() > 1).Select(g => g.Key));
                if (DuplicateBaseItems.Count > 0)
                {
                    Message(String.Format("Warning {0} Duplicate Guids found in Model", DuplicateBaseItems.Count));
                }
                var comparer     = new VersionGuidComparitor();
                var MyDictionary = MyTemp.Distinct <baselineitem>(comparer).ToDictionary(k => k.GUID, v => v); //think GroupBy?

                ret += StartProductsComparison();
            }
            else
            {
                IfcType ot = IfcMetaData.IfcType(filter.ToUpper());
                if (ot != null)
                {
                    if (ot.Type.IsSubclassOf(typeof(IfcRoot)))
                    {
                        WorkingCopyBaseline = new List <IfcRoot>(Baseline.Instances.OfType(filter, false).Cast <IfcRoot>());
                        WorkingCopyDelta    = new List <IfcRoot>(Revision.Instances.OfType(filter, false).Cast <IfcRoot>());
                        ret += StartProductsComparison();
                    }
                }
            }
            return(ret);
        }
예제 #8
0
        public Dictionary <string, XbimGeometryHandleCollection> GroupLayers(XbimGeometryHandleCollection InputHandles)
        {
            // creates a new dictionary and then fills it by type enumerating the known non-abstract subtypes of Product
            Dictionary <string, XbimGeometryHandleCollection> result = new Dictionary <string, XbimGeometryHandleCollection>();
            IfcType baseType = IfcMetaData.IfcType(typeof(IfcProduct));

            foreach (var subType in baseType.NonAbstractSubTypes)
            {
                short ifcTypeId = IfcMetaData.IfcTypeId(subType);
                XbimGeometryHandleCollection handles = new XbimGeometryHandleCollection(InputHandles.Where(g => g.IfcTypeId == ifcTypeId));

                // only add the item if there are handles in it
                if (handles.Count > 0)
                {
                    result.Add(subType.Name, handles);
                }
            }
            return(result);
        }
예제 #9
0
        private void SetEntityParameter(string value)
        {
            try
            {
                if (_currentInstance.Entity != null)
                {
                    _currentInstance.ParameterSetter(_currentInstance.CurrentParamIndex, _propertyValue);
                }
            }
            catch (Exception)
            {
                if (_errorCount > MaxErrorCount)
                {
                    throw new Exception("Too many errors in file, parser execution terminated");
                }
                _errorCount++;
                Part21Entity mainEntity = _processStack.Last();
                if (mainEntity != null)
                {
                    IfcType ifcType = IfcMetaData.IfcType(mainEntity.Entity);

                    string propertyName = mainEntity.CurrentParamIndex + 1 > ifcType.IfcProperties.Count ? "[UnknownProperty]" :
                                          ifcType.IfcProperties[mainEntity.CurrentParamIndex + 1].PropertyInfo.Name;

                    Logger.ErrorFormat("Entity #{0,-5} {1}, error at parameter {2}-{3} value = {4}",
                                       mainEntity.EntityLabel,
                                       mainEntity.Entity.GetType().Name.ToUpper(),
                                       mainEntity.CurrentParamIndex + 1,
                                       propertyName,
                                       value);
                }
                else
                {
                    Logger.Error("Unhandled Parser error, in Parser.cs SetEntityParameter");
                }
            }
            if (_listNestLevel == 0)
            {
                _currentInstance.CurrentParamIndex++;
                _deferListItems = false;
            }
        }
예제 #10
0
        internal override void EndEntity()
        {
            Part21Entity p21 = _processStack.Pop();

            Debug.Assert(_processStack.Count == 0);
            _currentInstance = null;
            if (_currentType != null)
            {
                _binaryWriter.Write((byte)P21ParseAction.EndEntity);
                IfcType      ifcType = IfcMetaData.IfcType(_currentType);
                MemoryStream data    = _binaryWriter.BaseStream as MemoryStream;
                byte[]       bytes   = data.ToArray();
                List <int>   keys    = new List <int>(_indexKeyValues);
                toStore.Add(new Tuple <int, short, List <int>, byte[], bool>(_currentLabel, ifcType.TypeId, keys, bytes, ifcType.IndexedClass));
                if (this.modelCache.IsCaching)
                {
                    toProcess.Add(new Tuple <int, Type, byte[]>(_currentLabel, ifcType.Type, bytes));
                }
            }
        }
예제 #11
0
        internal override void SetType(string entityTypeName)
        {
            if (InHeader)
            {
                IPersistIfc currentHeaderEntity;
                switch (entityTypeName)
                {
                case "FILE_DESCRIPTION":
                    currentHeaderEntity = _header.FileDescription;
                    break;

                case "FILE_NAME":
                    currentHeaderEntity = _header.FileName;
                    break;

                case "FILE_SCHEMA":
                    currentHeaderEntity = _header.FileSchema;
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid Header entity type {0}", entityTypeName));
                }
                _currentInstance = new Part21Entity(currentHeaderEntity);
                _processStack.Push(_currentInstance);
            }
            else
            {
                _currentType = entityTypeName;
                IfcType ifcType = IfcMetaData.IfcType(_currentType);
                if (ifcType == null)
                {
                    throw new ArgumentException(string.Format("Invalid entity type {0}", _currentType));
                }

                _indexKeys = ifcType.IndexedValues;
            }
        }
        public static bool PassesRule(this IPersistIfc Entity, MvdRule DataNode, MvdPropertyRuleValue requirement = null, PassMode PassMode = PassMode.Undefined)
        {
            // todo: add controls for schema cardinality
            //

            IfcType EntType = IfcMetaData.IfcType(Entity);

#if SYSDEBUG
            Debug.WriteLine(string.Format("testing {0} for {1}", Entity.ToString(), DataNode.Type));
#endif
            string RuleId        = "";
            bool   bEvaluateRule = false;
            if (DataNode.Properties.ContainsKey("RuleID") && requirement != null)
            {
                RuleId        = DataNode.Properties["RuleID"];
                bEvaluateRule = (requirement.Name == RuleId);
                // here the property is evaluated.
                if (bEvaluateRule)
                {
#if SYSDEBUG
                    Debug.Write("-- Evaluating");
#endif
                    if (Entity is IPersistIfcEntity)
                    {
                        Debug.Write(string.Format("Req: {0} Ent: {1}{2}\r\n", requirement.Name, Math.Abs(((IPersistIfcEntity)Entity).EntityLabel), EntType));
                    }
                    if (requirement.Prop == "Type")
                    {
                        string cmpVal = IfcMetaData.IfcType(Entity).Name;
                        return(requirement.Val == cmpVal);
                    }
                }
            }


            if (DataNode.Type == "AttributeRule")
            {
                string propName = DataNode.Properties["AttributeName"];
                var    prop     = EntType.IfcProperties.Where(x => x.Value.PropertyInfo.Name == propName).FirstOrDefault().Value;
                if (prop == null) // otherwise test inverses
                {
                    prop = EntType.IfcInverses.Where(x => x.PropertyInfo.Name == propName).FirstOrDefault();
                }
                if (prop == null)
                {
#if SYSDEBUG
                    Debug.WriteLine("AttributeRule failed on null value");
#endif
                    return(false);
                }

                object propVal = prop.PropertyInfo.GetValue(Entity, null);
                if (propVal == null)
                {
                    return(false);
                }
                if (propVal != null)
                {
                    if (bEvaluateRule)
                    {
                        if (requirement.Prop == "Value")
                        {
                            string cmpVal = propVal.ToString();
                            bool   retVal = (requirement.Val == cmpVal);
#if SYSDEBUG
                            if (requirement.Val.StartsWith(""))
                            {
                            }

                            if (!retVal)
                            {
                                Debug.WriteLine("AttributeRule failed on value");
                            }
#endif

                            return(retVal);
                        }
                    }
                    else if (requirement == null && propVal is IPersistIfc)
                    {
                        var  v            = (IPersistIfc)propVal;
                        bool AnyChildFail = false;
                        foreach (var nestedRule in DataNode.NestedRules)
                        {
                            Debug.Indent();
                            if (!v.PassesRule(nestedRule))
                            {
                                AnyChildFail = true;
                                Debug.Unindent();
                                break;
                            }
                            Debug.Unindent();
                        }
                        return(!AnyChildFail);
                    }

                    if (prop.IfcAttribute.IsEnumerable)
                    {
                        IEnumerable <object> propCollection = propVal as IEnumerable <object>;
                        if (propCollection == null)
                        {
                            return(false);
                        }
                        foreach (var child in propCollection)
                        {
                            if (child is IPersistIfc)
                            {
                                // todo: this might actually have to return fail if any nested rule fail, not if the first passes.
                                foreach (var nestedRule in DataNode.NestedRules)
                                {
                                    Debug.Indent();
                                    var loopret = ((IPersistIfc)child).PassesRule(nestedRule, requirement, PassMode);
                                    Debug.Unindent();
                                    if (loopret)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IPersistIfc pe = propVal as IPersistIfc;
                        if (pe == null)
                        {
#if SYSDEBUG
                            Debug.WriteLine("AttributeRule failed: not found");
#endif
                            return(false);
                        }
                        foreach (var nestedRule in DataNode.NestedRules)
                        {
                            if (pe.PassesRule(nestedRule, requirement))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else if (DataNode.Type == "EntityRule")
            {
                string  EName     = DataNode.Properties["EntityName"];
                IfcType ENameType = IfcMetaData.IfcType(EName.ToUpperInvariant());
                if (ENameType != null)
                {
                    // run type validation only if type matches
                    if (!(ENameType == EntType || ENameType.NonAbstractSubTypes.Contains(EntType.Type)))
                    {
#if SYSDEBUG
                        Debug.WriteLine("EntityRule failed: expected " + EName + " found: " + EntType.ToString());
#endif
                        return(false);
                    }
                    // if test is passed and no sub rules then return true
                    if (!DataNode.NestedRules.Any())
                    {
                        return(true);
                    }
                }
                else
                {
                    Debug.WriteLine("Probably IFC4 Type specified:" + EName);
                }
                foreach (var subRule in DataNode.NestedRules)
                {
                    var passed = Entity.PassesRule(subRule, requirement);
                    if (passed)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #13
0
 public static XbimMaterialProvider GetDefaultMaterial(IfcType ifcType)
 {
     return(GetDefaultMaterial(ifcType.Type.Name));
 }
예제 #14
0
        public static XbimMaterialProvider GetDefaultMaterial(short entityTypeId)
        {
            IfcType ifcType = IfcMetaData.IfcType(entityTypeId);

            return(GetDefaultMaterial(ifcType.Type.Name));
        }
예제 #15
0
        public Dictionary <string, XbimGeometryHandleCollection> GroupLayers(XbimGeometryHandleCollection inputHandles)
        {
            // creates a new dictionary and then fills it by type enumerating the known non-abstract subtypes of Product
            Dictionary <string, XbimGeometryHandleCollection> result = new Dictionary <string, XbimGeometryHandleCollection>();

            // prepares transparents first
            HashSet <short> traspTypes = new HashSet <short>();

            foreach (var ttp in _lightTransparentTypes)
            {
                traspTypes.Add(IfcMetaData.IfcTypeId(ttp));
            }
            XbimGeometryHandleCollection transp = new XbimGeometryHandleCollection(
                inputHandles.Where(g =>
                                   traspTypes.Contains(g.IfcTypeId)
                                   ||
                                   _lightTransparentEntities.Contains(g.ProductLabel)
                                   )
                );

            result.Add("_LightBlueTransparent", transp);

            // deal with ignore elements
            HashSet <short> hiddTypes = new HashSet <short>();

            foreach (var htp in _hiddenTypes)
            {
                hiddTypes.Add(IfcMetaData.IfcTypeId(htp));
            }
            XbimGeometryHandleCollection hidd = new XbimGeometryHandleCollection(
                inputHandles.Where(g =>
                                   hiddTypes.Contains(g.IfcTypeId)
                                   ||
                                   _hiddenEntities.Contains(g.ProductLabel)
                                   )
                );

            // now execute normal type loop, but with the exclusion of hidden and transparent
            //
            IfcType baseType = IfcMetaData.IfcType(typeof(IfcProduct));

            foreach (var subType in baseType.NonAbstractSubTypes)
            {
                short ifcTypeId = IfcMetaData.IfcTypeId(subType);
                XbimGeometryHandleCollection handles = new XbimGeometryHandleCollection(
                    inputHandles.Where(g =>
                                       g.IfcTypeId == ifcTypeId
                                       &&
                                       !(transp.Contains(g))
                                       &&
                                       !(hidd.Contains(g))
                                       )
                    );

                // only add the item if there are handles in it
                if (handles.Count > 0)
                {
                    result.Add(subType.Name, handles);
                }
            }
            return(result);
        }