From 76e2afb8464eedcfad89f6df6e5ac22f73c019e0 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 7 Sep 2013 19:38:52 +0200 Subject: [PATCH] Remove regions/fields present on project file but not present on SSIHUB Set UTM input fields enabled/disabled based on UTM mode p4#: 22344 --- .../RimWellPathImport.cpp | 110 ++++++++++++++---- .../WellPathImportSsihub/RimWellPathImport.h | 8 +- .../RiuWellImportWizard.cpp | 4 - 3 files changed, 96 insertions(+), 26 deletions(-) diff --git a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp index 87678417a1..3c4ed97ef0 100644 --- a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp +++ b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.cpp @@ -29,17 +29,6 @@ namespace caf { setDefault(RimWellPathImport::UTM_FILTER_PROJECT); } - /* - template<> - void caf::AppEnum< RimWellPathImport::WellTypeEnum >::setUp() - { - addItem(RimWellPathImport::WELL_ALL, "WELL_ALL", "All"); - addItem(RimWellPathImport::WELL_SURVEY, "WELL_SURVEY", "Survey"); - addItem(RimWellPathImport::WELL_PLAN, "WELL_PLAN", "Plan"); - setDefault(RimWellPathImport::WELL_ALL); - } - */ - } // End namespace caf @@ -56,7 +45,6 @@ RimWellPathImport::RimWellPathImport() CAF_PDM_InitField(&wellTypeSurvey, "WellTypeSurvey", true, "Survey", "", "", ""); CAF_PDM_InitField(&wellTypePlans, "WellTypePlans", true, "Plans", "", "", ""); - CAF_PDM_InitField(&wellTypeAll, "WellTypeAll", true, "All", "", "", ""); caf::AppEnum defaultUtmMode = UTM_FILTER_OFF; CAF_PDM_InitField(&utmFilterMode, "UtmMode", defaultUtmMode, "Utm filter", "", "", ""); @@ -76,10 +64,48 @@ void RimWellPathImport::updateRegions(const QStringList& regionStrings, const QS { assert(regionStrings.size() == fieldStrings.size() && regionStrings.size() == edmIds.size()); + std::vector regionsToRemove; + + // Remove regions and fields not present in last request + for (size_t regionIdx = 0; regionIdx < this->regions.size(); regionIdx++) + { + if (!regionStrings.contains(this->regions[regionIdx]->name)) + { + regionsToRemove.push_back(this->regions[regionIdx]); + } + else + { + std::vector fieldsToRemove; + + for (size_t fIdx = 0; fIdx < this->regions[regionIdx]->fields.size(); fIdx++) + { + if (!fieldStrings.contains(this->regions[regionIdx]->fields[fIdx]->name)) + { + fieldsToRemove.push_back(this->regions[regionIdx]->fields[fIdx]); + } + } + + for (size_t i = 0; i < fieldsToRemove.size(); i++) + { + this->regions[regionIdx]->fields.removeChildObject(fieldsToRemove[i]); + + delete fieldsToRemove[i]; + } + } + } + + for (size_t i = 0; i < regionsToRemove.size(); i++) + { + this->regions.removeChildObject(regionsToRemove[i]); + + delete regionsToRemove[i]; + } + + for (int i = 0; i < regionStrings.size(); i++) { RimOilRegionEntry* oilRegionEntry = NULL; - bool edmIdFound = false; + RimOilFieldEntry* oilFieldEntry = NULL; for (size_t regionIdx = 0; regionIdx < this->regions.size(); regionIdx++) { @@ -91,22 +117,24 @@ void RimWellPathImport::updateRegions(const QStringList& regionStrings, const QS { if (this->regions[regionIdx]->fields[fIdx]->edmId == edmIds[i]) { - edmIdFound = true; + oilFieldEntry = this->regions[regionIdx]->fields[fIdx]; } } } } - if (!edmIdFound) + if (!oilRegionEntry) { - if (!oilRegionEntry) - { - oilRegionEntry = new RimOilRegionEntry; - oilRegionEntry->name = regionStrings[i]; + oilRegionEntry = new RimOilRegionEntry; + oilRegionEntry->name = regionStrings[i]; - this->regions.push_back(oilRegionEntry); - } + this->regions.push_back(oilRegionEntry); + } + assert(oilRegionEntry); + + if (!oilFieldEntry) + { RimOilFieldEntry* oilFieldEntry = new RimOilFieldEntry; oilFieldEntry->name = fieldStrings[i]; oilFieldEntry->edmId = edmIds[i]; @@ -116,3 +144,43 @@ void RimWellPathImport::updateRegions(const QStringList& regionStrings, const QS } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathImport::initAfterRead() +{ + updateFieldVisibility(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathImport::updateFieldVisibility() +{ + if (utmFilterMode == UTM_FILTER_OFF) + { + north.setUiReadOnly(true); + south.setUiReadOnly(true); + east.setUiReadOnly(true); + west.setUiReadOnly(true); + } + else + { + north.setUiReadOnly(false); + south.setUiReadOnly(false); + east.setUiReadOnly(false); + west.setUiReadOnly(false); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathImport::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + if (changedField == &utmFilterMode) + { + updateFieldVisibility(); + } +} + diff --git a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h index d836401760..0cf24e0271 100644 --- a/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h +++ b/ApplicationCode/WellPathImportSsihub/RimWellPathImport.h @@ -44,7 +44,6 @@ public: caf::PdmField wellTypeSurvey; caf::PdmField wellTypePlans; - caf::PdmField wellTypeAll; caf::PdmField< caf::AppEnum< UtmFilterEnum > > utmFilterMode; caf::PdmField north; @@ -55,5 +54,12 @@ public: caf::PdmPointersField regions; void updateRegions(const QStringList& regions, const QStringList& fields, const QStringList& edmIds); + + virtual void initAfterRead(); + virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); + +//private: + void updateFieldVisibility(); + }; diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp index df98400260..2c6e03e60f 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp @@ -119,9 +119,6 @@ void RiuWellImportWizard::downloadFields() QFile::remove(wellFileName); } - m_wellPathImportObject->regions.deleteAllChildObjects(); - m_wellPathImportObject->updateConnectedEditors(); - QString completeUrlText = m_webServiceAddress + "/resinsight/projects"; QString destinationFileName = jsonFieldsFilePath(); @@ -701,7 +698,6 @@ FieldSelectionPage::FieldSelectionPage(RimWellPathImport* wellPathImport, QWidge layout->addWidget(propertyView); propertyView->showProperties(wellPathImport); - setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); }