1 // Copyright (C) 2013-2021 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 "XAOPlugin_ExportDlg.h"
22 #include "XAOPlugin_IOperations_i.hh"
25 #include <SUIT_Session.h>
26 #include <SUIT_ResourceMgr.h>
27 #include <SUIT_OverrideCursor.h>
28 #include <SUIT_FileDlg.h>
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Study.h>
32 #include <SalomeApp_Tools.h>
33 #include <LightApp_SelectionMgr.h>
36 #include "GeometryGUI.h"
38 #include "GEOMImpl_Types.hxx"
41 #include <TopoDS_Shape.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <QButtonGroup>
51 #include <QListWidget>
52 #include <QFileDialog>
54 #include <QRadioButton>
55 #include <QGridLayout>
56 #include <QPushButton>
60 //=================================================================================
62 //=================================================================================
63 XAOPlugin_ExportDlg::XAOPlugin_ExportDlg(GeometryGUI* geometryGUI, QWidget* parent)
65 GEOMBase_Skeleton(geometryGUI, parent, false)
67 m_mainObj = GEOM::GEOM_Object::_nil();
69 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
70 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("XAOPLUGIN_EXPORT_ICON")));
71 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
73 setWindowTitle(tr("XAOPLUGIN_EXPORT_TITLE"));
75 /***************************************************************/
76 mainFrame()->GroupConstructors->setTitle(tr("XAOPLUGIN_EXPORT_TITLE"));
77 mainFrame()->RadioButton1->setIcon(imageOp);
78 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
79 mainFrame()->RadioButton2->close();
80 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
81 mainFrame()->RadioButton3->close();
84 mainFrame()->GroupBoxName->hide();
86 //****************************
87 // Selection Group box
88 QGroupBox* gbxExport = new QGroupBox(parent);
90 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
92 gridLayoutExport->setSpacing(6);
93 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
95 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
98 QLabel* lblShape = new QLabel(tr("XAOPLUGIN_EXPORT_INGSHAPE"), gbxExport);
99 btnShapeSelect = new QPushButton(gbxExport);
100 btnShapeSelect->setIcon(iconSelect);
101 ledShape = new QLineEdit(gbxExport);
102 ledShape->setMinimumSize(QSize(100, 0));
104 int line = 0, col = 0;
105 // adWidget(widget, fromRow, fromColumn, rowSpan, columnSpan)
106 gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
107 gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
108 gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
111 QLabel* lblFileName = new QLabel(tr("XAOPLUGIN_EXPORT_FILENAME"), gbxExport);
112 btnFileSelect = new QPushButton(gbxExport);
113 ledFileName = new QLineEdit(gbxExport);
114 btnFileSelect->setText("...");
117 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
118 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
119 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
122 QLabel* lblAuthor = new QLabel(tr("XAOPLUGIN_EXPORT_AUTHOR"), gbxExport);
123 ledAuthor = new QLineEdit(gbxExport);
126 gridLayoutExport->addWidget(lblAuthor, line, col++, 1, 1);
128 gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
131 ckxUseSeparateFile = new QCheckBox(tr("XAOPLUGIN_EXPORT_SHAPEFILE"), gbxExport);
134 gridLayoutExport->addWidget(ckxUseSeparateFile, line, col++, 1, 2);
137 //****************************
139 QGroupBox* gbxFilter = new QGroupBox(parent);
141 QGridLayout* gridLayoutFilter = new QGridLayout(gbxFilter);
143 gridLayoutFilter->setSpacing(6);
144 gridLayoutFilter->setContentsMargins(9, 9, 9, 9);
146 gridLayoutFilter->setObjectName(QString::fromUtf8("gbxFilter"));
149 QLabel* lblGroups = new QLabel(tr("XAOPLUGIN_EXPORT_LGROUPS"), gbxFilter);
150 QLabel* lblFields = new QLabel(tr("XAOPLUGIN_EXPORT_LFIELDS"), gbxFilter);
153 gridLayoutFilter->addWidget(lblGroups, line, col++, 1, 1);
154 gridLayoutFilter->addWidget(lblFields, line, col++, 1, 1);
157 lstGroups = new QListWidget(gbxFilter);
158 lstGroups->setSelectionMode(QAbstractItemView::NoSelection);
159 lstFields = new QListWidget(gbxFilter);
160 lstFields->setSelectionMode(QAbstractItemView::NoSelection);
163 gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1);
164 gridLayoutFilter->addWidget(lstFields, line, col++, 1, 1);
166 //****************************
167 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
168 layout->setMargin(0);
169 layout->setSpacing(6);
170 layout->addWidget(gbxExport);
171 layout->addWidget(gbxFilter);
174 setHelpFileName("import_export_geom_obj_page.html#io_xao");
179 //=================================================================================
181 //=================================================================================
182 XAOPlugin_ExportDlg::~XAOPlugin_ExportDlg()
184 // no need to delete child widgets, Qt does it all for us
187 //=================================================================================
190 //=================================================================================
191 void XAOPlugin_ExportDlg::Init()
193 // Get setting of step value from file configuration
197 // Signal/slot connections
198 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
199 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
201 connect(btnShapeSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
202 connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
203 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
205 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
207 initName(tr("XAOPLUGIN_EXPORTXAO"));
208 SelectionIntoArgument();
211 //=================================================================================
212 // function : processObject()
213 // purpose : Fill dialog fields in accordance with myObj
214 //=================================================================================
215 void XAOPlugin_ExportDlg::processObject()
222 if (m_mainObj->_is_nil())
224 ledShape->setText("");
228 ledShape->setText(GEOMBase::GetName(m_mainObj));
229 GEOM::GEOM_IShapesOperations_var shapeOp = getGeomEngine()->GetIShapesOperations();
232 GEOM::ListOfGO_var groups = shapeOp->GetExistingSubObjects(m_mainObj, true);
233 for (int i = 0, n = groups->length(); i < n; i++)
235 QListWidgetItem* item = new QListWidgetItem();
236 item->setData(Qt::UserRole, QVariant(i));
237 item->setText(GEOMBase::GetName(groups[i]));
238 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
239 item->setCheckState(Qt::Checked);
240 lstGroups->addItem(item);
241 m_groups.append(GEOM::GeomObjPtr(groups[i].in()));
243 lstGroups->sortItems(Qt::AscendingOrder);
246 GEOM::GEOM_IFieldOperations_var fieldOp = getGeomEngine()->GetIFieldOperations();
248 GEOM::ListOfFields_var fields = fieldOp->GetFields(m_mainObj);
249 for (int i = 0, n = fields->length(); i < n; i++)
251 QListWidgetItem* item = new QListWidgetItem();
252 item->setData(Qt::UserRole, QVariant(i));
253 item->setText(fields[i]->GetName());
254 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
255 item->setCheckState(Qt::Checked);
256 lstFields->addItem(item);
257 m_fields.append(GEOM::GeomFieldPtr(fields[i].in()));
259 lstFields->sortItems(Qt::AscendingOrder);
263 //=================================================================================
264 // function : ClickOnOk()
266 //=================================================================================
267 void XAOPlugin_ExportDlg::ClickOnOk()
269 setIsApplyAndClose(true);
272 setIsApplyAndClose(false);
275 //=================================================================================
276 // function : ClickOnApply()
278 //=================================================================================
279 bool XAOPlugin_ExportDlg::ClickOnApply()
281 if (!isApplyAndClose())
283 setIsDisableBrowsing(true);
284 setIsDisplayResult(false);
293 SUIT_OverrideCursor wc;
294 SUIT_Session::session()->activeApplication()->putInfo("");
306 catch (const SALOME::SALOME_Exception& e)
308 SalomeApp_Tools::QtCatchCorbaException(e);
314 if (!isApplyAndClose())
316 setIsDisableBrowsing(false);
317 setIsDisplayResult(true);
324 //=================================================================================
325 // function : SelectionIntoArgument()
326 // purpose : Called when selection as changed or other case
327 //=================================================================================
328 void XAOPlugin_ExportDlg::SelectionIntoArgument()
330 m_mainObj = GEOM::GEOM_Object::_nil();
331 LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
332 SALOME_ListIO selList;
333 selMgr->selectedObjects(selList);
335 if (selList.Extent() == 1)
337 m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First());
343 //=================================================================================
344 // function : SetEditCurrentArgument()
346 //=================================================================================
347 void XAOPlugin_ExportDlg::SetEditCurrentArgument()
349 ledShape->setFocus();
350 myEditCurrentArgument = ledShape;
351 SelectionIntoArgument();
354 //=================================================================================
355 // function : btnFileSelectClicked()
357 //=================================================================================
358 void XAOPlugin_ExportDlg::btnFileSelectClicked()
360 QString file = SUIT_FileDlg::getFileName(this, ledFileName->text(),
361 tr("XAOPLUGIN_FILES"),
362 tr("XAOPLUGIN_EXPORT_SELECT"), false);
363 if ( !file.isEmpty() )
364 ledFileName->setText( file );
367 //=================================================================================
368 // function : ActivateThisDialog()
370 //=================================================================================
371 void XAOPlugin_ExportDlg::ActivateThisDialog()
373 GEOMBase_Skeleton::ActivateThisDialog();
376 //=================================================================================
377 // function : enterEvent [REDEFINED]
379 //=================================================================================
380 void XAOPlugin_ExportDlg::enterEvent(QEvent*)
382 if (!mainFrame()->GroupConstructors->isEnabled())
383 ActivateThisDialog();
386 //=================================================================================
387 // function : createOperation
389 //=================================================================================
390 GEOM::GEOM_IOperations_ptr XAOPlugin_ExportDlg::createOperation()
392 return getGeomEngine()->GetPluginOperations( "XAOPluginEngine" );
395 //=================================================================================
396 // function : isValid
398 //=================================================================================
399 bool XAOPlugin_ExportDlg::isValid(QString& /*msg*/)
402 if (ledShape->text().isEmpty())
406 if (ledFileName->text().isEmpty())
412 //=================================================================================
413 // function : execute
415 //=================================================================================
416 bool XAOPlugin_ExportDlg::execute()
420 QString author = ledAuthor->text();
421 QString fileName = ledFileName->text();
422 QString shapeFileName = QString("");//ledShapeFile->text();
423 if (ckxUseSeparateFile->isChecked())
425 shapeFileName = fileName;
426 shapeFileName.append(".brep");
429 // get selected groups
430 QList<QListWidgetItem*> selGroups;
431 for (int j = 0; j < lstGroups->count(); ++j)
433 if (lstGroups->item(j)->checkState() == Qt::Checked)
434 selGroups.append(lstGroups->item(j));
437 GEOM::ListOfGO_var groups = new GEOM::ListOfGO();
438 groups->length(selGroups.count());
440 for (QList<QListWidgetItem*>::iterator it = selGroups.begin(); it != selGroups.end(); ++it)
442 QListWidgetItem* item = (*it);
443 int index = item->data(Qt::UserRole).toInt();
444 groups[i++] = m_groups[index].copy();
447 // get selected fields
448 QList<QListWidgetItem*> selFields;
449 for (int j = 0; j < lstFields->count(); ++j)
451 if (lstFields->item(j)->checkState() == Qt::Checked)
452 selFields.append(lstFields->item(j));
455 GEOM::ListOfFields_var fields = new GEOM::ListOfFields();
456 fields->length(selFields.count());
458 for (QList<QListWidgetItem*>::iterator it = selFields.begin(); it != selFields.end(); ++it)
460 QListWidgetItem* item = (*it);
461 int index = item->data(Qt::UserRole).toInt();
462 fields[i++] = m_fields[index].copy();
465 // call engine function
466 GEOM::IXAOOperations_var aXAOOp = GEOM::IXAOOperations::_narrow( getOperation() );
467 res = aXAOOp->ExportXAO(m_mainObj, groups, fields,
468 author.toUtf8().constData(),
469 fileName.toUtf8().constData(),
470 shapeFileName.toStdString().c_str());