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 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
493 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO );
494 if ( !CORBA::is_nil( aSelectedObject ) ) {
495 QString aName = GEOMBase::GetName(aSelectedObject);
497 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
498 if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
499 myNeedType = TopAbs_VERTEX;
500 else if ( id == GEOM_POINT_EDGE )
501 myNeedType = TopAbs_EDGE;
502 else if ( id == GEOM_POINT_SURF )
503 myNeedType = TopAbs_FACE;
505 TColStd_IndexedMapOfInteger aMap;
506 aSelMgr->GetIndexes(anIO, aMap);
507 if ( aMap.Extent() == 1 ) { // Local Selection
508 int anIndex = aMap( 1 );
509 if ( myNeedType == TopAbs_FACE )
510 aName += QString( ":face_%1" ).arg( anIndex );
511 else if ( myNeedType == TopAbs_WIRE )
512 aName += QString( ":wire_%1" ).arg( anIndex );
513 else if ( myNeedType == TopAbs_EDGE )
514 aName += QString( ":edge_%1" ).arg( anIndex );
515 else if ( myNeedType == TopAbs_VERTEX )
516 aName += QString( ":vertex_%1" ).arg( anIndex );
518 //Find SubShape Object in Father
519 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
520 if ( aFindedObject->_is_nil() ) { // Object not found in study
521 GEOM::GEOM_IShapesOperations_var aShapesOp =
522 getGeomEngine()->GetIShapesOperations(getStudyId());
523 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
526 aSelectedObject = aFindedObject; // get Object from study
528 GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
530 else { // Global Selection
531 if ( aShape.ShapeType() != myNeedType ) {
532 aSelectedObject = GEOM::GEOM_Object::_nil();
534 if ( id == GEOM_POINT_XYZ ) return;
539 if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
544 if ( id == GEOM_POINT_XYZ ) {
545 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
546 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
547 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
548 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
550 else if ( id == GEOM_POINT_REF ) {
551 myRefPoint = aSelectedObject;
552 GroupRefPoint->LineEdit1->setText( aName );
554 else if ( id == GEOM_POINT_EDGE ) {
555 myEdge = aSelectedObject;
556 GroupOnCurve->LineEdit1->setText( aName );
558 else if ( id == GEOM_POINT_INTINT ) {
559 myEditCurrentArgument->setText( aName );
560 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
561 myLine1 = aSelectedObject;
562 if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
563 GroupLineIntersection->PushButton2->setMenu( 0 );
564 GroupLineIntersection->PushButton2->click();
565 GroupLineIntersection->PushButton2->setDown(true);
566 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
569 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
570 myLine2 = aSelectedObject;
571 if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
572 GroupLineIntersection->PushButton1->setMenu( 0 );
573 GroupLineIntersection->PushButton1->click();
574 GroupLineIntersection->PushButton1->setDown(true);
575 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
579 else if ( id == GEOM_POINT_SURF )
581 myFace = aSelectedObject;
582 GroupOnSurface->LineEdit1->setText( aName );
592 //=================================================================================
593 // function : LineEditReturnPressed()
595 //=================================================================================
596 void BasicGUI_PointDlg::LineEditReturnPressed()
598 QLineEdit* send = (QLineEdit*)sender();
599 if ( send == GroupRefPoint->LineEdit1 ||
600 send == GroupOnCurve->LineEdit1 ||
601 send == GroupLineIntersection->LineEdit1 ||
602 send == GroupLineIntersection->LineEdit2 ) {
603 myEditCurrentArgument = send;
604 GEOMBase_Skeleton::LineEditReturnPressed();
609 //=================================================================================
610 // function : SetEditCurrentArgument()
612 //=================================================================================
613 void BasicGUI_PointDlg::SetEditCurrentArgument()
615 QPushButton* send = (QPushButton*)sender();
617 if ( send == GroupRefPoint->PushButton1 ) {
618 GroupRefPoint->LineEdit1->setFocus();
619 myEditCurrentArgument = GroupRefPoint->LineEdit1;
620 globalSelection(); // close local contexts, if any
621 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
623 else if ( send == GroupOnCurve->PushButton1 ) {
624 GroupOnCurve->LineEdit1->setFocus();
625 myEditCurrentArgument = GroupOnCurve->LineEdit1;
626 globalSelection(); // close local contexts, if any
627 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
629 else if ( send == GroupOnSurface->PushButton1 )
631 GroupOnSurface->LineEdit1->setFocus();
632 myEditCurrentArgument = GroupOnSurface->LineEdit1;
633 globalSelection(); // close local contexts, if any
634 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
636 else if ( send == GroupLineIntersection->PushButton1 ) {
637 GroupLineIntersection->LineEdit1->setFocus();
638 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
639 GroupLineIntersection->PushButton2->setDown( false );
640 GroupLineIntersection->LineEdit1->setEnabled(true);
641 GroupLineIntersection->LineEdit2->setEnabled(false);
643 else if ( send == GroupLineIntersection->PushButton2 ) {
644 GroupLineIntersection->LineEdit2->setFocus();
645 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
646 GroupLineIntersection->PushButton1->setDown( false );
647 GroupLineIntersection->LineEdit1->setEnabled(false);
648 GroupLineIntersection->LineEdit2->setEnabled(true);
652 if ( ( send == GroupLineIntersection->PushButton1 ||
653 send == GroupLineIntersection->PushButton2 ) && !myBusy )
654 SelectionIntoArgument();
658 //=================================================================================
659 // function : enterEvent()
660 // purpose : to reactivate this dialog box when mouse enter onto the window
661 //=================================================================================
662 void BasicGUI_PointDlg::enterEvent( QEvent* )
664 if ( !mainFrame()->GroupConstructors->isEnabled() )
665 ActivateThisDialog();
669 //=================================================================================
670 // function : ActivateThisDialog()
672 //=================================================================================
673 void BasicGUI_PointDlg::ActivateThisDialog( )
675 GEOMBase_Skeleton::ActivateThisDialog();
677 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
678 this, SLOT( SelectionIntoArgument() ) );
680 ConstructorsClicked( getConstructorId() );
684 //=================================================================================
685 // function : DeactivateActiveDialog()
686 // purpose : public slot to deactivate if active
687 //=================================================================================
688 void BasicGUI_PointDlg::DeactivateActiveDialog()
690 // myGeomGUI->SetState( -1 );
691 GEOMBase_Skeleton::DeactivateActiveDialog();
695 //=================================================================================
696 // function : ValueChangedInSpinBox()
698 //=================================================================================
699 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
704 //=================================================================================
705 // funcion : getParameter()
707 //=================================================================================
708 double BasicGUI_PointDlg::getParameter() const
710 return GroupOnCurve->SpinBox_DX->value();
714 //=================================================================================
715 // funcion : getUParameter()
717 //=================================================================================
718 double BasicGUI_PointDlg::getUParameter() const
720 return GroupOnSurface->SpinBox_DX->value();
724 //=================================================================================
725 // funcion : getVParameter()
727 //=================================================================================
728 double BasicGUI_PointDlg::getVParameter() const
730 return GroupOnSurface->SpinBox_DY->value();
734 //=================================================================================
735 // function : OnPointSelected
737 //=================================================================================
738 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
740 if ( getConstructorId() == GEOM_POINT_XYZ ) {
741 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
742 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
743 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
749 //=================================================================================
750 // function : createOperation
752 //=================================================================================
753 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
755 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
758 //=================================================================================
759 // function : isValid
761 //=================================================================================
762 bool BasicGUI_PointDlg::isValid( QString& msg )
764 const int id = getConstructorId();
765 if ( id == GEOM_POINT_XYZ ) {
767 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
768 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
769 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
772 else if ( id == GEOM_POINT_REF ) {
774 ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
775 ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
776 ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
778 return !myRefPoint->_is_nil() && ok;
780 else if ( id == GEOM_POINT_EDGE ) {
782 if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE )
783 ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
785 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
786 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
787 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
789 return !myEdge->_is_nil() && ok;
791 else if ( id == GEOM_POINT_INTINT )
792 return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
793 else if ( id == GEOM_POINT_SURF ) {
795 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
796 ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
797 ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
800 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
801 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
802 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
804 return !myFace->_is_nil() && ok;
809 //=================================================================================
810 // function : execute
812 //=================================================================================
813 bool BasicGUI_PointDlg::execute( ObjectList& objects )
817 GEOM::GEOM_Object_var anObj;
818 QStringList aParameters;
820 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
822 switch ( getConstructorId() ) {
823 case GEOM_POINT_XYZ :
825 double x = GroupXYZ->SpinBox_DX->value();
826 double y = GroupXYZ->SpinBox_DY->value();
827 double z = GroupXYZ->SpinBox_DZ->value();
829 aParameters << GroupXYZ->SpinBox_DX->text();
830 aParameters << GroupXYZ->SpinBox_DY->text();
831 aParameters << GroupXYZ->SpinBox_DZ->text();
833 anObj = anOper->MakePointXYZ( x, y, z );
837 case GEOM_POINT_REF :
839 double dx = GroupRefPoint->SpinBox_DX->value();
840 double dy = GroupRefPoint->SpinBox_DY->value();
841 double dz = GroupRefPoint->SpinBox_DZ->value();
843 aParameters << GroupRefPoint->SpinBox_DX->text();
844 aParameters << GroupRefPoint->SpinBox_DY->text();
845 aParameters << GroupRefPoint->SpinBox_DZ->text();
847 anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
851 case GEOM_POINT_EDGE :
853 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
854 anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
855 aParameters<<GroupOnCurve->SpinBox_DX->text();
857 else if ( myParamCoord->checkedId() == LENGTH_VALUE ) {
858 anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter() );
859 aParameters<<GroupOnCurve->SpinBox_DX->text();
861 else if ( myParamCoord->checkedId() == COORD_VALUE ) {
862 double x = GroupXYZ->SpinBox_DX->value();
863 double y = GroupXYZ->SpinBox_DY->value();
864 double z = GroupXYZ->SpinBox_DZ->value();
866 aParameters << GroupXYZ->SpinBox_DX->text();
867 aParameters << GroupXYZ->SpinBox_DY->text();
868 aParameters << GroupXYZ->SpinBox_DZ->text();
870 anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
875 case GEOM_POINT_INTINT :
876 anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
877 if ( !anObj->_is_nil() ) {
878 QString aName = getNewObjectName();
879 if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
880 initName( tr( "GEOM_COMPOUND" ) );
881 else if ( anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
882 initName( tr( "GEOM_VERTEX" ) );
886 case GEOM_POINT_SURF :
888 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
889 anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
890 aParameters<<GroupOnSurface->SpinBox_DX->text();
891 aParameters<<GroupOnSurface->SpinBox_DY->text();
893 double x = GroupXYZ->SpinBox_DX->value();
894 double y = GroupXYZ->SpinBox_DY->value();
895 double z = GroupXYZ->SpinBox_DZ->value();
897 aParameters << GroupXYZ->SpinBox_DX->text();
898 aParameters << GroupXYZ->SpinBox_DY->text();
899 aParameters << GroupXYZ->SpinBox_DZ->text();
901 anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
908 const int id = getConstructorId();
909 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
910 id == GEOM_POINT_REF ||
911 id == GEOM_POINT_EDGE ||
912 id == GEOM_POINT_SURF) ) {
913 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
916 if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
918 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
919 aShape.ShapeType() == TopAbs_VERTEX ) {
920 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
921 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
922 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
923 myX->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
924 myY->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
925 myZ->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
934 if ( !anObj->_is_nil() ) {
935 objects.push_back( anObj._retn() );
941 //=================================================================================
942 // function : addSubshapeToStudy
943 // purpose : virtual method to add new SubObjects if local selection
944 //=================================================================================
945 void BasicGUI_PointDlg::addSubshapesToStudy()
947 QMap<QString, GEOM::GEOM_Object_var> objMap;
949 switch ( getConstructorId() ) {
953 objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
955 case GEOM_POINT_EDGE:
956 objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
958 case GEOM_POINT_INTINT:
959 objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
960 objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
962 case GEOM_POINT_SURF:
963 objMap[GroupOnSurface->LineEdit1->text()] = myFace;
966 addSubshapesToFather( objMap );
969 //=================================================================================
970 // function : ClickParamCoord()
972 //=================================================================================
973 void BasicGUI_PointDlg::ClickParamCoord( int id )
975 updateParamCoord( true );
979 //=================================================================================
980 // function : updateParamCoord
982 //=================================================================================
983 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
985 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
986 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
988 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
989 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
991 const int id = getConstructorId();
992 if ( id == GEOM_POINT_EDGE ) {
993 GroupOnCurve->TextLabel2->setShown( isParam || isLength );
994 GroupOnCurve->SpinBox_DX->setShown( isParam || isLength );
996 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision" );
997 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
998 GroupOnCurve->TextLabel2->setText(tr( "GEOM_PARAMETER" ));
1000 else if ( isLength ){
1001 initSpinBox( GroupOnCurve->SpinBox_DX, 0.0, COORD_MAX, 0.1 * step, "length_precision" );
1002 GroupOnCurve->SpinBox_DX->setValue( 0.0 );
1003 GroupOnCurve->TextLabel2->setText(tr( "GEOM_LENGTH" ));
1006 else if ( id == GEOM_POINT_SURF ) {
1007 GroupOnSurface->TextLabel2->setShown( isParam );
1008 GroupOnSurface->TextLabel3->setShown( isParam );
1009 GroupOnSurface->SpinBox_DX->setShown( isParam );
1010 GroupOnSurface->SpinBox_DY->setShown( isParam );
1013 GroupXYZ->setShown( !isParam && !isLength );
1016 QTimer::singleShot(50, this, SLOT(updateSize()));
1019 //=================================================================================
1020 // function : onBtnPopup()
1022 //=================================================================================
1023 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
1025 int index = myActions[a];
1026 globalSelection(); // close local contexts, if any
1029 myNeedType = TopAbs_EDGE;
1031 myNeedType = TopAbs_WIRE;
1033 localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1036 //=================================================================================
1037 // function : updateSize
1038 // purpose : adjust dialog size to minimum
1039 //=================================================================================
1040 void BasicGUI_PointDlg::updateSize()
1042 qApp->processEvents();
1044 resize( minimumSizeHint() );