/// <summary> /// Update the IFC Classification (from the UI) into the document. /// </summary> /// <param name="document">The document storing the saved Classification.</param> /// <param name="fileHeaderItem">The Classification item to save.</param> public void UpdateClassification(Document document, IFCClassification classification) { // TO DO: To handle individual item and not the whole since in the future we may support multiple classification systems!!! if (Schema != null) { IList <DataStorage> oldSavedClassification = GetClassificationInStorage(document, Schema); if (oldSavedClassification.Count > 0) { Transaction deleteTransaction = new Transaction(document, "Delete old IFC Classification"); deleteTransaction.Start(); List <ElementId> dataStorageToDelete = new List <ElementId>(); foreach (DataStorage dataStorage in oldSavedClassification) { dataStorageToDelete.Add(dataStorage.Id); } document.Delete(dataStorageToDelete); deleteTransaction.Commit(); } } // Update the address using the new information if (Schema != null) { Transaction transaction = new Transaction(document, "Update saved IFC classification"); transaction.Start(); DataStorage classificationStorage = DataStorage.Create(document); Entity entIFCClassification = new Entity(Schema); if (classification.ClassificationName != null) { entIFCClassification.Set <string>(s_ClassificationName, classification.ClassificationName.ToString()); } if (classification.ClassificationSource != null) { entIFCClassification.Set <string>(s_ClassificationSource, classification.ClassificationSource.ToString()); } if (classification.ClassificationEdition != null) { entIFCClassification.Set <string>(s_ClassificationEdition, classification.ClassificationEdition.ToString()); } if (classification.ClassificationEditionDate != null) { entIFCClassification.Set <Int32>(s_ClassificationEditionDate_Day, classification.ClassificationEditionDate.Day); entIFCClassification.Set <Int32>(s_ClassificationEditionDate_Month, classification.ClassificationEditionDate.Month); entIFCClassification.Set <Int32>(s_ClassificationEditionDate_Year, classification.ClassificationEditionDate.Year); } if (classification.ClassificationLocation != null) { entIFCClassification.Set <string>(s_ClassificationLocation, classification.ClassificationLocation.ToString()); } if (classification.ClassificationFieldName != null) { entIFCClassification.Set <string>(s_ClassificationFieldName, classification.ClassificationFieldName.ToString()); } classificationStorage.SetEntity(entIFCClassification); transaction.Commit(); } }
/// <summary> /// Actual copy/clone of the IFC Classification. /// </summary> /// <param name="other">the source File header to clone.</param> private IFCClassification(IFCClassification other) { this.ClassificationName = other.ClassificationName; this.ClassificationSource = other.ClassificationSource; this.ClassificationEdition = other.ClassificationEdition; this.ClassificationEditionDate = other.ClassificationEditionDate; this.ClassificationLocation = other.ClassificationLocation; this.ClassificationFieldName = other.ClassificationFieldName; }
/// <summary> /// Check whether the items are the same /// </summary> public bool IsUnchanged(IFCClassification classificationToCheck) { // Only check 4 properties that are stored into the schema. if (string.Compare(this.ClassificationName, classificationToCheck.ClassificationName) == 0 && string.Compare(this.ClassificationSource, classificationToCheck.ClassificationSource) == 0 && string.Compare(this.ClassificationEdition, classificationToCheck.ClassificationEdition) == 0 && this.ClassificationEditionDate.Equals(classificationToCheck.ClassificationEditionDate) && string.Compare(this.ClassificationLocation, classificationToCheck.ClassificationLocation) == 0 && string.Compare(this.ClassificationFieldName, classificationToCheck.ClassificationFieldName) == 0) { return(true); } return(false); }
/// <summary> /// Get saved IFC Classifications /// </summary> /// <param name="document">The document where Classification information is stored.</param> /// <param name="fileHeader">Output of the saved Classification from the extensible storage.</param> /// <returns>Status whether there is existing saved Classification.</returns> public bool GetSavedClassificationByName(Document document, string classificationName, out IFCClassification classification) { IFCClassification ifcClassificationSaved = new IFCClassification(); if (Schema != null) { IList <DataStorage> classificationStorage = GetClassificationInStorage(document, Schema); for (int noClass = 0; noClass < classificationStorage.Count; noClass++) { // expected only one File Header information in the storage Entity savedClassification = classificationStorage[noClass].GetEntity(Schema); ifcClassificationSaved.ClassificationName = savedClassification.Get <string>(Schema.GetField(s_ClassificationName)); // Get the details only if the name matches if (String.Compare(classificationName, ifcClassificationSaved.ClassificationName) == 0) { ifcClassificationSaved.ClassificationSource = savedClassification.Get <string>(Schema.GetField(s_ClassificationSource)); ifcClassificationSaved.ClassificationEdition = savedClassification.Get <string>(Schema.GetField(s_ClassificationEdition)); Int32 cldateDay = savedClassification.Get <Int32>(Schema.GetField(s_ClassificationEditionDate_Day)); Int32 cldateMonth = savedClassification.Get <Int32>(Schema.GetField(s_ClassificationEditionDate_Month)); Int32 cldateYear = savedClassification.Get <Int32>(Schema.GetField(s_ClassificationEditionDate_Year)); ifcClassificationSaved.ClassificationEditionDate = new DateTime(cldateYear, cldateMonth, cldateDay); ifcClassificationSaved.ClassificationLocation = savedClassification.Get <string>(Schema.GetField(s_ClassificationLocation)); ifcClassificationSaved.ClassificationFieldName = savedClassification.Get <string>(Schema.GetField(s_ClassificationFieldName)); classification = ifcClassificationSaved; return(true); } } } classification = ifcClassificationSaved; return(false); }
/// <summary> /// Actual copy/clone of the IFC Classification. /// </summary> /// <param name="other">the source File header to clone.</param> private IFCClassification(IFCClassification other) { this.ClassificationName = other.ClassificationName; this.ClassificationSource = other.ClassificationSource; this.ClassificationEdition = other.ClassificationEdition; this.ClassificationEditionDate = other.ClassificationEditionDate; this.ClassificationLocation = other.ClassificationLocation; this.ClassificationFieldName = other.ClassificationFieldName; }
/// <summary> /// Check whether the items are the same /// </summary> public bool IsUnchanged(IFCClassification classificationToCheck) { // Only check 4 properties that are stored into the schema. if (string.Compare(this.ClassificationName, classificationToCheck.ClassificationName) == 0 && string.Compare(this.ClassificationSource, classificationToCheck.ClassificationSource) == 0 && string.Compare(this.ClassificationEdition, classificationToCheck.ClassificationEdition) == 0 && this.ClassificationEditionDate.Equals(classificationToCheck.ClassificationEditionDate) && string.Compare(this.ClassificationLocation, classificationToCheck.ClassificationLocation) == 0 && string.Compare(this.ClassificationFieldName, classificationToCheck.ClassificationFieldName) == 0) return true; return false; }
/// <summary> /// Initialization of the Classification Tab when there is saved item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClassificationTab_Initialized(object sender, EventArgs e) { bool hasSavedItem = m_newClassificationMgr.GetSavedClassifications(IFCCommandOverrideApplication.TheDocument, null, out m_newClassificationList); m_newClassification = m_newClassificationList[0]; // Set the default first Classification item to the first member of the List if (hasSavedItem == true) { m_savedClassification = m_newClassification.Clone(); } if (m_newClassification.ClassificationEditionDate <= DateTime.MinValue || m_newClassification.ClassificationEditionDate >= DateTime.MaxValue) { DateTime today = DateTime.Now; m_newClassification.ClassificationEditionDate = today; } }
/// <summary> /// Create IfcClassification references from hardwired or custom classification code fields. /// </summary> /// <param name="exporterIFC">The exporterIFC class.</param> /// <param name="file">The IFC file class.</param> /// <param name="element">The element to export.</param> /// <param name="elemHnd">The corresponding IFC entity handle.</param> /// <returns>True if a classification or classification reference is created.</returns> public static bool CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd) { bool createdClassification = false; string paramClassificationCode = ""; string baseClassificationCodeFieldName = "ClassificationCode"; IList<string> customClassificationCodeNames = new List<string>(); string classificationName = null; string classificationCode = null; string classificationDescription = null; int customPass = 0; int standardPass = 1; int numCustomCodes = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames.Count; while (true) { // Create a classification, if it is not set. string classificationCodeFieldName = null; if (customPass < numCustomCodes) { classificationCodeFieldName = ExporterCacheManager.ClassificationCache.CustomClassificationCodeNames[customPass]; customPass++; } else { classificationCodeFieldName = baseClassificationCodeFieldName; if (standardPass > 1) classificationCodeFieldName += "(" + standardPass + ")"; standardPass++; } if (ParameterUtil.GetStringValueFromElementOrSymbol(element, classificationCodeFieldName, out paramClassificationCode) == null) break; ParseClassificationCode(paramClassificationCode, classificationCodeFieldName, out classificationName, out classificationCode, out classificationDescription); if (string.IsNullOrEmpty(classificationName)) { if (!ExporterCacheManager.ClassificationCache.FieldNameToClassificationNames.TryGetValue(classificationCodeFieldName, out classificationName)) classificationName = "Default Classification"; } IFCAnyHandle classification; if (!ExporterCacheManager.ClassificationCache.ClassificationHandles.TryGetValue(classificationName, out classification)) { IFCClassification savedClassification = new IFCClassification(); if (ExporterCacheManager.ClassificationCache.ClassificationsByName.TryGetValue(classificationName, out savedClassification)) { if (savedClassification.ClassificationEditionDate == null) { IFCAnyHandle editionDate = IFCInstanceExporter.CreateCalendarDate(file, savedClassification.ClassificationEditionDate.Day, savedClassification.ClassificationEditionDate.Month, savedClassification.ClassificationEditionDate.Year); classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, editionDate, savedClassification.ClassificationName); } else { classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, null, savedClassification.ClassificationName); } if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation)) ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation); } else { classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName); } ExporterCacheManager.ClassificationCache.ClassificationHandles.Add(classificationName, classification); createdClassification = true; } string location = null; ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location); { InsertClassificationReference(exporterIFC, file, element, elemHnd, classificationName, classificationCode, classificationDescription, location); createdClassification = true; } } return createdClassification; }
/// <summary> /// /// </summary> /// <param name="exporterIFC"></param> /// <param name="file"></param> /// <param name="element"></param> /// <param name="elemHnd"></param> /// <param name="location"></param> public static void CreateClassification(ExporterIFC exporterIFC, IFCFile file, Element element, IFCAnyHandle elemHnd, string location) { string paramClassificationCode = ""; string classificationName = null; string classificationCode = null; string classificationDescription = null; // For now the support is fixed to 10 predefined classification code parameter names (to support limitation of schedule key that supports only one category per schedule key and needs one parameter for each) int noClassCodeParam = 10; string [] classCodeParamName = {"ClassificationCode", "ClassificationCode(2)", "ClassificationCode(3)", "ClassificationCode(4)", "ClassificationCode(5)", "ClassificationCode(6)", "ClassificationCode(7)", "ClassificationCode(8)", "ClassificationCode(9)", "ClassificationCode(10)"}; int ret = 0; for (int n = 0; n < noClassCodeParam; n++) { // Create A classification, if it is not set. if (ParameterUtil.GetStringValueFromElementOrSymbol(element, classCodeParamName[n], out paramClassificationCode)) { ret = parseClassificationCode(paramClassificationCode, out classificationName, out classificationCode, out classificationDescription); if (string.IsNullOrEmpty(classificationName)) classificationName = "Default Classification"; IFCAnyHandle classification; if (!ExporterCacheManager.ClassificationCache.TryGetValue(classificationName, out classification)) { IFCClassificationMgr savedClassificationFromUI = new IFCClassificationMgr(); IFCClassification savedClassification = new IFCClassification(); if (savedClassificationFromUI.GetSavedClassificationByName(element.Document, classificationName, out savedClassification)) { if (savedClassification.ClassificationEditionDate == null) { IFCAnyHandle editionDate = IFCInstanceExporter.CreateCalendarDate(file, savedClassification.ClassificationEditionDate.Day, savedClassification.ClassificationEditionDate.Month, savedClassification.ClassificationEditionDate.Year); classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, editionDate, savedClassification.ClassificationName); } else classification = IFCInstanceExporter.CreateClassification(file, savedClassification.ClassificationSource, savedClassification.ClassificationEdition, null, savedClassification.ClassificationName); } else classification = IFCInstanceExporter.CreateClassification(file, "", "", null, classificationName); ExporterCacheManager.ClassificationCache.Add(classificationName, classification); if (!String.IsNullOrEmpty(savedClassification.ClassificationLocation)) ExporterCacheManager.ClassificationLocationCache.Add(classificationName, savedClassification.ClassificationLocation); } if (String.IsNullOrEmpty(location)) { ExporterCacheManager.ClassificationLocationCache.TryGetValue(classificationName, out location); } InsertClassificationReference(exporterIFC, file, element, elemHnd, classificationName, classificationCode, classificationDescription, location); } } }
/// <summary> /// Update the IFC Classification (from the UI) into the document. /// </summary> /// <param name="document">The document storing the saved Classification.</param> /// <param name="fileHeaderItem">The Classification item to save.</param> public static void UpdateClassification(Document document, IFCClassification classification) { // TO DO: To handle individual item and not the whole since in the future we may support multiple classification systems!!! Schema schema = GetSchema(); if (schema != null) { IList<DataStorage> oldSavedClassification = GetClassificationInStorage(document, schema); if (oldSavedClassification.Count > 0) { Transaction deleteTransaction = new Transaction(document, "Delete old IFC Classification"); deleteTransaction.Start(); List<ElementId> dataStorageToDelete = new List<ElementId>(); foreach (DataStorage dataStorage in oldSavedClassification) { dataStorageToDelete.Add(dataStorage.Id); } document.Delete(dataStorageToDelete); deleteTransaction.Commit(); } } // Update the address using the new information if (schema != null) { Transaction transaction = new Transaction(document, "Update saved IFC classification"); transaction.Start(); DataStorage classificationStorage = DataStorage.Create(document); Entity entIFCClassification = new Entity(schema); if (classification.ClassificationName != null) entIFCClassification.Set<string>(s_ClassificationName, classification.ClassificationName.ToString()); if (classification.ClassificationSource != null) entIFCClassification.Set<string>(s_ClassificationSource, classification.ClassificationSource.ToString()); if (classification.ClassificationEdition != null) entIFCClassification.Set<string>(s_ClassificationEdition, classification.ClassificationEdition.ToString()); if (classification.ClassificationEditionDate != null) { entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Day, classification.ClassificationEditionDate.Day); entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Month, classification.ClassificationEditionDate.Month); entIFCClassification.Set<Int32>(s_ClassificationEditionDate_Year, classification.ClassificationEditionDate.Year); } if (classification.ClassificationLocation != null) entIFCClassification.Set<string>(s_ClassificationLocation, classification.ClassificationLocation.ToString()); if (classification.ClassificationFieldName != null) entIFCClassification.Set<string>(s_ClassificationFieldName, classification.ClassificationFieldName.ToString()); classificationStorage.SetEntity(entIFCClassification); transaction.Commit(); } }
/// <summary> /// Get saved IFC Classifications /// </summary> /// <param name="document">The document where Classification information is stored.</param> /// <param name="fileHeader">Output of the saved Classification from the extensible storage.</param> /// <returns>Status whether there is existing saved Classification.</returns> public bool GetSavedClassificationByName (Document document, string classificationName, out IFCClassification classification) { IFCClassification ifcClassificationSaved = new IFCClassification(); if (Schema != null) { IList<DataStorage> classificationStorage = GetClassificationInStorage(document, Schema); for (int noClass=0; noClass < classificationStorage.Count; noClass++) { // expected only one File Header information in the storage Entity savedClassification = classificationStorage[noClass].GetEntity(Schema); ifcClassificationSaved.ClassificationName = savedClassification.Get<string>(Schema.GetField(s_ClassificationName)); // Get the details only if the name matches if (String.Compare(classificationName, ifcClassificationSaved.ClassificationName) == 0) { ifcClassificationSaved.ClassificationSource = savedClassification.Get<string>(Schema.GetField(s_ClassificationSource)); ifcClassificationSaved.ClassificationEdition = savedClassification.Get<string>(Schema.GetField(s_ClassificationEdition)); Int32 cldateDay = savedClassification.Get<Int32>(Schema.GetField(s_ClassificationEditionDate_Day)); Int32 cldateMonth = savedClassification.Get<Int32>(Schema.GetField(s_ClassificationEditionDate_Month)); Int32 cldateYear = savedClassification.Get<Int32>(Schema.GetField(s_ClassificationEditionDate_Year)); ifcClassificationSaved.ClassificationEditionDate = new DateTime(cldateYear, cldateMonth, cldateDay); ifcClassificationSaved.ClassificationLocation = savedClassification.Get<string>(Schema.GetField(s_ClassificationLocation)); ifcClassificationSaved.ClassificationFieldName = savedClassification.Get<string>(Schema.GetField(s_ClassificationFieldName)); classification = ifcClassificationSaved; return true; } } } classification = ifcClassificationSaved; return false; }