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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : RepairGUI_SuppressFacesDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_SuppressFacesDlg.h"
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SALOME_ListIteratorOfListIO.hxx>
38 #include <GEOMImpl_Types.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <utilities.h>
45 //=================================================================================
46 // class : RepairGUI_SuppressFacesDlg()
47 // purpose : Constructs a RepairGUI_SuppressFacesDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 RepairGUI_SuppressFacesDlg::RepairGUI_SuppressFacesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SUPRESS_FACE" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr("GEOM_SUPRESSFACE_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
63 mainFrame()->RadioButton1->setIcon( image0 );
64 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton2->close();
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_1Sel( centralWidget() );
70 GroupPoints->GroupBox1->setTitle( tr( "Faces to remove" ) );
71 GroupPoints->TextLabel1->setText( tr( "Faces" ) );
72 GroupPoints->PushButton1->setIcon( image1 );
73 GroupPoints->LineEdit1->setReadOnly( true );
75 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76 layout->setMargin( 0 ); layout->setSpacing( 6 );
77 layout->addWidget( GroupPoints );
78 /***************************************************************/
80 setHelpFileName( "suppress_faces_operation_page.html" );
86 //=================================================================================
87 // function : ~RepairGUI_SuppressFacesDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
95 //=================================================================================
98 //=================================================================================
99 void RepairGUI_SuppressFacesDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
104 myObjects = new GEOM::ListOfGO();
105 myObjects->length( 0 );
107 //myGeomGUI->SetState( 0 );
110 /* signals and slots connections */
111 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
117 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
118 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
120 initName( tr( "SUPRESS_FACE_NEW_OBJ_NAME" ) );
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose : Same than click on apply but close this dialog.
127 //=================================================================================
128 void RepairGUI_SuppressFacesDlg::ClickOnOk()
130 if ( ClickOnApply() )
134 //=================================================================================
135 // function : ClickOnApply()
137 //=================================================================================
138 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
145 myEditCurrentArgument->setText( "" );
146 myObjects->length( 0 );
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection as changed or other case
158 // : used only by SelectButtonC1A1 (LineEditC1A1)
159 //=================================================================================
160 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText( "" );
164 Standard_Boolean aRes = Standard_False;
168 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
169 SALOME_ListIO aSelList;
170 aSelMgr->selectedObjects(aSelList);
172 myObjects->length( aSelList.Extent() );
175 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
176 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
177 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
178 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
180 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) {
181 if ( aShape.ShapeType() <= TopAbs_FACE ) { // FACE, SHELL, SOLID, COMPOUND
182 GEOM::short_array anIndexes;
184 TColStd_IndexedMapOfInteger aMap;
185 aSelMgr->GetIndexes( anIO, aMap );
187 if ( !aMap.IsEmpty() ) {
188 Convert( aMap, anIndexes );
189 myObjects[i++] = aSelectedObject; // append the object
190 myFaces.append( anIndexes ); // append faces' indexes
191 numFaces += anIndexes.length();// just for text field output
197 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
199 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
202 //=================================================================================
203 // function : Convert()
205 //=================================================================================
206 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
208 const int n = theMap.Extent();
209 theOutSeq.length( n );
210 for ( int i = 0; i < n; i++ )
211 theOutSeq[i] = theMap( i+1 );
214 //=================================================================================
215 // function : SetEditCurrentArgument()
217 //=================================================================================
218 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
220 if ( sender() == GroupPoints->PushButton1 ) {
221 GroupPoints->LineEdit1->setFocus();
222 myEditCurrentArgument = GroupPoints->LineEdit1;
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : LineEditReturnPressed()
231 //=================================================================================
232 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
234 if ( sender() == GroupPoints->LineEdit1 ) {
235 myEditCurrentArgument = GroupPoints->LineEdit1;
236 GEOMBase_Skeleton::LineEditReturnPressed();
241 //=================================================================================
242 // function : ActivateThisDialog()
244 //=================================================================================
245 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
247 GEOMBase_Skeleton::ActivateThisDialog();
248 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
249 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
251 //myGeomGUI->SetState( 0 );
256 //=================================================================================
257 // function : enterEvent()
258 // purpose : Mouse enter onto the dialog to activate it
259 //=================================================================================
260 void RepairGUI_SuppressFacesDlg::enterEvent( QEvent* )
262 if ( !mainFrame()->GroupConstructors->isEnabled() )
263 ActivateThisDialog();
267 //=================================================================================
268 // function : createOperation
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
273 return getGeomEngine()->GetIHealingOperations( getStudyId() );
276 //=================================================================================
277 // function : isValid
279 //=================================================================================
280 bool RepairGUI_SuppressFacesDlg::isValid( QString& )
282 const int objL = myObjects->length(), facesL = myFaces.size();
283 return ( objL && objL == facesL );
286 //=================================================================================
287 // function : execute
289 //=================================================================================
290 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
292 QStringList anErrorObjNames;
293 for ( int i = 0; i < myObjects->length(); i++ ) {
294 GEOM::GEOM_Object_var obj = myObjects[i];
295 GEOM::short_array faces = myFaces[i];
296 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
297 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
298 if ( anObj->_is_nil() )
299 anErrorObjNames << GEOMBase::GetName( obj );
301 objects.push_back( anObj._retn() );
304 if ( !anErrorObjNames.empty() )
305 MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
307 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
310 //=================================================================================
311 // function : initSelection
313 //=================================================================================
314 void RepairGUI_SuppressFacesDlg::initSelection()
316 GEOM::GEOM_Object_var aNullGeomObject;
317 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects