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
22 // File : MeasureGUI_Skeleton.cxx
23 // Author : Damine COQUERET, Open CASCADE S.A.S.
26 #include "MeasureGUI_Skeleton.h"
27 #include "MeasureGUI_Widgets.h"
30 #include <GEOM_Displayer.h>
31 #include <GeometryGUI.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Tools.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_OverrideCursor.h>
44 //=================================================================================
45 // class : MeasureGUI_Skeleton()
46 // purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI, QWidget* parent,
52 bool modal, Qt::WindowFlags f )
53 : QDialog( parent, f ),
54 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
57 myMainFrame = new MeasureGUI_SkeletonBox( this );
58 QVBoxLayout* topLayout = new QVBoxLayout( this );
59 topLayout->setMargin( 9 ); topLayout->setSpacing( 0 );
60 topLayout->addWidget( myMainFrame );
62 setAttribute( Qt::WA_DeleteOnClose );
69 buttonClose()->setText( tr( "GEOM_BUT_CLOSE" ) );
70 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
74 //=================================================================================
75 // function : ~MeasureGUI_Skeleton()
76 // purpose : Destroys the object and frees any allocated resources
77 //=================================================================================
78 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
81 myGeomGUI->SetActiveDialogBox( 0 );
86 //=================================================================================
89 //=================================================================================
90 void MeasureGUI_Skeleton::Init()
94 myGeomGUI->SetActiveDialogBox( (QDialog*)this );
96 /* signals and slots connections */
98 connect( buttonClose(), SIGNAL( clicked() ),
99 this, SLOT( ClickOnCancel() ) );
101 connect( buttonHelp(), SIGNAL( clicked() ),
102 this, SLOT( ClickOnHelp() ) );
105 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
106 this, SLOT ( DeactivateActiveDialog() ) );
108 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
109 this, SLOT ( ClickOnCancel() ) );
113 connect( mySelEdit, SIGNAL( returnPressed() ),
114 this, SLOT( LineEditReturnPressed() ) );
118 connect( mySelBtn, SIGNAL( clicked() ),
119 this, SLOT ( SetEditCurrentArgument() ) );
122 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
124 connect( aSel, SIGNAL( currentSelectionChanged() ),
125 this, SLOT ( SelectionIntoArgument() ) ) ;
128 /* displays Dialog */
129 mainFrame()->RadioButton1->setChecked( true );
132 SelectionIntoArgument();
136 //=================================================================================
137 // function : ClickOnCancel()
139 //=================================================================================
140 void MeasureGUI_Skeleton::ClickOnCancel()
145 //=================================================================================
146 // function : ClickOnHelp()
148 //=================================================================================
149 void MeasureGUI_Skeleton::ClickOnHelp()
151 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
153 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString( "" ), myHelpFileName );
158 platform = "winapplication";
160 platform = "application";
162 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
163 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
164 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ) );
168 //=================================================================================
169 // function : LineEditReturnPressed()
171 //=================================================================================
172 void MeasureGUI_Skeleton::LineEditReturnPressed()
174 /* User name of object input management */
175 /* If successfull the selection is changed and signal emitted... */
176 /* so SelectionIntoArgument() is automatically called. */
179 const QString objectUserName = mySelEdit->text();
180 QWidget* thisWidget = ( QWidget* )this;
182 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
183 mySelEdit->setText( objectUserName );
188 //=================================================================================
189 // function : DeactivateActiveDialog()
191 //=================================================================================
192 void MeasureGUI_Skeleton::DeactivateActiveDialog()
196 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
198 disconnect( aSel, 0, this, 0 );
200 myGeomGUI->SetActiveDialogBox( 0 );
206 //=================================================================================
207 // function : ActivateThisDialog()
209 //=================================================================================
210 void MeasureGUI_Skeleton::ActivateThisDialog()
212 myGeomGUI->EmitSignalDeactivateDialog();
216 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
218 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
220 connect( aSel, SIGNAL( currentSelectionChanged() ),
221 this, SLOT ( SelectionIntoArgument() ) ) ;
227 //=================================================================================
228 // function : SetEditCurrentArgument
230 //=================================================================================
231 void MeasureGUI_Skeleton::SetEditCurrentArgument()
233 mySelEdit->setFocus();
234 SelectionIntoArgument();
237 //=================================================================================
238 // function : SelectionIntoArgument
240 //=================================================================================
241 void MeasureGUI_Skeleton::SelectionIntoArgument()
243 myObj = GEOM::GEOM_Object::_nil();
245 Standard_Boolean testResult = Standard_False;
246 GEOM::GEOM_Object_var aSelectedObject =
247 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
249 if ( !testResult || aSelectedObject->_is_nil() ) {
250 mySelEdit->setText( "" );
256 myObj = aSelectedObject;
257 mySelEdit->setText( GEOMBase::GetName( myObj ) );
262 //=================================================================================
263 // function : processObject
265 //=================================================================================
266 void MeasureGUI_Skeleton::processObject()
271 //=================================================================================
272 // function : closeEvent
274 //=================================================================================
275 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
277 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
279 disconnect( aSel, 0, this, 0 );
280 QDialog::closeEvent( e );
283 //=================================================================================
284 // function : enterEvent()
286 //=================================================================================
287 void MeasureGUI_Skeleton::enterEvent( QEvent* )
289 if ( mainFrame()->GroupConstructors->isEnabled() )
292 ActivateThisDialog();
295 //=================================================================================
296 // function : buildPrs
297 // purpose : Build presentation for "preview"
298 //=================================================================================
299 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
304 //=================================================================================
305 // function : closeEvent()
306 // purpose : Build presentation for "preview"
307 //=================================================================================
308 void MeasureGUI_Skeleton::redisplayPreview()
311 if ( !isValid( aMess ) ) {
312 erasePreview( true );
316 erasePreview( false );
319 SUIT_OverrideCursor();
321 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
322 getDisplayer()->SetToActivate( false );
324 if ( SALOME_Prs* aPrs = buildPrs() )
325 displayPreview( aPrs );
327 catch ( const SALOME::SALOME_Exception& e ) {
328 SalomeApp_Tools::QtCatchCorbaException( e );
333 //=================================================================================
334 // function : activateSelection
336 //=================================================================================
337 void MeasureGUI_Skeleton::activateSelection()
339 globalSelection( GEOM_ALLSHAPES );
342 //=================================================================================
343 // function : isValid
345 //=================================================================================
346 bool MeasureGUI_Skeleton::isValid( QString& )
348 return !myObj->_is_nil();
351 //================================================================
352 // Function : getDisplayer
354 //================================================================
355 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
358 myDisplayer = new GEOM_Displayer( getStudy() );
362 //=================================================================================
363 // function : createOperation
365 //=================================================================================
366 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
368 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
371 //=================================================================================
372 // function : keyPressEvent()
374 //=================================================================================
375 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
377 QDialog::keyPressEvent( e );
378 if ( e->isAccepted() )
381 if ( e->key() == Qt::Key_F1 ) {
387 MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
392 QWidget* MeasureGUI_Skeleton::centralWidget() const
394 return mainFrame()->GroupMedium;
397 QPushButton* MeasureGUI_Skeleton::buttonClose() const
399 return mainFrame()->buttonClose;
402 QPushButton* MeasureGUI_Skeleton::buttonHelp() const
404 return mainFrame()->buttonHelp;