2012-05-18 02:45:23 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 08:04:57 -05:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2012-05-18 02:45:23 -05:00
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
2018-04-18 03:10:39 -05:00
# include "RimRegularLegendConfig.h"
2013-05-06 05:02:32 -05:00
2016-08-01 15:27:03 -05:00
# include "RiaApplication.h"
2017-02-10 01:37:48 -06:00
# include "RiaColorTables.h"
2018-03-19 05:16:50 -05:00
# include "RiaPreferences.h"
2016-08-01 15:27:03 -05:00
2016-10-18 00:31:02 -05:00
# include "RimCellEdgeColors.h"
2016-08-02 03:25:55 -05:00
# include "RimEclipseCellColors.h"
2018-04-20 03:17:02 -05:00
# include "RimEnsembleCurveSet.h"
2018-05-04 06:06:48 -05:00
# include "RimEnsembleCurveSetCollection.h"
# include "RimEnsembleCurveSetColorManager.h"
2016-08-01 15:27:03 -05:00
# include "RimEclipseView.h"
2016-10-18 00:31:02 -05:00
# include "RimGeoMechResultDefinition.h"
2018-03-19 05:16:50 -05:00
# include "RimIntersectionCollection.h"
2017-02-20 05:26:36 -06:00
# include "RimStimPlanColors.h"
2016-12-09 13:36:31 -06:00
# include "RimViewLinker.h"
2016-08-01 15:27:03 -05:00
2018-04-05 08:25:33 -05:00
# include "cafTitledOverlayFrame.h"
2016-08-02 03:25:55 -05:00
# include "cafCategoryLegend.h"
# include "cafCategoryMapper.h"
2018-03-08 04:20:27 -06:00
# include "cafOverlayScalarMapperLegend.h"
2016-08-02 03:25:55 -05:00
2012-06-26 09:10:41 -05:00
# include "cafFactory.h"
2014-05-06 15:40:25 -05:00
# include "cafPdmFieldCvfColor.h"
# include "cafPdmFieldCvfMat4d.h"
2012-06-26 09:10:41 -05:00
# include "cafPdmUiComboBoxEditor.h"
2014-05-06 15:40:25 -05:00
# include "cafPdmUiLineEditor.h"
2013-05-06 05:02:32 -05:00
2014-05-06 15:40:25 -05:00
# include "cvfScalarMapperContinuousLinear.h"
# include "cvfScalarMapperContinuousLog.h"
2013-05-06 03:55:00 -05:00
# include "cvfScalarMapperDiscreteLinear.h"
2014-05-06 15:40:25 -05:00
# include "cvfScalarMapperDiscreteLog.h"
2016-09-09 05:10:24 -05:00
# include "cvfqtUtils.h"
2014-05-06 15:40:25 -05:00
2013-05-06 05:02:32 -05:00
# include <cmath>
2018-05-03 02:53:25 -05:00
# include <algorithm>
2012-05-18 02:45:23 -05:00
2018-05-04 06:06:48 -05:00
using ColorManager = RimEnsembleCurveSetColorManager ;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
CAF_PDM_SOURCE_INIT ( RimRegularLegendConfig , " Legend " ) ;
2012-05-18 02:45:23 -05:00
namespace caf {
template < >
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : ColorRangeEnum : : setUp ( )
2012-05-18 02:45:23 -05:00
{
2018-05-04 06:06:48 -05:00
addItem ( RimRegularLegendConfig : : NORMAL , " NORMAL " , " Full color, Red on top " ) ;
addItem ( RimRegularLegendConfig : : OPPOSITE_NORMAL , " OPPOSITE_NORMAL " , " Full color, Blue on top " ) ;
addItem ( RimRegularLegendConfig : : WHITE_PINK , " WHITE_PIMK " , " White to pink " ) ;
addItem ( RimRegularLegendConfig : : PINK_WHITE , " PINK_WHITE " , " Pink to white " ) ;
addItem ( RimRegularLegendConfig : : BLUE_WHITE_RED , " BLUE_WHITE_RED " , " Blue, white, red " ) ;
addItem ( RimRegularLegendConfig : : RED_WHITE_BLUE , " RED_WHITE_BLUE " , " Red, white, blue " ) ;
addItem ( RimRegularLegendConfig : : WHITE_BLACK , " WHITE_BLACK " , " White to black " ) ;
addItem ( RimRegularLegendConfig : : BLACK_WHITE , " BLACK_WHITE " , " Black to white " ) ;
addItem ( RimRegularLegendConfig : : CATEGORY , " CATEGORY " , " Category colors " ) ;
addItem ( RimRegularLegendConfig : : ANGULAR , " ANGULAR " , " Full color cyclic " ) ;
addItem ( RimRegularLegendConfig : : STIMPLAN , " STIMPLAN " , " StimPlan colors " ) ;
addItem ( RimRegularLegendConfig : : RED_LIGHT_DARK , " RED_DARK_LIGHT " , " Red Light to Dark " ) ;
addItem ( RimRegularLegendConfig : : GREEN_LIGHT_DARK , " GREEN_DARK_LIGHT " , " Green Light to Dark " ) ;
addItem ( RimRegularLegendConfig : : BLUE_LIGHT_DARK , " BLUE_DARK_LIGHT " , " Blue Light to Dark " ) ;
addItem ( RimRegularLegendConfig : : GREEN_RED , " GREEN_RED " , " Green to Red " ) ;
addItem ( RimRegularLegendConfig : : BLUE_MAGENTA , " BLUE_MAGENTA " , " Blue to Magenta " ) ;
2018-04-18 03:10:39 -05:00
setDefault ( RimRegularLegendConfig : : NORMAL ) ;
2012-05-18 02:45:23 -05:00
}
}
namespace caf {
template < >
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : MappingEnum : : setUp ( )
2012-05-18 02:45:23 -05:00
{
2018-04-18 03:10:39 -05:00
addItem ( RimRegularLegendConfig : : LINEAR_DISCRETE , " LinearDiscrete " , " Discrete Linear " ) ;
addItem ( RimRegularLegendConfig : : LINEAR_CONTINUOUS , " LinearContinuous " , " Continuous Linear " ) ;
addItem ( RimRegularLegendConfig : : LOG10_CONTINUOUS , " Log10Continuous " , " Continuous Logarithmic " ) ;
addItem ( RimRegularLegendConfig : : LOG10_DISCRETE , " Log10Discrete " , " Discrete Logarithmic " ) ;
addItem ( RimRegularLegendConfig : : CATEGORY_INTEGER , " Category " , " Category " ) ;
setDefault ( RimRegularLegendConfig : : LINEAR_CONTINUOUS ) ;
2012-05-18 02:45:23 -05:00
}
}
2013-04-30 07:48:53 -05:00
namespace caf {
template < >
2018-04-18 03:10:39 -05:00
void AppEnum < RimRegularLegendConfig : : NumberFormatType > : : setUp ( )
2013-04-30 07:48:53 -05:00
{
2018-04-18 03:10:39 -05:00
addItem ( RimRegularLegendConfig : : AUTO , " AUTO " , " Automatic " ) ;
addItem ( RimRegularLegendConfig : : FIXED , " FIXED " , " Fixed, decimal " ) ;
addItem ( RimRegularLegendConfig : : SCIENTIFIC , " SCIENTIFIC " , " Scientific notation " ) ;
setDefault ( RimRegularLegendConfig : : FIXED ) ;
2013-04-30 07:48:53 -05:00
}
}
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
RimRegularLegendConfig : : RimRegularLegendConfig ( )
2012-05-18 02:45:23 -05:00
: m_globalAutoMax ( cvf : : UNDEFINED_DOUBLE ) ,
m_globalAutoMin ( cvf : : UNDEFINED_DOUBLE ) ,
m_localAutoMax ( cvf : : UNDEFINED_DOUBLE ) ,
2013-06-03 06:08:11 -05:00
m_localAutoMin ( cvf : : UNDEFINED_DOUBLE ) ,
m_globalAutoPosClosestToZero ( 0 ) ,
m_globalAutoNegClosestToZero ( 0 ) ,
m_localAutoPosClosestToZero ( 0 ) ,
2017-01-03 07:58:34 -06:00
m_localAutoNegClosestToZero ( 0 ) ,
m_isAllTimeStepsRangeDisabled ( false )
2012-05-18 02:45:23 -05:00
{
CAF_PDM_InitObject ( " Legend Definition " , " :/Legend.png " , " " , " " ) ;
2018-04-17 08:59:50 -05:00
CAF_PDM_InitField ( & m_showLegend , " ShowLegend " , true , " Show Legend " , " " , " " , " " ) ;
m_showLegend . uiCapability ( ) - > setUiHidden ( true ) ;
2017-11-30 06:44:18 -06:00
CAF_PDM_InitField ( & m_numLevels , " NumberOfLevels " , 8 , " Number of Levels " , " " , " A hint on how many tick marks you whish. " , " " ) ;
CAF_PDM_InitField ( & m_precision , " Precision " , 4 , " Significant Digits " , " " , " The number of significant digits displayed in the legend numbers " , " " ) ;
2018-04-18 03:10:39 -05:00
CAF_PDM_InitField ( & m_tickNumberFormat , " TickNumberFormat " , caf : : AppEnum < RimRegularLegendConfig : : NumberFormatType > ( FIXED ) , " Number format " , " " , " " , " " ) ;
2013-04-30 07:48:53 -05:00
2013-09-26 03:44:20 -05:00
CAF_PDM_InitField ( & m_colorRangeMode , " ColorRangeMode " , ColorRangeEnum ( NORMAL ) , " Colors " , " " , " " , " " ) ;
2012-05-18 02:45:23 -05:00
CAF_PDM_InitField ( & m_mappingMode , " MappingMode " , MappingEnum ( LINEAR_CONTINUOUS ) , " Mapping " , " " , " " , " " ) ;
2017-11-30 06:44:18 -06:00
CAF_PDM_InitField ( & m_rangeMode , " RangeType " , RangeModeEnum ( AUTOMATIC_ALLTIMESTEPS ) , " Range Type " , " " , " Switches between automatic and user defined range on the legend " , " " ) ;
2017-06-30 09:05:46 -05:00
CAF_PDM_InitField ( & m_userDefinedMaxValue , " UserDefinedMax " , 1.0 , " Max " , " " , " Max value of the legend " , " " ) ;
CAF_PDM_InitField ( & m_userDefinedMinValue , " UserDefinedMin " , 0.0 , " Min " , " " , " Min value of the legend (if mapping is logarithmic only positive values are valid) " , " " ) ;
2012-05-18 02:45:23 -05:00
CAF_PDM_InitField ( & resultVariableName , " ResultVariableUsage " , QString ( " " ) , " " , " " , " " , " " ) ;
2015-08-05 06:27:36 -05:00
resultVariableName . uiCapability ( ) - > setUiHidden ( true ) ;
2012-05-18 02:45:23 -05:00
2012-10-02 03:17:52 -05:00
m_linDiscreteScalarMapper = new cvf : : ScalarMapperDiscreteLinear ;
m_logDiscreteScalarMapper = new cvf : : ScalarMapperDiscreteLog ;
2012-05-18 02:45:23 -05:00
m_linSmoothScalarMapper = new cvf : : ScalarMapperContinuousLinear ;
2012-10-02 03:17:52 -05:00
m_logSmoothScalarMapper = new cvf : : ScalarMapperContinuousLog ;
2012-05-18 02:45:23 -05:00
m_currentScalarMapper = m_linDiscreteScalarMapper ;
2016-08-02 03:25:55 -05:00
m_categoryMapper = new caf : : CategoryMapper ;
2013-04-19 01:02:36 -05:00
cvf : : Font * standardFont = RiaApplication : : instance ( ) - > standardFont ( ) ;
2018-03-08 04:20:27 -06:00
m_scalarMapperLegend = new caf : : OverlayScalarMapperLegend ( standardFont ) ;
2016-08-02 03:25:55 -05:00
m_categoryLegend = new caf : : CategoryLegend ( standardFont , m_categoryMapper . p ( ) ) ;
2012-05-18 02:45:23 -05:00
updateFieldVisibility ( ) ;
updateLegend ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
RimRegularLegendConfig : : ~ RimRegularLegendConfig ( )
2012-05-18 02:45:23 -05:00
{
}
2018-05-03 02:53:25 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig : : setNamedCategories ( const std : : vector < QString > & categoryNames , bool inverse )
{
std : : list < int > nameIndices ;
std : : list < cvf : : String > names ;
int categoriesCount = static_cast < int > ( categoryNames . size ( ) ) ;
for ( int i = 0 ; i < categoriesCount ; i + + )
{
if ( ! inverse )
{
nameIndices . push_back ( i ) ;
names . push_back ( cvfqt : : Utils : : toString ( categoryNames [ i ] ) ) ;
}
else
{
nameIndices . push_front ( i ) ;
names . push_front ( cvfqt : : Utils : : toString ( categoryNames [ i ] ) ) ;
}
}
m_categories = std : : vector < int > ( nameIndices . begin ( ) , nameIndices . end ( ) ) ;
m_categoryNames = std : : vector < cvf : : String > ( names . begin ( ) , names . end ( ) ) ;
m_categoryColors . clear ( ) ;
updateLegend ( ) ;
}
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : fieldChangedByUi ( const caf : : PdmFieldHandle * changedField , const QVariant & oldValue , const QVariant & newValue )
2012-05-18 02:45:23 -05:00
{
if ( changedField = = & m_numLevels )
{
int upperLimit = std : : numeric_limits < int > : : max ( ) ;
m_numLevels = cvf : : Math : : clamp ( m_numLevels . v ( ) , 1 , upperLimit ) ;
}
2016-08-02 03:25:55 -05:00
else if ( changedField = = & m_rangeMode | |
changedField = = & m_mappingMode )
2012-05-18 02:45:23 -05:00
{
if ( m_rangeMode = = USER_DEFINED )
{
if ( m_userDefinedMaxValue = = m_userDefinedMaxValue . defaultValue ( ) & & m_globalAutoMax ! = cvf : : UNDEFINED_DOUBLE )
{
2013-09-25 18:05:09 -05:00
m_userDefinedMaxValue = roundToNumSignificantDigits ( m_globalAutoMax , m_precision ) ;
2012-05-18 02:45:23 -05:00
}
if ( m_userDefinedMinValue = = m_userDefinedMinValue . defaultValue ( ) & & m_globalAutoMin ! = cvf : : UNDEFINED_DOUBLE )
{
2013-09-25 18:05:09 -05:00
m_userDefinedMinValue = roundToNumSignificantDigits ( m_globalAutoMin , m_precision ) ;
2012-05-18 02:45:23 -05:00
}
}
updateFieldVisibility ( ) ;
}
updateLegend ( ) ;
2018-02-01 10:45:22 -06:00
RimGridView * view = nullptr ;
2016-12-09 13:36:31 -06:00
this - > firstAncestorOrThisOfType ( view ) ;
if ( view )
{
RimViewLinker * viewLinker = view - > assosiatedViewLinker ( ) ;
if ( viewLinker )
{
viewLinker - > updateCellResult ( ) ;
}
2016-12-09 14:15:24 -06:00
view - > updateCurrentTimeStepAndRedraw ( ) ;
2018-02-01 10:45:22 -06:00
view - > crossSectionCollection ( ) - > scheduleCreateDisplayModelAndRedraw2dIntersectionViews ( ) ;
2016-12-09 14:15:24 -06:00
}
2018-01-02 04:21:37 -06:00
// Update stim plan templates if relevant
RimStimPlanColors * stimPlanColors ;
firstAncestorOrThisOfType ( stimPlanColors ) ;
if ( stimPlanColors )
{
stimPlanColors - > updateStimPlanTemplates ( ) ;
}
2018-04-20 03:17:02 -05:00
// Update ensemble curve set if relevant
RimEnsembleCurveSet * ensembleCurveSet ;
firstAncestorOrThisOfType ( ensembleCurveSet ) ;
if ( ensembleCurveSet )
{
ensembleCurveSet - > onLegendDefinitionChanged ( ) ;
}
2012-05-18 02:45:23 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : updateLegend ( )
2012-05-18 02:45:23 -05:00
{
double adjustedMin = cvf : : UNDEFINED_DOUBLE ;
double adjustedMax = cvf : : UNDEFINED_DOUBLE ;
2013-06-03 06:08:11 -05:00
double posClosestToZero = cvf : : UNDEFINED_DOUBLE ;
double negClosestToZero = cvf : : UNDEFINED_DOUBLE ;
2012-05-18 02:45:23 -05:00
if ( m_rangeMode = = AUTOMATIC_ALLTIMESTEPS )
{
2013-09-25 18:05:09 -05:00
adjustedMin = roundToNumSignificantDigits ( m_globalAutoMin , m_precision ) ;
adjustedMax = roundToNumSignificantDigits ( m_globalAutoMax , m_precision ) ;
2013-06-03 06:08:11 -05:00
posClosestToZero = m_globalAutoPosClosestToZero ;
negClosestToZero = m_globalAutoNegClosestToZero ;
2012-05-18 02:45:23 -05:00
}
else if ( m_rangeMode = = AUTOMATIC_CURRENT_TIMESTEP )
{
2013-09-25 18:05:09 -05:00
adjustedMin = roundToNumSignificantDigits ( m_localAutoMin , m_precision ) ;
adjustedMax = roundToNumSignificantDigits ( m_localAutoMax , m_precision ) ;
2013-06-03 06:08:11 -05:00
posClosestToZero = m_localAutoPosClosestToZero ;
negClosestToZero = m_localAutoNegClosestToZero ;
2012-05-18 02:45:23 -05:00
}
else
{
2013-09-25 18:05:09 -05:00
adjustedMin = roundToNumSignificantDigits ( m_userDefinedMinValue , m_precision ) ;
adjustedMax = roundToNumSignificantDigits ( m_userDefinedMaxValue , m_precision ) ;
2013-06-03 06:08:11 -05:00
posClosestToZero = m_globalAutoPosClosestToZero ;
negClosestToZero = m_globalAutoNegClosestToZero ;
2012-05-18 02:45:23 -05:00
}
m_linDiscreteScalarMapper - > setRange ( adjustedMin , adjustedMax ) ;
2013-06-03 06:08:11 -05:00
m_linSmoothScalarMapper - > setRange ( adjustedMin , adjustedMax ) ;
if ( m_mappingMode = = LOG10_CONTINUOUS | | m_mappingMode = = LOG10_DISCRETE )
{
if ( adjustedMin ! = adjustedMax )
{
if ( adjustedMin = = 0 )
{
if ( adjustedMax > adjustedMin )
{
adjustedMin = posClosestToZero ;
}
else
{
adjustedMin = negClosestToZero ;
}
}
else if ( adjustedMax = = 0 )
{
if ( adjustedMin > adjustedMax )
{
adjustedMax = posClosestToZero ;
}
else
{
adjustedMax = negClosestToZero ;
}
}
else if ( adjustedMin < 0 & & adjustedMax > 0 )
{
adjustedMin = posClosestToZero ;
}
else if ( adjustedMax < 0 & & adjustedMin > 0 )
{
adjustedMin = negClosestToZero ;
}
}
}
2012-10-02 03:17:52 -05:00
m_logDiscreteScalarMapper - > setRange ( adjustedMin , adjustedMax ) ;
2012-05-18 02:45:23 -05:00
m_logSmoothScalarMapper - > setRange ( adjustedMin , adjustedMax ) ;
2017-02-10 01:37:48 -06:00
cvf : : Color3ubArray legendColors = colorArrayFromColorType ( m_colorRangeMode ( ) ) ;
2012-05-18 02:45:23 -05:00
2012-10-02 03:17:52 -05:00
m_linDiscreteScalarMapper - > setColors ( legendColors ) ;
m_logDiscreteScalarMapper - > setColors ( legendColors ) ;
2012-05-18 02:45:23 -05:00
m_logSmoothScalarMapper - > setColors ( legendColors ) ;
m_linSmoothScalarMapper - > setColors ( legendColors ) ;
2016-08-02 03:25:55 -05:00
2012-10-02 03:17:52 -05:00
m_linDiscreteScalarMapper - > setLevelCount ( m_numLevels , true ) ;
m_logDiscreteScalarMapper - > setLevelCount ( m_numLevels , true ) ;
m_logSmoothScalarMapper - > setLevelCount ( m_numLevels , true ) ;
m_linSmoothScalarMapper - > setLevelCount ( m_numLevels , true ) ;
2012-05-18 02:45:23 -05:00
switch ( m_mappingMode ( ) )
{
case LINEAR_DISCRETE :
m_currentScalarMapper = m_linDiscreteScalarMapper . p ( ) ;
break ;
case LINEAR_CONTINUOUS :
m_currentScalarMapper = m_linSmoothScalarMapper . p ( ) ;
break ;
case LOG10_CONTINUOUS :
m_currentScalarMapper = m_logSmoothScalarMapper . p ( ) ;
break ;
2012-10-02 03:17:52 -05:00
case LOG10_DISCRETE :
m_currentScalarMapper = m_logDiscreteScalarMapper . p ( ) ;
break ;
2016-08-02 03:25:55 -05:00
case CATEGORY_INTEGER :
2016-09-07 03:28:57 -05:00
m_categoryMapper - > setCategoriesWithNames ( m_categories , m_categoryNames ) ;
2017-02-10 11:53:14 -06:00
if ( m_categoryColors . size ( ) > 0 )
{
m_categoryMapper - > setCycleColors ( m_categoryColors ) ;
}
else
{
m_categoryMapper - > setInterpolateColors ( legendColors ) ;
}
2016-08-02 03:25:55 -05:00
m_currentScalarMapper = m_categoryMapper . p ( ) ;
break ;
2012-05-18 02:45:23 -05:00
default :
break ;
}
2012-10-02 03:17:52 -05:00
2016-08-02 03:25:55 -05:00
if ( m_currentScalarMapper ! = m_categoryMapper . p ( ) )
{
m_scalarMapperLegend - > setScalarMapper ( m_currentScalarMapper . p ( ) ) ;
}
2013-09-25 18:05:09 -05:00
double decadesInRange = 0 ;
2013-04-30 07:48:53 -05:00
2013-09-25 18:05:09 -05:00
if ( m_mappingMode = = LOG10_CONTINUOUS | | m_mappingMode = = LOG10_DISCRETE )
{
2013-09-26 03:44:20 -05:00
// For log mapping, use the min value as reference for num valid digits
2013-09-27 07:43:11 -05:00
decadesInRange = cvf : : Math : : abs ( adjustedMin ) < cvf : : Math : : abs ( adjustedMax ) ? cvf : : Math : : abs ( adjustedMin ) : cvf : : Math : : abs ( adjustedMax ) ;
2013-09-25 18:05:09 -05:00
decadesInRange = log10 ( decadesInRange ) ;
}
else
{
2013-09-26 03:44:20 -05:00
// For linear mapping, use the max value as reference for num valid digits
2013-09-27 07:43:11 -05:00
double absRange = CVF_MAX ( cvf : : Math : : abs ( adjustedMax ) , cvf : : Math : : abs ( adjustedMin ) ) ;
2013-09-25 18:05:09 -05:00
decadesInRange = log10 ( absRange ) ;
}
decadesInRange = cvf : : Math : : ceil ( decadesInRange ) ;
// Using Fixed format
2013-04-30 07:48:53 -05:00
NumberFormatType nft = m_tickNumberFormat ( ) ;
2018-03-08 04:20:27 -06:00
m_scalarMapperLegend - > setTickFormat ( ( caf : : OverlayScalarMapperLegend : : NumberFormat ) nft ) ;
2012-05-18 02:45:23 -05:00
2013-09-25 18:05:09 -05:00
// Set the fixed number of digits after the decimal point to the number needed to show all the significant digits.
2013-09-26 03:44:20 -05:00
int numDecimalDigits = m_precision ( ) ;
if ( nft ! = SCIENTIFIC )
{
2013-09-27 07:43:11 -05:00
numDecimalDigits - = static_cast < int > ( decadesInRange ) ;
2013-09-26 03:44:20 -05:00
}
2016-08-01 15:27:03 -05:00
m_scalarMapperLegend - > setTickPrecision ( cvf : : Math : : clamp ( numDecimalDigits , 0 , 20 ) ) ;
2013-09-25 18:05:09 -05:00
2018-03-08 09:15:45 -06:00
RiaApplication * app = RiaApplication : : instance ( ) ;
RiaPreferences * preferences = app - > preferences ( ) ;
m_scalarMapperLegend - > enableBackground ( preferences - > showLegendBackground ( ) ) ;
m_categoryLegend - > enableBackground ( preferences - > showLegendBackground ( ) ) ;
2012-05-18 02:45:23 -05:00
if ( m_globalAutoMax ! = cvf : : UNDEFINED_DOUBLE )
{
2015-08-05 06:27:36 -05:00
m_userDefinedMaxValue . uiCapability ( ) - > setUiName ( QString ( " Max " ) + " ( " + QString : : number ( m_globalAutoMax , ' g ' , m_precision ) + " ) " ) ;
2012-05-18 02:45:23 -05:00
}
else
{
2015-08-05 06:27:36 -05:00
m_userDefinedMaxValue . uiCapability ( ) - > setUiName ( QString ( ) ) ;
2012-05-18 02:45:23 -05:00
}
if ( m_globalAutoMin ! = cvf : : UNDEFINED_DOUBLE )
{
2015-08-05 06:27:36 -05:00
m_userDefinedMinValue . uiCapability ( ) - > setUiName ( QString ( " Min " ) + " ( " + QString : : number ( m_globalAutoMin , ' g ' , m_precision ) + " ) " ) ;
2012-05-18 02:45:23 -05:00
}
else
{
2015-08-05 06:27:36 -05:00
m_userDefinedMinValue . uiCapability ( ) - > setUiName ( QString ( ) ) ;
2012-05-18 02:45:23 -05:00
}
}
2017-01-03 07:58:34 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : disableAllTimeStepsRange ( bool doDisable )
2017-01-03 07:58:34 -06:00
{
// If we enable AllTimesteps, and we have used current timestep, then "restore" the default
if ( m_isAllTimeStepsRangeDisabled & & ! doDisable & & m_rangeMode = = AUTOMATIC_CURRENT_TIMESTEP ) m_rangeMode = AUTOMATIC_ALLTIMESTEPS ;
m_isAllTimeStepsRangeDisabled = doDisable ;
if ( doDisable & & m_rangeMode = = AUTOMATIC_ALLTIMESTEPS ) m_rangeMode = AUTOMATIC_CURRENT_TIMESTEP ;
}
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setAutomaticRanges ( double globalMin , double globalMax , double localMin , double localMax )
2012-05-18 02:45:23 -05:00
{
2013-09-30 06:29:29 -05:00
double candidateGlobalAutoMin = roundToNumSignificantDigits ( globalMin , m_precision ) ;
double candidateGlobalAutoMax = roundToNumSignificantDigits ( globalMax , m_precision ) ;
2012-05-18 02:45:23 -05:00
2013-09-30 06:29:29 -05:00
double candidateLocalAutoMin = roundToNumSignificantDigits ( localMin , m_precision ) ;
double candidateLocalAutoMax = roundToNumSignificantDigits ( localMax , m_precision ) ;
2012-05-18 02:45:23 -05:00
2018-04-13 06:44:18 -05:00
m_globalAutoMin = candidateGlobalAutoMin ;
m_globalAutoMax = candidateGlobalAutoMax ;
2013-09-30 06:29:29 -05:00
2018-04-13 06:44:18 -05:00
m_localAutoMin = candidateLocalAutoMin ;
m_localAutoMax = candidateLocalAutoMax ;
2013-09-30 06:29:29 -05:00
2018-04-13 06:44:18 -05:00
updateLegend ( ) ;
2012-05-18 02:45:23 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : initAfterRead ( )
2012-05-18 02:45:23 -05:00
{
updateFieldVisibility ( ) ;
}
2018-04-18 03:10:39 -05:00
caf : : PdmFieldHandle * RimRegularLegendConfig : : objectToggleField ( )
2018-04-06 08:30:51 -05:00
{
2018-04-17 08:59:50 -05:00
return & m_showLegend ;
2018-04-06 08:30:51 -05:00
}
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : updateFieldVisibility ( )
2012-05-18 02:45:23 -05:00
{
2016-08-02 03:25:55 -05:00
bool showRangeItems = m_mappingMode = = CATEGORY_INTEGER ? false : true ;
m_numLevels . uiCapability ( ) - > setUiHidden ( ! showRangeItems ) ;
m_precision . uiCapability ( ) - > setUiHidden ( ! showRangeItems ) ;
m_tickNumberFormat . uiCapability ( ) - > setUiHidden ( ! showRangeItems ) ;
m_rangeMode . uiCapability ( ) - > setUiHidden ( ! showRangeItems ) ;
if ( showRangeItems & & m_rangeMode = = USER_DEFINED )
2012-05-18 02:45:23 -05:00
{
2015-08-05 06:27:36 -05:00
m_userDefinedMaxValue . uiCapability ( ) - > setUiHidden ( false ) ;
m_userDefinedMinValue . uiCapability ( ) - > setUiHidden ( false ) ;
2012-05-18 02:45:23 -05:00
}
else
{
2015-08-05 06:27:36 -05:00
m_userDefinedMaxValue . uiCapability ( ) - > setUiHidden ( true ) ;
m_userDefinedMinValue . uiCapability ( ) - > setUiHidden ( true ) ;
2012-05-18 02:45:23 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-05-11 01:01:10 -05:00
void RimRegularLegendConfig : : setColorRange ( ColorRangesType colorMode )
2012-05-18 02:45:23 -05:00
{
m_colorRangeMode = colorMode ;
updateLegend ( ) ;
}
2016-09-06 07:03:02 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setMappingMode ( MappingType mappingType )
2016-09-06 07:03:02 -05:00
{
m_mappingMode = mappingType ;
updateLegend ( ) ;
}
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : recreateLegend ( )
2012-05-18 02:45:23 -05:00
{
// Due to possible visualization bug, we need to recreate the legend if the last viewer
// has been removed, (and thus the opengl resources has been deleted) The text in
// the legend disappeared because of this, so workaround: recreate the legend when needed:
2013-04-19 01:02:36 -05:00
cvf : : Font * standardFont = RiaApplication : : instance ( ) - > standardFont ( ) ;
2018-03-08 04:20:27 -06:00
m_scalarMapperLegend = new caf : : OverlayScalarMapperLegend ( standardFont ) ;
2016-08-02 03:25:55 -05:00
m_categoryLegend = new caf : : CategoryLegend ( standardFont , m_categoryMapper . p ( ) ) ;
2012-05-18 02:45:23 -05:00
updateLegend ( ) ;
}
//--------------------------------------------------------------------------------------------------
2013-09-25 18:05:09 -05:00
/// Rounding the double value to given number of significant digits
2012-05-18 02:45:23 -05:00
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
double RimRegularLegendConfig : : roundToNumSignificantDigits ( double domainValue , double numSignificantDigits )
2012-05-18 02:45:23 -05:00
{
2013-02-26 05:45:41 -06:00
double absDomainValue = cvf : : Math : : abs ( domainValue ) ;
if ( absDomainValue = = 0.0 )
2012-05-18 02:45:23 -05:00
{
return 0.0 ;
}
2013-02-26 05:45:41 -06:00
double logDecValue = log10 ( absDomainValue ) ;
2012-05-18 02:45:23 -05:00
logDecValue = cvf : : Math : : ceil ( logDecValue ) ;
2013-09-25 18:05:09 -05:00
double factor = pow ( 10.0 , numSignificantDigits - logDecValue ) ;
2012-05-18 02:45:23 -05:00
double tmp = domainValue * factor ;
double integerPart ;
2013-09-25 18:05:09 -05:00
double fraction = modf ( tmp , & integerPart ) ;
2013-09-27 07:43:11 -05:00
if ( cvf : : Math : : abs ( fraction ) > = 0.5 ) ( integerPart > = 0 ) ? integerPart + + : integerPart - - ;
2012-05-18 02:45:23 -05:00
double newDomainValue = integerPart / factor ;
return newDomainValue ;
}
2013-06-03 06:08:11 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setClosestToZeroValues ( double globalPosClosestToZero , double globalNegClosestToZero , double localPosClosestToZero , double localNegClosestToZero )
2013-06-03 06:08:11 -05:00
{
2013-09-30 06:29:29 -05:00
bool needsUpdate = false ;
const double epsilon = std : : numeric_limits < double > : : epsilon ( ) ;
2013-06-03 06:08:11 -05:00
2013-09-30 06:29:29 -05:00
if ( cvf : : Math : : abs ( globalPosClosestToZero - m_globalAutoPosClosestToZero ) > epsilon )
{
needsUpdate = true ;
}
if ( cvf : : Math : : abs ( globalNegClosestToZero - m_globalAutoNegClosestToZero ) > epsilon )
{
needsUpdate = true ;
}
if ( cvf : : Math : : abs ( localPosClosestToZero - m_localAutoPosClosestToZero ) > epsilon )
{
needsUpdate = true ;
}
if ( cvf : : Math : : abs ( localNegClosestToZero - m_localAutoNegClosestToZero ) > epsilon )
{
needsUpdate = true ;
}
2013-06-03 06:08:11 -05:00
2013-09-30 06:29:29 -05:00
if ( needsUpdate )
{
m_globalAutoPosClosestToZero = globalPosClosestToZero ;
m_globalAutoNegClosestToZero = globalNegClosestToZero ;
m_localAutoPosClosestToZero = localPosClosestToZero ;
m_localAutoNegClosestToZero = localNegClosestToZero ;
if ( m_globalAutoPosClosestToZero = = HUGE_VAL ) m_globalAutoPosClosestToZero = 0 ;
if ( m_globalAutoNegClosestToZero = = - HUGE_VAL ) m_globalAutoNegClosestToZero = 0 ;
if ( m_localAutoPosClosestToZero = = HUGE_VAL ) m_localAutoPosClosestToZero = 0 ;
if ( m_localAutoNegClosestToZero = = - HUGE_VAL ) m_localAutoNegClosestToZero = 0 ;
updateLegend ( ) ;
}
2013-06-03 06:08:11 -05:00
}
2016-08-02 03:25:55 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setIntegerCategories ( const std : : vector < int > & categories )
2016-08-02 03:25:55 -05:00
{
2016-09-07 03:28:57 -05:00
m_categories = categories ;
m_categoryNames . clear ( ) ;
2017-02-10 11:53:14 -06:00
m_categoryColors . clear ( ) ;
2016-08-02 03:25:55 -05:00
2016-09-07 03:28:57 -05:00
updateLegend ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-05-03 02:53:25 -05:00
void RimRegularLegendConfig : : setNamedCategories ( const std : : vector < QString > & categoryNames )
2016-09-07 03:28:57 -05:00
{
2018-05-03 02:53:25 -05:00
setNamedCategories ( categoryNames , false ) ;
}
2016-09-06 08:35:17 -05:00
2018-05-03 02:53:25 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig : : setNamedCategoriesInverse ( const std : : vector < QString > & categoryNames )
{
setNamedCategories ( categoryNames , true ) ;
2016-08-02 03:25:55 -05:00
}
2017-01-03 02:27:25 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setCategoryItems ( const std : : vector < std : : tuple < QString , int , cvf : : Color3ub > > & categories )
2017-01-03 02:27:25 -06:00
{
2017-02-15 08:21:13 -06:00
m_categories . clear ( ) ;
m_categoryNames . clear ( ) ;
m_categoryColors . clear ( ) ;
m_categoryColors . reserve ( categories . size ( ) ) ;
2017-01-03 02:27:25 -06:00
2017-02-15 08:21:13 -06:00
for ( auto item : categories )
2017-01-03 02:27:25 -06:00
{
2017-02-15 08:21:13 -06:00
m_categoryNames . push_back ( cvfqt : : Utils : : toString ( std : : get < 0 > ( item ) ) ) ;
m_categories . push_back ( std : : get < 1 > ( item ) ) ;
m_categoryColors . add ( std : : get < 2 > ( item ) ) ;
2017-01-03 02:27:25 -06:00
}
updateLegend ( ) ;
}
2017-02-14 02:18:00 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
QString RimRegularLegendConfig : : categoryNameFromCategoryValue ( double categoryResultValue ) const
2017-02-14 02:18:00 -06:00
{
2017-03-21 02:49:45 -05:00
if ( categoryResultValue = = HUGE_VAL ) return " Undefined " ;
2017-02-14 02:18:00 -06:00
if ( m_categoryNames . size ( ) > 0 )
{
for ( size_t categoryIndex = 0 ; categoryIndex < m_categories . size ( ) ; categoryIndex + + )
{
2017-03-21 02:49:45 -05:00
if ( categoryResultValue = = m_categories [ categoryIndex ] )
2017-02-14 02:18:00 -06:00
{
return cvfqt : : Utils : : toQString ( m_categoryNames [ categoryIndex ] ) ;
}
}
}
2017-03-21 02:49:45 -05:00
return QString ( " %1 " ) . arg ( categoryResultValue ) ;
2017-02-14 02:18:00 -06:00
}
2018-05-03 02:53:25 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RimRegularLegendConfig : : categoryValueFromCategoryName ( const QString & categoryName ) const
{
2018-05-08 08:57:34 -05:00
for ( int i = 0 ; i < ( int ) m_categoryNames . size ( ) ; i + + )
2018-05-03 02:53:25 -05:00
{
if ( cvfqt : : Utils : : toQString ( m_categoryNames [ i ] ) . compare ( categoryName , Qt : : CaseInsensitive ) = = 0 )
{
return i ;
}
}
return HUGE_VAL ;
}
2016-08-02 03:25:55 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setTitle ( const QString & title )
2016-08-02 03:25:55 -05:00
{
2018-02-01 10:45:22 -06:00
auto cvfTitle = cvfqt : : Utils : : toString ( title ) ;
m_scalarMapperLegend - > setTitle ( cvfTitle ) ;
m_categoryLegend - > setTitle ( cvfTitle ) ;
2016-08-02 03:25:55 -05:00
}
2016-08-01 15:27:03 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
bool RimRegularLegendConfig : : showLegend ( ) const
2018-04-17 08:59:50 -05:00
{
return m_showLegend ;
}
2018-10-23 09:32:40 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig : : setShowLegend ( bool show )
{
m_showLegend = show ;
}
2018-04-18 03:32:51 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf : : TitledOverlayFrame * RimRegularLegendConfig : : titledOverlayFrame ( )
{
if ( m_currentScalarMapper = = m_categoryMapper )
{
return m_categoryLegend . p ( ) ;
}
else
{
return m_scalarMapperLegend . p ( ) ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf : : TitledOverlayFrame * RimRegularLegendConfig : : titledOverlayFrame ( ) const
{
if ( m_currentScalarMapper = = m_categoryMapper )
{
return m_categoryLegend . p ( ) ;
}
else
{
return m_scalarMapperLegend . p ( ) ;
}
}
2016-12-09 13:36:31 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : setUiValuesFromLegendConfig ( const RimRegularLegendConfig * otherLegendConfig )
2016-12-09 13:36:31 -06:00
{
2016-12-09 14:16:43 -06:00
QString serializedObjectString = otherLegendConfig - > writeObjectToXmlString ( ) ;
this - > readObjectFromXmlString ( serializedObjectString , caf : : PdmDefaultObjectFactory : : instance ( ) ) ;
2018-02-01 10:45:22 -06:00
this - > updateLegend ( ) ;
2016-12-09 13:36:31 -06:00
}
2017-02-10 01:37:48 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
cvf : : Color3ubArray RimRegularLegendConfig : : colorArrayFromColorType ( ColorRangesType colorType )
2017-02-10 01:37:48 -06:00
{
switch ( colorType )
{
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : NORMAL :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : normalPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : OPPOSITE_NORMAL :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : normalPaletteOppositeOrderingColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : WHITE_PINK :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : whitePinkPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : PINK_WHITE :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : pinkWhitePaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : WHITE_BLACK :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : whiteBlackPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : BLACK_WHITE :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : blackWhitePaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : BLUE_WHITE_RED :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : blueWhiteRedPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : RED_WHITE_BLUE :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : redWhiteBluePaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : CATEGORY :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : categoryPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : ANGULAR :
2017-02-10 01:37:48 -06:00
return RiaColorTables : : angularPaletteColors ( ) . color3ubArray ( ) ;
break ;
2018-04-18 03:10:39 -05:00
case RimRegularLegendConfig : : STIMPLAN :
2017-02-20 05:26:36 -06:00
return RiaColorTables : : stimPlanPaletteColors ( ) . color3ubArray ( ) ;
break ;
2017-02-10 01:37:48 -06:00
default :
2018-05-11 02:24:42 -05:00
if ( ColorManager : : isEnsembleColorRange ( colorType ) ) return ColorManager : : EnsembleColorRanges ( ) . at ( colorType ) ;
2017-02-10 01:37:48 -06:00
break ;
}
return RiaColorTables : : normalPaletteColors ( ) . color3ubArray ( ) ;
}
2013-09-26 03:44:20 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
void RimRegularLegendConfig : : defineUiOrdering ( QString uiConfigName , caf : : PdmUiOrdering & uiOrdering )
2013-09-26 03:44:20 -05:00
{
2014-04-14 01:04:09 -05:00
{
caf : : PdmUiOrdering * formatGr = uiOrdering . addNewGroup ( " Format " ) ;
formatGr - > add ( & m_numLevels ) ;
formatGr - > add ( & m_precision ) ;
formatGr - > add ( & m_tickNumberFormat ) ;
formatGr - > add ( & m_colorRangeMode ) ;
caf : : PdmUiOrdering * mappingGr = uiOrdering . addNewGroup ( " Mapping " ) ;
mappingGr - > add ( & m_mappingMode ) ;
mappingGr - > add ( & m_rangeMode ) ;
mappingGr - > add ( & m_userDefinedMaxValue ) ;
mappingGr - > add ( & m_userDefinedMinValue ) ;
}
2016-09-06 07:03:02 -05:00
updateFieldVisibility ( ) ;
2014-04-14 01:04:09 -05:00
}
2016-08-02 03:25:55 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-18 03:10:39 -05:00
QList < caf : : PdmOptionItemInfo > RimRegularLegendConfig : : calculateValueOptions ( const caf : : PdmFieldHandle * fieldNeedingOptions , bool * useOptionsOnly )
2016-08-02 03:25:55 -05:00
{
2017-02-20 05:26:36 -06:00
bool hasStimPlanParent = false ;
2018-04-20 04:28:28 -05:00
bool hasEnsembleCurveSetParent = false ;
2017-08-22 04:38:31 -05:00
2017-02-20 05:26:36 -06:00
RimStimPlanColors * stimPlanColors = nullptr ;
this - > firstAncestorOrThisOfType ( stimPlanColors ) ;
if ( stimPlanColors ) hasStimPlanParent = true ;
2016-08-02 03:25:55 -05:00
2018-04-20 04:28:28 -05:00
RimEnsembleCurveSet * ensembleCurveSet = nullptr ;
this - > firstAncestorOrThisOfType ( ensembleCurveSet ) ;
if ( ensembleCurveSet ) hasEnsembleCurveSetParent = true ;
2016-08-02 03:25:55 -05:00
bool isCategoryResult = false ;
{
2016-09-06 03:27:30 -05:00
RimEclipseCellColors * eclCellColors = nullptr ;
2016-09-21 06:59:41 -05:00
this - > firstAncestorOrThisOfType ( eclCellColors ) ;
2016-10-18 00:31:02 -05:00
RimGeoMechResultDefinition * gmCellColors = nullptr ;
2016-09-21 06:59:41 -05:00
this - > firstAncestorOrThisOfType ( gmCellColors ) ;
2016-09-06 05:17:02 -05:00
RimCellEdgeColors * eclCellEdgColors = nullptr ;
2016-09-21 06:59:41 -05:00
this - > firstAncestorOrThisOfType ( eclCellEdgColors ) ;
2016-09-06 03:27:30 -05:00
2018-05-03 02:53:25 -05:00
if ( ( eclCellColors & & eclCellColors - > hasCategoryResult ( ) )
| | ( gmCellColors & & gmCellColors - > hasCategoryResult ( ) )
| | ( eclCellEdgColors & & eclCellEdgColors - > hasCategoryResult ( ) )
2018-05-31 03:23:51 -05:00
| | ( ensembleCurveSet & & ensembleCurveSet - > currentEnsembleParameterType ( ) = = EnsembleParameter : : TYPE_TEXT ) )
2016-09-06 03:27:30 -05:00
{
isCategoryResult = true ;
}
2016-08-02 03:25:55 -05:00
}
2017-01-05 00:57:37 -06:00
QList < caf : : PdmOptionItemInfo > options ;
2016-10-13 05:13:32 -05:00
2016-08-02 03:25:55 -05:00
if ( fieldNeedingOptions = = & m_mappingMode )
{
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of this type
2016-10-13 05:13:32 -05:00
std : : vector < MappingType > mappingTypes ;
mappingTypes . push_back ( LINEAR_DISCRETE ) ;
mappingTypes . push_back ( LINEAR_CONTINUOUS ) ;
mappingTypes . push_back ( LOG10_CONTINUOUS ) ;
mappingTypes . push_back ( LOG10_DISCRETE ) ;
2016-08-02 03:25:55 -05:00
if ( isCategoryResult )
{
2016-10-13 05:13:32 -05:00
mappingTypes . push_back ( CATEGORY_INTEGER ) ;
}
for ( MappingType mapType : mappingTypes )
{
2017-01-05 00:57:37 -06:00
options . push_back ( caf : : PdmOptionItemInfo ( MappingEnum : : uiText ( mapType ) , mapType ) ) ;
2016-08-02 03:25:55 -05:00
}
}
else if ( fieldNeedingOptions = = & m_colorRangeMode )
{
// This is an app enum field, see cafInternalPdmFieldTypeSpecializations.h for the default specialization of this type
2016-10-13 05:13:32 -05:00
std : : vector < ColorRangesType > rangeTypes ;
2018-05-04 06:06:48 -05:00
if ( ! hasEnsembleCurveSetParent )
{
rangeTypes . push_back ( NORMAL ) ;
rangeTypes . push_back ( OPPOSITE_NORMAL ) ;
rangeTypes . push_back ( WHITE_PINK ) ;
rangeTypes . push_back ( PINK_WHITE ) ;
rangeTypes . push_back ( BLUE_WHITE_RED ) ;
rangeTypes . push_back ( RED_WHITE_BLUE ) ;
rangeTypes . push_back ( WHITE_BLACK ) ;
rangeTypes . push_back ( BLACK_WHITE ) ;
rangeTypes . push_back ( ANGULAR ) ;
}
else
{
2018-05-11 02:24:42 -05:00
for ( const auto & col : ColorManager : : EnsembleColorRanges ( ) )
2018-05-04 06:06:48 -05:00
{
rangeTypes . push_back ( col . first ) ;
}
}
2017-02-20 05:26:36 -06:00
if ( hasStimPlanParent ) rangeTypes . push_back ( STIMPLAN ) ;
2016-08-02 03:25:55 -05:00
if ( isCategoryResult )
{
2016-10-13 05:13:32 -05:00
rangeTypes . push_back ( CATEGORY ) ;
2016-08-02 03:25:55 -05:00
}
2016-10-13 05:13:32 -05:00
for ( ColorRangesType colType : rangeTypes )
{
2017-01-05 00:57:37 -06:00
options . push_back ( caf : : PdmOptionItemInfo ( ColorRangeEnum : : uiText ( colType ) , colType ) ) ;
2016-10-13 05:13:32 -05:00
}
2016-08-02 03:25:55 -05:00
}
2017-01-03 07:58:34 -06:00
else if ( fieldNeedingOptions = = & m_rangeMode )
{
2017-02-20 05:26:36 -06:00
if ( ! m_isAllTimeStepsRangeDisabled )
{
2018-04-20 04:28:28 -05:00
QString uiText ;
if ( ! hasEnsembleCurveSetParent ) uiText = RangeModeEnum : : uiText ( RimRegularLegendConfig : : AUTOMATIC_ALLTIMESTEPS ) ;
else uiText = " Auto Range " ;
options . push_back ( caf : : PdmOptionItemInfo ( uiText , RimRegularLegendConfig : : AUTOMATIC_ALLTIMESTEPS ) ) ;
2017-01-03 07:58:34 -06:00
}
2018-04-20 04:28:28 -05:00
if ( ! hasStimPlanParent & & ! hasEnsembleCurveSetParent )
2017-02-20 05:26:36 -06:00
{
2018-04-18 03:10:39 -05:00
options . push_back ( caf : : PdmOptionItemInfo ( RangeModeEnum : : uiText ( RimRegularLegendConfig : : AUTOMATIC_CURRENT_TIMESTEP ) , RimRegularLegendConfig : : AUTOMATIC_CURRENT_TIMESTEP ) ) ;
2017-02-20 05:26:36 -06:00
}
2018-04-18 03:10:39 -05:00
options . push_back ( caf : : PdmOptionItemInfo ( RangeModeEnum : : uiText ( RimRegularLegendConfig : : USER_DEFINED ) , RimRegularLegendConfig : : USER_DEFINED ) ) ;
2017-01-03 07:58:34 -06:00
}
2016-10-13 05:13:32 -05:00
2017-01-05 00:57:37 -06:00
return options ;
2016-08-02 03:25:55 -05:00
}