MovePlugin.cc 60.4 KB
Newer Older
1 2 3 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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
38 39 40 41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

#include <QtGui>

#include "MovePlugin.hh"

#include <iostream>
#include <ACG/GL/GLState.hh>
#include <QStringList>
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

#include <MeshTools/MeshFunctions.hh>
#include <MeshTools/MeshInfoT.hh>

#ifdef USE_OPENMP
#include <omp.h>
#endif

#ifdef ENABLE_POLYLINE_SUPPORT
#include <ObjectTypes/PolyLine/PolyLine.hh>
#endif



/** \brief Default Constructor
69
 *
Jan Möbius's avatar
 
Jan Möbius committed
70
 */
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
71
MovePlugin::MovePlugin() :
72 73 74 75 76
    placeAndSnapAction_(0),
    manMode_(QtTranslationManipulatorNode::TranslationRotation),
    contextAction_(0),
    toAllTargets_(0),
    placeMode_(false)
Jan Möbius's avatar
 
Jan Möbius committed
77 78 79 80 81 82 83 84 85
{
    manip_size_          = 1.0;
    manip_size_modifier_ = 1.0;

    selectionType_ = VERTEX;
    selectionConnected_ = false;

    axisA_ = 0;
    axisB_ = 1;
86 87

    hide_ = true;
88
    allTargets_ = false;
Jan Möbius's avatar
 
Jan Möbius committed
89 90
}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/** \brief Deconstructor
 *
 */
MovePlugin::~MovePlugin() {

	if(contextAction_) {
		delete contextAction_;
	}

	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
113 114 115 116 117 118

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

/** \brief Initialization of the plugin when it is loaded by the core
119
 *
Jan Möbius's avatar
 
Jan Möbius committed
120 121 122 123 124 125 126 127 128 129
 */
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
130
  //KEYS
Jan Möbius's avatar
Jan Möbius committed
131 132 133 134
  emit registerKey (Qt::Key_Shift, Qt::ShiftModifier, tr("Manipulator rotation"), true);
  emit registerKey (Qt::Key_Shift, Qt::NoModifier, tr("Manipulator rotation"), true);
  emit registerKey (Qt::Key_Control, Qt::ControlModifier, tr("Resize"), true);
  emit registerKey (Qt::Key_Control, Qt::NoModifier, tr("Resize"), true);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
135

Jan Möbius's avatar
 
Jan Möbius committed
136 137
  //SCRIPTING SLOT DESCRIPTIONS
  setDescriptions();
138

139
  // CONTEXT MENU
Jan Möbius's avatar
Jan Möbius committed
140
  toAllTargets_ = new QAction(tr("Apply to all targets"), this);
141
  toAllTargets_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
142
  toAllTargets_->setToolTip(tr("Apply transformation to all target objects"));
143 144
  toAllTargets_->setStatusTip( toAllTargets_->toolTip() );

Jan Möbius's avatar
Jan Möbius committed
145 146
  contextAction_ = new QAction(tr("Set properties"), this);
  contextAction_->setToolTip(tr("Set properties"));
147
  contextAction_->setStatusTip( contextAction_->toolTip() );
148

149
  emit addContextMenuItem(toAllTargets_ , CONTEXTNODEMENU );
150
  emit addContextMenuItem(contextAction_ , CONTEXTNODEMENU );
151

152 153
  connect(toAllTargets_,SIGNAL(toggled(bool) ),this,SLOT(setAllTargets(bool)));

154
  connect( contextAction_ , SIGNAL( triggered() ),
155
	   this, SLOT(showProps()) );
Jan Möbius's avatar
 
Jan Möbius committed
156 157

  //TOOLBAR
Jan Möbius's avatar
Jan Möbius committed
158
  toolbar_ = new QToolBar(tr("Transform and Move"));
Jan Möbius's avatar
 
Jan Möbius committed
159 160 161

  toolBarActions_ = new QActionGroup(toolbar_);

Jan Möbius's avatar
Jan Möbius committed
162
  moveAction_ = new QAction(tr("Move objects"), toolBarActions_);
Jan Möbius's avatar
 
Jan Möbius committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176
  moveAction_->setStatusTip(tr("Move object in 3D."));
  moveAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-objects.png") );
  moveAction_->setCheckable(true);
  toolbar_->addAction(moveAction_);

  moveSelectionAction_ = new QAction(tr("Move selections on objects"), toolBarActions_);
  moveSelectionAction_->setStatusTip(tr("Move selections in 3D."));
  moveSelectionAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-selections.png") );
  moveSelectionAction_->setCheckable(true);
  toolbar_->addAction(moveSelectionAction_);

  connect(toolBarActions_, SIGNAL(triggered(QAction*)), this, SLOT(slotSetMoveMode(QAction*)) );

  emit addToolbar(toolbar_);
177

Jan Möbius's avatar
Jan Möbius committed
178
  pickToolbar_ = new QToolBar(tr("Transform and Move"));
179
  pickToolbar_->setAttribute(Qt::WA_AlwaysShowToolTips, true);
180 181 182 183 184
  pickToolBarActions_ = new QActionGroup(pickToolbar_);
  pickToolBarActions_->setExclusive (false);

  placeAction_ = new QAction(tr("Place manipulator"), pickToolBarActions_);
  placeAction_->setStatusTip(tr("Place manipulator on object. <Doubleclick>"));
185
  placeAction_->setToolTip(tr("Place manipulator on object. <Doubleclick>"));
186 187 188 189 190 191
  placeAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-place.png") );
  placeAction_->setCheckable(true);
  pickToolbar_->addAction(placeAction_);

  pickToolbar_->addSeparator ();

192 193
  rotateTranslateAction_ = new QAction(tr("Rotate/Translate object"), pickToolBarActions_);
  rotateTranslateAction_->setStatusTip(tr("Rotate/Translate object."));
194
  rotateTranslateAction_->setToolTip(tr("Rotate/Translate object."));
195 196 197 198
  rotateTranslateAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-translaterotate.png") );
  rotateTranslateAction_->setCheckable(true);
  rotateTranslateAction_->setChecked(true);
  pickToolbar_->addAction(rotateTranslateAction_);
199 200 201

  resizeAction_ = new QAction(tr("Resize object"), pickToolBarActions_);
  resizeAction_->setStatusTip(tr("Resize object. <Control>"));
202
  resizeAction_->setToolTip(tr("Resize object. <Control>"));
203 204 205 206 207 208
  resizeAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-resize.png") );
  resizeAction_->setCheckable(true);
  pickToolbar_->addAction(resizeAction_);

  pickToolbar_->addSeparator ();

209 210
  rotateManipAction_ = new QAction(tr("Rotate manipulator"), pickToolBarActions_);
  rotateManipAction_->setStatusTip(tr("Rotate manipulator. <Shift>"));
211
  rotateManipAction_->setToolTip(tr("Rotate manipulator. <Shift>"));
212 213 214
  rotateManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-maniprotate.png") );
  rotateManipAction_->setCheckable(true);
  pickToolbar_->addAction(rotateManipAction_);
215

216 217
  placeAndSnapAction_ = new QAction(tr("Locally translate manipulator"), pickToolBarActions_);
  placeAndSnapAction_->setStatusTip(tr("Locally translate manipulator. Press and hold <Alt> for snapping."));
Mike Kremer's avatar
Mike Kremer committed
218
  placeAndSnapAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-placeandsnap.png") );
219 220 221
  placeAndSnapAction_->setCheckable(true);
  pickToolbar_->addAction(placeAndSnapAction_);

222 223
  smallerManipAction_ = new QAction(tr("Decrease size of manipulator"), pickToolBarActions_);
  smallerManipAction_->setStatusTip(tr("Make manipulator smaller. <Mouse wheel up>"));
224
  smallerManipAction_->setToolTip(tr("Make manipulator smaller. <Mouse wheel up>"));
225 226 227 228
  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
229
  biggerManipAction_ = new QAction(tr("Increase size of manipulator"), pickToolBarActions_);
230
  biggerManipAction_->setStatusTip(tr("Make manipulator bigger. <Mouse wheel down>"));
231
  biggerManipAction_->setToolTip(tr("Make manipulator bigger. <Mouse wheel down>"));
232 233 234 235 236 237 238 239 240
  biggerManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-manipbig.png") );
  biggerManipAction_->setCheckable(false);
  pickToolbar_->addAction(biggerManipAction_);

  connect(pickToolBarActions_, SIGNAL(triggered(QAction*)), this, SLOT(slotPickToolbarAction(QAction*)) );

  emit setPickModeToolbar ("Move", pickToolbar_);
  emit setPickModeToolbar ("MoveSelection", pickToolbar_);

Jan Möbius's avatar
 
Jan Möbius committed
241 242 243 244 245 246 247
}


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

Jan Möbius's avatar
Jan Möbius committed
248
void MovePlugin::initializePlugin()
Jan Möbius's avatar
 
Jan Möbius committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
{
   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));

   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));

   lastActiveManipulator_ = -1;

Jan Möbius's avatar
Jan Möbius committed
264
   emit addToolbox( tr("Move") , tool_ );
Jan Möbius's avatar
 
Jan Möbius committed
265 266 267 268 269 270 271 272
}


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

/** \brief MouseWheel event occured
273
 *
Jan Möbius's avatar
 
Jan Möbius committed
274 275 276 277 278 279 280
 * @param _event the event that occured
 */
void MovePlugin::slotMouseWheelEvent(QWheelEvent * _event, const std::string & /*_mode*/)
{
   manip_size_modifier_ = manip_size_modifier_ - (float)_event->delta() / 120.0 * 0.1;
   for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)
         o_it->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);
Dirk Wilden's avatar
Dirk Wilden committed
281

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
282
   emit visibilityChanged (-1);
Jan Möbius's avatar
 
Jan Möbius committed
283 284 285 286 287 288
}


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

/** \brief MousePress event occured
289
 *
Jan Möbius's avatar
 
Jan Möbius committed
290 291
 * @param _event the event that occured
 */
292 293 294
void MovePlugin::slotMouseEvent(QMouseEvent* _event) {
    if (((PluginFunctions::pickMode() == ("Move")) || (PluginFunctions::pickMode() == ("MoveSelection")))
            && PluginFunctions::actionMode() == Viewer::PickingMode) {
Jan Möbius's avatar
 
Jan Möbius committed
295

296 297
        if (_event->type() == QEvent::MouseButtonDblClick || (_event->type() == QEvent::MouseButtonPress
                && _event->button() == Qt::LeftButton && (placeAction_->isChecked() || placeMode_))) {
Jan Möbius's avatar
 
Jan Möbius committed
298

299 300 301
            placeManip(_event, (placeMode_ && (PluginFunctions::pickMode() == ("MoveSelection"))));
            placeAction_->setChecked(false);
            updateManipulatorDialog();
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
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 328 329 330 331 332 333 334 335 336 337 338 339 340
            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.
             */

            placeManip(_event, (PluginFunctions::pickMode() == ("MoveSelection")));
            updateManipulatorDialog();
            return;
        }

        // interaction
        ACG::SceneGraph::MouseEventAction action(_event);
        PluginFunctions::traverse(action);

        if (_event->buttons() == Qt::LeftButton)
            emit visibilityChanged(-1);

    }
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
341 342 343 344 345 346 347 348 349
}

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

void MovePlugin::slotKeyEvent (QKeyEvent* _event)
{
  if (_event->key() == Qt::Key_Control)
350
    setManipMode (QtTranslationManipulatorNode::Resize);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
351
  else if (_event->key () == Qt::Key_Shift)
352
    setManipMode (QtTranslationManipulatorNode::LocalRotation);
Jan Möbius's avatar
 
Jan Möbius committed
353 354
}

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
355 356 357 358 359 360
//------------------------------------------------------------------------------

void MovePlugin::slotKeyReleaseEvent (QKeyEvent* _event)
{
  if ((_event->key() == Qt::Key_Control && manMode_ == QtTranslationManipulatorNode::Resize) ||
      (_event->key() == Qt::Key_Shift && manMode_ == QtTranslationManipulatorNode::LocalRotation))
361
    setManipMode (QtTranslationManipulatorNode::TranslationRotation);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
362
}
Jan Möbius's avatar
 
Jan Möbius committed
363 364 365 366 367 368

/*******************************************************************************
        PickingInterface implementation
 *******************************************************************************/

/** \brief slot is called when the pickMode changed
369
 *
Jan Möbius's avatar
 
Jan Möbius committed
370 371 372 373
 * @param _mode new pickMode
 */
void MovePlugin::slotPickModeChanged( const std::string& _mode)
{
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
374 375
  moveAction_->setChecked(_mode == "Move");
  moveSelectionAction_->setChecked(_mode == "MoveSelection");
376

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
377
  hide_ = !(_mode == "Move" || _mode == "MoveSelection");
Jan Möbius's avatar
 
Jan Möbius committed
378

Jan Möbius's avatar
Dennis:  
Jan Möbius committed
379 380 381 382 383 384 385 386 387 388 389 390
  showManipulators();

  if (!hide_)
  {
    switch (manMode_)
    {
      case QtTranslationManipulatorNode::Resize:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
      case QtTranslationManipulatorNode::LocalRotation:
        PluginFunctions::setViewObjectMarker (&objectMarker_);
        break;
391 392 393
      case QtTranslationManipulatorNode::Place:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
394 395 396 397 398 399 400
      case QtTranslationManipulatorNode::TranslationRotation:
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
        break;
    }
  }
  else
    PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
Jan Möbius's avatar
 
Jan Möbius committed
401 402 403 404 405 406 407 408
}


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

/** \brief Move object with given transformation matrix
409
 *
Jan Möbius's avatar
 
Jan Möbius committed
410 411 412 413 414
 * @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
415
  if ( ! PluginFunctions::getObject(_id,object) )
Jan Möbius's avatar
 
Jan Möbius committed
416 417
    return;

418 419 420 421 422 423 424 425
  if  ( object->dataType()  == DATA_TRIANGLE_MESH ) {
    transformMesh(mat , *PluginFunctions::triMesh(object) );
  } else  if  ( object->dataType()  == DATA_POLY_MESH ) {
    transformMesh(mat , *PluginFunctions::polyMesh(object) );
  #ifdef ENABLE_POLYLINE_SUPPORT
  } else  if  ( object->dataType()  == DATA_POLY_LINE ) {
    transformPolyLine(mat , *PluginFunctions::polyLine(object) );
  #endif
Dirk Wilden's avatar
Dirk Wilden committed
426 427
  } else  if  ( object->dataType()  == DATA_PLANE ) {
    PluginFunctions::planeNode(object)->transform(mat);
428 429
  } else {

Jan Möbius's avatar
Jan Möbius committed
430
    emit log(LOGERR,tr("moveObject called for unsupported Object Type"));
431
    return;
Jan Möbius's avatar
 
Jan Möbius committed
432 433 434 435 436 437 438 439 440 441
  }

  emit updatedObject(_id);
  emit createBackup(_id,"Move");
}


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

/** \brief Move selection on an object with given transformation matrix
442
 *
Jan Möbius's avatar
 
Jan Möbius committed
443 444 445 446
 * 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.
 *
447 448
 * @param mat
 * @param _id
Jan Möbius's avatar
 
Jan Möbius committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462
 */
void MovePlugin::moveSelection(ACG::Matrix4x4d mat, int _id) {

  if (selectionType_ == VERTEX)
    transformVertexSelection( _id , mat );
  else if (selectionType_ == FACE)
    transformFaceSelection( _id , mat );
  else if (selectionType_ == EDGE)
    transformEdgeSelection( _id , mat );

  emit updatedObject(_id);
//   emit createBackup(_id,"MoveSelection");
}

463 464
//------------------------------------------------------------------------------

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
/** \brief Set the manipulator manipulation mode
 *
 * @param _mode Mode
 */

void MovePlugin::setManipMode (QtTranslationManipulatorNode::ManipulatorMode _mode)
{
  if (_mode != manMode_)
  {
    manMode_ = _mode;
    if ((PluginFunctions::pickMode() == "Move" ) || (PluginFunctions::pickMode() == "MoveSelection" )) {
        for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
              o_it != PluginFunctions::objectsEnd(); ++o_it)
           if ( o_it->manipPlaced() )
                o_it->manipulatorNode()->setMode (_mode);
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
480 481 482 483 484
      if (!hide_)
        switch (manMode_)
        {
          case QtTranslationManipulatorNode::Resize:
            PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
485
            placeMode_ = false;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
486 487 488
            break;
          case QtTranslationManipulatorNode::LocalRotation:
            PluginFunctions::setViewObjectMarker (&objectMarker_);
489 490 491 492 493
            placeMode_ = false;
            break;
          case QtTranslationManipulatorNode::Place:
            PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
            placeMode_ = true;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
494 495 496
            break;
          case QtTranslationManipulatorNode::TranslationRotation:
            PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
497
            placeMode_ = false;
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
498 499
            break;
        }
500 501 502 503 504
    }
    switch (manMode_)
    {
      case QtTranslationManipulatorNode::Resize:
        resizeAction_->setChecked (true);
505 506
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (false);
507
        placeAndSnapAction_->setChecked (false);
508 509 510
        break;
      case QtTranslationManipulatorNode::LocalRotation:
        resizeAction_->setChecked (false);
511 512
        rotateManipAction_->setChecked (true);
        rotateTranslateAction_->setChecked (false);
513
        placeAndSnapAction_->setChecked (false);
514 515 516
        break;
      case QtTranslationManipulatorNode::TranslationRotation:
        resizeAction_->setChecked (false);
517 518
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (true);
519 520 521 522 523 524 525
        placeAndSnapAction_->setChecked (false);
        break;
      case QtTranslationManipulatorNode::Place:
        resizeAction_->setChecked (false);
        rotateManipAction_->setChecked (false);
        rotateTranslateAction_->setChecked (false);
        placeAndSnapAction_->setChecked (true);
526 527 528 529 530 531 532
        break;
    }
  }
}

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

533
/** \brief Hide context menu entry when right clicking on node other than manipulator node
534
 *
535 536
 * @param _nodeId Identifier of node that has been clicked
 */
537
void MovePlugin::slotUpdateContextMenuNode(int _nodeId) {
538

539
    ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node(PluginFunctions::getSceneGraphRootNode(), _nodeId);
540

541 542
    if (node == 0)
        return;
543

544 545 546 547
    if (node->className() != "QtTranslationManipulatorNode") {
        contextAction_->setVisible(false);
    } else {
        contextAction_->setVisible(true);
548 549
    }
}
Jan Möbius's avatar
 
Jan Möbius committed
550 551 552 553

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

/** \brief move the object when its manipulator moves
554
 *
Jan Möbius's avatar
 
Jan Möbius committed
555 556 557 558 559 560 561 562 563 564 565 566
 * @param _node the manipulator node
 * @param _event the mouse event
 */
void MovePlugin::manipulatorMoved( QtTranslationManipulatorNode* _node , QMouseEvent* _event) {

  // React on event only in move mode
  if ( PluginFunctions::pickMode() != "Move" && PluginFunctions::pickMode() != "MoveSelection" )
    return;

  OpenFlipper::Options::redrawDisabled( true );

  // Apply changes only on Release for moveMode and after every movement in MoveSelection Mode
567
  if ( ((_event->type() == QEvent::MouseButtonRelease) || (PluginFunctions::pickMode() == "MoveSelection")) && !placeMode_) {
Jan Möbius's avatar
 
Jan Möbius committed
568 569 570 571 572 573 574 575 576 577 578

    int objectId = _node->getIdentifier();

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

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

579
    // move the object which corresponds to the manipulator
Jan Möbius's avatar
 
Jan Möbius committed
580 581 582 583 584
    if (PluginFunctions::pickMode() != "MoveSelection")
      moveObject( mat, objectId );
    else
      moveSelection( mat, objectId );

585
    // move all other targets without manipulator
586
    if(allTargets_) {
587 588 589 590 591 592 593 594 595 596
      for (PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); o_it
          != PluginFunctions::objectsEnd(); ++o_it) {
        if ((o_it->id() != objectId) && !o_it->manipulatorNode()->visible()) { // If it has its own manipulator active, dont move it
          if (PluginFunctions::pickMode() != "MoveSelection")
            moveObject(mat, o_it->id());
          else
            moveSelection(mat, o_it->id());
        }
      }
    }
Jan Möbius's avatar
 
Jan Möbius committed
597 598 599 600 601 602 603 604 605 606 607 608 609

    lastActiveManipulator_ = objectId;
    updateManipulatorDialog();
  }

  OpenFlipper::Options::redrawDisabled( false );

}


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

/** \brief update object when its manipulator changes position
610
 *
Jan Möbius's avatar
 
Jan Möbius committed
611 612 613 614 615 616 617
 * @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
618 619 620 621
  if ( objectId > 0 ){

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

Dirk Wilden's avatar
Dirk Wilden committed
623 624 625
    // Assume that it has a good position now
    object->manipPlaced( true );
  }
Jan Möbius's avatar
 
Jan Möbius committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639

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

  lastActiveManipulator_ = objectId;
  updateManipulatorDialog();

}


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

/** \brief Place and show the Manipulator
640
 *
Jan Möbius's avatar
 
Jan Möbius committed
641 642
 * @param _event  mouseEvent that occured
 */
643 644 645 646
void MovePlugin::placeManip(QMouseEvent * _event, bool _snap) {
    unsigned int node_idx, target_idx;
    OpenMesh::Vec3d hitPoint;
    BaseObjectData* object;
Jan Möbius's avatar
 
Jan Möbius committed
647

648
    bool successfullyPicked = false;
Jan Möbius's avatar
 
Jan Möbius committed
649

650 651 652 653 654 655 656 657
    /*
     * Snap manipulator to nearest geometry
     * element depending on which selection type is
     * active.
     */
    if (_snap) {
        successfullyPicked = PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE, _event->pos(), node_idx,
                target_idx, &hitPoint) && PluginFunctions::getPickedObject(node_idx, object);
Jan Möbius's avatar
 
Jan Möbius committed
658

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

664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
        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);
            }
        } 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);
            }
        } 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);
            }
        }
Jan Möbius's avatar
 
Jan Möbius committed
683

684 685 686 687
    } 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
688

689
    if (successfullyPicked) {
Jan Möbius's avatar
 
Jan Möbius committed
690

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

693 694 695
        /*if (!object->picked(node_idx)) {
            emit log(LOGWARN, tr("Picking failed"));
        }*/
Jan Möbius's avatar
 
Jan Möbius committed
696

697 698 699 700 701 702 703
        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
704

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

707 708 709 710 711 712 713 714 715 716 717 718 719
        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();

    } else {
        //emit log(LOGWARN, tr("Picking failed"));
    }
Jan Möbius's avatar
 
Jan Möbius committed
720 721 722 723 724 725
}


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

/** \brief Checks if the manipulators should be visible or not
726
 *
Jan Möbius's avatar
 
Jan Möbius committed
727 728 729
 */
void MovePlugin::showManipulators( )
{
Dirk Wilden's avatar
Dirk Wilden committed
730

731 732 733 734 735 736 737 738 739 740
	if (!hide_ && (toolboxActive_ || (PluginFunctions::pickMode() == "Move")
			|| (PluginFunctions::pickMode() == "MoveSelection"))) {
		for (PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS); o_it
				!= PluginFunctions::objectsEnd(); ++o_it)

			if (o_it->manipPlaced()) {
				o_it->manipulatorNode()->show();
				o_it->manipulatorNode()->apply_transformation(
						PluginFunctions::pickMode() == "Move");
			}
Dirk Wilden's avatar
Dirk Wilden committed
741

742 743 744 745 746 747
	} else {
		for (PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS); o_it
				!= PluginFunctions::objectsEnd(); ++o_it)

			o_it->manipulatorNode()->hide();
	}
Jan Möbius's avatar
 
Jan Möbius committed
748

749
	emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
750 751 752

}

753
//------------------------------------------------------------------------------
Jan Möbius's avatar
 
Jan Möbius committed
754

755
/** \brief Get Dialog Widget that contains the button
756
 *
757 758 759 760 761 762 763
 * @param _but Reference to QPushButton object that has been pressed
 */
movePropsWidget* MovePlugin::getDialogFromButton(QPushButton* _but) {

    if(_but == 0) return 0;
    return dynamic_cast<movePropsWidget*>((((_but->parentWidget())->parentWidget())->parentWidget()));
}
Jan Möbius's avatar
 
Jan Möbius committed
764 765 766
//------------------------------------------------------------------------------

/** \brief Position of manipulator in tab changed
767
 *
Jan Möbius's avatar
 
Jan Möbius committed
768 769
 */
void MovePlugin::slotSetPosition() {
770

771 772 773
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
774

775
    TriMesh::Point newpos;
776

777 778
    bool ok = false;
    newpos[0] =  (pW->nposx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
779
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate")); return; }
780
    newpos[1] =  (pW->nposy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
781
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
782
    newpos[2] =  (pW->nposz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
783
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
784

785 786 787 788 789 790 791
    BaseObjectData* object;
    if ( PluginFunctions::getObject(lastActiveManipulator_ , object) ) {
	if (  object->manipulatorNode()->visible() )
	    object->manipulatorNode()->set_center( newpos );
	updateManipulatorDialog();
	emit updateView();
    }
Jan Möbius's avatar
 
Jan Möbius committed
792 793 794 795 796 797
}


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

/** \brief Toggle the first axis for changing direction in tab
798
 *
Jan Möbius's avatar
 
Jan Möbius committed
799 800
 */
void MovePlugin::slotToggleAxisA() {
801

802 803 804
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
805 806

    axisA_ = (axisA_ + 1) % 3;
807

808 809
    if (axisA_ == axisB_)
	axisA_ = (axisA_ + 1) % 3;
810

811
    switch(axisA_){
Jan Möbius's avatar
Jan Möbius committed
812 813 814
	case 0: pW->axisAButton->setText(tr("X Direction")); break;
	case 1: pW->axisAButton->setText(tr("Y Direction")); break;
	case 2: pW->axisAButton->setText(tr("Z Direction")); break;
815 816
	default: break;
    }
Jan Möbius's avatar
 
Jan Möbius committed
817 818 819 820 821 822
}


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

/** \brief Toggle the second axis for changing direction in tab
823
 *
Jan Möbius's avatar
 
Jan Möbius committed
824 825
 */
void MovePlugin::slotToggleAxisB() {
826

827 828 829
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
830 831

    axisB_ = (axisB_ + 1) % 3;
832

833 834
    if (axisA_ == axisB_)
	axisB_ = (axisB_ + 1) % 3;
835

836
    switch(axisB_){
Jan Möbius's avatar
Jan Möbius committed
837 838 839
	case 0: pW->axisBButton->setText(tr("X Direction")); break;
	case 1: pW->axisBButton->setText(tr("Y Direction")); break;
	case 2: pW->axisBButton->setText(tr("Z Direction")); break;
840 841
	default: break;
    }
Jan Möbius's avatar
 
Jan Möbius committed
842 843 844 845 846 847
}


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

/** \brief Set Direction of manipulator in tab changed
848
 *
Jan Möbius's avatar
 
Jan Möbius committed
849 850
 */
void MovePlugin::slotSetDirection() {
851

852 853 854
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
855

856 857 858
    ACG::Vec3d newdirA,newdirB;
    ACG::Vec3d dirX,dirY;
    ACG::Vec3d dirZ(0.0,0.0,0.0);
859

860 861
    bool ok = false;
    newdirA[0] =  (pW->ndirAx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
862
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
863
    newdirA[1] =  (pW->ndirAy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
864
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
865
    newdirA[2] =  (pW->ndirAz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
866
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
867

868
    newdirB[0] =  (pW->ndirBx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
869
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
870
    newdirB[1] =  (pW->ndirBy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
871
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
872
    newdirB[2] =  (pW->ndirBz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
873
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
874

875 876
    bool xAxis = false;
    bool yAxis = false;
877

878 879 880 881 882
    switch(axisA_){
	case  0: dirX = newdirA; xAxis = true; break;
	case  1: dirY = newdirA; yAxis = true; break;
	default: dirZ = newdirA; break;
    }
883

884 885 886 887 888
    switch(axisB_){
	case  0: dirX = newdirB; xAxis = true; break;
	case  1: dirY = newdirB; yAxis = true; break;
	default: dirZ = newdirB; break;
    }
889

890 891
    if (!xAxis)
	dirX = dirY % dirZ;
892

893 894
    if (!yAxis)
	dirY = dirX % dirZ;
895 896


897
    if ( (dirX | dirY) != 0.0){
Jan Möbius's avatar
Jan Möbius committed
898
	emit log(LOGERR,tr("The axes of the new direction have to be orthogonal"));
899 900
	return;
    }
901

Jan Möbius's avatar
Jan Möbius committed
902 903 904 905 906 907 908 909 910
//    // Apply to All Target Objects
//     if ( pW->targetObjects->isChecked() ) {
// 	for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
//              o_it PluginFunctions::objectsEnd(); ++o_it){
//
// 	    o_it->manipulatorNode()->set_direction( dirX, dirY );
// 	}
//     }

911 912 913
    BaseObjectData* object = pW->getBaseObjectData();
    if ( object != 0 ) {
        if (  object->manipulatorNode()->visible() ){
Jan Möbius's avatar
 
Jan Möbius committed
914 915

            object->manipulatorNode()->set_direction( dirX, dirY );
916 917
	}
    } else return;
918

919 920
    updateManipulatorDialog();
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
921 922 923 924 925 926
}


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

/** \brief perform a translation for Manipulator in tab
927
 *
Jan Möbius's avatar
 
Jan Möbius committed
928 929
 */
void MovePlugin::slotTranslation() {
930

931 932 933
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
934

935
    ACG::Vec3d translation;
936

937 938
    bool ok = false;
    translation[0] =  (pW->translationX->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
939
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
940
    translation[1] =  (pW->translationY->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
941
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
942
    translation[2] =  (pW->translationZ->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
943
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
944

Jan Möbius's avatar
Jan Möbius committed
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
//	// Apply to All Target Objects
//	if ( pW->targetObjects->isChecked() ) {
//
//		int manipcount = 0; // Check how many of the target meshes have an visible manipulator
//		int targets = 0; // Count the number of target meshes
//		for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS); o_it != PluginFunctions::objectsEnd(); ++o_it) {
//			++targets;
//			if ( ! o_it->manipulatorNode()->hidden() ) {
//				++ manipcount;
//			}
//		}
//
//		if (manipcount == 0 ) // No manipulator -> no translation
//		return;
//
//		for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DataType( DATA_TRIANGLE_MESH | DATA_POLY_MESH ));
//				o_it != PluginFunctions::objectsEnd(); ++o_it) {
//			if ( manipcount > 1 ) { // Use manipulator direction for each target mesh
//				if ( o_it->manipulatorNode()->hidden() )
//				continue;
//			}
//
//			translate( o_it->id() , translation );
//
//			o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() + translation );
//			emit createBackup(o_it->id(),"Translation");
//			emit updatedObject(o_it->id());
//		}
//
//	}

976
    BaseObjectData* object = pW->getBaseObjectData();
977
	if (object != 0) {
978
		if (object->manipulatorNode()->visible()) {
Jan Möbius's avatar
 
Jan Möbius committed
979

980
			translate(object->id(), translation);
981

982 983 984 985 986 987 988
			object->manipulatorNode()->set_center(
					object->manipulatorNode()->center() + translation);
			emit createBackup(object->id(), "Translation");
			emit updatedObject(object->id());
		}
	} else {
		return;
989
	}
Jan Möbius's avatar
 
Jan Möbius committed
990

Jan Möbius's avatar
Jan Möbius committed
991

992 993 994
    updateManipulatorDialog();
    emit scriptInfo(QString("slotTranslation()"));
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
995 996 997 998 999 1000
}


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

/** \brief Project the current manipulator onto the tangent plane of the object
1001
 *
Jan Möbius's avatar
 
Jan Möbius committed
1002 1003
 */
void MovePlugin::slotProjectToTangentPlane() {
1004

1005 1006 1007 1008
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;

1009
    if ( allTargets_ ) {
Jan Möbius's avatar
Jan Möbius committed
1010
    	emit log(LOGWARN,tr("TODO Project for multiple targets"));
1011
    	return;
1012
    } else {
Jan Möbius's avatar
Jan Möbius committed
1013
    	emit log(LOGWARN,tr("TODO Project for one target"));
1014
    	return;
1015
    }
Jan Möbius's avatar
 
Jan Möbius committed
1016 1017 1018 1019 1020 1021 1022

}


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

/** \brief Move the current manipulator to the cog of the object
1023
 *
Jan Möbius's avatar
 
Jan Möbius committed
1024 1025
 */
void MovePlugin::slotMoveManipToCOG() {
1026

1027 1028 1029
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
1030

Jan Möbius's avatar
Jan Möbius committed
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046

//     if ( pW->targetObjects->isChecked() ) {
// 	for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
// 		if (  o_it->manipulatorNode()->hidden() )
// 		continue;
//
// 		if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
// 		o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(*o_it) ) );
// 		else if ( o_it->dataType( DATA_POLY_MESH ) )
// 		o_it->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(*o_it)) );
//
// 		updateManipulatorDialog();
// 		o_it->manipulatorNode()->loadIdentity();
// 	}
//     } else {

1047 1048 1049
    BaseObjectData* object = pW->getBaseObjectData();
    if ( object != 0 ) {
	if (  object->manipulatorNode()->visible() ){
1050

1051 1052 1053 1054
	    if ( object->dataType( DATA_TRIANGLE_MESH ) )
	    object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::triMesh(object)) );
	    else if ( object->dataType( DATA_POLY_MESH ) )
	    object->manipulatorNode()->set_center( MeshInfo::cog(*PluginFunctions::polyMesh(object)) );
Jan Möbius's avatar
 
Jan Möbius committed
1055

1056 1057 1058 1059
	    updateManipulatorDialog();
	    object->manipulatorNode()->loadIdentity();
	}
    }
Jan Möbius's avatar
 
Jan Möbius committed
1060

1061
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
1062 1063 1064 1065 1066 1067
}


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

/** \brief Rotate Manipulator (with values from Tab)