Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : RepairGUI_RemoveIntWiresDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "RepairGUI_RemoveIntWiresDlg.h"
30
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
35
36 #include "GEOMImpl_Types.hxx"
37
38 #include <TopAbs.hxx>
39 #include <TColStd_MapOfInteger.hxx>
40
41 using namespace std;
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                                                          const char* name, bool modal, WFlags fl)
52   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   QPixmap image0 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
56   QPixmap image1 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57
58   setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
59
60   /***************************************************************/
61   GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_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_INTERNAL_WIRES"));
68   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
69   GroupPoints->PushButton1->setPixmap(image1);
70   GroupPoints->LineEdit1->setReadOnly( true );
71
72   Layout1->addWidget(GroupPoints, 2, 0);
73
74   myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
75
76   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
77
78   mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
79   mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
80   mySelectWiresBtn->setText( trUtf8( "" ) );
81   mySelectWiresBtn->setPixmap(image1);
82   
83   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
84   mySelectWiresEdt->setReadOnly( true );
85
86   mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
87   mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
88
89   aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
90         aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );  
91   aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
92   QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
93   aSelectWiresLay->addItem( spacer, 1, 2 );
94
95   GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
96   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );  
97   /***************************************************************/
98
99   setHelpFileName("suppress_internal_wires.htm");
100
101   Init();
102 }
103
104
105 //=================================================================================
106 // function : ~RepairGUI_RemoveIntWiresDlg()
107 // purpose  : Destroys the object and frees any allocated resources
108 //=================================================================================
109 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
110 {
111 }
112
113
114 //=================================================================================
115 // function : Init()
116 // purpose  :
117 //=================================================================================
118 void RepairGUI_RemoveIntWiresDlg::Init()
119 {
120   /* init variables */
121   myEditCurrentArgument = GroupPoints->LineEdit1;
122
123   myObject = GEOM::GEOM_Object::_nil();
124         myWiresInd = new GEOM::short_array();
125         myWiresInd->length( 0 );
126
127   //myGeomGUI->SetState( 0 );
128   initSelection(); 
129
130   /* signals and slots connections */
131   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133
134   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136   connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137   connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138
139   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
140           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
141
142   connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
143
144   initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
145 }
146
147
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose  : Same than click on apply but close this dialog.
151 //=================================================================================
152 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
153 {
154   if ( ClickOnApply() )
155     ClickOnCancel();
156 }
157
158 //=================================================================================
159 // function : ClickOnApply()
160 // purpose  :
161 //=================================================================================
162 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
163 {
164   if ( !onAccept() )
165         return false;
166
167   initName();
168
169   myEditCurrentArgument = GroupPoints->LineEdit1;
170   myEditCurrentArgument->setText("");
171   mySelectWiresEdt->setText("");
172   myObject = GEOM::GEOM_Object::_nil();
173         myWiresInd->length( 0 );
174
175         initSelection();
176
177   return true;
178 }
179
180
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose  : Called when selection
184 //=================================================================================
185 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
186 {
187   myEditCurrentArgument->setText("");
188   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
189   else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
190
191   if ( IObjectCount() == 1 )
192     {
193       Handle(SALOME_InteractiveObject) anIO = firstIObject();
194       
195       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )    // face selection
196         {
197           Standard_Boolean aRes;
198           myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
199           if ( aRes && GEOMBase::IsShape( myObject ) )
200             myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
201           else
202             myObject = GEOM::GEOM_Object::_nil();
203         }
204       else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
205         {
206           TColStd_IndexedMapOfInteger aMap;
207           ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
208           const int n = aMap.Extent();
209           myWiresInd->length( n );
210           for ( int i = 1; i <= n; i++ )
211             myWiresInd[i-1] = aMap( i );
212           if ( n )
213             myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
214         }
215     }
216 }
217
218 //=================================================================================
219 // function : SetEditCurrentArgument()
220 // purpose  :
221 //=================================================================================
222 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
223 {
224         const QObject* send = sender();
225   if ( send == GroupPoints->PushButton1 )
226         myEditCurrentArgument = GroupPoints->LineEdit1;
227   else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
228         myEditCurrentArgument = mySelectWiresEdt;
229
230   if ( myEditCurrentArgument )
231   {
232         initSelection();
233         myEditCurrentArgument->setFocus();
234         SelectionIntoArgument();
235   }
236 }
237
238
239 //=================================================================================
240 // function : LineEditReturnPressed()
241 // purpose  :
242 //=================================================================================
243 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
244 {
245         const QObject* send = sender();
246   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
247   {
248     myEditCurrentArgument = (QLineEdit*)send;
249           GEOMBase_Skeleton::LineEditReturnPressed();
250         }
251 }
252
253
254 //=================================================================================
255 // function : ActivateThisDialog()
256 // purpose  :
257 //=================================================================================
258 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
259 {
260   GEOMBase_Skeleton::ActivateThisDialog();
261   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
262           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
263
264   myEditCurrentArgument = GroupPoints->LineEdit1;
265   myEditCurrentArgument->setText("");
266   mySelectWiresEdt->setText("");
267   myObject = GEOM::GEOM_Object::_nil();
268   myWiresInd->length( 0 );
269
270   //myGeomGUI->SetState( 0 );
271   initSelection();
272 }
273
274 //=================================================================================
275 // function : enterEvent()
276 // purpose  : Mouse enter onto the dialog to activate it
277 //=================================================================================
278 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
279 {
280   if ( !GroupConstructors->isEnabled() )
281     ActivateThisDialog();
282 }
283
284 //=================================================================================
285 // function : closeEvent()
286 // purpose  :
287 //=================================================================================
288 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
289 {
290   //myGeomGUI->SetState( -1 );
291   GEOMBase_Skeleton::closeEvent( e );
292 }
293
294 //=================================================================================
295 // function : createOperation
296 // purpose  :
297 //=================================================================================
298 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
299 {
300   return getGeomEngine()->GetIHealingOperations( getStudyId() );
301 }
302
303 //=================================================================================
304 // function : isValid
305 // purpose  :
306 //=================================================================================
307 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
308 {
309         return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
310 }
311
312 //=================================================================================
313 // function : execute
314 // purpose  :
315 //=================================================================================
316 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
317 {
318   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
319     RemoveIntWires( myObject, myWiresInd );
320   bool aResult = !anObj->_is_nil();
321   if ( aResult )
322     objects.push_back( anObj._retn() );
323
324   return aResult;
325 }
326
327 //=================================================================================
328 // function : onRemoveAllClicked
329 // purpose  :
330 //=================================================================================
331 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
332 {
333   bool b = myAllChk->isOn();
334   mySelectWiresLbl->setEnabled( !b );
335   mySelectWiresBtn->setEnabled( !b );
336   mySelectWiresEdt->setEnabled( !b );
337   if ( b )
338   {
339     mySelectWiresEdt->setText( "" );
340     myWiresInd->length( 0 );
341   }
342 }
343
344 //=================================================================================
345 // function : initSelection
346 // purpose  :
347 //=================================================================================
348 void RepairGUI_RemoveIntWiresDlg::initSelection()
349 {
350   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
351   {
352         TColStd_MapOfInteger aTypes;
353         aTypes.Add( GEOM_COMPOUND );
354         aTypes.Add( GEOM_SOLID );
355         aTypes.Add( GEOM_SHELL );
356         aTypes.Add( GEOM_FACE );
357         
358         globalSelection( aTypes );
359   }
360   else if ( myEditCurrentArgument == mySelectWiresEdt )
361   {
362     //localSelection( myObject, TopAbs_EDGE );
363     localSelection( myObject, TopAbs_WIRE );
364   }
365 }