1 // Copyright (C) 2013 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.
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
20 #include <GeometryGUI.h>
23 #include <SUIT_Session.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <SUIT_OverrideCursor.h>
26 #include <SalomeApp_Application.h>
27 #include <SalomeApp_Study.h>
28 #include <SalomeApp_Tools.h>
29 #include <LightApp_SelectionMgr.h>
33 #include <QButtonGroup>
34 #include <QListWidget>
35 #include <QFileDialog>
39 #include <TopoDS_Shape.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
46 #include "ImportExportGUI_ExportXAODlg.h"
48 //=================================================================================
50 //=================================================================================
51 ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
53 GEOMBase_Skeleton(geometryGUI, parent, false)
55 m_mainObj = GEOM::GEOM_Object::_nil();
57 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
58 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO")));
59 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_EXPORTXAO_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_EXPORTXAO_TITLE"));
65 mainFrame()->RadioButton1->setIcon(imageOp);
66 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton2->close();
68 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
69 mainFrame()->RadioButton3->close();
72 mainFrame()->GroupBoxName->hide();
74 //****************************
75 // Selection Group box
76 QGroupBox* gbxExport = new QGroupBox(parent);
78 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
80 gridLayoutExport->setSpacing(6);
81 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
83 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
86 QLabel* lblShape = new QLabel(tr("GEOM_EXPORTXAO_EXPORTINGSHAPE"), gbxExport);
87 btnShapeSelect = new QPushButton(gbxExport);
88 btnShapeSelect->setIcon(iconSelect);
89 ledShape = new QLineEdit(gbxExport);
90 ledShape->setMinimumSize(QSize(100, 0));
92 int line = 0, col = 0;
93 gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
94 gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
95 gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
98 QLabel* lblFileName = new QLabel(tr("GEOM_EXPORTXAO_FILENAME"), gbxExport);
99 btnFileSelect = new QPushButton(gbxExport);
100 ledFileName = new QLineEdit(gbxExport);
101 btnFileSelect->setText("...");
104 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
105 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
106 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
109 QLabel* lblAuthor = new QLabel(tr("GEOM_EXPORTXAO_AUTHOR"), gbxExport);
110 ledAuthor = new QLineEdit(gbxExport);
113 gridLayoutExport->addWidget(lblAuthor, line, col++, 2, 1);
115 gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
117 //****************************
119 QGroupBox* gbxFilter = new QGroupBox(parent);
121 QGridLayout* gridLayoutFilter = new QGridLayout(gbxFilter);
123 gridLayoutFilter->setSpacing(6);
124 gridLayoutFilter->setContentsMargins(9, 9, 9, 9);
126 gridLayoutFilter->setObjectName(QString::fromUtf8("gbxFilter"));
129 QLabel* lblGroups = new QLabel(tr("GEOM_EXPORTXAO_LGROUPS"), gbxFilter);
130 QLabel* lblFields = new QLabel(tr("GEOM_EXPORTXAO_LFIELDS"), gbxFilter);
133 gridLayoutFilter->addWidget(lblGroups, line, col++, 1, 1);
134 gridLayoutFilter->addWidget(lblFields, line, col++, 1, 1);
137 lstGroups = new QListWidget(gbxFilter);
138 lstGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
139 lstFields = new QListWidget(gbxFilter);
140 lstFields->setSelectionMode(QAbstractItemView::ExtendedSelection);
143 gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1);
144 gridLayoutFilter->addWidget(lstFields, line, col++, 1, 1);
146 //****************************
147 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
148 layout->setMargin(0);
149 layout->setSpacing(6);
150 layout->addWidget(gbxExport);
151 layout->addWidget(gbxFilter);
154 setHelpFileName("create_exportxao_page.html");
159 //=================================================================================
161 //=================================================================================
162 ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg()
164 // no need to delete child widgets, Qt does it all for us
167 //=================================================================================
170 //=================================================================================
171 void ImportExportGUI_ExportXAODlg::Init()
173 // Get setting of step value from file configuration
177 // Signal/slot connections
178 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
179 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
181 connect(btnShapeSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
182 connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
183 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
187 initName(tr("GEOM_EXPORTXAO"));
188 SelectionIntoArgument();
191 //=================================================================================
192 // function : processObject()
193 // purpose : Fill dialog fields in accordance with myObj
194 //=================================================================================
195 void ImportExportGUI_ExportXAODlg::processObject()
202 if (m_mainObj->_is_nil())
204 ledShape->setText("");
208 ledShape->setText(GEOMBase::GetName(m_mainObj));
209 GEOM::GEOM_IShapesOperations_var shapeOp = getGeomEngine()->GetIShapesOperations(getStudyId());
212 GEOM::ListOfGO_var groups = shapeOp->GetExistingSubObjects(m_mainObj, true);
213 for (int i = 0, n = groups->length(); i < n; i++)
215 QListWidgetItem* item = new QListWidgetItem();
216 item->setData(Qt::UserRole, QVariant(i));
217 item->setText(GEOMBase::GetName(groups[i]));
218 lstGroups->addItem(item);
219 item->setSelected(true);
220 m_groups.append(GEOM::GeomObjPtr(groups[i].in()));
222 lstGroups->sortItems(Qt::AscendingOrder);
225 GEOM::GEOM_IFieldOperations_var fieldOp = getGeomEngine()->GetIFieldOperations(getStudyId());
227 GEOM::ListOfFields_var fields = fieldOp->GetFields(m_mainObj);
228 for (int i = 0, n = fields->length(); i < n; i++)
230 QListWidgetItem* item = new QListWidgetItem();
231 item->setData(Qt::UserRole, QVariant(i));
232 item->setText(fields[i]->GetName());
233 lstFields->addItem(item);
234 item->setSelected(true);
235 m_fields.append(GEOM::GeomFieldPtr(fields[i].in()));
237 lstFields->sortItems(Qt::AscendingOrder);
241 //=================================================================================
242 // function : ClickOnOk()
244 //=================================================================================
245 void ImportExportGUI_ExportXAODlg::ClickOnOk()
247 setIsApplyAndClose(true);
250 setIsApplyAndClose(false);
253 //=================================================================================
254 // function : ClickOnApply()
256 //=================================================================================
257 bool ImportExportGUI_ExportXAODlg::ClickOnApply()
259 if (!isApplyAndClose())
261 setIsDisableBrowsing(true);
262 setIsDisplayResult(false);
271 SUIT_OverrideCursor wc;
272 SUIT_Session::session()->activeApplication()->putInfo("");
277 if (!execute(/*isApplyAndClose()*/))
284 catch (const SALOME::SALOME_Exception& e)
286 SalomeApp_Tools::QtCatchCorbaException(e);
292 if (!isApplyAndClose())
294 setIsDisableBrowsing(false);
295 setIsDisplayResult(true);
303 //=================================================================================
304 // function : SelectionIntoArgument()
305 // purpose : Called when selection as changed or other case
306 //=================================================================================
307 void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
309 m_mainObj = GEOM::GEOM_Object::_nil();
311 LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
312 SALOME_ListIO selList;
313 selMgr->selectedObjects(selList);
315 if (selList.Extent() == 1)
317 m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First());
323 //=================================================================================
324 // function : SetEditCurrentArgument()
326 //=================================================================================
327 void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument()
329 ledShape->setFocus();
330 myEditCurrentArgument = ledShape;
331 SelectionIntoArgument();
334 //=================================================================================
335 // function : btnFileSelectClicked()
337 //=================================================================================
338 void ImportExportGUI_ExportXAODlg::btnFileSelectClicked()
340 QString selFile = QFileDialog::getSaveFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
341 QString(), tr("XAO_FILES"));
342 if (!selFile.isEmpty())
344 ledFileName->setText(selFile);
348 //=================================================================================
349 // function : ActivateThisDialog()
351 //=================================================================================
352 void ImportExportGUI_ExportXAODlg::ActivateThisDialog()
354 GEOMBase_Skeleton::ActivateThisDialog();
357 //=================================================================================
358 // function : enterEvent [REDEFINED]
360 //=================================================================================
361 void ImportExportGUI_ExportXAODlg::enterEvent(QEvent*)
363 if (!mainFrame()->GroupConstructors->isEnabled())
364 ActivateThisDialog();
367 //=================================================================================
368 // function : createOperation
370 //=================================================================================
371 GEOM::GEOM_IOperations_ptr ImportExportGUI_ExportXAODlg::createOperation()
373 return getGeomEngine()->GetIInsertOperations(getStudyId());
376 //=================================================================================
377 // function : isValid
379 //=================================================================================
380 bool ImportExportGUI_ExportXAODlg::isValid(QString& msg)
383 if (ledShape->text().isEmpty())
387 if (ledFileName->text().isEmpty())
393 //=================================================================================
394 // function : execute
396 //=================================================================================
397 bool ImportExportGUI_ExportXAODlg::execute()
401 QString author = ledAuthor->text();
402 QString fileName = ledFileName->text();
404 // get selected groups
405 QList<QListWidgetItem*> selGroups = lstGroups->selectedItems();
406 GEOM::ListOfGO_var groups = new GEOM::ListOfGO();
407 groups->length(selGroups.count());
409 for (QList<QListWidgetItem*>::iterator it = selGroups.begin(); it != selGroups.end(); ++it)
411 QListWidgetItem* item = (*it);
412 int index = item->data(Qt::UserRole).toInt();
413 groups[i++] = m_groups[index].copy();
416 // get selected fields
417 QList<QListWidgetItem*> selFields = lstFields->selectedItems();
418 GEOM::ListOfFields_var fields = new GEOM::ListOfFields();
419 fields->length(m_fields.count());
421 for (QList<QListWidgetItem*>::iterator it = selFields.begin(); it != selFields.end(); ++it)
423 QListWidgetItem* item = (*it);
424 int index = item->data(Qt::UserRole).toInt();
425 fields[i++] = m_fields[index].copy();
428 // call engine function
429 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
430 res = ieOp->ExportXAO(m_mainObj, groups, fields,
431 author.toStdString().c_str(),
432 fileName.toStdString().c_str());