#5832 Add color legend data with import from LYR file.

This commit is contained in:
Stein Inge Dale
2020-04-30 16:54:25 +02:00
committed by Kristian Bendiksen
parent 3e5c77e79e
commit 6cb86d4792
24 changed files with 1114 additions and 24 deletions

View File

@@ -0,0 +1,22 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategories.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportColorCategories.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)
list(APPEND CODE_SOURCE_FILES
${SOURCE_GROUP_SOURCE_FILES}
)
source_group( "CommandFeature\\ColorLegend" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )
# cotire
caf_cotire_start_unity_at_first_item(SOURCE_GROUP_SOURCE_FILES)

View File

@@ -0,0 +1,100 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicImportColorCategories.h"
#include "RiaApplication.h"
#include "RigFormationNames.h"
#include "RimColorLegend.h"
#include "RimColorLegendCollection.h"
#include "RimColorLegendItem.h"
#include "RimProject.h"
#include "RifColorLegendData.h"
#include "Riu3DMainWindowTools.h"
#include <QAction>
#include <QFileDialog>
CAF_CMD_SOURCE_INIT( RicImportColorCategories, "RicImportColorCategories" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportColorCategories::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportColorCategories::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
QString defaultDir = app->lastUsedDialogDirectory( "BINARY_GRID" );
QString filterText = QString( "Formation Names description File (*.lyr);;All Files (*.*)" );
QString fileName = QFileDialog::getOpenFileName( Riu3DMainWindowTools::mainWindowWidget(),
"Import Formation File",
defaultDir,
filterText );
if ( fileName.isEmpty() ) return;
// Remember the path to next time
app->setLastUsedDialogDirectory( "BINARY_GRID", QFileInfo( fileName ).absolutePath() );
QString errormessage;
cvf::ref<RigFormationNames> formations = RifColorLegendData::readFormationNamesFile( fileName, &errormessage );
const std::vector<QString>& formationNames = formations->formationNames();
const std::vector<cvf::Color3f>& formationColors = formations->formationColors();
RimColorLegend* colorLegend = new RimColorLegend;
colorLegend->setColorLegendName( "LYR imported color legend" );
for ( size_t i = 0; i < formationColors.size(); i++ )
{
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
colorLegendItem->setValues( formationNames[i], i, formationColors[i] );
colorLegend->appendColorLegendItem( colorLegendItem );
}
RimProject* proj = RimProject::current();
RimColorLegendCollection* colorLegendCollection = proj->colorLegendCollection;
colorLegendCollection->appendColorLegend( colorLegend );
colorLegendCollection->updateConnectedEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportColorCategories::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/Formations16x16.png" ) );
actionToSetup->setText( "Import Color Legend from LYR Formation File" );
}

View File

@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 RicImportColorCategories : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};