1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : EntityGUI_SketcherDlg.cxx
24 // 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 ),
66 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
68 myLineWidth( lineWidth )
71 setAttribute( Qt::WA_DeleteOnClose );
73 myGeometryGUI->SetActiveDialogBox(this);
75 MainWidget = new EntityGUI_Skeleton( this );
76 QVBoxLayout* topLayout = new QVBoxLayout( this );
77 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
78 topLayout->addWidget( MainWidget );
80 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
81 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
82 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
83 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
85 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
86 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
87 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
89 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
91 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
92 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
93 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
94 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
95 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
96 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
97 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
99 /***************************************************************/
100 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
102 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
103 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
104 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
105 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
107 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
109 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
110 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
111 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
112 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
113 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
115 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
117 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
118 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
119 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
120 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
122 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
124 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
125 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
126 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
127 Group1Sel->PushButton1->setIcon( image0 );
128 Group1Sel->buttonUndo->setIcon( image1 );
129 Group1Sel->buttonRedo->setIcon( image2 );
130 Group1Sel->LineEdit1->setReadOnly( true );
132 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
133 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
134 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
135 Group1Spin->buttonUndo->setIcon( image1 );
136 Group1Spin->buttonRedo->setIcon( image2 );
138 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
139 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
140 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
141 Group2Spin->buttonUndo->setIcon( image1 );
142 Group2Spin->buttonRedo->setIcon( image2 );
144 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
145 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
146 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
147 Group3Spin->buttonUndo->setIcon( image1 );
148 Group3Spin->buttonRedo->setIcon( image2 );
150 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
151 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
152 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
153 Group4Spin->buttonUndo->setIcon( image1 );
154 Group4Spin->buttonRedo->setIcon( image2 );
156 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
157 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
158 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
159 DestCntLayout->addWidget( GroupD1, 1, 0 );
160 DestCntLayout->addWidget( GroupD2, 1, 1 );
162 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
163 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
164 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
165 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
166 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
167 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
168 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
169 /***************************************************************/
171 QButtonGroup* ButtonGroup = new QButtonGroup( this );
172 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
173 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
175 /* signals and slots connections */
176 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
177 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
178 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
179 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
181 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
182 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
183 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
184 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
185 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
186 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
187 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
188 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
189 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
190 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
191 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
192 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
193 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
194 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
195 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
197 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
198 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
199 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
200 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
201 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
203 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
204 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
206 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
207 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
208 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
209 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
210 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
211 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
212 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
213 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
214 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
215 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
217 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
219 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
220 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
222 // install event filter on spin-boxes to provide Apply action on Return pressed
223 Group1Spin->SpinBox_DX->installEventFilter(this);
224 Group2Spin->SpinBox_DX->installEventFilter(this);
225 Group2Spin->SpinBox_DY->installEventFilter(this);
226 Group3Spin->SpinBox_DX->installEventFilter(this);
227 Group3Spin->SpinBox_DY->installEventFilter(this);
228 Group3Spin->SpinBox_DZ->installEventFilter(this);
229 Group4Spin->SpinBox_DX->installEventFilter(this);
230 Group4Spin->SpinBox_DY->installEventFilter(this);
231 Group4Spin->SpinBox_DZ->installEventFilter(this);
232 Group4Spin->SpinBox_DS->installEventFilter(this);
238 //=================================================================================
239 // function : ~EntityGUI_SketcherDlg()
240 // purpose : Destroys the object and frees any allocated resources
241 //=================================================================================
242 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
244 myGeometryGUI->SetActiveDialogBox( 0 );
248 //=================================================================================
249 // function : eventFilter()
250 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
251 //=================================================================================
252 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
254 if (event->type() == QEvent::KeyPress) {
255 QKeyEvent* ke = (QKeyEvent*)event;
256 if (ke->key() == Qt::Key_Return) {
257 if (object == Group1Spin->SpinBox_DX) {
258 Group1Spin->buttonApply->animateClick();
260 } else if (object == Group2Spin->SpinBox_DX ||
261 object == Group2Spin->SpinBox_DY) {
262 Group2Spin->buttonApply->animateClick();
264 } else if (object == Group3Spin->SpinBox_DX ||
265 object == Group3Spin->SpinBox_DY ||
266 object == Group3Spin->SpinBox_DZ) {
267 Group3Spin->buttonApply->animateClick();
269 } else if (object == Group4Spin->SpinBox_DX ||
270 object == Group4Spin->SpinBox_DY ||
271 object == Group4Spin->SpinBox_DZ ||
272 object == Group4Spin->SpinBox_DS) {
273 Group4Spin->buttonApply->animateClick();
279 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
281 return QDialog::eventFilter(object, event);
285 //=================================================================================
288 //=================================================================================
289 void EntityGUI_SketcherDlg::Init()
292 myEditCurrentArgument = Group1Sel->LineEdit1;
293 myCommand.append( "Sketcher" );
294 myUndoCommand.append( "Sketcher" );
296 mySketchState = FIRST_POINT;
297 globalSelection( GEOM_POINT );
304 myHelpFileName = "create_sketcher_page.html";
306 /* Get setting of step value from file configuration */
307 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
309 /* min, max, step and decimals for spin boxes */
310 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
311 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
312 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
313 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
314 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
315 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
316 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
317 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
318 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
319 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
321 /* displays Dialog */
322 MainWidget->GroupConstructors->setEnabled( false );
323 MainWidget->GroupDest1->setEnabled( false );
324 setEnabledUndo( false );
325 setEnabledRedo( false );
327 MainWidget->RadioButton1->setChecked( true );
332 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
336 //=================================================================================
337 // function : InitClick()
339 //=================================================================================
340 void EntityGUI_SketcherDlg::InitClick()
342 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
354 //=================================================================================
355 // function : TypeClicked()
356 // purpose : Radio button management
357 //=================================================================================
358 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
360 myConstructorId = constructorId;
361 if ( myConstructorId == 0 ) { // SEGMENT
362 GroupD2->setEnabled( true );
363 MainWidget->RB_Dest1->setEnabled( true );
364 MainWidget->RB_Dest1->setChecked( true );
367 else if ( myConstructorId == 1 ) { // ARC
368 GroupD2->setEnabled( false );
369 MainWidget->RB_Dest1->setEnabled( false );
370 MainWidget->RB_Dest2->setChecked( true );
376 //=================================================================================
377 // function : DestClicked()
378 // purpose : Radio button management
379 //=================================================================================
380 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
386 if ( constructorId == 1 ) {
388 GroupPt->RB_Point1->setChecked( true );
390 PointClicked( 1 ); // XY
392 else if ( constructorId == 0 ) {
394 GroupD1->RB_Dir11->setChecked( true );
397 Dir1Clicked( 2 ); // Angle
402 //=================================================================================
403 // function : PointClicked()
404 // purpose : Radio button management
405 //=================================================================================
406 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
410 // Get setting of step value from file configuration
411 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
413 if ( myConstructorId == 0 ) { // SEGMENT
414 if ( constructorId == 1 ) { // XY
415 mySketchType = PT_ABS;
416 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
417 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
418 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
419 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
421 Group2Spin->SpinBox_DX->setValue( myX );
423 Group2Spin->SpinBox_DY->setValue( myY );
425 Group2Spin->buttonApply->setFocus();
427 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
429 else if ( constructorId == 0 ) { // DXDY
430 mySketchType = PT_RELATIVE;
431 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
432 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
433 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
434 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
436 Group2Spin->SpinBox_DX->setValue( myDX );
438 Group2Spin->SpinBox_DY->setValue( myDY );
440 Group2Spin->buttonApply->setFocus();
442 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
444 else if ( constructorId == 2 ) { // Selection
445 mySketchType = PT_SEL;
446 myEditCurrentArgument = Group1Sel->LineEdit1;
447 connect( myGeometryGUI->getApp()->selectionMgr(),
448 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
450 Group1Sel->buttonApply->setFocus();
451 SelectionIntoArgument();
457 //=================================================================================
458 // function : Dir1Clicked()
459 // purpose : Radio button management
460 //=================================================================================
461 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
463 myConstructorDirId = constructorId;
464 GroupD2->RB_Dir21->setChecked( true );
469 //=================================================================================
470 // function : Dir2Clicked()
471 // purpose : Radio button management
472 //=================================================================================
473 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
478 // Get setting of step value from file configuration
479 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
481 if ( myConstructorId == 0 ) { // SEGMENT
485 if ( myConstructorDirId == 2 ) { // Angle
486 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
487 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
488 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
489 Group2Spin->SpinBox_DX->setValue( myAngle );
490 Group2Spin->buttonApply->setFocus();
493 if ( constructorId == 2 ) { // Length
494 mySketchType = DIR_ANGLE_LENGTH;
495 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
496 Group2Spin->SpinBox_DY->setValue( myLength );
498 else if ( constructorId == 0 ) { // X
499 mySketchType = DIR_ANGLE_X;
500 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
501 Group2Spin->SpinBox_DY->setValue( myX );
503 else if ( constructorId == 1 ) { // Y
504 mySketchType = DIR_ANGLE_Y;
505 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
506 Group2Spin->SpinBox_DY->setValue( myY );
509 else if ( myConstructorDirId == 0 ) { // Perpendicular
511 Group1Spin->buttonApply->setFocus();
513 if ( constructorId == 2 ) { // Length
514 mySketchType = DIR_PER_LENGTH;
515 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
516 Group1Spin->SpinBox_DX->setValue( myLength );
518 else if ( constructorId == 0 ) { // X
519 mySketchType = DIR_PER_X;
520 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
521 Group1Spin->SpinBox_DX->setValue( myX );
523 else if ( constructorId == 1 ) { // Y
524 mySketchType = DIR_PER_Y;
525 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
526 Group1Spin->SpinBox_DX->setValue( myY );
529 else if ( myConstructorDirId == 1 ) { // Tangent
531 Group1Spin->buttonApply->setFocus();
533 if ( constructorId == 2 ) { // Length
534 mySketchType = DIR_TAN_LENGTH;
535 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
536 Group1Spin->SpinBox_DX->setValue( myLength );
538 else if ( constructorId == 0 ) { // X
539 mySketchType = DIR_TAN_X;
540 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
541 Group1Spin->SpinBox_DX->setValue( myX );
543 else if ( constructorId == 1 ) { // Y
544 mySketchType = DIR_TAN_Y;
545 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
546 Group1Spin->SpinBox_DX->setValue( myY );
549 else if ( myConstructorDirId == 3 ) { // DXDY
550 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
551 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
552 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
553 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
554 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
556 Group3Spin->SpinBox_DX->setValue( myDX );
558 Group3Spin->SpinBox_DY->setValue( myDY );
560 Group3Spin->buttonApply->setFocus();
562 if ( constructorId == 2 ) { // Length
563 mySketchType = DIR_DXDY_LENGTH;
564 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
565 Group3Spin->SpinBox_DZ->setValue( myLength );
567 else if ( constructorId == 0 ) { // X
568 mySketchType = DIR_DXDY_X;
569 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
570 Group3Spin->SpinBox_DZ->setValue( myX );
572 else if ( constructorId == 1 ) { // Y
573 mySketchType = DIR_DXDY_Y;
574 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
575 Group3Spin->SpinBox_DZ->setValue( myY );
579 else if ( myConstructorId == 1 ) { // ARC
580 if ( myConstructorDirId == 2 ) { // Angle
581 if ( constructorId == 2 ) { // Length
582 mySketchType = DIR_ANGLE_LENGTH;
583 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
584 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
585 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
586 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
587 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
588 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
589 Group3Spin->SpinBox_DX->setValue( myAngle );
591 Group3Spin->SpinBox_DY->setValue( myRadius );
593 Group3Spin->SpinBox_DZ->setValue( myLength );
595 Group3Spin->buttonApply->setFocus();
598 else if ( myConstructorDirId == 0 ) { // Perpendicular
599 if ( constructorId == 2 ) { // Length
600 mySketchType = DIR_PER_LENGTH;
601 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
602 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
603 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
604 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
606 Group2Spin->SpinBox_DX->setValue( myRadius );
608 Group2Spin->SpinBox_DY->setValue( myLength );
610 Group2Spin->buttonApply->setFocus();
613 else if ( myConstructorDirId == 1 ) { // Tangent
614 if ( constructorId == 2 ) { // Length
615 mySketchType = DIR_TAN_LENGTH;
616 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
617 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
618 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
619 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
621 Group2Spin->SpinBox_DX->setValue( myRadius );
623 Group2Spin->SpinBox_DY->setValue( myLength );
625 Group2Spin->buttonApply->setFocus();
628 else if ( myConstructorDirId == 3 ) { // DXDY
629 if ( constructorId == 2 ) { // Length
630 mySketchType = DIR_DXDY_LENGTH;
631 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
632 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
633 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
634 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
636 Group4Spin->SpinBox_DX->setValue( myDX );
638 Group4Spin->SpinBox_DY->setValue( myDY );
640 Group4Spin->SpinBox_DZ->setValue( myRadius );
642 Group4Spin->SpinBox_DS->setValue( myLength );
644 Group4Spin->buttonApply->setFocus();
649 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
653 //=================================================================================
654 // function : ClickOnCancel()
656 //=================================================================================
657 void EntityGUI_SketcherDlg::ClickOnCancel()
663 //=================================================================================
664 // function : ClickOnEnd()
665 // purpose : connected to buttonEnd AND buttonClose
666 //=================================================================================
667 void EntityGUI_SketcherDlg::ClickOnEnd()
669 if ( sender() == MainWidget->buttonClose ) {
670 // Verify validity of commands
671 if ( myCommand.count() <= 2 ) {
672 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
673 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
678 QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
679 Sketcher_Profile aProfile( Command.toAscii() );
681 Command = myCommand.join( "" );
682 aProfile = Sketcher_Profile( Command.toAscii() );
683 TopoDS_Shape myShape;
684 if ( aProfile.IsDone() )
685 myShape = aProfile.GetShape();
687 if ( myShape.ShapeType() != TopAbs_VERTEX )
688 myCommand.append( ":WW" );
691 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
692 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
693 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
694 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
695 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
696 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
702 if ( myCommand.size() > 2 )
709 //=================================================================================
710 // function : ClickOnApply()
712 //=================================================================================
713 bool EntityGUI_SketcherDlg::ClickOnApply()
715 if ( sender() && sender()->inherits( "QPushButton" ) )
716 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
719 myCommand.append( GetNewCommand( aParameters ) );
720 mySketchState = NEXT_POINT;
722 myUndoCommand.clear();
723 myUndoCommand.append( "Sketcher" );
725 myParameters.append( aParameters );
726 myUndoParameters.clear();
728 MainWidget->GroupConstructors->setEnabled( true );
729 MainWidget->GroupDest1->setEnabled( true );
730 setEnabledUndo( true );
731 setEnabledRedo( false );
734 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
737 // Set focus to SpinBox_DX
738 if ( sender() == Group1Spin->buttonApply ) {
739 (Group1Spin->SpinBox_DX)->setFocus();
740 (Group1Spin->SpinBox_DX)->selectAll();
742 else if ( sender() == Group2Spin->buttonApply ) {
743 (Group2Spin->SpinBox_DX)->setFocus();
744 (Group2Spin->SpinBox_DX)->selectAll();
746 else if ( sender() == Group3Spin->buttonApply ) {
747 (Group3Spin->SpinBox_DX)->setFocus();
748 (Group3Spin->SpinBox_DX)->selectAll();
750 else if ( sender() == Group4Spin->buttonApply ) {
751 (Group4Spin->SpinBox_DX)->setFocus();
752 (Group4Spin->SpinBox_DX)->selectAll();
758 //=================================================================================
759 // function : ClickOnHelp()
761 //=================================================================================
762 void EntityGUI_SketcherDlg::ClickOnHelp()
764 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
766 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
770 platform = "winapplication";
772 platform = "application";
775 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
776 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
777 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
778 QObject::tr( "BUT_OK" ) );
782 //=================================================================================
783 // function : ClickOnUndo()
785 //=================================================================================
786 void EntityGUI_SketcherDlg::ClickOnUndo()
788 myUndoCommand.append( myCommand.last() );
789 myCommand.pop_back();
791 myUndoParameters.append( myParameters.last() );
792 myParameters.pop_back();
794 if ( myCommand.count() == 1 ) {
795 mySketchState = FIRST_POINT;
797 MainWidget->RadioButton1->setChecked( true );
800 MainWidget->GroupConstructors->setEnabled( false );
801 MainWidget->GroupDest1->setEnabled( false );
802 setEnabledUndo( false );
805 setEnabledRedo( true );
807 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
810 //=================================================================================
811 // function : ClickOnRedo()
813 //=================================================================================
814 void EntityGUI_SketcherDlg::ClickOnRedo()
816 myCommand.append( myUndoCommand.last() );
817 myUndoCommand.pop_back();
819 myParameters.append( myUndoParameters.last() );
820 myUndoParameters.pop_back();
822 mySketchState = NEXT_POINT;
824 MainWidget->GroupConstructors->setEnabled( true );
825 MainWidget->GroupDest1->setEnabled( true );
826 setEnabledUndo( true );
828 if ( myUndoCommand.count() == 1 )
829 setEnabledRedo( false );
831 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
834 //=================================================================================
835 // function : setEnabledUndo()
837 //=================================================================================
838 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
840 Group1Sel->buttonUndo->setEnabled( value );
841 Group1Spin->buttonUndo->setEnabled( value );
842 Group2Spin->buttonUndo->setEnabled( value );
843 Group3Spin->buttonUndo->setEnabled( value );
844 Group4Spin->buttonUndo->setEnabled( value );
847 //=================================================================================
848 // function : setEnabledRedo()
850 //=================================================================================
851 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
853 Group1Sel->buttonRedo->setEnabled( value );
854 Group1Spin->buttonRedo->setEnabled( value );
855 Group2Spin->buttonRedo->setEnabled( value );
856 Group3Spin->buttonRedo->setEnabled( value );
857 Group4Spin->buttonRedo->setEnabled( value );
860 //=================================================================================
861 // function : SelectionIntoArgument()
862 // purpose : Called when selection as changed
863 //=================================================================================
864 void EntityGUI_SketcherDlg::SelectionIntoArgument()
866 myEditCurrentArgument->setText( "" );
870 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
871 SALOME_ListIO aSelList;
872 aSelMgr->selectedObjects(aSelList);
874 int nbSel = aSelList.Extent();
875 if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
876 Standard_Boolean aRes = Standard_False;
877 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
878 if (!CORBA::is_nil(aSelectedObject) && aRes) {
880 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
882 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
884 aTrans.SetTransformation(aWPlane);
885 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
886 aShape = aTransformation.Shape();
889 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
892 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
898 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
902 //=================================================================================
903 // function : SetEditCurrentArgument()
905 //=================================================================================
906 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
908 if ( sender() == Group1Sel->PushButton1 ) {
909 myEditCurrentArgument = Group1Sel->LineEdit1;
910 myEditCurrentArgument->setFocus();
912 SelectionIntoArgument();
916 //=================================================================================
917 // function : LineEditReturnPressed()
919 //=================================================================================
920 void EntityGUI_SketcherDlg::LineEditReturnPressed()
922 if ( sender() == Group1Sel->LineEdit1 ) {
923 myEditCurrentArgument = Group1Sel->LineEdit1;
925 /* User name of object input management */
926 /* If successfull the selection is changed and signal emitted... */
927 /* so SelectionIntoArgument() is automatically called. */
928 const QString objectUserName = myEditCurrentArgument->text();
929 QWidget* thisWidget = (QWidget*)this;
931 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
932 SALOME_ListIO aSelList;
933 aSelMgr->selectedObjects(aSelList);
935 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
936 myEditCurrentArgument->setText( objectUserName );
941 //=================================================================================
942 // function : DeactivateActiveDialog()
944 //=================================================================================
945 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
947 //myGeometryGUI->SetState( -1 );
951 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
952 myGeometryGUI->SetActiveDialogBox( 0 );
956 //=================================================================================
957 // function : ActivateThisDialog()
959 //=================================================================================
960 void EntityGUI_SketcherDlg::ActivateThisDialog()
962 myGeometryGUI->EmitSignalDeactivateDialog();
964 myGeometryGUI->SetActiveDialogBox( this );
966 connect( myGeometryGUI->getApp()->selectionMgr(),
967 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
969 //myGeometryGUI->SetState( 0 );
970 globalSelection( GEOM_POINT );
972 myEditCurrentArgument = Group1Sel->LineEdit1;
973 myEditCurrentArgument->setFocus();
975 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
979 //=================================================================================
980 // function : enterEvent [REDEFINED]
982 //=================================================================================
983 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
985 if ( !MainWidget->GroupConstructors->isEnabled() )
986 ActivateThisDialog();
990 //=================================================================================
991 // function : closeEvent()
993 //=================================================================================
994 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
996 //myGeometryGUI->SetState( -1 );
997 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
998 myGeometryGUI->getApp()->updateActions();
999 QDialog::closeEvent( e );
1003 //=================================================================================
1004 // function : ValueChangedInSpinBox()
1006 //=================================================================================
1007 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1009 QObject* send = (QObject*)sender();
1010 Standard_Real vx, vy, vz, vs;
1011 vx = vy = vz = vs = 0.0;
1013 QString vxStr, vyStr, vzStr, vsStr;
1015 QString newValueStr;
1016 if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1017 newValueStr = aDoubleSpinBox->text();
1019 if ( send == Group1Spin->SpinBox_DX ) {
1020 vx = newValue; vxStr = newValueStr;
1022 else if ( send == Group2Spin->SpinBox_DX ) {
1023 vx = newValue; vxStr = newValueStr;
1024 vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1026 else if ( send == Group2Spin->SpinBox_DY ) {
1027 vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1028 vy = newValue; vyStr = newValueStr;
1030 else if ( send == Group3Spin->SpinBox_DX ) {
1031 vx = newValue; vxStr = newValueStr;
1032 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1033 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1035 else if ( send == Group3Spin->SpinBox_DY ) {
1036 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1037 vy = newValue; vyStr = newValueStr;
1038 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1040 else if ( send == Group3Spin->SpinBox_DZ ) {
1041 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1042 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1043 vz = newValue; vzStr = newValueStr;
1045 else if ( send == Group4Spin->SpinBox_DX ) {
1046 vx = newValue; vxStr = newValueStr;
1047 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1048 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1049 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1051 else if ( send == Group4Spin->SpinBox_DY ) {
1052 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1053 vy = newValue; vyStr = newValueStr;
1054 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1055 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1057 else if ( send == Group4Spin->SpinBox_DZ ) {
1058 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1059 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1060 vz = newValue; vzStr = newValueStr;
1061 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1063 else if ( send == Group4Spin->SpinBox_DS ) {
1064 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1065 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1066 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1067 vs = newValue; vsStr = newValueStr;
1069 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1071 if ( myConstructorId == 0 ) { // SEGMENT
1072 if ( mySketchType == PT_ABS ) {
1078 else if ( mySketchType == PT_RELATIVE ) {
1084 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1088 myLengthStr = vyStr;
1090 else if ( mySketchType == DIR_ANGLE_X ) {
1096 else if ( mySketchType == DIR_ANGLE_Y ) {
1102 else if ( mySketchType == DIR_PER_LENGTH ) {
1104 myLengthStr = vxStr;
1106 else if ( mySketchType == DIR_PER_X ) {
1110 else if ( mySketchType == DIR_PER_Y ) {
1114 else if ( mySketchType == DIR_TAN_LENGTH ) {
1116 myLengthStr = vxStr;
1118 else if ( mySketchType == DIR_TAN_X ) {
1122 else if ( mySketchType == DIR_TAN_Y ) {
1126 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1132 myLengthStr = vzStr;
1134 else if ( mySketchType == DIR_DXDY_X ) {
1142 else if ( mySketchType == DIR_DXDY_Y ) {
1151 else if ( myConstructorId == 1 ) { // ARC
1152 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1157 myRadiusStr = vyStr;
1158 myLengthStr = vzStr;
1160 else if ( mySketchType == DIR_PER_LENGTH ) {
1163 myRadiusStr = vxStr;
1164 myLengthStr = vyStr;
1166 else if ( mySketchType == DIR_TAN_LENGTH ) {
1169 myRadiusStr = vxStr;
1170 myLengthStr = vyStr;
1172 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1179 myRadiusStr = vzStr;
1180 myLengthStr = vsStr;
1184 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1188 //=================================================================================
1189 // function : GetNewCommand()
1190 // purpose : Build the new command with context
1191 //=================================================================================
1192 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1194 theParameters.clear();
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 theParameters = myXStr + ":" + myYStr;
1201 if ( mySketchType == PT_RELATIVE) {
1202 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1203 theParameters = myDXStr + ":" + myDYStr;
1205 return myNewCommand;
1208 if ( myConstructorId == 0 ) { // SEGMENT
1209 if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1210 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1211 theParameters = myXStr + ":" + myYStr;
1213 if ( mySketchType == PT_RELATIVE) {
1214 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1215 theParameters = myDXStr + ":" + myDYStr;
1217 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1218 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1219 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1220 theParameters = myAngleStr + ":" + myLengthStr;
1222 if ( mySketchType == DIR_ANGLE_X ) {
1223 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1224 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1225 theParameters = myAngleStr + ":" + myXStr;
1227 if ( mySketchType == DIR_ANGLE_Y ) {
1228 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1229 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1230 theParameters = myAngleStr + ":" + myYStr;
1232 if ( mySketchType == DIR_PER_LENGTH ) {
1233 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1234 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1235 theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1237 if ( mySketchType == DIR_PER_X ) {
1238 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1239 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1240 theParameters = QString::number( 90.0 ) + ":" + myXStr;
1242 if ( mySketchType == DIR_PER_Y ) {
1243 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1244 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1245 theParameters = QString::number( 90.0 ) + ":" + myYStr;
1247 if ( mySketchType == DIR_TAN_LENGTH ) {
1248 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1249 theParameters = myLengthStr;
1251 if ( mySketchType == DIR_TAN_X ) {
1252 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1253 theParameters = myXStr;
1255 if ( mySketchType == DIR_TAN_Y) {
1256 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1257 theParameters = myYStr;
1259 if ( mySketchType == DIR_DXDY_LENGTH ) {
1260 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1261 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1262 theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1264 if ( mySketchType == DIR_DXDY_X ) {
1265 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1266 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1267 theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1269 if ( mySketchType == DIR_DXDY_Y ) {
1270 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1271 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1272 theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1275 else if ( myConstructorId == 1 ) { // ARC
1276 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1277 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1278 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1279 theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1281 if ( mySketchType == DIR_PER_LENGTH ) {
1282 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1283 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1284 theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1286 if ( mySketchType == DIR_TAN_LENGTH ) {
1287 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1288 theParameters = myRadiusStr + ":" + myLengthStr;
1290 if ( mySketchType == DIR_DXDY_LENGTH ) {
1291 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1292 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1293 theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1296 return myNewCommand;
1299 //=================================================================================
1300 // function : createOperation
1302 //=================================================================================
1303 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1305 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1308 //=================================================================================
1309 // function : isValid
1311 //=================================================================================
1312 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1315 bool toCorrect = !IsPreview() || myIsApply;
1317 if( Group1Spin->isVisible() ) {
1318 ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1320 else if( Group2Spin->isVisible() ) {
1321 ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1322 ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1324 else if( Group3Spin->isVisible() ) {
1325 ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1326 ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1327 ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1329 else if( Group4Spin->isVisible() ) {
1330 ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1331 ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1332 ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1333 ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1336 if( myIsApply && !ok )
1342 //=================================================================================
1343 // function : execute
1345 //=================================================================================
1346 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1348 QString aParameters;
1350 if ( mySketchState == FIRST_POINT ) {
1355 //Test if the current point is the same as the last one
1356 TopoDS_Shape myShape1, myShape2;
1359 QString Command1 = myCommand.join( "" );
1360 Sketcher_Profile aProfile1( Command1.toAscii() );
1361 if ( aProfile1.IsDone() )
1362 myShape1 = aProfile1.GetShape();
1365 QString Command2 = Command1 + GetNewCommand( aParameters );
1366 Sketcher_Profile aProfile2( Command2.toAscii() );
1367 if ( aProfile2.IsDone() )
1368 myShape2 = aProfile2.GetShape();
1370 if ( myShape2.IsNull() ) {
1371 //the current point is the same as the last one
1372 myLastX2 = myLastX1;
1373 myLastY2 = myLastY1;
1376 TopoDS_Vertex V1, V2;
1378 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1379 //the last shape is the first point
1380 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1385 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1386 pt = BRep_Tool::Pnt( V2 );
1390 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1391 pt = BRep_Tool::Pnt( V2 );
1398 if ( ( mySketchState != FIRST_POINT &&
1399 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1400 cmd = myCommand.join( "" );
1402 if ( Group1Sel->isVisible() ) {
1403 Group1Sel->buttonApply->setEnabled( false );
1404 //Group1Sel->buttonApply->setFocus();
1406 if ( Group1Spin->isVisible() ) {
1407 Group1Spin->buttonApply->setEnabled( false );
1408 //Group1Spin->buttonApply->setFocus();
1410 if ( Group2Spin->isVisible() ) {
1411 Group2Spin->buttonApply->setEnabled( false );
1412 //Group2Spin->buttonApply->setFocus();
1414 if ( Group3Spin->isVisible() ) {
1415 Group3Spin->buttonApply->setEnabled( false );
1416 //Group3Spin->buttonApply->setFocus();
1418 if ( Group4Spin->isVisible() ) {
1419 Group4Spin->buttonApply->setEnabled( false );
1420 //Group4Spin->buttonApply->setFocus();
1424 cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1426 if ( Group1Sel->isVisible() ) {
1427 Group1Sel->buttonApply->setEnabled( true );
1428 //Group1Sel->buttonApply->setFocus();
1430 if ( Group1Spin->isVisible() ) {
1431 Group1Spin->buttonApply->setEnabled( true );
1432 //Group1Spin->buttonApply->setFocus();
1434 if ( Group2Spin->isVisible() ) {
1435 Group2Spin->buttonApply->setEnabled( true );
1436 //Group2Spin->buttonApply->setFocus();
1438 if ( Group3Spin->isVisible() ) {
1439 Group3Spin->buttonApply->setEnabled( true );
1440 //Group3Spin->buttonApply->setFocus();
1442 if ( Group4Spin->isVisible() ) {
1443 Group4Spin->buttonApply->setEnabled( true );
1444 //Group4Spin->buttonApply->setFocus();
1448 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1449 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1450 WPlane->length( 9 );
1451 WPlane[0] = myWPlane.Location().X();
1452 WPlane[1] = myWPlane.Location().Y();
1453 WPlane[2] = myWPlane.Location().Z();
1455 WPlane[3] = myWPlane.Direction().X();
1456 WPlane[4] = myWPlane.Direction().Y();
1457 WPlane[5] = myWPlane.Direction().Z();
1459 WPlane[6] = myWPlane.XDirection().X();
1460 WPlane[7] = myWPlane.XDirection().Y();
1461 WPlane[8] = myWPlane.XDirection().Z();
1463 GEOM::GEOM_Object_var anObj =
1464 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.toLatin1(), WPlane );
1466 if ( !anObj->_is_nil() )
1468 if( !IsPreview() ) {
1469 QStringList aCurrentParameters = myParameters;
1470 aCurrentParameters << aParameters;
1471 anObj->SetParameters(GeometryGUI::JoinObjectParameters(aCurrentParameters));
1474 objects.push_back( anObj._retn() );
1480 //================================================================
1481 // Function : displayPreview
1482 // Purpose : Method for displaying preview of resulting shape
1483 // Redefined from GEOMBase_Helper.
1484 //================================================================
1485 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1487 const bool activate,
1489 const double lineWidth,
1490 const int displayMode,
1493 // Set color for preview shape
1494 getDisplayer()->SetColor( Quantity_NOC_RED );
1496 // set width of displayed shape
1497 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1499 // Disable activation of selection
1500 getDisplayer()->SetToActivate( activate );
1502 // Make a reference to GEOM_Object
1503 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1504 getDisplayer()->SetName( objStr.in() );
1506 // Create wire from applayed object
1507 TopoDS_Shape anApplyedWire, aLastSegment;
1508 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1512 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1513 if ( aPrs != 0 && !aPrs->IsNull() )
1514 GEOMBase_Helper::displayPreview( aPrs, append, update );
1516 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1517 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1518 if ( aPrs != 0 && !aPrs->IsNull() )
1519 GEOMBase_Helper::displayPreview( aPrs, append, update );
1521 getDisplayer()->UnsetName();
1523 // Enable activation of displayed objects
1524 getDisplayer()->SetToActivate( true );
1527 //================================================================
1528 // Function : createShapes
1529 // Purpose : Create applyed wire, and last segment from entry object
1530 //================================================================
1531 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1532 TopoDS_Shape& theApplyedWire,
1533 TopoDS_Shape& theLastSegment )
1535 TopoDS_Shape aShape;
1536 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1537 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1540 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1541 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1542 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1543 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1544 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1545 theApplyedWire = aShape;
1549 BRepBuilderAPI_MakeWire aBuilder;
1550 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1552 TopoDS_Shape anEdge = anExp.Current();
1554 if ( anExp.More() ) // i.e. non-last edge
1555 aBuilder.Add( TopoDS::Edge( anEdge ) );
1557 theLastSegment = anEdge;
1562 if ( aBuilder.IsDone() )
1563 theApplyedWire = aBuilder.Shape();
1568 //=================================================================================
1569 // function : keyPressEvent()
1571 //=================================================================================
1572 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1574 QDialog::keyPressEvent( e );
1575 if ( e->isAccepted() )
1578 if ( e->key() == Qt::Key_F1 ) {
1584 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1585 double min, double max,
1586 double step, int decimals )
1588 spinBox->setDecimals( decimals );
1589 spinBox->setRange( min, max );
1590 spinBox->setSingleStep( step );
1593 //=================================================================================
1594 // function : SetDoubleSpinBoxStep()
1595 // purpose : Double spin box management
1596 //=================================================================================
1597 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1599 Group1Spin->SpinBox_DX->setSingleStep(step);
1600 Group2Spin->SpinBox_DX->setSingleStep(step);
1601 Group2Spin->SpinBox_DY->setSingleStep(step);
1602 Group3Spin->SpinBox_DX->setSingleStep(step);
1603 Group3Spin->SpinBox_DY->setSingleStep(step);
1604 Group3Spin->SpinBox_DZ->setSingleStep(step);
1605 Group4Spin->SpinBox_DX->setSingleStep(step);
1606 Group4Spin->SpinBox_DY->setSingleStep(step);
1607 Group4Spin->SpinBox_DZ->setSingleStep(step);
1608 Group4Spin->SpinBox_DS->setSingleStep(step);