1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : EntityGUI_SketcherDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "EntityGUI_SketcherDlg.h"
27 #include "EntityGUI_Widgets.h"
30 #include <GeometryGUI.h>
31 #include <GEOMImpl_Types.hxx>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
43 #include <BRep_Tool.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopoDS_Vertex.hxx>
48 #include <BRepBuilderAPI_Transform.hxx>
49 #include <BRepBuilderAPI_MakeWire.hxx>
50 #include <Sketcher_Profile.hxx>
52 //=================================================================================
53 // class : EntityGUI_SketcherDlg()
54 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
60 bool modal, Qt::WindowFlags fl,
61 const double lineWidth )
62 : QDialog( parent, fl ),
63 myIsAllAdded( false ),
64 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
66 myLineWidth( lineWidth )
69 setAttribute( Qt::WA_DeleteOnClose );
71 myGeometryGUI->SetActiveDialogBox(this);
73 MainWidget = new EntityGUI_Skeleton( this );
74 QVBoxLayout* topLayout = new QVBoxLayout( this );
75 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
76 topLayout->addWidget( MainWidget );
78 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
79 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
80 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
81 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
83 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
84 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
85 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
87 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
89 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
90 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
91 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
92 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
93 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
94 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
95 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
97 /***************************************************************/
98 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
100 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
101 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
102 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
103 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
105 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
107 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
108 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
109 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
110 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
111 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
113 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
115 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
116 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
117 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
118 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
120 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
122 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
123 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
124 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
125 Group1Sel->PushButton1->setIcon( image0 );
126 Group1Sel->buttonUndo->setIcon( image1 );
127 Group1Sel->buttonRedo->setIcon( image2 );
128 Group1Sel->LineEdit1->setReadOnly( true );
130 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
131 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
132 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
133 Group1Spin->buttonUndo->setIcon( image1 );
134 Group1Spin->buttonRedo->setIcon( image2 );
136 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
137 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
138 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
139 Group2Spin->buttonUndo->setIcon( image1 );
140 Group2Spin->buttonRedo->setIcon( image2 );
142 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
143 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
144 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
145 Group3Spin->buttonUndo->setIcon( image1 );
146 Group3Spin->buttonRedo->setIcon( image2 );
148 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
149 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
150 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
151 Group4Spin->buttonUndo->setIcon( image1 );
152 Group4Spin->buttonRedo->setIcon( image2 );
154 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
155 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
156 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
157 DestCntLayout->addWidget( GroupD1, 1, 0 );
158 DestCntLayout->addWidget( GroupD2, 1, 1 );
160 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
161 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
162 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
163 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
164 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
165 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
166 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
167 /***************************************************************/
169 QButtonGroup* ButtonGroup = new QButtonGroup( this );
170 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
171 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
173 /* signals and slots connections */
174 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
175 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
176 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
177 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
179 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
180 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
181 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
182 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
183 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
184 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
185 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
186 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
187 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
188 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
189 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
190 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
191 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
192 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
193 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
195 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
196 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
197 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
198 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
199 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
201 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
202 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
204 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
205 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
206 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
207 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
208 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
209 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
210 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
211 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
212 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
213 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
215 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
217 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
218 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
220 connect( Group1Spin->SpinBox_DX, SIGNAL( editingFinished() ),
221 Group1Spin->buttonApply, SLOT( animateClick() ) );
222 connect( Group2Spin->SpinBox_DX, SIGNAL( editingFinished() ),
223 Group2Spin->buttonApply, SLOT( animateClick() ) );
224 connect( Group2Spin->SpinBox_DY, SIGNAL( editingFinished() ),
225 Group2Spin->buttonApply, SLOT( animateClick() ) );
226 connect( Group3Spin->SpinBox_DX, SIGNAL( editingFinished() ),
227 Group3Spin->buttonApply, SLOT( animateClick() ) );
228 connect( Group3Spin->SpinBox_DY, SIGNAL( editingFinished() ),
229 Group3Spin->buttonApply, SLOT( animateClick() ) );
230 connect( Group3Spin->SpinBox_DZ, SIGNAL( editingFinished() ),
231 Group3Spin->buttonApply, SLOT( animateClick() ) );
232 connect( Group4Spin->SpinBox_DX, SIGNAL( editingFinished() ),
233 Group4Spin->buttonApply, SLOT( animateClick() ) );
234 connect( Group4Spin->SpinBox_DY, SIGNAL( editingFinished() ),
235 Group4Spin->buttonApply, SLOT( animateClick() ) );
236 connect( Group4Spin->SpinBox_DZ, SIGNAL( editingFinished() ),
237 Group4Spin->buttonApply, SLOT( animateClick() ) );
238 connect( Group4Spin->SpinBox_DS, SIGNAL( editingFinished() ),
239 Group4Spin->buttonApply, SLOT( animateClick() ) );
245 //=================================================================================
246 // function : ~EntityGUI_SketcherDlg()
247 // purpose : Destroys the object and frees any allocated resources
248 //=================================================================================
249 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
251 myGeometryGUI->SetActiveDialogBox( 0 );
255 //=================================================================================
258 //=================================================================================
259 void EntityGUI_SketcherDlg::Init()
262 myEditCurrentArgument = Group1Sel->LineEdit1;
263 myCommand.append( "Sketcher" );
264 myUndoCommand.append( "Sketcher" );
266 mySketchState = FIRST_POINT;
267 globalSelection( GEOM_POINT );
274 myHelpFileName = "create_sketcher_page.html";
276 /* Get setting of step value from file configuration */
277 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
279 /* min, max, step and decimals for spin boxes */
280 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
281 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
282 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
283 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
284 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
285 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
286 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
287 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
288 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
289 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
291 /* displays Dialog */
292 MainWidget->GroupConstructors->setEnabled( false );
293 MainWidget->GroupDest1->setEnabled( false );
294 setEnabledUndo( false );
295 setEnabledRedo( false );
297 MainWidget->RadioButton1->setChecked( true );
302 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
306 //=================================================================================
307 // function : InitClick()
309 //=================================================================================
310 void EntityGUI_SketcherDlg::InitClick()
312 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
324 //=================================================================================
325 // function : TypeClicked()
326 // purpose : Radio button management
327 //=================================================================================
328 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
330 myConstructorId = constructorId;
331 if ( myConstructorId == 0 ) { // SEGMENT
332 GroupD2->setEnabled( true );
333 MainWidget->RB_Dest1->setEnabled( true );
334 MainWidget->RB_Dest1->setChecked( true );
337 else if ( myConstructorId == 1 ) { // ARC
338 GroupD2->setEnabled( false );
339 MainWidget->RB_Dest1->setEnabled( false );
340 MainWidget->RB_Dest2->setChecked( true );
346 //=================================================================================
347 // function : DestClicked()
348 // purpose : Radio button management
349 //=================================================================================
350 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
356 if ( constructorId == 1 ) {
358 GroupPt->RB_Point1->setChecked( true );
360 PointClicked( 1 ); // XY
362 else if ( constructorId == 0 ) {
364 GroupD1->RB_Dir11->setChecked( true );
367 Dir1Clicked( 2 ); // Angle
372 //=================================================================================
373 // function : PointClicked()
374 // purpose : Radio button management
375 //=================================================================================
376 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
380 // Get setting of step value from file configuration
381 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
383 if ( myConstructorId == 0 ) { // SEGMENT
384 if ( constructorId == 1 ) { // XY
385 mySketchType = PT_ABS;
386 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
387 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
388 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
389 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
391 Group2Spin->SpinBox_DX->setValue( myX );
393 Group2Spin->SpinBox_DY->setValue( myY );
395 Group2Spin->buttonApply->setFocus();
397 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
399 else if ( constructorId == 0 ) { // DXDY
400 mySketchType = PT_RELATIVE;
401 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
402 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
403 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
404 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
406 Group2Spin->SpinBox_DX->setValue( myDX );
408 Group2Spin->SpinBox_DY->setValue( myDY );
410 Group2Spin->buttonApply->setFocus();
412 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
414 else if ( constructorId == 2 ) { // Selection
415 mySketchType = PT_SEL;
416 myEditCurrentArgument = Group1Sel->LineEdit1;
417 connect( myGeometryGUI->getApp()->selectionMgr(),
418 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
420 Group1Sel->buttonApply->setFocus();
421 SelectionIntoArgument();
427 //=================================================================================
428 // function : Dir1Clicked()
429 // purpose : Radio button management
430 //=================================================================================
431 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
433 myConstructorDirId = constructorId;
434 GroupD2->RB_Dir21->setChecked( true );
439 //=================================================================================
440 // function : Dir2Clicked()
441 // purpose : Radio button management
442 //=================================================================================
443 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
448 // Get setting of step value from file configuration
449 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
451 if ( myConstructorId == 0 ) { // SEGMENT
455 if ( myConstructorDirId == 2 ) { // Angle
456 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
457 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
458 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
459 Group2Spin->SpinBox_DX->setValue( myAngle );
460 Group2Spin->buttonApply->setFocus();
463 if ( constructorId == 2 ) { // Length
464 mySketchType = DIR_ANGLE_LENGTH;
465 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
466 Group2Spin->SpinBox_DY->setValue( myLength );
468 else if ( constructorId == 0 ) { // X
469 mySketchType = DIR_ANGLE_X;
470 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
471 Group2Spin->SpinBox_DY->setValue( myX );
473 else if ( constructorId == 1 ) { // Y
474 mySketchType = DIR_ANGLE_Y;
475 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
476 Group2Spin->SpinBox_DY->setValue( myY );
479 else if ( myConstructorDirId == 0 ) { // Perpendicular
481 Group1Spin->buttonApply->setFocus();
483 if ( constructorId == 2 ) { // Length
484 mySketchType = DIR_PER_LENGTH;
485 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
486 Group1Spin->SpinBox_DX->setValue( myLength );
488 else if ( constructorId == 0 ) { // X
489 mySketchType = DIR_PER_X;
490 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
491 Group1Spin->SpinBox_DX->setValue( myX );
493 else if ( constructorId == 1 ) { // Y
494 mySketchType = DIR_PER_Y;
495 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
496 Group1Spin->SpinBox_DX->setValue( myY );
499 else if ( myConstructorDirId == 1 ) { // Tangent
501 Group1Spin->buttonApply->setFocus();
503 if ( constructorId == 2 ) { // Length
504 mySketchType = DIR_TAN_LENGTH;
505 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
506 Group1Spin->SpinBox_DX->setValue( myLength );
508 else if ( constructorId == 0 ) { // X
509 mySketchType = DIR_TAN_X;
510 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
511 Group1Spin->SpinBox_DX->setValue( myX );
513 else if ( constructorId == 1 ) { // Y
514 mySketchType = DIR_TAN_Y;
515 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
516 Group1Spin->SpinBox_DX->setValue( myY );
519 else if ( myConstructorDirId == 3 ) { // DXDY
520 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
521 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
522 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
523 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
524 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
526 Group3Spin->SpinBox_DX->setValue( myDX );
528 Group3Spin->SpinBox_DY->setValue( myDY );
530 Group3Spin->buttonApply->setFocus();
532 if ( constructorId == 2 ) { // Length
533 mySketchType = DIR_DXDY_LENGTH;
534 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
535 Group3Spin->SpinBox_DZ->setValue( myLength );
537 else if ( constructorId == 0 ) { // X
538 mySketchType = DIR_DXDY_X;
539 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
540 Group3Spin->SpinBox_DZ->setValue( myX );
542 else if ( constructorId == 1 ) { // Y
543 mySketchType = DIR_DXDY_Y;
544 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
545 Group3Spin->SpinBox_DZ->setValue( myY );
549 else if ( myConstructorId == 1 ) { // ARC
550 if ( myConstructorDirId == 2 ) { // Angle
551 if ( constructorId == 2 ) { // Length
552 mySketchType = DIR_ANGLE_LENGTH;
553 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
554 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
555 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
556 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
557 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
558 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
559 Group3Spin->SpinBox_DX->setValue( myAngle );
561 Group3Spin->SpinBox_DY->setValue( myRadius );
563 Group3Spin->SpinBox_DZ->setValue( myLength );
565 Group3Spin->buttonApply->setFocus();
568 else if ( myConstructorDirId == 0 ) { // Perpendicular
569 if ( constructorId == 2 ) { // Length
570 mySketchType = DIR_PER_LENGTH;
571 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
572 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
573 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
574 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
576 Group2Spin->SpinBox_DX->setValue( myRadius );
578 Group2Spin->SpinBox_DY->setValue( myLength );
580 Group2Spin->buttonApply->setFocus();
583 else if ( myConstructorDirId == 1 ) { // Tangent
584 if ( constructorId == 2 ) { // Length
585 mySketchType = DIR_TAN_LENGTH;
586 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
587 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
588 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
589 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
591 Group2Spin->SpinBox_DX->setValue( myRadius );
593 Group2Spin->SpinBox_DY->setValue( myLength );
595 Group2Spin->buttonApply->setFocus();
598 else if ( myConstructorDirId == 3 ) { // DXDY
599 if ( constructorId == 2 ) { // Length
600 mySketchType = DIR_DXDY_LENGTH;
601 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
602 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
603 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
604 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
606 Group4Spin->SpinBox_DX->setValue( myDX );
608 Group4Spin->SpinBox_DY->setValue( myDY );
610 Group4Spin->SpinBox_DZ->setValue( myRadius );
612 Group4Spin->SpinBox_DS->setValue( myLength );
614 Group4Spin->buttonApply->setFocus();
619 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
623 //=================================================================================
624 // function : ClickOnCancel()
626 //=================================================================================
627 void EntityGUI_SketcherDlg::ClickOnCancel()
633 //=================================================================================
634 // function : ClickOnEnd()
635 // purpose : connected to buttonEnd AND buttonClose
636 //=================================================================================
637 void EntityGUI_SketcherDlg::ClickOnEnd()
639 if ( sender() == MainWidget->buttonClose ) {
640 // Verify validity of commands
641 if ( myCommand.count() <= 2 ) {
642 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
643 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
647 QString Command = myCommand.join( "" ) + GetNewCommand();
648 Sketcher_Profile aProfile( Command.toAscii() );
650 Command = myCommand.join( "" );
651 aProfile = Sketcher_Profile( Command.toAscii() );
652 TopoDS_Shape myShape;
653 if ( aProfile.IsDone() )
654 myShape = aProfile.GetShape();
656 if ( myShape.ShapeType() != TopAbs_VERTEX )
657 myCommand.append( ":WW" );
660 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
661 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
662 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
663 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
664 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
665 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
671 if ( myCommand.size() > 2 )
678 //=================================================================================
679 // function : ClickOnApply()
681 //=================================================================================
682 bool EntityGUI_SketcherDlg::ClickOnApply()
684 if ( sender() && sender()->inherits( "QPushButton" ) )
685 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
687 myCommand.append( GetNewCommand() );
688 mySketchState = NEXT_POINT;
690 myUndoCommand.clear();
691 myUndoCommand.append( "Sketcher" );
693 MainWidget->GroupConstructors->setEnabled( true );
694 MainWidget->GroupDest1->setEnabled( true );
695 setEnabledUndo( true );
696 setEnabledRedo( false );
698 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
700 // Set focus to SpinBox_DX
701 if ( sender() == Group1Spin->buttonApply ) {
702 (Group1Spin->SpinBox_DX)->setFocus();
703 (Group1Spin->SpinBox_DX)->selectAll();
705 else if ( sender() == Group2Spin->buttonApply ) {
706 (Group2Spin->SpinBox_DX)->setFocus();
707 (Group2Spin->SpinBox_DX)->selectAll();
709 else if ( sender() == Group3Spin->buttonApply ) {
710 (Group3Spin->SpinBox_DX)->setFocus();
711 (Group3Spin->SpinBox_DX)->selectAll();
713 else if ( sender() == Group4Spin->buttonApply ) {
714 (Group4Spin->SpinBox_DX)->setFocus();
715 (Group4Spin->SpinBox_DX)->selectAll();
721 //=================================================================================
722 // function : ClickOnHelp()
724 //=================================================================================
725 void EntityGUI_SketcherDlg::ClickOnHelp()
727 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
729 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
733 platform = "winapplication";
735 platform = "application";
738 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
739 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
740 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
741 QObject::tr( "BUT_OK" ) );
745 //=================================================================================
746 // function : ClickOnUndo()
748 //=================================================================================
749 void EntityGUI_SketcherDlg::ClickOnUndo()
751 myUndoCommand.append( myCommand.last() );
752 myCommand.pop_back();
754 if ( myCommand.count() == 1 ) {
755 mySketchState = FIRST_POINT;
757 MainWidget->RadioButton1->setChecked( true );
760 MainWidget->GroupConstructors->setEnabled( false );
761 MainWidget->GroupDest1->setEnabled( false );
762 setEnabledUndo( false );
765 setEnabledRedo( true );
767 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
770 //=================================================================================
771 // function : ClickOnRedo()
773 //=================================================================================
774 void EntityGUI_SketcherDlg::ClickOnRedo()
776 myCommand.append( myUndoCommand.last() );
777 myUndoCommand.pop_back();
779 mySketchState = NEXT_POINT;
781 MainWidget->GroupConstructors->setEnabled( true );
782 MainWidget->GroupDest1->setEnabled( true );
783 setEnabledUndo( true );
785 if ( myUndoCommand.count() == 1 )
786 setEnabledRedo( false );
788 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
791 //=================================================================================
792 // function : setEnabledUndo()
794 //=================================================================================
795 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
797 Group1Sel->buttonUndo->setEnabled( value );
798 Group1Spin->buttonUndo->setEnabled( value );
799 Group2Spin->buttonUndo->setEnabled( value );
800 Group3Spin->buttonUndo->setEnabled( value );
801 Group4Spin->buttonUndo->setEnabled( value );
804 //=================================================================================
805 // function : setEnabledRedo()
807 //=================================================================================
808 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
810 Group1Sel->buttonRedo->setEnabled( value );
811 Group1Spin->buttonRedo->setEnabled( value );
812 Group2Spin->buttonRedo->setEnabled( value );
813 Group3Spin->buttonRedo->setEnabled( value );
814 Group4Spin->buttonRedo->setEnabled( value );
817 //=================================================================================
818 // function : SelectionIntoArgument()
819 // purpose : Called when selection as changed
820 //=================================================================================
821 void EntityGUI_SketcherDlg::SelectionIntoArgument()
823 myEditCurrentArgument->setText( "" );
827 int nbSel = IObjectCount();
828 if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 ) {
829 Standard_Boolean aRes = Standard_False;
830 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
831 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
833 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
835 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
837 aTrans.SetTransformation( aWPlane );
838 BRepBuilderAPI_Transform aTransformation( aShape, aTrans, Standard_False );
839 aShape = aTransformation.Shape();
842 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
845 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
851 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
855 //=================================================================================
856 // function : SetEditCurrentArgument()
858 //=================================================================================
859 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
861 if ( sender() == Group1Sel->PushButton1 ) {
862 myEditCurrentArgument = Group1Sel->LineEdit1;
863 myEditCurrentArgument->setFocus();
865 SelectionIntoArgument();
869 //=================================================================================
870 // function : LineEditReturnPressed()
872 //=================================================================================
873 void EntityGUI_SketcherDlg::LineEditReturnPressed()
875 if ( sender() == Group1Sel->LineEdit1 ) {
876 myEditCurrentArgument = Group1Sel->LineEdit1;
878 /* User name of object input management */
879 /* If successfull the selection is changed and signal emitted... */
880 /* so SelectionIntoArgument() is automatically called. */
881 const QString objectUserName = myEditCurrentArgument->text();
882 QWidget* thisWidget = (QWidget*)this;
883 if ( GEOMBase::SelectionByNameInDialogs( thisWidget, objectUserName, selectedIO() ) )
884 myEditCurrentArgument->setText( objectUserName );
889 //=================================================================================
890 // function : DeactivateActiveDialog()
892 //=================================================================================
893 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
895 //myGeometryGUI->SetState( -1 );
899 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
900 myGeometryGUI->SetActiveDialogBox( 0 );
904 //=================================================================================
905 // function : ActivateThisDialog()
907 //=================================================================================
908 void EntityGUI_SketcherDlg::ActivateThisDialog()
910 myGeometryGUI->EmitSignalDeactivateDialog();
912 myGeometryGUI->SetActiveDialogBox( this );
914 connect( myGeometryGUI->getApp()->selectionMgr(),
915 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
917 //myGeometryGUI->SetState( 0 );
918 globalSelection( GEOM_POINT );
920 myEditCurrentArgument = Group1Sel->LineEdit1;
921 myEditCurrentArgument->setFocus();
923 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
927 //=================================================================================
928 // function : enterEvent [REDEFINED]
930 //=================================================================================
931 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
933 if ( !MainWidget->GroupConstructors->isEnabled() )
934 ActivateThisDialog();
938 //=================================================================================
939 // function : closeEvent()
941 //=================================================================================
942 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
944 //myGeometryGUI->SetState( -1 );
945 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
946 QDialog::closeEvent( e );
950 //=================================================================================
951 // function : ValueChangedInSpinBox()
953 //=================================================================================
954 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
956 QObject* send = (QObject*)sender();
957 Standard_Real vx, vy, vz, vs;
958 vx = vy = vz = vs = 0.0;
960 if ( send == Group1Spin->SpinBox_DX ) {
963 else if ( send == Group2Spin->SpinBox_DX ) {
965 vy = Group2Spin->SpinBox_DY->value();
967 else if ( send == Group2Spin->SpinBox_DY ) {
968 vx = Group2Spin->SpinBox_DX->value();
971 else if ( send == Group3Spin->SpinBox_DX ) {
973 vy = Group3Spin->SpinBox_DY->value();
974 vz = Group3Spin->SpinBox_DZ->value();
976 else if ( send == Group3Spin->SpinBox_DY ) {
977 vx = Group3Spin->SpinBox_DX->value();
979 vz = Group3Spin->SpinBox_DZ->value();
981 else if ( send == Group3Spin->SpinBox_DZ ) {
982 vx = Group3Spin->SpinBox_DX->value();
983 vy = Group3Spin->SpinBox_DY->value();
986 else if ( send == Group4Spin->SpinBox_DX ) {
988 vy = Group4Spin->SpinBox_DY->value();
989 vz = Group4Spin->SpinBox_DZ->value();
990 vs = Group4Spin->SpinBox_DS->value();
992 else if ( send == Group4Spin->SpinBox_DY ) {
993 vx = Group4Spin->SpinBox_DX->value();
995 vz = Group4Spin->SpinBox_DZ->value();
996 vs = Group4Spin->SpinBox_DS->value();
998 else if ( send == Group4Spin->SpinBox_DZ ) {
999 vx = Group4Spin->SpinBox_DX->value();
1000 vy = Group4Spin->SpinBox_DY->value();
1002 vs = Group4Spin->SpinBox_DS->value();
1004 else if ( send == Group4Spin->SpinBox_DS ) {
1005 vx = Group4Spin->SpinBox_DX->value();
1006 vy = Group4Spin->SpinBox_DY->value();
1007 vz = Group4Spin->SpinBox_DZ->value();
1010 // NPAL16010 (Sketcher Apply non available if only one line is modified)
1011 // if ValueChangedInSpinBox() called from eventFilter()
1012 else if ( Group1Spin->SpinBox_DX->hasFocus() ) {
1015 else if ( Group2Spin->SpinBox_DX ->hasFocus() ) {
1017 vy = Group2Spin->SpinBox_DY->value();
1019 else if ( Group2Spin->SpinBox_DY->hasFocus() ) {
1020 vx = Group2Spin->SpinBox_DX->value();
1023 else if ( Group3Spin->SpinBox_DX->hasFocus() ) {
1025 vy = Group3Spin->SpinBox_DY->value();
1026 vz = Group3Spin->SpinBox_DZ->value();
1028 else if ( Group3Spin->SpinBox_DY->hasFocus() ) {
1029 vx = Group3Spin->SpinBox_DX->value();
1031 vz = Group3Spin->SpinBox_DZ->value();
1033 else if ( Group3Spin->SpinBox_DZ->hasFocus() ) {
1034 vx = Group3Spin->SpinBox_DX->value();
1035 vy = Group3Spin->SpinBox_DY->value();
1038 else if ( Group4Spin->SpinBox_DX->hasFocus() ) {
1040 vy = Group4Spin->SpinBox_DY->value();
1041 vz = Group4Spin->SpinBox_DZ->value();
1042 vs = Group4Spin->SpinBox_DS->value();
1044 else if ( Group4Spin->SpinBox_DY->hasFocus() ) {
1045 vx = Group4Spin->SpinBox_DX->value();
1047 vz = Group4Spin->SpinBox_DZ->value();
1048 vs = Group4Spin->SpinBox_DS->value();
1050 else if ( Group4Spin->SpinBox_DZ->hasFocus() ) {
1051 vx = Group4Spin->SpinBox_DX->value();
1052 vy = Group4Spin->SpinBox_DY->value();
1054 vs = Group4Spin->SpinBox_DS->value();
1056 else if ( Group4Spin->SpinBox_DS->hasFocus() ) {
1057 vx = Group4Spin->SpinBox_DX->value();
1058 vy = Group4Spin->SpinBox_DY->value();
1059 vz = Group4Spin->SpinBox_DZ->value();
1063 if ( myConstructorId == 0 ) { // SEGMENT
1064 if ( mySketchType == PT_ABS ) {
1068 else if ( mySketchType == PT_RELATIVE ) {
1072 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1076 else if ( mySketchType == DIR_ANGLE_X ) {
1080 else if ( mySketchType == DIR_ANGLE_Y ) {
1084 else if ( mySketchType == DIR_PER_LENGTH ) {
1087 else if ( mySketchType == DIR_PER_X ) {
1090 else if ( mySketchType == DIR_PER_Y ) {
1093 else if ( mySketchType == DIR_TAN_LENGTH ) {
1096 else if ( mySketchType == DIR_TAN_X ) {
1099 else if ( mySketchType == DIR_TAN_Y ) {
1102 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1107 else if ( mySketchType == DIR_DXDY_X ) {
1112 else if ( mySketchType == DIR_DXDY_Y ) {
1118 else if ( myConstructorId == 1 ) { // ARC
1119 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1124 else if ( mySketchType == DIR_PER_LENGTH ) {
1128 else if ( mySketchType == DIR_TAN_LENGTH ) {
1132 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1140 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1144 //=================================================================================
1145 // function : GetNewCommand()
1146 // purpose : Build the new command with context
1147 //=================================================================================
1148 QString EntityGUI_SketcherDlg::GetNewCommand()
1150 QString myNewCommand = ":";
1151 if ( mySketchState == FIRST_POINT ) {
1152 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1153 myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1154 if ( mySketchType == PT_RELATIVE)
1155 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1156 return myNewCommand;
1159 if ( myConstructorId == 0 ) { // SEGMENT
1160 if ( mySketchType == PT_ABS || mySketchType == PT_SEL )
1161 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1162 if ( mySketchType == PT_RELATIVE)
1163 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1164 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1165 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1166 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1168 if ( mySketchType == DIR_ANGLE_X ) {
1169 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1170 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1172 if ( mySketchType == DIR_ANGLE_Y ) {
1173 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1174 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1176 if ( mySketchType == DIR_PER_LENGTH ) {
1177 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1178 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1180 if ( mySketchType == DIR_PER_X ) {
1181 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1182 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1184 if ( mySketchType == DIR_PER_Y ) {
1185 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1186 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1188 if ( mySketchType == DIR_TAN_LENGTH )
1189 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1190 if ( mySketchType == DIR_TAN_X )
1191 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1192 if ( mySketchType == DIR_TAN_Y)
1193 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1194 if ( mySketchType == DIR_DXDY_LENGTH ) {
1195 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1196 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1198 if ( mySketchType == DIR_DXDY_X ) {
1199 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1200 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1202 if ( mySketchType == DIR_DXDY_Y ) {
1203 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1204 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1207 else if ( myConstructorId == 1 ) { // ARC
1208 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1209 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1210 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1212 if ( mySketchType == DIR_PER_LENGTH ) {
1213 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1214 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1216 if ( mySketchType == DIR_TAN_LENGTH ) {
1217 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1219 if ( mySketchType == DIR_DXDY_LENGTH ) {
1220 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1221 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1224 return myNewCommand;
1227 //=================================================================================
1228 // function : createOperation
1230 //=================================================================================
1231 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1233 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1236 //=================================================================================
1237 // function : isValid
1239 //=================================================================================
1240 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1245 //=================================================================================
1246 // function : execute
1248 //=================================================================================
1249 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1251 if ( mySketchState == FIRST_POINT ) {
1256 //Test if the current point is the same as the last one
1257 TopoDS_Shape myShape1, myShape2;
1260 QString Command1 = myCommand.join( "" );
1261 Sketcher_Profile aProfile1( Command1.toAscii() );
1262 if ( aProfile1.IsDone() )
1263 myShape1 = aProfile1.GetShape();
1266 QString Command2 = Command1 + GetNewCommand();
1267 Sketcher_Profile aProfile2( Command2.toAscii() );
1268 if ( aProfile2.IsDone() )
1269 myShape2 = aProfile2.GetShape();
1271 if ( myShape2.IsNull() ) {
1272 //the current point is the same as the last one
1273 myLastX2 = myLastX1;
1274 myLastY2 = myLastY1;
1277 TopoDS_Vertex V1, V2;
1279 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1280 //the last shape is the first point
1281 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1286 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1287 pt = BRep_Tool::Pnt( V2 );
1291 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1292 pt = BRep_Tool::Pnt( V2 );
1299 if ( ( mySketchState != FIRST_POINT &&
1300 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1301 cmd = myCommand.join( "" );
1303 if ( Group1Sel->isVisible() ) {
1304 Group1Sel->buttonApply->setEnabled( false );
1305 //Group1Sel->buttonApply->setFocus();
1307 if ( Group1Spin->isVisible() ) {
1308 Group1Spin->buttonApply->setEnabled( false );
1309 //Group1Spin->buttonApply->setFocus();
1311 if ( Group2Spin->isVisible() ) {
1312 Group2Spin->buttonApply->setEnabled( false );
1313 //Group2Spin->buttonApply->setFocus();
1315 if ( Group3Spin->isVisible() ) {
1316 Group3Spin->buttonApply->setEnabled( false );
1317 //Group3Spin->buttonApply->setFocus();
1319 if ( Group4Spin->isVisible() ) {
1320 Group4Spin->buttonApply->setEnabled( false );
1321 //Group4Spin->buttonApply->setFocus();
1325 cmd = myCommand.join( "" ) + GetNewCommand();
1327 if ( Group1Sel->isVisible() ) {
1328 Group1Sel->buttonApply->setEnabled( true );
1329 //Group1Sel->buttonApply->setFocus();
1331 if ( Group1Spin->isVisible() ) {
1332 Group1Spin->buttonApply->setEnabled( true );
1333 //Group1Spin->buttonApply->setFocus();
1335 if ( Group2Spin->isVisible() ) {
1336 Group2Spin->buttonApply->setEnabled( true );
1337 //Group2Spin->buttonApply->setFocus();
1339 if ( Group3Spin->isVisible() ) {
1340 Group3Spin->buttonApply->setEnabled( true );
1341 //Group3Spin->buttonApply->setFocus();
1343 if ( Group4Spin->isVisible() ) {
1344 Group4Spin->buttonApply->setEnabled( true );
1345 //Group4Spin->buttonApply->setFocus();
1349 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1350 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1351 WPlane->length( 9 );
1352 WPlane[0] = myWPlane.Location().X();
1353 WPlane[1] = myWPlane.Location().Y();
1354 WPlane[2] = myWPlane.Location().Z();
1356 WPlane[3] = myWPlane.Direction().X();
1357 WPlane[4] = myWPlane.Direction().Y();
1358 WPlane[5] = myWPlane.Direction().Z();
1360 WPlane[6] = myWPlane.XDirection().X();
1361 WPlane[7] = myWPlane.XDirection().Y();
1362 WPlane[8] = myWPlane.XDirection().Z();
1364 GEOM::GEOM_Object_var anObj =
1365 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.toLatin1(), WPlane );
1367 if ( !anObj->_is_nil() )
1368 objects.push_back( anObj._retn() );
1373 //================================================================
1374 // Function : displayPreview
1375 // Purpose : Method for displaying preview of resulting shape
1376 // Redefined from GEOMBase_Helper.
1377 //================================================================
1378 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1380 const bool activate,
1382 const double lineWidth )
1384 // Set color for preview shape
1385 getDisplayer()->SetColor( Quantity_NOC_RED );
1387 // set width of displayed shape
1388 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1390 // Disable activation of selection
1391 getDisplayer()->SetToActivate( activate );
1393 // Make a reference to GEOM_Object
1394 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1395 getDisplayer()->SetName( objStr.in() );
1397 // Create wire from applayed object
1398 TopoDS_Shape anApplyedWire, aLastSegment;
1399 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1403 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1404 if ( aPrs != 0 && !aPrs->IsNull() )
1405 GEOMBase_Helper::displayPreview( aPrs, append, update );
1407 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1408 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1409 if ( aPrs != 0 && !aPrs->IsNull() )
1410 GEOMBase_Helper::displayPreview( aPrs, append, update );
1412 getDisplayer()->UnsetName();
1414 // Enable activation of displayed objects
1415 getDisplayer()->SetToActivate( true );
1418 //================================================================
1419 // Function : createShapes
1420 // Purpose : Create applyed wire, and last segment from entry object
1421 //================================================================
1422 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1423 TopoDS_Shape& theApplyedWire,
1424 TopoDS_Shape& theLastSegment )
1426 TopoDS_Shape aShape;
1427 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1428 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1431 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1432 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1433 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1434 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1435 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1436 theApplyedWire = aShape;
1440 BRepBuilderAPI_MakeWire aBuilder;
1441 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1443 TopoDS_Shape anEdge = anExp.Current();
1445 if ( anExp.More() ) // i.e. non-last edge
1446 aBuilder.Add( TopoDS::Edge( anEdge ) );
1448 theLastSegment = anEdge;
1453 if ( aBuilder.IsDone() )
1454 theApplyedWire = aBuilder.Shape();
1459 //=================================================================================
1460 // function : keyPressEvent()
1462 //=================================================================================
1463 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1465 QDialog::keyPressEvent( e );
1466 if ( e->isAccepted() )
1469 if ( e->key() == Qt::Key_F1 ) {
1475 void EntityGUI_SketcherDlg::initSpinBox( QDoubleSpinBox* spinBox,
1476 double min, double max,
1477 double step, int decimals )
1479 spinBox->setRange( min, max );
1480 spinBox->setSingleStep( step );
1481 spinBox->setDecimals( decimals );
1484 //=================================================================================
1485 // function : SetDoubleSpinBoxStep()
1486 // purpose : Double spin box management
1487 //=================================================================================
1488 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1490 Group1Spin->SpinBox_DX->setSingleStep(step);
1491 Group2Spin->SpinBox_DX->setSingleStep(step);
1492 Group2Spin->SpinBox_DY->setSingleStep(step);
1493 Group3Spin->SpinBox_DX->setSingleStep(step);
1494 Group3Spin->SpinBox_DY->setSingleStep(step);
1495 Group3Spin->SpinBox_DZ->setSingleStep(step);
1496 Group4Spin->SpinBox_DX->setSingleStep(step);
1497 Group4Spin->SpinBox_DY->setSingleStep(step);
1498 Group4Spin->SpinBox_DZ->setSingleStep(step);
1499 Group4Spin->SpinBox_DS->setSingleStep(step);