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 "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Config.h"
35 #include "OCCViewer_Viewer3d.h"
37 #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 <qapplication.h>
50 //=================================================================================
51 // class : BasicGUI_PointDlg()
52 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_PointDlg::BasicGUI_PointDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
58 :GEOMBase_Skeleton(parent, name, Sel, modal, fl )
60 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POINT")));
61 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POINT_EDGE")));
62 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
63 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POINT_REF")));
65 setCaption(tr("GEOM_POINT_TITLE"));
67 QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
68 aFrame->setInsideMargin( 0 );
69 aFrame->setFrameStyle( QFrame::NoFrame );
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_POINTS"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image3);
75 RadioButton3->setPixmap(image1);
77 GroupXYZ = new DlgRef_3Spin( aFrame, "GroupXYZ" );
78 GroupXYZ->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
79 GroupXYZ->TextLabel1->setText(tr("GEOM_X"));
80 GroupXYZ->TextLabel2->setText(tr("GEOM_Y"));
81 GroupXYZ->TextLabel3->setText(tr("GEOM_Z"));
83 GroupOnCurve = new DlgRef_1Sel1Spin( aFrame, "GroupOnCurve" );
84 GroupOnCurve->GroupBox1->setTitle(tr("GEOM_PARAM_POINT"));
85 GroupOnCurve->TextLabel1->setText(tr("GEOM_EDGE"));
86 GroupOnCurve->TextLabel2->setText(tr("GEOM_PARAMETER"));
87 GroupOnCurve->PushButton1->setPixmap(image2);
89 GroupRefPoint = new DlgRef_1Sel3Spin( aFrame, "GoupRefPoint" );
90 GroupRefPoint->GroupBox1->setTitle(tr("GEOM_REF_POINT"));
91 GroupRefPoint->TextLabel1->setText(tr("GEOM_POINT"));
92 GroupRefPoint->PushButton1->setPixmap(image2);
93 GroupRefPoint->TextLabel2->setText(tr("GEOM_DX"));
94 GroupRefPoint->TextLabel3->setText(tr("GEOM_DY"));
95 GroupRefPoint->TextLabel4->setText(tr("GEOM_DZ"));
97 Layout1->addWidget( aFrame, 2, 0 );
98 /***************************************************************/
100 myCoordGrp = new QGroupBox( 2, Qt::Horizontal, tr( "GEOM_COORDINATES" ), aFrame );
101 new QLabel( tr( "GEOM_X" ), myCoordGrp );
102 myX = new QLineEdit( myCoordGrp );
103 new QLabel( tr( "GEOM_Y" ), myCoordGrp );
104 myY = new QLineEdit( myCoordGrp );
105 new QLabel( tr( "GEOM_Z" ), myCoordGrp );
106 myZ = new QLineEdit( myCoordGrp );
108 myX->setReadOnly( true );
109 myY->setReadOnly( true );
110 myZ->setReadOnly( true );
112 myX->setEnabled( false );
113 myY->setEnabled( false );
114 myZ->setEnabled( false );
116 QPalette aPal = myX->palette();
117 aPal.setColor( QPalette::Disabled, QColorGroup::Text, QColor( 0, 0, 0 ) ) ;
118 myX->setPalette( aPal );
119 myY->setPalette( aPal );
120 myZ->setPalette( aPal );
126 //=======================================================================
127 // function : ~BasicGUI_PointDlg()
128 // purpose : Destructor
129 //=======================================================================
130 BasicGUI_PointDlg::~BasicGUI_PointDlg()
135 //=================================================================================
138 //=================================================================================
139 void BasicGUI_PointDlg::Init()
141 GroupOnCurve->LineEdit1->setReadOnly( true );
142 GroupRefPoint->LineEdit1->setReadOnly( true );
144 myEdge = GEOM::GEOM_Object::_nil();
145 myRefPoint = GEOM::GEOM_Object::_nil();
147 myEditCurrentArgument = 0;
149 myGeomGUI->SetState( 0 );
151 /* Get setting of step value from file configuration */
152 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
153 double step = St.toDouble();
155 /* min, max, step and decimals for spin boxes */
156 GroupXYZ->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
157 GroupXYZ->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
158 GroupXYZ->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
159 GroupXYZ->SpinBox_DX->SetValue(0.0);
160 GroupXYZ->SpinBox_DY->SetValue(0.0);
161 GroupXYZ->SpinBox_DZ->SetValue(0.0);
163 GroupRefPoint->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
164 GroupRefPoint->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
165 GroupRefPoint->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
166 GroupRefPoint->SpinBox_DX->SetValue(0.0);
167 GroupRefPoint->SpinBox_DY->SetValue(0.0);
168 GroupRefPoint->SpinBox_DZ->SetValue(0.0);
171 GroupOnCurve->SpinBox_DX->RangeStepAndValidator(0., 1., step, 3);
172 GroupOnCurve->SpinBox_DX->SetValue( 0.5 );
174 /* signals and slots connections */
175 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
176 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
177 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
179 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
180 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
181 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
183 connect(GroupOnCurve->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
184 connect(GroupOnCurve->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
186 connect(GroupOnCurve->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
187 connect(GroupXYZ->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
188 connect(GroupXYZ->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
189 connect(GroupXYZ->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
190 connect(GroupRefPoint->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
191 connect(GroupRefPoint->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
192 connect(GroupRefPoint->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
194 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupOnCurve->SpinBox_DX, SLOT(SetStep(double)));
195 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DX, SLOT(SetStep(double)));
196 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DY, SLOT(SetStep(double)));
197 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupXYZ->SpinBox_DZ, SLOT(SetStep(double)));
198 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DX, SLOT(SetStep(double)));
199 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DY, SLOT(SetStep(double)));
200 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupRefPoint->SpinBox_DZ, SLOT(SetStep(double)));
202 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 initName( tr("GEOM_VERTEX") );
206 ConstructorsClicked( 0 );
210 //=================================================================================
211 // function : ConstructorsClicked()
212 // purpose : Radio button management
213 //=================================================================================
214 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
216 switch ( constructorId )
220 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
222 GroupRefPoint->hide();
223 GroupOnCurve->hide();
232 myEditCurrentArgument = GroupRefPoint->LineEdit1;
233 myEditCurrentArgument->setText("");
234 myRefPoint = GEOM::GEOM_Object::_nil();
236 globalSelection( GEOM_POINT );
239 GroupOnCurve->hide();
241 GroupRefPoint->show();
248 myEditCurrentArgument = GroupOnCurve->LineEdit1;
249 myEditCurrentArgument->setText("");
250 myEdge = GEOM::GEOM_Object::_nil();
252 globalSelection( GEOM_EDGE );
255 GroupRefPoint->hide();
257 GroupOnCurve->show();
268 qApp->processEvents();
270 resize( minimumSize() );
276 //=================================================================================
277 // function : ClickOnOk()
279 //=================================================================================
280 void BasicGUI_PointDlg::ClickOnOk()
282 if ( ClickOnApply() )
287 //=================================================================================
288 // function : ClickOnApply()
290 //=================================================================================
291 bool BasicGUI_PointDlg::ClickOnApply()
297 ConstructorsClicked( getConstructorId() );
302 //=======================================================================
303 // function : ClickOnCancel()
305 //=======================================================================
306 void BasicGUI_PointDlg::ClickOnCancel()
308 GEOMBase_Skeleton::ClickOnCancel();
312 //=================================================================================
313 // function : SelectionIntoArgument()
314 // purpose : Called when selection as changed (for constructors not using local context)
315 //=================================================================================
316 void BasicGUI_PointDlg::SelectionIntoArgument()
318 const int id = getConstructorId();
320 if ( ( id == 1 || id == 2 ) && myEditCurrentArgument != 0 )
322 myEditCurrentArgument->setText("");
326 myRefPoint = myEdge = GEOM::GEOM_Object::_nil();
329 if ( mySelection->IObjectCount() == 1 )
331 Standard_Boolean aRes = Standard_False;
332 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), aRes );
333 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
337 // get CORBA reference to data object
338 TopoDS_Shape aShape = GeometryGUI::GetGeomGUI()->GetShapeReader().GetShape(
339 GeometryGUI::GetGeomGUI()->GetGeomGen(), aSelectedObject );
340 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
342 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
343 GroupXYZ->SpinBox_DX->SetValue( aPnt.X() );
344 GroupXYZ->SpinBox_DY->SetValue( aPnt.Y() );
345 GroupXYZ->SpinBox_DZ->SetValue( aPnt.Z() );
350 myRefPoint = aSelectedObject;
351 GroupRefPoint->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
355 myEdge = aSelectedObject;
356 GroupOnCurve->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
365 //=================================================================================
366 // function : LineEditReturnPressed()
368 //=================================================================================
369 void BasicGUI_PointDlg::LineEditReturnPressed()
371 QLineEdit* send = (QLineEdit*)sender();
372 if ( send == GroupRefPoint->LineEdit1 || send == GroupOnCurve->LineEdit1 )
374 myEditCurrentArgument = send;
375 GEOMBase_Skeleton::LineEditReturnPressed();
380 //=================================================================================
381 // function : SetEditCurrentArgument()
383 //=================================================================================
384 void BasicGUI_PointDlg::SetEditCurrentArgument()
386 QPushButton* send = (QPushButton*)sender();
388 if ( send == GroupRefPoint->PushButton1 )
390 GroupRefPoint->LineEdit1->setFocus();
391 myEditCurrentArgument = GroupRefPoint->LineEdit1;
393 globalSelection( GEOM_POINT );
395 else if ( send == GroupOnCurve->PushButton1 )
397 GroupOnCurve->LineEdit1->setFocus();
398 myEditCurrentArgument = GroupOnCurve->LineEdit1;
400 globalSelection( GEOM_EDGE );
405 //=================================================================================
406 // function : enterEvent()
407 // purpose : to reactivate this dialog box when mouse enter onto the window
408 //=================================================================================
409 void BasicGUI_PointDlg::enterEvent(QEvent* e)
411 if ( !GroupConstructors->isEnabled() )
412 ActivateThisDialog();
416 //=================================================================================
417 // function : ActivateThisDialog()
419 //=================================================================================
420 void BasicGUI_PointDlg::ActivateThisDialog( )
422 GEOMBase_Skeleton::ActivateThisDialog();
423 myGeomGUI->SetState( 0 );
424 ConstructorsClicked( getConstructorId() );
428 //=================================================================================
429 // function : DeactivateActiveDialog()
430 // purpose : public slot to deactivate if active
431 //=================================================================================
432 void BasicGUI_PointDlg::DeactivateActiveDialog()
434 myGeomGUI->SetState( -1 );
435 GEOMBase_Skeleton::DeactivateActiveDialog();
439 //=================================================================================
440 // function : ValueChangedInSpinBox()
442 //=================================================================================
443 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
448 //=======================================================================
449 // funcion : getParameter()
451 //=======================================================================
452 double BasicGUI_PointDlg::getParameter() const
454 return GroupOnCurve->SpinBox_DX->GetValue();
457 //=================================================================================
458 // function : OnPointSelected
460 //=================================================================================
461 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
463 if ( getConstructorId() == 0 )
465 GroupXYZ->SpinBox_DX->SetValue( thePnt.X() );
466 GroupXYZ->SpinBox_DY->SetValue( thePnt.Y() );
467 GroupXYZ->SpinBox_DZ->SetValue( thePnt.Z() );
473 //=================================================================================
474 // function : createOperation
476 //=================================================================================
477 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
479 return getGeomEngine()->GetIBasicOperations( getStudyId() );
482 //=================================================================================
483 // function : isValid
485 //=================================================================================
486 bool BasicGUI_PointDlg::isValid( QString& msg )
488 const int id = getConstructorId();
492 return !myRefPoint->_is_nil();
494 return !myEdge->_is_nil();
498 //=================================================================================
499 // function : execute
501 //=================================================================================
502 bool BasicGUI_PointDlg::execute( ObjectList& objects )
506 GEOM::GEOM_Object_var anObj;
508 switch ( getConstructorId() )
512 double x = GroupXYZ->SpinBox_DX->GetValue();
513 double y = GroupXYZ->SpinBox_DY->GetValue();
514 double z = GroupXYZ->SpinBox_DZ->GetValue();
516 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointXYZ( x,y,z );
522 double dx = GroupRefPoint->SpinBox_DX->GetValue();
523 double dy = GroupRefPoint->SpinBox_DY->GetValue();
524 double dz = GroupRefPoint->SpinBox_DZ->GetValue();
526 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointWithReference( myRefPoint, dx, dy, dz );
531 anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakePointOnCurve( myEdge, getParameter() );
536 if ( getConstructorId() == 1 || getConstructorId() == 2 )
539 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
541 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
542 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
543 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
544 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
554 if ( !anObj->_is_nil() )
555 objects.push_back( anObj._retn() );
560 //=================================================================================
561 // function : closeEvent
563 //=================================================================================
564 void BasicGUI_PointDlg::closeEvent( QCloseEvent* e )
566 myGeomGUI->SetState( -1 );
567 GEOMBase_Skeleton::closeEvent( e );