/// <summary> /// Fill sheet rows for Type sheet /// </summary> /// <returns>COBieSheet</returns> public override COBieSheet <COBieTypeRow> Fill() { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif ProgressIndicator.ReportMessage("Starting Types..."); var ifcProject = Model.Instances.FirstOrDefault <IIfcProject>(); Debug.Assert(ifcProject != null); // Create new Sheet COBieSheet <COBieTypeRow> types = new COBieSheet <COBieTypeRow>(Constants.WORKSHEET_TYPE); //group the types by name as we need to filter duplicate items in for each loop IEnumerable <IfcTypeObject> ifcTypeObjects = Model.FederatedInstances.OfType <IfcTypeObject>() .Select(type => type) .Where(type => !Context.Exclude.ObjectType.Types.Contains(type.GetType())) .GroupBy(type => type.Name).SelectMany(g => g);//.Distinct() //set up property set helper class COBieDataPropertySetValues allPropertyValues = new COBieDataPropertySetValues(); //properties helper class COBieDataAttributeBuilder attributeBuilder = new COBieDataAttributeBuilder(Context, allPropertyValues); attributeBuilder.InitialiseAttributes(ref _attributes); attributeBuilder.ExcludeAttributePropertyNames.AddRange(Context.Exclude.Types.AttributesEqualTo); //we do not want for the attribute sheet so filter them out attributeBuilder.ExcludeAttributePropertyNamesWildcard.AddRange(Context.Exclude.Types.AttributesContain); //we do not want for the attribute sheet so filter them out attributeBuilder.ExcludeAttributePropertySetNames.AddRange(Context.Exclude.Types.PropertySetsEqualTo); //exclude the property set from selection of values attributeBuilder.RowParameters["Sheet"] = "Type"; ProgressIndicator.Initialise("Creating Types", ifcTypeObjects.Count()); //COBieTypeRow lastRow = null; foreach (IfcTypeObject type in ifcTypeObjects) { ProgressIndicator.IncrementAndUpdate(); COBieTypeRow typeRow = new COBieTypeRow(types); // TODO: Investigate centralising this common code. string name = type.Name; if (string.IsNullOrEmpty(type.Name)) { name = "Name Unknown " + UnknownCount.ToString(); UnknownCount++; } //set allPropertyValues to this element allPropertyValues.SetAllPropertyValues(type); //set the internal filtered IfcPropertySingleValues List in allPropertyValues typeRow.Name = name; string create_By = allPropertyValues.GetPropertySingleValueValue("COBieTypeCreatedBy", false); //support for COBie Toolkit for Autodesk Revit typeRow.CreatedBy = ValidateString(create_By) ? create_By : GetTelecomEmailAddress(type.OwnerHistory); string created_On = allPropertyValues.GetPropertySingleValueValue("COBieTypeCreatedOn", false); //support for COBie Toolkit for Autodesk Revit typeRow.CreatedOn = ValidateString(created_On) ? created_On : GetCreatedOnDateAsFmtString(type.OwnerHistory); typeRow.Category = GetCategory(allPropertyValues); string description = allPropertyValues.GetPropertySingleValueValue("COBieDescription", false);//support for COBie Toolkit for Autodesk Revit typeRow.Description = ValidateString(description) ? description : GetTypeObjDescription(type); string ext_System = allPropertyValues.GetPropertySingleValueValue("COBieTypeExtSystem", false);//support for COBie Toolkit for Autodesk Revit typeRow.ExtSystem = ValidateString(ext_System) ? ext_System : GetExternalSystem(type); typeRow.ExtObject = type.GetType().Name; typeRow.ExtIdentifier = type.GlobalId; FillPropertySetsValues(allPropertyValues, type, typeRow); //not duplicate so add to sheet //if (CheckForDuplicateRow(lastRow, typeRow)) //{ string rowhash = typeRow.RowHashValue; if (RowHashs.ContainsKey(rowhash)) { continue; } else { types.AddRow(typeRow); RowHashs.Add(rowhash, true); } //lastRow = typeRow; //save this row to test on next loop //} // Provide Attribute sheet with our context //fill in the attribute information attributeBuilder.RowParameters["Name"] = typeRow.Name; attributeBuilder.RowParameters["CreatedBy"] = typeRow.CreatedBy; attributeBuilder.RowParameters["CreatedOn"] = typeRow.CreatedOn; attributeBuilder.RowParameters["ExtSystem"] = typeRow.ExtSystem; attributeBuilder.PopulateAttributesRows(type); //fill attribute sheet rows } ProgressIndicator.Finalise(); //--------------Loop all IfcMaterialLayerSet----------------------------- ProgressIndicator.ReportMessage("Starting MaterialLayerSets..."); IEnumerable <IfcMaterialLayerSet> ifcMaterialLayerSets = Model.FederatedInstances.OfType <IfcMaterialLayerSet>(); ChildNamesList rowHolderChildNames = new ChildNamesList(); ChildNamesList rowHolderLayerChildNames = new ChildNamesList(); string createdBy = DEFAULT_STRING, createdOn = DEFAULT_STRING, extSystem = DEFAULT_STRING; ProgressIndicator.Initialise("Creating MaterialLayerSets", ifcMaterialLayerSets.Count()); foreach (IfcMaterialLayerSet ifcMaterialLayerSet in ifcMaterialLayerSets) { ProgressIndicator.IncrementAndUpdate(); //Material layer has no owner history, so lets take the owner history from IfcRelAssociatesMaterial.RelatingMaterial -> (IfcMaterialLayerSetUsage.ForLayerSet -> IfcMaterialLayerSet) || IfcMaterialLayerSet || IfcMaterialLayer as it is a IfcMaterialSelect IfcOwnerHistory ifcOwnerHistory = GetMaterialOwnerHistory(ifcMaterialLayerSet); if (ifcOwnerHistory != null) { createdBy = GetTelecomEmailAddress(ifcOwnerHistory); createdOn = GetCreatedOnDateAsFmtString(ifcOwnerHistory); extSystem = GetExternalSystem(ifcOwnerHistory); } else //default to the project as we failed to find a IfcRoot object to extract it from { createdBy = GetTelecomEmailAddress(ifcProject.OwnerHistory); createdOn = GetCreatedOnDateAsFmtString(ifcProject.OwnerHistory); extSystem = GetExternalSystem(ifcProject.OwnerHistory); } //add materialLayerSet name to rows COBieTypeRow matSetRow = new COBieTypeRow(types); matSetRow.Name = (string.IsNullOrEmpty(ifcMaterialLayerSet.LayerSetName)) ? DEFAULT_STRING : ifcMaterialLayerSet.LayerSetName.ToString(); matSetRow.CreatedBy = createdBy; matSetRow.CreatedOn = createdOn; matSetRow.ExtSystem = extSystem; matSetRow.ExtObject = ifcMaterialLayerSet.GetType().Name; matSetRow.AssetType = "Fixed"; types.AddRow(matSetRow); //loop the materials within the material layer set foreach (IfcMaterialLayer ifcMaterialLayer in ifcMaterialLayerSet.MaterialLayers) { if ((ifcMaterialLayer.Material != null) && (!string.IsNullOrEmpty(ifcMaterialLayer.Material.Name)) ) { string name = ifcMaterialLayer.Material.Name.ToString().Trim(); double thickness = ifcMaterialLayer.LayerThickness; string keyName = name + " (" + thickness.ToString(CultureInfo.InvariantCulture) + ")"; if (!rowHolderLayerChildNames.Contains(keyName.ToLower())) //check we do not already have it { COBieTypeRow matRow = new COBieTypeRow(types); matRow.Name = keyName; matRow.CreatedBy = createdBy; matRow.CreatedOn = createdOn; matRow.ExtSystem = extSystem; matRow.ExtObject = ifcMaterialLayer.GetType().Name; matRow.AssetType = "Fixed"; matRow.NominalWidth = thickness.ToString(); rowHolderLayerChildNames.Add(keyName.ToLower()); //we also don't want to repeat on the IfcMaterial loop below if (!rowHolderChildNames.Contains(name.ToLower())) { rowHolderChildNames.Add(name.ToLower()); } types.AddRow(matRow); } } } } ProgressIndicator.Finalise(); //--------Loop Materials in case they are not in a layer Set----- ProgressIndicator.ReportMessage("Starting Materials..."); IEnumerable <IfcMaterial> ifcMaterials = Model.FederatedInstances.OfType <IfcMaterial>(); ProgressIndicator.Initialise("Creating Materials", ifcMaterials.Count()); foreach (IfcMaterial ifcMaterial in ifcMaterials) { ProgressIndicator.IncrementAndUpdate(); string name = ifcMaterial.Name.ToString().Trim(); if (!string.IsNullOrEmpty(ifcMaterial.Name)) { if (!rowHolderChildNames.Contains(name.ToLower())) //check we do not already have it { COBieTypeRow matRow = new COBieTypeRow(types); matRow.Name = name; matRow.CreatedBy = createdBy; //no way of extraction on material, if no material layer set, so use last found in Layer Set loop matRow.CreatedOn = createdOn; //ditto matRow.ExtSystem = extSystem; //ditto matRow.ExtObject = ifcMaterial.GetType().Name; matRow.AssetType = "Fixed"; types.AddRow(matRow); } rowHolderChildNames.Add(name.ToLower()); } } types.OrderBy(s => s.Name); ProgressIndicator.Finalise(); #if DEBUG timer.Stop(); Console.WriteLine(String.Format("Time to generate Type data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); #endif return(types); }