internal void BeginNestedType(string typeName) { IfcType ifcType = IfcMetaData.IfcType(typeName); _currentInstance = new Part21Entity((IPersistIfc)Activator.CreateInstance(ifcType.Type)); _processStack.Push(_currentInstance); }
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); }
/// <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); }
/// <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); }
/// <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); }
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(); }
/// <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); } } }
/// <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); } } }
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> /// 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(");"); }
public IfcType this[string ifcTypeName] { get { return(IfcMetaData.IfcType(ifcTypeName)); } }
/// <summary> /// Returns the Xbim meta data about the Ifc Properties of the Type /// </summary> /// <param name="entity"></param> /// <returns></returns> public static IfcType IfcType(this IPersistIfcEntity entity) { return(IfcMetaData.IfcType(entity)); }
internal IfcType IfcType() { return(IfcMetaData.IfcType(EntityTypeId)); }