32 #include "MouseAndKeyPlugin.hh" 43 MouseAndKeyPlugin::MouseAndKeyPlugin() :
57 void MouseAndKeyPlugin::initializePlugin() {
60 emit registerKey(Qt::Key_J, Qt::NoModifier,
"Rotate object down");
61 emit registerKey(Qt::Key_K, Qt::NoModifier,
"Rotate object up");
62 emit registerKey(Qt::Key_H, Qt::NoModifier,
"Rotate object left");
63 emit registerKey(Qt::Key_L, Qt::NoModifier,
"Rotate object right");
65 tool_ =
new QWidget();
71 pickButton_ =
new QPushButton(tr(
"Select object"));
72 pickButton_->setCheckable(
true);
75 QLabel* label =
new QLabel();
76 label->setText(
"(De)activate pick mode");
79 QGridLayout* grid =
new QGridLayout;
80 grid->addWidget(label, 0, 0);
81 grid->addWidget(pickButton_, 1, 0);
83 tool_->setLayout(grid);
86 connect(pickButton_, SIGNAL(clicked()),
this, SLOT(slotButtonClicked()));
96 void MouseAndKeyPlugin::pluginsInitialized() {
99 emit addPickMode(
"MouseAndKeyPlugin");
104 contextMenuEntry_ =
new QMenu(
"Mouse and key plugin");
109 lastAction = contextMenuEntry_->addAction(
"Hide object" );
110 lastAction->setToolTip(
"Hide selected object");
111 lastAction->setStatusTip( lastAction->toolTip() );
119 connect(contextMenuEntry_, SIGNAL(triggered(QAction*)),
this, SLOT(contextMenuItemSelected(QAction*)));
127 void MouseAndKeyPlugin::slotButtonClicked() {
129 if(pickButton_->isChecked()) {
146 void MouseAndKeyPlugin::slotPickModeChanged(
const std::string& _mode) {
150 pickButton_->setChecked(_mode ==
"MouseAndKeyPlugin");
157 void MouseAndKeyPlugin::slotMouseEvent(QMouseEvent* _event) {
163 if (_event->type() == QEvent::MouseButtonDblClick) {
165 unsigned int node_idx, target_idx;
177 QDialog* dlg =
new QDialog;
179 QGridLayout* grid =
new QGridLayout;
180 QLabel* label =
new QLabel;
181 QString str = QString(
"You selected object ");
182 str += QString::number(node_idx);
184 grid->addWidget(label, 0,0);
186 dlg->setLayout(grid);
191 activeObject_ = node_idx;
211 void MouseAndKeyPlugin::slotKeyEvent( QKeyEvent* _event ) {
219 switch (_event->key())
224 object->manipulatorNode()->rotate(10.0, axis_x_);
230 object->manipulatorNode()->loadIdentity();
231 object->manipulatorNode()->rotate(-10.0, axis_x_);
237 object->manipulatorNode()->loadIdentity();
238 object->manipulatorNode()->rotate(10.0, axis_y_);
244 object->manipulatorNode()->loadIdentity();
245 object->manipulatorNode()->rotate(-10.0, axis_y_);
265 emit
log(
LOGINFO,
"No object has been selected to rotate! Select object first.");
276 template<
typename MeshT>
277 void MouseAndKeyPlugin::transformMesh(
ACG::Matrix4x4d _mat, MeshT& _mesh) {
279 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
280 typename MeshT::VertexIter v_end = _mesh.vertices_end();
284 for (; v_it != v_end; ++v_it) {
291 typename MeshT::FaceIter f_it = _mesh.faces_begin();
292 typename MeshT::FaceIter f_end = _mesh.faces_end();
295 for (; f_it != f_end; ++f_it)
304 void MouseAndKeyPlugin::contextMenuItemSelected(QAction* _action) {
307 QVariant contextObject = _action->data();
308 int objectId = contextObject.toInt();
310 if (objectId == -1) {
312 log(
LOGINFO,
"Could not get associated object id.");
323 log(
LOGINFO,
"Could not find associated object.");
void traverse(ACG::SceneGraph::MouseEventAction &_action)
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
void transformMesh(ACG::Matrix4x4d _matrix, MeshT &_mesh)
virtual void hide()
Sets the whole Scenegraph subtree of this node to invisible.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool dataType(DataType _type) const
The Menu will be shown when an object was picked.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
QtTranslationManipulatorNode * manipulatorNode()
void addToolbox(QString _name, QWidget *_widget)
Add a Toolbox from a plugin or from scripting.
const GLMatrixd & matrix() const
Returns a const reference to the current transformation matrix.
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...
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
Namespace providing different geometric functions concerning angles.
Viewer::ActionMode actionMode()
Get the current Action mode.
void updateView()
Called when a plugin requests an update in the viewer.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
pick any of the prior targets (should be implemented for all nodes)
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
VectorT< double, 3 > Vec3d
#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)
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.