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 if ( aShape.ShapeType() != TopAbs_VERTEX )
349 TColStd_IndexedMapOfInteger aMap;
351 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
353 if ( aMap.Extent() == 1 )
355 int anIndex = aMap( 1 );
356 TopTools_IndexedMapOfShape aShapes;
357 TopExp::MapShapes( aShape, aShapes );
358 aShape = aShapes.FindKey( anIndex );
360 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
367 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
368 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
369 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
370 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
374 myRefPoint = aSelectedObject;
375 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
379 myEdge = aSelectedObject;
380 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
389 //=================================================================================
390 // function : LineEditReturnPressed()
392 //=================================================================================
393 void BasicGUI_PointDlg::LineEditReturnPressed()
395 QLineEdit* send = (QLineEdit*)sender();
396 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
398 myEditCurrentArgument = send;
399 GEOMBase_Skeleton::LineEditReturnPressed();
404 //=================================================================================
405 // function : SetEditCurrentArgument()
407 //=================================================================================
408 void BasicGUI_PointDlg::SetEditCurrentArgument()
410 QPushButton* send = (QPushButton*)sender();
412 if ( send == GroupRefPoint->PushButton1 )
414 GroupRefPoint->LineEdit1->setFocus();
415 myEditCurrentArgument = GroupRefPoint->LineEdit1;
417 globalSelection( GEOM_POINT );
419 else if ( send == GroupOnCurve->PushButton1 )
421 GroupOnCurve->LineEdit1->setFocus();
422 myEditCurrentArgument = GroupOnCurve->LineEdit1;
424 globalSelection( GEOM_EDGE );
429 //=================================================================================
430 // function : enterEvent()
431 // purpose : to reactivate this dialog box when mouse enter onto the window
432 //=================================================================================
433 void BasicGUI_PointDlg::enterEvent(QEvent* e)
435 if ( !GroupConstructors->isEnabled() )
436 ActivateThisDialog();
440 //=================================================================================
441 // function : ActivateThisDialog()
443 //=================================================================================
444 void BasicGUI_PointDlg::ActivateThisDialog( )
446 GEOMBase_Skeleton::ActivateThisDialog();
447 // myGeometryGUI->SetState( 0 );
448 ConstructorsClicked( getConstructorId() );
452 //=================================================================================
453 // function : DeactivateActiveDialog()
454 // purpose : public slot to deactivate if active
455 //=================================================================================
456 void BasicGUI_PointDlg::DeactivateActiveDialog()
458 // myGeometryGUI->SetState( -1 );
459 GEOMBase_Skeleton::DeactivateActiveDialog();
463 //=================================================================================
464 // function : ValueChangedInSpinBox()
466 //=================================================================================
467 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
472 //=======================================================================
473 // funcion : getParameter()
475 //=======================================================================
476 double BasicGUI_PointDlg::getParameter() const
478 return GroupOnCurve->SpinBox_DX->GetValue();
481 //=================================================================================
482 // function : OnPointSelected
484 //=================================================================================
485 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
487 if ( getConstructorId() == 0 )
489 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
490 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
491 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
497 //=================================================================================
498 // function : createOperation
500 //=================================================================================
501 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
503 return myGeometryGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
506 //=================================================================================
507 // function : isValid
509 //=================================================================================
510 bool BasicGUI_PointDlg::isValid( QString& msg )
512 const int id = getConstructorId();
516 return !myRefPoint->_is_nil();
518 return !myEdge->_is_nil();
522 //=================================================================================
523 // function : execute
525 //=================================================================================
526 bool BasicGUI_PointDlg::execute( ObjectList& objects )
530 GEOM::GEOM_Object_var anObj;
532 switch ( getConstructorId() )
536 double x = GroupXYZ->SpinBox_DX->GetValue();
537 double y = GroupXYZ->SpinBox_DY->GetValue();
538 double z = GroupXYZ->SpinBox_DZ->GetValue();
540 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
546 double dx = GroupRefPoint->SpinBox_DX->GetValue();
547 double dy = GroupRefPoint->SpinBox_DY->GetValue();
548 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
550 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointWithReference( myRefPoint, dx, dy, dz );
555 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointOnCurve( myEdge, getParameter() );
560 if ( getConstructorId() == 1 || getConstructorId() == 2 )
563 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
565 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
566 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
567 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
568 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
578 if ( !anObj->_is_nil() )
580 //printf( "--> a valid point is created\n" );
581 objects.push_back( anObj._retn() );
587 //=================================================================================
588 // function : closeEvent
590 //=================================================================================
591 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
593 // myGeometryGUI->SetState( -1 );
594 GEOMBase_Skeleton::closeEvent( e );