1 // Copyright (C) 2013-2016 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_ImportDlg.h"
22 #include "XAOPlugin_IOperations_i.hh"
25 #include <SALOMEDS_wrap.hxx>
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_OverrideCursor.h>
31 #include <SUIT_FileDlg.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SalomeApp_Tools.h>
39 #include "GeometryGUI.h"
41 #include "GEOM_Field.hxx"
42 #include "GEOMImpl_Types.hxx"
45 #include <TopoDS_Shape.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
54 #include <QButtonGroup>
55 #include <QListWidget>
56 #include <QFileDialog>
57 #include <QRadioButton>
59 #include <QGridLayout>
60 #include <QPushButton>
63 //=================================================================================
65 //=================================================================================
66 XAOPlugin_ImportDlg::XAOPlugin_ImportDlg(GeometryGUI* geometryGUI, QWidget* parent)
68 GEOMBase_Skeleton(geometryGUI, parent, false)
70 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
71 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("XAOPLUGIN_IMPORT_ICON")));
72 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
74 setWindowTitle(tr("XAOPLUGIN_IMPORT_TITLE"));
76 /***************************************************************/
77 mainFrame()->GroupConstructors->setTitle(tr("XAOPLUGIN_IMPORT_TITLE"));
78 mainFrame()->RadioButton1->setIcon(imageOp);
79 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
80 mainFrame()->RadioButton2->close();
81 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
82 mainFrame()->RadioButton3->close();
85 mainFrame()->GroupBoxName->hide();
87 //****************************
88 // Selection Group box
89 QGroupBox* gbxExport = new QGroupBox(parent);
91 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
93 gridLayoutExport->setSpacing(6);
94 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
96 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
98 int line = 0, col = 0;
99 QLabel* lblFileName = new QLabel(tr("XAOPLUGIN_IMPORT_FILENAME"), gbxExport);
100 btnFileSelect = new QPushButton(gbxExport);
101 ledFileName = new QLineEdit(gbxExport);
102 btnFileSelect->setText("...");
105 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
106 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
107 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
109 //****************************
110 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
111 layout->setMargin(0);
112 layout->setSpacing(6);
113 layout->addWidget(gbxExport);
116 setHelpFileName("import_export_geom_obj_page.html#io_xao");
121 //=================================================================================
123 //=================================================================================
124 XAOPlugin_ImportDlg::~XAOPlugin_ImportDlg()
126 // no need to delete child widgets, Qt does it all for us
129 //=================================================================================
132 //=================================================================================
133 void XAOPlugin_ImportDlg::Init()
135 // Signal/slot connections
136 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
141 initName(tr("XAOPLUGIN_IMPORTXAO"));
142 //SelectionIntoArgument();
145 //=================================================================================
146 // function : ClickOnOk()
148 //=================================================================================
149 void XAOPlugin_ImportDlg::ClickOnOk()
151 setIsApplyAndClose(true);
154 setIsApplyAndClose(false);
157 //=================================================================================
158 // function : ClickOnApply()
160 //=================================================================================
161 bool XAOPlugin_ImportDlg::ClickOnApply()
163 if(!isApplyAndClose()) {
164 setIsDisableBrowsing( true );
165 setIsDisplayResult( false );
169 if ( !isValid( msg ) ) {
173 SUIT_OverrideCursor wc;
174 SUIT_Session::session()->activeApplication()->putInfo( "" );
178 if (!execute (/*isApplyAndClose()*/))
185 catch( const SALOME::SALOME_Exception& e ) {
186 SalomeApp_Tools::QtCatchCorbaException( e );
192 if(!isApplyAndClose()) {
193 setIsDisableBrowsing( false );
194 setIsDisplayResult( true );
200 //=================================================================================
201 // function : btnFileSelectClicked()
203 //=================================================================================
204 void XAOPlugin_ImportDlg::btnFileSelectClicked()
206 QString file = SUIT_FileDlg::getFileName(this, ledFileName->text(),
207 tr("XAOPLUGIN_FILES"),
208 tr("XAOPLUGIN_IMPORT_SELECT"));
209 if ( !file.isEmpty() )
210 ledFileName->setText( file );
213 //=================================================================================
214 // function : ActivateThisDialog()
216 //=================================================================================
217 void XAOPlugin_ImportDlg::ActivateThisDialog()
219 GEOMBase_Skeleton::ActivateThisDialog();
222 //=================================================================================
223 // function : enterEvent [REDEFINED]
225 //=================================================================================
226 void XAOPlugin_ImportDlg::enterEvent(QEvent*)
228 if (!mainFrame()->GroupConstructors->isEnabled())
229 ActivateThisDialog();
232 //=================================================================================
233 // function : createOperation
235 //=================================================================================
236 GEOM::GEOM_IOperations_ptr XAOPlugin_ImportDlg::createOperation()
238 return getGeomEngine()->GetPluginOperations( getStudyId(), "XAOPluginEngine" );
241 //=================================================================================
242 // function : isValid
244 //=================================================================================
245 bool XAOPlugin_ImportDlg::isValid(QString& msg)
248 if (ledFileName->text().isEmpty())
254 //=================================================================================
255 // function : execute
257 //=================================================================================
258 bool XAOPlugin_ImportDlg::execute()
262 QString fileName = ledFileName->text();
263 GEOM::GEOM_Object_var shape;
264 GEOM::ListOfGO_var groups, subShapes;
265 GEOM::ListOfFields_var fields;
267 GEOM::IXAOOperations_var ieOp = GEOM::IXAOOperations::_narrow(getOperation());
268 res = ieOp->ImportXAO(fileName.toUtf8().constData(), shape, subShapes, groups, fields);
270 if (!shape->_is_nil())
279 if (m_mainShape != NULL)
281 QStringList anEntryList;
282 anEntryList << addInStudy(m_mainShape, m_mainShape->GetName());
283 m_mainShape->UnRegister();
284 for (CORBA::ULong i = 0; i < subShapes->length(); i++)
286 addInStudy(subShapes[i].in(), subShapes[i]->GetName());
287 subShapes[i]->UnRegister();
289 for (CORBA::ULong i = 0; i < groups->length(); i++)
291 addInStudy(groups[i].in(), groups[i]->GetName());
292 groups[i]->UnRegister();
294 for (CORBA::ULong i = 0; i < fields->length(); i++)
296 addFieldInStudy(fields[i].in(), m_mainShape);
300 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
301 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
302 aLightApp->browseObjects( anEntryList );
309 QString XAOPlugin_ImportDlg::addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather)
314 _PTR(Study) aStudy = getStudy()->studyDS();
315 if ( !aStudy || theField->_is_nil() )
318 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
320 SALOMEDS::SObject_var aSO =
321 getGeomEngine()->AddInStudy(aStudyDS, theField, theField->GetName(), theFather);
322 theField->UnRegister();
325 if ( !aSO->_is_nil() ) {
326 CORBA::String_var entry = aSO->GetID();
327 anEntry = entry.in();
331 GEOM::ListOfLong_var steps = theField->GetSteps();
332 for (CORBA::ULong i = 0; i < steps->length(); ++i)
334 GEOM::GEOM_FieldStep_ptr step = theField->GetStep(steps[i]);
335 QString stepName = (tr("XAOPLUGIN_STEP") + " %1 %2").arg( step->GetID() ).arg( step->GetStamp() );
336 SALOMEDS::SObject_wrap aSOField =
337 getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), theField );
346 GEOM::GEOM_Object_ptr XAOPlugin_ImportDlg::getFather(GEOM::GEOM_Object_ptr object)
348 GEOM::GEOM_Object_var fatherObj;
349 if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
351 //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
352 //fatherObj = groupOper->GetMainShape(object);
353 fatherObj = m_mainShape;
355 return fatherObj._retn();
358 QString XAOPlugin_ImportDlg::getObjectName(GEOM::GEOM_Object_ptr object) const
360 if (object->_is_nil())
361 return QString::null;
362 return object->GetName();