]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_RemoveIntWiresDlg.cxx
Salome HOME
Remove some methods of GEOMBase_Helper (IObjectCount(), firstIObject(), lastIObject...
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveIntWiresDlg.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_RemoveIntWiresDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "RepairGUI_RemoveIntWiresDlg.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_Session.h>
35 #include <SUIT_ResourceMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
39 #include <TopAbs.hxx>
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42
43 //=================================================================================
44 // class    : RepairGUI_RemoveIntWiresDlg()
45 // purpose  : Constructs a RepairGUI_RemoveIntWiresDlg  which is a child of 'parent', with the
46 //            name 'name' and widget flags set to 'f'.
47 //            The dialog will by default be modeless, unless you set 'modal' to
48 //            TRUE to construct a modal dialog.
49 //=================================================================================
50 RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
51                                                           bool modal )
52   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
53 {
54   QPixmap image0( myGeomGUI->getApp()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUPPRESS_INT_WIRES" ) ) );
55   QPixmap image1( myGeomGUI->getApp()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56
57   setWindowTitle( tr( "GEOM_REMOVE_INTERNAL_WIRES_TITLE" ) );
58
59   /***************************************************************/
60   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_REMOVE_INTERNAL_WIRES_TITLE" ) );
61   mainFrame()->RadioButton1->setIcon( image0 );
62   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63   mainFrame()->RadioButton2->close();
64   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65   mainFrame()->RadioButton3->close();
66
67   GroupPoints = new DlgRef_1Sel1Check1Sel( centralWidget() );
68   GroupPoints->GroupBox1->setTitle( tr( "GEOM_INTERNAL_WIRES" ) );
69   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_FACE" ) );
70   GroupPoints->PushButton1->setIcon( image1 );
71   GroupPoints->LineEdit1->setReadOnly( true );
72   GroupPoints->CheckButton1->setText( tr( "GEOM_REMOVE_ALL_INT_WIRES" ) );
73   GroupPoints->TextLabel2->setText( tr( "GEOM_WIRES_TO_REMOVE" ) );
74   GroupPoints->PushButton2->setIcon( image1 );
75   GroupPoints->LineEdit2->setReadOnly( true );
76
77   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
78   layout->setMargin( 0 ); layout->setSpacing( 6 );
79   layout->addWidget( GroupPoints );
80
81   /***************************************************************/
82
83   setHelpFileName( "suppress_internal_wires_operation_page.html" );
84
85   Init();
86 }
87
88
89 //=================================================================================
90 // function : ~RepairGUI_RemoveIntWiresDlg()
91 // purpose  : Destroys the object and frees any allocated resources
92 //=================================================================================
93 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
94 {
95 }
96
97
98 //=================================================================================
99 // function : Init()
100 // purpose  :
101 //=================================================================================
102 void RepairGUI_RemoveIntWiresDlg::Init()
103 {
104   /* init variables */
105   myEditCurrentArgument = GroupPoints->LineEdit1;
106
107   myObject = GEOM::GEOM_Object::_nil();
108   myWiresInd = new GEOM::short_array();
109   myWiresInd->length( 0 );
110
111   //myGeomGUI->SetState( 0 );
112   initSelection(); 
113
114   /* signals and slots connections */
115   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117
118   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
119   connect( GroupPoints->PushButton2, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
120   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
121   connect( GroupPoints->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
122
123   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
124            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125
126   connect( GroupPoints->CheckButton1, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
127
128   initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
129 }
130
131
132 //=================================================================================
133 // function : ClickOnOk()
134 // purpose  : Same than click on apply but close this dialog.
135 //=================================================================================
136 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
137 {
138   if ( ClickOnApply() )
139     ClickOnCancel();
140 }
141
142 //=================================================================================
143 // function : ClickOnApply()
144 // purpose  :
145 //=================================================================================
146 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
147 {
148   if ( !onAccept() )
149     return false;
150
151   initName();
152
153   myEditCurrentArgument = GroupPoints->LineEdit1;
154   myEditCurrentArgument->setText( "" );
155   GroupPoints->LineEdit2->setText( "" );
156   myObject = GEOM::GEOM_Object::_nil();
157   myWiresInd->length( 0 );
158   
159   initSelection();
160   
161   return true;
162 }
163
164
165 //=================================================================================
166 // function : SelectionIntoArgument()
167 // purpose  : Called when selection
168 //=================================================================================
169 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
170 {
171   myEditCurrentArgument->setText( "" );
172   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
173   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myWiresInd->length( 0 );
174
175   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
176   SALOME_ListIO aSelList;
177   aSelMgr->selectedObjects(aSelList);
178
179   if ( aSelList.Extent() == 1 ) {
180     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
181     
182     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {    // face selection
183       Standard_Boolean aRes;
184       myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
185       if ( aRes && GEOMBase::IsShape( myObject ) )
186         myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
187       else
188         myObject = GEOM::GEOM_Object::_nil();
189     }
190     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 && 
191               !GroupPoints->CheckButton1->isChecked() ) {
192       TColStd_IndexedMapOfInteger aMap;
193       aSelMgr->GetIndexes( anIO, aMap );
194       const int n = aMap.Extent();
195       myWiresInd->length( n );
196       for ( int i = 1; i <= n; i++ )
197         myWiresInd[i-1] = aMap( i );
198       if ( n )
199         myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
200     }
201   }
202 }
203
204 //=================================================================================
205 // function : SetEditCurrentArgument()
206 // purpose  :
207 //=================================================================================
208 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
209 {
210   const QObject* send = sender();
211   if ( send == GroupPoints->PushButton1 )
212     myEditCurrentArgument = GroupPoints->LineEdit1;
213   else if ( send == GroupPoints->PushButton2 && !myObject->_is_nil() )
214     myEditCurrentArgument = GroupPoints->LineEdit2;
215
216   if ( myEditCurrentArgument ) {
217     initSelection();
218     myEditCurrentArgument->setFocus();
219     SelectionIntoArgument();
220   }
221 }
222
223
224 //=================================================================================
225 // function : LineEditReturnPressed()
226 // purpose  :
227 //=================================================================================
228 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
229 {
230   const QObject* send = sender();
231   if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
232     myEditCurrentArgument = (QLineEdit*)send;
233     GEOMBase_Skeleton::LineEditReturnPressed();
234   }
235 }
236
237
238 //=================================================================================
239 // function : ActivateThisDialog()
240 // purpose  :
241 //=================================================================================
242 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
243 {
244   GEOMBase_Skeleton::ActivateThisDialog();
245   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
246            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
247
248   myEditCurrentArgument = GroupPoints->LineEdit1;
249   myEditCurrentArgument->setText( "" );
250   GroupPoints->LineEdit2->setText( "" );
251   myObject = GEOM::GEOM_Object::_nil();
252   myWiresInd->length( 0 );
253
254   //myGeomGUI->SetState( 0 );
255   initSelection();
256 }
257
258 //=================================================================================
259 // function : enterEvent()
260 // purpose  : Mouse enter onto the dialog to activate it
261 //=================================================================================
262 void RepairGUI_RemoveIntWiresDlg::enterEvent( QEvent* )
263 {
264   if ( !mainFrame()->GroupConstructors->isEnabled() )
265     ActivateThisDialog();
266 }
267
268 //=================================================================================
269 // function : createOperation
270 // purpose  :
271 //=================================================================================
272 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
273 {
274   return getGeomEngine()->GetIHealingOperations( getStudyId() );
275 }
276
277 //=================================================================================
278 // function : isValid
279 // purpose  :
280 //=================================================================================
281 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& )
282 {
283   return !myObject->_is_nil() && ( GroupPoints->CheckButton1->isChecked() || myWiresInd->length() );
284 }
285
286 //=================================================================================
287 // function : execute
288 // purpose  :
289 //=================================================================================
290 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
291 {
292   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
293     RemoveIntWires( myObject, myWiresInd );
294   bool aResult = !anObj->_is_nil();
295   if ( aResult )
296     objects.push_back( anObj._retn() );
297
298   return aResult;
299 }
300
301 //=================================================================================
302 // function : onRemoveAllClicked
303 // purpose  :
304 //=================================================================================
305 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
306 {
307   bool b = GroupPoints->CheckButton1->isChecked();
308   GroupPoints->TextLabel2->setEnabled( !b );
309   GroupPoints->PushButton2->setEnabled( !b );
310   GroupPoints->LineEdit2->setEnabled( !b );
311   if ( b ) {
312     GroupPoints->LineEdit2->setText( "" );
313     myWiresInd->length( 0 );
314   }
315 }
316
317 //=================================================================================
318 // function : initSelection
319 // purpose  :
320 //=================================================================================
321 void RepairGUI_RemoveIntWiresDlg::initSelection()
322 {
323   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
324     TColStd_MapOfInteger aTypes;
325     aTypes.Add( GEOM_COMPOUND );
326     aTypes.Add( GEOM_SOLID );
327     aTypes.Add( GEOM_SHELL );
328     aTypes.Add( GEOM_FACE );
329     
330     globalSelection( aTypes );
331   }
332   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
333     //localSelection( myObject, TopAbs_EDGE );
334     localSelection( myObject, TopAbs_WIRE );
335   }
336 }