42 #include "RulerPlugin.hh" 45 #include <OpenFlipper/BasePlugin/WhatsThisGenerator.hh> 49 RulerPlugin::RulerPlugin()
52 pickModeName_(
"MeasureDistance"),
54 dblClickCheck_(false),
56 textSizeSettingName_(name()+QString(
"/TextSize"))
62 RulerPlugin::~RulerPlugin()
67 void RulerPlugin::initializePlugin()
69 QToolBar *button =
new QToolBar(
"Ruler");
71 buttonAction_ =
new QAction(tr(
"<B>Ruler</B><br> Display the distance between two points."),
this);
73 button->addAction(buttonAction_);
74 buttonAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"ruler.png"));
75 buttonAction_->setCheckable(
true);
77 whatsThisGen.setWhatsThis(buttonAction_,tr(
"Measures the distance between two points.<br><b>LeftClick</b>: define/change the position.<br><b>DoubleClick</b>: reset the ruler.<br>"));
79 buttonAction_->setChecked(
false);
81 connect(buttonAction_,SIGNAL(triggered()),
this , SLOT(slotChangePickMode()) );
82 emit addToolbar(button);
86 void RulerPlugin::pluginsInitialized()
88 emit addPickMode(pickModeName_);
92 void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
99 if (_event->type() == QEvent::MouseButtonRelease )
101 size_t node_idx, target_idx;
113 currentRuler_.reset(
new Ruler(
object,name(),0));
114 connect(currentRuler_.get(),SIGNAL(updateView()),
this,SIGNAL(updateView()));
116 currentRuler_->setTextSize(textSize);
117 currentRuler_->setPoints(hitPoint,hitPoint);
125 if (!dragModeActive())
128 float distToStart = (currentRuler_->points()[0] - hitPoint).length();
129 float distToEnd = (currentRuler_->points()[1] - hitPoint).length();
130 if (distToStart < distToEnd)
131 currentRuler_->setStartPoint(hitPoint);
133 currentRuler_->setEndPoint(hitPoint);
139 currentRuler_->setStartPoint(hitPoint);
141 currentRuler_->setEndPoint(hitPoint);
153 else if (_event->type() == QEvent::MouseButtonPress)
160 size_t node_idx, target_idx;
166 float distToStart = (currentRuler_->points()[0] - hitPoint).length();
167 float distToEnd = (currentRuler_->points()[1] - hitPoint).length();
168 enableDragMode( (distToStart < distToEnd)? 0 : 1);
173 else if (_event->type() == QEvent::MouseMove && dragModeActive())
176 size_t node_idx, target_idx;
179 std::copy(currentRuler_->points(),currentRuler_->points()+2,hitPoints);
185 QPoint position = _event->pos();
188 hitPoints[lineDrag_] =
ACG::Vec3d(hitPoint.
data()[0], hitPoint.
data()[1], hitPoints[lineDrag_].
data()[2] );
191 hitPoints[lineDrag_] = hitPoint;
193 currentRuler_->setPoints(hitPoints[0],hitPoints[1]);
197 else if (_event->type() == QEvent::MouseButtonDblClick)
200 dblClickCheck_ =
true;
202 if (dblClickCheck_ && _event->type() == QEvent::MouseButtonRelease)
203 dblClickCheck_ =
false;
207 void RulerPlugin::reset()
209 currentRuler_.reset();
213 void RulerPlugin::enableDragMode(
const int _point)
216 emit setPickModeMouseTracking(pickModeName_,
true);
220 void RulerPlugin::disableDragMode()
223 emit setPickModeMouseTracking(pickModeName_,
false);
227 void RulerPlugin::slotChangePickMode()
235 void RulerPlugin::slotPickModeChanged(
const std::string& _mode)
237 buttonAction_->setChecked(_mode == pickModeName_);
241 void RulerPlugin::slotAllCleared()
246 void RulerPlugin::objectDeleted(
int _id)
252 if (_id == currentRuler_->getBaseObj()->id())
254 disconnect(currentRuler_.get(),SIGNAL(updateView()),
this,SIGNAL(updateView()));
255 currentRuler_.reset();
267 optionsWidget_->textSizeSpinBox->setValue(textSize);
268 _widget = optionsWidget_;
272 void RulerPlugin::applyOptions()
274 int textSize = optionsWidget_->textSizeSpinBox->value();
276 currentRuler_->setTextSize(textSize);
280 void RulerPlugin::slotViewChanged()
287 ACG::Vec3d lineVector = currentRuler_->points()[0] - currentRuler_->points()[1];
290 float cosAngleLineRight = lineVector.
normalize() | rightVec;
294 rightVec *= -0.5f*currentRuler_->textScale();
298 if (cosAngleLineRight > 0.f)
300 updownVec *= (cosAngleUpLine < 0.f) ? -2.f : 0.5f;
304 updownVec *= (cosAngleUpLine < 0.f) ? 0.5f : -2.0f;
308 currentRuler_->setTextOffset(rightVec+updownVec);
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
Scalar * data()
access to Scalar array
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Viewer::ActionMode actionMode()
Get the current Action mode.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
pick any of the prior targets (should be implemented for all nodes)
const std::string pickMode()
Get the current Picking mode.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
int context_height() const
get gl context height
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
VectorT< double, 3 > Vec3d
bool initializeOptionsWidget(QWidget *&_widget)
Initialize the Options Widget.
ACG::GLState & glState()
Get the glState of the Viewer.