Back to index

salome-gui  6.5.0
ToolsGUI_CatalogGeneratorDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME TOOLSGUI : implementation of desktop "Tools" optioins
00024 //  File   : ToolsGUI_CatalogGeneratorDlg.cxx
00025 //  Author : Nicolas REJNERI
00026 //
00027 #include "ToolsGUI_CatalogGeneratorDlg.h"
00028 
00029 #include "SUIT_Application.h"
00030 #include "SUIT_MessageBox.h"
00031 //#include "SUIT_Tools.h"
00032 #include "SUIT_Session.h"
00033 
00034 #include <stdlib.h>
00035 
00036 #include <QLabel>
00037 #include <QLineEdit>
00038 #include <QPushButton>
00039 #include <QGridLayout>
00040 #include <QGroupBox>
00041 #include <QStringList>
00042 #include <QRegExp>
00043 #include <QIntValidator>
00044 #include <QFile>
00045 
00046 #include <OSD_Process.hxx>
00047 #include <OSD_Path.hxx>
00048 #include <TCollection_AsciiString.hxx>
00049 #include <Standard_CString.hxx>
00050 
00051 #include "utilities.h"
00052 
00053 #define SPACING_SIZE             6
00054 #define MARGIN_SIZE             11
00055 #define MIN_EDIT_SIZE          250
00056 
00067 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent )
00068 : QDialog( parent )
00069 {
00070   setModal( true );
00071 
00072   setWindowTitle( tr( "TOOLS_CATALOG_GENERATOR" ) );
00073   setSizeGripEnabled( true );
00074 
00075   QGridLayout* aTopLayout = new QGridLayout(this);
00076   aTopLayout->setMargin( MARGIN_SIZE );
00077   aTopLayout->setSpacing( SPACING_SIZE );
00078 
00079   QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this );
00080   filesGrp->setObjectName( "filesGrp" );
00081   QGridLayout* filesGrpLayout = new QGridLayout( filesGrp );
00082   filesGrpLayout->setAlignment( Qt::AlignTop );
00083   filesGrpLayout->setSpacing( SPACING_SIZE );
00084   filesGrpLayout->setMargin( MARGIN_SIZE  );
00085 
00086   myIdlEdit = new QLineEdit( filesGrp );
00087   myIdlEdit->setObjectName( "myIdlEdit" );
00088   myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00089   myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00090   myXmlEdit = new QLineEdit( filesGrp );
00091   myXmlEdit->setObjectName( "myXmlEdit" );
00092   myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00093   myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00094 
00095   myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
00096   myBrowseIdlBtn->setObjectName( "myBrowseIdlBtn" );
00097   myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
00098   myBrowseXmlBtn->setObjectName( "myBrowseXmlBtn" );
00099 //  QFontMetrics fm(myBrowseIdlBtn->font());
00100 //  myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
00101 //  myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
00102 
00103   filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
00104   filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
00105   filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
00106   filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
00107   filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
00108   filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
00109 
00110   QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" )  , this );
00111   supplGrp->setObjectName( "SupplGrp" );
00112   QGridLayout* supplGrpLayout = new QGridLayout( supplGrp );
00113   supplGrpLayout->setAlignment( Qt::AlignTop );
00114   supplGrpLayout->setSpacing( SPACING_SIZE );
00115   supplGrpLayout->setMargin( MARGIN_SIZE  );
00116 
00117   QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
00118 
00119   myAuthorEdit = new QLineEdit( supplGrp );
00120   myAuthorEdit->setObjectName( "myAuthorEdit" );
00121   myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00122   myAuthorEdit->setMinimumSize( myMinimumSize );
00123 
00124   OSD_Process aProcess;
00125   myAuthorEdit->setText(aProcess.UserName().ToCString());
00126 
00127   myVersionEdit = new QLineEdit( supplGrp );
00128   myVersionEdit->setObjectName( "myVersion" );
00129   myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00130   myVersionEdit->setMinimumSize( myMinimumSize );
00131   QStringList aList = tr( "INF_VERSION" ).split(QRegExp("\\s+"), QString::SkipEmptyParts);
00132   myVersionEdit->setText(aList.last());
00133 
00134   myPngEdit = new QLineEdit( supplGrp );
00135   myPngEdit->setObjectName( "myCompIcon" );
00136   myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00137   myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
00138 
00139   myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp );
00140   myBrowsePngBtn->setObjectName( "myBrowsePngBtn" );
00141 
00142   myCompName = new QLineEdit( supplGrp );
00143   myCompName->setObjectName( "myCompName" );
00144   myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00145   myCompName->setMinimumSize( myMinimumSize );
00146 
00147   myCompUserName = new QLineEdit( supplGrp );
00148   myCompUserName->setObjectName( "myCompUserName" );
00149   myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00150   myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
00151 
00152   myCompType = new QLineEdit( supplGrp );
00153   myCompType->setObjectName( "myCompType" );
00154   myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00155   myCompType->setMinimumSize( myMinimumSize );
00156   myCompType->setText("OTHER");
00157 
00158   myCompMultiStd = new QLineEdit( supplGrp );
00159   myCompMultiStd->setObjectName( "myCompMultiStd" );
00160   myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00161   myCompMultiStd->setMinimumSize( myMinimumSize );
00162   myCompMultiStd->setText("1");
00163   QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
00164   myCompMultiStd->setValidator(ivalidator);
00165   
00166   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
00167   supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
00168   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
00169   supplGrpLayout->addWidget(myCompName,0,3);
00170   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
00171   supplGrpLayout->addWidget(myCompUserName,0,5);
00172   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
00173   supplGrpLayout->addWidget( myVersionEdit, 1, 1);
00174   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
00175   supplGrpLayout->addWidget(myCompMultiStd,1,3);
00176   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
00177   supplGrpLayout->addWidget(myCompType,1,5);
00178   supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
00179   supplGrpLayout->addWidget( myPngEdit, 2,1,1,4 );
00180   supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
00181 
00182   QHBoxLayout* aBtnLayout = new QHBoxLayout;
00183   aBtnLayout->setSpacing( SPACING_SIZE );
00184   aBtnLayout->setMargin( 0 );
00185 
00186   myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY"  ), this );
00187   myApplyBtn->setObjectName( "myApplyBtn" );
00188   myApplyBtn->setAutoDefault( true );
00189   myApplyBtn->setDefault( true );
00190   myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this );
00191   myCloseBtn->setObjectName( "myCloseBtn" );
00192   myCloseBtn->setAutoDefault( true );
00193   
00194   aBtnLayout->addWidget( myApplyBtn );
00195   aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
00196   aBtnLayout->addWidget( myCloseBtn );
00197 
00198   aTopLayout->addWidget( filesGrp, 0, 0 );
00199   aTopLayout->addWidget( supplGrp, 1, 0 );
00200   aTopLayout->addLayout( aBtnLayout, 2, 0 ); 
00201 
00202   /* signals and slots connections */
00203   connect( myApplyBtn,     SIGNAL( clicked() ), this, SLOT( onApply() ) );
00204   connect( myCloseBtn,     SIGNAL( clicked() ), this, SLOT( reject() ) );
00205   connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
00206   connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
00207   connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
00208   connect( myIdlEdit,      SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
00209   connect( myXmlEdit,      SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
00210 
00211   updateButtonState();
00212 }
00213 
00217 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
00218 {  
00219 }
00220 
00225 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
00226 {
00227   return myIdlEdit->text().trimmed();
00228 }
00229 
00234 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
00235 {
00236   return myXmlEdit->text().trimmed();
00237 }
00238 
00243 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
00244 {
00245   return myPngEdit->text().trimmed();
00246 }
00247 
00252 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
00253 {
00254   return myAuthorEdit->text().trimmed();
00255 }
00256 
00261 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
00262 {
00263   return myVersionEdit->text().trimmed();
00264 }
00265 
00270 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
00271 {
00272   return myCompName->text().trimmed();
00273 }
00274 
00279 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
00280 {
00281   return myCompUserName->text().trimmed();
00282 }
00283 
00288 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
00289 {
00290   return myCompMultiStd->text().trimmed();
00291 }
00292 
00297 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
00298 {
00299   return myCompType->text().trimmed();
00300 }
00301 
00306 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
00307 {
00308   cout << "QAD_Desktop::getCatalogue() is not implemented!!";
00309   if ( true )
00310     return QString( "" );
00311 /*
00312   SALOME_ModuleCatalog::ModuleCatalog_var aCatalog = 
00313     SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
00314 
00315   SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
00316     aCatalog->GetComponentIconeList();
00317 
00318   QString IDLpath = "";
00319 
00320   for (unsigned int ind = 0; ind < list_composants->length();ind++) {
00321     QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
00322     
00323     QCString dir;
00324     if (dir = getenv( modulename + "_ROOT_DIR")) {
00325       IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) + 
00326                                                       SUIT_Tools::addSlash("idl") + 
00327                                                       SUIT_Tools::addSlash("salome")) + " ";
00328     }
00329   }
00330 
00331   //  MESSAGE ( " IDLpath = " << IDLpath);
00332 
00333   return IDLpath;
00334 */
00335 }
00336 
00340 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
00341 {
00342   QPushButton* send = (QPushButton*)sender();
00343   
00344   SUIT_Application* app = SUIT_Session::session()->activeApplication();
00345 
00346   if ( send == myBrowseIdlBtn ) {
00347     QString file = app->getFileName( true, myIdlEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
00348     if ( !file.isEmpty() ) {
00349       myIdlEdit->setText(file);
00350     }
00351   } 
00352   else if ( send == myBrowseXmlBtn ) {
00353     QString file = app->getFileName( false, myXmlEdit->text().trimmed(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
00354     if ( !file.isEmpty() ) {
00355       myXmlEdit->setText(file);
00356     }
00357   } else if ( send == myBrowsePngBtn ) {
00358     QString file = app->getFileName( true, myPngEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
00359     if ( !file.isEmpty() ) {
00360       myPngEdit->setText(file);
00361     
00362     }
00363   }
00364   updateButtonState();
00365 }
00366 
00370 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
00371 {
00372   myApplyBtn->setEnabled( !myIdlEdit->text().trimmed().isEmpty() && 
00373                           !myXmlEdit->text().trimmed().isEmpty() );
00374 }
00375 
00381 void ToolsGUI_CatalogGeneratorDlg::onApply()
00382 {
00383   QString IDLpath = getIdlPath();
00384   QString XmlFile = getXmlFile();
00385   QString IdlFile = getIdlFile();
00386   QString Author  = getAuthor();
00387   QString Version = getVersion();
00388   QString PngFile = getPngFile();
00389   QString CompName = getCompName(); //gets component name 
00390   QString CompUserName = getCompUserName(); //gets component username 
00391   QString CompType = getCompType(); //gets component type
00392   QString CompMultiStd = getCompMultiStd();
00393 
00394   if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
00395     if ( !QFile::exists( IdlFile ) ) {
00396       SUIT_MessageBox::critical( this, 
00397                                  tr("TOOLS_ERR_ERROR"), 
00398                                  tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile) );
00399     }
00400     else {
00401       QString command = "";
00402       if ( getenv("KERNEL_ROOT_DIR")  )
00403         command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
00404       else {
00405         SUIT_MessageBox::critical( this, 
00406                                    tr("TOOLS_ERR_ERROR"), 
00407                                    tr("KERNEL_ROOT_DIR variable is not defined") );
00408       }
00409 
00410       if (!Author.isEmpty()) command += ",author=" + Author; 
00411       if (!Version.isEmpty()) command += ",version=" + Version;
00412       if (!PngFile.isEmpty()) {
00413         OSD_Path aPath((Standard_CString)PngFile.toLatin1().constData()); 
00414         TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
00415         command += QString(",icon=") + QString(aFile.ToCString());
00416       }
00417       if (!CompName.isEmpty()) command += ",name=" + CompName;
00418       if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
00419       if (!CompType.isEmpty()) command += ",type=" + CompType;
00420       if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
00421       command += " " + IdlFile;
00422       MESSAGE( "shell command is : " << command.toLatin1().constData() );
00423       int res;
00424       res = system( ( char* )( command.toLatin1().constData() ) );
00425       if ( res == -1 ) {
00426         MESSAGE( "work failed (system command result = " << res );
00427       } else if (res == 217) {
00428         MESSAGE( "shell exec failed (system command result = " << res );
00429       }
00430     }
00431   }
00432 }