1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_FreeFacesDlg.cxx
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
27 #include "RepairGUI_FreeFacesDlg.h"
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Tools.h>
33 #include <SalomeApp_Study.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_ViewWindow.h>
41 #include <SUIT_ViewManager.h>
43 #include <GEOMImpl_Types.hxx>
44 #include <GEOM_Constants.h>
46 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <TColStd_MapOfInteger.hxx>
51 #include <GeometryGUI.h>
52 #include <GEOM_Displayer.h>
57 #include <QPushButton>
58 #include <QHBoxLayout>
59 #include <QVBoxLayout>
66 //=================================================================================
67 // class : RepairGUI_FreeFacesDlg()
68 // purpose : Constructs a RepairGUI_FreeFacesDlg which is a child of 'parent', with the
69 // name 'name' and widget flags set to 'f'.
70 // The dialog will by default be modeless, unless you set 'modal' to
71 // TRUE to construct a modal dialog.
72 //=================================================================================
73 RepairGUI_FreeFacesDlg::RepairGUI_FreeFacesDlg( GeometryGUI* GUI, QWidget* parent,
75 : QDialog( parent, 0 ),
76 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
80 setAttribute( Qt::WA_DeleteOnClose );
82 setSizeGripEnabled( true );
84 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
86 setWindowTitle( tr( "GEOM_FREE_FACES_TITLE" ) );
88 /***************************************************************/
90 QGroupBox* aMainGrp = new QGroupBox( tr( "GEOM_SELECTED_SHAPE" ), this );
92 QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
93 mySelBtn = new QPushButton( aMainGrp );
94 mySelBtn->setIcon( image1 );
95 myEdit = new QLineEdit( aMainGrp );
96 myEdit->setReadOnly( true );
97 myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
98 myEdit->setMinimumWidth( MIN_WIDTH );
100 QHBoxLayout* aMainLay = new QHBoxLayout( aMainGrp );
101 aMainLay->setSpacing( SPACING );
102 aMainLay->setMargin( MARGIN );
103 aMainLay->addWidget( lab );
104 aMainLay->addWidget( mySelBtn );
105 aMainLay->addWidget( myEdit );
107 QFrame* aFrame = new QFrame( this );
108 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
109 QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
110 QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
112 QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame );
113 aBtnLay->setSpacing( SPACING );
114 aBtnLay->setMargin( MARGIN );
115 aBtnLay->addWidget( aCloseBtn );
116 aBtnLay->addSpacing( SPACING );
117 aBtnLay->addStretch();
118 aBtnLay->addWidget( aHelpBtn );
120 QVBoxLayout* aLay = new QVBoxLayout( this );
121 aLay->setSpacing( SPACING );
122 aLay->setMargin( MARGIN );
123 aLay->addWidget( aMainGrp );
125 aLay->addWidget( aFrame );
127 myHelpFileName = "free_faces_page.html";
129 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
130 connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
131 connect( mySelBtn, SIGNAL( clicked() ),
132 this, SLOT ( onSetEditCurrentArgument() ) );
133 /***************************************************************/
139 //=================================================================================
140 // function : ~RepairGUI_FreeFacesDlg()
141 // purpose : Destroys the object and frees any allocated resources
142 //=================================================================================
143 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
148 //=================================================================================
149 // function : onClose
150 // purpose : SLOT. Called when "close" button pressed. Close dialog
151 //=================================================================================
152 void RepairGUI_FreeFacesDlg::onClose()
155 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
156 myGeomGUI->SetActiveDialogBox( 0 );
161 //=================================================================================
162 // function : onHelp()
164 //=================================================================================
165 void RepairGUI_FreeFacesDlg::onHelp()
167 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
169 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
173 platform = "winapplication";
175 platform = "application";
177 SUIT_MessageBox::warning( this,
179 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
180 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
182 arg( myHelpFileName ) );
186 //=================================================================================
187 // function : onDeactivate
188 // purpose : Deactivate this dialog
189 //=================================================================================
190 void RepairGUI_FreeFacesDlg::onDeactivate()
194 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
195 myGeomGUI->SetActiveDialogBox( 0 );
198 //=================================================================================
199 // function : onActivate
200 // purpose : Activate this dialog
201 //=================================================================================
202 void RepairGUI_FreeFacesDlg::onActivate()
204 myGeomGUI->EmitSignalDeactivateDialog();
206 myGeomGUI->SetActiveDialogBox( this );
207 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
208 SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
212 //=================================================================================
215 //=================================================================================
216 void RepairGUI_FreeFacesDlg::Init()
218 myObj = GEOM::GEOM_Object::_nil();
220 /* signals and slots connections */
221 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
222 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
223 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
229 //=================================================================================
230 // function : onSelectionDone
231 // purpose : SLOT. Called when selection changed.
232 //=================================================================================
233 void RepairGUI_FreeFacesDlg::onSelectionDone()
237 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
238 SALOME_ListIO aSelList;
239 aSelMgr->selectedObjects(aSelList);
241 if ( aSelList.Extent() != 1 ) {
242 myEdit->setText( "" );
246 GEOM::GEOM_Object_var anObj =
247 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
249 if ( !GEOMBase::IsShape( anObj ) ) {
250 myEdit->setText( "" );
255 displayPreview( true, false, true, true, 3 );
259 //=================================================================================
260 // function : enterEvent()
261 // purpose : Mouse enter onto the dialog to activate it
262 //=================================================================================
263 void RepairGUI_FreeFacesDlg::enterEvent( QEvent* )
268 //=================================================================================
269 // function : activateSelection
270 // purpose : activate selection of faces, shells, and solids
271 //=================================================================================
272 void RepairGUI_FreeFacesDlg::activateSelection()
274 TColStd_MapOfInteger aMap;
275 aMap.Add( GEOM_SOLID );
276 aMap.Add( GEOM_COMPOUND );
277 globalSelection( aMap );
280 //=================================================================================
281 // function : closeEvent()
283 //=================================================================================
284 void RepairGUI_FreeFacesDlg::closeEvent( QCloseEvent* )
289 //=================================================================================
290 // function : createOperation
292 //=================================================================================
293 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
295 return getGeomEngine()->GetIShapesOperations( getStudyId() );
298 //=================================================================================
299 // function : isValid
301 //=================================================================================
302 bool RepairGUI_FreeFacesDlg::isValid( QString& )
304 return !myObj->_is_nil() ;
307 //=================================================================================
308 // function : execute
310 //=================================================================================
311 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
313 bool aResult = false;
314 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
315 GEOM::ListOfLong_var aFaceLst = anOper->GetFreeFacesIDs( myObj );
316 TopoDS_Shape aSelShape;
318 TopTools_IndexedMapOfShape anIndices;
319 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
320 myEdit->setText( GEOMBase::GetName( myObj ) );
322 if ( !isValid( aMess ) ) {
323 erasePreview( true );
327 SUIT_OverrideCursor();
329 TopExp::MapShapes( aSelShape, anIndices);
330 SALOME_Prs* aPrs = 0;
332 //Get object trancparency and set it to preview
333 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
334 double transparency = 1.0;
336 SUIT_ViewWindow* window = app->desktop( )->activeWindow( );
337 if( window && window->getViewManager() ) {
339 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
341 int aMgrId = window->getViewManager()->getGlobalId();
342 CORBA::String_var aMainEntry = myObj->GetStudyEntry();
343 QString anEntry = aMainEntry.in();
344 QVariant v = aStudy->getObjectProperty( aMgrId , anEntry , GEOM::propertyName( GEOM::Transparency ) , transparency );
345 if( v.canConvert( QVariant::Double ) ) {
346 transparency = v.toDouble();
353 for ( int i = 0, n = aFaceLst->length(); i < n; i++ ) {
354 aFace = anIndices.FindKey( aFaceLst[i] );
356 getDisplayer()->SetColor( Quantity_NOC_RED );
357 getDisplayer()->SetTransparency( transparency );
358 getDisplayer()->SetWidth( 2 );
359 getDisplayer()->SetNbIsos( 1 );
360 getDisplayer()->SetIsosWidth( 1 );
361 getDisplayer()->SetIsosColor( Quantity_NOC_RED );
362 getDisplayer()->SetDisplayMode( 0 );
363 getDisplayer()->SetToActivate( false );
364 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
366 displayPreview( aPrs, true );
368 catch( const SALOME::SALOME_Exception& e )
370 SalomeApp_Tools::QtCatchCorbaException( e );
377 //================================================================
378 // Function : getDisplayer
380 //================================================================
381 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
384 myDisplayer = new GEOM_Displayer( getStudy() );
388 //=================================================================================
389 // function : SetEditCurrentArgument
391 //=================================================================================
392 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()
398 //=================================================================================
399 // function : keyPressEvent()
401 //=================================================================================
402 void RepairGUI_FreeFacesDlg::keyPressEvent( QKeyEvent* e )
404 QDialog::keyPressEvent( e );
405 if ( e->isAccepted() )
408 if ( e->key() == Qt::Key_F1 ) {