ResInsight/ApplicationCode/ProjectDataModel/RimGeoMechPropertyFilter.cpp
Jacob Støren 276addc713 (#405) Convert POR, SE, and ST to Bar. Fixed issues regarding property filters.
Result fields without component had an extra space in the option value string
that made the search for the option in the option list fail.
2015-09-26 09:38:29 +02:00

211 lines
7.7 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RimGeoMechPropertyFilter.h"
#include "RimGeoMechPropertyFilterCollection.h"
#include "RimGeoMechResultDefinition.h"
#include "cvfMath.h"
#include "cafPdmUiDoubleSliderEditor.h"
#include "cvfAssert.h"
#include "RigFemPartResultsCollection.h"
#include "RigGeoMechCaseData.h"
#include "RimGeoMechView.h"
#include "RiuMainWindow.h"
CAF_PDM_SOURCE_INIT(RimGeoMechPropertyFilter, "GeoMechPropertyFilter");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechPropertyFilter::RimGeoMechPropertyFilter()
: m_parentContainer(NULL)
{
CAF_PDM_InitObject("Property Filter", ":/CellFilter_Values.png", "", "");
CAF_PDM_InitFieldNoDefault(&resultDefinition, "ResultDefinition", "Result definition", "", "", "");
resultDefinition = new RimGeoMechResultDefinition();
// Set to hidden to avoid this item to been displayed as a child item
// Fields in this object are displayed using defineUiOrdering()
resultDefinition.uiCapability()->setUiHidden(true);
resultDefinition.uiCapability()->setUiChildrenHidden(true);
CAF_PDM_InitField(&lowerBound, "LowerBound", 0.0, "Min", "", "", "");
lowerBound.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&upperBound, "UpperBound", 0.0, "Max", "", "", "");
upperBound.uiCapability()->setUiEditorTypeName(caf::PdmUiDoubleSliderEditor::uiEditorTypeName());
updateIconState();
m_minimumResultValue = cvf::UNDEFINED_DOUBLE;
m_maximumResultValue = cvf::UNDEFINED_DOUBLE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechPropertyFilter::~RimGeoMechPropertyFilter()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if ( &lowerBound == changedField
|| &upperBound == changedField
|| &isActive == changedField
|| &filterMode == changedField)
{
this->updateIconState();
this->updateFilterName();
parentContainer()->updateDisplayModelNotifyManagedViews();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::setParentContainer(RimGeoMechPropertyFilterCollection* parentContainer)
{
m_parentContainer = parentContainer;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGeoMechPropertyFilterCollection* RimGeoMechPropertyFilter::parentContainer()
{
return m_parentContainer;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::setToDefaultValues()
{
CVF_ASSERT(m_parentContainer);
computeResultValueRange();
lowerBound = m_minimumResultValue;
upperBound = m_maximumResultValue;
this->updateFilterName();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&name);
caf::PdmUiGroup* group1 = uiOrdering.addNewGroup("Result");
group1->add(&(resultDefinition->m_resultPositionTypeUiField));
group1->add(&(resultDefinition->m_resultVariableUiField));
uiOrdering.add(&isActive);
uiOrdering.add(&filterMode);
uiOrdering.add(&lowerBound);
uiOrdering.add(&upperBound);
uiOrdering.add(&filterMode);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
if (m_minimumResultValue == cvf::UNDEFINED_DOUBLE || m_maximumResultValue == cvf::UNDEFINED_DOUBLE)
{
return;
}
if (field == &lowerBound || field == &upperBound)
{
caf::PdmUiDoubleSliderEditorAttribute* myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>(attribute);
if (!myAttr)
{
return;
}
myAttr->m_minimum = m_minimumResultValue;
myAttr->m_maximum = m_maximumResultValue;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::computeResultValueRange()
{
CVF_ASSERT(m_parentContainer);
double min = 0.0;
double max = 0.0;
RigFemResultAddress resultAddress = resultDefinition->resultAddress();
if (resultAddress.isValid() && resultDefinition->ownerCaseData())
{
resultDefinition->ownerCaseData()->femPartResults()->minMaxScalarValues(resultAddress, &min, &max);
}
m_maximumResultValue = max;
m_minimumResultValue = min;
lowerBound.uiCapability()->setUiName(QString("Min (%1)").arg(min));
upperBound.uiCapability()->setUiName(QString("Max (%1)").arg(max));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGeoMechPropertyFilter::updateFilterName()
{
RigFemResultAddress resultAddress = resultDefinition->resultAddress();
QString newFiltername;
QString posName;
switch (resultAddress.resultPosType)
{
case RIG_NODAL: posName = "N"; break;
case RIG_ELEMENT_NODAL: posName = "EN"; break;
case RIG_INTEGRATION_POINT: posName = "IP"; break;
}
QString fieldUiName = resultDefinition->resultFieldUiName();
QString compoUiName = resultDefinition->resultComponentUiName();
newFiltername = posName + ", " + fieldUiName + ", " + compoUiName + " ("
+ QString::number(lowerBound()) + " .. " + QString::number(upperBound) + ")";
this->name = newFiltername;
RiuMainWindow::instance()->forceProjectTreeRepaint();
}