internal static List <CcManufacturerProduct> GetManufacturerProductsForCode(string code) { List <CcManufacturerProduct> _products = new List <CcManufacturerProduct>(); foreach (Document doc in Workspace.Current.Documents.Values) { //get classificationreference for this code IfcClassificationReference classref = GetClassificationReferencesForCode(doc, code); if (classref != null) { //get relation to propertysettemplate IfcRelAssociatesClassification relassocclass = GetRelAssocClassification(doc, classref); if (relassocclass != null) { List <IfcPropertySet> psets = new List <IfcPropertySet>(); foreach (var psettempl in relassocclass.RelatedObjects.Items) { //get propertysets which use the referenced psettemplate if (psettempl is IfcPropertySetTemplate) { List <IfcPropertySet> tempset = GetPropertySetsForTemplateReference(doc, psettempl.Ref); if (tempset != null) { psets.AddRange(tempset); } } } _products.AddRange(GetListOfManufacturerProducts(doc, psets, code)); } } } return(_products); }
private static IfcRelAssociatesClassification GetRelAssocClassification(Document document, IfcClassificationReference classref) { IfcRelAssociatesClassification _rel = null; var relassoc = document.IfcXmlDocument.Items.OfType <IfcRelAssociatesClassification>() .Where(ele => ele.RelatingClassification.Item.Ref == classref.Id); List <IfcRelAssociatesClassification> grp = relassoc.ToList(); if (grp != null && grp.Count > 0) { _rel = grp[0]; } return(_rel); }
/// <summary> /// Set Category to the property set /// </summary> /// <param name="ifcRoot">IfcRoot Object (IfcPropertySet)</param> /// <param name="category">string, category Name</param> private void SetCategory(IfcRoot ifcRoot, string category) { IfcRelAssociatesClassification ifcRelAssociatesClassification = Model.Instances.Where <IfcRelAssociatesClassification>(r => (r.RelatingClassification is IfcClassificationReference) && ((IfcClassificationReference)r.RelatingClassification).Name.ToString().ToLower() == category.ToLower()).FirstOrDefault(); //create if none found if (ifcRelAssociatesClassification == null) { ifcRelAssociatesClassification = Model.Instances.New <IfcRelAssociatesClassification>(); IfcClassificationReference ifcClassificationReference = Model.Instances.New <IfcClassificationReference>(); ifcClassificationReference.Name = category; ifcRelAssociatesClassification.RelatingClassification = ifcClassificationReference; } //add this IfcRoot object if not already associated if (!ifcRelAssociatesClassification.RelatedObjects.Contains(ifcRoot)) { ifcRelAssociatesClassification.RelatedObjects.Add(ifcRoot); } }
public static IfcClassificationNotation GetFirstClassificationNotation(this IfcRoot root, IModel model) { IfcRelAssociatesClassification rel = model.Instances.Where <IfcRelAssociatesClassification>(r => r.RelatedObjects.Contains(root)). FirstOrDefault(); if (rel == null) { return(null); } IfcClassificationNotationSelect notationSelect = rel.RelatingClassification; if (notationSelect is IfcClassificationReference) { Debug.WriteLine( "Classification relation does not contain classification notation, but it contains external reference."); return(null); } return(notationSelect as IfcClassificationNotation); }
private void UpdateIfcRelAssociatesClassification(string propertyName, IfcClassificationReference ifcClassificationReference) { if (ifcClassificationReference == null) { // delete DeleteIfcRelAssociatesClassification(); return; } var existingIfcRelAssociatesClassificationCollection = GetIfcRelAssociatesClassificationCollection(); if (existingIfcRelAssociatesClassificationCollection.Count() == 0) { // add IfcRelAssociatesClassification ifcRelAssociatesClassification = new IfcRelAssociatesClassification(); ifcRelAssociatesClassification.RelatedObjects = new IfcRelAssociatesRelatedObjects(); ifcRelAssociatesClassification.RelatedObjects.Items.Add(this.RefInstance()); ifcRelAssociatesClassification.RelatingClassification = new IfcRelAssociatesClassificationRelatingClassification(); ifcRelAssociatesClassification.RelatingClassification.Item = new IfcClassificationReference() { Ref = ifcClassificationReference.Id }; this.Document.IfcXmlDocument.Items.Add(ifcRelAssociatesClassification); return; } foreach (var ifcRelAssociatesClassification in existingIfcRelAssociatesClassificationCollection) { // update ifcRelAssociatesClassification.RelatingClassification.Item = new IfcClassificationReference() { Ref = ifcClassificationReference.Id }; } }
/// <summary> /// Get the category from the IfcRelAssociatesClassification / IfcClassificationReference objects /// </summary> /// <param name="obj">IfcObjectDefinition object</param> /// <returns></returns> public string GetCategoryClassification(IfcObjectDefinition obj) { //Try by relationship first IfcRelAssociatesClassification ifcRAC = obj.HasAssociations.OfType <IfcRelAssociatesClassification>().FirstOrDefault(); IfcClassificationReference ifcCR = null; if (ifcRAC != null) { ifcCR = ifcRAC.RelatingClassification as IfcClassificationReference; } if (ifcCR != null) { string conCatChar = " : "; if ((Context.TemplateFileName != null) && (Context.TemplateFileName.Contains("COBie-US"))) //change for US format { conCatChar = ": "; } //holders for first and last part of category string itemReference = ifcCR.ItemReference; if (!string.IsNullOrEmpty(itemReference)) { itemReference = itemReference.Trim(); } string name = ifcCR.Name; if (!string.IsNullOrEmpty(name)) { name = name.Trim(); } //need to use split as sometime the whole category is stored in both ItemReference and Name //We split here as sometimes the whole category(13-15 11 34 11: Office) is place in itemReference and Name if ((!string.IsNullOrEmpty(name)) && (!string.IsNullOrEmpty(itemReference)) ) { itemReference = itemReference.Split(':').First().Trim(); string[] nameSplit = name.Split(':'); //just in case we have more than one ":"in name if (nameSplit.First().Trim().Equals(itemReference, StringComparison.OrdinalIgnoreCase)) { for (int i = 0; i < nameSplit.Count(); i++) { //skip first item if (i == 1) { name = nameSplit[i].Trim(); } if (i > 1) { name += conCatChar + nameSplit[i].Trim(); //add back the second, third... ": " } } } else { name = nameSplit.Last().Trim(); } } //Return the Category if ((!string.IsNullOrEmpty(itemReference)) && (!string.IsNullOrEmpty(name)) && (!itemReference.Equals(name, StringComparison.OrdinalIgnoreCase)) ) { return(itemReference + conCatChar + name); } else if (!string.IsNullOrEmpty(itemReference)) { return(itemReference); } else if (!string.IsNullOrEmpty(name)) { return(name); } else if (!string.IsNullOrEmpty(ifcCR.Location)) { return(ifcCR.Location); } else if ((ifcCR.ReferencedSource != null) && (!string.IsNullOrEmpty(ifcCR.ReferencedSource.Name)) ) { return(ifcCR.ReferencedSource.Name); } } return(null); }