1 // Copyright (C) 2007-2019 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>
48 #include <OSD_Process.hxx>
49 #include <OSD_Path.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <Standard_CString.hxx>
53 #include "utilities.h"
55 #define SPACING_SIZE 6
56 #define MARGIN_SIZE 11
57 #define MIN_EDIT_SIZE 250
60 \class ToolsGUI_CatalogGeneratorDlg
61 \brief A dialog box which allows converting the IDL files
62 to the XML description.
67 \param parent parent widget
69 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent )
74 setWindowTitle( tr( "TOOLS_CATALOG_GENERATOR" ) );
75 setSizeGripEnabled( true );
77 QGridLayout* aTopLayout = new QGridLayout(this);
78 aTopLayout->setMargin( MARGIN_SIZE );
79 aTopLayout->setSpacing( SPACING_SIZE );
81 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this );
82 filesGrp->setObjectName( "filesGrp" );
83 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp );
84 filesGrpLayout->setAlignment( Qt::AlignTop );
85 filesGrpLayout->setSpacing( SPACING_SIZE );
86 filesGrpLayout->setMargin( MARGIN_SIZE );
88 myIdlEdit = new QLineEdit( filesGrp );
89 myIdlEdit->setObjectName( "myIdlEdit" );
90 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
91 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
92 myXmlEdit = new QLineEdit( filesGrp );
93 myXmlEdit->setObjectName( "myXmlEdit" );
94 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
97 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
98 myBrowseIdlBtn->setObjectName( "myBrowseIdlBtn" );
99 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
100 myBrowseXmlBtn->setObjectName( "myBrowseXmlBtn" );
101 // QFontMetrics fm(myBrowseIdlBtn->font());
102 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
103 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
105 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
106 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
107 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
108 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
109 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
110 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
112 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this );
113 supplGrp->setObjectName( "SupplGrp" );
114 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp );
115 supplGrpLayout->setAlignment( Qt::AlignTop );
116 supplGrpLayout->setSpacing( SPACING_SIZE );
117 supplGrpLayout->setMargin( MARGIN_SIZE );
119 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
121 myAuthorEdit = new QLineEdit( supplGrp );
122 myAuthorEdit->setObjectName( "myAuthorEdit" );
123 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
124 myAuthorEdit->setMinimumSize( myMinimumSize );
126 OSD_Process aProcess;
127 myAuthorEdit->setText(aProcess.UserName().ToCString());
129 myVersionEdit = new QLineEdit( supplGrp );
130 myVersionEdit->setObjectName( "myVersion" );
131 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
132 myVersionEdit->setMinimumSize( myMinimumSize );
133 QStringList aList = tr( "INF_VERSION" ).split(QRegExp("\\s+"), QString::SkipEmptyParts);
134 myVersionEdit->setText(aList.last());
136 myPngEdit = new QLineEdit( supplGrp );
137 myPngEdit->setObjectName( "myCompIcon" );
138 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
139 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
141 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp );
142 myBrowsePngBtn->setObjectName( "myBrowsePngBtn" );
144 myCompName = new QLineEdit( supplGrp );
145 myCompName->setObjectName( "myCompName" );
146 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 myCompName->setMinimumSize( myMinimumSize );
149 myCompUserName = new QLineEdit( supplGrp );
150 myCompUserName->setObjectName( "myCompUserName" );
151 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
152 myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
154 myCompType = new QLineEdit( supplGrp );
155 myCompType->setObjectName( "myCompType" );
156 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
157 myCompType->setMinimumSize( myMinimumSize );
158 myCompType->setText("OTHER");
160 myCompMultiStd = new QLineEdit( supplGrp );
161 myCompMultiStd->setObjectName( "myCompMultiStd" );
162 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
163 myCompMultiStd->setMinimumSize( myMinimumSize );
164 myCompMultiStd->setText("1");
165 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
166 myCompMultiStd->setValidator(ivalidator);
168 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
169 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
170 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
171 supplGrpLayout->addWidget(myCompName,0,3);
172 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
173 supplGrpLayout->addWidget(myCompUserName,0,5);
174 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
175 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
176 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
177 supplGrpLayout->addWidget(myCompMultiStd,1,3);
178 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
179 supplGrpLayout->addWidget(myCompType,1,5);
180 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
181 supplGrpLayout->addWidget( myPngEdit, 2,1,1,4 );
182 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
184 QHBoxLayout* aBtnLayout = new QHBoxLayout;
185 aBtnLayout->setSpacing( SPACING_SIZE );
186 aBtnLayout->setMargin( 0 );
188 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this );
189 myApplyBtn->setObjectName( "myApplyBtn" );
190 myApplyBtn->setAutoDefault( true );
191 myApplyBtn->setDefault( true );
192 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this );
193 myCloseBtn->setObjectName( "myCloseBtn" );
194 myCloseBtn->setAutoDefault( true );
196 aBtnLayout->addWidget( myApplyBtn );
197 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
198 aBtnLayout->addWidget( myCloseBtn );
200 aTopLayout->addWidget( filesGrp, 0, 0 );
201 aTopLayout->addWidget( supplGrp, 1, 0 );
202 aTopLayout->addLayout( aBtnLayout, 2, 0 );
204 /* signals and slots connections */
205 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
206 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
207 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
208 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
209 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
210 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
211 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
219 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
224 \brief Get IDL file name
225 \return IDL file name entered by the user
227 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
229 return myIdlEdit->text().trimmed();
233 \brief Get XML file name
234 \return XML file name entered by the user
236 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
238 return myXmlEdit->text().trimmed();
242 \brief Get module icon file name
243 \return icon file name entered by the user
245 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
247 return myPngEdit->text().trimmed();
251 \brief Get author name
252 \return author name entered by the user
254 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
256 return myAuthorEdit->text().trimmed();
260 \brief Get version number
261 \return version number entered by the user
263 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
265 return myVersionEdit->text().trimmed();
269 \brief Get component name
270 \return name of the component entered by the user
272 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
274 return myCompName->text().trimmed();
278 \brief Get component title (user name)
279 \return title of the component entered by the user
281 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
283 return myCompUserName->text().trimmed();
287 \brief Get multistudy flag
288 \return multistudy flag for the component entered by the user
290 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
292 return myCompMultiStd->text().trimmed();
296 \brief Get component type
297 \return type of the component entered by the user
299 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
301 return myCompType->text().trimmed();
305 \brief Get IDL path of the modules
306 \return IDL path of modules
308 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
310 std::cout << "QAD_Desktop::getCatalogue() is not implemented!!";
312 return QString( "" );
314 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
315 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
317 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
318 aCatalog->GetComponentIconeList();
320 QString IDLpath = "";
322 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
323 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
326 if (dir = getenv( modulename + "_ROOT_DIR")) {
327 IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) +
328 SUIT_Tools::addSlash("idl") +
329 SUIT_Tools::addSlash("salome")) + " ";
333 // MESSAGE ( " IDLpath = " << IDLpath);
340 \brief Called when user presses "Browse" button
342 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
344 QPushButton* send = (QPushButton*)sender();
346 SUIT_Application* app = SUIT_Session::session()->activeApplication();
348 if ( send == myBrowseIdlBtn ) {
349 QString file = app->getFileName( true, myIdlEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
350 if ( !file.isEmpty() ) {
351 myIdlEdit->setText(file);
354 else if ( send == myBrowseXmlBtn ) {
355 QString file = app->getFileName( false, myXmlEdit->text().trimmed(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
356 if ( !file.isEmpty() ) {
357 myXmlEdit->setText(file);
359 } else if ( send == myBrowsePngBtn ) {
360 QString file = app->getFileName( true, myPngEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
361 if ( !file.isEmpty() ) {
362 myPngEdit->setText(file);
370 \brief Update <OK> button's state.
372 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
374 myApplyBtn->setEnabled( !myIdlEdit->text().trimmed().isEmpty() &&
375 !myXmlEdit->text().trimmed().isEmpty() );
379 \brief Called when user presses <Apply> button
381 Performs IDL to XML file conversion using \c runIDLparser SALOME utility.
383 void ToolsGUI_CatalogGeneratorDlg::onApply()
385 QString IDLpath = getIdlPath();
386 QString XmlFile = getXmlFile();
387 QString IdlFile = getIdlFile();
388 QString Author = getAuthor();
389 QString Version = getVersion();
390 QString PngFile = getPngFile();
391 QString CompName = getCompName(); //gets component name
392 QString CompUserName = getCompUserName(); //gets component username
393 QString CompType = getCompType(); //gets component type
394 QString CompMultiStd = getCompMultiStd();
396 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
397 if ( !QFile::exists( IdlFile ) ) {
398 SUIT_MessageBox::critical( this,
399 tr("TOOLS_ERR_ERROR"),
400 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile) );
403 QString command = "";
404 QString kernel_root = Qtx::getenv("KERNEL_ROOT_DIR");
405 if ( !kernel_root.isEmpty() )
406 command = kernel_root + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
408 SUIT_MessageBox::critical( this,
409 tr("TOOLS_ERR_ERROR"),
410 tr("KERNEL_ROOT_DIR variable is not defined") );
413 if (!Author.isEmpty()) command += ",author=" + Author;
414 if (!Version.isEmpty()) command += ",version=" + Version;
415 if (!PngFile.isEmpty()) {
416 OSD_Path aPath((Standard_CString)PngFile.toLatin1().constData());
417 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
418 command += QString(",icon=") + QString(aFile.ToCString());
420 if (!CompName.isEmpty()) command += ",name=" + CompName;
421 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
422 if (!CompType.isEmpty()) command += ",type=" + CompType;
423 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
424 command += " " + IdlFile;
425 MESSAGE( "shell command is : " << command.toLatin1().constData() );
427 res = system( ( char* )( command.toLatin1().constData() ) );
429 MESSAGE( "work failed (system command result = " << res );
430 } else if (res == 217) {
431 MESSAGE( "shell exec failed (system command result = " << res );