From 92b4840835483140e1d6947714bf2caf669cd4d8 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 12 Sep 2023 15:19:35 +0200 Subject: [PATCH] Use more from annotation tools --- .../Faults/RivFaultPartMgr.cpp | 26 +++++----------- .../ModelVisualization/RivAnnotationTools.cpp | 31 ++++++++++++++++--- .../ModelVisualization/RivAnnotationTools.h | 13 +++++--- .../ModelVisualization/RivWellHeadPartMgr.cpp | 19 ++++-------- .../ModelVisualization/RivWellPathPartMgr.cpp | 20 ++++-------- 5 files changed, 53 insertions(+), 56 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/Faults/RivFaultPartMgr.cpp b/ApplicationLibCode/ModelVisualization/Faults/RivFaultPartMgr.cpp index 31ab2c05d9..2e418bfde1 100644 --- a/ApplicationLibCode/ModelVisualization/Faults/RivFaultPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Faults/RivFaultPartMgr.cpp @@ -581,36 +581,24 @@ void RivFaultPartMgr::createLabelWithAnchorLine( const cvf::Part* part ) cvf::Font* font = app->defaultWellLabelFont(); - cvf::ref drawableText = new cvf::DrawableText; - drawableText->setFont( font ); - drawableText->setCheckPosVisible( false ); - drawableText->setDrawBorder( false ); - drawableText->setDrawBackground( false ); - drawableText->setVerticalAlignment( cvf::TextDrawer::CENTER ); - cvf::Color3f defWellLabelColor = app->preferences()->defaultWellLabelColor(); { + auto parentObject = m_rimFault->firstAncestorOrThisOfType(); + if ( parentObject ) { - auto parentObject = m_rimFault->firstAncestorOrThisOfType(); - if ( parentObject ) - { - defWellLabelColor = parentObject->faultLabelColor(); - } + defWellLabelColor = parentObject->faultLabelColor(); } } - drawableText->setTextColor( defWellLabelColor ); - - cvf::String cvfString = cvfqt::Utils::toString( m_rimFault->name() ); - cvf::Vec3f textCoord( labelPosition ); double characteristicCellSize = bb.extent().z() / 20; textCoord.z() += characteristicCellSize; - drawableText->addText( cvfString, textCoord ); + auto drawableText = + RivAnnotationTools::createDrawableTextNoBackground( font, defWellLabelColor, m_rimFault->name().toStdString(), textCoord ); cvf::ref labelPart = new cvf::Part; - labelPart->setName( "RivFaultPart : text " + cvfString ); + labelPart->setName( "RivFaultPart : text " + m_rimFault->name().toStdString() ); labelPart->setDrawable( drawableText.p() ); cvf::ref eff = new cvf::Effect; @@ -618,7 +606,7 @@ void RivFaultPartMgr::createLabelWithAnchorLine( const cvf::Part* part ) labelPart->setEffect( eff.p() ); labelPart->setPriority( RivPartPriority::PartType::Text ); - labelPart->setSourceInfo( new RivTextLabelSourceInfo( m_rimFault, cvfString, textCoord ) ); + labelPart->setSourceInfo( new RivTextLabelSourceInfo( m_rimFault, m_rimFault->name().toStdString(), textCoord ) ); m_faultLabelPart = labelPart; } diff --git a/ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp b/ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp index 0ec2db036c..bc6ba8fe03 100644 --- a/ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp +++ b/ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp @@ -364,11 +364,11 @@ void RivAnnotationTools::addAnnotationLabels( const cvf::Collection& //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -cvf::ref RivAnnotationTools::createDrawableText( cvf::Font* font, - cvf::Color3f textColor, - cvf::Color3f backgroundColor, - const std::string& text, - const cvf::Vec3f& position ) +cvf::ref RivAnnotationTools::createDrawableText( cvf::Font* font, + const cvf::Color3f& textColor, + const cvf::Color3f& backgroundColor, + const std::string& text, + const cvf::Vec3f& position ) { auto drawableText = new cvf::DrawableText; @@ -386,6 +386,27 @@ cvf::ref RivAnnotationTools::createDrawableText( cvf::Font* return drawableText; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +cvf::ref RivAnnotationTools::createDrawableTextNoBackground( cvf::Font* font, + const cvf::Color3f& textColor, + const std::string& text, + const cvf::Vec3f& position ) +{ + cvf::ref drawableText = new cvf::DrawableText; + + drawableText->setFont( font ); + drawableText->setCheckPosVisible( false ); + drawableText->setDrawBorder( false ); + drawableText->setDrawBackground( false ); + drawableText->setVerticalAlignment( cvf::TextDrawer::CENTER ); + drawableText->setTextColor( textColor ); + drawableText->addText( cvf::String( text ), position ); + + return drawableText; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ModelVisualization/RivAnnotationTools.h b/ApplicationLibCode/ModelVisualization/RivAnnotationTools.h index 9e88003ef6..13b98980c8 100644 --- a/ApplicationLibCode/ModelVisualization/RivAnnotationTools.h +++ b/ApplicationLibCode/ModelVisualization/RivAnnotationTools.h @@ -62,11 +62,14 @@ class RivAnnotationTools static cvf::ref createPartFromPolyline( const cvf::Color3f& color, const std::vector& polyLine ); - static cvf::ref createDrawableText( cvf::Font* font, - cvf::Color3f textColor, - cvf::Color3f backgroundColor, - const std::string& text, - const cvf::Vec3f& position ); + static cvf::ref createDrawableText( cvf::Font* font, + const cvf::Color3f& textColor, + const cvf::Color3f& backgroundColor, + const std::string& text, + const cvf::Vec3f& position ); + + static cvf::ref + createDrawableTextNoBackground( cvf::Font* font, const cvf::Color3f& textColor, const std::string& text, const cvf::Vec3f& position ); static cvf::ref createPart( cvf::DrawableText* drawableText ); diff --git a/ApplicationLibCode/ModelVisualization/RivWellHeadPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivWellHeadPartMgr.cpp index 83bbccdacc..dd911735fb 100644 --- a/ApplicationLibCode/ModelVisualization/RivWellHeadPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivWellHeadPartMgr.cpp @@ -290,20 +290,13 @@ void RivWellHeadPartMgr::buildWellHeadParts( size_t frameIndex, const caf::Displ // well disk labels are preferred since they have more info. if ( well->showWellLabel() && !well->name().isEmpty() && !well->showWellDisks() ) { - cvf::Font* font = RiaGuiApplication::instance()->defaultWellLabelFont(); - - cvf::ref drawableText = new cvf::DrawableText; - drawableText->setFont( font ); - drawableText->setCheckPosVisible( false ); - drawableText->setDrawBorder( false ); - drawableText->setDrawBackground( false ); - drawableText->setVerticalAlignment( cvf::TextDrawer::CENTER ); - drawableText->setTextColor( simWellInViewCollection()->wellLabelColor() ); - + cvf::Font* font = RiaGuiApplication::instance()->defaultWellLabelFont(); cvf::String cvfString = cvfqt::Utils::toString( m_rimWell->name() ); - cvf::Vec3f textCoord( textPosition ); - drawableText->addText( cvfString, textCoord ); + auto drawableText = RivAnnotationTools::createDrawableTextNoBackground( font, + simWellInViewCollection()->wellLabelColor(), + m_rimWell->name().toStdString(), + cvf::Vec3f( textPosition ) ); cvf::ref part = new cvf::Part; part->setName( "RivWellHeadPartMgr: text " + cvfString ); @@ -314,7 +307,7 @@ void RivWellHeadPartMgr::buildWellHeadParts( size_t frameIndex, const caf::Displ part->setEffect( eff.p() ); part->setPriority( RivPartPriority::PartType::Text ); - part->setSourceInfo( new RivTextLabelSourceInfo( m_rimWell, cvfString, textCoord ) ); + part->setSourceInfo( new RivTextLabelSourceInfo( m_rimWell, cvfString, cvf::Vec3f( textPosition ) ) ); m_wellHeadLabelPart = part; } diff --git a/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp index 80ffedb372..5d5654a5aa 100644 --- a/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp @@ -737,21 +737,13 @@ void RivWellPathPartMgr::buildWellPathParts( const caf::DisplayCoordTransform* d { cvf::Font* font = RiaGuiApplication::instance()->defaultWellLabelFont(); - cvf::ref drawableText = new cvf::DrawableText; - drawableText->setFont( font ); - drawableText->setCheckPosVisible( false ); - drawableText->setDrawBorder( false ); - drawableText->setDrawBackground( false ); - drawableText->setVerticalAlignment( cvf::TextDrawer::CENTER ); - drawableText->setTextColor( wellPathCollection->wellPathLabelColor() ); - - cvf::String cvfString = cvfqt::Utils::toString( m_rimWellPath->name() ); - - cvf::Vec3f textCoord( textPosition ); - drawableText->addText( cvfString, textCoord ); + auto drawableText = RivAnnotationTools::createDrawableTextNoBackground( font, + wellPathCollection->wellPathLabelColor(), + m_rimWellPath->name().toStdString(), + cvf::Vec3f( textPosition ) ); cvf::ref part = new cvf::Part; - part->setName( "RivWellHeadPartMgr: text " + cvfString ); + part->setName( "RivWellHeadPartMgr: text " + m_rimWellPath->name().toStdString() ); part->setDrawable( drawableText.p() ); cvf::ref eff = new cvf::Effect; @@ -759,7 +751,7 @@ void RivWellPathPartMgr::buildWellPathParts( const caf::DisplayCoordTransform* d part->setEffect( eff.p() ); part->setPriority( RivPartPriority::Text ); - part->setSourceInfo( new RivTextLabelSourceInfo( m_rimWellPath, cvfString, textCoord ) ); + part->setSourceInfo( new RivTextLabelSourceInfo( m_rimWellPath, m_rimWellPath->name().toStdString(), cvf::Vec3f( textPosition ) ) ); m_wellLabelPart = part; }