MovePluginScript.cc 64.2 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
49

Jan Möbius's avatar
 
Jan Möbius committed
50 51
#include "MovePlugin.hh"

Jan Möbius's avatar
Jan Möbius committed
52
#ifdef ENABLE_POLYLINE_SUPPORT
Jan Möbius's avatar
Jan Möbius committed
53
#include <ObjectTypes/PolyLine/PolyLine.hh>
Jan Möbius's avatar
Jan Möbius committed
54
#endif
Henrik Zimmer's avatar
Henrik Zimmer committed
55 56 57
#ifdef ENABLE_TSPLINEMESH_SUPPORT
#include <ObjectTypes/TSplineMesh/TSplineMesh.hh>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
58 59
#include <MeshTools/MeshFunctions.hh>

60 61 62 63 64 65
#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
66 67

/** \brief Set Descriptions for Scripting Slots
Jan Möbius's avatar
Jan Möbius committed
68
 *
Jan Möbius's avatar
 
Jan Möbius committed
69 70 71
 */
void MovePlugin::setDescriptions(){

Jan Möbius's avatar
Jan Möbius committed
72 73
  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
74

Jan Möbius's avatar
Jan Möbius committed
75 76 77
  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
78

Jan Möbius's avatar
Jan Möbius committed
79 80
  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
81

Jan Möbius's avatar
Jan Möbius committed
82 83
  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
84

Jan Möbius's avatar
Jan Möbius committed
85 86
  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
87

88 89 90
  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
91 92
  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
93

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

Jan Möbius's avatar
Jan Möbius committed
98 99
  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
100

Matthias Möller's avatar
Matthias Möller committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  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
117 118
  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
119

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

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

Jan Möbius's avatar
Jan Möbius committed
126 127
  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
128

Jan Möbius's avatar
Jan Möbius committed
129 130
  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
131

Jan Möbius's avatar
Jan Möbius committed
132 133
  emit setSlotDescription("manipulatorDirectionZ(int)",tr("Returns the z-direction of an object's manipulator."),
                          QStringList(tr("objectId")), QStringList(tr("ID of an object")));
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152


  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
153 154 155 156 157 158 159 160 161 162 163 164 165 166
}


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

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

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

Henrik Zimmer's avatar
Henrik Zimmer committed
187
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
188
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
189
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
190 191 192 193 194 195 196

    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
197
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
198
#endif
Matthias Möller's avatar
Matthias Möller committed
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 227 228 229 230 231 232
#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
233

234
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
235 236 237 238 239 240 241 242 243 244 245

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

    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
285
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
286
#endif
Matthias Möller's avatar
Matthias Möller committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300
#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
301

Matthias Möller's avatar
Matthias Möller committed
302 303 304 305
    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
306
    }
Matthias Möller's avatar
Matthias Möller committed
307 308 309 310 311 312 313 314 315
  }
#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
316
    }
Matthias Möller's avatar
Matthias Möller committed
317 318 319 320 321 322 323
  }
#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
324

325
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
326 327 328 329 330

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
331
                   
Jan Möbius's avatar
 
Jan Möbius committed
332 333 334 335 336 337
}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
338
 *
Jan Möbius's avatar
 
Jan Möbius committed
339 340 341
 * @param _objectId id of an object
 * @param _vector translation vector
 */
342
void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
Jan Möbius's avatar
 
Jan Möbius committed
343 344 345

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

Matthias Möller's avatar
Matthias Möller committed
350 351
  bool noneSelected = true;

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

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

    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
381 382
      if ( mesh.status(v_it).selected() ) {
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
383
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
384
      }
Jan Möbius's avatar
 
Jan Möbius committed
385
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
386
#endif
Matthias Möller's avatar
Matthias Möller committed
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 429 430 431 432 433 434
#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
435

436
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
437 438 439 440 441 442 443 444 445 446

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


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

447 448 449 450 451 452 453 454 455 456 457 458 459
/** \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
460 461
  bool noneSelected = true;

462 463 464
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
Matthias Möller's avatar
Matthias Möller committed
465 466 467 468 469 470

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

471 472 473
    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
474
      if ( mesh.status(*f_it).selected() )
475
      {
Matthias Möller's avatar
Matthias Möller committed
476 477
        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
478
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
479
        }
480 481
      }

Matthias Möller's avatar
Matthias Möller committed
482 483 484
    if (noneSelected)
      return;

485
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
486 487
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
488 489 490 491

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
Matthias Möller's avatar
Matthias Möller committed
492 493 494 495 496 497

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

498 499 500
    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
501
      if ( mesh.status(*f_it).selected() )
502
      {
Matthias Möller's avatar
Matthias Möller committed
503 504
        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
505
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
506
        }
507 508
      }

Matthias Möller's avatar
Matthias Möller committed
509 510 511
    if (noneSelected)
      return;

512
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
513 514
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
515 516 517 518 519
  }
#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
520 521 522 523 524 525

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

526 527 528 529 530
    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
531 532
        for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it) {
          noneSelected = false;
533
          mesh.status(fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
534
        }
535 536
      }

Matthias Möller's avatar
Matthias Möller committed
537 538 539
    if (noneSelected)
      return;

540 541 542 543 544 545 546 547 548 549 550 551
    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
552 553
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
554
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
555 556 557 558
        }

      if (noneSelected)
        return;
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 586 587 588 589 590 591
    }
  #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
592 593
  bool noneSelected = true;

594 595 596 597
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

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

Matthias Möller's avatar
Matthias Möller committed
598
    // clear tags
599 600
    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
601
      mesh.status(*v_it).set_tagged(false);
602 603 604 605

    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
606
      if ( mesh.status(*e_it).selected() )
607
      {
Matthias Möller's avatar
Matthias Möller committed
608
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
609
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
610 611 612 613 614

        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
615 616 617
    if (noneSelected)
      return;

618
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
619 620
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
621 622 623 624 625 626
      }

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

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

Matthias Möller's avatar
Matthias Möller committed
627
    // clear tags
628 629
    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
630
      mesh.status(*v_it).set_tagged(false);
631 632 633 634

    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
635
      if ( mesh.status(*e_it).selected() )
636
      {
Matthias Möller's avatar
Matthias Möller committed
637
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
638
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
639 640 641 642 643

        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
644 645 646
    if (noneSelected)
      return;

647
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
648 649
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
650 651 652 653 654 655 656
      }
  }
#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
657
    // clear tags
658 659 660 661 662 663 664 665 666
    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
667
        noneSelected = false;
668 669 670 671 672 673
        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
674 675 676
    if (noneSelected)
      return;

677 678 679 680 681 682 683 684 685 686 687 688 689
    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
690 691
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
692
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
693 694 695 696
        }

      if (noneSelected)
        return;
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
    }
  #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] ) + " ) )" );

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

715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
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);
}

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

741
/** \brief transform an object
Jan Möbius's avatar
Jan Möbius committed
742
 *
Jan Möbius's avatar
 
Jan Möbius committed
743 744 745 746 747 748 749
 * @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
750
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
751 752 753
    return;
  }

754 755 756 757
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
758 759 760 761 762 763
  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
764
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
765
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
766 767 768 769 770 771 772 773
    }

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

    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) ) );
786
      mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
787
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
788
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
789
#endif
Matthias Möller's avatar
Matthias Möller committed
790 791 792 793 794 795 796 797 798 799 800
#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
801

Matthias Möller's avatar
Matthias Möller committed
802 803 804 805 806 807
    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) ) );
808
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
809
    }
Matthias Möller's avatar
Matthias Möller committed
810 811 812 813 814 815 816 817 818 819 820
  }
#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) ) );
821
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
822
    }
Matthias Möller's avatar
Matthias Möller committed
823 824 825 826 827 828 829
  }
#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
830

831
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
832 833 834 835 836 837 838 839 840 841 842 843 844 845

  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
846
/** \brief Transform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
847
 *
Jan Möbius's avatar
 
Jan Möbius committed
848 849 850 851
 * @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
852
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
853 854 855

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

860 861 862 863
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
864 865 866 867 868 869 870
  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) ) );
871
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
872 873 874 875 876 877 878 879 880
    }

  } 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) ) );
881
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
882
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
883
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
884
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
885
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
886 887 888 889 890 891

    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) ) );
892
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
893
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
894
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
895
#endif
Matthias Möller's avatar
Matthias Möller committed
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
#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
911

Matthias Möller's avatar
Matthias Möller committed
912 913 914 915 916
    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) ) );
917
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
918
    }
Matthias Möller's avatar
Matthias Möller committed
919 920 921 922 923 924 925 926 927 928
  }
#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) ) );
929
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
930
    }
Matthias Möller's avatar
Matthias Möller committed
931 932 933 934 935 936 937
  }
#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
938

939
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
940 941 942 943 944 945 946 947 948

  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 + " ) )" );
949
  
Jan Möbius's avatar
 
Jan Möbius committed
950 951 952 953 954 955
}


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

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

969 970 971 972
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

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

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

    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() )
      {
1009
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1010
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1011
        mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
1012
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1013
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
1014
#endif
Matthias Möller's avatar
Matthias Möller committed
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
#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
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
#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) ) );
1044
        normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
      }
  }
#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) ) );
1060
        normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1061 1062 1063 1064
      }
  }
#endif

1065 1066 1067
  if (noneSelected)
    return false;

1068
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
1069 1070 1071 1072 1073 1074 1075 1076 1077

  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
1078

1079
  return true;
Jan Möbius's avatar
 
Jan Möbius committed
1080 1081 1082 1083 1084 1085
}


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

/** \brief transform face selection
Jan Möbius's avatar
Jan Möbius committed
1086
 *
Jan Möbius's avatar
 
Jan Möbius committed
1087 1088
 * @param _objectId id of an object
 * @param _matrix transformation matrix
1089 1090
 *
 * @return returns true if selected elements were transformed
Jan Möbius's avatar
 
Jan Möbius committed
1091
 */
1092
bool MovePlugin::transformFaceSelection( int _objectId , Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
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;
Jan Möbius's avatar
 
Jan Möbius committed
1097 1098
  }

1099 1100 1101 1102
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

1103
  bool noneSelected = true;
Jan Möbius's avatar
 
Jan Möbius committed
1104 1105 1106 1107 1108 1109 1110
  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
1111
        mesh.status(*v_it).set_tagged(false);
Jan Möbius's avatar
 
Jan Möbius committed
1112 1113 1114 1115

    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
1116
      if ( mesh.status(*f_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1117
      {
1118
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1119 1120
        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
1121 1122 1123
      }

    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1124 1125
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1126
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1127 1128 1129 1130 1131 1132 1133 1134 1135
      }

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

    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
1141
      if ( mesh.status(*f_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1142
      {
1143
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1144 1145
        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
1146 1147 1148
      }

    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
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1151
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
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::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() )
      {
1169
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1170 1171 1172 1173 1174 1175 1176
        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) ) );
1177
        mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
1178
      }
Jan Möbius's avatar
 
Jan Möbius committed
1179
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1180
#endif
1181 1182 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
#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) ) );
1208
          normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
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
      }

  }
#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) ) );
1240
          normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
1241 1242 1243
      }
  }
#endif
Jan Möbius's avatar
Jan Möbius committed
1244

1245 1246
  if (noneSelected)
    return false;
Jan Möbius's avatar
Jan Möbius committed
1247

1248
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
1249 1250 1251 1252 1253 1254 1255 1256 1257

  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 + " ) )" );
1258
  
1259
  return true;
Jan Möbius's avatar
 
Jan Möbius committed
1260 1261 1262 1263 1264 1265
}


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

/** \brief transform edge selection