2 // File : ToolsGUI_CatalogGeneratorDlg.cxx
3 // Created : Thu Apr 25 18:52:40 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "ToolsGUI_CatalogGeneratorDlg.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_FileDlg.h"
16 #include "QAD_MessageBox.h"
19 #include <qlineedit.h>
20 #include <qpushbutton.h>
22 #include <qgroupbox.h>
23 #include <qstringlist.h>
25 #include <qvalidator.h>
27 #include <OSD_Process.hxx>
28 #include <OSD_Path.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <Standard_CString.hxx>
32 #define SPACING_SIZE 6
33 #define MARGIN_SIZE 11
34 #define MIN_EDIT_SIZE 250
36 //=================================================================================
37 // class : ToolsGUI_CatalogGeneratorDlg()
38 // purpose : Constructor
39 //=================================================================================
40 ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, const char* name )
41 : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
44 setName( "ToolsGUI_CatalogGeneratorDlg" );
46 setCaption( tr( "TOOLS_CATALOG_GENERATOR" ) );
47 setSizeGripEnabled( TRUE );
49 QGridLayout* aTopLayout = new QGridLayout(this);
50 aTopLayout->setMargin(MARGIN_SIZE);
51 aTopLayout->setSpacing(SPACING_SIZE);
53 QGroupBox* filesGrp = new QGroupBox( tr( "TOOLS_FILES") , this, "filesGrp" );
54 filesGrp->setColumnLayout( 0, Qt::Vertical );
55 filesGrp->layout()->setSpacing( 0 );
56 filesGrp->layout()->setMargin( 0 );
57 QGridLayout* filesGrpLayout = new QGridLayout( filesGrp->layout() );
58 filesGrpLayout->setAlignment( Qt::AlignTop );
59 filesGrpLayout->setSpacing( SPACING_SIZE );
60 filesGrpLayout->setMargin( MARGIN_SIZE );
62 myIdlEdit = new QLineEdit( filesGrp, "myIdlEdit" );
63 myIdlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
64 myIdlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
65 myXmlEdit = new QLineEdit( filesGrp, "myXmlEdit" );
66 myXmlEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
67 myXmlEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
69 myBrowseIdlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseIdlBtn" );
70 myBrowseXmlBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), filesGrp, "myBrowseXmlBtn" );
71 // QFontMetrics fm(myBrowseIdlBtn->font());
72 // myBrowseIdlBtn->setFixedWidth(fm.width(myBrowseIdlBtn->text()) + 10);
73 // myBrowseXmlBtn->setFixedWidth(fm.width(myBrowseXmlBtn->text()) + 10);
75 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_IDL_FILE" ), filesGrp ), 0, 0);
76 filesGrpLayout->addWidget( myIdlEdit, 0, 1 );
77 filesGrpLayout->addWidget( myBrowseIdlBtn, 0, 2 );
78 filesGrpLayout->addWidget( new QLabel( tr( "TOOLS_XML_FILE" ), filesGrp ), 1, 0);
79 filesGrpLayout->addWidget( myXmlEdit, 1, 1 );
80 filesGrpLayout->addWidget( myBrowseXmlBtn, 1, 2 );
82 QGroupBox* supplGrp = new QGroupBox(tr( "TOOLS_SUPPLEMENT" ) , this, "SupplGrp" );
83 supplGrp->setColumnLayout( 0, Qt::Vertical );
84 supplGrp->layout()->setSpacing( 0 );
85 supplGrp->layout()->setMargin( 0 );
86 QGridLayout* supplGrpLayout = new QGridLayout( supplGrp->layout() );
87 supplGrpLayout->setAlignment( Qt::AlignTop );
88 supplGrpLayout->setSpacing( SPACING_SIZE );
89 supplGrpLayout->setMargin( MARGIN_SIZE );
91 myAuthorEdit = new QLineEdit( supplGrp , "myAuthorEdit" );
92 myAuthorEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
93 myAuthorEdit->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
96 myAuthorEdit->setText(aProcess.UserName().ToCString());
98 myVersionEdit = new QLineEdit(supplGrp , "myVersion" );
99 myVersionEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100 myVersionEdit->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
101 QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
102 myVersionEdit->setText(aList.last());
103 QDoubleValidator *validator = new QDoubleValidator(myVersionEdit);
104 myVersionEdit->setValidator(validator);
106 myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
107 myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
108 myPngEdit->setMinimumSize( MIN_EDIT_SIZE, 0 );
110 myBrowsePngBtn = new QPushButton( tr( "TOOLS_BUT_BROWSE" ), supplGrp, "myBrowsePngBtn" );
112 myCompName = new QLineEdit(supplGrp , "myCompName");
113 myCompName->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
114 myCompName->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
116 myCompType = new QLineEdit(supplGrp , "myCompType");
117 myCompType->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
118 myCompType->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
119 myCompType->setText("OTHER");
121 myCompMultiStd = new QLineEdit(supplGrp , "myCompMultiStd");
122 myCompMultiStd->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123 myCompMultiStd->setMinimumSize( MIN_EDIT_SIZE*0.3, 0 );
124 myCompMultiStd->setText("1");
125 QIntValidator *ivalidator = new QIntValidator(myVersionEdit);
126 myCompMultiStd->setValidator(ivalidator);
128 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_AUTHOR" ), supplGrp ), 0, 0);
129 supplGrpLayout->addWidget( myAuthorEdit, 0, 1 );
130 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_NAME" ), supplGrp ), 0, 2);
131 supplGrpLayout->addWidget(myCompName,0,3);
132 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_TYPE" ), supplGrp ), 0, 4);
133 supplGrpLayout->addWidget(myCompType,0,5);
134 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_VERSION" ), supplGrp ), 1, 0);
135 supplGrpLayout->addWidget( myVersionEdit, 1, 1);
136 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_COMP_MULTISTD" ), supplGrp ), 1, 2);
137 supplGrpLayout->addWidget(myCompMultiStd,1,3);
138 supplGrpLayout->addWidget( new QLabel( tr( "TOOLS_PNG_FILE" ), supplGrp ), 2, 0);
139 supplGrpLayout->addMultiCellWidget( myPngEdit, 2,2,1,4 );
140 supplGrpLayout->addWidget( myBrowsePngBtn, 2, 5 );
143 QHBoxLayout* aBtnLayout = new QHBoxLayout;
144 aBtnLayout->setSpacing( SPACING_SIZE );
145 aBtnLayout->setMargin( 0 );
147 myApplyBtn = new QPushButton( tr( "TOOLS_BUT_APPLY" ), this, "myApplyBtn" );
148 myApplyBtn->setAutoDefault( true );
149 myApplyBtn->setDefault( true );
150 myCloseBtn = new QPushButton( tr( "TOOLS_BUT_CLOSE" ), this, "myCloseBtn" );
151 myCloseBtn->setAutoDefault( true );
153 aBtnLayout->addWidget( myApplyBtn );
154 aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
155 aBtnLayout->addWidget( myCloseBtn );
157 aTopLayout->addWidget( filesGrp, 0, 0 );
158 aTopLayout->addWidget( supplGrp, 1, 0 );
159 aTopLayout->addLayout( aBtnLayout, 2, 0 );
161 /* signals and slots connections */
162 connect( myApplyBtn, SIGNAL( clicked() ), this, SLOT( onApply() ) );
163 connect( myCloseBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
164 connect( myBrowseIdlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
165 connect( myBrowseXmlBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
166 connect( myBrowsePngBtn, SIGNAL( clicked() ), this, SLOT( onBrowseBtnClicked() ) );
167 connect( myIdlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
168 connect( myXmlEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( updateButtonState() ) );
173 //=================================================================================
174 // function : ~ToolsGUI_CatalogGeneratorDlg()
175 // purpose : destructor
176 //=================================================================================
177 ToolsGUI_CatalogGeneratorDlg::~ToolsGUI_CatalogGeneratorDlg()
181 //=================================================================================
182 // function : getIdlFile()
183 // purpose : gets IDL file name entered
184 //=================================================================================
185 QString ToolsGUI_CatalogGeneratorDlg::getIdlFile()
187 return myIdlEdit->text().stripWhiteSpace();
190 //=================================================================================
191 // function : getXmlFile()
192 // purpose : gets XML file name entered
193 //=================================================================================
194 QString ToolsGUI_CatalogGeneratorDlg::getXmlFile()
196 return myXmlEdit->text().stripWhiteSpace();
199 //=================================================================================
200 // function : getPngFile()
201 // purpose : gets PNG file name entered
202 //=================================================================================
203 QString ToolsGUI_CatalogGeneratorDlg::getPngFile()
205 return myPngEdit->text().stripWhiteSpace();
208 //=================================================================================
209 // function : getAuthor()
210 // purpose : gets author
211 //=================================================================================
212 QString ToolsGUI_CatalogGeneratorDlg::getAuthor()
214 return myAuthorEdit->text().stripWhiteSpace();
217 //=================================================================================
218 // function : getVersion()
219 // purpose : gets version number
220 //=================================================================================
221 QString ToolsGUI_CatalogGeneratorDlg::getVersion()
223 return myVersionEdit->text().stripWhiteSpace();
226 //=================================================================================
227 // function : getCompName()
228 // purpose : gets name of the component
229 //=================================================================================
230 QString ToolsGUI_CatalogGeneratorDlg::getCompName()
232 return myCompName->text().stripWhiteSpace();
235 //=================================================================================
236 // function : getCompType()
237 // purpose : gets type of the component
238 //=================================================================================
239 QString ToolsGUI_CatalogGeneratorDlg::getCompMultiStd()
241 return myCompMultiStd->text().stripWhiteSpace();
243 //=================================================================================
244 // function : getComptype()
245 // purpose : gets type of the component
246 //=================================================================================
247 QString ToolsGUI_CatalogGeneratorDlg::getCompType()
249 return myCompType->text().stripWhiteSpace();
252 //=================================================================================
253 // function : onBrowseBtnClicked()
254 // purpose : <...> (Browse) buttons slot
255 //=================================================================================
256 void ToolsGUI_CatalogGeneratorDlg::onBrowseBtnClicked()
258 QPushButton* send = (QPushButton*)sender();
260 if ( send == myBrowseIdlBtn ) {
261 QString file = myIdlEdit->text().stripWhiteSpace();
262 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
264 tr("TOOLS_MEN_IMPORT_IDL"),
265 tr("TOOLS_MEN_IMPORT"),
267 if ( !file.isEmpty() ) {
268 myIdlEdit->setText(file);
271 else if ( send == myBrowseXmlBtn ) {
272 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
273 myXmlEdit->text().stripWhiteSpace(),
274 tr("TOOLS_MEN_EXPORT_XML"),
275 tr("TOOLS_MEN_EXPORT"),
277 if ( !file.isEmpty() ) {
278 myXmlEdit->setText(file);
280 } else if ( send == myBrowsePngBtn ) {
281 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
282 myXmlEdit->text().stripWhiteSpace(),
283 tr("TOOLS_MEN_IMPORT_PNG"),
284 tr("TOOLS_MEN_IMPORT"),
286 if ( !file.isEmpty() ) {
287 myPngEdit->setText(file);
294 //=================================================================================
295 // function : updateButtonState()
296 // purpose : Updates <OK> button's state
297 //=================================================================================
298 void ToolsGUI_CatalogGeneratorDlg::updateButtonState()
300 myApplyBtn->setEnabled( !myIdlEdit->text().stripWhiteSpace().isEmpty() &&
301 !myXmlEdit->text().stripWhiteSpace().isEmpty() );
304 //=================================================================================
305 // function : onApply()
306 // purpose : <Apply> button slot, performs IDL->XML conversion
307 //=================================================================================
308 void ToolsGUI_CatalogGeneratorDlg::onApply()
310 QString XmlFile = getXmlFile();
311 QString IdlFile = getIdlFile();
312 QString Author = getAuthor();
313 QString Version = getVersion();
314 QString PngFile = getPngFile();
315 QString CompName = getCompName(); //gets component name
316 QString CompType = getCompType(); //gets component type
317 QString CompMultiStd = getCompMultiStd();
319 if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) {
320 if ( !QFile::exists( IdlFile ) ) {
321 QAD_MessageBox::error1( this,
322 tr("TOOLS_ERR_ERROR"),
323 tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile),
324 tr ("TOOLS_BUT_OK") );
327 QString command = "";
328 if ( getenv("SALOME_ROOT_DIR") )
329 command = QString( getenv( "SALOME_ROOT_DIR" ) ) + "/bin/runIDLparser -Wbcatalog=" + XmlFile;
330 else if ( getenv("KERNEL_ROOT_DIR") )
331 command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/runIDLparser -Wbcatalog=" + XmlFile;
333 QAD_MessageBox::error1( this,
334 tr("TOOLS_ERR_ERROR"),
335 tr("SALOME_ROOT_DIR or KERNEL_ROOT_DIR variables are not defined"),
336 tr("TOOLS_BUT_OK") );
338 if (!Author.isEmpty()) command += ",author=" + Author;
339 if (!Version.isEmpty()) command += ",version=" + Version;
340 if (!PngFile.isEmpty()) {
341 OSD_Path aPath((Standard_CString)PngFile.latin1());
342 TCollection_AsciiString aFile = aPath.Name() + aPath.Extension();
343 command += QString(",icon=") + QString(aFile.ToCString());
345 if (!CompName.isEmpty()) command += ",name=" + CompName;
346 if (!CompType.isEmpty()) command += ",type=" + CompType;
347 if (!CompMultiStd.isEmpty()) command += ",multistudy=" + CompMultiStd;
348 command += " " + IdlFile;
349 MESSAGE( "shell command is : " << command );
351 res = system( ( char* )( command.latin1() ) );
353 MESSAGE( "work failed (system command result = " << res );
354 } else if (res == 217) {
355 MESSAGE( "shell exec failed (system command result = " << res );