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>
52#include <QInputDialog>
53#include <QActionGroup>
56#define SHOW_SELECTION "Show/Hide Selections"
57#define SHOW_AREAS "Show/Hide All Modeling Areas"
58#define SHOW_AREA "Show/Hide Modeling Area"
59#define SHOW_HANDLE "Show/Hide Handle Area"
60#define SHOW_FEATURES "Show/Hide Feature Selection"
61#define SIZE_SELECTION "Set Selection Width"
62#define SIZE_FEATURES "Set Feature Width"
63#define USEGLOBALDRAWMODE "Use Global DrawMode"
64#define SETSHADERS "Set Shader"
66ViewControlPlugin::ViewControlPlugin():
71toolbarViewingDirections_(0),
82void ViewControlPlugin::pluginsInitialized() {
85 OpenFlipper::Options::drawModesInContextMenu(
false);
88 viewControlMenu_ =
new QMenu(
"Visualization");
91 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"drawModes.png");
92 viewControlMenu_->setIcon(icon);
96 if(it->name ==
"Unknown" || it->name ==
"Group" || it->name ==
"All")
continue;
97 emit addContextMenuItem(viewControlMenu_->menuAction(), it->type,
CONTEXTOBJECTMENU );
100 connect( viewControlMenu_, SIGNAL( triggered(QAction*) ),
this, SLOT( contextMenuTriggered(QAction*) ));
105 toolbar_ =
new QToolBar(tr(
"Viewing Directions"));
108 toolbarViewingDirections_ =
new QActionGroup(toolbar_);
109 QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
112 viewTop_ =
new QAction( QIcon(iconPath +
"viewcontrol_top.png"), tr(
"View from top") , toolbarViewingDirections_);
113 toolbar_->addAction( viewTop_ );
114 viewBottom_ =
new QAction( QIcon(iconPath +
"viewcontrol_bottom.png"), tr(
"View from bottom") , toolbarViewingDirections_);
115 toolbar_->addAction( viewBottom_ );
116 viewLeft_ =
new QAction( QIcon(iconPath +
"viewcontrol_left.png"), tr(
"View from left") , toolbarViewingDirections_);
117 toolbar_->addAction( viewLeft_ );
118 viewRight_ =
new QAction( QIcon(iconPath +
"viewcontrol_right.png"), tr(
"View from right") , toolbarViewingDirections_);
119 toolbar_->addAction( viewRight_ );
120 viewFront_ =
new QAction( QIcon(iconPath +
"viewcontrol_front.png"), tr(
"View from front") , toolbarViewingDirections_);
121 toolbar_->addAction( viewFront_ );
122 viewBack_ =
new QAction( QIcon(iconPath +
"viewcontrol_back.png"), tr(
"View from back") , toolbarViewingDirections_);
123 toolbar_->addAction( viewBack_ );
125 connect( toolbarViewingDirections_, SIGNAL( triggered(QAction*) ),
this, SLOT(setView(QAction*)) );
128 emit addToolbar(toolbar_);
133void ViewControlPlugin::updateShaderList() {
139 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
141 for (
int i = 0 ; i < shadersDirs.size(); ++i ) {
144 QFileInfo descriptionFile(OpenFlipper::Options::shaderDirStr() +
145 OpenFlipper::Options::dirSeparator() +
146 shadersDirs[i] + OpenFlipper::Options::dirSeparator() +
"shader.ini" );
149 if ( !descriptionFile.exists() || !ini.
connect( descriptionFile.filePath() ,
false ) ) {
150 emit log(
LOGWARN,
"Unable to open description file for shader " + shadersDirs[i] +
" at " + descriptionFile.filePath() );
152 info.description =
"Unknown";
153 info.version =
"Unknown";
154 info.name = shadersDirs[i];
155 info.details =
"----------";
164 info.name = shadersDirs[i];
165 emit log(
LOGWARN,
"Unable to get name from description file for shader " + shadersDirs[i] );
168 if ( ini.
get_entry(tmp,
"Info",
"description") )
169 info.description = tmp;
171 info.description =
"Unknown";
172 emit log(
LOGWARN,
"Unable to get shader description from description file for shader " + shadersDirs[i] );
175 if ( ini.
get_entry(tmp,
"Info",
"details") )
178 info.details =
"----------";
179 emit log(
LOGWARN,
"Unable to get shader details from description file for shader " + shadersDirs[i] );
182 if ( ini.
get_entry(tmp,
"Info",
"version") )
185 info.version =
"Unknown";
186 emit log(
LOGWARN,
"Unable to get shader version from description file for shader " + shadersDirs[i] );
189 if ( ini.
get_entry(tmp,
"Info",
"example") )
190 info.example = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator() +
191 shadersDirs[i] + OpenFlipper::Options::dirSeparator() + tmp;
194 emit log(
LOGWARN,
"Unable to get example image from Description file for shader " + shadersDirs[i] );
197 if ( ini.
get_entry(tmp,
"FragmentShader",
"file") )
198 info.fragmentShader = tmp;
200 info.fragmentShader =
"Fragment.glsl";
201 emit log(
LOGWARN,
"Unable to get fragment shader filename from Description file for shader " + shadersDirs[i] );
204 if ( ini.
get_entry(tmp,
"VertexShader",
"file") )
205 info.vertexShader = tmp;
207 info.vertexShader =
"Vertex.glsl";
208 emit log(
LOGWARN,
"Unable to get vertex shader filename from Description file for shader " + shadersDirs[i] );
211 if ( ini.
get_entry(tmp,
"PickVertexShader",
"file") )
212 info.pickVertexShader = tmp;
214 info.pickVertexShader =
"";
216 if ( ini.
get_entry(tmp,
"PickFragmentShader",
"file") )
217 info.pickFragmentShader = tmp;
219 info.pickFragmentShader =
"";
222 std::vector<QString> uniforms;
223 if ( ini.
get_entry(uniforms,
"Info",
"uniforms") ) {
224 info.hasUniforms =
true;
225 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
226 info.uniforms << uniforms[uniform];
228 info.hasUniforms =
false;
229 info.uniforms.clear();
234 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformTypes") ) {
235 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
236 info.uniformTypes << uniforms[uniform];
237 }
else if ( info.hasUniforms ) {
238 info.hasUniforms =
false;
239 info.uniforms.clear();
240 info.uniformTypes.clear();
241 emit log(
LOGERR,
"Uniforms for shader " + shadersDirs[i] +
" defined but no type available, disabled uniforms." );
246 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsDefault" ) ) {
247 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
248 info.uniformsDefault << uniforms[uniform];
249 }
else if ( info.hasUniforms ) {
250 info.hasUniforms =
false;
251 info.uniforms.clear();
252 info.uniformTypes.clear();
253 emit log(
LOGERR,
"Uniforms for shader " + shadersDirs[i] +
" defined but no defaults available, disabled uniforms." );
257 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsMin" ) ) {
258 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
259 info.uniformsMin << uniforms[uniform];
260 }
else if ( info.hasUniforms )
261 info.uniformsMin = info.uniformsDefault;
265 if ( info.hasUniforms && ini.
get_entry(uniforms,
"Info",
"uniformsMax" ) ) {
266 for ( uint uniform = 0 ; uniform < uniforms.size() ; ++uniform)
267 info.uniformsMax << uniforms[uniform];
268 }
else if ( info.hasUniforms )
269 info.uniformsMax = info.uniformsDefault;
274 info.directory = descriptionFile.path();
276 QFileInfo vertexShaderFile( info.directory + OpenFlipper::Options::dirSeparator() + info.vertexShader );
277 if ( !vertexShaderFile.exists() ) {
278 emit log(
LOGERR,
"Unable to find vertex shader file " + vertexShaderFile.filePath() );
282 QFileInfo fragmentShaderFile( info.directory + OpenFlipper::Options::dirSeparator() + info.fragmentShader );
283 if ( !fragmentShaderFile.exists() ) {
284 emit log(
LOGERR,
"Unable to find fragment shader file " + fragmentShaderFile.filePath() );
294void ViewControlPlugin::contextMenuTriggered(QAction* _action){
295 if ( _action->text() == SHOW_SELECTION) {
297 QVariant contextObject = _action->data();
298 int objectId = contextObject.toInt();
308 if ( _action->text() == SIZE_SELECTION) {
310 QVariant contextObject = _action->data();
311 int objectId = contextObject.toInt();
323 double d = QInputDialog::getDouble(0, tr(
"Line width for features"),
324 tr(
"Size:"), 2.0, 1.0, 50.0, 2, &ok,
325 Qt::WindowFlags(), 1);
332 double d = QInputDialog::getDouble(0, tr(
"Line width for features"),
333 tr(
"Size:"), 2.0, 1.0, 50.0, 2, &ok,
334 Qt::WindowFlags(), 1);
342 if ( _action->text() == SHOW_AREAS) {
344 QVariant contextObject = _action->data();
345 int objectId = contextObject.toInt();
355 if ( _action->text() == SHOW_AREA) {
357 QVariant contextObject = _action->data();
358 int objectId = contextObject.toInt();
368 if ( _action->text() == SHOW_HANDLE) {
370 QVariant contextObject = _action->data();
371 int objectId = contextObject.toInt();
381 if ( _action->text() == SHOW_FEATURES) {
383 QVariant contextObject = _action->data();
384 int objectId = contextObject.toInt();
401 if ( polyMeshObject )
409 if ( _action->text() == SIZE_FEATURES) {
411 QVariant contextObject = _action->data();
412 int objectId = contextObject.toInt();
424 double d = QInputDialog::getDouble(0, tr(
"Line width for features"),
425 tr(
"Size:"), 2.0, 1.0, 50.0, 2, &ok,
426 Qt::WindowFlags(), 1);
433 double d = QInputDialog::getDouble(0, tr(
"Line width for features"),
434 tr(
"Size:"), 2.0, 1.0, 50.0, 2, &ok,
435 Qt::WindowFlags(), 1);
445 if ( _action->text() == SETSHADERS ) {
446 if ( shaderWidget_ == 0 ) {
448 connect(shaderWidget_->availableShaders,SIGNAL(itemClicked(QListWidgetItem*)),
449 this ,SLOT(slotShaderClicked(QListWidgetItem*)));
450 connect(shaderWidget_->availableShaders,SIGNAL(itemDoubleClicked(QListWidgetItem*)),
451 this ,SLOT(slotShaderDoubleClicked(QListWidgetItem*)));
453 connect(shaderWidget_->setShaderButton,SIGNAL(clicked()),
this, SLOT(slotSetShader()));
454 connect(shaderWidget_->closeButton,SIGNAL(clicked()),shaderWidget_, SLOT(close()));
456 connect(shaderWidget_->uniforms, SIGNAL(itemChanged(QTableWidgetItem*)),
457 this, SLOT(itemChanged(QTableWidgetItem*)) );
462 shaderWidget_->show();
485 if ( polyMeshObject )
503 if ( triMeshObject ) {
510 if ( polyMeshObject )
519 return areasVisible(StatusBits(HANDLEAREA | AREA), _id);
534 triMeshObject->
hideArea( _bits, !_state);
539 if ( polyMeshObject )
540 polyMeshObject->
hideArea( _bits, !_state);
546 showAreas(StatusBits(HANDLEAREA | AREA) , _id, _state );
562 triMeshObject->
statusNode()->material().lineWidth(_width );
567 if ( polyMeshObject )
568 polyMeshObject->
statusNode()->material().lineWidth(_width );
586 triMeshObject->
featureNode()->material().lineWidth(_width );
591 if ( polyMeshObject )
592 polyMeshObject->
featureNode()->material().lineWidth(_width );
615 if ( polyMeshObject )
621void ViewControlPlugin::slotUpdateContextMenu(
int _objectId ){
623 viewControlMenu_->clear();
629 emit log(
LOGERR,
"Unable to create Context Menu ... Unable to get Object");
636 act = viewControlMenu_->addAction( SHOW_SELECTION );
637 act->setCheckable(
true);
639 act->setStatusTip(
"Switch visualization for selection on/off" );
640 act->setToolTip(
"Switch visualization for selection on/off" );
641 act->setWhatsThis(
"Switch the visualization of your current selections on and off." );
643 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"selections.png"));
653 if ( polyMeshObject )
660 act = viewControlMenu_->addAction( SHOW_AREAS );
661 act->setCheckable(
true);
663 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"areaSelections.png"));
673 if ( polyMeshObject )
681 act = viewControlMenu_->addAction( SHOW_HANDLE );
682 act->setCheckable(
true);
684 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"viewcontrol_handleSelection.png"));
694 if ( polyMeshObject )
701 act = viewControlMenu_->addAction( SHOW_AREA );
702 act->setCheckable(
true);
704 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"viewcontrol_modelingSelection.png"));
714 if ( polyMeshObject )
723 act = viewControlMenu_->addAction( SHOW_FEATURES );
724 act->setCheckable(
true);
726 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"viewcontrol_featureSelections.png"));
736 if ( polyMeshObject )
743 act = viewControlMenu_->addAction( SIZE_FEATURES );
745 act->setCheckable(
true);
747 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"viewcontrol_featureSize.png"));
752 act = viewControlMenu_->addAction( SIZE_SELECTION );
754 act->setCheckable(
true);
756 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"viewcontrol_selectionSize.png"));
762 viewControlMenu_->addSeparator();
764 QAction* act = viewControlMenu_->addAction( SETSHADERS );
765 act->setCheckable(
false );
768 viewControlMenu_->addSeparator();
770 QActionGroup * globalDrawActionsGroup =
new QActionGroup(
this );
772 QAction * action =
new QAction( USEGLOBALDRAWMODE , globalDrawActionsGroup );
773 action->setCheckable(
false );
775 viewControlMenu_->addActions(globalDrawActionsGroup->actions());
777 connect( globalDrawActionsGroup, SIGNAL( triggered( QAction * ) ),
778 this , SLOT( slotDrawModeSelected( QAction * ) ) );
780 QActionGroup * drawGroup =
new QActionGroup(
this );
781 drawGroup->setExclusive(
false );
793 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
800 activeCheckboxes.clear();
801 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
806 QCheckBox *checkBox =
new QCheckBox(QString(descr.c_str()), viewControlMenu_);
807 activeCheckboxes[checkBox] = id;
809 checkBox->setCheckState(Qt::Checked);
811 checkBox->setCheckState(Qt::PartiallyChecked);
813 checkBox->setCheckState(Qt::Unchecked);
814 QWidgetAction *checkableAction =
new QWidgetAction(drawGroup);
815 checkableAction->setText(descr.c_str());
816 checkableAction->setDefaultWidget(checkBox);
817 connect(checkBox, SIGNAL( stateChanged(
int) ), checkableAction, SLOT(trigger() ) );
820 viewControlMenu_->addActions( drawGroup->actions() );
822 connect( drawGroup, SIGNAL( triggered( QAction * ) ),
823 this, SLOT( slotDrawModeSelected( QAction * ) ) );
827void ViewControlPlugin::slotDrawModeSelected( QAction * _action) {
829 QWidgetAction *
const wdgtAction =
dynamic_cast<QWidgetAction*
>(_action);
830 QCheckBox *
const checkbox = wdgtAction ?
dynamic_cast<QCheckBox*
>(wdgtAction->defaultWidget()) : 0;
831 const bool activateDrawMode = checkbox ? (checkbox->checkState() != Qt::Unchecked) : false;
837 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
839 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
841 QString descr = QString( availDrawModeIds[i].
description().c_str() );
843 if ( descr == _action->text() ) {
844 mode = availDrawModeIds[i];
852 bool useGlobalDrawMode =
false;
853 bool contextMenuStaysOpen =
false;
854 if ( _action->text() != USEGLOBALDRAWMODE ) {
867 if ( qApp->keyboardModifiers() & Qt::ShiftModifier ) {
868 if (activateDrawMode) {
873 useGlobalDrawMode =
true;
878 contextMenuStaysOpen =
true;
880 if (activateDrawMode) {
884 useGlobalDrawMode =
true;
886 emit hideContextMenu();
890 useGlobalDrawMode =
true;
896 useGlobalDrawMode =
true;
899 if (contextMenuStaysOpen) {
900 typedef std::map<QCheckBox*, ACG::SceneGraph::DrawModes::DrawMode> CBM;
902 for (CBM::iterator it = activeCheckboxes.begin(), it_end = activeCheckboxes.end(); it != it_end; ++it) {
903 it->first->blockSignals(
true);
905 it->first->setCheckState(Qt::Checked);
907 it->first->setCheckState(Qt::PartiallyChecked);
909 it->first->setCheckState(Qt::Unchecked);
911 it->first->blockSignals(
false);
935void ViewControlPlugin::initShaderWidget(){
941 shaderWidget_->availableShaders->clear();
947 shaderWidget_->availableShaders->setCurrentRow(0);
948 slotShaderClicked(shaderWidget_->availableShaders->currentItem());
952void ViewControlPlugin::slotShaderClicked( QListWidgetItem * _item ){
954 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
962 std::cerr <<
"Strange index Error! " << std::endl;
968 shaderWidget_->details->setText(
shaderList_[index].details );
969 shaderWidget_->version->setText(
shaderList_[index].version );
970 shaderWidget_->vertexShader->setText(
shaderList_[index].vertexShader );
971 shaderWidget_->fragmentShader->setText(
shaderList_[index].fragmentShader );
972 shaderWidget_->pickVertexShader->setText(
shaderList_[index].pickVertexShader );
973 shaderWidget_->pickFragmentShader->setText(
shaderList_[index].pickFragmentShader );
974 shaderWidget_->example->setPixmap( QPixmap(
shaderList_[index].example) );
977 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
978 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
980 QString vertexFile = shaderDir + shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
981 OpenFlipper::Options::dirSeparator() + shaderWidget_->vertexShader->text();
982 QString fragmentFile = shaderDir + shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
983 OpenFlipper::Options::dirSeparator() + shaderWidget_->fragmentShader->text();
986 shaderWidget_->drawModes->clear();
988 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
991 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
996 std::vector< QString > dm = drawModeToDescriptions(
id );
998 if ( !dm.empty() && dm[0].trimmed() !=
""){
999 QListWidgetItem* item =
new QListWidgetItem(dm[0]);
1001 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
1007 if ( object->
shaderNode()->vertexShaderName(
id ) == vertexFile.toStdString() &&
1008 object->
shaderNode()->fragmentShaderName(
id ) == fragmentFile.toStdString() )
1009 item->setCheckState( Qt::Checked );
1014 item->setCheckState( Qt::Unchecked );
1017 shaderWidget_->drawModes->addItem(item);
1023 shaderWidget_->uniforms->clear();
1024 shaderWidget_->uniforms->setColumnCount ( 1 );
1025 shaderWidget_->uniforms->setRowCount (
shaderList_[index].uniforms.count() );
1027 shaderWidget_->uniforms->setHorizontalHeaderLabels( QStringList(
"Value") );
1028 shaderWidget_->uniforms->setVerticalHeaderLabels(
shaderList_[index].uniforms );
1030 for (
int i=0; i <
shaderList_[index].uniforms.count(); i++){
1031 QTableWidgetItem* item =
new QTableWidgetItem(
shaderList_[index].uniformsDefault[i] );
1032 item->setFlags( Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1033 shaderWidget_->uniforms->setItem(i,0,item );
1036 shaderWidget_->uniformBox->setVisible(
true );
1039 shaderWidget_->uniformBox->setVisible(
false );
1044void ViewControlPlugin::slotShaderDoubleClicked( QListWidgetItem * ){
1048void ViewControlPlugin::itemChanged(QTableWidgetItem* item){
1052 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
1053 if (
shaderList_[i].
name == shaderWidget_->availableShaders->currentItem()->text() ) {
1059 if ( index == -1 ) {
1060 std::cerr <<
"Error: Shader Index not found! " << std::endl;
1065 int row = item->row();
1068 std::cerr <<
"Error: uniform index out of bounds" << std::endl;
1073 if (
shaderList_[index].uniformTypes[row] ==
"float"){
1076 float value = item->text().toFloat(&ok);
1079 item->setText(
shaderList_[index].uniformsDefault[row] );
1081 && value <
shaderList_[index].uniformsMin[row].toFloat())
1082 item->setText(
shaderList_[index].uniformsMin[row] );
1084 && value >
shaderList_[index].uniformsMax[row].toFloat())
1085 item->setText(
shaderList_[index].uniformsMax[row] );
1090void ViewControlPlugin::slotSetShader()
1095 for (
int i = 0; i < (int)
shaderList_.size(); ++i) {
1096 if (
shaderList_[i].
name == shaderWidget_->availableShaders->currentItem()->text()) {
1103 std::cerr <<
"Error: Shader Index not found! " << std::endl;
1107 std::vector<QString> mode;
1108 for (
int i = 0; i < shaderWidget_->drawModes->count(); i++) {
1109 if (shaderWidget_->drawModes->item(i)->checkState() == Qt::Checked) {
1110 mode.push_back(shaderWidget_->drawModes->item(i)->text());
1114 mode.push_back(shaderWidget_->drawModes->item(i)->text());
1132 object->shaderNode()->disableShader(_drawMode);
1134 std::string shadeDir = _shader->directory.toStdString() + OpenFlipper::Options::dirSeparator().toStdString();
1136 if (object->
shaderNode()->vertexShaderName(_drawMode) == shadeDir + _shader->vertexShader.toStdString()
1137 && object->
shaderNode()->fragmentShaderName(_drawMode) == shadeDir + _shader->fragmentShader.toStdString())
1138 object->shaderNode()->disableShader(_drawMode);
1147 if ( OpenFlipper::Options::nogui() )
1154 QFileInfo vertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.vertexShader);
1155 QFileInfo fragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.fragmentShader);
1156 QFileInfo pickVertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickVertexShader);
1157 QFileInfo pickFragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickFragmentShader);
1160 && _shader.vertexShader.length() && _shader.fragmentShader.length()) {
1162 if (vertexFile.absolutePath() != fragmentFile.absolutePath()) {
1163 emit log(
LOGERR,
"Cannot set shader. Currently shader files have to be in the same folder.");
1167 if (_shader.pickVertexShader.length() && _shader.pickFragmentShader.length())
1169 if (vertexFile.absolutePath() != pickVertexFile.absolutePath() ||
1170 vertexFile.absolutePath() != pickFragmentFile.absolutePath()) {
1171 emit log(
LOGERR,
"Cannot set picking shader. Currently shader files have to be in the same folder.");
1175 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1177 object->shaderNode()->setShader(_drawMode,
1178 vertexFile.fileName().toStdString(),
1179 fragmentFile.fileName().toStdString(),
1180 pickVertexFile.fileName().toStdString(),
1181 pickFragmentFile.fileName().toStdString());
1185 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1186 object->shaderNode()->setShader(_drawMode, vertexFile.fileName().toStdString(), fragmentFile.fileName().toStdString());
1192 if (_shader.hasUniforms) {
1194 if ( shader == 0 ) {
1195 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1199 for (
int u=0; u < _shader.uniforms.count(); u++) {
1201 if (_shader.uniformTypes[u] ==
"float" ) {
1202 shaderWidget_->uniforms->setCurrentCell(u,0);
1203 float value = shaderWidget_->uniforms->currentItem()->text().toFloat();
1204 shader->
setUniform(_shader.uniforms[u].toUtf8(), value);
1207 if (_shader.uniformTypes[u] ==
"vec3" ) {
1208 shaderWidget_->uniforms->setCurrentCell(u,0);
1209 QStringList vecStr = shaderWidget_->uniforms->currentItem()->text().split(
",");
1210 if (vecStr.count() == 3) {
1211 ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
1212 shader->
setUniform(_shader.uniforms[u].toUtf8(), value);
1215 std::cerr <<
"Error: handling of uniformType '" << _shader.uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1228 if ( OpenFlipper::Options::nogui() )
1235 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
1242 if ( index == -1 ) {
1243 std::cerr <<
"Error: Shader not found! " << std::endl;
1247 std::vector <QString> mode;
1248 mode.push_back(_drawMode);
1260 return QStringList();
1263QString ViewControlPlugin::getUniformType(QString _shader, QString _uniform ){
1268 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1276QString ViewControlPlugin::getUniformDefault(QString _shader, QString _uniform ){
1281 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1289QString ViewControlPlugin::getUniformMin(QString _shader, QString _uniform ){
1294 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1302QString ViewControlPlugin::getUniformMax(QString _shader, QString _uniform ){
1307 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1331 if ( shader == 0 ) {
1332 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1336 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++){
1347 else if (
shaderList_[i].uniformTypes[u] ==
"vec3" ){
1348 QStringList vecStr = _value.split(
",");
1349 if (vecStr.count() == 3){
1350 ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
1354 std::cerr <<
"Error: handling of uniformType '" <<
shaderList_[i].uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1390 if ( _viewer == PluginFunctions::ALL_VIEWERS )
1393 else if ( _viewer == PluginFunctions::ACTIVE_VIEWER )
1398 std::cerr <<
"Illegal viewer requested! " << std::endl;
1409 QStringList list = _mode.split(
';');
1411 std::vector< QString > drawModeList;
1413 for (
int i = 0 ; i < list.size() ; ++i )
1414 drawModeList.push_back(list[i]);
1430 QStringList list = _mode.split(
';');
1432 std::vector< QString > drawModeList;
1434 for (
int i = 0 ; i < list.size() ; ++i )
1435 drawModeList.push_back(list[i]);
1470void ViewControlPlugin::setView(
int _mode,
int _viewer ) {
1473 case PluginFunctions::VIEW_TOP :
1476 case PluginFunctions::VIEW_BOTTOM :
1479 case PluginFunctions::VIEW_LEFT :
1482 case PluginFunctions::VIEW_RIGHT :
1485 case PluginFunctions::VIEW_FRONT :
1488 case PluginFunctions::VIEW_BACK :
1492 emit log(
LOGERR,
"ViewControl: Unknown view mode: " + QString::number(_mode));
1501void ViewControlPlugin::setView(QAction* _action) {
1503 if ( _action == viewTop_) setView (PluginFunctions::VIEW_TOP, PluginFunctions::ACTIVE_VIEWER);
1504 else if ( _action == viewBottom_) setView (PluginFunctions::VIEW_BOTTOM, PluginFunctions::ACTIVE_VIEWER);
1505 else if ( _action == viewLeft_) setView (PluginFunctions::VIEW_LEFT, PluginFunctions::ACTIVE_VIEWER);
1506 else if ( _action == viewRight_) setView (PluginFunctions::VIEW_RIGHT, PluginFunctions::ACTIVE_VIEWER);
1507 else if ( _action == viewFront_) setView (PluginFunctions::VIEW_FRONT, PluginFunctions::ACTIVE_VIEWER);
1508 else if ( _action == viewBack_) setView (PluginFunctions::VIEW_BACK, PluginFunctions::ACTIVE_VIEWER);
1509 else emit log(
LOGERR,
"ViewControl: Unknown view mode action!");
1514void ViewControlPlugin::setEyePosition(
Vector _eye){
1518 PluginFunctions::ACTIVE_VIEWER);
1568 if (cnode->
getProjectionMode() == ACG::SceneGraph::CoordsysNode::PERSPECTIVE_PROJECTION) {
1570 cnode->
setProjectionMode(ACG::SceneGraph::CoordsysNode::ORTHOGRAPHIC_PROJECTION);
1574 if ( !_orthogonal) {
1575 cnode->
setProjectionMode(ACG::SceneGraph::CoordsysNode::PERSPECTIVE_PROJECTION);
1581 emit log(
LOGERR,tr(
"setCoordsysProjection(): Could not find coordsys node, thus its projection mode will not be toggled."));
1586void ViewControlPlugin::setTwoSidedLighting(
bool _enabled) {
1595void ViewControlPlugin::setDescriptions() {
1596 emit setSlotDescription(
"translate(Vector,int)",
"Translate Scene",
1597 QString(
"TranslationVector,Viewer").split(
","),
1598 QString(
"vector for the translation.,Viewer id (default is all)").split(
","));
1599 emit setSlotDescription(
"translate(Vector)",
"Translate Scene in all Viewers",
1600 QString(
"TranslationVector").split(
","),
1601 QString(
"vector for the translation.").split(
","));
1602 emit setSlotDescription(
"rotate(Vector,double,Vector,int)",
"Rotate Scene",
1603 QString(
"Axis,Angle,Center,Viewer").split(
","),
1604 QString(
"Rotation axis., Rotation Angle., Rotation Center.").split(
","));
1605 emit setSlotDescription(
"rotate(Vector,double,Vector)",
"Rotate Scene in all viewers",
1606 QString(
"Axis,Angle,Center").split(
","),
1607 QString(
"Rotation axis., Rotation Angle., Rotation Center.").split(
","));
1608 emit setSlotDescription(
"setViewingDirection(Vector,Vector,int)",
"Set the viewing direction",
1609 QString(
"direction,upVector,Viewer").split(
","),
1610 QString(
"Viewing direction., Up-Vector.,Viewer id (default is all)").split(
","));
1611 emit setSlotDescription(
"setViewingDirection(Vector,Vector)",
"Set the viewing direction in all viewers",
1612 QString(
"direction,upVector").split(
","),
1613 QString(
"Viewing direction., Up-Vector.").split(
","));
1614 emit setSlotDescription(
"setDrawMode(QString,int)",
"Set the drawMode",
1615 QString(
"DrawMode,Viewer").split(
","),
1616 QString(
"the drawMode ( ; separated list ),Viewer id (default is all)").split(
","));
1617 emit setSlotDescription(
"setDrawMode(QString)",
"Set the drawMode for all viewers",
1619 QStringList(
"DrawMode"), QStringList(
"the drawMode ( ; separated list )"));
1621 emit setSlotDescription(
"setObjectDrawMode(QString,int,bool)",
"Set the drawMode for an object",
1622 QString(
"DrawMode,ObjectID,Force").split(
","),
1623 QString(
"the drawMode ( ; separated list ),Object id,Apply without checking support(default is true)").split(
","));
1625 emit setSlotDescription(
"viewAll()",
"Change View on all viewers to view whole scene",
1626 QStringList(), QStringList());
1627 emit setSlotDescription(
"viewAll(int)",
"Change View on given viewer to view whole scene",
1628 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1630 emit setSlotDescription(
"viewHome()",
"Change View on all viewers to view home position",
1631 QStringList(), QStringList());
1632 emit setSlotDescription(
"viewHome(int)",
"Change View on given viewer to view home position",
1633 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1636 emit setSlotDescription(
"orthographicProjection()",
"Change Viewer to orthographic projection",
1637 QStringList(), QStringList());
1638 emit setSlotDescription(
"orthographicProjection(int)",
"Change all Viewers to orthographic projection",
1639 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1642 emit setSlotDescription(
"perspectiveProjection()",
"Change Viewer to perspective projection",
1643 QStringList(), QStringList());
1644 emit setSlotDescription(
"perspectiveProjection(int)",
"Change all Viewers to perspective projection",
1645 QStringList(
"Viewer"), QStringList(
"Id of the viewer to change"));
1647 emit setSlotDescription(
"setFOVY(double)",
"Set fovy angle of projection for all viewers.",
1648 QStringList(
"fovy"), QStringList(
"FOVY angle"));
1650 emit setSlotDescription(
"setCoordsysProjection(bool)",
"Set the projection mode of the coordinate system.",
1651 QStringList(
"orthogonal"), QStringList(
"If true, orthogonal projection otherwise perspective projection"));
1653 emit setSlotDescription(
"upVector()",
"Get the current upVector.",
1654 QStringList(), QStringList());
1656 emit setSlotDescription(
"upVector(int)",
"Get the current upVector of a specific viewer.",
1657 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1659 emit setSlotDescription(
"eyePosition()",
"Get the current eyePosition.",
1660 QStringList(), QStringList());
1662 emit setSlotDescription(
"eyePosition(int)",
"Get the current eyePosition of a specific viewer.",
1663 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1665 emit setSlotDescription(
"sceneCenter()",
"Get the current sceneCenter.",
1666 QStringList(), QStringList());
1668 emit setSlotDescription(
"sceneCenter(int)",
"Get the current sceneCenter of a specific viewer.",
1669 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1671 emit setSlotDescription(
"viewingDirection()",
"Get the current viewingDirection.",
1672 QStringList(), QStringList());
1674 emit setSlotDescription(
"viewingDirection(int)",
"Get the current viewingDirection of a specific viewer.",
1675 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1677 emit setSlotDescription(
"setTwoSidedLighting(bool)",
"Enable or disable two sided lighting.",
1678 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.
DLLEXPORT std::vector< TypeInfo >::const_iterator typesBegin()
Get iterator pointing to the first element in the types list.
#define DATA_TRIANGLE_MESH
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
ChildIter find(BaseNode *_node)
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
void setProjectionMode(const ProjectionMode _mode)
set mode to either ORTHOGRAPHIC_PROJECTION or PERSPECTIVE_PROJECTION
ProjectionMode getProjectionMode() const
get current projection mode
void combine(DrawMode _mode)
combine with another drawmode
void filter(DrawMode _filter)
filter out one drawmode
std::string description() const
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
bool containsAtomicDrawMode(const DrawMode &_atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
virtual ACG::SceneGraph::ShaderNode * shaderNode()
virtual BaseNode * primaryNode()
bool dataType(DataType _type) const
void disable()
Resets to standard rendering pipeline.
void use()
Enables the program object for using.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Class for the handling of simple configuration files.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void disconnect()
Remove connection of this object to a file.
bool areaVisible(StatusBits _bit)
Return if the selected areas are currently visible.
ACG::SceneGraph::StatusNodeT< MeshT, FeatureNodeMod< MeshT > > * featureNode()
Returns the feature selection node if available, nullptr otherwise.
bool featuresVisible()
return if the feature Node of the object is currently visible
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
ACG::SceneGraph::SelectionNodeT< MeshT > * statusNode()
bool selectionVisible()
return if the selections are currently visible
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
void hideArea(StatusBits _bit, bool _hide)
Hide or show the area Nodes of the object.
Type for a Meshobject containing a poly mesh.
Type for a MeshObject containing a triangle mesh.
void setSceneCenter(Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the scene center.
void showSelection(int _id, bool _state)
Allows to enable/disable visualization of the objects selection for meshes.
void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo *_shader=0)
void viewAll()
Change View on all viewers to view whole scene.
void perspectiveProjection()
Change Viewer to perspectiveProjection.
void setViewingDirection(Vector _direction, Vector _upvector, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the viewing direction.
void translate(Vector _vec, int _viewer=PluginFunctions::ALL_VIEWERS)
translate Scene
std::vector< ShaderInfo > shaderList_
void rotate(Vector _axis, double _angle, Vector _center, int _viewer=PluginFunctions::ALL_VIEWERS)
Rotate Scene.
Vector eyePosition(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers eye Position
void showModelingAreas(int _id, bool _state)
Allows to enable/disable visualization of the objects modeling area for meshes.
Vector upVector(int _viewer=PluginFunctions::ACTIVE_VIEWER)
get a viewers up vector
void showAreas(StatusBits _bits, int _id, bool _state)
Show or hide modeling areas.
void setFOVY(double _fovy)
Set fovy angle of projection.
void viewHome()
Change View on given Viewer to view home position.
bool selectionVisible(int _id)
For meshes returns if the selection for this object is visible.
ACG::SceneGraph::DrawModes::DrawMode availDrawModes_
void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader)
ACG::SceneGraph::DrawModes::DrawMode activeDrawModes_
ACG::Vec3d project(ACG::Vec3d _point, int _viewerId=0)
Use the projection matrix of the given viewer to project the point.
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
QString description()
Return a description of what the plugin is doing.
void setDrawMode(QString _mode, int _viewer=PluginFunctions::ALL_VIEWERS)
Set the draw mode for a viewer.
Vector viewingDirection(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get a viewers viewing direction.
bool modelingAreasVisible(int _id)
For meshes returns if the modeling areas for this object is visible.
void setObjectDrawMode(QString _mode, int _objectID, bool _force=true)
Set the draw mode for an object.
void setFeatureLineWidth(int _id, double _width)
Set the line width of the features.
void setCoordsysProjection(bool _orthogonal)
bool areasVisible(StatusBits _bits, int _id)
Return of all of the given modeling areas are visible.
void setSelectionLineWidth(int _id, double _width)
Set the line width of the selections.
void orthographicProjection()
Change Viewer to orthographicProjection.
void setSceneRadius(double _radius, int _viewer=PluginFunctions::ALL_VIEWERS)
Set scene radius.
QString name()
Return a name for the plugin.
void enableBackfaceCulling(bool _state, int _viewer=PluginFunctions::ALL_VIEWERS)
Enable or disable Backface culling.
QStringList getUniforms(QString _shader)
get information about available uniforms for a given shader
Vector sceneCenter(int _viewer=PluginFunctions::ACTIVE_VIEWER)
Get the scene center.
void twoSidedLighting(bool _state)
set 2-sided lighting on/off
bool backFaceCulling()
Get current state of backface culling.
ACG::GLState & glState()
Get the glState of the Viewer.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
void traverse(BaseNode *_node, Action &_action)
void translate(const ACG::Vec3d &_vector, int _viewer)
Translate viewer pos by given vector.
void perspectiveProjection(int _viewer)
Switch to perspective Projection.
void setSceneRadius(double _radius, int _viewer)
Set the background color of the examiner widget.
ACG::Vec3d eyePos(int _viewer)
Get the current viewer position.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
void viewHome(int _viewer)
Go to home position.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void orthographicProjection(int _viewer)
Switch to orthographic Projection.
void setScenePos(const ACG::Vec3d &_center, const double _radius, int _viewer)
Set the Scene position.
PolyMeshObject * polyMeshObject(BaseObjectData *_object)
Cast an BaseObject to a PolyMeshObject if possible.
ACG::Vec3d upVector(int _viewer)
Get the current up vector.
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.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
void setFOVY(double _fovy)
Set field of view angle.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
void lookAt(const ACG::Vec3d &_eye, const ACG::Vec3d &_center, const ACG::Vec3d &_up, int _viewer)
Set the look at transformation directly.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
const ACG::Vec3d sceneCenter(int _viewer)
Get the current scene center.
void viewAll(int _viewer)
View the whole scene.