MovePluginScript.cc 71.5 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
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif
63 64 65
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
#include <ObjectTypes/TetrahedralMesh/TetrahedralMesh.hh>
#endif
66 67 68
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif
Jan Möbius's avatar
 
Jan Möbius committed
69 70

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

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

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

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

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

Jan Möbius's avatar
Jan Möbius committed
88 89
  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
90

91 92 93
  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
94 95
  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
96

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

Jan Möbius's avatar
Jan Möbius committed
101 102
  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
103

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

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

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

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

Jan Möbius's avatar
Jan Möbius committed
132 133
  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
134

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


  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
156 157 158 159 160 161 162 163 164 165 166 167 168 169
}


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

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

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

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

    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
200
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
201
#endif
Matthias Möller's avatar
Matthias Möller committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
#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
221 222 223 224 225 226 227 228 229 230
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
  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
Matthias Möller's avatar
Matthias Möller committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
#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
246

247
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
248 249 250 251 252 253 254 255 256 257 258

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

  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

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

    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
288
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
289
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
290
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
291 292 293 294 295 296 297

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

    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
298
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
299
#endif
Matthias Möller's avatar
Matthias Möller committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313
#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
314

Matthias Möller's avatar
Matthias Möller committed
315 316 317 318
    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
319
    }
Matthias Möller's avatar
Matthias Möller committed
320 321
  }
#endif
322 323 324 325 326 327 328 329 330 331
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
  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
Matthias Möller's avatar
Matthias Möller committed
332 333 334 335 336 337 338
#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
339
    }
Matthias Möller's avatar
Matthias Möller committed
340 341 342 343 344 345 346
  }
#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
347

348
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
349 350 351 352 353

  emit scriptInfo( "translate( ObjectId , Vector(" +
                   QString::number( _vector[0] ) + " , " +
                   QString::number( _vector[1] ) + " , " +
                   QString::number( _vector[2] ) + " ) )" );
354
                   
Jan Möbius's avatar
 
Jan Möbius committed
355 356 357 358 359 360
}


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

/** \brief translate vertex selection
Jan Möbius's avatar
Jan Möbius committed
361
 *
Jan Möbius's avatar
 
Jan Möbius committed
362 363 364
 * @param _objectId id of an object
 * @param _vector translation vector
 */
365
void MovePlugin::translateVertexSelection( int _objectId , Vector _vector) {
Jan Möbius's avatar
 
Jan Möbius committed
366 367 368

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

Matthias Möller's avatar
Matthias Möller committed
373 374
  bool noneSelected = true;

Jan Möbius's avatar
 
Jan Möbius committed
375 376 377 378 379 380
  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
381 382
      if ( mesh.status(*v_it).selected() ) {
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius 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 386 387 388 389 390 391

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

    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
404 405
      if ( mesh.status(v_it).selected() ) {
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
406
        mesh.set_point(v_it,mesh.point(v_it) + _vector );
Matthias Möller's avatar
Matthias Möller committed
407
      }
Jan Möbius's avatar
 
Jan Möbius committed
408
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
409
#endif
Matthias Möller's avatar
Matthias Möller committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
#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
436 437 438 439 440 441 442 443 444 445 446 447 448 449
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
  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
Matthias Möller's avatar
Matthias Möller committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
#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
472

473
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
474 475 476 477 478 479 480 481 482 483

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


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

484 485 486 487 488 489 490 491 492 493 494 495 496
/** \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
497 498
  bool noneSelected = true;

499 500 501
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh&  mesh  = (*PluginFunctions::triMesh(object));
Matthias Möller's avatar
Matthias Möller committed
502 503 504 505 506 507

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

508 509 510
    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
511
      if ( mesh.status(*f_it).selected() )
512
      {
Matthias Möller's avatar
Matthias Möller committed
513 514
        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
515
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
516
        }
517 518
      }

Matthias Möller's avatar
Matthias Möller committed
519 520 521
    if (noneSelected)
      return;

522
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
523 524
      if ( mesh.status(*v_it).tagged() )
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
525 526 527 528

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

    PolyMesh&  mesh  = (*PluginFunctions::polyMesh(object));
Matthias Möller's avatar
Matthias Möller committed
529 530 531 532 533 534

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

535 536 537
    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
538
      if ( mesh.status(*f_it).selected() )
539
      {
Matthias Möller's avatar
Matthias Möller committed
540 541
        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
542
          mesh.status(*fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
543
        }
544 545
      }

Matthias Möller's avatar
Matthias Möller committed
546 547 548
    if (noneSelected)
      return;

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

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

563 564 565 566 567
    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
568 569
        for(TriMesh::FVIter fv_it = mesh.fv_iter(f_it); fv_it; ++fv_it) {
          noneSelected = false;
570
          mesh.status(fv_it).set_tagged(true);
Matthias Möller's avatar
Matthias Möller committed
571
        }
572 573
      }

Matthias Möller's avatar
Matthias Möller committed
574 575 576
    if (noneSelected)
      return;

577 578 579 580 581 582 583 584 585 586 587 588
    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
589 590
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
591
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
592 593 594 595
        }

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

631 632 633 634
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

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

Matthias Möller's avatar
Matthias Möller committed
635
    // clear tags
636 637
    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
638
      mesh.status(*v_it).set_tagged(false);
639 640 641 642

    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
643
      if ( mesh.status(*e_it).selected() )
644
      {
Matthias Möller's avatar
Matthias Möller committed
645
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
646
        TriMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
647 648 649 650 651

        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
652 653 654
    if (noneSelected)
      return;

655
    for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
Jan Möbius's avatar
OM 3  
Jan Möbius committed
656 657
      if ( mesh.status(*v_it).tagged() ){
        mesh.set_point(*v_it,mesh.point(*v_it) + _vector );
658 659 660 661 662 663
      }

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

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

Matthias Möller's avatar
Matthias Möller committed
664
    // clear tags
665 666
    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
667
      mesh.status(*v_it).set_tagged(false);
668 669 670 671

    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
672
      if ( mesh.status(*e_it).selected() )
673
      {
Matthias Möller's avatar
Matthias Möller committed
674
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
675
        PolyMesh::HalfedgeHandle hh = mesh.halfedge_handle( *e_it, 0 );
676 677 678 679 680

        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
681 682 683
    if (noneSelected)
      return;

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

714 715 716 717 718 719 720 721 722 723 724 725 726
    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
727 728
        if ( line.vertex_selection(i) ) {
          noneSelected = false;
729
          line.point(i) = line.point(i)  + _vector;
Matthias Möller's avatar
Matthias Möller committed
730 731 732 733
        }

      if (noneSelected)
        return;
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
    }
  #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] ) + " ) )" );

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

752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
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);
}

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

778
/** \brief transform an object
Jan Möbius's avatar
Jan Möbius committed
779
 *
Jan Möbius's avatar
 
Jan Möbius committed
780 781 782 783 784 785 786
 * @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
787
    emit log(LOGERR,tr("transform : unable to get object" ));
Jan Möbius's avatar
 
Jan Möbius committed
788 789 790
    return;
  }

791 792 793 794
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
795 796 797 798 799 800
  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
801
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
802
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
803 804 805 806 807 808 809 810
    }

  } 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
811
      mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
812
      mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
813
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
814
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
815
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
816
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
817 818 819 820 821 822

    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) ) );
823
      mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
824
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
825
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
826
#endif
Matthias Möller's avatar
Matthias Möller committed
827 828 829 830 831 832 833 834 835 836 837
#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
838

Matthias Möller's avatar
Matthias Möller committed
839 840 841 842 843 844
    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) ) );
845
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
846
    }
Matthias Möller's avatar
Matthias Möller committed
847 848
  }
#endif
849 850 851 852 853 854 855 856 857 858 859 860 861
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
  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
Matthias Möller's avatar
Matthias Möller committed
862 863 864 865 866 867 868 869 870
#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) ) );
871
      normalAttrib[*v_it] = normalMatrix.transform_vector( normalAttrib[*v_it] );
Jan Möbius's avatar
Jan Möbius committed
872
    }
Matthias Möller's avatar
Matthias Möller committed
873 874 875 876 877 878 879
  }
#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
880

881
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
882 883 884 885 886 887 888 889 890 891 892 893 894 895

  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
896
/** \brief Transform a set of vertex handles
Jan Möbius's avatar
Jan Möbius committed
897
 *
Jan Möbius's avatar
 
Jan Möbius committed
898 899 900 901
 * @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
902
void MovePlugin::transform( int _objectId , IdList _vHandles, Matrix4x4 _matrix ){
Jan Möbius's avatar
 
Jan Möbius committed
903 904 905

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

910 911 912 913
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

Jan Möbius's avatar
 
Jan Möbius committed
914 915 916 917 918 919 920
  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) ) );
921
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
922 923 924 925 926 927 928 929 930
    }

  } 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) ) );
931
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Jan Möbius's avatar
 
Jan Möbius committed
932
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
933
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
934
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Matthias Möller's avatar
Matthias Möller committed
935
  else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
936 937 938 939 940 941

    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) ) );
942
      mesh.set_normal(vh, normalMatrix.transform_vector( mesh.normal(vh) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
943
    }
Henrik Zimmer's avatar
Henrik Zimmer committed
944
   }
Henrik Zimmer's avatar
Henrik Zimmer committed
945
#endif
Matthias Möller's avatar
Matthias Möller committed
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
#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
961

Matthias Möller's avatar
Matthias Möller committed
962 963 964 965 966
    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) ) );
967
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
968
    }
Matthias Möller's avatar
Matthias Möller committed
969 970
  }
#endif
971 972 973 974 975 976 977 978 979 980 981 982
#ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
  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
Matthias Möller's avatar
Matthias Möller committed
983 984 985 986 987 988 989 990
#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) ) );
991
      normalAttrib[v] = normalMatrix.transform_vector( normalAttrib[v] );
Jan Möbius's avatar
Jan Möbius committed
992
    }
Matthias Möller's avatar
Matthias Möller committed
993 994 995 996 997 998 999
  }
#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
1000

1001
  emit updatedObject(_objectId, UPDATE_GEOMETRY);
Jan Möbius's avatar
 
Jan Möbius committed
1002 1003 1004 1005 1006 1007 1008 1009 1010

  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 + " ) )" );
1011
  
Jan Möbius's avatar
 
Jan Möbius committed
1012 1013 1014 1015 1016 1017
}


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

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

1031 1032 1033 1034
  Matrix4x4 normalMatrix = _matrix;
  normalMatrix.invert();
  normalMatrix.transpose();

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

  } 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
1055
      if ( mesh.status(*v_it).selected() )
Jan Möbius's avatar
 
Jan Möbius committed
1056
      {
1057
        noneSelected = false;
Jan Möbius's avatar
OM 3  
Jan Möbius committed
1058
        mesh.set_point (*v_it, _matrix.transform_point ( mesh.point(*v_it) ) );
1059
        mesh.set_normal(*v_it, normalMatrix.transform_vector( mesh.normal(*v_it) ) );
Jan Möbius's avatar
 
Jan Möbius committed
1060
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1061
  }
Henrik Zimmer's avatar
Henrik Zimmer committed
1062
#ifdef ENABLE_TSPLINEMESH_SUPPORT
Henrik Zimmer's avatar
Henrik Zimmer committed
1063
   else if ( object->dataType( DATA_TSPLINE_MESH ) ) {
Henrik Zimmer's avatar
Henrik Zimmer committed
1064 1065 1066 1067 1068 1069 1070

    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() )
      {
1071
        noneSelected = false;
Henrik Zimmer's avatar
Henrik Zimmer committed
1072
        mesh.set_point (v_it, _matrix.transform_point ( mesh.point(v_it) ) );
1073
        mesh.set_normal(v_it, normalMatrix.transform_vector( mesh.normal(v_it) ) );
Henrik Zimmer's avatar
Henrik Zimmer committed
1074
      }
Henrik Zimmer's avatar
Henrik Zimmer committed
1075
   }
Henrik Zimmer's avatar
Henrik Zimmer committed