MovePluginScript.cc 37.4 KB
Newer Older
1 2 3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
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
 *                           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

Jan Möbius's avatar
 
Jan Möbius committed
43 44 45
#include "MovePlugin.hh"

#include "../OpenFlipper/BasePlugin/PluginFunctions.hh"
Jan Möbius's avatar
Jan Möbius committed
46
#ifdef ENABLE_POLYLINE_SUPPORT
Jan Möbius's avatar
Jan Möbius committed
47
#include <ObjectTypes/PolyLine/PolyLine.hh>
Jan Möbius's avatar
Jan Möbius committed
48
#endif
Henrik Zimmer's avatar
Henrik Zimmer committed
49 50 51
#ifdef ENABLE_TSPLINEMESH_SUPPORT
#include <ObjectTypes/TSplineMesh/TSplineMesh.hh>
#endif
52 53 54
#ifdef ENABLE_SKELETON_SUPPORT
#include <ObjectTypes/Skeleton/SkeletonTransform.hh>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
55 56 57 58 59

#include <MeshTools/MeshFunctions.hh>


/** \brief Set Descriptions for Scripting Slots
Jan Möbius's avatar
Jan Möbius committed
60
 *
Jan Möbius's avatar
 
Jan Möbius committed
61 62 63
 */
void MovePlugin::setDescriptions(){

Jan Möbius's avatar
Jan Möbius committed
64 65
  emit setSlotDescription("translate(int,Vector)",tr("Translate object by given vector."),
                          QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
66

Jan Möbius's avatar
Jan Möbius committed
67 68 69
  emit setSlotDescription("translate(int,idList,Vector)",tr("Translate vertices by given vector."),
                          QString(tr("objectId,VertexHandles,Vector")).split(","),
                          QString(tr("ID of an object, List of vertex handles, translation vector")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
70

Jan Möbius's avatar
Jan Möbius committed
71 72
  emit setSlotDescription("translateVertexSelection(int,Vector)",tr("Translate current vertex selection of an object by given vector."),
                          QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
73

Jan Möbius's avatar
Jan Möbius committed
74 75
  emit setSlotDescription("translateFaceSelection(int,Vector)",tr("Translate current face selection of an object by given vector."),
                          QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
76

Jan Möbius's avatar
Jan Möbius committed
77 78
  emit setSlotDescription("translateEdgeSelection(int,Vector)",tr("Translate current edge selection of an object by given vector."),
                          QString(tr("objectId,Vector")).split(","), QString(tr("ID of an object, translation vector")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
79

Jan Möbius's avatar
Jan Möbius committed
80 81
  emit setSlotDescription("transform(int,Matrix4x4)",tr("transform object by given matrix."),
                          QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
82

Jan Möbius's avatar
Jan Möbius committed
83 84 85
  emit setSlotDescription("transform(int,idList,Matrix4x4)",tr("transform vertices by given matrix."),
                          QString(tr("objectId,VertexHandles,Matrix")).split(","),
                          QString(tr("ID of an object, List of vertex handles, transformation matrix")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
86

Jan Möbius's avatar
Jan Möbius committed
87 88
  emit setSlotDescription("transformSelection(int,Matrix4x4)",tr("transform current selection of an object by given matrix."),
                          QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
89

Jan Möbius's avatar
Jan Möbius committed
90 91
  emit setSlotDescription("setManipulatorPosition(int,Vector)",tr("Set the position of the manipulator."),
                          QString(tr("objectId,Position")).split(","), QString(tr("ID of an object, 3D point")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
92

Jan Möbius's avatar
Jan Möbius committed
93 94
  emit setSlotDescription("setManipulatorDirection(int,Vector, Vector)",tr("Set the direction of the manipulator."),
                          QString(tr("objectId,Direction, Direction")).split(","), QString(tr("ID of an object, x-direction, y-direction")).split(","));
Jan Möbius's avatar
 
Jan Möbius committed
95

Jan Möbius's avatar
Jan Möbius committed
96 97
  emit setSlotDescription("manipulatorPosition(int)",tr("Returns the position of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Jan Möbius's avatar
 
Jan Möbius committed
98

Jan Möbius's avatar
Jan Möbius committed
99 100
  emit setSlotDescription("manipulatorDirectionX(int)",tr("Returns the x-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Jan Möbius's avatar
 
Jan Möbius committed
101

Jan Möbius's avatar
Jan Möbius committed
102 103
  emit setSlotDescription("manipulatorDirectionY(int)",tr("Returns the y-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Jan Möbius's avatar
 
Jan Möbius committed
104

Jan Möbius's avatar
Jan Möbius committed
105 106
  emit setSlotDescription("manipulatorDirectionZ(int)",tr("Returns the z-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
Jan Möbius's avatar
 
Jan Möbius committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120
}


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

/** \brief Translate an object
 *
 * @param _objectId id of the object
 * @param _vector translation vector
 */
void MovePlugin::translate( int _objectId , Vector _vector) {

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
121
    emit log(LOGERR,tr("translate : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      mesh.set_point(v_it,mesh.point(v_it) + _vector );

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      mesh.set_point(v_it,mesh.point(v_it) + _vector );

Henrik Zimmer's avatar
Henrik Zimmer committed
141
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
142
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
143
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
144 145 146 147 148 149 150

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      mesh.set_point(v_it,mesh.point(v_it) + _vector );

Jan Möbius's avatar
 
Jan Möbius committed
151
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
152
#endif
Jan Möbius's avatar
Jan Möbius committed
153 154
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
155 156 157 158 159
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
        line.point(i) = line.point(i)  + _vector; 
Jan Möbius's avatar
Jan Möbius committed
160 161 162 163 164 165 166
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
167

168
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
169 170 171 172 173

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
174 175 176
                   
  // Create backup
  emit createBackup(_objectId, "Translation");
Jan Möbius's avatar
 
Jan Möbius committed
177 178 179 180 181 182
}


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

/** \brief translate a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
183
 *
Jan Möbius's avatar
 
Jan Möbius committed
184 185 186 187
 * @param _objectId id of an object
 * @param _vHandles list of vertex handles
 * @param _vector translation vector
 */
Jan Möbius's avatar
Jan Möbius committed
188
void MovePlugin::translate( int _objectId , IdList _vHandles, Vector _vector ){
Jan Möbius's avatar
 
Jan Möbius committed
189 190
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
191
    emit log(LOGERR,tr("translate : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));

    for (uint i=0; i < _vHandles.size(); i++){
      TriMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point(vh  ,mesh.point( vh ) + _vector );
    }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));

    for (uint i=0; i < _vHandles.size(); i++){
      PolyMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point(vh  ,mesh.point( vh ) + _vector );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
212
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
213
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
214
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
215 216 217 218 219 220 221

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));

    for (uint i=0; i < _vHandles.size(); i++){
      TSplineMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point(vh  ,mesh.point( vh ) + _vector );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
222
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
223
#endif
Jan Möbius's avatar
 
Jan Möbius committed
224

Jan Möbius's avatar
Jan Möbius committed
225 226
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
227 228 229 230 231 232 233 234
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      const int max = line.n_vertices();
      
      for ( unsigned int i = 0 ; i < _vHandles.size(); ++i ) 
        if ( (_vHandles[i] > 0) && ( _vHandles[i] < max ) )
          line.point( _vHandles[i] ) = line.point( _vHandles[i] )  + _vector; 
Jan Möbius's avatar
Jan Möbius committed
235 236 237 238 239 240 241
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
242

243
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
244 245 246 247 248

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
249 250 251
                   
  // Create backup
  emit createBackup(_objectId, "Translation");
Jan Möbius's avatar
 
Jan Möbius committed
252 253 254 255 256 257 258

}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
259
 *
Jan Möbius's avatar
 
Jan Möbius committed
260 261 262 263 264 265 266
 * @param _objectId id of an object
 * @param _vector translation vector
 */
void MovePlugin::translateSelection( int _objectId , Vector _vector) {

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
267
    emit log(LOGERR,tr("translate : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
        mesh.set_point(v_it,mesh.point(v_it) + _vector );

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Henrik Zimmer's avatar
Henrik Zimmer committed
288
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
289
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
290
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
291 292 293 294 295 296 297

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Jan Möbius's avatar
 
Jan Möbius committed
298
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
299 300
#endif
  
Jan Möbius's avatar
Jan Möbius committed
301 302
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
303 304 305 306 307 308
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
        if ( line.vertex_selection(i) )
          line.point(i) = line.point(i)  + _vector; 
Jan Möbius's avatar
Jan Möbius committed
309 310 311 312 313 314 315
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
316

317
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
318 319 320 321 322

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
323 324 325
                   
  // Create backup
  emit createBackup(_objectId, "Translation of Selection");
Jan Möbius's avatar
 
Jan Möbius committed
326 327 328 329 330 331
}


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

/** \brief tranform an object
Jan Möbius's avatar
Jan Möbius committed
332
 *
Jan Möbius's avatar
 
Jan Möbius committed
333 334 335 336 337 338 339
 * @param _objectId object id
 * @param _matrix transformation matrix
 */
void MovePlugin::transform( int _objectId , Matrix4x4 _matrix ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
340
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it){
      mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
      mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
    }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it){
      mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
      mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
363
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
364
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
365
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
366 367 368 369 370 371 372 373

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it){
      mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
      mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
374
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
375
#endif
Jan Möbius's avatar
 
Jan Möbius committed
376

Jan Möbius's avatar
Jan Möbius committed
377 378
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
379 380 381 382 383
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
        line.point(i) = _matrix.transform_point( line.point(i) ); 
Jan Möbius's avatar
Jan Möbius committed
384 385 386 387 388 389 390
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
391

392
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
393 394 395 396 397 398 399 400 401

  QString matString;
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transform( ObjectId , Matrix4x4(" + matString + " ) )" );
402 403 404
  
  // Create backup
  emit createBackup(_objectId, "Transformation");
Jan Möbius's avatar
 
Jan Möbius committed
405 406 407 408 409 410
}


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

/** \brief Tranform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
411
 *
Jan Möbius's avatar
 
Jan Möbius committed
412 413 414 415
 * @param _objectId id of an object
 * @param _vHandles list of vertex handles
 * @param _matrix transformation matrix
 */
Jan Möbius's avatar
Jan Möbius committed
416
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
417 418 419

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
420
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();

    for (uint i=0; i < _vHandles.size(); i++){
      TriMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
      mesh.set_normal(vh, _matrix.transform_vector( mesh.normal(vh) ) );
    }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();

    for (uint i=0; i < _vHandles.size(); i++){
      PolyMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
      mesh.set_normal(vh, _matrix.transform_vector( mesh.normal(vh) ) );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
447
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
448
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
449
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
450 451 452 453 454 455 456 457 458 459

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();

    for (uint i=0; i < _vHandles.size(); i++){
      TSplineMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
      mesh.set_normal(vh, _matrix.transform_vector( mesh.normal(vh) ) );
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
460
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
461
#endif
Jan Möbius's avatar
 
Jan Möbius committed
462

Jan Möbius's avatar
Jan Möbius committed
463 464
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
465 466 467 468 469 470 471 472 473
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      const int max = line.n_vertices();
      
      for ( unsigned int i = 0 ; i < _vHandles.size(); ++i ) 
        if ( (_vHandles[i] > 0) && ( _vHandles[i] < max ) )
          line.point( _vHandles[i] ) = _matrix.transform_point( line.point( _vHandles[i] ) ); 
      
Jan Möbius's avatar
Jan Möbius committed
474 475 476 477 478 479 480
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
481

482
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
483 484 485 486 487 488 489 490 491

  QString matString;
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transform( ObjectId , Matrix4x4(" + matString + " ) )" );
492 493 494
  
  // Create backup
  emit createBackup(_objectId, "Transformation");
Jan Möbius's avatar
 
Jan Möbius committed
495 496 497 498 499 500
}


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

/** \brief transform vertex selection
Jan Möbius's avatar
Jan Möbius committed
501
 *
Jan Möbius's avatar
 
Jan Möbius committed
502 503 504 505 506 507 508
 * @param _objectId id of an object
 * @param _matrix transformation matrix
 */
void MovePlugin::transformVertexSelection( int _objectId , Matrix4x4 _matrix ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
509
    emit log(LOGERR,tr("transform : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
      {
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
      {
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
536
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
537
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
538
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
539 540 541 542 543 544 545 546 547 548

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).selected() )
      {
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
549
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
550
#endif
Henrik Zimmer's avatar
Henrik Zimmer committed
551
  
Jan Möbius's avatar
Jan Möbius committed
552 553
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
554 555 556 557 558 559
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
        if ( line.vertex_selection(i) )
          line.point(i) = _matrix.transform_point( line.point(i) ); 
Jan Möbius's avatar
Jan Möbius committed
560 561 562 563 564 565 566
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
567

568
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
569 570 571 572 573 574 575 576 577

  QString matString;
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transformVertexSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
578 579 580
  
  // Create backup
  emit createBackup(_objectId, "Transformation of Vertex Selection");
Jan Möbius's avatar
 
Jan Möbius committed
581 582 583 584 585 586
}


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

/** \brief transform face selection
Jan Möbius's avatar
Jan Möbius committed
587
 *
Jan Möbius's avatar
 
Jan Möbius committed
588 589 590 591 592 593 594
 * @param _objectId id of an object
 * @param _matrix transformation matrix
 */
void MovePlugin::transformFaceSelection( int _objectId , Matrix4x4 _matrix ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
595
    emit log(LOGERR,tr("transform : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));

    //init tags
    TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    TriMesh::FaceIter f_it  = mesh.faces_begin();
    TriMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
      if ( mesh.status(f_it).selected() )
      {
        for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it)
          mesh.status(fv_it).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));

    //init tags
    PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    PolyMesh::FaceIter f_it  = mesh.faces_begin();
    PolyMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
      if ( mesh.status(f_it).selected() )
      {
        for(PolyMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it)
          mesh.status(fv_it).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
646
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
647
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
648
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));

    //init tags
    TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    TSplineMesh::FaceIter f_it  = mesh.faces_begin();
    TSplineMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
      if ( mesh.status(f_it).selected() )
      {
        for(TSplineMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it)
          mesh.status(fv_it).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Jan Möbius's avatar
 
Jan Möbius committed
671
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
672
#endif
Jan Möbius's avatar
Jan Möbius committed
673 674


675
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
676 677 678 679 680 681 682 683 684

  QString matString;
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transformFaceSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
685 686 687
  
  // Create backup
  emit createBackup(_objectId, "Transformation of Face Selection");
Jan Möbius's avatar
 
Jan Möbius committed
688 689 690 691 692 693
}


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

/** \brief transform edge selection
Jan Möbius's avatar
Jan Möbius committed
694
 *
Jan Möbius's avatar
 
Jan Möbius committed
695 696 697 698 699 700 701
 * @param _objectId id of an object
 * @param _matrix transformation matrix
 */
void MovePlugin::transformEdgeSelection( int _objectId , Matrix4x4 _matrix ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
702
    emit log(LOGERR,tr("transform : unable to get object" ) );
Jan Möbius's avatar
 
Jan Möbius committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));

    //init tags
    TriMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    TriMesh::EdgeIter e_it  = mesh.edges_begin();
    TriMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
      if ( mesh.status(e_it).selected() )
      {
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( e_it, 0 );

        mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
        mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }

  } else if ( object->dataType( DATA_POLY_MESH ) ) {

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));

    //init tags
    PolyMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    PolyMesh::EdgeIter e_it  = mesh.edges_begin();
    PolyMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
      if ( mesh.status(e_it).selected() )
      {
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( e_it, 0 );

        mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
        mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
757
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
758
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
759
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));

    //init tags
    TSplineMesh::VertexIter v_it, v_end( mesh.vertices_end() );
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
        mesh.status(v_it).set_tagged(false);

    TSplineMesh::EdgeIter e_it  = mesh.edges_begin();
    TSplineMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
      if ( mesh.status(e_it).selected() )
      {
        TSplineMesh::HalfedgeHandle hh = mesh.halfedge_handle( e_it, 0 );

        mesh.status( mesh.from_vertex_handle( hh ) ).set_tagged(true);
        mesh.status( mesh.to_vertex_handle( hh ) ).set_tagged(true);
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() ){
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
        mesh.set_normal(v_it, _matrix.transform_vector( mesh.normal(v_it) ) );
      }
Jan Möbius's avatar
 
Jan Möbius committed
784
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
785 786
#endif
  
Jan Möbius's avatar
Jan Möbius committed
787 788 789 790 791 792 793 794 795 796
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
      std::cerr << "Todo : transform PolyLine" << std::endl;
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
Jan Möbius's avatar
 
Jan Möbius committed
797

798
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
799 800 801 802 803 804 805 806 807

  QString matString;
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transformEdgeSelection( ObjectId , Matrix4x4(" + matString + " ) )" );
808 809 810
  
  // Create backup
  emit createBackup(_objectId, "Transformation of Edge Selection");
Jan Möbius's avatar
 
Jan Möbius committed
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
//------------------------------------------------------------------------------

#ifdef ENABLE_SKELETON_SUPPORT
/** \brief transform selected joints with given matrix
 *
 * when a manipulator is placed on a joint, the selection of the skeleton
 * is cleared and only that joint is selected
 * the selection is used here to find the joint to be deformed
 *
 * @param _objectId id of an object
 * @param _matrix transformation matrix
 */
void MovePlugin::transformSkeletonJoint( int _objectId , Matrix4x4 _matrix ){
    
  BaseObjectData* obj = 0;
  
  PluginFunctions::getObject(_objectId, obj);
  
  if (obj == 0){
    emit log(LOGERR, tr("Unable to get object"));
    return;
  }
  
Dirk Wilden's avatar
Dirk Wilden committed
836 837 838 839 840 841 842
  SkeletonObject* skeletonObj = PluginFunctions::skeletonObject(obj);
  
  if (skeletonObj == 0){
    emit log(LOGERR, tr("Unable to get skeletonObject"));
    return;
  }
  
843 844 845 846 847 848 849
  Skeleton* skeleton = PluginFunctions::skeleton(obj);

  if (skeleton == 0){
    emit log(LOGERR, tr("Unable to get skeleton"));
    return;
  }
  
Dirk Wilden's avatar
Dirk Wilden committed
850 851
  bool recursiveJointTransformation = recursiveJointTransformation_;
  
Dirk Wilden's avatar
Dirk Wilden committed
852
  AnimationHandle handle = skeletonObj->skeletonNode()->getActivePose();
853
  
854 855
  Skeleton::Pose* activePose;
  
856
  if ( !handle.isValid() ){
857
    activePose = skeleton->getReferencePose();
858
  }else{
Dirk Wilden's avatar
Dirk Wilden committed
859
    
860
    activePose = skeleton->getAnimation( handle.getAnimation() )->getPose( handle.getFrame() );
Dirk Wilden's avatar
Dirk Wilden committed
861 862 863 864 865 866 867 868 869 870 871 872 873
    
    //always tranform children otherwise only the local coordsys is rotated
    recursiveJointTransformation = false;
    
    // translation changes the skeleton structure
    // this is only allowed in refPose therefore delete translation
    Matrix4x4 mat = _matrix;
    mat(0,3) = 0.0;
    mat(1,3) = 0.0;
    mat(2,3) = 0.0;
    if ( mat.is_identity() )
      _matrix = mat;
  }
874

875 876
  Skeleton::Joint* joint = skeleton->getJoint( skeletonObj->manipulatorNode()->getData().toInt() );
  
877
  SkeletonTransform transformer(*skeleton);
878
  
879 880 881
  if ( handle.isValid() )
    //we are in an animation pose -> only rotation allowed
    transformer.rotateJoint(joint, activePose, _matrix, !transformCurrentPose_);
882
  else
883 884 885 886 887 888 889 890 891 892 893 894 895
    //we are in the refPose apply full transformation
    transformer.transformJoint(joint, _matrix, recursiveJointTransformation);

//   //if we are in refPose update segmentation
//   if ( !handle.isValid() ){  
//     //tell segmenation plugin to update the segmentation
//     bool exists = false;
// 
//     emit functionExists("segmentationplugin", "updateSegmentation()", exists);
// 
//     if (exists)
//       RPC::callFunction("segmentationplugin", "updateSegmentation");
//   }
Dirk Wilden's avatar
Dirk Wilden committed
896 897 898 899 900

  //update the skin
  bool exists = false;

  emit functionExists("skeletonplugin", "updateSkin()", exists);
901
  
Dirk Wilden's avatar
Dirk Wilden committed
902 903 904
  if (exists)
    RPC::callFunction("skeletonplugin", "updateSkin");

905
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
906
 
907
  QString matString;
908 909 910 911 912 913 914 915 916 917
  for (int i=0; i < 4; i++)
    for (int j=0; j < 4; j++)
      matString += " , " + QString::number( _matrix(i,j) );

  matString = matString.right( matString.length()-3 );

  emit scriptInfo( "transformSkeletonJoint( ObjectId , Matrix4x4(" + matString + " ) )" );
  
  // Create backup
  emit createBackup(_objectId, "Transformation of Skeleton Joints");
918 919 920
}

#endif
Jan Möbius's avatar
 
Jan Möbius committed
921 922 923 924

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

/** \brief set the position of the manipulator
Jan Möbius's avatar
Jan Möbius committed
925
 *
Jan Möbius's avatar
 
Jan Möbius committed
926 927 928 929 930 931 932
 * @param _objectId id of an object
 * @param _position new position
 */
void MovePlugin::setManipulatorPosition( int _objectId , Vector _position ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
933
    emit log(LOGERR,tr("setManipulatorPosition : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
    return;
  }


  manip_size_ = PluginFunctions::sceneRadius() * 0.1;


  object->manipPlaced( true );

  object->manipulatorNode()->loadIdentity();
  object->manipulatorNode()->set_center(_position);
  object->manipulatorNode()->set_draw_cylinder(true);
  object->manipulatorNode()->set_size(manip_size_ * manip_size_modifier_);
  object->manipulatorNode()->show();

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

  emit scriptInfo( "setManipulatorPosition( ObjectId , Vector(" +
                   QString::number( _position[0] ) + " , " +
                   QString::number( _position[1] ) + " , " +
                   QString::number( _position[2] ) + " ) )" );
}


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

/** \brief Get the position of the manipulator
Jan Möbius's avatar
Jan Möbius committed
969
 *
Jan Möbius's avatar
 
Jan Möbius committed
970 971 972 973 974 975 976
 * @param _objectId id of an object
 * @return current manipulator position
 */
Vector MovePlugin::manipulatorPosition( int _objectId ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
977
    emit log(LOGERR,tr("manipulatorPosition : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
978 979 980 981 982 983 984 985 986 987
    return Vector();
  }

  return (Vector) object->manipulatorNode()->center();
}


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

/** \brief set the direction of the manipulator
Jan Möbius's avatar
Jan Möbius committed
988
 *
Jan Möbius's avatar
 
Jan Möbius committed
989 990 991 992 993 994 995 996
 * @param _objectId id of an object
 * @param _directionX vector for the X direction
 * @param _directionY vector for the Y direction
 */
void MovePlugin::setManipulatorDirection( int _objectId , Vector _directionX, Vector _directionY ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
997
    emit log(LOGERR,tr("setManipulatorDirection : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
998 999 1000 1001
    return;
  }

  if ( !object->manipPlaced() ){
Jan Möbius's avatar
Jan Möbius committed
1002
    emit log(LOGERR,tr("setManipulatorDirection : manipulator position has to be set first" ));
Jan Möbius's avatar
 
Jan Möbius committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
    return;
  }

  object->manipulatorNode()->set_direction(_directionX, _directionY);

  emit scriptInfo( "setManipulatorDirection( ObjectId , Vector(" +
                   QString::number( _directionX[0] ) + " , " +
                   QString::number( _directionX[1] ) + " , " +
                   QString::number( _directionX[2] ) + " ), Vector(" +
                   QString::number( _directionY[0] ) + " , " +
                   QString::number( _directionY[1] ) + " , " +
                   QString::number( _directionY[2] ) + " ) )" );
}


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

/** \brief Get the x-direction of the manipulator
Jan Möbius's avatar
Jan Möbius committed
1021
 *
Jan Möbius's avatar
 
Jan Möbius committed
1022 1023 1024 1025 1026 1027 1028
 * @param _objectId id of an object
 * @return x-direction of the manipulator
 */
Vector MovePlugin::manipulatorDirectionX( int _objectId ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1029
    emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
    return Vector();
  }

  return (Vector) object->manipulatorNode()->directionX();
}


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

/** \brief Get the y-direction of the manipulator
Jan Möbius's avatar
Jan Möbius committed
1040
 *
Jan Möbius's avatar
 
Jan Möbius committed
1041 1042 1043 1044 1045 1046 1047
 * @param _objectId id of an object
 * @return y-direction of the manipulator
 */
Vector MovePlugin::manipulatorDirectionY( int _objectId ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1048
    emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
    return Vector();
  }

  return (Vector) object->manipulatorNode()->directionY();
}


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

/** \brief Get the z-direction of the manipulator
Jan Möbius's avatar
Jan Möbius committed
1059
 *
Jan Möbius's avatar
 
Jan Möbius committed
1060 1061 1062 1063 1064 1065 1066
 * @param _objectId id of an object
 * @return z-direction of the manipulator
 */
Vector MovePlugin::manipulatorDirectionZ( int _objectId ){

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1067
    emit log(LOGERR,tr("manipulatorDirection : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
1068 1069 1070 1071 1072
    return Vector();
  }

  return (Vector) object->manipulatorNode()->directionZ();
}