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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
36 #include "SalomeApp_Tools.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_OverrideCursor.h"
40 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
44 #include <qbuttongroup.h>
45 #include <qapplication.h>
47 //=================================================================================
48 // class : MeasureGUI_Skeleton()
49 // purpose : Constructs a MeasureGUI_Skeleton which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_Skeleton::MeasureGUI_Skeleton( GeometryGUI* GUI,
57 : MeasureGUI_Skeleton_QTD( parent, name, false,
58 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
67 setName( "MeasureGUI_Skeleton" );
69 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
71 buttonClose->setAutoDefault( false );
73 GroupMedium->close( TRUE );
78 //=================================================================================
79 // function : ~MeasureGUI_Skeleton()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
84 myGeomGUI->SetActiveDialogBox( 0 );
89 //=================================================================================
92 //=================================================================================
93 void MeasureGUI_Skeleton::Init()
96 myGeomGUI->SetActiveDialogBox((QDialog*)this);
98 /* signals and slots connections */
100 connect( buttonClose, SIGNAL( clicked() ),
101 this, SLOT( ClickOnCancel() ) );
103 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
104 this, SLOT ( DeactivateActiveDialog() ) );
106 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
107 this, SLOT ( ClickOnCancel() ) );
109 connect( mySelEdit, SIGNAL( returnPressed() ),
110 this, SLOT( LineEditReturnPressed() ) );
112 connect( mySelBtn, SIGNAL( clicked() ),
113 this, SLOT ( SetEditCurrentArgument() ) );
115 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
117 connect( aSel, SIGNAL( currentSelectionChanged() ),
118 this, SLOT ( SelectionIntoArgument() ) ) ;
120 /* displays Dialog */
121 RadioButton1->setChecked( TRUE );
124 SelectionIntoArgument();
129 //=================================================================================
130 // function : ClickOnCancel()
132 //=================================================================================
133 void MeasureGUI_Skeleton::ClickOnCancel()
139 //=================================================================================
140 // function : LineEditReturnPressed()
142 //=================================================================================
143 void MeasureGUI_Skeleton::LineEditReturnPressed()
145 /* User name of object input management */
146 /* If successfull the selection is changed and signal emitted... */
147 /* so SelectionIntoArgument() is automatically called. */
149 const QString objectUserName = mySelEdit->text();
150 QWidget* thisWidget = ( QWidget* )this;
152 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
153 mySelEdit->setText( objectUserName );
157 //=================================================================================
158 // function : DeactivateActiveDialog()
160 //=================================================================================
161 void MeasureGUI_Skeleton::DeactivateActiveDialog()
165 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
167 disconnect( aSel, 0, this, 0 );
169 myGeomGUI->SetActiveDialogBox( 0 );
175 //=================================================================================
176 // function : ActivateThisDialog()
178 //=================================================================================
179 void MeasureGUI_Skeleton::ActivateThisDialog()
181 myGeomGUI->EmitSignalDeactivateDialog();
185 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
187 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
189 connect( aSel, SIGNAL( currentSelectionChanged() ),
190 this, SLOT ( SelectionIntoArgument() ) ) ;
196 //=================================================================================
197 // function : SetEditCurrentArgument
199 //=================================================================================
200 void MeasureGUI_Skeleton::SetEditCurrentArgument()
202 mySelEdit->setFocus();
203 SelectionIntoArgument();
206 //=================================================================================
207 // function : SelectionIntoArgument
209 //=================================================================================
210 void MeasureGUI_Skeleton::SelectionIntoArgument()
212 myObj = GEOM::GEOM_Object::_nil();
214 Standard_Boolean testResult = Standard_False;
215 GEOM::GEOM_Object_var aSelectedObject =
216 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
218 if( !testResult || aSelectedObject->_is_nil() )
220 mySelEdit->setText( "" );
226 myObj = aSelectedObject;
227 mySelEdit->setText( GEOMBase::GetName( myObj ) );
232 //=================================================================================
233 // function : processObject
235 //=================================================================================
236 void MeasureGUI_Skeleton::processObject()
241 //=================================================================================
242 // function : closeEvent
244 //=================================================================================
245 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
247 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
249 disconnect( aSel, 0, this, 0 );
250 QDialog::closeEvent( e );
253 //=================================================================================
254 // function : enterEvent()
256 //=================================================================================
257 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
259 if ( GroupConstructors->isEnabled() )
262 ActivateThisDialog();
265 //=================================================================================
266 // function : buildPrs
267 // purpose : Build presentation for "preview"
268 //=================================================================================
269 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
274 //=================================================================================
275 // function : closeEvent()
276 // purpose : Build presentation for "preview"
277 //=================================================================================
278 void MeasureGUI_Skeleton::redisplayPreview()
281 if ( !isValid( aMess ) )
283 erasePreview( true );
287 erasePreview( false );
291 SUIT_OverrideCursor();
293 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
294 getDisplayer()->SetToActivate( false );
296 if ( SALOME_Prs* aPrs = buildPrs() )
297 displayPreview( aPrs );
299 catch( const SALOME::SALOME_Exception& e )
301 SalomeApp_Tools::QtCatchCorbaException( e );
306 //=================================================================================
307 // function : activateSelection
309 //=================================================================================
310 void MeasureGUI_Skeleton::activateSelection()
312 globalSelection( GEOM_ALLSHAPES );
315 //=================================================================================
316 // function : isValid
318 //=================================================================================
319 bool MeasureGUI_Skeleton::isValid( QString& )
321 return !myObj->_is_nil();
324 //================================================================
325 // Function : getDisplayer
327 //================================================================
328 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
331 myDisplayer = new GEOM_Displayer( getStudy() );
335 //=================================================================================
336 // function : createOperation
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
341 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
344 //=================================================================================
345 // function : getDesktop()
347 //=================================================================================
348 SUIT_Desktop* MeasureGUI_Skeleton::getDesktop() const
350 return dynamic_cast<SUIT_Desktop*>( parentWidget() );