]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx
Salome HOME
4bb3b5bece6abe1f6620b411c787de9229030445
[modules/geom.git] / src / RepairGUI / RepairGUI_SuppressFacesDlg.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_SuppressFacesDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "RepairGUI_SuppressFacesDlg.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_SuppressFacesDlg()
44 // purpose  : Constructs a RepairGUI_SuppressFacesDlg  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_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(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_SUPRESS_FACE")));
53   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54     
55   setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
56
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
59   RadioButton1->setPixmap(image0);
60   RadioButton2->close(TRUE);
61   RadioButton3->close(TRUE);
62
63   GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
64   GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
65   GroupPoints->TextLabel1->setText(tr("Faces"));
66   GroupPoints->PushButton1->setPixmap(image1);
67   GroupPoints->LineEdit1->setReadOnly( true );
68
69   Layout1->addWidget(GroupPoints, 1, 0);
70   /***************************************************************/
71
72   Init();
73 }
74
75
76 //=================================================================================
77 // function : ~RepairGUI_SuppressFacesDlg()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
81 {
82 }
83
84
85 //=================================================================================
86 // function : Init()
87 // purpose  :
88 //=================================================================================
89 void RepairGUI_SuppressFacesDlg::Init()
90 {
91   /* init variables */
92   myEditCurrentArgument = GroupPoints->LineEdit1;
93
94   myObjects = new GEOM::ListOfGO();
95   myObjects->length( 0 );
96
97   myGeomGUI->SetState( 0 );
98   initSelection();
99           
100   /* signals and slots connections */
101   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
102   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
103   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
104
105   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
106   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107
108   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110
111   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
112 }
113
114
115 //=================================================================================
116 // function : ClickOnOk()
117 // purpose  : Same than click on apply but close this dialog.
118 //=================================================================================
119 void RepairGUI_SuppressFacesDlg::ClickOnOk()
120 {
121   if ( ClickOnApply() )
122     ClickOnCancel();
123 }
124
125
126
127 //=================================================================================
128 // function : ClickOnApply()
129 // purpose  :
130 //=================================================================================
131 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
132 {
133         if ( !onAccept() )
134                 return false;
135
136   myEditCurrentArgument->setText("");
137   myObjects->length( 0 );
138   myFaces.clear();
139
140         initSelection();
141         
142         return true;
143 }
144
145
146 //=================================================================================
147 // function : ClickOnCancel()
148 // purpose  :
149 //=================================================================================
150 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
151 {
152   GEOMBase_Skeleton::ClickOnCancel();
153 }
154
155
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose  : Called when selection as changed or other case
159 //          : used only by SelectButtonC1A1 (LineEditC1A1)
160 //=================================================================================
161 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
162 {
163   myEditCurrentArgument->setText("");
164
165   Standard_Boolean aRes = Standard_False;
166   int i = 0;
167   int numFaces = 0;
168   myObjects->length( mySelection->IObjectCount() );
169   myFaces.clear();
170   for ( SALOME_ListIteratorOfListIO anIt( mySelection->StoredIObjects() ); anIt.More(); anIt.Next() )
171   {
172     Handle(SALOME_InteractiveObject) anIO = anIt.Value();
173     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
174     if ( !CORBA::is_nil( aSelectedObject ) && aRes )
175     {
176       TopoDS_Shape aShape;
177       if ( myGeomBase->GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
178       {
179                                 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
180                                 {
181                                         GEOM::short_array anIndexes;
182                                         if ( mySelection->HasIndex( anIO ) )
183                                         {
184                                                 TColStd_IndexedMapOfInteger aMap;
185                                                 mySelection->GetIndex( anIO, aMap );
186                                                 Convert( aMap, anIndexes );
187                                                 myObjects[i++] = aSelectedObject; // append the object
188                                                 myFaces.append( anIndexes );   // append faces' indexes
189                                                 numFaces += anIndexes.length();// just for text field output
190                                         }
191                                 }
192       }
193     }
194   }
195   myObjects->length( i ); // this is the right length, smaller of equal to the previously set
196   if ( numFaces )
197     myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
198 }
199
200 //=================================================================================
201 // function : Convert()
202 // purpose  :
203 //=================================================================================
204 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
205 {
206         const int n = theMap.Extent();
207         theOutSeq.length( n );
208         for ( int i = 0; i < n; i++ )
209                 theOutSeq[i] = theMap( i+1 );
210 }
211
212 //=================================================================================
213 // function : SetEditCurrentArgument()
214 // purpose  :
215 //=================================================================================
216 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
217 {
218   if( sender() == GroupPoints->PushButton1 )
219   {
220     GroupPoints->LineEdit1->setFocus();
221     myEditCurrentArgument = GroupPoints->LineEdit1;
222   }
223   SelectionIntoArgument();
224 }
225
226
227 //=================================================================================
228 // function : LineEditReturnPressed()
229 // purpose  :
230 //=================================================================================
231 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
232 {
233   if( sender() == GroupPoints->LineEdit1 )
234   {
235     myEditCurrentArgument = GroupPoints->LineEdit1;
236           GEOMBase_Skeleton::LineEditReturnPressed();
237         }
238 }
239
240
241 //=================================================================================
242 // function : DeactivateActiveDialog()
243 // purpose  :
244 //=================================================================================
245 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
246 {
247   myGeomGUI->SetState( -1 );
248   GEOMBase_Skeleton::DeactivateActiveDialog();
249 }
250
251
252 //=================================================================================
253 // function : ActivateThisDialog()
254 // purpose  :
255 //=================================================================================
256 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
257 {
258   GEOMBase_Skeleton::ActivateThisDialog();
259   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260
261   myGeomGUI->SetState( 0 );
262         initSelection();
263 }
264
265
266 //=================================================================================
267 // function : enterEvent()
268 // purpose  : Mouse enter onto the dialog to activate it
269 //=================================================================================
270 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
271 {
272   if ( !GroupConstructors->isEnabled() )
273     ActivateThisDialog();
274 }
275
276
277 //=================================================================================
278 // function : closeEvent()
279 // purpose  :
280 //=================================================================================
281 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
282 {
283   myGeomGUI->SetState( -1 );
284   GEOMBase_Skeleton::closeEvent( e );
285 }
286
287 //=================================================================================
288 // function : createOperation
289 // purpose  :
290 //=================================================================================
291 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
292 {
293   return getGeomEngine()->GetIHealingOperations( getStudyId() );
294 }
295
296 //=================================================================================
297 // function : isValid
298 // purpose  :
299 //=================================================================================
300 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
301 {
302         const int objL = myObjects->length(), facesL = myFaces.size();
303   return ( objL && objL == facesL );
304 }
305
306 //=================================================================================
307 // function : execute
308 // purpose  :
309 //=================================================================================
310 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
311 {
312   QStringList anErrorObjNames;
313         for ( int i = 0; i < myObjects->length(); i++ )
314         {
315                 GEOM::GEOM_Object_var obj = myObjects[i];
316                 GEOM::short_array faces = myFaces[i];
317                 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
318                 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
319                 if ( anObj->_is_nil() )
320                         anErrorObjNames << GEOMBase::GetName( obj );
321                 else
322                         objects.push_back( anObj._retn() );
323         }
324
325         if ( !anErrorObjNames.empty() )
326                 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
327
328         return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
329 }
330
331 //=================================================================================
332 // function : initSelection
333 // purpose  :
334 //=================================================================================
335 void RepairGUI_SuppressFacesDlg::initSelection()
336 {
337   GEOM::GEOM_Object_var aNullGeomObject;
338   localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects
339 }