mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3806 Measurement. Display text label at last clicked position
This commit is contained in:
parent
deec4c16e9
commit
d6f4962ed7
@ -48,34 +48,15 @@ bool RicMeasurementPickEventHandler::handlePickEvent(const Ric3DPickEvent& event
|
||||
|
||||
if (measurement && measurement->isInMeasurementMode())
|
||||
{
|
||||
{
|
||||
Rim3dView* rimView = RiaApplication::instance()->activeReservoirView();
|
||||
Rim3dView* rimView = RiaApplication::instance()->activeReservoirView();
|
||||
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
|
||||
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
|
||||
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
|
||||
cvf::Vec3d domainCoord = transForm->transformToDomainCoord(eventObject.m_pickItemInfos.front().globalPickedPoint());
|
||||
|
||||
//if (intersection->inputPolyLineFromViewerEnabled())
|
||||
{
|
||||
measurement->addPointInDomain(domainCoord);
|
||||
measurement->addPointInDomain(domainCoord);
|
||||
|
||||
// Further Ui processing is stopped when true is returned
|
||||
return true;
|
||||
}
|
||||
//else if (intersection->inputExtrusionPointsFromViewerEnabled())
|
||||
//{
|
||||
// intersection->appendPointToExtrusionDirection(domainCoord);
|
||||
|
||||
// // Further Ui processing is stopped when true is returned
|
||||
// return true;
|
||||
//}
|
||||
//else if (intersection->inputTwoAzimuthPointsFromViewerEnabled())
|
||||
//{
|
||||
// intersection->appendPointToAzimuthLine(domainCoord);
|
||||
|
||||
// // Further Ui processing is stopped when true is returned
|
||||
// return true;
|
||||
//}
|
||||
}
|
||||
// Further Ui processing is stopped when true is returned
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -65,7 +65,8 @@ void RicToggleMeasurementModeFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Measurement Mode");
|
||||
|
||||
if(measurement()->isInMeasurementMode())
|
||||
auto* meas = measurement();
|
||||
if(meas && meas->isInMeasurementMode())
|
||||
actionToSetup->setIcon(QIcon(":/NoRuler16x16.png"));
|
||||
else
|
||||
actionToSetup->setIcon(QIcon(":/Ruler16x16.png"));
|
||||
|
@ -24,6 +24,9 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaBoundingBoxTools.h"
|
||||
#include "RiaColorTools.h"
|
||||
#include "RiaFontCache.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimAnnotationInViewCollection.h"
|
||||
@ -41,9 +44,11 @@
|
||||
#include <cvfModelBasicList.h>
|
||||
#include <cvfPart.h>
|
||||
#include <cvfDrawableGeo.h>
|
||||
#include <cvfDrawableText.h>
|
||||
#include "cvfRenderStateDepth.h"
|
||||
#include "cvfRenderStatePoint.h"
|
||||
#include "cvfBoundingBox.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
#include "cafEffectGenerator.h"
|
||||
#include "cafDisplayCoordTransform.h"
|
||||
@ -93,6 +98,11 @@ void RivMeasurementPartMgr::appendGeometryPartsToModel(cvf::ModelBasicList*
|
||||
{
|
||||
model->addPart(m_pointPart.p());
|
||||
}
|
||||
|
||||
if (m_labelPart.notNull())
|
||||
{
|
||||
model->addPart(m_labelPart.p());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -111,16 +121,11 @@ void RivMeasurementPartMgr::buildPolyLineParts(const caf::DisplayCoordTransform*
|
||||
{
|
||||
auto pointsInDisplay = transformPolylinesPointsToDisplay(m_measurement->pointsInDomain(), displayCoordTransform);
|
||||
|
||||
// Highlight line
|
||||
// Measurement lines
|
||||
{
|
||||
cvf::ref<cvf::DrawableGeo> polylineGeo = RivPolylineGenerator::createLineAlongPolylineDrawable(pointsInDisplay);
|
||||
if (polylineGeo.notNull())
|
||||
{
|
||||
//if (useBufferObjects)
|
||||
//{
|
||||
// polylineGeo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
//}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section Polyline");
|
||||
part->setDrawable(polylineGeo.p());
|
||||
@ -128,9 +133,6 @@ void RivMeasurementPartMgr::buildPolyLineParts(const caf::DisplayCoordTransform*
|
||||
part->updateBoundingBox();
|
||||
part->setPriority(RivPartPriority::PartType::Highlight);
|
||||
|
||||
// Always show this part, also when mesh is turned off
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator lineEffGen(cvf::Color3::MAGENTA);
|
||||
eff = lineEffGen.generateUnCachedEffect();
|
||||
@ -145,14 +147,10 @@ void RivMeasurementPartMgr::buildPolyLineParts(const caf::DisplayCoordTransform*
|
||||
}
|
||||
}
|
||||
|
||||
// Measurement points
|
||||
cvf::ref<cvf::DrawableGeo> polylinePointsGeo = RivPolylineGenerator::createPointsFromPolylineDrawable(pointsInDisplay);
|
||||
if (polylinePointsGeo.notNull())
|
||||
{
|
||||
//if (useBufferObjects)
|
||||
//{
|
||||
// polylinePointsGeo->setRenderMode(cvf::DrawableGeo::BUFFER_OBJECT);
|
||||
//}
|
||||
|
||||
cvf::ref<cvf::Part> part = new cvf::Part;
|
||||
part->setName("Cross Section Polyline");
|
||||
part->setDrawable(polylinePointsGeo.p());
|
||||
@ -160,9 +158,6 @@ void RivMeasurementPartMgr::buildPolyLineParts(const caf::DisplayCoordTransform*
|
||||
part->updateBoundingBox();
|
||||
part->setPriority(RivPartPriority::PartType::Highlight);
|
||||
|
||||
// Always show this part, also when mesh is turned off
|
||||
// part->setEnableMask(meshFaultBit);
|
||||
|
||||
cvf::ref<cvf::Effect> eff;
|
||||
caf::MeshEffectGenerator lineEffGen(cvf::Color3::MAGENTA);
|
||||
eff = lineEffGen.generateUnCachedEffect();
|
||||
@ -179,6 +174,42 @@ void RivMeasurementPartMgr::buildPolyLineParts(const caf::DisplayCoordTransform*
|
||||
|
||||
m_pointPart = part;
|
||||
}
|
||||
|
||||
// Text label
|
||||
if(pointsInDisplay.size() > 1)
|
||||
{
|
||||
auto fontSize = RiaFontCache::FONT_SIZE_8;
|
||||
auto backgroundColor = RiaApplication::instance()->preferences()->defaultViewerBackgroundColor;
|
||||
auto fontColor = cvf::Color3f::BLACK;
|
||||
QString text = m_measurement->label();
|
||||
auto labelPosition = pointsInDisplay.back();
|
||||
|
||||
auto font = RiaFontCache::getFont(fontSize);
|
||||
cvf::ref<cvf::DrawableText> drawableText = new cvf::DrawableText;
|
||||
drawableText->setFont(font.p());
|
||||
drawableText->setCheckPosVisible(false);
|
||||
drawableText->setDrawBorder(true);
|
||||
drawableText->setDrawBackground(true);
|
||||
drawableText->setVerticalAlignment(cvf::TextDrawer::BASELINE);
|
||||
drawableText->setBackgroundColor(backgroundColor);
|
||||
drawableText->setBorderColor(RiaColorTools::computeOffsetColor(backgroundColor, 0.3f));
|
||||
drawableText->setTextColor(fontColor);
|
||||
|
||||
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("RivMeasurementPartMgr: " + cvfString);
|
||||
part->setDrawable(drawableText.p());
|
||||
|
||||
cvf::ref<cvf::Effect> eff = new cvf::Effect();
|
||||
part->setEffect(eff.p());
|
||||
part->setPriority(RivPartPriority::PartType::Text);
|
||||
|
||||
m_labelPart = part;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -56,7 +56,6 @@ public:
|
||||
|
||||
void clearGeometryCache();
|
||||
|
||||
|
||||
private:
|
||||
void buildPolyLineParts(const caf::DisplayCoordTransform* displayCoordTransform);
|
||||
|
||||
@ -69,4 +68,5 @@ private:
|
||||
caf::PdmPointer<RimMeasurement> m_measurement;
|
||||
cvf::ref<cvf::Part> m_linePart;
|
||||
cvf::ref<cvf::Part> m_pointPart;
|
||||
cvf::ref<cvf::Part> m_labelPart;
|
||||
};
|
||||
|
@ -90,6 +90,44 @@ std::vector<cvf::Vec3d> RimMeasurement::pointsInDomain() const
|
||||
return m_pointsInDomain;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimMeasurement::label() const
|
||||
{
|
||||
auto lengths = calculateLenghts();
|
||||
return QString("Total length: \t%1\nLast length: \t%2\nTotal horizontal length: \t%3\nLast horizontal length: \t%4")
|
||||
.arg(lengths.totalLength)
|
||||
.arg(lengths.lastSegmentLength)
|
||||
.arg(lengths.totalHorizontalLength)
|
||||
.arg(lengths.lastSegmentHorisontalLength);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimMeasurement::Lengths RimMeasurement::calculateLenghts() const
|
||||
{
|
||||
Lengths lengths;
|
||||
|
||||
for (size_t p = 1; p < m_pointsInDomain.size(); p++)
|
||||
{
|
||||
const auto& p0 = m_pointsInDomain[p - 1];
|
||||
const auto& p1 = m_pointsInDomain[p];
|
||||
|
||||
lengths.lastSegmentLength = (p1 - p0).length();
|
||||
|
||||
const auto& p1_horiz = cvf::Vec3d(p1.x(), p1.y(), p0.z());
|
||||
|
||||
lengths.lastSegmentHorisontalLength = (p1_horiz - p0).length();
|
||||
|
||||
lengths.totalLength += lengths.lastSegmentLength;
|
||||
lengths.totalHorizontalLength += lengths.lastSegmentHorisontalLength;
|
||||
}
|
||||
|
||||
return lengths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -33,6 +33,23 @@ class RimMeasurement : public caf::PdmObject
|
||||
using Vec3d = cvf::Vec3d;
|
||||
|
||||
public:
|
||||
class Lengths
|
||||
{
|
||||
public:
|
||||
Lengths()
|
||||
: totalLength(0),
|
||||
lastSegmentLength(0),
|
||||
totalHorizontalLength(0),
|
||||
lastSegmentHorisontalLength(0),
|
||||
area(0) {}
|
||||
|
||||
double totalLength;
|
||||
double lastSegmentLength;
|
||||
double totalHorizontalLength;
|
||||
double lastSegmentHorisontalLength;
|
||||
double area;
|
||||
};
|
||||
|
||||
RimMeasurement();
|
||||
~RimMeasurement() override;
|
||||
|
||||
@ -42,7 +59,12 @@ public:
|
||||
void addPointInDomain(const Vec3d& pointInDomain);
|
||||
std::vector<Vec3d> pointsInDomain() const;
|
||||
|
||||
QString label() const;
|
||||
|
||||
private:
|
||||
Lengths calculateLenghts() const;
|
||||
|
||||
|
||||
void updateView() const;
|
||||
|
||||
bool m_isInMeasurementMode;
|
||||
|
@ -107,7 +107,7 @@
|
||||
#include "cvfRay.h"
|
||||
#include "RimTextAnnotation.h"
|
||||
|
||||
|
||||
#include "QDebug"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
@ -529,6 +529,14 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
|
||||
cvf::HitItemCollection hitItems;
|
||||
m_viewer->rayPick(winPosX, winPosY, &hitItems);
|
||||
|
||||
qDebug() << "Click: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
|
||||
for (size_t i = 0; i < hitItems.count(); i++)
|
||||
{
|
||||
const auto& item = hitItems.item(i);
|
||||
qDebug() << " Pt: " << QString("%1, %2, %3").arg(item->intersectionPoint().x()).arg(item->intersectionPoint().y()).arg(item->intersectionPoint().z());
|
||||
}
|
||||
qDebug() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
|
||||
|
||||
// Do specialized text pick, since vizfwk does not hit text
|
||||
handleTextPicking(winPosX, winPosY, &hitItems);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user