1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BasicGUI_PointDlg.h"
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SalomeApp_Application.h>
32 #include <LightApp_SelectionMgr.h>
34 #include <GeometryGUI.h>
39 #include <GEOMImpl_Types.hxx>
41 #include <QApplication>
42 #include <QButtonGroup>
43 #include <QHBoxLayout>
45 #include <QRadioButton>
50 #include <TopoDS_Shape.hxx>
51 #include <TopAbs_ShapeEnum.hxx>
53 #include <BRep_Tool.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
56 #include <TopTools_IndexedMapOfShape.hxx>
60 #define LENGTH_VALUE 2
62 #define GEOM_POINT_XYZ 0
63 #define GEOM_POINT_REF 1
64 #define GEOM_POINT_EDGE 2
65 #define GEOM_POINT_INTINT 3
66 #define GEOM_POINT_SURF 4
71 //=================================================================================
72 // class : BasicGUI_PointDlg()
73 // purpose : Constructs a BasicGUI_PointDlg which is a child of 'parent', with the
74 // name 'name' and widget flags set to 'f'.
75 // The dialog will by default be modeless, unless you set 'modal' to
76 // TRUE to construct a modal dialog.
77 //=================================================================================
78 BasicGUI_PointDlg::BasicGUI_PointDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
79 bool modal, Qt::WindowFlags fl )
80 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
83 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT") ) );
84 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_EDGE" ) ) );
85 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
86 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_REF" ) ) );
87 QPixmap image4( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_LINES") ) );
88 QPixmap image5( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POINT_FACE" ) ) );
89 QPixmap image6( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_LINE" ) ) );
90 QPixmap image7( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_WIRE" ) ) );
92 setWindowTitle( tr( "GEOM_POINT_TITLE" ) );
94 /***************************************************************/
95 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_POINTS" ) );
96 mainFrame()->RadioButton1->setIcon( image0 );
97 mainFrame()->RadioButton2->setIcon( image3 );
98 mainFrame()->RadioButton3->setIcon( image1 );
99 mainFrame()->RadioButton4->show();
100 mainFrame()->RadioButton4->setIcon( image4 );
101 mainFrame()->RadioButton5->show();
102 mainFrame()->RadioButton5->setIcon( image5 );
104 myParamGroup = new QGroupBox( centralWidget() );
105 myParamCoord = new QButtonGroup( myParamGroup );
106 QHBoxLayout* boxLayout = new QHBoxLayout( myParamGroup );
107 boxLayout->setMargin( MARGIN ); boxLayout->setSpacing( SPACING );
108 QRadioButton* btn = new QRadioButton( tr( "GEOM_PARAM_VALUE" ), myParamGroup );
109 myParamCoord->addButton( btn, PARAM_VALUE );
110 boxLayout->addWidget( btn );
111 btn = new QRadioButton( tr( "GEOM_LENGTH_VALUE" ), myParamGroup );
112 myParamCoord->addButton( btn, LENGTH_VALUE );
113 boxLayout->addWidget( btn );
114 btn = new QRadioButton( tr( "GEOM_COORD_VALUE" ), myParamGroup );
115 myParamCoord->addButton( btn, COORD_VALUE );
116 boxLayout->addWidget( btn );
117 myParamCoord->setExclusive( true );
118 myParamCoord->button( PARAM_VALUE )->setChecked( true );
120 GroupXYZ = new DlgRef_3Spin( centralWidget() );
121 GroupXYZ->GroupBox1->setTitle( tr( "GEOM_COORDINATES" ) );
122 GroupXYZ->TextLabel1->setText( tr( "GEOM_X" ) );
123 GroupXYZ->TextLabel2->setText( tr( "GEOM_Y" ) );
124 GroupXYZ->TextLabel3->setText( tr( "GEOM_Z" ) );
126 GroupOnCurve = new DlgRef_1Sel1Spin( centralWidget() );
127 GroupOnCurve->GroupBox1->setTitle( tr( "GEOM_POINT_ON_EDGE" ) );
128 GroupOnCurve->TextLabel1->setText( tr( "GEOM_EDGE" ) );
129 GroupOnCurve->TextLabel2->setText( tr( "GEOM_PARAMETER" ) );
130 GroupOnCurve->PushButton1->setIcon( image2 );
132 GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
133 GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
134 GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
135 GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
136 GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
137 GroupOnSurface->PushButton1->setIcon( image2 );
139 GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
140 GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
141 GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
142 GroupRefPoint->PushButton1->setIcon( image2 );
143 GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
144 GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
145 GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
147 /* popup menu for line intersect buttons */
148 myBtnPopup = new QMenu(this);
149 QIcon ico_line = QIcon( image6 );
150 QIcon ico_wire = QIcon( image7 );
151 myActions[myBtnPopup->addAction( ico_line, tr( "GEOM_EDGE" ) )] = 0;
152 myActions[myBtnPopup->addAction( ico_wire, tr( "GEOM_WIRE" ) )] = 1;
154 GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
155 GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
156 GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
157 GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
158 GroupLineIntersection->PushButton1->setIcon( image2 );
159 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
160 GroupLineIntersection->PushButton2->setIcon( image2 );
161 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
162 GroupLineIntersection->LineEdit2->setEnabled(false);
164 myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
165 QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
166 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
167 myX = new QLineEdit( myCoordGrp );
168 myCoordGrpLayout->addWidget( myX, 0, 1 );
169 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
170 myY = new QLineEdit( myCoordGrp );
171 myCoordGrpLayout->addWidget( myY, 1, 1 );
172 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
173 myZ = new QLineEdit( myCoordGrp );
174 myCoordGrpLayout->addWidget( myZ, 2, 1 );
176 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
177 layout->setMargin( 0 ); layout->setSpacing( 6 );
178 layout->addWidget( myParamGroup );
179 layout->addWidget( GroupXYZ );
180 layout->addWidget( GroupOnCurve );
181 layout->addWidget( GroupOnSurface );
182 layout->addWidget( GroupRefPoint );
183 layout->addWidget( GroupLineIntersection );
184 layout->addWidget( myCoordGrp );
186 myX->setReadOnly( true );
187 myY->setReadOnly( true );
188 myZ->setReadOnly( true );
190 myX->setEnabled( false );
191 myY->setEnabled( false );
192 myZ->setEnabled( false );
194 QPalette aPal = myX->palette();
195 aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) );
196 myX->setPalette( aPal );
197 myY->setPalette( aPal );
198 myZ->setPalette( aPal );
200 setHelpFileName( "create_point_page.html" );
206 //=================================================================================
207 // function : ~BasicGUI_PointDlg()
208 // purpose : Destructor
209 //=================================================================================
210 BasicGUI_PointDlg::~BasicGUI_PointDlg()
215 //=================================================================================
218 //=================================================================================
219 void BasicGUI_PointDlg::Init()
221 GroupOnCurve->LineEdit1->setReadOnly( true );
222 GroupOnSurface->LineEdit1->setReadOnly( true );
223 GroupRefPoint->LineEdit1->setReadOnly( true );
224 GroupLineIntersection->LineEdit1->setReadOnly( true );
225 GroupLineIntersection->LineEdit2->setReadOnly( true );
226 GroupLineIntersection->LineEdit1->setEnabled( true );
227 GroupLineIntersection->LineEdit2->setEnabled( false );
229 myEdge = GEOM::GEOM_Object::_nil();
230 myRefPoint = GEOM::GEOM_Object::_nil();
231 myNeedType = TopAbs_VERTEX;
233 myEditCurrentArgument = 0;
235 /* Get setting of step value from file configuration */
236 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
237 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
239 /* min, max, step and decimals for spin boxes */
240 initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
241 initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
242 initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
243 GroupXYZ->SpinBox_DX->setValue( 0.0 );
244 GroupXYZ->SpinBox_DY->setValue( 0.0 );
245 GroupXYZ->SpinBox_DZ->setValue( 0.0 );
247 initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
248 initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
249 initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
250 GroupRefPoint->SpinBox_DX->setValue( 0.0 );
251 GroupRefPoint->SpinBox_DY->setValue( 0.0 );
252 GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
256 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision" );
257 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
259 initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision" );
260 GroupOnSurface->SpinBox_DX->setValue( 0.5 );
261 initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision" );
262 GroupOnSurface->SpinBox_DY->setValue( 0.5 );
264 /* signals and slots connections */
265 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
266 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
268 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
269 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
271 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
273 connect( myParamCoord, SIGNAL( buttonClicked( int ) ), this, SLOT( ClickParamCoord( int ) ) );
274 connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
275 connect( GroupOnCurve->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
277 connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
278 connect( GroupOnSurface->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
280 connect( myBtnPopup, SIGNAL( triggered( QAction* ) ), SLOT( onBtnPopup( QAction* ) ) );
281 connect( GroupLineIntersection->PushButton1, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
282 connect( GroupLineIntersection->PushButton2, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
283 connect( GroupLineIntersection->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
284 connect( GroupLineIntersection->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
286 connect( GroupOnCurve->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
287 connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
288 connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
289 connect( GroupXYZ->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
290 connect( GroupXYZ->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
291 connect( GroupXYZ->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
292 connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
293 connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
294 connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
296 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
298 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
299 this, SLOT(SelectionIntoArgument() ) );
301 initName( tr( "GEOM_VERTEX" ) );
303 ConstructorsClicked( 0 );
306 //=================================================================================
307 // function : SetDoubleSpinBoxStep()
308 // purpose : Double spin box management
309 //=================================================================================
310 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
312 GroupOnCurve->SpinBox_DX->setSingleStep(step);
313 GroupXYZ->SpinBox_DX->setSingleStep(step);
314 GroupXYZ->SpinBox_DY->setSingleStep(step);
315 GroupXYZ->SpinBox_DZ->setSingleStep(step);
316 GroupRefPoint->SpinBox_DX->setSingleStep(step);
317 GroupRefPoint->SpinBox_DY->setSingleStep(step);
318 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
322 //=================================================================================
323 // function : ConstructorsClicked()
324 // purpose : Radio button management
325 //=================================================================================
326 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
328 switch ( constructorId ) {
331 globalSelection(); // close local contexts, if any
332 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
334 GroupRefPoint->hide();
335 GroupOnCurve->hide();
336 GroupLineIntersection->hide();
337 GroupOnSurface->hide();
339 myParamGroup->hide();
345 globalSelection(); // close local contexts, if any
346 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
348 myEditCurrentArgument = GroupRefPoint->LineEdit1;
349 myEditCurrentArgument->setText( "" );
350 myRefPoint = GEOM::GEOM_Object::_nil();
351 GroupRefPoint->PushButton1->setDown(true);
352 myParamGroup->hide();
354 GroupOnCurve->hide();
355 GroupLineIntersection->hide();
356 GroupOnSurface->hide();
357 GroupRefPoint->show();
361 case GEOM_POINT_EDGE:
363 globalSelection(); // close local contexts, if any
364 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
366 myEditCurrentArgument = GroupOnCurve->LineEdit1;
367 myEditCurrentArgument->setText( "" );
368 myEdge = GEOM::GEOM_Object::_nil();
369 GroupOnCurve->PushButton1->setDown(true);
370 GroupRefPoint->hide();
371 GroupLineIntersection->hide();
372 GroupOnSurface->hide();
373 myParamGroup->show();
374 myParamCoord->button( LENGTH_VALUE )->show();
375 myParamCoord->button( PARAM_VALUE )->setChecked( true );
376 GroupOnCurve->show();
378 updateParamCoord( false );
381 case GEOM_POINT_INTINT:
383 globalSelection(); // close local contexts, if any
384 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
385 myNeedType = TopAbs_EDGE;
387 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
388 GroupLineIntersection->LineEdit1->setText( "" );
389 GroupLineIntersection->LineEdit2->setText( "" );
390 GroupLineIntersection->LineEdit1->setEnabled( true );
391 GroupLineIntersection->LineEdit2->setEnabled( false );
392 myLine1 = GEOM::GEOM_Object::_nil();
393 myLine2 = GEOM::GEOM_Object::_nil();
394 GroupLineIntersection->PushButton1->setDown(true);
395 GroupLineIntersection->PushButton2->setDown(false);
396 myParamGroup->hide();
398 GroupRefPoint->hide();
399 GroupOnCurve->hide();
400 GroupOnSurface->hide();
402 GroupLineIntersection->show();
405 case GEOM_POINT_SURF:
407 globalSelection(); // close local contexts, if any
408 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
410 myEditCurrentArgument = GroupOnSurface->LineEdit1;
411 myEditCurrentArgument->setText( "" );
412 myFace = GEOM::GEOM_Object::_nil();
413 GroupOnSurface->PushButton1->setDown(true);
414 GroupRefPoint->hide();
415 GroupOnCurve->hide();
416 GroupLineIntersection->hide();
417 myParamGroup->show();
418 myParamCoord->button( LENGTH_VALUE )->hide();
419 myParamCoord->button( PARAM_VALUE )->setChecked(true);
420 GroupOnSurface->show();
422 updateParamCoord( false );
431 QTimer::singleShot(50, this, SLOT(updateSize()));
433 SelectionIntoArgument();
437 //=================================================================================
438 // function : ClickOnOk()
440 //=================================================================================
441 void BasicGUI_PointDlg::ClickOnOk()
448 //=================================================================================
449 // function : ClickOnApply()
451 //=================================================================================
452 bool BasicGUI_PointDlg::ClickOnApply()
458 ConstructorsClicked( getConstructorId() );
463 //=================================================================================
464 // function : SelectionIntoArgument()
465 // purpose : Called when selection as changed (for constructors not using local context)
466 //=================================================================================
467 void BasicGUI_PointDlg::SelectionIntoArgument()
470 const int id = getConstructorId();
472 if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
474 myEditCurrentArgument->setText( "" );
478 myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
479 } else if ( id == GEOM_POINT_INTINT ) {
480 myEditCurrentArgument->setText( "" );
481 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 )
482 myLine1 = GEOM::GEOM_Object::_nil();
483 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 )
484 myLine2 = GEOM::GEOM_Object::_nil();
487 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
488 SALOME_ListIO aSelList;
489 aSelMgr->selectedObjects(aSelList);
491 if (aSelList.Extent() == 1) {
492 Standard_Boolean aRes = Standard_False;
493 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
494 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
495 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
496 QString aName = GEOMBase::GetName(aSelectedObject);
498 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
499 if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
500 myNeedType = TopAbs_VERTEX;
501 else if ( id == GEOM_POINT_EDGE )
502 myNeedType = TopAbs_EDGE;
503 else if ( id == GEOM_POINT_SURF )
504 myNeedType = TopAbs_FACE;
506 TColStd_IndexedMapOfInteger aMap;
507 aSelMgr->GetIndexes(anIO, aMap);
508 if ( aMap.Extent() == 1 ) { // Local Selection
509 int anIndex = aMap( 1 );
510 if ( myNeedType == TopAbs_FACE )
511 aName += QString( ":face_%1" ).arg( anIndex );
512 else if ( myNeedType == TopAbs_WIRE )
513 aName += QString( ":wire_%1" ).arg( anIndex );
514 else if ( myNeedType == TopAbs_EDGE )
515 aName += QString( ":edge_%1" ).arg( anIndex );
516 else if ( myNeedType == TopAbs_VERTEX )
517 aName += QString( ":vertex_%1" ).arg( anIndex );
519 //Find SubShape Object in Father
520 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
521 if ( aFindedObject->_is_nil() ) { // Object not found in study
522 GEOM::GEOM_IShapesOperations_var aShapesOp =
523 getGeomEngine()->GetIShapesOperations(getStudyId());
524 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
527 aSelectedObject = aFindedObject; // get Object from study
529 GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
531 else { // Global Selection
532 if ( aShape.ShapeType() != myNeedType ) {
533 aSelectedObject = GEOM::GEOM_Object::_nil();
535 if ( id == GEOM_POINT_XYZ ) return;
540 if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
545 if ( id == GEOM_POINT_XYZ ) {
546 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
547 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
548 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
549 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
551 else if ( id == GEOM_POINT_REF ) {
552 myRefPoint = aSelectedObject;
553 GroupRefPoint->LineEdit1->setText( aName );
555 else if ( id == GEOM_POINT_EDGE ) {
556 myEdge = aSelectedObject;
557 GroupOnCurve->LineEdit1->setText( aName );
559 else if ( id == GEOM_POINT_INTINT ) {
560 myEditCurrentArgument->setText( aName );
561 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
562 myLine1 = aSelectedObject;
563 if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
564 GroupLineIntersection->PushButton2->setMenu( 0 );
565 GroupLineIntersection->PushButton2->click();
566 GroupLineIntersection->PushButton2->setDown(true);
567 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
570 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
571 myLine2 = aSelectedObject;
572 if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
573 GroupLineIntersection->PushButton1->setMenu( 0 );
574 GroupLineIntersection->PushButton1->click();
575 GroupLineIntersection->PushButton1->setDown(true);
576 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
580 else if ( id == GEOM_POINT_SURF )
582 myFace = aSelectedObject;
583 GroupOnSurface->LineEdit1->setText( aName );
593 //=================================================================================
594 // function : LineEditReturnPressed()
596 //=================================================================================
597 void BasicGUI_PointDlg::LineEditReturnPressed()
599 QLineEdit* send = (QLineEdit*)sender();
600 if ( send == GroupRefPoint->LineEdit1 ||
601 send == GroupOnCurve->LineEdit1 ||
602 send == GroupLineIntersection->LineEdit1 ||
603 send == GroupLineIntersection->LineEdit2 ) {
604 myEditCurrentArgument = send;
605 GEOMBase_Skeleton::LineEditReturnPressed();
610 //=================================================================================
611 // function : SetEditCurrentArgument()
613 //=================================================================================
614 void BasicGUI_PointDlg::SetEditCurrentArgument()
616 QPushButton* send = (QPushButton*)sender();
618 if ( send == GroupRefPoint->PushButton1 ) {
619 GroupRefPoint->LineEdit1->setFocus();
620 myEditCurrentArgument = GroupRefPoint->LineEdit1;
621 globalSelection(); // close local contexts, if any
622 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
624 else if ( send == GroupOnCurve->PushButton1 ) {
625 GroupOnCurve->LineEdit1->setFocus();
626 myEditCurrentArgument = GroupOnCurve->LineEdit1;
627 globalSelection(); // close local contexts, if any
628 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
630 else if ( send == GroupOnSurface->PushButton1 )
632 GroupOnSurface->LineEdit1->setFocus();
633 myEditCurrentArgument = GroupOnSurface->LineEdit1;
634 globalSelection(); // close local contexts, if any
635 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
637 else if ( send == GroupLineIntersection->PushButton1 ) {
638 GroupLineIntersection->LineEdit1->setFocus();
639 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
640 GroupLineIntersection->PushButton2->setDown( false );
641 GroupLineIntersection->LineEdit1->setEnabled(true);
642 GroupLineIntersection->LineEdit2->setEnabled(false);
644 else if ( send == GroupLineIntersection->PushButton2 ) {
645 GroupLineIntersection->LineEdit2->setFocus();
646 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
647 GroupLineIntersection->PushButton1->setDown( false );
648 GroupLineIntersection->LineEdit1->setEnabled(false);
649 GroupLineIntersection->LineEdit2->setEnabled(true);
653 if ( ( send == GroupLineIntersection->PushButton1 ||
654 send == GroupLineIntersection->PushButton2 ) && !myBusy )
655 SelectionIntoArgument();
659 //=================================================================================
660 // function : enterEvent()
661 // purpose : to reactivate this dialog box when mouse enter onto the window
662 //=================================================================================
663 void BasicGUI_PointDlg::enterEvent( QEvent* )
665 if ( !mainFrame()->GroupConstructors->isEnabled() )
666 ActivateThisDialog();
670 //=================================================================================
671 // function : ActivateThisDialog()
673 //=================================================================================
674 void BasicGUI_PointDlg::ActivateThisDialog( )
676 GEOMBase_Skeleton::ActivateThisDialog();
678 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
679 this, SLOT( SelectionIntoArgument() ) );
681 ConstructorsClicked( getConstructorId() );
685 //=================================================================================
686 // function : DeactivateActiveDialog()
687 // purpose : public slot to deactivate if active
688 //=================================================================================
689 void BasicGUI_PointDlg::DeactivateActiveDialog()
691 // myGeomGUI->SetState( -1 );
692 GEOMBase_Skeleton::DeactivateActiveDialog();
696 //=================================================================================
697 // function : ValueChangedInSpinBox()
699 //=================================================================================
700 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
705 //=================================================================================
706 // funcion : getParameter()
708 //=================================================================================
709 double BasicGUI_PointDlg::getParameter() const
711 return GroupOnCurve->SpinBox_DX->value();
715 //=================================================================================
716 // funcion : getUParameter()
718 //=================================================================================
719 double BasicGUI_PointDlg::getUParameter() const
721 return GroupOnSurface->SpinBox_DX->value();
725 //=================================================================================
726 // funcion : getVParameter()
728 //=================================================================================
729 double BasicGUI_PointDlg::getVParameter() const
731 return GroupOnSurface->SpinBox_DY->value();
735 //=================================================================================
736 // function : OnPointSelected
738 //=================================================================================
739 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
741 if ( getConstructorId() == GEOM_POINT_XYZ ) {
742 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
743 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
744 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
750 //=================================================================================
751 // function : createOperation
753 //=================================================================================
754 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
756 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
759 //=================================================================================
760 // function : isValid
762 //=================================================================================
763 bool BasicGUI_PointDlg::isValid( QString& msg )
765 const int id = getConstructorId();
766 if ( id == GEOM_POINT_XYZ ) {
768 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
769 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
770 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
773 else if ( id == GEOM_POINT_REF ) {
775 ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
776 ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
777 ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
779 return !myRefPoint->_is_nil() && ok;
781 else if ( id == GEOM_POINT_EDGE ) {
783 if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE )
784 ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
786 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
787 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
788 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
790 return !myEdge->_is_nil() && ok;
792 else if ( id == GEOM_POINT_INTINT )
793 return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
794 else if ( id == GEOM_POINT_SURF ) {
796 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
797 ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
798 ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
801 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
802 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
803 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
805 return !myFace->_is_nil() && ok;
810 //=================================================================================
811 // function : execute
813 //=================================================================================
814 bool BasicGUI_PointDlg::execute( ObjectList& objects )
818 GEOM::GEOM_Object_var anObj;
819 QStringList aParameters;
821 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
823 switch ( getConstructorId() ) {
824 case GEOM_POINT_XYZ :
826 double x = GroupXYZ->SpinBox_DX->value();
827 double y = GroupXYZ->SpinBox_DY->value();
828 double z = GroupXYZ->SpinBox_DZ->value();
830 aParameters << GroupXYZ->SpinBox_DX->text();
831 aParameters << GroupXYZ->SpinBox_DY->text();
832 aParameters << GroupXYZ->SpinBox_DZ->text();
834 anObj = anOper->MakePointXYZ( x, y, z );
838 case GEOM_POINT_REF :
840 double dx = GroupRefPoint->SpinBox_DX->value();
841 double dy = GroupRefPoint->SpinBox_DY->value();
842 double dz = GroupRefPoint->SpinBox_DZ->value();
844 aParameters << GroupRefPoint->SpinBox_DX->text();
845 aParameters << GroupRefPoint->SpinBox_DY->text();
846 aParameters << GroupRefPoint->SpinBox_DZ->text();
848 anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
852 case GEOM_POINT_EDGE :
854 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
855 anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
856 aParameters<<GroupOnCurve->SpinBox_DX->text();
858 else if ( myParamCoord->checkedId() == LENGTH_VALUE ) {
859 anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter() );
860 aParameters<<GroupOnCurve->SpinBox_DX->text();
862 else if ( myParamCoord->checkedId() == COORD_VALUE ) {
863 double x = GroupXYZ->SpinBox_DX->value();
864 double y = GroupXYZ->SpinBox_DY->value();
865 double z = GroupXYZ->SpinBox_DZ->value();
867 aParameters << GroupXYZ->SpinBox_DX->text();
868 aParameters << GroupXYZ->SpinBox_DY->text();
869 aParameters << GroupXYZ->SpinBox_DZ->text();
871 anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
876 case GEOM_POINT_INTINT :
877 anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
878 if ( !anObj->_is_nil() ) {
879 QString aName = getNewObjectName();
880 if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
881 initName( tr( "GEOM_COMPOUND" ) );
882 else if ( anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
883 initName( tr( "GEOM_VERTEX" ) );
887 case GEOM_POINT_SURF :
889 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
890 anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
891 aParameters<<GroupOnSurface->SpinBox_DX->text();
892 aParameters<<GroupOnSurface->SpinBox_DY->text();
894 double x = GroupXYZ->SpinBox_DX->value();
895 double y = GroupXYZ->SpinBox_DY->value();
896 double z = GroupXYZ->SpinBox_DZ->value();
898 aParameters << GroupXYZ->SpinBox_DX->text();
899 aParameters << GroupXYZ->SpinBox_DY->text();
900 aParameters << GroupXYZ->SpinBox_DZ->text();
902 anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
909 const int id = getConstructorId();
910 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
911 id == GEOM_POINT_REF ||
912 id == GEOM_POINT_EDGE ||
913 id == GEOM_POINT_SURF) ) {
914 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
917 if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
919 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
920 aShape.ShapeType() == TopAbs_VERTEX ) {
921 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
922 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
923 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
924 myX->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
925 myY->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
926 myZ->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
935 if ( !anObj->_is_nil() ) {
936 objects.push_back( anObj._retn() );
942 //=================================================================================
943 // function : addSubshapeToStudy
944 // purpose : virtual method to add new SubObjects if local selection
945 //=================================================================================
946 void BasicGUI_PointDlg::addSubshapesToStudy()
948 QMap<QString, GEOM::GEOM_Object_var> objMap;
950 switch ( getConstructorId() ) {
954 objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
956 case GEOM_POINT_EDGE:
957 objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
959 case GEOM_POINT_INTINT:
960 objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
961 objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
963 case GEOM_POINT_SURF:
964 objMap[GroupOnSurface->LineEdit1->text()] = myFace;
967 addSubshapesToFather( objMap );
970 //=================================================================================
971 // function : ClickParamCoord()
973 //=================================================================================
974 void BasicGUI_PointDlg::ClickParamCoord( int id )
976 updateParamCoord( true );
980 //=================================================================================
981 // function : updateParamCoord
983 //=================================================================================
984 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
986 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
987 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
989 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
990 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
992 const int id = getConstructorId();
993 if ( id == GEOM_POINT_EDGE ) {
994 GroupOnCurve->TextLabel2->setShown( isParam || isLength );
995 GroupOnCurve->SpinBox_DX->setShown( isParam || isLength );
997 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision" );
998 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
999 GroupOnCurve->TextLabel2->setText(tr( "GEOM_PARAMETER" ));
1001 else if ( isLength ){
1002 initSpinBox( GroupOnCurve->SpinBox_DX, 0.0, COORD_MAX, 0.1 * step, "length_precision" );
1003 GroupOnCurve->SpinBox_DX->setValue( 0.0 );
1004 GroupOnCurve->TextLabel2->setText(tr( "GEOM_LENGTH" ));
1007 else if ( id == GEOM_POINT_SURF ) {
1008 GroupOnSurface->TextLabel2->setShown( isParam );
1009 GroupOnSurface->TextLabel3->setShown( isParam );
1010 GroupOnSurface->SpinBox_DX->setShown( isParam );
1011 GroupOnSurface->SpinBox_DY->setShown( isParam );
1014 GroupXYZ->setShown( !isParam && !isLength );
1017 QTimer::singleShot(50, this, SLOT(updateSize()));
1020 //=================================================================================
1021 // function : onBtnPopup()
1023 //=================================================================================
1024 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
1026 int index = myActions[a];
1027 globalSelection(); // close local contexts, if any
1030 myNeedType = TopAbs_EDGE;
1032 myNeedType = TopAbs_WIRE;
1034 localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1037 //=================================================================================
1038 // function : updateSize
1039 // purpose : adjust dialog size to minimum
1040 //=================================================================================
1041 void BasicGUI_PointDlg::updateSize()
1043 qApp->processEvents();
1045 resize( minimumSizeHint() );