public void SetInversePropertyVal(QLEntity entity, string propertyName, QLEntityId qlEntityId, bool deleteOld) { var index = repository.InversePropertyIndex(entity.ClassName, propertyName); var part = entity.QlInverseList.List[index]; if (deleteOld || (part.QLEntityId == null && part.QLList == null)) { entity.QlInverseList.List[index] = new QLPart() { QLEntityId = qlEntityId } } ; else { if (part.QLEntityId != null) { var list = new QLList(); list.Add(new QLPart() { QLEntityId = part.QLEntityId }); list.Add(new QLPart() { QLEntityId = qlEntityId }); part.QLEntityId = null; part.QLList = list; } else { part.QLList.Add(new QLPart() { QLEntityId = qlEntityId }); } } }
public QLEntity[] LoadIfcFile(string ifcFilename) { bool currentIfc4; var linesAsString = ExtractEntityLines(ifcFilename, out currentIfc4); QLEntityId.SetStartId(); var scanner = new Scanner(linesAsString.ToStream()); var parser = new Parser(scanner); var oldSchema = parser.QLExchangeFile.CurrentSchema; parser.QLExchangeFile.CurrentSchema = currentIfc4 ? Schema.Ifc4 : Schema.Ifc2X3; parser.Parse(); if (entityLines.Count == 0 || parser.QLExchangeFile.CurrentSchema != oldSchema) { isIfc4 = currentIfc4; LoadSchema(); } var entities = parser.QLExchangeFile.QLExchangeFiles.ToArray(); classNameToProperties = new Dictionary <string, List <QLProperty> >(); invertedAttributeReversed = new Dictionary <string, HashSet <Tuple <string, string, string> > >(); var entitiesWithPropNames = entities.Select(e => LookUpPropertyNames(entityLines, e)).Where(e => e != null).ToArray(); foreach (var pair in classNameToProperties) { foreach (var inverseProp in pair.Value.Where(p => p.Inverse)) { var className = pair.Key; var splittedTyp = inverseProp.Type.Split(' '); var inverseTyp = splittedTyp.First(t => t.StartsWith("Ifc")).ToUpper(); var inverseAttribute = splittedTyp.Last(); var hashSet = new HashSet <string>(); if (inheritanceNodes.ContainsKey(inverseTyp)) { var basetype = inheritanceNodes[inverseTyp]; var queue = new Queue <P21InheritanceNode>(); queue.Enqueue(basetype); while (queue.Count > 0) { var current = queue.Dequeue(); hashSet.Add(current.Name); foreach (var subtype in current.Subtypes) { if (!hashSet.Contains(subtype.Name)) { queue.Enqueue(subtype); hashSet.Add(subtype.Name); } } } foreach (var typeName in hashSet) { AddInverseAttribute(typeName, inverseAttribute, inverseProp, className); } } else { AddInverseAttribute(inverseTyp, inverseAttribute, inverseProp, className); } } } var idToEntity = new Dictionary <int, QLEntity>(); foreach (var entity in entitiesWithPropNames) { idToEntity.Add(entity.Id, entity); } foreach (var entity in entitiesWithPropNames) { SetInverseValues(entity, entity.QLDirectList, 0, 0, idToEntity); } invertedAttributeReversed.Clear(); typeNameToNetType.Clear(); classNameToProperties.Clear(); entityLines.Clear(); return(entitiesWithPropNames); }