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>
23 #include <SUIT_Session.h>
24 #include <SUIT_ResourceMgr.h>
25 #include <SalomeApp_Application.h>
26 #include <SalomeApp_Study.h>
27 #include <LightApp_SelectionMgr.h>
31 #include <QButtonGroup>
32 #include <QListWidget>
33 #include <QFileDialog>
37 #include <TopoDS_Shape.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <GEOMImpl_Types.hxx>
44 #include "ImportExportGUI_ImportXAODlg.h"
46 //=================================================================================
48 //=================================================================================
49 ImportExportGUI_ImportXAODlg::ImportExportGUI_ImportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
51 GEOMBase_Skeleton(geometryGUI, parent, false)
53 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
54 QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_IMPORTXAO")));
55 QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
57 setWindowTitle(tr("GEOM_IMPORTXAO_TITLE"));
59 /***************************************************************/
60 mainFrame()->GroupConstructors->setTitle(tr("GEOM_IMPORTXAO_TITLE"));
61 mainFrame()->RadioButton1->setIcon(imageOp);
62 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
63 mainFrame()->RadioButton2->close();
64 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
65 mainFrame()->RadioButton3->close();
68 mainFrame()->GroupBoxName->hide();
70 //****************************
71 // Selection Group box
72 QGroupBox* gbxExport = new QGroupBox(parent);
74 QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
76 gridLayoutExport->setSpacing(6);
77 gridLayoutExport->setContentsMargins(9, 9, 9, 9);
79 gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
81 int line = 0, col = 0;
82 QLabel* lblFileName = new QLabel(tr("GEOM_IMPORTXAO_FILENAME"), gbxExport);
83 btnFileSelect = new QPushButton(gbxExport);
84 ledFileName = new QLineEdit(gbxExport);
85 btnFileSelect->setText("...");
88 gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
89 gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
90 gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
92 //****************************
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
95 layout->setSpacing(6);
96 layout->addWidget(gbxExport);
99 setHelpFileName("create_importxao_page.html");
104 //=================================================================================
106 //=================================================================================
107 ImportExportGUI_ImportXAODlg::~ImportExportGUI_ImportXAODlg()
109 // no need to delete child widgets, Qt does it all for us
112 //=================================================================================
115 //=================================================================================
116 void ImportExportGUI_ImportXAODlg::Init()
118 // Signal/slot connections
119 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122 connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
124 initName(tr("GEOM_IMPORTXAO"));
125 //SelectionIntoArgument();
128 //=================================================================================
129 // function : ClickOnOk()
131 //=================================================================================
132 void ImportExportGUI_ImportXAODlg::ClickOnOk()
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool ImportExportGUI_ImportXAODlg::ClickOnApply()
152 //=================================================================================
153 // function : btnFileSelectClicked()
155 //=================================================================================
156 void ImportExportGUI_ImportXAODlg::btnFileSelectClicked()
158 QString selFile = QFileDialog::getOpenFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
159 QString(), tr("XAO_FILES"));
160 if (!selFile.isEmpty())
162 ledFileName->setText(selFile);
166 //=================================================================================
167 // function : ActivateThisDialog()
169 //=================================================================================
170 void ImportExportGUI_ImportXAODlg::ActivateThisDialog()
172 GEOMBase_Skeleton::ActivateThisDialog();
175 //=================================================================================
176 // function : enterEvent [REDEFINED]
178 //=================================================================================
179 void ImportExportGUI_ImportXAODlg::enterEvent(QEvent*)
181 if (!mainFrame()->GroupConstructors->isEnabled())
182 ActivateThisDialog();
185 //=================================================================================
186 // function : createOperation
188 //=================================================================================
189 GEOM::GEOM_IOperations_ptr ImportExportGUI_ImportXAODlg::createOperation()
191 return getGeomEngine()->GetIInsertOperations(getStudyId());
194 //=================================================================================
195 // function : isValid
197 //=================================================================================
198 bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
201 if (ledFileName->text().isEmpty())
207 //=================================================================================
208 // function : execute
210 //=================================================================================
211 bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
215 QString fileName = ledFileName->text();
216 GEOM::GEOM_Object_var shape;
217 GEOM::ListOfGO_var groups, fields, subShapes;
219 GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
220 res = ieOp->ImportXAO(fileName.toStdString().c_str(), shape, subShapes, groups, fields);
222 if (!shape->_is_nil())
225 objects.push_back(shape._retn());
232 for (int i = 0; i < subShapes->length(); i++)
234 objects.push_back(GEOM::GEOM_Object::_duplicate(subShapes[i]));
236 for (int i = 0; i < groups->length(); i++)
238 objects.push_back(GEOM::GEOM_Object::_duplicate(groups[i]));
240 for (int i = 0; i < fields->length(); i++)
242 objects.push_back(GEOM::GEOM_Object::_duplicate(fields[i]));
248 GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
250 GEOM::GEOM_Object_var fatherObj;
251 if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
253 //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
254 //fatherObj = groupOper->GetMainShape(object);
255 fatherObj = m_mainShape;
257 return fatherObj._retn();
260 QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object) const
262 if (object->_is_nil())
263 return QString::null;
264 return object->GetName();