1 // Copyright (C) 2007-2016 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 : 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()
250 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
251 SALOME_ListIO aSelList;
252 aSelMgr->selectedObjects(aSelList);
254 if (aSelList.Extent() > 0) {
255 myObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
259 mySelEdit->setText("");
265 mySelEdit->setText(GEOMBase::GetName(myObj.get()));
270 //=================================================================================
271 // function : processObject
273 //=================================================================================
274 void MeasureGUI_Skeleton::processObject()
279 //=================================================================================
280 // function : closeEvent
282 //=================================================================================
283 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
285 LightApp_SelectionMgr* aSel = ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr();
287 disconnect( aSel, 0, this, 0 );
288 QDialog::closeEvent( e );
291 //=================================================================================
292 // function : enterEvent()
294 //=================================================================================
295 void MeasureGUI_Skeleton::enterEvent( QEvent* )
297 if ( mainFrame()->GroupConstructors->isEnabled() )
300 ActivateThisDialog();
303 //=================================================================================
304 // function : buildPrs
305 // purpose : Build presentation for "preview"
306 //=================================================================================
307 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
312 //=================================================================================
313 // function : closeEvent()
314 // purpose : Build presentation for "preview"
315 //=================================================================================
316 void MeasureGUI_Skeleton::redisplayPreview()
319 if ( !isValid( aMess ) ) {
320 erasePreview( true );
324 erasePreview( false );
327 SUIT_OverrideCursor wc;
329 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
330 getDisplayer()->SetToActivate( false );
332 if ( SALOME_Prs* aPrs = buildPrs() )
333 displayPreview( aPrs );
335 catch ( const SALOME::SALOME_Exception& e ) {
336 SalomeApp_Tools::QtCatchCorbaException( e );
341 //=================================================================================
342 // function : activateSelection
344 //=================================================================================
345 void MeasureGUI_Skeleton::activateSelection()
347 globalSelection( GEOM_ALLSHAPES );
350 //=================================================================================
351 // function : isValid
353 //=================================================================================
354 bool MeasureGUI_Skeleton::isValid( QString& )
359 //================================================================
360 // Function : getDisplayer
362 //================================================================
363 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
366 myDisplayer = new GEOM_Displayer( getStudy() );
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
376 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
379 //=================================================================================
380 // function : keyPressEvent()
382 //=================================================================================
383 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
385 QDialog::keyPressEvent( e );
386 if ( e->isAccepted() )
389 if ( e->key() == Qt::Key_F1 ) {
395 MeasureGUI_SkeletonBox* MeasureGUI_Skeleton::mainFrame() const
400 QWidget* MeasureGUI_Skeleton::centralWidget() const
402 return mainFrame()->GroupMedium;
405 QPushButton* MeasureGUI_Skeleton::buttonClose() const
407 return mainFrame()->buttonClose;
410 QPushButton* MeasureGUI_Skeleton::buttonHelp() const
412 return mainFrame()->buttonHelp;