QtShaderDialog.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS QtShaderDialog - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 #include "QtShaderDialog.hh"
00055 #include "../Scenegraph/ShaderNode.hh"
00056 #include "../Scenegraph/DrawModes.hh"
00057 #include <QFileInfo>
00058 #include <QDir>
00059 
00060 //== NAMESPACES ============================================================== 
00061 
00062 
00063 namespace ACG {
00064 namespace QtWidgets {
00065 
00066 
00067 //== IMPLEMENTATION ========================================================== 
00068 
00069 
00070 QtShaderDialog::QtShaderDialog( QWidget                * _parent,
00071                                 SceneGraph::ShaderNode * _node )
00072   : QDialog( _parent ),
00073     node_(_node)
00074 {
00075   ui_.setupUi( this );
00076   
00077   unsigned int drawmode = ACG::SceneGraph::DrawModes::DEFAULT;
00078   
00079   while ( drawmode != ACG::SceneGraph::DrawModes::UNUSED )
00080   {
00081     ui_.drawModeBox->addItem( QString(ACG::SceneGraph::DrawModes::description(drawmode).c_str() ));
00082     drawmode *= 2 ;
00083   }
00084   
00085   ui_.shaderDir->setText( QString(_node->shaderDir().c_str()) );
00086   ui_.vertexShader->setText( QString(_node->vertexShaderName(ACG::SceneGraph::DrawModes::DEFAULT).c_str()) );
00087   ui_.fragmentShader->setText( QString(_node->fragmentShaderName(ACG::SceneGraph::DrawModes::DEFAULT).c_str()) ); 
00088   
00089   connect( ui_.okButton, SIGNAL( clicked() ),
00090            this, SLOT( applyChanges() ) );
00091   connect( ui_.cancelButton, SIGNAL( clicked() ),
00092            this, SLOT( reject() ) );
00093   
00094   connect( ui_.drawModeBox, SIGNAL( currentIndexChanged( int ) ),
00095            this, SLOT( comboChanged( int ) ) );
00096 }
00097 
00098 
00099 //-----------------------------------------------------------------------------
00100 
00101 
00102 void QtShaderDialog::reject()
00103 {
00104   std::cerr << "reject" << std::endl;
00105   undoChanges();
00106   QDialog::reject();
00107 }
00108 
00109 
00110 //-----------------------------------------------------------------------------
00111 
00112 
00113 void QtShaderDialog::applyChanges()
00114 {
00115   // Get and test shader directory
00116   std::string shaderDirectory("");
00117   
00118   QString shaderDir = ui_.shaderDir->text();
00119   QDir dir(shaderDir);
00120   
00121   if ( dir.exists() ) {
00122     if ( ! shaderDir.endsWith('/' ) && ! shaderDir.endsWith( '\\' ) ) {
00123       shaderDir += "/"; 
00124     }
00125     
00126     shaderDirectory = std::string( shaderDir.toUtf8() );
00127     node_->setShaderDir( shaderDirectory );
00128     
00129   } else {
00130     std::cerr << "Shader directory does not exist" << std::string( shaderDir.toUtf8() ) << std::endl; 
00131     return;
00132   }
00133   
00134   unsigned int drawMode = 1;
00135   
00136   for ( int i = 0 ; i < ui_.drawModeBox->currentIndex() ; ++i )
00137     drawMode *= 2; 
00138   
00139   node_->setShader(drawMode, 
00140                    std::string(  ui_.vertexShader->text().toUtf8() ),
00141                    std::string(  ui_.fragmentShader->text().toUtf8() ) );
00142           
00143   emit signalNodeChanged(node_);
00144   
00145   accept();
00146 }
00147 
00148 
00149 //-----------------------------------------------------------------------------
00150 
00151 
00152 void QtShaderDialog::undoChanges()
00153 {
00154   std::cerr << "undo" << std::endl;
00155   emit signalNodeChanged(node_);
00156 }
00157 
00158 void QtShaderDialog::comboChanged ( int index ) {
00159   unsigned int drawMode = 1;
00160   
00161   for ( int i = 0 ; i < index; ++i )
00162     drawMode *= 2;  
00163   
00164   QString vertexShader(node_->vertexShaderName(drawMode).c_str());
00165   QString fragmentShader(node_->fragmentShaderName(drawMode).c_str());
00166   
00167   
00168   QString shaderDir( node_->shaderDir().c_str() );
00169   vertexShader   = vertexShader.remove( shaderDir );
00170   fragmentShader = fragmentShader.remove( shaderDir );
00171   
00172   ui_.vertexShader->setText( vertexShader );
00173   ui_.fragmentShader->setText( fragmentShader );
00174 }
00175 
00176 
00177 //=============================================================================
00178 } // namespace QtWidgets
00179 } // namespace ACG
00180 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .