PluginFunctions.cc 43.9 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
\*===========================================================================*/
49 50 51 52 53 54 55 56 57 58 59




//=============================================================================
//
//  Plugin Functions
//
//=============================================================================

#include <OpenFlipper/common/Types.hh>
60
#include <OpenFlipper/common/GlobalOptions.hh>
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
61
//#include <QGLWidget>
62

63 64 65
#include <../ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <../ObjectTypes/PolyMesh/PolyMesh.hh>

66
#include "PluginFunctionsCore.hh"
67 68 69 70 71 72 73

namespace PluginFunctions {

 /** \brief DONT USE DIRECTLY!!
  *
  * This Pointer will be used to access the data trees root in the plugin. Never use it directly as
 *  the internal Structure will change. Use the Access functions instead */
Jan Möbius's avatar
Jan Möbius committed
74
static BaseObject* objectRoot_ = 0;
75 76 77 78 79

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is internally used to acces the examiner widget in the main apllication
 */
80
static std::vector< glViewer* > examiner_widgets_;
Jan Möbius's avatar
Jan Möbius committed
81

Dirk Wilden's avatar
Dirk Wilden committed
82 83 84 85 86 87
/** \brief DONT USE DIRECTLY!!
 *
 * This vector is used internally to access properties of all viewers
 */
static std::vector< Viewer::ViewerProperties* > viewerProperties_;

Jan Möbius's avatar
Jan Möbius committed
88
/// TODO : Remove this variable and implement multiView correctly here
89
static glViewer*  examiner_widget_;
Jan Möbius's avatar
Jan Möbius committed
90

Jan Möbius's avatar
Docu  
Jan Möbius committed
91
/// Contains the currently active examiner
Jan Möbius's avatar
Jan Möbius committed
92
static unsigned int activeExaminer_ = 0;
93

94 95
static bool internalLightHandling_ = true;

96 97
/** \brief DONT USE DIRECTLY!!
 *
98 99
 * The pointer to the beginning of the scenegraph nodes ( only the nodes belonging to objects )
 * Between the actual root node ( sceneGraphRootNode_ ) and this node global nodes could be added
100 101
 * This pointer is internally used to access the scenegraphs root node
 */
102 103 104 105 106 107
static SeparatorNode* dataRootNode_ = 0;

/** This node is used to add nodes between the root node of the scenegraph and the objects separator node.
* It is directly below the sceneGraphRootNode_
*/
static SeparatorNode* dataSeparatorNode_ = 0;
108

109 110 111 112
/** \brief Scenegraph global nodes root
 */
static SeparatorNode* sceneGraphRootNodeGlobal_ = 0;

Jan Möbius's avatar
Docu  
Jan Möbius committed
113 114
/** \brief Scenegraph root node
 */
115
static SeparatorNode* sceneGraphRootNode_ = 0;
116

Jan Möbius's avatar
Docu  
Jan Möbius committed
117 118 119
/** \brief a dummy properties object returned as a reference if the real object does not exist
 *
 */
120
static Viewer::ViewerProperties dummyProperties(-1);
121

122 123 124 125 126 127 128

/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is used internally
 */
static ViewObjectMarker* defaultMarker_ = 0;

129 130 131 132 133 134
/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is used internally
 */
static QGLWidget* shareGLWidget_ = 0;

135 136 137 138
/** This is a unique id for the running OpenFlipper instance. Use it to identify yourself on the network
*/
static int viewerId_ = 0;

139 140 141 142 143 144
/// Number of currently open objects
static int objectCounter_ = 0;

/// Number of current target objects
static int targetCounter_ = 0;

145 146 147
/// Map that holds the object handles
static std::map<int, BaseObject*> objectMap_;

148 149 150
/// Map of scenegraph widget generators
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > sceneGraphGenerators_;

151 152 153 154
void setDataRoot( BaseObject* _root ) {
   objectRoot_ = _root;
}

155
int viewers( ) {
156 157 158
  return examiner_widgets_.size();
}

159 160 161 162 163 164 165 166
void disableExaminerLightHandling() {
  internalLightHandling_ = false;  
}

bool examinerLightHandling() {
  return internalLightHandling_;  
}

167 168 169 170
int viewerId() {
  return viewerId_;
}

171 172
void setViewers( std::vector< glViewer* > _viewerWidgets ) {
   PluginFunctions::examiner_widgets_ = _viewerWidgets;
Jan Möbius's avatar
Jan Möbius committed
173
   PluginFunctions::examiner_widget_ =  examiner_widgets_[0];
174 175 176 177 178

   // Generate a (hopefully) unique viewer id
   QTime time = QTime::currentTime();
   qsrand( time.hour() * 10 + time.minute() * 100 + time.second() * 1000 + time.msec() * 10000  );
   viewerId_ = qrand();
Jan Möbius's avatar
Jan Möbius committed
179 180
}

Dirk Wilden's avatar
Dirk Wilden committed
181 182 183 184
void setViewerProperties( std::vector< Viewer::ViewerProperties* > _viewerProperties ) {
   PluginFunctions::viewerProperties_ = _viewerProperties;
}

185
void setActiveExaminer( const unsigned int _id ) {
Jan Möbius's avatar
Jan Möbius committed
186
  activeExaminer_ = _id;
187 188
}

189 190 191 192 193 194 195 196 197
glViewer* viewer(int  _viewerId ) {
   if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     return examiner_widgets_[activeExaminer()];
   }

   return( examiner_widgets_[_viewerId] );
}

198 199 200 201
unsigned int activeExaminer( ) {
  return activeExaminer_;
}

202 203 204 205 206 207
QString getEncodedExaminerView() {
  return getEncodedExaminerView(activeExaminer());
}

/// Get the encoded view for the given
QString getEncodedExaminerView(int _viewerId) {
Mike Kremer's avatar
Mike Kremer committed
208

209
  QString view;
Mike Kremer's avatar
Mike Kremer committed
210

211 212 213 214
  if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     examiner_widgets_[activeExaminer()]->encodeView ( view );
     return view;
Mike Kremer's avatar
Mike Kremer committed
215 216
  }

217 218
  examiner_widgets_[_viewerId]->encodeView ( view );
  return view;
Mike Kremer's avatar
Mike Kremer committed
219

220 221 222 223 224 225 226
}

void setEncodedExaminerView( QString _view ) {
  setEncodedExaminerView( activeExaminer() , _view );
}

void setEncodedExaminerView(int _viewerId , QString _view ) {
Mike Kremer's avatar
Mike Kremer committed
227

228 229 230
  if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
     std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
     examiner_widgets_[activeExaminer()]->decodeView ( _view );
Mike Kremer's avatar
Mike Kremer committed
231 232
  }

233
  examiner_widgets_[_viewerId]->decodeView ( _view );
Mike Kremer's avatar
Mike Kremer committed
234 235
}

236 237 238
void setDataSeparatorNodes( SeparatorNode* _dataSeparatorNode ) {
  
  // The function should only be called once by the core. 
239

240 241 242 243 244 245 246 247 248 249 250 251 252
  // Set the separatorNode
  PluginFunctions::dataSeparatorNode_ = _dataSeparatorNode;

  
  if ( PluginFunctions::dataSeparatorNode_->nChildren() != 1 ){
    std::cerr << "Only one child allowed for dataSeparatorNode on initialization!" << std::endl;
    std::cerr << "The Core has initialized the scenegraph in a strange way!" << std::endl;
  }
  
  // Set the root node for the data objects
  // which has to be a child of the dataSeparatorNode_
  PluginFunctions::dataRootNode_ = dynamic_cast<ACG::SceneGraph::SeparatorNode*> (*(PluginFunctions::dataSeparatorNode_->childrenBegin()) );
  
253 254
}

255
void setSceneGraphRootNode( SeparatorNode* _root_node ) {
256
   PluginFunctions::sceneGraphRootNode_ = _root_node;
257 258
}

259 260 261 262
void setSceneGraphRootNodeGlobal( SeparatorNode* _root_node ) {
   PluginFunctions::sceneGraphRootNodeGlobal_ = _root_node;
}

263
bool getPickedObject(const unsigned int _node_idx , BaseObjectData*& _object) {
264
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
265 266 267 268 269 270 271 272 273
    if ( o_it->picked( _node_idx ) ) {
      _object = *o_it;
      return true;
    }
  }
  return false;
}


274
bool getSourceIdentifiers( std::vector<int>& _identifiers  ) {
275 276
  _identifiers.clear();

277
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
278 279 280
    if ( o_it->source() )
      _identifiers.push_back ( o_it->id() );
  }
281
  return ( ! _identifiers.empty() );
282 283
}

284
bool getTargetIdentifiers( std::vector<int>& _identifiers  ) {
285 286
  _identifiers.clear();

287
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
288 289 290
    if ( o_it->target() )
      _identifiers.push_back ( o_it->id() );
  }
291
  return ( !_identifiers.empty() );
292 293 294 295 296 297
}

// ===============================================================================
// Get objects
// ===============================================================================

298
bool getObject(  const int _identifier , BaseObject*& _object ) {
299

300 301
  if ( _identifier == -1 )
    return false;
302

303 304 305 306 307 308 309 310 311
  // Obsolete:
  //_object = objectRoot_->childExists( _identifier );
  
  // Search for specified object in object map:
  std::map<int, BaseObject*>::iterator it;
  it = objectMap_.find(_identifier);
  // Get object
  _object = (it != objectMap_.end() ? it->second : 0);
  
312 313 314
  return ( _object != 0 );
}

315
bool getObject(  const int _identifier , BaseObjectData*& _object ) {
316

317 318
  if ( _identifier == -1 )
    return false;
319

320 321 322 323 324 325 326 327
  // Obsolete: BaseObject* object = objectRoot_->childExists( _identifier );
  
  // Search for specified object in object map:
  std::map<int, BaseObject*>::iterator it;
  it = objectMap_.find(_identifier);
  // Get object
  BaseObject* object = (it != objectMap_.end() ? it->second : 0);
  
328 329 330 331
  _object = dynamic_cast< BaseObjectData* >(object);
  return ( _object != 0 );
}

Jan Möbius's avatar
Jan Möbius committed
332
int getObjectId( const QString& _name ) {
Jan Möbius's avatar
Jan Möbius committed
333
  if(_name.isEmpty()) return -1;
334

Jan Möbius's avatar
Jan Möbius committed
335 336
  BaseObject* object = objectRoot_->childExists( _name );
  return object ? object->id() : -1;
337 338
}

339 340 341
// ===============================================================================
// ===============================================================================

342
bool objectExists(  const int _identifier ) {
343

344 345
  if ( _identifier == -1 )
    return false;
346

347 348 349 350 351 352
  BaseObject* object = objectRoot_->childExists( _identifier );
  return ( object != 0 );
}

//===============================================================================

353
bool getAllMeshes( std::vector<int>& _identifiers  ) {
354 355 356 357

  _identifiers.clear();

  // find changed manipulator
358
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,typeId("TriangleMesh")) ;
359
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
360 361 362
    _identifiers.push_back( o_it->id() );
  }

363
  return (!_identifiers.empty());
364 365
}

366
bool getAllObjectIdentifiers( std::vector<int>& _identifiers  ) {
367 368 369 370 371

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
372
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
373 374 375
    _identifiers.push_back( o_it->id() );
  }

376
  return ( !_identifiers.empty() );
377 378 379
}

void setBackColor( OpenMesh::Vec4f _color) {
380
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
381
    PluginFunctions::viewerProperties(i).backgroundColor(_color);
382 383
}

384 385 386 387 388 389 390 391 392 393
void setFixedView(int _mode, int _viewer ) {

  if ( (_viewer != ACTIVE_VIEWER ) && ( ( _viewer < 0 ) || _viewer >= (int)examiner_widgets_.size()) ){
    std::cerr << "Unable to set fixed view. Wrong viewer id (" << _viewer << ")" << std::endl;
    return;
  }

  switch ( _mode ){
    case VIEW_TOP : //TOP
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, -1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
394
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
395 396 397
      break;
    case VIEW_BOTTOM : //BOTTOM
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
398
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
399 400 401
      break;
    case VIEW_LEFT : //LEFT
      PluginFunctions::viewingDirection( ACG::Vec3d(1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
402
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
403 404 405
      break;
    case VIEW_RIGHT : //RIGHT
      PluginFunctions::viewingDirection( ACG::Vec3d(-1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
406
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
407 408 409
      break;
    case VIEW_FRONT : //FRONT
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, -1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
410
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
411 412 413
      break;
    case VIEW_BACK : //BACK
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, 1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
414
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
415 416 417 418 419 420 421 422 423 424 425 426
      break;
    default : //Free View
      PluginFunctions::allowRotation(true, _viewer);
      break;
  }

  if ( _viewer == ACTIVE_VIEWER )
    viewerProperties(activeExaminer()).currentViewingDirection( _mode );
  else
    viewerProperties( _viewer ).currentViewingDirection( _mode );
}

427
QPoint mapToGlobal(const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
428
  return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
429 430
}

431
QPoint mapToLocal( const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
432
  return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
433 434
}

Jan Möbius's avatar
Jan Möbius committed
435
void setDrawMode( const ACG::SceneGraph::DrawModes::DrawMode& _mode , int _viewer) {
436

Jan Möbius's avatar
Jan Möbius committed
437
  if ( _viewer == ACTIVE_VIEWER )
438 439
    viewerProperties(activeExaminer()).drawMode(_mode);
  else if ( _viewer == ALL_VIEWERS )
Jan Möbius's avatar
Jan Möbius committed
440
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
441
      viewerProperties(i).drawMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
442
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
443
    viewerProperties(_viewer).drawMode(_mode);
444 445 446
  else
    std::cerr << "Requested illegal viewer for setting DrawMode!!" << std::endl;

447 448 449 450 451 452 453
}

/** Get the current draw Mode of the examiner widget.\n
 *
 * The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
 * They can be combined.
 */
Jan Möbius's avatar
Jan Möbius committed
454
ACG::SceneGraph::DrawModes::DrawMode drawMode( int _viewer ) {
455
  if ( _viewer == ACTIVE_VIEWER ) {
456
    return viewerProperties(activeExaminer()).drawMode();
457 458 459
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get viewing direction!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
460
    return viewerProperties(_viewer).drawMode();
461 462
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
463

464
  return viewerProperties(activeExaminer()).drawMode();
465 466
}

467
//get a viewing ray for the active examiner x and y are in widgetspace
468
void viewingRay(int _x, int _y,
469 470
               ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection)
{
471
  viewingRay(_x,_y,_outOrigin,_outDirection,activeExaminer_);
472 473 474
}

//get a viewing ray for the specified examiner x and y are in widgetspace
475
void viewingRay(int _x, int _y,
476 477 478 479 480
               ACG::Vec3d& _outOrigin, ACG::Vec3d& _outDirection, int _viewerIndex)
{
  viewerProperties(_viewerIndex).glState().viewing_ray(_x,_y,_outOrigin,_outDirection);
}

481
// Pick returning node index
482
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
Jan Möbius's avatar
Jan Möbius committed
483 484 485 486

   return examiner_widgets_[activeExaminer_]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
}

487
// Pick returning node index
488
bool scenegraphPick( const unsigned int _examiner, ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
Jan Möbius's avatar
Jan Möbius committed
489 490 491 492 493 494

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
  return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
495 496
}

497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516

// Pick returning object and calling refine
bool scenegraphPick( const unsigned int          _examiner ,
                     ACG::SceneGraph::PickTarget _pickTarget,
                     const QPoint &              _mousePos,
                     BaseObjectData*&            _object,
                     unsigned int &              _targetIdx,
                     const bool                  _refine,
                     ACG::Vec3d *                _hitPointPtr ) {

  unsigned int nodeIdx = 0;

  bool ok = scenegraphPick(_examiner,_pickTarget,_mousePos,nodeIdx,_targetIdx,_hitPointPtr);

  // If successfully picked and object is found
  if ( ok && PluginFunctions::getPickedObject(nodeIdx, _object) ) {

    if ( _refine && (_hitPointPtr != 0) ) {

      // Map to correct coordinates in OpenGL
517 518
      double x = _mousePos.x();
      double y = examiner_widget_->glHeight() - _mousePos.y();
519

520 521
      ACG::Vec3d mousePoint3d;
      ACG::Vec3d direction;
522

523
      viewingRay(x,y,mousePoint3d,direction);
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548

      *_hitPointPtr = _object->refinePick(_pickTarget,*_hitPointPtr, mousePoint3d , direction ,  _targetIdx );

    }

  }

  return ok;
}

// Pick returning object and calling refine
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget,
                     const QPoint &              _mousePos,
                     BaseObjectData*&            _object,
                     unsigned int &              _targetIdx,
                     const bool                  _refine,
                     ACG::Vec3d *                _hitPointPtr ) {

  return scenegraphPick(activeExaminer_,_pickTarget,_mousePos, _object,_targetIdx,_refine,_hitPointPtr );

}




Henrik Zimmer's avatar
Henrik Zimmer committed
549 550 551
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list,
552 553
                           QVector<float>*                            _depths,
                           QVector<ACG::Vec3d>*                       _points)
Henrik Zimmer's avatar
Henrik Zimmer committed
554
{
555
  return examiner_widgets_[activeExaminer_]->pick_region( _pickTarget, _region, _list, _depths, _points);
Henrik Zimmer's avatar
Henrik Zimmer committed
556 557 558 559 560 561
}

bool scenegraphRegionPick( const unsigned int                         _examiner,
                           ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list,
562 563
                           QVector<float>*                            _depths,
                           QVector<ACG::Vec3d>*                       _points)
Henrik Zimmer's avatar
Henrik Zimmer committed
564 565 566 567 568
{
  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
569
  return examiner_widgets_[_examiner]->pick_region( _pickTarget, _region, _list, _depths, _points);
Henrik Zimmer's avatar
Henrik Zimmer committed
570
}
571 572 573

//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction  &_action ) {
574 575
  // Single pass action, as the mouse action will only update the graph.
  // If its changed, it will be set to dirty and an automatic redraw is triggered.
576
  ACG::SceneGraph::traverse(sceneGraphRootNode_, _action );
577 578
}

579
const std::string pickMode () {
580
  // No seperate draw modes available all should have the same so take first
581
  return viewerProperties().pickMode();
582 583
}

Jan Möbius's avatar
Jan Möbius committed
584
void pickMode ( const std::string& _mode) {
585 586
  // switch to default marker
  setViewObjectMarker (defaultViewObjectMarker ());
587
  viewerProperties().pickMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
588 589
}

590 591
Viewer::ActionMode actionMode() {
   return viewerProperties().actionMode();
592 593
}

594 595
void actionMode ( Viewer::ActionMode _mode) {

596
  viewerProperties().actionMode(_mode);
597 598
}

599 600 601 602 603 604 605 606 607 608
void shareGLWidget (QGLWidget *_widget)
{
  shareGLWidget_ = _widget;
}

QGLWidget *shareGLWidget ()
{
  return shareGLWidget_;
}

609
void getCurrentViewImage(QImage& _image) {
610
  viewer( activeExaminer() )->snapshot( _image );
611 612
}

613
Viewer::ViewerProperties& viewerProperties(int _id) {
Dirk Wilden's avatar
Dirk Wilden committed
614
  if ( _id >= (int)viewerProperties_.size() ) {
615 616 617 618 619 620 621
    std::cerr << " Error, requested properties for non-existing Viewer!" << std::endl;
    return dummyProperties;
  }

  if ( _id == -1 )
    _id = activeExaminer_;

Dirk Wilden's avatar
Dirk Wilden committed
622
  return ( *viewerProperties_[_id] );
623

624 625
}

Jan Möbius's avatar
Jan Möbius committed
626 627 628 629 630 631 632 633 634 635
void perspectiveProjection( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->perspectiveProjection();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->perspectiveProjection();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->perspectiveProjection();
  else
    std::cerr << "Requested illegal viewer for perspectiveProjection()!!" << std::endl;
636 637
}

Jan Möbius's avatar
Jan Möbius committed
638 639 640 641 642 643 644 645 646 647
void orthographicProjection( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->orthographicProjection();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->orthographicProjection();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->orthographicProjection();
  else
    std::cerr << "Requested illegal viewer for orthographicProjection()!!" << std::endl;
648 649
}

650
void setFOVY( double _fovy) {
651
  
652 653 654
  // Set FOVY for all viewers
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
    examiner_widgets_[i]->setFOVY(_fovy);
655 656
}

657 658 659 660 661 662 663 664
void allowRotation(bool _mode, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->allowRotation(_mode);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->allowRotation(_mode);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->allowRotation(_mode);
665
  else {
666
    std::cerr << "Requested illegal viewer for allowRotation!!" << std::endl;
667 668 669 670 671 672 673
    return;
  }
  
  if ( _viewer == ACTIVE_VIEWER )
    viewerProperties(activeExaminer()).rotationLocked( !_mode );
  else
    viewerProperties( _viewer ).rotationLocked( !_mode );
674 675 676 677 678 679 680 681 682 683 684
}

bool allowRotation( int _viewer ) {

  if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return examiner_widgets_[_viewer]->allowRotation();
  else {

    std::cerr << "Requested illegal viewer for isRotationAllowed!!" << std::endl;
    return false;
  }
685 686
}

687 688 689 690
void setMainGLContext() {
  examiner_widget_->makeCurrent();
}

691 692 693 694 695 696 697 698 699 700
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up , int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->viewingDirection(_dir,_up);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->viewingDirection(_dir,_up);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->viewingDirection(_dir,_up);
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
701 702
}

703 704 705 706 707 708 709 710 711 712 713 714 715
void lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const ACG::Vec3d& _up, int _viewer) {
    
    if ( _viewer == ACTIVE_VIEWER ) {
        examiner_widgets_[activeExaminer_]->lookAt(_eye,_center, _up);
    } else if ( _viewer == ALL_VIEWERS )
        for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
            examiner_widgets_[i]->lookAt(_eye,_center, _up);
        else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
            examiner_widgets_[_viewer]->lookAt(_eye,_center, _up);
        else
            std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
}

Dirk Wilden's avatar
Dirk Wilden committed
716
const ACG::Vec3d trackBallCenter( int _viewer ) {
717 718 719 720 721 722 723 724 725
  if ( _viewer == ACTIVE_VIEWER ) {
    return examiner_widgets_[activeExaminer_]->trackBallCenter();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      return examiner_widgets_[i]->trackBallCenter(  );
    else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
      return examiner_widgets_[_viewer]->trackBallCenter(  );
    else
      std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
Jan Möbius's avatar
Jan Möbius committed
726 727

  return examiner_widgets_[activeExaminer_]->trackBallCenter();
728 729 730 731 732 733 734 735 736 737 738 739 740 741
}

void setTrackBallCenter(const ACG::Vec3d& _center, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setTrackBallCenter( _center );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setTrackBallCenter( _center );
    else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
      examiner_widgets_[_viewer]->setTrackBallCenter( _center );
    else
      std::cerr << "Requested illegal viewer for setTrackBallCenter!!" << std::endl;
}

742 743 744 745 746 747 748 749 750 751
void setScenePos(const ACG::Vec3d& _center,const double _radius, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setScenePos( _center, _radius );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setScenePos( _center, _radius );
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->setScenePos( _center, _radius );
  else
    std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
752 753
}

754 755 756 757 758 759 760 761 762 763
void setScenePos(const ACG::Vec3d& _center, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->setScenePos( _center, examiner_widgets_[activeExaminer_]->scene_radius() );
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->setScenePos( _center, examiner_widgets_[i]->scene_radius() );
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->setScenePos( _center, examiner_widgets_[_viewer]->scene_radius() );
  else
    std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
764 765
}

766 767
void setSceneCenter(const ACG::Vec3d& _center, int _viewer) {

Jan Möbius's avatar
Jan Möbius committed
768 769 770
  if (_viewer == ACTIVE_VIEWER) {
    examiner_widgets_[activeExaminer_]->setSceneCenter(_center);
  } else if (_viewer == ALL_VIEWERS) {
771

Jan Möbius's avatar
Jan Möbius committed
772 773 774 775 776 777 778 779
    for (uint i = 0; i < examiner_widgets_.size(); ++i) {
      examiner_widgets_[i]->setSceneCenter(_center);
    }
  } else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size()) {
    examiner_widgets_[_viewer]->setSceneCenter(_center);
  } else {
    std::cerr << "Requested illegal viewer for setSceneCenter!!" << std::endl;
  }
780 781
}

782
const ACG::Vec3d sceneCenter(int _viewer) {
783

Jan Möbius's avatar
Jan Möbius committed
784 785 786 787 788 789 790 791 792 793
  if (_viewer == ACTIVE_VIEWER) {
    return examiner_widgets_[activeExaminer_]->scene_center();
  } else if (_viewer == ALL_VIEWERS)
    std::cerr << "Please select viewer to get sceneCenter!" << std::endl;
  else if ((_viewer >= 0) && _viewer < (int) examiner_widgets_.size())
    return examiner_widgets_[_viewer]->scene_center();
  else
    std::cerr << "Requested illegal viewer for sceneCenter!!" << std::endl;

  return examiner_widgets_[activeExaminer_]->scene_center();
794 795 796
}

double sceneRadius() {
797
   return examiner_widgets_[activeExaminer_]->scene_radius();
798 799
}

800 801 802 803 804 805 806 807 808
double sceneRadius( int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return examiner_widgets_[activeExaminer_]->scene_radius();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Illegal request for scene radius. Please select one viewer!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return examiner_widgets_[_viewer]->scene_radius();
  else
    std::cerr << "Requested illegal viewer for translate!!" << std::endl;
Mike Kremer's avatar
Mike Kremer committed
809

810 811 812
  return -1;
}

813 814
void setSceneRadius(double _radius, int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
Marcel Campen's avatar
Marcel Campen committed
815
    examiner_widgets_[activeExaminer_]->setSceneRadius(_radius);
816 817
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
Marcel Campen's avatar
Marcel Campen committed
818
      examiner_widgets_[i]->setSceneRadius(_radius);
819
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
Marcel Campen's avatar
Marcel Campen committed
820
    examiner_widgets_[_viewer]->setSceneRadius(_radius);
821 822 823 824
  else
    std::cerr << "Requested illegal viewer for translate!!" << std::endl;
}

825 826 827 828 829 830 831 832 833 834
void translate( const ACG::Vec3d &_vector , int _viewer ) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->translate(_vector);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->translate(_vector);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->translate(_vector);
  else
    std::cerr << "Requested illegal viewer for translate!!" << std::endl;
835 836
}

837
void rotate(const ACG::Vec3d&  _axis,
838
            const double       _angle,
839 840
            const ACG::Vec3d&  _center,
            int                _viewer )
841
{
842 843 844 845 846 847 848 849 850
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->rotate(_axis,_angle,_center);
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->rotate(_axis,_angle,_center);
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->rotate(_axis,_angle,_center);
  else
    std::cerr << "Requested illegal viewer for rotate!!" << std::endl;
851 852
}

853 854 855 856 857 858 859 860 861 862
void viewHome(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->home();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->home();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->home();
  else
    std::cerr << "Requested illegal viewer for viewHome!!" << std::endl;
863 864
}

865 866 867 868 869 870 871 872 873 874
void viewAll(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->viewAll();
  } else if ( _viewer == ALL_VIEWERS )
    for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
      examiner_widgets_[i]->viewAll();
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->viewAll();
  else
    std::cerr << "Requested illegal viewer for viewAll!!" << std::endl;
875 876
}

877 878 879 880 881 882 883 884 885 886
ACG::Vec3d viewingDirection(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().viewing_direction();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get viewing direction!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().viewing_direction();
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;

887
  return viewerProperties().glState().viewing_direction();
888 889
}

890 891
bool isProjectionOrthographic( int _viewer ) {

892 893 894 895
  if ( _viewer == ACTIVE_VIEWER) {
    return (examiner_widgets_[activeExaminer_]->projectionMode() == 0);
  } else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() ){
    return ( examiner_widgets_[_viewer]->projectionMode() == 0); //ORTHOGRAPHIC_PROJECTION ?
896 897 898 899 900 901
  } else
    std::cerr << "Requested illegal viewer for isProjectionOrthographic!!" << std::endl;

  return false;
}

902 903 904 905 906 907 908 909 910 911
ACG::Vec3d eyePos(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().eye();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get eyePos!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().eye();
  else
    std::cerr << "Requested illegal viewer for eyePos!!" << std::endl;

912
  return viewerProperties().glState().eye();
913 914
}

915 916 917 918 919 920 921 922 923 924
ACG::Vec3d upVector(int _viewer) {
  if ( _viewer == ACTIVE_VIEWER ) {
    return viewerProperties(activeExaminer_).glState().up();
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get up vector!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    return viewerProperties(_viewer).glState().up();
  else
    std::cerr << "Requested illegal viewer for up vector!!" << std::endl;

925
  return viewerProperties().glState().up();
926 927
}

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
/** \brief Get field of view angle
 */
DLLEXPORT
double fovy(int _viewer) {
    if ( _viewer == ACTIVE_VIEWER ) {
      return viewerProperties(activeExaminer_).glState().fovy();
    } else if ( _viewer == ALL_VIEWERS )
      std::cerr << "Please select viewer to get fovy!" << std::endl;
    else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
      return viewerProperties(_viewer).glState().fovy();
    else
      std::cerr << "Requested illegal viewer for fovy!!" << std::endl;

    return viewerProperties().glState().fovy();
}

944 945
void setViewObjectMarker(ViewObjectMarker * _marker)
{
Jan Möbius's avatar
Jan Möbius committed
946 947
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
    PluginFunctions::viewerProperties(i).objectMarker(_marker);
948 949 950 951 952 953 954 955 956 957 958 959 960
}

void setDefaultViewObjectMarker(ViewObjectMarker * _marker)
{
  defaultMarker_ = _marker;
}

ViewObjectMarker * defaultViewObjectMarker()
{
  return defaultMarker_;
}


961
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
962
   return PluginFunctions::sceneGraphRootNode_;
963 964
}

965
ACG::SceneGraph::BaseNode* getRootNode() {
966
  return PluginFunctions::dataRootNode_;
967 968
}

969 970 971 972 973 974 975 976 977
void addGlobalStatusNode(ACG::SceneGraph::BaseNode* _node) {
 if (PluginFunctions::sceneGraphRootNode_){
    
    // get the current parent Node 
    ACG::SceneGraph::BaseNode* parent = sceneGraphRootNodeGlobal_->parent();

    // Move the node to the new parent
    _node->set_parent(parent);
    
Jan Möbius's avatar
Jan Möbius committed
978
    // move sceneGraphRootNodeGlobal_ to the new parent
979 980 981 982
    sceneGraphRootNodeGlobal_->set_parent(_node);
  }
}

983 984
void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraphRootNode_)
985
    _node->set_parent( PluginFunctions::sceneGraphRootNodeGlobal_ );
986 987 988
}


989 990 991 992 993 994 995 996 997 998 999
void addObjectRenderingNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraphRootNode_){
    
    // get the current parent Node 
    ACG::SceneGraph::BaseNode* parent = dataRootNode_->parent();

    // Move the node to the new parent
    _node->set_parent(parent);
    
    // move dataRootNode_ to the new parent
    dataRootNode_->set_parent(_node);
1000
  }
1001
  
1002 1003
}

1004
int objectCount() {
1005
  return(objectCounter_);
1006 1007 1008 1009
}



1010 1011
int targetCount() {
  return ( targetCounter_ );
1012 1013
}

1014
int sourceCount() {
1015 1016 1017 1018
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
1019
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
1020 1021 1022 1023 1024 1025
    ++count;
  }

  return ( count );
}

1026
int visibleCount() {
1027 1028 1029 1030
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
1031
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
    if ( o_it->visible() )
    ++count;
  }

  return ( count );

}


/** Returns a vector containing all currently available objects
 *
 * @param _objects vector of all objects
 */
void get_all_objects( std::vector < BaseObjectData*>& _objects ) {

   _objects.clear();

  // find changed manipulator
1050
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_ALL) ;
1051
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
1052 1053 1054 1055 1056
    _objects.push_back( *o_it );
  }

}

1057 1058

/// Fly to point and viewing direction (animated).
Jan Möbius's avatar
Jan Möbius committed
1059
void flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time) {
1060
   examiner_widgets_[activeExaminer_]->flyTo(_position,_center,_time);
1061 1062
}

1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

/// Fly to point and keep viewing direction (animated).
void flyTo (const ACG::Vec3d &_center, bool _move_back, double _time) {
  ACG::Vec3d eye = PluginFunctions::viewerProperties().glState().eye();
  ACG::Vec3d t = _center - eye;
  ACG::Vec3d e = eye + t * (_move_back ? -0.5f : 0.5f);
  examiner_widgets_[activeExaminer_]->flyTo(e, _center, _time);
}


1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
/// Take a snapshot of a viewer
void viewerSnapshot(int _viewer, QImage& _image, int _width, int _height, bool _alpha,
                    bool _hideCoordsys, int _samples) {
    
  if ( _viewer == ACTIVE_VIEWER ) {
    examiner_widgets_[activeExaminer_]->snapshot(_image, _width, _height, _alpha, _hideCoordsys, _samples);
  } else if ( _viewer == ALL_VIEWERS )
    std::cerr << "Please select viewer to get snapshot!" << std::endl;
  else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
    examiner_widgets_[_viewer]->snapshot(_image, _width, _height, _alpha, _hideCoordsys, _samples);
  else
    std::cerr << "Requested illegal viewer for snapshot!!" << std::endl;
}

1087 1088


1089 1090 1091 1092 1093 1094 1095
// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================

BaseObjectData* baseObjectData( BaseObject* _object ){
  if ( _object == 0 )
    return 0;
1096

1097 1098 1099 1100 1101 1102
  return dynamic_cast< BaseObjectData* >(_object);
}

// ===============================================================================
// Get the root of the object structure
// ===============================================================================
Jan Möbius's avatar
Jan Möbius committed
1103
BaseObject*& objectRoot() {
1104 1105 1106
  return (objectRoot_);
}

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
void increaseObjectCount() {
  objectCounter_++;
}

// Increase the number of current Object
void decreaseObjectCount() {
  objectCounter_--;
  
  if ( objectCounter_ < 0 )
    std::cerr << "Deleted more objects than created!!!" << std::endl;
}

void increaseTargetCount() {
  targetCounter_++;
}

// Increase the number of current Object
void decreaseTargetCount() {
  targetCounter_--;
  
  if ( targetCounter_ < 0 )
    std::cerr << "target object counter underflow!!!" << std::endl;
}

1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
// ===============================================================================
// Add an object to the internal object map
// ===============================================================================
void addObjectToMap(int _objectId, BaseObject* _object) {
    
    // Look if object's id already exists in map
    std::map<int, BaseObject*>::iterator it;
    it = objectMap_.find(_objectId);
    // If so return
    if(it != objectMap_.end()) return;
    
    // Add new object to map
    objectMap_.insert(std::pair<int, BaseObject*>(_objectId, _object));
}

// ===============================================================================
// Remove an object from the internal object map
// ===============================================================================
void removeObjectFromMap(int _objectId) {
    
    // Look if object exists in map
    std::map<int, BaseObject*>::iterator it;
    it = objectMap_.find(_objectId);
    
    // Erase entry
    if(it != objectMap_.end()) objectMap_.erase(it);
1157
}
1158 1159


1160
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator* _generator) {
1161
  
1162
   // Check if we already have a generator for this type.
1163 1164
  if ( sceneGraphGenerators_.contains( _generator->handles() ) ) 
    return;
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174

  // Store the generator
  sceneGraphGenerators_[_generator->handles() ] = _generator;
}


QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > getSceneGraphGeneratorList(){
  return sceneGraphGenerators_;
}

1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
QString getOpenFileName(const QString &configProperty,
                        QWidget * parent, const QString & caption,
                        const QString & defaultDir, const QString & filter,
                        QString * selectedFilter, QFileDialog::Options options) {

    const QString dir = OpenFlipperSettings().value(configProperty, defaultDir).toString();
    const QString result = QFileDialog::getOpenFileName(parent, caption, dir,
                                                        filter, selectedFilter, options);
    if (result.length())
        OpenFlipperSettings().setValue(configProperty, result);
    return result;
}

QString getSaveFileName(const QString &configProperty,
                        QWidget * parent, const QString & caption,
                        const QString & defaultDir, const QString & filter,
1191 1192
                        QString * selectedFilter, QFileDialog::Options options,
                        const QString & defaultSuffix) {
1193 1194

    const QString dir = OpenFlipperSettings().value(configProperty, defaultDir).toString();
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213

    /*
     * We don't use this convenience wrapper any more since it
     * prevents us from setting the default suffix.
     *
     * const QString result = QFileDialog::getSaveFileName(
     *     parent, caption, dir, filter, selectedFilter, options);
     */

    QFileDialog dialog(parent, caption, dir, filter);
    dialog.setOptions(options);
    dialog.setAcceptMode(QFileDialog::AcceptSave);
    if (selectedFilter && !selectedFilter->isEmpty())
        dialog.selectNameFilter(*selectedFilter);
    dialog.setDefaultSuffix(defaultSuffix);
    if (dialog.exec() == QDialog::Accepted) {
        if (selectedFilter)
            *selectedFilter = dialog.selectedNameFilter();
        QString result = dialog.selectedFiles().value(0);
1214
        OpenFlipperSettings().setValue(configProperty, result);
1215 1216 1217
        return result;
    }
    return QString();
1218 1219
}

1220 1221
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
    QStringList result;
1222
    for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_ALL) ; o_it != objectsEnd(); ++o_it) {
1223 1224 1225

        if (visibleOnly && !o_it->visible()) continue;

1226
        result.append(o_it->getAllCommentsFlat());
1227 1228 1229 1230
    }
    return result;
}

1231
QStringList collectObjectMaterials(bool visibleOnly, bool targetedOnly) {
1232
    if (!ACG::SceneGraph::Material::support_json_serialization())
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
        return QStringList();

    QStringList result;
    for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_ALL) ; o_it != objectsEnd(); ++o_it) {

        if (visibleOnly && !o_it->visible()) continue;

        QString materialStr(QObject::tr("<not available>"));
        if (!o_it->materialNode())
            materialStr = QObject::tr("<not available: materialNode == null>");
        else
            materialStr = o_it->materialNode()->material().serializeToJson();

        if (!result.empty())
            result.last().append(QString::fromUtf8(","));
        result.append(QString::fromUtf8("\"%1\": %2").arg(o_it->name()).arg(materialStr));
    }
    return result;
}

1253 1254 1255 1256 1257 1258
void invalidatePickCaches() {
    for(size_t i = 0; i < examiner_widgets_.size(); ++i) {
        examiner_widgets_[i]->invalidatePickCache();
    }
}

Henrik Zimmer's avatar
Henrik Zimmer committed
1259
} // End namespace PluginFunctions