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
29 #include "RepairGUI_SuppressFacesDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "SalomeApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include "GEOMImpl_Types.hxx"
44 //=================================================================================
45 // class : RepairGUI_SuppressFacesDlg()
46 // purpose : Constructs a RepairGUI_SuppressFacesDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPRESS_FACE")));
55 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
66 GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
67 GroupPoints->TextLabel1->setText(tr("Faces"));
68 GroupPoints->PushButton1->setPixmap(image1);
69 GroupPoints->LineEdit1->setReadOnly( true );
71 Layout1->addWidget(GroupPoints, 2, 0);
72 /***************************************************************/
78 //=================================================================================
79 // function : ~RepairGUI_SuppressFacesDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
87 //=================================================================================
90 //=================================================================================
91 void RepairGUI_SuppressFacesDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
96 myObjects = new GEOM::ListOfGO();
97 myObjects->length( 0 );
99 //myGeomGUI->SetState( 0 );
102 /* signals and slots connections */
103 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
104 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
105 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
107 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
114 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
116 initName( tr( "SUPRESS_FACE_NEW_OBJ_NAME" ) );
120 //=================================================================================
121 // function : ClickOnOk()
122 // purpose : Same than click on apply but close this dialog.
123 //=================================================================================
124 void RepairGUI_SuppressFacesDlg::ClickOnOk()
126 if ( ClickOnApply() )
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
143 myEditCurrentArgument->setText("");
144 myObjects->length( 0 );
153 //=================================================================================
154 // function : ClickOnCancel()
156 //=================================================================================
157 void RepairGUI_SuppressFacesDlg::ClickOnCancel()
159 GEOMBase_Skeleton::ClickOnCancel();
163 //=================================================================================
164 // function : SelectionIntoArgument()
165 // purpose : Called when selection as changed or other case
166 // : used only by SelectButtonC1A1 (LineEditC1A1)
167 //=================================================================================
168 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
170 myEditCurrentArgument->setText("");
172 Standard_Boolean aRes = Standard_False;
175 myObjects->length( IObjectCount() );
177 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
179 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
180 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
181 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
184 if ( myGeomBase->GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
186 if ( aShape.ShapeType() <= TopAbs_FACE ) // FACE, SHELL, SOLID, COMPOUND
188 GEOM::short_array anIndexes;
190 TColStd_IndexedMapOfInteger aMap;
191 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
193 if ( !aMap.IsEmpty() )
195 Convert( aMap, anIndexes );
196 myObjects[i++] = aSelectedObject; // append the object
197 myFaces.append( anIndexes ); // append faces' indexes
198 numFaces += anIndexes.length();// just for text field output
204 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
206 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
209 //=================================================================================
210 // function : Convert()
212 //=================================================================================
213 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
215 const int n = theMap.Extent();
216 theOutSeq.length( n );
217 for ( int i = 0; i < n; i++ )
218 theOutSeq[i] = theMap( i+1 );
221 //=================================================================================
222 // function : SetEditCurrentArgument()
224 //=================================================================================
225 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
227 if( sender() == GroupPoints->PushButton1 )
229 GroupPoints->LineEdit1->setFocus();
230 myEditCurrentArgument = GroupPoints->LineEdit1;
232 SelectionIntoArgument();
236 //=================================================================================
237 // function : LineEditReturnPressed()
239 //=================================================================================
240 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
242 if( sender() == GroupPoints->LineEdit1 )
244 myEditCurrentArgument = GroupPoints->LineEdit1;
245 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : DeactivateActiveDialog()
253 //=================================================================================
254 void RepairGUI_SuppressFacesDlg::DeactivateActiveDialog()
256 //myGeomGUI->SetState( -1 );
257 GEOMBase_Skeleton::DeactivateActiveDialog();
261 //=================================================================================
262 // function : ActivateThisDialog()
264 //=================================================================================
265 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
267 GEOMBase_Skeleton::ActivateThisDialog();
268 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
269 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271 //myGeomGUI->SetState( 0 );
276 //=================================================================================
277 // function : enterEvent()
278 // purpose : Mouse enter onto the dialog to activate it
279 //=================================================================================
280 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
282 if ( !GroupConstructors->isEnabled() )
283 ActivateThisDialog();
287 //=================================================================================
288 // function : closeEvent()
290 //=================================================================================
291 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
293 //myGeomGUI->SetState( -1 );
294 GEOMBase_Skeleton::closeEvent( e );
297 //=================================================================================
298 // function : createOperation
300 //=================================================================================
301 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
303 return getGeomEngine()->GetIHealingOperations( getStudyId() );
306 //=================================================================================
307 // function : isValid
309 //=================================================================================
310 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
312 const int objL = myObjects->length(), facesL = myFaces.size();
313 return ( objL && objL == facesL );
316 //=================================================================================
317 // function : execute
319 //=================================================================================
320 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
322 QStringList anErrorObjNames;
323 for ( int i = 0; i < myObjects->length(); i++ )
325 GEOM::GEOM_Object_var obj = myObjects[i];
326 GEOM::short_array faces = myFaces[i];
327 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
328 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
329 if ( anObj->_is_nil() )
330 anErrorObjNames << GEOMBase::GetName( obj );
332 objects.push_back( anObj._retn() );
335 if ( !anErrorObjNames.empty() )
336 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
338 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
341 //=================================================================================
342 // function : initSelection
344 //=================================================================================
345 void RepairGUI_SuppressFacesDlg::initSelection()
347 GEOM::GEOM_Object_var aNullGeomObject;
348 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects