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;
167 myObjects->length( IObjectCount() );
169 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() ) {
170 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
171 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
172 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
174 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) {
175 if ( aShape.ShapeType() <= TopAbs_FACE ) { // FACE, SHELL, SOLID, COMPOUND
176 GEOM::short_array anIndexes;
178 TColStd_IndexedMapOfInteger aMap;
179 myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
181 if ( !aMap.IsEmpty() ) {
182 Convert( aMap, anIndexes );
183 myObjects[i++] = aSelectedObject; // append the object
184 myFaces.append( anIndexes ); // append faces' indexes
185 numFaces += anIndexes.length();// just for text field output
191 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
193 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
196 //=================================================================================
197 // function : Convert()
199 //=================================================================================
200 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
202 const int n = theMap.Extent();
203 theOutSeq.length( n );
204 for ( int i = 0; i < n; i++ )
205 theOutSeq[i] = theMap( i+1 );
208 //=================================================================================
209 // function : SetEditCurrentArgument()
211 //=================================================================================
212 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
214 if ( sender() == GroupPoints->PushButton1 ) {
215 GroupPoints->LineEdit1->setFocus();
216 myEditCurrentArgument = GroupPoints->LineEdit1;
218 SelectionIntoArgument();
222 //=================================================================================
223 // function : LineEditReturnPressed()
225 //=================================================================================
226 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
228 if ( sender() == GroupPoints->LineEdit1 ) {
229 myEditCurrentArgument = GroupPoints->LineEdit1;
230 GEOMBase_Skeleton::LineEditReturnPressed();
235 //=================================================================================
236 // function : ActivateThisDialog()
238 //=================================================================================
239 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
241 GEOMBase_Skeleton::ActivateThisDialog();
242 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
243 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
245 //myGeomGUI->SetState( 0 );
250 //=================================================================================
251 // function : enterEvent()
252 // purpose : Mouse enter onto the dialog to activate it
253 //=================================================================================
254 void RepairGUI_SuppressFacesDlg::enterEvent( QEvent* )
256 if ( !mainFrame()->GroupConstructors->isEnabled() )
257 ActivateThisDialog();
261 //=================================================================================
262 // function : createOperation
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
267 return getGeomEngine()->GetIHealingOperations( getStudyId() );
270 //=================================================================================
271 // function : isValid
273 //=================================================================================
274 bool RepairGUI_SuppressFacesDlg::isValid( QString& )
276 const int objL = myObjects->length(), facesL = myFaces.size();
277 return ( objL && objL == facesL );
280 //=================================================================================
281 // function : execute
283 //=================================================================================
284 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
286 QStringList anErrorObjNames;
287 for ( int i = 0; i < myObjects->length(); i++ ) {
288 GEOM::GEOM_Object_var obj = myObjects[i];
289 GEOM::short_array faces = myFaces[i];
290 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
291 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
292 if ( anObj->_is_nil() )
293 anErrorObjNames << GEOMBase::GetName( obj );
295 objects.push_back( anObj._retn() );
298 if ( !anErrorObjNames.empty() )
299 MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
301 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
304 //=================================================================================
305 // function : initSelection
307 //=================================================================================
308 void RepairGUI_SuppressFacesDlg::initSelection()
310 GEOM::GEOM_Object_var aNullGeomObject;
311 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects