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_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,
61 const char* name, bool modal, WFlags fl)
62 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, fl )
64 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
65 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
66 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POINT_REF")));
69 setCaption(tr("GEOM_POINT_TITLE"));
71 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
72 aFrame->setInsideMargin( 0 );
73 aFrame->setFrameStyle( QFrame::NoFrame );
75 /***************************************************************/
76 GroupConstructors->setTitle(tr("GEOM_POINTS"));
77 RadioButton1->setPixmap(image0);
78 RadioButton2->setPixmap(image3);
79 RadioButton3->setPixmap(image1);
81 GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
82 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
83 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
84 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
85 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
87 GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
88 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
89 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
90 GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
91 GroupOnCurve->PushButton1->setPixmap(image2);
93 GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
94 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
95 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
96 GroupRefPoint->PushButton1->setPixmap(image2);
97 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
98 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
99 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
101 Layout1->addWidget( aFrame, 2, 0 );
102 /***************************************************************/
104 myCoordGrp = new QGroupBox( 2, Qt::Horizontal, tr( "GEOM_COORDINATES" ), aFrame );
105 new QLabel( tr( "GEOM_X" ), myCoordGrp );
106 myX = new QLineEdit( myCoordGrp );
107 new QLabel( tr( "GEOM_Y" ), myCoordGrp );
108 myY = new QLineEdit( myCoordGrp );
109 new QLabel( tr( "GEOM_Z" ), myCoordGrp );
110 myZ = new QLineEdit( myCoordGrp );
112 myX->setReadOnly( true );
113 myY->setReadOnly( true );
114 myZ->setReadOnly( true );
116 myX->setEnabled( false );
117 myY->setEnabled( false );
118 myZ->setEnabled( false );
120 QPalette aPal = myX->palette();
121 aPal.setColor( QPalette::Disabled, QColorGroup::Text, QColor( 0, 0, 0 ) ) ;
122 myX->setPalette( aPal );
123 myY->setPalette( aPal );
124 myZ->setPalette( aPal );
126 setHelpFileName("point.htm");
132 //=================================================================================
133 // function : ~BasicGUI_PointDlg()
134 // purpose : Destructor
135 //=================================================================================
136 BasicGUI_PointDlg::~BasicGUI_PointDlg()
141 //=================================================================================
144 //=================================================================================
145 void BasicGUI_PointDlg::Init()
147 GroupOnCurve->LineEdit1->setReadOnly( true );
148 GroupRefPoint->LineEdit1->setReadOnly( true );
150 myEdge = GEOM::GEOM_Object::_nil();
151 myRefPoint = GEOM::GEOM_Object::_nil();
153 myEditCurrentArgument = 0;
155 /* Get setting of step value from file configuration */
156 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
157 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
159 /* min, max, step and decimals for spin boxes */
160 GroupXYZ->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
161 GroupXYZ->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
162 GroupXYZ->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
163 GroupXYZ->SpinBox_DX->SetValue(0.0);
164 GroupXYZ->SpinBox_DY->SetValue(0.0);
165 GroupXYZ->SpinBox_DZ->SetValue(0.0);
167 GroupRefPoint->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
168 GroupRefPoint->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
169 GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
170 GroupRefPoint->SpinBox_DX->SetValue(0.0);
171 GroupRefPoint->SpinBox_DY->SetValue(0.0);
172 GroupRefPoint->SpinBox_DZ->SetValue(0.0);
175 GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, 3);
176 GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
178 /* signals and slots connections */
179 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
180 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
181 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
183 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
184 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
185 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
187 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
188 connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
190 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
192 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
193 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
194 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
195 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
196 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
198 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
199 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
200 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
201 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
202 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
203 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
204 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
206 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
207 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
209 initName( tr("GEOM_VERTEX") );
211 ConstructorsClicked( 0 );
215 //=================================================================================
216 // function : ConstructorsClicked()
217 // purpose : Radio button management
218 //=================================================================================
219 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
221 switch ( constructorId )
225 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
227 GroupRefPoint->hide();
228 GroupOnCurve->hide();
237 myEditCurrentArgument = GroupRefPoint->LineEdit1;
238 myEditCurrentArgument->setText("");
239 myRefPoint = GEOM::GEOM_Object::_nil();
241 globalSelection( GEOM_POINT );
244 GroupOnCurve->hide();
246 GroupRefPoint->show();
253 myEditCurrentArgument = GroupOnCurve->LineEdit1;
254 myEditCurrentArgument->setText("");
255 myEdge = GEOM::GEOM_Object::_nil();
257 globalSelection( GEOM_EDGE );
260 GroupRefPoint->hide();
262 GroupOnCurve->show();
273 qApp->processEvents();
275 resize( minimumSize() );
277 SelectionIntoArgument();
281 //=================================================================================
282 // function : ClickOnOk()
284 //=================================================================================
285 void BasicGUI_PointDlg::ClickOnOk()
292 //=================================================================================
293 // function : ClickOnApply()
295 //=================================================================================
296 bool BasicGUI_PointDlg::ClickOnApply()
302 ConstructorsClicked( getConstructorId() );
307 //=================================================================================
308 // function : ClickOnCancel()
310 //=================================================================================
311 void BasicGUI_PointDlg::ClickOnCancel()
313 GEOMBase_Skeleton::ClickOnCancel();
317 //=================================================================================
318 // function : SelectionIntoArgument()
319 // purpose : Called when selection as changed (for constructors not using local context)
320 //=================================================================================
321 void BasicGUI_PointDlg::SelectionIntoArgument()
323 const int id = getConstructorId();
325 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 )
327 myEditCurrentArgument->setText("");
331 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
334 if ( IObjectCount() == 1 )
336 Standard_Boolean aRes = Standard_False;
337 Handle(SALOME_InteractiveObject) anIO = firstIObject();
338 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
339 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
343 // get CORBA reference to data object
344 TopoDS_Shape aShape = myGeomGUI->GetShapeReader().GetShape
345 ( myGeomGUI->GetGeomGen(), aSelectedObject );
346 if ( aShape.IsNull() )
349 if ( aShape.ShapeType() != TopAbs_VERTEX )
351 TColStd_IndexedMapOfInteger aMap;
352 LightApp_Application* anApp =
353 (LightApp_Application*)(SUIT_Session::session()->activeApplication());
354 anApp->selectionMgr()->GetIndexes( anIO, aMap );
356 if ( aMap.Extent() == 1 )
358 int anIndex = aMap( 1 );
359 TopTools_IndexedMapOfShape aShapes;
360 TopExp::MapShapes( aShape, aShapes );
361 aShape = aShapes.FindKey( anIndex );
363 if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
370 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
371 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
372 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
373 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
377 myRefPoint = aSelectedObject;
378 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
382 myEdge = aSelectedObject;
383 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
392 //=================================================================================
393 // function : LineEditReturnPressed()
395 //=================================================================================
396 void BasicGUI_PointDlg::LineEditReturnPressed()
398 QLineEdit* send = (QLineEdit*)sender();
399 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
401 myEditCurrentArgument = send;
402 GEOMBase_Skeleton::LineEditReturnPressed();
407 //=================================================================================
408 // function : SetEditCurrentArgument()
410 //=================================================================================
411 void BasicGUI_PointDlg::SetEditCurrentArgument()
413 QPushButton* send = (QPushButton*)sender();
415 if ( send == GroupRefPoint->PushButton1 )
417 GroupRefPoint->LineEdit1->setFocus();
418 myEditCurrentArgument = GroupRefPoint->LineEdit1;
420 globalSelection( GEOM_POINT );
422 else if ( send == GroupOnCurve->PushButton1 )
424 GroupOnCurve->LineEdit1->setFocus();
425 myEditCurrentArgument = GroupOnCurve->LineEdit1;
427 globalSelection( GEOM_EDGE );
432 //=================================================================================
433 // function : enterEvent()
434 // purpose : to reactivate this dialog box when mouse enter onto the window
435 //=================================================================================
436 void BasicGUI_PointDlg::enterEvent(QEvent* e)
438 if ( !GroupConstructors->isEnabled() )
439 ActivateThisDialog();
443 //=================================================================================
444 // function : ActivateThisDialog()
446 //=================================================================================
447 void BasicGUI_PointDlg::ActivateThisDialog( )
449 GEOMBase_Skeleton::ActivateThisDialog();
450 // myGeomGUI->SetState( 0 );
451 ConstructorsClicked( getConstructorId() );
455 //=================================================================================
456 // function : DeactivateActiveDialog()
457 // purpose : public slot to deactivate if active
458 //=================================================================================
459 void BasicGUI_PointDlg::DeactivateActiveDialog()
461 // myGeomGUI->SetState( -1 );
462 GEOMBase_Skeleton::DeactivateActiveDialog();
466 //=================================================================================
467 // function : ValueChangedInSpinBox()
469 //=================================================================================
470 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
475 //=================================================================================
476 // funcion : getParameter()
478 //=================================================================================
479 double BasicGUI_PointDlg::getParameter() const
481 return GroupOnCurve->SpinBox_DX->GetValue();
484 //=================================================================================
485 // function : OnPointSelected
487 //=================================================================================
488 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
490 if ( getConstructorId() == 0 )
492 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
493 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
494 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
500 //=================================================================================
501 // function : createOperation
503 //=================================================================================
504 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
506 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
509 //=================================================================================
510 // function : isValid
512 //=================================================================================
513 bool BasicGUI_PointDlg::isValid( QString& msg )
515 const int id = getConstructorId();
519 return !myRefPoint->_is_nil();
521 return !myEdge->_is_nil();
525 //=================================================================================
526 // function : execute
528 //=================================================================================
529 bool BasicGUI_PointDlg::execute( ObjectList& objects )
533 GEOM::GEOM_Object_var anObj;
535 switch ( getConstructorId() )
539 double x = GroupXYZ->SpinBox_DX->GetValue();
540 double y = GroupXYZ->SpinBox_DY->GetValue();
541 double z = GroupXYZ->SpinBox_DZ->GetValue();
543 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
549 double dx = GroupRefPoint->SpinBox_DX->GetValue();
550 double dy = GroupRefPoint->SpinBox_DY->GetValue();
551 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
553 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
554 MakePointWithReference( myRefPoint, dx, dy, dz );
559 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->
560 MakePointOnCurve( myEdge, getParameter() );
565 if ( getConstructorId() == 1 || getConstructorId() == 2 )
568 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
570 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
571 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
572 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
573 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
583 if ( !anObj->_is_nil() )
585 //printf( "--> a valid point is created\n" );
586 objects.push_back( anObj._retn() );
592 //=================================================================================
593 // function : closeEvent
595 //=================================================================================
596 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
598 GEOMBase_Skeleton::closeEvent( e );