1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_FreeBoundDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
27 #include "RepairGUI_FreeBoundDlg.h"
32 #include <GeometryGUI.h>
33 #include <GEOM_Displayer.h>
34 #include <GEOMImpl_Types.hxx>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ResourceMgr.h>
44 #include <TColStd_MapOfInteger.hxx>
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
50 #include <QGridLayout>
52 #include <QPushButton>
59 Class : RepairGUI_FreeBoundDlg
60 Description : Dialog for displaying free boundaries of selected face, shell or solid
63 //=================================================================================
64 // function : RepairGUI_FreeBoundDlg
65 // purpose : Constructor
66 //=================================================================================
67 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg (GeometryGUI* theGUI, QWidget* theParent)
68 : GEOMBase_Skeleton(theGUI, theParent)
70 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_BOUNDS")));
71 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
73 setWindowTitle(tr("CAPTION"));
75 /***************************************************************/
77 mainFrame()->GroupConstructors->setTitle(tr("FREE_BOUND"));
78 mainFrame()->RadioButton1->setIcon(image0);
79 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
80 mainFrame()->RadioButton2->close();
81 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
82 mainFrame()->RadioButton3->close();
84 mainFrame()->GroupBoxName->hide();
86 QGroupBox* aMainGrp = new QGroupBox (tr("FREE_BOUND"), this);
88 QLabel* lab = new QLabel (tr("GEOM_OBJECT"), aMainGrp);
89 QPushButton* btn = new QPushButton (aMainGrp);
91 myEdit = new QLineEdit (aMainGrp);
92 myEdit->setReadOnly(true);
93 myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
95 myClosedLbl = new QLabel (tr("NUMBER_CLOSED"), aMainGrp);
96 myOpenLbl = new QLabel (tr("NUMBER_OPEN"), aMainGrp);
97 myClosedLbl->setMinimumWidth(150);
98 myOpenLbl->setMinimumWidth(150);
100 QGridLayout* aMainGrpLayout = new QGridLayout (aMainGrp);
101 aMainGrpLayout->addWidget(lab, 0, 0);
102 aMainGrpLayout->addWidget(btn, 0, 1);
103 aMainGrpLayout->addWidget(myEdit, 0, 2);
104 aMainGrpLayout->addWidget(myClosedLbl, 1, 0, 1, 3);
105 aMainGrpLayout->addWidget(myOpenLbl, 2, 0, 1, 3);
107 QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
108 aLay->setSpacing(SPACING);
109 aLay->setMargin(MARGIN);
110 aLay->addWidget(aMainGrp);
112 resize(minimumSizeHint());
113 /***************************************************************/
115 myHelpFileName = "boundaries_page.html";
120 //=================================================================================
121 // function : ~RepairGUI_FreeBoundDlg
122 // purpose : Destructor
123 //=================================================================================
124 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
128 //=================================================================================
130 // purpose : Initialize dialog fields
131 //=================================================================================
132 void RepairGUI_FreeBoundDlg::Init()
134 myNbClosed = myNbOpen = 0;
135 myObj = GEOM::GEOM_Object::_nil();
137 myEditCurrentArgument = myEdit;
139 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
142 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
143 this, SLOT(SelectionIntoArgument()));
146 SelectionIntoArgument();
149 //=================================================================================
150 // function : ClickOnOk()
152 //=================================================================================
153 void RepairGUI_FreeBoundDlg::ClickOnOk()
159 //=================================================================================
160 // function : ClickOnApply()
162 //=================================================================================
163 bool RepairGUI_FreeBoundDlg::ClickOnApply()
170 //=================================================================================
171 // function : ActivateThisDialog()
173 //=================================================================================
174 void RepairGUI_FreeBoundDlg::ActivateThisDialog()
176 GEOMBase_Skeleton::ActivateThisDialog();
178 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
179 this, SLOT(SelectionIntoArgument()));
182 displayPreview(true);
185 //=================================================================================
186 // function : enterEvent()
188 //=================================================================================
189 void RepairGUI_FreeBoundDlg::enterEvent(QEvent*)
191 if (!mainFrame()->GroupConstructors->isEnabled())
192 ActivateThisDialog();
195 //=================================================================================
196 // function : SelectionIntoArgument
197 // purpose : SLOT. Called when selection changed.
198 //=================================================================================
199 void RepairGUI_FreeBoundDlg::SelectionIntoArgument()
201 myEditCurrentArgument->setText("");
202 myClosedLbl->setText(tr("NUMBER_CLOSED"));
203 myOpenLbl->setText(tr("NUMBER_OPEN"));
204 myObj = GEOM::GEOM_Object::_nil();
207 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
208 SALOME_ListIO aSelList;
209 aSelMgr->selectedObjects(aSelList);
211 if (aSelList.Extent() != 1)
214 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
216 if (!GEOMBase::IsShape(anObj))
220 myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
221 displayPreview(true, false, true, true, 3, 0);
224 //=================================================================================
225 // function : activateSelection
226 // purpose : activate selection of faces, shells, and solids
227 //=================================================================================
228 void RepairGUI_FreeBoundDlg::activateSelection()
230 TColStd_MapOfInteger aMap;
232 aMap.Add(GEOM_SHELL);
233 aMap.Add(GEOM_SOLID);
234 aMap.Add(GEOM_COMPOUND);
235 globalSelection(aMap);
238 //=================================================================================
239 // function : createOperation
240 // purpose : Create operation
241 //=================================================================================
242 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
244 return getGeomEngine()->GetIHealingOperations(getStudyId());
247 //=================================================================================
248 // function : isValid
250 //=================================================================================
251 bool RepairGUI_FreeBoundDlg::isValid (QString&)
253 return !myObj->_is_nil();
256 //=================================================================================
257 // function : execute
258 // purpose : Get free boundaries
259 //=================================================================================
260 bool RepairGUI_FreeBoundDlg::execute (ObjectList& objects)
262 GEOM::ListOfGO_var aClosed, anOpen;
264 GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
267 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
268 bool result = anOper->GetFreeBoundary(objList, aClosed, anOpen);
271 myNbClosed = aClosed->length();
272 myNbOpen = anOpen->length();
274 for (i = 0; i < myNbClosed; i++)
275 objects.push_back(aClosed[i]._retn());
276 for (i = 0; i < myNbOpen; i++)
277 objects.push_back(anOpen[i]._retn());
279 QString aLabelText = tr("NUMBER_CLOSED") + QString("%1").arg(myNbClosed);
280 myClosedLbl->setText(aLabelText);
281 aLabelText = tr("NUMBER_OPEN") + QString("%1").arg(myNbOpen);
282 myOpenLbl->setText(aLabelText);
289 //================================================================
290 // Function : getNewObjectName
291 // Purpose : Redefine this method to return proper name for a new object
292 //================================================================
293 QString RepairGUI_FreeBoundDlg::getNewObjectName (int currObj) const
295 QString aName = tr("NAME_CLOSED").arg(currObj);
296 if (currObj > myNbClosed)
297 aName = tr("NAME_OPEN").arg(currObj);
301 //================================================================
302 // Function : getFather
303 // Purpose : Get father object for object to be added in study
304 // (called with addInStudy method)
305 //================================================================
306 GEOM::GEOM_Object_ptr RepairGUI_FreeBoundDlg::getFather (GEOM::GEOM_Object_ptr)
311 //=================================================================================
312 // function : getSourceObjects
313 // purpose : virtual method to get source objects
314 //=================================================================================
315 QList<GEOM::GeomObjPtr> RepairGUI_FreeBoundDlg::getSourceObjects()
317 QList<GEOM::GeomObjPtr> res;
318 GEOM::GeomObjPtr aGeomObjPtr(myObj);