51 #include "ViewControlPlugin.hh"
52 #include <OpenFlipper/INIFile/INIFile.hh>
54 #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
55 #include <ACG/Scenegraph/CoordsysNode.hh>
57 #if QT_VERSION >= 0x050000
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"
70 ViewControlPlugin::ViewControlPlugin():
75 toolbarViewingDirections_(0),
86 void ViewControlPlugin::pluginsInitialized() {
89 OpenFlipper::Options::drawModesInContextMenu(
false);
92 viewControlMenu_ =
new QMenu(
"Visualization");
95 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"drawModes.png");
96 viewControlMenu_->setIcon(icon);
100 if(it->name ==
"Unknown" || it->name ==
"Group" || it->name ==
"All")
continue;
101 emit addContextMenuItem(viewControlMenu_->menuAction(), it->type,
CONTEXTOBJECTMENU );
104 connect( viewControlMenu_, SIGNAL( triggered(QAction*) ),
this, SLOT( contextMenuTriggered(QAction*) ));
109 toolbar_ =
new QToolBar(tr(
"Viewing Directions"));
112 toolbarViewingDirections_ =
new QActionGroup(toolbar_);
113 QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
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_ );
129 connect( toolbarViewingDirections_, SIGNAL( triggered(QAction*) ),
this, SLOT(setView(QAction*)) );
132 emit addToolbar(toolbar_);
137 void ViewControlPlugin::updateShaderList() {
143 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
145 for (
int i = 0 ; i < shadersDirs.size(); ++i ) {
148 QFileInfo descriptionFile(OpenFlipper::Options::shaderDirStr() +
149 OpenFlipper::Options::dirSeparator() +
150 shadersDirs[i] + OpenFlipper::Options::dirSeparator() +
"shader.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() );
156 info.description =
"Unknown";
157 info.version =
"Unknown";
158 info.name = shadersDirs[i];
159 info.details =
"----------";
168 info.name = shadersDirs[i];
169 emit log(
LOGWARN,
"Unable to get name from description file for shader " + shadersDirs[i] );
172 if ( ini.
get_entry(tmp,
"Info",
"description") )
173 info.description = tmp;
175 info.description =
"Unknown";
176 emit log(
LOGWARN,
"Unable to get shader description from description file for shader " + shadersDirs[i] );
179 if ( ini.
get_entry(tmp,
"Info",
"details") )
182 info.details =
"----------";
183 emit log(
LOGWARN,
"Unable to get shader details from description file for shader " + shadersDirs[i] );
186 if ( ini.
get_entry(tmp,
"Info",
"version") )
189 info.version =
"Unknown";
190 emit log(
LOGWARN,
"Unable to get shader version from description file for shader " + shadersDirs[i] );
193 if ( ini.
get_entry(tmp,
"Info",
"example") )
194 info.example = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator() +
195 shadersDirs[i] + OpenFlipper::Options::dirSeparator() + tmp;
198 emit log(
LOGWARN,
"Unable to get example image from Description file for shader " + shadersDirs[i] );
201 if ( ini.
get_entry(tmp,
"FragmentShader",
"file") )
202 info.fragmentShader = tmp;
204 info.fragmentShader =
"Fragment.glsl";
205 emit log(
LOGWARN,
"Unable to get fragment shader filename from Description file for shader " + shadersDirs[i] );
208 if ( ini.
get_entry(tmp,
"VertexShader",
"file") )
209 info.vertexShader = tmp;
211 info.vertexShader =
"Vertex.glsl";
212 emit log(
LOGWARN,
"Unable to get vertex shader filename from Description file for shader " + shadersDirs[i] );
215 if ( ini.
get_entry(tmp,
"PickVertexShader",
"file") )
216 info.pickVertexShader = tmp;
218 info.pickVertexShader =
"";
220 if ( ini.
get_entry(tmp,
"PickFragmentShader",
"file") )
221 info.pickFragmentShader = tmp;
223 info.pickFragmentShader =
"";
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];
232 info.hasUniforms =
false;
233 info.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." );
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." );
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;
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;
278 info.directory = descriptionFile.path();
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() );
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() );
292 shaderList_.push_back(info);
298 void ViewControlPlugin::contextMenuTriggered(QAction* _action){
299 if ( _action->text() == SHOW_SELECTION) {
301 QVariant contextObject = _action->data();
302 int objectId = contextObject.toInt();
312 if ( _action->text() == SHOW_AREAS) {
314 QVariant contextObject = _action->data();
315 int objectId = contextObject.toInt();
325 if ( _action->text() == SHOW_AREA) {
327 QVariant contextObject = _action->data();
328 int objectId = contextObject.toInt();
338 if ( _action->text() == SHOW_HANDLE) {
340 QVariant contextObject = _action->data();
341 int objectId = contextObject.toInt();
351 if ( _action->text() == SHOW_FEATURES) {
353 QVariant contextObject = _action->data();
354 int objectId = contextObject.toInt();
371 if ( polyMeshObject )
379 if ( _action->text() == SETSHADERS ) {
380 if ( 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*)));
387 connect(shaderWidget_->setShaderButton,SIGNAL(clicked()),
this, SLOT(slotSetShader()));
388 connect(shaderWidget_->closeButton,SIGNAL(clicked()),shaderWidget_, SLOT(close()));
390 connect(shaderWidget_->uniforms, SIGNAL(itemChanged(QTableWidgetItem*)),
391 this, SLOT(itemChanged(QTableWidgetItem*)) );
396 shaderWidget_->show();
419 if ( polyMeshObject )
437 if ( triMeshObject ) {
444 if ( polyMeshObject )
453 return areasVisible(StatusBits(HANDLEAREA | AREA), _id);
468 triMeshObject->
hideArea( _bits, !_state);
473 if ( polyMeshObject )
474 polyMeshObject->
hideArea( _bits, !_state);
480 showAreas(StatusBits(HANDLEAREA | AREA) , _id, _state );
501 if ( polyMeshObject )
507 void ViewControlPlugin::slotUpdateContextMenu(
int _objectId ){
509 viewControlMenu_->clear();
515 emit log(
LOGERR,
"Unable to create Context Menu ... Unable to get Object");
522 act = viewControlMenu_->addAction( SHOW_SELECTION );
523 act->setCheckable(
true);
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." );
529 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"selections.png"));
539 if ( polyMeshObject )
546 act = viewControlMenu_->addAction( SHOW_AREAS );
547 act->setCheckable(
true);
549 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"areaSelections.png"));
554 act->setChecked( triMeshObject->
areaVisible( StatusBits(HANDLEAREA | AREA) ) );
559 if ( polyMeshObject )
560 act->setChecked( polyMeshObject->
areaVisible( StatusBits(HANDLEAREA | AREA) ) );
567 act = viewControlMenu_->addAction( SHOW_HANDLE );
568 act->setCheckable(
true);
570 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"handleSelection.png"));
575 act->setChecked( triMeshObject->
areaVisible( HANDLEAREA ) );
580 if ( polyMeshObject )
581 act->setChecked( polyMeshObject->
areaVisible( HANDLEAREA ) );
587 act = viewControlMenu_->addAction( SHOW_AREA );
588 act->setCheckable(
true);
590 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"modelingSelection.png"));
595 act->setChecked( triMeshObject->
areaVisible( AREA ) );
600 if ( polyMeshObject )
601 act->setChecked( polyMeshObject->
areaVisible( AREA ) );
609 act = viewControlMenu_->addAction( SHOW_FEATURES );
610 act->setCheckable(
true);
612 act->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"featureSelections.png"));
622 if ( polyMeshObject )
631 viewControlMenu_->addSeparator();
633 QAction* act = viewControlMenu_->addAction( SETSHADERS );
634 act->setCheckable(
false );
637 viewControlMenu_->addSeparator();
639 QActionGroup * globalDrawActionsGroup =
new QActionGroup(
this );
641 QAction * action =
new QAction( USEGLOBALDRAWMODE , globalDrawActionsGroup );
642 action->setCheckable(
false );
644 viewControlMenu_->addActions(globalDrawActionsGroup->actions());
646 connect( globalDrawActionsGroup, SIGNAL( triggered( QAction * ) ),
647 this , SLOT( slotDrawModeSelected( QAction * ) ) );
649 QActionGroup * drawGroup =
new QActionGroup(
this );
650 drawGroup->setExclusive(
false );
662 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
663 availDrawModeIds = availDrawModes_.getAtomicDrawModes();
669 activeCheckboxes.clear();
670 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
673 std::string descr =
id.description();
675 QCheckBox *checkBox =
new QCheckBox(QString(descr.c_str()), viewControlMenu_);
676 activeCheckboxes[checkBox] = id;
677 if (activeDrawModes_.containsAtomicDrawMode(
id))
678 checkBox->setCheckState(Qt::Checked);
680 checkBox->setCheckState(Qt::PartiallyChecked);
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() ) );
689 viewControlMenu_->addActions( drawGroup->actions() );
691 connect( drawGroup, SIGNAL( triggered( QAction * ) ),
692 this, SLOT( slotDrawModeSelected( QAction * ) ) );
696 void ViewControlPlugin::slotDrawModeSelected( QAction * _action) {
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;
706 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
707 availDrawModeIds = availDrawModes_.getAtomicDrawModes();
708 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
710 QString descr = QString( availDrawModeIds[i].
description().c_str() );
712 if ( descr == _action->text() ) {
713 mode = availDrawModeIds[i];
721 bool useGlobalDrawMode =
false;
722 bool contextMenuStaysOpen =
false;
723 if ( _action->text() != USEGLOBALDRAWMODE ) {
729 if ( qApp->keyboardModifiers() & Qt::ShiftModifier ) {
730 if (activateDrawMode) {
731 activeDrawModes_ |= mode;
733 if (activeDrawModes_ == mode) {
735 useGlobalDrawMode =
true;
737 activeDrawModes_.
filter(mode);
740 contextMenuStaysOpen =
true;
742 if (activateDrawMode) {
743 activeDrawModes_ = mode ;
746 useGlobalDrawMode =
true;
748 emit hideContextMenu();
752 useGlobalDrawMode =
true;
758 useGlobalDrawMode =
true;
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);
769 it->first->setCheckState(Qt::PartiallyChecked);
771 it->first->setCheckState(Qt::Unchecked);
773 it->first->blockSignals(
false);
797 void ViewControlPlugin::initShaderWidget(){
803 shaderWidget_->availableShaders->clear();
809 shaderWidget_->availableShaders->setCurrentRow(0);
810 slotShaderClicked(shaderWidget_->availableShaders->currentItem());
814 void ViewControlPlugin::slotShaderClicked( QListWidgetItem * _item ){
816 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
824 std::cerr <<
"Strange index Error! " << std::endl;
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) );
839 QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
840 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
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();
848 shaderWidget_->drawModes->clear();
850 std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
851 availDrawModeIds = availDrawModes_.getAtomicDrawModes( );
853 for (
unsigned int i = 0; i < availDrawModeIds.size(); ++i )
858 std::vector< QString > dm = drawModeToDescriptions(
id );
860 if ( !dm.empty() && dm[0].trimmed() !=
""){
861 QListWidgetItem* item =
new QListWidgetItem(dm[0]);
863 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
869 if ( object->
shaderNode()->vertexShaderName(
id ) == vertexFile.toStdString() &&
870 object->shaderNode()->fragmentShaderName(
id ) == fragmentFile.toStdString() )
871 item->setCheckState( Qt::Checked );
876 item->setCheckState( Qt::Unchecked );
879 shaderWidget_->drawModes->addItem(item);
885 shaderWidget_->uniforms->clear();
886 shaderWidget_->uniforms->setColumnCount ( 1 );
887 shaderWidget_->uniforms->setRowCount (
shaderList_[index].uniforms.count() );
889 shaderWidget_->uniforms->setHorizontalHeaderLabels( QStringList(
"Value") );
890 shaderWidget_->uniforms->setVerticalHeaderLabels(
shaderList_[index].uniforms );
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 );
898 shaderWidget_->uniformBox->setVisible(
true );
901 shaderWidget_->uniformBox->setVisible(
false );
906 void ViewControlPlugin::slotShaderDoubleClicked( QListWidgetItem * ){
910 void ViewControlPlugin::itemChanged(QTableWidgetItem* item){
914 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
915 if (
shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text() ) {
922 std::cerr <<
"Error: Shader Index not found! " << std::endl;
927 int row = item->row();
930 std::cerr <<
"Error: uniform index out of bounds" << std::endl;
935 if (
shaderList_[index].uniformTypes[row] ==
"float"){
938 float value = item->text().toFloat(&ok);
941 item->setText(
shaderList_[index].uniformsDefault[row] );
943 && value <
shaderList_[index].uniformsMin[row].toFloat())
944 item->setText(
shaderList_[index].uniformsMin[row] );
946 && value >
shaderList_[index].uniformsMax[row].toFloat())
947 item->setText(
shaderList_[index].uniformsMax[row] );
952 void ViewControlPlugin::slotSetShader()
957 for (
int i = 0; i < (int)
shaderList_.size(); ++i) {
958 if (
shaderList_[i].name == shaderWidget_->availableShaders->currentItem()->text()) {
965 std::cerr <<
"Error: Shader Index not found! " << std::endl;
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());
976 mode.push_back(shaderWidget_->drawModes->item(i)->text());
994 object->shaderNode()->disableShader(_drawMode);
996 std::string shadeDir = _shader->directory.toStdString() + OpenFlipper::Options::dirSeparator().toStdString();
998 if (object->
shaderNode()->vertexShaderName(_drawMode) == shadeDir + _shader->vertexShader.toStdString()
999 &&
object->shaderNode()->fragmentShaderName(_drawMode) == shadeDir + _shader->fragmentShader.toStdString())
1009 if ( OpenFlipper::Options::nogui() )
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);
1022 && _shader.vertexShader.length() && _shader.fragmentShader.length()) {
1024 if (vertexFile.absolutePath() != fragmentFile.absolutePath()) {
1025 emit log(
LOGERR,
"Cannot set shader. Currently shader files have to be in the same folder.");
1029 if (_shader.pickVertexShader.length() && _shader.pickFragmentShader.length())
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.");
1037 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1039 object->shaderNode()->setShader(_drawMode,
1040 vertexFile.fileName().toStdString(),
1041 fragmentFile.fileName().toStdString(),
1042 pickVertexFile.fileName().toStdString(),
1043 pickFragmentFile.fileName().toStdString());
1047 object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
1048 object->shaderNode()->setShader(_drawMode, vertexFile.fileName().toStdString(), fragmentFile.fileName().toStdString());
1054 if (_shader.hasUniforms) {
1056 if ( shader == 0 ) {
1057 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1061 for (
int u=0; u < _shader.uniforms.count(); u++) {
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);
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);
1077 std::cerr <<
"Error: handling of uniformType '" << _shader.uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1090 if ( OpenFlipper::Options::nogui() )
1097 for (
int i = 0 ; i < (int)
shaderList_.size(); ++i) {
1104 if ( index == -1 ) {
1105 std::cerr <<
"Error: Shader not found! " << std::endl;
1109 std::vector <QString> mode;
1110 mode.push_back(_drawMode);
1122 return QStringList();
1125 QString ViewControlPlugin::getUniformType(QString _shader, QString _uniform ){
1130 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1138 QString ViewControlPlugin::getUniformDefault(QString _shader, QString _uniform ){
1143 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1151 QString ViewControlPlugin::getUniformMin(QString _shader, QString _uniform ){
1156 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1164 QString ViewControlPlugin::getUniformMax(QString _shader, QString _uniform ){
1169 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++)
1193 if ( shader == 0 ) {
1194 std::cerr <<
"Error: Unable to get shader for shader mode" << std::endl;
1198 for (
int u=0; u <
shaderList_[i].uniforms.count(); u++){
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() );
1216 std::cerr <<
"Error: handling of uniformType '" <<
shaderList_[i].uniformTypes[u].toStdString() <<
"' not yet implemented" << std::endl;
1252 if ( _viewer == PluginFunctions::ALL_VIEWERS )
1255 else if ( _viewer == PluginFunctions::ACTIVE_VIEWER )
1257 else if ( _viewer >= 0 && _viewer < PluginFunctions::viewers( ) )
1260 std::cerr <<
"Illegal viewer requested! " << std::endl;
1271 QStringList list = _mode.split(
';');
1273 std::vector< QString > drawModeList;
1275 for (
int i = 0 ; i < list.size() ; ++i )
1276 drawModeList.push_back(list[i]);
1292 QStringList list = _mode.split(
';');
1294 std::vector< QString > drawModeList;
1296 for (
int i = 0 ; i < list.size() ; ++i )
1297 drawModeList.push_back(list[i]);
1332 void ViewControlPlugin::setView(
int _mode,
int _viewer ) {
1335 case PluginFunctions::VIEW_TOP :
1338 case PluginFunctions::VIEW_BOTTOM :
1341 case PluginFunctions::VIEW_LEFT :
1344 case PluginFunctions::VIEW_RIGHT :
1347 case PluginFunctions::VIEW_FRONT :
1350 case PluginFunctions::VIEW_BACK :
1354 emit log(
LOGERR,
"ViewControl: Unknown view mode: " + QString::number(_mode));
1363 void ViewControlPlugin::setView(QAction* _action) {
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!");
1376 void ViewControlPlugin::setEyePosition(
Vector _eye){
1380 PluginFunctions::ACTIVE_VIEWER);
1436 if ( !_orthogonal) {
1443 emit log(
LOGERR,tr(
"setCoordsysProjection(): Could not find coordsys node, thus its projection mode will not be toggled."));
1448 void ViewControlPlugin::setTwoSidedLighting(
bool _enabled) {
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",
1477 QStringList(
"DrawMode"), QStringList(
"the drawMode ( ; separated list )"));
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(
","));
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"));
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"));
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"));
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"));
1505 emit setSlotDescription(
"setFOVY(double)",
"Set fovy angle of projection for all viewers.",
1506 QStringList(
"fovy"), QStringList(
"FOVY angle"));
1508 emit setSlotDescription(
"setCoordsysProjection(bool)",
"Set the projection mode of the coordinate system.",
1509 QStringList(
"orthogonal"), QStringList(
"If true, orthogonal projection otherwise perspective projection"));
1511 emit setSlotDescription(
"upVector()",
"Get the current upVector.",
1512 QStringList(), QStringList());
1514 emit setSlotDescription(
"upVector(int)",
"Get the current upVector of a specific viewer.",
1515 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1517 emit setSlotDescription(
"eyePosition()",
"Get the current eyePosition.",
1518 QStringList(), QStringList());
1520 emit setSlotDescription(
"eyePosition(int)",
"Get the current eyePosition of a specific viewer.",
1521 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1523 emit setSlotDescription(
"sceneCenter()",
"Get the current sceneCenter.",
1524 QStringList(), QStringList());
1526 emit setSlotDescription(
"sceneCenter(int)",
"Get the current sceneCenter of a specific viewer.",
1527 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1529 emit setSlotDescription(
"viewingDirection()",
"Get the current viewingDirection.",
1530 QStringList(), QStringList());
1532 emit setSlotDescription(
"viewingDirection(int)",
"Get the current viewingDirection of a specific viewer.",
1533 QStringList(
"ViewerId"), QStringList(
"Id of the viewer"));
1535 emit setSlotDescription(
"setTwoSidedLighting(bool)",
"Enable or disable two sided lighting.",
1536 QStringList(
"enabled"), QStringList(
"Specifies whether to enable or disable two sided lighting."));
1541 #if QT_VERSION < 0x050000
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.
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.
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.
DrawMode DEFAULT
use the default (global) draw mode and not the node's own.
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.
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.
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.
void disableShader(DrawModes::DrawMode _drawmode)
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.
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
DrawModes::DrawMode drawMode() const
Get the collected draw modes.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
bool dataType(DataType _type) const
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.
void hideFeatures(bool _hide)
Hide or show the feature Node of the object.
QStringList getUniforms(QString _shader)
get information about available uniforms for a given shader
bool selectionVisible()
return if the selections are currently visible
void viewHome(int _viewer)
Go to home position.
void use()
Enables the program object for using.
Class for the handling of simple configuration files.
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.
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.
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.
void hideSelection(bool _hide)
Hide or show the selection Node of the object.
ProjectionMode getProjectionMode() const
get current projection mode
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.
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)
void showAreas(StatusBits _bits, int _id, bool _state)
Show or hide modeling areas.
#define DATA_TRIANGLE_MESH
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.
void viewAll(int _viewer)
View the whole scene.
ChildIter find(BaseNode *_node)