1 // Copyright (C) 2007-2012 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.
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 : MeasureGUI_Skeleton.cxx
25 // Author : Damine COQUERET, Open CASCADE S.A.S.
27 #include "MeasureGUI_Skeleton.h"
28 #include "MeasureGUI_Widgets.h"
31 #include <GEOM_Displayer.h>
32 #include <GeometryGUI.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_Tools.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_OverrideCursor.h>
45 //=================================================================================
46 // class : MeasureGUI_Skeleton()
47 // purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI, QWidget* parent,
53 bool modal, Qt::WindowFlags f )
54 : QDialog( parent, f ),
55 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
58 myMainFrame = new MeasureGUI_SkeletonBox( this );
59 QVBoxLayout* topLayout = new QVBoxLayout( this );
60 topLayout->setMargin( 9 ); topLayout->setSpacing( 0 );
61 topLayout->addWidget( myMainFrame );
63 setAttribute( Qt::WA_DeleteOnClose );
70 buttonClose()->setText( tr( "GEOM_BUT_CLOSE" ) );
71 buttonHelp()->setText( tr( "GEOM_BUT_HELP" ) );
75 //=================================================================================
76 // function : ~MeasureGUI_Skeleton()
77 // purpose : Destroys the object and frees any allocated resources
78 //=================================================================================
79 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
82 myGeomGUI->SetActiveDialogBox( 0 );
87 //=================================================================================
90 //=================================================================================
91 void MeasureGUI_Skeleton::Init()
95 myGeomGUI->SetActiveDialogBox( (QDialog*)this );
97 /* signals and slots connections */
99 connect( buttonClose(), SIGNAL( clicked() ),
100 this, SLOT( ClickOnCancel() ) );
102 connect( buttonHelp(), SIGNAL( clicked() ),
103 this, SLOT( ClickOnHelp() ) );
106 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
107 this, SLOT ( DeactivateActiveDialog() ) );
109 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
110 this, SLOT ( ClickOnCancel() ) );
114 connect( mySelEdit, SIGNAL( returnPressed() ),
115 this, SLOT( LineEditReturnPressed() ) );
119 connect( mySelBtn, SIGNAL( clicked() ),
120 this, SLOT ( SetEditCurrentArgument() ) );
123 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
125 connect( aSel, SIGNAL( currentSelectionChanged() ),
126 this, SLOT ( SelectionIntoArgument() ) ) ;
129 /* displays Dialog */
130 mainFrame()->RadioButton1->setChecked( true );
133 SelectionIntoArgument();
137 //=================================================================================
138 // function : ClickOnCancel()
140 //=================================================================================
141 void MeasureGUI_Skeleton::ClickOnCancel()
146 //=================================================================================
147 // function : ClickOnHelp()
149 //=================================================================================
150 void MeasureGUI_Skeleton::ClickOnHelp()
152 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
154 app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString( "" ), myHelpFileName );
159 platform = "winapplication";
161 platform = "application";
163 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
164 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
165 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ) );
169 //=================================================================================
170 // function : LineEditReturnPressed()
172 //=================================================================================
173 void MeasureGUI_Skeleton::LineEditReturnPressed()
175 /* User name of object input management */
176 /* If successfull the selection is changed and signal emitted... */
177 /* so SelectionIntoArgument() is automatically called. */
180 const QString objectUserName = mySelEdit->text();
181 QWidget* thisWidget = ( QWidget* )this;
183 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
184 SALOME_ListIO aSelList;
185 aSelMgr->selectedObjects(aSelList);
187 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
188 mySelEdit->setText(objectUserName);
193 //=================================================================================
194 // function : DeactivateActiveDialog()
196 //=================================================================================
197 void MeasureGUI_Skeleton::DeactivateActiveDialog()
201 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
203 disconnect( aSel, 0, this, 0 );
205 myGeomGUI->SetActiveDialogBox( 0 );
211 //=================================================================================
212 // function : ActivateThisDialog()
214 //=================================================================================
215 void MeasureGUI_Skeleton::ActivateThisDialog()
217 myGeomGUI->EmitSignalDeactivateDialog();
221 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
223 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
225 connect( aSel, SIGNAL( currentSelectionChanged() ),
226 this, SLOT ( SelectionIntoArgument() ) ) ;
232 //=================================================================================
233 // function : SetEditCurrentArgument
235 //=================================================================================
236 void MeasureGUI_Skeleton::SetEditCurrentArgument()
238 mySelEdit->setFocus();
239 SelectionIntoArgument();
242 //=================================================================================
243 // function : SelectionIntoArgument
245 //=================================================================================
246 void MeasureGUI_Skeleton::SelectionIntoArgument()
248 myObj = GEOM::GEOM_Object::_nil();
250 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
251 SALOME_ListIO aSelList;
252 aSelMgr->selectedObjects(aSelList);
254 GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
256 if (aSelList.Extent() > 0) {
257 aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
260 if (aSelectedObject->_is_nil()) {
261 mySelEdit->setText("");
267 myObj = aSelectedObject;
268 mySelEdit->setText(GEOMBase::GetName(myObj));
273 //=================================================================================
274 // function : processObject
276 //=================================================================================
277 void MeasureGUI_Skeleton::processObject()
282 //=================================================================================
283 // function : closeEvent
285 //=================================================================================
286 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
288 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
290 disconnect( aSel, 0, this, 0 );
291 QDialog::closeEvent( e );
294 //=================================================================================
295 // function : enterEvent()
297 //=================================================================================
298 void MeasureGUI_Skeleton::enterEvent( QEvent* )
300 if ( mainFrame()->GroupConstructors->isEnabled() )
303 ActivateThisDialog();
306 //=================================================================================
307 // function : buildPrs
308 // purpose : Build presentation for "preview"
309 //=================================================================================
310 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
315 //=================================================================================
316 // function : closeEvent()
317 // purpose : Build presentation for "preview"
318 //=================================================================================
319 void MeasureGUI_Skeleton::redisplayPreview()
322 if ( !isValid( aMess ) ) {
323 erasePreview( true );
327 erasePreview( false );
330 SUIT_OverrideCursor();
332 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
333 getDisplayer()->SetToActivate( false );
335 if ( SALOME_Prs* aPrs = buildPrs() )
336 displayPreview( aPrs );
338 catch ( const SALOME::SALOME_Exception& e ) {
339 SalomeApp_Tools::QtCatchCorbaException( e );
344 //=================================================================================
345 // function : activateSelection
347 //=================================================================================
348 void MeasureGUI_Skeleton::activateSelection()
350 globalSelection( GEOM_ALLSHAPES );
353 //=================================================================================
354 // function : isValid
356 //=================================================================================
357 bool MeasureGUI_Skeleton::isValid( QString& )
359 return !myObj->_is_nil();
362 //================================================================
363 // Function : getDisplayer
365 //================================================================
366 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
369 myDisplayer = new GEOM_Displayer( getStudy() );
373 //=================================================================================
374 // function : createOperation
376 //=================================================================================
377 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
379 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
382 //=================================================================================
383 // function : keyPressEvent()
385 //=================================================================================
386 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
388 QDialog::keyPressEvent( e );
389 if ( e->isAccepted() )
392 if ( e->key() == Qt::Key_F1 ) {
398 MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
403 QWidget* MeasureGUI_Skeleton::centralWidget() const
405 return mainFrame()->GroupMedium;
408 QPushButton* MeasureGUI_Skeleton::buttonClose() const
410 return mainFrame()->buttonClose;
413 QPushButton* MeasureGUI_Skeleton::buttonHelp() const
415 return mainFrame()->buttonHelp;