Show ternary range on overlay item

This commit is contained in:
Magne Sjaastad 2014-05-06 23:29:41 +02:00
parent cc4e9eb505
commit bed902d005
3 changed files with 58 additions and 3 deletions

View File

@ -121,9 +121,15 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
cvf::TextDrawer textDrawer(m_font.p());
textDrawer.setTextColor(m_textColor);
textDrawer.addText("SWAT", cvf::Vec2f(0.0, 0.0));
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - 28), 0.0));
textDrawer.addText("SWAT", cvf::Vec2f(0.0, 10.0));
textDrawer.addText(m_swatRange, cvf::Vec2f(0.0, 0.0));
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - 40), 10.0));
textDrawer.addText(m_soilRange, cvf::Vec2f(static_cast<float>(size.x() - 40), 0.0));
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (size.x() / 2) - 17 ), static_cast<float>(size.y() - 10)));
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (size.x() / 2) - 17 ), static_cast<float>(size.y() - 20)));
textDrawer.renderSoftware(oglContext, camera);
renderAxisImmediateMode(oglContext);
@ -197,4 +203,14 @@ void RivTernarySaturationOverlayItem::renderAxisImmediateMode(cvf::OpenGLContext
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setRangeText(const cvf::String& soilRange, const cvf::String& sgasRange, const cvf::String& swatRange)
{
m_soilRange = soilRange;
m_sgasRange = sgasRange;
m_swatRange = swatRange;
}

View File

@ -40,6 +40,8 @@ public:
RivTernarySaturationOverlayItem(cvf::Font* font);
~RivTernarySaturationOverlayItem();
void setRangeText(const cvf::String& soilRange, const cvf::String& sgasRange, const cvf::String& swatRange);
virtual cvf::Vec2ui sizeHint();
virtual void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
@ -56,6 +58,10 @@ private:
private:
cvf::Color3f m_textColor; // Text color
cvf::ref<cvf::Font> m_font;
cvf::String m_soilRange;
cvf::String m_sgasRange;
cvf::String m_swatRange;
cvf::Vec2ui m_size; // Pixel size of draw area
};

View File

@ -27,6 +27,7 @@
#include "RivTernarySaturationOverlayItem.h"
#include <cmath>
#include "cvfqtUtils.h"
CAF_PDM_SOURCE_INIT(RimTernaryLegendConfig, "RimTernaryLegendConfig");
@ -154,7 +155,39 @@ void RimTernaryLegendConfig::fieldChangedByUi(const caf::PdmFieldHandle* changed
//--------------------------------------------------------------------------------------------------
void RimTernaryLegendConfig::updateLegend()
{
// TODO: Update text on ternary legend
double soilLower = 0.0;
double soilUpper = 1.0;
double sgasLower = 0.0;
double sgasUpper = 1.0;
double swatLower = 0.0;
double swatUpper = 1.0;
ternaryRanges(soilLower, soilUpper, sgasLower, sgasUpper, swatLower, swatUpper);
cvf::String soilRange;
cvf::String sgasRange;
cvf::String swatRange;
int numberPrecision = 1;
{
QString tmpString = QString::number(soilLower, 'g', numberPrecision) + " - " + QString::number(soilUpper, 'g', numberPrecision);
soilRange = cvfqt::Utils::toString(tmpString);
}
{
QString tmpString = QString::number(sgasLower, 'g', numberPrecision) + " - " + QString::number(sgasUpper, 'g', numberPrecision);
sgasRange = cvfqt::Utils::toString(tmpString);
}
{
QString tmpString = QString::number(swatLower, 'g', numberPrecision) + " - " + QString::number(swatUpper, 'g', numberPrecision);
swatRange = cvfqt::Utils::toString(tmpString);
}
if (!m_legend.isNull())
{
m_legend->setRangeText(soilRange, sgasRange, swatRange);
}
}
//--------------------------------------------------------------------------------------------------