29 #include "MouseAndKeyPlugin.hh" 40 MouseAndKeyPlugin::MouseAndKeyPlugin() :
54 void MouseAndKeyPlugin::initializePlugin() {
57 emit registerKey(Qt::Key_J, Qt::NoModifier,
"Rotate object down");
58 emit registerKey(Qt::Key_K, Qt::NoModifier,
"Rotate object up");
59 emit registerKey(Qt::Key_H, Qt::NoModifier,
"Rotate object left");
60 emit registerKey(Qt::Key_L, Qt::NoModifier,
"Rotate object right");
62 tool_ =
new QWidget();
68 pickButton_ =
new QPushButton(tr(
"Select object"));
69 pickButton_->setCheckable(
true);
72 QLabel* label =
new QLabel();
73 label->setText(
"(De)activate pick mode");
76 QGridLayout* grid =
new QGridLayout;
77 grid->addWidget(label, 0, 0);
78 grid->addWidget(pickButton_, 1, 0);
80 tool_->setLayout(grid);
83 connect(pickButton_, SIGNAL(clicked()),
this, SLOT(slotButtonClicked()));
93 void MouseAndKeyPlugin::pluginsInitialized() {
96 emit addPickMode(
"MouseAndKeyPlugin");
101 contextMenuEntry_ =
new QMenu(
"Mouse and key plugin");
106 lastAction = contextMenuEntry_->addAction(
"Hide object" );
107 lastAction->setToolTip(
"Hide selected object");
108 lastAction->setStatusTip( lastAction->toolTip() );
116 connect(contextMenuEntry_, SIGNAL(triggered(QAction*)),
this, SLOT(contextMenuItemSelected(QAction*)));
124 void MouseAndKeyPlugin::slotButtonClicked() {
126 if(pickButton_->isChecked()) {
143 void MouseAndKeyPlugin::slotPickModeChanged(
const std::string& _mode) {
147 pickButton_->setChecked(_mode ==
"MouseAndKeyPlugin");
154 void MouseAndKeyPlugin::slotMouseEvent(QMouseEvent* _event) {
160 if (_event->type() == QEvent::MouseButtonDblClick) {
162 unsigned int node_idx, target_idx;
174 QDialog* dlg =
new QDialog;
176 QGridLayout* grid =
new QGridLayout;
177 QLabel* label =
new QLabel;
178 QString str = QString(
"You selected object ");
179 str += QString::number(node_idx);
181 grid->addWidget(label, 0,0);
183 dlg->setLayout(grid);
188 activeObject_ = node_idx;
208 void MouseAndKeyPlugin::slotKeyEvent( QKeyEvent* _event ) {
216 switch (_event->key())
221 object->manipulatorNode()->rotate(10.0, axis_x_);
227 object->manipulatorNode()->loadIdentity();
228 object->manipulatorNode()->rotate(-10.0, axis_x_);
234 object->manipulatorNode()->loadIdentity();
235 object->manipulatorNode()->rotate(10.0, axis_y_);
241 object->manipulatorNode()->loadIdentity();
242 object->manipulatorNode()->rotate(-10.0, axis_y_);
262 emit
log(
LOGINFO,
"No object has been selected to rotate! Select object first.");
273 template<
typename MeshT>
274 void MouseAndKeyPlugin::transformMesh(
ACG::Matrix4x4d _mat, MeshT& _mesh) {
276 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
277 typename MeshT::VertexIter v_end = _mesh.vertices_end();
281 for (; v_it != v_end; ++v_it) {
288 typename MeshT::FaceIter f_it = _mesh.faces_begin();
289 typename MeshT::FaceIter f_end = _mesh.faces_end();
292 for (; f_it != f_end; ++f_it)
301 void MouseAndKeyPlugin::contextMenuItemSelected(QAction* _action) {
304 QVariant contextObject = _action->data();
305 int objectId = contextObject.toInt();
307 if (objectId == -1) {
309 log(
LOGINFO,
"Could not get associated object id.");
320 log(
LOGINFO,
"Could not find associated object.");
Namespace providing different geometric functions concerning angles.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
pick any of the prior targets (should be implemented for all nodes)
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool dataType(DataType _type) const
void addToolbox(QString _name, QWidget *_widget)
Add a Toolbox from a plugin or from scripting.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
VectorT< double, 3 > Vec3d
const GLMatrixd & matrix() const
Returns a const reference to the current transformation matrix.
void updateView()
Called when a plugin requests an update in the viewer.
void transformMesh(ACG::Matrix4x4d _matrix, MeshT &_mesh)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Viewer::ActionMode actionMode()
Get the current Action mode.
#define DATA_TRIANGLE_MESH
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
The Menu will be shown when an object was picked.
void traverse(ACG::SceneGraph::MouseEventAction &_action)
QtTranslationManipulatorNode * manipulatorNode()
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
const std::string pickMode()
Get the current Picking mode.
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.