]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_RemoveHolesDlg.cxx
Salome HOME
*** empty log message ***
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveHolesDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : RepairGUI_RemoveHolesDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "RepairGUI_RemoveHolesDlg.h"
27
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <TopAbs.hxx>
41 #include <TColStd_MapOfInteger.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43
44 //=================================================================================
45 // class    : RepairGUI_RemoveHolesDlg()
46 // purpose  : Constructs a RepairGUI_RemoveHolesDlg  which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 RepairGUI_RemoveHolesDlg::RepairGUI_RemoveHolesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
52                                                     bool modal )
53   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
54 {
55   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUPPRESS_HOLES" ) ) );
56   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57
58   setWindowTitle( tr( "GEOM_REMOVE_HOLES_TITLE" ) );
59
60   /***************************************************************/
61   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_REMOVE_HOLES_TITLE" ) );
62   mainFrame()->RadioButton1->setIcon( image0 );
63   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
64   mainFrame()->RadioButton2->close();
65   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66   mainFrame()->RadioButton3->close();
67
68   GroupPoints = new DlgRef_1Sel1Check1Sel( centralWidget() );
69   GroupPoints->GroupBox1->setTitle( tr( "GEOM_HOLES" ) );
70   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
71   GroupPoints->PushButton1->setIcon( image1 );
72   GroupPoints->LineEdit1->setReadOnly( true );
73   GroupPoints->CheckButton1->setText( tr( "GEOM_REMOVE_ALL_HOLES" ) );
74   GroupPoints->TextLabel2->setText( tr( "GEOM_SELECTED_SHAPE" ) );
75   GroupPoints->PushButton2->setIcon( image1 );
76   GroupPoints->LineEdit2->setReadOnly( true );
77   
78   myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ), 
79                                     GroupPoints->Box );
80   QVBoxLayout* l = new QVBoxLayout( GroupPoints->Box );
81   l->setMargin( 0 ); l->setSpacing( 0 );
82   l->addWidget( myFreeBoundBtn );
83   
84   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85   layout->setMargin( 0 ); layout->setSpacing( 6 );
86   layout->addWidget( GroupPoints );
87
88   /***************************************************************/
89
90   setHelpFileName( "suppress_holes.htm" );
91
92   Init();
93 }
94
95
96 //=================================================================================
97 // function : ~RepairGUI_RemoveHolesDlg()
98 // purpose  : Destroys the object and frees any allocated resources
99 //=================================================================================
100 RepairGUI_RemoveHolesDlg::~RepairGUI_RemoveHolesDlg()
101 {
102 }
103
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void RepairGUI_RemoveHolesDlg::Init()
110 {
111   /* init variables */
112   myEditCurrentArgument = GroupPoints->LineEdit1;
113   
114   myObject = GEOM::GEOM_Object::_nil();
115   myWiresInd = new GEOM::short_array();
116   myWiresInd->length( 0 );
117
118   //myGeomGUI->SetState( 0 );
119   initSelection();
120
121   myClosed = -1;
122   myOpen = -1;
123   
124   /* signals and slots connections */
125   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
126   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
127
128   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
129   connect( GroupPoints->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
130   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
131   connect( GroupPoints->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
132
133   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
134            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
135
136   connect( GroupPoints->CheckButton1, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
137   connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
138
139   initName( tr( "REMOVE_HOLES_NEW_OBJ_NAME" ) );
140 }
141
142
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose  : Same than click on apply but close this dialog.
146 //=================================================================================
147 void RepairGUI_RemoveHolesDlg::ClickOnOk()
148 {
149   if ( ClickOnApply() )
150     ClickOnCancel();
151 }
152
153 //=================================================================================
154 // function : ClickOnApply()
155 // purpose  :
156 //=================================================================================
157 bool RepairGUI_RemoveHolesDlg::ClickOnApply()
158 {
159   if ( !onAccept() )
160     return false;
161
162   initName();
163
164   myEditCurrentArgument = GroupPoints->LineEdit1;
165   myEditCurrentArgument->setText( "" );
166   GroupPoints->LineEdit2->setText( "" );
167   myObject = GEOM::GEOM_Object::_nil();
168   myWiresInd->length( 0 );
169
170   initSelection();
171
172   return true;
173 }
174
175
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose  : Called when selection
179 //=================================================================================
180 void RepairGUI_RemoveHolesDlg::SelectionIntoArgument()
181 {
182   erasePreview();
183   myEditCurrentArgument->setText( "" );
184   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
185   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myWiresInd->length( 0 );
186
187   if ( IObjectCount() == 1 ) {
188     Handle(SALOME_InteractiveObject) anIO = firstIObject();
189
190     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {    // face selection
191       Standard_Boolean aRes;
192       myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
193       if ( aRes && GEOMBase::IsShape( myObject ) )
194         myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
195       else
196         myObject = GEOM::GEOM_Object::_nil();
197     }
198     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && 
199               !GroupPoints->CheckButton1->isChecked() ) {
200       TColStd_IndexedMapOfInteger aMap;
201       ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr()->GetIndexes( anIO, aMap );
202       const int n = aMap.Extent();
203       myWiresInd->length( n );
204       for ( int i = 1; i <= n; i++ )
205         myWiresInd[i-1] = aMap( i );
206       if ( n )
207         myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
208     }
209   }
210 }
211
212 //=================================================================================
213 // function : SetEditCurrentArgument()
214 // purpose  :
215 //=================================================================================
216 void RepairGUI_RemoveHolesDlg::SetEditCurrentArgument()
217 {
218   const QObject* send = sender();
219   if ( send == GroupPoints->PushButton1 )
220     myEditCurrentArgument = GroupPoints->LineEdit1; 
221   else if ( send == GroupPoints->PushButton2 && !myObject->_is_nil() )
222     myEditCurrentArgument = GroupPoints->LineEdit2;
223   if ( myEditCurrentArgument ) {
224     initSelection();
225     myEditCurrentArgument->setFocus();
226     SelectionIntoArgument();
227   }
228 }
229
230
231 //=================================================================================
232 // function : LineEditReturnPressed()
233 // purpose  :
234 //=================================================================================
235 void RepairGUI_RemoveHolesDlg::LineEditReturnPressed()
236 {
237   const QObject* send = sender();
238   if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
239     myEditCurrentArgument = (QLineEdit*)send;
240     GEOMBase_Skeleton::LineEditReturnPressed();
241   }
242 }
243
244
245 //=================================================================================
246 // function : ActivateThisDialog()
247 // purpose  :
248 //=================================================================================
249 void RepairGUI_RemoveHolesDlg::ActivateThisDialog()
250 {
251   GEOMBase_Skeleton::ActivateThisDialog();
252   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
253            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
254
255   myEditCurrentArgument = GroupPoints->LineEdit1;
256   myEditCurrentArgument->setText( "" );
257   GroupPoints->LineEdit2->setText( "" );
258   myObject = GEOM::GEOM_Object::_nil();
259   myWiresInd->length( 0 );
260
261   myClosed = -1;
262   myOpen = -1;
263
264   //myGeomGUI->SetState( 0 );
265   initSelection();
266 }
267
268
269 //=================================================================================
270 // function : enterEvent()
271 // purpose  : Mouse enter onto the dialog to activate it
272 //=================================================================================
273 void RepairGUI_RemoveHolesDlg::enterEvent( QEvent* )
274 {
275   if ( !mainFrame()->GroupConstructors->isEnabled() )
276     ActivateThisDialog();
277 }
278
279
280 //=================================================================================
281 // function : closeEvent()
282 // purpose  :
283 //=================================================================================
284 void RepairGUI_RemoveHolesDlg::closeEvent( QCloseEvent* e )
285 {
286   //myGeomGUI->SetState( -1 );
287   GEOMBase_Skeleton::closeEvent( e );
288 }
289
290 //=================================================================================
291 // function : createOperation
292 // purpose  :
293 //=================================================================================
294 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
295 {
296   return getGeomEngine()->GetIHealingOperations( getStudyId() );
297 }
298
299 //=================================================================================
300 // function : isValid
301 // purpose  :
302 //=================================================================================
303 bool RepairGUI_RemoveHolesDlg::isValid( QString& )
304 {
305   myClosed = -1;
306   return !myObject->_is_nil() && ( IsPreview() || GroupPoints->CheckButton1->isChecked() || myWiresInd->length() );
307 }
308
309 //=================================================================================
310 // function : execute
311 // purpose  :
312 //=================================================================================
313 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
314 {
315   bool aResult = false;
316   if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
317     GEOM::ListOfGO_var aClosed, anOpen;
318
319     aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
320
321     if ( aResult ) {
322       myClosed = aClosed->length();
323       myOpen = anOpen->length();
324       int i;
325       for ( i = 0; i < myClosed; i++ )
326         objects.push_back( aClosed[i]._retn() );
327       for ( i = 0; i < myOpen; i++ )
328         objects.push_back( anOpen[i]._retn() );
329     }
330     else
331       myClosed = -1;
332   }
333   else {
334     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
335     aResult = !anObj->_is_nil();
336     if ( aResult )
337       objects.push_back( anObj._retn() );
338   }
339         
340   return aResult;
341 }
342
343 //=================================================================================
344 // function : onRemoveAllClicked
345 // purpose  :
346 //=================================================================================
347 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
348 {
349   bool b = GroupPoints->CheckButton1->isChecked();
350   GroupPoints->TextLabel2->setEnabled( !b );
351   GroupPoints->PushButton2->setEnabled( !b );
352   GroupPoints->LineEdit2->setEnabled( !b );
353   if ( b ) {
354     GroupPoints->LineEdit2->setText( "" );
355     myWiresInd->length( 0 );
356   }
357 }
358
359 //=================================================================================
360 // function : initSelection
361 // purpose  :
362 //=================================================================================
363 void RepairGUI_RemoveHolesDlg::initSelection()
364 {
365   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
366     TColStd_MapOfInteger aTypes;
367     aTypes.Add( GEOM_COMPOUND );
368     aTypes.Add( GEOM_SOLID );
369     aTypes.Add( GEOM_SHELL );
370     aTypes.Add( GEOM_FACE );
371     
372     globalSelection( aTypes );
373   }
374   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
375     localSelection( myObject, TopAbs_EDGE );
376     localSelection( myObject, TopAbs_WIRE );
377   }
378 }
379
380
381 //=================================================================================
382 // function : onDetect
383 // purpose  :
384 //=================================================================================
385 void RepairGUI_RemoveHolesDlg::onDetect()
386 {
387   displayPreview( false, true, true, 3 );
388
389   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
390   QString msg;
391   if ( myClosed != -1 )
392     msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
393   else
394     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
395   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );
396 }
397