1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RepairGUI_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_SuppressFacesDlg.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
34 #include "SUIT_Session.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
43 //=================================================================================
44 // class : RepairGUI_SuppressFacesDlg()
45 // purpose : Constructs a RepairGUI_SuppressFacesDlg 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_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
66 GroupPoints->TextLabel1->setText(tr("Faces"));
67 GroupPoints->PushButton1->setPixmap(image1);
68 GroupPoints->LineEdit1->setReadOnly( true );
70 Layout1->addWidget(GroupPoints, 2, 0);
71 /***************************************************************/
77 //=================================================================================
78 // function : ~RepairGUI_SuppressFacesDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
86 //=================================================================================
89 //=================================================================================
90 void RepairGUI_SuppressFacesDlg::Init()
93 myEditCurrentArgument = GroupPoints->LineEdit1;
95 myObjects = new GEOM::ListOfGO();
96 myObjects->length( 0 );
98 //myGeomGUI->SetState( 0 );
101 /* signals and slots connections */
102 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
103 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
104 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
106 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
109 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
113 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
115 initName( tr( "SUPRESS_FACE_NEW_OBJ_NAME" ) );
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose : Same than click on apply but close this dialog.
122 //=================================================================================
123 void RepairGUI_SuppressFacesDlg::ClickOnOk()
125 if ( ClickOnApply() )
131 //=================================================================================
132 // function : ClickOnApply()
134 //=================================================================================
135 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
142 myEditCurrentArgument->setText("");
143 myObjects->length( 0 );
152 //=================================================================================
153 // function : ClickOnCancel()
155 //=================================================================================
156 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
158 GEOMBase_Skeleton::ClickOnCancel();
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose : Called when selection as changed or other case
165 // : used only by SelectButtonC1A1 (LineEditC1A1)
166 //=================================================================================
167 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
169 myEditCurrentArgument->setText("");
171 Standard_Boolean aRes = Standard_False;
174 myObjects->length( IObjectCount() );
176 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
178 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
179 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
180 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
183 if ( myGeomBase->GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
185 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
187 GEOM::short_array anIndexes;
189 TColStd_IndexedMapOfInteger aMap;
190 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
192 if ( !aMap.IsEmpty() )
194 Convert( aMap, anIndexes );
195 myObjects[i++] = aSelectedObject; // append the object
196 myFaces.append( anIndexes ); // append faces' indexes
197 numFaces += anIndexes.length();// just for text field output
203 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
205 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
208 //=================================================================================
209 // function : Convert()
211 //=================================================================================
212 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
214 const int n = theMap.Extent();
215 theOutSeq.length( n );
216 for ( int i = 0; i < n; i++ )
217 theOutSeq[i] = theMap( i+1 );
220 //=================================================================================
221 // function : SetEditCurrentArgument()
223 //=================================================================================
224 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
226 if( sender() == GroupPoints->PushButton1 )
228 GroupPoints->LineEdit1->setFocus();
229 myEditCurrentArgument = GroupPoints->LineEdit1;
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : LineEditReturnPressed()
238 //=================================================================================
239 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
241 if( sender() == GroupPoints->LineEdit1 )
243 myEditCurrentArgument = GroupPoints->LineEdit1;
244 GEOMBase_Skeleton::LineEditReturnPressed();
249 //=================================================================================
250 // function : DeactivateActiveDialog()
252 //=================================================================================
253 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
255 //myGeomGUI->SetState( -1 );
256 GEOMBase_Skeleton::DeactivateActiveDialog();
260 //=================================================================================
261 // function : ActivateThisDialog()
263 //=================================================================================
264 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
266 GEOMBase_Skeleton::ActivateThisDialog();
267 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
268 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
270 //myGeomGUI->SetState( 0 );
275 //=================================================================================
276 // function : enterEvent()
277 // purpose : Mouse enter onto the dialog to activate it
278 //=================================================================================
279 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
281 if ( !GroupConstructors->isEnabled() )
282 ActivateThisDialog();
286 //=================================================================================
287 // function : closeEvent()
289 //=================================================================================
290 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
292 //myGeomGUI->SetState( -1 );
293 GEOMBase_Skeleton::closeEvent( e );
296 //=================================================================================
297 // function : createOperation
299 //=================================================================================
300 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
302 return getGeomEngine()->GetIHealingOperations( getStudyId() );
305 //=================================================================================
306 // function : isValid
308 //=================================================================================
309 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
311 const int objL = myObjects->length(), facesL = myFaces.size();
312 return ( objL && objL == facesL );
315 //=================================================================================
316 // function : execute
318 //=================================================================================
319 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
321 QStringList anErrorObjNames;
322 for ( int i = 0; i < myObjects->length(); i++ )
324 GEOM::GEOM_Object_var obj = myObjects[i];
325 GEOM::short_array faces = myFaces[i];
326 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
327 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
328 if ( anObj->_is_nil() )
329 anErrorObjNames << GEOMBase::GetName( obj );
331 objects.push_back( anObj._retn() );
334 if ( !anErrorObjNames.empty() )
335 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
337 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
340 //=================================================================================
341 // function : initSelection
343 //=================================================================================
344 void RepairGUI_SuppressFacesDlg::initSelection()
346 GEOM::GEOM_Object_var aNullGeomObject;
347 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects