Commit af0cc5d1 authored by Matthias Möller's avatar Matthias Möller
Browse files

add ruleroffset for better ruler position

refs #1626

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17432 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 035991c1
...@@ -9,6 +9,7 @@ Ruler::Ruler(BaseObjectData* _obj,const QString &_pluginName, unsigned index) ...@@ -9,6 +9,7 @@ Ruler::Ruler(BaseObjectData* _obj,const QString &_pluginName, unsigned index)
lineNode_(0), lineNode_(0),
textNode_(0), textNode_(0),
textTransformNode_(0), textTransformNode_(0),
offset_(),
obj_(_obj) obj_(_obj)
{ {
points_[0] = points_[1] = ACG::Vec3d(0.0,0.0,0.0); points_[0] = points_[1] = ACG::Vec3d(0.0,0.0,0.0);
...@@ -89,11 +90,18 @@ void Ruler::updateNodes() ...@@ -89,11 +90,18 @@ void Ruler::updateNodes()
textNode_->setText(distanceStr.toStdString()); textNode_->setText(distanceStr.toStdString());
textNode_->multipassNodeSetActive(8, true); textNode_->multipassNodeSetActive(8, true);
//translate and scale text //translate
textTransformNode_->loadIdentity(); setTextOffset(offset_);
textTransformNode_->translate(Point1);
ACG::Vec3d halfDist = distVec/2.f;
textTransformNode_->translate(-halfDist);
emit updateView(); emit updateView();
} }
void Ruler::setTextOffset(const ACG::Vec3d& offset)
{
offset_ = offset;
ACG::Vec3d distVec = points_[0] - points_[1];
ACG::Vec3d halfDist = distVec/2.f;
textTransformNode_->loadIdentity();
textTransformNode_->translate((points_[0]-halfDist)+offset_);
}
...@@ -65,13 +65,17 @@ public: ...@@ -65,13 +65,17 @@ public:
void setPoints(const ACG::Vec3d& _start,const ACG::Vec3d& _end); void setPoints(const ACG::Vec3d& _start,const ACG::Vec3d& _end);
void setStartPoint(const ACG::Vec3d& _start); void setStartPoint(const ACG::Vec3d& _start);
void setEndPoint(const ACG::Vec3d& _end); void setEndPoint(const ACG::Vec3d& _end);
void setTextOffset(const ACG::Vec3d& offset);
const ACG::Vec3d* points() const{return points_;} const ACG::Vec3d* points() const{return points_;}
const BaseObject* getBaseObj(){return obj_;} const BaseObject* getBaseObj(){return obj_;}
float textScale(){return textNode_->lastScale();}
public slots: public slots:
// set text size in pixels
void setTextSize(const unsigned _size){textNode_->setPixelSize(_size); emit updateView();} void setTextSize(const unsigned _size){textNode_->setPixelSize(_size); emit updateView();}
private: private:
...@@ -88,5 +92,6 @@ private: ...@@ -88,5 +92,6 @@ private:
ACG::SceneGraph::TransformNode* textTransformNode_; ACG::SceneGraph::TransformNode* textTransformNode_;
ACG::Vec3d points_[2]; ACG::Vec3d points_[2];
ACG::Vec3d offset_;
BaseObjectData* obj_; BaseObjectData* obj_;
}; };
...@@ -53,6 +53,7 @@ buttonAction_(0), ...@@ -53,6 +53,7 @@ buttonAction_(0),
pickModeName_("MeasureDistance"), pickModeName_("MeasureDistance"),
lineDrag_(-1), lineDrag_(-1),
dblClickCheck_(false), dblClickCheck_(false),
viewupdated_(false),
optionsWidget_(0), optionsWidget_(0),
textSizeSettingName_(name()+QString("/TextSize")) textSizeSettingName_(name()+QString("/TextSize"))
{ {
...@@ -194,11 +195,10 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event) ...@@ -194,11 +195,10 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
currentRuler_->setPoints(hitPoints[0],hitPoints[1]); currentRuler_->setPoints(hitPoints[0],hitPoints[1]);
} }
///////////////////////Reset/////////////////////////////////
else if (_event->type() == QEvent::MouseButtonDblClick) else if (_event->type() == QEvent::MouseButtonDblClick)
{//reset {//reset
reset(); reset();
currentRuler_.reset();
dblClickCheck_ = true; dblClickCheck_ = true;
} }
if (dblClickCheck_ && _event->type() == QEvent::MouseButtonRelease) if (dblClickCheck_ && _event->type() == QEvent::MouseButtonRelease)
...@@ -208,6 +208,7 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event) ...@@ -208,6 +208,7 @@ void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void RulerPlugin::reset() void RulerPlugin::reset()
{ {
currentRuler_.reset();
lineDrag_ = -1; lineDrag_ = -1;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -277,6 +278,49 @@ void RulerPlugin::applyOptions() ...@@ -277,6 +278,49 @@ void RulerPlugin::applyOptions()
currentRuler_->setTextSize(textSize); currentRuler_->setTextSize(textSize);
OpenFlipperSettings().setValue(textSizeSettingName_,textSize); OpenFlipperSettings().setValue(textSizeSettingName_,textSize);
} }
//------------------------------------------------------------------------------
void RulerPlugin::slotViewChanged()
{
if (!currentRuler_)
return;
// check, if this function requested a viewupdate
if (viewupdated_)
{
viewupdated_ = false;
return;
}
//compute line direction
ACG::Vec3d lineVector = currentRuler_->points()[0] - currentRuler_->points()[1];
ACG::Vec3d rightVec = (PluginFunctions::viewingDirection() % -PluginFunctions::upVector()).normalize();
float cosAngleLineRight = lineVector.normalize() | rightVec;
float cosAngleUpLine = PluginFunctions::upVector().normalized() | lineVector.normalized() ;
rightVec *= -0.5f*currentRuler_->textScale();
ACG::Vec3d updownVec = PluginFunctions::upVector()*currentRuler_->textScale();
//compute up/down offset
if (cosAngleLineRight > 0.f)
{
updownVec *= (cosAngleUpLine < 0.f) ? -2.f : 0.5f;
}
else
{
updownVec *= (cosAngleUpLine < 0.f) ? 0.5f : -2.0f;
}
// small offset to the right and big offset up/down depending on the line
currentRuler_->setTextOffset(rightVec+updownVec);
viewupdated_ = true;
emit updateView();
}
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( rulerPlugin , RulerPlugin ); Q_EXPORT_PLUGIN2( rulerPlugin , RulerPlugin );
......
...@@ -55,10 +55,6 @@ ...@@ -55,10 +55,6 @@
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh> #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/OptionsInterface.hh> #include <OpenFlipper/BasePlugin/OptionsInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "Ruler.hh" #include "Ruler.hh"
#include "RulerOptions.hh" #include "RulerOptions.hh"
...@@ -91,7 +87,7 @@ public slots: ...@@ -91,7 +87,7 @@ public slots:
void slotMouseEvent(QMouseEvent* _event); void slotMouseEvent(QMouseEvent* _event);
void slotViewChanged();
public: public:
// OptionsInterface // OptionsInterface
...@@ -123,6 +119,8 @@ private: ...@@ -123,6 +119,8 @@ private:
//checks if a double click was provided for resetting //checks if a double click was provided for resetting
bool dblClickCheck_; bool dblClickCheck_;
bool viewupdated_;
ptr::shared_ptr<Ruler> currentRuler_; ptr::shared_ptr<Ruler> currentRuler_;
RulerOptions* optionsWidget_; RulerOptions* optionsWidget_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment