]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_FreeBoundDlg.cxx
Salome HOME
Merge from BR_siman_phase1 14/02/2013
[modules/geom.git] / src / RepairGUI / RepairGUI_FreeBoundDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, 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.
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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : RepairGUI_FreeBoundDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
25
26 #include "RepairGUI_FreeBoundDlg.h"
27
28 #include <GEOMBase.h>
29 #include <DlgRef.h>
30
31 #include <GeometryGUI.h>
32 #include <GEOM_Displayer.h>
33 #include <GEOMImpl_Types.hxx>
34
35 #include <SalomeApp_Application.h>
36 #include <LightApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_ResourceMgr.h>
42
43 #include <TColStd_MapOfInteger.hxx>
44
45 #include <QLineEdit>
46 #include <QLabel>
47 #include <QHBoxLayout>
48 #include <QVBoxLayout>
49 #include <QGridLayout>
50 #include <QGroupBox>
51 #include <QPushButton>
52 #include <QKeyEvent>
53
54 #define SPACING 6
55 #define MARGIN  0
56
57 /*!
58   Class       : RepairGUI_FreeBoundDlg
59   Description : Dialog for displaying free boundaries of selected face, shell or solid
60 */
61
62 //=================================================================================
63 // function : RepairGUI_FreeBoundDlg
64 // purpose  : Constructor
65 //=================================================================================
66 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg (GeometryGUI* theGUI, QWidget* theParent)
67   : GEOMBase_Skeleton(theGUI, theParent)
68 {
69   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FREE_BOUNDS")));
70   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
71
72   setWindowTitle(tr("CAPTION"));
73
74   /***************************************************************/
75
76   mainFrame()->GroupConstructors->setTitle(tr("FREE_BOUND"));
77   mainFrame()->RadioButton1->setIcon(image0);
78   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
79   mainFrame()->RadioButton2->close();
80   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
81   mainFrame()->RadioButton3->close();
82
83   mainFrame()->GroupBoxName->hide();
84
85   QGroupBox* aMainGrp = new QGroupBox (tr("FREE_BOUND"), this);
86
87   QLabel* lab = new QLabel (tr("GEOM_OBJECT"), aMainGrp);
88   QPushButton* btn = new QPushButton (aMainGrp);
89   btn->setIcon(image1);
90   myEdit = new QLineEdit (aMainGrp);
91   myEdit->setReadOnly(true);
92   myEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
93
94   myClosedLbl = new QLabel (tr("NUMBER_CLOSED"), aMainGrp);
95   myOpenLbl   = new QLabel (tr("NUMBER_OPEN"),   aMainGrp);
96   myClosedLbl->setMinimumWidth(150);
97   myOpenLbl->setMinimumWidth(150);
98
99   QGridLayout* aMainGrpLayout = new QGridLayout (aMainGrp);
100   aMainGrpLayout->addWidget(lab,    0, 0);
101   aMainGrpLayout->addWidget(btn,    0, 1);
102   aMainGrpLayout->addWidget(myEdit, 0, 2);
103   aMainGrpLayout->addWidget(myClosedLbl, 1, 0, 1, 3);
104   aMainGrpLayout->addWidget(myOpenLbl,   2, 0, 1, 3);
105
106   QVBoxLayout* aLay = new QVBoxLayout (centralWidget());
107   aLay->setSpacing(SPACING);
108   aLay->setMargin(MARGIN);
109   aLay->addWidget(aMainGrp);
110
111   resize(minimumSizeHint());
112   /***************************************************************/
113
114   myHelpFileName = "boundaries_page.html";
115
116   Init();
117 }
118
119 //=================================================================================
120 // function : ~RepairGUI_FreeBoundDlg
121 // purpose  : Destructor
122 //=================================================================================
123 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
124 {
125 }
126
127 //=================================================================================
128 // function : Init
129 // purpose  : Initialize dialog fields
130 //=================================================================================
131 void RepairGUI_FreeBoundDlg::Init()
132 {
133   myNbClosed = myNbOpen = 0;
134   myObj = GEOM::GEOM_Object::_nil();
135
136   myEditCurrentArgument = myEdit;
137
138   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140
141   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
142           this, SLOT(SelectionIntoArgument()));
143
144   activateSelection();
145   SelectionIntoArgument();
146 }
147
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose  :
151 //=================================================================================
152 void RepairGUI_FreeBoundDlg::ClickOnOk()
153 {
154   if (ClickOnApply())
155     ClickOnCancel();
156 }
157
158 //=================================================================================
159 // function : ClickOnApply()
160 // purpose  :
161 //=================================================================================
162 bool RepairGUI_FreeBoundDlg::ClickOnApply()
163 {
164   if (!onAccept())
165     return false;
166   return true;
167 }
168
169 //=================================================================================
170 // function : ActivateThisDialog()
171 // purpose  :
172 //=================================================================================
173 void RepairGUI_FreeBoundDlg::ActivateThisDialog()
174 {
175   GEOMBase_Skeleton::ActivateThisDialog();
176
177   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
178           this, SLOT(SelectionIntoArgument()));
179
180   activateSelection();
181   displayPreview(true);
182 }
183
184 //=================================================================================
185 // function : enterEvent()
186 // purpose  :
187 //=================================================================================
188 void RepairGUI_FreeBoundDlg::enterEvent(QEvent*)
189 {
190   if (!mainFrame()->GroupConstructors->isEnabled())
191     ActivateThisDialog();
192 }
193
194 //=================================================================================
195 // function : SelectionIntoArgument
196 // purpose  : SLOT. Called when selection changed.
197 //=================================================================================
198 void RepairGUI_FreeBoundDlg::SelectionIntoArgument()
199 {
200   myEditCurrentArgument->setText("");
201   myClosedLbl->setText(tr("NUMBER_CLOSED"));
202   myOpenLbl->setText(tr("NUMBER_OPEN"));
203   myObj = GEOM::GEOM_Object::_nil();
204   erasePreview();
205
206   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
207   SALOME_ListIO aSelList;
208   aSelMgr->selectedObjects(aSelList);
209
210   if (aSelList.Extent() != 1)
211     return;
212
213   GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
214
215   if (!GEOMBase::IsShape(anObj))
216     return;
217
218   myObj = anObj;
219   myEditCurrentArgument->setText(GEOMBase::GetName(myObj));
220   displayPreview(true, false, true, true, 3);
221 }
222
223 //=================================================================================
224 // function : activateSelection
225 // purpose  : activate selection of faces, shells, and solids
226 //=================================================================================
227 void RepairGUI_FreeBoundDlg::activateSelection()
228 {
229   TColStd_MapOfInteger aMap;
230   aMap.Add(GEOM_FACE);
231   aMap.Add(GEOM_SHELL);
232   aMap.Add(GEOM_SOLID);
233   aMap.Add(GEOM_COMPOUND);
234   globalSelection(aMap);
235 }
236
237 //=================================================================================
238 // function : createOperation
239 // purpose  : Create operation
240 //=================================================================================
241 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
242 {
243   return getGeomEngine()->GetIHealingOperations(getStudyId());
244 }
245
246 //=================================================================================
247 // function : isValid
248 // purpose  :
249 //=================================================================================
250 bool RepairGUI_FreeBoundDlg::isValid (QString&)
251 {
252   return !myObj->_is_nil();
253 }
254
255 //=================================================================================
256 // function : execute
257 // purpose  : Get free boundaries
258 //=================================================================================
259 bool RepairGUI_FreeBoundDlg::execute (ObjectList& objects)
260 {
261   GEOM::ListOfGO_var aClosed, anOpen;
262
263   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation());
264   bool result = anOper->GetFreeBoundary(myObj, aClosed, anOpen);
265
266   if (result) {
267     myNbClosed = aClosed->length();
268     myNbOpen = anOpen->length();
269     int i;
270     for (i = 0; i < myNbClosed; i++)
271       objects.push_back(aClosed[i]._retn());
272     for (i = 0; i < myNbOpen; i++)
273       objects.push_back(anOpen[i]._retn());
274
275     QString aLabelText = tr("NUMBER_CLOSED") + QString("%1").arg(myNbClosed);
276     myClosedLbl->setText(aLabelText);
277     aLabelText = tr("NUMBER_OPEN") + QString("%1").arg(myNbOpen);
278     myOpenLbl->setText(aLabelText);
279   }
280
281   myCurrObj = 1;
282   return result;
283 }
284
285 //================================================================
286 // Function : getNewObjectName
287 // Purpose  : Redefine this method to return proper name for a new object
288 //================================================================
289 QString RepairGUI_FreeBoundDlg::getNewObjectName (int currObj) const
290 {
291   QString aName = tr("NAME_CLOSED").arg(currObj);
292   if (currObj > myNbClosed)
293     aName = tr("NAME_OPEN").arg(currObj);
294   return aName;
295 }
296
297 //================================================================
298 // Function : getFather
299 // Purpose  : Get father object for object to be added in study
300 //            (called with addInStudy method)
301 //================================================================
302 GEOM::GEOM_Object_ptr RepairGUI_FreeBoundDlg::getFather (GEOM::GEOM_Object_ptr)
303 {
304   return myObj;
305 }