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 : BasicGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_PointDlg.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include "GEOMImpl_Types.hxx"
39 #include "utilities.h"
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopAbs_ShapeEnum.hxx>
46 #include <BRep_Tool.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <qapplication.h>
53 //=================================================================================
54 // class : BasicGUI_PointDlg()
55 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 BasicGUI_PointDlg::BasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
61 :GEOMBase_Skeleton(parent, name, modal, fl ), myGeometryGUI(theGeometryGUI)
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 setCaption(tr("GEOM_POINT_TITLE"));
70 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
71 aFrame->setInsideMargin( 0 );
72 aFrame->setFrameStyle( QFrame::NoFrame );
74 /***************************************************************/
75 GroupConstructors->setTitle(tr("GEOM_POINTS"));
76 RadioButton1->setPixmap(image0);
77 RadioButton2->setPixmap(image3);
78 RadioButton3->setPixmap(image1);
80 GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
81 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
82 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
83 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
84 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
86 GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
87 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
88 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
89 GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
90 GroupOnCurve->PushButton1->setPixmap(image2);
92 GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
93 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
94 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
95 GroupRefPoint->PushButton1->setPixmap(image2);
96 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
97 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
98 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
100 Layout1->addWidget( aFrame, 2, 0 );
101 /***************************************************************/
103 myCoordGrp = new QGroupBox( 2, Qt::Horizontal, tr( "GEOM_COORDINATES" ), aFrame );
104 new QLabel( tr( "GEOM_X" ), myCoordGrp );
105 myX = new QLineEdit( myCoordGrp );
106 new QLabel( tr( "GEOM_Y" ), myCoordGrp );
107 myY = new QLineEdit( myCoordGrp );
108 new QLabel( tr( "GEOM_Z" ), myCoordGrp );
109 myZ = new QLineEdit( myCoordGrp );
111 myX->setReadOnly( true );
112 myY->setReadOnly( true );
113 myZ->setReadOnly( true );
115 myX->setEnabled( false );
116 myY->setEnabled( false );
117 myZ->setEnabled( false );
119 QPalette aPal = myX->palette();
120 aPal.setColor( QPalette::Disabled, QColorGroup::Text, QColor( 0, 0, 0 ) ) ;
121 myX->setPalette( aPal );
122 myY->setPalette( aPal );
123 myZ->setPalette( aPal );
129 //=======================================================================
130 // function : ~BasicGUI_PointDlg()
131 // purpose : Destructor
132 //=======================================================================
133 BasicGUI_PointDlg::~BasicGUI_PointDlg()
138 //=================================================================================
141 //=================================================================================
142 void BasicGUI_PointDlg::Init()
144 GroupOnCurve->LineEdit1->setReadOnly( true );
145 GroupRefPoint->LineEdit1->setReadOnly( true );
147 myEdge = GEOM::GEOM_Object::_nil();
148 myRefPoint = GEOM::GEOM_Object::_nil();
150 myEditCurrentArgument = 0;
152 // myGeometryGUI->SetState( 0 );
154 /* Get setting of step value from file configuration */
155 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
156 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
158 /* min, max, step and decimals for spin boxes */
159 GroupXYZ->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
160 GroupXYZ->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
161 GroupXYZ->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
162 GroupXYZ->SpinBox_DX->SetValue(0.0);
163 GroupXYZ->SpinBox_DY->SetValue(0.0);
164 GroupXYZ->SpinBox_DZ->SetValue(0.0);
166 GroupRefPoint->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
167 GroupRefPoint->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
168 GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
169 GroupRefPoint->SpinBox_DX->SetValue(0.0);
170 GroupRefPoint->SpinBox_DY->SetValue(0.0);
171 GroupRefPoint->SpinBox_DZ->SetValue(0.0);
174 GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, 3);
175 GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
177 /* signals and slots connections */
178 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
179 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
180 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
182 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
183 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
184 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
186 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
187 connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
189 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
190 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
192 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
193 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
194 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
195 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
197 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
198 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
199 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
200 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
201 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
202 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
203 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
205 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
206 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
208 initName( tr("GEOM_VERTEX") );
210 ConstructorsClicked( 0 );
214 //=================================================================================
215 // function : ConstructorsClicked()
216 // purpose : Radio button management
217 //=================================================================================
218 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
220 switch ( constructorId )
224 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
226 GroupRefPoint->hide();
227 GroupOnCurve->hide();
236 myEditCurrentArgument = GroupRefPoint->LineEdit1;
237 myEditCurrentArgument->setText("");
238 myRefPoint = GEOM::GEOM_Object::_nil();
240 globalSelection( GEOM_POINT );
243 GroupOnCurve->hide();
245 GroupRefPoint->show();
252 myEditCurrentArgument = GroupOnCurve->LineEdit1;
253 myEditCurrentArgument->setText("");
254 myEdge = GEOM::GEOM_Object::_nil();
256 globalSelection( GEOM_EDGE );
259 GroupRefPoint->hide();
261 GroupOnCurve->show();
272 qApp->processEvents();
274 resize( minimumSize() );
276 SelectionIntoArgument();
280 //=================================================================================
281 // function : ClickOnOk()
283 //=================================================================================
284 void BasicGUI_PointDlg::ClickOnOk()
291 //=================================================================================
292 // function : ClickOnApply()
294 //=================================================================================
295 bool BasicGUI_PointDlg::ClickOnApply()
301 ConstructorsClicked( getConstructorId() );
306 //=======================================================================
307 // function : ClickOnCancel()
309 //=======================================================================
310 void BasicGUI_PointDlg::ClickOnCancel()
312 GEOMBase_Skeleton::ClickOnCancel();
316 //=================================================================================
317 // function : SelectionIntoArgument()
318 // purpose : Called when selection as changed (for constructors not using local context)
319 //=================================================================================
320 void BasicGUI_PointDlg::SelectionIntoArgument()
322 const int id = getConstructorId();
324 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 )
326 myEditCurrentArgument->setText("");
330 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
333 if ( IObjectCount() == 1 )
335 Standard_Boolean aRes = Standard_False;
336 Handle(SALOME_InteractiveObject) anIO = firstIObject();
337 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
338 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
342 // get CORBA reference to data object
343 TopoDS_Shape aShape = myGeometryGUI->GetShapeReader().GetShape( myGeometryGUI->GetGeomGen(), aSelectedObject );
344 if ( aShape.IsNull() )
347 TColStd_IndexedMapOfInteger aMap;
349 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
351 if ( aMap.Extent() == 1 )
353 int anIndex = aMap( 1 );
354 TopTools_IndexedMapOfShape aShapes;
355 TopExp::MapShapes( aShape, aShapes );
356 aShape = aShapes.FindKey( anIndex );
358 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
361 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
362 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
363 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
364 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
369 myRefPoint = aSelectedObject;
370 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
374 myEdge = aSelectedObject;
375 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
384 //=================================================================================
385 // function : LineEditReturnPressed()
387 //=================================================================================
388 void BasicGUI_PointDlg::LineEditReturnPressed()
390 QLineEdit* send = (QLineEdit*)sender();
391 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
393 myEditCurrentArgument = send;
394 GEOMBase_Skeleton::LineEditReturnPressed();
399 //=================================================================================
400 // function : SetEditCurrentArgument()
402 //=================================================================================
403 void BasicGUI_PointDlg::SetEditCurrentArgument()
405 QPushButton* send = (QPushButton*)sender();
407 if ( send == GroupRefPoint->PushButton1 )
409 GroupRefPoint->LineEdit1->setFocus();
410 myEditCurrentArgument = GroupRefPoint->LineEdit1;
412 globalSelection( GEOM_POINT );
414 else if ( send == GroupOnCurve->PushButton1 )
416 GroupOnCurve->LineEdit1->setFocus();
417 myEditCurrentArgument = GroupOnCurve->LineEdit1;
419 globalSelection( GEOM_EDGE );
424 //=================================================================================
425 // function : enterEvent()
426 // purpose : to reactivate this dialog box when mouse enter onto the window
427 //=================================================================================
428 void BasicGUI_PointDlg::enterEvent(QEvent* e)
430 if ( !GroupConstructors->isEnabled() )
431 ActivateThisDialog();
435 //=================================================================================
436 // function : ActivateThisDialog()
438 //=================================================================================
439 void BasicGUI_PointDlg::ActivateThisDialog( )
441 GEOMBase_Skeleton::ActivateThisDialog();
442 // myGeometryGUI->SetState( 0 );
443 ConstructorsClicked( getConstructorId() );
447 //=================================================================================
448 // function : DeactivateActiveDialog()
449 // purpose : public slot to deactivate if active
450 //=================================================================================
451 void BasicGUI_PointDlg::DeactivateActiveDialog()
453 // myGeometryGUI->SetState( -1 );
454 GEOMBase_Skeleton::DeactivateActiveDialog();
458 //=================================================================================
459 // function : ValueChangedInSpinBox()
461 //=================================================================================
462 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
467 //=======================================================================
468 // funcion : getParameter()
470 //=======================================================================
471 double BasicGUI_PointDlg::getParameter() const
473 return GroupOnCurve->SpinBox_DX->GetValue();
476 //=================================================================================
477 // function : OnPointSelected
479 //=================================================================================
480 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
482 if ( getConstructorId() == 0 )
484 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
485 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
486 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
492 //=================================================================================
493 // function : createOperation
495 //=================================================================================
496 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
498 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
501 //=================================================================================
502 // function : isValid
504 //=================================================================================
505 bool BasicGUI_PointDlg::isValid( QString& msg )
507 const int id = getConstructorId();
511 return !myRefPoint->_is_nil();
513 return !myEdge->_is_nil();
517 //=================================================================================
518 // function : execute
520 //=================================================================================
521 bool BasicGUI_PointDlg::execute( ObjectList& objects )
525 GEOM::GEOM_Object_var anObj;
527 switch ( getConstructorId() )
531 double x = GroupXYZ->SpinBox_DX->GetValue();
532 double y = GroupXYZ->SpinBox_DY->GetValue();
533 double z = GroupXYZ->SpinBox_DZ->GetValue();
535 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
541 double dx = GroupRefPoint->SpinBox_DX->GetValue();
542 double dy = GroupRefPoint->SpinBox_DY->GetValue();
543 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
545 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointWithReference( myRefPoint, dx, dy, dz );
550 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointOnCurve( myEdge, getParameter() );
555 if ( getConstructorId() == 1 || getConstructorId() == 2 )
558 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
560 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
561 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
562 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
563 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
573 if ( !anObj->_is_nil() )
575 //printf( "--> a valid point is created\n" );
576 objects.push_back( anObj._retn() );
582 //=================================================================================
583 // function : closeEvent
585 //=================================================================================
586 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
588 // myGeometryGUI->SetState( -1 );
589 GEOMBase_Skeleton::closeEvent( e );