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
62 //=================================================================================
63 // class : ToolsGUI_CatalogGeneratorDlg()
64 // purpose : Constructor
65 //=================================================================================
66 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
67 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
70 setName( "ToolsGUI_CatalogGeneratorDlg" );
72 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
73 setSizeGripEnabled( TRUE );
75 QGridLayout* aTopLayout = new QGridLayout(this);
76 aTopLayout->setMargin(MARGIN_SIZE);
77 aTopLayout->setSpacing(SPACING_SIZE);
79 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
80 filesGrp->setColumnLayout( 0, Qt::Vertical );
81 filesGrp->layout()->setSpacing( 0 );
82 filesGrp->layout()->setMargin( 0 );
83 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
84 filesGrpLayout->setAlignment( Qt::AlignTop );
85 filesGrpLayout->setSpacing( SPACING_SIZE );
86 filesGrpLayout->setMargin( MARGIN_SIZE );
88 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
89 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
91 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
92 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
93 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
95 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
96 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
97 // QFontMetrics fm(myBrowseIdlBtn->font());
98 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
99 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
101 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
102 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
103 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
104 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
105 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
106 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
108 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
109 supplGrp->setColumnLayout( 0, Qt::Vertical );
110 supplGrp->layout()->setSpacing( 0 );
111 supplGrp->layout()->setMargin( 0 );
112 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
113 supplGrpLayout->setAlignment( Qt::AlignTop );
114 supplGrpLayout->setSpacing( SPACING_SIZE );
115 supplGrpLayout->setMargin( MARGIN_SIZE );
117 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
119 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
120 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
121 myAuthorEdit->setMinimumSize( myMinimumSize );
123 OSD_Process aProcess;
124 myAuthorEdit->setText(aProcess.UserName().ToCString());
126 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
127 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
128 myVersionEdit->setMinimumSize( myMinimumSize );
129 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
130 myVersionEdit->setText(aList.last());
132 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
133 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
134 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
136 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
138 myCompName = new QLineEdit(supplGrp , "myCompName");
139 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
140 myCompName->setMinimumSize( myMinimumSize );
142 myCompUserName = new QLineEdit(supplGrp , "myCompUserName");
143 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
144 myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
146 myCompType = new QLineEdit(supplGrp , "myCompType");
147 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
148 myCompType->setMinimumSize( myMinimumSize );
149 myCompType->setText("OTHER");
151 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
152 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
153 myCompMultiStd->setMinimumSize( myMinimumSize );
154 myCompMultiStd->setText("1");
155 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
156 myCompMultiStd->setValidator(ivalidator);
158 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
159 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
160 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
161 supplGrpLayout->addWidget(myCompName,0,3);
162 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
163 supplGrpLayout->addWidget(myCompUserName,0,5);
164 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
165 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
166 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
167 supplGrpLayout->addWidget(myCompMultiStd,1,3);
168 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
169 supplGrpLayout->addWidget(myCompType,1,5);
170 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
171 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
172 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
175 QHBoxLayout* aBtnLayout = new QHBoxLayout;
176 aBtnLayout->setSpacing( SPACING_SIZE );
177 aBtnLayout->setMargin( 0 );
179 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
180 myApplyBtn->setAutoDefault( true );
181 myApplyBtn->setDefault( true );
182 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
183 myCloseBtn->setAutoDefault( true );
185 aBtnLayout->addWidget( myApplyBtn );
186 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
187 aBtnLayout->addWidget( myCloseBtn );
189 aTopLayout->addWidget( filesGrp, 0, 0 );
190 aTopLayout->addWidget( supplGrp, 1, 0 );
191 aTopLayout->addLayout( aBtnLayout, 2, 0 );
193 /* signals and slots connections */
194 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
195 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
196 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
197 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
198 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
199 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
200 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
205 //=================================================================================
206 // function : ~ToolsGUI_CatalogGeneratorDlg()
207 // purpose : destructor
208 //=================================================================================
209 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
213 //=================================================================================
214 // function : getIdlFile()
215 // purpose : gets IDL file name entered
216 //=================================================================================
217 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
219 return myIdlEdit->text().stripWhiteSpace();
222 //=================================================================================
223 // function : getXmlFile()
224 // purpose : gets XML file name entered
225 //=================================================================================
226 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
228 return myXmlEdit->text().stripWhiteSpace();
231 //=================================================================================
232 // function : getPngFile()
233 // purpose : gets PNG file name entered
234 //=================================================================================
235 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
237 return myPngEdit->text().stripWhiteSpace();
240 //=================================================================================
241 // function : getAuthor()
242 // purpose : gets author
243 //=================================================================================
244 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
246 return myAuthorEdit->text().stripWhiteSpace();
249 //=================================================================================
250 // function : getVersion()
251 // purpose : gets version number
252 //=================================================================================
253 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
255 return myVersionEdit->text().stripWhiteSpace();
258 //=================================================================================
259 // function : getCompName()
260 // purpose : gets name of the component
261 //=================================================================================
262 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
264 return myCompName->text().stripWhiteSpace();
267 //=================================================================================
268 // function : getCompUserName()
269 // purpose : gets username of the component
270 //=================================================================================
271 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
273 return myCompUserName->text().stripWhiteSpace();
276 //=================================================================================
277 // function : getCompType()
278 // purpose : gets type of the component
279 //=================================================================================
280 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
282 return myCompMultiStd->text().stripWhiteSpace();
284 //=================================================================================
285 // function : getComptype()
286 // purpose : gets type of the component
287 //=================================================================================
288 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
290 return myCompType->text().stripWhiteSpace();
293 //=================================================================================
294 // function : getIdlPath()
295 // purpose : gets IDL path of modules
296 //=================================================================================
297 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
299 cout << "QAD_Desktop::getCatalogue() is not implemented!!";
301 return QString( "" );
303 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
304 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
306 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
307 aCatalog->GetComponentIconeList();
309 QString IDLpath = "";
311 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
312 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
315 if (dir = getenv( modulename + "_ROOT_DIR")) {
316 IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) +
317 SUIT_Tools::addSlash("idl") +
318 SUIT_Tools::addSlash("salome")) + " ";
322 // MESSAGE ( " IDLpath = " << IDLpath);
328 //=================================================================================
329 // function : onBrowseBtnClicked()
330 // purpose : <...> (Browse) buttons slot
331 //=================================================================================
332 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
334 QPushButton* send = (QPushButton*)sender();
336 SUIT_Application* app = SUIT_Session::session()->activeApplication();
338 if ( send == myBrowseIdlBtn ) {
339 QString file = app->getFileName( true, myIdlEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
340 if ( !file.isEmpty() ) {
341 myIdlEdit->setText(file);
344 else if ( send == myBrowseXmlBtn ) {
345 QString file = app->getFileName( false, myXmlEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
346 if ( !file.isEmpty() ) {
347 myXmlEdit->setText(file);
349 } else if ( send == myBrowsePngBtn ) {
350 QString file = app->getFileName( true, myPngEdit->text().stripWhiteSpace(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
351 if ( !file.isEmpty() ) {
352 myPngEdit->setText(file);
359 //=================================================================================
360 // function : updateButtonState()
361 // purpose : Updates <OK> button's state
362 //=================================================================================
363 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
365 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
366 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
369 //=================================================================================
370 // function : onApply()
371 // purpose : <Apply> button slot, performs IDL->XML conversion
372 //=================================================================================
373 void ToolsGUI_CatalogGeneratorDlg::onApply()
375 QString IDLpath = getIdlPath();
376 QString XmlFile = getXmlFile();
377 QString IdlFile = getIdlFile();
378 QString Author = getAuthor();
379 QString Version = getVersion();
380 QString PngFile = getPngFile();
381 QString CompName = getCompName(); //gets component name
382 QString CompUserName = getCompUserName(); //gets component username
383 QString CompType = getCompType(); //gets component type
384 QString CompMultiStd = getCompMultiStd();
386 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
387 if ( !QFile::exists( IdlFile ) ) {
388 SUIT_MessageBox::error1( this,
389 tr("TOOLS_ERR_ERROR"),
390 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
391 tr ("TOOLS_BUT_OK") );
394 QString command = "";
395 if ( getenv("KERNEL_ROOT_DIR") )
396 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
398 SUIT_MessageBox::error1( this,
399 tr("TOOLS_ERR_ERROR"),
400 tr("KERNEL_ROOT_DIR variable is not defined"),
401 tr("TOOLS_BUT_OK") );
404 if (!Author.isEmpty()) command += ",author=" + Author;
405 if (!Version.isEmpty()) command += ",version=" + Version;
406 if (!PngFile.isEmpty()) {
407 OSD_Path aPath((Standard_CString)PngFile.latin1());
408 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
409 command += QString(",icon=") + QString(aFile.ToCString());
411 if (!CompName.isEmpty()) command += ",name=" + CompName;
412 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
413 if (!CompType.isEmpty()) command += ",type=" + CompType;
414 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
415 command += " " + IdlFile;
416 MESSAGE( "shell command is : " << command );
418 res = system( ( char* )( command.latin1() ) );
420 MESSAGE( "work failed (system command result = " << res );
421 } else if (res == 217) {
422 MESSAGE( "shell exec failed (system command result = " << res );