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 <GeometryGUI.h>
23 #include <GEOM_Field.hxx>
25 #include <SUIT_Session.h>
26 #include <SUIT_ResourceMgr.h>
27 #include <SUIT_OverrideCursor.h>
28 #include <SUIT_FileDlg.h>
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Study.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SalomeApp_Tools.h>
36 #include <QButtonGroup>
37 #include <QListWidget>
38 #include <QFileDialog>
42 #include <TopoDS_Shape.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <GEOMImpl_Types.hxx>
49 #include "ImportExportGUI_ImportXAODlg.h"
51 #include <SALOMEDS_wrap.hxx>
53 //=================================================================================
55 //=================================================================================
56 ImportExportGUI_ImportXAODlg::ImportExportGUI_ImportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
58 GEOMBase_Skeleton(geometryGUI, parent, false)
60 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
61 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_IMPORTXAO")));
62 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
64 setWindowTitle(tr("GEOM_IMPORTXAO_TITLE"));
66 /***************************************************************/
67 mainFrame()->GroupConstructors->setTitle(tr("GEOM_IMPORTXAO_TITLE"));
68 mainFrame()->RadioButton1->setIcon(imageOp);
69 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
70 mainFrame()->RadioButton2->close();
71 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72 mainFrame()->RadioButton3->close();
75 mainFrame()->GroupBoxName->hide();
77 //****************************
78 // Selection Group box
79 QGroupBox* gbxExport = new QGroupBox(parent);
81 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
83 gridLayoutExport->setSpacing(6);
84 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
86 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
88 int line = 0, col = 0;
89 QLabel* lblFileName = new QLabel(tr("GEOM_IMPORTXAO_FILENAME"), gbxExport);
90 btnFileSelect = new QPushButton(gbxExport);
91 ledFileName = new QLineEdit(gbxExport);
92 btnFileSelect->setText("...");
95 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
96 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
97 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
99 //****************************
100 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
101 layout->setMargin(0);
102 layout->setSpacing(6);
103 layout->addWidget(gbxExport);
106 setHelpFileName("xao_format_page.html");
111 //=================================================================================
113 //=================================================================================
114 ImportExportGUI_ImportXAODlg::~ImportExportGUI_ImportXAODlg()
116 // no need to delete child widgets, Qt does it all for us
119 //=================================================================================
122 //=================================================================================
123 void ImportExportGUI_ImportXAODlg::Init()
125 // Signal/slot connections
126 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
131 initName(tr("GEOM_IMPORTXAO"));
132 //SelectionIntoArgument();
135 //=================================================================================
136 // function : ClickOnOk()
138 //=================================================================================
139 void ImportExportGUI_ImportXAODlg::ClickOnOk()
141 setIsApplyAndClose(true);
144 setIsApplyAndClose(false);
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 bool ImportExportGUI_ImportXAODlg::ClickOnApply()
153 if(!isApplyAndClose()) {
154 setIsDisableBrowsing( true );
155 setIsDisplayResult( false );
159 if ( !isValid( msg ) ) {
163 SUIT_OverrideCursor wc;
164 SUIT_Session::session()->activeApplication()->putInfo( "" );
168 if (!execute (/*isApplyAndClose()*/))
175 catch( const SALOME::SALOME_Exception& e ) {
176 SalomeApp_Tools::QtCatchCorbaException( e );
182 if(!isApplyAndClose()) {
183 setIsDisableBrowsing( false );
184 setIsDisplayResult( true );
190 //=================================================================================
191 // function : btnFileSelectClicked()
193 //=================================================================================
194 void ImportExportGUI_ImportXAODlg::btnFileSelectClicked()
196 QString file = SUIT_FileDlg::getFileName(this, ledFileName->text(),
198 tr("GEOM_SELECT_IMPORT_XAO"));
199 if ( !file.isEmpty() )
200 ledFileName->setText( file );
203 //=================================================================================
204 // function : ActivateThisDialog()
206 //=================================================================================
207 void ImportExportGUI_ImportXAODlg::ActivateThisDialog()
209 GEOMBase_Skeleton::ActivateThisDialog();
212 //=================================================================================
213 // function : enterEvent [REDEFINED]
215 //=================================================================================
216 void ImportExportGUI_ImportXAODlg::enterEvent(QEvent*)
218 if (!mainFrame()->GroupConstructors->isEnabled())
219 ActivateThisDialog();
222 //=================================================================================
223 // function : createOperation
225 //=================================================================================
226 GEOM::GEOM_IOperations_ptr ImportExportGUI_ImportXAODlg::createOperation()
228 return getGeomEngine()->GetIInsertOperations(getStudyId());
231 //=================================================================================
232 // function : isValid
234 //=================================================================================
235 bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
238 if (ledFileName->text().isEmpty())
244 //=================================================================================
245 // function : execute
247 //=================================================================================
248 bool ImportExportGUI_ImportXAODlg::execute()
252 QString fileName = ledFileName->text();
253 GEOM::GEOM_Object_var shape;
254 GEOM::ListOfGO_var groups, subShapes;
255 GEOM::ListOfFields_var fields;
257 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
258 res = ieOp->ImportXAO(fileName.toUtf8().constData(), shape, subShapes, groups, fields);
260 if (!shape->_is_nil())
269 if (m_mainShape != NULL)
271 QStringList anEntryList;
272 anEntryList << addInStudy(m_mainShape, m_mainShape->GetName());
274 for (int i = 0; i < subShapes->length(); i++)
276 addInStudy(subShapes[i].in(), subShapes[i]->GetName());
278 for (int i = 0; i < groups->length(); i++)
280 addInStudy(groups[i].in(), groups[i]->GetName());
282 for (int i = 0; i < fields->length(); i++)
284 addFieldInStudy(fields[i].in(), m_mainShape);
288 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
289 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
290 aLightApp->browseObjects( anEntryList );
297 QString ImportExportGUI_ImportXAODlg::addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather)
302 _PTR(Study) aStudy = getStudy()->studyDS();
303 if ( !aStudy || theField->_is_nil() )
306 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
308 SALOMEDS::SObject_var aSO =
309 getGeomEngine()->AddInStudy(aStudyDS, theField, theField->GetName(), theFather);
312 if ( !aSO->_is_nil() ) {
313 CORBA::String_var entry = aSO->GetID();
314 anEntry = entry.in();
318 GEOM::ListOfLong_var steps = theField->GetSteps();
319 for (int i = 0; i < steps->length(); ++i)
321 GEOM::GEOM_FieldStep_ptr step = theField->GetStep(steps[i]);
322 QString stepName = (tr("STEP") + " %1 %2").arg( step->GetID() ).arg( step->GetStamp() );
323 SALOMEDS::SObject_wrap aSOField =
324 getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), theField );
332 GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
334 GEOM::GEOM_Object_var fatherObj;
335 if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
337 //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
338 //fatherObj = groupOper->GetMainShape(object);
339 fatherObj = m_mainShape;
341 return fatherObj._retn();
344 QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object) const
346 if (object->_is_nil())
347 return QString::null;
348 return object->GetName();