/// <summary> /// Validate system sheet for merge types in ComponentName, depending on the role of the model this worksheet was built from /// </summary> /// <param name="names">string list holding the name properties removed from the component sheet</param> /// <returns>Number removed</returns> public int ValidateSystemMerge(List <string> names) { COBieColumn compName = Columns.Where(c => c.Value.ColumnName == "ComponentNames").Select(c => c.Value).FirstOrDefault(); List <T> RemainRows = new List <T>(); if (compName != null) { for (int i = 0; i < Rows.Count; i++) { COBieRow row = Rows[i]; COBieCell cell = row[compName.ColumnOrder]; string componentName = cell.CellValue; if (names.Contains(componentName)) { RowsRemoved.Add((T)row); } else { RemainRows.Add((T)row); } } Rows = RemainRows; } return(RowsRemoved.Count); }
/// <summary> /// Validate type sheet for merge types depending on the role of the model this worksheet was built from /// </summary> ///<param name="GlobalIds">List of GlobalId's</param> ///<returns>Number of rows removed</returns> public int ValidateTypeMerge(List <string> GlobalIds) { COBieColumn colExtId = Columns.Where(c => c.Value.ColumnName == "ExtIdentifier").Select(c => c.Value).FirstOrDefault(); List <T> RemainRows = new List <T>(); if (colExtId != null) { for (int i = 0; i < Rows.Count; i++) { COBieRow row = Rows[i]; COBieCell cell = row[colExtId.ColumnOrder]; string extId = cell.CellValue; if (GlobalIds.Contains(extId)) { RowsRemoved.Add((T)row); } else { RemainRows.Add((T)row); } } Rows = RemainRows; } return(RowsRemoved.Count); }
/// <summary> /// Validate attribute sheet for merge types depending on the role of the model this worksheet was built from /// </summary> /// <param name="keys">string list holding the sheetname and name property concatenated together</param> /// <returns>Number removed</returns> public int ValidateAttributeMerge(List <string> keys) { COBieColumn colSheet = Columns.Where(c => c.Value.ColumnName == "SheetName").Select(c => c.Value).FirstOrDefault(); COBieColumn colName = Columns.Where(c => c.Value.ColumnName == "RowName").Select(c => c.Value).FirstOrDefault(); List <T> RemainRows = new List <T>(); if ((colSheet != null) && (colName != null)) { for (int i = 0; i < Rows.Count; i++) { COBieRow row = Rows[i]; COBieCell cellSheet = row[colSheet.ColumnOrder]; string sheetName = cellSheet.CellValue; COBieCell cellName = row[colName.ColumnOrder]; string rowName = cellName.CellValue; if (keys.Contains(sheetName + rowName)) { RowsRemoved.Add((T)row); } else { RemainRows.Add((T)row); } } Rows = RemainRows; } return(RowsRemoved.Count); }
public COBieCell this[int i] { get { COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault(); if (cobieColumn != null) { object pVal = cobieColumn.PropertyInfo.GetValue(this, null); string cellValue = (pVal != null) ? pVal.ToString() : Constants.DEFAULT_STRING; COBieCell thiscell = new COBieCell(cellValue, cobieColumn); return(thiscell); } return(null); } set { COBieColumn cobieColumn = ParentSheet.Columns.Where(idxcol => idxcol.Key == i).Select(idxcol => idxcol.Value).FirstOrDefault(); if (cobieColumn != null) { cobieColumn.PropertyInfo.SetValue(this, value.CellValue, null); } } }
/// <summary> /// Constructs a class representing the relationships between a Foreign Key column and its Primary key column elsewhere in the /// workbook /// </summary> /// <param name="workbook">The COBie Workbook holding all the sheets</param> /// <param name="column">The foreign key column</param> public COBieColumnRelationship(COBieWorkbook workbook, COBieColumn column) { if(workbook == null) throw new ArgumentNullException("workbook"); if (column.KeyType != COBieKeyType.ForeignKey && column.KeyType != COBieKeyType.CompoundKey_ForeignKey) throw new ArgumentException(String.Format("Column '{0}' is not a foreign key column", column.ColumnName)); if (string.IsNullOrEmpty(column.ReferenceColumnName)) throw new ArgumentException(errorMessage); string[] sheetRefInfo = column.ReferenceColumnName.Split('.'); if (sheetRefInfo.Length != 2) throw new ArgumentException(errorMessage); SheetName = sheetRefInfo[0]; ColumnName = sheetRefInfo[1]; Sheet = workbook[SheetName]; if(Sheet == null) throw new ArgumentException(String.Format("Sheet '{0}' was not found in the workbook", SheetName)); if (Sheet.Indices.ContainsKey(ColumnName) == false) throw new ArgumentException(String.Format("Column '{0}' was not found in the '{1}' workbook", ColumnName, SheetName)); }
/// <summary> /// Role Merge /// </summary> /// <param name="model"></param> /// <param name="fileRoles">bit fields enumeration to hold all the roles in one place using bitwise AND, OR, EXCLUSIVE OR</param> public void ValidateRoles(XbimModel model, COBieMergeRoles fileRoles) { #if DEBUG Stopwatch timer = new Stopwatch(); timer.Start(); #endif if (fileRoles != COBieMergeRoles.Unknown) //if role is a single value of unknown then do no merging { var sheet = this[Constants.WORKSHEET_COMPONENT]; List <string> typeGlobalIds = sheet.ValidateComponentMerge(model, fileRoles); sheet = this[Constants.WORKSHEET_TYPE]; int remNo = sheet.ValidateTypeMerge(typeGlobalIds); sheet = this[Constants.WORKSHEET_COMPONENT]; List <string> keyList = new List <string>(); List <string> nameList = new List <string>(); if (sheet.RemovedRows != null) { foreach (var item in sheet.RemovedRows) { string sheetName = "Component"; COBieColumn colName = item.ParentSheet.Columns.Where(c => c.Value.ColumnName == "Name").Select(c => c.Value).FirstOrDefault(); var name = item[colName.ColumnOrder].CellValue; nameList.Add(name); keyList.Add(sheetName + name); } sheet = this[Constants.WORKSHEET_ATTRIBUTE]; int attRemNo = sheet.ValidateAttributeMerge(keyList); sheet = this[Constants.WORKSHEET_SYSTEM]; int systemRemNo = sheet.ValidateSystemMerge(nameList); } } #if DEBUG timer.Stop(); Console.WriteLine(String.Format("Time to generate Role Merge data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); #endif }
/// <summary> /// Validate component sheet for merge types depending on the role of the model this worksheet was built from /// </summary> /// <param name="model">model the cobie file was generated from</param> /// <param name="fileRoles">the file roles</param> public List <string> ValidateComponentMerge(XbimModel model, COBieMergeRoles fileRoles) { List <string> typeObjectGlobalId = new List <string>(); List <string> typeObjectGlobalIdKeep = new List <string>(); //RowsRemoved.Clear(); if (fileRoles != COBieMergeRoles.Unknown) //if role is a single value of unknown then do no merging { COBieColumn colExtObj = Columns.Where(c => c.Value.ColumnName == "ExtObject").Select(c => c.Value).FirstOrDefault(); COBieColumn colExtId = Columns.Where(c => c.Value.ColumnName == "ExtIdentifier").Select(c => c.Value).FirstOrDefault(); List <IfcElement> elements = model.InstancesLocal.OfType <IfcElement>().ToList(); //get all IfcElements, List <T> RemainRows = new List <T>(); if (colExtObj != null) { FilterValuesOnMerge mergeHelper = new FilterValuesOnMerge(); for (int i = 0; i < Rows.Count; i++) { COBieRow row = Rows[i];//.ElementAt(i); COBieCell cell = row[colExtObj.ColumnOrder]; string extObject = cell.CellValue; if (mergeHelper.Merge(extObject)) //object can be tested on { COBieCell cellExtId = row[colExtId.ColumnOrder]; string extId = cellExtId.CellValue; IfcElement IfcElement = elements.Where(ie => ie.GlobalId.ToString() == extId).FirstOrDefault(); if (IfcElement != null) { //we need to remove the ObjectType from the type sheet IfcRelDefinesByType elementDefinesByType = IfcElement.IsDefinedBy.OfType <IfcRelDefinesByType>().FirstOrDefault(); //should be only one IfcTypeObject elementType = null; if (elementDefinesByType != null) { elementType = elementDefinesByType.RelatingType; } if (mergeHelper.Merge(IfcElement, fileRoles)) { RemainRows.Add((T)row); if ((elementType != null) && (!typeObjectGlobalIdKeep.Contains(elementType.GlobalId))) { typeObjectGlobalIdKeep.Add(elementType.GlobalId); } } else { RowsRemoved.Add((T)row); if ((elementType != null) && (!typeObjectGlobalId.Contains(elementType.GlobalId))) { typeObjectGlobalId.Add(elementType.GlobalId); } } } else { RemainRows.Add((T)row); //cannot evaluate IfcType so keep } } } Rows = RemainRows; } } typeObjectGlobalId.RemoveAll(Id => typeObjectGlobalIdKeep.Contains(Id)); //ensure we remove any type we have kept from the type object GlobalId list (ones to remove) return(typeObjectGlobalId); }
public COBieCell(string cellValue, COBieColumn cobieColumn) { CellValue = cellValue; COBieColumn = cobieColumn; }