51 #include "RulerPlugin.hh" 57 RulerPlugin::RulerPlugin()
60 pickModeName_(
"MeasureDistance"),
62 dblClickCheck_(false),
64 textSizeSettingName_(name()+QString(
"/TextSize"))
70 RulerPlugin::~RulerPlugin()
75 void RulerPlugin::initializePlugin()
77 QToolBar *button =
new QToolBar(
"Ruler");
79 buttonAction_ =
new QAction(tr(
"<B>Ruler</B><br> Display the distance between two points."),
this);
81 button->addAction(buttonAction_);
82 buttonAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"ruler.png"));
83 buttonAction_->setCheckable(
true);
85 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>"));
87 buttonAction_->setChecked(
false);
89 connect(buttonAction_,SIGNAL(triggered()),
this , SLOT(slotChangePickMode()) );
90 emit addToolbar(button);
94 void RulerPlugin::pluginsInitialized()
96 emit addPickMode(pickModeName_);
100 void RulerPlugin::slotMouseEvent(QMouseEvent* _event)
107 if (_event->type() == QEvent::MouseButtonRelease )
109 unsigned int node_idx, target_idx;
121 currentRuler_.reset(
new Ruler(
object,name(),0));
122 connect(currentRuler_.get(),SIGNAL(updateView()),
this,SIGNAL(updateView()));
124 currentRuler_->setTextSize(textSize);
125 currentRuler_->setPoints(hitPoint,hitPoint);
133 if (!dragModeActive())
136 float distToStart = (currentRuler_->points()[0] - hitPoint).length();
137 float distToEnd = (currentRuler_->points()[1] - hitPoint).length();
138 if (distToStart < distToEnd)
139 currentRuler_->setStartPoint(hitPoint);
141 currentRuler_->setEndPoint(hitPoint);
147 currentRuler_->setStartPoint(hitPoint);
149 currentRuler_->setEndPoint(hitPoint);
161 else if (_event->type() == QEvent::MouseButtonPress)
168 unsigned int node_idx, target_idx;
174 float distToStart = (currentRuler_->points()[0] - hitPoint).length();
175 float distToEnd = (currentRuler_->points()[1] - hitPoint).length();
176 enableDragMode( (distToStart < distToEnd)? 0 : 1);
181 else if (_event->type() == QEvent::MouseMove && dragModeActive())
184 unsigned int node_idx, target_idx;
187 std::copy(currentRuler_->points(),currentRuler_->points()+2,hitPoints);
193 QPoint position = _event->pos();
196 hitPoints[lineDrag_] =
ACG::Vec3d(hitPoint.
data()[0], hitPoint.
data()[1], hitPoints[lineDrag_].
data()[2] );
199 hitPoints[lineDrag_] = hitPoint;
201 currentRuler_->setPoints(hitPoints[0],hitPoints[1]);
205 else if (_event->type() == QEvent::MouseButtonDblClick)
208 dblClickCheck_ =
true;
210 if (dblClickCheck_ && _event->type() == QEvent::MouseButtonRelease)
211 dblClickCheck_ =
false;
215 void RulerPlugin::reset()
217 currentRuler_.reset();
221 void RulerPlugin::enableDragMode(
const int _point)
224 emit setPickModeMouseTracking(pickModeName_,
true);
228 void RulerPlugin::disableDragMode()
231 emit setPickModeMouseTracking(pickModeName_,
false);
235 void RulerPlugin::slotChangePickMode()
243 void RulerPlugin::slotPickModeChanged(
const std::string& _mode)
245 buttonAction_->setChecked(_mode == pickModeName_);
249 void RulerPlugin::slotAllCleared()
254 void RulerPlugin::objectDeleted(
int _id)
260 if (_id == currentRuler_->getBaseObj()->id())
262 disconnect(currentRuler_.get(),SIGNAL(updateView()),
this,SIGNAL(updateView()));
263 currentRuler_.reset();
275 optionsWidget_->textSizeSpinBox->setValue(textSize);
276 _widget = optionsWidget_;
280 void RulerPlugin::applyOptions()
282 int textSize = optionsWidget_->textSizeSpinBox->value();
284 currentRuler_->setTextSize(textSize);
288 void RulerPlugin::slotViewChanged()
295 ACG::Vec3d lineVector = currentRuler_->points()[0] - currentRuler_->points()[1];
298 float cosAngleLineRight = lineVector.
normalize() | rightVec;
302 rightVec *= -0.5f*currentRuler_->textScale();
306 if (cosAngleLineRight > 0.f)
308 updownVec *= (cosAngleUpLine < 0.f) ? -2.f : 0.5f;
312 updownVec *= (cosAngleUpLine < 0.f) ? 0.5f : -2.0f;
316 currentRuler_->setTextOffset(rightVec+updownVec);
321 #if QT_VERSION < 0x050000 bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
ACG::GLState & glState()
Get the glState of the Viewer.
int context_height() const
get gl context height
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
const std::string pickMode()
Get the current Picking mode.
bool initializeOptionsWidget(QWidget *&_widget)
Initialize the Options Widget.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Viewer::ActionMode actionMode()
Get the current Action mode.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
pick any of the prior targets (should be implemented for all nodes)
VectorT< double, 3 > Vec3d
Scalar * data()
access to Scalar array