Refactored after review

This commit is contained in:
Gaute Lindkvist 2018-04-09 11:51:30 +02:00
parent fe56375be6
commit b6fb60115a
18 changed files with 62 additions and 67 deletions

View File

@ -43,7 +43,7 @@
RivTernarySaturationOverlayItem::RivTernarySaturationOverlayItem(cvf::Font* font)
: TitledOverlayFrame(font, 120, 150)
{
this->computeLayoutAndExtents();
this->computeLayoutAndExtents(cvf::Vec2i(0, 0), this->sizeHint());
}
//--------------------------------------------------------------------------------------------------
@ -57,9 +57,9 @@ RivTernarySaturationOverlayItem::~RivTernarySaturationOverlayItem()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::computeLayoutAndExtents()
void RivTernarySaturationOverlayItem::computeLayoutAndExtents(const cvf::Vec2i& position, const cvf::Vec2ui& size)
{
this->setMinimumWidth(this->sizeHint().x());
this->setMinimumWidth(size.x());
}
//--------------------------------------------------------------------------------------------------
@ -91,21 +91,21 @@ void RivTernarySaturationOverlayItem::renderSoftware(cvf::OpenGLContext* oglCont
//--------------------------------------------------------------------------------------------------
void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglContext,
const cvf::Vec2i& position,
const cvf::Vec2ui& sizeHint,
const cvf::Vec2ui& size,
bool software)
{
if (sizeHint.x() <= 0 || sizeHint.y() <= 0)
if (size.x() <= 0 || size.y() <= 0)
{
return;
}
float border = 0.0f;
cvf::Vec2ui sizeMatched = sizeHint;
sizeMatched.x() = this->matchedWidth(); // Match to other legends
cvf::Vec2ui sizeFrameBox = size;
sizeFrameBox.x() = this->matchedWidth(); // Match to other legends
cvf::Camera camera;
camera.setViewport(position.x(), position.y(), sizeMatched.x(), sizeMatched.y());
camera.setViewport(position.x(), position.y(), sizeFrameBox.x(), sizeFrameBox.y());
camera.setProjectionAsPixelExact2D();
camera.setViewMatrix(cvf::Mat4d::IDENTITY);
camera.applyOpenGL();
@ -116,7 +116,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
if ( software )
{
caf::InternalLegendRenderTools::renderBackgroundImmediateMode(oglContext,
cvf::Vec2f(sizeMatched),
cvf::Vec2f(sizeFrameBox),
this->backgroundColor(),
this->backgroundFrameColor());
}
@ -126,7 +126,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
caf::InternalLegendRenderTools::renderBackgroundUsingShaders(oglContext,
matrixState,
cvf::Vec2f(sizeMatched),
cvf::Vec2f(sizeFrameBox),
this->backgroundColor(),
this->backgroundFrameColor());
}
@ -138,7 +138,7 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
float lineHeightInPixels = (float)(this->font()->textExtent("SWAT").y() + 2);
float textPosY = static_cast<float>(sizeMatched.y() - lineHeightInPixels - border);
float textPosY = static_cast<float>(size.y() - lineHeightInPixels - border);
for (size_t it = 0; it < this->titleStrings().size(); it++)
{
cvf::Vec2f pos(border, textPosY);
@ -154,11 +154,11 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
{
cvf::uint sgasTextWidth = this->font()->textExtent("SGAS").x();
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (sizeMatched.x() / 2) - sgasTextWidth / 2 ), textPosY));
textDrawer.addText("SGAS", cvf::Vec2f(static_cast<float>( (size.x() / 2) - sgasTextWidth / 2 ), textPosY));
cvf::uint sgasRangeTextWidth = this->font()->textExtent(m_sgasRange).x();
textPosY -= lineHeightInPixels;
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (sizeMatched.x() / 2) - sgasRangeTextWidth / 2 ), textPosY));
textDrawer.addText(m_sgasRange, cvf::Vec2f(static_cast<float>( (size.x() / 2) - sgasRangeTextWidth / 2 ), textPosY));
}
textDrawer.addText("SWAT", cvf::Vec2f((float)border, (float)(lineHeightInPixels + border)));
@ -166,10 +166,10 @@ void RivTernarySaturationOverlayItem::renderGeneric(cvf::OpenGLContext* oglConte
{
cvf::uint soilTextWidth = this->font()->textExtent("SOIL").x();
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(sizeMatched.x() - soilTextWidth - border), lineHeightInPixels + border));
textDrawer.addText("SOIL", cvf::Vec2f(static_cast<float>(size.x() - soilTextWidth - border), lineHeightInPixels + border));
cvf::uint soilRangeTextWidth = this->font()->textExtent(m_soilRange).x();
float soilRangePos = static_cast<float>(sizeMatched.x()) - soilRangeTextWidth - border;
float soilRangePos = static_cast<float>(size.x()) - soilRangeTextWidth - border;
textDrawer.addText(m_soilRange, cvf::Vec2f(soilRangePos, (float)border));
}

View File

@ -41,7 +41,7 @@ class RivTernarySaturationOverlayItem : public caf::TitledOverlayFrame
public:
explicit RivTernarySaturationOverlayItem(cvf::Font* font);
~RivTernarySaturationOverlayItem();
virtual void computeLayoutAndExtents() override;
virtual void computeLayoutAndExtents(const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
void setRangeText(const cvf::String& soilRange, const cvf::String& sgasRange, const cvf::String& swatRange);

View File

@ -603,7 +603,7 @@ void Rim2dIntersectionView::updateLegends()
if ( legend )
{
m_viewer->addColorLegendToBottomLeftCorner(legend, this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(legend);
}
}

View File

@ -69,7 +69,7 @@ public:
bool showDefiningPoints() const;
protected:
void updateLegends();
void updateLegends() override;
virtual bool isGridVisualizationMode() const override;
virtual void axisLabels(cvf::String* xLabel, cvf::String* yLabel, cvf::String* zLabel) override;

View File

@ -736,6 +736,7 @@ void Rim3dView::applyBackgroundColor()
}
updateGridBoxData();
updateAnnotationItems();
updateLegends();
}
//--------------------------------------------------------------------------------------------------

View File

@ -132,6 +132,7 @@ public:
void createHighlightAndGridBoxDisplayModelWithRedraw();
void updateGridBoxData();
void updateAnnotationItems();
virtual void updateLegends() = 0;
bool isMasterView() const;
@ -157,7 +158,7 @@ protected:
// Implementation of RiuViewerToViewInterface
virtual cvf::Color3f backgroundColor() const override { return m_backgroundColor(); }
virtual void applyBackgroundColor();
void applyBackgroundColor();
// Abstract methods to implement in subclasses

View File

@ -1087,7 +1087,7 @@ void RimEclipseView::updateLegends()
}
}
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend(), this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend());
this->cellEdgeResult()->legendConfig()->setTitle(QString("Edge Results: \n") + this->cellEdgeResult()->resultVariableUiShortName());
}
else
@ -1104,7 +1104,7 @@ void RimEclipseView::updateLegends()
if (fractureColors()->isChecked() && stimPlanLegend->legend())
{
m_viewer->addColorLegendToBottomLeftCorner(stimPlanLegend->legend(), this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(stimPlanLegend->legend());
}
}
@ -1113,7 +1113,7 @@ void RimEclipseView::updateLegends()
updateVirtualConnectionLegendRanges();
RimLegendConfig* virtLegend = m_virtualPerforationResult->legendConfig();
m_viewer->addColorLegendToBottomLeftCorner(virtLegend->legend(), this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(virtLegend->legend());
}
}
@ -1128,7 +1128,7 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel,
if (resultColors->hasResult() && resultColors->legendConfig()->enableLegend())
{
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend(), this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(resultColors->legendConfig()->legend());
resultColors->legendConfig()->setTitle(legendLabel + resultColors->resultVariableUiShortName());
}
@ -1138,7 +1138,7 @@ void RimEclipseView::updateMinMaxValuesAndAddLegendToView(QString legendLabel,
if (resultColors->ternaryLegendConfig->enableLegend() && resultColors->ternaryLegendConfig->legend())
{
resultColors->ternaryLegendConfig->setTitle(legendLabel);
m_viewer->addColorLegendToBottomLeftCorner(resultColors->ternaryLegendConfig->legend(), this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(resultColors->ternaryLegendConfig->legend());
}
}
}
@ -1598,12 +1598,10 @@ void RimEclipseView::resetLegendsInViewer()
if (cellResultNormalLegendConfig)
{
m_viewer->addColorLegendToBottomLeftCorner(cellResultNormalLegendConfig->legend(),
this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(cellResultNormalLegendConfig->legend());
}
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend(),
this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(this->cellEdgeResult()->legendConfig()->legend());
}
//--------------------------------------------------------------------------------------------------
@ -1739,15 +1737,6 @@ bool RimEclipseView::showActiveCellsOnly()
return !m_showInactiveCells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseView::applyBackgroundColor()
{
Rim3dView::applyBackgroundColor();
this->updateLegends();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -147,7 +147,6 @@ protected:
virtual void createPartCollectionFromSelection(cvf::Collection<cvf::Part>* parts) override;
virtual bool showActiveCellsOnly() override;
virtual void applyBackgroundColor() override;
private:
void createDisplayModel() override;
@ -160,7 +159,7 @@ private:
virtual void updateStaticCellColors() override;
void updateStaticCellColors(RivCellSetEnum geometryType);
void updateLegends();
void updateLegends() override;
void updateMinMaxValuesAndAddLegendToView(QString legendLabel, RimEclipseCellColors* resultColors, RigCaseCellResultsData* cellResultsData);
virtual void resetLegendsInViewer() override;
void updateVirtualConnectionLegendRanges();

View File

@ -364,8 +364,7 @@ void RimGeoMechView::resetLegendsInViewer()
this->cellResult()->legendConfig->recreateLegend();
m_viewer->removeAllColorLegends();
m_viewer->addColorLegendToBottomLeftCorner(this->cellResult()->legendConfig->legend(),
this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(this->cellResult()->legendConfig->legend());
}
//--------------------------------------------------------------------------------------------------
@ -379,18 +378,19 @@ void RimGeoMechView::updateLegends()
this->updateLegendTextAndRanges(cellResult()->legendConfig(), m_currentTimeStep());
if (cellResult()->hasResult())
if (cellResult()->hasResult() && cellResult()->legendConfig()->enableLegend())
{
m_viewer->addColorLegendToBottomLeftCorner(cellResult()->legendConfig->legend(),
this->backgroundColor());
m_viewer->addColorLegendToBottomLeftCorner(cellResult()->legendConfig->legend());
}
updateTensorLegendTextAndRanges(m_tensorResults->arrowColorLegendConfig(), m_currentTimeStep());
if (tensorResults()->vectorColors() == RimTensorResults::RESULT_COLORS && tensorResults()->showTensors())
{
m_viewer->addColorLegendToBottomLeftCorner(m_tensorResults->arrowColorLegendConfig->legend(),
this->backgroundColor());
if (tensorResults()->arrowColorLegendConfig()->enableLegend())
{
m_viewer->addColorLegendToBottomLeftCorner(m_tensorResults->arrowColorLegendConfig->legend());
}
}
}
}

View File

@ -110,7 +110,7 @@ private:
virtual void resetLegendsInViewer() override;
void updateLegends();
void updateLegends() override;
void updateTensorLegendTextAndRanges(RimLegendConfig* legendConfig, int timeStepIndex);

View File

@ -371,7 +371,7 @@ void RimLegendConfig::updateLegend()
numDecimalDigits -= static_cast<int>(decadesInRange);
}
m_scalarMapperLegend->setTickPrecision(cvf::Math::clamp(numDecimalDigits, 0, 20));
m_scalarMapperLegend->computeLayoutAndExtents();
m_scalarMapperLegend->computeLayoutAndExtents(cvf::Vec2i(0, 0), m_scalarMapperLegend->sizeHint());
RiaApplication* app = RiaApplication::instance();
RiaPreferences* preferences = app->preferences();

View File

@ -432,7 +432,7 @@ void RiuViewer::paintOverlayItems(QPainter* painter)
painter->drawLine(centerPos.x() - markerHalfLength, centerPos.y(), centerPos.x() + markerHalfLength, centerPos.y());
}
}
}
}
}
//--------------------------------------------------------------------------------------------------
@ -536,7 +536,7 @@ void RiuViewer::removeAllColorLegends()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend, const cvf::Color3f& backgroundColor)
void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend)
{
RiaApplication* app = RiaApplication::instance();
CVF_ASSERT(app);
@ -547,12 +547,16 @@ void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend
if (legend)
{
cvf::Color4f backgroundColor = mainCamera()->viewport()->clearColor();
backgroundColor.a() = 0.8f;
cvf::Color3f frameColor(backgroundColor.r(), backgroundColor.g(), backgroundColor.b());
updateLegendTextAndTickMarkColor(legend);
firstRendering->addOverlayItem(legend);
legend->enableBackground(preferences->showLegendBackground());
legend->setBackgroundColor(cvf::Color4f(backgroundColor, 0.8f));
legend->setBackgroundFrameColor(cvf::Color4f(RiaColorTools::computeOffsetColor(backgroundColor, 0.3f), 0.9f));
legend->setBackgroundColor(backgroundColor);
legend->setBackgroundFrameColor(cvf::Color4f(RiaColorTools::computeOffsetColor(frameColor, 0.3f), 0.9f));
m_visibleLegends.push_back(legend);
}
@ -616,12 +620,13 @@ void RiuViewer::addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend
}
unsigned int requiredLegendWidth = 0u;
for (auto legend : m_visibleLegends)
for (auto legend : overlayItems)
{
legend->computeLayoutAndExtents(cvf::Vec2i(0, 0), legend->sizeHint());
requiredLegendWidth = std::max(requiredLegendWidth, legend->minimumWidth());
}
for (auto legend : m_visibleLegends)
for (auto legend : overlayItems)
{
legend->setMatchedWidth(requiredLegendWidth);
}

View File

@ -96,7 +96,7 @@ public:
void showAnimationProgress(bool enable);
void removeAllColorLegends();
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend, const cvf::Color3f& backgroundColor);
void addColorLegendToBottomLeftCorner(caf::TitledOverlayFrame* legend);
void enableNavigationRotation(bool disable);
void updateNavigationPolicy();

View File

@ -129,7 +129,7 @@ void CategoryLegend::renderGeneric(OpenGLContext* oglContext,
camera.applyOpenGL();
camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);
this->computeLayoutAndExtents();
this->computeLayoutAndExtents(position, size);
Vec2f backgroundSize(CVF_MIN((float) this->matchedWidth(), (float)size.x()), (float)size.y());
@ -494,9 +494,10 @@ void CategoryLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CategoryLegend::computeLayoutAndExtents()
void CategoryLegend::computeLayoutAndExtents(const Vec2i& position, const Vec2ui& size)
{
// Todo: Cache this between renderings. Update only when needed.
m_Layout = OverlayColorLegendLayoutInfo(position, size);
layoutInfo(&m_Layout);
m_textDrawer = new TextDrawer(this->font());

View File

@ -31,7 +31,7 @@ public:
virtual ~CategoryLegend();
size_t categoryCount() const;
void computeLayoutAndExtents() override;
void computeLayoutAndExtents(const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
protected:
void render(cvf::OpenGLContext* oglContext, const cvf::Vec2i& position, const cvf::Vec2ui& size) override;

View File

@ -183,12 +183,9 @@ void OverlayScalarMapperLegend::renderGeneric(OpenGLContext* oglContext, const V
camera.applyOpenGL();
camera.viewport()->applyOpenGL(oglContext, Viewport::CLEAR_DEPTH);
m_Layout.position = position;
m_Layout.size = size;
this->computeLayoutAndExtents();
this->computeLayoutAndExtents(position, size);
Vec2f backgroundSize(CVF_MIN((float)this->matchedWidth(), (float)size.x()), (float)size.y());
Vec2f backgroundSize(this->matchedWidth(), (float)size.y());
// Do the actual rendering
if (software)
@ -665,8 +662,10 @@ void OverlayScalarMapperLegend::setTickFormat(NumberFormat format)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void OverlayScalarMapperLegend::computeLayoutAndExtents()
void OverlayScalarMapperLegend::computeLayoutAndExtents(const Vec2i& position, const Vec2ui& size)
{
// Todo: Cache this between renderings. Update only when needed.
//m_Layout = OverlayColorLegendLayoutInfo(position, size);
layoutInfo(&m_Layout);
m_textDrawer = new TextDrawer(this->font());

View File

@ -85,7 +85,7 @@ public:
void setTickPrecision(int precision);
enum NumberFormat { AUTO, SCIENTIFIC, FIXED};
void setTickFormat(NumberFormat format);
void computeLayoutAndExtents() override;
void computeLayoutAndExtents(const cvf::Vec2i& position, const cvf::Vec2ui& size) override;
protected:
void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;
void renderSoftware(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size) override;

View File

@ -35,7 +35,7 @@ namespace caf {
void setBackgroundColor(const cvf::Color4f& backgroundColor);
void setBackgroundFrameColor(const cvf::Color4f& backgroundFrameColor);
virtual void computeLayoutAndExtents() = 0;
virtual void computeLayoutAndExtents(const cvf::Vec2i& position, const cvf::Vec2ui& size) = 0;
virtual cvf::Vec2ui sizeHint() override;
unsigned int minimumWidth();