Salome HOME
updated copyright message
[modules/geom.git] / src / RepairGUI / RepairGUI_FreeBoundDlg.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
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)
26
27 #include "RepairGUI_FreeBoundDlg.h"
28
29 #include <GEOMBase.h>
30 #include <DlgRef.h>
31
32 #include <GeometryGUI.h>
33 #include <GEOM_Displayer.h>
34 #include <GEOMImpl_Types.hxx>
35
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>
43
44 #include <TColStd_MapOfInteger.hxx>
45
46 #include <QLineEdit>
47 #include <QLabel>
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
50 #include <QGridLayout>
51 #include <QGroupBox>
52 #include <QPushButton>
53 #include <QKeyEvent>
54
55 #define SPACING 6
56 #define MARGIN  0
57
58 /*!
59   Class       : RepairGUI_FreeBoundDlg
60   Description : Dialog for displaying free boundaries of selected face, shell or solid
61 */
62
63 //=================================================================================
64 // function : RepairGUI_FreeBoundDlg
65 // purpose  : Constructor
66 //=================================================================================
67 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg (GeometryGUI* theGUI, QWidget* theParent)
68   : GEOMBase_Skeleton(theGUI, theParent)
69 {
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")));
72
73   setWindowTitle(tr("CAPTION"));
74
75   /***************************************************************/
76
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();
83
84   mainFrame()->GroupBoxName->hide();
85
86   QGroupBox* aMainGrp = new QGroupBox (tr("FREE_BOUND"), this);
87
88   QLabel* lab = new QLabel (tr("GEOM_OBJECT"), aMainGrp);
89   QPushButton* btn = new QPushButton (aMainGrp);
90   btn->setIcon(image1);
91   myEdit = new QLineEdit (aMainGrp);
92   myEdit->setReadOnly(true);
93   myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
94
95   myClosedLbl = new QLabel (tr("NUMBER_CLOSED"), aMainGrp);
96   myOpenLbl   = new QLabel (tr("NUMBER_OPEN"),   aMainGrp);
97   myClosedLbl->setMinimumWidth(150);
98   myOpenLbl->setMinimumWidth(150);
99
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);
106
107   QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
108   aLay->setSpacing(SPACING);
109   aLay->setMargin(MARGIN);
110   aLay->addWidget(aMainGrp);
111
112   resize(minimumSizeHint());
113   /***************************************************************/
114
115   myHelpFileName = "boundaries_page.html";
116
117   Init();
118 }
119
120 //=================================================================================
121 // function : ~RepairGUI_FreeBoundDlg
122 // purpose  : Destructor
123 //=================================================================================
124 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
125 {
126 }
127
128 //=================================================================================
129 // function : Init
130 // purpose  : Initialize dialog fields
131 //=================================================================================
132 void RepairGUI_FreeBoundDlg::Init()
133 {
134   myNbClosed = myNbOpen = 0;
135   myObj = GEOM::GEOM_Object::_nil();
136
137   myEditCurrentArgument = myEdit;
138
139   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
140   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141
142   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
143           this, SLOT(SelectionIntoArgument()));
144
145   activateSelection();
146   SelectionIntoArgument();
147 }
148
149 //=================================================================================
150 // function : ClickOnOk()
151 // purpose  :
152 //=================================================================================
153 void RepairGUI_FreeBoundDlg::ClickOnOk()
154 {
155   if (ClickOnApply())
156     ClickOnCancel();
157 }
158
159 //=================================================================================
160 // function : ClickOnApply()
161 // purpose  :
162 //=================================================================================
163 bool RepairGUI_FreeBoundDlg::ClickOnApply()
164 {
165   if (!onAccept())
166     return false;
167   return true;
168 }
169
170 //=================================================================================
171 // function : ActivateThisDialog()
172 // purpose  :
173 //=================================================================================
174 void RepairGUI_FreeBoundDlg::ActivateThisDialog()
175 {
176   GEOMBase_Skeleton::ActivateThisDialog();
177
178   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
179           this, SLOT(SelectionIntoArgument()));
180
181   activateSelection();
182   displayPreview(true);
183 }
184
185 //=================================================================================
186 // function : enterEvent()
187 // purpose  :
188 //=================================================================================
189 void RepairGUI_FreeBoundDlg::enterEvent(QEvent*)
190 {
191   if (!mainFrame()->GroupConstructors->isEnabled())
192     ActivateThisDialog();
193 }
194
195 //=================================================================================
196 // function : SelectionIntoArgument
197 // purpose  : SLOT. Called when selection changed.
198 //=================================================================================
199 void RepairGUI_FreeBoundDlg::SelectionIntoArgument()
200 {
201   myEditCurrentArgument->setText("");
202   myClosedLbl->setText(tr("NUMBER_CLOSED"));
203   myOpenLbl->setText(tr("NUMBER_OPEN"));
204   myObj = GEOM::GEOM_Object::_nil();
205   erasePreview();
206
207   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
208   SALOME_ListIO aSelList;
209   aSelMgr->selectedObjects(aSelList);
210
211   if (aSelList.Extent() != 1)
212     return;
213
214   GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
215
216   if (!GEOMBase::IsShape(anObj))
217     return;
218
219   myObj = anObj;
220   myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
221   displayPreview(true, false, true, true, 3, 0);
222 }
223
224 //=================================================================================
225 // function : activateSelection
226 // purpose  : activate selection of faces, shells, and solids
227 //=================================================================================
228 void RepairGUI_FreeBoundDlg::activateSelection()
229 {
230   TColStd_MapOfInteger aMap;
231   aMap.Add(GEOM_FACE);
232   aMap.Add(GEOM_SHELL);
233   aMap.Add(GEOM_SOLID);
234   aMap.Add(GEOM_COMPOUND);
235   globalSelection(aMap);
236 }
237
238 //=================================================================================
239 // function : createOperation
240 // purpose  : Create operation
241 //=================================================================================
242 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
243 {
244   return getGeomEngine()->GetIHealingOperations();
245 }
246
247 //=================================================================================
248 // function : isValid
249 // purpose  :
250 //=================================================================================
251 bool RepairGUI_FreeBoundDlg::isValid (QString&)
252 {
253   return !myObj->_is_nil();
254 }
255
256 //=================================================================================
257 // function : execute
258 // purpose  : Get free boundaries
259 //=================================================================================
260 bool RepairGUI_FreeBoundDlg::execute (ObjectList& objects)
261 {
262   GEOM::ListOfGO_var aClosed, anOpen;
263
264   GEOM::ListOfGO_var objList = new GEOM::ListOfGO;
265   objList->length(1);
266   objList[0] = myObj;
267   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
268   bool result = anOper->GetFreeBoundary(objList, aClosed, anOpen);
269
270   if (result) {
271     myNbClosed = aClosed->length();
272     myNbOpen = anOpen->length();
273     int i;
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());
278
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);
283   }
284
285   myCurrObj = 1;
286   return result;
287 }
288
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
294 {
295   QString aName = tr("NAME_CLOSED").arg(currObj);
296   if (currObj > myNbClosed)
297     aName = tr("NAME_OPEN").arg(currObj);
298   return aName;
299 }
300
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)
307 {
308   return myObj;
309 }
310
311 //=================================================================================
312 // function : getSourceObjects
313 // purpose  : virtual method to get source objects
314 //=================================================================================
315 QList<GEOM::GeomObjPtr> RepairGUI_FreeBoundDlg::getSourceObjects()
316 {
317   QList<GEOM::GeomObjPtr> res;
318   GEOM::GeomObjPtr aGeomObjPtr(myObj);
319   res << aGeomObjPtr;
320   return res;
321 }