MovePlugin.cc 96.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49

Matthias Möller's avatar
Matthias Möller committed
50

Jan Möbius's avatar
 
Jan Möbius committed
51 52 53 54 55 56 57
#include "MovePlugin.hh"

#include <MeshTools/MeshInfoT.hh>

#ifdef USE_OPENMP
#endif

58
#if QT_VERSION >= 0x050000
59 60 61 62
#else
#include <QtGui>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
63 64 65 66
#ifdef ENABLE_POLYLINE_SUPPORT
#include <ObjectTypes/PolyLine/PolyLine.hh>
#endif

Henrik Zimmer's avatar
Henrik Zimmer committed
67 68 69
#ifdef ENABLE_TSPLINEMESH_SUPPORT
#include <ObjectTypes/TSplineMesh/TSplineMesh.hh>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
70

Dirk Wilden's avatar
Dirk Wilden committed
71 72 73 74
#ifdef ENABLE_SKELETON_SUPPORT
#include <ObjectTypes/Skeleton/Helper/SkeletonTransform.hh>
#endif

75
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
76 77 78
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif

79
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
80 81 82
#include <ObjectTypes/TetrahedralMesh/TetrahedralMesh.hh>
#endif

83
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
84 85 86
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
87
/** \brief Default Constructor
88
 *
Jan Möbius's avatar
 
Jan Möbius committed
89
 */
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
90
MovePlugin::MovePlugin() :
Jan Möbius's avatar
Jan Möbius committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
axisA_(0),
axisB_(1),
toolboxActive_(false),
tool_(0),
toolIcon_(0),
moveAction_(0),
moveSelectionAction_(0),
toolBarActions_(0),
toolbar_(0),
pickToolbar_(0),
placeAction_(0),
rotateTranslateAction_(0),
rotateManipAction_(0),
resizeAction_(0),
biggerManipAction_(0),
smallerManipAction_(0),
fixChildManipAction_(0),
transformRefPoseManipAction_(0),
currentPoseManipAction_(0),
placeAndSnapAction_(0),
pickToolBarActions_(0),
manip_size_(1.0),
manip_size_modifier_(1.0),
lastActiveManipulator_(-1),
manMode_(QtTranslationManipulatorNode::TranslationRotation),
selectionType_(VERTEX),
contextAction_(0),
contextActionHide_(0),
toAllTargets_(0),
120 121
contextMenuManipControl_(0),
contextMenuManipControlsAction_(0),
Jan Möbius's avatar
Jan Möbius committed
122 123
hide_(true),
allTargets_(false),
124 125
placeMode_(false),
transformedSelected_(false)
Jan Möbius's avatar
 
Jan Möbius committed
126 127 128 129
{

}

130 131 132 133 134 135 136 137 138
/** \brief Deconstructor
 *
 */
MovePlugin::~MovePlugin() {

	if(contextAction_) {
		delete contextAction_;
	}

Jan Möbius's avatar
Jan Möbius committed
139 140 141 142
  if(contextActionHide_) {
    delete contextActionHide_;
  }

143 144 145 146 147 148 149 150 151 152 153 154 155
	if(toAllTargets_) {
		delete toAllTargets_;
	}

	for(QList<movePropsWidget*>::iterator it = propsWindows_.begin();
		it != propsWindows_.end(); ++it) {

		if(*it) {
			delete *it;
		}
	}
}

Jan Möbius's avatar
 
Jan Möbius committed
156 157 158 159 160 161

/*******************************************************************************
        BaseInterface implementation
 *******************************************************************************/

/** \brief Initialization of the plugin when it is loaded by the core
162
 *
Jan Möbius's avatar
 
Jan Möbius committed
163 164 165 166 167 168 169 170 171 172
 */
void MovePlugin::pluginsInitialized() {

  //PICKMODES
  emit addPickMode("Separator");
  emit addHiddenPickMode("Move");
  emit setPickModeMouseTracking ("Move", true);
  emit addHiddenPickMode("MoveSelection");
  emit setPickModeMouseTracking ("MoveSelection", true);

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
173
  //KEYS
Mike Kremer's avatar
Mike Kremer committed
174
  emit registerKey (Qt::Key_Shift, Qt::NoModifier, tr("Manipulator rotation"), true);
Jan Möbius's avatar
Jan Möbius committed
175
  emit registerKey (Qt::Key_Shift, Qt::ShiftModifier, tr("Manipulator rotation"), true);
176
  emit registerKey (Qt::Key_Shift, Qt::ControlModifier | Qt::ShiftModifier, tr("Manipulator rotation"), true);
Mike Kremer's avatar
Mike Kremer committed
177
  emit registerKey (Qt::Key_Control, Qt::NoModifier, tr("Resize"), true);
Jan Möbius's avatar
Jan Möbius committed
178
  emit registerKey (Qt::Key_Control, Qt::ControlModifier, tr("Resize"), true);
Mike Kremer's avatar
Mike Kremer committed
179
  emit registerKey (Qt::Key_Control, Qt::ShiftModifier | Qt::ControlModifier, tr("Resize"), true);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
180

Jan Möbius's avatar
 
Jan Möbius committed
181 182
  //SCRIPTING SLOT DESCRIPTIONS
  setDescriptions();
183

184 185 186
  // ==================================
  // Toolbar
  // ==================================
187 188 189 190

  WhatsThisGenerator whatsThis("Move");
  WhatsThisGenerator whatsThisUser("user");

Jan Möbius's avatar
Jan Möbius committed
191
  toolbar_ = new QToolBar(tr("Transform and Move"));
192
  toolbar_->setObjectName("TransformAndMoveToolBar");
Jan Möbius's avatar
 
Jan Möbius committed
193 194 195

  toolBarActions_ = new QActionGroup(toolbar_);

196
  moveAction_ = new QAction(tr("<B>Move Object</B><br>Move an object in 3D"), toolBarActions_);
Jan Möbius's avatar
 
Jan Möbius committed
197 198 199
  moveAction_->setStatusTip(tr("Move object in 3D."));
  moveAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-objects.png") );
  moveAction_->setCheckable(true);
200
  whatsThis.setWhatsThis(moveAction_,tr("Move the whole object."));
Jan Möbius's avatar
 
Jan Möbius committed
201 202
  toolbar_->addAction(moveAction_);

203
  moveSelectionAction_ = new QAction(tr("<B>Move Selection</B><br>Move a selection on an object"), toolBarActions_);
Jan Möbius's avatar
 
Jan Möbius committed
204 205 206
  moveSelectionAction_->setStatusTip(tr("Move selections in 3D."));
  moveSelectionAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-selections.png") );
  moveSelectionAction_->setCheckable(true);
207
  whatsThis.setWhatsThis(moveSelectionAction_,tr("Move only a selection."));
Jan Möbius's avatar
 
Jan Möbius committed
208
  toolbar_->addAction(moveSelectionAction_);
209
  
Jan Möbius's avatar
 
Jan Möbius committed
210 211 212
  connect(toolBarActions_, SIGNAL(triggered(QAction*)), this, SLOT(slotSetMoveMode(QAction*)) );

  emit addToolbar(toolbar_);
213

214 215 216 217
  // ==================================
  // Pick Toolbar
  // ==================================

218 219 220
  pickToolbar_ = new QToolBar(tr("Transform and Move PickTool bar"));
  pickToolbar_->setObjectName("TransformAndMovePickToolBar");

221
  pickToolbar_->setAttribute(Qt::WA_AlwaysShowToolTips, true);
222 223 224 225 226
  pickToolBarActions_ = new QActionGroup(pickToolbar_);
  pickToolBarActions_->setExclusive (false);

  placeAction_ = new QAction(tr("Place manipulator"), pickToolBarActions_);
  placeAction_->setStatusTip(tr("Place manipulator on object. <Doubleclick>"));
227
  placeAction_->setToolTip(tr("Place manipulator on object. <Doubleclick>"));
228
  placeAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-place.png") );
229
  whatsThisUser.setWhatsThis(placeAction_,tr("Place the manipulator."),"obj_man","manipulator.html");
230 231 232 233 234
  placeAction_->setCheckable(true);
  pickToolbar_->addAction(placeAction_);

  pickToolbar_->addSeparator ();

235 236
  rotateTranslateAction_ = new QAction(tr("Rotate/Translate object"), pickToolBarActions_);
  rotateTranslateAction_->setStatusTip(tr("Rotate/Translate object."));
237
  rotateTranslateAction_->setToolTip(tr("Rotate/Translate object."));
238 239 240
  rotateTranslateAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-translaterotate.png") );
  rotateTranslateAction_->setCheckable(true);
  rotateTranslateAction_->setChecked(true);
241
  whatsThisUser.setWhatsThis(rotateTranslateAction_,tr("Rotate or translate an object or selection."),"obj_translation","manipulator.html");
242
  pickToolbar_->addAction(rotateTranslateAction_);
243 244 245

  resizeAction_ = new QAction(tr("Resize object"), pickToolBarActions_);
  resizeAction_->setStatusTip(tr("Resize object. <Control>"));
246
  resizeAction_->setToolTip(tr("Resize object. <Control>"));
247
  resizeAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-resize.png") );
248
  whatsThisUser.setWhatsThis(resizeAction_,tr("Resize object or selection."),"obj_resizing","manipulator.html");
249 250 251 252 253
  resizeAction_->setCheckable(true);
  pickToolbar_->addAction(resizeAction_);

  pickToolbar_->addSeparator ();

254 255
  rotateManipAction_ = new QAction(tr("Rotate manipulator"), pickToolBarActions_);
  rotateManipAction_->setStatusTip(tr("Rotate manipulator. <Shift>"));
256
  rotateManipAction_->setToolTip(tr("Rotate manipulator. <Shift>"));
257
  rotateManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-maniprotate.png") );
258
  whatsThisUser.setWhatsThis(rotateManipAction_,tr("Rotate only the Manipulator."),"man_rotating","manipulator.html");
259 260
  rotateManipAction_->setCheckable(true);
  pickToolbar_->addAction(rotateManipAction_);
261

262 263
  placeAndSnapAction_ = new QAction(tr("Locally translate manipulator"), pickToolBarActions_);
  placeAndSnapAction_->setStatusTip(tr("Locally translate manipulator. Press and hold <Alt> for snapping."));
264
  whatsThisUser.setWhatsThis(placeAndSnapAction_,tr("Translate only the Manipulator."),"man_translation","manipulator.html");
Mike Kremer's avatar
Mike Kremer committed
265
  placeAndSnapAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-placeandsnap.png") );
266 267 268
  placeAndSnapAction_->setCheckable(true);
  pickToolbar_->addAction(placeAndSnapAction_);

269 270
  smallerManipAction_ = new QAction(tr("Decrease size of manipulator"), pickToolBarActions_);
  smallerManipAction_->setStatusTip(tr("Make manipulator smaller. <Mouse wheel up>"));
271
  smallerManipAction_->setToolTip(tr("Make manipulator smaller. <Mouse wheel up>"));
272
  whatsThisUser.setWhatsThis(smallerManipAction_,tr("Resize the Manipulator to a smaller one."),"man_resizing","manipulator.html");
273 274 275 276
  smallerManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-manipsmall.png") );
  smallerManipAction_->setCheckable(false);
  pickToolbar_->addAction(smallerManipAction_);

Jan Möbius's avatar
Jan Möbius committed
277
  biggerManipAction_ = new QAction(tr("Increase size of manipulator"), pickToolBarActions_);
278
  biggerManipAction_->setStatusTip(tr("Make manipulator bigger. <Mouse wheel down>"));
279
  biggerManipAction_->setToolTip(tr("Make manipulator bigger. <Mouse wheel down>"));
280
  whatsThisUser.setWhatsThis(biggerManipAction_,tr("Resize the Manipulator to a bigger one."),"man_resizing","manipulator.html");
281 282 283
  biggerManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-manipbig.png") );
  biggerManipAction_->setCheckable(false);
  pickToolbar_->addAction(biggerManipAction_);
284
  
285 286 287 288
  connect(pickToolBarActions_, SIGNAL(triggered(QAction*)), this, SLOT(slotPickToolbarAction(QAction*)) );

  emit setPickModeToolbar ("Move", pickToolbar_);
  emit setPickModeToolbar ("MoveSelection", pickToolbar_);
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

  // ==================================
  // CONTEXT MENU
  // ==================================
  toAllTargets_ = new QAction(tr("Apply to all targets"), this);
  toAllTargets_->setCheckable(true);
  toAllTargets_->setToolTip(tr("Apply transformation to all target objects"));
  toAllTargets_->setStatusTip( toAllTargets_->toolTip() );

  contextAction_ = new QAction(tr("Set properties"), this);
  contextAction_->setToolTip(tr("Set properties"));
  contextAction_->setStatusTip( contextAction_->toolTip() );
  contextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-properties.png") );

  contextActionHide_ = new QAction(tr("Hide Manipulator"), this);
  contextActionHide_->setToolTip(tr("Hide Manipulator"));
  contextActionHide_->setStatusTip( contextActionHide_->toolTip() );
  contextActionHide_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-hide.png") );

  // QMenu replicating the relevant pick toolbar actions
  contextMenuManipControl_ = new QMenu(tr("Manipulator Controls"));
  contextMenuManipControl_->addAction(rotateTranslateAction_);
  contextMenuManipControl_->addAction(resizeAction_);
  contextMenuManipControl_->addAction(rotateManipAction_);
  contextMenuManipControl_->addAction(placeAndSnapAction_);
  contextMenuManipControl_->addAction(smallerManipAction_);
  contextMenuManipControl_->addAction(biggerManipAction_);


  contextMenuManipControlsAction_ = contextMenuManipControl_->menuAction();

  emit addContextMenuItem(toAllTargets_                   , CONTEXTNODEMENU );
  emit addContextMenuItem(contextAction_                  , CONTEXTNODEMENU );
  emit addContextMenuItem(contextActionHide_              , CONTEXTNODEMENU );
  emit addContextMenuItem(contextMenuManipControlsAction_ , CONTEXTNODEMENU );

  connect( toAllTargets_  ,     SIGNAL(toggled(bool) ), this, SLOT(setAllTargets(bool)));
  connect( contextAction_ ,     SIGNAL( triggered() ),  this, SLOT(showProps()) );
  connect( contextActionHide_ , SIGNAL( triggered() ),  this, SLOT(hideManipulator()) );
Jan Möbius's avatar
 
Jan Möbius committed
328 329 330 331 332 333 334
}


/*******************************************************************************
        ToolBoxInterface implementation
 *******************************************************************************/

Jan Möbius's avatar
Jan Möbius committed
335
void MovePlugin::initializePlugin()
Jan Möbius's avatar
 
Jan Möbius committed
336 337 338 339 340 341 342 343
{
   toolboxActive_ = false;
   tool_ = new moveToolbarWidget();

   connect(tool_->moveToOrigin,SIGNAL(clicked() ),this,SLOT(slotMoveToOrigin()));

   tool_->moveToOrigin->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "moveToCOG.png") );
   tool_->moveToOrigin->setIconSize(QSize(48,48));
344 345 346
   WhatsThisGenerator whatsThis("Move");
   tool_->moveToOrigin->setWhatsThis(QString(tr("Moves the selected objects such that their center of gravity is at the origin."))
       +whatsThis.generateLink("move_cog"));
Jan Möbius's avatar
 
Jan Möbius committed
347 348 349 350

   connect(tool_->unifyBoundingBoxDiagonal,SIGNAL(clicked() ),this,SLOT(slotUnifyBoundingBoxDiagonal()));
   tool_->unifyBoundingBoxDiagonal->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "unifyBB.png") );
   tool_->unifyBoundingBoxDiagonal->setIconSize(QSize(48,48));
351 352
   tool_->unifyBoundingBoxDiagonal->setWhatsThis(QString(tr("Rescale objects such that its bounding box diagonal has length one."))
          +whatsThis.generateLink("unifyBB"));
Jan Möbius's avatar
 
Jan Möbius committed
353

354
   connect(tool_->unifyBoundingBoxLongest,SIGNAL(clicked() ),this,SLOT(slotUnifyBoundingBoxLongestAxis()));
355
   tool_->unifyBoundingBoxLongest->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "unifyBB_longest.png") );
356 357 358
   tool_->unifyBoundingBoxLongest->setIconSize(QSize(48,48));

   connect(tool_->unifyBoundingBoxAll,SIGNAL(clicked() ),this,SLOT(slotUnifyBoundingBoxAllAxis()));
359
   tool_->unifyBoundingBoxAll->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "unifyBB_all.png") );
360 361
   tool_->unifyBoundingBoxAll->setIconSize(QSize(48,48));

Jan Möbius's avatar
 
Jan Möbius committed
362 363
   lastActiveManipulator_ = -1;

Dirk Wilden's avatar
Dirk Wilden committed
364 365
   toolIcon_ = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-toolBox.png");
   emit addToolbox( tr("Move") , tool_, toolIcon_ );
Jan Möbius's avatar
 
Jan Möbius committed
366 367 368 369 370 371 372 373 374
}


/*******************************************************************************
        MouseInterface implementation
 *******************************************************************************/

void MovePlugin::slotMouseWheelEvent(QWheelEvent * _event, const std::string & /*_mode*/)
{
375
  // Skip execution if this is not our pick mode
376
  if( ( (PluginFunctions::pickMode() != "Move")
Dirk Wilden's avatar
Dirk Wilden committed
377
     && (PluginFunctions::pickMode() != "MoveSelection") )
378
    || PluginFunctions::actionMode() != Viewer::PickingMode)
379 380 381 382
    return;
  
  // compute the manipulator size modifier based on the mouse wheel change
  manip_size_modifier_ = manip_size_modifier_ - (float)_event->delta() / 120.0 * 0.1;
383 384 385 386

  //dont scroll into negative sizes
  if (manip_size_modifier_ < 0.0)
    manip_size_modifier_ = 0.0;
387 388 389 390 391 392 393
  
  // Resize all manipulators based on the modifier on all objects
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
      o_it->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);

  // Redraw scene with updated manipulators
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
394 395 396 397 398 399
}


//------------------------------------------------------------------------------

/** \brief MousePress event occured
400
 *
Jan Möbius's avatar
 
Jan Möbius committed
401 402
 * @param _event the event that occured
 */
403
void MovePlugin::slotMouseEvent(QMouseEvent* _event) {
404
    if (((PluginFunctions::pickMode() == ("Move"))
Dirk Wilden's avatar
Dirk Wilden committed
405
      || (PluginFunctions::pickMode() == ("MoveSelection")))
406
            && PluginFunctions::actionMode() == Viewer::PickingMode) {
Jan Möbius's avatar
 
Jan Möbius committed
407

408 409
        if (_event->type() == QEvent::MouseButtonDblClick || (_event->type() == QEvent::MouseButtonPress
                && _event->button() == Qt::LeftButton && (placeAction_->isChecked() || placeMode_))) {
Dirk Wilden's avatar
Dirk Wilden committed
410 411

            bool snap = (placeMode_ && (PluginFunctions::pickMode() == ("MoveSelection")));
Jan Möbius's avatar
 
Jan Möbius committed
412

413
            placeManip(_event, snap);
414 415
            placeAction_->setChecked(false);
            updateManipulatorDialog();
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
416

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
            if (placeMode_) {
                manMode_ = QtTranslationManipulatorNode::TranslationRotation;

                for (PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS); o_it
                        != PluginFunctions::objectsEnd(); ++o_it)
                    if (o_it->manipPlaced())
                        o_it->manipulatorNode()->setMode(manMode_);

                resizeAction_->setChecked(false);
                rotateManipAction_->setChecked(false);
                rotateTranslateAction_->setChecked(true);
                placeAndSnapAction_->setChecked(false);
            }

            placeMode_ = false;
            return;

        } else if (placeMode_) {

            /*
             * Move manipulator along with cursor if placeAndSnap mode
             * is active. Snap to nearest geometry element (vertex, line, face center)
             * depending on which selection type is active.
440
             *
441 442
             */

443
            placeManip(_event, (PluginFunctions::pickMode() != ("Move")));
444 445 446 447 448
            updateManipulatorDialog();
            return;
        }

        // interaction
449
        ACG::SceneGraph::MouseEventAction action(_event,PluginFunctions::viewerProperties().glState());
450 451 452
        PluginFunctions::traverse(action);

        if (_event->buttons() == Qt::LeftButton)
453
          emit nodeVisibilityChanged(-1);
454 455

    }
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
456 457 458 459 460 461 462 463
}

/*******************************************************************************
        KeyInterface implementation
 *******************************************************************************/

void MovePlugin::slotKeyEvent (QKeyEvent* _event)
{
464
  if ((_event->key() == Qt::Key_Control) && _event->modifiers() != Qt::ShiftModifier) {
465
    setManipMode (QtTranslationManipulatorNode::Resize);
466 467
    return;
  } else if ((_event->key () == Qt::Key_Shift) && _event->modifiers() != Qt::ControlModifier) {
468
    setManipMode (QtTranslationManipulatorNode::LocalRotation);
469 470 471 472 473 474
    return;
  }

  // Return to normal mode if Ctrl + Shift is pressed since this
  // is used in translation manipulator node for rotation rasterization
  setManipMode (QtTranslationManipulatorNode::TranslationRotation);
Jan Möbius's avatar
 
Jan Möbius committed
475 476
}

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
477 478
//------------------------------------------------------------------------------

479 480
void MovePlugin::slotEnableSelectionMode()
{
481
  PluginFunctions::pickMode("MoveSelection");
482 483 484 485 486 487 488 489 490
}

//------------------------------------------------------------------------------
void MovePlugin::slotEnableObjectMode()
{
  PluginFunctions::pickMode("Move");
}
//------------------------------------------------------------------------------

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
491 492 493 494
void MovePlugin::slotKeyReleaseEvent (QKeyEvent* _event)
{
  if ((_event->key() == Qt::Key_Control && manMode_ == QtTranslationManipulatorNode::Resize) ||
      (_event->key() == Qt::Key_Shift && manMode_ == QtTranslationManipulatorNode::LocalRotation))
495
    setManipMode (QtTranslationManipulatorNode::TranslationRotation);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
496
}
Jan Möbius's avatar
 
Jan Möbius committed
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
void MovePlugin::setPickModeProps(movePropsWidget* _pW, const std::string &_pickmode)
{
  if (_pickmode == "Move")
  {
    _pW->objectRadioButton->setChecked(true);
  }
  else if (_pickmode == "MoveSelection")
  {
    _pW->selectionRadioButton->setChecked(true);
  }
  else
  {
    //not supported, so deselect all radio buttons
    _pW->objectRadioButton->setAutoExclusive(false);
    _pW->selectionRadioButton->setAutoExclusive(false);
    _pW->objectRadioButton->setChecked(false);
    _pW->selectionRadioButton->setChecked(false);
    _pW->objectRadioButton->setAutoExclusive(true);
    _pW->selectionRadioButton->setAutoExclusive(true);
  }
}

Jan Möbius's avatar
 
Jan Möbius committed
520 521 522 523 524
/*******************************************************************************
        PickingInterface implementation
 *******************************************************************************/

/** \brief slot is called when the pickMode changed
525
 *
Jan Möbius's avatar
 
Jan Möbius committed
526 527 528 529
 * @param _mode new pickMode
 */
void MovePlugin::slotPickModeChanged( const std::string& _mode)
{
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
530 531
  moveAction_->setChecked(_mode == "Move");
  moveSelectionAction_->setChecked(_mode == "MoveSelection");
532

Dirk Wilden's avatar
Dirk Wilden committed
533
  hide_ = !(_mode == "Move" || _mode == "MoveSelection");
Jan Möbius's avatar
 
Jan Möbius committed
534

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
535 536 537 538 539 540
  showManipulators();

  if (!hide_)
  {
    switch (manMode_)
    {
541 542 543
      case QtTranslationManipulatorNode::Rotation:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
544 545 546 547 548 549
      case QtTranslationManipulatorNode::Resize:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
      case QtTranslationManipulatorNode::LocalRotation:
        PluginFunctions::setViewObjectMarker (&objectMarker_);
        break;
550 551 552
      case QtTranslationManipulatorNode::Place:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
553 554 555 556 557 558 559
      case QtTranslationManipulatorNode::TranslationRotation:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
    }
  }
  else
    PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
560 561

  //change the selection mode in propety widget
562
  for (int i = 0; i < propsWindows_.size(); ++i)
563 564
    setPickModeProps(propsWindows_[i], _mode);

Jan Möbius's avatar
 
Jan Möbius committed
565 566 567 568 569 570 571 572
}


/*******************************************************************************
        MovePlugin implementation
 *******************************************************************************/

/** \brief Move object with given transformation matrix
573
 *
Jan Möbius's avatar
 
Jan Möbius committed
574 575 576 577 578
 * @param mat transformation matrix
 * @param _id id of the object
 */
void MovePlugin::moveObject(ACG::Matrix4x4d mat, int _id) {
  BaseObjectData* object;
Dirk Wilden's avatar
Dirk Wilden committed
579
  if ( ! PluginFunctions::getObject(_id,object) )
Jan Möbius's avatar
 
Jan Möbius committed
580 581
    return;

Dirk Wilden's avatar
Dirk Wilden committed
582 583 584
  if ( mat.is_identity() )
    return;

585 586 587 588
  if  ( object->dataType()  == DATA_TRIANGLE_MESH ) {
    transformMesh(mat , *PluginFunctions::triMesh(object) );
  } else  if  ( object->dataType()  == DATA_POLY_MESH ) {
    transformMesh(mat , *PluginFunctions::polyMesh(object) );
Henrik Zimmer's avatar
Henrik Zimmer committed
589 590 591 592
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  } else  if  ( object->dataType()  == DATA_TSPLINE_MESH ) {
    transformMesh(mat , *PluginFunctions::tsplineMesh(object) );
#endif
593
#ifdef ENABLE_POLYLINE_SUPPORT
594 595
  } else  if  ( object->dataType()  == DATA_POLY_LINE ) {
    transformPolyLine(mat , *PluginFunctions::polyLine(object) );
Dirk Wilden's avatar
Dirk Wilden committed
596 597 598 599
#endif
#ifdef ENABLE_SKELETON_SUPPORT
  } else  if  ( object->dataType()  == DATA_SKELETON ) {
    transformSkeleton(mat , *PluginFunctions::skeleton(object) );
600
#endif
601
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
602 603 604 605
  } else  if  ( object->dataType()  == DATA_HEXAHEDRAL_MESH ) {
    HexahedralMeshObject* obj = PluginFunctions::hexahedralMeshObject(object);
    transformVolumeMesh(mat , *obj->mesh() , obj->normals() );
#endif
606
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
607 608 609 610
  } else  if  ( object->dataType()  == DATA_TETRAHEDRAL_MESH ) {
    TetrahedralMeshObject* obj = PluginFunctions::tetrahedralMeshObject(object);
    transformVolumeMesh(mat , *obj->mesh() , obj->normals() );
#endif
611
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
612 613 614
  } else  if  ( object->dataType()  == DATA_POLYHEDRAL_MESH ) {
    PolyhedralMeshObject* obj = PluginFunctions::polyhedralMeshObject(object);
    transformVolumeMesh(mat , *obj->mesh() , obj->normals() );
615
#endif
Dirk Wilden's avatar
Dirk Wilden committed
616
  } else  if  ( object->dataType()  == DATA_PLANE ) {
Jan Möbius's avatar
 
Jan Möbius committed
617
    PluginFunctions::plane(object)->transform(mat);
618 619
  } else {

Jan Möbius's avatar
Jan Möbius committed
620
    emit log(LOGERR,tr("moveObject called for unsupported Object Type"));
621
    return;
Jan Möbius's avatar
 
Jan Möbius committed
622 623
  }

624
  emit updatedObject(_id, UPDATE_GEOMETRY);
Dirk Wilden's avatar
Dirk Wilden committed
625
  emit createBackup(_id, "Move Object", UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
626 627 628 629 630 631
}


//------------------------------------------------------------------------------

/** \brief Move selection on an object with given transformation matrix
632
 *
Jan Möbius's avatar
 
Jan Möbius committed
633 634 635 636
 * Which Selection (Vertex, Edge, Face) is used is determined by the
 * current SelectionMode in SelectionPlugin.
 * If the Plugin is unable to communicate with SelectionPlugin, Vertex Selection is used.
 *
Jan Möbius's avatar
Jan Möbius committed
637 638 639
 * @param _mat  Matrix that should be applied to the selection
 * @param _id   Object id of the target object
 * @param _type Type of mouse event ( release of the button creates a backup)
Jan Möbius's avatar
 
Jan Möbius committed
640
 */
Jan Möbius's avatar
Jan Möbius committed
641
void MovePlugin::moveSelection(ACG::Matrix4x4d _mat, int _id, QEvent::Type _type) {
642 643
  // Get currently active primitive type
  updateSelectionType();
644

Jan Möbius's avatar
Jan Möbius committed
645
  if ( !_mat.is_identity() ){
646
    if (selectionType_ & VERTEX) {
647
      transformedSelected_ = transformVertexSelection( _id , _mat );
648
    }
649
    if (selectionType_ & FACE) {
650
      transformedSelected_ = transformFaceSelection( _id , _mat );
651
    }
652
    if (selectionType_ & EDGE) {
653
      transformedSelected_ = transformEdgeSelection( _id , _mat );
654
    }
655 656 657
    if (selectionType_ & CELL) {
      transformedSelected_ = transformCellSelection( _id , _mat );
    }
Jan Möbius's avatar
 
Jan Möbius committed
658

Dirk Wilden's avatar
Dirk Wilden committed
659 660 661
    emit updatedObject(_id, UPDATE_GEOMETRY);
  }

662 663
  //only create backups on mouseRelease and something has to have been selected and transformed
  if ( _type == QEvent::MouseButtonRelease && transformedSelected_ )
Dirk Wilden's avatar
Dirk Wilden committed
664
    emit createBackup(_id,"Move Selection", UPDATE_GEOMETRY);
665

Jan Möbius's avatar
 
Jan Möbius committed
666 667
}

668 669
//------------------------------------------------------------------------------

670 671 672 673 674 675 676 677 678
/** \brief Set the manipulator manipulation mode
 *
 * @param _mode Mode
 */
void MovePlugin::setManipMode (QtTranslationManipulatorNode::ManipulatorMode _mode)
{
  if (_mode != manMode_)
  {
    manMode_ = _mode;
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709

    // Iterate over all objects that have a placed manip and set their mode
    for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
      if ( o_it->manipPlaced() )
        o_it->manipulatorNode()->setMode (_mode);


    if (!hide_) {
      switch (manMode_)
      {
        case QtTranslationManipulatorNode::Rotation:
          PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
          placeMode_ = false;
          break;
        case QtTranslationManipulatorNode::Resize:
          PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
          placeMode_ = false;
          break;
        case QtTranslationManipulatorNode::LocalRotation:
          PluginFunctions::setViewObjectMarker (&objectMarker_);
          placeMode_ = false;
          break;
        case QtTranslationManipulatorNode::Place:
          PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
          placeMode_ = true;
          break;
        case QtTranslationManipulatorNode::TranslationRotation:
          PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
          placeMode_ = false;
          break;
      }
710
    }
711 712

    // Update the toolbar icons
713 714 715 716
    switch (manMode_)
    {
      case QtTranslationManipulatorNode::Resize:
        resizeAction_->setChecked (true);
717 718
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (false);
719
        placeAndSnapAction_->setChecked (false);
720 721 722
        break;
      case QtTranslationManipulatorNode::LocalRotation:
        resizeAction_->setChecked (false);
723 724
        rotateManipAction_->setChecked (true);
        rotateTranslateAction_->setChecked (false);
725
        placeAndSnapAction_->setChecked (false);
726 727 728
        break;
      case QtTranslationManipulatorNode::TranslationRotation:
        resizeAction_->setChecked (false);
729 730
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (true);
731 732 733 734 735 736 737
        placeAndSnapAction_->setChecked (false);
        break;
      case QtTranslationManipulatorNode::Place:
        resizeAction_->setChecked (false);
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (false);
        placeAndSnapAction_->setChecked (true);
738
        break;
Matthias Möller's avatar
Matthias Möller committed
739 740 741 742 743 744
      case QtTranslationManipulatorNode::Rotation:
        resizeAction_->setChecked(false);
        rotateManipAction_->setChecked(true);
        rotateTranslateAction_->setChecked(false);
        placeAndSnapAction_->setChecked(false);
        break;
745 746 747 748 749 750
    }
  }
}

//------------------------------------------------------------------------------

751
/** \brief Hide context menu entry when right clicking on node other than manipulator node
752
 *
753 754
 * @param _nodeId Identifier of node that has been clicked
 */
755
void MovePlugin::slotUpdateContextMenuNode(int _nodeId) {
756

757
    ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node(PluginFunctions::getSceneGraphRootNode(), _nodeId);
758

759 760
    if (node == 0)
        return;
761

762 763 764 765
    if (node->className() != "QtTranslationManipulatorNode") {
        contextAction_->setVisible(false);
    } else {
        contextAction_->setVisible(true);
766 767
    }
}
Jan Möbius's avatar
 
Jan Möbius committed
768 769 770 771

//------------------------------------------------------------------------------

/** \brief move the object when its manipulator moves
772
 *
Jan Möbius's avatar
 
Jan Möbius committed
773 774 775 776 777 778
 * @param _node the manipulator node
 * @param _event the mouse event
 */
void MovePlugin::manipulatorMoved( QtTranslationManipulatorNode* _node , QMouseEvent* _event) {

  // React on event only in move mode
779
  if ( PluginFunctions::pickMode() != "Move"
Dirk Wilden's avatar
Dirk Wilden committed
780
    && PluginFunctions::pickMode() != "MoveSelection" )
Jan Möbius's avatar
 
Jan Möbius committed
781
    return;
782
  
Jan Möbius's avatar
 
Jan Möbius committed
783 784
  OpenFlipper::Options::redrawDisabled( true );

Dirk Wilden's avatar
Dirk Wilden committed
785
  // Apply changes only on Release for moveMode and after every movement in MoveSelection Mode
786 787
  if ( !placeMode_ && ((_event->type() == QEvent::MouseButtonRelease) || 
             (PluginFunctions::pickMode() != "Move" && _event->buttons() != Qt::NoButton)) ) {
Jan Möbius's avatar
 
Jan Möbius committed
788 789 790 791 792 793 794 795 796 797 798

    int objectId = _node->getIdentifier();

    ACG::Matrix4x4d mat;
    mat.identity();
    mat = _node->matrix();

    // Reset Node
    _node->loadIdentity();
    _node->set_center(mat.transform_point(_node->center()));

799
    // move the object which corresponds to the manipulator
800
    if (PluginFunctions::pickMode() == "Move")
Jan Möbius's avatar
 
Jan Möbius committed
801
      moveObject( mat, objectId );
802
    else if (PluginFunctions::pickMode() == "MoveSelection")
Dirk Wilden's avatar
Dirk Wilden committed
803
      moveSelection( mat, objectId, _event->type() );
Jan Möbius's avatar
 
Jan Möbius committed
804

805
    // move all other targets without manipulator
806
    if(allTargets_) {
807 808
      for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); o_it
          != PluginFunctions::objectsEnd(); ++o_it) {
809
        if ((o_it->id() != objectId) && !o_it->manipulatorNode()->draw_manipulator()) { // If it has its own manipulator active, dont move it
Dirk Wilden's avatar
Dirk Wilden committed
810

811 812 813 814
          // move the object which corresponds to the manipulator
          if (PluginFunctions::pickMode() == "Move")
            moveObject( mat, o_it->id() );
          else if (PluginFunctions::pickMode() == "MoveSelection")
Dirk Wilden's avatar
Dirk Wilden committed
815
            moveSelection( mat, o_it->id(), _event->type() );
816 817 818
        }
      }
    }
Jan Möbius's avatar
 
Jan Möbius committed
819 820 821 822 823 824 825 826 827 828 829 830

    lastActiveManipulator_ = objectId;
    updateManipulatorDialog();
  }

  OpenFlipper::Options::redrawDisabled( false );
}


//------------------------------------------------------------------------------

/** \brief update object when its manipulator changes position
831
 *
Jan Möbius's avatar
 
Jan Möbius committed
832 833 834 835 836 837 838
 * @param _node the manipulator node
 */
void MovePlugin::ManipulatorPositionChanged(QtTranslationManipulatorNode* _node ) {

  // Position has been changed of the manipulator by a direct function
  int objectId = _node->getIdentifier();

Dirk Wilden's avatar
Dirk Wilden committed
839 840 841 842
  if ( objectId > 0 ){

    BaseObjectData* object;
    PluginFunctions::getObject(objectId,object);
Jan Möbius's avatar
 
Jan Möbius committed
843

Dirk Wilden's avatar
Dirk Wilden committed
844 845 846
    // Assume that it has a good position now
    object->manipPlaced( true );
  }
Jan Möbius's avatar
 
Jan Möbius committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860

  // Show manipulator only if in Move mode
  if ( PluginFunctions::pickMode() == "Move" )
    _node->show();

  lastActiveManipulator_ = objectId;
  updateManipulatorDialog();

}


//------------------------------------------------------------------------------

/** \brief Place and show the Manipulator
861
 *
Jan Möbius's avatar
Jan Möbius committed
862 863
 * @param _event  mouseEvent that occurred
 * @param _snap   Snap manipulator to nearest geometry primitive?
Jan Möbius's avatar
 
Jan Möbius committed
864
 */
865
void MovePlugin::placeManip(QMouseEvent * _event, bool _snap) {
866
    size_t node_idx, target_idx;
867 868
    OpenMesh::Vec3d hitPoint;
    BaseObjectData* object;
Jan Möbius's avatar
 
Jan Möbius committed
869

870
    bool successfullyPicked = false;
Jan Möbius's avatar
 
Jan Möbius committed
871

872
    
873

874 875 876 877 878 879
    /*
     * Snap manipulator to nearest geometry
     * element depending on which selection type is
     * active.
     */
    if (_snap) {
880 881 882 883 884 885 886 887
 
          successfullyPicked = PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(), node_idx,
                               target_idx, &hitPoint) && PluginFunctions::getPickedObject(node_idx, object);

          if(!successfullyPicked) {
              //emit log(LOGWARN, tr("Picking failed"));
              return;
          }
Jan Möbius's avatar
 
Jan Möbius committed
888

889 890 891 892 893
          if (selectionType_ == VERTEX) {
              if ( object->dataType(DATA_TRIANGLE_MESH) ) {
                  hitPoint = getNearestVertex(PluginFunctions::triMesh(object), target_idx, hitPoint);
              } else if ( object->dataType(DATA_POLY_MESH) ) {
                  hitPoint = getNearestVertex(PluginFunctions::polyMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
894
#ifdef ENABLE_TSPLINEMESH_SUPPORT
895 896
              } else if ( object->dataType(DATA_TSPLINE_MESH) ) {
                  hitPoint = getNearestVertex(PluginFunctions::tsplineMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
897
#endif
898 899 900 901 902 903
              }
          } else if (selectionType_ == EDGE) {
              if ( object->dataType(DATA_TRIANGLE_MESH) ) {
                  hitPoint = getNearestEdge(PluginFunctions::triMesh(object), target_idx, hitPoint);
              } else if ( object->dataType(DATA_POLY_MESH) ) {
                  hitPoint = getNearestEdge(PluginFunctions::polyMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
904
#ifdef ENABLE_TSPLINEMESH_SUPPORT
905 906
              } else if ( object->dataType(DATA_TSPLINE_MESH) ) {
                  hitPoint = getNearestEdge(PluginFunctions::tsplineMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
907
#endif
908 909 910 911 912 913
              }
          } else if (selectionType_ == FACE) {
              if ( object->dataType(DATA_TRIANGLE_MESH) ) {
                  hitPoint = getNearestFace(PluginFunctions::triMesh(object), target_idx, hitPoint);
              } else if ( object->dataType(DATA_POLY_MESH) ) {
                  hitPoint = getNearestFace(PluginFunctions::polyMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
914
#ifdef ENABLE_TSPLINEMESH_SUPPORT
915 916
              } else if ( object->dataType(DATA_TSPLINE_MESH) ) {
                  hitPoint = getNearestFace(PluginFunctions::tsplineMesh(object), target_idx, hitPoint);
Henrik Zimmer's avatar
Henrik Zimmer committed
917
#endif
918 919
              }
          }
Jan Möbius's avatar
 
Jan Möbius committed
920

921 922 923 924
    } else {
        successfullyPicked = PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING, _event->pos(), node_idx,
                target_idx, &hitPoint) && PluginFunctions::getPickedObject(node_idx, object);
    }
Jan Möbius's avatar
 
Jan Möbius committed
925

926
    if (successfullyPicked) {
Jan Möbius's avatar
 
Jan Möbius committed
927

928
        object->manipPlaced(true);
Jan Möbius's avatar
 
Jan Möbius committed
929

930 931
        /// TODO: Whats this?
        int data = -1;
932 933
        if (data != -1)
          object->manipulatorNode()->setData( data );
Jan Möbius's avatar
 
Jan Möbius committed
934

935 936 937 938 939 940 941
        object->manipulatorNode()->loadIdentity();
        object->manipulatorNode()->set_center(hitPoint);
        object->manipulatorNode()->set_draw_cylinder(true);
        object->manipulatorNode()->set_autosize(QtTranslationManipulatorNode::Once);
        object->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);
        object->manipulatorNode()->setMode(manMode_);
        object->manipulatorNode()->show();
Jan Möbius's avatar
 
Jan Möbius committed
942

943
        object->manipulatorNode()->apply_transformation(PluginFunctions::pickMode() == "Move");
Jan Möbius's avatar
 
Jan Möbius committed
944

945 946 947 948 949 950 951 952
        // Disconnect a previously connected Signal
        disconnect(object->manipulatorNode() , SIGNAL(manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)),
                   this , SLOT( manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)));
                
        disconnect(object->manipulatorNode() , SIGNAL(positionChanged(QtTranslationManipulatorNode*)),
                  this , SLOT( ManipulatorPositionChanged(QtTranslationManipulatorNode*)));
        
        // Reconnect the signals.
953 954 955 956 957 958 959 960 961
        connect(object->manipulatorNode() , SIGNAL(manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)),
                this , SLOT( manipulatorMoved(QtTranslationManipulatorNode*,QMouseEvent*)));

        connect(object->manipulatorNode() , SIGNAL(positionChanged(QtTranslationManipulatorNode*)),
                this , SLOT( ManipulatorPositionChanged(QtTranslationManipulatorNode*)));

        lastActiveManipulator_ = object->id();

        emit updateView();
962 963 964 965 966 967 968 969 970 971 972
       
        bool found = false;
        
        for (uint i=0; i < activeManipulators_.size(); i++)
          if ( activeManipulators_[i] == object->id() ){
            found = true;
            break;
          }
        
        if ( !found )
          activeManipulators_.push_back( object->id() );
973 974 975 976

    } else {
        //emit log(LOGWARN, tr("Picking failed"));
    }
Jan Möbius's avatar
 
Jan Möbius committed
977 978 979 980 981 982
}


//------------------------------------------------------------------------------

/** \brief Checks if the manipulators should be visible or not
983
 *
Jan Möbius's avatar
 
Jan Möbius committed
984 985 986
 */
void MovePlugin::showManipulators( )
{
Dirk Wilden's avatar
Dirk Wilden committed
987

988
  if (!hide_ && (toolboxActive_ || (PluginFunctions::pickMode() == "Move")
Dirk Wilden's avatar
Dirk Wilden committed
989
                                || (PluginFunctions::pickMode() == "MoveSelection"))) {
990
    
991 992 993 994 995 996 997 998 999 1000
    for (uint i=0; i < activeManipulators_.size(); i++){
      
      BaseObjectData* obj = 0;
      
      PluginFunctions::getObject( activeManipulators_[i], obj );
      
      if (obj != 0 && obj->manipPlaced()) {
        obj->manipulatorNode()->show();
        obj->manipulatorNode()->apply_transformation( PluginFunctions::pickMode() == "Move" );
        emit nodeVisibilityChanged(obj->id());
1001
      }
1002
    }
Jan Möbius's avatar
 
Jan Möbius committed
1003

1004
  } else {
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
    
    for (uint i=0; i < activeManipulators_.size