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_FreeFacesDlg.cxx
29 #include "RepairGUI_FreeFacesDlg.h"
31 #include "LightApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_Tools.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_OverrideCursor.h"
40 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "GEOMImpl_Types.hxx"
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <TColStd_MapOfInteger.hxx>
47 #include "GeometryGUI.h"
48 #include "GEOM_Displayer.h"
50 #include <qapplication.h>
51 #include <qlineedit.h>
54 #include <qgroupbox.h>
55 #include <qpushbutton.h>
62 //=================================================================================
63 // class : RepairGUI_FreeFacesDlg()
64 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
65 // name 'name' and widget flags set to 'f'.
66 // The dialog will by default be modeless, unless you set 'modal' to
67 // TRUE to construct a modal dialog.
68 //=================================================================================
69 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg(GeometryGUI* GUI, QWidget* parent,
70 const char* name, bool modal, WFlags fl)
71 :QDialog(parent, "RepairGUI_FreeBoundDlg", false,
72 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
73 GEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(parent)),
78 setSizeGripEnabled( TRUE );
79 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
81 setCaption(tr("GEOM_FREE_FACES_TITLE"));
83 /***************************************************************/
85 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "GEOM_SELECTED_SHAPE" ), this );
88 QGroupBox* aSelGrp = new QGroupBox( 1, Qt::Vertical, aMainGrp );
90 aSelGrp->setInsideMargin( 0 );
91 aSelGrp->setFrameStyle( QFrame::NoFrame );
92 new QLabel( tr( "GEOM_OBJECT" ), aSelGrp );
93 mySelBtn = new QPushButton( aSelGrp );
94 mySelBtn->setPixmap( image1 );
95 myEdit = new QLineEdit( aSelGrp );
96 myEdit->setReadOnly( true );
97 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
98 myEdit->setMinimumWidth( MIN_WIDTH );
100 QFrame* aFrame = new QFrame( this );
101 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
102 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
103 QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
104 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
105 aBtnLay->addWidget( aCloseBtn );
106 aBtnLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
107 aBtnLay->addWidget( aHelpBtn );
109 QVBoxLayout* aLay = new QVBoxLayout( this );
110 aLay->setSpacing( SPACING );
111 aLay->setMargin( MARGIN );
112 aLay->addWidget( aMainGrp );
113 aLay->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
114 aLay->addWidget( aFrame );
116 myHelpFileName = "check_free_faces.htm";
118 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
119 connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
120 connect( mySelBtn, SIGNAL( clicked() ),
121 this, SLOT ( onSetEditCurrentArgument() ) );
122 /***************************************************************/
128 //=================================================================================
129 // function : ~RepairGUI_FreeFacesDlg()
130 // purpose : Destroys the object and frees any allocated resources
131 //=================================================================================
132 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
137 //=================================================================================
138 // function : onClose
139 // purpose : SLOT. Called when "close" button pressed. Close dialog
140 //=================================================================================
141 void RepairGUI_FreeFacesDlg::onClose()
144 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
145 myGeomGUI->SetActiveDialogBox( 0 );
150 //=================================================================================
151 // function : onHelp()
153 //=================================================================================
154 void RepairGUI_FreeFacesDlg::onHelp()
156 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
158 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
160 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
161 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
162 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
163 QObject::tr("BUT_OK"));
167 //=================================================================================
168 // function : onDeactivate
169 // purpose : Deactivate this dialog
170 //=================================================================================
171 void RepairGUI_FreeFacesDlg::onDeactivate()
175 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
176 myGeomGUI->SetActiveDialogBox( 0 );
179 //=================================================================================
180 // function : onActivate
181 // purpose : Activate this dialog
182 //=================================================================================
183 void RepairGUI_FreeFacesDlg::onActivate()
185 myGeomGUI->EmitSignalDeactivateDialog();
187 myGeomGUI->SetActiveDialogBox( this );
188 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
189 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
193 //=================================================================================
196 //=================================================================================
197 void RepairGUI_FreeFacesDlg::Init()
199 myObj = GEOM::GEOM_Object::_nil();
201 /* signals and slots connections */
202 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
203 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
204 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
210 //=================================================================================
211 // function : onSelectionDone
212 // purpose : SLOT. Called when selection changed.
213 //=================================================================================
214 void RepairGUI_FreeFacesDlg::onSelectionDone()
217 if( IObjectCount() != 1 )
219 myEdit->setText( "" );
223 Standard_Boolean isOk = Standard_False;
224 GEOM::GEOM_Object_var anObj =
225 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
227 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
229 myEdit->setText( "" );
235 displayPreview( false, true, true, 3 );
239 //=================================================================================
240 // function : enterEvent()
241 // purpose : Mouse enter onto the dialog to activate it
242 //=================================================================================
243 void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
248 //=================================================================================
249 // function : activateSelection
250 // purpose : activate selection of faces, shells, and solids
251 //=================================================================================
252 void RepairGUI_FreeFacesDlg::activateSelection()
254 TColStd_MapOfInteger aMap;
255 aMap.Add( GEOM_SOLID );
256 aMap.Add( GEOM_COMPOUND );
257 globalSelection( aMap );
260 //=================================================================================
261 // function : closeEvent()
263 //=================================================================================
264 void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
269 //=================================================================================
270 // function : createOperation
272 //=================================================================================
273 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
275 return getGeomEngine()->GetIShapesOperations( getStudyId() );
278 //=================================================================================
279 // function : isValid
281 //=================================================================================
282 bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
284 return !myObj->_is_nil() ;
287 //=================================================================================
288 // function : execute
290 //=================================================================================
291 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
293 bool aResult = false;
294 GEOM::ListOfLong_var aFaceLst =
295 GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
296 TopoDS_Shape aSelShape;
298 TopTools_IndexedMapOfShape anIndices;
299 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
301 myEdit->setText( GEOMBase::GetName( myObj ) );
303 if ( !isValid( aMess ) )
305 erasePreview( true );
309 SUIT_OverrideCursor();
311 TopExp::MapShapes( aSelShape, anIndices);
312 SALOME_Prs* aPrs = 0;
314 for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
316 aFace = anIndices.FindKey( aFaceLst[i] );
319 getDisplayer()->SetColor( Quantity_NOC_RED );
320 getDisplayer()->SetToActivate( false );
321 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
323 displayPreview( aPrs, true );
325 catch( const SALOME::SALOME_Exception& e )
327 SalomeApp_Tools::QtCatchCorbaException( e );
334 //================================================================
335 // Function : getDisplayer
337 //================================================================
338 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
341 myDisplayer = new GEOM_Displayer( getStudy() );
345 //=================================================================================
346 // function : SetEditCurrentArgument
348 //=================================================================================
349 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()
355 //=================================================================================
356 // function : keyPressEvent()
358 //=================================================================================
359 void RepairGUI_FreeFacesDlg::keyPressEvent( QKeyEvent* e )
361 QDialog::keyPressEvent( e );
362 if ( e->isAccepted() )
365 if ( e->key() == Key_F1 )