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
22 // File : BasicGUI_PointDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_PointDlg.h"
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
33 #include <GeometryGUI.h>
38 #include <GEOMImpl_Types.hxx>
40 #include <QApplication>
44 #include <TopoDS_Shape.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
47 #include <BRep_Tool.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
52 //=================================================================================
53 // class : BasicGUI_PointDlg()
54 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60 bool modal, Qt::WindowFlags fl )
61 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
63 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
64 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
65 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
68 setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
70 /***************************************************************/
71 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
72 mainFrame()->RadioButton1->setIcon( image0 );
73 mainFrame()->RadioButton2->setIcon( image3 );
74 mainFrame()->RadioButton3->setIcon( image1 );
76 GroupXYZ = new DlgRef_3Spin( centralWidget() );
77 GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
78 GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
79 GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
80 GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
82 GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
83 GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_PARAM_POINT" ) );
84 GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
85 GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
86 GroupOnCurve->PushButton1->setIcon( image2 );
88 GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
89 GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
90 GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
91 GroupRefPoint->PushButton1->setIcon( image2 );
92 GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
93 GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
94 GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
96 myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES" ), centralWidget() );
97 QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
98 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
99 myX = new QLineEdit( myCoordGrp );
100 myCoordGrpLayout->addWidget( myX, 0, 1 );
101 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
102 myY = new QLineEdit( myCoordGrp );
103 myCoordGrpLayout->addWidget( myY, 1, 1 );
104 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
105 myZ = new QLineEdit( myCoordGrp );
106 myCoordGrpLayout->addWidget( myZ, 2, 1 );
108 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
109 layout->setMargin( 0 ); layout->setSpacing( 6 );
110 layout->addWidget( GroupXYZ );
111 layout->addWidget( GroupOnCurve );
112 layout->addWidget( GroupRefPoint );
113 layout->addWidget( myCoordGrp );
115 myX->setReadOnly( true );
116 myY->setReadOnly( true );
117 myZ->setReadOnly( true );
119 myX->setEnabled( false );
120 myY->setEnabled( false );
121 myZ->setEnabled( false );
123 QPalette aPal = myX->palette();
124 aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) ) ;
125 myX->setPalette( aPal );
126 myY->setPalette( aPal );
127 myZ->setPalette( aPal );
129 setHelpFileName( "point.htm" );
135 //=================================================================================
136 // function : ~BasicGUI_PointDlg()
137 // purpose : Destructor
138 //=================================================================================
139 BasicGUI_PointDlg::~BasicGUI_PointDlg()
144 //=================================================================================
147 //=================================================================================
148 void BasicGUI_PointDlg::Init()
150 GroupOnCurve->LineEdit1->setReadOnly( true );
151 GroupRefPoint->LineEdit1->setReadOnly( true );
153 myEdge = GEOM::GEOM_Object::_nil();
154 myRefPoint = GEOM::GEOM_Object::_nil();
156 myEditCurrentArgument = 0;
158 /* Get setting of step value from file configuration */
159 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
160 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
162 /* min, max, step and decimals for spin boxes */
163 initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
164 initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
165 initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
166 GroupXYZ->SpinBox_DX->setValue( 0.0 );
167 GroupXYZ->SpinBox_DY->setValue( 0.0 );
168 GroupXYZ->SpinBox_DZ->setValue( 0.0 );
170 initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
171 initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
172 initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
173 GroupRefPoint->SpinBox_DX->setValue( 0.0 );
174 GroupRefPoint->SpinBox_DY->setValue( 0.0 );
175 GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
179 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 3 );
180 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
182 /* signals and slots connections */
183 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
184 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
186 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
187 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
189 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
191 connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
192 connect( GroupOnCurve->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
194 connect( GroupOnCurve->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
195 connect( GroupXYZ->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
196 connect( GroupXYZ->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
197 connect( GroupXYZ->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
198 connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
199 connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
200 connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
203 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupOnCurve->SpinBox_DX, SLOT( SetStep( double ) ) );
204 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DX, SLOT( SetStep( double ) ) );
205 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DY, SLOT( SetStep( double ) ) );
206 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupXYZ->SpinBox_DZ, SLOT( SetStep( double ) ) );
207 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DX, SLOT( SetStep( double ) ) );
208 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DY, SLOT( SetStep( double ) ) );
209 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupRefPoint->SpinBox_DZ, SLOT( SetStep( double ) ) );
212 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
213 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
215 initName( tr( "GEOM_VERTEX" ) );
217 ConstructorsClicked( 0 );
221 //=================================================================================
222 // function : ConstructorsClicked()
223 // purpose : Radio button management
224 //=================================================================================
225 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
227 switch ( constructorId ) {
230 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
232 GroupRefPoint->hide();
233 GroupOnCurve->hide();
242 myEditCurrentArgument = GroupRefPoint->LineEdit1;
243 myEditCurrentArgument->setText( "" );
244 myRefPoint = GEOM::GEOM_Object::_nil();
246 globalSelection( GEOM_POINT );
249 GroupOnCurve->hide();
251 GroupRefPoint->show();
258 myEditCurrentArgument = GroupOnCurve->LineEdit1;
259 myEditCurrentArgument->setText( "" );
260 myEdge = GEOM::GEOM_Object::_nil();
262 globalSelection( GEOM_EDGE );
265 GroupRefPoint->hide();
267 GroupOnCurve->show();
278 qApp->processEvents();
280 resize( minimumSize() );
282 SelectionIntoArgument();
286 //=================================================================================
287 // function : ClickOnOk()
289 //=================================================================================
290 void BasicGUI_PointDlg::ClickOnOk()
297 //=================================================================================
298 // function : ClickOnApply()
300 //=================================================================================
301 bool BasicGUI_PointDlg::ClickOnApply()
307 ConstructorsClicked( getConstructorId() );
312 //=================================================================================
313 // function : SelectionIntoArgument()
314 // purpose : Called when selection as changed (for constructors not using local context)
315 //=================================================================================
316 void BasicGUI_PointDlg::SelectionIntoArgument()
318 const int id = getConstructorId();
320 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 ) {
321 myEditCurrentArgument->setText( "" );
325 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
328 if ( IObjectCount() == 1 ) {
329 Standard_Boolean aRes = Standard_False;
330 Handle(SALOME_InteractiveObject) anIO = firstIObject();
331 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
332 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
334 // get CORBA reference to data object
335 TopoDS_Shape aShape = myGeomGUI->GetShapeReader().GetShape( myGeomGUI->GetGeomGen(), aSelectedObject );
336 if ( aShape.IsNull() )
339 if ( aShape.ShapeType() != TopAbs_VERTEX ) {
340 TColStd_IndexedMapOfInteger aMap;
341 LightApp_Application* anApp =
342 (LightApp_Application*)(SUIT_Session::session()->activeApplication());
343 anApp->selectionMgr()->GetIndexes( anIO, aMap );
345 if ( aMap.Extent() == 1 ) {
346 int anIndex = aMap( 1 );
347 TopTools_IndexedMapOfShape aShapes;
348 TopExp::MapShapes( aShape, aShapes );
349 aShape = aShapes.FindKey( anIndex );
351 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
358 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
359 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
360 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
361 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
363 else if ( id == 1 ) {
364 myRefPoint = aSelectedObject;
365 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
367 else if ( id == 2 ) {
368 myEdge = aSelectedObject;
369 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
378 //=================================================================================
379 // function : LineEditReturnPressed()
381 //=================================================================================
382 void BasicGUI_PointDlg::LineEditReturnPressed()
384 QLineEdit* send = (QLineEdit*)sender();
385 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
387 myEditCurrentArgument = send;
388 GEOMBase_Skeleton::LineEditReturnPressed();
393 //=================================================================================
394 // function : SetEditCurrentArgument()
396 //=================================================================================
397 void BasicGUI_PointDlg::SetEditCurrentArgument()
399 QPushButton* send = (QPushButton*)sender();
401 if ( send == GroupRefPoint->PushButton1 ) {
402 GroupRefPoint->LineEdit1->setFocus();
403 myEditCurrentArgument = GroupRefPoint->LineEdit1;
405 globalSelection( GEOM_POINT );
407 else if ( send == GroupOnCurve->PushButton1 ) {
408 GroupOnCurve->LineEdit1->setFocus();
409 myEditCurrentArgument = GroupOnCurve->LineEdit1;
411 globalSelection( GEOM_EDGE );
416 //=================================================================================
417 // function : enterEvent()
418 // purpose : to reactivate this dialog box when mouse enter onto the window
419 //=================================================================================
420 void BasicGUI_PointDlg::enterEvent( QEvent* )
422 if ( !mainFrame()->GroupConstructors->isEnabled() )
423 ActivateThisDialog();
427 //=================================================================================
428 // function : ActivateThisDialog()
430 //=================================================================================
431 void BasicGUI_PointDlg::ActivateThisDialog( )
433 GEOMBase_Skeleton::ActivateThisDialog();
434 // myGeomGUI->SetState( 0 );
435 ConstructorsClicked( getConstructorId() );
439 //=================================================================================
440 // function : DeactivateActiveDialog()
441 // purpose : public slot to deactivate if active
442 //=================================================================================
443 void BasicGUI_PointDlg::DeactivateActiveDialog()
445 // myGeomGUI->SetState( -1 );
446 GEOMBase_Skeleton::DeactivateActiveDialog();
450 //=================================================================================
451 // function : ValueChangedInSpinBox()
453 //=================================================================================
454 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
459 //=================================================================================
460 // funcion : getParameter()
462 //=================================================================================
463 double BasicGUI_PointDlg::getParameter() const
465 return GroupOnCurve->SpinBox_DX->value();
468 //=================================================================================
469 // function : OnPointSelected
471 //=================================================================================
472 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
474 if ( getConstructorId() == 0 ) {
475 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
476 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
477 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
483 //=================================================================================
484 // function : createOperation
486 //=================================================================================
487 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
489 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
492 //=================================================================================
493 // function : isValid
495 //=================================================================================
496 bool BasicGUI_PointDlg::isValid( QString& /*msg*/ )
498 const int id = getConstructorId();
502 return !myRefPoint->_is_nil();
504 return !myEdge->_is_nil();
508 //=================================================================================
509 // function : execute
511 //=================================================================================
512 bool BasicGUI_PointDlg::execute( ObjectList& objects )
516 GEOM::GEOM_Object_var anObj;
518 switch ( getConstructorId() ) {
521 double x = GroupXYZ->SpinBox_DX->value();
522 double y = GroupXYZ->SpinBox_DY->value();
523 double z = GroupXYZ->SpinBox_DZ->value();
525 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x, y, z );
531 double dx = GroupRefPoint->SpinBox_DX->value();
532 double dy = GroupRefPoint->SpinBox_DY->value();
533 double dz = GroupRefPoint->SpinBox_DZ->value();
535 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
536 MakePointWithReference( myRefPoint, dx, dy, dz );
541 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
542 MakePointOnCurve( myEdge, getParameter() );
547 if ( getConstructorId() == 1 || getConstructorId() == 2 ) {
549 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
550 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
551 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
552 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
553 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
562 if ( !anObj->_is_nil() ) {
563 objects.push_back( anObj._retn() );
569 //=================================================================================
570 // function : closeEvent
572 //=================================================================================
573 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
575 GEOMBase_Skeleton::closeEvent( e );