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
24 // File : RepairGUI_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_SuppressFacesDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
52 const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
54 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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 setCaption(tr("GEOM_SUPRESSFACE_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_SUPRESSFACE"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("Faces to remove"));
69 GroupPoints->TextLabel1->setText(tr("Faces"));
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->LineEdit1->setReadOnly( true );
73 Layout1->addWidget(GroupPoints, 2, 0);
74 /***************************************************************/
76 setHelpFileName("suppress_faces.htm");
82 //=================================================================================
83 // function : ~RepairGUI_SuppressFacesDlg()
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 RepairGUI_SuppressFacesDlg::~RepairGUI_SuppressFacesDlg()
91 //=================================================================================
94 //=================================================================================
95 void RepairGUI_SuppressFacesDlg::Init()
98 myEditCurrentArgument = GroupPoints->LineEdit1;
100 myObjects = new GEOM::ListOfGO();
101 myObjects->length( 0 );
103 //myGeomGUI->SetState( 0 );
106 /* signals and slots connections */
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() )
130 //=================================================================================
131 // function : ClickOnApply()
133 //=================================================================================
134 bool RepairGUI_SuppressFacesDlg::ClickOnApply()
141 myEditCurrentArgument->setText("");
142 myObjects->length( 0 );
151 //=================================================================================
152 // function : SelectionIntoArgument()
153 // purpose : Called when selection as changed or other case
154 // : used only by SelectButtonC1A1 (LineEditC1A1)
155 //=================================================================================
156 void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
158 myEditCurrentArgument->setText("");
160 Standard_Boolean aRes = Standard_False;
163 myObjects->length( IObjectCount() );
165 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
167 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
168 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
169 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
172 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) )
174 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() )
183 Convert( aMap, anIndexes );
184 myObjects[i++] = aSelectedObject; // append the object
185 myFaces.append( anIndexes ); // append faces' indexes
186 numFaces += anIndexes.length();// just for text field output
192 myObjects->length( i ); // this is the right length, smaller of equal to the previously set
194 myEditCurrentArgument->setText( QString::number( numFaces ) + "_" + tr( "GEOM_FACE" ) + tr( "_S_" ) );
197 //=================================================================================
198 // function : Convert()
200 //=================================================================================
201 void RepairGUI_SuppressFacesDlg::Convert( const TColStd_IndexedMapOfInteger& theMap, GEOM::short_array& theOutSeq )
203 const int n = theMap.Extent();
204 theOutSeq.length( n );
205 for ( int i = 0; i < n; i++ )
206 theOutSeq[i] = theMap( i+1 );
209 //=================================================================================
210 // function : SetEditCurrentArgument()
212 //=================================================================================
213 void RepairGUI_SuppressFacesDlg::SetEditCurrentArgument()
215 if( sender() == GroupPoints->PushButton1 )
217 GroupPoints->LineEdit1->setFocus();
218 myEditCurrentArgument = GroupPoints->LineEdit1;
220 SelectionIntoArgument();
224 //=================================================================================
225 // function : LineEditReturnPressed()
227 //=================================================================================
228 void RepairGUI_SuppressFacesDlg::LineEditReturnPressed()
230 if( sender() == GroupPoints->LineEdit1 )
232 myEditCurrentArgument = GroupPoints->LineEdit1;
233 GEOMBase_Skeleton::LineEditReturnPressed();
238 //=================================================================================
239 // function : ActivateThisDialog()
241 //=================================================================================
242 void RepairGUI_SuppressFacesDlg::ActivateThisDialog()
244 GEOMBase_Skeleton::ActivateThisDialog();
245 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
246 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
248 //myGeomGUI->SetState( 0 );
253 //=================================================================================
254 // function : enterEvent()
255 // purpose : Mouse enter onto the dialog to activate it
256 //=================================================================================
257 void RepairGUI_SuppressFacesDlg::enterEvent(QEvent* e)
259 if ( !GroupConstructors->isEnabled() )
260 ActivateThisDialog();
264 //=================================================================================
265 // function : closeEvent()
267 //=================================================================================
268 void RepairGUI_SuppressFacesDlg::closeEvent(QCloseEvent* e)
270 //myGeomGUI->SetState( -1 );
271 GEOMBase_Skeleton::closeEvent( e );
274 //=================================================================================
275 // function : createOperation
277 //=================================================================================
278 GEOM::GEOM_IOperations_ptr RepairGUI_SuppressFacesDlg::createOperation()
280 return getGeomEngine()->GetIHealingOperations( getStudyId() );
283 //=================================================================================
284 // function : isValid
286 //=================================================================================
287 bool RepairGUI_SuppressFacesDlg::isValid( QString& msg )
289 const int objL = myObjects->length(), facesL = myFaces.size();
290 return ( objL && objL == facesL );
293 //=================================================================================
294 // function : execute
296 //=================================================================================
297 bool RepairGUI_SuppressFacesDlg::execute( ObjectList& objects )
299 QStringList anErrorObjNames;
300 for ( int i = 0; i < myObjects->length(); i++ )
302 GEOM::GEOM_Object_var obj = myObjects[i];
303 GEOM::short_array faces = myFaces[i];
304 //MESSAGE(">>>> Dlg, passing faces.. len = " << faces.length());
305 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->SuppressFaces( obj, faces );
306 if ( anObj->_is_nil() )
307 anErrorObjNames << GEOMBase::GetName( obj );
309 objects.push_back( anObj._retn() );
312 if ( !anErrorObjNames.empty() )
313 MESSAGE("ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ));
315 return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
318 //=================================================================================
319 // function : initSelection
321 //=================================================================================
322 void RepairGUI_SuppressFacesDlg::initSelection()
324 GEOM::GEOM_Object_var aNullGeomObject;
325 localSelection( aNullGeomObject, TopAbs_FACE ); // load local selection on ALL objects