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); }
public static IModel ModelOf(IPersistIfcEntity instance) { #if SupportActivation if (instance.ModelOf != null) { return(instance.ModelOf); } else #endif if (instance == _lastAccessedInstance) { return(_lastAccessedModel); } if (_lastAccessedModel != null && _lastAccessedModel.ContainsInstance(instance)) //try this first to improve performance { _lastAccessedInstance = instance; return(_lastAccessedModel); } else { foreach (IModel model in _models.Where(m => m != _lastAccessedModel)) { if (model.ContainsInstance(instance)) { _lastAccessedModel = model; _lastAccessedInstance = instance; return(model); } } } throw new ArgumentException( "Failure in ModelManager.ModelOf, the instance is in none of the current models", "instance"); }
/// <summary> /// Set a property /field value, if a transaction is active it is transacted and undoable, if the owner supports INotifyPropertyChanged, the required events will be raised /// </summary> /// <typeparam name = "TProperty"></typeparam> /// The property type to be set /// <param name = "field"></param> /// The field to be set /// <param name = "newValue"></param> /// The value to set the field to /// <param name = "setter"></param> /// The function to set and unset the field /// <param name = "notifyPropertyName"></param> /// A list of property names of the owner to raise notification on internal static void SetModelValue <TProperty>(this IPersistIfc entity, IPersistIfcEntity target, ref TProperty field, TProperty newValue, ReversibleInstancePropertySetter <TProperty> setter, string notifyPropertyName) { //The object must support Property Change Notification so notify ISupportChangeNotification iPropChanged = target as ISupportChangeNotification; if (iPropChanged != null) { target.Activate(true); // Transaction.AddPropertyChange(setter, field, newValue); iPropChanged.NotifyPropertyChanging(notifyPropertyName); field = newValue; //target.ModelOf.Update(target); iPropChanged.NotifyPropertyChanged(notifyPropertyName); } else { throw new Exception( string.Format( "Request to Notify Property Changes on type {0} that does not support ISupportChangeNotification", target.GetType().Name)); } }
internal void SetObjectValue(IPersistIfc value) { _propertyValue.Init(value); //CurrentInstance.SetPropertyValue(PropertyValue); _currentInstance.Entity.IfcParse(_currentInstance.CurrentParamIndex, _propertyValue); if (_listNestLevel == 0) { _currentInstance.CurrentParamIndex++; } }
/// <summary> /// Handles the case where a property was not expected for this entity. /// </summary> /// <param name="persistIfc">The item being parsed.</param> /// <param name="propIndex">Index of the property.</param> /// <param name="value">The value of the property.</param> internal static void HandleUnexpectedAttribute(this IPersistIfc persistIfc, int propIndex, IPropertyValue value) { // TODO: Review this workaround for older IFC files with extraneous properties if (value.Type == IfcParserType.Enum && String.Compare(value.EnumVal, "NOTDEFINED") == 0) { return; } throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, persistIfc.GetType().Name.ToUpper())); }
public DeferredReference(int paramIndex, IPersistIfc hostEntity, int refID) { ParameterIndex = paramIndex; HostEntity = hostEntity; ReferenceID = refID; }
internal void Init(IPersistIfc iPersistIfc) { _object = iPersistIfc; _parserType = IfcParserType.Entity; }
public static short IfcTypeId(IPersistIfc entity) { return(TypeToIfcTypeLookup[entity.GetType()].TypeId); }
public IfcType this[IPersistIfc ent] { get { return(this[ent.GetType()]); } }
public Part21Entity(long label, IPersistIfc ent) { EntityLabel = label; Entity = ent; }
public Part21Entity(IPersistIfc ent) : this(-1, ent) { }
public Part21Entity(string label, IPersistIfc ent) : this(Convert.ToInt64(label.TrimStart('#')), ent) { }
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); }
private void EndElement(XmlReader input, XmlNodeType prevInputType, string prevInputName, out IPersistIfcEntity writeEntity) { try { // before end element, we need to deal with SetCollection if (_currentNode is XmlCollectionProperty) { // SetCollection will handle SetValue for Collection CollectionType CType = ((XmlCollectionProperty)_currentNode).CType; switch (CType) { case CollectionType.List: case CollectionType.ListUnique: ((XmlCollectionProperty)_currentNode).Entities.Sort(XmlCollectionProperty.CompareNodes); break; case CollectionType.Set: break; default: throw new Exception("Unknown list type, " + CType); } foreach (XmlNode item in ((XmlCollectionProperty)_currentNode).Entities) { if (item is XmlEntity) { XmlEntity node = (XmlEntity)item; XmlEntity collectionOwner = item.Parent.Parent as XmlEntity; XmlCollectionProperty collection = item.Parent as XmlCollectionProperty; //the collection to add to; IPersistIfc ifcCollectionOwner = collectionOwner.Entity; PropertyValue pv = new PropertyValue(); pv.Init(node.Entity); ifcCollectionOwner.IfcParse(collection.PropertyIndex - 1, pv); } } } else if (_currentNode.Parent is XmlProperty) { XmlProperty propNode = (XmlProperty)_currentNode.Parent; if (_currentNode is XmlEntity) { XmlEntity entityNode = (XmlEntity)_currentNode; propNode.SetValue(entityNode.Entity); } else if (_currentNode is XmlExpressType) { //create ExpressType, call ifcparse with propindex and object //((XmlProperty)_currentNode.Parent).SetValue((XmlExpressType)_currentNode); XmlExpressType expressNode = (XmlExpressType)_currentNode; if (expressNode.Type != propNode.Property.PropertyType) { //propNode.SetValue(expressNode); IfcType ifcType; if (IsIfcType(input.LocalName, out ifcType)) //we have an IPersistIfc { IPersistIfc ent; object[] param = new object[1]; param[0] = expressNode.Value; ent = (IPersistIfc)Activator.CreateInstance(ifcType.Type, param); propNode.SetValue(ent); } } else { propNode.SetValue(expressNode.Value, primitives[expressNode.Type.Name]); } } else if (_currentNode is XmlBasicType) { //set PropertyValue to write type boolean, integer, call ifcparse with string XmlBasicType basicNode = (XmlBasicType)_currentNode; propNode.SetValue(basicNode.Value, basicNode.Type); } } else if (prevInputType == XmlNodeType.Element && prevInputName == input.LocalName && _currentNode is XmlProperty && _currentNode.Parent != null && _currentNode.Parent is XmlEntity) { // WE SHOULDNT EXECUTE THE FOLLOWING CODE IF THIS PROPERTY ALREADY CALLED SETVALUE XmlProperty node = (XmlProperty)_currentNode; PropertyValue propVal = new PropertyValue(); Type t = node.Property.PropertyType; if (t != null && t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { t = Nullable.GetUnderlyingType(t); } ExpressType et = null; if (t != null && typeof(ExpressType).IsAssignableFrom(t)) { et = (ExpressType)(Activator.CreateInstance(t)); } IfcParserType pt = IfcParserType.Undefined; if (et != null) { pt = primitives[et.UnderlyingSystemType.Name]; } else { if (t.IsEnum) { pt = IfcParserType.Enum; } else if (primitives.ContainsKey(t.Name)) { pt = primitives[t.Name]; } } if (pt != IfcParserType.Undefined) { if (pt.ToString().ToLower() == "string") { propVal.Init("'" + input.Value + "'", pt); } else { if (pt.ToString().ToLower() == "boolean") { propVal.Init(Convert.ToBoolean(input.Value) ? ".T." : ".F", pt); } else { propVal.Init(input.Value, pt); } } ((XmlEntity)node.Parent).Entity.IfcParse(node.PropertyIndex - 1, propVal); } } else if (_currentNode.Parent is XmlCollectionProperty && !(_currentNode.Parent is XmlUosCollection)) { if (_currentNode is XmlEntity) { ((XmlCollectionProperty)_currentNode.Parent).Entities.Add(((XmlEntity)_currentNode)); } else if (_currentNode is XmlExpressType) { XmlExpressType expressNode = (XmlExpressType)_currentNode; //actualEntityType is the actual type of the value to create Type actualEntityType = expressNode.Type; //Determine if the Express Type is a Nullable, if so get the type of the Nullable if (actualEntityType.IsGenericType && actualEntityType.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { actualEntityType = Nullable.GetUnderlyingType(actualEntityType); } //need to resolve what the Parser type is //if the generic type of the collection is different from the actualEntityType then we need to create an entity and call Ifc Parse //otherwise we need to call Ifcparse with a string value and the type of the underlying type XmlCollectionProperty collection = _currentNode.Parent as XmlCollectionProperty; //the collection to add to; Type collectionValueType = collection.Property.PropertyType; Type collectionGenericType = GetItemTypeFromGenericType(collectionValueType);; bool genericTypeIsSameAsValueType = (collectionGenericType == actualEntityType); PropertyValue pv = new PropertyValue(); if (genericTypeIsSameAsValueType) //call IfcParse with string value and parser type { ExpressType actualEntityValue = (ExpressType)(Activator.CreateInstance(actualEntityType)); //resolve the underlying type IfcParserType parserType = primitives[actualEntityValue.UnderlyingSystemType.Name]; if (parserType == IfcParserType.String) { pv.Init("'" + expressNode.Value + "'", parserType); } else { pv.Init(expressNode.Value, parserType); } } else //call IfcParse with an entity { object[] param = new object[1]; param[0] = expressNode.Value; ExpressType actualEntityValue = (ExpressType)(Activator.CreateInstance(expressNode.Type, param)); pv.Init(actualEntityValue); } XmlEntity collectionOwner = _currentNode.Parent.Parent as XmlEntity; //go to owner of collection IPersistIfc ifcCollectionOwner = collectionOwner.Entity; ifcCollectionOwner.IfcParse(collection.PropertyIndex - 1, pv); } else if (_currentNode is XmlBasicType) { XmlBasicType basicNode = (XmlBasicType)_currentNode; XmlEntity collectionOwner = _currentNode.Parent.Parent as XmlEntity; XmlCollectionProperty collection = _currentNode.Parent as XmlCollectionProperty; //the collection to add to; IPersistIfc ifcCollectionOwner = collectionOwner.Entity; PropertyValue pv = new PropertyValue(); pv.Init(basicNode.Value, basicNode.Type); ifcCollectionOwner.IfcParse(collection.PropertyIndex - 1, pv); } } writeEntity = null; if (_currentNode.Parent != null) // we are not at UOS yet { if (_currentNode is XmlEntity) { writeEntity = ((XmlEntity)_currentNode).Entity; } _currentNode = _currentNode.Parent; } } catch (Exception e) { throw new Exception("Error reading IfcXML data at node " + input.LocalName, e); } }
public static short IfcTypeId(IPersistIfc entity) { return TypeToIfcTypeLookup[entity.GetType()].TypeId; }
internal void SetObjectValue(IPersistIfc value) { _propertyValue.Init(value); //CurrentInstance.SetPropertyValue(PropertyValue); _currentInstance.Entity.IfcParse(_currentInstance.CurrentParamIndex, _propertyValue); if (_listNestLevel == 0) _currentInstance.CurrentParamIndex++; }
/// <summary> /// Returns the IfcType of the specified entity /// </summary> /// <param name="entity"></param> /// <returns></returns> public static IfcType IfcType(IPersistIfc entity) { return TypeToIfcTypeLookup[entity.GetType()]; }
/// <summary> /// Returns the IfcType of the specified entity /// </summary> /// <param name="entity"></param> /// <returns></returns> public static IfcType IfcType(IPersistIfc entity) { return(TypeToIfcTypeLookup[entity.GetType()]); }
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; }