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 "RivReachCircleAnnotationPartMgr.h"
|
|
|
|
|
2018-11-28 04:58:38 -06:00
|
|
|
#include "RimAnnotationCollection.h"
|
2018-11-23 06:33:59 -06:00
|
|
|
#include "RimReachCircleAnnotation.h"
|
|
|
|
|
|
|
|
#include "RivPolylineGenerator.h"
|
|
|
|
#include "RivPartPriority.h"
|
|
|
|
#include "RivReachCircleAnnotationSourceInfo.h"
|
|
|
|
|
|
|
|
#include "cafEffectGenerator.h"
|
|
|
|
|
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cafDisplayCoordTransform.h"
|
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
#include <cmath>
|
2018-11-23 06:33:59 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RivReachCircleAnnotationPartMgr::RivReachCircleAnnotationPartMgr(RimReachCircleAnnotation* annotation)
|
|
|
|
: m_rimAnnotation(annotation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RivReachCircleAnnotationPartMgr::~RivReachCircleAnnotationPartMgr()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
///
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
void RivReachCircleAnnotationPartMgr::buildParts(const caf::DisplayCoordTransform* displayXf, bool doFlatten, double xOffset)
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
2018-11-26 04:08:38 -06:00
|
|
|
clearAllGeometry();
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
cvf::ref<RivReachCircleAnnotationSourceInfo> sourceInfo = new RivReachCircleAnnotationSourceInfo(m_rimAnnotation);
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-28 04:58:38 -06:00
|
|
|
Vec3d centerPositionInDomain = m_rimAnnotation->centerPoint();
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* collection = dynamic_cast<RimAnnotationCollection*>(annotationCollection());
|
|
|
|
if (collection && collection->snapAnnotations())
|
|
|
|
{
|
|
|
|
centerPositionInDomain.z() = collection->annotationPlaneZ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec3d centerPosition = displayXf->transformToDisplayCoord(centerPositionInDomain);
|
2018-11-26 04:08:38 -06:00
|
|
|
double radius = m_rimAnnotation->radius();
|
2018-11-27 07:27:02 -06:00
|
|
|
auto lineColor = m_rimAnnotation->appearance()->color();
|
|
|
|
auto isDashedLine = m_rimAnnotation->appearance()->isDashed();
|
|
|
|
auto lineThickness = m_rimAnnotation->appearance()->thickness();
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
// Circle part
|
|
|
|
{
|
|
|
|
int numPoints = 36;
|
|
|
|
std::vector<Vec3d> points;
|
|
|
|
for (int i = 0; i < numPoints; i++)
|
|
|
|
{
|
|
|
|
double rad = 2 * cvf::PI_D * (double)i / (double)numPoints;
|
|
|
|
Vec3d pt(centerPosition.x() + cos(rad) * radius, centerPosition.y() + sin(rad) * radius , centerPosition.z());
|
|
|
|
points.push_back(pt);
|
|
|
|
}
|
|
|
|
points.push_back(points.front());
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
cvf::ref<cvf::DrawableGeo> drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable(points);
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setDrawable(drawableGeo.p());
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-27 07:27:02 -06:00
|
|
|
caf::MeshEffectGenerator effgen(lineColor);
|
|
|
|
effgen.setLineWidth(lineThickness);
|
|
|
|
if (isDashedLine) effgen.setLineStipple(true);
|
|
|
|
cvf::ref<cvf::Effect> eff = effgen.generateUnCachedEffect();
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -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 04:08:38 -06:00
|
|
|
m_circlePart = part;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
2018-11-29 01:48:01 -06:00
|
|
|
|
|
|
|
// Center point part
|
|
|
|
{
|
|
|
|
double symbolSize = 20;
|
|
|
|
double xMin = centerPosition.x() - symbolSize / 2.0;
|
|
|
|
double xMax = xMin + symbolSize;
|
|
|
|
double yMin = centerPosition.y() - symbolSize / 2.0;
|
|
|
|
double yMax = yMin + symbolSize;
|
|
|
|
double z = centerPosition.z();
|
|
|
|
std::vector<Vec3d> line1 = { {xMin, yMin, z}, {xMax, yMax, z} };
|
|
|
|
std::vector<Vec3d> line2 = { {xMax, yMin, z}, {xMin, yMax, z} };
|
|
|
|
std::vector<std::vector<Vec3d>> symbol = { line1, line2 };
|
|
|
|
cvf::ref<cvf::DrawableGeo> drawableGeo = RivPolylineGenerator::createLineAlongPolylineDrawable(symbol);
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setDrawable(drawableGeo.p());
|
|
|
|
|
|
|
|
caf::MeshEffectGenerator effgen(lineColor);
|
|
|
|
effgen.setLineWidth(2);
|
|
|
|
cvf::ref<cvf::Effect> eff = effgen.generateUnCachedEffect();
|
|
|
|
|
|
|
|
part->setEffect(eff.p());
|
|
|
|
part->setPriority(RivPartPriority::PartType::MeshLines);
|
|
|
|
part->setSourceInfo(sourceInfo.p());
|
|
|
|
|
|
|
|
m_centerPointPart = part;
|
|
|
|
}
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
///
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
void RivReachCircleAnnotationPartMgr::clearAllGeometry()
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
2018-11-26 04:08:38 -06:00
|
|
|
m_circlePart = nullptr;
|
2018-11-29 01:48:01 -06:00
|
|
|
m_centerPointPart = nullptr;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
///
|
2018-11-23 06:33:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-26 04:08:38 -06:00
|
|
|
void RivReachCircleAnnotationPartMgr::appendDynamicGeometryPartsToModel(cvf::ModelBasicList* model,
|
|
|
|
const caf::DisplayCoordTransform* displayXf)
|
2018-11-23 06:33:59 -06:00
|
|
|
{
|
2018-11-26 04:08:38 -06:00
|
|
|
if (m_rimAnnotation.isNull()) return;
|
2018-11-28 07:18:10 -06:00
|
|
|
if (!m_rimAnnotation->isActive()) return;
|
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
if (!validateAnnotation(m_rimAnnotation)) return;
|
2018-11-23 06:33:59 -06:00
|
|
|
|
2018-11-26 04:08:38 -06:00
|
|
|
buildParts(displayXf, false, 0.0);
|
|
|
|
model->addPart(m_circlePart.p());
|
2018-11-29 01:48:01 -06:00
|
|
|
model->addPart(m_centerPointPart.p());
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RivReachCircleAnnotationPartMgr::validateAnnotation(const RimReachCircleAnnotation* annotation) const
|
|
|
|
{
|
2018-11-26 04:08:38 -06:00
|
|
|
return m_rimAnnotation->centerPoint() != cvf::Vec3d::ZERO && m_rimAnnotation->radius() > 0.0;
|
2018-11-23 06:33:59 -06:00
|
|
|
}
|
2018-11-28 04:58:38 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimAnnotationCollectionBase* RivReachCircleAnnotationPartMgr::annotationCollection() const
|
|
|
|
{
|
|
|
|
RimAnnotationCollectionBase* coll;
|
|
|
|
m_rimAnnotation->firstAncestorOrThisOfType(coll);
|
|
|
|
return coll;
|
|
|
|
}
|