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 "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_FileDlg.h"
35 #include "QAD_MessageBox.h"
36 #include "QAD_Tools.h"
39 #include <qlineedit.h>
40 #include <qpushbutton.h>
42 #include <qgroupbox.h>
43 #include <qstringlist.h>
45 #include <qvalidator.h>
47 #include <OSD_Process.hxx>
48 #include <OSD_Path.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <Standard_CString.hxx>
52 #include "utilities.h"
56 #define SPACING_SIZE 6
57 #define MARGIN_SIZE 11
58 #define MIN_EDIT_SIZE 250
60 //=================================================================================
61 // class : ToolsGUI_CatalogGeneratorDlg()
62 // purpose : Constructor
63 //=================================================================================
64 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
65 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
68 setName( "ToolsGUI_CatalogGeneratorDlg" );
70 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
71 setSizeGripEnabled( TRUE );
73 QGridLayout* aTopLayout = new QGridLayout(this);
74 aTopLayout->setMargin(MARGIN_SIZE);
75 aTopLayout->setSpacing(SPACING_SIZE);
77 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
78 filesGrp->setColumnLayout( 0, Qt::Vertical );
79 filesGrp->layout()->setSpacing( 0 );
80 filesGrp->layout()->setMargin( 0 );
81 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
82 filesGrpLayout->setAlignment( Qt::AlignTop );
83 filesGrpLayout->setSpacing( SPACING_SIZE );
84 filesGrpLayout->setMargin( MARGIN_SIZE );
86 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
87 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
88 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
89 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
90 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
91 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
93 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
94 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
95 // QFontMetrics fm(myBrowseIdlBtn->font());
96 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
97 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
99 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
100 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
101 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
102 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
103 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
104 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
106 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
107 supplGrp->setColumnLayout( 0, Qt::Vertical );
108 supplGrp->layout()->setSpacing( 0 );
109 supplGrp->layout()->setMargin( 0 );
110 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
111 supplGrpLayout->setAlignment( Qt::AlignTop );
112 supplGrpLayout->setSpacing( SPACING_SIZE );
113 supplGrpLayout->setMargin( MARGIN_SIZE );
115 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
117 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
118 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119 myAuthorEdit->setMinimumSize( myMinimumSize );
121 OSD_Process aProcess;
122 myAuthorEdit->setText(aProcess.UserName().ToCString());
124 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
125 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
126 myVersionEdit->setMinimumSize( myMinimumSize );
127 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
128 myVersionEdit->setText(aList.last());
130 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
131 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
132 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
134 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
136 myCompName = new QLineEdit(supplGrp , "myCompName");
137 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
138 myCompName->setMinimumSize( myMinimumSize );
140 myCompUserName = new QLineEdit(supplGrp , "myCompUserName");
141 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 myCompUserName->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
144 myCompType = new QLineEdit(supplGrp , "myCompType");
145 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
146 myCompType->setMinimumSize( myMinimumSize );
147 myCompType->setText("OTHER");
149 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
150 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
151 myCompMultiStd->setMinimumSize( myMinimumSize );
152 myCompMultiStd->setText("1");
153 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
154 myCompMultiStd->setValidator(ivalidator);
156 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
157 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
158 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
159 supplGrpLayout->addWidget(myCompName,0,3);
160 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
161 supplGrpLayout->addWidget(myCompUserName,0,5);
162 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
163 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
164 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
165 supplGrpLayout->addWidget(myCompMultiStd,1,3);
166 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
167 supplGrpLayout->addWidget(myCompType,1,5);
168 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
169 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
170 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
173 QHBoxLayout* aBtnLayout = new QHBoxLayout;
174 aBtnLayout->setSpacing( SPACING_SIZE );
175 aBtnLayout->setMargin( 0 );
177 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
178 myApplyBtn->setAutoDefault( true );
179 myApplyBtn->setDefault( true );
180 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
181 myCloseBtn->setAutoDefault( true );
183 aBtnLayout->addWidget( myApplyBtn );
184 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
185 aBtnLayout->addWidget( myCloseBtn );
187 aTopLayout->addWidget( filesGrp, 0, 0 );
188 aTopLayout->addWidget( supplGrp, 1, 0 );
189 aTopLayout->addLayout( aBtnLayout, 2, 0 );
191 /* signals and slots connections */
192 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
193 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
194 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
195 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
196 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
197 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
198 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
203 //=================================================================================
204 // function : ~ToolsGUI_CatalogGeneratorDlg()
205 // purpose : destructor
206 //=================================================================================
207 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
211 //=================================================================================
212 // function : getIdlFile()
213 // purpose : gets IDL file name entered
214 //=================================================================================
215 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
217 return myIdlEdit->text().stripWhiteSpace();
220 //=================================================================================
221 // function : getXmlFile()
222 // purpose : gets XML file name entered
223 //=================================================================================
224 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
226 return myXmlEdit->text().stripWhiteSpace();
229 //=================================================================================
230 // function : getPngFile()
231 // purpose : gets PNG file name entered
232 //=================================================================================
233 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
235 return myPngEdit->text().stripWhiteSpace();
238 //=================================================================================
239 // function : getAuthor()
240 // purpose : gets author
241 //=================================================================================
242 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
244 return myAuthorEdit->text().stripWhiteSpace();
247 //=================================================================================
248 // function : getVersion()
249 // purpose : gets version number
250 //=================================================================================
251 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
253 return myVersionEdit->text().stripWhiteSpace();
256 //=================================================================================
257 // function : getCompName()
258 // purpose : gets name of the component
259 //=================================================================================
260 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
262 return myCompName->text().stripWhiteSpace();
265 //=================================================================================
266 // function : getCompUserName()
267 // purpose : gets username of the component
268 //=================================================================================
269 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
271 return myCompUserName->text().stripWhiteSpace();
274 //=================================================================================
275 // function : getCompType()
276 // purpose : gets type of the component
277 //=================================================================================
278 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
280 return myCompMultiStd->text().stripWhiteSpace();
282 //=================================================================================
283 // function : getComptype()
284 // purpose : gets type of the component
285 //=================================================================================
286 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
288 return myCompType->text().stripWhiteSpace();
291 //=================================================================================
292 // function : getIdlPath()
293 // purpose : gets IDL path of modules
294 //=================================================================================
295 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
297 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
298 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue());
300 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
301 aCatalog->GetComponentIconeList();
303 QString IDLpath = "";
305 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
306 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
309 if (dir = getenv( modulename + "_ROOT_DIR")) {
310 IDLpath = IDLpath + "-I" + QAD_Tools::addSlash( QAD_Tools::addSlash(dir) +
311 QAD_Tools::addSlash("idl") +
312 QAD_Tools::addSlash("salome")) + " ";
316 // MESSAGE ( " IDLpath = " << IDLpath);
321 //=================================================================================
322 // function : onBrowseBtnClicked()
323 // purpose : <...> (Browse) buttons slot
324 //=================================================================================
325 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
327 QPushButton* send = (QPushButton*)sender();
329 if ( send == myBrowseIdlBtn ) {
330 QString file = myIdlEdit->text().stripWhiteSpace();
331 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
333 tr("TOOLS_MEN_IMPORT_IDL"),
334 tr("TOOLS_MEN_IMPORT"),
336 if ( !file.isEmpty() ) {
337 myIdlEdit->setText(file);
340 else if ( send == myBrowseXmlBtn ) {
341 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
342 myXmlEdit->text().stripWhiteSpace(),
343 tr("TOOLS_MEN_EXPORT_XML"),
344 tr("TOOLS_MEN_EXPORT"),
346 if ( !file.isEmpty() ) {
347 myXmlEdit->setText(file);
349 } else if ( send == myBrowsePngBtn ) {
350 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
351 myXmlEdit->text().stripWhiteSpace(),
352 tr("TOOLS_MEN_IMPORT_PNG"),
353 tr("TOOLS_MEN_IMPORT"),
355 if ( !file.isEmpty() ) {
356 myPngEdit->setText(file);
363 //=================================================================================
364 // function : updateButtonState()
365 // purpose : Updates <OK> button's state
366 //=================================================================================
367 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
369 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
370 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
373 //=================================================================================
374 // function : onApply()
375 // purpose : <Apply> button slot, performs IDL->XML conversion
376 //=================================================================================
377 void ToolsGUI_CatalogGeneratorDlg::onApply()
379 QString IDLpath = getIdlPath();
380 QString XmlFile = getXmlFile();
381 QString IdlFile = getIdlFile();
382 QString Author = getAuthor();
383 QString Version = getVersion();
384 QString PngFile = getPngFile();
385 QString CompName = getCompName(); //gets component name
386 QString CompUserName = getCompUserName(); //gets component username
387 QString CompType = getCompType(); //gets component type
388 QString CompMultiStd = getCompMultiStd();
390 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
391 if ( !QFile::exists( IdlFile ) ) {
392 QAD_MessageBox::error1( this,
393 tr("TOOLS_ERR_ERROR"),
394 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
395 tr ("TOOLS_BUT_OK") );
398 QString command = "";
399 if ( getenv("KERNEL_ROOT_DIR") )
400 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
402 QAD_MessageBox::error1( this,
403 tr("TOOLS_ERR_ERROR"),
404 tr("KERNEL_ROOT_DIR variable is not defined"),
405 tr("TOOLS_BUT_OK") );
408 if (!Author.isEmpty()) command += ",author=" + Author;
409 if (!Version.isEmpty()) command += ",version=" + Version;
410 if (!PngFile.isEmpty()) {
411 OSD_Path aPath((Standard_CString)PngFile.latin1());
412 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
413 command += QString(",icon=") + QString(aFile.ToCString());
415 if (!CompName.isEmpty()) command += ",name=" + CompName;
416 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
417 if (!CompType.isEmpty()) command += ",type=" + CompType;
418 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
419 command += " " + IdlFile;
420 MESSAGE( "shell command is : " << command );
422 res = system( ( char* )( command.latin1() ) );
424 MESSAGE( "work failed (system command result = " << res );
425 } else if (res == 217) {
426 MESSAGE( "shell exec failed (system command result = " << res );