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