diff --git a/ApplicationCode/Commands/ColorLegendCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ColorLegendCommands/CMakeLists_files.cmake index fe238f11ea..95bc8fc0de 100644 --- a/ApplicationCode/Commands/ColorLegendCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ColorLegendCommands/CMakeLists_files.cmake @@ -1,10 +1,16 @@ set (SOURCE_GROUP_HEADER_FILES -${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategories.h +${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategoriesFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicCopyStandardLegendFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicInsertColorLegendFeature.h +${CMAKE_CURRENT_LIST_DIR}/RicInsertColorLegendItemFeature.h ) set (SOURCE_GROUP_SOURCE_FILES -${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategories.cpp +${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategoriesFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicCopyStandardLegendFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicInsertColorLegendFeature.cpp +${CMAKE_CURRENT_LIST_DIR}/RicInsertColorLegendItemFeature.cpp ) diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.cpp b/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.cpp new file mode 100644 index 0000000000..bc9a6a6e1b --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.cpp @@ -0,0 +1,92 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicCopyStandardLegendFeature.h" + +#include "RimColorLegend.h" +#include "RimColorLegendCollection.h" +#include "RimProject.h" + +#include "cafSelectionManager.h" + +#include "Riu3DMainWindowTools.h" + +#include + +CAF_CMD_SOURCE_INIT( RicCopyStandardLegendFeature, "RicCopyStandardLegendFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCopyStandardLegendFeature::isCommandEnabled() +{ + if ( selectedColorLegend() ) return true; + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCopyStandardLegendFeature::onActionTriggered( bool isChecked ) +{ + RimColorLegend* standardLegend = selectedColorLegend(); + + if ( standardLegend ) + { + // perform deep copy of standard legend object via XML + RimColorLegend* customLegend = dynamic_cast( + standardLegend->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) ); + + customLegend->setColorLegendName( "Copy of " + standardLegend->colorLegendName() ); + + RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection; + + colorLegendCollection->appendCustomColorLegend( customLegend ); + colorLegendCollection->updateConnectedEditors(); + + Riu3DMainWindowTools::setExpanded( customLegend ); + Riu3DMainWindowTools::selectAsCurrentItem( customLegend ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCopyStandardLegendFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/Legend.png" ) ); + actionToSetup->setText( "Copy Legend to Custom Legends" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimColorLegend* RicCopyStandardLegendFeature::selectedColorLegend() +{ + caf::PdmObject* selectedObject = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + + if ( !selectedObject ) return nullptr; + + RimColorLegend* colorLegend = nullptr; + + selectedObject->firstAncestorOrThisOfType( colorLegend ); + if ( colorLegend ) return colorLegend; + + return nullptr; +} diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.h b/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.h new file mode 100644 index 0000000000..ffb271b03d --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicCopyStandardLegendFeature.h @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RimColorLegend; + +//================================================================================================== +/// +//================================================================================================== +class RicCopyStandardLegendFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + RimColorLegend* selectedColorLegend(); +}; diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.cpp b/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.cpp similarity index 76% rename from ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.cpp rename to ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.cpp index 8bdab07afd..17b8156122 100644 --- a/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.cpp +++ b/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.cpp @@ -16,7 +16,7 @@ // ///////////////////////////////////////////////////////////////////////////////// -#include "RicImportColorCategories.h" +#include "RicImportColorCategoriesFeature.h" #include "RiaApplication.h" @@ -30,23 +30,35 @@ #include "RifColorLegendData.h" #include "Riu3DMainWindowTools.h" +#include "cafSelectionManager.h" + #include #include -CAF_CMD_SOURCE_INIT( RicImportColorCategories, "RicImportColorCategories" ); +CAF_CMD_SOURCE_INIT( RicImportColorCategoriesFeature, "RicImportColorCategoriesFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicImportColorCategories::isCommandEnabled() +bool RicImportColorCategoriesFeature::isCommandEnabled() { - return true; + RimColorLegendCollection* legendCollection = nullptr; + + caf::PdmObject* selObj = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + if ( selObj ) + { + selObj->firstAncestorOrThisOfType( legendCollection ); + } + + if ( legendCollection ) return true; + + return false; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicImportColorCategories::onActionTriggered( bool isChecked ) +void RicImportColorCategoriesFeature::onActionTriggered( bool isChecked ) { RiaApplication* app = RiaApplication::instance(); QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" ); @@ -70,13 +82,13 @@ void RicImportColorCategories::onActionTriggered( bool isChecked ) const std::vector& formationColors = formations->formationColors(); RimColorLegend* colorLegend = new RimColorLegend; - colorLegend->setColorLegendName( "LYR imported color legend" ); + colorLegend->setColorLegendName( QFileInfo( fileName ).baseName() ); for ( size_t i = 0; i < formationColors.size(); i++ ) { RimColorLegendItem* colorLegendItem = new RimColorLegendItem; - colorLegendItem->setValues( formationNames[i], i, formationColors[i] ); + colorLegendItem->setValues( formationNames[i], (int)i, formationColors[i] ); colorLegend->appendColorLegendItem( colorLegendItem ); } @@ -85,15 +97,18 @@ void RicImportColorCategories::onActionTriggered( bool isChecked ) RimColorLegendCollection* colorLegendCollection = proj->colorLegendCollection; - colorLegendCollection->appendColorLegend( colorLegend ); + colorLegendCollection->appendCustomColorLegend( colorLegend ); colorLegendCollection->updateConnectedEditors(); + + Riu3DMainWindowTools::setExpanded( colorLegend ); + Riu3DMainWindowTools::selectAsCurrentItem( colorLegend ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RicImportColorCategories::setupActionLook( QAction* actionToSetup ) +void RicImportColorCategoriesFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setIcon( QIcon( ":/Formations16x16.png" ) ); actionToSetup->setText( "Import Color Legend from LYR Formation File" ); diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.h b/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.h similarity index 95% rename from ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.h rename to ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.h index 1a6e60fd4d..84d8d3c484 100644 --- a/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategories.h +++ b/ApplicationCode/Commands/ColorLegendCommands/RicImportColorCategoriesFeature.h @@ -23,7 +23,7 @@ //================================================================================================== /// //================================================================================================== -class RicImportColorCategories : public caf::CmdFeature +class RicImportColorCategoriesFeature : public caf::CmdFeature { CAF_CMD_HEADER_INIT; diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.cpp b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.cpp new file mode 100644 index 0000000000..9f99f3cb17 --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.cpp @@ -0,0 +1,92 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicInsertColorLegendFeature.h" + +#include "RimColorLegend.h" +#include "RimColorLegendCollection.h" + +#include "RimProject.h" + +#include "cafSelectionManager.h" + +#include "Riu3DMainWindowTools.h" +#include + +CAF_CMD_SOURCE_INIT( RicInsertColorLegendFeature, "RicInsertColorLegendFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicInsertColorLegendFeature::isCommandEnabled() +{ + if ( selectedColorLegendCollection() ) return true; + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// TODO: insert new color legend prior to entry of selected color legend ? +/// C.f. RicNewAnalysisPlotFeature.cpp(70-71) +//-------------------------------------------------------------------------------------------------- +void RicInsertColorLegendFeature::onActionTriggered( bool isChecked ) +{ + RimColorLegendCollection* colorLegendCollection = selectedColorLegendCollection(); + + if ( colorLegendCollection ) + { + RimColorLegend* customLegend = new RimColorLegend(); + customLegend->setColorLegendName( "New Color Legend" ); + + RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection; + + colorLegendCollection->appendCustomColorLegend( customLegend ); + caf::SelectionManager::instance()->setSelectedItem( customLegend ); + + colorLegendCollection->updateConnectedEditors(); + + Riu3DMainWindowTools::setExpanded( customLegend ); + Riu3DMainWindowTools::selectAsCurrentItem( customLegend ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicInsertColorLegendFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/Legend.png" ) ); + actionToSetup->setText( "New Custom Color Legend" ); +} + +//-------------------------------------------------------------------------------------------------- +/// C.f. RicNewAnalysisPlotFeature.cpp(42) +//-------------------------------------------------------------------------------------------------- +RimColorLegendCollection* RicInsertColorLegendFeature::selectedColorLegendCollection() +{ + caf::PdmObject* selectedObject = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + + if ( !selectedObject ) return nullptr; + + RimColorLegendCollection* colorLegendCollection = nullptr; + + selectedObject->firstAncestorOrThisOfType( colorLegendCollection ); + if ( colorLegendCollection ) return colorLegendCollection; + + return nullptr; +} diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.h b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.h new file mode 100644 index 0000000000..5de8c99ba4 --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendFeature.h @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RimColorLegendCollection; + +//================================================================================================== +/// +//================================================================================================== +class RicInsertColorLegendFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + RimColorLegendCollection* selectedColorLegendCollection(); +}; diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.cpp b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.cpp new file mode 100644 index 0000000000..5b61132ddf --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.cpp @@ -0,0 +1,102 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicInsertColorLegendItemFeature.h" + +#include "RimColorLegend.h" +#include "RimColorLegendCollection.h" +#include "RimColorLegendItem.h" +#include "RimProject.h" + +#include "Riu3DMainWindowTools.h" + +#include "cafSelectionManager.h" + +#include + +CAF_CMD_SOURCE_INIT( RicInsertColorLegendItemFeature, "RicInsertColorLegendItemFeature" ); + +//-------------------------------------------------------------------------------------------------- +/// Disallows insert of color legend item in standard color legends +//-------------------------------------------------------------------------------------------------- +bool RicInsertColorLegendItemFeature::isCommandEnabled() +{ + RimColorLegend* legend = selectedColorLegend(); + + if ( legend ) + { + RimColorLegendCollection* colorLegendCollection = nullptr; + + legend->firstAncestorOrThisOfType( colorLegendCollection ); + + if ( colorLegendCollection && !colorLegendCollection->isStandardColorLegend( legend ) ) return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// TODO: insert new color legend item prior to selected color legend item? +/// C.f. RicNewAnalysisPlotFeature.cpp(70-71) +//-------------------------------------------------------------------------------------------------- +void RicInsertColorLegendItemFeature::onActionTriggered( bool isChecked ) +{ + RimColorLegend* legend = selectedColorLegend(); + + if ( legend ) + { + RimColorLegendItem* newLegendItem = new RimColorLegendItem(); + + legend->appendColorLegendItem( newLegendItem ); + legend->updateConnectedEditors(); + + caf::SelectionManager::instance()->setSelectedItem( newLegendItem ); + + legend->updateConnectedEditors(); + + Riu3DMainWindowTools::setExpanded( newLegendItem ); + Riu3DMainWindowTools::selectAsCurrentItem( newLegendItem ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicInsertColorLegendItemFeature::setupActionLook( QAction* actionToSetup ) +{ + actionToSetup->setIcon( QIcon( ":/Legend.png" ) ); + actionToSetup->setText( "Append Color Legend Item" ); +} + +//-------------------------------------------------------------------------------------------------- +/// C.f. RicNewAnalysisPlotFeature.cpp(42) +//-------------------------------------------------------------------------------------------------- +RimColorLegend* RicInsertColorLegendItemFeature::selectedColorLegend() +{ + caf::PdmObject* selectedObject = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); + + if ( !selectedObject ) return nullptr; + + RimColorLegend* colorLegend = nullptr; + + selectedObject->firstAncestorOrThisOfType( colorLegend ); + + if ( colorLegend ) return colorLegend; + + return nullptr; +} diff --git a/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.h b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.h new file mode 100644 index 0000000000..0cedebd1d1 --- /dev/null +++ b/ApplicationCode/Commands/ColorLegendCommands/RicInsertColorLegendItemFeature.h @@ -0,0 +1,39 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +class RimColorLegend; + +//================================================================================================== +/// +//================================================================================================== +class RicInsertColorLegendItemFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + bool isCommandEnabled() override; + void onActionTriggered( bool isChecked ) override; + void setupActionLook( QAction* actionToSetup ) override; + +private: + RimColorLegend* selectedColorLegend(); +}; diff --git a/ApplicationCode/Commands/RicDeleteItemFeature.cpp b/ApplicationCode/Commands/RicDeleteItemFeature.cpp index d72cb3bcdc..0e0716871c 100644 --- a/ApplicationCode/Commands/RicDeleteItemFeature.cpp +++ b/ApplicationCode/Commands/RicDeleteItemFeature.cpp @@ -77,6 +77,8 @@ #include "cafPdmReferenceHelper.h" #include "cafSelectionManager.h" +#include "RimColorLegend.h" +#include "RimColorLegendItem.h" #include CAF_CMD_SOURCE_INIT( RicDeleteItemFeature, "RicDeleteItemFeature" ); @@ -143,6 +145,8 @@ bool isDeletable( caf::PdmUiItem* uiItem ) if ( dynamic_cast( uiItem ) ) return true; if ( dynamic_cast( uiItem ) ) return true; if ( dynamic_cast( uiItem ) ) return true; + if ( dynamic_cast( uiItem ) ) return true; + if ( dynamic_cast( uiItem ) ) return true; if ( dynamic_cast( uiItem ) ) { diff --git a/ApplicationCode/Commands/RicImportFaciesFeature.cpp b/ApplicationCode/Commands/RicImportFaciesFeature.cpp index 6f8e38fd39..2dc656c0ef 100644 --- a/ApplicationCode/Commands/RicImportFaciesFeature.cpp +++ b/ApplicationCode/Commands/RicImportFaciesFeature.cpp @@ -91,7 +91,7 @@ void RicImportFaciesFeature::onActionTriggered( bool isChecked ) } RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection; - colorLegendCollection->appendColorLegend( colorLegend ); + colorLegendCollection->appendCustomColorLegend( colorLegend ); colorLegendCollection->updateConnectedEditors(); } diff --git a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp index ac6bb9379b..5a10300cfb 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegend.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegend.cpp @@ -44,9 +44,9 @@ RimColorLegend::~RimColorLegend() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::PdmFieldHandle* RimColorLegend::userDescriptionField() +QString RimColorLegend::colorLegendName() { - return &m_colorLegendName; + return m_colorLegendName; } //-------------------------------------------------------------------------------------------------- @@ -57,6 +57,19 @@ void RimColorLegend::setColorLegendName( const QString& colorLegendName ) m_colorLegendName = colorLegendName; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegend::setReadOnly( bool doReadOnly ) +{ + m_colorLegendName.uiCapability()->setUiReadOnly( true ); + + for ( auto colorLegendItem : m_colorLegendItems ) + { + colorLegendItem->setReadOnly( true ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -73,6 +86,14 @@ std::vector RimColorLegend::colorLegendItems() const return m_colorLegendItems.childObjects(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::PdmFieldHandle* RimColorLegend::userDescriptionField() +{ + return &m_colorLegendName; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimColorLegend.h b/ApplicationCode/ProjectDataModel/RimColorLegend.h index bc33849ce9..e816b4f571 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegend.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegend.h @@ -42,7 +42,12 @@ public: ~RimColorLegend() override; public: + QString colorLegendName(); + void setColorLegendName( const QString& colorLegendName ); + + void setReadOnly( bool doReadOnly ); + void appendColorLegendItem( RimColorLegendItem* colorLegendItem ); std::vector colorLegendItems() const; diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp index d0bcb0915d..dcb123c143 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.cpp @@ -18,6 +18,11 @@ #include "RimColorLegendCollection.h" #include "RimColorLegend.h" +#include "RimRegularLegendConfig.h" + +#include "RimColorLegendItem.h" +#include "RimProject.h" +#include CAF_PDM_SOURCE_INIT( RimColorLegendCollection, "ColorLegendCollection" ); @@ -26,10 +31,16 @@ CAF_PDM_SOURCE_INIT( RimColorLegendCollection, "ColorLegendCollection" ); //-------------------------------------------------------------------------------------------------- RimColorLegendCollection::RimColorLegendCollection() { - CAF_PDM_InitObject( "ColorLegendCollection", ":/Formations16x16.png", "", "" ); + CAF_PDM_InitObject( "Color Legend Collection", ":/Legend.png", "", "" ); - CAF_PDM_InitFieldNoDefault( &m_colorLegends, "ColorLegends", "", "", "", "" ); - m_colorLegends.uiCapability()->setUiHidden( true ); + CAF_PDM_InitFieldNoDefault( &m_standardColorLegends, + "StandardColorLegends", + "Standard Color Legends", + ":/Legend.png", + "", + "" ); + + CAF_PDM_InitFieldNoDefault( &m_customColorLegends, "CustomColorLegends", "Custom Color Legends", ":/Legend.png", "", "" ); } //-------------------------------------------------------------------------------------------------- @@ -42,17 +53,86 @@ RimColorLegendCollection::~RimColorLegendCollection() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimColorLegendCollection::appendColorLegend( RimColorLegend* colorLegend ) +void RimColorLegendCollection::appendCustomColorLegend( RimColorLegend* colorLegend ) { - m_colorLegends.push_back( colorLegend ); + m_customColorLegends.push_back( colorLegend ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimColorLegendCollection::colorLegends() const +bool RimColorLegendCollection::isStandardColorLegend( RimColorLegend* legend ) { - return m_colorLegends.childObjects(); + for ( auto standardLegend : m_standardColorLegends ) + { + if ( legend == standardLegend ) return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegendCollection::deleteCustomColorLegends() +{ + m_customColorLegends.deleteAllChildObjects(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegendCollection::createStandardColorLegends() +{ + typedef caf::AppEnum ColorRangeEnum; + + for ( size_t typeIdx = 0; typeIdx < ColorRangeEnum::size(); typeIdx++ ) + { + QString legendName = ColorRangeEnum::uiTextFromIndex( typeIdx ); + cvf::Color3ubArray colorArray = + RimRegularLegendConfig::colorArrayFromColorType( ColorRangeEnum::fromIndex( typeIdx ) ); + + RimColorLegend* colorLegend = new RimColorLegend; + colorLegend->setColorLegendName( legendName ); + + for ( int i = (int)colorArray.size() - 1; i > -1; i-- ) // reverse to assign last color to top of legend + { + cvf::Color3f color3f( colorArray[i] ); + QColor colorQ( colorArray[i].r(), colorArray[i].g(), colorArray[i].b() ); + + RimColorLegendItem* colorLegendItem = new RimColorLegendItem; + colorLegendItem->setValues( colorQ.name(), i, color3f ); + + colorLegend->appendColorLegendItem( colorLegendItem ); + colorLegend->setReadOnly( true ); + } + + m_standardColorLegends.push_back( colorLegend ); + } + + this->updateConnectedEditors(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimColorLegendCollection::customColorLegends() const +{ + std::vector allLegends; + + auto standardLegends = m_standardColorLegends.childObjects(); + for ( auto l : standardLegends ) + { + allLegends.push_back( l ); + } + + auto customLegends = m_customColorLegends.childObjects(); + for ( auto l : customLegends ) + { + allLegends.push_back( l ); + } + + return allLegends; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h index 62d33c46b3..836fc7cfe6 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegendCollection.h @@ -41,12 +41,19 @@ public: RimColorLegendCollection(); ~RimColorLegendCollection() override; - void appendColorLegend( RimColorLegend* colorLegend ); + void createStandardColorLegends(); - std::vector colorLegends() const; + void appendCustomColorLegend( RimColorLegend* customColorLegend ); + + bool isStandardColorLegend( RimColorLegend* colorLegend ); + + void deleteCustomColorLegends(); + + std::vector customColorLegends() const; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; private: - caf::PdmChildArrayField m_colorLegends; + caf::PdmChildArrayField m_standardColorLegends; // ResInsight standard (built-in) legends + caf::PdmChildArrayField m_customColorLegends; // user specified legends }; diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp b/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp index d62d2bb201..4794a6bf2c 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp +++ b/ApplicationCode/ProjectDataModel/RimColorLegendItem.cpp @@ -33,6 +33,7 @@ RimColorLegendItem::RimColorLegendItem() CAF_PDM_InitObject( "ColorLegendItem", "", "", "" ); CAF_PDM_InitFieldNoDefault( &m_color, "Color", "Color", "", "", "" ); + m_color = cvf::Color3f( cvf::Color3::ColorIdent::BLACK ); CAF_PDM_InitField( &m_categoryValue, "CategoryValue", 0, "Category Value", "", "", "" ); CAF_PDM_InitField( &m_categoryName, "CategoryName", QString( "" ), "Category Name", "", "", "" ); @@ -60,6 +61,16 @@ void RimColorLegendItem::setValues( const QString& categoryName, int categoryVal m_color = color; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimColorLegendItem::setReadOnly( bool doReadOnly ) +{ + m_categoryName.uiCapability()->setUiReadOnly( true ); + m_categoryValue.uiCapability()->setUiReadOnly( true ); + m_color.uiCapability()->setUiReadOnly( true ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimColorLegendItem.h b/ApplicationCode/ProjectDataModel/RimColorLegendItem.h index dcb296462c..be8902cddd 100644 --- a/ApplicationCode/ProjectDataModel/RimColorLegendItem.h +++ b/ApplicationCode/ProjectDataModel/RimColorLegendItem.h @@ -41,7 +41,9 @@ public: RimColorLegendItem(); ~RimColorLegendItem() override; - void setValues( const QString& categoryName, int categoryValue, const cvf::Color3f& color ); + void setValues( const QString& categoryName, int categoryValue, const cvf::Color3f& color ); + void setReadOnly( bool doReadOnly ); + const cvf::Color3f& color() const; const QString& categoryName() const; int categoryValue() const; @@ -49,6 +51,7 @@ public: public: void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ ) override; + caf::PdmFieldHandle* userDescriptionField() override; private: diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 0bf11eda3f..ed810a7f7d 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -39,7 +39,9 @@ #include "RimCellEdgeColors.h" #include "RimCellRangeFilter.h" #include "RimCellRangeFilterCollection.h" +#include "RimColorLegend.h" #include "RimColorLegendCollection.h" +#include "RimColorLegendItem.h" #include "RimCorrelationMatrixPlot.h" #include "RimCorrelationPlot.h" #include "RimCorrelationPlotCollection.h" @@ -792,8 +794,20 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() } else if ( dynamic_cast( firstUiItem ) ) { - menuBuilder << "RicImportColorCategories"; + menuBuilder << "RicInsertColorLegendFeature"; + menuBuilder << "RicImportColorCategoriesFeature"; // import of color legend from LYR file } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicInsertColorLegendFeature"; + menuBuilder << "RicCopyStandardLegendFeature"; + menuBuilder << "RicInsertColorLegendItemFeature"; + } + else if ( dynamic_cast( firstUiItem ) ) + { + menuBuilder << "RicInsertColorLegendItemFeature"; + } + else if ( dynamic_cast( firstUiItem ) ) { menuBuilder << "RicImportFormationNamesFeature"; diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index 6f40fbdcac..0ce714bd29 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -133,6 +133,7 @@ RimProject::RimProject( void ) CAF_PDM_InitFieldNoDefault( &colorLegendCollection, "ColorLegendCollection", "Color Legend Collection", "", "", "" ); colorLegendCollection = new RimColorLegendCollection(); + colorLegendCollection->createStandardColorLegends(); CAF_PDM_InitFieldNoDefault( &scriptCollection, "ScriptCollection", "Octave Scripts", ":/octave.png", "", "" ); scriptCollection.uiCapability()->setUiHidden( true ); @@ -256,6 +257,7 @@ void RimProject::close() m_dialogData->clearProjectSpecificData(); calculationCollection->deleteAllContainedObjects(); + colorLegendCollection->deleteCustomColorLegends(); delete viewLinkerCollection->viewLinker(); viewLinkerCollection->viewLinker = nullptr; diff --git a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp index 2920b6bd18..5f35fbcf05 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogTrack.cpp @@ -2525,7 +2525,7 @@ void RimWellLogTrack::updateResultPropertyNamesOnPlot() RimProject* proj = RimProject::current(); RimColorLegendCollection* colorLegendCollection = proj->colorLegendCollection; - std::vector legends = colorLegendCollection->colorLegends(); + std::vector legends = colorLegendCollection->customColorLegends(); if ( legends.empty() ) { RiaLogging::error( "No color legend found." );