1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME TOOLSGUI : implementation of desktop "Tools" optioins
24 // File : ToolsGUI_CatalogGeneratorDlg.cxx
25 // Author : Nicolas REJNERI
27 #include "ToolsGUI_CatalogGeneratorDlg.h"
29 #include "SUIT_Application.h"
30 #include "SUIT_MessageBox.h"
31 //#include "SUIT_Tools.h"
32 #include "SUIT_Session.h"
38 #include <QPushButton>
39 #include <QGridLayout>
41 #include <QStringList>
43 #include <QIntValidator>
46 #include <OSD_Process.hxx>
47 #include <OSD_Path.hxx>
48 #include <TCollection_AsciiString.hxx>
49 #include <Standard_CString.hxx>
51 #include "utilities.h"
53 #define SPACING_SIZE 6
54 #define MARGIN_SIZE 11
55 #define MIN_EDIT_SIZE 250
58 \class ToolsGUI_CatalogGeneratorDlg
59 \brief A dialog box which allows converting the IDL files
60 to the XML description.
65 \param parent parent widget
67 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent )
72 setWindowTitle( 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 );
80 filesGrp->setObjectName( "filesGrp" );
81 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp );
82 filesGrpLayout->setAlignment( Qt::AlignTop );
83 filesGrpLayout->setSpacing( SPACING_SIZE );
84 filesGrpLayout->setMargin( MARGIN_SIZE );
86 myIdlEdit = new QLineEdit( filesGrp );
87 myIdlEdit->setObjectName( "myIdlEdit" );
88 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
90 myXmlEdit = new QLineEdit( filesGrp );
91 myXmlEdit->setObjectName( "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 );
96 myBrowseIdlBtn->setObjectName( "myBrowseIdlBtn" );
97 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
98 myBrowseXmlBtn->setObjectName( "myBrowseXmlBtn" );
99 // QFontMetrics fm(myBrowseIdlBtn->font());
100 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
101 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
103 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
104 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
105 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
106 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
107 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
108 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
110 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this );
111 supplGrp->setObjectName( "SupplGrp" );
112 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp );
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 );
120 myAuthorEdit->setObjectName( "myAuthorEdit" );
121 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 myAuthorEdit->setMinimumSize( myMinimumSize );
124 OSD_Process aProcess;
125 myAuthorEdit->setText(aProcess.UserName().ToCString());
127 myVersionEdit = new QLineEdit( supplGrp );
128 myVersionEdit->setObjectName( "myVersion" );
129 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
130 myVersionEdit->setMinimumSize( myMinimumSize );
131 QStringList aList = tr( "INF_VERSION" ).split(QRegExp("\\s+"), QString::SkipEmptyParts);
132 myVersionEdit->setText(aList.last());
134 myPngEdit = new QLineEdit( supplGrp );
135 myPngEdit->setObjectName( "myCompIcon" );
136 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
139 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp );
140 myBrowsePngBtn->setObjectName( "myBrowsePngBtn" );
142 myCompName = new QLineEdit( supplGrp );
143 myCompName->setObjectName( "myCompName" );
144 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
145 myCompName->setMinimumSize( myMinimumSize );
147 myCompUserName = new QLineEdit( supplGrp );
148 myCompUserName->setObjectName( "myCompUserName" );
149 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
150 myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
152 myCompType = new QLineEdit( supplGrp );
153 myCompType->setObjectName( "myCompType" );
154 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
155 myCompType->setMinimumSize( myMinimumSize );
156 myCompType->setText("OTHER");
158 myCompMultiStd = new QLineEdit( supplGrp );
159 myCompMultiStd->setObjectName( "myCompMultiStd" );
160 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161 myCompMultiStd->setMinimumSize( myMinimumSize );
162 myCompMultiStd->setText("1");
163 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
164 myCompMultiStd->setValidator(ivalidator);
166 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
167 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
168 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
169 supplGrpLayout->addWidget(myCompName,0,3);
170 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
171 supplGrpLayout->addWidget(myCompUserName,0,5);
172 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
173 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
174 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
175 supplGrpLayout->addWidget(myCompMultiStd,1,3);
176 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
177 supplGrpLayout->addWidget(myCompType,1,5);
178 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
179 supplGrpLayout->addWidget( myPngEdit, 2,1,1,4 );
180 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
182 QHBoxLayout* aBtnLayout = new QHBoxLayout;
183 aBtnLayout->setSpacing( SPACING_SIZE );
184 aBtnLayout->setMargin( 0 );
186 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this );
187 myApplyBtn->setObjectName( "myApplyBtn" );
188 myApplyBtn->setAutoDefault( true );
189 myApplyBtn->setDefault( true );
190 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this );
191 myCloseBtn->setObjectName( "myCloseBtn" );
192 myCloseBtn->setAutoDefault( true );
194 aBtnLayout->addWidget( myApplyBtn );
195 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
196 aBtnLayout->addWidget( myCloseBtn );
198 aTopLayout->addWidget( filesGrp, 0, 0 );
199 aTopLayout->addWidget( supplGrp, 1, 0 );
200 aTopLayout->addLayout( aBtnLayout, 2, 0 );
202 /* signals and slots connections */
203 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
204 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
205 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
206 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
207 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
208 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
209 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
217 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
222 \brief Get IDL file name
223 \return IDL file name entered by the user
225 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
227 return myIdlEdit->text().trimmed();
231 \brief Get XML file name
232 \return XML file name entered by the user
234 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
236 return myXmlEdit->text().trimmed();
240 \brief Get module icon file name
241 \return icon file name entered by the user
243 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
245 return myPngEdit->text().trimmed();
249 \brief Get author name
250 \return author name entered by the user
252 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
254 return myAuthorEdit->text().trimmed();
258 \brief Get version number
259 \return version number entered by the user
261 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
263 return myVersionEdit->text().trimmed();
267 \brief Get component name
268 \return name of the component entered by the user
270 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
272 return myCompName->text().trimmed();
276 \brief Get component title (user name)
277 \return title of the component entered by the user
279 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
281 return myCompUserName->text().trimmed();
285 \brief Get multistudy flag
286 \return multistudy flag for the component entered by the user
288 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
290 return myCompMultiStd->text().trimmed();
294 \brief Get component type
295 \return type of the component entered by the user
297 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
299 return myCompType->text().trimmed();
303 \brief Get IDL path of the modules
304 \return IDL path of modules
306 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
308 cout << "QAD_Desktop::getCatalogue() is not implemented!!";
310 return QString( "" );
312 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
313 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
315 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
316 aCatalog->GetComponentIconeList();
318 QString IDLpath = "";
320 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
321 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
324 if (dir = getenv( modulename + "_ROOT_DIR")) {
325 IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) +
326 SUIT_Tools::addSlash("idl") +
327 SUIT_Tools::addSlash("salome")) + " ";
331 // MESSAGE ( " IDLpath = " << IDLpath);
338 \brief Called when user presses "Browse" button
340 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
342 QPushButton* send = (QPushButton*)sender();
344 SUIT_Application* app = SUIT_Session::session()->activeApplication();
346 if ( send == myBrowseIdlBtn ) {
347 QString file = app->getFileName( true, myIdlEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
348 if ( !file.isEmpty() ) {
349 myIdlEdit->setText(file);
352 else if ( send == myBrowseXmlBtn ) {
353 QString file = app->getFileName( false, myXmlEdit->text().trimmed(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
354 if ( !file.isEmpty() ) {
355 myXmlEdit->setText(file);
357 } else if ( send == myBrowsePngBtn ) {
358 QString file = app->getFileName( true, myPngEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
359 if ( !file.isEmpty() ) {
360 myPngEdit->setText(file);
368 \brief Update <OK> button's state.
370 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
372 myApplyBtn->setEnabled( !myIdlEdit->text().trimmed().isEmpty() &&
373 !myXmlEdit->text().trimmed().isEmpty() );
377 \brief Called when user presses <Apply> button
379 Performs IDL to XML file conversion using \c runIDLparser SALOME utility.
381 void ToolsGUI_CatalogGeneratorDlg::onApply()
383 QString IDLpath = getIdlPath();
384 QString XmlFile = getXmlFile();
385 QString IdlFile = getIdlFile();
386 QString Author = getAuthor();
387 QString Version = getVersion();
388 QString PngFile = getPngFile();
389 QString CompName = getCompName(); //gets component name
390 QString CompUserName = getCompUserName(); //gets component username
391 QString CompType = getCompType(); //gets component type
392 QString CompMultiStd = getCompMultiStd();
394 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
395 if ( !QFile::exists( IdlFile ) ) {
396 SUIT_MessageBox::critical( this,
397 tr("TOOLS_ERR_ERROR"),
398 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile) );
401 QString command = "";
402 if ( getenv("KERNEL_ROOT_DIR") )
403 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
405 SUIT_MessageBox::critical( this,
406 tr("TOOLS_ERR_ERROR"),
407 tr("KERNEL_ROOT_DIR variable is not defined") );
410 if (!Author.isEmpty()) command += ",author=" + Author;
411 if (!Version.isEmpty()) command += ",version=" + Version;
412 if (!PngFile.isEmpty()) {
413 OSD_Path aPath((Standard_CString)PngFile.toLatin1().constData());
414 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
415 command += QString(",icon=") + QString(aFile.ToCString());
417 if (!CompName.isEmpty()) command += ",name=" + CompName;
418 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
419 if (!CompType.isEmpty()) command += ",type=" + CompType;
420 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
421 command += " " + IdlFile;
422 MESSAGE( "shell command is : " << command.toLatin1().constData() );
424 res = system( ( char* )( command.toLatin1().constData() ) );
426 MESSAGE( "work failed (system command result = " << res );
427 } else if (res == 217) {
428 MESSAGE( "shell exec failed (system command result = " << res );