/// <summary> /// Check whether the addresses are the same /// </summary> public Boolean isUnchanged(IFCAddressItem addressToCheck) { if (this.Equals(addressToCheck)) { return(true); } return(false); }
/// <summary> /// To initialized object that is cloned /// </summary> /// <param name="other">object to clone.</param> private IFCAddressItem(IFCAddressItem other) { this.Purpose = other.Purpose; this.Description = other.Description; this.UserDefinedPurpose = other.UserDefinedPurpose; this.AddressLine1 = other.AddressLine1; this.AddressLine2 = other.AddressLine2; this.POBox = other.POBox; this.TownOrCity = other.TownOrCity; this.RegionOrState = other.RegionOrState; this.PostalCode = other.PostalCode; this.Country = other.Country; this.UpdateProjectInformation = other.UpdateProjectInformation; }
/// <summary> /// Upon AddressTab initialization /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddressTab_Initialized(object sender, EventArgs e) { bool hasSavedItem = m_newAddress.GetSavedAddress(IFCCommandOverrideApplication.TheDocument, out m_newAddressItem); if (hasSavedItem == true) { //keep a copy of the original saved items for checking for any value changed later on m_savedAddressItem = m_newAddressItem.Clone(); PurposeComboBox.SelectedItem = m_newAddressItem.Purpose; } else { string projLocation = IFCCommandOverrideApplication.TheDocument.SiteLocation.PlaceName; if (projLocation != null) { // if the formatted Address is empty and there is location set for the site (project) in Revit, take it and assign it by default to AddressLine1. m_newAddressItem.AddressLine1 = projLocation; } } }
/// <summary> /// Update the address saved into the extensible storage using values from the UI /// </summary> /// <param name="document">The document storing the saved address.</param> /// <param name="addressItem">address information from the UI to be saved into extensible storage</param> public void UpdateAddress(Document document, IFCAddressItem addressItem) { if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { IList <DataStorage> oldSavedAddress = GetAddressInStorage(document, m_schema); if (oldSavedAddress.Count > 0) { Transaction deleteTransaction = new Transaction(document, "Delete old IFC address"); deleteTransaction.Start(); List <ElementId> dataStorageToDelete = new List <ElementId>(); foreach (DataStorage dataStorage in oldSavedAddress) { dataStorageToDelete.Add(dataStorage.Id); } document.Delete(dataStorageToDelete); deleteTransaction.Commit(); } } // Update the address using the new information if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { Transaction transaction = new Transaction(document, "Update saved IFC Address"); transaction.Start(); DataStorage addressStorage = DataStorage.Create(document); Entity mapEntity = new Entity(m_schema); IDictionary <string, string> mapData = new Dictionary <string, string>(); if (addressItem.Purpose != null) { mapData.Add(s_addressPurpose, addressItem.Purpose.ToString()); } if (addressItem.Description != null) { mapData.Add(s_addressDescription, addressItem.Description.ToString()); } if (addressItem.UserDefinedPurpose != null) { mapData.Add(s_addressUserDefinedPurpose, addressItem.UserDefinedPurpose.ToString()); } if (addressItem.InternalLocation != null) { mapData.Add(s_addressInternalLocation, addressItem.InternalLocation.ToString()); } if (addressItem.AddressLine1 != null) { mapData.Add(s_addressAddressLine1, addressItem.AddressLine1.ToString()); } if (addressItem.AddressLine2 != null) { mapData.Add(s_addressAddressLine2, addressItem.AddressLine2.ToString()); } if (addressItem.POBox != null) { mapData.Add(s_addressPOBox, addressItem.POBox.ToString()); } if (addressItem.TownOrCity != null) { mapData.Add(s_addressTownOrCity, addressItem.TownOrCity.ToString()); } if (addressItem.RegionOrState != null) { mapData.Add(s_addressRegionOrState, addressItem.RegionOrState.ToString()); } if (addressItem.PostalCode != null) { mapData.Add(s_addressPostalCode, addressItem.PostalCode.ToString()); } if (addressItem.Country != null) { mapData.Add(s_addressCountry, addressItem.Country.ToString()); } mapEntity.Set <IDictionary <string, String> >(s_addressMapField, mapData); addressStorage.SetEntity(mapEntity); transaction.Commit(); } }
/// <summary> /// Get saved IFC address from the extensible storage. /// </summary> /// <param name="document">The document storing the saved address.</param> /// <param name="address">saved address information from the extensible storage.</param> /// <returns>returns status whether there is any saved address in the extensible storage.</returns> public bool GetSavedAddress(Document document, out IFCAddressItem address) { IFCAddressItem addressItemSaved = new IFCAddressItem(); if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { IList <DataStorage> addressStorage = GetAddressInStorage(document, m_schema); if (addressStorage.Count > 0) { // expected only one address in the storage Entity savedAddress = addressStorage[0].GetEntity(m_schema); IDictionary <string, string> savedAddressMap = savedAddress.Get <IDictionary <string, string> >(s_addressMapField); if (savedAddressMap.ContainsKey(s_addressPurpose)) { addressItemSaved.Purpose = savedAddressMap[s_addressPurpose]; } if (savedAddressMap.ContainsKey(s_addressDescription)) { addressItemSaved.Description = savedAddressMap[s_addressDescription]; } if (savedAddressMap.ContainsKey(s_addressUserDefinedPurpose)) { addressItemSaved.UserDefinedPurpose = savedAddressMap[s_addressUserDefinedPurpose]; } if (savedAddressMap.ContainsKey(s_addressInternalLocation)) { addressItemSaved.InternalLocation = savedAddressMap[s_addressInternalLocation]; } if (savedAddressMap.ContainsKey(s_addressAddressLine1)) { addressItemSaved.AddressLine1 = savedAddressMap[s_addressAddressLine1]; } if (savedAddressMap.ContainsKey(s_addressAddressLine2)) { addressItemSaved.AddressLine2 = savedAddressMap[s_addressAddressLine2]; } if (savedAddressMap.ContainsKey(s_addressPOBox)) { addressItemSaved.POBox = savedAddressMap[s_addressPOBox]; } if (savedAddressMap.ContainsKey(s_addressTownOrCity)) { addressItemSaved.TownOrCity = savedAddressMap[s_addressTownOrCity]; } if (savedAddressMap.ContainsKey(s_addressRegionOrState)) { addressItemSaved.RegionOrState = savedAddressMap[s_addressRegionOrState]; } if (savedAddressMap.ContainsKey(s_addressPostalCode)) { addressItemSaved.PostalCode = savedAddressMap[s_addressPostalCode]; } if (savedAddressMap.ContainsKey(s_addressCountry)) { addressItemSaved.Country = savedAddressMap[s_addressCountry]; } address = addressItemSaved; return(true); } } address = addressItemSaved; return(false); }
/// <summary> /// Update the address saved into the extensible storage using values from the UI /// </summary> /// <param name="document">The document storing the saved address.</param> /// <param name="addressItem">address information from the UI to be saved into extensible storage</param> public void UpdateAddress(Document document, IFCAddressItem addressItem) { if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { IList<DataStorage> oldSavedAddress = GetAddressInStorage(document, m_schema); if (oldSavedAddress.Count > 0) { Transaction deleteTransaction = new Transaction(document, "Delete old IFC address"); deleteTransaction.Start(); List<ElementId> dataStorageToDelete = new List<ElementId>(); foreach (DataStorage dataStorage in oldSavedAddress) { dataStorageToDelete.Add(dataStorage.Id); } document.Delete(dataStorageToDelete); deleteTransaction.Commit(); } } // Update the address using the new information if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { Transaction transaction = new Transaction(document, "Update saved IFC Address"); transaction.Start(); DataStorage addressStorage = DataStorage.Create(document); Entity mapEntity = new Entity(m_schema); IDictionary<string, string> mapData = new Dictionary<string, string>(); if (addressItem.Purpose != null) mapData.Add(s_addressPurpose, addressItem.Purpose.ToString()); if (addressItem.Description != null) mapData.Add(s_addressDescription, addressItem.Description.ToString()); if (addressItem.UserDefinedPurpose != null) mapData.Add(s_addressUserDefinedPurpose, addressItem.UserDefinedPurpose.ToString()); if (addressItem.InternalLocation != null) mapData.Add(s_addressInternalLocation, addressItem.InternalLocation.ToString()); if (addressItem.AddressLine1 != null) mapData.Add(s_addressAddressLine1, addressItem.AddressLine1.ToString()); if (addressItem.AddressLine2 != null) mapData.Add(s_addressAddressLine2, addressItem.AddressLine2.ToString()); if (addressItem.POBox != null) mapData.Add(s_addressPOBox, addressItem.POBox.ToString()); if (addressItem.TownOrCity != null) mapData.Add(s_addressTownOrCity, addressItem.TownOrCity.ToString()); if (addressItem.RegionOrState != null) mapData.Add(s_addressRegionOrState, addressItem.RegionOrState.ToString()); if (addressItem.PostalCode != null) mapData.Add(s_addressPostalCode, addressItem.PostalCode.ToString()); if (addressItem.Country != null) mapData.Add(s_addressCountry, addressItem.Country.ToString()); mapEntity.Set<IDictionary<string, String>>(s_addressMapField, mapData); addressStorage.SetEntity(mapEntity); transaction.Commit(); } }
/// <summary> /// Get saved IFC address from the extensible storage. /// </summary> /// <param name="document">The document storing the saved address.</param> /// <param name="address">saved address information from the extensible storage.</param> /// <returns>returns status whether there is any saved address in the extensible storage.</returns> public bool GetSavedAddress(Document document, out IFCAddressItem address) { IFCAddressItem addressItemSaved = new IFCAddressItem(); if (m_schema == null) { m_schema = Schema.Lookup(s_schemaId); } if (m_schema != null) { IList<DataStorage> addressStorage = GetAddressInStorage(document, m_schema); if (addressStorage.Count > 0) { // expected only one address in the storage Entity savedAddress = addressStorage[0].GetEntity(m_schema); IDictionary<string, string> savedAddressMap = savedAddress.Get<IDictionary<string, string>>(s_addressMapField); if (savedAddressMap.ContainsKey(s_addressPurpose)) addressItemSaved.Purpose = savedAddressMap[s_addressPurpose]; if (savedAddressMap.ContainsKey(s_addressDescription)) addressItemSaved.Description = savedAddressMap[s_addressDescription]; if (savedAddressMap.ContainsKey(s_addressUserDefinedPurpose)) addressItemSaved.UserDefinedPurpose = savedAddressMap[s_addressUserDefinedPurpose]; if (savedAddressMap.ContainsKey(s_addressInternalLocation)) addressItemSaved.InternalLocation = savedAddressMap[s_addressInternalLocation]; if (savedAddressMap.ContainsKey(s_addressAddressLine1)) addressItemSaved.AddressLine1 = savedAddressMap[s_addressAddressLine1]; if (savedAddressMap.ContainsKey(s_addressAddressLine2)) addressItemSaved.AddressLine2 = savedAddressMap[s_addressAddressLine2]; if (savedAddressMap.ContainsKey(s_addressPOBox)) addressItemSaved.POBox = savedAddressMap[s_addressPOBox]; if (savedAddressMap.ContainsKey(s_addressTownOrCity)) addressItemSaved.TownOrCity = savedAddressMap[s_addressTownOrCity]; if (savedAddressMap.ContainsKey(s_addressRegionOrState)) addressItemSaved.RegionOrState = savedAddressMap[s_addressRegionOrState]; if (savedAddressMap.ContainsKey(s_addressPostalCode)) addressItemSaved.PostalCode = savedAddressMap[s_addressPostalCode]; if (savedAddressMap.ContainsKey(s_addressCountry)) addressItemSaved.Country = savedAddressMap[s_addressCountry]; address = addressItemSaved; return true; } } address = addressItemSaved; return false; }
/// <summary> /// Upon AddressTab initialization /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddressTab_Initialized(object sender, EventArgs e) { bool hasSavedItem = m_newAddress.GetSavedAddress(IFCCommandOverrideApplication.TheDocument, out m_newAddressItem); if (hasSavedItem == true) { //keep a copy of the original saved items for checking for any value changed later on m_savedAddressItem = m_newAddressItem.Clone(); // We won't initialize PurposeComboBox.SelectedIndex, as otherwise that will change the value // of m_newAddressItem.Purpose to the first item in the list, which we don't want. It is // OK for this to be "uninitialized". // This is a short list, so we just do an O(n) search. int numItems = ifcPurposeList.Count(); for (int ii = 0; ii < numItems; ii++) { if (m_newAddressItem.Purpose == ifcPurposeList[ii]) { PurposeComboBox.SelectedIndex = ii; break; } } } else { string projLocation = IFCCommandOverrideApplication.TheDocument.SiteLocation.PlaceName; if (projLocation != null) { // if the formatted Address is empty and there is location set for the site (project) in Revit, take it and assign it by default to AddressLine1. m_newAddressItem.AddressLine1 = projLocation; } } }
/// <summary> /// To initialized object that is cloned /// </summary> /// <param name="other">object to clone.</param> private IFCAddressItem (IFCAddressItem other) { this.Purpose = other.Purpose; this.Description = other.Description; this.UserDefinedPurpose = other.UserDefinedPurpose; this.AddressLine1 = other.AddressLine1; this.AddressLine2 = other.AddressLine2; this.POBox = other.POBox; this.TownOrCity = other.TownOrCity; this.RegionOrState = other.RegionOrState; this.PostalCode = other.PostalCode; this.Country = other.Country; this.UpdateProjectInformation = other.UpdateProjectInformation; }
/// <summary> /// Check whether the addresses are the same /// </summary> public Boolean isUnchanged(IFCAddressItem addressToCheck) { if (this.Equals(addressToCheck)) return true; return false; }