Salome HOME
Windows porting
[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 "SalomeApp_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(QWidget* parent, const char* name, bool modal, WFlags fl)
51   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 {
53   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
54   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55
56   setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
57
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
60   RadioButton1->setPixmap(image0);
61   RadioButton2->close(TRUE);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
65   GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
66   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
67   GroupPoints->PushButton1->setPixmap(image1);
68   GroupPoints->LineEdit1->setReadOnly( true );
69
70   Layout1->addWidget(GroupPoints, 2, 0);
71
72   myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
73
74   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
75
76   mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
77   mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
78   mySelectWiresBtn->setText( trUtf8( "" ) );
79   mySelectWiresBtn->setPixmap(image1);
80   
81   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
82   mySelectWiresEdt->setReadOnly( true );
83
84   mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
85   mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
86
87   aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
88         aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );  
89   aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
90   QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
91   aSelectWiresLay->addItem( spacer, 1, 2 );
92
93   GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
94   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );  
95   /***************************************************************/
96
97   Init();
98 }
99
100
101 //=================================================================================
102 // function : ~RepairGUI_RemoveIntWiresDlg()
103 // purpose  : Destroys the object and frees any allocated resources
104 //=================================================================================
105 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
106 {
107 }
108
109
110 //=================================================================================
111 // function : Init()
112 // purpose  :
113 //=================================================================================
114 void RepairGUI_RemoveIntWiresDlg::Init()
115 {
116   /* init variables */
117   myEditCurrentArgument = GroupPoints->LineEdit1;
118
119   myObject = GEOM::GEOM_Object::_nil();
120         myWiresInd = new GEOM::short_array();
121         myWiresInd->length( 0 );
122
123   //myGeomGUI->SetState( 0 );
124   initSelection(); 
125
126   /* signals and slots connections */
127   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
128   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
129   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
130
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
160 //=================================================================================
161 // function : ClickOnApply()
162 // purpose  :
163 //=================================================================================
164 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
165 {
166   if ( !onAccept() )
167         return false;
168
169   initName();
170
171   myEditCurrentArgument = GroupPoints->LineEdit1;
172   myEditCurrentArgument->setText("");
173   mySelectWiresEdt->setText("");
174   myObject = GEOM::GEOM_Object::_nil();
175         myWiresInd->length( 0 );
176
177         initSelection();
178
179   return true;
180 }
181
182
183 //=================================================================================
184 // function : ClickOnCancel()
185 // purpose  :
186 //=================================================================================
187 void RepairGUI_RemoveIntWiresDlg::ClickOnCancel()
188 {
189   GEOMBase_Skeleton::ClickOnCancel();
190 }
191
192
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose  : Called when selection
196 //=================================================================================
197 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
198 {
199   myEditCurrentArgument->setText("");
200   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
201   else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
202
203   if ( IObjectCount() == 1 )
204     {
205       Handle(SALOME_InteractiveObject) anIO = firstIObject();
206       
207       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )    // face selection
208         {
209           Standard_Boolean aRes;
210           myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
211           if ( aRes && GEOMBase::IsShape( myObject ) )
212             myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
213           else
214             myObject = GEOM::GEOM_Object::_nil();
215         }
216       else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
217         {
218           TColStd_IndexedMapOfInteger aMap;
219           ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
220           const int n = aMap.Extent();
221           myWiresInd->length( n );
222           for ( int i = 1; i <= n; i++ )
223             myWiresInd[i-1] = aMap( i );
224           if ( n )
225             myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
226         }
227     }
228 }
229
230 //=================================================================================
231 // function : SetEditCurrentArgument()
232 // purpose  :
233 //=================================================================================
234 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
235 {
236         const QObject* send = sender();
237   if ( send == GroupPoints->PushButton1 )
238         myEditCurrentArgument = GroupPoints->LineEdit1;
239   else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
240         myEditCurrentArgument = mySelectWiresEdt;
241
242   if ( myEditCurrentArgument )
243   {
244         initSelection();
245         myEditCurrentArgument->setFocus();
246         SelectionIntoArgument();
247   }
248 }
249
250
251 //=================================================================================
252 // function : LineEditReturnPressed()
253 // purpose  :
254 //=================================================================================
255 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
256 {
257         const QObject* send = sender();
258   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
259   {
260     myEditCurrentArgument = (QLineEdit*)send;
261           GEOMBase_Skeleton::LineEditReturnPressed();
262         }
263 }
264
265
266 //=================================================================================
267 // function : DeactivateActiveDialog()
268 // purpose  :
269 //=================================================================================
270 void RepairGUI_RemoveIntWiresDlg::DeactivateActiveDialog()
271 {
272   //myGeomGUI->SetState( -1 );
273   GEOMBase_Skeleton::DeactivateActiveDialog();
274 }
275
276
277 //=================================================================================
278 // function : ActivateThisDialog()
279 // purpose  :
280 //=================================================================================
281 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
282 {
283   GEOMBase_Skeleton::ActivateThisDialog();
284   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
285           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
286
287   myEditCurrentArgument = GroupPoints->LineEdit1;
288   myEditCurrentArgument->setText("");
289   mySelectWiresEdt->setText("");
290   myObject = GEOM::GEOM_Object::_nil();
291   myWiresInd->length( 0 );
292
293   //myGeomGUI->SetState( 0 );
294   initSelection();
295 }
296
297
298 //=================================================================================
299 // function : enterEvent()
300 // purpose  : Mouse enter onto the dialog to activate it
301 //=================================================================================
302 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
303 {
304   if ( !GroupConstructors->isEnabled() )
305     ActivateThisDialog();
306 }
307
308
309 //=================================================================================
310 // function : closeEvent()
311 // purpose  :
312 //=================================================================================
313 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
314 {
315   //myGeomGUI->SetState( -1 );
316   GEOMBase_Skeleton::closeEvent( e );
317 }
318
319 //=================================================================================
320 // function : createOperation
321 // purpose  :
322 //=================================================================================
323 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
324 {
325   return getGeomEngine()->GetIHealingOperations( getStudyId() );
326 }
327
328 //=================================================================================
329 // function : isValid
330 // purpose  :
331 //=================================================================================
332 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
333 {
334         return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
335 }
336
337 //=================================================================================
338 // function : execute
339 // purpose  :
340 //=================================================================================
341 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
342 {
343         GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->RemoveIntWires( myObject, myWiresInd );
344         bool aResult = !anObj->_is_nil();
345         if ( aResult )
346                 objects.push_back( anObj._retn() );
347
348         return aResult;
349 }
350
351 //=================================================================================
352 // function : onRemoveAllClicked
353 // purpose  :
354 //=================================================================================
355 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
356 {
357         bool b = myAllChk->isOn();
358   mySelectWiresLbl->setEnabled( !b );
359   mySelectWiresBtn->setEnabled( !b );
360   mySelectWiresEdt->setEnabled( !b );
361   if ( b )
362   {
363     mySelectWiresEdt->setText( "" );
364     myWiresInd->length( 0 );
365   }
366 }
367
368 //=================================================================================
369 // function : initSelection
370 // purpose  :
371 //=================================================================================
372 void RepairGUI_RemoveIntWiresDlg::initSelection()
373 {
374   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
375   {
376         TColStd_MapOfInteger aTypes;
377         aTypes.Add( GEOM_COMPOUND );
378         aTypes.Add( GEOM_SOLID );
379         aTypes.Add( GEOM_SHELL );
380         aTypes.Add( GEOM_FACE );
381         
382         globalSelection( aTypes );
383   }
384   else if ( myEditCurrentArgument == mySelectWiresEdt )
385   {
386     //localSelection( myObject, TopAbs_EDGE );
387     localSelection( myObject, TopAbs_WIRE );
388   }
389 }
390
391