Developer Documentation
ViewControlPlugin.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 #include "ViewControlPlugin.hh"
46 #include <OpenFlipper/INIFile/INIFile.hh>
47 
48 #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
49 #include <ACG/Scenegraph/CoordsysNode.hh>
50 
51 #include <QWidgetAction>
52 
53 #define SHOW_SELECTION "Selections"
54 #define SHOW_AREAS "Modeling Areas"
55 #define SHOW_AREA "Modeling Area"
56 #define SHOW_HANDLE "Handle Area"
57 #define SHOW_FEATURES "Feature Selection"
58 #define USEGLOBALDRAWMODE "Use Global DrawMode"
59 #define SETSHADERS "Set Shader"
60 
61 ViewControlPlugin::ViewControlPlugin():
62 viewControlMenu_(0),
63 lastObjectId_(0),
64 shaderWidget_(0),
65 toolbar_(0),
66 toolbarViewingDirections_(0),
67 viewTop_(0),
68 viewBottom_(0),
69 viewLeft_(0),
70 viewRight_(0),
71 viewFront_(0),
72 viewBack_(0)
73 {
74 
75 }
76 
77 void ViewControlPlugin::pluginsInitialized() {
78 
79  // Disable Context Menu for draw Modes
80  OpenFlipper::Options::drawModesInContextMenu(false);
81 
82  // Create a new visualization context menu
83  viewControlMenu_ = new QMenu("Visualization");
84 
85  // Set an icon for the menu
86  QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
87  viewControlMenu_->setIcon(icon);
88 
89  // Add it as context menu for all registered data types
90  for(std::vector<TypeInfo>::const_iterator it = typesBegin(); it != typesEnd(); ++it) {
91  if(it->name == "Unknown" || it->name == "Group" || it->name == "All") continue;
92  emit addContextMenuItem(viewControlMenu_->menuAction(), it->type, CONTEXTOBJECTMENU );
93  }
94 
95  connect( viewControlMenu_, SIGNAL( triggered(QAction*) ), this, SLOT( contextMenuTriggered(QAction*) ));
96 
97  setDescriptions();
98 
99  // Create toolbar
100  toolbar_ = new QToolBar(tr("Viewing Directions"));
101 
102  // Action group for toolbar
103  toolbarViewingDirections_ = new QActionGroup(toolbar_);
104  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
105 
106  // different viewing direction buttons for toolbar
107  viewTop_ = new QAction( QIcon(iconPath + "viewcontrol_top.png"), tr("View from top") , toolbarViewingDirections_);
108  toolbar_->addAction( viewTop_ );
109  viewBottom_ = new QAction( QIcon(iconPath + "viewcontrol_bottom.png"), tr("View from bottom") , toolbarViewingDirections_);
110  toolbar_->addAction( viewBottom_ );
111  viewLeft_ = new QAction( QIcon(iconPath + "viewcontrol_left.png"), tr("View from left") , toolbarViewingDirections_);
112  toolbar_->addAction( viewLeft_ );
113  viewRight_ = new QAction( QIcon(iconPath + "viewcontrol_right.png"), tr("View from right") , toolbarViewingDirections_);
114  toolbar_->addAction( viewRight_ );
115  viewFront_ = new QAction( QIcon(iconPath + "viewcontrol_front.png"), tr("View from front") , toolbarViewingDirections_);
116  toolbar_->addAction( viewFront_ );
117  viewBack_ = new QAction( QIcon(iconPath + "viewcontrol_back.png"), tr("View from back") , toolbarViewingDirections_);
118  toolbar_->addAction( viewBack_ );
119 
120  connect( toolbarViewingDirections_, SIGNAL( triggered(QAction*) ), this, SLOT(setView(QAction*)) );
121 
122  // Add the generated toolbar to the core
123  emit addToolbar(toolbar_);
124 
125 
126 }
127 
128 void ViewControlPlugin::updateShaderList() {
129 
130  //=======================================================================================
131  // Get Shaders
132  //=======================================================================================
133  shaderList_.clear();
134  QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
135 
136  for ( int i = 0 ; i < shadersDirs.size(); ++i ) {
137  ShaderInfo info;
138 
139  QFileInfo descriptionFile(OpenFlipper::Options::shaderDirStr() +
140  OpenFlipper::Options::dirSeparator() +
141  shadersDirs[i] + OpenFlipper::Options::dirSeparator() + "shader.ini" );
142 
143  INIFile ini;
144  if ( !descriptionFile.exists() || !ini.connect( descriptionFile.filePath() ,false ) ) {
145  emit log( LOGWARN, "Unable to open description file for shader " + shadersDirs[i] + " at " + descriptionFile.filePath() );
146 
147  info.description = "Unknown";
148  info.version = "Unknown";
149  info.name = shadersDirs[i];
150  info.details = "----------";
151  info.example = "";
152 
153  } else {
154 
155  QString tmp;
156  if ( ini.get_entry(tmp,"Info","name") )
157  info.name = tmp;
158  else {
159  info.name = shadersDirs[i];
160  emit log( LOGWARN, "Unable to get name from description file for shader " + shadersDirs[i] );
161  }
162 
163  if ( ini.get_entry(tmp,"Info","description") )
164  info.description = tmp;
165  else {
166  info.description = "Unknown";
167  emit log( LOGWARN, "Unable to get shader description from description file for shader " + shadersDirs[i] );
168  }
169 
170  if ( ini.get_entry(tmp,"Info","details") )
171  info.details = tmp;
172  else {
173  info.details = "----------";
174  emit log( LOGWARN, "Unable to get shader details from description file for shader " + shadersDirs[i] );
175  }
176 
177  if ( ini.get_entry(tmp,"Info","version") )
178  info.version = tmp;
179  else {
180  info.version = "Unknown";
181  emit log( LOGWARN, "Unable to get shader version from description file for shader " + shadersDirs[i] );
182  }
183 
184  if ( ini.get_entry(tmp,"Info","example") )
185  info.example = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator() +
186  shadersDirs[i] + OpenFlipper::Options::dirSeparator() + tmp;
187  else {
188  info.example = "";
189  emit log( LOGWARN, "Unable to get example image from Description file for shader " + shadersDirs[i] );
190  }
191 
192  if ( ini.get_entry(tmp,"FragmentShader","file") )
193  info.fragmentShader = tmp;
194  else {
195  info.fragmentShader = "Fragment.glsl";
196  emit log( LOGWARN, "Unable to get fragment shader filename from Description file for shader " + shadersDirs[i] );
197  }
198 
199  if ( ini.get_entry(tmp,"VertexShader","file") )
200  info.vertexShader = tmp;
201  else {
202  info.vertexShader = "Vertex.glsl";
203  emit log( LOGWARN, "Unable to get vertex shader filename from Description file for shader " + shadersDirs[i] );
204  }
205 
206  if ( ini.get_entry(tmp,"PickVertexShader","file") )
207  info.pickVertexShader = tmp;
208  else
209  info.pickVertexShader = "";
210 
211  if ( ini.get_entry(tmp,"PickFragmentShader","file") )
212  info.pickFragmentShader = tmp;
213  else
214  info.pickFragmentShader = "";
215 
216  //uniform names
217  std::vector<QString> uniforms;
218  if ( ini.get_entry(uniforms,"Info","uniforms") ) {
219  info.hasUniforms = true;
220  for ( uint i = 0 ; i < uniforms.size() ; ++i)
221  info.uniforms << uniforms[i];
222  } else {
223  info.hasUniforms = false;
224  info.uniforms.clear();
225  }
226 
227  //unform types
228  uniforms.clear();
229  if ( info.hasUniforms && ini.get_entry(uniforms,"Info","uniformTypes") ) {
230  for ( uint i = 0 ; i < uniforms.size() ; ++i)
231  info.uniformTypes << uniforms[i];
232  } else if ( info.hasUniforms ) {
233  info.hasUniforms = false;
234  info.uniforms.clear();
235  info.uniformTypes.clear();
236  emit log( LOGERR, "Uniforms for shader " + shadersDirs[i] + " defined but no type available, disabled uniforms." );
237  }
238 
239  //uniform default values
240  uniforms.clear();
241  if ( info.hasUniforms && ini.get_entry(uniforms,"Info","uniformsDefault" ) ) {
242  for ( uint i = 0 ; i < uniforms.size() ; ++i)
243  info.uniformsDefault << uniforms[i];
244  } else if ( info.hasUniforms ) {
245  info.hasUniforms = false;
246  info.uniforms.clear();
247  info.uniformTypes.clear();
248  emit log( LOGERR, "Uniforms for shader " + shadersDirs[i] + " defined but no defaults available, disabled uniforms." );
249  }
250  //uniform min values
251  uniforms.clear();
252  if ( info.hasUniforms && ini.get_entry(uniforms,"Info","uniformsMin" ) ) {
253  for ( uint i = 0 ; i < uniforms.size() ; ++i)
254  info.uniformsMin << uniforms[i];
255  } else if ( info.hasUniforms )
256  info.uniformsMin = info.uniformsDefault;
257 
258  //uniform max values
259  uniforms.clear();
260  if ( info.hasUniforms && ini.get_entry(uniforms,"Info","uniformsMax" ) ) {
261  for ( uint i = 0 ; i < uniforms.size() ; ++i)
262  info.uniformsMax << uniforms[i];
263  } else if ( info.hasUniforms )
264  info.uniformsMax = info.uniformsDefault;
265 
266  ini.disconnect();
267  }
268 
269  info.directory = descriptionFile.path();
270 
271  QFileInfo vertexShaderFile( info.directory + OpenFlipper::Options::dirSeparator() + info.vertexShader );
272  if ( !vertexShaderFile.exists() ) {
273  emit log( LOGERR, "Unable to find vertex shader file " + vertexShaderFile.filePath() );
274  continue;
275  }
276 
277  QFileInfo fragmentShaderFile( info.directory + OpenFlipper::Options::dirSeparator() + info.fragmentShader );
278  if ( !fragmentShaderFile.exists() ) {
279  emit log( LOGERR, "Unable to find fragment shader file " + fragmentShaderFile.filePath() );
280  continue;
281  }
282 
283  shaderList_.push_back(info);
284  }
285 
286 }
287 
288 
289 void ViewControlPlugin::contextMenuTriggered(QAction* _action){
290  if ( _action->text() == SHOW_SELECTION) {
291 
292  QVariant contextObject = _action->data();
293  int objectId = contextObject.toInt();
294 
295  if ( objectId == -1)
296  return;
297 
298  showSelection( objectId , !selectionVisible( objectId) );
299 
300  emit updateView();
301  }
302 
303  if ( _action->text() == SHOW_AREAS) {
304 
305  QVariant contextObject = _action->data();
306  int objectId = contextObject.toInt();
307 
308  if ( objectId == -1)
309  return;
310 
311  showModelingAreas( objectId, !modelingAreasVisible(objectId) );
312 
313  emit updateView();
314  }
315 
316  if ( _action->text() == SHOW_AREA) {
317 
318  QVariant contextObject = _action->data();
319  int objectId = contextObject.toInt();
320 
321  if ( objectId == -1)
322  return;
323 
324  showAreas( AREA, objectId, !areasVisible(AREA,objectId) );
325 
326  emit updateView();
327  }
328 
329  if ( _action->text() == SHOW_HANDLE) {
330 
331  QVariant contextObject = _action->data();
332  int objectId = contextObject.toInt();
333 
334  if ( objectId == -1)
335  return;
336 
337  showAreas( HANDLEAREA, objectId, !areasVisible(HANDLEAREA,objectId) );
338 
339  emit updateView();
340  }
341 
342  if ( _action->text() == SHOW_FEATURES) {
343 
344  QVariant contextObject = _action->data();
345  int objectId = contextObject.toInt();
346 
347  if ( objectId == -1)
348  return;
349 
350  BaseObjectData* object = 0;
351  if ( ! PluginFunctions::getObject(objectId,object) )
352  return;
353 
354  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
356  if ( triMeshObject )
357  triMeshObject->hideFeatures( triMeshObject->featuresVisible() );
358  }
359 
360  if ( object->dataType( DATA_POLY_MESH ) ) {
362  if ( polyMeshObject )
363  polyMeshObject->hideFeatures( polyMeshObject->featuresVisible() );
364  }
365 
366  emit updateView();
367 
368  }
369 
370  if ( _action->text() == SETSHADERS ) {
371  if ( shaderWidget_ == 0 ) {
372  shaderWidget_ = new ShaderWidget(0);
373  connect(shaderWidget_->availableShaders,SIGNAL(itemClicked(QListWidgetItem*)),
374  this ,SLOT(slotShaderClicked(QListWidgetItem*)));
375  connect(shaderWidget_->availableShaders,SIGNAL(itemDoubleClicked(QListWidgetItem*)),
376  this ,SLOT(slotShaderDoubleClicked(QListWidgetItem*)));
377 
378  connect(shaderWidget_->setShaderButton,SIGNAL(clicked()),this, SLOT(slotSetShader()));
379  connect(shaderWidget_->closeButton,SIGNAL(clicked()),shaderWidget_, SLOT(close()));
380 
381  connect(shaderWidget_->uniforms, SIGNAL(itemChanged(QTableWidgetItem*)),
382  this, SLOT(itemChanged(QTableWidgetItem*)) );
383  }
384 
385  initShaderWidget();
386 
387  shaderWidget_->show();
388 
389  emit updateView();
390  }
391 
392 }
393 
395  if ( _id == -1)
396  return false;
397 
398  BaseObjectData* object = 0;
399  if ( ! PluginFunctions::getObject(_id,object) )
400  return false;
401 
402  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
403  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
404  if ( triMeshObject )
405  return triMeshObject->selectionVisible();
406  }
407 
408  if ( object->dataType( DATA_POLY_MESH ) ) {
409  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
410  if ( polyMeshObject )
411  return polyMeshObject->selectionVisible();
412  }
413 
414  return false;
415 }
416 
417 bool ViewControlPlugin::areasVisible( StatusBits _bits, int _id ) {
418 
419  if ( _id == -1)
420  return false;
421 
422  BaseObjectData* object = 0;
423  if ( ! PluginFunctions::getObject(_id,object) )
424  return false;
425 
426  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
427  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
428  if ( triMeshObject ) {
429  return triMeshObject->areaVisible( _bits );
430  }
431  }
432 
433  if ( object->dataType( DATA_POLY_MESH ) ) {
434  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
435  if ( polyMeshObject )
436  return( polyMeshObject->areaVisible( _bits ) );
437  }
438 
439  return false;
440 
441 }
442 
444  return areasVisible(StatusBits(HANDLEAREA | AREA), _id);
445 }
446 
447 void ViewControlPlugin::showAreas( StatusBits _bits, int _id , bool _state ) {
448 
449  if ( _id == -1)
450  return;
451 
452  BaseObjectData* object = 0;
453  if ( ! PluginFunctions::getObject(_id,object) )
454  return;
455 
456  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
457  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
458  if ( triMeshObject )
459  triMeshObject->hideArea( _bits, !_state);
460  }
461 
462  if ( object->dataType( DATA_POLY_MESH ) ) {
463  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
464  if ( polyMeshObject )
465  polyMeshObject->hideArea( _bits, !_state);
466  }
467 
468 }
469 
470 void ViewControlPlugin::showModelingAreas( int _id , bool _state ) {
471  showAreas(StatusBits(HANDLEAREA | AREA) , _id, _state );
472 }
473 
474 
475 void ViewControlPlugin::showSelection( int _id , bool _state ) {
476 
477  if ( _id == -1)
478  return;
479 
480  BaseObjectData* object = 0;
481  if ( ! PluginFunctions::getObject(_id,object) )
482  return;
483 
484  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
485  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
486  if ( triMeshObject )
487  triMeshObject->hideSelection( !_state );
488  }
489 
490  if ( object->dataType( DATA_POLY_MESH ) ) {
491  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
492  if ( polyMeshObject )
493  polyMeshObject->hideSelection( !_state );
494  }
495 
496 }
497 
498 void ViewControlPlugin::slotUpdateContextMenu( int _objectId ){
499 
500  viewControlMenu_->clear();
501 
502  lastObjectId_ = _objectId;
503 
504  BaseObjectData* object = 0;
505  if ( !PluginFunctions::getObject( _objectId, object ) ) {
506  emit log(LOGERR,"Unable to create Context Menu ... Unable to get Object");
507  return;
508  }
509 
510  if (object->dataType( DATA_TRIANGLE_MESH ) || object->dataType( DATA_POLY_MESH ) ) {
511 
512  QAction* act;
513  act = viewControlMenu_->addAction( SHOW_SELECTION );
514  act->setCheckable(true);
515 
516  act->setStatusTip( "Switch visualization for selection on/off" );
517  act->setToolTip( "Switch visualization for selection on/off" );
518  act->setWhatsThis( "Switch the visualization of your current selections on and off." );
519 
520  act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"selections.png"));
521 
522  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
523  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
524  if ( triMeshObject )
525  act->setChecked( triMeshObject->selectionVisible() );
526  }
527 
528  if ( object->dataType( DATA_POLY_MESH ) ) {
529  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
530  if ( polyMeshObject )
531  act->setChecked( polyMeshObject->selectionVisible() );
532  }
533 
534  // ============================================
535  // Action for all modeling areas
536  // ============================================
537  act = viewControlMenu_->addAction( SHOW_AREAS );
538  act->setCheckable(true);
539 
540  act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"areaSelections.png"));
541 
542  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
543  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
544  if ( triMeshObject )
545  act->setChecked( triMeshObject->areaVisible( StatusBits(HANDLEAREA | AREA) ) );
546  }
547 
548  if ( object->dataType( DATA_POLY_MESH ) ) {
549  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
550  if ( polyMeshObject )
551  act->setChecked( polyMeshObject->areaVisible( StatusBits(HANDLEAREA | AREA) ) );
552  }
553 
554 
555  // ============================================
556  // Action for handle areas
557  // ============================================
558  act = viewControlMenu_->addAction( SHOW_HANDLE );
559  act->setCheckable(true);
560 
561  act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"handleSelection.png"));
562 
563  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
564  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
565  if ( triMeshObject )
566  act->setChecked( triMeshObject->areaVisible( HANDLEAREA ) );
567  }
568 
569  if ( object->dataType( DATA_POLY_MESH ) ) {
570  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
571  if ( polyMeshObject )
572  act->setChecked( polyMeshObject->areaVisible( HANDLEAREA ) );
573  }
574 
575  // ============================================
576  // Action for modeling areas
577  // ============================================
578  act = viewControlMenu_->addAction( SHOW_AREA );
579  act->setCheckable(true);
580 
581  act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"modelingSelection.png"));
582 
583  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
584  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
585  if ( triMeshObject )
586  act->setChecked( triMeshObject->areaVisible( AREA ) );
587  }
588 
589  if ( object->dataType( DATA_POLY_MESH ) ) {
590  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
591  if ( polyMeshObject )
592  act->setChecked( polyMeshObject->areaVisible( AREA ) );
593  }
594 
595  // ============================================
596  // Action for features
597  // ============================================
598 
599 
600  act = viewControlMenu_->addAction( SHOW_FEATURES );
601  act->setCheckable(true);
602 
603  act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"featureSelections.png"));
604 
605  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
606  TriMeshObject* triMeshObject = PluginFunctions::triMeshObject( object );
607  if ( triMeshObject )
608  act->setChecked( triMeshObject->featuresVisible() );
609  }
610 
611  if ( object->dataType( DATA_POLY_MESH ) ) {
612  PolyMeshObject* polyMeshObject = PluginFunctions::polyMeshObject( object );
613  if ( polyMeshObject )
614  act->setChecked( polyMeshObject->featuresVisible() );
615  }
616 
617 
618  }
619 
620  // If this Object has a shader Node, allow settings for the shader
621  if ( object->shaderNode() ) {
622  viewControlMenu_->addSeparator();
623 
624  QAction* act = viewControlMenu_->addAction( SETSHADERS );
625  act->setCheckable( false );
626  }
627 
628  viewControlMenu_->addSeparator();
629 
630  QActionGroup * globalDrawActionsGroup = new QActionGroup( this );
631 
632  QAction * action = new QAction( USEGLOBALDRAWMODE , globalDrawActionsGroup );
633  action->setCheckable( false );
634 
635  viewControlMenu_->addActions(globalDrawActionsGroup->actions());
636 
637  connect( globalDrawActionsGroup, SIGNAL( triggered( QAction * ) ),
638  this , SLOT( slotDrawModeSelected( QAction * ) ) );
639 
640  QActionGroup * drawGroup = new QActionGroup( this );
641  drawGroup->setExclusive( false );
642 
643  // Collect available draw Modes for this object
645  ACG::SceneGraph::traverse( object->primaryNode() , actionAvailable);
646  availDrawModes_ = actionAvailable.drawModes();
647 
648  // Collect available draw Modes for this object
650  ACG::SceneGraph::traverse( object->primaryNode() , actionActive);
651  activeDrawModes_ = actionActive.drawMode();
652 
653  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
654  availDrawModeIds = availDrawModes_.getAtomicDrawModes();
655 
657 
658  const bool containsGlobalDM = activeDrawModes_ == ACG::SceneGraph::DrawModes::DEFAULT;
659 
660  activeCheckboxes.clear();
661  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
662  {
663  ACG::SceneGraph::DrawModes::DrawMode id = availDrawModeIds[i];
664  std::string descr = id.description();
665 
666  QCheckBox *checkBox = new QCheckBox(QString(descr.c_str()), viewControlMenu_);
667  activeCheckboxes[checkBox] = id;
668  if (activeDrawModes_.containsAtomicDrawMode(id))
669  checkBox->setCheckState(Qt::Checked);
670  else if (containsGlobalDM && globalDrawModes.containsAtomicDrawMode(id))
671  checkBox->setCheckState(Qt::PartiallyChecked);
672  else
673  checkBox->setCheckState(Qt::Unchecked);
674  QWidgetAction *checkableAction = new QWidgetAction(drawGroup);
675  checkableAction->setText(descr.c_str());
676  checkableAction->setDefaultWidget(checkBox);
677  connect(checkBox, SIGNAL( stateChanged(int) ), checkableAction, SLOT(trigger() ) );
678  }
679 
680  viewControlMenu_->addActions( drawGroup->actions() );
681 
682  connect( drawGroup, SIGNAL( triggered( QAction * ) ),
683  this, SLOT( slotDrawModeSelected( QAction * ) ) );
684 
685 }
686 
687 void ViewControlPlugin::slotDrawModeSelected( QAction * _action) {
688 
689  QWidgetAction * const wdgtAction = dynamic_cast<QWidgetAction*>(_action);
690  QCheckBox * const checkbox = wdgtAction ? dynamic_cast<QCheckBox*>(wdgtAction->defaultWidget()) : 0;
691  const bool activateDrawMode = checkbox ? (checkbox->checkState() != Qt::Unchecked) : false;
692 
693  //======================================================================================
694  // Get the mode toggled
695  //======================================================================================
697  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
698  availDrawModeIds = availDrawModes_.getAtomicDrawModes();
699  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
700  {
701  QString descr = QString( availDrawModeIds[i].description().c_str() );
702 
703  if ( descr == _action->text() ) {
704  mode = availDrawModeIds[i];
705  break;
706  }
707  }
708 
709  //======================================================================================
710  // possibly combine draw modes
711  //======================================================================================
712  bool useGlobalDrawMode = false;
713  bool contextMenuStaysOpen = false;
714  if ( _action->text() != USEGLOBALDRAWMODE ) {
715 
716  // extract global draw mode in case we want to combine it with another draw mode
717  if(activeDrawModes_ == ACG::SceneGraph::DrawModes::DEFAULT) {
719  activeDrawModes_.combine(widgetDrawMode);
720  }
721 
722  // As this is not the global draw mode, filter out default as draw mode or it will interfere with the other modes!
723  activeDrawModes_.filter(ACG::SceneGraph::DrawModes::DEFAULT);
724 
725  // If shift is pressed, we combine the modes (and toggle therefore xor)
726  // Otherwise we directly take the new mode
727  if ( qApp->keyboardModifiers() & Qt::ShiftModifier ) {
728  if (activateDrawMode) {
729  activeDrawModes_.combine(mode); // explicit call to combine() states intent more clearly
730  } else {
731  if (activeDrawModes_ == mode) {
732  activeDrawModes_ = ACG::SceneGraph::DrawModes::DEFAULT;
733  useGlobalDrawMode = true;
734  } else {
735  activeDrawModes_.filter(mode);
736  }
737  }
738  contextMenuStaysOpen = true;
739  } else {
740  if (activateDrawMode) {
741  activeDrawModes_ = mode ;
742  } else {
743  activeDrawModes_ = ACG::SceneGraph::DrawModes::DEFAULT;
744  useGlobalDrawMode = true;
745  }
746  emit hideContextMenu();
747  }
748 
749  if (activeDrawModes_ == ACG::SceneGraph::DrawModes::DEFAULT) {
750  useGlobalDrawMode = true;
751  }
752 
753  } else {
754  // Switch back to global drawmode-> default
755  activeDrawModes_ = ACG::SceneGraph::DrawModes::DEFAULT;
756  useGlobalDrawMode = true;
757  }
758 
759  if (contextMenuStaysOpen) {
760  typedef std::map<QCheckBox*, ACG::SceneGraph::DrawModes::DrawMode> CBM;
762  for (CBM::iterator it = activeCheckboxes.begin(), it_end = activeCheckboxes.end(); it != it_end; ++it) {
763  it->first->blockSignals(true);
764  if (activeDrawModes_.containsAtomicDrawMode(it->second)) {
765  it->first->setCheckState(Qt::Checked);
766  } else if (useGlobalDrawMode && globalDrawModes.containsAtomicDrawMode(it->second)) {
767  it->first->setCheckState(Qt::PartiallyChecked);
768  } else {
769  it->first->setCheckState(Qt::Unchecked);
770  }
771  it->first->blockSignals(false);
772  }
773  }
774 
775  //======================================================================================
776  // Now do the update in the sceneGraph
777  //======================================================================================
778 
779  // Get the associated object
780  BaseObjectData* object = 0;
781  PluginFunctions::getObject( lastObjectId_, object );
782 
783  // Set draw Modes for this object ( force it when we do not set the global draw mode, to override global draw mode and force the modes on the nodes )
784  ACG::SceneGraph::SetDrawModesAction actionActive( activeDrawModes_ , !useGlobalDrawMode );
785 
786 
787  if ( object )
788  ACG::SceneGraph::traverse( object->primaryNode() , actionActive);
789  else
791 
792  emit updateView();
793 }
794 
795 void ViewControlPlugin::initShaderWidget(){
796 
797  //update the shader list
798 
799  updateShaderList();
800 
801  shaderWidget_->availableShaders->clear();
802 
803  for ( uint i = 0 ; i < shaderList_.size(); ++i ) {
804  shaderWidget_->availableShaders->addItem( shaderList_[i].name );
805  }
806 
807  shaderWidget_->availableShaders->setCurrentRow(0);
808  slotShaderClicked(shaderWidget_->availableShaders->currentItem());
809 
810 }
811 
812 void ViewControlPlugin::slotShaderClicked( QListWidgetItem * _item ){
813  int index = -1;
814  for ( int i = 0 ; i < (int)shaderList_.size(); ++i) {
815  if ( shaderList_[i].name == _item->text() ) {
816  index = i;
817  break;
818  }
819  }
820 
821  if ( index == -1 ) {
822  std::cerr << "Strange index Error! " << std::endl;
823  return;
824  }
825 
826  shaderWidget_->shaderName->setText( shaderList_[index].name );
827  shaderWidget_->description->setText( shaderList_[index].description );
828  shaderWidget_->details->setText( shaderList_[index].details );
829  shaderWidget_->version->setText( shaderList_[index].version );
830  shaderWidget_->vertexShader->setText( shaderList_[index].vertexShader );
831  shaderWidget_->fragmentShader->setText( shaderList_[index].fragmentShader );
832  shaderWidget_->pickVertexShader->setText( shaderList_[index].pickVertexShader );
833  shaderWidget_->pickFragmentShader->setText( shaderList_[index].pickFragmentShader );
834  shaderWidget_->example->setPixmap( QPixmap(shaderList_[index].example) );
835 
836  //get shader paths
837  QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
838  QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
839 
840  QString vertexFile = shaderDir + shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
841  OpenFlipper::Options::dirSeparator() + shaderWidget_->vertexShader->text();
842  QString fragmentFile = shaderDir + shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
843  OpenFlipper::Options::dirSeparator() + shaderWidget_->fragmentShader->text();
844 
845  //update drawMode checkStates
846  shaderWidget_->drawModes->clear();
847 
848  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
849  availDrawModeIds = availDrawModes_.getAtomicDrawModes( );
850 
851  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
852  {
853  ACG::SceneGraph::DrawModes::DrawMode id = availDrawModeIds[i];
854 
855 
856  std::vector< QString > dm = drawModeToDescriptions( id );
857 
858  if ( !dm.empty() && dm[0].trimmed() != ""){
859  QListWidgetItem* item = new QListWidgetItem(dm[0]);
860 
861  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
862 
863  BaseObjectData* object = 0;
864 
865  PluginFunctions::getObject( lastObjectId_, object );
866  if ( object && object->shaderNode() ){
867  if ( object->shaderNode()->vertexShaderName( id ) == vertexFile.toStdString() &&
868  object->shaderNode()->fragmentShaderName( id ) == fragmentFile.toStdString() )
869  item->setCheckState( Qt::Checked );
870  else
871  {
872  //std::cerr << "vertex:" << object->shaderNode()->vertexShaderName( id ) << ", this: " << vertexFile.toStdString() << std::endl;
873  //std::cerr << "fragment:" << object->shaderNode()->fragmentShaderName( id ) << ", this: " << fragmentFile.toStdString() << std::endl;
874  item->setCheckState( Qt::Unchecked );
875  }
876  }
877  shaderWidget_->drawModes->addItem(item);
878  }
879  }
880 
881  if ( shaderList_[index].hasUniforms ) {
882  //set up uniform table
883  shaderWidget_->uniforms->clear();
884  shaderWidget_->uniforms->setColumnCount ( 1 );
885  shaderWidget_->uniforms->setRowCount ( shaderList_[index].uniforms.count() );
886 
887  shaderWidget_->uniforms->setHorizontalHeaderLabels( QStringList("Value") );
888  shaderWidget_->uniforms->setVerticalHeaderLabels( shaderList_[index].uniforms );
889 
890  for (int i=0; i < shaderList_[index].uniforms.count(); i++){
891  QTableWidgetItem* item = new QTableWidgetItem( shaderList_[index].uniformsDefault[i] );
892  item->setFlags( Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
893  shaderWidget_->uniforms->setItem(i,0,item );
894  }
895 
896  shaderWidget_->uniformBox->setVisible( true );
897 
898  }else
899  shaderWidget_->uniformBox->setVisible( false );
900 
901  emit updateView();
902 }
903 
904 void ViewControlPlugin::slotShaderDoubleClicked( QListWidgetItem * /*_item*/ ){
905 // slotSetShader();
906 }
907 
908 void ViewControlPlugin::itemChanged(QTableWidgetItem* item){
909 
910  //get current shader index
911  int index = -1;
912  for ( int i = 0 ; i < (int)shaderList_.size(); ++i) {
913  if ( shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text() ) {
914  index = i;
915  break;
916  }
917  }
918 
919  if ( index == -1 ) {
920  std::cerr << "Error: Shader Index not found! " << std::endl;
921  return;
922  }
923 
924 
925  int row = item->row();
926 
927  if ( row > shaderList_[index].uniforms.count() ){
928  std::cerr << "Error: uniform index out of bounds" << std::endl;
929  return;
930  }
931 
932  //handle different datatypes
933  if (shaderList_[index].uniformTypes[row] == "float"){
934  bool ok;
935 
936  float value = item->text().toFloat(&ok);
937 
938  if (!ok)
939  item->setText( shaderList_[index].uniformsDefault[row] );
940  else if (shaderList_[index].uniformsDefault[row] != shaderList_[index].uniformsMin[row]
941  && value < shaderList_[index].uniformsMin[row].toFloat())
942  item->setText( shaderList_[index].uniformsMin[row] );
943  else if (shaderList_[index].uniformsDefault[row] != shaderList_[index].uniformsMin[row]
944  && value > shaderList_[index].uniformsMax[row].toFloat())
945  item->setText( shaderList_[index].uniformsMax[row] );
946  }
947 
948 }
949 
950 void ViewControlPlugin::slotSetShader()
951 {
952 
953  //get current shader index
954  int index = -1;
955  for (int i = 0; i < (int) shaderList_.size(); ++i) {
956  if (shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text()) {
957  index = i;
958  break;
959  }
960  }
961 
962  if (index == -1) {
963  std::cerr << "Error: Shader Index not found! " << std::endl;
964  return;
965  }
966 
967  std::vector<QString> mode;
968  for (int i = 0; i < shaderWidget_->drawModes->count(); i++) {
969  if (shaderWidget_->drawModes->item(i)->checkState() == Qt::Checked) {
970  mode.push_back(shaderWidget_->drawModes->item(i)->text());
971  setShader(lastObjectId_, descriptionsToDrawMode(mode), shaderList_[index]);
972  mode.clear();
973  } else {
974  mode.push_back(shaderWidget_->drawModes->item(i)->text());
975  disableShader(lastObjectId_, descriptionsToDrawMode(mode), &shaderList_[index]);
976  mode.clear();
977  }
978  }
979 }
980 
982  int _objectId,
984  ShaderInfo* _shader)
985 {
986 
987  BaseObjectData* object = 0;
988  PluginFunctions::getObject(_objectId, object);
989 
990  if (object) {
991  if (!_shader)
992  object->shaderNode()->disableShader(_drawMode);
993  else {
994  std::string shadeDir = _shader->directory.toStdString() + OpenFlipper::Options::dirSeparator().toStdString();
995 
996  if (object->shaderNode()->vertexShaderName(_drawMode) == shadeDir + _shader->vertexShader.toStdString()
997  && object->shaderNode()->fragmentShaderName(_drawMode) == shadeDir + _shader->fragmentShader.toStdString())
998  object->shaderNode()->disableShader(_drawMode);
999  }
1000  }
1001 
1002  emit updateView();
1003 }
1004 
1006 
1007  if ( OpenFlipper::Options::nogui() )
1008  return;
1009 
1010  BaseObjectData* object = 0;
1011  PluginFunctions::getObject( _id, object );
1012 
1013  //get shader paths
1014  QFileInfo vertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.vertexShader);
1015  QFileInfo fragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.fragmentShader);
1016  QFileInfo pickVertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickVertexShader);
1017  QFileInfo pickFragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickFragmentShader);
1018 
1019  if ( object && object->shaderNode()
1020  && _shader.vertexShader.length() && _shader.fragmentShader.length()) {
1021 
1022  if (vertexFile.absolutePath() != fragmentFile.absolutePath()) {
1023  emit log(LOGERR, "Cannot set shader. Currently shader files have to be in the same folder.");
1024  return;
1025  }
1026 
1027  if (_shader.pickVertexShader.length() && _shader.pickFragmentShader.length())
1028  {
1029  if (vertexFile.absolutePath() != pickVertexFile.absolutePath() ||
1030  vertexFile.absolutePath() != pickFragmentFile.absolutePath()) {
1031  emit log(LOGERR, "Cannot set picking shader. Currently shader files have to be in the same folder.");
1032  return;
1033  }
1034 
1035  object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1036 
1037  object->shaderNode()->setShader(_drawMode,
1038  vertexFile.fileName().toStdString(),
1039  fragmentFile.fileName().toStdString(),
1040  pickVertexFile.fileName().toStdString(),
1041  pickFragmentFile.fileName().toStdString());
1042  }
1043  else
1044  {
1045  object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1046  object->shaderNode()->setShader(_drawMode, vertexFile.fileName().toStdString(), fragmentFile.fileName().toStdString());
1047  }
1048  }
1049 
1050 
1051  // set uniforms if available
1052  if (_shader.hasUniforms) {
1053  GLSL::PtrProgram shader = object->shaderNode()->getShader( _drawMode );
1054  if ( shader == 0 ) {
1055  std::cerr << "Error: Unable to get shader for shader mode" << std::endl;
1056  } else {
1057  shader->use();
1058 
1059  for (int u=0; u < _shader.uniforms.count(); u++) {
1060  //float uniforms
1061  if (_shader.uniformTypes[u] == "float" ) {
1062  shaderWidget_->uniforms->setCurrentCell(u,0);
1063  float value = shaderWidget_->uniforms->currentItem()->text().toFloat();
1064  shader->setUniform(_shader.uniforms[u].toUtf8(), value);
1065  } else
1066  //vec3 uniforms
1067  if (_shader.uniformTypes[u] == "vec3" ) {
1068  shaderWidget_->uniforms->setCurrentCell(u,0);
1069  QStringList vecStr = shaderWidget_->uniforms->currentItem()->text().split(",");
1070  if (vecStr.count() == 3) {
1071  ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
1072  shader->setUniform(_shader.uniforms[u].toUtf8(), value);
1073  }
1074  } else
1075  std::cerr << "Error: handling of uniformType '" << _shader.uniformTypes[u].toStdString() << "' not yet implemented" << std::endl;
1076 
1077  }
1078 
1079  shader->disable();
1080  }
1081  }
1082 
1083  emit updateView();
1084 }
1085 
1086 void ViewControlPlugin::setShader(int _id, QString _drawMode, QString _name ){
1087 
1088  if ( OpenFlipper::Options::nogui() )
1089  return;
1090 
1091  updateShaderList();
1092 
1093  //get current shader index
1094  int index = -1;
1095  for ( int i = 0 ; i < (int)shaderList_.size(); ++i) {
1096  if ( shaderList_[i].name == _name ) {
1097  index = i;
1098  break;
1099  }
1100  }
1101 
1102  if ( index == -1 ) {
1103  std::cerr << "Error: Shader not found! " << std::endl;
1104  return;
1105  }
1106 
1107  std::vector <QString> mode;
1108  mode.push_back(_drawMode);
1109 
1110  setShader(_id, listToDrawMode(mode), shaderList_[index]);
1111 }
1112 
1113 //-----------------------------------------------------------------------------
1114 
1115 QStringList ViewControlPlugin::getUniforms(QString _shader){
1116  for (uint i=0; i < shaderList_.size(); i++)
1117  if ( shaderList_[i].name == _shader)
1118  return shaderList_[i].uniforms;
1119 
1120  return QStringList();
1121 }
1122 
1123 QString ViewControlPlugin::getUniformType(QString _shader, QString _uniform ){
1124 
1125  for (uint i=0; i < shaderList_.size(); i++)
1126  if ( shaderList_[i].name == _shader){
1127 
1128  for (int u=0; u < shaderList_[i].uniforms.count(); u++)
1129  if ( shaderList_[i].uniforms[u] == _uniform )
1130  return shaderList_[i].uniformTypes[u];
1131  }
1132 
1133  return QString();
1134 }
1135 
1136 QString ViewControlPlugin::getUniformDefault(QString _shader, QString _uniform ){
1137 
1138  for (uint i=0; i < shaderList_.size(); i++)
1139  if ( shaderList_[i].name == _shader){
1140 
1141  for (int u=0; u < shaderList_[i].uniforms.count(); u++)
1142  if ( shaderList_[i].uniforms[u] == _uniform )
1143  return shaderList_[i].uniformsDefault[u];
1144  }
1145 
1146  return QString();
1147 }
1148 
1149 QString ViewControlPlugin::getUniformMin(QString _shader, QString _uniform ){
1150 
1151  for (uint i=0; i < shaderList_.size(); i++)
1152  if ( shaderList_[i].name == _shader){
1153 
1154  for (int u=0; u < shaderList_[i].uniforms.count(); u++)
1155  if ( shaderList_[i].uniforms[u] == _uniform )
1156  return shaderList_[i].uniformsMin[u];
1157  }
1158 
1159  return QString();
1160 }
1161 
1162 QString ViewControlPlugin::getUniformMax(QString _shader, QString _uniform ){
1163 
1164  for (uint i=0; i < shaderList_.size(); i++)
1165  if ( shaderList_[i].name == _shader){
1166 
1167  for (int u=0; u < shaderList_[i].uniforms.count(); u++)
1168  if ( shaderList_[i].uniforms[u] == _uniform )
1169  return shaderList_[i].uniformsMax[u];
1170  }
1171 
1172  return QString();
1173 }
1174 
1175 //-----------------------------------------------------------------------------
1176 
1178 void ViewControlPlugin::setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value ){
1179 
1180  BaseObjectData* object = 0;
1181 
1182  PluginFunctions::getObject( _objID, object );
1183  if ( object && object->shaderNode() ){
1184 
1185  for (uint i=0; i < shaderList_.size(); i++)
1186  if ( shaderList_[i].name == _shader){
1187 
1188  // set uniforms if available
1189  if (shaderList_[i].hasUniforms){
1190  GLSL::PtrProgram shader = object->shaderNode()->getShader( _drawMode );
1191  if ( shader == 0 ) {
1192  std::cerr << "Error: Unable to get shader for shader mode" << std::endl;
1193  } else {
1194  shader->use();
1195 
1196  for (int u=0; u < shaderList_[i].uniforms.count(); u++){
1197 
1198  //only apply to uniform which was given as param
1199  if ( shaderList_[i].uniforms[u] != _uniform )
1200  continue;
1201 
1202  //float uniforms
1203  if (shaderList_[i].uniformTypes[u] == "float" )
1204  shader->setUniform(shaderList_[i].uniforms[u].toUtf8(), _value.toFloat() );
1205 
1206  //vec3 uniforms
1207  else if (shaderList_[i].uniformTypes[u] == "vec3" ){
1208  QStringList vecStr = _value.split(",");
1209  if (vecStr.count() == 3){
1210  ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
1211  shader->setUniform(shaderList_[i].uniforms[u].toUtf8(), value);
1212  }
1213  }else
1214  std::cerr << "Error: handling of uniformType '" << shaderList_[i].uniformTypes[u].toStdString() << "' not yet implemented" << std::endl;
1215  }
1216 
1217  shader->disable();
1218  }
1219  }
1220  }
1221  }
1222 }
1223 
1224 //-----------------------------------------------------------------------------
1225 
1226 void ViewControlPlugin::setViewingDirection( Vector _direction, Vector _upvector , int _viewer){
1227  PluginFunctions::viewingDirection(_direction, _upvector, _viewer);
1228 }
1229 
1230 //-----------------------------------------------------------------------------
1231 
1232 void ViewControlPlugin::setSceneRadius( double _radius , int _viewer){
1233  PluginFunctions::setSceneRadius(_radius, _viewer);
1234 }
1235 
1236 //-----------------------------------------------------------------------------
1237 
1238 void ViewControlPlugin::rotate( Vector _axis, double _angle, Vector _center , int _viewer) {
1239  PluginFunctions::rotate( _axis, _angle, _center ,_viewer);
1240 }
1241 
1242 //-----------------------------------------------------------------------------
1243 
1244 void ViewControlPlugin::translate( Vector _vec , int _viewer) {
1245  PluginFunctions::translate( _vec ,_viewer);
1246 }
1247 
1248 
1249 void ViewControlPlugin::enableBackfaceCulling( bool _state , int _viewer ) {
1250  if ( _viewer == PluginFunctions::ALL_VIEWERS )
1251  for ( int i = 0 ; i < PluginFunctions::viewers( ); ++i )
1253  else if ( _viewer == PluginFunctions::ACTIVE_VIEWER )
1255  else if ( _viewer >= 0 && _viewer < PluginFunctions::viewers( ) )
1257  else
1258  std::cerr << "Illegal viewer requested! " << std::endl;
1259 
1260 }
1261 
1262 
1263 //-----------------------------------------------------------------------------
1264 
1265 void
1266 ViewControlPlugin::setDrawMode(QString _mode, int _viewer)
1267 {
1268 
1269  QStringList list = _mode.split(';');
1270 
1271  std::vector< QString > drawModeList;
1272 
1273  for ( int i = 0 ; i < list.size() ; ++i )
1274  drawModeList.push_back(list[i]);
1275 
1276  ACG::SceneGraph::DrawModes::DrawMode mode = listToDrawMode(drawModeList);
1277 
1278  PluginFunctions::setDrawMode( mode , _viewer );
1279  emit updateView();
1280 }
1281 
1282 //-----------------------------------------------------------------------------
1283 
1284 void
1285 ViewControlPlugin::setObjectDrawMode(QString _mode, int _objectID, bool _force)
1286 {
1287  BaseObjectData* object = 0;
1288  PluginFunctions::getObject( _objectID, object );
1289 
1290  QStringList list = _mode.split(';');
1291 
1292  std::vector< QString > drawModeList;
1293 
1294  for ( int i = 0 ; i < list.size() ; ++i )
1295  drawModeList.push_back(list[i]);
1296 
1297  ACG::SceneGraph::DrawModes::DrawMode mode = listToDrawMode(drawModeList);
1298 
1299  // Set draw Modes for this object ( force it when we do not set the global draw mode, to override global draw mode and force the modes on the nodes )
1300  ACG::SceneGraph::SetDrawModesAction actionActive( mode , _force );
1301 
1302  if ( object )
1303  ACG::SceneGraph::traverse( object->primaryNode() , actionActive);
1304 }
1305 
1306 //-----------------------------------------------------------------------------
1307 
1309  return PluginFunctions::viewingDirection(_viewer);
1310 }
1311 
1313  return PluginFunctions::upVector(_viewer);
1314 }
1315 
1317  return PluginFunctions::eyePos(_viewer);
1318 }
1319 
1320 void ViewControlPlugin::setSceneCenter( Vector _center, int _viewer ) {
1321  PluginFunctions::setScenePos(_center, _viewer);
1322 }
1323 
1325  return PluginFunctions::sceneCenter(_viewer);
1326 }
1327 
1328 //-----------------------------------------------------------------------------
1329 
1330 void ViewControlPlugin::setView(int _mode, int _viewer ) {
1331 
1332  switch ( _mode ){
1333  case PluginFunctions::VIEW_TOP : //TOP
1334  setViewingDirection( ACG::Vec3d(0.0, -1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
1335  break;
1336  case PluginFunctions::VIEW_BOTTOM : //BOTTOM
1337  setViewingDirection( ACG::Vec3d(0.0, 1.0, 0.0), ACG::Vec3d(0.0, 0.0, -1.0), _viewer );
1338  break;
1339  case PluginFunctions::VIEW_LEFT : //LEFT
1340  setViewingDirection( ACG::Vec3d(1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
1341  break;
1342  case PluginFunctions::VIEW_RIGHT : //RIGHT
1343  setViewingDirection( ACG::Vec3d(-1.0, 0.0, 0.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
1344  break;
1345  case PluginFunctions::VIEW_FRONT : //FRONT
1346  setViewingDirection( ACG::Vec3d(0.0, 0.0, -1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
1347  break;
1348  case PluginFunctions::VIEW_BACK : //BACK
1349  setViewingDirection( ACG::Vec3d(0.0, 0.0, 1.0), ACG::Vec3d(0.0, 1.0, 0.0), _viewer );
1350  break;
1351  default :
1352  emit log(LOGERR, "ViewControl: Unknown view mode: " + QString::number(_mode));
1353  break;
1354  }
1355 
1356  updateView();
1357 }
1358 
1359 //-----------------------------------------------------------------------------
1360 
1361 void ViewControlPlugin::setView(QAction* _action) {
1362 
1363  if ( _action == viewTop_) setView (PluginFunctions::VIEW_TOP, PluginFunctions::ACTIVE_VIEWER);
1364  else if ( _action == viewBottom_) setView (PluginFunctions::VIEW_BOTTOM, PluginFunctions::ACTIVE_VIEWER);
1365  else if ( _action == viewLeft_) setView (PluginFunctions::VIEW_LEFT, PluginFunctions::ACTIVE_VIEWER);
1366  else if ( _action == viewRight_) setView (PluginFunctions::VIEW_RIGHT, PluginFunctions::ACTIVE_VIEWER);
1367  else if ( _action == viewFront_) setView (PluginFunctions::VIEW_FRONT, PluginFunctions::ACTIVE_VIEWER);
1368  else if ( _action == viewBack_) setView (PluginFunctions::VIEW_BACK, PluginFunctions::ACTIVE_VIEWER);
1369  else emit log(LOGERR, "ViewControl: Unknown view mode action!");
1370 }
1371 
1372 //-----------------------------------------------------------------------------
1373 
1374 void ViewControlPlugin::setEyePosition(Vector _eye){
1376  PluginFunctions::sceneCenter(PluginFunctions::ACTIVE_VIEWER),
1377  PluginFunctions::upVector(PluginFunctions::ACTIVE_VIEWER),
1378  PluginFunctions::ACTIVE_VIEWER);
1379 }
1380 
1381 
1384 }
1385 
1386 void ViewControlPlugin::viewAll(int _viewer) {
1387  PluginFunctions::viewAll(_viewer);
1388 }
1389 
1392 }
1393 
1394 void ViewControlPlugin::viewHome(int _viewer) {
1395  PluginFunctions::viewHome(_viewer);
1396 }
1397 
1400 }
1401 
1404 }
1405 
1406 
1409 }
1410 
1413 }
1414 
1415 void ViewControlPlugin::setFOVY( double _fovy ) {
1416  PluginFunctions::setFOVY(_fovy);
1417 
1418  emit updateView();
1419 }
1420 
1422 
1423  // Find coordsys node
1424  ACG::SceneGraph::BaseNode* node = 0;
1425  node = PluginFunctions::getSceneGraphRootNode()->find("Core Coordsys Node");
1426  if (node != 0) {
1427  ACG::SceneGraph::CoordsysNode* cnode = dynamic_cast<ACG::SceneGraph::CoordsysNode*> (node);
1429  if ( _orthogonal) {
1431  emit updateView();
1432  }
1433  } else {
1434  if ( !_orthogonal) {
1436  emit updateView();
1437  }
1438  }
1439 
1440  } else {
1441  emit log(LOGERR,tr("setCoordsysProjection(): Could not find coordsys node, thus its projection mode will not be toggled."));
1442  }
1443 
1444 }
1445 
1446 void ViewControlPlugin::setTwoSidedLighting(bool _enabled) {
1448 }
1449 
1450 
1451 void ViewControlPlugin::setDescriptions() {
1452  emit setSlotDescription("translate(Vector,int)", "Translate Scene",
1453  QString("TranslationVector,Viewer").split(","),
1454  QString("vector for the translation.,Viewer id (default is all)").split(","));
1455  emit setSlotDescription("translate(Vector)", "Translate Scene in all Viewers",
1456  QString("TranslationVector").split(","),
1457  QString("vector for the translation.").split(","));
1458  emit setSlotDescription("rotate(Vector,double,Vector,int)", "Rotate Scene",
1459  QString("Axis,Angle,Center,Viewer").split(","),
1460  QString("Rotation axis., Rotation Angle., Rotation Center.").split(","));
1461  emit setSlotDescription("rotate(Vector,double,Vector)", "Rotate Scene in all viewers",
1462  QString("Axis,Angle,Center").split(","),
1463  QString("Rotation axis., Rotation Angle., Rotation Center.").split(","));
1464  emit setSlotDescription("setViewingDirection(Vector,Vector,int)", "Set the viewing direction",
1465  QString("direction,upVector,Viewer").split(","),
1466  QString("Viewing direction., Up-Vector.,Viewer id (default is all)").split(","));
1467  emit setSlotDescription("setViewingDirection(Vector,Vector)", "Set the viewing direction in all viewers",
1468  QString("direction,upVector").split(","),
1469  QString("Viewing direction., Up-Vector.").split(","));
1470  emit setSlotDescription("setDrawMode(QString,int)", "Set the drawMode",
1471  QString("DrawMode,Viewer").split(","),
1472  QString("the drawMode ( ; separated list ),Viewer id (default is all)").split(","));
1473  emit setSlotDescription("setDrawMode(QString)", "Set the drawMode for all viewers",
1474 
1475  QStringList("DrawMode"), QStringList("the drawMode ( ; separated list )"));
1476 
1477  emit setSlotDescription("setObjectDrawMode(QString,int,bool)", "Set the drawMode for an object",
1478  QString("DrawMode,ObjectID,Force").split(","),
1479  QString("the drawMode ( ; separated list ),Object id,Apply without checking support(default is true)").split(","));
1480 
1481  emit setSlotDescription("viewAll()", "Change View on all viewers to view whole scene",
1482  QStringList(), QStringList());
1483  emit setSlotDescription("viewAll(int)", "Change View on given viewer to view whole scene",
1484  QStringList("Viewer"), QStringList("Id of the viewer to change"));
1485 
1486  emit setSlotDescription("viewHome()", "Change View on all viewers to view home position",
1487  QStringList(), QStringList());
1488  emit setSlotDescription("viewHome(int)", "Change View on given viewer to view home position",
1489  QStringList("Viewer"), QStringList("Id of the viewer to change"));
1490 
1491 
1492  emit setSlotDescription("orthographicProjection()", "Change Viewer to orthographic projection",
1493  QStringList(), QStringList());
1494  emit setSlotDescription("orthographicProjection(int)", "Change all Viewers to orthographic projection",
1495  QStringList("Viewer"), QStringList("Id of the viewer to change"));
1496 
1497 
1498  emit setSlotDescription("perspectiveProjection()", "Change Viewer to perspective projection",
1499  QStringList(), QStringList());
1500  emit setSlotDescription("perspectiveProjection(int)", "Change all Viewers to perspective projection",
1501  QStringList("Viewer"), QStringList("Id of the viewer to change"));
1502 
1503  emit setSlotDescription("setFOVY(double)", "Set fovy angle of projection for all viewers.",
1504  QStringList("fovy"), QStringList("FOVY angle"));
1505 
1506  emit setSlotDescription("setCoordsysProjection(bool)", "Set the projection mode of the coordinate system.",
1507  QStringList("orthogonal"), QStringList("If true, orthogonal projection otherwise perspective projection"));
1508 
1509  emit setSlotDescription("upVector()", "Get the current upVector.",
1510  QStringList(), QStringList());
1511 
1512  emit setSlotDescription("upVector(int)", "Get the current upVector of a specific viewer.",
1513  QStringList("ViewerId"), QStringList("Id of the viewer"));
1514 
1515  emit setSlotDescription("eyePosition()", "Get the current eyePosition.",
1516  QStringList(), QStringList());
1517 
1518  emit setSlotDescription("eyePosition(int)", "Get the current eyePosition of a specific viewer.",
1519  QStringList("ViewerId"), QStringList("Id of the viewer"));
1520 
1521  emit setSlotDescription("sceneCenter()", "Get the current sceneCenter.",
1522  QStringList(), QStringList());
1523 
1524  emit setSlotDescription("sceneCenter(int)", "Get the current sceneCenter of a specific viewer.",
1525  QStringList("ViewerId"), QStringList("Id of the viewer"));
1526 
1527  emit setSlotDescription("viewingDirection()", "Get the current viewingDirection.",
1528  QStringList(), QStringList());
1529 
1530  emit setSlotDescription("viewingDirection(int)", "Get the current viewingDirection of a specific viewer.",
1531  QStringList("ViewerId"), QStringList("Id of the viewer"));
1532 
1533  emit setSlotDescription("setTwoSidedLighting(bool)", "Enable or disable two sided lighting.",
1534  QStringList("enabled"), QStringList("Specifies whether to enable or disable two sided lighting."));
1535 
1536 }
1537 
1538 
1539 
DLLEXPORT std::vector< TypeInfo >::const_iterator typesEnd()
Get iterator pointing to the last element in the types list.
Definition: Types.cc:185
void setSceneRadius(double _radius, int _viewer=PluginFunctions::ALL_VIEWERS)
Set scene radius.
void setSceneRadius(double _radius, int _viewer)
Set the background color of the examiner widget.
const ACG::Vec3d sceneCenter(int _viewer)
Get the current scene center.
virtual BaseNode * primaryNode()
#define DATA_POLY_MESH
Definition: PolyMesh.hh:59
bool areaVisible(StatusBits _bit)
Return if the selected areas are currently visible.
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
void orthographicProjection()
Change Viewer to orthographicProjection.
Vector upVector(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers up vector
void viewHome()
Change View on given Viewer to view home position.
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
void setCoordsysProjection(bool _orthogonal)
void enableBackfaceCulling(bool _state, int _viewer=PluginFunctions::ALL_VIEWERS)
Enable or disable Backface culling.
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
Definition: SceneGraph.hh:613
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
Vector eyePosition(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers eye Position
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
void setViewingDirection(Vector _direction, Vector _upvector, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the viewing direction.
DLLEXPORT std::vector< TypeInfo >::const_iterator typesBegin()
Get iterator pointing to the first element in the types list.
Definition: Types.cc:180
Vector viewingDirection(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get a viewers viewing direction.
QStringList getUniforms(QString _shader)
get information about available uniforms for a given shader
void twoSidedLighting(bool _state)
set 2-sided lighting on/off
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
Definition: SceneGraph.hh:582
void viewHome(int _viewer)
Go to home position.
void perspectiveProjection()
Change Viewer to perspectiveProjection.
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
bool dataType(DataType _type) const
Definition: BaseObject.cc:221
void translate(Vector _vec, int _viewer=PluginFunctions::ALL_VIEWERS)
translate Scene
void disable()
Resets to standard rendering pipeline.
Definition: GLSLShader.cc:355
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Definition: INIFile.cc:70
int viewers()
Get the number of viewers.
GLSL program class.
Definition: GLSLShader.hh:211
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
bool modelingAreasVisible(int _id)
For meshes returns if the modeling areas for this object is visible.
void disableShader(DrawModes::DrawMode _drawmode)
Definition: ShaderNode.cc:262
DrawMode DEFAULT
use the default (global) draw mode and not the node&#39;s own.
Definition: DrawModes.cc:72
ProjectionMode getProjectionMode() const
get current projection mode
void setFOVY(double _fovy)
Set field of view angle.
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:67
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void viewAll()
Change View on all viewers to view whole scene.
void setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value)
set the value of a uniform in a shader for a specific drawMode
void translate(const ACG::Vec3d &_vector, int _viewer)
Translate viewer pos by given vector.
void showModelingAreas(int _id, bool _state)
Allows to enable/disable visualization of the objects modeling area for meshes.
void showSelection(int _id, bool _state)
Allows to enable/disable visualization of the objects selection for meshes.
void hideArea(StatusBits _bit, bool _hide)
Hide or show the area Nodes of the object.
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:346
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
void setFOVY(double _fovy)
Set fovy angle of projection.
bool backFaceCulling()
Get current state of backface culling.
bool selectionVisible(int _id)
For meshes returns if the selection for this object is visible.
void viewAll(int _viewer)
View the whole scene.
Vector sceneCenter(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get the scene center.
void filter(DrawMode _filter)
filter out one drawmode
Definition: DrawModes.cc:463
void setScenePos(const ACG::Vec3d &_center, const double _radius, int _viewer)
Set the Scene position.
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:137
bool selectionVisible()
return if the selections are currently visible
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
void rotate(Vector _axis, double _angle, Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Rotate Scene.
void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader)
void setSceneCenter(Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the scene center.
bool featuresVisible()
return if the feature Node of the object is currently visible
void rotate(const ACG::Vec3d &_axis, const double _angle, const ACG::Vec3d &_center, int _viewer)
Rotate Scene around axis.
bool areasVisible(StatusBits _bits, int _id)
Return of all of the given modeling areas are visible.
void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo *_shader=0)
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
void setObjectDrawMode(QString _mode, int _objectID, bool _force=true)
Set the draw mode for an object.
#define DATA_TRIANGLE_MESH
Definition: TriangleMesh.hh:60
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
Definition: DrawModes.cc:520
void disconnect()
Remove connection of this object to a file.
Definition: INIFile.cc:122
void showAreas(StatusBits _bits, int _id, bool _state)
Show or hide modeling areas.
The Menu will be shown when an object was picked.
Type for a Meshobject containing a poly mesh.
Definition: PolyMesh.hh:65
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Definition: GLSLShader.cc:385
void setDrawMode(QString _mode, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the draw mode for a viewer.
void use()
Enables the program object for using.
Definition: GLSLShader.cc:345
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
virtual ACG::SceneGraph::ShaderNode * shaderNode()
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
void lookAt(const ACG::Vec3d &_eye, const ACG::Vec3d &_center, const ACG::Vec3d &_up, int _viewer)
Set the look at transformation directly.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
Definition: INIFile.cc:433