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;
237 /* Get setting of step value from file configuration */
238 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
239 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
241 /* min, max, step and decimals for spin boxes */
242 initSpinBox( GroupXYZ->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
243 initSpinBox( GroupXYZ->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
244 initSpinBox( GroupXYZ->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
245 GroupXYZ->SpinBox_DX->setValue( 0.0 );
246 GroupXYZ->SpinBox_DY->setValue( 0.0 );
247 GroupXYZ->SpinBox_DZ->setValue( 0.0 );
249 initSpinBox( GroupRefPoint->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
250 initSpinBox( GroupRefPoint->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
251 initSpinBox( GroupRefPoint->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
252 GroupRefPoint->SpinBox_DX->setValue( 0.0 );
253 GroupRefPoint->SpinBox_DY->setValue( 0.0 );
254 GroupRefPoint->SpinBox_DZ->setValue( 0.0 );
258 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., step, "parametric_precision" );
259 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
261 initSpinBox( GroupOnSurface->SpinBox_DX, 0., 1., step, "parametric_precision" );
262 GroupOnSurface->SpinBox_DX->setValue( 0.5 );
263 initSpinBox( GroupOnSurface->SpinBox_DY, 0., 1., step, "parametric_precision" );
264 GroupOnSurface->SpinBox_DY->setValue( 0.5 );
266 /* signals and slots connections */
267 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
268 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
270 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
271 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
273 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
275 connect( myParamCoord, SIGNAL( buttonClicked( int ) ), this, SLOT( ClickParamCoord( int ) ) );
276 connect( GroupOnCurve->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
277 connect( GroupOnCurve->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
279 connect( GroupOnSurface->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
280 connect( GroupOnSurface->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
282 connect( myBtnPopup, SIGNAL( triggered( QAction* ) ), SLOT( onBtnPopup( QAction* ) ) );
283 connect( GroupLineIntersection->PushButton1, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
284 connect( GroupLineIntersection->PushButton2, SIGNAL( pressed() ), this, SLOT( SetEditCurrentArgument() ) );
285 connect( GroupLineIntersection->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
286 connect( GroupLineIntersection->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
288 connect( GroupOnCurve->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
289 connect( GroupOnSurface->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
290 connect( GroupOnSurface->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
291 connect( GroupXYZ->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
292 connect( GroupXYZ->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
293 connect( GroupXYZ->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
294 connect( GroupRefPoint->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
295 connect( GroupRefPoint->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
296 connect( GroupRefPoint->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
298 connect( GroupOnCurve->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( CheckBoxClicked( int ) ) );
300 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
302 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged() ),
303 this, SLOT(SelectionIntoArgument() ) );
305 initName( tr( "GEOM_VERTEX" ) );
307 ConstructorsClicked( 0 );
310 //=================================================================================
311 // function : SetDoubleSpinBoxStep()
312 // purpose : Double spin box management
313 //=================================================================================
314 void BasicGUI_PointDlg::SetDoubleSpinBoxStep( double step )
316 GroupOnCurve->SpinBox_DX->setSingleStep(step);
317 GroupXYZ->SpinBox_DX->setSingleStep(step);
318 GroupXYZ->SpinBox_DY->setSingleStep(step);
319 GroupXYZ->SpinBox_DZ->setSingleStep(step);
320 GroupRefPoint->SpinBox_DX->setSingleStep(step);
321 GroupRefPoint->SpinBox_DY->setSingleStep(step);
322 GroupRefPoint->SpinBox_DZ->setSingleStep(step);
326 //=================================================================================
327 // function : ConstructorsClicked()
328 // purpose : Radio button management
329 //=================================================================================
330 void BasicGUI_PointDlg::ConstructorsClicked(int constructorId)
332 switch ( constructorId ) {
335 globalSelection(); // close local contexts, if any
336 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
338 GroupRefPoint->hide();
339 GroupOnCurve->hide();
340 GroupLineIntersection->hide();
341 GroupOnSurface->hide();
343 myParamGroup->hide();
349 globalSelection(); // close local contexts, if any
350 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
352 myEditCurrentArgument = GroupRefPoint->LineEdit1;
353 myEditCurrentArgument->setText( "" );
354 myRefPoint = GEOM::GEOM_Object::_nil();
355 GroupRefPoint->PushButton1->setDown(true);
356 myParamGroup->hide();
358 GroupOnCurve->hide();
359 GroupLineIntersection->hide();
360 GroupOnSurface->hide();
361 GroupRefPoint->show();
365 case GEOM_POINT_EDGE:
367 globalSelection(); // close local contexts, if any
368 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
370 myEditCurrentArgument = GroupOnCurve->LineEdit1;
371 myEditCurrentArgument->setText( "" );
372 myEdge = GEOM::GEOM_Object::_nil();
373 GroupOnCurve->PushButton1->setDown(true);
374 GroupRefPoint->hide();
375 GroupLineIntersection->hide();
376 GroupOnSurface->hide();
377 myParamGroup->show();
378 myParamCoord->button( LENGTH_VALUE )->show();
379 myParamCoord->button( PARAM_VALUE )->setChecked( true );
380 GroupOnCurve->show();
382 updateParamCoord( false );
385 case GEOM_POINT_INTINT:
387 globalSelection(); // close local contexts, if any
388 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
389 myNeedType = TopAbs_EDGE;
391 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
392 GroupLineIntersection->LineEdit1->setText( "" );
393 GroupLineIntersection->LineEdit2->setText( "" );
394 GroupLineIntersection->LineEdit1->setEnabled( true );
395 GroupLineIntersection->LineEdit2->setEnabled( false );
396 myLine1 = GEOM::GEOM_Object::_nil();
397 myLine2 = GEOM::GEOM_Object::_nil();
398 GroupLineIntersection->PushButton1->setDown(true);
399 GroupLineIntersection->PushButton2->setDown(false);
400 myParamGroup->hide();
402 GroupRefPoint->hide();
403 GroupOnCurve->hide();
404 GroupOnSurface->hide();
406 GroupLineIntersection->show();
409 case GEOM_POINT_SURF:
411 globalSelection(); // close local contexts, if any
412 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
414 myEditCurrentArgument = GroupOnSurface->LineEdit1;
415 myEditCurrentArgument->setText( "" );
416 myFace = GEOM::GEOM_Object::_nil();
417 GroupOnSurface->PushButton1->setDown(true);
418 GroupRefPoint->hide();
419 GroupOnCurve->hide();
420 GroupLineIntersection->hide();
421 myParamGroup->show();
422 myParamCoord->button( LENGTH_VALUE )->hide();
423 myParamCoord->button( PARAM_VALUE )->setChecked(true);
424 GroupOnSurface->show();
426 updateParamCoord( false );
435 QTimer::singleShot(50, this, SLOT(updateSize()));
437 SelectionIntoArgument();
441 //=================================================================================
442 // function : ClickOnOk()
444 //=================================================================================
445 void BasicGUI_PointDlg::ClickOnOk()
452 //=================================================================================
453 // function : ClickOnApply()
455 //=================================================================================
456 bool BasicGUI_PointDlg::ClickOnApply()
462 ConstructorsClicked( getConstructorId() );
467 //=================================================================================
468 // function : SelectionIntoArgument()
469 // purpose : Called when selection as changed (for constructors not using local context)
470 //=================================================================================
471 void BasicGUI_PointDlg::SelectionIntoArgument()
474 const int id = getConstructorId();
476 if ( ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) && myEditCurrentArgument != 0 )
478 myEditCurrentArgument->setText( "" );
482 myRefPoint = myEdge = myFace = GEOM::GEOM_Object::_nil();
483 } else if ( id == GEOM_POINT_INTINT ) {
484 myEditCurrentArgument->setText( "" );
485 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 )
486 myLine1 = GEOM::GEOM_Object::_nil();
487 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 )
488 myLine2 = GEOM::GEOM_Object::_nil();
491 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
492 SALOME_ListIO aSelList;
493 aSelMgr->selectedObjects(aSelList);
495 if (aSelList.Extent() == 1) {
496 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
497 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO );
498 if ( !CORBA::is_nil( aSelectedObject ) ) {
499 QString aName = GEOMBase::GetName(aSelectedObject);
501 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
502 if ( id == GEOM_POINT_XYZ || id == GEOM_POINT_REF)
503 myNeedType = TopAbs_VERTEX;
504 else if ( id == GEOM_POINT_EDGE )
505 myNeedType = TopAbs_EDGE;
506 else if ( id == GEOM_POINT_SURF )
507 myNeedType = TopAbs_FACE;
509 TColStd_IndexedMapOfInteger aMap;
510 aSelMgr->GetIndexes(anIO, aMap);
511 if ( aMap.Extent() == 1 ) { // Local Selection
512 int anIndex = aMap( 1 );
513 if ( myNeedType == TopAbs_FACE )
514 aName += QString( ":face_%1" ).arg( anIndex );
515 else if ( myNeedType == TopAbs_WIRE )
516 aName += QString( ":wire_%1" ).arg( anIndex );
517 else if ( myNeedType == TopAbs_EDGE )
518 aName += QString( ":edge_%1" ).arg( anIndex );
519 else if ( myNeedType == TopAbs_VERTEX )
520 aName += QString( ":vertex_%1" ).arg( anIndex );
522 //Find SubShape Object in Father
523 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
524 if ( aFindedObject->_is_nil() ) { // Object not found in study
525 GEOM::GEOM_IShapesOperations_var aShapesOp =
526 getGeomEngine()->GetIShapesOperations(getStudyId());
527 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
530 aSelectedObject = aFindedObject; // get Object from study
532 GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE );
534 else { // Global Selection
535 if ( aShape.ShapeType() != myNeedType ) {
536 aSelectedObject = GEOM::GEOM_Object::_nil();
538 if ( id == GEOM_POINT_XYZ ) return;
543 if ( aShape.IsNull() || aShape.ShapeType() != myNeedType)
548 if ( id == GEOM_POINT_XYZ ) {
549 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
550 GroupXYZ->SpinBox_DX->setValue( aPnt.X() );
551 GroupXYZ->SpinBox_DY->setValue( aPnt.Y() );
552 GroupXYZ->SpinBox_DZ->setValue( aPnt.Z() );
554 else if ( id == GEOM_POINT_REF ) {
555 myRefPoint = aSelectedObject;
556 GroupRefPoint->LineEdit1->setText( aName );
558 else if ( id == GEOM_POINT_EDGE ) {
559 myEdge = aSelectedObject;
560 GroupOnCurve->LineEdit1->setText( aName );
562 else if ( id == GEOM_POINT_INTINT ) {
563 myEditCurrentArgument->setText( aName );
564 if ( myEditCurrentArgument == GroupLineIntersection->LineEdit1 ) {
565 myLine1 = aSelectedObject;
566 if ( !myLine1->_is_nil() && myLine2->_is_nil() ) {
567 GroupLineIntersection->PushButton2->setMenu( 0 );
568 GroupLineIntersection->PushButton2->click();
569 GroupLineIntersection->PushButton2->setDown(true);
570 GroupLineIntersection->PushButton2->setMenu( myBtnPopup );
573 else if ( myEditCurrentArgument == GroupLineIntersection->LineEdit2 ) {
574 myLine2 = aSelectedObject;
575 if ( !myLine2->_is_nil() && myLine1->_is_nil() ) {
576 GroupLineIntersection->PushButton1->setMenu( 0 );
577 GroupLineIntersection->PushButton1->click();
578 GroupLineIntersection->PushButton1->setDown(true);
579 GroupLineIntersection->PushButton1->setMenu( myBtnPopup );
583 else if ( id == GEOM_POINT_SURF )
585 myFace = aSelectedObject;
586 GroupOnSurface->LineEdit1->setText( aName );
596 //=================================================================================
597 // function : LineEditReturnPressed()
599 //=================================================================================
600 void BasicGUI_PointDlg::LineEditReturnPressed()
602 QLineEdit* send = (QLineEdit*)sender();
603 if ( send == GroupRefPoint->LineEdit1 ||
604 send == GroupOnCurve->LineEdit1 ||
605 send == GroupLineIntersection->LineEdit1 ||
606 send == GroupLineIntersection->LineEdit2 ) {
607 myEditCurrentArgument = send;
608 GEOMBase_Skeleton::LineEditReturnPressed();
613 //=================================================================================
614 // function : SetEditCurrentArgument()
616 //=================================================================================
617 void BasicGUI_PointDlg::SetEditCurrentArgument()
619 QPushButton* send = (QPushButton*)sender();
621 if ( send == GroupRefPoint->PushButton1 ) {
622 GroupRefPoint->LineEdit1->setFocus();
623 myEditCurrentArgument = GroupRefPoint->LineEdit1;
624 globalSelection(); // close local contexts, if any
625 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
627 else if ( send == GroupOnCurve->PushButton1 ) {
628 GroupOnCurve->LineEdit1->setFocus();
629 myEditCurrentArgument = GroupOnCurve->LineEdit1;
630 globalSelection(); // close local contexts, if any
631 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
633 else if ( send == GroupOnSurface->PushButton1 )
635 GroupOnSurface->LineEdit1->setFocus();
636 myEditCurrentArgument = GroupOnSurface->LineEdit1;
637 globalSelection(); // close local contexts, if any
638 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
640 else if ( send == GroupLineIntersection->PushButton1 ) {
641 GroupLineIntersection->LineEdit1->setFocus();
642 myEditCurrentArgument = GroupLineIntersection->LineEdit1;
643 GroupLineIntersection->PushButton2->setDown( false );
644 GroupLineIntersection->LineEdit1->setEnabled(true);
645 GroupLineIntersection->LineEdit2->setEnabled(false);
647 else if ( send == GroupLineIntersection->PushButton2 ) {
648 GroupLineIntersection->LineEdit2->setFocus();
649 myEditCurrentArgument = GroupLineIntersection->LineEdit2;
650 GroupLineIntersection->PushButton1->setDown( false );
651 GroupLineIntersection->LineEdit1->setEnabled(false);
652 GroupLineIntersection->LineEdit2->setEnabled(true);
656 if ( ( send == GroupLineIntersection->PushButton1 ||
657 send == GroupLineIntersection->PushButton2 ) && !myBusy )
658 SelectionIntoArgument();
662 //=================================================================================
663 // function : enterEvent()
664 // purpose : to reactivate this dialog box when mouse enter onto the window
665 //=================================================================================
666 void BasicGUI_PointDlg::enterEvent( QEvent* )
668 if ( !mainFrame()->GroupConstructors->isEnabled() )
669 ActivateThisDialog();
673 //=================================================================================
674 // function : ActivateThisDialog()
676 //=================================================================================
677 void BasicGUI_PointDlg::ActivateThisDialog( )
679 GEOMBase_Skeleton::ActivateThisDialog();
681 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
682 this, SLOT( SelectionIntoArgument() ) );
684 ConstructorsClicked( getConstructorId() );
688 //=================================================================================
689 // function : DeactivateActiveDialog()
690 // purpose : public slot to deactivate if active
691 //=================================================================================
692 void BasicGUI_PointDlg::DeactivateActiveDialog()
694 // myGeomGUI->SetState( -1 );
695 GEOMBase_Skeleton::DeactivateActiveDialog();
699 //=================================================================================
700 // function : ValueChangedInSpinBox()
702 //=================================================================================
703 void BasicGUI_PointDlg::ValueChangedInSpinBox(double newValue)
708 //=================================================================================
709 // function : CheckBoxClicked()
710 // purpose : Check Boxes Management
711 //=================================================================================
712 void BasicGUI_PointDlg::CheckBoxClicked( int State )
718 //=================================================================================
719 // funcion : getParameter()
721 //=================================================================================
722 double BasicGUI_PointDlg::getParameter() const
724 return GroupOnCurve->SpinBox_DX->value();
728 //=================================================================================
729 // funcion : getUParameter()
731 //=================================================================================
732 double BasicGUI_PointDlg::getUParameter() const
734 return GroupOnSurface->SpinBox_DX->value();
738 //=================================================================================
739 // funcion : getVParameter()
741 //=================================================================================
742 double BasicGUI_PointDlg::getVParameter() const
744 return GroupOnSurface->SpinBox_DY->value();
748 //=================================================================================
749 // function : OnPointSelected
751 //=================================================================================
752 void BasicGUI_PointDlg::OnPointSelected( const gp_Pnt& thePnt )
754 if ( getConstructorId() == GEOM_POINT_XYZ ) {
755 GroupXYZ->SpinBox_DX->setValue( thePnt.X() );
756 GroupXYZ->SpinBox_DY->setValue( thePnt.Y() );
757 GroupXYZ->SpinBox_DZ->setValue( thePnt.Z() );
763 //=================================================================================
764 // function : createOperation
766 //=================================================================================
767 GEOM::GEOM_IOperations_ptr BasicGUI_PointDlg::createOperation()
769 return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
772 //=================================================================================
773 // function : isValid
775 //=================================================================================
776 bool BasicGUI_PointDlg::isValid( QString& msg )
778 const int id = getConstructorId();
779 if ( id == GEOM_POINT_XYZ ) {
781 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
782 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
783 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
786 else if ( id == GEOM_POINT_REF ) {
788 ok = GroupRefPoint->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
789 ok = GroupRefPoint->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
790 ok = GroupRefPoint->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
792 return !myRefPoint->_is_nil() && ok;
794 else if ( id == GEOM_POINT_EDGE ) {
796 if ( myParamCoord->checkedId() == PARAM_VALUE || myParamCoord->checkedId() == LENGTH_VALUE )
797 ok = GroupOnCurve->SpinBox_DX->isValid( msg, !IsPreview() );
799 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
800 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
801 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
803 return !myEdge->_is_nil() && ok;
805 else if ( id == GEOM_POINT_INTINT )
806 return ( !myLine1->_is_nil() && !myLine2->_is_nil() );
807 else if ( id == GEOM_POINT_SURF ) {
809 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
810 ok = GroupOnSurface->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
811 ok = GroupOnSurface->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
814 ok = GroupXYZ->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
815 ok = GroupXYZ->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
816 ok = GroupXYZ->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
818 return !myFace->_is_nil() && ok;
823 //=================================================================================
824 // function : execute
826 //=================================================================================
827 bool BasicGUI_PointDlg::execute( ObjectList& objects )
831 GEOM::GEOM_Object_var anObj;
832 QStringList aParameters;
834 GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
836 switch ( getConstructorId() ) {
837 case GEOM_POINT_XYZ :
839 double x = GroupXYZ->SpinBox_DX->value();
840 double y = GroupXYZ->SpinBox_DY->value();
841 double z = GroupXYZ->SpinBox_DZ->value();
843 aParameters << GroupXYZ->SpinBox_DX->text();
844 aParameters << GroupXYZ->SpinBox_DY->text();
845 aParameters << GroupXYZ->SpinBox_DZ->text();
847 anObj = anOper->MakePointXYZ( x, y, z );
851 case GEOM_POINT_REF :
853 double dx = GroupRefPoint->SpinBox_DX->value();
854 double dy = GroupRefPoint->SpinBox_DY->value();
855 double dz = GroupRefPoint->SpinBox_DZ->value();
857 aParameters << GroupRefPoint->SpinBox_DX->text();
858 aParameters << GroupRefPoint->SpinBox_DY->text();
859 aParameters << GroupRefPoint->SpinBox_DZ->text();
861 anObj = anOper->MakePointWithReference( myRefPoint, dx, dy, dz );
865 case GEOM_POINT_EDGE :
867 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
868 anObj = anOper->MakePointOnCurve( myEdge, getParameter() );
869 aParameters<<GroupOnCurve->SpinBox_DX->text();
871 else if ( myParamCoord->checkedId() == LENGTH_VALUE ) {
872 bool reversed = GroupOnCurve->CheckButton1->isChecked();
873 anObj = anOper->MakePointOnCurveByLength( myEdge, getParameter(), reversed );
875 aParameters<<GroupOnCurve->SpinBox_DX->text();
876 aParameters<<QString::number( reversed );
878 else if ( myParamCoord->checkedId() == COORD_VALUE ) {
879 double x = GroupXYZ->SpinBox_DX->value();
880 double y = GroupXYZ->SpinBox_DY->value();
881 double z = GroupXYZ->SpinBox_DZ->value();
883 aParameters << GroupXYZ->SpinBox_DX->text();
884 aParameters << GroupXYZ->SpinBox_DY->text();
885 aParameters << GroupXYZ->SpinBox_DZ->text();
887 anObj = anOper->MakePointOnCurveByCoord( myEdge, x, y, z );
892 case GEOM_POINT_INTINT :
893 anObj = anOper->MakePointOnLinesIntersection( myLine1, myLine2 );
894 if ( !anObj->_is_nil() ) {
895 QString aName = getNewObjectName();
896 if ( anObj->GetShapeType() == GEOM::COMPOUND && aName.startsWith("Vertex") )
897 initName( tr( "GEOM_COMPOUND" ) );
898 else if ( anObj->GetShapeType() == GEOM::VERTEX && aName.startsWith("Compound"))
899 initName( tr( "GEOM_VERTEX" ) );
903 case GEOM_POINT_SURF :
905 if ( myParamCoord->checkedId() == PARAM_VALUE ) {
906 anObj = anOper->MakePointOnSurface( myFace, getUParameter(), getVParameter() );
907 aParameters<<GroupOnSurface->SpinBox_DX->text();
908 aParameters<<GroupOnSurface->SpinBox_DY->text();
910 double x = GroupXYZ->SpinBox_DX->value();
911 double y = GroupXYZ->SpinBox_DY->value();
912 double z = GroupXYZ->SpinBox_DZ->value();
914 aParameters << GroupXYZ->SpinBox_DX->text();
915 aParameters << GroupXYZ->SpinBox_DY->text();
916 aParameters << GroupXYZ->SpinBox_DZ->text();
918 anObj = anOper->MakePointOnSurfaceByCoord( myFace, x, y, z );
925 const int id = getConstructorId();
926 if(!anObj->_is_nil() && !IsPreview() && (id == GEOM_POINT_XYZ ||
927 id == GEOM_POINT_REF ||
928 id == GEOM_POINT_EDGE ||
929 id == GEOM_POINT_SURF) ) {
930 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
933 if ( id == GEOM_POINT_REF || id == GEOM_POINT_EDGE || id == GEOM_POINT_SURF ) {
935 if ( GEOMBase::GetShape( anObj, aShape ) && !aShape.IsNull() &&
936 aShape.ShapeType() == TopAbs_VERTEX ) {
937 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
938 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
939 int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
940 myX->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
941 myY->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
942 myZ->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
951 if ( !anObj->_is_nil() ) {
952 objects.push_back( anObj._retn() );
958 //=================================================================================
959 // function : addSubshapeToStudy
960 // purpose : virtual method to add new SubObjects if local selection
961 //=================================================================================
962 void BasicGUI_PointDlg::addSubshapesToStudy()
964 QMap<QString, GEOM::GEOM_Object_var> objMap;
966 switch ( getConstructorId() ) {
970 objMap[GroupRefPoint->LineEdit1->text()] = myRefPoint;
972 case GEOM_POINT_EDGE:
973 objMap[GroupOnCurve->LineEdit1->text()] = myEdge;
975 case GEOM_POINT_INTINT:
976 objMap[GroupLineIntersection->LineEdit1->text()] = myLine1;
977 objMap[GroupLineIntersection->LineEdit2->text()] = myLine2;
979 case GEOM_POINT_SURF:
980 objMap[GroupOnSurface->LineEdit1->text()] = myFace;
983 addSubshapesToFather( objMap );
986 //=================================================================================
987 // function : ClickParamCoord()
989 //=================================================================================
990 void BasicGUI_PointDlg::ClickParamCoord( int id )
992 updateParamCoord( true );
996 //=================================================================================
997 // function : updateParamCoord
999 //=================================================================================
1000 void BasicGUI_PointDlg::updateParamCoord(bool theIsUpdate)
1002 bool isParam = myParamCoord->checkedId() == PARAM_VALUE;
1003 bool isLength = myParamCoord->checkedId() == LENGTH_VALUE;
1005 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1006 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
1008 const int id = getConstructorId();
1009 if ( id == GEOM_POINT_EDGE ) {
1010 GroupOnCurve->TextLabel2->setVisible( isParam || isLength );
1011 GroupOnCurve->SpinBox_DX->setVisible( isParam || isLength );
1013 initSpinBox( GroupOnCurve->SpinBox_DX, 0., 1., 0.1, "parametric_precision" );
1014 GroupOnCurve->SpinBox_DX->setValue( 0.5 );
1015 GroupOnCurve->TextLabel2->setText(tr( "GEOM_PARAMETER" ));
1016 GroupOnCurve->CheckButton1->setVisible(false);
1018 else if ( isLength ){
1019 initSpinBox( GroupOnCurve->SpinBox_DX, 0.0, COORD_MAX, step, "length_precision" );
1020 GroupOnCurve->SpinBox_DX->setValue( 0.0 );
1021 GroupOnCurve->TextLabel2->setText(tr( "GEOM_LENGTH" ));
1022 GroupOnCurve->CheckButton1->setVisible(true);
1025 else if ( id == GEOM_POINT_SURF ) {
1026 GroupOnSurface->TextLabel2->setShown( isParam );
1027 GroupOnSurface->TextLabel3->setShown( isParam );
1028 GroupOnSurface->SpinBox_DX->setShown( isParam );
1029 GroupOnSurface->SpinBox_DY->setShown( isParam );
1032 GroupXYZ->setShown( !isParam && !isLength );
1035 QTimer::singleShot(50, this, SLOT(updateSize()));
1038 //=================================================================================
1039 // function : onBtnPopup()
1041 //=================================================================================
1042 void BasicGUI_PointDlg::onBtnPopup( QAction* a )
1044 int index = myActions[a];
1045 globalSelection(); // close local contexts, if any
1048 myNeedType = TopAbs_EDGE;
1050 myNeedType = TopAbs_WIRE;
1052 localSelection( GEOM::GEOM_Object::_nil(), myNeedType );
1055 //=================================================================================
1056 // function : updateSize
1057 // purpose : adjust dialog size to minimum
1058 //=================================================================================
1059 void BasicGUI_PointDlg::updateSize()
1061 qApp->processEvents();
1063 resize( minimumSizeHint() );