Ternary legend : Added title

This commit is contained in:
Magne Sjaastad 2014-08-01 08:46:46 +02:00
parent 09f7868eb5
commit 8b04e2a2e8
5 changed files with 44 additions and 11 deletions

View File

@ -121,11 +121,25 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
cvf::TextDrawer textDrawer(m_font.p());
textDrawer.setTextColor(m_textColor);
float lineHeightInPixels = 10;
float textPosY = static_cast<float>(size.y() - 10);
for (size_t it = 0; it < m_titleStrings.size(); it++)
{
cvf::Vec2f pos(5, textPosY);
textDrawer.addText(m_titleStrings[it], pos);
textPosY -= lineHeightInPixels;
}
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (size.x() / 2) - 17 ), textPosY));
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (size.x() / 2) - 17 ), textPosY - lineHeightInPixels));
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() - 25), 10.0));
float soilRangePos = static_cast<float>(size.x() - 40);
if (m_soilRange.size() < 6)
{
@ -133,12 +147,9 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
}
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, 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);
renderAxisImmediateMode(textPosY - lineHeightInPixels, oglContext);
CVF_CHECK_OGL(oglContext);
}
@ -148,7 +159,7 @@ void RivTernarySaturationOverlayItem::render(cvf::OpenGLContext* oglContext, con
//--------------------------------------------------------------------------------------------------
/// Draw the axis using immediate mode OpenGL
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::renderAxisImmediateMode(cvf::OpenGLContext* oglContext)
void RivTernarySaturationOverlayItem::renderAxisImmediateMode(float upperBoundY, cvf::OpenGLContext* oglContext)
{
#ifdef CVF_OPENGL_ES
CVF_UNUSED(layout);
@ -166,7 +177,7 @@ void RivTernarySaturationOverlayItem::renderAxisImmediateMode(cvf::OpenGLContext
cvf::Color3ub colC(cvf::Color3::RED);
float lowerBoundY = 20;
float upperBoundY = static_cast<float>(m_size.y() - 20);
//float upperBoundY = static_cast<float>(m_size.y() - 20);
cvf::Vec3f a(0, lowerBoundY, 0);
cvf::Vec3f b(static_cast<float>(m_size.x()), lowerBoundY, 0);
@ -219,4 +230,20 @@ void RivTernarySaturationOverlayItem::setRangeText(const cvf::String& soilRange,
m_swatRange = swatRange;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::setTitle(const cvf::String& title)
{
// Title
if (title.isEmpty())
{
m_titleStrings.clear();
}
else
{
m_titleStrings = title.split("\n");
}
}

View File

@ -48,12 +48,13 @@ public:
virtual void renderSoftware(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size);
void setSize(const cvf::Vec2ui& size);
void setAxisLabelsColor(const cvf::Color3f& color);
void setTitle(const cvf::String& title);
private:
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size, bool software);
void renderAxisImmediateMode(cvf::OpenGLContext* oglContext);
void renderAxisImmediateMode(float upperY, cvf::OpenGLContext* oglContext);
private:
cvf::Color3f m_textColor; // Text color
@ -64,5 +65,7 @@ private:
cvf::String m_swatRange;
cvf::Vec2ui m_size; // Pixel size of draw area
std::vector<cvf::String> m_titleStrings;
};

View File

@ -40,6 +40,7 @@
#include "RiuViewer.h"
#include "RivReservoirPipesPartMgr.h"
#include "RivWellPathCollectionPartMgr.h"
#include "RivTernarySaturationOverlayItem.h"
#include "cafCadNavigation.h"
#include "cafCeetronPlusNavigation.h"
@ -1508,6 +1509,7 @@ void RimReservoirView::updateMinMaxValuesAndAddLegendToView(QString legendLabel,
if (resultSlot->ternaryLegendConfig->legend())
{
resultSlot->ternaryLegendConfig->legend()->setTitle(cvfqt::Utils::toString(legendLabel));
m_viewer->addColorLegendToBottomLeftCorner(resultSlot->ternaryLegendConfig->legend());
}
}

View File

@ -298,7 +298,7 @@ void RimTernaryLegendConfig::defineUiOrdering(QString uiConfigName, caf::PdmUiOr
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::OverlayItem* RimTernaryLegendConfig::legend()
RivTernarySaturationOverlayItem* RimTernaryLegendConfig::legend()
{
return m_legend.p();
}

View File

@ -69,7 +69,8 @@ public:
void ternaryRanges(double& soilLower, double& soilUpper, double& sgasLower, double& sgasUpper, double& swatLower, double& swatUpper) const;
void recreateLegend();
cvf::OverlayItem* legend();
RivTernarySaturationOverlayItem* legend();
protected:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);