1 // SALOME TOOLSGUI : implementation of desktop "Tools" optioins
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : ToolsGUI_CatalogGeneratorDlg.cxx
25 // Author : Nicolas REJNERI
26 // Modified : Marc TAJCHMAN
30 #include "ToolsGUI_CatalogGeneratorDlg.h"
32 #include "SUIT_Application.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_MessageBox.h"
35 #include "SUIT_Tools.h"
36 #include "SUIT_Session.h"
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
43 #include <qgroupbox.h>
44 #include <qstringlist.h>
46 #include <qvalidator.h>
49 #include <OSD_Process.hxx>
50 #include <OSD_Path.hxx>
51 #include <TCollection_AsciiString.hxx>
52 #include <Standard_CString.hxx>
54 #include "utilities.h"
58 #define SPACING_SIZE 6
59 #define MARGIN_SIZE 11
60 #define MIN_EDIT_SIZE 250
65 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
66 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
69 setName( "ToolsGUI_CatalogGeneratorDlg" );
71 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
72 setSizeGripEnabled( TRUE );
74 QGridLayout* aTopLayout = new QGridLayout(this);
75 aTopLayout->setMargin(MARGIN_SIZE);
76 aTopLayout->setSpacing(SPACING_SIZE);
78 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
79 filesGrp->setColumnLayout( 0, Qt::Vertical );
80 filesGrp->layout()->setSpacing( 0 );
81 filesGrp->layout()->setMargin( 0 );
82 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
83 filesGrpLayout->setAlignment( Qt::AlignTop );
84 filesGrpLayout->setSpacing( SPACING_SIZE );
85 filesGrpLayout->setMargin( MARGIN_SIZE );
87 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
88 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
90 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
91 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
92 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
94 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
95 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
96 // QFontMetrics fm(myBrowseIdlBtn->font());
97 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
98 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
100 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
101 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
102 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
103 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
104 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
105 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
107 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
108 supplGrp->setColumnLayout( 0, Qt::Vertical );
109 supplGrp->layout()->setSpacing( 0 );
110 supplGrp->layout()->setMargin( 0 );
111 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
112 supplGrpLayout->setAlignment( Qt::AlignTop );
113 supplGrpLayout->setSpacing( SPACING_SIZE );
114 supplGrpLayout->setMargin( MARGIN_SIZE );
116 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
118 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
119 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
120 myAuthorEdit->setMinimumSize( myMinimumSize );
122 OSD_Process aProcess;
123 myAuthorEdit->setText(aProcess.UserName().ToCString());
125 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
126 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127 myVersionEdit->setMinimumSize( myMinimumSize );
128 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
129 myVersionEdit->setText(aList.last());
131 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
132 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
133 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
135 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
137 myCompName = new QLineEdit(supplGrp , "myCompName");
138 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
139 myCompName->setMinimumSize( myMinimumSize );
141 myCompUserName = new QLineEdit(supplGrp , "myCompUserName");
142 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
143 myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
145 myCompType = new QLineEdit(supplGrp , "myCompType");
146 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 myCompType->setMinimumSize( myMinimumSize );
148 myCompType->setText("OTHER");
150 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
151 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
152 myCompMultiStd->setMinimumSize( myMinimumSize );
153 myCompMultiStd->setText("1");
154 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
155 myCompMultiStd->setValidator(ivalidator);
157 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
158 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
159 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
160 supplGrpLayout->addWidget(myCompName,0,3);
161 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
162 supplGrpLayout->addWidget(myCompUserName,0,5);
163 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
164 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
165 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
166 supplGrpLayout->addWidget(myCompMultiStd,1,3);
167 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
168 supplGrpLayout->addWidget(myCompType,1,5);
169 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
170 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
171 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
174 QHBoxLayout* aBtnLayout = new QHBoxLayout;
175 aBtnLayout->setSpacing( SPACING_SIZE );
176 aBtnLayout->setMargin( 0 );
178 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
179 myApplyBtn->setAutoDefault( true );
180 myApplyBtn->setDefault( true );
181 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
182 myCloseBtn->setAutoDefault( true );
184 aBtnLayout->addWidget( myApplyBtn );
185 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
186 aBtnLayout->addWidget( myCloseBtn );
188 aTopLayout->addWidget( filesGrp, 0, 0 );
189 aTopLayout->addWidget( supplGrp, 1, 0 );
190 aTopLayout->addLayout( aBtnLayout, 2, 0 );
192 /* signals and slots connections */
193 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
194 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
195 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
196 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
197 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
198 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
199 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
207 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
212 \return IDL file name entered
214 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
216 return myIdlEdit->text().stripWhiteSpace();
220 \return XML file name entered
222 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
224 return myXmlEdit->text().stripWhiteSpace();
228 \return PNG file name entered
230 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
232 return myPngEdit->text().stripWhiteSpace();
238 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
240 return myAuthorEdit->text().stripWhiteSpace();
244 \return version number
246 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
248 return myVersionEdit->text().stripWhiteSpace();
252 \return name of the component
254 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
256 return myCompName->text().stripWhiteSpace();
260 \return username of the component
262 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
264 return myCompUserName->text().stripWhiteSpace();
268 \return type of the component
270 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
272 return myCompMultiStd->text().stripWhiteSpace();
276 \return type of the component
278 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
280 return myCompType->text().stripWhiteSpace();
284 \return IDL path of modules
286 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
288 cout << "QAD_Desktop::getCatalogue() is not implemented!!";
290 return QString( "" );
292 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
293 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
295 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
296 aCatalog->GetComponentIconeList();
298 QString IDLpath = "";
300 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
301 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
304 if (dir = getenv( modulename + "_ROOT_DIR")) {
305 IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) +
306 SUIT_Tools::addSlash("idl") +
307 SUIT_Tools::addSlash("salome")) + " ";
311 // MESSAGE ( " IDLpath = " << IDLpath);
318 SLOT: called on Browse button click
320 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
322 QPushButton* send = (QPushButton*)sender();
324 SUIT_Application* app = SUIT_Session::session()->activeApplication();
326 if ( send == myBrowseIdlBtn ) {
327 QString file = app->getFileName( true, myIdlEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
328 if ( !file.isEmpty() ) {
329 myIdlEdit->setText(file);
332 else if ( send == myBrowseXmlBtn ) {
333 QString file = app->getFileName( false, myXmlEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
334 if ( !file.isEmpty() ) {
335 myXmlEdit->setText(file);
337 } else if ( send == myBrowsePngBtn ) {
338 QString file = app->getFileName( true, myPngEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
339 if ( !file.isEmpty() ) {
340 myPngEdit->setText(file);
348 Updates <OK> button's state
350 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
352 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
353 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
357 <Apply> button slot, performs IDL->XML conversion
359 void ToolsGUI_CatalogGeneratorDlg::onApply()
361 QString IDLpath = getIdlPath();
362 QString XmlFile = getXmlFile();
363 QString IdlFile = getIdlFile();
364 QString Author = getAuthor();
365 QString Version = getVersion();
366 QString PngFile = getPngFile();
367 QString CompName = getCompName(); //gets component name
368 QString CompUserName = getCompUserName(); //gets component username
369 QString CompType = getCompType(); //gets component type
370 QString CompMultiStd = getCompMultiStd();
372 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
373 if ( !QFile::exists( IdlFile ) ) {
374 SUIT_MessageBox::error1( this,
375 tr("TOOLS_ERR_ERROR"),
376 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
377 tr ("TOOLS_BUT_OK") );
380 QString command = "";
381 if ( getenv("KERNEL_ROOT_DIR") )
382 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
384 SUIT_MessageBox::error1( this,
385 tr("TOOLS_ERR_ERROR"),
386 tr("KERNEL_ROOT_DIR variable is not defined"),
387 tr("TOOLS_BUT_OK") );
390 if (!Author.isEmpty()) command += ",author=" + Author;
391 if (!Version.isEmpty()) command += ",version=" + Version;
392 if (!PngFile.isEmpty()) {
393 OSD_Path aPath((Standard_CString)PngFile.latin1());
394 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
395 command += QString(",icon=") + QString(aFile.ToCString());
397 if (!CompName.isEmpty()) command += ",name=" + CompName;
398 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
399 if (!CompType.isEmpty()) command += ",type=" + CompType;
400 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
401 command += " " + IdlFile;
402 MESSAGE( "shell command is : " << command );
404 res = system( ( char* )( command.latin1() ) );
406 MESSAGE( "work failed (system command result = " << res );
407 } else if (res == 217) {
408 MESSAGE( "shell exec failed (system command result = " << res );