Salome HOME
e865a125dd38768a9c9284e0de3518611727b873
[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 using namespace std;
30 #include "RepairGUI_RemoveIntWiresDlg.h"
31
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
36
37 #include "GEOMImpl_Types.hxx"
38
39 #include <TopAbs.hxx>
40
41
42 //=================================================================================
43 // class    : RepairGUI_RemoveIntWiresDlg()
44 // purpose  : Constructs a RepairGUI_RemoveIntWiresDlg  which is a child of 'parent', with the
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 {
52   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
53   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54
55   setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
56
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
59   RadioButton1->setPixmap(image0);
60   RadioButton2->close(TRUE);
61   RadioButton3->close(TRUE);
62
63   GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
64   GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
65   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
66   GroupPoints->PushButton1->setPixmap(image1);
67   GroupPoints->LineEdit1->setReadOnly( true );
68
69   Layout1->addWidget(GroupPoints, 2, 0);
70
71   myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
72
73   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
74
75   mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
76   mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
77   mySelectWiresBtn->setText( trUtf8( "" ) );
78   mySelectWiresBtn->setPixmap(image1);
79   
80   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
81   mySelectWiresEdt->setReadOnly( true );
82
83   mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
84   mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
85
86   aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
87         aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );  
88   aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
89   QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
90   aSelectWiresLay->addItem( spacer, 1, 2 );
91
92   GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
93   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );  
94   /***************************************************************/
95
96   Init();
97 }
98
99
100 //=================================================================================
101 // function : ~RepairGUI_RemoveIntWiresDlg()
102 // purpose  : Destroys the object and frees any allocated resources
103 //=================================================================================
104 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
105 {
106 }
107
108
109 //=================================================================================
110 // function : Init()
111 // purpose  :
112 //=================================================================================
113 void RepairGUI_RemoveIntWiresDlg::Init()
114 {
115   /* init variables */
116   myEditCurrentArgument = GroupPoints->LineEdit1;
117
118   myObject = GEOM::GEOM_Object::_nil();
119         myWiresInd = new GEOM::short_array();
120         myWiresInd->length( 0 );
121
122   myGeomGUI->SetState( 0 );
123   initSelection(); 
124
125   /* signals and slots connections */
126   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
127   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
128   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
129
130   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
132
133   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135   connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136   connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137
138   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
139
140   connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
141
142   initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
143 }
144
145
146 //=================================================================================
147 // function : ClickOnOk()
148 // purpose  : Same than click on apply but close this dialog.
149 //=================================================================================
150 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
151 {
152   if ( ClickOnApply() )
153     ClickOnCancel();
154 }
155
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 : ClickOnCancel()
183 // purpose  :
184 //=================================================================================
185 void RepairGUI_RemoveIntWiresDlg::ClickOnCancel()
186 {
187   GEOMBase_Skeleton::ClickOnCancel();
188 }
189
190
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose  : Called when selection
194 //=================================================================================
195 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
196 {
197   myEditCurrentArgument->setText("");
198   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
199   else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
200
201   if ( mySelection->IObjectCount() == 1 )
202         {
203                 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
204
205                 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )  // face selection
206                 {
207                         Standard_Boolean aRes;
208                         myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
209                         if ( aRes && GEOMBase::IsShape( myObject ) )
210                                 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
211       else
212         myObject = GEOM::GEOM_Object::_nil();
213                 }
214                 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
215                 {
216                         TColStd_IndexedMapOfInteger aMap;
217                         mySelection->GetIndex( anIO, aMap );
218                         const int n = aMap.Extent();
219                         myWiresInd->length( n );
220                         for ( int i = 1; i <= n; i++ )
221                                 myWiresInd[i-1] = aMap( i );
222                         if ( n )
223                                 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
224                 }
225         }
226 }
227
228 //=================================================================================
229 // function : SetEditCurrentArgument()
230 // purpose  :
231 //=================================================================================
232 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
233 {
234         const QObject* send = sender();
235   if ( send == GroupPoints->PushButton1 )
236         myEditCurrentArgument = GroupPoints->LineEdit1;
237   else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
238         myEditCurrentArgument = mySelectWiresEdt;
239
240   if ( myEditCurrentArgument )
241   {
242         initSelection();
243         myEditCurrentArgument->setFocus();
244         SelectionIntoArgument();
245   }
246 }
247
248
249 //=================================================================================
250 // function : LineEditReturnPressed()
251 // purpose  :
252 //=================================================================================
253 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
254 {
255         const QObject* send = sender();
256   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
257   {
258     myEditCurrentArgument = (QLineEdit*)send;
259           GEOMBase_Skeleton::LineEditReturnPressed();
260         }
261 }
262
263
264 //=================================================================================
265 // function : DeactivateActiveDialog()
266 // purpose  :
267 //=================================================================================
268 void RepairGUI_RemoveIntWiresDlg::DeactivateActiveDialog()
269 {
270   myGeomGUI->SetState( -1 );
271   GEOMBase_Skeleton::DeactivateActiveDialog();
272 }
273
274
275 //=================================================================================
276 // function : ActivateThisDialog()
277 // purpose  :
278 //=================================================================================
279 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
280 {
281   GEOMBase_Skeleton::ActivateThisDialog();
282   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
283
284   myEditCurrentArgument = GroupPoints->LineEdit1;
285   myEditCurrentArgument->setText("");
286   mySelectWiresEdt->setText("");
287   myObject = GEOM::GEOM_Object::_nil();
288   myWiresInd->length( 0 );
289
290   myGeomGUI->SetState( 0 );
291         initSelection();
292 }
293
294
295 //=================================================================================
296 // function : enterEvent()
297 // purpose  : Mouse enter onto the dialog to activate it
298 //=================================================================================
299 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
300 {
301   if ( !GroupConstructors->isEnabled() )
302     ActivateThisDialog();
303 }
304
305
306 //=================================================================================
307 // function : closeEvent()
308 // purpose  :
309 //=================================================================================
310 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
311 {
312   myGeomGUI->SetState( -1 );
313   GEOMBase_Skeleton::closeEvent( e );
314 }
315
316 //=================================================================================
317 // function : createOperation
318 // purpose  :
319 //=================================================================================
320 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
321 {
322   return getGeomEngine()->GetIHealingOperations( getStudyId() );
323 }
324
325 //=================================================================================
326 // function : isValid
327 // purpose  :
328 //=================================================================================
329 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
330 {
331         return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
332 }
333
334 //=================================================================================
335 // function : execute
336 // purpose  :
337 //=================================================================================
338 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
339 {
340         GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->RemoveIntWires( myObject, myWiresInd );
341         bool aResult = !anObj->_is_nil();
342         if ( aResult )
343                 objects.push_back( anObj._retn() );
344
345         return aResult;
346 }
347
348 //=================================================================================
349 // function : onRemoveAllClicked
350 // purpose  :
351 //=================================================================================
352 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
353 {
354         bool b = myAllChk->isOn();
355   mySelectWiresLbl->setEnabled( !b );
356   mySelectWiresBtn->setEnabled( !b );
357   mySelectWiresEdt->setEnabled( !b );
358   if ( b )
359   {
360     mySelectWiresEdt->setText( "" );
361     myWiresInd->length( 0 );
362   }
363 }
364
365 //=================================================================================
366 // function : initSelection
367 // purpose  :
368 //=================================================================================
369 void RepairGUI_RemoveIntWiresDlg::initSelection()
370 {
371   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
372   {
373         TColStd_MapOfInteger aTypes;
374         aTypes.Add( GEOM_COMPOUND );
375         aTypes.Add( GEOM_SOLID );
376         aTypes.Add( GEOM_SHELL );
377         aTypes.Add( GEOM_FACE );
378         
379         globalSelection( aTypes );
380   }
381   else if ( myEditCurrentArgument == mySelectWiresEdt )
382   {
383     //localSelection( myObject, TopAbs_EDGE );
384     localSelection( myObject, TopAbs_WIRE );
385   }
386 }
387
388