MovePluginScript.cc 63.7 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-2014 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

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
Jan Möbius's avatar
 
Jan Möbius committed
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
Jan Möbius's avatar
 
Jan Möbius committed
60 61

/** \brief Set Descriptions for Scripting Slots
Jan Möbius's avatar
Jan Möbius committed
62
 *
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
87

Matthias Möller's avatar
Matthias Möller committed
88
  emit setSlotDescription("transform(int,IdList,Matrix4x4)",tr("transform vertices by given matrix."),
Jan Möbius's avatar
Jan Möbius committed
89 90
                          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
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(","));
Jan Möbius's avatar
 
Jan Möbius committed
94

Matthias Möller's avatar
Matthias Möller committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  emit setSlotDescription("transformCellSelection(int,Matrix4x4)",tr("transform selected cells by given matrix."),
                          QString(tr("objectId,Matrix")).split(","),
                          QString(tr("ID of an object, transformation matrix")).split(","));

  emit setSlotDescription("transformVertexSelection(int,Matrix4x4)",tr("transform selected vertices by given matrix."),
                          QString(tr("objectId,Matrix")).split(","),
                          QString(tr("ID of an object, transformation matrix")).split(","));

  emit setSlotDescription("transformFaceSelection(int,Matrix4x4)",tr("transform selected faces by given matrix."),
                          QString(tr("objectId,Matrix")).split(","),
                          QString(tr("ID of an object, transformation matrix")).split(","));

  emit setSlotDescription("transformEdgeSelection(int,Matrix4x4)",tr("transform selected edges 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
111 112
  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
113

Jan Möbius's avatar
Jan Möbius committed
114 115
  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
116

Jan Möbius's avatar
Jan Möbius committed
117 118
  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
119

Jan Möbius's avatar
Jan Möbius committed
120 121
  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
122

Jan Möbius's avatar
Jan Möbius committed
123 124
  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
125

Jan Möbius's avatar
Jan Möbius committed
126 127
  emit setSlotDescription("manipulatorDirectionZ(int)",tr("Returns the z-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146


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


Jan Möbius's avatar
 
Jan Möbius committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160
}


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

/** \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
161
    emit log(LOGERR,tr("translate : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
162 163 164 165 166 167 168 169 170
    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
171
      mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
Jan Möbius's avatar
 
Jan Möbius committed
172 173 174 175 176 177 178

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

Henrik Zimmer's avatar
Henrik Zimmer committed
181
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
182
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
183
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
184 185 186 187 188 189 190

    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
191
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
192
#endif
Matthias Möller's avatar
Matthias Möller committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
#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 )
      line.point(i) = line.point(i)  + _vector; 
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {

    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it != v_end; ++v_it)
      mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it != v_end; ++v_it)
      mesh.set_vertex(*v_it, mesh.vertex(*v_it) + _vector );
  }
#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
227

228
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
229 230 231 232 233 234 235 236 237 238 239

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


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

/** \brief translate a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
240
 *
Jan Möbius's avatar
 
Jan Möbius committed
241 242 243 244
 * @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
245
void MovePlugin::translate( int _objectId , IdList _vHandles, Vector _vector ){
Jan Möbius's avatar
 
Jan Möbius committed
246 247
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
248
    emit log(LOGERR,tr("translate : unable to get object") );
Jan Möbius's avatar
 
Jan Möbius committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    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
269
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
270
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
271
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
272 273 274 275 276 277 278

    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
279
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
280
#endif
Matthias Möller's avatar
Matthias Möller committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294
#ifdef ENABLE_POLYLINE_SUPPORT
  else if ( object->dataType(DATA_POLY_LINE) ) {
    
    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; 
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
295

Matthias Möller's avatar
Matthias Möller committed
296 297 298 299
    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    for (unsigned int i = 0; i < _vHandles.size(); ++i) {
      OpenVolumeMesh::VertexHandle v(_vHandles[i]);
      mesh.set_vertex(v, mesh.vertex(v) + _vector );
Jan Möbius's avatar
Jan Möbius committed
300
    }
Matthias Möller's avatar
Matthias Möller committed
301 302 303 304 305 306 307 308 309
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    for (unsigned int i = 0; i < _vHandles.size(); ++i) {
      OpenVolumeMesh::VertexHandle v(_vHandles[i]);
      mesh.set_vertex(v, mesh.vertex(v) + _vector );
Jan Möbius's avatar
Jan Möbius committed
310
    }
Matthias Möller's avatar
Matthias Möller committed
311 312 313 314 315 316 317
  }
#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
318

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

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
325
                   
Jan Möbius's avatar
 
Jan Möbius committed
326 327 328 329 330 331
}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
332
 *
Jan Möbius's avatar
 
Jan Möbius committed
333 334 335
 * @param _objectId id of an object
 * @param _vector translation vector
 */
336
void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
Jan Möbius's avatar
 
Jan Möbius committed
337 338 339

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
340
    emit log(LOGERR,tr("translate : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
341 342 343
    return;
  }

Matthias Möller's avatar
Matthias Möller committed
344 345
  bool noneSelected = true;

Jan Möbius's avatar
 
Jan Möbius committed
346 347 348 349 350 351
  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)
Matthias Möller's avatar
Matthias Möller committed
352 353
      if ( mesh.status(*v_it).selected() ) {
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
354
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
355
      }
Jan Möbius's avatar
 
Jan Möbius committed
356 357 358 359 360 361 362

  } 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)
Matthias Möller's avatar
Matthias Möller committed
363 364
      if ( mesh.status(*v_it).selected() ) {
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
365
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
366
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
367
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
368
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
369
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
370 371 372 373 374

    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)
Matthias Möller's avatar
Matthias Möller committed
375 376
      if ( mesh.status(v_it).selected() ) {
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
377
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
378
      }
Jan Möbius's avatar
 
Jan Möbius committed
379
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
380
#endif
Matthias Möller's avatar
Matthias Möller committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 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
#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) ) {
        noneSelected = false;
        line.point(i) = line.point(i)  + _vector; 
      }
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {

    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    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, mesh.vertex(*v_it) + _vector );
      }
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
  else if ( object->dataType(DATA_POLYHEDRAL_MESH) ) {

    PolyhedralMesh& mesh = (*PluginFunctions::polyhedralMesh(object));
    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, mesh.vertex(*v_it) + _vector );
      }
  }
#endif
#ifdef ENABLE_BSPLINE_CURVE_SUPPORT
  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
    std::cerr << "Todo : translate BSplineCurve" << std::endl;
  }
#endif

  if (noneSelected)
    return;
Jan Möbius's avatar
 
Jan Möbius committed
429

430
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
431 432 433 434 435 436 437 438 439 440

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


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

441 442 443 444 445 446 447 448 449 450 451 452 453
/** \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;
  }

Matthias Möller's avatar
Matthias Möller committed
454 455
  bool noneSelected = true;

456 457 458
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
Matthias Möller's avatar
Matthias Möller committed
459 460 461 462 463 464

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

465 466 467
    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
468
      if ( mesh.status(*f_it).selected() )
469
      {
Matthias Möller's avatar
Matthias Möller committed
470 471
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
          noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
472
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
473
        }
474 475
      }

Matthias Möller's avatar
Matthias Möller committed
476 477 478
    if (noneSelected)
      return;

479
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
480 481
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
482 483 484 485

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
Matthias Möller's avatar
Matthias Möller committed
486 487 488 489 490 491

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

492 493 494
    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
495
      if ( mesh.status(*f_it).selected() )
496
      {
Matthias Möller's avatar
Matthias Möller committed
497 498
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it) {
          noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
499
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
500
        }
501 502
      }

Matthias Möller's avatar
Matthias Möller committed
503 504 505
    if (noneSelected)
      return;

506
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
507 508
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
509 510 511 512 513
  }
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {

    TSplineMesh&  mesh  = (*PluginFunctions::tsplineMesh(object));
Matthias Möller's avatar
Matthias Möller committed
514 515 516 517 518 519

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

520 521 522 523 524
    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() )
      {
Matthias Möller's avatar
Matthias Möller committed
525 526
        for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it) {
          noneSelected = false;
527
          mesh.status(fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
528
        }
529 530
      }

Matthias Möller's avatar
Matthias Möller committed
531 532 533
    if (noneSelected)
      return;

534 535 536 537 538 539 540 541 542 543 544 545
    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 )
Matthias Möller's avatar
Matthias Möller committed
546 547
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
548
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
549 550 551 552
        }

      if (noneSelected)
        return;
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
    }
  #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] ) + " ) )" );

}


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

/** \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;
  }

Matthias Möller's avatar
Matthias Möller committed
586 587
  bool noneSelected = true;

588 589 590 591
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

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

Matthias Möller's avatar
Matthias Möller committed
592
    // clear tags
593 594
    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
595
      mesh.status(*v_it).set_tagged(false);
596 597 598 599

    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
600
      if ( mesh.status(*e_it).selected() )
601
      {
Matthias Möller's avatar
Matthias Möller committed
602
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
603
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
604 605 606 607 608

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

Matthias Möller's avatar
Matthias Möller committed
609 610 611
    if (noneSelected)
      return;

612
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
613 614
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
615 616 617 618 619 620
      }

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

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

Matthias Möller's avatar
Matthias Möller committed
621
    // clear tags
622 623
    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
624
      mesh.status(*v_it).set_tagged(false);
625 626 627 628

    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
629
      if ( mesh.status(*e_it).selected() )
630
      {
Matthias Möller's avatar
Matthias Möller committed
631
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
632
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
633 634 635 636 637

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

Matthias Möller's avatar
Matthias Möller committed
638 639 640
    if (noneSelected)
      return;

641
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
642 643
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
644 645 646 647 648 649 650
      }
  }
#ifdef ENABLE_TSPLINEMESH_SUPPORT
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {

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

Matthias Möller's avatar
Matthias Möller committed
651
    // clear tags
652 653 654 655 656 657 658 659 660
    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() )
      {
Matthias Möller's avatar
Matthias Möller committed
661
        noneSelected = false;
662 663 664 665 666 667
        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);
      }

Matthias Möller's avatar
Matthias Möller committed
668 669 670
    if (noneSelected)
      return;

671 672 673 674 675 676 677 678 679 680 681 682 683
    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 )
Matthias Möller's avatar
Matthias Möller committed
684 685
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
686
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
687 688 689 690
        }

      if (noneSelected)
        return;
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
    }
  #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] ) + " ) )" );

}
//------------------------------------------------------------------------------

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

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

735
/** \brief transform an object
Jan Möbius's avatar
Jan Möbius committed
736
 *
Jan Möbius's avatar
 
Jan Möbius committed
737 738 739 740 741 742 743
 * @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
744
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
745 746 747
    return;
  }

748 749 750 751
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
752 753 754 755 756 757
  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
758
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
759
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
760 761 762 763 764 765 766 767
    }

  } 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
768
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
769
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
770
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
771
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
772
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
773
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
774 775 776 777 778 779

    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) ) );
780
      mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
781
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
782
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
783
#endif
Matthias Möller's avatar
Matthias Möller committed
784 785 786 787 788 789 790 791 792 793 794
#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 )
      line.point(i) = _matrix.transform_point( line.point(i) ); 
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
795

Matthias Möller's avatar
Matthias Möller committed
796 797 798 799 800 801
    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    OpenVolumeMesh::VertexIter v_it = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it != v_end; ++v_it) {
      mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
802
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
803
    }
Matthias Möller's avatar
Matthias Möller committed
804 805 806 807 808 809 810 811 812 813 814
  }
#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::VertexIter v_it = mesh.vertices_begin();
    OpenVolumeMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it != v_end; ++v_it) {
      mesh.set_vertex(*v_it, _matrix.transform_point ( mesh.vertex(*v_it) ) );
815
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
816
    }
Matthias Möller's avatar
Matthias Möller committed
817 818 819 820 821 822 823
  }
#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
824

825
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
826 827 828 829 830 831 832 833 834 835 836 837 838 839

  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 + " ) )" );
}


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

Matthias Möller's avatar
Matthias Möller committed
840
/** \brief Transform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
841
 *
Jan Möbius's avatar
 
Jan Möbius committed
842 843 844 845
 * @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
846
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
847 848 849

  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
850
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
851 852 853
    return;
  }

854 855 856 857
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
858 859 860 861 862 863 864
  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, _matrix.transform_point ( mesh.point(vh) ) );
865
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
866 867 868 869 870 871 872 873 874
    }

  } 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, _matrix.transform_point ( mesh.point(vh) ) );
875
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
876
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
877
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
878
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
879
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
880 881 882 883 884 885

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

    for (uint i=0; i < _vHandles.size(); i++){
      TSplineMesh::VertexHandle vh( _vHandles[i] );
      mesh.set_point (vh, _matrix.transform_point ( mesh.point(vh) ) );
886
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
887
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
888
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
889
#endif
Matthias Möller's avatar
Matthias Möller committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
#ifdef ENABLE_POLYLINE_SUPPORT
  else if ( object->dataType(DATA_POLY_LINE) ) {
    
    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] ) ); 
    
  }
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
905

Matthias Möller's avatar
Matthias Möller committed
906 907 908 909 910
    HexahedralMesh& mesh = (*PluginFunctions::hexahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<HexahedralMesh>& normalAttrib = ((HexahedralMeshObject*)object)->normals();
    for (unsigned int i = 0; i < _vHandles.size(); ++i) {
      OpenVolumeMesh::VertexHandle v(_vHandles[i]);
      mesh.set_vertex(v, _matrix.transform_point ( mesh.vertex(v) ) );
911
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
912
    }
Matthias Möller's avatar
Matthias Möller committed
913 914 915 916 917 918 919 920 921 922
  }
#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();
    for (unsigned int i = 0; i < _vHandles.size(); ++i) {
      OpenVolumeMesh::VertexHandle v(_vHandles[i]);
      mesh.set_vertex(v, _matrix.transform_point ( mesh.vertex(v) ) );
923
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
924
    }
Matthias Möller's avatar
Matthias Möller committed
925 926 927 928 929 930 931
  }
#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
932

933
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
934 935 936 937 938 939 940 941 942

  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 + " ) )" );
943
  
Jan Möbius's avatar
 
Jan Möbius committed
944 945 946 947 948 949
}


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

/** \brief transform vertex selection
Jan Möbius's avatar
Jan Möbius committed
950
 *
Jan Möbius's avatar
 
Jan Möbius committed
951 952
 * @param _objectId id of an object
 * @param _matrix transformation matrix
953 954
 *
 * @return returns true if selected elements were transformed
Jan Möbius's avatar
 
Jan Möbius committed
955
 */
956
bool MovePlugin::transformVertexSelection( int _objectId , Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
957 958
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
959
    emit log(LOGERR,tr("transform : unable to get object") );
960
    return false;
Jan Möbius's avatar
 
Jan Möbius committed
961 962
  }

963 964 965 966
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

967
  bool noneSelected = true;
Jan Möbius's avatar
 
Jan Möbius committed
968 969 970 971 972 973
  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
974
      if ( mesh.status(*v_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
975
      {
976
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
977
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
978
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
979 980 981 982 983 984 985 986
      }

  } 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
987
      if ( mesh.status(*v_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
988
      {
989
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
990
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
991
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
992
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
993
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
994
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
995
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
996 997 998 999 1000 1001 1002

    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() )
      {
1003
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1004
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1005
        mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
1006
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1007
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
1008
#endif
Matthias Möller's avatar
Matthias Möller committed
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
#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) ) {
        noneSelected = false;
        line.point(i) = _matrix.transform_point( line.point(i) );
      }
  }
#endif
#ifdef ENABLE_BSPLINE_CURVE_SUPPORT
  else if ( object->dataType(DATA_BSPLINE_CURVE) ) {
    std::cerr << "Todo : transform BSplineCurve" << std::endl;
  }
#endif
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
#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) ) );
1038
        normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
      }
  }
#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) ) );
1054
        normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1055 1056 1057 1058
      }
  }
#endif

1059 1060 1061
  if (noneSelected)
    return false;

1062
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
1063 1064 1065 1066 1067 1068 1069 1070 1071

  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
1072

1073
  return true;
Jan Möbius's avatar
 
Jan Möbius committed
1074 1075 1076 1077 1078 1079
}


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

/** \brief transform face selection
Jan Möbius's avatar
Jan Möbius committed
1080
 *
Jan Möbius's avatar
 
Jan Möbius committed
1081 1082
 * @param _objectId id of an object
 * @param _matrix transformation matrix
1083 1084
 *
 * @return returns true if selected elements were transformed
Jan Möbius's avatar
 
Jan Möbius committed
1085
 */
1086
bool MovePlugin::transformFaceSelection( int _objectId , Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
1087 1088
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1089
    emit log(LOGERR,tr("transform : unable to get object") );
1090
    return false;
Jan Möbius's avatar
 
Jan Möbius committed
1091 1092
  }

1093 1094 1095 1096
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

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

    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
1110
      if ( mesh.status(*f_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1111
      {
1112
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1113 1114
        for(TriMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
Jan Möbius's avatar
 
Jan Möbius committed
1115 1116 1117
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1118 1119
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1120
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1121 1122 1123 1124 1125 1126 1127 1128 1129
      }

  } 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
1130
        mesh.status(*v_it).set_tagged(false);
Jan Möbius's avatar
 
Jan Möbius committed
1131 1132 1133 1134

    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
1135
      if ( mesh.status(*f_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1136
      {
1137
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1138 1139
        for(PolyMesh::FVIter fv_it = mesh.fv_iter(*f_it); fv_it.is_valid(); ++fv_it)
          mesh.status(*fv_it).set_tagged(true);
Jan Möbius's avatar
 
Jan Möbius committed
1140 1141 1142
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1143 1144
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1145
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1146
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1147
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1148
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
1149
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162

    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() )
      {
1163
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1164 1165 1166 1167 1168 1169 1170
        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) ) );
1171
        mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
1172
      }
Jan Möbius's avatar
 
Jan Möbius committed
1173
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1174
#endif
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
#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) ) );
1202
          normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
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
      }

  }
#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) ) );
1234
          normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1235 1236 1237
      }
  }
#endif
Jan Möbius's avatar
Jan Möbius committed
1238

1239 1240
  if (noneSelected)
    return false;
Jan Möbius's avatar
Jan Möbius committed
1241

1242
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
1243 1244 1245 1246 1247 1248 1249 1250 1251

  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 + " ) )" );
1252
  
1253
  return true;
Jan Möbius's avatar
 
Jan Möbius committed
1254 1255 1256 1257 1258 1259
}


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

/** \brief transform edge selection
Jan Möbius's avatar
Jan Möbius committed
1260
 *
Jan Möbius's avatar
 
Jan Möbius committed
1261 1262
 * @param _objectId id of an object
 * @param _matrix transformation matrix
1263 1264
 *
 * @return returns true if selected elements were transformed
Jan Möbius's avatar
 
Jan Möbius committed
1265
 */
1266
bool MovePlugin::transformEdgeSelection( int _objectId , Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
1267 1268
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1269
    emit log(LOGERR,tr("transform : unable to get object" ) );
1270
    return false;
Jan Möbius's avatar
 
Jan Möbius committed
1271 1272
  }

1273 1274 1275 1276
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

1277
  bool noneSelected = true;
Jan Möbius's avatar
 
Jan Möbius committed
1278 1279 1280 1281 1282 1283 1284
  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
1285
        mesh.status(*v_it).set_tagged(false);
Jan Möbius's avatar
 
Jan Möbius committed
1286 1287 1288 1289

    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
1290
      if ( mesh.status(*e_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1291
      {
1292
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1293
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
Jan Möbius's avatar
 
Jan Möbius committed
1294 1295 1296 1297 1298 1299

        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
1300 1301
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1302
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1303 1304 1305 1306 1307 1308 1309 1310 1311
      }

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