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 "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>
59 //=================================================================================
61 //=================================================================================
62 XAOPlugin_ExportDlg::XAOPlugin_ExportDlg(GeometryGUI* geometryGUI, QWidget* parent)
64 GEOMBase_Skeleton(geometryGUI, parent, false)
66 m_mainObj = GEOM::GEOM_Object::_nil();
68 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
69 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("XAOPLUGIN_EXPORT_ICON")));
70 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
72 setWindowTitle(tr("XAOPLUGIN_EXPORT_TITLE"));
74 /***************************************************************/
75 mainFrame()->GroupConstructors->setTitle(tr("XAOPLUGIN_EXPORT_TITLE"));
76 mainFrame()->RadioButton1->setIcon(imageOp);
77 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
78 mainFrame()->RadioButton2->close();
79 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
80 mainFrame()->RadioButton3->close();
83 mainFrame()->GroupBoxName->hide();
85 //****************************
86 // Selection Group box
87 QGroupBox* gbxExport = new QGroupBox(parent);
89 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
91 gridLayoutExport->setSpacing(6);
92 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
94 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
97 QLabel* lblShape = new QLabel(tr("XAOPLUGIN_EXPORT_INGSHAPE"), gbxExport);
98 btnShapeSelect = new QPushButton(gbxExport);
99 btnShapeSelect->setIcon(iconSelect);
100 ledShape = new QLineEdit(gbxExport);
101 ledShape->setMinimumSize(QSize(100, 0));
103 int line = 0, col = 0;
104 gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
105 gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
106 gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
109 QLabel* lblFileName = new QLabel(tr("XAOPLUGIN_EXPORT_FILENAME"), gbxExport);
110 btnFileSelect = new QPushButton(gbxExport);
111 ledFileName = new QLineEdit(gbxExport);
112 btnFileSelect->setText("...");
115 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
116 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
117 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
120 QLabel* lblAuthor = new QLabel(tr("XAOPLUGIN_EXPORT_AUTHOR"), gbxExport);
121 ledAuthor = new QLineEdit(gbxExport);
124 gridLayoutExport->addWidget(lblAuthor, line, col++, 2, 1);
126 gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
128 //****************************
130 QGroupBox* gbxFilter = new QGroupBox(parent);
132 QGridLayout* gridLayoutFilter = new QGridLayout(gbxFilter);
134 gridLayoutFilter->setSpacing(6);
135 gridLayoutFilter->setContentsMargins(9, 9, 9, 9);
137 gridLayoutFilter->setObjectName(QString::fromUtf8("gbxFilter"));
140 QLabel* lblGroups = new QLabel(tr("XAOPLUGIN_EXPORT_LGROUPS"), gbxFilter);
141 QLabel* lblFields = new QLabel(tr("XAOPLUGIN_EXPORT_LFIELDS"), gbxFilter);
144 gridLayoutFilter->addWidget(lblGroups, line, col++, 1, 1);
145 gridLayoutFilter->addWidget(lblFields, line, col++, 1, 1);
148 lstGroups = new QListWidget(gbxFilter);
149 lstGroups->setSelectionMode(QAbstractItemView::NoSelection);
150 lstFields = new QListWidget(gbxFilter);
151 lstFields->setSelectionMode(QAbstractItemView::NoSelection);
154 gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1);
155 gridLayoutFilter->addWidget(lstFields, line, col++, 1, 1);
157 //****************************
158 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
159 layout->setMargin(0);
160 layout->setSpacing(6);
161 layout->addWidget(gbxExport);
162 layout->addWidget(gbxFilter);
165 setHelpFileName("xao_format_page.html");
170 //=================================================================================
172 //=================================================================================
173 XAOPlugin_ExportDlg::~XAOPlugin_ExportDlg()
175 // no need to delete child widgets, Qt does it all for us
178 //=================================================================================
181 //=================================================================================
182 void XAOPlugin_ExportDlg::Init()
184 // Get setting of step value from file configuration
188 // Signal/slot connections
189 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
190 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
192 connect(btnShapeSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
193 connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
194 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
198 initName(tr("XAOPLUGIN_EXPORTXAO"));
199 SelectionIntoArgument();
202 //=================================================================================
203 // function : processObject()
204 // purpose : Fill dialog fields in accordance with myObj
205 //=================================================================================
206 void XAOPlugin_ExportDlg::processObject()
213 if (m_mainObj->_is_nil())
215 ledShape->setText("");
219 ledShape->setText(GEOMBase::GetName(m_mainObj));
220 GEOM::GEOM_IShapesOperations_var shapeOp = getGeomEngine()->GetIShapesOperations(getStudyId());
223 GEOM::ListOfGO_var groups = shapeOp->GetExistingSubObjects(m_mainObj, true);
224 for (int i = 0, n = groups->length(); i < n; i++)
226 QListWidgetItem* item = new QListWidgetItem();
227 item->setData(Qt::UserRole, QVariant(i));
228 item->setText(GEOMBase::GetName(groups[i]));
229 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
230 item->setCheckState(Qt::Checked);
231 lstGroups->addItem(item);
232 m_groups.append(GEOM::GeomObjPtr(groups[i].in()));
234 lstGroups->sortItems(Qt::AscendingOrder);
237 GEOM::GEOM_IFieldOperations_var fieldOp = getGeomEngine()->GetIFieldOperations(getStudyId());
239 GEOM::ListOfFields_var fields = fieldOp->GetFields(m_mainObj);
240 for (int i = 0, n = fields->length(); i < n; i++)
242 QListWidgetItem* item = new QListWidgetItem();
243 item->setData(Qt::UserRole, QVariant(i));
244 item->setText(fields[i]->GetName());
245 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
246 item->setCheckState(Qt::Checked);
247 lstFields->addItem(item);
248 m_fields.append(GEOM::GeomFieldPtr(fields[i].in()));
250 lstFields->sortItems(Qt::AscendingOrder);
254 //=================================================================================
255 // function : ClickOnOk()
257 //=================================================================================
258 void XAOPlugin_ExportDlg::ClickOnOk()
260 setIsApplyAndClose(true);
263 setIsApplyAndClose(false);
266 //=================================================================================
267 // function : ClickOnApply()
269 //=================================================================================
270 bool XAOPlugin_ExportDlg::ClickOnApply()
272 if (!isApplyAndClose())
274 setIsDisableBrowsing(true);
275 setIsDisplayResult(false);
284 SUIT_OverrideCursor wc;
285 SUIT_Session::session()->activeApplication()->putInfo("");
297 catch (const SALOME::SALOME_Exception& e)
299 SalomeApp_Tools::QtCatchCorbaException(e);
305 if (!isApplyAndClose())
307 setIsDisableBrowsing(false);
308 setIsDisplayResult(true);
315 //=================================================================================
316 // function : SelectionIntoArgument()
317 // purpose : Called when selection as changed or other case
318 //=================================================================================
319 void XAOPlugin_ExportDlg::SelectionIntoArgument()
321 m_mainObj = GEOM::GEOM_Object::_nil();
322 LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
323 SALOME_ListIO selList;
324 selMgr->selectedObjects(selList);
326 if (selList.Extent() == 1)
328 m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First());
334 //=================================================================================
335 // function : SetEditCurrentArgument()
337 //=================================================================================
338 void XAOPlugin_ExportDlg::SetEditCurrentArgument()
340 ledShape->setFocus();
341 myEditCurrentArgument = ledShape;
342 SelectionIntoArgument();
345 //=================================================================================
346 // function : btnFileSelectClicked()
348 //=================================================================================
349 void XAOPlugin_ExportDlg::btnFileSelectClicked()
351 QString file = SUIT_FileDlg::getFileName(this, ledFileName->text(),
352 tr("XAOPLUGIN_FILES"),
353 tr("XAOPLUGIN_EXPORT_SELECT"), false);
354 if ( !file.isEmpty() )
355 ledFileName->setText( file );
358 //=================================================================================
359 // function : ActivateThisDialog()
361 //=================================================================================
362 void XAOPlugin_ExportDlg::ActivateThisDialog()
364 GEOMBase_Skeleton::ActivateThisDialog();
367 //=================================================================================
368 // function : enterEvent [REDEFINED]
370 //=================================================================================
371 void XAOPlugin_ExportDlg::enterEvent(QEvent*)
373 if (!mainFrame()->GroupConstructors->isEnabled())
374 ActivateThisDialog();
377 //=================================================================================
378 // function : createOperation
380 //=================================================================================
381 GEOM::GEOM_IOperations_ptr XAOPlugin_ExportDlg::createOperation()
383 return getGeomEngine()->GetPluginOperations( getStudyId(), "XAOPluginEngine" );
386 //=================================================================================
387 // function : isValid
389 //=================================================================================
390 bool XAOPlugin_ExportDlg::isValid(QString& msg)
393 if (ledShape->text().isEmpty())
397 if (ledFileName->text().isEmpty())
403 //=================================================================================
404 // function : execute
406 //=================================================================================
407 bool XAOPlugin_ExportDlg::execute()
411 QString author = ledAuthor->text();
412 QString fileName = ledFileName->text();
414 // get selected groups
415 QList<QListWidgetItem*> selGroups;
416 for (int j = 0; j < lstGroups->count(); ++j)
418 if (lstGroups->item(j)->checkState() == Qt::Checked)
419 selGroups.append(lstGroups->item(j));
422 GEOM::ListOfGO_var groups = new GEOM::ListOfGO();
423 groups->length(selGroups.count());
425 for (QList<QListWidgetItem*>::iterator it = selGroups.begin(); it != selGroups.end(); ++it)
427 QListWidgetItem* item = (*it);
428 int index = item->data(Qt::UserRole).toInt();
429 groups[i++] = m_groups[index].copy();
432 // get selected fields
433 QList<QListWidgetItem*> selFields;
434 for (int j = 0; j < lstFields->count(); ++j)
436 if (lstFields->item(j)->checkState() == Qt::Checked)
437 selFields.append(lstFields->item(j));
440 GEOM::ListOfFields_var fields = new GEOM::ListOfFields();
441 fields->length(selFields.count());
443 for (QList<QListWidgetItem*>::iterator it = selFields.begin(); it != selFields.end(); ++it)
445 QListWidgetItem* item = (*it);
446 int index = item->data(Qt::UserRole).toInt();
447 fields[i++] = m_fields[index].copy();
450 // call engine function
451 GEOM::IXAOOperations_var aXAOOp = GEOM::IXAOOperations::_narrow( getOperation() );
452 res = aXAOOp->ExportXAO(m_mainObj, groups, fields,
453 author.toStdString().c_str(),
454 fileName.toStdString().c_str());