]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_SewingDlg.cxx
Salome HOME
PAL8378: fix a bug in Partition algorithm
[modules/geom.git] / src / RepairGUI / RepairGUI_SewingDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : RepairGUI_SewingDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "RepairGUI_SewingDlg.h"
31
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_MessageBox.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "SALOME_ListIteratorOfListIO.hxx"
37
38 #include "GEOMImpl_Types.hxx"
39
40 #include <TopAbs.hxx>
41
42 #define DEFAULT_TOLERANCE_VALUE 1e-07
43
44
45 //=================================================================================
46 // class    : RepairGUI_SewingDlg()
47 // purpose  : Constructs a RepairGUI_SewingDlg  which is a child of 'parent', with the
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 RepairGUI_SewingDlg::RepairGUI_SewingDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
53   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SEWING")));
56   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_SEWING_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_SEWING_TITLE"));
62   RadioButton1->setPixmap(image0);
63   RadioButton2->close(TRUE);
64   RadioButton3->close(TRUE);
65
66   GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
67   GroupPoints->GroupBox1->setTitle(tr("GEOM_SEWING"));
68   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
69   GroupPoints->PushButton1->setPixmap(image1);
70   GroupPoints->LineEdit1->setReadOnly( true );
71
72   Layout1->addWidget(GroupPoints, 2, 0);
73
74   QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
75   myTolEdt = new QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
76   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
77   QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
78         myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ), GroupPoints->GroupBox1 );
79   QLabel* aLbl2 = new QLabel( tr( "GEOM_FREE_BOUNDARIES" ), GroupPoints->GroupBox1 );
80   aLay->addWidget( aLbl1, 0, 0 );
81   aLay->addWidget( myTolEdt, 0, 1 );
82   aLay->addWidget( aLbl2, 1, 0 );
83   aLay->addWidget( myFreeBoundBtn, 1, 1 );
84
85   GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
86   /***************************************************************/
87
88   Init();
89 }
90
91
92 //=================================================================================
93 // function : ~RepairGUI_SewingDlg()
94 // purpose  : Destroys the object and frees any allocated resources
95 //=================================================================================
96 RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
97 {
98 }
99
100
101 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void RepairGUI_SewingDlg::Init()
106 {
107   /* init variables */
108   myEditCurrentArgument = GroupPoints->LineEdit1;
109
110   myObject = GEOM::GEOM_Object::_nil();
111
112   myGeomGUI->SetState( 0 );
113   initSelection();
114
115   myClosed = -1;
116   myOpen = -1;
117         
118   /* signals and slots connections */
119   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
122
123   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125
126   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128
129   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130
131   connect(myFreeBoundBtn, SIGNAL(clicked()), this, SLOT(onDetect()));
132
133   initName( tr( "SEWING_NEW_OBJ_NAME" ) );
134 }
135
136
137 //=================================================================================
138 // function : ClickOnOk()
139 // purpose  : Same than click on apply but close this dialog.
140 //=================================================================================
141 void RepairGUI_SewingDlg::ClickOnOk()
142 {
143   if ( ClickOnApply() )
144     ClickOnCancel();
145 }
146
147
148
149 //=================================================================================
150 // function : ClickOnApply()
151 // purpose  :
152 //=================================================================================
153 bool RepairGUI_SewingDlg::ClickOnApply()
154 {
155   if ( !onAccept() )
156         return false;
157
158   initName();
159
160   GroupPoints->LineEdit1->setText("");
161   myObject = GEOM::GEOM_Object::_nil();
162
163   initSelection();
164
165   return true;
166 }
167
168
169 //=================================================================================
170 // function : ClickOnCancel()
171 // purpose  :
172 //=================================================================================
173 void RepairGUI_SewingDlg::ClickOnCancel()
174 {
175   GEOMBase_Skeleton::ClickOnCancel();
176 }
177
178
179 //=================================================================================
180 // function : SelectionIntoArgument()
181 // purpose  : Called when selection
182 //=================================================================================
183 void RepairGUI_SewingDlg::SelectionIntoArgument()
184 {
185   erasePreview();
186   myEditCurrentArgument->setText("");
187   myObject = GEOM::GEOM_Object::_nil();
188
189   if ( mySelection->IObjectCount() == 1 )
190   {
191     Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
192     Standard_Boolean aRes;
193     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
194     if ( aRes )
195       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
196   }
197 }
198
199 //=================================================================================
200 // function : SetEditCurrentArgument()
201 // purpose  :
202 //=================================================================================
203 void RepairGUI_SewingDlg::SetEditCurrentArgument()
204 {
205   const QObject* send = sender();
206   if ( send == GroupPoints->PushButton1 )
207   {
208     myEditCurrentArgument->setFocus();
209     SelectionIntoArgument();
210   }
211 }
212
213
214 //=================================================================================
215 // function : LineEditReturnPressed()
216 // purpose  :
217 //=================================================================================
218 void RepairGUI_SewingDlg::LineEditReturnPressed()
219 {
220   const QObject* send = sender();
221   if( send == GroupPoints->LineEdit1 )
222   {
223     myEditCurrentArgument = GroupPoints->LineEdit1;
224     GEOMBase_Skeleton::LineEditReturnPressed();
225   }
226 }
227
228
229 //=================================================================================
230 // function : DeactivateActiveDialog()
231 // purpose  :
232 //=================================================================================
233 void RepairGUI_SewingDlg::DeactivateActiveDialog()
234 {
235   myGeomGUI->SetState( -1 );
236   GEOMBase_Skeleton::DeactivateActiveDialog();
237 }
238
239
240 //=================================================================================
241 // function : ActivateThisDialog()
242 // purpose  :
243 //=================================================================================
244 void RepairGUI_SewingDlg::ActivateThisDialog()
245 {
246   GEOMBase_Skeleton::ActivateThisDialog();
247   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248
249   GroupPoints->LineEdit1->setText("");
250   myObject = GEOM::GEOM_Object::_nil();
251
252   myClosed = -1;
253   myOpen = -1;
254
255   myGeomGUI->SetState( 0 );
256   initSelection();
257 }
258
259
260 //=================================================================================
261 // function : enterEvent()
262 // purpose  : Mouse enter onto the dialog to activate it
263 //=================================================================================
264 void RepairGUI_SewingDlg::enterEvent(QEvent* e)
265 {
266   if ( !GroupConstructors->isEnabled() )
267     ActivateThisDialog();
268 }
269
270
271 //=================================================================================
272 // function : closeEvent()
273 // purpose  :
274 //=================================================================================
275 void RepairGUI_SewingDlg::closeEvent(QCloseEvent* e)
276 {
277   myGeomGUI->SetState( -1 );
278   GEOMBase_Skeleton::closeEvent( e );
279 }
280
281 //=================================================================================
282 // function : createOperation
283 // purpose  :
284 //=================================================================================
285 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
286 {
287   return getGeomEngine()->GetIHealingOperations( getStudyId() );
288 }
289
290 //=================================================================================
291 // function : isValid
292 // purpose  :
293 //=================================================================================
294 bool RepairGUI_SewingDlg::isValid( QString& msg )
295 {
296   myClosed = -1;
297   return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
298 }
299
300 //=================================================================================
301 // function : execute
302 // purpose  :
303 //=================================================================================
304 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
305 {
306   bool aResult = false;
307   if ( IsPreview() ) // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
308   {
309     GEOM::ListOfGO_var aClosed, anOpen;
310
311     aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
312
313     if ( aResult )
314     {
315       myClosed = aClosed->length();
316       myOpen = anOpen->length();
317       int i;
318       for ( i = 0; i < myClosed; i++ )
319         objects.push_back( aClosed[i]._retn() );
320       for ( i = 0; i < myOpen; i++ )
321         objects.push_back( anOpen[i]._retn() );
322     }
323     else
324       myClosed = -1;
325   }
326   else
327   {
328     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->Sew( myObject, myTolEdt->value() );
329     aResult = !anObj->_is_nil();
330     if ( aResult )
331       objects.push_back( anObj._retn() );
332   }
333
334   return aResult;
335 }
336
337 //=================================================================================
338 // function : initSelection
339 // purpose  :
340 //=================================================================================
341 void RepairGUI_SewingDlg::initSelection()
342 {
343   TColStd_MapOfInteger aTypes;
344   aTypes.Add( GEOM_SHELL );
345   aTypes.Add( GEOM_SOLID );
346   aTypes.Add( GEOM_COMPOUND );
347   globalSelection( aTypes );
348 }
349
350 //=================================================================================
351 // function : onDetect
352 // purpose  :
353 //=================================================================================
354 void RepairGUI_SewingDlg::onDetect()
355 {
356   displayPreview( false, true, true, 3 );
357
358   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
359   QString msg;
360   if ( myClosed != -1 )
361     msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
362   else
363     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
364   QAD_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );
365 }