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>
53 #define SPACING_SIZE 6
54 #define MARGIN_SIZE 11
55 #define MIN_EDIT_SIZE 250
57 //=================================================================================
58 // class : ToolsGUI_CatalogGeneratorDlg()
59 // purpose : Constructor
60 //=================================================================================
61 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
62 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
65 setName( "ToolsGUI_CatalogGeneratorDlg" );
67 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
68 setSizeGripEnabled( TRUE );
70 QGridLayout* aTopLayout = new QGridLayout(this);
71 aTopLayout->setMargin(MARGIN_SIZE);
72 aTopLayout->setSpacing(SPACING_SIZE);
74 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
75 filesGrp->setColumnLayout( 0, Qt::Vertical );
76 filesGrp->layout()->setSpacing( 0 );
77 filesGrp->layout()->setMargin( 0 );
78 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
79 filesGrpLayout->setAlignment( Qt::AlignTop );
80 filesGrpLayout->setSpacing( SPACING_SIZE );
81 filesGrpLayout->setMargin( MARGIN_SIZE );
83 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
84 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
85 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
86 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
87 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
88 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
90 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
91 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
92 // QFontMetrics fm(myBrowseIdlBtn->font());
93 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
94 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
96 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
97 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
98 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
99 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
100 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
101 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
103 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
104 supplGrp->setColumnLayout( 0, Qt::Vertical );
105 supplGrp->layout()->setSpacing( 0 );
106 supplGrp->layout()->setMargin( 0 );
107 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
108 supplGrpLayout->setAlignment( Qt::AlignTop );
109 supplGrpLayout->setSpacing( SPACING_SIZE );
110 supplGrpLayout->setMargin( MARGIN_SIZE );
112 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
114 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
115 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
116 myAuthorEdit->setMinimumSize( myMinimumSize );
118 OSD_Process aProcess;
119 myAuthorEdit->setText(aProcess.UserName().ToCString());
121 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
122 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123 myVersionEdit->setMinimumSize( myMinimumSize );
124 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
125 myVersionEdit->setText(aList.last());
126 QDoubleValidator *validator = new QDoubleValidator(myVersionEdit);
127 myVersionEdit->setValidator(validator);
129 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
130 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
133 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
135 myCompName = new QLineEdit(supplGrp , "myCompName");
136 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 myCompName->setMinimumSize( myMinimumSize );
139 myCompUserName = new QLineEdit(supplGrp , "myCompUserName");
140 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
141 myCompUserName->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
143 myCompType = new QLineEdit(supplGrp , "myCompType");
144 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
145 myCompType->setMinimumSize( myMinimumSize );
146 myCompType->setText("OTHER");
148 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
149 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
150 myCompMultiStd->setMinimumSize( myMinimumSize );
151 myCompMultiStd->setText("1");
152 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
153 myCompMultiStd->setValidator(ivalidator);
155 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
156 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
157 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
158 supplGrpLayout->addWidget(myCompName,0,3);
159 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
160 supplGrpLayout->addWidget(myCompUserName,0,5);
161 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
162 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
163 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
164 supplGrpLayout->addWidget(myCompMultiStd,1,3);
165 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
166 supplGrpLayout->addWidget(myCompType,1,5);
167 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
168 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
169 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
172 QHBoxLayout* aBtnLayout = new QHBoxLayout;
173 aBtnLayout->setSpacing( SPACING_SIZE );
174 aBtnLayout->setMargin( 0 );
176 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
177 myApplyBtn->setAutoDefault( true );
178 myApplyBtn->setDefault( true );
179 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
180 myCloseBtn->setAutoDefault( true );
182 aBtnLayout->addWidget( myApplyBtn );
183 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
184 aBtnLayout->addWidget( myCloseBtn );
186 aTopLayout->addWidget( filesGrp, 0, 0 );
187 aTopLayout->addWidget( supplGrp, 1, 0 );
188 aTopLayout->addLayout( aBtnLayout, 2, 0 );
190 /* signals and slots connections */
191 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
192 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
193 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
194 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
195 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
196 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
197 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
202 //=================================================================================
203 // function : ~ToolsGUI_CatalogGeneratorDlg()
204 // purpose : destructor
205 //=================================================================================
206 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
210 //=================================================================================
211 // function : getIdlFile()
212 // purpose : gets IDL file name entered
213 //=================================================================================
214 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
216 return myIdlEdit->text().stripWhiteSpace();
219 //=================================================================================
220 // function : getXmlFile()
221 // purpose : gets XML file name entered
222 //=================================================================================
223 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
225 return myXmlEdit->text().stripWhiteSpace();
228 //=================================================================================
229 // function : getPngFile()
230 // purpose : gets PNG file name entered
231 //=================================================================================
232 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
234 return myPngEdit->text().stripWhiteSpace();
237 //=================================================================================
238 // function : getAuthor()
239 // purpose : gets author
240 //=================================================================================
241 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
243 return myAuthorEdit->text().stripWhiteSpace();
246 //=================================================================================
247 // function : getVersion()
248 // purpose : gets version number
249 //=================================================================================
250 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
252 return myVersionEdit->text().stripWhiteSpace();
255 //=================================================================================
256 // function : getCompName()
257 // purpose : gets name of the component
258 //=================================================================================
259 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
261 return myCompName->text().stripWhiteSpace();
264 //=================================================================================
265 // function : getCompUserName()
266 // purpose : gets username of the component
267 //=================================================================================
268 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
270 return myCompUserName->text().stripWhiteSpace();
273 //=================================================================================
274 // function : getCompType()
275 // purpose : gets type of the component
276 //=================================================================================
277 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
279 return myCompMultiStd->text().stripWhiteSpace();
281 //=================================================================================
282 // function : getComptype()
283 // purpose : gets type of the component
284 //=================================================================================
285 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
287 return myCompType->text().stripWhiteSpace();
290 //=================================================================================
291 // function : getIdlPath()
292 // purpose : gets IDL path of modules
293 //=================================================================================
294 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
296 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
297 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue());
299 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
300 aCatalog->GetComponentIconeList();
302 QString IDLpath = "";
304 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
305 QString modulename = strdup(list_composants[ind].modulename) ;
308 if (dir = getenv( modulename + "_ROOT_DIR")) {
309 IDLpath = IDLpath + "-I" + QAD_Tools::addSlash( QAD_Tools::addSlash(dir) +
310 QAD_Tools::addSlash("idl") +
311 QAD_Tools::addSlash("salome")) + " ";
315 // MESSAGE ( " IDLpath = " << IDLpath);
320 //=================================================================================
321 // function : onBrowseBtnClicked()
322 // purpose : <...> (Browse) buttons slot
323 //=================================================================================
324 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
326 QPushButton* send = (QPushButton*)sender();
328 if ( send == myBrowseIdlBtn ) {
329 QString file = myIdlEdit->text().stripWhiteSpace();
330 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
332 tr("TOOLS_MEN_IMPORT_IDL"),
333 tr("TOOLS_MEN_IMPORT"),
335 if ( !file.isEmpty() ) {
336 myIdlEdit->setText(file);
339 else if ( send == myBrowseXmlBtn ) {
340 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
341 myXmlEdit->text().stripWhiteSpace(),
342 tr("TOOLS_MEN_EXPORT_XML"),
343 tr("TOOLS_MEN_EXPORT"),
345 if ( !file.isEmpty() ) {
346 myXmlEdit->setText(file);
348 } else if ( send == myBrowsePngBtn ) {
349 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
350 myXmlEdit->text().stripWhiteSpace(),
351 tr("TOOLS_MEN_IMPORT_PNG"),
352 tr("TOOLS_MEN_IMPORT"),
354 if ( !file.isEmpty() ) {
355 myPngEdit->setText(file);
362 //=================================================================================
363 // function : updateButtonState()
364 // purpose : Updates <OK> button's state
365 //=================================================================================
366 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
368 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
369 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
372 //=================================================================================
373 // function : onApply()
374 // purpose : <Apply> button slot, performs IDL->XML conversion
375 //=================================================================================
376 void ToolsGUI_CatalogGeneratorDlg::onApply()
378 QString IDLpath = getIdlPath();
379 QString XmlFile = getXmlFile();
380 QString IdlFile = getIdlFile();
381 QString Author = getAuthor();
382 QString Version = getVersion();
383 QString PngFile = getPngFile();
384 QString CompName = getCompName(); //gets component name
385 QString CompUserName = getCompUserName(); //gets component username
386 QString CompType = getCompType(); //gets component type
387 QString CompMultiStd = getCompMultiStd();
389 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
390 if ( !QFile::exists( IdlFile ) ) {
391 QAD_MessageBox::error1( this,
392 tr("TOOLS_ERR_ERROR"),
393 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
394 tr ("TOOLS_BUT_OK") );
397 QString command = "";
398 if ( getenv("KERNEL_ROOT_DIR") )
399 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser " + IDLpath + " -Wbcatalog=" + XmlFile;
401 QAD_MessageBox::error1( this,
402 tr("TOOLS_ERR_ERROR"),
403 tr("KERNEL_ROOT_DIR variable is not defined"),
404 tr("TOOLS_BUT_OK") );
407 if (!Author.isEmpty()) command += ",author=" + Author;
408 if (!Version.isEmpty()) command += ",version=" + Version;
409 if (!PngFile.isEmpty()) {
410 OSD_Path aPath((Standard_CString)PngFile.latin1());
411 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
412 command += QString(",icon=") + QString(aFile.ToCString());
414 if (!CompName.isEmpty()) command += ",name=" + CompName;
415 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
416 if (!CompType.isEmpty()) command += ",type=" + CompType;
417 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
418 command += " " + IdlFile;
419 MESSAGE( "shell command is : " << command );
421 res = system( ( char* )( command.latin1() ) );
423 MESSAGE( "work failed (system command result = " << res );
424 } else if (res == 217) {
425 MESSAGE( "shell exec failed (system command result = " << res );