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_1Sel1Spin1Check( 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->CheckButton1->setText( tr( "GEOM_REVERSE" ) );
131 GroupOnCurve->PushButton1->setIcon( image2 );
134 GroupOnSurface = new DlgRef_1Sel2Spin( centralWidget() );
135 GroupOnSurface->GroupBox1->setTitle( tr( "GEOM_POINT_ON_FACE" ) );
136 GroupOnSurface->TextLabel1->setText( tr( "GEOM_FACE" ) );
137 GroupOnSurface->TextLabel2->setText( tr( "GEOM_UPARAMETER" ) );
138 GroupOnSurface->TextLabel3->setText( tr( "GEOM_VPARAMETER" ) );
139 GroupOnSurface->PushButton1->setIcon( image2 );
141 GroupRefPoint = new DlgRef_1Sel3Spin( centralWidget() );
142 GroupRefPoint->GroupBox1->setTitle( tr( "GEOM_REF_POINT" ) );
143 GroupRefPoint->TextLabel1->setText( tr( "GEOM_POINT" ) );
144 GroupRefPoint->PushButton1->setIcon( image2 );
145 GroupRefPoint->TextLabel2->setText( tr( "GEOM_DX" ) );
146 GroupRefPoint->TextLabel3->setText( tr( "GEOM_DY" ) );
147 GroupRefPoint->TextLabel4->setText( tr( "GEOM_DZ" ) );
149 /* popup menu for line intersect buttons */
150 myBtnPopup = new QMenu(this);
151 QIcon ico_line = QIcon( image6 );
152 QIcon ico_wire = QIcon( image7 );
153 myActions[myBtnPopup->addAction( ico_line, tr( "GEOM_EDGE" ) )] = 0;
154 myActions[myBtnPopup->addAction( ico_wire, tr( "GEOM_WIRE" ) )] = 1;
156 GroupLineIntersection = new DlgRef_2Sel( centralWidget() );
157 GroupLineIntersection->GroupBox1->setTitle( tr( "GEOM_LINE_INTERSECTION" ) );
158 GroupLineIntersection->TextLabel1->setText( tr( "GEOM_LINE1" ) );
159 GroupLineIntersection->TextLabel2->setText( tr( "GEOM_LINE2" ) );
160 GroupLineIntersection->PushButton1->setIcon( image2 );
161 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
162 GroupLineIntersection->PushButton2->setIcon( image2 );
163 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
164 GroupLineIntersection->LineEdit2->setEnabled(false);
166 myCoordGrp = new QGroupBox( tr( "GEOM_COORDINATES_RES" ), centralWidget() );
167 QGridLayout* myCoordGrpLayout = new QGridLayout( myCoordGrp );
168 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), myCoordGrp ), 0, 0 );
169 myX = new QLineEdit( myCoordGrp );
170 myCoordGrpLayout->addWidget( myX, 0, 1 );
171 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), myCoordGrp ), 1, 0 );
172 myY = new QLineEdit( myCoordGrp );
173 myCoordGrpLayout->addWidget( myY, 1, 1 );
174 myCoordGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), myCoordGrp ), 2, 0 );
175 myZ = new QLineEdit( myCoordGrp );
176 myCoordGrpLayout->addWidget( myZ, 2, 1 );
178 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
179 layout->setMargin( 0 ); layout->setSpacing( 6 );
180 layout->addWidget( myParamGroup );
181 layout->addWidget( GroupXYZ );
182 layout->addWidget( GroupOnCurve );
183 layout->addWidget( GroupOnSurface );
184 layout->addWidget( GroupRefPoint );
185 layout->addWidget( GroupLineIntersection );
186 layout->addWidget( myCoordGrp );
188 myX->setReadOnly( true );
189 myY->setReadOnly( true );
190 myZ->setReadOnly( true );
192 myX->setEnabled( false );
193 myY->setEnabled( false );
194 myZ->setEnabled( false );
196 QPalette aPal = myX->palette();
197 aPal.setColor( QPalette::Disabled, QPalette::Text, QColor( 0, 0, 0 ) );
198 myX->setPalette( aPal );
199 myY->setPalette( aPal );
200 myZ->setPalette( aPal );
202 setHelpFileName( "create_point_page.html" );
208 //=================================================================================
209 // function : ~BasicGUI_PointDlg()
210 // purpose : Destructor
211 //=================================================================================
212 BasicGUI_PointDlg::~BasicGUI_PointDlg()
217 //=================================================================================
220 //=================================================================================
221 void BasicGUI_PointDlg::Init()
223 GroupOnCurve->LineEdit1->setReadOnly( true );
224 GroupOnSurface->LineEdit1->setReadOnly( true );
225 GroupRefPoint->LineEdit1->setReadOnly( true );
226 GroupLineIntersection->LineEdit1->setReadOnly( true );
227 GroupLineIntersection->LineEdit2->setReadOnly( true );
228 GroupLineIntersection->LineEdit1->setEnabled( true );
229 GroupLineIntersection->LineEdit2->setEnabled( false );
231 myEdge = GEOM::GEOM_Object::_nil();
232 myRefPoint = GEOM::GEOM_Object::_nil();
233 myNeedType = TopAbs_VERTEX;
235 myEditCurrentArgument = 0;
238 /* Get setting of step value from file configuration */
239 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
240 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
242 /* min, max, step and decimals for spin boxes */
243 initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
244 initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
245 initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
246 GroupXYZ->SpinBox_DX->setValue( 0.0 );
247 GroupXYZ->SpinBox_DY->setValue( 0.0 );
248 GroupXYZ->SpinBox_DZ->setValue( 0.0 );
250 initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
251 initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
252 initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
253 GroupRefPoint->SpinBox_DX->setValue( 0.0 );
254 GroupRefPoint->SpinBox_DY->setValue( 0.0 );
255 GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
259 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision" );
260 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
262 initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision" );
263 GroupOnSurface->SpinBox_DX->setValue( 0.5 );
264 initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision" );
265 GroupOnSurface->SpinBox_DY->setValue( 0.5 );
267 /* signals and slots connections */
268 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
269 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
271 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
272 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
274 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
276 connect( myParamCoord, SIGNAL( buttonClicked( int ) ), this, SLOT( ClickParamCoord( int ) ) );
277 connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
278 connect( GroupOnCurve->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
280 connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
281 connect( GroupOnSurface->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
283 connect( myBtnPopup, SIGNAL( triggered( QAction* ) ), SLOT( onBtnPopup( QAction* ) ) );
284 connect( GroupLineIntersection->PushButton1, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
285 connect( GroupLineIntersection->PushButton2, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
286 connect( GroupLineIntersection->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
287 connect( GroupLineIntersection->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
289 connect( GroupOnCurve->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
290 connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
291 connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
292 connect( GroupXYZ->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
293 connect( GroupXYZ->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
294 connect( GroupXYZ->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
295 connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
296 connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
297 connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
299 connect( GroupOnCurve->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
301 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
303 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
304 this, SLOT(SelectionIntoArgument() ) );
306 initName( tr( "GEOM_VERTEX" ) );
308 ConstructorsClicked( 0 );
311 //=================================================================================
312 // function : SetDoubleSpinBoxStep()
313 // purpose : Double spin box management
314 //=================================================================================
315 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
317 GroupOnCurve->SpinBox_DX->setSingleStep(step);
318 GroupXYZ->SpinBox_DX->setSingleStep(step);
319 GroupXYZ->SpinBox_DY->setSingleStep(step);
320 GroupXYZ->SpinBox_DZ->setSingleStep(step);
321 GroupRefPoint->SpinBox_DX->setSingleStep(step);
322 GroupRefPoint->SpinBox_DY->setSingleStep(step);
323 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
327 //=================================================================================
328 // function : ConstructorsClicked()
329 // purpose : Radio button management
330 //=================================================================================
331 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
333 switch ( constructorId ) {
336 globalSelection(); // close local contexts, if any
337 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
339 GroupRefPoint->hide();
340 GroupOnCurve->hide();
341 GroupLineIntersection->hide();
342 GroupOnSurface->hide();
344 myParamGroup->hide();
350 globalSelection(); // close local contexts, if any
351 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
353 myEditCurrentArgument = GroupRefPoint->LineEdit1;
354 myEditCurrentArgument->setText( "" );
355 myRefPoint = GEOM::GEOM_Object::_nil();
356 GroupRefPoint->PushButton1->setDown(true);
357 myParamGroup->hide();
359 GroupOnCurve->hide();
360 GroupLineIntersection->hide();
361 GroupOnSurface->hide();
362 GroupRefPoint->show();
366 case GEOM_POINT_EDGE:
368 globalSelection(); // close local contexts, if any
369 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
371 myEditCurrentArgument = GroupOnCurve->LineEdit1;
372 myEditCurrentArgument->setText( "" );
373 myEdge = GEOM::GEOM_Object::_nil();
374 GroupOnCurve->PushButton1->setDown(true);
375 GroupRefPoint->hide();
376 GroupLineIntersection->hide();
377 GroupOnSurface->hide();
378 myParamGroup->show();
379 myParamCoord->button( LENGTH_VALUE )->show();
380 myParamCoord->button( PARAM_VALUE )->setChecked( true );
381 GroupOnCurve->show();
383 updateParamCoord( false );
386 case GEOM_POINT_INTINT:
388 globalSelection(); // close local contexts, if any
389 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
390 myNeedType = TopAbs_EDGE;
392 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
393 GroupLineIntersection->LineEdit1->setText( "" );
394 GroupLineIntersection->LineEdit2->setText( "" );
395 GroupLineIntersection->LineEdit1->setEnabled( true );
396 GroupLineIntersection->LineEdit2->setEnabled( false );
397 myLine1 = GEOM::GEOM_Object::_nil();
398 myLine2 = GEOM::GEOM_Object::_nil();
399 GroupLineIntersection->PushButton1->setDown(true);
400 GroupLineIntersection->PushButton2->setDown(false);
401 myParamGroup->hide();
403 GroupRefPoint->hide();
404 GroupOnCurve->hide();
405 GroupOnSurface->hide();
407 GroupLineIntersection->show();
410 case GEOM_POINT_SURF:
412 globalSelection(); // close local contexts, if any
413 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
415 myEditCurrentArgument = GroupOnSurface->LineEdit1;
416 myEditCurrentArgument->setText( "" );
417 myFace = GEOM::GEOM_Object::_nil();
418 GroupOnSurface->PushButton1->setDown(true);
419 GroupRefPoint->hide();
420 GroupOnCurve->hide();
421 GroupLineIntersection->hide();
422 myParamGroup->show();
423 myParamCoord->button( LENGTH_VALUE )->hide();
424 myParamCoord->button( PARAM_VALUE )->setChecked(true);
425 GroupOnSurface->show();
427 updateParamCoord( false );
436 QTimer::singleShot(50, this, SLOT(updateSize()));
438 SelectionIntoArgument();
442 //=================================================================================
443 // function : ClickOnOk()
445 //=================================================================================
446 void BasicGUI_PointDlg::ClickOnOk()
453 //=================================================================================
454 // function : ClickOnApply()
456 //=================================================================================
457 bool BasicGUI_PointDlg::ClickOnApply()
463 ConstructorsClicked( getConstructorId() );
468 //=================================================================================
469 // function : SelectionIntoArgument()
470 // purpose : Called when selection as changed (for constructors not using local context)
471 //=================================================================================
472 void BasicGUI_PointDlg::SelectionIntoArgument()
475 const int id = getConstructorId();
477 if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
479 myEditCurrentArgument->setText( "" );
483 myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
484 } else if ( id == GEOM_POINT_INTINT ) {
485 myEditCurrentArgument->setText( "" );
486 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 )
487 myLine1 = GEOM::GEOM_Object::_nil();
488 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 )
489 myLine2 = GEOM::GEOM_Object::_nil();
492 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
493 SALOME_ListIO aSelList;
494 aSelMgr->selectedObjects(aSelList);
496 if (aSelList.Extent() == 1) {
497 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
498 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO );
499 if ( !CORBA::is_nil( aSelectedObject ) ) {
500 QString aName = GEOMBase::GetName(aSelectedObject);
502 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
503 if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
504 myNeedType = TopAbs_VERTEX;
505 else if ( id == GEOM_POINT_EDGE )
506 myNeedType = TopAbs_EDGE;
507 else if ( id == GEOM_POINT_SURF )
508 myNeedType = TopAbs_FACE;
510 TColStd_IndexedMapOfInteger aMap;
511 aSelMgr->GetIndexes(anIO, aMap);
512 if ( aMap.Extent() == 1 ) { // Local Selection
513 int anIndex = aMap( 1 );
514 if ( myNeedType == TopAbs_FACE )
515 aName += QString( ":face_%1" ).arg( anIndex );
516 else if ( myNeedType == TopAbs_WIRE )
517 aName += QString( ":wire_%1" ).arg( anIndex );
518 else if ( myNeedType == TopAbs_EDGE )
519 aName += QString( ":edge_%1" ).arg( anIndex );
520 else if ( myNeedType == TopAbs_VERTEX )
521 aName += QString( ":vertex_%1" ).arg( anIndex );
523 //Find SubShape Object in Father
524 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
525 if ( aFindedObject->_is_nil() ) { // Object not found in study
526 GEOM::GEOM_IShapesOperations_var aShapesOp =
527 getGeomEngine()->GetIShapesOperations(getStudyId());
528 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
531 aSelectedObject = aFindedObject; // get Object from study
533 GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
535 else { // Global Selection
536 if ( aShape.ShapeType() != myNeedType ) {
537 aSelectedObject = GEOM::GEOM_Object::_nil();
539 if ( id == GEOM_POINT_XYZ ) return;
544 if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
549 if ( id == GEOM_POINT_XYZ ) {
550 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
551 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
552 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
553 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
555 else if ( id == GEOM_POINT_REF ) {
556 myRefPoint = aSelectedObject;
557 GroupRefPoint->LineEdit1->setText( aName );
559 else if ( id == GEOM_POINT_EDGE ) {
560 myEdge = aSelectedObject;
561 GroupOnCurve->LineEdit1->setText( aName );
563 else if ( id == GEOM_POINT_INTINT ) {
564 myEditCurrentArgument->setText( aName );
565 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
566 myLine1 = aSelectedObject;
567 if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
568 GroupLineIntersection->PushButton2->setMenu( 0 );
569 GroupLineIntersection->PushButton2->click();
570 GroupLineIntersection->PushButton2->setDown(true);
571 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
574 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
575 myLine2 = aSelectedObject;
576 if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
577 GroupLineIntersection->PushButton1->setMenu( 0 );
578 GroupLineIntersection->PushButton1->click();
579 GroupLineIntersection->PushButton1->setDown(true);
580 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
584 else if ( id == GEOM_POINT_SURF )
586 myFace = aSelectedObject;
587 GroupOnSurface->LineEdit1->setText( aName );
597 //=================================================================================
598 // function : LineEditReturnPressed()
600 //=================================================================================
601 void BasicGUI_PointDlg::LineEditReturnPressed()
603 QLineEdit* send = (QLineEdit*)sender();
604 if ( send == GroupRefPoint->LineEdit1 ||
605 send == GroupOnCurve->LineEdit1 ||
606 send == GroupLineIntersection->LineEdit1 ||
607 send == GroupLineIntersection->LineEdit2 ) {
608 myEditCurrentArgument = send;
609 GEOMBase_Skeleton::LineEditReturnPressed();
614 //=================================================================================
615 // function : SetEditCurrentArgument()
617 //=================================================================================
618 void BasicGUI_PointDlg::SetEditCurrentArgument()
620 QPushButton* send = (QPushButton*)sender();
622 if ( send == GroupRefPoint->PushButton1 ) {
623 GroupRefPoint->LineEdit1->setFocus();
624 myEditCurrentArgument = GroupRefPoint->LineEdit1;
625 globalSelection(); // close local contexts, if any
626 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
628 else if ( send == GroupOnCurve->PushButton1 ) {
629 GroupOnCurve->LineEdit1->setFocus();
630 myEditCurrentArgument = GroupOnCurve->LineEdit1;
631 globalSelection(); // close local contexts, if any
632 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
634 else if ( send == GroupOnSurface->PushButton1 )
636 GroupOnSurface->LineEdit1->setFocus();
637 myEditCurrentArgument = GroupOnSurface->LineEdit1;
638 globalSelection(); // close local contexts, if any
639 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
641 else if ( send == GroupLineIntersection->PushButton1 ) {
642 GroupLineIntersection->LineEdit1->setFocus();
643 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
644 GroupLineIntersection->PushButton2->setDown( false );
645 GroupLineIntersection->LineEdit1->setEnabled(true);
646 GroupLineIntersection->LineEdit2->setEnabled(false);
648 else if ( send == GroupLineIntersection->PushButton2 ) {
649 GroupLineIntersection->LineEdit2->setFocus();
650 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
651 GroupLineIntersection->PushButton1->setDown( false );
652 GroupLineIntersection->LineEdit1->setEnabled(false);
653 GroupLineIntersection->LineEdit2->setEnabled(true);
657 if ( ( send == GroupLineIntersection->PushButton1 ||
658 send == GroupLineIntersection->PushButton2 ) && !myBusy )
659 SelectionIntoArgument();
663 //=================================================================================
664 // function : enterEvent()
665 // purpose : to reactivate this dialog box when mouse enter onto the window
666 //=================================================================================
667 void BasicGUI_PointDlg::enterEvent( QEvent* )
669 if ( !mainFrame()->GroupConstructors->isEnabled() )
670 ActivateThisDialog();
674 //=================================================================================
675 // function : ActivateThisDialog()
677 //=================================================================================
678 void BasicGUI_PointDlg::ActivateThisDialog( )
680 GEOMBase_Skeleton::ActivateThisDialog();
682 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
683 this, SLOT( SelectionIntoArgument() ) );
685 ConstructorsClicked( getConstructorId() );
689 //=================================================================================
690 // function : DeactivateActiveDialog()
691 // purpose : public slot to deactivate if active
692 //=================================================================================
693 void BasicGUI_PointDlg::DeactivateActiveDialog()
695 // myGeomGUI->SetState( -1 );
696 GEOMBase_Skeleton::DeactivateActiveDialog();
700 //=================================================================================
701 // function : ValueChangedInSpinBox()
703 //=================================================================================
704 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
709 //=================================================================================
710 // function : CheckBoxClicked()
711 // purpose : Check Boxes Management
712 //=================================================================================
713 void BasicGUI_PointDlg::CheckBoxClicked( int State )
720 //=================================================================================
721 // funcion : getParameter()
723 //=================================================================================
724 double BasicGUI_PointDlg::getParameter() const
726 return GroupOnCurve->SpinBox_DX->value();
730 //=================================================================================
731 // funcion : getUParameter()
733 //=================================================================================
734 double BasicGUI_PointDlg::getUParameter() const
736 return GroupOnSurface->SpinBox_DX->value();
740 //=================================================================================
741 // funcion : getVParameter()
743 //=================================================================================
744 double BasicGUI_PointDlg::getVParameter() const
746 return GroupOnSurface->SpinBox_DY->value();
750 //=================================================================================
751 // function : OnPointSelected
753 //=================================================================================
754 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
756 if ( getConstructorId() == GEOM_POINT_XYZ ) {
757 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
758 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
759 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
765 //=================================================================================
766 // function : createOperation
768 //=================================================================================
769 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
771 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
774 //=================================================================================
775 // function : isValid
777 //=================================================================================
778 bool BasicGUI_PointDlg::isValid( QString& msg )
780 const int id = getConstructorId();
781 if ( id == GEOM_POINT_XYZ ) {
783 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
784 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
785 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
788 else if ( id == GEOM_POINT_REF ) {
790 ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
791 ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
792 ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
794 return !myRefPoint->_is_nil() && ok;
796 else if ( id == GEOM_POINT_EDGE ) {
798 if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE )
799 ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
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 !myEdge->_is_nil() && ok;
807 else if ( id == GEOM_POINT_INTINT )
808 return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
809 else if ( id == GEOM_POINT_SURF ) {
811 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
812 ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
813 ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
816 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
817 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
818 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
820 return !myFace->_is_nil() && ok;
825 //=================================================================================
826 // function : execute
828 //=================================================================================
829 bool BasicGUI_PointDlg::execute( ObjectList& objects )
833 GEOM::GEOM_Object_var anObj;
834 QStringList aParameters;
836 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
838 switch ( getConstructorId() ) {
839 case GEOM_POINT_XYZ :
841 double x = GroupXYZ->SpinBox_DX->value();
842 double y = GroupXYZ->SpinBox_DY->value();
843 double z = GroupXYZ->SpinBox_DZ->value();
845 aParameters << GroupXYZ->SpinBox_DX->text();
846 aParameters << GroupXYZ->SpinBox_DY->text();
847 aParameters << GroupXYZ->SpinBox_DZ->text();
849 anObj = anOper->MakePointXYZ( x, y, z );
853 case GEOM_POINT_REF :
855 double dx = GroupRefPoint->SpinBox_DX->value();
856 double dy = GroupRefPoint->SpinBox_DY->value();
857 double dz = GroupRefPoint->SpinBox_DZ->value();
859 aParameters << GroupRefPoint->SpinBox_DX->text();
860 aParameters << GroupRefPoint->SpinBox_DY->text();
861 aParameters << GroupRefPoint->SpinBox_DZ->text();
863 anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
867 case GEOM_POINT_EDGE :
869 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
870 anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
871 aParameters<<GroupOnCurve->SpinBox_DX->text();
873 else if ( myParamCoord->checkedId() == LENGTH_VALUE ) {
874 anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter(), myCheckFlag );
876 std::stringstream out;
878 std::string flag = out.str();
879 aParameters<<GroupOnCurve->SpinBox_DX->text();
880 aParameters<<flag.c_str();
882 else if ( myParamCoord->checkedId() == COORD_VALUE ) {
883 double x = GroupXYZ->SpinBox_DX->value();
884 double y = GroupXYZ->SpinBox_DY->value();
885 double z = GroupXYZ->SpinBox_DZ->value();
887 aParameters << GroupXYZ->SpinBox_DX->text();
888 aParameters << GroupXYZ->SpinBox_DY->text();
889 aParameters << GroupXYZ->SpinBox_DZ->text();
891 anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
896 case GEOM_POINT_INTINT :
897 anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
898 if ( !anObj->_is_nil() ) {
899 QString aName = getNewObjectName();
900 if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
901 initName( tr( "GEOM_COMPOUND" ) );
902 else if ( anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
903 initName( tr( "GEOM_VERTEX" ) );
907 case GEOM_POINT_SURF :
909 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
910 anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
911 aParameters<<GroupOnSurface->SpinBox_DX->text();
912 aParameters<<GroupOnSurface->SpinBox_DY->text();
914 double x = GroupXYZ->SpinBox_DX->value();
915 double y = GroupXYZ->SpinBox_DY->value();
916 double z = GroupXYZ->SpinBox_DZ->value();
918 aParameters << GroupXYZ->SpinBox_DX->text();
919 aParameters << GroupXYZ->SpinBox_DY->text();
920 aParameters << GroupXYZ->SpinBox_DZ->text();
922 anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
929 const int id = getConstructorId();
930 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
931 id == GEOM_POINT_REF ||
932 id == GEOM_POINT_EDGE ||
933 id == GEOM_POINT_SURF) ) {
934 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
937 if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
939 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
940 aShape.ShapeType() == TopAbs_VERTEX ) {
941 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
942 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
943 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
944 myX->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
945 myY->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
946 myZ->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
955 if ( !anObj->_is_nil() ) {
956 objects.push_back( anObj._retn() );
962 //=================================================================================
963 // function : addSubshapeToStudy
964 // purpose : virtual method to add new SubObjects if local selection
965 //=================================================================================
966 void BasicGUI_PointDlg::addSubshapesToStudy()
968 QMap<QString, GEOM::GEOM_Object_var> objMap;
970 switch ( getConstructorId() ) {
974 objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
976 case GEOM_POINT_EDGE:
977 objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
979 case GEOM_POINT_INTINT:
980 objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
981 objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
983 case GEOM_POINT_SURF:
984 objMap[GroupOnSurface->LineEdit1->text()] = myFace;
987 addSubshapesToFather( objMap );
990 //=================================================================================
991 // function : ClickParamCoord()
993 //=================================================================================
994 void BasicGUI_PointDlg::ClickParamCoord( int id )
996 updateParamCoord( true );
1000 //=================================================================================
1001 // function : updateParamCoord
1003 //=================================================================================
1004 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
1006 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
1007 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
1009 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1010 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
1012 const int id = getConstructorId();
1013 if ( id == GEOM_POINT_EDGE ) {
1014 GroupOnCurve->TextLabel2->setVisible( isParam || isLength );
1015 GroupOnCurve->SpinBox_DX->setVisible( isParam || isLength );
1017 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision" );
1018 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
1019 GroupOnCurve->TextLabel2->setText(tr( "GEOM_PARAMETER" ));
1020 GroupOnCurve->CheckButton1->setVisible(false);
1022 else if ( isLength ){
1023 initSpinBox( GroupOnCurve->SpinBox_DX, 0.0, COORD_MAX, step, "length_precision" );
1024 GroupOnCurve->SpinBox_DX->setValue( 0.0 );
1025 GroupOnCurve->TextLabel2->setText(tr( "GEOM_LENGTH" ));
1026 GroupOnCurve->CheckButton1->setVisible(true);
1029 else if ( id == GEOM_POINT_SURF ) {
1030 GroupOnSurface->TextLabel2->setShown( isParam );
1031 GroupOnSurface->TextLabel3->setShown( isParam );
1032 GroupOnSurface->SpinBox_DX->setShown( isParam );
1033 GroupOnSurface->SpinBox_DY->setShown( isParam );
1036 GroupXYZ->setShown( !isParam && !isLength );
1039 QTimer::singleShot(50, this, SLOT(updateSize()));
1042 //=================================================================================
1043 // function : onBtnPopup()
1045 //=================================================================================
1046 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
1048 int index = myActions[a];
1049 globalSelection(); // close local contexts, if any
1052 myNeedType = TopAbs_EDGE;
1054 myNeedType = TopAbs_WIRE;
1056 localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1059 //=================================================================================
1060 // function : updateSize
1061 // purpose : adjust dialog size to minimum
1062 //=================================================================================
1063 void BasicGUI_PointDlg::updateSize()
1065 qApp->processEvents();
1067 resize( minimumSizeHint() );