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 : EntityGUI_SketcherDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "EntityGUI_SketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
32 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
34 #include <Geom_Surface.hxx>
35 #include <Geom_Plane.hxx>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Application.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
47 #include <BRep_Tool.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Vertex.hxx>
52 #include <BRepBuilderAPI_Transform.hxx>
53 #include <BRepBuilderAPI_MakeWire.hxx>
54 #include <Sketcher_Profile.hxx>
56 #include <SalomeApp_Study.h>
60 //=================================================================================
61 // class : EntityGUI_SketcherDlg()
62 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
63 // name 'name' and widget flags set to 'f'.
64 // The dialog will by default be modeless, unless you set 'modal' to
65 // TRUE to construct a modal dialog.
66 //=================================================================================
67 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
68 bool modal, Qt::WindowFlags fl,
69 const double lineWidth )
70 : QDialog( parent, fl ),
71 myIsAllAdded( false ),
73 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
75 myLineWidth( lineWidth )
78 setAttribute( Qt::WA_DeleteOnClose );
80 myGeometryGUI->SetActiveDialogBox(this);
82 MainWidget = new EntityGUI_Skeleton( this );
83 QVBoxLayout* topLayout = new QVBoxLayout( this );
84 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
86 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
87 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
88 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
89 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
91 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
92 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
93 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
95 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
97 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
98 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
99 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
100 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
101 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
102 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
103 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
105 /***************************************************************/
107 GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
108 QGridLayout* OwnLayout = new QGridLayout(GroupBox1);
109 OwnLayout->setSpacing(6);
110 OwnLayout->setMargin(11);
112 ComboBox1 = new QComboBox(GroupBox1);
113 OwnLayout->addWidget(ComboBox1);
115 topLayout->addWidget(GroupBox1);
116 topLayout->addWidget( MainWidget );
118 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
120 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
121 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
122 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
123 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
125 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
127 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
128 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
129 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
130 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
131 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
133 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
135 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
136 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
137 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
138 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
140 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
142 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
143 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
144 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
145 Group1Sel->PushButton1->setIcon( image0 );
146 Group1Sel->buttonUndo->setIcon( image1 );
147 Group1Sel->buttonRedo->setIcon( image2 );
148 Group1Sel->LineEdit1->setReadOnly( true );
150 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
151 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
152 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
153 Group1Spin->buttonUndo->setIcon( image1 );
154 Group1Spin->buttonRedo->setIcon( image2 );
156 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
157 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
158 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
159 Group2Spin->buttonUndo->setIcon( image1 );
160 Group2Spin->buttonRedo->setIcon( image2 );
162 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
163 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
164 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
165 Group3Spin->buttonUndo->setIcon( image1 );
166 Group3Spin->buttonRedo->setIcon( image2 );
168 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
169 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
170 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
171 Group4Spin->buttonUndo->setIcon( image1 );
172 Group4Spin->buttonRedo->setIcon( image2 );
174 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
175 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
176 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
177 DestCntLayout->addWidget( GroupD1, 1, 0 );
178 DestCntLayout->addWidget( GroupD2, 1, 1 );
180 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
181 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
182 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
183 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
184 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
185 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
186 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
187 /***************************************************************/
189 QButtonGroup* ButtonGroup = new QButtonGroup( this );
190 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
191 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
193 /* signals and slots connections */
194 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
195 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
196 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
197 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
199 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
200 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
201 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
202 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
203 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
204 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
205 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
206 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
207 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
208 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
209 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
210 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
211 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
212 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
213 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
215 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
216 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
217 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
218 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
219 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
221 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
222 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
224 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
225 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
226 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
227 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
228 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
229 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
230 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
231 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
232 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
233 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
235 connect( ComboBox1, SIGNAL( activated( int ) ), this, SLOT( SelectionIntoArgument() ) );
237 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
239 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
240 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
242 // install event filter on spin-boxes to provide Apply action on Return pressed
243 Group1Spin->SpinBox_DX->installEventFilter(this);
244 Group2Spin->SpinBox_DX->installEventFilter(this);
245 Group2Spin->SpinBox_DY->installEventFilter(this);
246 Group3Spin->SpinBox_DX->installEventFilter(this);
247 Group3Spin->SpinBox_DY->installEventFilter(this);
248 Group3Spin->SpinBox_DZ->installEventFilter(this);
249 Group4Spin->SpinBox_DX->installEventFilter(this);
250 Group4Spin->SpinBox_DY->installEventFilter(this);
251 Group4Spin->SpinBox_DZ->installEventFilter(this);
252 Group4Spin->SpinBox_DS->installEventFilter(this);
258 //=================================================================================
259 // function : ~EntityGUI_SketcherDlg()
260 // purpose : Destroys the object and frees any allocated resources
261 //=================================================================================
262 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
264 myGeometryGUI->SetActiveDialogBox( 0 );
268 //=================================================================================
269 // function : eventFilter()
270 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
271 //=================================================================================
272 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
274 if (event->type() == QEvent::KeyPress) {
275 QKeyEvent* ke = (QKeyEvent*)event;
276 if (ke->key() == Qt::Key_Return) {
277 if (object == Group1Spin->SpinBox_DX) {
278 Group1Spin->buttonApply->animateClick();
280 } else if (object == Group2Spin->SpinBox_DX ||
281 object == Group2Spin->SpinBox_DY) {
282 Group2Spin->buttonApply->animateClick();
284 } else if (object == Group3Spin->SpinBox_DX ||
285 object == Group3Spin->SpinBox_DY ||
286 object == Group3Spin->SpinBox_DZ) {
287 Group3Spin->buttonApply->animateClick();
289 } else if (object == Group4Spin->SpinBox_DX ||
290 object == Group4Spin->SpinBox_DY ||
291 object == Group4Spin->SpinBox_DZ ||
292 object == Group4Spin->SpinBox_DS) {
293 Group4Spin->buttonApply->animateClick();
299 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
301 return QDialog::eventFilter(object, event);
305 //=================================================================================
308 //=================================================================================
309 void EntityGUI_SketcherDlg::Init()
312 myEditCurrentArgument = Group1Sel->LineEdit1;
313 myCommand.append( "Sketcher" );
314 myUndoCommand.append( "Sketcher" );
316 mySketchState = FIRST_POINT;
317 globalSelection( GEOM_POINT );
324 myHelpFileName = "create_sketcher_page.html";
326 /* Get setting of step value from file configuration */
327 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
329 /* min, max, step and decimals for spin boxes */
330 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
331 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
332 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
333 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
334 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
335 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
336 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
337 // san: Note specific step values below!
338 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
339 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
340 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., "length_precision" );
342 /* displays Dialog */
343 MainWidget->GroupConstructors->setEnabled( false );
344 MainWidget->GroupDest1->setEnabled( false );
345 setEnabledUndo( false );
346 setEnabledRedo( false );
348 MainWidget->RadioButton1->setChecked( true );
356 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
360 //=================================================================================
361 // function : InitClick()
363 //=================================================================================
364 void EntityGUI_SketcherDlg::InitClick()
366 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
376 //=================================================================================
377 // function : TypeClicked()
378 // purpose : Radio button management
379 //=================================================================================
380 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
382 myConstructorId = constructorId;
383 if ( myConstructorId == 0 ) { // SEGMENT
384 GroupD2->setEnabled( true );
385 MainWidget->RB_Dest1->setEnabled( true );
386 MainWidget->RB_Dest1->setChecked( true );
389 else if ( myConstructorId == 1 ) { // ARC
390 GroupD2->setEnabled( false );
391 MainWidget->RB_Dest1->setEnabled( false );
392 MainWidget->RB_Dest2->setChecked( true );
398 //=================================================================================
399 // function : DestClicked()
400 // purpose : Radio button management
401 //=================================================================================
402 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
408 if ( constructorId == 1 ) {
410 GroupPt->RB_Point1->setChecked( true );
412 PointClicked( 1 ); // XY
414 else if ( constructorId == 0 ) {
416 GroupD1->RB_Dir11->setChecked( true );
419 Dir1Clicked( 2 ); // Angle
424 //=================================================================================
425 // function : PointClicked()
426 // purpose : Radio button management
427 //=================================================================================
428 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
432 // Get setting of step value from file configuration
433 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
435 if ( myConstructorId == 0 ) { // SEGMENT
436 if ( constructorId == 1 ) { // XY
437 mySketchType = PT_ABS;
438 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
439 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
440 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
441 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
443 Group2Spin->SpinBox_DX->setValue( myX );
445 Group2Spin->SpinBox_DY->setValue( myY );
447 Group2Spin->buttonApply->setFocus();
449 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
451 else if ( constructorId == 0 ) { // DXDY
452 mySketchType = PT_RELATIVE;
453 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
454 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
455 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
456 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
458 Group2Spin->SpinBox_DX->setValue( myDX );
460 Group2Spin->SpinBox_DY->setValue( myDY );
462 Group2Spin->buttonApply->setFocus();
464 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
466 else if ( constructorId == 2 ) { // Selection
467 mySketchType = PT_SEL;
468 myEditCurrentArgument = Group1Sel->LineEdit1;
469 connect( myGeometryGUI->getApp()->selectionMgr(),
470 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
472 Group1Sel->buttonApply->setFocus();
473 SelectionIntoArgument();
479 //=================================================================================
480 // function : Dir1Clicked()
481 // purpose : Radio button management
482 //=================================================================================
483 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
485 myConstructorDirId = constructorId;
486 GroupD2->RB_Dir21->setChecked( true );
491 //=================================================================================
492 // function : Dir2Clicked()
493 // purpose : Radio button management
494 //=================================================================================
495 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
500 // Get setting of step value from file configuration
501 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
503 if ( myConstructorId == 0 ) { // SEGMENT
507 if ( myConstructorDirId == 2 ) { // Angle
508 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "length_precision" );
509 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
510 Group2Spin->SpinBox_DX->setValue( myAngle );
511 Group2Spin->buttonApply->setFocus();
514 if ( constructorId == 2 ) { // Length
515 mySketchType = DIR_ANGLE_LENGTH;
516 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
517 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
518 Group2Spin->SpinBox_DY->setValue( myLength );
520 else if ( constructorId == 0 ) { // X
521 mySketchType = DIR_ANGLE_X;
522 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
523 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
524 Group2Spin->SpinBox_DY->setValue( myX );
526 else if ( constructorId == 1 ) { // Y
527 mySketchType = DIR_ANGLE_Y;
528 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "angle_precision" );
529 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
530 Group2Spin->SpinBox_DY->setValue( myY );
533 else if ( myConstructorDirId == 0 ) { // Perpendicular
535 Group1Spin->buttonApply->setFocus();
537 if ( constructorId == 2 ) { // Length
538 mySketchType = DIR_PER_LENGTH;
539 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
540 Group1Spin->SpinBox_DX->setValue( myLength );
542 else if ( constructorId == 0 ) { // X
543 mySketchType = DIR_PER_X;
544 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
545 Group1Spin->SpinBox_DX->setValue( myX );
547 else if ( constructorId == 1 ) { // Y
548 mySketchType = DIR_PER_Y;
549 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
550 Group1Spin->SpinBox_DX->setValue( myY );
553 else if ( myConstructorDirId == 1 ) { // Tangent
555 Group1Spin->buttonApply->setFocus();
557 if ( constructorId == 2 ) { // Length
558 mySketchType = DIR_TAN_LENGTH;
559 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
560 Group1Spin->SpinBox_DX->setValue( myLength );
562 else if ( constructorId == 0 ) { // X
563 mySketchType = DIR_TAN_X;
564 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
565 Group1Spin->SpinBox_DX->setValue( myX );
567 else if ( constructorId == 1 ) { // Y
568 mySketchType = DIR_TAN_Y;
569 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
570 Group1Spin->SpinBox_DX->setValue( myY );
573 else if ( myConstructorDirId == 3 ) { // DXDY
574 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
575 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, "length_precision" );
576 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
577 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
578 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
580 Group3Spin->SpinBox_DX->setValue( myDX );
582 Group3Spin->SpinBox_DY->setValue( myDY );
584 Group3Spin->buttonApply->setFocus();
586 if ( constructorId == 2 ) { // Length
587 mySketchType = DIR_DXDY_LENGTH;
588 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
589 Group3Spin->SpinBox_DZ->setValue( myLength );
591 else if ( constructorId == 0 ) { // X
592 mySketchType = DIR_DXDY_X;
593 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
594 Group3Spin->SpinBox_DZ->setValue( myX );
596 else if ( constructorId == 1 ) { // Y
597 mySketchType = DIR_DXDY_Y;
598 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
599 Group3Spin->SpinBox_DZ->setValue( myY );
603 else if ( myConstructorId == 1 ) { // ARC
604 if ( myConstructorDirId == 2 ) { // Angle
605 if ( constructorId == 2 ) { // Length
606 mySketchType = DIR_ANGLE_LENGTH;
607 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., "angle_precision" );
608 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
609 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., "angle_precision" );
610 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
611 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
612 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
613 Group3Spin->SpinBox_DX->setValue( myAngle );
615 Group3Spin->SpinBox_DY->setValue( myRadius );
617 Group3Spin->SpinBox_DZ->setValue( myLength );
619 Group3Spin->buttonApply->setFocus();
622 else if ( myConstructorDirId == 0 ) { // Perpendicular
623 if ( constructorId == 2 ) { // Length
624 mySketchType = DIR_PER_LENGTH;
625 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
626 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
627 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
628 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
630 Group2Spin->SpinBox_DX->setValue( myRadius );
632 Group2Spin->SpinBox_DY->setValue( myLength );
634 Group2Spin->buttonApply->setFocus();
637 else if ( myConstructorDirId == 1 ) { // Tangent
638 if ( constructorId == 2 ) { // Length
639 mySketchType = DIR_TAN_LENGTH;
640 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
641 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., "angle_precision" );
642 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
643 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
645 Group2Spin->SpinBox_DX->setValue( myRadius );
647 Group2Spin->SpinBox_DY->setValue( myLength );
649 Group2Spin->buttonApply->setFocus();
652 else if ( myConstructorDirId == 3 ) { // DXDY
653 if ( constructorId == 2 ) { // Length
654 mySketchType = DIR_DXDY_LENGTH;
655 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
656 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
657 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
658 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
660 Group4Spin->SpinBox_DX->setValue( myDX );
662 Group4Spin->SpinBox_DY->setValue( myDY );
664 Group4Spin->SpinBox_DZ->setValue( myRadius );
666 Group4Spin->SpinBox_DS->setValue( myLength );
668 Group4Spin->buttonApply->setFocus();
673 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
677 //=================================================================================
678 // function : ClickOnCancel()
680 //=================================================================================
681 void EntityGUI_SketcherDlg::ClickOnCancel()
687 //=================================================================================
688 // function : ClickOnEnd()
689 // purpose : connected to buttonEnd AND buttonClose
690 //=================================================================================
691 void EntityGUI_SketcherDlg::ClickOnEnd()
693 if ( sender() == MainWidget->buttonClose ) {
694 // Verify validity of commands
695 if ( myCommand.count() <= 2 ) {
696 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
697 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
702 QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
703 Sketcher_Profile aProfile( Command.toAscii() );
705 Command = myCommand.join( "" );
706 aProfile = Sketcher_Profile( Command.toAscii() );
707 TopoDS_Shape myShape;
708 if ( aProfile.IsDone() )
709 myShape = aProfile.GetShape();
711 if ( myShape.ShapeType() != TopAbs_VERTEX )
712 myCommand.append( ":WW" );
715 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
716 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
717 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
718 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
719 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
720 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
726 if ( myCommand.size() > 2 )
733 //=================================================================================
734 // function : ClickOnApply()
736 //=================================================================================
737 bool EntityGUI_SketcherDlg::ClickOnApply()
739 if ( sender() && sender()->inherits( "QPushButton" ) )
740 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
743 myCommand.append( GetNewCommand( aParameters ) );
744 mySketchState = NEXT_POINT;
746 myUndoCommand.clear();
747 myUndoCommand.append( "Sketcher" );
749 myParameters.append( aParameters );
750 myUndoParameters.clear();
752 MainWidget->GroupConstructors->setEnabled( true );
753 MainWidget->GroupDest1->setEnabled( true );
754 setEnabledUndo( true );
755 setEnabledRedo( false );
758 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
761 // Set focus to SpinBox_DX
762 if ( sender() == Group1Spin->buttonApply ) {
763 (Group1Spin->SpinBox_DX)->setFocus();
764 (Group1Spin->SpinBox_DX)->selectAll();
766 else if ( sender() == Group2Spin->buttonApply ) {
767 (Group2Spin->SpinBox_DX)->setFocus();
768 (Group2Spin->SpinBox_DX)->selectAll();
770 else if ( sender() == Group3Spin->buttonApply ) {
771 (Group3Spin->SpinBox_DX)->setFocus();
772 (Group3Spin->SpinBox_DX)->selectAll();
774 else if ( sender() == Group4Spin->buttonApply ) {
775 (Group4Spin->SpinBox_DX)->setFocus();
776 (Group4Spin->SpinBox_DX)->selectAll();
782 //=================================================================================
783 // function : ClickOnHelp()
785 //=================================================================================
786 void EntityGUI_SketcherDlg::ClickOnHelp()
788 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
790 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
794 platform = "winapplication";
796 platform = "application";
799 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
800 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
801 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
802 QObject::tr( "BUT_OK" ) );
806 //=================================================================================
807 // function : ClickOnUndo()
809 //=================================================================================
810 void EntityGUI_SketcherDlg::ClickOnUndo()
812 myUndoCommand.append( myCommand.last() );
813 myCommand.pop_back();
815 myUndoParameters.append( myParameters.last() );
816 myParameters.pop_back();
818 if ( myCommand.count() == 1 ) {
819 mySketchState = FIRST_POINT;
821 MainWidget->RadioButton1->setChecked( true );
824 MainWidget->GroupConstructors->setEnabled( false );
825 MainWidget->GroupDest1->setEnabled( false );
826 setEnabledUndo( false );
829 setEnabledRedo( true );
831 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
834 //=================================================================================
835 // function : ClickOnRedo()
837 //=================================================================================
838 void EntityGUI_SketcherDlg::ClickOnRedo()
840 myCommand.append( myUndoCommand.last() );
841 myUndoCommand.pop_back();
843 myParameters.append( myUndoParameters.last() );
844 myUndoParameters.pop_back();
846 mySketchState = NEXT_POINT;
848 MainWidget->GroupConstructors->setEnabled( true );
849 MainWidget->GroupDest1->setEnabled( true );
850 setEnabledUndo( true );
852 if ( myUndoCommand.count() == 1 )
853 setEnabledRedo( false );
855 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
858 //=================================================================================
859 // function : setEnabledUndo()
861 //=================================================================================
862 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
864 Group1Sel->buttonUndo->setEnabled( value );
865 Group1Spin->buttonUndo->setEnabled( value );
866 Group2Spin->buttonUndo->setEnabled( value );
867 Group3Spin->buttonUndo->setEnabled( value );
868 Group4Spin->buttonUndo->setEnabled( value );
871 //=================================================================================
872 // function : setEnabledRedo()
874 //=================================================================================
875 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
877 Group1Sel->buttonRedo->setEnabled( value );
878 Group1Spin->buttonRedo->setEnabled( value );
879 Group2Spin->buttonRedo->setEnabled( value );
880 Group3Spin->buttonRedo->setEnabled( value );
881 Group4Spin->buttonRedo->setEnabled( value );
884 //=================================================================================
885 // function : SelectionIntoArgument()
886 // purpose : Called when selection as changed
887 //=================================================================================
888 void EntityGUI_SketcherDlg::SelectionIntoArgument()
890 myEditCurrentArgument->setText( "" );
894 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
895 SALOME_ListIO aSelList;
896 aSelMgr->selectedObjects(aSelList);
898 int nbSel = aSelList.Extent();
899 if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
900 Standard_Boolean aRes = Standard_False;
901 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
902 if (!CORBA::is_nil(aSelectedObject) && aRes) {
904 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
906 gp_Ax3 aWPlane = GetActiveLocalCS();
908 aTrans.SetTransformation(aWPlane);
909 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
910 aShape = aTransformation.Shape();
913 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
916 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
922 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
926 //=================================================================================
927 // function : SetEditCurrentArgument()
929 //=================================================================================
930 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
932 if ( sender() == Group1Sel->PushButton1 ) {
933 myEditCurrentArgument = Group1Sel->LineEdit1;
934 myEditCurrentArgument->setFocus();
936 SelectionIntoArgument();
940 //=================================================================================
941 // function : LineEditReturnPressed()
943 //=================================================================================
944 void EntityGUI_SketcherDlg::LineEditReturnPressed()
946 if ( sender() == Group1Sel->LineEdit1 ) {
947 myEditCurrentArgument = Group1Sel->LineEdit1;
949 /* User name of object input management */
950 /* If successfull the selection is changed and signal emitted... */
951 /* so SelectionIntoArgument() is automatically called. */
952 const QString objectUserName = myEditCurrentArgument->text();
953 QWidget* thisWidget = (QWidget*)this;
955 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
956 SALOME_ListIO aSelList;
957 aSelMgr->selectedObjects(aSelList);
959 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
960 myEditCurrentArgument->setText( objectUserName );
965 //=================================================================================
966 // function : DeactivateActiveDialog()
968 //=================================================================================
969 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
971 //myGeometryGUI->SetState( -1 );
975 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
976 myGeometryGUI->SetActiveDialogBox( 0 );
980 //=================================================================================
981 // function : ActivateThisDialog()
983 //=================================================================================
984 void EntityGUI_SketcherDlg::ActivateThisDialog()
986 myGeometryGUI->EmitSignalDeactivateDialog();
988 myGeometryGUI->SetActiveDialogBox( this );
990 connect( myGeometryGUI->getApp()->selectionMgr(),
991 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
993 //myGeometryGUI->SetState( 0 );
994 globalSelection( GEOM_POINT );
996 myEditCurrentArgument = Group1Sel->LineEdit1;
997 myEditCurrentArgument->setFocus();
999 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1003 //=================================================================================
1004 // function : enterEvent [REDEFINED]
1006 //=================================================================================
1007 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1009 if ( !MainWidget->GroupConstructors->isEnabled() )
1010 ActivateThisDialog();
1014 //=================================================================================
1015 // function : closeEvent()
1017 //=================================================================================
1018 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1020 //myGeometryGUI->SetState( -1 );
1021 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1022 myGeometryGUI->getApp()->updateActions();
1023 QDialog::closeEvent( e );
1027 //=================================================================================
1028 // function : ValueChangedInSpinBox()
1030 //=================================================================================
1031 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1033 QObject* send = (QObject*)sender();
1034 Standard_Real vx, vy, vz, vs;
1035 vx = vy = vz = vs = 0.0;
1037 QString vxStr, vyStr, vzStr, vsStr;
1039 QString newValueStr;
1040 if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1041 newValueStr = aDoubleSpinBox->text();
1043 if ( send == Group1Spin->SpinBox_DX ) {
1044 vx = newValue; vxStr = newValueStr;
1046 else if ( send == Group2Spin->SpinBox_DX ) {
1047 vx = newValue; vxStr = newValueStr;
1048 vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1050 else if ( send == Group2Spin->SpinBox_DY ) {
1051 vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1052 vy = newValue; vyStr = newValueStr;
1054 else if ( send == Group3Spin->SpinBox_DX ) {
1055 vx = newValue; vxStr = newValueStr;
1056 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1057 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1059 else if ( send == Group3Spin->SpinBox_DY ) {
1060 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1061 vy = newValue; vyStr = newValueStr;
1062 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1064 else if ( send == Group3Spin->SpinBox_DZ ) {
1065 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1066 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1067 vz = newValue; vzStr = newValueStr;
1069 else if ( send == Group4Spin->SpinBox_DX ) {
1070 vx = newValue; vxStr = newValueStr;
1071 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1072 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1073 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1075 else if ( send == Group4Spin->SpinBox_DY ) {
1076 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1077 vy = newValue; vyStr = newValueStr;
1078 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1079 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1081 else if ( send == Group4Spin->SpinBox_DZ ) {
1082 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1083 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1084 vz = newValue; vzStr = newValueStr;
1085 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1087 else if ( send == Group4Spin->SpinBox_DS ) {
1088 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1089 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1090 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1091 vs = newValue; vsStr = newValueStr;
1093 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1095 if ( myConstructorId == 0 ) { // SEGMENT
1096 if ( mySketchType == PT_ABS ) {
1102 else if ( mySketchType == PT_RELATIVE ) {
1108 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1112 myLengthStr = vyStr;
1114 else if ( mySketchType == DIR_ANGLE_X ) {
1120 else if ( mySketchType == DIR_ANGLE_Y ) {
1126 else if ( mySketchType == DIR_PER_LENGTH ) {
1128 myLengthStr = vxStr;
1130 else if ( mySketchType == DIR_PER_X ) {
1134 else if ( mySketchType == DIR_PER_Y ) {
1138 else if ( mySketchType == DIR_TAN_LENGTH ) {
1140 myLengthStr = vxStr;
1142 else if ( mySketchType == DIR_TAN_X ) {
1146 else if ( mySketchType == DIR_TAN_Y ) {
1150 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1156 myLengthStr = vzStr;
1158 else if ( mySketchType == DIR_DXDY_X ) {
1166 else if ( mySketchType == DIR_DXDY_Y ) {
1175 else if ( myConstructorId == 1 ) { // ARC
1176 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1181 myRadiusStr = vyStr;
1182 myLengthStr = vzStr;
1184 else if ( mySketchType == DIR_PER_LENGTH ) {
1187 myRadiusStr = vxStr;
1188 myLengthStr = vyStr;
1190 else if ( mySketchType == DIR_TAN_LENGTH ) {
1193 myRadiusStr = vxStr;
1194 myLengthStr = vyStr;
1196 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1203 myRadiusStr = vzStr;
1204 myLengthStr = vsStr;
1208 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1212 //=================================================================================
1213 // function : GetNewCommand()
1214 // purpose : Build the new command with context
1215 //=================================================================================
1216 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1218 theParameters.clear();
1219 QString myNewCommand = ":";
1220 if ( mySketchState == FIRST_POINT ) {
1221 if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1222 myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1223 theParameters = myXStr + ":" + myYStr;
1225 if ( mySketchType == PT_RELATIVE) {
1226 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1227 theParameters = myDXStr + ":" + myDYStr;
1229 return myNewCommand;
1232 if ( myConstructorId == 0 ) { // SEGMENT
1233 if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1234 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1235 theParameters = myXStr + ":" + myYStr;
1237 if ( mySketchType == PT_RELATIVE) {
1238 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1239 theParameters = myDXStr + ":" + myDYStr;
1241 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1242 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1243 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1244 theParameters = myAngleStr + ":" + myLengthStr;
1246 if ( mySketchType == DIR_ANGLE_X ) {
1247 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1248 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1249 theParameters = myAngleStr + ":" + myXStr;
1251 if ( mySketchType == DIR_ANGLE_Y ) {
1252 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1253 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1254 theParameters = myAngleStr + ":" + myYStr;
1256 if ( mySketchType == DIR_PER_LENGTH ) {
1257 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1258 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1259 theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1261 if ( mySketchType == DIR_PER_X ) {
1262 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1263 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1264 theParameters = QString::number( 90.0 ) + ":" + myXStr;
1266 if ( mySketchType == DIR_PER_Y ) {
1267 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1268 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1269 theParameters = QString::number( 90.0 ) + ":" + myYStr;
1271 if ( mySketchType == DIR_TAN_LENGTH ) {
1272 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1273 theParameters = myLengthStr;
1275 if ( mySketchType == DIR_TAN_X ) {
1276 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1277 theParameters = myXStr;
1279 if ( mySketchType == DIR_TAN_Y) {
1280 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1281 theParameters = myYStr;
1283 if ( mySketchType == DIR_DXDY_LENGTH ) {
1284 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1285 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1286 theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1288 if ( mySketchType == DIR_DXDY_X ) {
1289 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1290 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1291 theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1293 if ( mySketchType == DIR_DXDY_Y ) {
1294 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1295 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1296 theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1299 else if ( myConstructorId == 1 ) { // ARC
1300 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1301 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1302 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1303 theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1305 if ( mySketchType == DIR_PER_LENGTH ) {
1306 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1307 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1308 theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1310 if ( mySketchType == DIR_TAN_LENGTH ) {
1311 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1312 theParameters = myRadiusStr + ":" + myLengthStr;
1314 if ( mySketchType == DIR_DXDY_LENGTH ) {
1315 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1316 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1317 theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1320 return myNewCommand;
1323 //=================================================================================
1324 // function : createOperation
1326 //=================================================================================
1327 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1329 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1332 //=================================================================================
1333 // function : isValid
1335 //=================================================================================
1336 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1339 bool toCorrect = !IsPreview() || myIsApply;
1341 if( Group1Spin->isVisible() ) {
1342 ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1344 else if( Group2Spin->isVisible() ) {
1345 ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1346 ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1348 else if( Group3Spin->isVisible() ) {
1349 ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1350 ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1351 ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1353 else if( Group4Spin->isVisible() ) {
1354 ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1355 ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1356 ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1357 ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1360 if( myIsApply && !ok )
1366 //=================================================================================
1367 // function : execute
1369 //=================================================================================
1370 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1372 QString aParameters;
1374 if ( mySketchState == FIRST_POINT ) {
1379 //Test if the current point is the same as the last one
1380 TopoDS_Shape myShape1, myShape2;
1383 QString Command1 = myCommand.join( "" );
1384 Sketcher_Profile aProfile1( Command1.toAscii() );
1385 if ( aProfile1.IsDone() )
1386 myShape1 = aProfile1.GetShape();
1389 QString Command2 = Command1 + GetNewCommand( aParameters );
1390 Sketcher_Profile aProfile2( Command2.toAscii() );
1391 if ( aProfile2.IsDone() )
1392 myShape2 = aProfile2.GetShape();
1394 if ( myShape2.IsNull() ) {
1395 //the current point is the same as the last one
1396 myLastX2 = myLastX1;
1397 myLastY2 = myLastY1;
1400 TopoDS_Vertex V1, V2;
1402 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1403 //the last shape is the first point
1404 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1409 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1410 pt = BRep_Tool::Pnt( V2 );
1414 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1415 pt = BRep_Tool::Pnt( V2 );
1422 if ( ( mySketchState != FIRST_POINT &&
1423 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1424 cmd = myCommand.join( "" );
1426 if ( Group1Sel->isVisible() ) {
1427 Group1Sel->buttonApply->setEnabled( false );
1428 //Group1Sel->buttonApply->setFocus();
1430 if ( Group1Spin->isVisible() ) {
1431 Group1Spin->buttonApply->setEnabled( false );
1432 //Group1Spin->buttonApply->setFocus();
1434 if ( Group2Spin->isVisible() ) {
1435 Group2Spin->buttonApply->setEnabled( false );
1436 //Group2Spin->buttonApply->setFocus();
1438 if ( Group3Spin->isVisible() ) {
1439 Group3Spin->buttonApply->setEnabled( false );
1440 //Group3Spin->buttonApply->setFocus();
1442 if ( Group4Spin->isVisible() ) {
1443 Group4Spin->buttonApply->setEnabled( false );
1444 //Group4Spin->buttonApply->setFocus();
1448 cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1450 if ( Group1Sel->isVisible() ) {
1451 Group1Sel->buttonApply->setEnabled( true );
1452 //Group1Sel->buttonApply->setFocus();
1454 if ( Group1Spin->isVisible() ) {
1455 Group1Spin->buttonApply->setEnabled( true );
1456 //Group1Spin->buttonApply->setFocus();
1458 if ( Group2Spin->isVisible() ) {
1459 Group2Spin->buttonApply->setEnabled( true );
1460 //Group2Spin->buttonApply->setFocus();
1462 if ( Group3Spin->isVisible() ) {
1463 Group3Spin->buttonApply->setEnabled( true );
1464 //Group3Spin->buttonApply->setFocus();
1466 if ( Group4Spin->isVisible() ) {
1467 Group4Spin->buttonApply->setEnabled( true );
1468 //Group4Spin->buttonApply->setFocus();
1472 gp_Ax3 myWPlane = GetActiveLocalCS();
1473 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1474 WPlane->length( 9 );
1475 WPlane[0] = myWPlane.Location().X();
1476 WPlane[1] = myWPlane.Location().Y();
1477 WPlane[2] = myWPlane.Location().Z();
1479 WPlane[3] = myWPlane.Direction().X();
1480 WPlane[4] = myWPlane.Direction().Y();
1481 WPlane[5] = myWPlane.Direction().Z();
1483 WPlane[6] = myWPlane.XDirection().X();
1484 WPlane[7] = myWPlane.XDirection().Y();
1485 WPlane[8] = myWPlane.XDirection().Z();
1487 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1488 GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
1490 if ( !anObj->_is_nil() )
1492 if( !IsPreview() ) {
1493 QStringList aCurrentParameters = myParameters;
1494 aCurrentParameters << aParameters;
1495 anObj->SetParameters(aCurrentParameters.join(":").toLatin1().constData());
1498 objects.push_back( anObj._retn() );
1504 //================================================================
1505 // Function : displayPreview
1506 // Purpose : Method for displaying preview of resulting shape
1507 // Redefined from GEOMBase_Helper.
1508 //================================================================
1509 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1511 const bool activate,
1513 const double lineWidth,
1514 const int displayMode,
1517 // Set color for preview shape
1518 getDisplayer()->SetColor( Quantity_NOC_RED );
1520 // set width of displayed shape
1521 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1523 // Disable activation of selection
1524 getDisplayer()->SetToActivate( activate );
1526 // Make a reference to GEOM_Object
1527 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1528 getDisplayer()->SetName( objStr.in() );
1530 // Create wire from applayed object
1531 TopoDS_Shape anApplyedWire, aLastSegment;
1532 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1536 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1537 if ( aPrs != 0 && !aPrs->IsNull() )
1538 GEOMBase_Helper::displayPreview( aPrs, append, update );
1540 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1541 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1542 if ( aPrs != 0 && !aPrs->IsNull() )
1543 GEOMBase_Helper::displayPreview( aPrs, append, update );
1545 getDisplayer()->UnsetName();
1547 // Enable activation of displayed objects
1548 getDisplayer()->SetToActivate( true );
1551 //================================================================
1552 // Function : createShapes
1553 // Purpose : Create applyed wire, and last segment from entry object
1554 //================================================================
1555 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1556 TopoDS_Shape& theApplyedWire,
1557 TopoDS_Shape& theLastSegment )
1559 TopoDS_Shape aShape;
1560 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1561 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1564 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1565 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1566 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1567 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1568 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1569 theApplyedWire = aShape;
1573 BRepBuilderAPI_MakeWire aBuilder;
1574 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1576 TopoDS_Shape anEdge = anExp.Current();
1578 if ( anExp.More() ) // i.e. non-last edge
1579 aBuilder.Add( TopoDS::Edge( anEdge ) );
1581 theLastSegment = anEdge;
1586 if ( aBuilder.IsDone() )
1587 theApplyedWire = aBuilder.Shape();
1592 //=================================================================================
1593 // function : keyPressEvent()
1595 //=================================================================================
1596 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1598 QDialog::keyPressEvent( e );
1599 if ( e->isAccepted() )
1602 if ( e->key() == Qt::Key_F1 ) {
1608 //=================================================================================
1609 // function : initSpinBox()
1611 //=================================================================================
1612 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1613 double min, double max,
1614 double step, const char* quantity )
1616 // The same stuff as in GEOMBase_Skeleton::initSpinBox()!
1617 // TODO: Think how to keep the single piece of code...
1619 // Obtain precision from preferences
1620 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1621 int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
1623 spinBox->setPrecision( aPrecision );
1624 spinBox->setDecimals( aPrecision ); // it's necessary to set decimals before the range setting,
1625 // by default Qt rounds boundaries to 2 decimals at setRange
1626 spinBox->setRange( min, max );
1627 spinBox->setSingleStep( step );
1629 // Add a hint for the user saying how to tune precision
1630 QString userPropName = QObject::tr( QString( "PREF_%1" ).arg( quantity ).toLatin1().constData() );
1631 spinBox->setProperty( "validity_tune_hint",
1632 QVariant( QObject::tr( "PRECISION_HINT" ).arg( userPropName ) ) );
1635 //=================================================================================
1636 // function : SetDoubleSpinBoxStep()
1637 // purpose : Double spin box management
1638 //=================================================================================
1639 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1641 Group1Spin->SpinBox_DX->setSingleStep(step);
1642 Group2Spin->SpinBox_DX->setSingleStep(step);
1643 Group2Spin->SpinBox_DY->setSingleStep(step);
1644 Group3Spin->SpinBox_DX->setSingleStep(step);
1645 Group3Spin->SpinBox_DY->setSingleStep(step);
1646 Group3Spin->SpinBox_DZ->setSingleStep(step);
1647 Group4Spin->SpinBox_DZ->setSingleStep(step);
1649 // san: Do NOT override the step when a speicifc step value is used
1650 // in some input fields!
1651 //Group4Spin->SpinBox_DX->setSingleStep(step);
1652 //Group4Spin->SpinBox_DY->setSingleStep(step);
1653 //Group4Spin->SpinBox_DS->setSingleStep(step);
1656 //=================================================================================
1657 // function : FindLocalCS()
1658 // purpose : Find All Coordinates systems in study
1659 //=================================================================================
1660 void EntityGUI_SketcherDlg::FindLocalCS()
1664 SalomeApp_Application* app =
1665 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1669 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1673 _PTR(Study) aStudy = appStudy->studyDS();
1676 ComboBox1->addItem(tr("GEOM_GCS"));
1677 gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
1678 gp_Dir aDirZ = gp_Dir(0, 0, 1);
1679 gp_Dir aDirX = gp_Dir(1, 0, 0);
1680 gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
1681 myLCSList.push_back(globalCS);
1683 // get GEOM component
1684 CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
1685 _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
1688 _PTR(SComponent) fc = obj->GetFatherComponent();
1689 QString geomComp = fc->GetID().c_str();
1690 _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
1694 // browse through all GEOM data tree
1695 _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
1696 for ( it->InitEx( true ); it->More(); it->Next() ) {
1697 _PTR(SObject) child( it->Value() );
1698 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
1699 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
1700 if( CORBA::is_nil( geomObj ) )
1702 if (geomObj->GetType() == GEOM_MARKER) {
1703 ComboBox1->addItem(geomObj->GetName());
1704 TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
1707 aLCS.Transform(aShape.Location().Transformation());
1708 if (aShape.ShapeType() == TopAbs_FACE) {
1709 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
1710 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
1711 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
1712 gp_Pln aPln = aGPlane->Pln();
1713 aLCS = aPln.Position();
1716 myLCSList.push_back(aLCS);
1721 //=================================================================================
1722 // function : GetActiveLocalCS()
1723 // purpose : Find All Coordinates systems in study
1724 //=================================================================================
1725 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
1727 int ind = ComboBox1->currentIndex();
1729 return myGeometryGUI->GetWorkingPlane();
1731 gp_Ax3 aLCS = myLCSList.at(ind);
1733 myGeometryGUI->SetWorkingPlane( aLCS );
1734 myGeometryGUI->ActiveWorkingPlane();