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>
22 #include <GEOM_Field.hxx>
24 #include <SUIT_Session.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_OverrideCursor.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_Study.h>
29 #include <LightApp_SelectionMgr.h>
30 #include <SalomeApp_Tools.h>
34 #include <QButtonGroup>
35 #include <QListWidget>
36 #include <QFileDialog>
40 #include <TopoDS_Shape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <GEOMImpl_Types.hxx>
47 #include "ImportExportGUI_ImportXAODlg.h"
49 #include <SALOMEDS_wrap.hxx>
51 //=================================================================================
53 //=================================================================================
54 ImportExportGUI_ImportXAODlg::ImportExportGUI_ImportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
56 GEOMBase_Skeleton(geometryGUI, parent, false)
58 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
59 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_IMPORTXAO")));
60 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_IMPORTXAO_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_IMPORTXAO_TITLE"));
66 mainFrame()->RadioButton1->setIcon(imageOp);
67 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton3->close();
73 mainFrame()->GroupBoxName->hide();
75 //****************************
76 // Selection Group box
77 QGroupBox* gbxExport = new QGroupBox(parent);
79 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
81 gridLayoutExport->setSpacing(6);
82 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
84 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
86 int line = 0, col = 0;
87 QLabel* lblFileName = new QLabel(tr("GEOM_IMPORTXAO_FILENAME"), gbxExport);
88 btnFileSelect = new QPushButton(gbxExport);
89 ledFileName = new QLineEdit(gbxExport);
90 btnFileSelect->setText("...");
93 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
94 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
95 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
97 //****************************
98 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
100 layout->setSpacing(6);
101 layout->addWidget(gbxExport);
104 setHelpFileName("create_importxao_page.html");
109 //=================================================================================
111 //=================================================================================
112 ImportExportGUI_ImportXAODlg::~ImportExportGUI_ImportXAODlg()
114 // no need to delete child widgets, Qt does it all for us
117 //=================================================================================
120 //=================================================================================
121 void ImportExportGUI_ImportXAODlg::Init()
123 // Signal/slot connections
124 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
129 initName(tr("GEOM_IMPORTXAO"));
130 //SelectionIntoArgument();
133 //=================================================================================
134 // function : ClickOnOk()
136 //=================================================================================
137 void ImportExportGUI_ImportXAODlg::ClickOnOk()
143 //=================================================================================
144 // function : ClickOnApply()
146 //=================================================================================
147 /*bool ImportExportGUI_ImportXAODlg::ClickOnApply()
157 bool ImportExportGUI_ImportXAODlg::ClickOnApply()
159 if(!isApplyAndClose()) {
160 setIsDisableBrowsing( true );
161 setIsDisplayResult( false );
165 if ( !isValid( msg ) ) {
169 SUIT_OverrideCursor wc;
170 SUIT_Session::session()->activeApplication()->putInfo( "" );
174 if (!execute (/*isApplyAndClose()*/))
181 catch( const SALOME::SALOME_Exception& e ) {
182 SalomeApp_Tools::QtCatchCorbaException( e );
188 if(!isApplyAndClose()) {
189 setIsDisableBrowsing( false );
190 setIsDisplayResult( true );
196 //=================================================================================
197 // function : btnFileSelectClicked()
199 //=================================================================================
200 void ImportExportGUI_ImportXAODlg::btnFileSelectClicked()
202 QString selFile = QFileDialog::getOpenFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
203 QString(), tr("XAO_FILES"));
204 if (!selFile.isEmpty())
206 ledFileName->setText(selFile);
210 //=================================================================================
211 // function : ActivateThisDialog()
213 //=================================================================================
214 void ImportExportGUI_ImportXAODlg::ActivateThisDialog()
216 GEOMBase_Skeleton::ActivateThisDialog();
219 //=================================================================================
220 // function : enterEvent [REDEFINED]
222 //=================================================================================
223 void ImportExportGUI_ImportXAODlg::enterEvent(QEvent*)
225 if (!mainFrame()->GroupConstructors->isEnabled())
226 ActivateThisDialog();
229 //=================================================================================
230 // function : createOperation
232 //=================================================================================
233 GEOM::GEOM_IOperations_ptr ImportExportGUI_ImportXAODlg::createOperation()
235 return getGeomEngine()->GetIInsertOperations(getStudyId());
238 //=================================================================================
239 // function : isValid
241 //=================================================================================
242 bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
245 if (ledFileName->text().isEmpty())
251 //=================================================================================
252 // function : execute
254 //=================================================================================
255 bool ImportExportGUI_ImportXAODlg::execute()
259 QString fileName = ledFileName->text();
260 GEOM::GEOM_Object_var shape;
261 GEOM::ListOfGO_var groups, subShapes;
262 GEOM::ListOfFields_var fields;
264 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
265 res = ieOp->ImportXAO(fileName.toStdString().c_str(), shape, subShapes, groups, fields);
267 if (!shape->_is_nil())
276 if (m_mainShape != NULL)
278 addInStudy(m_mainShape, m_mainShape->GetName());
280 for (int i = 0; i < subShapes->length(); i++)
282 addInStudy(subShapes[i].in(), subShapes[i]->GetName());
284 for (int i = 0; i < groups->length(); i++)
286 addInStudy(groups[i].in(), groups[i]->GetName());
288 for (int i = 0; i < fields->length(); i++)
290 addFieldInStudy(fields[i].in(), m_mainShape);
299 QString ImportExportGUI_ImportXAODlg::addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather)
304 _PTR(Study) aStudy = getStudy()->studyDS();
305 if ( !aStudy || theField->_is_nil() )
308 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
310 SALOMEDS::SObject_var aSO =
311 getGeomEngine()->AddInStudy(aStudyDS, theField, theField->GetName(), theFather);
314 if ( !aSO->_is_nil() ) {
315 CORBA::String_var entry = aSO->GetID();
316 anEntry = entry.in();
320 GEOM::ListOfLong_var steps = theField->GetSteps();
321 for (int i = 0; i < steps->length(); ++i)
323 GEOM::GEOM_FieldStep_ptr step = theField->GetStep(steps[i]);
324 QString stepName = (tr("STEP") + " %1 %2").arg( step->GetID() ).arg( step->GetStamp() );
325 SALOMEDS::SObject_wrap aSOField =
326 getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), theField );
334 GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
336 GEOM::GEOM_Object_var fatherObj;
337 if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
339 //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
340 //fatherObj = groupOper->GetMainShape(object);
341 fatherObj = m_mainShape;
343 return fatherObj._retn();
346 QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object) const
348 if (object->_is_nil())
349 return QString::null;
350 return object->GetName();