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_FreeFacesDlg.cxx
30 #include "RepairGUI_FreeFacesDlg.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
34 #include "SalomeApp_Tools.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_OverrideCursor.h"
39 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "GEOMImpl_Types.hxx"
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_MapOfInteger.hxx>
46 #include "GeometryGUI.h"
47 #include "GEOM_Displayer.h"
49 #include <qapplication.h>
50 #include <qlineedit.h>
53 #include <qgroupbox.h>
54 #include <qpushbutton.h>
60 //=================================================================================
61 // class : RepairGUI_FreeFacesDlg()
62 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
63 // name 'name' and widget flags set to 'f'.
64 // The dialog will by default be modeless, unless you set 'modal' to
65 // TRUE to construct a modal dialog.
66 //=================================================================================
67 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg(GeometryGUI* GUI, QWidget* parent, const char* name, bool modal, WFlags fl)
68 :QDialog( parent, "RepairGUI_FreeBoundDlg", false,
69 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
70 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
75 setSizeGripEnabled( TRUE );
76 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
78 setCaption(tr("GEOM_FREE_FACES_TITLE"));
80 /***************************************************************/
82 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
85 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
87 aSelGrp->setInsideMargin( 0 );
88 aSelGrp->setFrameStyle( QFrame::NoFrame );
89 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
90 mySelBtn = new QPushButton( aSelGrp );
91 mySelBtn->setPixmap( image1 );
92 myEdit = new QLineEdit( aSelGrp );
93 myEdit->setReadOnly( true );
94 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 myEdit->setMinimumWidth( MIN_WIDTH );
97 QFrame* aFrame = new QFrame( this );
98 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
99 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
100 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
101 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
102 aBtnLay->addWidget( aCloseBtn );
103 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
105 QVBoxLayout* aLay = new QVBoxLayout( this );
106 aLay->setSpacing( SPACING );
107 aLay->setMargin( MARGIN );
108 aLay->addWidget( aMainGrp );
109 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
110 aLay->addWidget( aFrame );
112 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
113 connect( mySelBtn, SIGNAL( clicked() ),
114 this, SLOT ( onSetEditCurrentArgument() ) );
115 /***************************************************************/
121 //=================================================================================
122 // function : ~RepairGUI_FreeFacesDlg()
123 // purpose : Destroys the object and frees any allocated resources
124 //=================================================================================
125 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
130 //=================================================================================
131 // function : onClose
132 // purpose : SLOT. Called when "close" button pressed. Close dialog
133 //=================================================================================
134 void RepairGUI_FreeFacesDlg::onClose()
137 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
138 myGeomGUI->SetActiveDialogBox( 0 );
143 //=================================================================================
144 // function : onDeactivate
145 // purpose : Deactivate this dialog
146 //=================================================================================
147 void RepairGUI_FreeFacesDlg::onDeactivate()
151 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
152 myGeomGUI->SetActiveDialogBox( 0 );
155 //=================================================================================
156 // function : onActivate
157 // purpose : Activate this dialog
158 //=================================================================================
159 void RepairGUI_FreeFacesDlg::onActivate()
161 myGeomGUI->EmitSignalDeactivateDialog();
163 myGeomGUI->SetActiveDialogBox( this );
164 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
165 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
169 //=================================================================================
172 //=================================================================================
173 void RepairGUI_FreeFacesDlg::Init()
175 myObj = GEOM::GEOM_Object::_nil();
177 /* signals and slots connections */
178 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
179 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
180 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
186 //=================================================================================
187 // function : onSelectionDone
188 // purpose : SLOT. Called when selection changed.
189 //=================================================================================
190 void RepairGUI_FreeFacesDlg::onSelectionDone()
193 if( IObjectCount() != 1 )
195 myEdit->setText( "" );
199 Standard_Boolean isOk = Standard_False;
200 GEOM::GEOM_Object_var anObj =
201 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
203 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
205 myEdit->setText( "" );
211 displayPreview( false, true, true, 3 );
215 //=================================================================================
216 // function : enterEvent()
217 // purpose : Mouse enter onto the dialog to activate it
218 //=================================================================================
219 void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
224 //=================================================================================
225 // function : activateSelection
226 // purpose : activate selection of faces, shells, and solids
227 //=================================================================================
228 void RepairGUI_FreeFacesDlg::activateSelection()
230 TColStd_MapOfInteger aMap;
231 aMap.Add( GEOM_SOLID );
232 aMap.Add( GEOM_COMPOUND );
233 globalSelection( aMap );
236 //=================================================================================
237 // function : closeEvent()
239 //=================================================================================
240 void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
245 //=================================================================================
246 // function : createOperation
248 //=================================================================================
249 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
251 return getGeomEngine()->GetIShapesOperations( getStudyId() );
254 //=================================================================================
255 // function : isValid
257 //=================================================================================
258 bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
260 return !myObj->_is_nil() ;
263 //=================================================================================
264 // function : execute
266 //=================================================================================
267 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
269 bool aResult = false;
270 GEOM::ListOfLong_var aFaceLst =
271 GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
272 TopoDS_Shape aSelShape;
274 TopTools_IndexedMapOfShape anIndices;
275 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
277 myEdit->setText( GEOMBase::GetName( myObj ) );
279 if ( !isValid( aMess ) )
281 erasePreview( true );
285 SUIT_OverrideCursor();
287 TopExp::MapShapes( aSelShape, anIndices);
288 SALOME_Prs* aPrs = 0;
290 for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
292 aFace = anIndices.FindKey( aFaceLst[i] );
295 getDisplayer()->SetColor( Quantity_NOC_RED );
296 getDisplayer()->SetToActivate( false );
297 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
299 displayPreview( aPrs, true );
301 catch( const SALOME::SALOME_Exception& e )
303 SalomeApp_Tools::QtCatchCorbaException( e );
310 //================================================================
311 // Function : getDisplayer
313 //================================================================
314 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
317 myDisplayer = new GEOM_Displayer( getStudy() );
321 //=================================================================================
322 // function : SetEditCurrentArgument
324 //=================================================================================
325 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()