]> SALOME platform Git repositories - modules/geom.git/blob - RepairGUI_RemoveHolesDlg.cxx
Salome HOME
d8b0347a7601827f62c6638b52142d99fdbac384
[modules/geom.git] / 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 <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_WIRES_TO_REMOVE" ) );
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_operation_page.html" );
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 : createOperation
282 // purpose  :
283 //=================================================================================
284 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveHolesDlg::createOperation()
285 {
286   return getGeomEngine()->GetIHealingOperations( getStudyId() );
287 }
288
289 //=================================================================================
290 // function : isValid
291 // purpose  :
292 //=================================================================================
293 bool RepairGUI_RemoveHolesDlg::isValid( QString& )
294 {
295   myClosed = -1;
296   return !myObject->_is_nil() && ( IsPreview() || GroupPoints->CheckButton1->isChecked() || myWiresInd->length() );
297 }
298
299 //=================================================================================
300 // function : execute
301 // purpose  :
302 //=================================================================================
303 bool RepairGUI_RemoveHolesDlg::execute( ObjectList& objects )
304 {
305   bool aResult = false;
306   if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
307     GEOM::ListOfGO_var aClosed, anOpen;
308
309     aResult = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->GetFreeBoundary( myObject, aClosed, anOpen );
310
311     if ( aResult ) {
312       myClosed = aClosed->length();
313       myOpen = anOpen->length();
314       int i;
315       for ( i = 0; i < myClosed; i++ )
316         objects.push_back( aClosed[i]._retn() );
317       for ( i = 0; i < myOpen; i++ )
318         objects.push_back( anOpen[i]._retn() );
319     }
320     else
321       myClosed = -1;
322   }
323   else {
324     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->FillHoles( myObject, myWiresInd );
325     aResult = !anObj->_is_nil();
326     if ( aResult )
327       objects.push_back( anObj._retn() );
328   }
329         
330   return aResult;
331 }
332
333 //=================================================================================
334 // function : onRemoveAllClicked
335 // purpose  :
336 //=================================================================================
337 void RepairGUI_RemoveHolesDlg::onRemoveAllClicked()
338 {
339   bool b = GroupPoints->CheckButton1->isChecked();
340   GroupPoints->TextLabel2->setEnabled( !b );
341   GroupPoints->PushButton2->setEnabled( !b );
342   GroupPoints->LineEdit2->setEnabled( !b );
343   if ( b ) {
344     GroupPoints->LineEdit2->setText( "" );
345     myWiresInd->length( 0 );
346   }
347 }
348
349 //=================================================================================
350 // function : initSelection
351 // purpose  :
352 //=================================================================================
353 void RepairGUI_RemoveHolesDlg::initSelection()
354 {
355   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
356     TColStd_MapOfInteger aTypes;
357     aTypes.Add( GEOM_COMPOUND );
358     aTypes.Add( GEOM_SOLID );
359     aTypes.Add( GEOM_SHELL );
360     aTypes.Add( GEOM_FACE );
361     
362     globalSelection( aTypes );
363   }
364   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
365     localSelection( myObject, TopAbs_EDGE );
366     localSelection( myObject, TopAbs_WIRE );
367   }
368 }
369
370
371 //=================================================================================
372 // function : onDetect
373 // purpose  :
374 //=================================================================================
375 void RepairGUI_RemoveHolesDlg::onDetect()
376 {
377   displayPreview( false, true, true, 3 );
378
379   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
380   QString msg;
381   if ( myClosed != -1 )
382     msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
383   else
384     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
385   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );
386 }
387