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 ),
59 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
68 setName( "MeasureGUI_Skeleton" );
70 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
72 buttonClose->setAutoDefault( false );
74 GroupMedium->close( TRUE );
79 //=================================================================================
80 // function : ~MeasureGUI_Skeleton()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 MeasureGUI_Skeleton::~MeasureGUI_Skeleton()
85 myGeomGUI->SetActiveDialogBox( 0 );
90 //=================================================================================
93 //=================================================================================
94 void MeasureGUI_Skeleton::Init()
97 myGeomGUI->SetActiveDialogBox((QDialog*)this);
99 /* signals and slots connections */
101 connect( buttonClose, SIGNAL( clicked() ),
102 this, SLOT( ClickOnCancel() ) );
104 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ),
105 this, SLOT ( DeactivateActiveDialog() ) );
107 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),
108 this, SLOT ( ClickOnCancel() ) );
110 connect( mySelEdit, SIGNAL( returnPressed() ),
111 this, SLOT( LineEditReturnPressed() ) );
113 connect( mySelBtn, SIGNAL( clicked() ),
114 this, SLOT ( SetEditCurrentArgument() ) );
116 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
118 connect( aSel, SIGNAL( currentSelectionChanged() ),
119 this, SLOT ( SelectionIntoArgument() ) ) ;
121 /* displays Dialog */
122 RadioButton1->setChecked( TRUE );
125 SelectionIntoArgument();
130 //=================================================================================
131 // function : ClickOnCancel()
133 //=================================================================================
134 void MeasureGUI_Skeleton::ClickOnCancel()
140 //=================================================================================
141 // function : LineEditReturnPressed()
143 //=================================================================================
144 void MeasureGUI_Skeleton::LineEditReturnPressed()
146 /* User name of object input management */
147 /* If successfull the selection is changed and signal emitted... */
148 /* so SelectionIntoArgument() is automatically called. */
150 const QString objectUserName = mySelEdit->text();
151 QWidget* thisWidget = ( QWidget* )this;
153 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
154 mySelEdit->setText( objectUserName );
158 //=================================================================================
159 // function : DeactivateActiveDialog()
161 //=================================================================================
162 void MeasureGUI_Skeleton::DeactivateActiveDialog()
166 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
168 disconnect( aSel, 0, this, 0 );
170 myGeomGUI->SetActiveDialogBox( 0 );
176 //=================================================================================
177 // function : ActivateThisDialog()
179 //=================================================================================
180 void MeasureGUI_Skeleton::ActivateThisDialog()
182 myGeomGUI->EmitSignalDeactivateDialog();
186 myGeomGUI->SetActiveDialogBox( ( QDialog* )this );
188 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
190 connect( aSel, SIGNAL( currentSelectionChanged() ),
191 this, SLOT ( SelectionIntoArgument() ) ) ;
197 //=================================================================================
198 // function : SetEditCurrentArgument
200 //=================================================================================
201 void MeasureGUI_Skeleton::SetEditCurrentArgument()
203 mySelEdit->setFocus();
204 SelectionIntoArgument();
207 //=================================================================================
208 // function : SelectionIntoArgument
210 //=================================================================================
211 void MeasureGUI_Skeleton::SelectionIntoArgument()
213 myObj = GEOM::GEOM_Object::_nil();
215 Standard_Boolean testResult = Standard_False;
216 GEOM::GEOM_Object_var aSelectedObject =
217 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
219 if( !testResult || aSelectedObject->_is_nil() )
221 mySelEdit->setText( "" );
227 myObj = aSelectedObject;
228 mySelEdit->setText( GEOMBase::GetName( myObj ) );
233 //=================================================================================
234 // function : processObject
236 //=================================================================================
237 void MeasureGUI_Skeleton::processObject()
242 //=================================================================================
243 // function : closeEvent
245 //=================================================================================
246 void MeasureGUI_Skeleton::closeEvent( QCloseEvent* e )
248 SalomeApp_SelectionMgr* aSel = ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr();
250 disconnect( aSel, 0, this, 0 );
251 QDialog::closeEvent( e );
254 //=================================================================================
255 // function : enterEvent()
257 //=================================================================================
258 void MeasureGUI_Skeleton::enterEvent(QEvent* e)
260 if ( GroupConstructors->isEnabled() )
263 ActivateThisDialog();
266 //=================================================================================
267 // function : buildPrs
268 // purpose : Build presentation for "preview"
269 //=================================================================================
270 SALOME_Prs* MeasureGUI_Skeleton::buildPrs()
275 //=================================================================================
276 // function : closeEvent()
277 // purpose : Build presentation for "preview"
278 //=================================================================================
279 void MeasureGUI_Skeleton::redisplayPreview()
282 if ( !isValid( aMess ) )
284 erasePreview( true );
288 erasePreview( false );
292 SUIT_OverrideCursor();
294 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
295 getDisplayer()->SetToActivate( false );
297 if ( SALOME_Prs* aPrs = buildPrs() )
298 displayPreview( aPrs );
300 catch( const SALOME::SALOME_Exception& e )
302 SalomeApp_Tools::QtCatchCorbaException( e );
307 //=================================================================================
308 // function : activateSelection
310 //=================================================================================
311 void MeasureGUI_Skeleton::activateSelection()
313 globalSelection( GEOM_ALLSHAPES );
316 //=================================================================================
317 // function : isValid
319 //=================================================================================
320 bool MeasureGUI_Skeleton::isValid( QString& )
322 return !myObj->_is_nil();
325 //================================================================
326 // Function : getDisplayer
328 //================================================================
329 GEOM_Displayer* MeasureGUI_Skeleton::getDisplayer()
332 myDisplayer = new GEOM_Displayer( getStudy() );
336 //=================================================================================
337 // function : createOperation
339 //=================================================================================
340 GEOM::GEOM_IOperations_ptr MeasureGUI_Skeleton::createOperation()
342 return getGeomEngine()->GetIMeasureOperations( getStudyId() );