Skip to content

Commit

Permalink
Remove duplicated code
Browse files Browse the repository at this point in the history
* Use annotation tools from part manager
* Set version to 2023.06.01-dev.06
  • Loading branch information
magnesj authored Sep 13, 2023
1 parent f4c61c9 commit c22b8b2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 95 deletions.
26 changes: 7 additions & 19 deletions ApplicationLibCode/ModelVisualization/Faults/RivFaultPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,44 +581,32 @@ void RivFaultPartMgr::createLabelWithAnchorLine( const cvf::Part* part )

cvf::Font* font = app->defaultWellLabelFont();

cvf::ref<cvf::DrawableText> 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<RimFaultInViewCollection>();
if ( parentObject )
{
auto parentObject = m_rimFault->firstAncestorOrThisOfType<RimFaultInViewCollection>();
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<cvf::Part> labelPart = new cvf::Part;
labelPart->setName( "RivFaultPart : text " + cvfString );
labelPart->setName( "RivFaultPart : text " + m_rimFault->name().toStdString() );
labelPart->setDrawable( drawableText.p() );

cvf::ref<cvf::Effect> eff = new cvf::Effect;

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;
}
Expand Down
40 changes: 30 additions & 10 deletions ApplicationLibCode/ModelVisualization/RivAnnotationTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,12 @@ void RivAnnotationTools::setCountHint( int countHint )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Part> RivAnnotationTools::createPartFromPolyline( const std::string& partName,
const cvf::Color3f& color,
const std::vector<cvf::Vec3d>& polyLine )
cvf::ref<cvf::Part> RivAnnotationTools::createPartFromPolyline( const cvf::Color3f& color, const std::vector<cvf::Vec3d>& polyLine )
{
cvf::ref<cvf::DrawableGeo> drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable( polyLine );
if ( drawableGeo.isNull() ) return nullptr;

cvf::ref<cvf::Part> part = new cvf::Part;
part->setName( partName );
part->setDrawable( drawableGeo.p() );

caf::MeshEffectGenerator colorEffgen( color );
Expand Down Expand Up @@ -333,9 +330,11 @@ void RivAnnotationTools::addAnnotationLabels( const cvf::Collection<cvf::Part>&
std::vector<cvf::Vec3d> points = { lineAnchorPosition, labelPosition };

auto anchorLineColor = cvf::Color3f::BLACK;
auto part = RivAnnotationTools::createPartFromPolyline( "AnnotationObjectAnchorPoints", anchorLineColor, points );
auto part = RivAnnotationTools::createPartFromPolyline( anchorLineColor, points );

if ( part.notNull() )
{
part->setName( "AnnotationObjectAnchorPoints" );
model->addPart( part.p() );
}
}
Expand Down Expand Up @@ -365,11 +364,11 @@ void RivAnnotationTools::addAnnotationLabels( const cvf::Collection<cvf::Part>&
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableText> RivAnnotationTools::createDrawableText( cvf::Font* font,
cvf::Color3f textColor,
cvf::Color3f backgroundColor,
const std::string& text,
const cvf::Vec3f& position )
cvf::ref<cvf::DrawableText> 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;

Expand All @@ -387,6 +386,27 @@ cvf::ref<cvf::DrawableText> RivAnnotationTools::createDrawableText( cvf::Font*
return drawableText;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::DrawableText> RivAnnotationTools::createDrawableTextNoBackground( cvf::Font* font,
const cvf::Color3f& textColor,
const std::string& text,
const cvf::Vec3f& position )
{
cvf::ref<cvf::DrawableText> 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;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
16 changes: 9 additions & 7 deletions ApplicationLibCode/ModelVisualization/RivAnnotationTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ class RivAnnotationTools
// Create labels for the given collection of parts. The labels are added to the given model.
void addAnnotationLabels( const cvf::Collection<cvf::Part>& partCollection, const cvf::Camera* camera, cvf::ModelBasicList* model );

static cvf::ref<cvf::Part>
createPartFromPolyline( const std::string& partName, const cvf::Color3f& color, const std::vector<cvf::Vec3d>& polyLine );
static cvf::ref<cvf::Part> createPartFromPolyline( const cvf::Color3f& color, const std::vector<cvf::Vec3d>& polyLine );

static cvf::ref<cvf::DrawableText> createDrawableText( cvf::Font* font,
cvf::Color3f textColor,
cvf::Color3f backgroundColor,
const std::string& text,
const cvf::Vec3f& position );
static cvf::ref<cvf::DrawableText> createDrawableText( cvf::Font* font,
const cvf::Color3f& textColor,
const cvf::Color3f& backgroundColor,
const std::string& text,
const cvf::Vec3f& position );

static cvf::ref<cvf::DrawableText>
createDrawableTextNoBackground( cvf::Font* font, const cvf::Color3f& textColor, const std::string& text, const cvf::Vec3f& position );

static cvf::ref<cvf::Part> createPart( cvf::DrawableText* drawableText );

Expand Down
37 changes: 6 additions & 31 deletions ApplicationLibCode/ModelVisualization/RivTextAnnotationPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,48 +98,23 @@ void RivTextAnnotationPartMgr::buildParts( const caf::DisplayCoordTransform* dis
{
std::vector<cvf::Vec3d> points = { anchorPosition, labelPosition };

cvf::ref<cvf::DrawableGeo> drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable( points );

cvf::ref<cvf::Part> part = new cvf::Part;
auto part = RivAnnotationTools::createPartFromPolyline( anchorLineColor, points );
part->setName( "RivTextAnnotationPartMgr" );
part->setDrawable( drawableGeo.p() );

caf::MeshEffectGenerator colorEffgen( anchorLineColor );
cvf::ref<cvf::Effect> eff = colorEffgen.generateUnCachedEffect();

part->setEffect( eff.p() );
part->setPriority( RivPartPriority::PartType::MeshLines );
part->setSourceInfo( new RivObjectSourceInfo( rimAnnotation() ) );

m_linePart = part;
}

// Text part
{
auto font = RiaFontCache::getFont( fontSize );
cvf::ref<cvf::DrawableText> drawableText = new cvf::DrawableText;
drawableText->setFont( font.p() );
drawableText->setCheckPosVisible( false );
drawableText->setUseDepthBuffer( true );
drawableText->setDrawBorder( true );
drawableText->setDrawBackground( true );
drawableText->setVerticalAlignment( cvf::TextDrawer::BASELINE );
drawableText->setBackgroundColor( backgroundColor );
drawableText->setBorderColor( RiaColorTools::computeOffsetColor( backgroundColor, 0.3f ) );
drawableText->setTextColor( fontColor );
auto font = RiaFontCache::getFont( fontSize );

cvf::String cvfString = cvfqt::Utils::toString( text );
auto drawableText =
RivAnnotationTools::createDrawableText( font.p(), fontColor, backgroundColor, text.toStdString(), cvf::Vec3f( labelPosition ) );

cvf::Vec3f textCoord( labelPosition );
drawableText->addText( cvfString, textCoord );

cvf::ref<cvf::Part> part = new cvf::Part;
auto part = RivAnnotationTools::createPart( drawableText.p() );
cvf::String cvfString = cvfqt::Utils::toString( text );
part->setName( "RivTextAnnotationPartMgr: " + cvfString );
part->setDrawable( drawableText.p() );

cvf::ref<cvf::Effect> eff = new cvf::Effect();
part->setEffect( eff.p() );
part->setPriority( RivPartPriority::PartType::MeshLines );

m_labelPart = part;
}
Expand Down
19 changes: 6 additions & 13 deletions ApplicationLibCode/ModelVisualization/RivWellHeadPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cvf::DrawableText> 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<cvf::Part> part = new cvf::Part;
part->setName( "RivWellHeadPartMgr: text " + cvfString );
Expand All @@ -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;
}
Expand Down
20 changes: 6 additions & 14 deletions ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,29 +737,21 @@ void RivWellPathPartMgr::buildWellPathParts( const caf::DisplayCoordTransform* d
{
cvf::Font* font = RiaGuiApplication::instance()->defaultWellLabelFont();

cvf::ref<cvf::DrawableText> 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<cvf::Part> part = new cvf::Part;
part->setName( "RivWellHeadPartMgr: text " + cvfString );
part->setName( "RivWellHeadPartMgr: text " + m_rimWellPath->name().toStdString() );
part->setDrawable( drawableText.p() );

cvf::ref<cvf::Effect> eff = new cvf::Effect;

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;
}
Expand Down
2 changes: 1 addition & 1 deletion ResInsightVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(RESINSIGHT_VERSION_TEXT "-dev")
# Must be unique and increasing within one combination of major/minor/patch version
# The uniqueness of this text is independent of RESINSIGHT_VERSION_TEXT
# Format of text must be ".xx"
set(RESINSIGHT_DEV_VERSION ".05")
set(RESINSIGHT_DEV_VERSION ".06")

# https://github.com/CRAVA/crava/tree/master/libs/nrlib
set(NRLIB_GITHUB_SHA "ba35d4359882f1c6f5e9dc30eb95fe52af50fd6f")
Expand Down

0 comments on commit c22b8b2

Please sign in to comment.