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 : BasicGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_PointDlg.h"
31 #include "SUIT_ResourceMgr.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include "GeometryGUI.h"
39 #include "DlgRef_SpinBox.h"
40 #include "DlgRef_1Sel1Spin.h"
41 #include "DlgRef_3Spin.h"
42 #include "DlgRef_1Sel3Spin.h"
44 #include "GEOMImpl_Types.hxx"
46 #include <QApplication>
50 #include <TopoDS_Shape.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
53 #include <BRep_Tool.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
56 #include <TopTools_IndexedMapOfShape.hxx>
59 //=================================================================================
60 // class : BasicGUI_PointDlg()
61 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
62 // name 'name' and widget flags set to 'f'.
63 // The dialog will by default be modeless, unless you set 'modal' to
64 // TRUE to construct a modal dialog.
65 //=================================================================================
66 BasicGUI_PointDlg::BasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
67 const char* name, bool modal, Qt::WindowFlags fl)
68 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl )
70 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
71 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
72 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
73 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_REF")));
75 setWindowTitle(tr("GEOM_POINT_TITLE"));
77 QFrame* aFrame = new QFrame( this );
78 aFrame->setContentsMargins( 0, 0, 0, 0 );
79 aFrame->setFrameStyle( QFrame::NoFrame );
80 QHBoxLayout* aFrameLayout = new QHBoxLayout( aFrame );
82 /***************************************************************/
83 GroupConstructors->setTitle(tr("GEOM_POINTS"));
84 RadioButton1->setIcon(image0);
85 RadioButton2->setIcon(image3);
86 RadioButton3->setIcon(image1);
88 GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
89 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
90 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
91 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
92 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
93 aFrameLayout->addWidget(GroupXYZ);
95 GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
96 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
97 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
98 GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
99 GroupOnCurve->PushButton1->setIcon(image2);
100 aFrameLayout->addWidget(GroupOnCurve);
102 GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
103 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
104 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
105 GroupRefPoint->PushButton1->setIcon(image2);
106 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
107 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
108 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
109 aFrameLayout->addWidget(GroupRefPoint);
111 gridLayout1->addWidget( aFrame, 2, 0 );
112 /***************************************************************/
114 myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES" ), aFrame );
115 QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
116 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
117 myX = new QLineEdit( myCoordGrp );
118 myCoordGrpLayout->addWidget( myX, 0, 1 );
119 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
120 myY = new QLineEdit( myCoordGrp );
121 myCoordGrpLayout->addWidget( myY, 1, 1 );
122 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
123 myZ = new QLineEdit( myCoordGrp );
124 myCoordGrpLayout->addWidget( myZ, 2, 1 );
126 myX->setReadOnly( true );
127 myY->setReadOnly( true );
128 myZ->setReadOnly( true );
130 myX->setEnabled( false );
131 myY->setEnabled( false );
132 myZ->setEnabled( false );
134 QPalette aPal = myX->palette();
135 aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) ) ;
136 myX->setPalette( aPal );
137 myY->setPalette( aPal );
138 myZ->setPalette( aPal );
140 setHelpFileName("point.htm");
146 //=================================================================================
147 // function : ~BasicGUI_PointDlg()
148 // purpose : Destructor
149 //=================================================================================
150 BasicGUI_PointDlg::~BasicGUI_PointDlg()
155 //=================================================================================
158 //=================================================================================
159 void BasicGUI_PointDlg::Init()
161 GroupOnCurve->LineEdit1->setReadOnly( true );
162 GroupRefPoint->LineEdit1->setReadOnly( true );
164 myEdge = GEOM::GEOM_Object::_nil();
165 myRefPoint = GEOM::GEOM_Object::_nil();
167 myEditCurrentArgument = 0;
169 /* Get setting of step value from file configuration */
170 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
171 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
173 /* min, max, step and decimals for spin boxes */
174 GroupXYZ->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
175 GroupXYZ->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
176 GroupXYZ->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
177 GroupXYZ->SpinBox_DX->SetValue(0.0);
178 GroupXYZ->SpinBox_DY->SetValue(0.0);
179 GroupXYZ->SpinBox_DZ->SetValue(0.0);
181 GroupRefPoint->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
182 GroupRefPoint->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
183 GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
184 GroupRefPoint->SpinBox_DX->SetValue(0.0);
185 GroupRefPoint->SpinBox_DY->SetValue(0.0);
186 GroupRefPoint->SpinBox_DZ->SetValue(0.0);
189 GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, 3);
190 GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
192 /* signals and slots connections */
193 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
194 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
195 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
197 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
198 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
199 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
201 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
202 connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
204 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
205 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
206 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
207 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
208 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
209 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
210 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
212 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
213 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
214 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
215 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
216 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
217 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
218 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
220 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
221 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
223 initName( tr("GEOM_VERTEX").toLatin1().constData() );
225 ConstructorsClicked( 0 );
229 //=================================================================================
230 // function : ConstructorsClicked()
231 // purpose : Radio button management
232 //=================================================================================
233 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
235 switch ( constructorId )
239 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
241 GroupRefPoint->hide();
242 GroupOnCurve->hide();
251 myEditCurrentArgument = GroupRefPoint->LineEdit1;
252 myEditCurrentArgument->setText("");
253 myRefPoint = GEOM::GEOM_Object::_nil();
255 globalSelection( GEOM_POINT );
258 GroupOnCurve->hide();
260 GroupRefPoint->show();
267 myEditCurrentArgument = GroupOnCurve->LineEdit1;
268 myEditCurrentArgument->setText("");
269 myEdge = GEOM::GEOM_Object::_nil();
271 globalSelection( GEOM_EDGE );
274 GroupRefPoint->hide();
276 GroupOnCurve->show();
287 qApp->processEvents();
289 resize( minimumSize() );
291 SelectionIntoArgument();
295 //=================================================================================
296 // function : ClickOnOk()
298 //=================================================================================
299 void BasicGUI_PointDlg::ClickOnOk()
306 //=================================================================================
307 // function : ClickOnApply()
309 //=================================================================================
310 bool BasicGUI_PointDlg::ClickOnApply()
316 ConstructorsClicked( getConstructorId() );
321 //=================================================================================
322 // function : ClickOnCancel()
324 //=================================================================================
325 void BasicGUI_PointDlg::ClickOnCancel()
327 GEOMBase_Skeleton::ClickOnCancel();
331 //=================================================================================
332 // function : SelectionIntoArgument()
333 // purpose : Called when selection as changed (for constructors not using local context)
334 //=================================================================================
335 void BasicGUI_PointDlg::SelectionIntoArgument()
337 const int id = getConstructorId();
339 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 )
341 myEditCurrentArgument->setText("");
345 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
348 if ( IObjectCount() == 1 )
350 Standard_Boolean aRes = Standard_False;
351 Handle(SALOME_InteractiveObject) anIO = firstIObject();
352 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
353 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
357 // get CORBA reference to data object
358 TopoDS_Shape aShape = myGeomGUI->GetShapeReader().GetShape
359 ( myGeomGUI->GetGeomGen(), aSelectedObject );
360 if ( aShape.IsNull() )
363 if ( aShape.ShapeType() != TopAbs_VERTEX )
365 TColStd_IndexedMapOfInteger aMap;
366 LightApp_Application* anApp =
367 (LightApp_Application*)(SUIT_Session::session()->activeApplication());
368 anApp->selectionMgr()->GetIndexes( anIO, aMap );
370 if ( aMap.Extent() == 1 )
372 int anIndex = aMap( 1 );
373 TopTools_IndexedMapOfShape aShapes;
374 TopExp::MapShapes( aShape, aShapes );
375 aShape = aShapes.FindKey( anIndex );
377 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
384 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
385 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
386 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
387 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
391 myRefPoint = aSelectedObject;
392 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
396 myEdge = aSelectedObject;
397 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
406 //=================================================================================
407 // function : LineEditReturnPressed()
409 //=================================================================================
410 void BasicGUI_PointDlg::LineEditReturnPressed()
412 QLineEdit* send = (QLineEdit*)sender();
413 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
415 myEditCurrentArgument = send;
416 GEOMBase_Skeleton::LineEditReturnPressed();
421 //=================================================================================
422 // function : SetEditCurrentArgument()
424 //=================================================================================
425 void BasicGUI_PointDlg::SetEditCurrentArgument()
427 QPushButton* send = (QPushButton*)sender();
429 if ( send == GroupRefPoint->PushButton1 )
431 GroupRefPoint->LineEdit1->setFocus();
432 myEditCurrentArgument = GroupRefPoint->LineEdit1;
434 globalSelection( GEOM_POINT );
436 else if ( send == GroupOnCurve->PushButton1 )
438 GroupOnCurve->LineEdit1->setFocus();
439 myEditCurrentArgument = GroupOnCurve->LineEdit1;
441 globalSelection( GEOM_EDGE );
446 //=================================================================================
447 // function : enterEvent()
448 // purpose : to reactivate this dialog box when mouse enter onto the window
449 //=================================================================================
450 void BasicGUI_PointDlg::enterEvent(QEvent* e)
452 if ( !GroupConstructors->isEnabled() )
453 ActivateThisDialog();
457 //=================================================================================
458 // function : ActivateThisDialog()
460 //=================================================================================
461 void BasicGUI_PointDlg::ActivateThisDialog( )
463 GEOMBase_Skeleton::ActivateThisDialog();
464 // myGeomGUI->SetState( 0 );
465 ConstructorsClicked( getConstructorId() );
469 //=================================================================================
470 // function : DeactivateActiveDialog()
471 // purpose : public slot to deactivate if active
472 //=================================================================================
473 void BasicGUI_PointDlg::DeactivateActiveDialog()
475 // myGeomGUI->SetState( -1 );
476 GEOMBase_Skeleton::DeactivateActiveDialog();
480 //=================================================================================
481 // function : ValueChangedInSpinBox()
483 //=================================================================================
484 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
489 //=================================================================================
490 // funcion : getParameter()
492 //=================================================================================
493 double BasicGUI_PointDlg::getParameter() const
495 return GroupOnCurve->SpinBox_DX->GetValue();
498 //=================================================================================
499 // function : OnPointSelected
501 //=================================================================================
502 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
504 if ( getConstructorId() == 0 )
506 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
507 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
508 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
514 //=================================================================================
515 // function : createOperation
517 //=================================================================================
518 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
520 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
523 //=================================================================================
524 // function : isValid
526 //=================================================================================
527 bool BasicGUI_PointDlg::isValid( QString& msg )
529 const int id = getConstructorId();
533 return !myRefPoint->_is_nil();
535 return !myEdge->_is_nil();
539 //=================================================================================
540 // function : execute
542 //=================================================================================
543 bool BasicGUI_PointDlg::execute( ObjectList& objects )
547 GEOM::GEOM_Object_var anObj;
549 switch ( getConstructorId() )
553 double x = GroupXYZ->SpinBox_DX->GetValue();
554 double y = GroupXYZ->SpinBox_DY->GetValue();
555 double z = GroupXYZ->SpinBox_DZ->GetValue();
557 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
563 double dx = GroupRefPoint->SpinBox_DX->GetValue();
564 double dy = GroupRefPoint->SpinBox_DY->GetValue();
565 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
567 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
568 MakePointWithReference( myRefPoint, dx, dy, dz );
573 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
574 MakePointOnCurve( myEdge, getParameter() );
579 if ( getConstructorId() == 1 || getConstructorId() == 2 )
582 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
584 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
585 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
586 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
587 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
597 if ( !anObj->_is_nil() )
599 //printf( "--> a valid point is created\n" );
600 objects.push_back( anObj._retn() );
606 //=================================================================================
607 // function : closeEvent
609 //=================================================================================
610 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
612 GEOMBase_Skeleton::closeEvent( e );