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"
35 #include "SUIT_Session.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include "GEOMImpl_Types.hxx"
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TColStd_MapOfInteger.hxx>
44 #include "GeometryGUI.h"
45 #include "GEOM_Displayer.h"
47 #include <qapplication.h>
48 #include <qlineedit.h>
51 #include <qgroupbox.h>
52 #include <qpushbutton.h>
58 //=================================================================================
59 // class : RepairGUI_FreeFacesDlg()
60 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
61 // name 'name' and widget flags set to 'f'.
62 // The dialog will by default be modeless, unless you set 'modal' to
63 // TRUE to construct a modal dialog.
64 //=================================================================================
65 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg(GeometryGUI* GUI, QWidget* parent, const char* name, bool modal, WFlags fl)
66 :QDialog( parent, "RepairGUI_FreeBoundDlg", false,
67 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
72 setSizeGripEnabled( TRUE );
73 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
75 setCaption(tr("GEOM_FREE_FACES_TITLE"));
77 /***************************************************************/
79 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
82 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
84 aSelGrp->setInsideMargin( 0 );
85 aSelGrp->setFrameStyle( QFrame::NoFrame );
86 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
87 mySelBtn = new QPushButton( aSelGrp );
88 mySelBtn->setPixmap( image1 );
89 myEdit = new QLineEdit( aSelGrp );
90 myEdit->setReadOnly( true );
91 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
92 myEdit->setMinimumWidth( MIN_WIDTH );
94 QFrame* aFrame = new QFrame( this );
95 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
96 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
97 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
98 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
99 aBtnLay->addWidget( aCloseBtn );
100 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
102 QVBoxLayout* aLay = new QVBoxLayout( this );
103 aLay->setSpacing( SPACING );
104 aLay->setMargin( MARGIN );
105 aLay->addWidget( aMainGrp );
106 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
107 aLay->addWidget( aFrame );
109 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
110 connect( mySelBtn, SIGNAL( clicked() ),
111 this, SLOT ( onSetEditCurrentArgument() ) );
112 /***************************************************************/
118 //=================================================================================
119 // function : ~RepairGUI_FreeFacesDlg()
120 // purpose : Destroys the object and frees any allocated resources
121 //=================================================================================
122 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
127 //=================================================================================
128 // function : onClose
129 // purpose : SLOT. Called when "close" button pressed. Close dialog
130 //=================================================================================
131 void RepairGUI_FreeFacesDlg::onClose()
134 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
135 myGeomGUI->SetActiveDialogBox( 0 );
140 //=================================================================================
141 // function : onDeactivate
142 // purpose : Deactivate this dialog
143 //=================================================================================
144 void RepairGUI_FreeFacesDlg::onDeactivate()
148 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
149 myGeomGUI->SetActiveDialogBox( 0 );
152 //=================================================================================
153 // function : onActivate
154 // purpose : Activate this dialog
155 //=================================================================================
156 void RepairGUI_FreeFacesDlg::onActivate()
158 myGeomGUI->EmitSignalDeactivateDialog();
160 myGeomGUI->SetActiveDialogBox( this );
161 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
162 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
166 //=================================================================================
169 //=================================================================================
170 void RepairGUI_FreeFacesDlg::Init()
172 myObj = GEOM::GEOM_Object::_nil();
174 /* signals and slots connections */
175 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
176 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
177 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
183 //=================================================================================
184 // function : onSelectionDone
185 // purpose : SLOT. Called when selection changed.
186 //=================================================================================
187 void RepairGUI_FreeFacesDlg::onSelectionDone()
190 if( IObjectCount() != 1 )
192 myEdit->setText( "" );
196 Standard_Boolean isOk = Standard_False;
197 GEOM::GEOM_Object_var anObj =
198 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
200 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
202 myEdit->setText( "" );
208 displayPreview( false, true, true, 3 );
212 //=================================================================================
213 // function : enterEvent()
214 // purpose : Mouse enter onto the dialog to activate it
215 //=================================================================================
216 void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
221 //=================================================================================
222 // function : activateSelection
223 // purpose : activate selection of faces, shells, and solids
224 //=================================================================================
225 void RepairGUI_FreeFacesDlg::activateSelection()
227 TColStd_MapOfInteger aMap;
228 aMap.Add( GEOM_SOLID );
229 aMap.Add( GEOM_COMPOUND );
230 globalSelection( aMap );
233 //=================================================================================
234 // function : closeEvent()
236 //=================================================================================
237 void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
242 //=================================================================================
243 // function : createOperation
245 //=================================================================================
246 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
248 return getGeomEngine()->GetIShapesOperations( getStudyId() );
251 //=================================================================================
252 // function : isValid
254 //=================================================================================
255 bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
257 return !myObj->_is_nil() ;
260 //=================================================================================
261 // function : execute
263 //=================================================================================
264 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
266 bool aResult = false;
267 GEOM::ListOfLong_var aFaceLst =
268 GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
269 TopoDS_Shape aSelShape;
271 TopTools_IndexedMapOfShape anIndices;
272 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
274 myEdit->setText( GEOMBase::GetName( myObj ) );
276 if ( !isValid( aMess ) )
278 erasePreview( true );
282 TopExp::MapShapes( aSelShape, anIndices);
283 SALOME_Prs* aPrs = 0;
284 QApplication::setOverrideCursor( Qt::waitCursor );
286 for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
288 aFace = anIndices.FindKey( aFaceLst[i] );
291 getDisplayer()->SetColor( Quantity_NOC_RED );
292 getDisplayer()->SetToActivate( false );
293 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
295 displayPreview( aPrs, true );
297 catch( const SALOME::SALOME_Exception& e )
299 SalomeApp_Tools::QtCatchCorbaException( e );
306 //================================================================
307 // Function : getDisplayer
309 //================================================================
310 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
313 myDisplayer = new GEOM_Displayer( getStudy() );
317 //=================================================================================
318 // function : SetEditCurrentArgument
320 //=================================================================================
321 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()
327 //=================================================================================
328 // function : getDesktop()
330 //=================================================================================
331 SUIT_Desktop* RepairGUI_FreeFacesDlg::getDesktop() const
333 return dynamic_cast<SUIT_Desktop*>( parentWidget() );