PluginFunctions.cc 39.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52




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

#include <OpenFlipper/common/Types.hh>
53
#include <OpenFlipper/common/GlobalOptions.hh>
54
#include <QGLWidget>
Jan Möbius's avatar
 
Jan Möbius committed
55

56 57 58
#include <../ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <../ObjectTypes/PolyMesh/PolyMesh.hh>

Jan Möbius's avatar
 
Jan Möbius committed
59
#include "PluginFunctions.hh"
Jan Möbius's avatar
 
Jan Möbius committed
60
#include "PluginFunctionsCore.hh"
Jan Möbius's avatar
 
Jan Möbius committed
61 62 63 64 65 66 67

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
68
static BaseObject* objectRoot_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
69 70 71 72 73

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

Dirk Wilden's avatar
Dirk Wilden committed
76 77 78 79 80 81
/** \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
82
/// TODO : Remove this variable and implement multiView correctly here
Jan Möbius's avatar
 
Jan Möbius committed
83
static glViewer*  examiner_widget_;
Jan Möbius's avatar
Jan Möbius committed
84

Jan Möbius's avatar
Docu  
Jan Möbius committed
85
/// Contains the currently active examiner
Jan Möbius's avatar
Jan Möbius committed
86
static unsigned int activeExaminer_ = 0;
Jan Möbius's avatar
 
Jan Möbius committed
87

88 89
static bool internalLightHandling_ = true;

Jan Möbius's avatar
 
Jan Möbius committed
90 91
/** \brief DONT USE DIRECTLY!!
 *
Jan Möbius's avatar
Jan Möbius committed
92 93
 * 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
Jan Möbius's avatar
 
Jan Möbius committed
94 95
 * This pointer is internally used to access the scenegraphs root node
 */
Jan Möbius's avatar
Jan Möbius committed
96 97 98 99 100 101
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;
Jan Möbius's avatar
 
Jan Möbius committed
102

103 104 105 106
/** \brief Scenegraph global nodes root
 */
static SeparatorNode* sceneGraphRootNodeGlobal_ = 0;

Jan Möbius's avatar
Docu  
Jan Möbius committed
107 108
/** \brief Scenegraph root node
 */
Jan Möbius's avatar
Jan Möbius committed
109
static SeparatorNode* sceneGraphRootNode_ = 0;
Dirk Wilden's avatar
Dirk Wilden committed
110

Jan Möbius's avatar
Docu  
Jan Möbius committed
111 112 113
/** \brief a dummy properties object returned as a reference if the real object does not exist
 *
 */
114
static Viewer::ViewerProperties dummyProperties(-1);
Jan Möbius's avatar
 
Jan Möbius committed
115

116 117 118 119 120 121 122

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

123 124 125 126 127 128
/** \brief DONT USE DIRECTLY!!
 *
 * This pointer is used internally
 */
static QGLWidget* shareGLWidget_ = 0;

129 130 131 132
/** This is a unique id for the running OpenFlipper instance. Use it to identify yourself on the network
*/
static int viewerId_ = 0;

133 134 135 136 137 138
/// Number of currently open objects
static int objectCounter_ = 0;

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

139 140 141
/// Map that holds the object handles
static std::map<int, BaseObject*> objectMap_;

142 143 144
/// Map of scenegraph widget generators
QMap< std::string ,ACG::QtWidgets::SceneGraphWidgetGenerator* > sceneGraphGenerators_;

Jan Möbius's avatar
 
Jan Möbius committed
145 146 147 148
void setDataRoot( BaseObject* _root ) {
   objectRoot_ = _root;
}

149 150 151 152
int viewers( ) {
  return examiner_widgets_.size();
}

153 154 155 156 157 158 159 160
void disableExaminerLightHandling() {
  internalLightHandling_ = false;  
}

bool examinerLightHandling() {
  return internalLightHandling_;  
}

161 162 163 164
int viewerId() {
  return viewerId_;
}

165 166
void setViewers( std::vector< glViewer* > _viewerWidgets ) {
   PluginFunctions::examiner_widgets_ = _viewerWidgets;
Jan Möbius's avatar
Jan Möbius committed
167
   PluginFunctions::examiner_widget_ =  examiner_widgets_[0];
168 169 170 171 172

   // 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
173 174
}

Dirk Wilden's avatar
Dirk Wilden committed
175 176 177 178
void setViewerProperties( std::vector< Viewer::ViewerProperties* > _viewerProperties ) {
   PluginFunctions::viewerProperties_ = _viewerProperties;
}

179
void setActiveExaminer( const unsigned int _id ) {
Jan Möbius's avatar
Jan Möbius committed
180
  activeExaminer_ = _id;
Jan Möbius's avatar
 
Jan Möbius committed
181 182
}

183 184 185 186 187 188 189 190 191
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] );
}

192 193 194 195
unsigned int activeExaminer( ) {
  return activeExaminer_;
}

196 197 198 199 200 201
QString getEncodedExaminerView() {
  return getEncodedExaminerView(activeExaminer());
}

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

203
  QString view;
Mike Kremer's avatar
Mike Kremer committed
204

205 206 207 208
  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
209 210
  }

211 212
  examiner_widgets_[_viewerId]->encodeView ( view );
  return view;
Mike Kremer's avatar
Mike Kremer committed
213

214 215 216 217 218 219 220
}

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

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

222 223 224
  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
225 226
  }

227
  examiner_widgets_[_viewerId]->decodeView ( _view );
Mike Kremer's avatar
Mike Kremer committed
228 229
}

Jan Möbius's avatar
Jan Möbius committed
230 231 232
void setDataSeparatorNodes( SeparatorNode* _dataSeparatorNode ) {
  
  // The function should only be called once by the core. 
233

Jan Möbius's avatar
Jan Möbius committed
234 235 236 237 238 239 240 241 242 243 244 245 246
  // 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()) );
  
Jan Möbius's avatar
 
Jan Möbius committed
247 248
}

Jan Möbius's avatar
 
Jan Möbius committed
249
void setSceneGraphRootNode( SeparatorNode* _root_node ) {
Jan Möbius's avatar
Jan Möbius committed
250
   PluginFunctions::sceneGraphRootNode_ = _root_node;
Dirk Wilden's avatar
Dirk Wilden committed
251 252
}

253 254 255 256
void setSceneGraphRootNodeGlobal( SeparatorNode* _root_node ) {
   PluginFunctions::sceneGraphRootNodeGlobal_ = _root_node;
}

Jan Möbius's avatar
 
Jan Möbius committed
257
bool getPickedObject(const unsigned int _node_idx , BaseObjectData*& _object) {
Jan Möbius's avatar
 
Jan Möbius committed
258
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
259 260 261 262 263 264 265 266 267
    if ( o_it->picked( _node_idx ) ) {
      _object = *o_it;
      return true;
    }
  }
  return false;
}


Jan Möbius's avatar
 
Jan Möbius committed
268
bool getSourceIdentifiers( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
269 270
  _identifiers.clear();

Jan Möbius's avatar
 
Jan Möbius committed
271
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
272 273 274
    if ( o_it->source() )
      _identifiers.push_back ( o_it->id() );
  }
275
  return ( ! _identifiers.empty() );
Jan Möbius's avatar
 
Jan Möbius committed
276 277
}

Jan Möbius's avatar
 
Jan Möbius committed
278
bool getTargetIdentifiers( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
279 280
  _identifiers.clear();

Jan Möbius's avatar
 
Jan Möbius committed
281
  for ( ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
282 283 284
    if ( o_it->target() )
      _identifiers.push_back ( o_it->id() );
  }
285
  return ( !_identifiers.empty() );
Jan Möbius's avatar
 
Jan Möbius committed
286 287 288 289 290 291
}

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

Jan Möbius's avatar
 
Jan Möbius committed
292
bool getObject(  const int _identifier , BaseObject*& _object ) {
293

Jan Möbius's avatar
 
Jan Möbius committed
294 295
  if ( _identifier == -1 )
    return false;
296

297 298 299 300 301 302 303 304 305
  // 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);
  
Jan Möbius's avatar
 
Jan Möbius committed
306 307 308
  return ( _object != 0 );
}

Jan Möbius's avatar
 
Jan Möbius committed
309
bool getObject(  const int _identifier , BaseObjectData*& _object ) {
310

Jan Möbius's avatar
 
Jan Möbius committed
311 312
  if ( _identifier == -1 )
    return false;
313

314 315 316 317 318 319 320 321
  // 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);
  
Jan Möbius's avatar
 
Jan Möbius committed
322 323 324 325
  _object = dynamic_cast< BaseObjectData* >(object);
  return ( _object != 0 );
}

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

Jan Möbius's avatar
Jan Möbius committed
329 330
  BaseObject* object = objectRoot_->childExists( _name );
  return object ? object->id() : -1;
331 332
}

Jan Möbius's avatar
 
Jan Möbius committed
333 334 335
// ===============================================================================
// ===============================================================================

336
bool objectExists(  const int _identifier ) {
337

Jan Möbius's avatar
 
Jan Möbius committed
338 339
  if ( _identifier == -1 )
    return false;
340

Jan Möbius's avatar
 
Jan Möbius committed
341 342 343 344 345 346
  BaseObject* object = objectRoot_->childExists( _identifier );
  return ( object != 0 );
}

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

Jan Möbius's avatar
 
Jan Möbius committed
347
bool getAllMeshes( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
348 349 350 351

  _identifiers.clear();

  // find changed manipulator
352
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,typeId("TriangleMesh")) ;
Jan Möbius's avatar
 
Jan Möbius committed
353
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
354 355 356
    _identifiers.push_back( o_it->id() );
  }

357
  return (!_identifiers.empty());
Jan Möbius's avatar
 
Jan Möbius committed
358 359
}

360
bool getAllObjectIdentifiers( std::vector<int>& _identifiers  ) {
Jan Möbius's avatar
 
Jan Möbius committed
361 362 363 364 365

  _identifiers.clear();

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
 
Jan Möbius committed
366
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
367 368 369
    _identifiers.push_back( o_it->id() );
  }

370
  return ( !_identifiers.empty() );
Jan Möbius's avatar
 
Jan Möbius committed
371 372 373
}

void setBackColor( OpenMesh::Vec4f _color) {
374
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
375
    PluginFunctions::viewerProperties(i).backgroundColor(_color);
Jan Möbius's avatar
 
Jan Möbius committed
376 377
}

378 379 380 381 382 383 384 385 386 387
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 );
388
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
389 390 391
      break;
    case VIEW_BOTTOM : //BOTTOM
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
392
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
393 394 395
      break;
    case VIEW_LEFT : //LEFT
      PluginFunctions::viewingDirection( ACG::Vec3d(1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
396
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
397 398 399
      break;
    case VIEW_RIGHT : //RIGHT
      PluginFunctions::viewingDirection( ACG::Vec3d(-1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
400
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
401 402 403
      break;
    case VIEW_FRONT : //FRONT
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, -1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
404
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
405 406 407
      break;
    case VIEW_BACK : //BACK
      PluginFunctions::viewingDirection( ACG::Vec3d(0.0, 0.0, 1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
408
      PluginFunctions::allowRotation(!PluginFunctions::viewerProperties().rotationLocked(), _viewer);
409 410 411 412 413 414 415 416 417 418 419 420
      break;
    default : //Free View
      PluginFunctions::allowRotation(true, _viewer);
      break;
  }

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

421
QPoint mapToGlobal(const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
422
  return examiner_widgets_[activeExaminer_]->glMapToGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
423 424
}

425
QPoint mapToLocal( const QPoint _point ) {
Jan Möbius's avatar
Jan Möbius committed
426
  return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
Jan Möbius's avatar
 
Jan Möbius committed
427 428
}

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

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

Jan Möbius's avatar
 
Jan Möbius committed
441 442 443 444 445 446 447
}

/** 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
448
ACG::SceneGraph::DrawModes::DrawMode drawMode( int _viewer ) {
449
  if ( _viewer == ACTIVE_VIEWER ) {
450
    return viewerProperties(activeExaminer()).drawMode();
451 452 453
  } 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() )
454
    return viewerProperties(_viewer).drawMode();
455 456
  else
    std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
457

458
  return viewerProperties(activeExaminer()).drawMode();
459 460
}

Jan Möbius's avatar
 
Jan Möbius committed
461
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
462 463 464 465

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

Jan Möbius's avatar
 
Jan Möbius committed
466
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
467 468 469 470 471 472

  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
  return examiner_widgets_[_examiner]->pick( _pickTarget,_mousePos,_nodeIdx,_targetIdx,_hitPointPtr );
Jan Möbius's avatar
 
Jan Möbius committed
473 474
}

Henrik Zimmer's avatar
Henrik Zimmer committed
475 476 477
bool scenegraphRegionPick( ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list,
478 479
                           QVector<float>*                            _depths,
                           QVector<ACG::Vec3d>*                       _points)
Henrik Zimmer's avatar
Henrik Zimmer committed
480
{
481
  return examiner_widgets_[activeExaminer_]->pick_region( _pickTarget, _region, _list, _depths, _points);
Henrik Zimmer's avatar
Henrik Zimmer committed
482 483 484 485 486 487
}

bool scenegraphRegionPick( const unsigned int                         _examiner,
                           ACG::SceneGraph::PickTarget                _pickTarget,
                           const QRegion&                             _region,
                           QList<QPair<unsigned int, unsigned int> >& _list,
488 489
                           QVector<float>*                            _depths,
                           QVector<ACG::Vec3d>*                       _points)
Henrik Zimmer's avatar
Henrik Zimmer committed
490 491 492 493 494
{
  if ( _examiner >= examiner_widgets_.size() ) {
    std::cerr << "Wrong examiner id" << std::endl;
    return false;
  }
495
  return examiner_widgets_[_examiner]->pick_region( _pickTarget, _region, _list, _depths, _points);
Henrik Zimmer's avatar
Henrik Zimmer committed
496
}
Jan Möbius's avatar
 
Jan Möbius committed
497 498 499

//Warning : Dont use template function as external static pointer for examiner widget is not resolved correctly!!
void traverse( ACG::SceneGraph::MouseEventAction  &_action ) {
500 501
  // 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.
502
  ACG::SceneGraph::traverse(sceneGraphRootNode_, _action );
Jan Möbius's avatar
 
Jan Möbius committed
503 504
}

505
const std::string pickMode () {
506
  // No seperate draw modes available all should have the same so take first
507
  return viewerProperties().pickMode();
Jan Möbius's avatar
 
Jan Möbius committed
508 509
}

Jan Möbius's avatar
Jan Möbius committed
510
void pickMode ( const std::string& _mode) {
511 512
  // switch to default marker
  setViewObjectMarker (defaultViewObjectMarker ());
513
  viewerProperties().pickMode(_mode);
Jan Möbius's avatar
Jan Möbius committed
514 515
}

516 517
Viewer::ActionMode actionMode() {
   return viewerProperties().actionMode();
Jan Möbius's avatar
 
Jan Möbius committed
518 519
}

Jan Möbius's avatar
 
Jan Möbius committed
520 521
void actionMode ( Viewer::ActionMode _mode) {

522
  viewerProperties().actionMode(_mode);
Jan Möbius's avatar
 
Jan Möbius committed
523 524
}

525 526 527 528 529 530 531 532 533 534
void shareGLWidget (QGLWidget *_widget)
{
  shareGLWidget_ = _widget;
}

QGLWidget *shareGLWidget ()
{
  return shareGLWidget_;
}

Jan Möbius's avatar
 
Jan Möbius committed
535
void getCurrentViewImage(QImage& _image) {
536
  viewer( activeExaminer() )->snapshot( _image );
Jan Möbius's avatar
 
Jan Möbius committed
537 538
}

Jan Möbius's avatar
 
Jan Möbius committed
539
Viewer::ViewerProperties& viewerProperties(int _id) {
Dirk Wilden's avatar
Dirk Wilden committed
540
  if ( _id >= (int)viewerProperties_.size() ) {
Jan Möbius's avatar
 
Jan Möbius committed
541 542 543 544 545 546 547
    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
548
  return ( *viewerProperties_[_id] );
Jan Möbius's avatar
 
Jan Möbius committed
549

Jan Möbius's avatar
 
Jan Möbius committed
550 551
}

Jan Möbius's avatar
Jan Möbius committed
552 553 554 555 556 557 558 559 560 561
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;
Jan Möbius's avatar
 
Jan Möbius committed
562 563
}

Jan Möbius's avatar
Jan Möbius committed
564 565 566 567 568 569 570 571 572 573
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;
Jan Möbius's avatar
 
Jan Möbius committed
574 575
}

576
void setFOVY( double _fovy) {
577
  
578 579 580
  // Set FOVY for all viewers
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
    examiner_widgets_[i]->setFOVY(_fovy);
581 582
}

583 584 585 586 587 588 589 590
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);
591
  else {
592
    std::cerr << "Requested illegal viewer for allowRotation!!" << std::endl;
593 594 595 596 597 598 599
    return;
  }
  
  if ( _viewer == ACTIVE_VIEWER )
    viewerProperties(activeExaminer()).rotationLocked( !_mode );
  else
    viewerProperties( _viewer ).rotationLocked( !_mode );
600 601 602 603 604 605 606 607 608 609 610
}

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;
  }
Jan Möbius's avatar
 
Jan Möbius committed
611 612
}

613 614 615 616
void setMainGLContext() {
  examiner_widget_->makeCurrent();
}

617 618 619 620 621 622 623 624 625 626
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;
Jan Möbius's avatar
 
Jan Möbius committed
627 628
}

629 630 631 632 633 634 635 636 637 638 639 640 641
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
642
const ACG::Vec3d trackBallCenter( int _viewer ) {
643 644 645 646 647 648 649 650 651
  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
652 653

  return examiner_widgets_[activeExaminer_]->trackBallCenter();
654 655 656 657 658 659 660 661 662 663 664 665 666 667
}

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

668 669 670 671 672 673 674 675 676 677
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;
678 679
}

680 681 682 683 684 685 686 687 688 689
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;
Jan Möbius's avatar
 
Jan Möbius committed
690 691
}

692 693
void setSceneCenter(const ACG::Vec3d& _center, int _viewer) {

Jan Möbius's avatar
Jan Möbius committed
694 695 696
  if (_viewer == ACTIVE_VIEWER) {
    examiner_widgets_[activeExaminer_]->setSceneCenter(_center);
  } else if (_viewer == ALL_VIEWERS) {
697

Jan Möbius's avatar
Jan Möbius committed
698 699 700 701 702 703 704 705
    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;
  }
706 707
}

708
const ACG::Vec3d sceneCenter(int _viewer) {
709

Jan Möbius's avatar
Jan Möbius committed
710 711 712 713 714 715 716 717 718 719
  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();
Jan Möbius's avatar
 
Jan Möbius committed
720 721 722
}

double sceneRadius() {
723
   return examiner_widgets_[activeExaminer_]->scene_radius();
Jan Möbius's avatar
 
Jan Möbius committed
724 725
}

726 727 728 729 730 731 732 733 734
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
735

736 737 738
  return -1;
}

739 740 741 742 743 744 745 746 747 748
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;
Jan Möbius's avatar
 
Jan Möbius committed
749 750
}

751
void rotate(const ACG::Vec3d&  _axis,
752
            const double       _angle,
753 754
            const ACG::Vec3d&  _center,
            int                _viewer )
Jan Möbius's avatar
 
Jan Möbius committed
755
{
756 757 758 759 760 761 762 763 764
  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;
Jan Möbius's avatar
 
Jan Möbius committed
765 766
}

767 768 769 770 771 772 773 774 775 776
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;
Jan Möbius's avatar
 
Jan Möbius committed
777 778
}

779 780 781 782 783 784 785 786 787 788
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;
Jan Möbius's avatar
 
Jan Möbius committed
789 790
}

791 792 793 794 795 796 797 798 799 800
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;

801
  return viewerProperties().glState().viewing_direction();
Jan Möbius's avatar
 
Jan Möbius committed
802 803
}

804 805
bool isProjectionOrthographic( int _viewer ) {

806 807 808 809
  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 ?
810 811 812 813 814 815
  } else
    std::cerr << "Requested illegal viewer for isProjectionOrthographic!!" << std::endl;

  return false;
}

816 817 818 819 820 821 822 823 824 825
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;

826
  return viewerProperties().glState().eye();
Jan Möbius's avatar
 
Jan Möbius committed
827 828
}

829 830 831 832 833 834 835 836 837 838
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;

839
  return viewerProperties().glState().up();
Jan Möbius's avatar
 
Jan Möbius committed
840 841
}

842 843
void setViewObjectMarker(ViewObjectMarker * _marker)
{
Jan Möbius's avatar
Jan Möbius committed
844 845
  for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
    PluginFunctions::viewerProperties(i).objectMarker(_marker);
846 847 848 849 850 851 852 853 854 855 856 857 858
}

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

ViewObjectMarker * defaultViewObjectMarker()
{
  return defaultMarker_;
}


Dirk Wilden's avatar
Dirk Wilden committed
859
ACG::SceneGraph::BaseNode* getSceneGraphRootNode() {
Jan Möbius's avatar
Jan Möbius committed
860
   return PluginFunctions::sceneGraphRootNode_;
Dirk Wilden's avatar
Dirk Wilden committed
861 862
}

Jan Möbius's avatar
 
Jan Möbius committed
863
ACG::SceneGraph::BaseNode* getRootNode() {
Jan Möbius's avatar
Jan Möbius committed
864
  return PluginFunctions::dataRootNode_;
Jan Möbius's avatar
 
Jan Möbius committed
865 866
}

867 868 869 870 871 872 873 874 875
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
876
    // move sceneGraphRootNodeGlobal_ to the new parent
877 878 879 880
    sceneGraphRootNodeGlobal_->set_parent(_node);
  }
}

Jan Möbius's avatar
Jan Möbius committed
881 882
void addGlobalNode(ACG::SceneGraph::BaseNode* _node){
  if (PluginFunctions::sceneGraphRootNode_)
883
    _node->set_parent( PluginFunctions::sceneGraphRootNodeGlobal_ );
Dirk Wilden's avatar
Dirk Wilden committed
884 885 886
}


Jan Möbius's avatar
Jan Möbius committed
887 888 889 890 891 892 893 894 895 896 897
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);
Dirk Wilden's avatar
Dirk Wilden committed
898
  }
Jan Möbius's avatar
Jan Möbius committed
899
  
Dirk Wilden's avatar
Dirk Wilden committed
900 901
}

Jan Möbius's avatar
 
Jan Möbius committed
902
int objectCount() {
903
  return(objectCounter_);
Jan Möbius's avatar
 
Jan Möbius committed
904 905 906 907
}



908 909
int targetCount() {
  return ( targetCounter_ );
Jan Möbius's avatar
 
Jan Möbius committed
910 911
}

Jan Möbius's avatar
 
Jan Möbius committed
912
int sourceCount() {
Jan Möbius's avatar
 
Jan Möbius committed
913 914 915 916
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::SOURCE_OBJECTS) ;
Jan Möbius's avatar
 
Jan Möbius committed
917
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
918 919 920 921 922 923
    ++count;
  }

  return ( count );
}

Jan Möbius's avatar
 
Jan Möbius committed
924
int visibleCount() {
Jan Möbius's avatar
 
Jan Möbius committed
925 926 927 928
  int count = 0;

  // find changed manipulator
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
Jan Möbius's avatar
 
Jan Möbius committed
929
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
    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
948
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS,DATA_ALL) ;
Jan Möbius's avatar
 
Jan Möbius committed
949
                                        o_it != PluginFunctions::objectsEnd(); ++o_it)  {
Jan Möbius's avatar
 
Jan Möbius committed
950 951 952 953 954
    _objects.push_back( *o_it );
  }

}

955 956

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

961 962 963 964 965 966 967 968 969 970

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


971 972 973 974 975 976 977 978 979 980 981 982 983 984
/// 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;
}

985 986


Jan Möbius's avatar
 
Jan Möbius committed
987 988 989 990 991 992 993
// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================

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

Jan Möbius's avatar
 
Jan Möbius committed
995 996 997 998 999 1000
  return dynamic_cast< BaseObjectData* >(_object);
}

// ===============================================================================
// Get the root of the object structure
// ===============================================================================
Jan Möbius's avatar
Jan Möbius committed
1001
BaseObject*& objectRoot() {
Jan Möbius's avatar
 
Jan Möbius committed
1002 1003 1004
  return (objectRoot_);
}

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
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;
}

1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
// ===============================================================================
// 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);
Jan Möbius's avatar
 
Jan Möbius committed
1055
}
1056 1057


1058
void addSceneGraphGenerator(ACG::QtWidgets::SceneGraphWidgetGenerator* _generator) {
1059
  
1060
   // Check if we already have a generator for this type.
1061 1062
  if ( sceneGraphGenerators_.contains( _generator->handles() ) ) 
    return;
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072

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


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

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
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,
                        QString * selectedFilter, QFileDialog::Options options) {

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

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
QStringList collectObjectComments(bool visibleOnly, bool targetedOnly) {
    QStringList result;
    for (ObjectIterator o_it(targetedOnly ? TARGET_OBJECTS : ALL_OBJECTS, DATA_TRIANGLE_MESH|DATA_POLY_MESH) ; o_it != objectsEnd(); ++o_it) {

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

        OpenMesh::BaseKernel *mesh = 0;
        {
            TriMeshObject * const triMeshObj = dynamic_cast<TriMeshObject*>(*o_it);
            if (triMeshObj) {
                mesh = triMeshObj->mesh();
            }
            PolyMeshObject * const polyMeshObj = dynamic_cast<PolyMeshObject*>(*o_it);
            if (polyMeshObj) {
                mesh = polyMeshObj->mesh();
            }
        }

        if (mesh) {
            OpenMesh::MPropHandleT<std::string> mp_comment;
            if (mesh->get_property_handle(mp_comment, "COMMENT")) {
                result.append(QString("Object \"%1\" Comment Begin\n%2\nObject \"%1\" Comment End\n")
                              .arg((*o_it)->name())
                              .arg(QString::fromStdString(mesh->property(mp_comment))));
            }
        }
    }
    return result;
}

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