1 // Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <GeometryGUI.h>
24 #include <SUIT_Session.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_OverrideCursor.h>
27 #include <SUIT_FileDlg.h>
28 #include <SalomeApp_Application.h>
29 #include <SalomeApp_Study.h>
30 #include <SalomeApp_Tools.h>
31 #include <LightApp_SelectionMgr.h>
35 #include <QButtonGroup>
36 #include <QListWidget>
37 #include <QFileDialog>
41 #include <TopoDS_Shape.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <GEOMImpl_Types.hxx>
48 #include "ImportExportGUI_ExportXAODlg.h"
50 //=================================================================================
52 //=================================================================================
53 ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
55 GEOMBase_Skeleton(geometryGUI, parent, false)
57 m_mainObj = GEOM::GEOM_Object::_nil();
59 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
60 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO")));
61 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
63 setWindowTitle(tr("GEOM_EXPORTXAO_TITLE"));
65 /***************************************************************/
66 mainFrame()->GroupConstructors->setTitle(tr("GEOM_EXPORTXAO_TITLE"));
67 mainFrame()->RadioButton1->setIcon(imageOp);
68 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
69 mainFrame()->RadioButton2->close();
70 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
71 mainFrame()->RadioButton3->close();
74 mainFrame()->GroupBoxName->hide();
76 //****************************
77 // Selection Group box
78 QGroupBox* gbxExport = new QGroupBox(parent);
80 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
82 gridLayoutExport->setSpacing(6);
83 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
85 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
88 QLabel* lblShape = new QLabel(tr("GEOM_EXPORTXAO_EXPORTINGSHAPE"), gbxExport);
89 btnShapeSelect = new QPushButton(gbxExport);
90 btnShapeSelect->setIcon(iconSelect);
91 ledShape = new QLineEdit(gbxExport);
92 ledShape->setMinimumSize(QSize(100, 0));
94 int line = 0, col = 0;
95 gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
96 gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
97 gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
100 QLabel* lblFileName = new QLabel(tr("GEOM_EXPORTXAO_FILENAME"), gbxExport);
101 btnFileSelect = new QPushButton(gbxExport);
102 ledFileName = new QLineEdit(gbxExport);
103 btnFileSelect->setText("...");
106 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
107 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
108 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
111 QLabel* lblAuthor = new QLabel(tr("GEOM_EXPORTXAO_AUTHOR"), gbxExport);
112 ledAuthor = new QLineEdit(gbxExport);
115 gridLayoutExport->addWidget(lblAuthor, line, col++, 2, 1);
117 gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
119 //****************************
121 QGroupBox* gbxFilter = new QGroupBox(parent);
123 QGridLayout* gridLayoutFilter = new QGridLayout(gbxFilter);
125 gridLayoutFilter->setSpacing(6);
126 gridLayoutFilter->setContentsMargins(9, 9, 9, 9);
128 gridLayoutFilter->setObjectName(QString::fromUtf8("gbxFilter"));
131 QLabel* lblGroups = new QLabel(tr("GEOM_EXPORTXAO_LGROUPS"), gbxFilter);
132 QLabel* lblFields = new QLabel(tr("GEOM_EXPORTXAO_LFIELDS"), gbxFilter);
135 gridLayoutFilter->addWidget(lblGroups, line, col++, 1, 1);
136 gridLayoutFilter->addWidget(lblFields, line, col++, 1, 1);
139 lstGroups = new QListWidget(gbxFilter);
140 lstGroups->setSelectionMode(QAbstractItemView::NoSelection);
141 lstFields = new QListWidget(gbxFilter);
142 lstFields->setSelectionMode(QAbstractItemView::NoSelection);
145 gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1);
146 gridLayoutFilter->addWidget(lstFields, line, col++, 1, 1);
148 //****************************
149 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
150 layout->setMargin(0);
151 layout->setSpacing(6);
152 layout->addWidget(gbxExport);
153 layout->addWidget(gbxFilter);
156 setHelpFileName("xao_format_page.html");
161 //=================================================================================
163 //=================================================================================
164 ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg()
166 // no need to delete child widgets, Qt does it all for us
169 //=================================================================================
172 //=================================================================================
173 void ImportExportGUI_ExportXAODlg::Init()
175 // Get setting of step value from file configuration
179 // Signal/slot connections
180 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
181 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
183 connect(btnShapeSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
184 connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
185 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
187 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
189 initName(tr("GEOM_EXPORTXAO"));
190 SelectionIntoArgument();
193 //=================================================================================
194 // function : processObject()
195 // purpose : Fill dialog fields in accordance with myObj
196 //=================================================================================
197 void ImportExportGUI_ExportXAODlg::processObject()
204 if (m_mainObj->_is_nil())
206 ledShape->setText("");
210 ledShape->setText(GEOMBase::GetName(m_mainObj));
211 GEOM::GEOM_IShapesOperations_var shapeOp = getGeomEngine()->GetIShapesOperations(getStudyId());
214 GEOM::ListOfGO_var groups = shapeOp->GetExistingSubObjects(m_mainObj, true);
215 for (int i = 0, n = groups->length(); i < n; i++)
217 QListWidgetItem* item = new QListWidgetItem();
218 item->setData(Qt::UserRole, QVariant(i));
219 item->setText(GEOMBase::GetName(groups[i]));
220 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
221 item->setCheckState(Qt::Checked);
222 lstGroups->addItem(item);
223 m_groups.append(GEOM::GeomObjPtr(groups[i].in()));
225 lstGroups->sortItems(Qt::AscendingOrder);
228 GEOM::GEOM_IFieldOperations_var fieldOp = getGeomEngine()->GetIFieldOperations(getStudyId());
230 GEOM::ListOfFields_var fields = fieldOp->GetFields(m_mainObj);
231 for (int i = 0, n = fields->length(); i < n; i++)
233 QListWidgetItem* item = new QListWidgetItem();
234 item->setData(Qt::UserRole, QVariant(i));
235 item->setText(fields[i]->GetName());
236 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
237 item->setCheckState(Qt::Checked);
238 lstFields->addItem(item);
239 m_fields.append(GEOM::GeomFieldPtr(fields[i].in()));
241 lstFields->sortItems(Qt::AscendingOrder);
245 //=================================================================================
246 // function : ClickOnOk()
248 //=================================================================================
249 void ImportExportGUI_ExportXAODlg::ClickOnOk()
251 setIsApplyAndClose(true);
254 setIsApplyAndClose(false);
257 //=================================================================================
258 // function : ClickOnApply()
260 //=================================================================================
261 bool ImportExportGUI_ExportXAODlg::ClickOnApply()
263 if (!isApplyAndClose())
265 setIsDisableBrowsing(true);
266 setIsDisplayResult(false);
275 SUIT_OverrideCursor wc;
276 SUIT_Session::session()->activeApplication()->putInfo("");
288 catch (const SALOME::SALOME_Exception& e)
290 SalomeApp_Tools::QtCatchCorbaException(e);
296 if (!isApplyAndClose())
298 setIsDisableBrowsing(false);
299 setIsDisplayResult(true);
307 //=================================================================================
308 // function : SelectionIntoArgument()
309 // purpose : Called when selection as changed or other case
310 //=================================================================================
311 void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
313 m_mainObj = GEOM::GEOM_Object::_nil();
315 LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
316 SALOME_ListIO selList;
317 selMgr->selectedObjects(selList);
319 if (selList.Extent() == 1)
321 m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First());
327 //=================================================================================
328 // function : SetEditCurrentArgument()
330 //=================================================================================
331 void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument()
333 ledShape->setFocus();
334 myEditCurrentArgument = ledShape;
335 SelectionIntoArgument();
338 //=================================================================================
339 // function : btnFileSelectClicked()
341 //=================================================================================
342 void ImportExportGUI_ExportXAODlg::btnFileSelectClicked()
344 QString file = SUIT_FileDlg::getFileName(this, ledFileName->text(),
346 tr("GEOM_SELECT_EXPORT_XAO"), false);
347 if ( !file.isEmpty() )
348 ledFileName->setText( file );
351 //=================================================================================
352 // function : ActivateThisDialog()
354 //=================================================================================
355 void ImportExportGUI_ExportXAODlg::ActivateThisDialog()
357 GEOMBase_Skeleton::ActivateThisDialog();
360 //=================================================================================
361 // function : enterEvent [REDEFINED]
363 //=================================================================================
364 void ImportExportGUI_ExportXAODlg::enterEvent(QEvent*)
366 if (!mainFrame()->GroupConstructors->isEnabled())
367 ActivateThisDialog();
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr ImportExportGUI_ExportXAODlg::createOperation()
376 return getGeomEngine()->GetIInsertOperations(getStudyId());
379 //=================================================================================
380 // function : isValid
382 //=================================================================================
383 bool ImportExportGUI_ExportXAODlg::isValid(QString& msg)
386 if (ledShape->text().isEmpty())
390 if (ledFileName->text().isEmpty())
396 //=================================================================================
397 // function : execute
399 //=================================================================================
400 bool ImportExportGUI_ExportXAODlg::execute()
404 QString author = ledAuthor->text();
405 QString fileName = ledFileName->text();
407 // get selected groups
408 QList<QListWidgetItem*> selGroups;
409 for (int j = 0; j < lstGroups->count(); ++j)
411 if (lstGroups->item(j)->checkState() == Qt::Checked)
412 selGroups.append(lstGroups->item(j));
415 GEOM::ListOfGO_var groups = new GEOM::ListOfGO();
416 groups->length(selGroups.count());
418 for (QList<QListWidgetItem*>::iterator it = selGroups.begin(); it != selGroups.end(); ++it)
420 QListWidgetItem* item = (*it);
421 int index = item->data(Qt::UserRole).toInt();
422 groups[i++] = m_groups[index].copy();
425 // get selected fields
426 QList<QListWidgetItem*> selFields;
427 for (int j = 0; j < lstFields->count(); ++j)
429 if (lstFields->item(j)->checkState() == Qt::Checked)
430 selFields.append(lstFields->item(j));
433 GEOM::ListOfFields_var fields = new GEOM::ListOfFields();
434 fields->length(selFields.count());
436 for (QList<QListWidgetItem*>::iterator it = selFields.begin(); it != selFields.end(); ++it)
438 QListWidgetItem* item = (*it);
439 int index = item->data(Qt::UserRole).toInt();
440 fields[i++] = m_fields[index].copy();
443 // call engine function
444 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
445 res = ieOp->ExportXAO(m_mainObj, groups, fields,
446 author.toStdString().c_str(),
447 fileName.toStdString().c_str());