MovePlugin.cc 51.6 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
 manMode_ (QtTranslationManipulatorNode::TranslationRotation),
 contextAction_(0),
 toAllTargets_(0)
Jan Möbius's avatar
 
Jan Möbius committed
75
76
77
78
79
80
81
82
83
{
    manip_size_          = 1.0;
    manip_size_modifier_ = 1.0;

    selectionType_ = VERTEX;
    selectionConnected_ = false;

    axisA_ = 0;
    axisB_ = 1;
84
85

    hide_ = true;
86
    allTargets_ = false;
Jan Möbius's avatar
 
Jan Möbius committed
87
88
89
90
91
92
93
94
}


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

/** \brief Initialization of the plugin when it is loaded by the core
95
 *
Jan Möbius's avatar
 
Jan Möbius committed
96
97
98
99
100
101
102
103
104
105
 */
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
106
  //KEYS
Jan Möbius's avatar
Jan Möbius committed
107
108
109
110
  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
111

Jan Möbius's avatar
 
Jan Möbius committed
112
113
  //SCRIPTING SLOT DESCRIPTIONS
  setDescriptions();
114

115
  // CONTEXT MENU
Jan Möbius's avatar
Jan Möbius committed
116
  toAllTargets_ = new QAction(tr("Apply to all targets"), this);
117
  toAllTargets_->setCheckable(true);
Jan Möbius's avatar
Jan Möbius committed
118
  toAllTargets_->setToolTip(tr("Apply transformation to all target objects"));
119
120
  toAllTargets_->setStatusTip( toAllTargets_->toolTip() );

Jan Möbius's avatar
Jan Möbius committed
121
122
  contextAction_ = new QAction(tr("Set properties"), this);
  contextAction_->setToolTip(tr("Set properties"));
123
  contextAction_->setStatusTip( contextAction_->toolTip() );
124

125
  emit addContextMenuItem(toAllTargets_ , CONTEXTNODEMENU );
126
  emit addContextMenuItem(contextAction_ , CONTEXTNODEMENU );
127

128
129
  connect(toAllTargets_,SIGNAL(toggled(bool) ),this,SLOT(setAllTargets(bool)));

130
  connect( contextAction_ , SIGNAL( triggered() ),
131
	   this, SLOT(showProps()) );
Jan Möbius's avatar
 
Jan Möbius committed
132
133

  //TOOLBAR
Jan Möbius's avatar
Jan Möbius committed
134
  toolbar_ = new QToolBar(tr("Transform and Move"));
Jan Möbius's avatar
 
Jan Möbius committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

  toolBarActions_ = new QActionGroup(toolbar_);

  moveAction_ = new QAction(tr("&Move objects"), toolBarActions_);
  std::cerr << "Todo : Show all manipulators placed" << std::endl;
  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_);
154

Jan Möbius's avatar
Jan Möbius committed
155
  pickToolbar_ = new QToolBar(tr("Transform and Move"));
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  pickToolBarActions_ = new QActionGroup(pickToolbar_);
  pickToolBarActions_->setExclusive (false);

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

  pickToolbar_->addSeparator ();

  ratateTranslateAction_ = new QAction(tr("Rotate/Translate object"), pickToolBarActions_);
  ratateTranslateAction_->setStatusTip(tr("Rotate/Translate object."));
  ratateTranslateAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-translaterotate.png") );
  ratateTranslateAction_->setCheckable(true);
  ratateTranslateAction_->setChecked(true);
  pickToolbar_->addAction(ratateTranslateAction_);

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

  pickToolbar_->addSeparator ();

  ratateManipAction_ = new QAction(tr("Rotate manipulator"), pickToolBarActions_);
  ratateManipAction_->setStatusTip(tr("Rotate manipulator. <Shift>"));
  ratateManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-maniprotate.png") );
  ratateManipAction_->setCheckable(true);
  pickToolbar_->addAction(ratateManipAction_);

  smallerManipAction_ = new QAction(tr("Decrease size of manipulator"), pickToolBarActions_);
  smallerManipAction_->setStatusTip(tr("Make manipulator smaller. <Mouse wheel up>"));
  smallerManipAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"move-manipsmall.png") );
  smallerManipAction_->setCheckable(false);
  pickToolbar_->addAction(smallerManipAction_);

  biggerManipAction_ = new QAction(tr("&Increase size of manipulator"), pickToolBarActions_);
  biggerManipAction_->setStatusTip(tr("Make manipulator bigger. <Mouse wheel down>"));
  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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
}


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

/** \brief Create the move toolbox-widget and return a reference to it
 *
 * @param _widget A reference to the move toolbox that we will return
 * @return return wether the widget was successfully generated
 */
bool MovePlugin::initializeToolbox(QWidget*& _widget)
{
   toolboxActive_ = false;
   tool_ = new moveToolbarWidget();
Jan Möbius's avatar
Jan Möbius committed
221
//    tool_ -> setMaximumWidth(300);
Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
   _widget = tool_;

   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;

   return true;
}


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

/** \brief MouseWheel event occured
244
 *
Jan Möbius's avatar
 
Jan Möbius committed
245
246
247
248
249
250
251
 * @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
252

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
253
   emit visibilityChanged (-1);
Jan Möbius's avatar
 
Jan Möbius committed
254
255
256
257
258
259
}


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

/** \brief MousePress event occured
260
 *
Jan Möbius's avatar
 
Jan Möbius committed
261
262
263
264
 * @param _event the event that occured
 */
void MovePlugin::slotMouseEvent( QMouseEvent* _event )
{
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
265
266
  if (((PluginFunctions::pickMode() == ("Move")) || (PluginFunctions::pickMode() == ("MoveSelection"))) &&
      PluginFunctions::actionMode() == Viewer::PickingMode) {
Jan Möbius's avatar
 
Jan Möbius committed
267

268
    if (_event->type() == QEvent::MouseButtonDblClick ||
Jan Möbius's avatar
Jan Möbius committed
269
        (_event->type() == QEvent::MouseButtonPress &&
270
271
         _event->button () == Qt::LeftButton &&
         placeAction_->isChecked ())) {
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
272
273

      placeManip(_event);
Dirk Wilden's avatar
Dirk Wilden committed
274
      placeAction_->setChecked(false);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
275
276
277
      updateManipulatorDialog();
      return;
    }
Jan Möbius's avatar
 
Jan Möbius committed
278

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
279
280
281
    // interaction
    ACG::SceneGraph::MouseEventAction action(_event);
    PluginFunctions::traverse(action);
Jan Möbius's avatar
 
Jan Möbius committed
282

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
283
284
    if (_event->buttons() == Qt::LeftButton)
      emit visibilityChanged (-1);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
285

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
286
287
288
289
290
291
292
293
294
295
  }
}

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

void MovePlugin::slotKeyEvent (QKeyEvent* _event)
{
  if (_event->key() == Qt::Key_Control)
296
    setManipMode (QtTranslationManipulatorNode::Resize);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
297
  else if (_event->key () == Qt::Key_Shift)
298
    setManipMode (QtTranslationManipulatorNode::LocalRotation);
Jan Möbius's avatar
 
Jan Möbius committed
299
300
}

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
301
302
303
304
305
306
//------------------------------------------------------------------------------

void MovePlugin::slotKeyReleaseEvent (QKeyEvent* _event)
{
  if ((_event->key() == Qt::Key_Control && manMode_ == QtTranslationManipulatorNode::Resize) ||
      (_event->key() == Qt::Key_Shift && manMode_ == QtTranslationManipulatorNode::LocalRotation))
307
    setManipMode (QtTranslationManipulatorNode::TranslationRotation);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
308
}
Jan Möbius's avatar
 
Jan Möbius committed
309
310
311
312
313
314

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

/** \brief slot is called when the pickMode changed
315
 *
Jan Möbius's avatar
 
Jan Möbius committed
316
317
318
319
 * @param _mode new pickMode
 */
void MovePlugin::slotPickModeChanged( const std::string& _mode)
{
320
321
322
323
	moveAction_->setChecked(_mode == "Move");
	moveSelectionAction_->setChecked(_mode == "MoveSelection");

	hide_ = !(_mode == "Move" || _mode == "MoveSelection");
Jan Möbius's avatar
 
Jan Möbius committed
324

325
	showManipulators();
Jan Möbius's avatar
 
Jan Möbius committed
326
327
328
329
330
331
332
333
}


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

/** \brief Move object with given transformation matrix
334
 *
Jan Möbius's avatar
 
Jan Möbius committed
335
336
337
338
339
 * @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
340
  if ( ! PluginFunctions::getObject(_id,object) )
Jan Möbius's avatar
 
Jan Möbius committed
341
342
    return;

343
344
345
346
347
348
349
350
  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
351
352
  } else  if  ( object->dataType()  == DATA_PLANE ) {
    PluginFunctions::planeNode(object)->transform(mat);
353
354
  } else {

Jan Möbius's avatar
Jan Möbius committed
355
    emit log(LOGERR,tr("moveObject called for unsupported Object Type"));
356
    return;
Jan Möbius's avatar
 
Jan Möbius committed
357
358
359
360
361
362
363
364
365
366
  }

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


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

/** \brief Move selection on an object with given transformation matrix
367
 *
Jan Möbius's avatar
 
Jan Möbius committed
368
369
370
371
 * 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.
 *
372
373
 * @param mat
 * @param _id
Jan Möbius's avatar
 
Jan Möbius committed
374
375
376
377
378
379
380
381
382
383
384
385
386
387
 */
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");
}

388
389
//------------------------------------------------------------------------------

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/** \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);
    }
    switch (manMode_)
    {
      case QtTranslationManipulatorNode::Resize:
        resizeAction_->setChecked (true);
        ratateManipAction_->setChecked (false);
        ratateTranslateAction_->setChecked (false);
412
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
413
414
415
416
417
        break;
      case QtTranslationManipulatorNode::LocalRotation:
        resizeAction_->setChecked (false);
        ratateManipAction_->setChecked (true);
        ratateTranslateAction_->setChecked (false);
418
        PluginFunctions::setViewObjectMarker (&objectMarker_);
419
420
421
422
423
        break;
      case QtTranslationManipulatorNode::TranslationRotation:
        resizeAction_->setChecked (false);
        ratateManipAction_->setChecked (false);
        ratateTranslateAction_->setChecked (true);
424
        PluginFunctions::setViewObjectMarker (PluginFunctions::defaultViewObjectMarker ());
425
426
427
428
429
430
431
        break;
    }
  }
}

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

432
/** \brief Hide context menu entry when right clicking on node other than manipulator node
433
 *
434
435
436
 * @param _nodeId Identifier of node that has been clicked
 */
void MovePlugin::slotUpdateContextMenuNode( int _nodeId ) {
437

438
    ACG::SceneGraph::BaseNode* node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode(), _nodeId );
439

440
    if (node == 0) return;
441

442
443
444
445
446
447
448
    if(node->className() != "QtTranslationManipulatorNode") {
	contextAction_->setVisible(false);
    }
    else {
	contextAction_->setVisible(true);
    }
}
Jan Möbius's avatar
 
Jan Möbius committed
449
450
451
452

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

/** \brief move the object when its manipulator moves
453
 *
Jan Möbius's avatar
 
Jan Möbius committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
 * @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
  if ( (_event->type() == QEvent::MouseButtonRelease) || (PluginFunctions::pickMode() == "MoveSelection") ) {

    int objectId = _node->getIdentifier();

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

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

478
    // move the object which corresponds to the manipulator
Jan Möbius's avatar
 
Jan Möbius committed
479
480
481
482
483
    if (PluginFunctions::pickMode() != "MoveSelection")
      moveObject( mat, objectId );
    else
      moveSelection( mat, objectId );

484
    // move all other targets without manipulator
485
    if(allTargets_) {
486
487
488
489
490
491
492
493
494
495
      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
496
497
498
499
500
501
502
503
504
505
506
507
508

    lastActiveManipulator_ = objectId;
    updateManipulatorDialog();
  }

  OpenFlipper::Options::redrawDisabled( false );

}


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

/** \brief update object when its manipulator changes position
509
 *
Jan Möbius's avatar
 
Jan Möbius committed
510
511
512
513
514
515
516
 * @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
517
518
519
520
  if ( objectId > 0 ){

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

Dirk Wilden's avatar
Dirk Wilden committed
522
523
524
    // Assume that it has a good position now
    object->manipPlaced( true );
  }
Jan Möbius's avatar
 
Jan Möbius committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538

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

  lastActiveManipulator_ = objectId;
  updateManipulatorDialog();

}


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

/** \brief Place and show the Manipulator
539
 *
Jan Möbius's avatar
 
Jan Möbius committed
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
 * @param _event  mouseEvent that occured
 */
void MovePlugin::placeManip(QMouseEvent * _event)
{
   unsigned int  node_idx, target_idx;
   OpenMesh::Vec3d         hitPoint;

   if ( PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_ANYTHING,_event->pos(), node_idx, target_idx,&hitPoint) ) {

      BaseObjectData* object;

      if ( PluginFunctions::getPickedObject(node_idx, object) ) {
         object->manipPlaced( true );

         if ( !object->picked(node_idx) ) {
Jan Möbius's avatar
Jan Möbius committed
555
            emit log(LOGWARN,tr("Picking failed"));
Jan Möbius's avatar
 
Jan Möbius committed
556
557
558
559
560
         }

         object->manipulatorNode()->loadIdentity();
         object->manipulatorNode()->set_center(hitPoint);
         object->manipulatorNode()->set_draw_cylinder(true);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
561
         object->manipulatorNode()->set_autosize(QtTranslationManipulatorNode::Once);
Jan Möbius's avatar
 
Jan Möbius committed
562
         object->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
563
         object->manipulatorNode()->setMode (manMode_);
Jan Möbius's avatar
 
Jan Möbius committed
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
         object->manipulatorNode()->show();

         object->manipulatorNode()->apply_transformation( PluginFunctions::pickMode() == "Move" );

         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 {
Jan Möbius's avatar
Jan Möbius committed
580
       emit log(LOGWARN,tr("Picking failed"));
Jan Möbius's avatar
 
Jan Möbius committed
581
582
583
584
585
586
587
   }
}


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

/** \brief Checks if the manipulators should be visible or not
588
 *
Jan Möbius's avatar
 
Jan Möbius committed
589
590
591
 */
void MovePlugin::showManipulators( )
{
Dirk Wilden's avatar
Dirk Wilden committed
592

593
594
595
596
597
598
599
600
601
602
	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
603

604
605
606
607
608
609
	} 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
610

611
	emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
612
613
614

}

615
//------------------------------------------------------------------------------
Jan Möbius's avatar
 
Jan Möbius committed
616

617
/** \brief Get Dialog Widget that contains the button
618
 *
619
620
621
622
623
624
625
 * @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
626
627
628
//------------------------------------------------------------------------------

/** \brief Position of manipulator in tab changed
629
 *
Jan Möbius's avatar
 
Jan Möbius committed
630
631
 */
void MovePlugin::slotSetPosition() {
632

633
634
635
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
636

637
    TriMesh::Point newpos;
638

639
640
    bool ok = false;
    newpos[0] =  (pW->nposx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
641
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate")); return; }
642
    newpos[1] =  (pW->nposy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
643
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
644
    newpos[2] =  (pW->nposz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
645
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
646

647
648
649
650
651
652
653
    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
654
655
656
657
658
659
}


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

/** \brief Toggle the first axis for changing direction in tab
660
 *
Jan Möbius's avatar
 
Jan Möbius committed
661
662
 */
void MovePlugin::slotToggleAxisA() {
663

664
665
666
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
667
668

    axisA_ = (axisA_ + 1) % 3;
669

670
671
    if (axisA_ == axisB_)
	axisA_ = (axisA_ + 1) % 3;
672

673
    switch(axisA_){
Jan Möbius's avatar
Jan Möbius committed
674
675
676
	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;
677
678
	default: break;
    }
Jan Möbius's avatar
 
Jan Möbius committed
679
680
681
682
683
684
}


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

/** \brief Toggle the second axis for changing direction in tab
685
 *
Jan Möbius's avatar
 
Jan Möbius committed
686
687
 */
void MovePlugin::slotToggleAxisB() {
688

689
690
691
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
692
693

    axisB_ = (axisB_ + 1) % 3;
694

695
696
    if (axisA_ == axisB_)
	axisB_ = (axisB_ + 1) % 3;
697

698
    switch(axisB_){
Jan Möbius's avatar
Jan Möbius committed
699
700
701
	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;
702
703
	default: break;
    }
Jan Möbius's avatar
 
Jan Möbius committed
704
705
706
707
708
709
}


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

/** \brief Set Direction of manipulator in tab changed
710
 *
Jan Möbius's avatar
 
Jan Möbius committed
711
712
 */
void MovePlugin::slotSetDirection() {
713

714
715
716
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
717

718
719
720
    ACG::Vec3d newdirA,newdirB;
    ACG::Vec3d dirX,dirY;
    ACG::Vec3d dirZ(0.0,0.0,0.0);
721

722
723
    bool ok = false;
    newdirA[0] =  (pW->ndirAx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
724
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
725
    newdirA[1] =  (pW->ndirAy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
726
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
727
    newdirA[2] =  (pW->ndirAz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
728
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
729

730
    newdirB[0] =  (pW->ndirBx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
731
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
732
    newdirB[1] =  (pW->ndirBy->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
733
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
734
    newdirB[2] =  (pW->ndirBz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
735
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
736

737
738
    bool xAxis = false;
    bool yAxis = false;
739

740
741
742
743
744
    switch(axisA_){
	case  0: dirX = newdirA; xAxis = true; break;
	case  1: dirY = newdirA; yAxis = true; break;
	default: dirZ = newdirA; break;
    }
745

746
747
748
749
750
    switch(axisB_){
	case  0: dirX = newdirB; xAxis = true; break;
	case  1: dirY = newdirB; yAxis = true; break;
	default: dirZ = newdirB; break;
    }
751

752
753
    if (!xAxis)
	dirX = dirY % dirZ;
754

755
756
    if (!yAxis)
	dirY = dirX % dirZ;
757
758


759
    if ( (dirX | dirY) != 0.0){
Jan Möbius's avatar
Jan Möbius committed
760
	emit log(LOGERR,tr("The axes of the new direction have to be orthogonal"));
761
762
	return;
    }
763

Jan Möbius's avatar
Jan Möbius committed
764
765
766
767
768
769
770
771
772
//    // 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 );
// 	}
//     }

773
774
775
    BaseObjectData* object = pW->getBaseObjectData();
    if ( object != 0 ) {
        if (  object->manipulatorNode()->visible() ){
Jan Möbius's avatar
 
Jan Möbius committed
776
777

            object->manipulatorNode()->set_direction( dirX, dirY );
778
779
	}
    } else return;
780

781
782
    updateManipulatorDialog();
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
783
784
785
786
787
788
}


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

/** \brief perform a translation for Manipulator in tab
789
 *
Jan Möbius's avatar
 
Jan Möbius committed
790
791
 */
void MovePlugin::slotTranslation() {
792

793
794
795
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
796

797
    ACG::Vec3d translation;
798

799
800
    bool ok = false;
    translation[0] =  (pW->translationX->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
801
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
802
    translation[1] =  (pW->translationY->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
803
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
804
    translation[2] =  (pW->translationZ->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
805
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
806

Jan Möbius's avatar
Jan Möbius committed
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
//	// 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());
//		}
//
//	}

838
    BaseObjectData* object = pW->getBaseObjectData();
839
	if (object != 0) {
840
		if (object->manipulatorNode()->visible()) {
Jan Möbius's avatar
 
Jan Möbius committed
841

842
			translate(object->id(), translation);
843

844
845
846
847
848
849
850
			object->manipulatorNode()->set_center(
					object->manipulatorNode()->center() + translation);
			emit createBackup(object->id(), "Translation");
			emit updatedObject(object->id());
		}
	} else {
		return;
851
	}
Jan Möbius's avatar
 
Jan Möbius committed
852

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

854
855
856
    updateManipulatorDialog();
    emit scriptInfo(QString("slotTranslation()"));
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
857
858
859
860
861
862
}


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

/** \brief Project the current manipulator onto the tangent plane of the object
863
 *
Jan Möbius's avatar
 
Jan Möbius committed
864
865
 */
void MovePlugin::slotProjectToTangentPlane() {
866

867
868
869
870
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;

871
    if ( allTargets_ ) {
Jan Möbius's avatar
Jan Möbius committed
872
    	emit log(LOGWARN,tr("TODO Project for multiple targets"));
873
    	return;
874
    } else {
Jan Möbius's avatar
Jan Möbius committed
875
    	emit log(LOGWARN,tr("TODO Project for one target"));
876
    	return;
877
    }
Jan Möbius's avatar
 
Jan Möbius committed
878
879
880
881
882
883
884

}


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

/** \brief Move the current manipulator to the cog of the object
885
 *
Jan Möbius's avatar
 
Jan Möbius committed
886
887
 */
void MovePlugin::slotMoveManipToCOG() {
888

889
890
891
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
892

Jan Möbius's avatar
Jan Möbius committed
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908

//     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 {

909
910
911
    BaseObjectData* object = pW->getBaseObjectData();
    if ( object != 0 ) {
	if (  object->manipulatorNode()->visible() ){
912

913
914
915
916
	    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
917

918
919
920
921
	    updateManipulatorDialog();
	    object->manipulatorNode()->loadIdentity();
	}
    }
Jan Möbius's avatar
 
Jan Möbius committed
922

923
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
924
925
926
927
928
929
}


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

/** \brief Rotate Manipulator (with values from Tab)
930
 *
Jan Möbius's avatar
 
Jan Möbius committed
931
932
 */
void MovePlugin::slotRotate() {
933

934
935
936
    QPushButton* but = dynamic_cast<QPushButton*>(QObject::sender());
    movePropsWidget* pW = getDialogFromButton(but);
    if(pW == 0) return;
937

938
939
    TriMesh::Point axis;
    double angle;
940

941
942
    bool ok = false;
    axis[0] =  (pW->rotx->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
943
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for X Coordinate"));  return; }
944
    axis[1] =  (pW->roty->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
945
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Y Coordinate")); return; }
946
    axis[2] =  (pW->rotz->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
947
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for Z Coordinate")); return; }
948

949
    angle =  (pW->rotAngle->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
950
    if ( !ok ) {  emit log(LOGERR,tr("Wrong Format for Angle")); return; }
951

Jan Möbius's avatar
Jan Möbius committed
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
//     if ( pW->targetObjects->isChecked() ) {
// 	for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
// 		if (  o_it->manipulatorNode()->hidden() )
// 		continue;
// 		o_it->manipulatorNode()->rotate(  angle,axis);
//
// 		if (o_it->dataType( DATA_TRIANGLE_MESH ) )
// 		transformMesh(  o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) );
//
// 		if (o_it->dataType( DATA_POLY_MESH ) )
// 		transformMesh(  o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) );
//
// 		o_it->manipulatorNode()->loadIdentity();
// 		updateManipulatorDialog();
//
// 		emit createBackup(o_it->id(),"Rotation");
// 		emit updatedObject(o_it->id());
// 	}
//     } else {


973
    BaseObjectData* object = pW->getBaseObjectData();
974
975
	if (object != 0) {
		if (object->manipulatorNode()->visible() && (object->target()
976
				|| !allTargets_)) {
977

978
			object->manipulatorNode()->rotate(angle, axis);
979

980
981
982
			if (object->dataType(DATA_TRIANGLE_MESH))
				transformMesh(getLastManipulatorMatrix(true),
						(*PluginFunctions::triMesh(object)));
983

984
985
986
			if (object->dataType(DATA_POLY_MESH))
				transformMesh(getLastManipulatorMatrix(true),
						(*PluginFunctions::polyMesh(object)));
987

988
			updateManipulatorDialog();
989

990
991
992
			emit createBackup(object->id(), "Rotation");
			emit updatedObject(object->id());
		}
993
	}
994

995
996
	emit scriptInfo(QString("slotRotate()"));
	emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
997
998
999
1000
1001
1002
}


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

/** \brief Scale Manipulator (with values from Tab)
1003
 *
Jan Möbius's avatar
 
Jan Möbius committed
1004
1005
 */
void MovePlugin::slotScale() {
1006

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


1012
    TriMesh::Point scale;
1013

1014
1015
    bool ok = false;
    scale[0] =  (pW->scalex->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
1016
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for factor 1"));  return; }
1017
    scale[1] =  (pW->scaley->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
1018
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for factor 2")); return; }
1019
    scale[2] =  (pW->scalez->text()).toDouble(&ok);
Jan Möbius's avatar
Jan Möbius committed
1020
    if ( !ok ) { emit log(LOGERR,tr("Wrong Format for factor 3")); return; }
1021

Jan Möbius's avatar
Jan Möbius committed
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
//    if ( pW->targetObjects->isChecked() ) {
// 	for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
// 		if (  o_it->manipulatorNode()->hidden() )
// 		continue;
// 		o_it->manipulatorNode()->scale(  scale);
//
// 		if (o_it->dataType( DATA_TRIANGLE_MESH ) )
// 		transformMesh(  o_it->manipulatorNode()->matrix() , (*PluginFunctions::triMesh(*o_it)) );
//
// 		if (o_it->dataType( DATA_POLY_MESH ) )
// 		transformMesh(  o_it->manipulatorNode()->matrix() , (*PluginFunctions::polyMesh(*o_it)) );
//
// 		o_it->manipulatorNode()->loadIdentity();
// 		updateManipulatorDialog();
//
// 		emit createBackup(o_it->id(),"Scaling");
// 		emit updatedObject(o_it->id());
// 	}
//     } else {


1043
    BaseObjectData* object = pW->getBaseObjectData();
1044
1045
	if (object != 0) {
		if (object->manipulatorNode()->visible() && (object->target()
1046
				|| !allTargets_)) {
Jan Möbius's avatar
 
Jan Möbius committed
1047

1048
			object->manipulatorNode()->scale(scale);
1049

1050
1051
1052
			if (object->dataType(DATA_TRIANGLE_MESH))
				transformMesh(getLastManipulatorMatrix(true),
						(*PluginFunctions::triMesh(object)));
1053

1054
1055
1056
			if (object->dataType(DATA_POLY_MESH))
				transformMesh(getLastManipulatorMatrix(true),
						(*PluginFunctions::polyMesh(object)));
1057

1058
			updateManipulatorDialog();
1059

1060
1061
1062
			emit createBackup(object->id(), "Scaling");
			emit updatedObject(object->id());
		}
1063
	}
Jan Möbius's avatar
 
Jan Möbius committed
1064

1065
1066
    emit scriptInfo(QString("slotScale()"));
    emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
1067
1068
1069
1070
1071
1072
}


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


1073
/** \brief Move target Meshes cog to the origin
1074
 *
Jan Möbius's avatar
 
Jan Möbius committed
1075
1076
1077
 */
void MovePlugin::slotMoveToOrigin() {

1078
1079
1080
1081
1082
1083
1084
1085
  bool useCommonCOG = false;
  ACG::Vec3d cog = ACG::Vec3d(0.0,0.0,0.0);
  
  if ( PluginFunctions::targetCount() > 1 ) {
    QMessageBox::StandardButton button = QMessageBox::question( 0, tr("Use common COG?"), tr("Should the targets be moved depending on their common cog?"),QMessageBox::Yes|QMessageBox::No);
    
    
    useCommonCOG =  ( button == QMessageBox::Yes );
Jan Möbius's avatar
Jan Möbius committed
1086
    double vertexCount = 0.0;
1087

1088
1089
1090
1091
1092
1093
    if ( useCommonCOG ) {
      
      // Compute cog for all objects
      for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
        if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
          TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
Jan Möbius's avatar
Jan Möbius committed
1094
1095
          cog += MeshInfo::cog(mesh) * double(mesh.n_vertices());
          vertexCount += double(mesh.n_vertices());
1096
        }
Jan Möbius's avatar
 
Jan Möbius committed
1097

1098
1099
        if ( o_it->dataType( DATA_POLY_MESH )) {
          PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
Jan Möbius's avatar
Jan Möbius committed
1100
1101
          cog += MeshInfo::cog(mesh) * double(mesh.n_vertices());
          vertexCount += double(mesh.n_vertices());
1102
        }
1103
      }
1104
      
Jan Möbius's avatar
Jan Möbius committed
1105
      cog = cog / vertexCount;
1106
1107
1108
    }
    
  }
Jan Möbius's avatar
 
Jan Möbius committed
1109

1110
1111
1112
1113
1114
1115
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
    if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
        TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
        
        if ( !useCommonCOG ) 
          cog = MeshInfo::cog(mesh);
Jan Möbius's avatar
 
Jan Möbius committed
1116

1117
1118
        for ( TriMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
          mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
Jan Möbius's avatar
 
Jan Möbius committed
1119

1120
1121
        o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );
    }
Jan Möbius's avatar
 
Jan Möbius committed
1122

1123
1124
1125
1126
1127
    if ( o_it->dataType( DATA_POLY_MESH )) {
        PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
        
        if ( !useCommonCOG ) 
          cog = MeshInfo::cog(mesh);
Jan Möbius's avatar
 
Jan Möbius committed
1128

1129
1130
        for ( PolyMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end() ; ++v_it)
          mesh.set_point(v_it , ( mesh.point(v_it) ) - cog );
Jan Möbius's avatar
 
Jan Möbius committed
1131

1132
1133
1134
1135
1136
        o_it->manipulatorNode()->set_center( o_it->manipulatorNode()->center() - cog );

    }

    emit updatedObject( o_it->id() );
Jan Möbius's avatar
 
Jan Möbius committed
1137

1138
1139
1140
1141
1142
1143
1144
    updateManipulatorDialog();
    o_it->manipulatorNode()->loadIdentity();

    emit createBackup(o_it->id(),"Move to origin");
  }

  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
1145
1146
1147
1148
1149
1150
}


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

/** \brief Scale Boundingbox Diagonal to unit size
1151
 *
Jan Möbius's avatar
 
Jan Möbius committed
1152
1153
1154
 */
void MovePlugin::slotUnifyBoundingBoxDiagonal()
{
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
  bool useCommonBB = false;
  ACG::Vec3d bb_min = ACG::Vec3d(FLT_MAX,FLT_MAX,FLT_MAX);
  ACG::Vec3d bb_max = ACG::Vec3d(FLT_MIN,FLT_MIN,FLT_MIN);
  
  if ( PluginFunctions::targetCount() > 1 ) {
    QMessageBox::StandardButton button = QMessageBox::question( 0, tr("Use common BB?"), tr("Should the targets be scaled depending on their common Bounding Box?"),QMessageBox::Yes|QMessageBox::No);
    
    
    useCommonBB =  ( button == QMessageBox::Yes );
    double count = 0.0;

    if ( useCommonBB ) {
      
      // Compute cog for all objects
      for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
        ACG::Vec3d bb_min_tmp(0.0,0.0,0.0);
        ACG::Vec3d bb_max_tmp(0.0,0.0,0.0);
        
        if ( o_it->dataType( DATA_TRIANGLE_MESH )) {
          TriMesh& mesh = *PluginFunctions::triMesh(*o_it);
          getBB(mesh,bb_min_tmp,bb_max_tmp);
          bb_min.minimize(bb_min_tmp);
          bb_max.maximize(bb_max_tmp);
        }

        if ( o_it->dataType( DATA_POLY_MESH )) {
          PolyMesh& mesh = *PluginFunctions::polyMesh(*o_it);
          getBB(mesh,bb_min_tmp,bb_max_tmp);
          bb_min.minimize(bb_min_tmp);
          bb_max.maximize(bb_max_tmp);          
        }
      }
    }
    
  }
  
1191
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it)  {
1192
1193
1194
1195
1196
1197
    if ( useCommonBB ) {
      if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
        unifyBBDiag(*PluginFunctions::triMesh(*o_it),bb_min,bb_max);
      else if ( o_it->dataType( DATA_POLY_MESH ) )
        unifyBBDiag(*PluginFunctions::polyMesh(*o_it),bb_min,bb_max);
    } else {
1198
1199
1200
      if ( o_it->dataType( DATA_TRIANGLE_MESH ) )
        unifyBBDiag(*PluginFunctions::triMesh(*o_it));
      else if ( o_it->dataType( DATA_POLY_MESH ) )
1201
1202
        unifyBBDiag(*PluginFunctions::polyMesh(*o_it)); 
    }
Jan Möbius's avatar
 
Jan Möbius committed
1203

1204
    emit updatedObject( o_it->id() );
Jan Möbius's avatar
 
Jan Möbius committed
1205

1206
1207
1208
  }
       
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
1209
1210
1211
1212
1213
1214
}


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

/** \brief Update the Dialog with the last clicked manipulator
1215
 *
Jan Möbius's avatar
 
Jan Möbius committed
1216
1217
 */
void MovePlugin::updateManipulatorDialog() {
1218

1219
1220
1221
1222
    BaseObjectData* object;
    if ( !PluginFunctions::getObject(lastActiveManipulator_ , object) ) {
	return;
    }
1223

1224
    if ( object->manipulatorNode()->visible() ) {
1225

1226
1227
1228
	// Get properties widget that corresponds to
        // to the last manipulated object
        movePropsWidget* pW = getDialogWidget(object);
1229

Mike Kremer's avatar