MovePluginScript.cc 70.7 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
\*===========================================================================*/

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

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

Jan Möbius's avatar
 
Jan Möbius committed
44 45
#include "MovePlugin.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
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
55 56
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif
57
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
58 59
#include <ObjectTypes/TetrahedralMesh/TetrahedralMesh.hh>
#endif
60
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
61 62
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
63 64

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

Jan Möbius's avatar
Jan Möbius committed
69 70
  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
71

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

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

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

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

85 86 87
  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
88 89
  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
90

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

Jan Möbius's avatar
Jan Möbius committed
95 96
  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
97

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

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

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

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

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

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


  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
150 151 152 153 154 155 156 157 158 159 160 161 162 163
}


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

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

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

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

    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
194
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
195
#endif
Matthias Möller's avatar
Matthias Möller committed
196 197 198 199 200 201 202 203 204
#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
205
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
206 207 208 209 210 211 212 213 214
  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
215
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
216 217 218 219 220 221 222 223 224
  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {

    TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(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
225
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239
  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
240

241
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
242 243 244 245 246 247 248 249 250 251 252

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

    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
292
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
293
#endif
Matthias Möller's avatar
Matthias Möller committed
294 295 296 297 298 299 300 301 302 303 304 305
#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
306
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
307
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
308

Matthias Möller's avatar
Matthias Möller committed
309 310 311 312
    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
313
    }
Matthias Möller's avatar
Matthias Möller committed
314 315
  }
#endif
316
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
317 318 319 320 321 322 323 324 325
  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {

    TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
    for (unsigned int i = 0; i < _vHandles.size(); ++i) {
      OpenVolumeMesh::VertexHandle v(_vHandles[i]);
      mesh.set_vertex(v, mesh.vertex(v) + _vector );
    }
  }
#endif
326
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
327 328 329 330 331 332
  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
333
    }
Matthias Möller's avatar
Matthias Möller committed
334 335 336 337 338 339 340
  }
#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
341

342
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
343 344 345 346 347

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
348
                   
Jan Möbius's avatar
 
Jan Möbius committed
349 350 351 352 353 354
}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
355
 *
Jan Möbius's avatar
 
Jan Möbius committed
356 357 358
 * @param _objectId id of an object
 * @param _vector translation vector
 */
359
void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
Jan Möbius's avatar
 
Jan Möbius committed
360 361 362

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

Matthias Möller's avatar
Matthias Möller committed
367 368
  bool noneSelected = true;

Jan Möbius's avatar
 
Jan Möbius committed
369 370 371 372 373 374
  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
375 376
      if ( mesh.status(*v_it).selected() ) {
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius 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 380 381 382 383 384 385

  } 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
386 387
      if ( mesh.status(*v_it).selected() ) {
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
388
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
389
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
390
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
391
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
392
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
393 394 395 396 397

    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
398 399
      if ( mesh.status(v_it).selected() ) {
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
400
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
401
      }
Jan Möbius's avatar
 
Jan Möbius committed
402
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
403
#endif
Matthias Möller's avatar
Matthias Möller committed
404 405 406 407 408 409 410 411 412 413 414 415
#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
416
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
417 418 419 420 421 422 423 424 425 426 427 428 429
  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
430
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
431 432 433 434 435 436 437 438 439 440 441 442 443
  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {

    TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
    OpenVolumeMesh::StatusAttrib& statusAttrib = ((TetrahedralMeshObject*)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
444
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  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
466

467
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
468 469 470 471 472 473 474 475 476 477

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


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

478 479 480 481 482 483 484 485 486 487 488 489 490
/** \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
491 492
  bool noneSelected = true;

493 494 495
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
Matthias Möller's avatar
Matthias Möller committed
496 497 498 499 500 501

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

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

Matthias Möller's avatar
Matthias Möller committed
513 514 515
    if (noneSelected)
      return;

516
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
517 518
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
519 520 521 522

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
Matthias Möller's avatar
Matthias Möller committed
523 524 525 526 527 528

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

529 530 531
    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
532
      if ( mesh.status(*f_it).selected() )
533
      {
Matthias Möller's avatar
Matthias Möller committed
534 535
        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
536
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
537
        }
538 539
      }

Matthias Möller's avatar
Matthias Möller committed
540 541 542
    if (noneSelected)
      return;

543
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
544 545
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
546 547 548 549 550
  }
#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
551 552 553 554 555 556

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

557 558 559 560 561
    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
562 563
        for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it) {
          noneSelected = false;
564
          mesh.status(fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
565
        }
566 567
      }

Matthias Möller's avatar
Matthias Möller committed
568 569 570
    if (noneSelected)
      return;

571 572 573 574 575 576 577 578 579 580 581 582
    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
583 584
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
585
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
586 587 588 589
        }

      if (noneSelected)
        return;
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
    }
  #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
623 624
  bool noneSelected = true;

625 626 627 628
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

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

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

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

        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
646 647 648
    if (noneSelected)
      return;

649
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
650 651
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
652 653 654 655 656 657
      }

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

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

Matthias Möller's avatar
Matthias Möller committed
658
    // clear tags
659 660
    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
661
      mesh.status(*v_it).set_tagged(false);
662 663 664 665

    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
666
      if ( mesh.status(*e_it).selected() )
667
      {
Matthias Möller's avatar
Matthias Möller committed
668
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
669
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
670 671 672 673 674

        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
675 676 677
    if (noneSelected)
      return;

678
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
679 680
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
681 682 683 684 685 686 687
      }
  }
#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
688
    // clear tags
689 690 691 692 693 694 695 696 697
    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
698
        noneSelected = false;
699 700 701 702 703 704
        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
705 706 707
    if (noneSelected)
      return;

708 709 710 711 712 713 714 715 716 717 718 719 720
    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
721 722
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
723
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
724 725 726 727
        }

      if (noneSelected)
        return;
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    }
  #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] ) + " ) )" );

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

746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
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);
}

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

772
/** \brief transform an object
Jan Möbius's avatar
Jan Möbius committed
773
 *
Jan Möbius's avatar
 
Jan Möbius committed
774 775 776 777 778 779 780
 * @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
781
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
782 783 784
    return;
  }

785 786 787 788
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
789 790 791 792 793 794
  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
795
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
796
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
797 798 799 800 801 802 803 804
    }

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
    PolyMesh::VertexIter v_it  = mesh.vertices_begin();
    PolyMesh::VertexIter v_end = mesh.vertices_end();
    for (; v_it!=v_end; ++v_it){
Jan Möbius's avatar
OM 3  
Jan Möbius committed
805
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
806
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
807
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
808
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
809
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
810
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
811 812 813 814 815 816

    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) ) );
817
      mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
818
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
819
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
820
#endif
Matthias Möller's avatar
Matthias Möller committed
821 822 823 824 825 826 827 828 829
#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
830
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
831
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
832

Matthias Möller's avatar
Matthias Möller committed
833 834 835 836 837 838
    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) ) );
839
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
840
    }
Matthias Möller's avatar
Matthias Möller committed
841 842
  }
#endif
843
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
844 845 846 847 848 849 850 851 852 853 854 855
  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {

    TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)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) ) );
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
    }
  }
#endif
856
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
857 858 859 860 861 862 863 864
  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) ) );
865
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
866
    }
Matthias Möller's avatar
Matthias Möller committed
867 868 869 870 871 872 873
  }
#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
874

875
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
876 877 878 879 880 881 882 883 884 885 886 887 888 889

  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
890
/** \brief Transform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
891
 *
Jan Möbius's avatar
 
Jan Möbius committed
892 893 894 895
 * @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
896
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
897 898 899

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

904 905 906 907
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
908 909 910 911 912 913 914
  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) ) );
915
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
916 917 918 919 920 921 922 923 924
    }

  } 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) ) );
925
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
926
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
927
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
928
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
929
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
930 931 932 933 934 935

    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) ) );
936
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
937
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
938
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
939
#endif
Matthias Möller's avatar
Matthias Möller committed
940 941 942 943 944 945 946 947 948 949 950 951 952
#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
953
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
954
  else if ( object->dataType(DATA_HEXAHEDRAL_MESH) ) {
Jan Möbius's avatar
 
Jan Möbius committed
955

Matthias Möller's avatar
Matthias Möller committed
956 957 958 959 960
    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) ) );
961
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
962
    }
Matthias Möller's avatar
Matthias Möller committed
963 964
  }
#endif
965
#ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
966 967 968 969 970 971 972 973 974 975 976
  else if ( object->dataType(DATA_TETRAHEDRAL_MESH) ) {

    TetrahedralMesh& mesh = (*PluginFunctions::tetrahedralMesh(object));
    OpenVolumeMesh::NormalAttrib<TetrahedralMesh>& normalAttrib = ((TetrahedralMeshObject*)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) ) );
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
    }
  }
#endif
977
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
978 979 980 981 982 983 984
  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) ) );
985
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
986
    }
Matthias Möller's avatar
Matthias Möller committed
987 988 989 990 991 992 993
  }
#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
994

995
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
996 997 998 999 1000 1001 1002 1003 1004

  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 + " ) )" );
1005
  
Jan Möbius's avatar
 
Jan Möbius committed
1006 1007 1008 1009 1010 1011
}


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

/** \brief transform vertex selection
Jan Möbius's avatar
Jan Möbius committed
1012
 *
Jan Möbius's avatar
 
Jan Möbius committed
1013 1014
 * @param _objectId id of an object
 * @param _matrix transformation matrix
1015 1016
 *
 * @return returns true if selected elements were transformed
Jan Möbius's avatar
 
Jan Möbius committed
1017
 */
1018
bool MovePlugin::transformVertexSelection( int _objectId , Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
1019 1020
  BaseObjectData* object;
  if ( ! PluginFunctions::getObject(_objectId,object) ) {
Jan Möbius's avatar
Jan Möbius committed
1021
    emit log(LOGERR,tr("transform : unable to get object") );
1022
    return false;
Jan Möbius's avatar
 
Jan Möbius committed
1023 1024
  }

1025 1026 1027 1028
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

1029
  bool noneSelected = true;
Jan Möbius's avatar
 
Jan Möbius committed
1030 1031 1032 1033 1034 1035
  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
1036
      if ( mesh.status(*v_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1037
      {
1038
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1039
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1040
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1041 1042 1043 1044 1045 1046 1047 1048
      }

  } 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
1049
      if ( mesh.status(*v_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1050
      {