1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_PointDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_PointDlg.h"
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
33 #include <GeometryGUI.h>
38 #include <GEOMImpl_Types.hxx>
40 #include <QApplication>
41 #include <QButtonGroup>
42 #include <QHBoxLayout>
44 #include <QRadioButton>
47 #include <TopoDS_Shape.hxx>
48 #include <TopAbs_ShapeEnum.hxx>
50 #include <BRep_Tool.hxx>
52 #include <TColStd_IndexedMapOfInteger.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
58 #define GEOM_POINT_XYZ 0
59 #define GEOM_POINT_REF 1
60 #define GEOM_POINT_EDGE 2
61 #define GEOM_POINT_INTINT 3
62 #define GEOM_POINT_SURF 4
65 //=================================================================================
66 // class : BasicGUI_PointDlg()
67 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
68 // name 'name' and widget flags set to 'f'.
69 // The dialog will by default be modeless, unless you set 'modal' to
70 // TRUE to construct a modal dialog.
71 //=================================================================================
72 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
73 bool modal, Qt::WindowFlags fl )
74 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
76 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
77 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
78 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
79 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
80 QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
81 QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
83 setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
85 /***************************************************************/
86 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
87 mainFrame()->RadioButton1->setIcon( image0 );
88 mainFrame()->RadioButton2->setIcon( image3 );
89 mainFrame()->RadioButton3->setIcon( image1 );
90 mainFrame()->RadioButton4->show();
91 mainFrame()->RadioButton4->setIcon( image4 );
92 mainFrame()->RadioButton5->show();
93 mainFrame()->RadioButton5->setIcon( image5 );
95 QGroupBox* paramGrp = new QGroupBox( centralWidget() );
96 myParamCoord = new QButtonGroup( paramGrp );
97 QHBoxLayout* boxLayout = new QHBoxLayout( paramGrp );
98 boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
99 QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), paramGrp );
100 myParamCoord->addButton( btn, PARAM_VALUE );
101 boxLayout->addWidget( btn );
102 btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), paramGrp );
103 myParamCoord->addButton( btn, COORD_VALUE );
104 boxLayout->addWidget( btn );
105 myParamCoord->setExclusive( true );
106 myParamCoord->button( PARAM_VALUE )->setChecked( true );
108 GroupXYZ = new DlgRef_3Spin( centralWidget() );
109 GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
110 GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
111 GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
112 GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
114 GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
115 GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_POINT_ON_EDGE" ) );
116 GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
117 GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
118 GroupOnCurve->PushButton1->setIcon( image2 );
120 GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
121 GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
122 GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
123 GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
124 GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
125 GroupOnSurface->PushButton1->setIcon( image2 );
127 GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
128 GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
129 GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
130 GroupRefPoint->PushButton1->setIcon( image2 );
131 GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
132 GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
133 GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
135 GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
136 GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
137 GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
138 GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
139 GroupLineIntersection->PushButton1->setIcon( image2 );
140 GroupLineIntersection->PushButton2->setIcon( image2 );
141 GroupLineIntersection->LineEdit2->setEnabled(false);
143 myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
144 QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
145 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
146 myX = new QLineEdit( myCoordGrp );
147 myCoordGrpLayout->addWidget( myX, 0, 1 );
148 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
149 myY = new QLineEdit( myCoordGrp );
150 myCoordGrpLayout->addWidget( myY, 1, 1 );
151 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
152 myZ = new QLineEdit( myCoordGrp );
153 myCoordGrpLayout->addWidget( myZ, 2, 1 );
155 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
156 layout->setMargin( 0 ); layout->setSpacing( 6 );
157 layout->addWidget( paramGrp );
158 layout->addWidget( GroupXYZ );
159 layout->addWidget( GroupOnCurve );
160 layout->addWidget( GroupOnSurface );
161 layout->addWidget( GroupRefPoint );
162 layout->addWidget( GroupLineIntersection );
163 layout->addWidget( myCoordGrp );
165 myX->setReadOnly( true );
166 myY->setReadOnly( true );
167 myZ->setReadOnly( true );
169 myX->setEnabled( false );
170 myY->setEnabled( false );
171 myZ->setEnabled( false );
173 QPalette aPal = myX->palette();
174 aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) );
175 myX->setPalette( aPal );
176 myY->setPalette( aPal );
177 myZ->setPalette( aPal );
179 setHelpFileName( "create_point_page.html" );
185 //=================================================================================
186 // function : ~BasicGUI_PointDlg()
187 // purpose : Destructor
188 //=================================================================================
189 BasicGUI_PointDlg::~BasicGUI_PointDlg()
194 //=================================================================================
197 //=================================================================================
198 void BasicGUI_PointDlg::Init()
200 GroupOnCurve->LineEdit1->setReadOnly( true );
201 GroupOnSurface->LineEdit1->setReadOnly( true );
202 GroupRefPoint->LineEdit1->setReadOnly( true );
203 GroupLineIntersection->LineEdit1->setReadOnly( true );
204 GroupLineIntersection->LineEdit2->setReadOnly( true );
205 GroupLineIntersection->LineEdit1->setEnabled( true );
206 GroupLineIntersection->LineEdit2->setEnabled( false );
208 myEdge = GEOM::GEOM_Object::_nil();
209 myRefPoint = GEOM::GEOM_Object::_nil();
211 myEditCurrentArgument = 0;
213 /* Get setting of step value from file configuration */
214 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
215 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
217 /* min, max, step and decimals for spin boxes */
218 initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
219 initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
220 initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
221 GroupXYZ->SpinBox_DX->setValue( 0.0 );
222 GroupXYZ->SpinBox_DY->setValue( 0.0 );
223 GroupXYZ->SpinBox_DZ->setValue( 0.0 );
225 initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
226 initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
227 initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
228 GroupRefPoint->SpinBox_DX->setValue( 0.0 );
229 GroupRefPoint->SpinBox_DY->setValue( 0.0 );
230 GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
234 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
235 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
237 initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
238 GroupOnSurface->SpinBox_DX->setValue( 0.5 );
239 initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
240 GroupOnSurface->SpinBox_DY->setValue( 0.5 );
242 /* signals and slots connections */
243 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
244 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
246 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
247 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
249 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
251 connect( myParamCoord->button( PARAM_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
252 connect( myParamCoord->button( COORD_VALUE ), SIGNAL( clicked() ), this, SLOT( ClickParamCoord() ) );
253 connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
254 connect( GroupOnCurve->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
256 connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
257 connect( GroupOnSurface->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
259 connect( GroupLineIntersection->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
260 connect( GroupLineIntersection->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
261 connect( GroupLineIntersection->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
262 connect( GroupLineIntersection->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
264 connect( GroupOnCurve->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
265 connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
266 connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
267 connect( GroupXYZ->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
268 connect( GroupXYZ->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
269 connect( GroupXYZ->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
270 connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
271 connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
272 connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
274 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
276 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
277 this, SLOT(SelectionIntoArgument() ) );
279 initName( tr( "GEOM_VERTEX" ) );
281 ConstructorsClicked( 0 );
284 //=================================================================================
285 // function : SetDoubleSpinBoxStep()
286 // purpose : Double spin box management
287 //=================================================================================
288 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
290 GroupOnCurve->SpinBox_DX->setSingleStep(step);
291 GroupXYZ->SpinBox_DX->setSingleStep(step);
292 GroupXYZ->SpinBox_DY->setSingleStep(step);
293 GroupXYZ->SpinBox_DZ->setSingleStep(step);
294 GroupRefPoint->SpinBox_DX->setSingleStep(step);
295 GroupRefPoint->SpinBox_DY->setSingleStep(step);
296 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
297 GroupOnSurface->SpinBox_DX->setSingleStep(step);
298 GroupOnSurface->SpinBox_DY->setSingleStep(step);
302 //=================================================================================
303 // function : ConstructorsClicked()
304 // purpose : Radio button management
305 //=================================================================================
306 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
308 globalSelection(); // close local contexts, if any
310 switch ( constructorId ) {
313 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
315 GroupRefPoint->hide();
316 GroupOnCurve->hide();
317 GroupLineIntersection->hide();
318 GroupOnSurface->hide();
322 myParamCoord->button( PARAM_VALUE )->hide();
323 myParamCoord->button( COORD_VALUE )->hide();
329 myEditCurrentArgument = GroupRefPoint->LineEdit1;
330 myEditCurrentArgument->setText( "" );
331 myRefPoint = GEOM::GEOM_Object::_nil();
332 GroupRefPoint->PushButton1->setDown(true);
333 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
335 myParamCoord->button( PARAM_VALUE )->hide();
336 myParamCoord->button( COORD_VALUE )->hide();
338 GroupOnCurve->hide();
339 GroupLineIntersection->hide();
340 GroupOnSurface->hide();
342 GroupRefPoint->show();
347 case GEOM_POINT_EDGE:
349 myEditCurrentArgument = GroupOnCurve->LineEdit1;
350 myEditCurrentArgument->setText( "" );
351 myEdge = GEOM::GEOM_Object::_nil();
352 GroupOnCurve->PushButton1->setDown(true);
353 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
355 GroupRefPoint->hide();
356 GroupLineIntersection->hide();
357 GroupOnSurface->hide();
359 myParamCoord->button( PARAM_VALUE )->show();
360 myParamCoord->button( COORD_VALUE )->show();
361 GroupOnCurve->show();
364 updateParamCoord( false );
367 case GEOM_POINT_INTINT:
369 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
370 GroupLineIntersection->LineEdit1->setText( "" );
371 GroupLineIntersection->LineEdit2->setText( "" );
372 GroupLineIntersection->LineEdit1->setEnabled( true );
373 GroupLineIntersection->LineEdit2->setEnabled( false );
374 myLine1 = GEOM::GEOM_Object::_nil();
375 myLine2 = GEOM::GEOM_Object::_nil();
376 GroupLineIntersection->PushButton1->setDown(true);
377 GroupLineIntersection->PushButton2->setDown(false);
379 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
381 myParamCoord->button( PARAM_VALUE )->hide();
382 myParamCoord->button( COORD_VALUE )->hide();
384 GroupRefPoint->hide();
385 GroupOnCurve->hide();
386 GroupOnSurface->hide();
390 GroupLineIntersection->show();
393 case GEOM_POINT_SURF:
395 myEditCurrentArgument = GroupOnSurface->LineEdit1;
396 myEditCurrentArgument->setText( "" );
397 myFace = GEOM::GEOM_Object::_nil();
398 GroupOnSurface->PushButton1->setDown(true);
399 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
401 GroupRefPoint->hide();
402 GroupOnCurve->hide();
403 GroupLineIntersection->hide();
405 myParamCoord->button( PARAM_VALUE )->show();
406 myParamCoord->button( COORD_VALUE )->show();
407 GroupOnSurface->show();
410 updateParamCoord( false );
419 qApp->processEvents();
421 resize( minimumSizeHint() );
423 SelectionIntoArgument();
427 //=================================================================================
428 // function : ClickOnOk()
430 //=================================================================================
431 void BasicGUI_PointDlg::ClickOnOk()
438 //=================================================================================
439 // function : ClickOnApply()
441 //=================================================================================
442 bool BasicGUI_PointDlg::ClickOnApply()
448 ConstructorsClicked( getConstructorId() );
453 //=================================================================================
454 // function : SelectionIntoArgument()
455 // purpose : Called when selection as changed (for constructors not using local context)
456 //=================================================================================
457 void BasicGUI_PointDlg::SelectionIntoArgument()
459 const int id = getConstructorId();
461 if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
463 myEditCurrentArgument->setText( "" );
467 myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
470 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
471 SALOME_ListIO aSelList;
472 aSelMgr->selectedObjects(aSelList);
474 if (aSelList.Extent() == 1) {
475 Standard_Boolean aRes = Standard_False;
476 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
477 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
478 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
479 QString aName = GEOMBase::GetName(aSelectedObject);
480 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
482 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
483 if ( id == GEOM_POINT_EDGE || id == GEOM_POINT_INTINT )
484 aNeedType = TopAbs_EDGE;
485 else if ( id == GEOM_POINT_SURF )
486 aNeedType = TopAbs_FACE;
488 TColStd_IndexedMapOfInteger aMap;
489 aSelMgr->GetIndexes(anIO, aMap);
490 if ( aMap.Extent() == 1 ) { // Local Selection
491 int anIndex = aMap( 1 );
492 if ( aNeedType == TopAbs_EDGE )
493 aName += QString( ":edge_%1" ).arg( anIndex );
495 aName += QString( ":vertex_%1" ).arg( anIndex );
497 //Find SubShape Object in Father
498 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
500 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
501 GEOM::GEOM_IShapesOperations_var aShapesOp =
502 getGeomEngine()->GetIShapesOperations(getStudyId());
503 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
506 aSelectedObject = aFindedObject; // get Object from study
508 GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
510 else { // Global Selection
511 if ( aShape.ShapeType() != aNeedType ) {
512 aSelectedObject = GEOM::GEOM_Object::_nil();
514 if ( id == GEOM_POINT_XYZ ) return;
519 if ( aShape.IsNull() || aShape.ShapeType() != aNeedType)
522 if ( id == GEOM_POINT_XYZ ) {
523 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
524 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
525 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
526 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
528 else if ( id == GEOM_POINT_REF ) {
529 myRefPoint = aSelectedObject;
530 GroupRefPoint->LineEdit1->setText( aName );
532 else if ( id == GEOM_POINT_EDGE ) {
533 myEdge = aSelectedObject;
534 GroupOnCurve->LineEdit1->setText( aName );
536 else if ( id == GEOM_POINT_INTINT ) {
537 myEditCurrentArgument->setText( aName );
539 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
540 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
541 myLine1 = aSelectedObject;
542 if ( !myLine1->_is_nil() && myLine2->_is_nil() )
543 GroupLineIntersection->PushButton2->click();
545 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
546 myLine2 = aSelectedObject;
547 if ( !myLine2->_is_nil() && myLine1->_is_nil() )
548 GroupLineIntersection->PushButton1->click();
551 else if ( id == GEOM_POINT_SURF )
553 myFace = aSelectedObject;
554 GroupOnSurface->LineEdit1->setText( aName );
563 //=================================================================================
564 // function : LineEditReturnPressed()
566 //=================================================================================
567 void BasicGUI_PointDlg::LineEditReturnPressed()
569 QLineEdit* send = (QLineEdit*)sender();
570 if ( send == GroupRefPoint->LineEdit1 ||
571 send == GroupOnCurve->LineEdit1 ||
572 send == GroupLineIntersection->LineEdit1 ||
573 send == GroupLineIntersection->LineEdit2 ) {
574 myEditCurrentArgument = send;
575 GEOMBase_Skeleton::LineEditReturnPressed();
580 //=================================================================================
581 // function : SetEditCurrentArgument()
583 //=================================================================================
584 void BasicGUI_PointDlg::SetEditCurrentArgument()
586 globalSelection(); // close local contexts, if any
588 QPushButton* send = (QPushButton*)sender();
590 if ( send == GroupRefPoint->PushButton1 ) {
591 GroupRefPoint->LineEdit1->setFocus();
592 myEditCurrentArgument = GroupRefPoint->LineEdit1;
594 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
596 else if ( send == GroupOnCurve->PushButton1 ) {
597 GroupOnCurve->LineEdit1->setFocus();
598 myEditCurrentArgument = GroupOnCurve->LineEdit1;
600 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
602 else if ( send == GroupOnSurface->PushButton1 )
604 GroupOnSurface->LineEdit1->setFocus();
605 myEditCurrentArgument = GroupOnSurface->LineEdit1;
607 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
609 else if ( send == GroupLineIntersection->PushButton1 ) {
610 GroupLineIntersection->LineEdit1->setFocus();
611 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
612 GroupLineIntersection->PushButton2->setDown( false );
613 GroupLineIntersection->LineEdit1->setEnabled(true);
614 GroupLineIntersection->LineEdit2->setEnabled(false);
615 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
617 else if ( send == GroupLineIntersection->PushButton2 ) {
618 GroupLineIntersection->LineEdit2->setFocus();
619 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
620 GroupLineIntersection->PushButton1->setDown( false );
621 GroupLineIntersection->LineEdit1->setEnabled(false);
622 GroupLineIntersection->LineEdit2->setEnabled(true);
623 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
629 //=================================================================================
630 // function : enterEvent()
631 // purpose : to reactivate this dialog box when mouse enter onto the window
632 //=================================================================================
633 void BasicGUI_PointDlg::enterEvent( QEvent* )
635 if ( !mainFrame()->GroupConstructors->isEnabled() )
636 ActivateThisDialog();
640 //=================================================================================
641 // function : ActivateThisDialog()
643 //=================================================================================
644 void BasicGUI_PointDlg::ActivateThisDialog( )
646 GEOMBase_Skeleton::ActivateThisDialog();
648 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
649 this, SLOT( SelectionIntoArgument() ) );
651 ConstructorsClicked( getConstructorId() );
655 //=================================================================================
656 // function : DeactivateActiveDialog()
657 // purpose : public slot to deactivate if active
658 //=================================================================================
659 void BasicGUI_PointDlg::DeactivateActiveDialog()
661 // myGeomGUI->SetState( -1 );
662 GEOMBase_Skeleton::DeactivateActiveDialog();
666 //=================================================================================
667 // function : ValueChangedInSpinBox()
669 //=================================================================================
670 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
675 //=================================================================================
676 // funcion : getParameter()
678 //=================================================================================
679 double BasicGUI_PointDlg::getParameter() const
681 return GroupOnCurve->SpinBox_DX->value();
685 //=================================================================================
686 // funcion : getUParameter()
688 //=================================================================================
689 double BasicGUI_PointDlg::getUParameter() const
691 return GroupOnSurface->SpinBox_DX->value();
695 //=================================================================================
696 // funcion : getVParameter()
698 //=================================================================================
699 double BasicGUI_PointDlg::getVParameter() const
701 return GroupOnSurface->SpinBox_DY->value();
705 //=================================================================================
706 // function : OnPointSelected
708 //=================================================================================
709 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
711 if ( getConstructorId() == GEOM_POINT_XYZ ) {
712 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
713 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
714 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
720 //=================================================================================
721 // function : createOperation
723 //=================================================================================
724 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
726 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
729 //=================================================================================
730 // function : isValid
732 //=================================================================================
733 bool BasicGUI_PointDlg::isValid( QString& msg )
735 const int id = getConstructorId();
736 if ( id == GEOM_POINT_XYZ ) {
738 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
739 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
740 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
743 else if ( id == GEOM_POINT_REF ) {
745 ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
746 ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
747 ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
749 return !myRefPoint->_is_nil() && ok;
751 else if ( id == GEOM_POINT_EDGE ) {
753 if ( myParamCoord->checkedId() == PARAM_VALUE )
754 ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
756 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
757 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
758 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
760 return !myEdge->_is_nil() && ok;
762 else if ( id == GEOM_POINT_INTINT )
763 return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
764 else if ( id == GEOM_POINT_SURF ) {
766 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
767 ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
768 ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
771 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
772 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
773 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
775 return !myFace->_is_nil() && ok;
780 //=================================================================================
781 // function : execute
783 //=================================================================================
784 bool BasicGUI_PointDlg::execute( ObjectList& objects )
788 GEOM::GEOM_Object_var anObj;
789 QStringList aParameters;
791 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
793 switch ( getConstructorId() ) {
794 case GEOM_POINT_XYZ :
796 double x = GroupXYZ->SpinBox_DX->value();
797 double y = GroupXYZ->SpinBox_DY->value();
798 double z = GroupXYZ->SpinBox_DZ->value();
800 aParameters << GroupXYZ->SpinBox_DX->text();
801 aParameters << GroupXYZ->SpinBox_DY->text();
802 aParameters << GroupXYZ->SpinBox_DZ->text();
804 anObj = anOper->MakePointXYZ( x, y, z );
808 case GEOM_POINT_REF :
810 double dx = GroupRefPoint->SpinBox_DX->value();
811 double dy = GroupRefPoint->SpinBox_DY->value();
812 double dz = GroupRefPoint->SpinBox_DZ->value();
814 aParameters << GroupRefPoint->SpinBox_DX->text();
815 aParameters << GroupRefPoint->SpinBox_DY->text();
816 aParameters << GroupRefPoint->SpinBox_DZ->text();
818 anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
822 case GEOM_POINT_EDGE :
824 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
825 anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
826 aParameters<<GroupOnCurve->SpinBox_DX->text();
828 double x = GroupXYZ->SpinBox_DX->value();
829 double y = GroupXYZ->SpinBox_DY->value();
830 double z = GroupXYZ->SpinBox_DZ->value();
832 aParameters << GroupXYZ->SpinBox_DX->text();
833 aParameters << GroupXYZ->SpinBox_DY->text();
834 aParameters << GroupXYZ->SpinBox_DZ->text();
836 anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
841 case GEOM_POINT_INTINT :
842 anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
845 case GEOM_POINT_SURF :
847 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
848 anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
849 aParameters<<GroupOnSurface->SpinBox_DX->text();
850 aParameters<<GroupOnSurface->SpinBox_DY->text();
852 double x = GroupXYZ->SpinBox_DX->value();
853 double y = GroupXYZ->SpinBox_DY->value();
854 double z = GroupXYZ->SpinBox_DZ->value();
856 aParameters << GroupXYZ->SpinBox_DX->text();
857 aParameters << GroupXYZ->SpinBox_DY->text();
858 aParameters << GroupXYZ->SpinBox_DZ->text();
860 anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
867 const int id = getConstructorId();
868 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
869 id == GEOM_POINT_REF ||
870 id == GEOM_POINT_EDGE ||
871 id == GEOM_POINT_SURF) ) {
872 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
875 if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
877 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
878 aShape.ShapeType() == TopAbs_VERTEX ) {
879 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
880 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
881 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
882 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
891 if ( !anObj->_is_nil() ) {
892 objects.push_back( anObj._retn() );
898 //=================================================================================
899 // function : addSubshapeToStudy
900 // purpose : virtual method to add new SubObjects if local selection
901 //=================================================================================
902 void BasicGUI_PointDlg::addSubshapesToStudy()
904 QMap<QString, GEOM::GEOM_Object_var> objMap;
906 switch ( getConstructorId() ) {
910 objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
912 case GEOM_POINT_EDGE:
913 objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
915 case GEOM_POINT_INTINT:
916 objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
917 objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
919 case GEOM_POINT_SURF:
920 objMap[GroupOnSurface->LineEdit1->text()] = myFace;
923 addSubshapesToFather( objMap );
926 //=================================================================================
927 // function : ClickParamCoord()
929 //=================================================================================
930 void BasicGUI_PointDlg::ClickParamCoord()
932 updateParamCoord( true );
936 //=================================================================================
937 // function : updateParamCoord
939 //=================================================================================
940 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
942 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
943 GroupXYZ->setShown( !isParam );
945 const int id = getConstructorId();
946 if ( id == GEOM_POINT_EDGE ) {
947 GroupOnCurve->TextLabel2->setShown( isParam );
948 GroupOnCurve->SpinBox_DX->setShown( isParam );
950 else if ( id == GEOM_POINT_SURF ) {
951 GroupOnSurface->TextLabel2->setShown( isParam );
952 GroupOnSurface->TextLabel3->setShown( isParam );
953 GroupOnSurface->SpinBox_DX->setShown( isParam );
954 GroupOnSurface->SpinBox_DY->setShown( isParam );
957 qApp->processEvents();
959 resize( minimumSizeHint() );