1 // Copyright (C) 2007-2008 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.
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
22 // SALOME TOOLSGUI : implementation of desktop "Tools" optioins
23 // File : ToolsGUI_CatalogGeneratorDlg.cxx
24 // Author : Nicolas REJNERI
26 #include "ToolsGUI_CatalogGeneratorDlg.h"
28 #include "SUIT_Application.h"
29 #include "SUIT_MessageBox.h"
30 //#include "SUIT_Tools.h"
31 #include "SUIT_Session.h"
37 #include <QPushButton>
38 #include <QGridLayout>
40 #include <QStringList>
42 #include <QIntValidator>
45 #include <OSD_Process.hxx>
46 #include <OSD_Path.hxx>
47 #include <TCollection_AsciiString.hxx>
48 #include <Standard_CString.hxx>
50 #include "utilities.h"
54 #define SPACING_SIZE 6
55 #define MARGIN_SIZE 11
56 #define MIN_EDIT_SIZE 250
59 \class ToolsGUI_CatalogGeneratorDlg
60 \brief A dialog box which allows converting the IDL files
61 to the XML description.
66 \param parent parent widget
68 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent )
73 setWindowTitle( tr( "TOOLS_CATALOG_GENERATOR" ) );
74 setSizeGripEnabled( true );
76 QGridLayout* aTopLayout = new QGridLayout(this);
77 aTopLayout->setMargin( MARGIN_SIZE );
78 aTopLayout->setSpacing( SPACING_SIZE );
80 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this );
81 filesGrp->setObjectName( "filesGrp" );
82 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp );
83 filesGrpLayout->setAlignment( Qt::AlignTop );
84 filesGrpLayout->setSpacing( SPACING_SIZE );
85 filesGrpLayout->setMargin( MARGIN_SIZE );
87 myIdlEdit = new QLineEdit( filesGrp );
88 myIdlEdit->setObjectName( "myIdlEdit" );
89 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
91 myXmlEdit = new QLineEdit( filesGrp );
92 myXmlEdit->setObjectName( "myXmlEdit" );
93 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
96 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
97 myBrowseIdlBtn->setObjectName( "myBrowseIdlBtn" );
98 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp );
99 myBrowseXmlBtn->setObjectName( "myBrowseXmlBtn" );
100 // QFontMetrics fm(myBrowseIdlBtn->font());
101 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
102 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
104 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
105 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
106 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
107 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
108 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
109 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
111 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this );
112 supplGrp->setObjectName( "SupplGrp" );
113 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp );
114 supplGrpLayout->setAlignment( Qt::AlignTop );
115 supplGrpLayout->setSpacing( SPACING_SIZE );
116 supplGrpLayout->setMargin( MARGIN_SIZE );
118 QSize myMinimumSize(int(MIN_EDIT_SIZE*0.3), 0);
120 myAuthorEdit = new QLineEdit( supplGrp );
121 myAuthorEdit->setObjectName( "myAuthorEdit" );
122 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123 myAuthorEdit->setMinimumSize( myMinimumSize );
125 OSD_Process aProcess;
126 myAuthorEdit->setText(aProcess.UserName().ToCString());
128 myVersionEdit = new QLineEdit( supplGrp );
129 myVersionEdit->setObjectName( "myVersion" );
130 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131 myVersionEdit->setMinimumSize( myMinimumSize );
132 QStringList aList = tr( "INF_VERSION" ).split(QRegExp("\\s+"), QString::SkipEmptyParts);
133 myVersionEdit->setText(aList.last());
135 myPngEdit = new QLineEdit( supplGrp );
136 myPngEdit->setObjectName( "myCompIcon" );
137 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
138 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
140 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp );
141 myBrowsePngBtn->setObjectName( "myBrowsePngBtn" );
143 myCompName = new QLineEdit( supplGrp );
144 myCompName->setObjectName( "myCompName" );
145 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
146 myCompName->setMinimumSize( myMinimumSize );
148 myCompUserName = new QLineEdit( supplGrp );
149 myCompUserName->setObjectName( "myCompUserName" );
150 myCompUserName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
151 myCompUserName->setMinimumSize( (int)(MIN_EDIT_SIZE*0.3), 0 );
153 myCompType = new QLineEdit( supplGrp );
154 myCompType->setObjectName( "myCompType" );
155 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
156 myCompType->setMinimumSize( myMinimumSize );
157 myCompType->setText("OTHER");
159 myCompMultiStd = new QLineEdit( supplGrp );
160 myCompMultiStd->setObjectName( "myCompMultiStd" );
161 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
162 myCompMultiStd->setMinimumSize( myMinimumSize );
163 myCompMultiStd->setText("1");
164 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
165 myCompMultiStd->setValidator(ivalidator);
167 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
168 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
169 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
170 supplGrpLayout->addWidget(myCompName,0,3);
171 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_USERNAME" ), supplGrp ), 0, 4);
172 supplGrpLayout->addWidget(myCompUserName,0,5);
173 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
174 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
175 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
176 supplGrpLayout->addWidget(myCompMultiStd,1,3);
177 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 1, 4);
178 supplGrpLayout->addWidget(myCompType,1,5);
179 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
180 supplGrpLayout->addWidget( myPngEdit, 2,1,1,4 );
181 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
183 QHBoxLayout* aBtnLayout = new QHBoxLayout;
184 aBtnLayout->setSpacing( SPACING_SIZE );
185 aBtnLayout->setMargin( 0 );
187 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this );
188 myApplyBtn->setObjectName( "myApplyBtn" );
189 myApplyBtn->setAutoDefault( true );
190 myApplyBtn->setDefault( true );
191 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this );
192 myCloseBtn->setObjectName( "myCloseBtn" );
193 myCloseBtn->setAutoDefault( true );
195 aBtnLayout->addWidget( myApplyBtn );
196 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
197 aBtnLayout->addWidget( myCloseBtn );
199 aTopLayout->addWidget( filesGrp, 0, 0 );
200 aTopLayout->addWidget( supplGrp, 1, 0 );
201 aTopLayout->addLayout( aBtnLayout, 2, 0 );
203 /* signals and slots connections */
204 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
205 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
206 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
207 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
208 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
209 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
210 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
218 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
223 \brief Get IDL file name
224 \return IDL file name entered by the user
226 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
228 return myIdlEdit->text().trimmed();
232 \brief Get XML file name
233 \return XML file name entered by the user
235 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
237 return myXmlEdit->text().trimmed();
241 \brief Get module icon file name
242 \return icon file name entered by the user
244 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
246 return myPngEdit->text().trimmed();
250 \brief Get author name
251 \return author name entered by the user
253 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
255 return myAuthorEdit->text().trimmed();
259 \brief Get version number
260 \return version number entered by the user
262 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
264 return myVersionEdit->text().trimmed();
268 \brief Get component name
269 \return name of the component entered by the user
271 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
273 return myCompName->text().trimmed();
277 \brief Get component title (user name)
278 \return title of the component entered by the user
280 QString ToolsGUI_CatalogGeneratorDlg::getCompUserName()
282 return myCompUserName->text().trimmed();
286 \brief Get multistudy flag
287 \return multistudy flag for the component entered by the user
289 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
291 return myCompMultiStd->text().trimmed();
295 \brief Get component type
296 \return type of the component entered by the user
298 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
300 return myCompType->text().trimmed();
304 \brief Get IDL path of the modules
305 \return IDL path of modules
307 QString ToolsGUI_CatalogGeneratorDlg::getIdlPath()
309 cout << "QAD_Desktop::getCatalogue() is not implemented!!";
311 return QString( "" );
313 SALOME_ModuleCatalog::ModuleCatalog_var aCatalog =
314 SALOME_ModuleCatalog::ModuleCatalog::_narrow( QAD_Application::getDesktop()->getCatalogue() );
316 SALOME_ModuleCatalog::ListOfIAPP_Affich_var list_composants =
317 aCatalog->GetComponentIconeList();
319 QString IDLpath = "";
321 for (unsigned int ind = 0; ind < list_composants->length();ind++) {
322 QString modulename = CORBA::string_dup(list_composants[ind].modulename) ;
325 if (dir = getenv( modulename + "_ROOT_DIR")) {
326 IDLpath = IDLpath + "-I" + SUIT_Tools::addSlash( SUIT_Tools::addSlash(dir) +
327 SUIT_Tools::addSlash("idl") +
328 SUIT_Tools::addSlash("salome")) + " ";
332 // MESSAGE ( " IDLpath = " << IDLpath);
339 \brief Called when user presses "Browse" button
341 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
343 QPushButton* send = (QPushButton*)sender();
345 SUIT_Application* app = SUIT_Session::session()->activeApplication();
347 if ( send == myBrowseIdlBtn ) {
348 QString file = app->getFileName( true, myIdlEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_IDL"), tr("TOOLS_MEN_IMPORT"), 0 );
349 if ( !file.isEmpty() ) {
350 myIdlEdit->setText(file);
353 else if ( send == myBrowseXmlBtn ) {
354 QString file = app->getFileName( false, myXmlEdit->text().trimmed(), tr("TOOLS_MEN_EXPORT_XML"), tr("TOOLS_MEN_EXPORT"), 0 );
355 if ( !file.isEmpty() ) {
356 myXmlEdit->setText(file);
358 } else if ( send == myBrowsePngBtn ) {
359 QString file = app->getFileName( true, myPngEdit->text().trimmed(), tr("TOOLS_MEN_IMPORT_PNG"), tr("TOOLS_MEN_IMPORT"), 0 );
360 if ( !file.isEmpty() ) {
361 myPngEdit->setText(file);
369 \brief Update <OK> button's state.
371 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
373 myApplyBtn->setEnabled( !myIdlEdit->text().trimmed().isEmpty() &&
374 !myXmlEdit->text().trimmed().isEmpty() );
378 \brief Called when user presses <Apply> button
380 Performs IDL to XML file conversion using \c runIDLparser SALOME utility.
382 void ToolsGUI_CatalogGeneratorDlg::onApply()
384 QString IDLpath = getIdlPath();
385 QString XmlFile = getXmlFile();
386 QString IdlFile = getIdlFile();
387 QString Author = getAuthor();
388 QString Version = getVersion();
389 QString PngFile = getPngFile();
390 QString CompName = getCompName(); //gets component name
391 QString CompUserName = getCompUserName(); //gets component username
392 QString CompType = getCompType(); //gets component type
393 QString CompMultiStd = getCompMultiStd();
395 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
396 if ( !QFile::exists( IdlFile ) ) {
397 SUIT_MessageBox::critical( this,
398 tr("TOOLS_ERR_ERROR"),
399 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile) );
402 QString command = "";
403 if ( getenv("KERNEL_ROOT_DIR") )
404 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
406 SUIT_MessageBox::critical( this,
407 tr("TOOLS_ERR_ERROR"),
408 tr("KERNEL_ROOT_DIR variable is not defined") );
411 if (!Author.isEmpty()) command += ",author=" + Author;
412 if (!Version.isEmpty()) command += ",version=" + Version;
413 if (!PngFile.isEmpty()) {
414 OSD_Path aPath((Standard_CString)PngFile.toLatin1().constData());
415 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
416 command += QString(",icon=") + QString(aFile.ToCString());
418 if (!CompName.isEmpty()) command += ",name=" + CompName;
419 if (!CompUserName.isEmpty()) command += ",username=" + CompUserName;
420 if (!CompType.isEmpty()) command += ",type=" + CompType;
421 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
422 command += " " + IdlFile;
423 MESSAGE( "shell command is : " << command.toLatin1().constData() );
425 res = system( ( char* )( command.toLatin1().constData() ) );
427 MESSAGE( "work failed (system command result = " << res );
428 } else if (res == 217) {
429 MESSAGE( "shell exec failed (system command result = " << res );