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
30 #include "BasicGUI_PointDlg.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
36 #include "GEOMImpl_Types.hxx"
40 #include "utilities.h"
43 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
47 #include <BRep_Tool.hxx>
49 #include <qapplication.h>
51 //=================================================================================
52 // class : BasicGUI_PointDlg()
53 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 BasicGUI_PointDlg::BasicGUI_PointDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
59 :GEOMBase_Skeleton(parent, name, modal, fl ), myGeometryGUI(theGeometryGUI)
61 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
63 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_REF")));
66 setCaption(tr("GEOM_POINT_TITLE"));
68 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
69 aFrame->setInsideMargin( 0 );
70 aFrame->setFrameStyle( QFrame::NoFrame );
72 /***************************************************************/
73 GroupConstructors->setTitle(tr("GEOM_POINTS"));
74 RadioButton1->setPixmap(image0);
75 RadioButton2->setPixmap(image3);
76 RadioButton3->setPixmap(image1);
78 GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
79 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
80 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
81 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
82 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
84 GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
85 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
86 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
87 GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
88 GroupOnCurve->PushButton1->setPixmap(image2);
90 GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
91 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
92 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
93 GroupRefPoint->PushButton1->setPixmap(image2);
94 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
95 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
96 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
98 Layout1->addWidget( aFrame, 2, 0 );
99 /***************************************************************/
101 myCoordGrp = new QGroupBox( 2, Qt::Horizontal, tr( "GEOM_COORDINATES" ), aFrame );
102 new QLabel( tr( "GEOM_X" ), myCoordGrp );
103 myX = new QLineEdit( myCoordGrp );
104 new QLabel( tr( "GEOM_Y" ), myCoordGrp );
105 myY = new QLineEdit( myCoordGrp );
106 new QLabel( tr( "GEOM_Z" ), myCoordGrp );
107 myZ = new QLineEdit( myCoordGrp );
109 myX->setReadOnly( true );
110 myY->setReadOnly( true );
111 myZ->setReadOnly( true );
113 myX->setEnabled( false );
114 myY->setEnabled( false );
115 myZ->setEnabled( false );
117 QPalette aPal = myX->palette();
118 aPal.setColor( QPalette::Disabled, QColorGroup::Text, QColor( 0, 0, 0 ) ) ;
119 myX->setPalette( aPal );
120 myY->setPalette( aPal );
121 myZ->setPalette( aPal );
127 //=======================================================================
128 // function : ~BasicGUI_PointDlg()
129 // purpose : Destructor
130 //=======================================================================
131 BasicGUI_PointDlg::~BasicGUI_PointDlg()
136 //=================================================================================
139 //=================================================================================
140 void BasicGUI_PointDlg::Init()
142 GroupOnCurve->LineEdit1->setReadOnly( true );
143 GroupRefPoint->LineEdit1->setReadOnly( true );
145 myEdge = GEOM::GEOM_Object::_nil();
146 myRefPoint = GEOM::GEOM_Object::_nil();
148 myEditCurrentArgument = 0;
150 // myGeometryGUI->SetState( 0 );
152 /* Get setting of step value from file configuration */
153 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
154 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
156 /* min, max, step and decimals for spin boxes */
157 GroupXYZ->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
158 GroupXYZ->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
159 GroupXYZ->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
160 GroupXYZ->SpinBox_DX->SetValue(0.0);
161 GroupXYZ->SpinBox_DY->SetValue(0.0);
162 GroupXYZ->SpinBox_DZ->SetValue(0.0);
164 GroupRefPoint->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
165 GroupRefPoint->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
166 GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
167 GroupRefPoint->SpinBox_DX->SetValue(0.0);
168 GroupRefPoint->SpinBox_DY->SetValue(0.0);
169 GroupRefPoint->SpinBox_DZ->SetValue(0.0);
172 GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, 3);
173 GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
175 /* signals and slots connections */
176 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
177 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
178 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
180 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
181 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
182 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
184 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
185 connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
187 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
188 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
189 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
190 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
192 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
193 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
195 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
196 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
197 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
198 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
199 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
200 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
201 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
203 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
204 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
206 initName( tr("GEOM_VERTEX") );
208 ConstructorsClicked( 0 );
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose : Radio button management
215 //=================================================================================
216 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
218 switch ( constructorId )
222 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
224 GroupRefPoint->hide();
225 GroupOnCurve->hide();
234 myEditCurrentArgument = GroupRefPoint->LineEdit1;
235 myEditCurrentArgument->setText("");
236 myRefPoint = GEOM::GEOM_Object::_nil();
238 globalSelection( GEOM_POINT );
241 GroupOnCurve->hide();
243 GroupRefPoint->show();
250 myEditCurrentArgument = GroupOnCurve->LineEdit1;
251 myEditCurrentArgument->setText("");
252 myEdge = GEOM::GEOM_Object::_nil();
254 globalSelection( GEOM_EDGE );
257 GroupRefPoint->hide();
259 GroupOnCurve->show();
270 qApp->processEvents();
272 resize( minimumSize() );
278 //=================================================================================
279 // function : ClickOnOk()
281 //=================================================================================
282 void BasicGUI_PointDlg::ClickOnOk()
284 if ( ClickOnApply() )
289 //=================================================================================
290 // function : ClickOnApply()
292 //=================================================================================
293 bool BasicGUI_PointDlg::ClickOnApply()
299 ConstructorsClicked( getConstructorId() );
304 //=======================================================================
305 // function : ClickOnCancel()
307 //=======================================================================
308 void BasicGUI_PointDlg::ClickOnCancel()
310 GEOMBase_Skeleton::ClickOnCancel();
314 //=================================================================================
315 // function : SelectionIntoArgument()
316 // purpose : Called when selection as changed (for constructors not using local context)
317 //=================================================================================
318 void BasicGUI_PointDlg::SelectionIntoArgument()
320 const int id = getConstructorId();
322 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 )
324 myEditCurrentArgument->setText("");
328 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
331 if ( IObjectCount() == 1 )
333 Standard_Boolean aRes = Standard_False;
334 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
335 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
339 // get CORBA reference to data object
340 TopoDS_Shape aShape = myGeometryGUI->GetShapeReader().GetShape( myGeometryGUI->GetGeomGen(), aSelectedObject );
341 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
343 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
344 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
345 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
346 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
351 myRefPoint = aSelectedObject;
352 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
356 myEdge = aSelectedObject;
357 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
366 //=================================================================================
367 // function : LineEditReturnPressed()
369 //=================================================================================
370 void BasicGUI_PointDlg::LineEditReturnPressed()
372 QLineEdit* send = (QLineEdit*)sender();
373 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
375 myEditCurrentArgument = send;
376 GEOMBase_Skeleton::LineEditReturnPressed();
381 //=================================================================================
382 // function : SetEditCurrentArgument()
384 //=================================================================================
385 void BasicGUI_PointDlg::SetEditCurrentArgument()
387 QPushButton* send = (QPushButton*)sender();
389 if ( send == GroupRefPoint->PushButton1 )
391 GroupRefPoint->LineEdit1->setFocus();
392 myEditCurrentArgument = GroupRefPoint->LineEdit1;
394 globalSelection( GEOM_POINT );
396 else if ( send == GroupOnCurve->PushButton1 )
398 GroupOnCurve->LineEdit1->setFocus();
399 myEditCurrentArgument = GroupOnCurve->LineEdit1;
401 globalSelection( GEOM_EDGE );
406 //=================================================================================
407 // function : enterEvent()
408 // purpose : to reactivate this dialog box when mouse enter onto the window
409 //=================================================================================
410 void BasicGUI_PointDlg::enterEvent(QEvent* e)
412 if ( !GroupConstructors->isEnabled() )
413 ActivateThisDialog();
417 //=================================================================================
418 // function : ActivateThisDialog()
420 //=================================================================================
421 void BasicGUI_PointDlg::ActivateThisDialog( )
423 GEOMBase_Skeleton::ActivateThisDialog();
424 // myGeometryGUI->SetState( 0 );
425 ConstructorsClicked( getConstructorId() );
429 //=================================================================================
430 // function : DeactivateActiveDialog()
431 // purpose : public slot to deactivate if active
432 //=================================================================================
433 void BasicGUI_PointDlg::DeactivateActiveDialog()
435 // myGeometryGUI->SetState( -1 );
436 GEOMBase_Skeleton::DeactivateActiveDialog();
440 //=================================================================================
441 // function : ValueChangedInSpinBox()
443 //=================================================================================
444 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
449 //=======================================================================
450 // funcion : getParameter()
452 //=======================================================================
453 double BasicGUI_PointDlg::getParameter() const
455 return GroupOnCurve->SpinBox_DX->GetValue();
458 //=================================================================================
459 // function : OnPointSelected
461 //=================================================================================
462 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
464 if ( getConstructorId() == 0 )
466 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
467 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
468 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
474 //=================================================================================
475 // function : createOperation
477 //=================================================================================
478 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
480 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
483 //=================================================================================
484 // function : isValid
486 //=================================================================================
487 bool BasicGUI_PointDlg::isValid( QString& msg )
489 const int id = getConstructorId();
493 return !myRefPoint->_is_nil();
495 return !myEdge->_is_nil();
499 //=================================================================================
500 // function : execute
502 //=================================================================================
503 bool BasicGUI_PointDlg::execute( ObjectList& objects )
507 GEOM::GEOM_Object_var anObj;
509 switch ( getConstructorId() )
513 double x = GroupXYZ->SpinBox_DX->GetValue();
514 double y = GroupXYZ->SpinBox_DY->GetValue();
515 double z = GroupXYZ->SpinBox_DZ->GetValue();
517 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
523 double dx = GroupRefPoint->SpinBox_DX->GetValue();
524 double dy = GroupRefPoint->SpinBox_DY->GetValue();
525 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
527 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointWithReference( myRefPoint, dx, dy, dz );
532 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointOnCurve( myEdge, getParameter() );
537 if ( getConstructorId() == 1 || getConstructorId() == 2 )
540 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
542 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
543 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
544 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
545 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
555 if ( !anObj->_is_nil() )
556 objects.push_back( anObj._retn() );
561 //=================================================================================
562 // function : closeEvent
564 //=================================================================================
565 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
567 // myGeometryGUI->SetState( -1 );
568 GEOMBase_Skeleton::closeEvent( e );