1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
22 // File : EntityGUI_SketcherDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "EntityGUI_SketcherDlg.h"
27 #include "EntityGUI_Widgets.h"
30 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
43 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopoDS_Vertex.hxx>
48 #include <BRepBuilderAPI_Transform.hxx>
49 #include <BRepBuilderAPI_MakeWire.hxx>
50 #include <Sketcher_Profile.hxx>
52 //=================================================================================
53 // class : EntityGUI_SketcherDlg()
54 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
60 bool modal, Qt::WindowFlags fl,
61 const double lineWidth )
62 : QDialog( parent, fl ),
63 myIsAllAdded( false ),
64 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
66 myLineWidth( lineWidth )
69 setAttribute( Qt::WA_DeleteOnClose );
71 myGeometryGUI->SetActiveDialogBox(this);
73 MainWidget = new EntityGUI_Skeleton( this );
74 QVBoxLayout* topLayout = new QVBoxLayout( this );
75 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
76 topLayout->addWidget( MainWidget );
78 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
79 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
80 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
81 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
83 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
84 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
85 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
87 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
89 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
90 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
91 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
92 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
93 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
94 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
95 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
97 /***************************************************************/
98 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
100 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
101 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
102 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
103 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
105 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
107 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
108 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
109 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
110 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
111 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
113 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
115 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
116 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
117 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
118 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
120 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
122 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
123 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
124 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
125 Group1Sel->PushButton1->setIcon( image0 );
126 Group1Sel->buttonUndo->setIcon( image1 );
127 Group1Sel->buttonRedo->setIcon( image2 );
128 Group1Sel->LineEdit1->setReadOnly( true );
130 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
131 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
132 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
133 Group1Spin->buttonUndo->setIcon( image1 );
134 Group1Spin->buttonRedo->setIcon( image2 );
136 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
137 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
138 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
139 Group2Spin->buttonUndo->setIcon( image1 );
140 Group2Spin->buttonRedo->setIcon( image2 );
142 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
143 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
144 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
145 Group3Spin->buttonUndo->setIcon( image1 );
146 Group3Spin->buttonRedo->setIcon( image2 );
148 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
149 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
150 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
151 Group4Spin->buttonUndo->setIcon( image1 );
152 Group4Spin->buttonRedo->setIcon( image2 );
154 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
155 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
156 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
157 DestCntLayout->addWidget( GroupD1, 1, 0 );
158 DestCntLayout->addWidget( GroupD2, 1, 1 );
160 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
161 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
162 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
163 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
164 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
165 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
166 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
167 /***************************************************************/
169 QButtonGroup* ButtonGroup = new QButtonGroup( this );
170 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
171 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
173 /* signals and slots connections */
174 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
175 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
176 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
177 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
179 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
180 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
181 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
182 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
183 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
184 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
185 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
186 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
187 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
188 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
189 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
190 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
191 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
192 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
193 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
195 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
196 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
197 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
198 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
199 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
201 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
202 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
204 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
205 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
206 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
207 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
208 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
209 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
210 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
211 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
212 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
213 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
215 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
217 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
218 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
220 // install event filter on spin-boxes to provide Apply action on Return pressed
221 Group1Spin->SpinBox_DX->installEventFilter(this);
222 Group2Spin->SpinBox_DX->installEventFilter(this);
223 Group2Spin->SpinBox_DY->installEventFilter(this);
224 Group3Spin->SpinBox_DX->installEventFilter(this);
225 Group3Spin->SpinBox_DY->installEventFilter(this);
226 Group3Spin->SpinBox_DZ->installEventFilter(this);
227 Group4Spin->SpinBox_DX->installEventFilter(this);
228 Group4Spin->SpinBox_DY->installEventFilter(this);
229 Group4Spin->SpinBox_DZ->installEventFilter(this);
230 Group4Spin->SpinBox_DS->installEventFilter(this);
236 //=================================================================================
237 // function : ~EntityGUI_SketcherDlg()
238 // purpose : Destroys the object and frees any allocated resources
239 //=================================================================================
240 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
242 myGeometryGUI->SetActiveDialogBox( 0 );
246 //=================================================================================
247 // function : eventFilter()
248 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
249 //=================================================================================
250 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
252 if (event->type() == QEvent::KeyPress) {
253 QKeyEvent* ke = (QKeyEvent*)event;
254 if (ke->key() == Qt::Key_Return) {
255 if (object == Group1Spin->SpinBox_DX) {
256 Group1Spin->buttonApply->animateClick();
258 } else if (object == Group2Spin->SpinBox_DX ||
259 object == Group2Spin->SpinBox_DY) {
260 Group2Spin->buttonApply->animateClick();
262 } else if (object == Group3Spin->SpinBox_DX ||
263 object == Group3Spin->SpinBox_DY ||
264 object == Group3Spin->SpinBox_DZ) {
265 Group3Spin->buttonApply->animateClick();
267 } else if (object == Group4Spin->SpinBox_DX ||
268 object == Group4Spin->SpinBox_DY ||
269 object == Group4Spin->SpinBox_DZ ||
270 object == Group4Spin->SpinBox_DS) {
271 Group4Spin->buttonApply->animateClick();
277 if (event->type() == QEvent::KeyRelease) {
278 // NPAL16010 (Sketcher Apply non available if only one line is modified)
279 // To have Apply active as soon as value text changed
280 QDoubleSpinBox* aDoubleSpinBox = (QDoubleSpinBox*)object;
282 ValueChangedInSpinBox( aDoubleSpinBox->value() );
285 return QDialog::eventFilter(object, event);
289 //=================================================================================
292 //=================================================================================
293 void EntityGUI_SketcherDlg::Init()
296 myEditCurrentArgument = Group1Sel->LineEdit1;
297 myCommand.append( "Sketcher" );
298 myUndoCommand.append( "Sketcher" );
300 mySketchState = FIRST_POINT;
301 globalSelection( GEOM_POINT );
308 myHelpFileName = "create_sketcher_page.html";
310 /* Get setting of step value from file configuration */
311 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
313 /* min, max, step and decimals for spin boxes */
314 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
315 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
316 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
317 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
318 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
319 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
320 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
321 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
322 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
323 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
325 /* displays Dialog */
326 MainWidget->GroupConstructors->setEnabled( false );
327 MainWidget->GroupDest1->setEnabled( false );
328 setEnabledUndo( false );
329 setEnabledRedo( false );
331 MainWidget->RadioButton1->setChecked( true );
336 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
340 //=================================================================================
341 // function : InitClick()
343 //=================================================================================
344 void EntityGUI_SketcherDlg::InitClick()
346 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
358 //=================================================================================
359 // function : TypeClicked()
360 // purpose : Radio button management
361 //=================================================================================
362 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
364 myConstructorId = constructorId;
365 if ( myConstructorId == 0 ) { // SEGMENT
366 GroupD2->setEnabled( true );
367 MainWidget->RB_Dest1->setEnabled( true );
368 MainWidget->RB_Dest1->setChecked( true );
371 else if ( myConstructorId == 1 ) { // ARC
372 GroupD2->setEnabled( false );
373 MainWidget->RB_Dest1->setEnabled( false );
374 MainWidget->RB_Dest2->setChecked( true );
380 //=================================================================================
381 // function : DestClicked()
382 // purpose : Radio button management
383 //=================================================================================
384 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
390 if ( constructorId == 1 ) {
392 GroupPt->RB_Point1->setChecked( true );
394 PointClicked( 1 ); // XY
396 else if ( constructorId == 0 ) {
398 GroupD1->RB_Dir11->setChecked( true );
401 Dir1Clicked( 2 ); // Angle
406 //=================================================================================
407 // function : PointClicked()
408 // purpose : Radio button management
409 //=================================================================================
410 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
414 // Get setting of step value from file configuration
415 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
417 if ( myConstructorId == 0 ) { // SEGMENT
418 if ( constructorId == 1 ) { // XY
419 mySketchType = PT_ABS;
420 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
421 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
422 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
423 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
425 Group2Spin->SpinBox_DX->setValue( myX );
427 Group2Spin->SpinBox_DY->setValue( myY );
429 Group2Spin->buttonApply->setFocus();
431 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
433 else if ( constructorId == 0 ) { // DXDY
434 mySketchType = PT_RELATIVE;
435 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
436 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
437 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
438 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
440 Group2Spin->SpinBox_DX->setValue( myDX );
442 Group2Spin->SpinBox_DY->setValue( myDY );
444 Group2Spin->buttonApply->setFocus();
446 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
448 else if ( constructorId == 2 ) { // Selection
449 mySketchType = PT_SEL;
450 myEditCurrentArgument = Group1Sel->LineEdit1;
451 connect( myGeometryGUI->getApp()->selectionMgr(),
452 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
454 Group1Sel->buttonApply->setFocus();
455 SelectionIntoArgument();
461 //=================================================================================
462 // function : Dir1Clicked()
463 // purpose : Radio button management
464 //=================================================================================
465 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
467 myConstructorDirId = constructorId;
468 GroupD2->RB_Dir21->setChecked( true );
473 //=================================================================================
474 // function : Dir2Clicked()
475 // purpose : Radio button management
476 //=================================================================================
477 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
482 // Get setting of step value from file configuration
483 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
485 if ( myConstructorId == 0 ) { // SEGMENT
489 if ( myConstructorDirId == 2 ) { // Angle
490 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
491 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
492 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
493 Group2Spin->SpinBox_DX->setValue( myAngle );
494 Group2Spin->buttonApply->setFocus();
497 if ( constructorId == 2 ) { // Length
498 mySketchType = DIR_ANGLE_LENGTH;
499 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
500 Group2Spin->SpinBox_DY->setValue( myLength );
502 else if ( constructorId == 0 ) { // X
503 mySketchType = DIR_ANGLE_X;
504 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
505 Group2Spin->SpinBox_DY->setValue( myX );
507 else if ( constructorId == 1 ) { // Y
508 mySketchType = DIR_ANGLE_Y;
509 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
510 Group2Spin->SpinBox_DY->setValue( myY );
513 else if ( myConstructorDirId == 0 ) { // Perpendicular
515 Group1Spin->buttonApply->setFocus();
517 if ( constructorId == 2 ) { // Length
518 mySketchType = DIR_PER_LENGTH;
519 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
520 Group1Spin->SpinBox_DX->setValue( myLength );
522 else if ( constructorId == 0 ) { // X
523 mySketchType = DIR_PER_X;
524 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
525 Group1Spin->SpinBox_DX->setValue( myX );
527 else if ( constructorId == 1 ) { // Y
528 mySketchType = DIR_PER_Y;
529 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
530 Group1Spin->SpinBox_DX->setValue( myY );
533 else if ( myConstructorDirId == 1 ) { // Tangent
535 Group1Spin->buttonApply->setFocus();
537 if ( constructorId == 2 ) { // Length
538 mySketchType = DIR_TAN_LENGTH;
539 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
540 Group1Spin->SpinBox_DX->setValue( myLength );
542 else if ( constructorId == 0 ) { // X
543 mySketchType = DIR_TAN_X;
544 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
545 Group1Spin->SpinBox_DX->setValue( myX );
547 else if ( constructorId == 1 ) { // Y
548 mySketchType = DIR_TAN_Y;
549 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
550 Group1Spin->SpinBox_DX->setValue( myY );
553 else if ( myConstructorDirId == 3 ) { // DXDY
554 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
555 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
556 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
557 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
558 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
560 Group3Spin->SpinBox_DX->setValue( myDX );
562 Group3Spin->SpinBox_DY->setValue( myDY );
564 Group3Spin->buttonApply->setFocus();
566 if ( constructorId == 2 ) { // Length
567 mySketchType = DIR_DXDY_LENGTH;
568 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
569 Group3Spin->SpinBox_DZ->setValue( myLength );
571 else if ( constructorId == 0 ) { // X
572 mySketchType = DIR_DXDY_X;
573 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
574 Group3Spin->SpinBox_DZ->setValue( myX );
576 else if ( constructorId == 1 ) { // Y
577 mySketchType = DIR_DXDY_Y;
578 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
579 Group3Spin->SpinBox_DZ->setValue( myY );
583 else if ( myConstructorId == 1 ) { // ARC
584 if ( myConstructorDirId == 2 ) { // Angle
585 if ( constructorId == 2 ) { // Length
586 mySketchType = DIR_ANGLE_LENGTH;
587 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
588 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
589 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
590 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
591 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
592 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
593 Group3Spin->SpinBox_DX->setValue( myAngle );
595 Group3Spin->SpinBox_DY->setValue( myRadius );
597 Group3Spin->SpinBox_DZ->setValue( myLength );
599 Group3Spin->buttonApply->setFocus();
602 else if ( myConstructorDirId == 0 ) { // Perpendicular
603 if ( constructorId == 2 ) { // Length
604 mySketchType = DIR_PER_LENGTH;
605 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
606 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
607 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
608 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
610 Group2Spin->SpinBox_DX->setValue( myRadius );
612 Group2Spin->SpinBox_DY->setValue( myLength );
614 Group2Spin->buttonApply->setFocus();
617 else if ( myConstructorDirId == 1 ) { // Tangent
618 if ( constructorId == 2 ) { // Length
619 mySketchType = DIR_TAN_LENGTH;
620 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
621 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
622 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
623 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
625 Group2Spin->SpinBox_DX->setValue( myRadius );
627 Group2Spin->SpinBox_DY->setValue( myLength );
629 Group2Spin->buttonApply->setFocus();
632 else if ( myConstructorDirId == 3 ) { // DXDY
633 if ( constructorId == 2 ) { // Length
634 mySketchType = DIR_DXDY_LENGTH;
635 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
636 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
637 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
638 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
640 Group4Spin->SpinBox_DX->setValue( myDX );
642 Group4Spin->SpinBox_DY->setValue( myDY );
644 Group4Spin->SpinBox_DZ->setValue( myRadius );
646 Group4Spin->SpinBox_DS->setValue( myLength );
648 Group4Spin->buttonApply->setFocus();
653 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
657 //=================================================================================
658 // function : ClickOnCancel()
660 //=================================================================================
661 void EntityGUI_SketcherDlg::ClickOnCancel()
667 //=================================================================================
668 // function : ClickOnEnd()
669 // purpose : connected to buttonEnd AND buttonClose
670 //=================================================================================
671 void EntityGUI_SketcherDlg::ClickOnEnd()
673 if ( sender() == MainWidget->buttonClose ) {
674 // Verify validity of commands
675 if ( myCommand.count() <= 2 ) {
676 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
677 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
681 QString Command = myCommand.join( "" ) + GetNewCommand();
682 Sketcher_Profile aProfile( Command.toAscii() );
684 Command = myCommand.join( "" );
685 aProfile = Sketcher_Profile( Command.toAscii() );
686 TopoDS_Shape myShape;
687 if ( aProfile.IsDone() )
688 myShape = aProfile.GetShape();
690 if ( myShape.ShapeType() != TopAbs_VERTEX )
691 myCommand.append( ":WW" );
694 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
695 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
696 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
697 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
698 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
699 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
705 if ( myCommand.size() > 2 )
712 //=================================================================================
713 // function : ClickOnApply()
715 //=================================================================================
716 bool EntityGUI_SketcherDlg::ClickOnApply()
718 if ( sender() && sender()->inherits( "QPushButton" ) )
719 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
721 myCommand.append( GetNewCommand() );
722 mySketchState = NEXT_POINT;
724 myUndoCommand.clear();
725 myUndoCommand.append( "Sketcher" );
727 MainWidget->GroupConstructors->setEnabled( true );
728 MainWidget->GroupDest1->setEnabled( true );
729 setEnabledUndo( true );
730 setEnabledRedo( false );
732 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
734 // Set focus to SpinBox_DX
735 if ( sender() == Group1Spin->buttonApply ) {
736 (Group1Spin->SpinBox_DX)->setFocus();
737 (Group1Spin->SpinBox_DX)->selectAll();
739 else if ( sender() == Group2Spin->buttonApply ) {
740 (Group2Spin->SpinBox_DX)->setFocus();
741 (Group2Spin->SpinBox_DX)->selectAll();
743 else if ( sender() == Group3Spin->buttonApply ) {
744 (Group3Spin->SpinBox_DX)->setFocus();
745 (Group3Spin->SpinBox_DX)->selectAll();
747 else if ( sender() == Group4Spin->buttonApply ) {
748 (Group4Spin->SpinBox_DX)->setFocus();
749 (Group4Spin->SpinBox_DX)->selectAll();
755 //=================================================================================
756 // function : ClickOnHelp()
758 //=================================================================================
759 void EntityGUI_SketcherDlg::ClickOnHelp()
761 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
763 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
767 platform = "winapplication";
769 platform = "application";
772 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
773 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
774 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
775 QObject::tr( "BUT_OK" ) );
779 //=================================================================================
780 // function : ClickOnUndo()
782 //=================================================================================
783 void EntityGUI_SketcherDlg::ClickOnUndo()
785 myUndoCommand.append( myCommand.last() );
786 myCommand.pop_back();
788 if ( myCommand.count() == 1 ) {
789 mySketchState = FIRST_POINT;
791 MainWidget->RadioButton1->setChecked( true );
794 MainWidget->GroupConstructors->setEnabled( false );
795 MainWidget->GroupDest1->setEnabled( false );
796 setEnabledUndo( false );
799 setEnabledRedo( true );
801 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
804 //=================================================================================
805 // function : ClickOnRedo()
807 //=================================================================================
808 void EntityGUI_SketcherDlg::ClickOnRedo()
810 myCommand.append( myUndoCommand.last() );
811 myUndoCommand.pop_back();
813 mySketchState = NEXT_POINT;
815 MainWidget->GroupConstructors->setEnabled( true );
816 MainWidget->GroupDest1->setEnabled( true );
817 setEnabledUndo( true );
819 if ( myUndoCommand.count() == 1 )
820 setEnabledRedo( false );
822 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
825 //=================================================================================
826 // function : setEnabledUndo()
828 //=================================================================================
829 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
831 Group1Sel->buttonUndo->setEnabled( value );
832 Group1Spin->buttonUndo->setEnabled( value );
833 Group2Spin->buttonUndo->setEnabled( value );
834 Group3Spin->buttonUndo->setEnabled( value );
835 Group4Spin->buttonUndo->setEnabled( value );
838 //=================================================================================
839 // function : setEnabledRedo()
841 //=================================================================================
842 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
844 Group1Sel->buttonRedo->setEnabled( value );
845 Group1Spin->buttonRedo->setEnabled( value );
846 Group2Spin->buttonRedo->setEnabled( value );
847 Group3Spin->buttonRedo->setEnabled( value );
848 Group4Spin->buttonRedo->setEnabled( value );
851 //=================================================================================
852 // function : SelectionIntoArgument()
853 // purpose : Called when selection as changed
854 //=================================================================================
855 void EntityGUI_SketcherDlg::SelectionIntoArgument()
857 myEditCurrentArgument->setText( "" );
861 int nbSel = IObjectCount();
862 if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 ) {
863 Standard_Boolean aRes = Standard_False;
864 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
865 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
867 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
869 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
871 aTrans.SetTransformation( aWPlane );
872 BRepBuilderAPI_Transform aTransformation( aShape, aTrans, Standard_False );
873 aShape = aTransformation.Shape();
876 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
879 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
885 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
889 //=================================================================================
890 // function : SetEditCurrentArgument()
892 //=================================================================================
893 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
895 if ( sender() == Group1Sel->PushButton1 ) {
896 myEditCurrentArgument = Group1Sel->LineEdit1;
897 myEditCurrentArgument->setFocus();
899 SelectionIntoArgument();
903 //=================================================================================
904 // function : LineEditReturnPressed()
906 //=================================================================================
907 void EntityGUI_SketcherDlg::LineEditReturnPressed()
909 if ( sender() == Group1Sel->LineEdit1 ) {
910 myEditCurrentArgument = Group1Sel->LineEdit1;
912 /* User name of object input management */
913 /* If successfull the selection is changed and signal emitted... */
914 /* so SelectionIntoArgument() is automatically called. */
915 const QString objectUserName = myEditCurrentArgument->text();
916 QWidget* thisWidget = (QWidget*)this;
917 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
918 myEditCurrentArgument->setText( objectUserName );
923 //=================================================================================
924 // function : DeactivateActiveDialog()
926 //=================================================================================
927 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
929 //myGeometryGUI->SetState( -1 );
933 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
934 myGeometryGUI->SetActiveDialogBox( 0 );
938 //=================================================================================
939 // function : ActivateThisDialog()
941 //=================================================================================
942 void EntityGUI_SketcherDlg::ActivateThisDialog()
944 myGeometryGUI->EmitSignalDeactivateDialog();
946 myGeometryGUI->SetActiveDialogBox( this );
948 connect( myGeometryGUI->getApp()->selectionMgr(),
949 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
951 //myGeometryGUI->SetState( 0 );
952 globalSelection( GEOM_POINT );
954 myEditCurrentArgument = Group1Sel->LineEdit1;
955 myEditCurrentArgument->setFocus();
957 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
961 //=================================================================================
962 // function : enterEvent [REDEFINED]
964 //=================================================================================
965 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
967 if ( !MainWidget->GroupConstructors->isEnabled() )
968 ActivateThisDialog();
972 //=================================================================================
973 // function : closeEvent()
975 //=================================================================================
976 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
978 //myGeometryGUI->SetState( -1 );
979 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
980 QDialog::closeEvent( e );
984 //=================================================================================
985 // function : ValueChangedInSpinBox()
987 //=================================================================================
988 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
990 QObject* send = (QObject*)sender();
991 Standard_Real vx, vy, vz, vs;
992 vx = vy = vz = vs = 0.0;
994 if ( send == Group1Spin->SpinBox_DX ) {
997 else if ( send == Group2Spin->SpinBox_DX ) {
999 vy = Group2Spin->SpinBox_DY->value();
1001 else if ( send == Group2Spin->SpinBox_DY ) {
1002 vx = Group2Spin->SpinBox_DX->value();
1005 else if ( send == Group3Spin->SpinBox_DX ) {
1007 vy = Group3Spin->SpinBox_DY->value();
1008 vz = Group3Spin->SpinBox_DZ->value();
1010 else if ( send == Group3Spin->SpinBox_DY ) {
1011 vx = Group3Spin->SpinBox_DX->value();
1013 vz = Group3Spin->SpinBox_DZ->value();
1015 else if ( send == Group3Spin->SpinBox_DZ ) {
1016 vx = Group3Spin->SpinBox_DX->value();
1017 vy = Group3Spin->SpinBox_DY->value();
1020 else if ( send == Group4Spin->SpinBox_DX ) {
1022 vy = Group4Spin->SpinBox_DY->value();
1023 vz = Group4Spin->SpinBox_DZ->value();
1024 vs = Group4Spin->SpinBox_DS->value();
1026 else if ( send == Group4Spin->SpinBox_DY ) {
1027 vx = Group4Spin->SpinBox_DX->value();
1029 vz = Group4Spin->SpinBox_DZ->value();
1030 vs = Group4Spin->SpinBox_DS->value();
1032 else if ( send == Group4Spin->SpinBox_DZ ) {
1033 vx = Group4Spin->SpinBox_DX->value();
1034 vy = Group4Spin->SpinBox_DY->value();
1036 vs = Group4Spin->SpinBox_DS->value();
1038 else if ( send == Group4Spin->SpinBox_DS ) {
1039 vx = Group4Spin->SpinBox_DX->value();
1040 vy = Group4Spin->SpinBox_DY->value();
1041 vz = Group4Spin->SpinBox_DZ->value();
1044 // NPAL16010 (Sketcher Apply non available if only one line is modified)
1045 // if ValueChangedInSpinBox() called from eventFilter()
1046 else if ( Group1Spin->SpinBox_DX->hasFocus() ) {
1049 else if ( Group2Spin->SpinBox_DX ->hasFocus() ) {
1051 vy = Group2Spin->SpinBox_DY->value();
1053 else if ( Group2Spin->SpinBox_DY->hasFocus() ) {
1054 vx = Group2Spin->SpinBox_DX->value();
1057 else if ( Group3Spin->SpinBox_DX->hasFocus() ) {
1059 vy = Group3Spin->SpinBox_DY->value();
1060 vz = Group3Spin->SpinBox_DZ->value();
1062 else if ( Group3Spin->SpinBox_DY->hasFocus() ) {
1063 vx = Group3Spin->SpinBox_DX->value();
1065 vz = Group3Spin->SpinBox_DZ->value();
1067 else if ( Group3Spin->SpinBox_DZ->hasFocus() ) {
1068 vx = Group3Spin->SpinBox_DX->value();
1069 vy = Group3Spin->SpinBox_DY->value();
1072 else if ( Group4Spin->SpinBox_DX->hasFocus() ) {
1074 vy = Group4Spin->SpinBox_DY->value();
1075 vz = Group4Spin->SpinBox_DZ->value();
1076 vs = Group4Spin->SpinBox_DS->value();
1078 else if ( Group4Spin->SpinBox_DY->hasFocus() ) {
1079 vx = Group4Spin->SpinBox_DX->value();
1081 vz = Group4Spin->SpinBox_DZ->value();
1082 vs = Group4Spin->SpinBox_DS->value();
1084 else if ( Group4Spin->SpinBox_DZ->hasFocus() ) {
1085 vx = Group4Spin->SpinBox_DX->value();
1086 vy = Group4Spin->SpinBox_DY->value();
1088 vs = Group4Spin->SpinBox_DS->value();
1090 else if ( Group4Spin->SpinBox_DS->hasFocus() ) {
1091 vx = Group4Spin->SpinBox_DX->value();
1092 vy = Group4Spin->SpinBox_DY->value();
1093 vz = Group4Spin->SpinBox_DZ->value();
1097 if ( myConstructorId == 0 ) { // SEGMENT
1098 if ( mySketchType == PT_ABS ) {
1102 else if ( mySketchType == PT_RELATIVE ) {
1106 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1110 else if ( mySketchType == DIR_ANGLE_X ) {
1114 else if ( mySketchType == DIR_ANGLE_Y ) {
1118 else if ( mySketchType == DIR_PER_LENGTH ) {
1121 else if ( mySketchType == DIR_PER_X ) {
1124 else if ( mySketchType == DIR_PER_Y ) {
1127 else if ( mySketchType == DIR_TAN_LENGTH ) {
1130 else if ( mySketchType == DIR_TAN_X ) {
1133 else if ( mySketchType == DIR_TAN_Y ) {
1136 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1141 else if ( mySketchType == DIR_DXDY_X ) {
1146 else if ( mySketchType == DIR_DXDY_Y ) {
1152 else if ( myConstructorId == 1 ) { // ARC
1153 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1158 else if ( mySketchType == DIR_PER_LENGTH ) {
1162 else if ( mySketchType == DIR_TAN_LENGTH ) {
1166 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1174 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1178 //=================================================================================
1179 // function : GetNewCommand()
1180 // purpose : Build the new command with context
1181 //=================================================================================
1182 QString EntityGUI_SketcherDlg::GetNewCommand()
1184 QString myNewCommand = ":";
1185 if ( mySketchState == FIRST_POINT ) {
1186 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1187 myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1188 if ( mySketchType == PT_RELATIVE)
1189 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1190 return myNewCommand;
1193 if ( myConstructorId == 0 ) { // SEGMENT
1194 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1195 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1196 if ( mySketchType == PT_RELATIVE)
1197 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1198 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1199 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1200 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1202 if ( mySketchType == DIR_ANGLE_X ) {
1203 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1204 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1206 if ( mySketchType == DIR_ANGLE_Y ) {
1207 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1208 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1210 if ( mySketchType == DIR_PER_LENGTH ) {
1211 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1212 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1214 if ( mySketchType == DIR_PER_X ) {
1215 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1216 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1218 if ( mySketchType == DIR_PER_Y ) {
1219 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1220 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1222 if ( mySketchType == DIR_TAN_LENGTH )
1223 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1224 if ( mySketchType == DIR_TAN_X )
1225 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1226 if ( mySketchType == DIR_TAN_Y)
1227 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1228 if ( mySketchType == DIR_DXDY_LENGTH ) {
1229 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1230 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1232 if ( mySketchType == DIR_DXDY_X ) {
1233 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1234 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1236 if ( mySketchType == DIR_DXDY_Y ) {
1237 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1238 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1241 else if ( myConstructorId == 1 ) { // ARC
1242 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1243 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1244 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1246 if ( mySketchType == DIR_PER_LENGTH ) {
1247 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1248 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1250 if ( mySketchType == DIR_TAN_LENGTH ) {
1251 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1253 if ( mySketchType == DIR_DXDY_LENGTH ) {
1254 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1255 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1258 return myNewCommand;
1261 //=================================================================================
1262 // function : createOperation
1264 //=================================================================================
1265 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1267 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1270 //=================================================================================
1271 // function : isValid
1273 //=================================================================================
1274 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1279 //=================================================================================
1280 // function : execute
1282 //=================================================================================
1283 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1285 if ( mySketchState == FIRST_POINT ) {
1290 //Test if the current point is the same as the last one
1291 TopoDS_Shape myShape1, myShape2;
1294 QString Command1 = myCommand.join( "" );
1295 Sketcher_Profile aProfile1( Command1.toAscii() );
1296 if ( aProfile1.IsDone() )
1297 myShape1 = aProfile1.GetShape();
1300 QString Command2 = Command1 + GetNewCommand();
1301 Sketcher_Profile aProfile2( Command2.toAscii() );
1302 if ( aProfile2.IsDone() )
1303 myShape2 = aProfile2.GetShape();
1305 if ( myShape2.IsNull() ) {
1306 //the current point is the same as the last one
1307 myLastX2 = myLastX1;
1308 myLastY2 = myLastY1;
1311 TopoDS_Vertex V1, V2;
1313 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1314 //the last shape is the first point
1315 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1320 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1321 pt = BRep_Tool::Pnt( V2 );
1325 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1326 pt = BRep_Tool::Pnt( V2 );
1333 if ( ( mySketchState != FIRST_POINT &&
1334 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1335 cmd = myCommand.join( "" );
1337 if ( Group1Sel->isVisible() ) {
1338 Group1Sel->buttonApply->setEnabled( false );
1339 //Group1Sel->buttonApply->setFocus();
1341 if ( Group1Spin->isVisible() ) {
1342 Group1Spin->buttonApply->setEnabled( false );
1343 //Group1Spin->buttonApply->setFocus();
1345 if ( Group2Spin->isVisible() ) {
1346 Group2Spin->buttonApply->setEnabled( false );
1347 //Group2Spin->buttonApply->setFocus();
1349 if ( Group3Spin->isVisible() ) {
1350 Group3Spin->buttonApply->setEnabled( false );
1351 //Group3Spin->buttonApply->setFocus();
1353 if ( Group4Spin->isVisible() ) {
1354 Group4Spin->buttonApply->setEnabled( false );
1355 //Group4Spin->buttonApply->setFocus();
1359 cmd = myCommand.join( "" ) + GetNewCommand();
1361 if ( Group1Sel->isVisible() ) {
1362 Group1Sel->buttonApply->setEnabled( true );
1363 //Group1Sel->buttonApply->setFocus();
1365 if ( Group1Spin->isVisible() ) {
1366 Group1Spin->buttonApply->setEnabled( true );
1367 //Group1Spin->buttonApply->setFocus();
1369 if ( Group2Spin->isVisible() ) {
1370 Group2Spin->buttonApply->setEnabled( true );
1371 //Group2Spin->buttonApply->setFocus();
1373 if ( Group3Spin->isVisible() ) {
1374 Group3Spin->buttonApply->setEnabled( true );
1375 //Group3Spin->buttonApply->setFocus();
1377 if ( Group4Spin->isVisible() ) {
1378 Group4Spin->buttonApply->setEnabled( true );
1379 //Group4Spin->buttonApply->setFocus();
1383 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1384 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1385 WPlane->length( 9 );
1386 WPlane[0] = myWPlane.Location().X();
1387 WPlane[1] = myWPlane.Location().Y();
1388 WPlane[2] = myWPlane.Location().Z();
1390 WPlane[3] = myWPlane.Direction().X();
1391 WPlane[4] = myWPlane.Direction().Y();
1392 WPlane[5] = myWPlane.Direction().Z();
1394 WPlane[6] = myWPlane.XDirection().X();
1395 WPlane[7] = myWPlane.XDirection().Y();
1396 WPlane[8] = myWPlane.XDirection().Z();
1398 GEOM::GEOM_Object_var anObj =
1399 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.toLatin1(), WPlane );
1401 if ( !anObj->_is_nil() )
1402 objects.push_back( anObj._retn() );
1407 //================================================================
1408 // Function : displayPreview
1409 // Purpose : Method for displaying preview of resulting shape
1410 // Redefined from GEOMBase_Helper.
1411 //================================================================
1412 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1414 const bool activate,
1416 const double lineWidth,
1417 const int displayMode,
1420 // Set color for preview shape
1421 getDisplayer()->SetColor( Quantity_NOC_RED );
1423 // set width of displayed shape
1424 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1426 // Disable activation of selection
1427 getDisplayer()->SetToActivate( activate );
1429 // Make a reference to GEOM_Object
1430 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1431 getDisplayer()->SetName( objStr.in() );
1433 // Create wire from applayed object
1434 TopoDS_Shape anApplyedWire, aLastSegment;
1435 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1439 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1440 if ( aPrs != 0 && !aPrs->IsNull() )
1441 GEOMBase_Helper::displayPreview( aPrs, append, update );
1443 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1444 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1445 if ( aPrs != 0 && !aPrs->IsNull() )
1446 GEOMBase_Helper::displayPreview( aPrs, append, update );
1448 getDisplayer()->UnsetName();
1450 // Enable activation of displayed objects
1451 getDisplayer()->SetToActivate( true );
1454 //================================================================
1455 // Function : createShapes
1456 // Purpose : Create applyed wire, and last segment from entry object
1457 //================================================================
1458 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1459 TopoDS_Shape& theApplyedWire,
1460 TopoDS_Shape& theLastSegment )
1462 TopoDS_Shape aShape;
1463 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1464 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1467 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1468 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1469 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1470 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1471 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1472 theApplyedWire = aShape;
1476 BRepBuilderAPI_MakeWire aBuilder;
1477 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1479 TopoDS_Shape anEdge = anExp.Current();
1481 if ( anExp.More() ) // i.e. non-last edge
1482 aBuilder.Add( TopoDS::Edge( anEdge ) );
1484 theLastSegment = anEdge;
1489 if ( aBuilder.IsDone() )
1490 theApplyedWire = aBuilder.Shape();
1495 //=================================================================================
1496 // function : keyPressEvent()
1498 //=================================================================================
1499 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1501 QDialog::keyPressEvent( e );
1502 if ( e->isAccepted() )
1505 if ( e->key() == Qt::Key_F1 ) {
1511 void EntityGUI_SketcherDlg::initSpinBox( QDoubleSpinBox* spinBox,
1512 double min, double max,
1513 double step, int decimals )
1515 spinBox->setDecimals( decimals );
1516 spinBox->setRange( min, max );
1517 spinBox->setSingleStep( step );
1520 //=================================================================================
1521 // function : SetDoubleSpinBoxStep()
1522 // purpose : Double spin box management
1523 //=================================================================================
1524 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1526 Group1Spin->SpinBox_DX->setSingleStep(step);
1527 Group2Spin->SpinBox_DX->setSingleStep(step);
1528 Group2Spin->SpinBox_DY->setSingleStep(step);
1529 Group3Spin->SpinBox_DX->setSingleStep(step);
1530 Group3Spin->SpinBox_DY->setSingleStep(step);
1531 Group3Spin->SpinBox_DZ->setSingleStep(step);
1532 Group4Spin->SpinBox_DX->setSingleStep(step);
1533 Group4Spin->SpinBox_DY->setSingleStep(step);
1534 Group4Spin->SpinBox_DZ->setSingleStep(step);
1535 Group4Spin->SpinBox_DS->setSingleStep(step);