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

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
42

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
#include <MeshTools/MeshFunctions.hh>

54 55 56 57 58 59
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
60 61

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

Jan Möbius's avatar
Jan Möbius committed
66 67
  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(","));
68

Jan Möbius's avatar
Jan Möbius committed
69 70 71
  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(","));
72

Jan Möbius's avatar
Jan Möbius committed
73 74
  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(","));
75

Jan Möbius's avatar
Jan Möbius committed
76 77
  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(","));
78

Jan Möbius's avatar
Jan Möbius committed
79 80
  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(","));
81

82 83 84
  emit setSlotDescription("transformHandleRegion(int,Matrix4x4)",tr("Transform handle region using the specified matrix."),
                          QString(tr("objectId,Matrix")).split(","), QString(tr("ID of an object, transformation matrix")).split(","));

Jan Möbius's avatar
Jan Möbius committed
85 86
  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(","));
87

Jan Möbius's avatar
Jan Möbius committed
88 89 90
  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(","));
91

Jan Möbius's avatar
Jan Möbius committed
92 93
  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(","));
94

Jan Möbius's avatar
Jan Möbius committed
95 96
  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(","));
97

Jan Möbius's avatar
Jan Möbius committed
98 99
  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(","));
100

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

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

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

Jan Möbius's avatar
Jan Möbius committed
110 111
  emit setSlotDescription("manipulatorDirectionZ(int)",tr("Returns the z-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130


  emit setSlotDescription("objectRenderingMatrixIdentity(int)",tr("Resets  the objects rendering matrix to identity."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));


  emit setSlotDescription("objectRenderingMatrixScale(int,double)",tr("Adds a scaling factor to the Object rendering Matrix in the scenegraph."),
                          QStringList(tr("objectId;Scaling Factor").split(";")), QStringList(tr("ID of an object; Scaling factor").split(";")));

  emit setSlotDescription("objectRenderingMatrixTranslate(int,Vector)",tr("Adds a translation to the Object rendering Matrix in the scenegraph."),
                          QStringList(tr("objectId;translation vector").split(";")), QStringList(tr("ID of an object;Translation vector").split(";")));

  emit setSlotDescription("objectRenderingMatrixRotate(int,Vector,double)",tr("Adds a Rotation to the Object rendering Matrix in the scenegraph."),
                          QStringList(tr("objectId;rotation axis;angle").split(";")), QStringList(tr("ID of an object;Rotation axis;angle").split(";")));

  emit setSlotDescription("getObjectRenderingMatrix(int)",tr("Returns the current object transformation matrix from the scenegraph."),
                            QStringList(tr("objectId").split(";")), QStringList(tr("ID of an object").split(";")));


131 132 133 134 135 136 137 138 139 140 141 142 143 144
}


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

/** \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
145
    emit log(LOGERR,tr("translate : unable to get object") );
146 147 148 149 150 151 152 153 154
    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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
155
      mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
156 157 158 159 160 161 162

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
163
      mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
164

Henrik Zimmer's avatar
Henrik Zimmer committed
165
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
166
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
167
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
168 169 170 171 172 173 174

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

175
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
176
#endif
Jan Möbius's avatar
Jan Möbius committed
177 178
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
179 180 181 182 183
      
      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
184 185 186 187 188 189 190
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
191

192
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
193 194 195 196 197

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
198 199 200
                   
  // Create backup
  emit createBackup(_objectId, "Translation");
201 202 203 204 205 206
}


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

/** \brief translate a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
207
 *
208 209 210 211
 * @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
212
void MovePlugin::translate( int _objectId , IdList _vHandles, Vector _vector ){
213 214
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
215
    emit log(LOGERR,tr("translate : unable to get object") );
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    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
236
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
237
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
238
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
239 240 241 242 243 244 245

    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
246
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
247
#endif
248

Jan Möbius's avatar
Jan Möbius committed
249 250
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
251 252 253 254 255 256 257 258
      
      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
259 260 261 262 263 264 265
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
266

267
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
268 269 270 271 272

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
273 274 275
                   
  // Create backup
  emit createBackup(_objectId, "Translation");
276 277 278 279 280 281 282

}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
283
 *
284 285 286
 * @param _objectId id of an object
 * @param _vector translation vector
 */
287
void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
288 289 290

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
291
    emit log(LOGERR,tr("translate : unable to get object" ));
292 293 294 295 296 297 298 299 300
    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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
301 302
      if ( mesh.status(*v_it).selected() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
303 304 305 306 307 308 309

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
310 311
      if ( mesh.status(*v_it).selected() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
Henrik Zimmer's avatar
Henrik Zimmer committed
312
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
313
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
314
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
315 316 317 318 319 320 321

    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 );
322
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
323 324
#endif
  
Jan Möbius's avatar
Jan Möbius committed
325 326
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
327 328 329 330 331 332
      
      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
333 334 335 336 337 338 339
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif
340

341
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
342 343 344 345 346

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
347 348 349
                   
  // Create backup
  emit createBackup(_objectId, "Translation of Selection");
350 351 352 353 354
}


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

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
/** \brief translate face selection
 *
 * @param _objectId id of an object
 * @param _vector translation vector
 */
void MovePlugin::translateFaceSelection( int _objectId , Vector _vector) {

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    emit log(LOGERR,tr("translate : unable to get object" ));
    return;
  }

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
    TriMesh::FaceIter f_it  = mesh.faces_begin();
    TriMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
374
      if ( mesh.status(*f_it).selected() )
375
      {
Jan Möbius's avatar
OM 3  
Jan Möbius committed
376 377
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
378 379 380 381 382
      }

    TriMesh::VertexIter v_it  = mesh.vertices_begin();
    TriMesh::VertexIter v_end = mesh.vertices_end();
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
383 384
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
385 386 387 388 389 390 391

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::FaceIter f_it  = mesh.faces_begin();
    PolyMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
392
      if ( mesh.status(*f_it).selected() )
393
      {
Jan Möbius's avatar
OM 3  
Jan Möbius committed
394 395
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
396 397 398 399 400
      }

    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
401 402
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 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 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
  }
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
    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(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it)
          mesh.status(fv_it).set_tagged(true);
      }

    TSplineMesh::VertexIter v_it  = mesh.vertices_begin();
    TSplineMesh::VertexIter v_end = mesh.vertices_end();
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
      if ( mesh.status(v_it).tagged() )
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
  }
#endif

  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {

      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;
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif

  emit updatedObject(_objectId, UPDATE_GEOMETRY);

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );

  // Create backup
  emit createBackup(_objectId, "Translation of Selection");
}


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

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

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    emit log(LOGERR,tr("translate : unable to get object" ));
    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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
475
      mesh.status(*v_it).set_tagged(false);
476 477 478 479

    TriMesh::EdgeIter e_it  = mesh.edges_begin();
    TriMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
480
      if ( mesh.status(*e_it).selected() )
481
      {
Jan Möbius's avatar
OM 3  
Jan Möbius committed
482
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
483 484 485 486 487 488

        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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
489 490
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
491 492 493 494 495 496 497 498 499
      }

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
500
      mesh.status(*v_it).set_tagged(false);
501 502 503 504

    PolyMesh::EdgeIter e_it  = mesh.edges_begin();
    PolyMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
505
      if ( mesh.status(*e_it).selected() )
506
      {
Jan Möbius's avatar
OM 3  
Jan Möbius committed
507
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
508 509 510 511 512 513

        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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
514 515
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
      }
  }
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {

    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() )
      {
        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,mesh.point(v_it) + _vector );
      }
  }
#endif

  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {

      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;
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : translate BSplineCurve" << std::endl;
    }
  #endif

  emit updatedObject(_objectId, UPDATE_GEOMETRY);

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );

  // Create backup
  emit createBackup(_objectId, "Translation of Selection");
}
//------------------------------------------------------------------------------

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
void MovePlugin::transformHandleRegion(int _objectId, Matrix4x4 _matrix) {

  BaseObjectData* object = NULL;
  if (!PluginFunctions::getObject(_objectId, object)) {
    emit log(LOGERR, tr("transformHandleRegion: Unable to get object!"));
    return;
  }

  if(object->dataType(DATA_TRIANGLE_MESH)) {

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

    MeshFunctions::transformHandleVertices(_matrix, mesh);

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

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

    MeshFunctions::transformHandleVertices(_matrix, mesh);
  }

  emit updatedObject(_objectId, UPDATE_GEOMETRY);
}

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

600
/** \brief tranform an object
Jan Möbius's avatar
Jan Möbius committed
601
 *
602 603 604 605 606 607 608
 * @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
609
    emit log(LOGERR,tr("transform : unable to get object" ));
610 611 612 613 614 615 616 617 618
    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){
Jan Möbius's avatar
OM 3  
Jan Möbius committed
619 620
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
      mesh.set_normal(*v_it, _matrix.transform_vector( mesh.normal(*v_it) ) );
621 622 623 624 625 626 627 628
    }

  } 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){
Jan Möbius's avatar
OM 3  
Jan Möbius committed
629 630
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
      mesh.set_normal(*v_it, _matrix.transform_vector( mesh.normal(*v_it) ) );
631
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
632
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
633
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
634
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
635 636 637 638 639 640 641 642

    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
643
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
644
#endif
645

Jan Möbius's avatar
Jan Möbius committed
646 647
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
648 649 650 651 652
      
      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
653 654 655 656 657 658 659
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
660

661
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
662 663 664 665 666 667 668 669 670

  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 + " ) )" );
671
  
672 673 674
  // Create backup if there was a change
  if (!_matrix.is_identity())
    emit createBackup(_objectId, "Transformation");
675 676 677 678 679 680
}


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

/** \brief Tranform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
681
 *
682 683 684 685
 * @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
686
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
687 688 689

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
690
    emit log(LOGERR,tr("transform : unable to get object" ));
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
    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
717
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
718
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
719
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
720 721 722 723 724 725 726 727 728 729

    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
730
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
731
#endif
732

Jan Möbius's avatar
Jan Möbius committed
733 734
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
735 736 737 738 739 740 741 742 743
      
      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
744 745 746 747 748 749 750
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
751

752
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
753 754 755 756 757 758 759 760 761

  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 + " ) )" );
762
  
763 764 765
  // Create backup if there was a change
  if (!_matrix.is_identity())
    emit createBackup(_objectId, "Transformation");
766 767 768 769 770 771
}


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

/** \brief transform vertex selection
Jan Möbius's avatar
Jan Möbius committed
772
 *
773 774
 * @param _objectId id of an object
 * @param _matrix transformation matrix
775 776
 *
 * @return returns true if selected elements were transformed
777
 */
778
bool MovePlugin::transformVertexSelection( int _objectId , Matrix4x4 _matrix ){
779 780
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
781
    emit log(LOGERR,tr("transform : unable to get object") );
782
    return false;
783 784
  }

785
  bool noneSelected = true;
786 787 788 789 790 791
  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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
792
      if ( mesh.status(*v_it).selected() )
793
      {
794
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
795 796
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
        mesh.set_normal(*v_it, _matrix.transform_vector( mesh.normal(*v_it) ) );
797 798 799 800 801 802 803 804
      }

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
805
      if ( mesh.status(*v_it).selected() )
806
      {
807
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
808 809
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
        mesh.set_normal(*v_it, _matrix.transform_vector( mesh.normal(*v_it) ) );
810
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
811
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
812
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
813
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
814 815 816 817 818 819 820

    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() )
      {
821
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
822 823 824
        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
825
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
826
#endif
Henrik Zimmer's avatar
Henrik Zimmer committed
827
  
Jan Möbius's avatar
Jan Möbius committed
828 829
  #ifdef ENABLE_POLYLINE_SUPPORT
    else if ( object->dataType(DATA_POLY_LINE) ) {
830 831 832 833
      
      PolyLine& line = (* PluginFunctions::polyLine(object) );
      
      for ( int i = 0 ; i < (int)line.n_vertices(); ++i )
834
        if ( line.vertex_selection(i) ) {
835
          noneSelected = false;
836 837
          line.point(i) = _matrix.transform_point( line.point(i) );
        }
Jan Möbius's avatar
Jan Möbius committed
838 839 840 841 842 843 844
    }
  #endif
  #ifdef ENABLE_BSPLINE_CURVE_SUPPORT
    else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
      std::cerr << "Todo : transform BSplineCurve" << std::endl;
    }
  #endif
845

846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_it  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].selected() )
      {
        noneSelected = false;
        mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
        normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {
    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_it  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].selected() )
      {
        noneSelected = false;
        mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
        normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }
  }
#endif

879 880 881
  if (noneSelected)
    return false;

882
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
883 884 885 886 887 888 889 890 891

  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 + " ) )" );
Dirk Wilden's avatar
Dirk Wilden committed
892

893
  // Create backup if there was a change
Dirk Wilden's avatar
Dirk Wilden committed
894
  // the backup is only created when the slot is called via scripting (sender == 0)
895
  if ( !_matrix.is_identity() && (sender() == 0) )
896
    emit createBackup(_objectId, "Transformation of Vertex Selection");
897 898

  return true;
899 900 901 902 903 904
}


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

/** \brief transform face selection
Jan Möbius's avatar
Jan Möbius committed
905
 *
906 907
 * @param _objectId id of an object
 * @param _matrix transformation matrix
908 909
 *
 * @return returns true if selected elements were transformed
910
 */
911
bool MovePlugin::transformFaceSelection( int _objectId , Matrix4x4 _matrix ){
912 913
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
914
    emit log(LOGERR,tr("transform : unable to get object") );
915
    return false;
916 917
  }

918
  bool noneSelected = true;
919 920 921 922 923 924 925
  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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
926
        mesh.status(*v_it).set_tagged(false);
927 928 929 930

    TriMesh::FaceIter f_it  = mesh.faces_begin();
    TriMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
931
      if ( mesh.status(*f_it).selected() )
932
      {
933
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
934 935
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
936 937 938
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
939 940 941
      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) ) );
942 943 944 945 946 947 948 949 950
      }

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
951
        mesh.status(*v_it).set_tagged(false);
952 953 954 955

    PolyMesh::FaceIter f_it  = mesh.faces_begin();
    PolyMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
956
      if ( mesh.status(*f_it).selected() )
957
      {
958
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
959 960
        for(PolyMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
961 962 963
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
964 965 966
      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) ) );
967
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
968
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
969
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
970
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
971 972 973 974 975 976 977 978 979 980 981 982 983

    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() )
      {
984
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
985 986 987 988 989 990 991 992 993
        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) ) );
      }
994
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
995
#endif
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {

    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::FaceIter f_it  = mesh.faces_begin();
    OpenVolumeMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
      if ( statusAttrib[*f_it].selected() )
      {
        noneSelected = false;
        for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh.hfv_iter(mesh.halfface_handle(*f_it,0)); hfv_it.valid(); ++hfv_it)
            statusAttrib[*hfv_it].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }

  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::FaceIter f_it  = mesh.faces_begin();
    OpenVolumeMesh::FaceIter f_end = mesh.faces_end();
    for (; f_it!=f_end; ++f_it)
      if ( statusAttrib[*f_it].selected() )
      {
        noneSelected = false;
        for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh.hfv_iter(mesh.halfface_handle(*f_it,0)); hfv_it.valid(); ++hfv_it)
            statusAttrib[*hfv_it].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }
  }
#endif
Jan Möbius's avatar
Jan Möbius committed
1059

1060 1061
  if (noneSelected)
    return false;
Jan Möbius's avatar
Jan Möbius committed
1062

1063
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1064 1065 1066 1067 1068 1069 1070 1071 1072

  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 + " ) )" );
1073
  
1074
  // Create backup if there was a change
Dirk Wilden's avatar
Dirk Wilden committed
1075
  // the backup is only created when the slot is called via scripting (sender == 0)
1076
  if ( !_matrix.is_identity() && (sender() == 0) )
1077
    emit createBackup(_objectId, "Transformation of Face Selection");
1078 1079

  return true;
1080 1081 1082 1083 1084 1085
}


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

/** \brief transform edge selection
Jan Möbius's avatar
Jan Möbius committed
1086
 *
1087 1088
 * @param _objectId id of an object
 * @param _matrix transformation matrix
1089 1090
 *
 * @return returns true if selected elements were transformed
1091
 */
1092
bool MovePlugin::transformEdgeSelection( int _objectId , Matrix4x4 _matrix ){
1093 1094
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1095
    emit log(LOGERR,tr("transform : unable to get object" ) );
1096
    return false;
1097 1098
  }

1099
  bool noneSelected = true;
1100 1101 1102 1103 1104 1105 1106
  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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1107
        mesh.status(*v_it).set_tagged(false);
1108 1109 1110 1111

    TriMesh::EdgeIter e_it  = mesh.edges_begin();
    TriMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1112
      if ( mesh.status(*e_it).selected() )
1113
      {
1114
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1115
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
1116 1117 1118 1119 1120 1121

        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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1122 1123 1124
      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) ) );
1125 1126 1127 1128 1129 1130 1131 1132 1133
      }

  } 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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1134
        mesh.status(*v_it).set_tagged(false);
1135 1136 1137 1138

    PolyMesh::EdgeIter e_it  = mesh.edges_begin();
    PolyMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1139
      if ( mesh.status(*e_it).selected() )
1140
      {
1141
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1142
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
1143 1144 1145 1146 1147 1148

        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)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1149 1150 1151
      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) ) );
1152
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1153
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1154
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
1155
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168

    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() )
      {
1169
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
        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) ) );
      }
1181
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1182
#endif
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {

    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::EdgeIter e_it  = mesh.edges_begin();
    OpenVolumeMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
      if ( statusAttrib[*e_it].selected() )
      {
        noneSelected = false;
        OpenVolumeMesh::OpenVolumeMeshEdge e(mesh.edge(*e_it));
        statusAttrib[e.from_vertex()].set_tagged(true);
        statusAttrib[e.to_vertex()].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }

  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::EdgeIter e_it  = mesh.edges_begin();
    OpenVolumeMesh::EdgeIter e_end = mesh.edges_end();
    for (; e_it!=e_end; ++e_it)
      if ( statusAttrib[*e_it].selected() )
      {
        noneSelected = false;
        OpenVolumeMesh::OpenVolumeMeshEdge e(mesh.edge(*e_it));
        statusAttrib[e.from_vertex()].set_tagged(true);
        statusAttrib[e.to_vertex()].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }

  }
#endif
Henrik Zimmer's avatar
Henrik Zimmer committed
1249
  
Jan Möbius's avatar
Jan Möbius committed
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
  #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
1260

1261 1262 1263
  if (noneSelected)
    return false;

1264
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
1265 1266 1267 1268 1269 1270 1271 1272 1273

  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 + " ) )" );
1274
  
1275
  // Create backup if there was a change
Dirk Wilden's avatar
Dirk Wilden committed
1276
  // the backup is only created when the slot is called via scripting (sender == 0)
1277
  if ( !_matrix.is_identity() && (sender() == 0) )
1278
    emit createBackup(_objectId, "Transformation of Edge Selection");
1279 1280

  return true;
1281 1282
}

1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387
//------------------------------------------------------------------------------

/** \brief transform cell selection
 *
 * @param _objectId id of an object
 * @param _matrix transformation matrix
 *
 * @return returns true if selected elements were transformed
 */
bool MovePlugin::transformCellSelection( int _objectId , Matrix4x4 _matrix ){
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
    emit log(LOGERR,tr("transform : unable to get object") );
    return false;
  }

  bool noneSelected = true;

#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  if ( object->dataType( DATA_HEXAHEDRAL_MESH ) ) {

    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((HexahedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::CellIter c_it  = mesh.cells_begin();
    OpenVolumeMesh::CellIter c_end = mesh.cells_end();
    for (; c_it!=c_end; ++c_it)
      if ( statusAttrib[*c_it].selected() )
      {
        noneSelected = false;
        for (OpenVolumeMesh::CellVertexIter cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
            statusAttrib[*cv_it].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }

  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType( DATA_POLYHEDRAL_MESH ) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    OpenVolumeMesh::NormalAttrib<PolyhedralMesh>& normalAttrib = ((PolyhedralMeshObject*)object)->normals();
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((PolyhedralMeshObject*)object)->status();
    OpenVolumeMesh::VertexIter v_begin  = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();

    //init tags
    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
        statusAttrib[*v_it].set_tagged(false);

    OpenVolumeMesh::CellIter c_it  = mesh.cells_begin();
    OpenVolumeMesh::CellIter c_end = mesh.cells_end();
    for (; c_it!=c_end; ++c_it)
      if ( statusAttrib[*c_it].selected() )
      {
        noneSelected = false;
        for (OpenVolumeMesh::CellVertexIter cv_it = mesh.cv_iter(*c_it); cv_it.valid(); ++cv_it)
            statusAttrib[*cv_it].set_tagged(true);
      }

    for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it!=v_end; ++v_it)
      if ( statusAttrib[*v_it].tagged() )
      {
          mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
          normalAttrib[*v_it] = _matrix.transform_vector( normalAttrib[*v_it] );
      }
  }
#endif

  if (noneSelected)
    return false;

  emit updatedObject(_objectId, UPDATE_GEOMETRY);

  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( "transformCellSelection( ObjectId , Matrix4x4(" + matString + " ) )" );

  // Create backup if there was a change
  // the backup is only created when the slot is called via scripting (sender == 0)
  if ( !_matrix.is_identity() && (sender() == 0) )
    emit createBackup(_objectId, "Transformation of Cell Selection");

  return true;
}


1388 1389
//------------------------------------------------------------------------------

1390
/** \brief set the position of the manipulator
Jan Möbius's avatar
Jan Möbius committed
1391
 *
1392 1393 1394 1395 1396 1397 1398
 * @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
1399
    emit log(LOGERR,tr("setManipulatorPosition : unable to get object") );
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
    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
1435
 *
1436 1437 1438 1439 1440 1441 1442
 * @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
1443
    emit log(LOGERR,tr("manipulatorPosition : unable to get object" ));
Jan Möbius's avatar
g