45 #include "ViewControlPlugin.hh" 46 #include <OpenFlipper/INIFile/INIFile.hh> 48 #include <OpenFlipper/ACGHelper/DrawModeConverter.hh> 49 #include <ACG/Scenegraph/CoordsysNode.hh> 51 #include <QWidgetAction> 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" 61 ViewControlPlugin::ViewControlPlugin():
66 toolbarViewingDirections_(0),
77 void ViewControlPlugin::pluginsInitialized() {
80 OpenFlipper::Options::drawModesInContextMenu(
false);
83 viewControlMenu_ =
new QMenu(
"Visualization");
86 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"drawModes.png");
87 viewControlMenu_->setIcon(icon);
91 if(it->name ==
"Unknown" || it->name ==
"Group" || it->name ==
"All")
continue;
92 emit addContextMenuItem(viewControlMenu_->menuAction(), it->type,
CONTEXTOBJECTMENU );
95 connect( viewControlMenu_, SIGNAL( triggered(QAction*) ),
this, SLOT( contextMenuTriggered(QAction*) ));
100 toolbar_ =
new QToolBar(tr(
"Viewing Directions"));
103 toolbarViewingDirections_ =
new QActionGroup(toolbar_);
104 QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
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_ );
120 connect( toolbarViewingDirections_, SIGNAL( triggered(QAction*) ),
this, SLOT(setView(QAction*)) );
123 emit addToolbar(toolbar_);
128 void ViewControlPlugin::updateShaderList() {
134 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
136 for (
int i = 0 ; i < shadersDirs.size(); ++i ) {
139 QFileInfo descriptionFile(OpenFlipper::Options::shaderDirStr() +
140 OpenFlipper::Options::dirSeparator() +
141 shadersDirs[i] + OpenFlipper::Options::dirSeparator() +
"shader.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() );
147 info.description =
"Unknown";
148 info.version =
"Unknown";
149 info.name = shadersDirs[i];
150 info.details =
"----------";
159 info.name = shadersDirs[i];
160 emit log(
LOGWARN,
"Unable to get name from description file for shader " + shadersDirs[i] );
163 if ( ini.
get_entry(tmp,
"Info",
"description") )
164 info.description = tmp;
166 info.description =
"Unknown";
167 emit log(
LOGWARN,
"Unable to get shader description from description file for shader " + shadersDirs[i] );
170 if ( ini.
get_entry(tmp,
"Info",
"details") )
173 info.details =
"----------";
174 emit log(
LOGWARN,
"Unable to get shader details from description file for shader " + shadersDirs[i] );
177 if ( ini.
get_entry(tmp,
"Info",
"version") )
180 info.version =
"Unknown";
181 emit log(
LOGWARN,
"Unable to get shader version from description file for shader " + shadersDirs[i] );
184 if ( ini.
get_entry(tmp,
"Info",
"example") )
185 info.example = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator() +
186 shadersDirs[i] + OpenFlipper::Options::dirSeparator() + tmp;
189 emit log(
LOGWARN,
"Unable to get example image from Description file for shader " + shadersDirs[i] );
192 if ( ini.
get_entry(tmp,
"FragmentShader",
"file") )
193 info.fragmentShader = tmp;
195 info.fragmentShader =
"Fragment.glsl";
196 emit log(
LOGWARN,
"Unable to get fragment shader filename from Description file for shader " + shadersDirs[i] );
199 if ( ini.
get_entry(tmp,
"VertexShader",
"file") )
200 info.vertexShader = tmp;
202 info.vertexShader =
"Vertex.glsl";
203 emit log(
LOGWARN,
"Unable to get vertex shader filename from Description file for shader " + shadersDirs[i] );
206 if ( ini.
get_entry(tmp,
"PickVertexShader",
"file") )
207 info.pickVertexShader = tmp;
209 info.pickVertexShader =
"";
211 if ( ini.
get_entry(tmp,
"PickFragmentShader",
"file") )
212 info.pickFragmentShader = tmp;
214 info.pickFragmentShader =
"";
217 std::vector<QString> uniforms;
218 if ( ini.
get_entry(uniforms,
"Info",
"uniforms") ) {
219 info.hasUniforms =
true;
220 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
221 info.uniforms << uniforms[uniform];
223 info.hasUniforms =
false;
224 info.uniforms.clear();
229 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformTypes") ) {
230 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
231 info.uniformTypes << uniforms[uniform];
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." );
241 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsDefault" ) ) {
242 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
243 info.uniformsDefault << uniforms[uniform];
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." );
252 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsMin" ) ) {
253 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
254 info.uniformsMin << uniforms[uniform];
255 }
else if ( info.hasUniforms )
256 info.uniformsMin = info.uniformsDefault;
260 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsMax" ) ) {
261 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
262 info.uniformsMax << uniforms[uniform];
263 }
else if ( info.hasUniforms )
264 info.uniformsMax = info.uniformsDefault;
269 info.directory = descriptionFile.path();
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() );
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() );
283 shaderList_.push_back(info);
289 void ViewControlPlugin::contextMenuTriggered(QAction* _action){
290 if ( _action->text() == SHOW_SELECTION) {
292 QVariant contextObject = _action->data();
293 int objectId = contextObject.toInt();
298 showSelection( objectId , !selectionVisible( objectId) );
303 if ( _action->text() == SHOW_AREAS) {
305 QVariant contextObject = _action->data();
306 int objectId = contextObject.toInt();
311 showModelingAreas( objectId, !modelingAreasVisible(objectId) );
316 if ( _action->text() == SHOW_AREA) {
318 QVariant contextObject = _action->data();
319 int objectId = contextObject.toInt();
324 showAreas( AREA, objectId, !areasVisible(AREA,objectId) );
329 if ( _action->text() == SHOW_HANDLE) {
331 QVariant contextObject = _action->data();
332 int objectId = contextObject.toInt();
337 showAreas( HANDLEAREA, objectId, !areasVisible(HANDLEAREA,objectId) );
342 if ( _action->text() == SHOW_FEATURES) {
344 QVariant contextObject = _action->data();
345 int objectId = contextObject.toInt();
362 if ( polyMeshObject )
370 if ( _action->text() == SETSHADERS ) {
371 if ( 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*)));
378 connect(shaderWidget_->setShaderButton,SIGNAL(clicked()),
this, SLOT(slotSetShader()));
379 connect(shaderWidget_->closeButton,SIGNAL(clicked()),shaderWidget_, SLOT(close()));
381 connect(shaderWidget_->uniforms, SIGNAL(itemChanged(QTableWidgetItem*)),
382 this, SLOT(itemChanged(QTableWidgetItem*)) );
387 shaderWidget_->show();
410 if ( polyMeshObject )
428 if ( triMeshObject ) {
435 if ( polyMeshObject )
444 return areasVisible(StatusBits(HANDLEAREA | AREA), _id);
459 triMeshObject->
hideArea( _bits, !_state);
464 if ( polyMeshObject )
465 polyMeshObject->
hideArea( _bits, !_state);
471 showAreas(StatusBits(HANDLEAREA | AREA) , _id, _state );
492 if ( polyMeshObject )
498 void ViewControlPlugin::slotUpdateContextMenu(
int _objectId ){
500 viewControlMenu_->clear();
502 lastObjectId_ = _objectId;
506 emit log(
LOGERR,
"Unable to create Context Menu ... Unable to get Object");
513 act = viewControlMenu_->addAction( SHOW_SELECTION );
514 act->setCheckable(
true);
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." );
520 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"selections.png"));
530 if ( polyMeshObject )
537 act = viewControlMenu_->addAction( SHOW_AREAS );
538 act->setCheckable(
true);
540 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"areaSelections.png"));
545 act->setChecked( triMeshObject->
areaVisible( StatusBits(HANDLEAREA | AREA) ) );
550 if ( polyMeshObject )
551 act->setChecked( polyMeshObject->
areaVisible( StatusBits(HANDLEAREA | AREA) ) );
558 act = viewControlMenu_->addAction( SHOW_HANDLE );
559 act->setCheckable(
true);
561 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"handleSelection.png"));
566 act->setChecked( triMeshObject->
areaVisible( HANDLEAREA ) );
571 if ( polyMeshObject )
572 act->setChecked( polyMeshObject->
areaVisible( HANDLEAREA ) );
578 act = viewControlMenu_->addAction( SHOW_AREA );
579 act->setCheckable(
true);
581 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"modelingSelection.png"));
586 act->setChecked( triMeshObject->
areaVisible( AREA ) );
591 if ( polyMeshObject )
592 act->setChecked( polyMeshObject->
areaVisible( AREA ) );
600 act = viewControlMenu_->addAction( SHOW_FEATURES );
601 act->setCheckable(
true);
603 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"featureSelections.png"));
613 if ( polyMeshObject )
622 viewControlMenu_->addSeparator();
624 QAction* act = viewControlMenu_->addAction( SETSHADERS );
625 act->setCheckable(
false );
628 viewControlMenu_->addSeparator();
630 QActionGroup * globalDrawActionsGroup =
new QActionGroup(
this );
632 QAction * action =
new QAction( USEGLOBALDRAWMODE , globalDrawActionsGroup );
633 action->setCheckable(
false );
635 viewControlMenu_->addActions(globalDrawActionsGroup->actions());
637 connect( globalDrawActionsGroup, SIGNAL( triggered( QAction * ) ),
638 this , SLOT( slotDrawModeSelected( QAction * ) ) );
640 QActionGroup * drawGroup =
new QActionGroup(
this );
641 drawGroup->setExclusive(
false );
646 availDrawModes_ = actionAvailable.
drawModes();
651 activeDrawModes_ = actionActive.
drawMode();
653 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
654 availDrawModeIds = availDrawModes_.getAtomicDrawModes();
660 activeCheckboxes.clear();
661 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
664 std::string descr =
id.description();
666 QCheckBox *checkBox =
new QCheckBox(QString(descr.c_str()), viewControlMenu_);
667 activeCheckboxes[checkBox] = id;
668 if (activeDrawModes_.containsAtomicDrawMode(
id))
669 checkBox->setCheckState(Qt::Checked);
671 checkBox->setCheckState(Qt::PartiallyChecked);
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() ) );
680 viewControlMenu_->addActions( drawGroup->actions() );
682 connect( drawGroup, SIGNAL( triggered( QAction * ) ),
683 this, SLOT( slotDrawModeSelected( QAction * ) ) );
687 void ViewControlPlugin::slotDrawModeSelected( QAction * _action) {
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;
697 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
698 availDrawModeIds = availDrawModes_.getAtomicDrawModes();
699 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
701 QString descr = QString( availDrawModeIds[i].description().c_str() );
703 if ( descr == _action->text() ) {
704 mode = availDrawModeIds[i];
712 bool useGlobalDrawMode =
false;
713 bool contextMenuStaysOpen =
false;
714 if ( _action->text() != USEGLOBALDRAWMODE ) {
719 activeDrawModes_.combine(widgetDrawMode);
727 if ( qApp->keyboardModifiers() & Qt::ShiftModifier ) {
728 if (activateDrawMode) {
729 activeDrawModes_.combine(mode);
731 if (activeDrawModes_ == mode) {
733 useGlobalDrawMode =
true;
735 activeDrawModes_.
filter(mode);
738 contextMenuStaysOpen =
true;
740 if (activateDrawMode) {
741 activeDrawModes_ = mode ;
744 useGlobalDrawMode =
true;
746 emit hideContextMenu();
750 useGlobalDrawMode =
true;
756 useGlobalDrawMode =
true;
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);
767 it->first->setCheckState(Qt::PartiallyChecked);
769 it->first->setCheckState(Qt::Unchecked);
771 it->first->blockSignals(
false);
795 void ViewControlPlugin::initShaderWidget(){
801 shaderWidget_->availableShaders->clear();
803 for ( uint i = 0 ; i < shaderList_.size(); ++i ) {
804 shaderWidget_->availableShaders->addItem( shaderList_[i].name );
807 shaderWidget_->availableShaders->setCurrentRow(0);
808 slotShaderClicked(shaderWidget_->availableShaders->currentItem());
812 void ViewControlPlugin::slotShaderClicked( QListWidgetItem * _item ){
814 for (
int i = 0 ; i < (int)shaderList_.size(); ++i) {
815 if ( shaderList_[i].name == _item->text() ) {
822 std::cerr <<
"Strange index Error! " << std::endl;
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) );
837 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
838 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
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();
846 shaderWidget_->drawModes->clear();
848 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
849 availDrawModeIds = availDrawModes_.getAtomicDrawModes( );
851 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
856 std::vector< QString > dm = drawModeToDescriptions(
id );
858 if ( !dm.empty() && dm[0].trimmed() !=
""){
859 QListWidgetItem* item =
new QListWidgetItem(dm[0]);
861 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
867 if ( object->
shaderNode()->vertexShaderName(
id ) == vertexFile.toStdString() &&
868 object->shaderNode()->fragmentShaderName(
id ) == fragmentFile.toStdString() )
869 item->setCheckState( Qt::Checked );
874 item->setCheckState( Qt::Unchecked );
877 shaderWidget_->drawModes->addItem(item);
881 if ( shaderList_[index].hasUniforms ) {
883 shaderWidget_->uniforms->clear();
884 shaderWidget_->uniforms->setColumnCount ( 1 );
885 shaderWidget_->uniforms->setRowCount ( shaderList_[index].uniforms.count() );
887 shaderWidget_->uniforms->setHorizontalHeaderLabels( QStringList(
"Value") );
888 shaderWidget_->uniforms->setVerticalHeaderLabels( shaderList_[index].uniforms );
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 );
896 shaderWidget_->uniformBox->setVisible(
true );
899 shaderWidget_->uniformBox->setVisible(
false );
904 void ViewControlPlugin::slotShaderDoubleClicked( QListWidgetItem * ){
908 void ViewControlPlugin::itemChanged(QTableWidgetItem* item){
912 for (
int i = 0 ; i < (int)shaderList_.size(); ++i) {
913 if ( shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text() ) {
920 std::cerr <<
"Error: Shader Index not found! " << std::endl;
925 int row = item->row();
927 if ( row > shaderList_[index].uniforms.count() ){
928 std::cerr <<
"Error: uniform index out of bounds" << std::endl;
933 if (shaderList_[index].uniformTypes[row] ==
"float"){
936 float value = item->text().toFloat(&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] );
950 void ViewControlPlugin::slotSetShader()
955 for (
int i = 0; i < (int) shaderList_.size(); ++i) {
956 if (shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text()) {
963 std::cerr <<
"Error: Shader Index not found! " << std::endl;
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]);
974 mode.push_back(shaderWidget_->drawModes->item(i)->text());
975 disableShader(lastObjectId_, descriptionsToDrawMode(mode), &shaderList_[index]);
992 object->shaderNode()->disableShader(_drawMode);
994 std::string shadeDir = _shader->directory.toStdString() + OpenFlipper::Options::dirSeparator().toStdString();
996 if (object->
shaderNode()->vertexShaderName(_drawMode) == shadeDir + _shader->vertexShader.toStdString()
997 &&
object->shaderNode()->fragmentShaderName(_drawMode) == shadeDir + _shader->fragmentShader.toStdString())
1007 if ( OpenFlipper::Options::nogui() )
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);
1020 && _shader.vertexShader.length() && _shader.fragmentShader.length()) {
1022 if (vertexFile.absolutePath() != fragmentFile.absolutePath()) {
1023 emit log(
LOGERR,
"Cannot set shader. Currently shader files have to be in the same folder.");
1027 if (_shader.pickVertexShader.length() && _shader.pickFragmentShader.length())
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.");
1035 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1037 object->shaderNode()->setShader(_drawMode,
1038 vertexFile.fileName().toStdString(),
1039 fragmentFile.fileName().toStdString(),
1040 pickVertexFile.fileName().toStdString(),
1041 pickFragmentFile.fileName().toStdString());
1045 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1046 object->shaderNode()->setShader(_drawMode, vertexFile.fileName().toStdString(), fragmentFile.fileName().toStdString());
1052 if (_shader.hasUniforms) {
1054 if ( shader == 0 ) {
1055 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1059 for (
int u=0; u < _shader.uniforms.count(); u++) {
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);
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);
1075 std::cerr <<
"Error: handling of uniformType '" << _shader.uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1088 if ( OpenFlipper::Options::nogui() )
1095 for (
int i = 0 ; i < (int)shaderList_.size(); ++i) {
1096 if ( shaderList_[i].name == _name ) {
1102 if ( index == -1 ) {
1103 std::cerr <<
"Error: Shader not found! " << std::endl;
1107 std::vector <QString> mode;
1108 mode.push_back(_drawMode);
1110 setShader(_id, listToDrawMode(mode), shaderList_[index]);
1116 for (uint i=0; i < shaderList_.size(); i++)
1117 if ( shaderList_[i].name == _shader)
1118 return shaderList_[i].uniforms;
1120 return QStringList();
1123 QString ViewControlPlugin::getUniformType(QString _shader, QString _uniform ){
1125 for (uint i=0; i < shaderList_.size(); i++)
1126 if ( shaderList_[i].name == _shader){
1128 for (
int u=0; u < shaderList_[i].uniforms.count(); u++)
1129 if ( shaderList_[i].uniforms[u] == _uniform )
1130 return shaderList_[i].uniformTypes[u];
1136 QString ViewControlPlugin::getUniformDefault(QString _shader, QString _uniform ){
1138 for (uint i=0; i < shaderList_.size(); i++)
1139 if ( shaderList_[i].name == _shader){
1141 for (
int u=0; u < shaderList_[i].uniforms.count(); u++)
1142 if ( shaderList_[i].uniforms[u] == _uniform )
1143 return shaderList_[i].uniformsDefault[u];
1149 QString ViewControlPlugin::getUniformMin(QString _shader, QString _uniform ){
1151 for (uint i=0; i < shaderList_.size(); i++)
1152 if ( shaderList_[i].name == _shader){
1154 for (
int u=0; u < shaderList_[i].uniforms.count(); u++)
1155 if ( shaderList_[i].uniforms[u] == _uniform )
1156 return shaderList_[i].uniformsMin[u];
1162 QString ViewControlPlugin::getUniformMax(QString _shader, QString _uniform ){
1164 for (uint i=0; i < shaderList_.size(); i++)
1165 if ( shaderList_[i].name == _shader){
1167 for (
int u=0; u < shaderList_[i].uniforms.count(); u++)
1168 if ( shaderList_[i].uniforms[u] == _uniform )
1169 return shaderList_[i].uniformsMax[u];
1185 for (uint i=0; i < shaderList_.size(); i++)
1186 if ( shaderList_[i].name == _shader){
1189 if (shaderList_[i].hasUniforms){
1191 if ( shader == 0 ) {
1192 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1196 for (
int u=0; u < shaderList_[i].uniforms.count(); u++){
1199 if ( shaderList_[i].uniforms[u] != _uniform )
1203 if (shaderList_[i].uniformTypes[u] ==
"float" )
1204 shader->
setUniform(shaderList_[i].uniforms[u].toUtf8(), _value.toFloat() );
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);
1214 std::cerr <<
"Error: handling of uniformType '" << shaderList_[i].uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1250 if ( _viewer == PluginFunctions::ALL_VIEWERS )
1253 else if ( _viewer == PluginFunctions::ACTIVE_VIEWER )
1255 else if ( _viewer >= 0 && _viewer < PluginFunctions::viewers( ) )
1258 std::cerr <<
"Illegal viewer requested! " << std::endl;
1269 QStringList list = _mode.split(
';');
1271 std::vector< QString > drawModeList;
1273 for (
int i = 0 ; i < list.size() ; ++i )
1274 drawModeList.push_back(list[i]);
1290 QStringList list = _mode.split(
';');
1292 std::vector< QString > drawModeList;
1294 for (
int i = 0 ; i < list.size() ; ++i )
1295 drawModeList.push_back(list[i]);
1330 void ViewControlPlugin::setView(
int _mode,
int _viewer ) {
1333 case PluginFunctions::VIEW_TOP :
1336 case PluginFunctions::VIEW_BOTTOM :
1339 case PluginFunctions::VIEW_LEFT :
1342 case PluginFunctions::VIEW_RIGHT :
1345 case PluginFunctions::VIEW_FRONT :
1348 case PluginFunctions::VIEW_BACK :
1352 emit log(
LOGERR,
"ViewControl: Unknown view mode: " + QString::number(_mode));
1361 void ViewControlPlugin::setView(QAction* _action) {
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!");
1374 void ViewControlPlugin::setEyePosition(
Vector _eye){
1378 PluginFunctions::ACTIVE_VIEWER);
1434 if ( !_orthogonal) {
1441 emit log(
LOGERR,tr(
"setCoordsysProjection(): Could not find coordsys node, thus its projection mode will not be toggled."));
1446 void ViewControlPlugin::setTwoSidedLighting(
bool _enabled) {
1455 void ViewControlPlugin::setDescriptions() {
1456 emit setSlotDescription(
"translate(Vector,int)",
"Translate Scene",
1457 QString(
"TranslationVector,Viewer").split(
","),
1458 QString(
"vector for the translation.,Viewer id (default is all)").split(
","));
1459 emit setSlotDescription(
"translate(Vector)",
"Translate Scene in all Viewers",
1460 QString(
"TranslationVector").split(
","),
1461 QString(
"vector for the translation.").split(
","));
1462 emit setSlotDescription(
"rotate(Vector,double,Vector,int)",
"Rotate Scene",
1463 QString(
"Axis,Angle,Center,Viewer").split(
","),
1464 QString(
"Rotation axis., Rotation Angle., Rotation Center.").split(
","));
1465 emit setSlotDescription(
"rotate(Vector,double,Vector)",
"Rotate Scene in all viewers",
1466 QString(
"Axis,Angle,Center").split(
","),
1467 QString(
"Rotation axis., Rotation Angle., Rotation Center.").split(
","));
1468 emit setSlotDescription(
"setViewingDirection(Vector,Vector,int)",
"Set the viewing direction",
1469 QString(
"direction,upVector,Viewer").split(
","),
1470 QString(
"Viewing direction., Up-Vector.,Viewer id (default is all)").split(
","));
1471 emit setSlotDescription(
"setViewingDirection(Vector,Vector)",
"Set the viewing direction in all viewers",
1472 QString(
"direction,upVector").split(
","),
1473 QString(
"Viewing direction., Up-Vector.").split(
","));
1474 emit setSlotDescription(
"setDrawMode(QString,int)",
"Set the drawMode",
1475 QString(
"DrawMode,Viewer").split(
","),
1476 QString(
"the drawMode ( ; separated list ),Viewer id (default is all)").split(
","));
1477 emit setSlotDescription(
"setDrawMode(QString)",
"Set the drawMode for all viewers",
1479 QStringList(
"DrawMode"), QStringList(
"the drawMode ( ; separated list )"));
1481 emit setSlotDescription(
"setObjectDrawMode(QString,int,bool)",
"Set the drawMode for an object",
1482 QString(
"DrawMode,ObjectID,Force").split(
","),
1483 QString(
"the drawMode ( ; separated list ),Object id,Apply without checking support(default is true)").split(
","));
1485 emit setSlotDescription(
"viewAll()",
"Change View on all viewers to view whole scene",
1486 QStringList(), QStringList());
1487 emit setSlotDescription(
"viewAll(int)",
"Change View on given viewer to view whole scene",
1488 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1490 emit setSlotDescription(
"viewHome()",
"Change View on all viewers to view home position",
1491 QStringList(), QStringList());
1492 emit setSlotDescription(
"viewHome(int)",
"Change View on given viewer to view home position",
1493 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1496 emit setSlotDescription(
"orthographicProjection()",
"Change Viewer to orthographic projection",
1497 QStringList(), QStringList());
1498 emit setSlotDescription(
"orthographicProjection(int)",
"Change all Viewers to orthographic projection",
1499 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1502 emit setSlotDescription(
"perspectiveProjection()",
"Change Viewer to perspective projection",
1503 QStringList(), QStringList());
1504 emit setSlotDescription(
"perspectiveProjection(int)",
"Change all Viewers to perspective projection",
1505 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1507 emit setSlotDescription(
"setFOVY(double)",
"Set fovy angle of projection for all viewers.",
1508 QStringList(
"fovy"), QStringList(
"FOVY angle"));
1510 emit setSlotDescription(
"setCoordsysProjection(bool)",
"Set the projection mode of the coordinate system.",
1511 QStringList(
"orthogonal"), QStringList(
"If true, orthogonal projection otherwise perspective projection"));
1513 emit setSlotDescription(
"upVector()",
"Get the current upVector.",
1514 QStringList(), QStringList());
1516 emit setSlotDescription(
"upVector(int)",
"Get the current upVector of a specific viewer.",
1517 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1519 emit setSlotDescription(
"eyePosition()",
"Get the current eyePosition.",
1520 QStringList(), QStringList());
1522 emit setSlotDescription(
"eyePosition(int)",
"Get the current eyePosition of a specific viewer.",
1523 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1525 emit setSlotDescription(
"sceneCenter()",
"Get the current sceneCenter.",
1526 QStringList(), QStringList());
1528 emit setSlotDescription(
"sceneCenter(int)",
"Get the current sceneCenter of a specific viewer.",
1529 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1531 emit setSlotDescription(
"viewingDirection()",
"Get the current viewingDirection.",
1532 QStringList(), QStringList());
1534 emit setSlotDescription(
"viewingDirection(int)",
"Get the current viewingDirection of a specific viewer.",
1535 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1537 emit setSlotDescription(
"setTwoSidedLighting(bool)",
"Enable or disable two sided lighting.",
1538 QStringList(
"enabled"), QStringList(
"Specifies whether to enable or disable two sided lighting."));
DLLEXPORT std::vector< TypeInfo >::const_iterator typesEnd()
Get iterator pointing to the last element in the types list.
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
void viewHome(int _viewer)
Go to home position.
bool areaVisible(StatusBits _bit)
Return if the selected areas are currently visible.
void setScenePos(const ACG::Vec3d &_center, const double _radius, int _viewer)
Set the Scene position.
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 orthographicProjection()
Change Viewer to orthographicProjection.
#define DATA_TRIANGLE_MESH
void showModelingAreas(int _id, bool _state)
Allows to enable/disable visualization of the objects modeling area for meshes.
Vector viewingDirection(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get a viewers viewing direction.
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
Vector sceneCenter(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get the scene center.
void twoSidedLighting(bool _state)
set 2-sided lighting on/off
void use()
Enables the program object for using.
void disconnect()
Remove connection of this object to a file.
Type for a Meshobject containing a poly mesh.
Vector eyePosition(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers eye Position
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
void setDrawMode(QString _mode, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the draw mode for a viewer.
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
void viewAll()
Change View on all viewers to view whole scene.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
const ACG::Vec3d sceneCenter(int _viewer)
Get the current scene center.
void showAreas(StatusBits _bits, int _id, bool _state)
Show or hide modeling areas.
void disableShader(DrawModes::DrawMode _drawmode)
void viewHome()
Change View on given Viewer to view home position.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
void enableBackfaceCulling(bool _state, int _viewer=PluginFunctions::ALL_VIEWERS)
Enable or disable Backface culling.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void hideArea(StatusBits _bit, bool _hide)
Hide or show the area Nodes of the object.
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
void setFOVY(double _fovy)
Set fovy angle of projection.
bool backFaceCulling()
Get current state of backface culling.
QStringList getUniforms(QString _shader)
get information about available uniforms for a given shader
bool dataType(DataType _type) const
void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo *_shader=0)
virtual BaseNode * primaryNode()
void setObjectDrawMode(QString _mode, int _objectID, bool _force=true)
Set the draw mode for an object.
bool selectionVisible(int _id)
For meshes returns if the selection for this object is visible.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
void rotate(const ACG::Vec3d &_axis, const double _angle, const ACG::Vec3d &_center, int _viewer)
Rotate Scene around axis.
int viewers()
Get the number of viewers.
bool selectionVisible()
return if the selections are currently visible
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
bool featuresVisible()
return if the feature Node of the object is currently visible
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
ACG::Vec3d project(ACG::Vec3d _point, int _viewerId=0)
Use the projection matrix of the given viewer to project the point.
void disable()
Resets to standard rendering pipeline.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Type for a MeshObject containing a triangle mesh.
void filter(DrawMode _filter)
filter out one drawmode
void showSelection(int _id, bool _state)
Allows to enable/disable visualization of the objects selection for meshes.
void rotate(Vector _axis, double _angle, Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Rotate Scene.
bool areasVisible(StatusBits _bits, int _id)
Return of all of the given modeling areas are visible.
void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader)
bool modelingAreasVisible(int _id)
For meshes returns if the modeling areas for this object is visible.
void setCoordsysProjection(bool _orthogonal)
void lookAt(const ACG::Vec3d &_eye, const ACG::Vec3d &_center, const ACG::Vec3d &_up, int _viewer)
Set the look at transformation directly.
void setSceneCenter(Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the scene center.
void perspectiveProjection()
Change Viewer to perspectiveProjection.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
void setViewingDirection(Vector _direction, Vector _upvector, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the viewing direction.
void setSceneRadius(double _radius, int _viewer)
Set the background color of the examiner widget.
Class for the handling of simple configuration files.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void setSceneRadius(double _radius, int _viewer=PluginFunctions::ALL_VIEWERS)
Set scene radius.
void setFOVY(double _fovy)
Set field of view angle.
virtual ACG::SceneGraph::ShaderNode * shaderNode()
ChildIter find(BaseNode *_node)
void translate(const ACG::Vec3d &_vector, int _viewer)
Translate viewer pos by given vector.
void translate(Vector _vec, int _viewer=PluginFunctions::ALL_VIEWERS)
translate Scene
DLLEXPORT std::vector< TypeInfo >::const_iterator typesBegin()
Get iterator pointing to the first element in the types list.
Vector upVector(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers up vector
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
ProjectionMode getProjectionMode() const
get current projection mode
void traverse(BaseNode *_node, Action &_action)
ACG::GLState & glState()
Get the glState of the Viewer.
void viewAll(int _viewer)
View the whole scene.