2018-11-23 06:33:59 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011- Statoil ASA
|
|
|
|
// Copyright (C) 2013- Ceetron Solutions AS
|
|
|
|
// Copyright (C) 2011-2012 Ceetron AS
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "RivTextAnnotationPartMgr.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2018-11-26 05:49:22 -06:00
|
|
|
#include "RiaColorTools.h"
|
2018-11-26 02:27:18 -06:00
|
|
|
#include "RiaPreferences.h"
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-29 03:13:19 -06:00
|
|
|
#include "Rim3dView.h"
|
|
|
|
#include "RimAnnotationInViewCollection.h"
|
2018-11-23 06:33:59 -06:00
|
|
|
#include "RimTextAnnotation.h"
|
|
|
|
|
|
|
|
#include "RivPolylineGenerator.h"
|
|
|
|
#include "RivPartPriority.h"
|
|
|
|
#include "RivTextAnnotationSourceInfo.h"
|
|
|
|
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfDrawableText.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cvfqtUtils.h"
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-29 03:13:19 -06:00
|
|
|
RivTextAnnotationPartMgr::RivTextAnnotationPartMgr(Rim3dView* view, RimTextAnnotation* annotation)
|
|
|
|
: m_rimView(view), m_rimAnnotation(annotation)
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RivTextAnnotationPartMgr::~RivTextAnnotationPartMgr()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 02:27:18 -06:00
|
|
|
void RivTextAnnotationPartMgr::buildParts(const caf::DisplayCoordTransform * displayXf,
|
|
|
|
bool doFlatten,
|
|
|
|
double xOffset)
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
|
|
|
clearAllGeometry();
|
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
cvf::ref<RivTextAnnotationSourceInfo> sourceInfo = new RivTextAnnotationSourceInfo(m_rimAnnotation);
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-28 04:58:38 -06:00
|
|
|
cvf::Vec3d anchorPositionInDomain = m_rimAnnotation->anchorPoint();
|
|
|
|
cvf::Vec3d labelPositionInDomain = m_rimAnnotation->labelPoint();
|
|
|
|
|
|
|
|
{
|
2018-11-29 03:13:19 -06:00
|
|
|
auto* collection = annotationCollection();
|
2018-11-28 04:58:38 -06:00
|
|
|
if (collection && collection->snapAnnotations())
|
|
|
|
{
|
|
|
|
anchorPositionInDomain.z() = collection->annotationPlaneZ();
|
|
|
|
labelPositionInDomain.z() = collection->annotationPlaneZ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::Vec3d anchorPosition = displayXf->transformToDisplayCoord(anchorPositionInDomain);
|
|
|
|
cvf::Vec3d labelPosition = displayXf->transformToDisplayCoord(labelPositionInDomain);
|
2018-11-26 02:27:18 -06:00
|
|
|
QString text = m_rimAnnotation->text();
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
// Line part
|
|
|
|
{
|
|
|
|
std::vector<cvf::Vec3d> points = { anchorPosition, labelPosition };
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
cvf::ref<cvf::DrawableGeo> drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable(points);
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setDrawable(drawableGeo.p());
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
caf::MeshEffectGenerator colorEffgen(cvf::Color3f::BLACK);
|
|
|
|
cvf::ref<cvf::Effect> eff = colorEffgen.generateUnCachedEffect();
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
part->setEffect(eff.p());
|
|
|
|
part->setPriority(RivPartPriority::PartType::MeshLines);
|
|
|
|
part->setSourceInfo(sourceInfo.p());
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
m_linePart = part;
|
|
|
|
}
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
// Text part
|
|
|
|
{
|
|
|
|
auto app = RiaApplication::instance();
|
|
|
|
cvf::Font* font = app->customFont();
|
|
|
|
auto prefs = app->preferences();
|
|
|
|
|
|
|
|
cvf::ref<cvf::DrawableText> drawableText = new cvf::DrawableText;
|
|
|
|
drawableText->setFont(font);
|
|
|
|
drawableText->setCheckPosVisible(false);
|
|
|
|
drawableText->setDrawBorder(true);
|
|
|
|
drawableText->setDrawBackground(true);
|
|
|
|
drawableText->setVerticalAlignment(cvf::TextDrawer::BASELINE);
|
|
|
|
drawableText->setBackgroundColor(prefs->defaultViewerBackgroundColor);
|
2018-11-26 05:49:22 -06:00
|
|
|
drawableText->setBorderColor(RiaColorTools::computeOffsetColor(prefs->defaultViewerBackgroundColor, 0.3f));
|
2018-11-26 02:27:18 -06:00
|
|
|
drawableText->setTextColor(cvf::Color3f::BLACK);
|
|
|
|
|
|
|
|
cvf::String cvfString = cvfqt::Utils::toString(text);
|
|
|
|
|
|
|
|
cvf::Vec3f textCoord(labelPosition);
|
|
|
|
drawableText->addText(cvfString, textCoord);
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setName("RivTextAnnotationPartMgr: " + cvfString);
|
|
|
|
part->setDrawable(drawableText.p());
|
|
|
|
|
|
|
|
cvf::ref<cvf::Effect> eff = new cvf::Effect();
|
|
|
|
part->setEffect(eff.p());
|
|
|
|
part->setPriority(RivPartPriority::PartType::Text);
|
|
|
|
part->setSourceInfo(sourceInfo.p());
|
|
|
|
|
|
|
|
m_labelPart = part;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivTextAnnotationPartMgr::clearAllGeometry()
|
|
|
|
{
|
2018-11-26 02:27:18 -06:00
|
|
|
m_linePart = nullptr;
|
|
|
|
m_labelPart = nullptr;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivTextAnnotationPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model,
|
|
|
|
const caf::DisplayCoordTransform * displayXf)
|
|
|
|
{
|
|
|
|
if (m_rimAnnotation.isNull()) return;
|
2018-11-28 07:18:10 -06:00
|
|
|
if (!m_rimAnnotation->isActive()) return;
|
|
|
|
|
2018-11-23 06:33:59 -06:00
|
|
|
if (!validateAnnotation(m_rimAnnotation)) return;
|
|
|
|
|
2018-11-26 02:27:18 -06:00
|
|
|
buildParts(displayXf, false, 0.0);
|
|
|
|
model->addPart(m_linePart.p());
|
|
|
|
model->addPart(m_labelPart.p());
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RivTextAnnotationPartMgr::validateAnnotation(const RimTextAnnotation* annotation) const
|
|
|
|
{
|
|
|
|
return m_rimAnnotation->anchorPoint() != cvf::Vec3d::ZERO && !m_rimAnnotation->text().isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-11-28 04:58:38 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-29 03:13:19 -06:00
|
|
|
RimAnnotationInViewCollection* RivTextAnnotationPartMgr::annotationCollection() const
|
2018-11-28 04:58:38 -06:00
|
|
|
{
|
2018-11-29 03:13:19 -06:00
|
|
|
std::vector<RimAnnotationInViewCollection*> colls;
|
|
|
|
m_rimView->descendantsIncludingThisOfType(colls);
|
|
|
|
return !colls.empty() ? colls.front() : nullptr;
|
2018-11-28 04:58:38 -06:00
|
|
|
}
|