public SimpleGroup(IfcGroup group, SimpleGroup parent) { if (group == null) throw new ArgumentNullException(); _group = group; _parent = parent; Init(); }
private void Init() { _children = new List<SimpleGroup>(); _buildingElementTypes = new List<SimpleBuildingElementType>(); IEnumerable<IfcRelAssignsToGroup> rels = _model.Instances.Where<IfcRelAssignsToGroup>(r => r.RelatingGroup == _group).ToList(); if (rels.FirstOrDefault() == null) { using (XbimReadWriteTransaction trans = _model.BeginTransaction("Group relation creation")) { var rel = _model.Instances.New<IfcRelAssignsToGroup>(r => r.RelatingGroup = _group); trans.Commit(); (rel as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler(RelationChanged); (rel.RelatedObjects as INotifyCollectionChanged).CollectionChanged -= new NotifyCollectionChangedEventHandler(ElementCollectionChanged); (rel.RelatedObjects as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(ElementCollectionChanged); } } else { foreach (var rel in rels) { (rel as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler(RelationChanged); (rel.RelatedObjects as INotifyCollectionChanged).CollectionChanged -= new NotifyCollectionChangedEventHandler(ElementCollectionChanged); (rel.RelatedObjects as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(ElementCollectionChanged); IEnumerable<IfcGroup> groups = rel.RelatedObjects.OfType<IfcGroup>(); foreach (IfcGroup group in groups) { SimpleGroup child = new SimpleGroup(group, this); child.PropertyChanged += new PropertyChangedEventHandler(ChildChanged); _children.Add(child); } IEnumerable<IfcTypeProduct> types = rel.RelatedObjects.OfType<IfcTypeProduct>(); foreach (var type in types) { SimpleBuildingElementType simpleType = new SimpleBuildingElementType(type); simpleType.PropertyChanged -= new PropertyChangedEventHandler(TypeChanged); simpleType.PropertyChanged += new PropertyChangedEventHandler(TypeChanged); _buildingElementTypes.Add(simpleType); } } } }
private static SimpleBuildingElementType GetTypeFromHierarchy(IfcTypeProduct type, SimpleGroup group) { SimpleBuildingElementType simpleType = group._buildingElementTypes.Where(t => t.IfcType == type).FirstOrDefault(); if (simpleType != null) return simpleType; foreach (var subGroup in group._children) { simpleType = GetTypeFromHierarchy(type, subGroup); if (simpleType != null) return simpleType; } return null; }