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 : MeasureGUI_Skeleton.cxx
25 // Author : Damien COQUERET
29 #include "MeasureGUI_Skeleton.h"
31 #include "GEOM_Displayer.h"
32 #include "GeometryGUI.h"
34 #include "LightApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "SalomeApp_Application.h"
37 #include "SalomeApp_Tools.h"
38 #include "SUIT_MessageBox.h"
39 #include "SUIT_Session.h"
40 #include "SUIT_OverrideCursor.h"
42 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
46 #include <qbuttongroup.h>
47 #include <qapplication.h>
49 //=================================================================================
50 // class : MeasureGUI_Skeleton()
51 // purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI,
59 : MeasureGUI_Skeleton_QTD( parent, name, false,
60 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
61 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
71 setName( "MeasureGUI_Skeleton" );
73 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
74 buttonHelp->setText(tr("GEOM_BUT_HELP"));
76 buttonClose->setAutoDefault( false );
78 GroupMedium->close( TRUE );
83 //=================================================================================
84 // function : ~MeasureGUI_Skeleton()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
89 myGeomGUI->SetActiveDialogBox( 0 );
94 //=================================================================================
97 //=================================================================================
98 void MeasureGUI_Skeleton::Init()
101 myGeomGUI->SetActiveDialogBox((QDialog*)this);
103 /* signals and slots connections */
105 connect( buttonClose, SIGNAL( clicked() ),
106 this, SLOT( ClickOnCancel() ) );
108 connect( buttonHelp, SIGNAL( clicked() ),
109 this, SLOT( ClickOnHelp() ) );
111 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
112 this, SLOT ( DeactivateActiveDialog() ) );
114 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
115 this, SLOT ( ClickOnCancel() ) );
117 connect( mySelEdit, SIGNAL( returnPressed() ),
118 this, SLOT( LineEditReturnPressed() ) );
120 connect( mySelBtn, SIGNAL( clicked() ),
121 this, SLOT ( SetEditCurrentArgument() ) );
123 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
125 connect( aSel, SIGNAL( currentSelectionChanged() ),
126 this, SLOT ( SelectionIntoArgument() ) ) ;
128 /* displays Dialog */
129 RadioButton1->setChecked( TRUE );
132 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);
158 platform = "winapplication";
160 platform = "application";
162 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
163 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
164 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
165 QObject::tr("BUT_OK"));
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. */
179 const QString objectUserName = mySelEdit->text();
180 QWidget* thisWidget = ( QWidget* )this;
182 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
183 mySelEdit->setText( objectUserName );
187 //=================================================================================
188 // function : DeactivateActiveDialog()
190 //=================================================================================
191 void MeasureGUI_Skeleton::DeactivateActiveDialog()
195 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
197 disconnect( aSel, 0, this, 0 );
199 myGeomGUI->SetActiveDialogBox( 0 );
205 //=================================================================================
206 // function : ActivateThisDialog()
208 //=================================================================================
209 void MeasureGUI_Skeleton::ActivateThisDialog()
211 myGeomGUI->EmitSignalDeactivateDialog();
215 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
217 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
219 connect( aSel, SIGNAL( currentSelectionChanged() ),
220 this, SLOT ( SelectionIntoArgument() ) ) ;
226 //=================================================================================
227 // function : SetEditCurrentArgument
229 //=================================================================================
230 void MeasureGUI_Skeleton::SetEditCurrentArgument()
232 mySelEdit->setFocus();
233 SelectionIntoArgument();
236 //=================================================================================
237 // function : SelectionIntoArgument
239 //=================================================================================
240 void MeasureGUI_Skeleton::SelectionIntoArgument()
242 myObj = GEOM::GEOM_Object::_nil();
244 Standard_Boolean testResult = Standard_False;
245 GEOM::GEOM_Object_var aSelectedObject =
246 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
248 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* e)
289 if ( 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 ) )
313 erasePreview( true );
317 erasePreview( false );
321 SUIT_OverrideCursor();
323 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
324 getDisplayer()->SetToActivate( false );
326 if ( SALOME_Prs* aPrs = buildPrs() )
327 displayPreview( aPrs );
329 catch( const SALOME::SALOME_Exception& e )
331 SalomeApp_Tools::QtCatchCorbaException( e );
336 //=================================================================================
337 // function : activateSelection
339 //=================================================================================
340 void MeasureGUI_Skeleton::activateSelection()
342 globalSelection( GEOM_ALLSHAPES );
345 //=================================================================================
346 // function : isValid
348 //=================================================================================
349 bool MeasureGUI_Skeleton::isValid( QString& )
351 return !myObj->_is_nil();
354 //================================================================
355 // Function : getDisplayer
357 //================================================================
358 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
361 myDisplayer = new GEOM_Displayer( getStudy() );
365 //=================================================================================
366 // function : createOperation
368 //=================================================================================
369 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
371 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
374 //=================================================================================
375 // function : keyPressEvent()
377 //=================================================================================
378 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
380 QDialog::keyPressEvent( e );
381 if ( e->isAccepted() )
384 if ( e->key() == Key_F1 )