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"
28 #include <QtxDoubleSpinBox.h>
31 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_SelectionMgr.h>
44 #include <BRep_Tool.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Vertex.hxx>
49 #include <BRepBuilderAPI_Transform.hxx>
50 #include <BRepBuilderAPI_MakeWire.hxx>
51 #include <Sketcher_Profile.hxx>
53 //=================================================================================
54 // class : EntityGUI_SketcherDlg()
55 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
61 bool modal, Qt::WindowFlags fl,
62 const double lineWidth )
63 : QDialog( parent, fl ),
64 myIsAllAdded( false ),
65 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
67 myLineWidth( lineWidth )
70 setAttribute( Qt::WA_DeleteOnClose );
72 myGeometryGUI->SetActiveDialogBox(this);
74 MainWidget = new EntityGUI_Skeleton( this );
75 QVBoxLayout* topLayout = new QVBoxLayout( this );
76 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
77 topLayout->addWidget( MainWidget );
79 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
80 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
81 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
82 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
84 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
85 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
86 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
88 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
90 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
91 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
92 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
93 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
94 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
95 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
96 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
98 /***************************************************************/
99 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
101 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
102 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
103 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
104 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
106 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
108 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
109 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
110 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
111 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
112 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
114 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
116 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
117 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
118 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
119 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
121 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
123 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
124 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
125 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
126 Group1Sel->PushButton1->setIcon( image0 );
127 Group1Sel->buttonUndo->setIcon( image1 );
128 Group1Sel->buttonRedo->setIcon( image2 );
129 Group1Sel->LineEdit1->setReadOnly( true );
131 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
132 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
133 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
134 Group1Spin->buttonUndo->setIcon( image1 );
135 Group1Spin->buttonRedo->setIcon( image2 );
137 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
138 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
139 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
140 Group2Spin->buttonUndo->setIcon( image1 );
141 Group2Spin->buttonRedo->setIcon( image2 );
143 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
144 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
145 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
146 Group3Spin->buttonUndo->setIcon( image1 );
147 Group3Spin->buttonRedo->setIcon( image2 );
149 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
150 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
151 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
152 Group4Spin->buttonUndo->setIcon( image1 );
153 Group4Spin->buttonRedo->setIcon( image2 );
155 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
156 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
157 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
158 DestCntLayout->addWidget( GroupD1, 1, 0 );
159 DestCntLayout->addWidget( GroupD2, 1, 1 );
161 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
162 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
163 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
164 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
165 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
166 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
167 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
168 /***************************************************************/
170 QButtonGroup* ButtonGroup = new QButtonGroup( this );
171 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
172 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
174 /* signals and slots connections */
175 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
176 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
177 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
178 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
180 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
181 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
182 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
183 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
184 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
185 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
186 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
187 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
188 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
189 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
190 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
191 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
192 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
193 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
194 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
196 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
197 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
198 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
199 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
200 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
202 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
203 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
205 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
206 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
207 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
208 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
209 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
210 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
211 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
212 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
213 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
214 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
216 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
218 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
219 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
221 // install event filter on spin-boxes to provide Apply action on Return pressed
222 Group1Spin->SpinBox_DX->installEventFilter(this);
223 Group2Spin->SpinBox_DX->installEventFilter(this);
224 Group2Spin->SpinBox_DY->installEventFilter(this);
225 Group3Spin->SpinBox_DX->installEventFilter(this);
226 Group3Spin->SpinBox_DY->installEventFilter(this);
227 Group3Spin->SpinBox_DZ->installEventFilter(this);
228 Group4Spin->SpinBox_DX->installEventFilter(this);
229 Group4Spin->SpinBox_DY->installEventFilter(this);
230 Group4Spin->SpinBox_DZ->installEventFilter(this);
231 Group4Spin->SpinBox_DS->installEventFilter(this);
237 //=================================================================================
238 // function : ~EntityGUI_SketcherDlg()
239 // purpose : Destroys the object and frees any allocated resources
240 //=================================================================================
241 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
243 myGeometryGUI->SetActiveDialogBox( 0 );
247 //=================================================================================
248 // function : eventFilter()
249 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
250 //=================================================================================
251 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
253 if (event->type() == QEvent::KeyPress) {
254 QKeyEvent* ke = (QKeyEvent*)event;
255 if (ke->key() == Qt::Key_Return) {
256 if (object == Group1Spin->SpinBox_DX) {
257 Group1Spin->buttonApply->animateClick();
259 } else if (object == Group2Spin->SpinBox_DX ||
260 object == Group2Spin->SpinBox_DY) {
261 Group2Spin->buttonApply->animateClick();
263 } else if (object == Group3Spin->SpinBox_DX ||
264 object == Group3Spin->SpinBox_DY ||
265 object == Group3Spin->SpinBox_DZ) {
266 Group3Spin->buttonApply->animateClick();
268 } else if (object == Group4Spin->SpinBox_DX ||
269 object == Group4Spin->SpinBox_DY ||
270 object == Group4Spin->SpinBox_DZ ||
271 object == Group4Spin->SpinBox_DS) {
272 Group4Spin->buttonApply->animateClick();
278 if (event->type() == QEvent::KeyRelease) {
279 // NPAL16010 (Sketcher Apply non available if only one line is modified)
280 // To have Apply active as soon as value text changed
281 QtxDoubleSpinBox* aDoubleSpinBox = (QtxDoubleSpinBox*)object;
283 ValueChangedInSpinBox( aDoubleSpinBox->value() );
286 return QDialog::eventFilter(object, event);
290 //=================================================================================
293 //=================================================================================
294 void EntityGUI_SketcherDlg::Init()
297 myEditCurrentArgument = Group1Sel->LineEdit1;
298 myCommand.append( "Sketcher" );
299 myUndoCommand.append( "Sketcher" );
301 mySketchState = FIRST_POINT;
302 globalSelection( GEOM_POINT );
309 myHelpFileName = "create_sketcher_page.html";
311 /* Get setting of step value from file configuration */
312 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
314 /* min, max, step and decimals for spin boxes */
315 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
316 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
317 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
318 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
319 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
320 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
321 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
322 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
323 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
324 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
326 /* displays Dialog */
327 MainWidget->GroupConstructors->setEnabled( false );
328 MainWidget->GroupDest1->setEnabled( false );
329 setEnabledUndo( false );
330 setEnabledRedo( false );
332 MainWidget->RadioButton1->setChecked( true );
337 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
341 //=================================================================================
342 // function : InitClick()
344 //=================================================================================
345 void EntityGUI_SketcherDlg::InitClick()
347 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
359 //=================================================================================
360 // function : TypeClicked()
361 // purpose : Radio button management
362 //=================================================================================
363 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
365 myConstructorId = constructorId;
366 if ( myConstructorId == 0 ) { // SEGMENT
367 GroupD2->setEnabled( true );
368 MainWidget->RB_Dest1->setEnabled( true );
369 MainWidget->RB_Dest1->setChecked( true );
372 else if ( myConstructorId == 1 ) { // ARC
373 GroupD2->setEnabled( false );
374 MainWidget->RB_Dest1->setEnabled( false );
375 MainWidget->RB_Dest2->setChecked( true );
381 //=================================================================================
382 // function : DestClicked()
383 // purpose : Radio button management
384 //=================================================================================
385 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
391 if ( constructorId == 1 ) {
393 GroupPt->RB_Point1->setChecked( true );
395 PointClicked( 1 ); // XY
397 else if ( constructorId == 0 ) {
399 GroupD1->RB_Dir11->setChecked( true );
402 Dir1Clicked( 2 ); // Angle
407 //=================================================================================
408 // function : PointClicked()
409 // purpose : Radio button management
410 //=================================================================================
411 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
415 // Get setting of step value from file configuration
416 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
418 if ( myConstructorId == 0 ) { // SEGMENT
419 if ( constructorId == 1 ) { // XY
420 mySketchType = PT_ABS;
421 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
422 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
423 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
424 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
426 Group2Spin->SpinBox_DX->setValue( myX );
428 Group2Spin->SpinBox_DY->setValue( myY );
430 Group2Spin->buttonApply->setFocus();
432 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
434 else if ( constructorId == 0 ) { // DXDY
435 mySketchType = PT_RELATIVE;
436 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
437 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
438 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
439 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
441 Group2Spin->SpinBox_DX->setValue( myDX );
443 Group2Spin->SpinBox_DY->setValue( myDY );
445 Group2Spin->buttonApply->setFocus();
447 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
449 else if ( constructorId == 2 ) { // Selection
450 mySketchType = PT_SEL;
451 myEditCurrentArgument = Group1Sel->LineEdit1;
452 connect( myGeometryGUI->getApp()->selectionMgr(),
453 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
455 Group1Sel->buttonApply->setFocus();
456 SelectionIntoArgument();
462 //=================================================================================
463 // function : Dir1Clicked()
464 // purpose : Radio button management
465 //=================================================================================
466 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
468 myConstructorDirId = constructorId;
469 GroupD2->RB_Dir21->setChecked( true );
474 //=================================================================================
475 // function : Dir2Clicked()
476 // purpose : Radio button management
477 //=================================================================================
478 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
483 // Get setting of step value from file configuration
484 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
486 if ( myConstructorId == 0 ) { // SEGMENT
490 if ( myConstructorDirId == 2 ) { // Angle
491 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
492 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
493 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
494 Group2Spin->SpinBox_DX->setValue( myAngle );
495 Group2Spin->buttonApply->setFocus();
498 if ( constructorId == 2 ) { // Length
499 mySketchType = DIR_ANGLE_LENGTH;
500 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
501 Group2Spin->SpinBox_DY->setValue( myLength );
503 else if ( constructorId == 0 ) { // X
504 mySketchType = DIR_ANGLE_X;
505 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
506 Group2Spin->SpinBox_DY->setValue( myX );
508 else if ( constructorId == 1 ) { // Y
509 mySketchType = DIR_ANGLE_Y;
510 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
511 Group2Spin->SpinBox_DY->setValue( myY );
514 else if ( myConstructorDirId == 0 ) { // Perpendicular
516 Group1Spin->buttonApply->setFocus();
518 if ( constructorId == 2 ) { // Length
519 mySketchType = DIR_PER_LENGTH;
520 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
521 Group1Spin->SpinBox_DX->setValue( myLength );
523 else if ( constructorId == 0 ) { // X
524 mySketchType = DIR_PER_X;
525 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
526 Group1Spin->SpinBox_DX->setValue( myX );
528 else if ( constructorId == 1 ) { // Y
529 mySketchType = DIR_PER_Y;
530 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
531 Group1Spin->SpinBox_DX->setValue( myY );
534 else if ( myConstructorDirId == 1 ) { // Tangent
536 Group1Spin->buttonApply->setFocus();
538 if ( constructorId == 2 ) { // Length
539 mySketchType = DIR_TAN_LENGTH;
540 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
541 Group1Spin->SpinBox_DX->setValue( myLength );
543 else if ( constructorId == 0 ) { // X
544 mySketchType = DIR_TAN_X;
545 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
546 Group1Spin->SpinBox_DX->setValue( myX );
548 else if ( constructorId == 1 ) { // Y
549 mySketchType = DIR_TAN_Y;
550 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
551 Group1Spin->SpinBox_DX->setValue( myY );
554 else if ( myConstructorDirId == 3 ) { // DXDY
555 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
556 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
557 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
558 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
559 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
561 Group3Spin->SpinBox_DX->setValue( myDX );
563 Group3Spin->SpinBox_DY->setValue( myDY );
565 Group3Spin->buttonApply->setFocus();
567 if ( constructorId == 2 ) { // Length
568 mySketchType = DIR_DXDY_LENGTH;
569 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
570 Group3Spin->SpinBox_DZ->setValue( myLength );
572 else if ( constructorId == 0 ) { // X
573 mySketchType = DIR_DXDY_X;
574 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
575 Group3Spin->SpinBox_DZ->setValue( myX );
577 else if ( constructorId == 1 ) { // Y
578 mySketchType = DIR_DXDY_Y;
579 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
580 Group3Spin->SpinBox_DZ->setValue( myY );
584 else if ( myConstructorId == 1 ) { // ARC
585 if ( myConstructorDirId == 2 ) { // Angle
586 if ( constructorId == 2 ) { // Length
587 mySketchType = DIR_ANGLE_LENGTH;
588 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
589 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
590 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
591 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
592 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
593 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
594 Group3Spin->SpinBox_DX->setValue( myAngle );
596 Group3Spin->SpinBox_DY->setValue( myRadius );
598 Group3Spin->SpinBox_DZ->setValue( myLength );
600 Group3Spin->buttonApply->setFocus();
603 else if ( myConstructorDirId == 0 ) { // Perpendicular
604 if ( constructorId == 2 ) { // Length
605 mySketchType = DIR_PER_LENGTH;
606 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
607 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
608 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
609 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
611 Group2Spin->SpinBox_DX->setValue( myRadius );
613 Group2Spin->SpinBox_DY->setValue( myLength );
615 Group2Spin->buttonApply->setFocus();
618 else if ( myConstructorDirId == 1 ) { // Tangent
619 if ( constructorId == 2 ) { // Length
620 mySketchType = DIR_TAN_LENGTH;
621 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
622 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
623 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
624 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
626 Group2Spin->SpinBox_DX->setValue( myRadius );
628 Group2Spin->SpinBox_DY->setValue( myLength );
630 Group2Spin->buttonApply->setFocus();
633 else if ( myConstructorDirId == 3 ) { // DXDY
634 if ( constructorId == 2 ) { // Length
635 mySketchType = DIR_DXDY_LENGTH;
636 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
637 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
638 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
639 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
641 Group4Spin->SpinBox_DX->setValue( myDX );
643 Group4Spin->SpinBox_DY->setValue( myDY );
645 Group4Spin->SpinBox_DZ->setValue( myRadius );
647 Group4Spin->SpinBox_DS->setValue( myLength );
649 Group4Spin->buttonApply->setFocus();
654 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
658 //=================================================================================
659 // function : ClickOnCancel()
661 //=================================================================================
662 void EntityGUI_SketcherDlg::ClickOnCancel()
668 //=================================================================================
669 // function : ClickOnEnd()
670 // purpose : connected to buttonEnd AND buttonClose
671 //=================================================================================
672 void EntityGUI_SketcherDlg::ClickOnEnd()
674 if ( sender() == MainWidget->buttonClose ) {
675 // Verify validity of commands
676 if ( myCommand.count() <= 2 ) {
677 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
678 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
682 QString Command = myCommand.join( "" ) + GetNewCommand();
683 Sketcher_Profile aProfile( Command.toAscii() );
685 Command = myCommand.join( "" );
686 aProfile = Sketcher_Profile( Command.toAscii() );
687 TopoDS_Shape myShape;
688 if ( aProfile.IsDone() )
689 myShape = aProfile.GetShape();
691 if ( myShape.ShapeType() != TopAbs_VERTEX )
692 myCommand.append( ":WW" );
695 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
696 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
697 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
698 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
699 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
700 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
706 if ( myCommand.size() > 2 )
713 //=================================================================================
714 // function : ClickOnApply()
716 //=================================================================================
717 bool EntityGUI_SketcherDlg::ClickOnApply()
719 if ( sender() && sender()->inherits( "QPushButton" ) )
720 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
722 myCommand.append( GetNewCommand() );
723 mySketchState = NEXT_POINT;
725 myUndoCommand.clear();
726 myUndoCommand.append( "Sketcher" );
728 MainWidget->GroupConstructors->setEnabled( true );
729 MainWidget->GroupDest1->setEnabled( true );
730 setEnabledUndo( true );
731 setEnabledRedo( false );
733 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
735 // Set focus to SpinBox_DX
736 if ( sender() == Group1Spin->buttonApply ) {
737 (Group1Spin->SpinBox_DX)->setFocus();
738 (Group1Spin->SpinBox_DX)->selectAll();
740 else if ( sender() == Group2Spin->buttonApply ) {
741 (Group2Spin->SpinBox_DX)->setFocus();
742 (Group2Spin->SpinBox_DX)->selectAll();
744 else if ( sender() == Group3Spin->buttonApply ) {
745 (Group3Spin->SpinBox_DX)->setFocus();
746 (Group3Spin->SpinBox_DX)->selectAll();
748 else if ( sender() == Group4Spin->buttonApply ) {
749 (Group4Spin->SpinBox_DX)->setFocus();
750 (Group4Spin->SpinBox_DX)->selectAll();
756 //=================================================================================
757 // function : ClickOnHelp()
759 //=================================================================================
760 void EntityGUI_SketcherDlg::ClickOnHelp()
762 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
764 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
768 platform = "winapplication";
770 platform = "application";
773 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
774 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
775 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
776 QObject::tr( "BUT_OK" ) );
780 //=================================================================================
781 // function : ClickOnUndo()
783 //=================================================================================
784 void EntityGUI_SketcherDlg::ClickOnUndo()
786 myUndoCommand.append( myCommand.last() );
787 myCommand.pop_back();
789 if ( myCommand.count() == 1 ) {
790 mySketchState = FIRST_POINT;
792 MainWidget->RadioButton1->setChecked( true );
795 MainWidget->GroupConstructors->setEnabled( false );
796 MainWidget->GroupDest1->setEnabled( false );
797 setEnabledUndo( false );
800 setEnabledRedo( true );
802 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
805 //=================================================================================
806 // function : ClickOnRedo()
808 //=================================================================================
809 void EntityGUI_SketcherDlg::ClickOnRedo()
811 myCommand.append( myUndoCommand.last() );
812 myUndoCommand.pop_back();
814 mySketchState = NEXT_POINT;
816 MainWidget->GroupConstructors->setEnabled( true );
817 MainWidget->GroupDest1->setEnabled( true );
818 setEnabledUndo( true );
820 if ( myUndoCommand.count() == 1 )
821 setEnabledRedo( false );
823 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
826 //=================================================================================
827 // function : setEnabledUndo()
829 //=================================================================================
830 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
832 Group1Sel->buttonUndo->setEnabled( value );
833 Group1Spin->buttonUndo->setEnabled( value );
834 Group2Spin->buttonUndo->setEnabled( value );
835 Group3Spin->buttonUndo->setEnabled( value );
836 Group4Spin->buttonUndo->setEnabled( value );
839 //=================================================================================
840 // function : setEnabledRedo()
842 //=================================================================================
843 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
845 Group1Sel->buttonRedo->setEnabled( value );
846 Group1Spin->buttonRedo->setEnabled( value );
847 Group2Spin->buttonRedo->setEnabled( value );
848 Group3Spin->buttonRedo->setEnabled( value );
849 Group4Spin->buttonRedo->setEnabled( value );
852 //=================================================================================
853 // function : SelectionIntoArgument()
854 // purpose : Called when selection as changed
855 //=================================================================================
856 void EntityGUI_SketcherDlg::SelectionIntoArgument()
858 myEditCurrentArgument->setText( "" );
862 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
863 SALOME_ListIO aSelList;
864 aSelMgr->selectedObjects(aSelList);
866 int nbSel = aSelList.Extent();
867 if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
868 Standard_Boolean aRes = Standard_False;
869 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
870 if (!CORBA::is_nil(aSelectedObject) && aRes) {
872 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
874 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
876 aTrans.SetTransformation(aWPlane);
877 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
878 aShape = aTransformation.Shape();
881 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
884 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
890 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
894 //=================================================================================
895 // function : SetEditCurrentArgument()
897 //=================================================================================
898 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
900 if ( sender() == Group1Sel->PushButton1 ) {
901 myEditCurrentArgument = Group1Sel->LineEdit1;
902 myEditCurrentArgument->setFocus();
904 SelectionIntoArgument();
908 //=================================================================================
909 // function : LineEditReturnPressed()
911 //=================================================================================
912 void EntityGUI_SketcherDlg::LineEditReturnPressed()
914 if ( sender() == Group1Sel->LineEdit1 ) {
915 myEditCurrentArgument = Group1Sel->LineEdit1;
917 /* User name of object input management */
918 /* If successfull the selection is changed and signal emitted... */
919 /* so SelectionIntoArgument() is automatically called. */
920 const QString objectUserName = myEditCurrentArgument->text();
921 QWidget* thisWidget = (QWidget*)this;
923 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
924 SALOME_ListIO aSelList;
925 aSelMgr->selectedObjects(aSelList);
927 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
928 myEditCurrentArgument->setText( objectUserName );
933 //=================================================================================
934 // function : DeactivateActiveDialog()
936 //=================================================================================
937 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
939 //myGeometryGUI->SetState( -1 );
943 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
944 myGeometryGUI->SetActiveDialogBox( 0 );
948 //=================================================================================
949 // function : ActivateThisDialog()
951 //=================================================================================
952 void EntityGUI_SketcherDlg::ActivateThisDialog()
954 myGeometryGUI->EmitSignalDeactivateDialog();
956 myGeometryGUI->SetActiveDialogBox( this );
958 connect( myGeometryGUI->getApp()->selectionMgr(),
959 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
961 //myGeometryGUI->SetState( 0 );
962 globalSelection( GEOM_POINT );
964 myEditCurrentArgument = Group1Sel->LineEdit1;
965 myEditCurrentArgument->setFocus();
967 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
971 //=================================================================================
972 // function : enterEvent [REDEFINED]
974 //=================================================================================
975 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
977 if ( !MainWidget->GroupConstructors->isEnabled() )
978 ActivateThisDialog();
982 //=================================================================================
983 // function : closeEvent()
985 //=================================================================================
986 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
988 //myGeometryGUI->SetState( -1 );
989 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
990 myGeometryGUI->getApp()->updateActions();
991 QDialog::closeEvent( e );
995 //=================================================================================
996 // function : ValueChangedInSpinBox()
998 //=================================================================================
999 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1001 QObject* send = (QObject*)sender();
1002 Standard_Real vx, vy, vz, vs;
1003 vx = vy = vz = vs = 0.0;
1005 if ( send == Group1Spin->SpinBox_DX ) {
1008 else if ( send == Group2Spin->SpinBox_DX ) {
1010 vy = Group2Spin->SpinBox_DY->value();
1012 else if ( send == Group2Spin->SpinBox_DY ) {
1013 vx = Group2Spin->SpinBox_DX->value();
1016 else if ( send == Group3Spin->SpinBox_DX ) {
1018 vy = Group3Spin->SpinBox_DY->value();
1019 vz = Group3Spin->SpinBox_DZ->value();
1021 else if ( send == Group3Spin->SpinBox_DY ) {
1022 vx = Group3Spin->SpinBox_DX->value();
1024 vz = Group3Spin->SpinBox_DZ->value();
1026 else if ( send == Group3Spin->SpinBox_DZ ) {
1027 vx = Group3Spin->SpinBox_DX->value();
1028 vy = Group3Spin->SpinBox_DY->value();
1031 else if ( send == Group4Spin->SpinBox_DX ) {
1033 vy = Group4Spin->SpinBox_DY->value();
1034 vz = Group4Spin->SpinBox_DZ->value();
1035 vs = Group4Spin->SpinBox_DS->value();
1037 else if ( send == Group4Spin->SpinBox_DY ) {
1038 vx = Group4Spin->SpinBox_DX->value();
1040 vz = Group4Spin->SpinBox_DZ->value();
1041 vs = Group4Spin->SpinBox_DS->value();
1043 else if ( send == Group4Spin->SpinBox_DZ ) {
1044 vx = Group4Spin->SpinBox_DX->value();
1045 vy = Group4Spin->SpinBox_DY->value();
1047 vs = Group4Spin->SpinBox_DS->value();
1049 else if ( send == Group4Spin->SpinBox_DS ) {
1050 vx = Group4Spin->SpinBox_DX->value();
1051 vy = Group4Spin->SpinBox_DY->value();
1052 vz = Group4Spin->SpinBox_DZ->value();
1055 // NPAL16010 (Sketcher Apply non available if only one line is modified)
1056 // if ValueChangedInSpinBox() called from eventFilter()
1057 else if ( Group1Spin->SpinBox_DX->hasFocus() ) {
1060 else if ( Group2Spin->SpinBox_DX ->hasFocus() ) {
1062 vy = Group2Spin->SpinBox_DY->value();
1064 else if ( Group2Spin->SpinBox_DY->hasFocus() ) {
1065 vx = Group2Spin->SpinBox_DX->value();
1068 else if ( Group3Spin->SpinBox_DX->hasFocus() ) {
1070 vy = Group3Spin->SpinBox_DY->value();
1071 vz = Group3Spin->SpinBox_DZ->value();
1073 else if ( Group3Spin->SpinBox_DY->hasFocus() ) {
1074 vx = Group3Spin->SpinBox_DX->value();
1076 vz = Group3Spin->SpinBox_DZ->value();
1078 else if ( Group3Spin->SpinBox_DZ->hasFocus() ) {
1079 vx = Group3Spin->SpinBox_DX->value();
1080 vy = Group3Spin->SpinBox_DY->value();
1083 else if ( Group4Spin->SpinBox_DX->hasFocus() ) {
1085 vy = Group4Spin->SpinBox_DY->value();
1086 vz = Group4Spin->SpinBox_DZ->value();
1087 vs = Group4Spin->SpinBox_DS->value();
1089 else if ( Group4Spin->SpinBox_DY->hasFocus() ) {
1090 vx = Group4Spin->SpinBox_DX->value();
1092 vz = Group4Spin->SpinBox_DZ->value();
1093 vs = Group4Spin->SpinBox_DS->value();
1095 else if ( Group4Spin->SpinBox_DZ->hasFocus() ) {
1096 vx = Group4Spin->SpinBox_DX->value();
1097 vy = Group4Spin->SpinBox_DY->value();
1099 vs = Group4Spin->SpinBox_DS->value();
1101 else if ( Group4Spin->SpinBox_DS->hasFocus() ) {
1102 vx = Group4Spin->SpinBox_DX->value();
1103 vy = Group4Spin->SpinBox_DY->value();
1104 vz = Group4Spin->SpinBox_DZ->value();
1108 if ( myConstructorId == 0 ) { // SEGMENT
1109 if ( mySketchType == PT_ABS ) {
1113 else if ( mySketchType == PT_RELATIVE ) {
1117 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1121 else if ( mySketchType == DIR_ANGLE_X ) {
1125 else if ( mySketchType == DIR_ANGLE_Y ) {
1129 else if ( mySketchType == DIR_PER_LENGTH ) {
1132 else if ( mySketchType == DIR_PER_X ) {
1135 else if ( mySketchType == DIR_PER_Y ) {
1138 else if ( mySketchType == DIR_TAN_LENGTH ) {
1141 else if ( mySketchType == DIR_TAN_X ) {
1144 else if ( mySketchType == DIR_TAN_Y ) {
1147 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1152 else if ( mySketchType == DIR_DXDY_X ) {
1157 else if ( mySketchType == DIR_DXDY_Y ) {
1163 else if ( myConstructorId == 1 ) { // ARC
1164 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1169 else if ( mySketchType == DIR_PER_LENGTH ) {
1173 else if ( mySketchType == DIR_TAN_LENGTH ) {
1177 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1185 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1189 //=================================================================================
1190 // function : GetNewCommand()
1191 // purpose : Build the new command with context
1192 //=================================================================================
1193 QString EntityGUI_SketcherDlg::GetNewCommand()
1195 QString myNewCommand = ":";
1196 if ( mySketchState == FIRST_POINT ) {
1197 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1198 myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1199 if ( mySketchType == PT_RELATIVE)
1200 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1201 return myNewCommand;
1204 if ( myConstructorId == 0 ) { // SEGMENT
1205 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1206 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1207 if ( mySketchType == PT_RELATIVE)
1208 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1209 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1210 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1211 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1213 if ( mySketchType == DIR_ANGLE_X ) {
1214 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1215 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1217 if ( mySketchType == DIR_ANGLE_Y ) {
1218 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1219 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1221 if ( mySketchType == DIR_PER_LENGTH ) {
1222 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1223 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1225 if ( mySketchType == DIR_PER_X ) {
1226 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1227 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1229 if ( mySketchType == DIR_PER_Y ) {
1230 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1231 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1233 if ( mySketchType == DIR_TAN_LENGTH )
1234 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1235 if ( mySketchType == DIR_TAN_X )
1236 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1237 if ( mySketchType == DIR_TAN_Y)
1238 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1239 if ( mySketchType == DIR_DXDY_LENGTH ) {
1240 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1241 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1243 if ( mySketchType == DIR_DXDY_X ) {
1244 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1245 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1247 if ( mySketchType == DIR_DXDY_Y ) {
1248 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1249 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1252 else if ( myConstructorId == 1 ) { // ARC
1253 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1254 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1255 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1257 if ( mySketchType == DIR_PER_LENGTH ) {
1258 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1259 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1261 if ( mySketchType == DIR_TAN_LENGTH ) {
1262 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1264 if ( mySketchType == DIR_DXDY_LENGTH ) {
1265 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1266 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1269 return myNewCommand;
1272 //=================================================================================
1273 // function : createOperation
1275 //=================================================================================
1276 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1278 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1281 //=================================================================================
1282 // function : isValid
1284 //=================================================================================
1285 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1290 //=================================================================================
1291 // function : execute
1293 //=================================================================================
1294 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1296 if ( mySketchState == FIRST_POINT ) {
1301 //Test if the current point is the same as the last one
1302 TopoDS_Shape myShape1, myShape2;
1305 QString Command1 = myCommand.join( "" );
1306 Sketcher_Profile aProfile1( Command1.toAscii() );
1307 if ( aProfile1.IsDone() )
1308 myShape1 = aProfile1.GetShape();
1311 QString Command2 = Command1 + GetNewCommand();
1312 Sketcher_Profile aProfile2( Command2.toAscii() );
1313 if ( aProfile2.IsDone() )
1314 myShape2 = aProfile2.GetShape();
1316 if ( myShape2.IsNull() ) {
1317 //the current point is the same as the last one
1318 myLastX2 = myLastX1;
1319 myLastY2 = myLastY1;
1322 TopoDS_Vertex V1, V2;
1324 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1325 //the last shape is the first point
1326 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1331 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1332 pt = BRep_Tool::Pnt( V2 );
1336 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1337 pt = BRep_Tool::Pnt( V2 );
1344 if ( ( mySketchState != FIRST_POINT &&
1345 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1346 cmd = myCommand.join( "" );
1348 if ( Group1Sel->isVisible() ) {
1349 Group1Sel->buttonApply->setEnabled( false );
1350 //Group1Sel->buttonApply->setFocus();
1352 if ( Group1Spin->isVisible() ) {
1353 Group1Spin->buttonApply->setEnabled( false );
1354 //Group1Spin->buttonApply->setFocus();
1356 if ( Group2Spin->isVisible() ) {
1357 Group2Spin->buttonApply->setEnabled( false );
1358 //Group2Spin->buttonApply->setFocus();
1360 if ( Group3Spin->isVisible() ) {
1361 Group3Spin->buttonApply->setEnabled( false );
1362 //Group3Spin->buttonApply->setFocus();
1364 if ( Group4Spin->isVisible() ) {
1365 Group4Spin->buttonApply->setEnabled( false );
1366 //Group4Spin->buttonApply->setFocus();
1370 cmd = myCommand.join( "" ) + GetNewCommand();
1372 if ( Group1Sel->isVisible() ) {
1373 Group1Sel->buttonApply->setEnabled( true );
1374 //Group1Sel->buttonApply->setFocus();
1376 if ( Group1Spin->isVisible() ) {
1377 Group1Spin->buttonApply->setEnabled( true );
1378 //Group1Spin->buttonApply->setFocus();
1380 if ( Group2Spin->isVisible() ) {
1381 Group2Spin->buttonApply->setEnabled( true );
1382 //Group2Spin->buttonApply->setFocus();
1384 if ( Group3Spin->isVisible() ) {
1385 Group3Spin->buttonApply->setEnabled( true );
1386 //Group3Spin->buttonApply->setFocus();
1388 if ( Group4Spin->isVisible() ) {
1389 Group4Spin->buttonApply->setEnabled( true );
1390 //Group4Spin->buttonApply->setFocus();
1394 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1395 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1396 WPlane->length( 9 );
1397 WPlane[0] = myWPlane.Location().X();
1398 WPlane[1] = myWPlane.Location().Y();
1399 WPlane[2] = myWPlane.Location().Z();
1401 WPlane[3] = myWPlane.Direction().X();
1402 WPlane[4] = myWPlane.Direction().Y();
1403 WPlane[5] = myWPlane.Direction().Z();
1405 WPlane[6] = myWPlane.XDirection().X();
1406 WPlane[7] = myWPlane.XDirection().Y();
1407 WPlane[8] = myWPlane.XDirection().Z();
1409 GEOM::GEOM_Object_var anObj =
1410 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.toLatin1(), WPlane );
1412 if ( !anObj->_is_nil() )
1413 objects.push_back( anObj._retn() );
1418 //================================================================
1419 // Function : displayPreview
1420 // Purpose : Method for displaying preview of resulting shape
1421 // Redefined from GEOMBase_Helper.
1422 //================================================================
1423 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1425 const bool activate,
1427 const double lineWidth,
1428 const int displayMode,
1431 // Set color for preview shape
1432 getDisplayer()->SetColor( Quantity_NOC_RED );
1434 // set width of displayed shape
1435 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1437 // Disable activation of selection
1438 getDisplayer()->SetToActivate( activate );
1440 // Make a reference to GEOM_Object
1441 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1442 getDisplayer()->SetName( objStr.in() );
1444 // Create wire from applayed object
1445 TopoDS_Shape anApplyedWire, aLastSegment;
1446 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1450 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1451 if ( aPrs != 0 && !aPrs->IsNull() )
1452 GEOMBase_Helper::displayPreview( aPrs, append, update );
1454 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1455 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1456 if ( aPrs != 0 && !aPrs->IsNull() )
1457 GEOMBase_Helper::displayPreview( aPrs, append, update );
1459 getDisplayer()->UnsetName();
1461 // Enable activation of displayed objects
1462 getDisplayer()->SetToActivate( true );
1465 //================================================================
1466 // Function : createShapes
1467 // Purpose : Create applyed wire, and last segment from entry object
1468 //================================================================
1469 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1470 TopoDS_Shape& theApplyedWire,
1471 TopoDS_Shape& theLastSegment )
1473 TopoDS_Shape aShape;
1474 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1475 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1478 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1479 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1480 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1481 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1482 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1483 theApplyedWire = aShape;
1487 BRepBuilderAPI_MakeWire aBuilder;
1488 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1490 TopoDS_Shape anEdge = anExp.Current();
1492 if ( anExp.More() ) // i.e. non-last edge
1493 aBuilder.Add( TopoDS::Edge( anEdge ) );
1495 theLastSegment = anEdge;
1500 if ( aBuilder.IsDone() )
1501 theApplyedWire = aBuilder.Shape();
1506 //=================================================================================
1507 // function : keyPressEvent()
1509 //=================================================================================
1510 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1512 QDialog::keyPressEvent( e );
1513 if ( e->isAccepted() )
1516 if ( e->key() == Qt::Key_F1 ) {
1522 void EntityGUI_SketcherDlg::initSpinBox( QDoubleSpinBox* spinBox,
1523 double min, double max,
1524 double step, int decimals )
1526 spinBox->setDecimals( decimals );
1527 spinBox->setRange( min, max );
1528 spinBox->setSingleStep( step );
1531 //=================================================================================
1532 // function : SetDoubleSpinBoxStep()
1533 // purpose : Double spin box management
1534 //=================================================================================
1535 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1537 Group1Spin->SpinBox_DX->setSingleStep(step);
1538 Group2Spin->SpinBox_DX->setSingleStep(step);
1539 Group2Spin->SpinBox_DY->setSingleStep(step);
1540 Group3Spin->SpinBox_DX->setSingleStep(step);
1541 Group3Spin->SpinBox_DY->setSingleStep(step);
1542 Group3Spin->SpinBox_DZ->setSingleStep(step);
1543 Group4Spin->SpinBox_DX->setSingleStep(step);
1544 Group4Spin->SpinBox_DY->setSingleStep(step);
1545 Group4Spin->SpinBox_DZ->setSingleStep(step);
1546 Group4Spin->SpinBox_DS->setSingleStep(step);