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("xao_format_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()
139 setIsApplyAndClose(true);
142 setIsApplyAndClose(false);
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool ImportExportGUI_ImportXAODlg::ClickOnApply()
151 if(!isApplyAndClose()) {
152 setIsDisableBrowsing( true );
153 setIsDisplayResult( false );
157 if ( !isValid( msg ) ) {
161 SUIT_OverrideCursor wc;
162 SUIT_Session::session()->activeApplication()->putInfo( "" );
166 if (!execute (/*isApplyAndClose()*/))
173 catch( const SALOME::SALOME_Exception& e ) {
174 SalomeApp_Tools::QtCatchCorbaException( e );
180 if(!isApplyAndClose()) {
181 setIsDisableBrowsing( false );
182 setIsDisplayResult( true );
188 //=================================================================================
189 // function : btnFileSelectClicked()
191 //=================================================================================
192 void ImportExportGUI_ImportXAODlg::btnFileSelectClicked()
194 QString selFile = QFileDialog::getOpenFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
195 QString(), tr("XAO_FILES"));
196 if (!selFile.isEmpty())
198 ledFileName->setText(selFile);
202 //=================================================================================
203 // function : ActivateThisDialog()
205 //=================================================================================
206 void ImportExportGUI_ImportXAODlg::ActivateThisDialog()
208 GEOMBase_Skeleton::ActivateThisDialog();
211 //=================================================================================
212 // function : enterEvent [REDEFINED]
214 //=================================================================================
215 void ImportExportGUI_ImportXAODlg::enterEvent(QEvent*)
217 if (!mainFrame()->GroupConstructors->isEnabled())
218 ActivateThisDialog();
221 //=================================================================================
222 // function : createOperation
224 //=================================================================================
225 GEOM::GEOM_IOperations_ptr ImportExportGUI_ImportXAODlg::createOperation()
227 return getGeomEngine()->GetIInsertOperations(getStudyId());
230 //=================================================================================
231 // function : isValid
233 //=================================================================================
234 bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
237 if (ledFileName->text().isEmpty())
243 //=================================================================================
244 // function : execute
246 //=================================================================================
247 bool ImportExportGUI_ImportXAODlg::execute()
251 QString fileName = ledFileName->text();
252 GEOM::GEOM_Object_var shape;
253 GEOM::ListOfGO_var groups, subShapes;
254 GEOM::ListOfFields_var fields;
256 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
257 res = ieOp->ImportXAO(fileName.toUtf8().constData(), shape, subShapes, groups, fields);
259 if (!shape->_is_nil())
268 if (m_mainShape != NULL)
270 QStringList anEntryList;
271 anEntryList << addInStudy(m_mainShape, m_mainShape->GetName());
273 for (int i = 0; i < subShapes->length(); i++)
275 addInStudy(subShapes[i].in(), subShapes[i]->GetName());
277 for (int i = 0; i < groups->length(); i++)
279 addInStudy(groups[i].in(), groups[i]->GetName());
281 for (int i = 0; i < fields->length(); i++)
283 addFieldInStudy(fields[i].in(), m_mainShape);
287 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
288 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
289 aLightApp->browseObjects( anEntryList );
296 QString ImportExportGUI_ImportXAODlg::addFieldInStudy( GEOM::GEOM_Field_ptr theField, GEOM::GEOM_Object_ptr theFather)
301 _PTR(Study) aStudy = getStudy()->studyDS();
302 if ( !aStudy || theField->_is_nil() )
305 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
307 SALOMEDS::SObject_var aSO =
308 getGeomEngine()->AddInStudy(aStudyDS, theField, theField->GetName(), theFather);
311 if ( !aSO->_is_nil() ) {
312 CORBA::String_var entry = aSO->GetID();
313 anEntry = entry.in();
317 GEOM::ListOfLong_var steps = theField->GetSteps();
318 for (int i = 0; i < steps->length(); ++i)
320 GEOM::GEOM_FieldStep_ptr step = theField->GetStep(steps[i]);
321 QString stepName = (tr("STEP") + " %1 %2").arg( step->GetID() ).arg( step->GetStamp() );
322 SALOMEDS::SObject_wrap aSOField =
323 getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), theField );
331 GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
333 GEOM::GEOM_Object_var fatherObj;
334 if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
336 //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
337 //fatherObj = groupOper->GetMainShape(object);
338 fatherObj = m_mainShape;
340 return fatherObj._retn();
343 QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object) const
345 if (object->_is_nil())
346 return QString::null;
347 return object->GetName();