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 ) ),
70 setName( "MeasureGUI_Skeleton" );
72 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
73 buttonHelp->setText(tr("GEOM_BUT_HELP"));
75 buttonClose->setAutoDefault( false );
81 //=================================================================================
82 // function : ~MeasureGUI_Skeleton()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
87 myGeomGUI->SetActiveDialogBox( 0 );
92 //=================================================================================
95 //=================================================================================
96 void MeasureGUI_Skeleton::Init()
99 myGeomGUI->SetActiveDialogBox((QDialog*)this);
101 /* signals and slots connections */
103 connect( buttonClose, SIGNAL( clicked() ),
104 this, SLOT( ClickOnCancel() ) );
106 connect( buttonHelp, SIGNAL( clicked() ),
107 this, SLOT( ClickOnHelp() ) );
109 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
110 this, SLOT ( DeactivateActiveDialog() ) );
112 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
113 this, SLOT ( ClickOnCancel() ) );
115 connect( mySelEdit, SIGNAL( returnPressed() ),
116 this, SLOT( LineEditReturnPressed() ) );
118 connect( mySelBtn, SIGNAL( clicked() ),
119 this, SLOT ( SetEditCurrentArgument() ) );
121 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
123 connect( aSel, SIGNAL( currentSelectionChanged() ),
124 this, SLOT ( SelectionIntoArgument() ) ) ;
126 /* displays Dialog */
127 RadioButton1->setChecked( TRUE );
130 SelectionIntoArgument();
135 //=================================================================================
136 // function : ClickOnCancel()
138 //=================================================================================
139 void MeasureGUI_Skeleton::ClickOnCancel()
144 //=================================================================================
145 // function : ClickOnHelp()
147 //=================================================================================
148 void MeasureGUI_Skeleton::ClickOnHelp()
150 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
152 app->onHelpContextModule(myGeomGUI ? app->moduleName(myGeomGUI->moduleName()) : QString(""), myHelpFileName);
156 platform = "winapplication";
158 platform = "application";
160 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
161 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
162 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
163 QObject::tr("BUT_OK"));
167 //=================================================================================
168 // function : LineEditReturnPressed()
170 //=================================================================================
171 void MeasureGUI_Skeleton::LineEditReturnPressed()
173 /* User name of object input management */
174 /* If successfull the selection is changed and signal emitted... */
175 /* so SelectionIntoArgument() is automatically called. */
177 const QString objectUserName = mySelEdit->text();
178 QWidget* thisWidget = ( QWidget* )this;
180 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
181 mySelEdit->setText( objectUserName );
185 //=================================================================================
186 // function : DeactivateActiveDialog()
188 //=================================================================================
189 void MeasureGUI_Skeleton::DeactivateActiveDialog()
193 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
195 disconnect( aSel, 0, this, 0 );
197 myGeomGUI->SetActiveDialogBox( 0 );
203 //=================================================================================
204 // function : ActivateThisDialog()
206 //=================================================================================
207 void MeasureGUI_Skeleton::ActivateThisDialog()
209 myGeomGUI->EmitSignalDeactivateDialog();
213 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
215 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
217 connect( aSel, SIGNAL( currentSelectionChanged() ),
218 this, SLOT ( SelectionIntoArgument() ) ) ;
224 //=================================================================================
225 // function : SetEditCurrentArgument
227 //=================================================================================
228 void MeasureGUI_Skeleton::SetEditCurrentArgument()
230 mySelEdit->setFocus();
231 SelectionIntoArgument();
234 //=================================================================================
235 // function : SelectionIntoArgument
237 //=================================================================================
238 void MeasureGUI_Skeleton::SelectionIntoArgument()
240 myObj = GEOM::GEOM_Object::_nil();
242 Standard_Boolean testResult = Standard_False;
243 GEOM::GEOM_Object_var aSelectedObject =
244 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
246 if( !testResult || aSelectedObject->_is_nil() )
248 mySelEdit->setText( "" );
254 myObj = aSelectedObject;
255 mySelEdit->setText( GEOMBase::GetName( myObj ) );
260 //=================================================================================
261 // function : processObject
263 //=================================================================================
264 void MeasureGUI_Skeleton::processObject()
269 //=================================================================================
270 // function : closeEvent
272 //=================================================================================
273 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
275 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
277 disconnect( aSel, 0, this, 0 );
278 QDialog::closeEvent( e );
281 //=================================================================================
282 // function : enterEvent()
284 //=================================================================================
285 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
287 if ( GroupConstructors->isEnabled() )
290 ActivateThisDialog();
293 //=================================================================================
294 // function : buildPrs
295 // purpose : Build presentation for "preview"
296 //=================================================================================
297 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
302 //=================================================================================
303 // function : closeEvent()
304 // purpose : Build presentation for "preview"
305 //=================================================================================
306 void MeasureGUI_Skeleton::redisplayPreview()
309 if ( !isValid( aMess ) )
311 erasePreview( true );
315 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 )
329 SalomeApp_Tools::QtCatchCorbaException( e );
334 //=================================================================================
335 // function : activateSelection
337 //=================================================================================
338 void MeasureGUI_Skeleton::activateSelection()
340 globalSelection( GEOM_ALLSHAPES );
343 //=================================================================================
344 // function : isValid
346 //=================================================================================
347 bool MeasureGUI_Skeleton::isValid( QString& )
349 return !myObj->_is_nil();
352 //================================================================
353 // Function : getDisplayer
355 //================================================================
356 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
359 myDisplayer = new GEOM_Displayer( getStudy() );
363 //=================================================================================
364 // function : createOperation
366 //=================================================================================
367 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
369 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
372 //=================================================================================
373 // function : keyPressEvent()
375 //=================================================================================
376 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
378 QDialog::keyPressEvent( e );
379 if ( e->isAccepted() )
382 if ( e->key() == Key_F1 )