mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Various operations on color legends
This commit is contained in:
committed by
Magne Sjaastad
parent
fd475589a5
commit
d39bcb31ab
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicCopyStandardLegendFeature.h"
|
||||
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimColorLegendCollection.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
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<RimColorLegend*>(
|
||||
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::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
|
||||
|
||||
if ( !selectedObject ) return nullptr;
|
||||
|
||||
RimColorLegend* colorLegend = nullptr;
|
||||
|
||||
selectedObject->firstAncestorOrThisOfType( colorLegend );
|
||||
if ( colorLegend ) return colorLegend;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// 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();
|
||||
};
|
||||
@@ -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 <QAction>
|
||||
#include <QFileDialog>
|
||||
|
||||
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::PdmObject*>( 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<cvf::Color3f>& 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" );
|
||||
@@ -23,7 +23,7 @@
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicImportColorCategories : public caf::CmdFeature
|
||||
class RicImportColorCategoriesFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicInsertColorLegendFeature.h"
|
||||
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimColorLegendCollection.h"
|
||||
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
#include <QAction>
|
||||
|
||||
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::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
|
||||
|
||||
if ( !selectedObject ) return nullptr;
|
||||
|
||||
RimColorLegendCollection* colorLegendCollection = nullptr;
|
||||
|
||||
selectedObject->firstAncestorOrThisOfType( colorLegendCollection );
|
||||
if ( colorLegendCollection ) return colorLegendCollection;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// 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();
|
||||
};
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// 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 <QAction>
|
||||
|
||||
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::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
|
||||
|
||||
if ( !selectedObject ) return nullptr;
|
||||
|
||||
RimColorLegend* colorLegend = nullptr;
|
||||
|
||||
selectedObject->firstAncestorOrThisOfType( colorLegend );
|
||||
|
||||
if ( colorLegend ) return colorLegend;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/gpl.html>
|
||||
// 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();
|
||||
};
|
||||
Reference in New Issue
Block a user