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 = "files/salome2_sp3_measuregui_functions.htm#free_faces";
117 myHelpFileName = "using_measurement_tools_page.html#faces_anchor";
119 connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
120 connect( aHelpBtn, SIGNAL( clicked() ), SLOT( onHelp() ) );
121 connect( mySelBtn, SIGNAL( clicked() ),
122 this, SLOT ( onSetEditCurrentArgument() ) );
123 /***************************************************************/
129 //=================================================================================
130 // function : ~RepairGUI_FreeFacesDlg()
131 // purpose : Destroys the object and frees any allocated resources
132 //=================================================================================
133 RepairGUI_FreeFacesDlg::~RepairGUI_FreeFacesDlg()
138 //=================================================================================
139 // function : onClose
140 // purpose : SLOT. Called when "close" button pressed. Close dialog
141 //=================================================================================
142 void RepairGUI_FreeFacesDlg::onClose()
145 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
146 myGeomGUI->SetActiveDialogBox( 0 );
151 //=================================================================================
152 // function : onHelp()
154 //=================================================================================
155 void RepairGUI_FreeFacesDlg::onHelp()
157 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
159 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
163 platform = "winapplication";
165 platform = "application";
167 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
168 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
169 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
170 QObject::tr("BUT_OK"));
174 //=================================================================================
175 // function : onDeactivate
176 // purpose : Deactivate this dialog
177 //=================================================================================
178 void RepairGUI_FreeFacesDlg::onDeactivate()
182 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
183 myGeomGUI->SetActiveDialogBox( 0 );
186 //=================================================================================
187 // function : onActivate
188 // purpose : Activate this dialog
189 //=================================================================================
190 void RepairGUI_FreeFacesDlg::onActivate()
192 myGeomGUI->EmitSignalDeactivateDialog();
194 myGeomGUI->SetActiveDialogBox( this );
195 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
196 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
200 //=================================================================================
203 //=================================================================================
204 void RepairGUI_FreeFacesDlg::Init()
206 myObj = GEOM::GEOM_Object::_nil();
208 /* signals and slots connections */
209 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT ( onDeactivate() ) );
210 connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
211 SIGNAL( currentSelectionChanged() ), SLOT ( onSelectionDone() ) );
217 //=================================================================================
218 // function : onSelectionDone
219 // purpose : SLOT. Called when selection changed.
220 //=================================================================================
221 void RepairGUI_FreeFacesDlg::onSelectionDone()
224 if( IObjectCount() != 1 )
226 myEdit->setText( "" );
230 Standard_Boolean isOk = Standard_False;
231 GEOM::GEOM_Object_var anObj =
232 GEOMBase::ConvertIOinGEOMObject( firstIObject(), isOk );
234 if ( !isOk || anObj->_is_nil() || !GEOMBase::IsShape( anObj ) )
236 myEdit->setText( "" );
242 displayPreview( false, true, true, 3 );
246 //=================================================================================
247 // function : enterEvent()
248 // purpose : Mouse enter onto the dialog to activate it
249 //=================================================================================
250 void RepairGUI_FreeFacesDlg::enterEvent(QEvent* e)
255 //=================================================================================
256 // function : activateSelection
257 // purpose : activate selection of faces, shells, and solids
258 //=================================================================================
259 void RepairGUI_FreeFacesDlg::activateSelection()
261 TColStd_MapOfInteger aMap;
262 aMap.Add( GEOM_SOLID );
263 aMap.Add( GEOM_COMPOUND );
264 globalSelection( aMap );
267 //=================================================================================
268 // function : closeEvent()
270 //=================================================================================
271 void RepairGUI_FreeFacesDlg::closeEvent(QCloseEvent* e)
276 //=================================================================================
277 // function : createOperation
279 //=================================================================================
280 GEOM::GEOM_IOperations_ptr RepairGUI_FreeFacesDlg::createOperation()
282 return getGeomEngine()->GetIShapesOperations( getStudyId() );
285 //=================================================================================
286 // function : isValid
288 //=================================================================================
289 bool RepairGUI_FreeFacesDlg::isValid( QString& msg )
291 return !myObj->_is_nil() ;
294 //=================================================================================
295 // function : execute
297 //=================================================================================
298 bool RepairGUI_FreeFacesDlg::execute( ObjectList& objects )
300 bool aResult = false;
301 GEOM::ListOfLong_var aFaceLst =
302 GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->GetFreeFacesIDs( myObj );
303 TopoDS_Shape aSelShape;
305 TopTools_IndexedMapOfShape anIndices;
306 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) )
308 myEdit->setText( GEOMBase::GetName( myObj ) );
310 if ( !isValid( aMess ) )
312 erasePreview( true );
316 SUIT_OverrideCursor();
318 TopExp::MapShapes( aSelShape, anIndices);
319 SALOME_Prs* aPrs = 0;
321 for ( int i = 0, n = aFaceLst->length(); i < n; i++ )
323 aFace = anIndices.FindKey( aFaceLst[i] );
326 getDisplayer()->SetColor( Quantity_NOC_RED );
327 getDisplayer()->SetToActivate( false );
328 aPrs = !aFace.IsNull() ? getDisplayer()->BuildPrs( aFace ) : 0;
330 displayPreview( aPrs, true );
332 catch( const SALOME::SALOME_Exception& e )
334 SalomeApp_Tools::QtCatchCorbaException( e );
341 //================================================================
342 // Function : getDisplayer
344 //================================================================
345 GEOM_Displayer* RepairGUI_FreeFacesDlg::getDisplayer()
348 myDisplayer = new GEOM_Displayer( getStudy() );
352 //=================================================================================
353 // function : SetEditCurrentArgument
355 //=================================================================================
356 void RepairGUI_FreeFacesDlg::onSetEditCurrentArgument()
362 //=================================================================================
363 // function : keyPressEvent()
365 //=================================================================================
366 void RepairGUI_FreeFacesDlg::keyPressEvent( QKeyEvent* e )
368 QDialog::keyPressEvent( e );
369 if ( e->isAccepted() )
372 if ( e->key() == Key_F1 )