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);
156 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
157 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
158 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
159 QObject::tr("BUT_OK"));
163 //=================================================================================
164 // function : LineEditReturnPressed()
166 //=================================================================================
167 void MeasureGUI_Skeleton::LineEditReturnPressed()
169 /* User name of object input management */
170 /* If successfull the selection is changed and signal emitted... */
171 /* so SelectionIntoArgument() is automatically called. */
173 const QString objectUserName = mySelEdit->text();
174 QWidget* thisWidget = ( QWidget* )this;
176 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
177 mySelEdit->setText( objectUserName );
181 //=================================================================================
182 // function : DeactivateActiveDialog()
184 //=================================================================================
185 void MeasureGUI_Skeleton::DeactivateActiveDialog()
189 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
191 disconnect( aSel, 0, this, 0 );
193 myGeomGUI->SetActiveDialogBox( 0 );
199 //=================================================================================
200 // function : ActivateThisDialog()
202 //=================================================================================
203 void MeasureGUI_Skeleton::ActivateThisDialog()
205 myGeomGUI->EmitSignalDeactivateDialog();
209 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
211 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
213 connect( aSel, SIGNAL( currentSelectionChanged() ),
214 this, SLOT ( SelectionIntoArgument() ) ) ;
220 //=================================================================================
221 // function : SetEditCurrentArgument
223 //=================================================================================
224 void MeasureGUI_Skeleton::SetEditCurrentArgument()
226 mySelEdit->setFocus();
227 SelectionIntoArgument();
230 //=================================================================================
231 // function : SelectionIntoArgument
233 //=================================================================================
234 void MeasureGUI_Skeleton::SelectionIntoArgument()
236 myObj = GEOM::GEOM_Object::_nil();
238 Standard_Boolean testResult = Standard_False;
239 GEOM::GEOM_Object_var aSelectedObject =
240 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
242 if( !testResult || aSelectedObject->_is_nil() )
244 mySelEdit->setText( "" );
250 myObj = aSelectedObject;
251 mySelEdit->setText( GEOMBase::GetName( myObj ) );
256 //=================================================================================
257 // function : processObject
259 //=================================================================================
260 void MeasureGUI_Skeleton::processObject()
265 //=================================================================================
266 // function : closeEvent
268 //=================================================================================
269 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
271 LightApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
273 disconnect( aSel, 0, this, 0 );
274 QDialog::closeEvent( e );
277 //=================================================================================
278 // function : enterEvent()
280 //=================================================================================
281 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
283 if ( GroupConstructors->isEnabled() )
286 ActivateThisDialog();
289 //=================================================================================
290 // function : buildPrs
291 // purpose : Build presentation for "preview"
292 //=================================================================================
293 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
298 //=================================================================================
299 // function : closeEvent()
300 // purpose : Build presentation for "preview"
301 //=================================================================================
302 void MeasureGUI_Skeleton::redisplayPreview()
305 if ( !isValid( aMess ) )
307 erasePreview( true );
311 erasePreview( false );
315 SUIT_OverrideCursor();
317 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
318 getDisplayer()->SetToActivate( false );
320 if ( SALOME_Prs* aPrs = buildPrs() )
321 displayPreview( aPrs );
323 catch( const SALOME::SALOME_Exception& e )
325 SalomeApp_Tools::QtCatchCorbaException( e );
330 //=================================================================================
331 // function : activateSelection
333 //=================================================================================
334 void MeasureGUI_Skeleton::activateSelection()
336 globalSelection( GEOM_ALLSHAPES );
339 //=================================================================================
340 // function : isValid
342 //=================================================================================
343 bool MeasureGUI_Skeleton::isValid( QString& )
345 return !myObj->_is_nil();
348 //================================================================
349 // Function : getDisplayer
351 //================================================================
352 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
355 myDisplayer = new GEOM_Displayer( getStudy() );
359 //=================================================================================
360 // function : createOperation
362 //=================================================================================
363 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
365 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
368 //=================================================================================
369 // function : keyPressEvent()
371 //=================================================================================
372 void MeasureGUI_Skeleton::keyPressEvent( QKeyEvent* e )
374 QDialog::keyPressEvent( e );
375 if ( e->isAccepted() )
378 if ( e->key() == Key_F1 )