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