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>
33 #include <Geom_Surface.hxx>
34 #include <Geom_Plane.hxx>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Application.h>
41 #include <SalomeApp_Notebook.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
47 #include <BRep_Tool.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS_Vertex.hxx>
52 #include <BRepBuilderAPI_Transform.hxx>
53 #include <BRepBuilderAPI_MakeWire.hxx>
54 #include <Sketcher_Profile.hxx>
56 #include <SalomeApp_Study.h>
60 //=================================================================================
61 // class : EntityGUI_SketcherDlg()
62 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
63 // name 'name' and widget flags set to 'f'.
64 // The dialog will by default be modeless, unless you set 'modal' to
65 // TRUE to construct a modal dialog.
66 //=================================================================================
67 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
68 bool modal, Qt::WindowFlags fl,
69 const double lineWidth )
70 : QDialog( parent, fl ),
71 myIsAllAdded( false ),
73 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
75 myLineWidth( lineWidth )
78 setAttribute( Qt::WA_DeleteOnClose );
80 myGeometryGUI->SetActiveDialogBox(this);
82 MainWidget = new EntityGUI_Skeleton( this );
83 QVBoxLayout* topLayout = new QVBoxLayout( this );
84 topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
86 MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
87 MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
88 MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
89 MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
91 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
92 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
93 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
95 setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
97 MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
98 MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
99 MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
100 MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
101 MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
102 MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
103 MainWidget->RB_Dest2->setText( tr( "GEOM_SKETCHER_DIR" ) );
105 /***************************************************************/
107 GroupBox1 = new QGroupBox(tr("GEOM_CS"), this);
108 QGridLayout* OwnLayout = new QGridLayout(GroupBox1);
109 OwnLayout->setSpacing(6);
110 OwnLayout->setMargin(11);
112 ComboBox1 = new QComboBox(GroupBox1);
113 OwnLayout->addWidget(ComboBox1);
115 topLayout->addWidget(GroupBox1);
116 topLayout->addWidget( MainWidget );
118 GroupPt = new EntityGUI_Point( MainWidget->DestCnt );
120 GroupPt->GroupPoint->setTitle( tr( "GEOM_SKETCHER_POINT" ) );
121 GroupPt->RB_Point1->setText( tr( "GEOM_SKETCHER_ABS" ) );
122 GroupPt->RB_Point2->setText( tr( "GEOM_SKETCHER_REL" ) );
123 GroupPt->RB_Point3->setText( tr( "GEOM_SKETCHER_SEL" ) );
125 GroupD1 = new EntityGUI_Dir1( MainWidget->DestCnt );
127 GroupD1->GroupDir1->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
128 GroupD1->RB_Dir11->setText( tr( "GEOM_SKETCHER_ANGLE" ) );
129 GroupD1->RB_Dir12->setText( tr( "GEOM_SKETCHER_PER" ) );
130 GroupD1->RB_Dir13->setText( tr( "GEOM_SKETCHER_TAN" ) );
131 GroupD1->RB_Dir14->setText( tr( "GEOM_SKETCHER_VXVY" ) );
133 GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
135 GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
136 GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
137 GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
138 GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
140 Group1Sel = new EntityGUI_1Sel( MainWidget->SkeletonCnt );
142 Group1Sel->TextLabel1->setText( tr( "GEOM_SKETCHER_POINT2" ) );
143 Group1Sel->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
144 Group1Sel->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
145 Group1Sel->PushButton1->setIcon( image0 );
146 Group1Sel->buttonUndo->setIcon( image1 );
147 Group1Sel->buttonRedo->setIcon( image2 );
148 Group1Sel->LineEdit1->setReadOnly( true );
150 Group1Spin = new EntityGUI_1Spin( MainWidget->SkeletonCnt );
151 Group1Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
152 Group1Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
153 Group1Spin->buttonUndo->setIcon( image1 );
154 Group1Spin->buttonRedo->setIcon( image2 );
156 Group2Spin = new EntityGUI_2Spin( MainWidget->SkeletonCnt );
157 Group2Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
158 Group2Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
159 Group2Spin->buttonUndo->setIcon( image1 );
160 Group2Spin->buttonRedo->setIcon( image2 );
162 Group3Spin = new EntityGUI_3Spin( MainWidget->SkeletonCnt );
163 Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
164 Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
165 Group3Spin->buttonUndo->setIcon( image1 );
166 Group3Spin->buttonRedo->setIcon( image2 );
168 Group4Spin = new EntityGUI_4Spin( MainWidget->SkeletonCnt );
169 Group4Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
170 Group4Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
171 Group4Spin->buttonUndo->setIcon( image1 );
172 Group4Spin->buttonRedo->setIcon( image2 );
174 QGridLayout* DestCntLayout = new QGridLayout( MainWidget->DestCnt );
175 DestCntLayout->setMargin( 0 ); DestCntLayout->setSpacing( 6 );
176 DestCntLayout->addWidget( GroupPt, 0, 0, 1, 2 );
177 DestCntLayout->addWidget( GroupD1, 1, 0 );
178 DestCntLayout->addWidget( GroupD2, 1, 1 );
180 QVBoxLayout* SkeletonCntlayout = new QVBoxLayout( MainWidget->SkeletonCnt );
181 SkeletonCntlayout->setMargin( 0 ); SkeletonCntlayout->setSpacing( 6 );
182 SkeletonCntlayout->addWidget( Group1Sel, 0, 0 );
183 SkeletonCntlayout->addWidget( Group1Spin, 0, 0 );
184 SkeletonCntlayout->addWidget( Group2Spin, 0, 0 );
185 SkeletonCntlayout->addWidget( Group3Spin, 0, 0 );
186 SkeletonCntlayout->addWidget( Group4Spin, 0, 0 );
187 /***************************************************************/
189 QButtonGroup* ButtonGroup = new QButtonGroup( this );
190 ButtonGroup->addButton( MainWidget->RB_Dest1, 1 );
191 ButtonGroup->addButton( MainWidget->RB_Dest2, 0 );
193 /* signals and slots connections */
194 connect( MainWidget->buttonEnd, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
195 connect( MainWidget->buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnEnd() ) );
196 connect( MainWidget->buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
197 connect( MainWidget->buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
199 connect( Group1Sel->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
200 connect( Group1Sel->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
201 connect( Group1Sel->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
202 connect( Group1Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
203 connect( Group1Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
204 connect( Group1Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
205 connect( Group2Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
206 connect( Group2Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
207 connect( Group2Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
208 connect( Group3Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
209 connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
210 connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
211 connect( Group4Spin->buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
212 connect( Group4Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
213 connect( Group4Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) );
215 connect( MainWidget->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
216 connect( ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( DestClicked( int ) ) );
217 connect( GroupPt->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( PointClicked( int ) ) );
218 connect( GroupD1->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir1Clicked( int ) ) );
219 connect( GroupD2->ButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( Dir2Clicked( int ) ));
221 connect( Group1Sel->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
222 connect( Group1Sel->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
224 connect( Group1Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
225 connect( Group2Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
226 connect( Group2Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
227 connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
228 connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
229 connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
230 connect( Group4Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
231 connect( Group4Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
232 connect( Group4Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
233 connect( Group4Spin->SpinBox_DS, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
235 connect( ComboBox1, SIGNAL( activated( int ) ), this, SLOT( SelectionIntoArgument() ) );
237 connect( myGeometryGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
239 connect( myGeometryGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
240 connect( myGeometryGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
242 // install event filter on spin-boxes to provide Apply action on Return pressed
243 Group1Spin->SpinBox_DX->installEventFilter(this);
244 Group2Spin->SpinBox_DX->installEventFilter(this);
245 Group2Spin->SpinBox_DY->installEventFilter(this);
246 Group3Spin->SpinBox_DX->installEventFilter(this);
247 Group3Spin->SpinBox_DY->installEventFilter(this);
248 Group3Spin->SpinBox_DZ->installEventFilter(this);
249 Group4Spin->SpinBox_DX->installEventFilter(this);
250 Group4Spin->SpinBox_DY->installEventFilter(this);
251 Group4Spin->SpinBox_DZ->installEventFilter(this);
252 Group4Spin->SpinBox_DS->installEventFilter(this);
258 //=================================================================================
259 // function : ~EntityGUI_SketcherDlg()
260 // purpose : Destroys the object and frees any allocated resources
261 //=================================================================================
262 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
264 myGeometryGUI->SetActiveDialogBox( 0 );
268 //=================================================================================
269 // function : eventFilter()
270 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
271 //=================================================================================
272 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
274 if (event->type() == QEvent::KeyPress) {
275 QKeyEvent* ke = (QKeyEvent*)event;
276 if (ke->key() == Qt::Key_Return) {
277 if (object == Group1Spin->SpinBox_DX) {
278 Group1Spin->buttonApply->animateClick();
280 } else if (object == Group2Spin->SpinBox_DX ||
281 object == Group2Spin->SpinBox_DY) {
282 Group2Spin->buttonApply->animateClick();
284 } else if (object == Group3Spin->SpinBox_DX ||
285 object == Group3Spin->SpinBox_DY ||
286 object == Group3Spin->SpinBox_DZ) {
287 Group3Spin->buttonApply->animateClick();
289 } else if (object == Group4Spin->SpinBox_DX ||
290 object == Group4Spin->SpinBox_DY ||
291 object == Group4Spin->SpinBox_DZ ||
292 object == Group4Spin->SpinBox_DS) {
293 Group4Spin->buttonApply->animateClick();
299 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
301 return QDialog::eventFilter(object, event);
305 //=================================================================================
308 //=================================================================================
309 void EntityGUI_SketcherDlg::Init()
312 myEditCurrentArgument = Group1Sel->LineEdit1;
313 myCommand.append( "Sketcher" );
314 myUndoCommand.append( "Sketcher" );
316 mySketchState = FIRST_POINT;
317 globalSelection( GEOM_POINT );
324 myHelpFileName = "create_sketcher_page.html";
326 /* Get setting of step value from file configuration */
327 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
329 /* min, max, step and decimals for spin boxes */
330 initSpinBox( Group1Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
331 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
332 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
333 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
334 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
335 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
336 initSpinBox( Group4Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
337 initSpinBox( Group4Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
338 initSpinBox( Group4Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
339 initSpinBox( Group4Spin->SpinBox_DS, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
341 /* displays Dialog */
342 MainWidget->GroupConstructors->setEnabled( false );
343 MainWidget->GroupDest1->setEnabled( false );
344 setEnabledUndo( false );
345 setEnabledRedo( false );
347 MainWidget->RadioButton1->setChecked( true );
354 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
358 //=================================================================================
359 // function : InitClick()
361 //=================================================================================
362 void EntityGUI_SketcherDlg::InitClick()
364 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
376 //=================================================================================
377 // function : TypeClicked()
378 // purpose : Radio button management
379 //=================================================================================
380 void EntityGUI_SketcherDlg::TypeClicked( int constructorId )
382 myConstructorId = constructorId;
383 if ( myConstructorId == 0 ) { // SEGMENT
384 GroupD2->setEnabled( true );
385 MainWidget->RB_Dest1->setEnabled( true );
386 MainWidget->RB_Dest1->setChecked( true );
389 else if ( myConstructorId == 1 ) { // ARC
390 GroupD2->setEnabled( false );
391 MainWidget->RB_Dest1->setEnabled( false );
392 MainWidget->RB_Dest2->setChecked( true );
398 //=================================================================================
399 // function : DestClicked()
400 // purpose : Radio button management
401 //=================================================================================
402 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
408 if ( constructorId == 1 ) {
410 GroupPt->RB_Point1->setChecked( true );
412 PointClicked( 1 ); // XY
414 else if ( constructorId == 0 ) {
416 GroupD1->RB_Dir11->setChecked( true );
419 Dir1Clicked( 2 ); // Angle
424 //=================================================================================
425 // function : PointClicked()
426 // purpose : Radio button management
427 //=================================================================================
428 void EntityGUI_SketcherDlg::PointClicked( int constructorId )
432 // Get setting of step value from file configuration
433 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
435 if ( myConstructorId == 0 ) { // SEGMENT
436 if ( constructorId == 1 ) { // XY
437 mySketchType = PT_ABS;
438 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
439 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
440 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
441 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
443 Group2Spin->SpinBox_DX->setValue( myX );
445 Group2Spin->SpinBox_DY->setValue( myY );
447 Group2Spin->buttonApply->setFocus();
449 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
451 else if ( constructorId == 0 ) { // DXDY
452 mySketchType = PT_RELATIVE;
453 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
454 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
455 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
456 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
458 Group2Spin->SpinBox_DX->setValue( myDX );
460 Group2Spin->SpinBox_DY->setValue( myDY );
462 Group2Spin->buttonApply->setFocus();
464 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
466 else if ( constructorId == 2 ) { // Selection
467 mySketchType = PT_SEL;
468 myEditCurrentArgument = Group1Sel->LineEdit1;
469 connect( myGeometryGUI->getApp()->selectionMgr(),
470 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
472 Group1Sel->buttonApply->setFocus();
473 SelectionIntoArgument();
479 //=================================================================================
480 // function : Dir1Clicked()
481 // purpose : Radio button management
482 //=================================================================================
483 void EntityGUI_SketcherDlg::Dir1Clicked( int constructorId )
485 myConstructorDirId = constructorId;
486 GroupD2->RB_Dir21->setChecked( true );
491 //=================================================================================
492 // function : Dir2Clicked()
493 // purpose : Radio button management
494 //=================================================================================
495 void EntityGUI_SketcherDlg::Dir2Clicked( int constructorId )
500 // Get setting of step value from file configuration
501 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
503 if ( myConstructorId == 0 ) { // SEGMENT
507 if ( myConstructorDirId == 2 ) { // Angle
508 initSpinBox( Group2Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
509 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
510 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
511 Group2Spin->SpinBox_DX->setValue( myAngle );
512 Group2Spin->buttonApply->setFocus();
515 if ( constructorId == 2 ) { // Length
516 mySketchType = DIR_ANGLE_LENGTH;
517 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
518 Group2Spin->SpinBox_DY->setValue( myLength );
520 else if ( constructorId == 0 ) { // X
521 mySketchType = DIR_ANGLE_X;
522 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_X3" ) );
523 Group2Spin->SpinBox_DY->setValue( myX );
525 else if ( constructorId == 1 ) { // Y
526 mySketchType = DIR_ANGLE_Y;
527 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y3" ) );
528 Group2Spin->SpinBox_DY->setValue( myY );
531 else if ( myConstructorDirId == 0 ) { // Perpendicular
533 Group1Spin->buttonApply->setFocus();
535 if ( constructorId == 2 ) { // Length
536 mySketchType = DIR_PER_LENGTH;
537 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
538 Group1Spin->SpinBox_DX->setValue( myLength );
540 else if ( constructorId == 0 ) { // X
541 mySketchType = DIR_PER_X;
542 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
543 Group1Spin->SpinBox_DX->setValue( myX );
545 else if ( constructorId == 1 ) { // Y
546 mySketchType = DIR_PER_Y;
547 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
548 Group1Spin->SpinBox_DX->setValue( myY );
551 else if ( myConstructorDirId == 1 ) { // Tangent
553 Group1Spin->buttonApply->setFocus();
555 if ( constructorId == 2 ) { // Length
556 mySketchType = DIR_TAN_LENGTH;
557 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
558 Group1Spin->SpinBox_DX->setValue( myLength );
560 else if ( constructorId == 0 ) { // X
561 mySketchType = DIR_TAN_X;
562 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X3" ) );
563 Group1Spin->SpinBox_DX->setValue( myX );
565 else if ( constructorId == 1 ) { // Y
566 mySketchType = DIR_TAN_Y;
567 Group1Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_Y3" ) );
568 Group1Spin->SpinBox_DX->setValue( myY );
571 else if ( myConstructorDirId == 3 ) { // DXDY
572 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
573 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 0.1, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
574 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
575 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
576 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
578 Group3Spin->SpinBox_DX->setValue( myDX );
580 Group3Spin->SpinBox_DY->setValue( myDY );
582 Group3Spin->buttonApply->setFocus();
584 if ( constructorId == 2 ) { // Length
585 mySketchType = DIR_DXDY_LENGTH;
586 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_LENGTH2" ) );
587 Group3Spin->SpinBox_DZ->setValue( myLength );
589 else if ( constructorId == 0 ) { // X
590 mySketchType = DIR_DXDY_X;
591 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_X3" ) );
592 Group3Spin->SpinBox_DZ->setValue( myX );
594 else if ( constructorId == 1 ) { // Y
595 mySketchType = DIR_DXDY_Y;
596 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Y3" ) );
597 Group3Spin->SpinBox_DZ->setValue( myY );
601 else if ( myConstructorId == 1 ) { // ARC
602 if ( myConstructorDirId == 2 ) { // Angle
603 if ( constructorId == 2 ) { // Length
604 mySketchType = DIR_ANGLE_LENGTH;
605 initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
606 initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
607 initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
608 Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
609 Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
610 Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_ANGLE2" ));
611 Group3Spin->SpinBox_DX->setValue( myAngle );
613 Group3Spin->SpinBox_DY->setValue( myRadius );
615 Group3Spin->SpinBox_DZ->setValue( myLength );
617 Group3Spin->buttonApply->setFocus();
620 else if ( myConstructorDirId == 0 ) { // Perpendicular
621 if ( constructorId == 2 ) { // Length
622 mySketchType = DIR_PER_LENGTH;
623 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
624 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
625 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
626 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
628 Group2Spin->SpinBox_DX->setValue( myRadius );
630 Group2Spin->SpinBox_DY->setValue( myLength );
632 Group2Spin->buttonApply->setFocus();
635 else if ( myConstructorDirId == 1 ) { // Tangent
636 if ( constructorId == 2 ) { // Length
637 mySketchType = DIR_TAN_LENGTH;
638 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
639 initSpinBox( Group2Spin->SpinBox_DY, COORD_MIN, COORD_MAX, 5., 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
640 Group2Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
641 Group2Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
643 Group2Spin->SpinBox_DX->setValue( myRadius );
645 Group2Spin->SpinBox_DY->setValue( myLength );
647 Group2Spin->buttonApply->setFocus();
650 else if ( myConstructorDirId == 3 ) { // DXDY
651 if ( constructorId == 2 ) { // Length
652 mySketchType = DIR_DXDY_LENGTH;
653 Group4Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_VX2" ) );
654 Group4Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_VY2" ) );
655 Group4Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_RADIUS2" ) );
656 Group4Spin->TextLabel4->setText( tr( "GEOM_SKETCHER_ANGLE2" ) );
658 Group4Spin->SpinBox_DX->setValue( myDX );
660 Group4Spin->SpinBox_DY->setValue( myDY );
662 Group4Spin->SpinBox_DZ->setValue( myRadius );
664 Group4Spin->SpinBox_DS->setValue( myLength );
666 Group4Spin->buttonApply->setFocus();
671 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
675 //=================================================================================
676 // function : ClickOnCancel()
678 //=================================================================================
679 void EntityGUI_SketcherDlg::ClickOnCancel()
685 //=================================================================================
686 // function : ClickOnEnd()
687 // purpose : connected to buttonEnd AND buttonClose
688 //=================================================================================
689 void EntityGUI_SketcherDlg::ClickOnEnd()
691 if ( sender() == MainWidget->buttonClose ) {
692 // Verify validity of commands
693 if ( myCommand.count() <= 2 ) {
694 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
695 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
700 QString Command = myCommand.join( "" ) + GetNewCommand( Parameters );
701 Sketcher_Profile aProfile( Command.toAscii() );
703 Command = myCommand.join( "" );
704 aProfile = Sketcher_Profile( Command.toAscii() );
705 TopoDS_Shape myShape;
706 if ( aProfile.IsDone() )
707 myShape = aProfile.GetShape();
709 if ( myShape.ShapeType() != TopAbs_VERTEX )
710 myCommand.append( ":WW" );
713 // PAL16008 (Sketcher Validation should be equal to Apply&Close)
714 if ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ||
715 Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ||
716 Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ||
717 Group4Spin->buttonApply->isEnabled() && Group4Spin->isVisible() ||
718 Group1Sel ->buttonApply->isEnabled() && Group1Sel->isVisible() ) {
724 if ( myCommand.size() > 2 )
731 //=================================================================================
732 // function : ClickOnApply()
734 //=================================================================================
735 bool EntityGUI_SketcherDlg::ClickOnApply()
737 if ( sender() && sender()->inherits( "QPushButton" ) )
738 ( (QPushButton*)sender() )->setFocus(); // to update value of currently edited spin-box (PAL11948)
741 myCommand.append( GetNewCommand( aParameters ) );
742 mySketchState = NEXT_POINT;
744 myUndoCommand.clear();
745 myUndoCommand.append( "Sketcher" );
747 myParameters.append( aParameters );
748 myUndoParameters.clear();
750 MainWidget->GroupConstructors->setEnabled( true );
751 MainWidget->GroupDest1->setEnabled( true );
752 setEnabledUndo( true );
753 setEnabledRedo( false );
756 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
759 // Set focus to SpinBox_DX
760 if ( sender() == Group1Spin->buttonApply ) {
761 (Group1Spin->SpinBox_DX)->setFocus();
762 (Group1Spin->SpinBox_DX)->selectAll();
764 else if ( sender() == Group2Spin->buttonApply ) {
765 (Group2Spin->SpinBox_DX)->setFocus();
766 (Group2Spin->SpinBox_DX)->selectAll();
768 else if ( sender() == Group3Spin->buttonApply ) {
769 (Group3Spin->SpinBox_DX)->setFocus();
770 (Group3Spin->SpinBox_DX)->selectAll();
772 else if ( sender() == Group4Spin->buttonApply ) {
773 (Group4Spin->SpinBox_DX)->setFocus();
774 (Group4Spin->SpinBox_DX)->selectAll();
780 //=================================================================================
781 // function : ClickOnHelp()
783 //=================================================================================
784 void EntityGUI_SketcherDlg::ClickOnHelp()
786 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
788 app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), myHelpFileName );
792 platform = "winapplication";
794 platform = "application";
797 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
798 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
799 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( myHelpFileName ),
800 QObject::tr( "BUT_OK" ) );
804 //=================================================================================
805 // function : ClickOnUndo()
807 //=================================================================================
808 void EntityGUI_SketcherDlg::ClickOnUndo()
810 myUndoCommand.append( myCommand.last() );
811 myCommand.pop_back();
813 myUndoParameters.append( myParameters.last() );
814 myParameters.pop_back();
816 if ( myCommand.count() == 1 ) {
817 mySketchState = FIRST_POINT;
819 MainWidget->RadioButton1->setChecked( true );
822 MainWidget->GroupConstructors->setEnabled( false );
823 MainWidget->GroupDest1->setEnabled( false );
824 setEnabledUndo( false );
827 setEnabledRedo( true );
829 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
832 //=================================================================================
833 // function : ClickOnRedo()
835 //=================================================================================
836 void EntityGUI_SketcherDlg::ClickOnRedo()
838 myCommand.append( myUndoCommand.last() );
839 myUndoCommand.pop_back();
841 myParameters.append( myUndoParameters.last() );
842 myUndoParameters.pop_back();
844 mySketchState = NEXT_POINT;
846 MainWidget->GroupConstructors->setEnabled( true );
847 MainWidget->GroupDest1->setEnabled( true );
848 setEnabledUndo( true );
850 if ( myUndoCommand.count() == 1 )
851 setEnabledRedo( false );
853 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
856 //=================================================================================
857 // function : setEnabledUndo()
859 //=================================================================================
860 void EntityGUI_SketcherDlg::setEnabledUndo( bool value )
862 Group1Sel->buttonUndo->setEnabled( value );
863 Group1Spin->buttonUndo->setEnabled( value );
864 Group2Spin->buttonUndo->setEnabled( value );
865 Group3Spin->buttonUndo->setEnabled( value );
866 Group4Spin->buttonUndo->setEnabled( value );
869 //=================================================================================
870 // function : setEnabledRedo()
872 //=================================================================================
873 void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
875 Group1Sel->buttonRedo->setEnabled( value );
876 Group1Spin->buttonRedo->setEnabled( value );
877 Group2Spin->buttonRedo->setEnabled( value );
878 Group3Spin->buttonRedo->setEnabled( value );
879 Group4Spin->buttonRedo->setEnabled( value );
882 //=================================================================================
883 // function : SelectionIntoArgument()
884 // purpose : Called when selection as changed
885 //=================================================================================
886 void EntityGUI_SketcherDlg::SelectionIntoArgument()
888 myEditCurrentArgument->setText( "" );
892 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
893 SALOME_ListIO aSelList;
894 aSelMgr->selectedObjects(aSelList);
896 int nbSel = aSelList.Extent();
897 if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
898 Standard_Boolean aRes = Standard_False;
899 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
900 if (!CORBA::is_nil(aSelectedObject) && aRes) {
902 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX)) {
904 gp_Ax3 aWPlane = GetActiveLocalCS();
906 aTrans.SetTransformation(aWPlane);
907 BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
908 aShape = aTransformation.Shape();
911 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
914 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
920 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
924 //=================================================================================
925 // function : SetEditCurrentArgument()
927 //=================================================================================
928 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
930 if ( sender() == Group1Sel->PushButton1 ) {
931 myEditCurrentArgument = Group1Sel->LineEdit1;
932 myEditCurrentArgument->setFocus();
934 SelectionIntoArgument();
938 //=================================================================================
939 // function : LineEditReturnPressed()
941 //=================================================================================
942 void EntityGUI_SketcherDlg::LineEditReturnPressed()
944 if ( sender() == Group1Sel->LineEdit1 ) {
945 myEditCurrentArgument = Group1Sel->LineEdit1;
947 /* User name of object input management */
948 /* If successfull the selection is changed and signal emitted... */
949 /* so SelectionIntoArgument() is automatically called. */
950 const QString objectUserName = myEditCurrentArgument->text();
951 QWidget* thisWidget = (QWidget*)this;
953 LightApp_SelectionMgr* aSelMgr = myGeometryGUI->getApp()->selectionMgr();
954 SALOME_ListIO aSelList;
955 aSelMgr->selectedObjects(aSelList);
957 if (GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, aSelList))
958 myEditCurrentArgument->setText( objectUserName );
963 //=================================================================================
964 // function : DeactivateActiveDialog()
966 //=================================================================================
967 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
969 //myGeometryGUI->SetState( -1 );
973 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
974 myGeometryGUI->SetActiveDialogBox( 0 );
978 //=================================================================================
979 // function : ActivateThisDialog()
981 //=================================================================================
982 void EntityGUI_SketcherDlg::ActivateThisDialog()
984 myGeometryGUI->EmitSignalDeactivateDialog();
986 myGeometryGUI->SetActiveDialogBox( this );
988 connect( myGeometryGUI->getApp()->selectionMgr(),
989 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
991 //myGeometryGUI->SetState( 0 );
992 globalSelection( GEOM_POINT );
994 myEditCurrentArgument = Group1Sel->LineEdit1;
995 myEditCurrentArgument->setFocus();
997 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1001 //=================================================================================
1002 // function : enterEvent [REDEFINED]
1004 //=================================================================================
1005 void EntityGUI_SketcherDlg::enterEvent( QEvent* )
1007 if ( !MainWidget->GroupConstructors->isEnabled() )
1008 ActivateThisDialog();
1012 //=================================================================================
1013 // function : closeEvent()
1015 //=================================================================================
1016 void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
1018 //myGeometryGUI->SetState( -1 );
1019 disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
1020 myGeometryGUI->getApp()->updateActions();
1021 QDialog::closeEvent( e );
1025 //=================================================================================
1026 // function : ValueChangedInSpinBox()
1028 //=================================================================================
1029 void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
1031 QObject* send = (QObject*)sender();
1032 Standard_Real vx, vy, vz, vs;
1033 vx = vy = vz = vs = 0.0;
1035 QString vxStr, vyStr, vzStr, vsStr;
1037 QString newValueStr;
1038 if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = (SalomeApp_DoubleSpinBox*)send )
1039 newValueStr = aDoubleSpinBox->text();
1041 if ( send == Group1Spin->SpinBox_DX ) {
1042 vx = newValue; vxStr = newValueStr;
1044 else if ( send == Group2Spin->SpinBox_DX ) {
1045 vx = newValue; vxStr = newValueStr;
1046 vy = Group2Spin->SpinBox_DY->value(); vyStr = Group2Spin->SpinBox_DY->text();
1048 else if ( send == Group2Spin->SpinBox_DY ) {
1049 vx = Group2Spin->SpinBox_DX->value(); vxStr = Group2Spin->SpinBox_DX->text();
1050 vy = newValue; vyStr = newValueStr;
1052 else if ( send == Group3Spin->SpinBox_DX ) {
1053 vx = newValue; vxStr = newValueStr;
1054 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1055 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1057 else if ( send == Group3Spin->SpinBox_DY ) {
1058 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1059 vy = newValue; vyStr = newValueStr;
1060 vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
1062 else if ( send == Group3Spin->SpinBox_DZ ) {
1063 vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
1064 vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
1065 vz = newValue; vzStr = newValueStr;
1067 else if ( send == Group4Spin->SpinBox_DX ) {
1068 vx = newValue; vxStr = newValueStr;
1069 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1070 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1071 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1073 else if ( send == Group4Spin->SpinBox_DY ) {
1074 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1075 vy = newValue; vyStr = newValueStr;
1076 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1077 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1079 else if ( send == Group4Spin->SpinBox_DZ ) {
1080 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1081 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1082 vz = newValue; vzStr = newValueStr;
1083 vs = Group4Spin->SpinBox_DS->value(); vsStr = Group4Spin->SpinBox_DS->text();
1085 else if ( send == Group4Spin->SpinBox_DS ) {
1086 vx = Group4Spin->SpinBox_DX->value(); vxStr = Group4Spin->SpinBox_DX->text();
1087 vy = Group4Spin->SpinBox_DY->value(); vyStr = Group4Spin->SpinBox_DY->text();
1088 vz = Group4Spin->SpinBox_DZ->value(); vzStr = Group4Spin->SpinBox_DZ->text();
1089 vs = newValue; vsStr = newValueStr;
1091 // Fix of the NPAL16010 bug is removed, because it's not actual with the Qt-4.x
1093 if ( myConstructorId == 0 ) { // SEGMENT
1094 if ( mySketchType == PT_ABS ) {
1100 else if ( mySketchType == PT_RELATIVE ) {
1106 else if ( mySketchType == DIR_ANGLE_LENGTH ) {
1110 myLengthStr = vyStr;
1112 else if ( mySketchType == DIR_ANGLE_X ) {
1118 else if ( mySketchType == DIR_ANGLE_Y ) {
1124 else if ( mySketchType == DIR_PER_LENGTH ) {
1126 myLengthStr = vxStr;
1128 else if ( mySketchType == DIR_PER_X ) {
1132 else if ( mySketchType == DIR_PER_Y ) {
1136 else if ( mySketchType == DIR_TAN_LENGTH ) {
1138 myLengthStr = vxStr;
1140 else if ( mySketchType == DIR_TAN_X ) {
1144 else if ( mySketchType == DIR_TAN_Y ) {
1148 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1154 myLengthStr = vzStr;
1156 else if ( mySketchType == DIR_DXDY_X ) {
1164 else if ( mySketchType == DIR_DXDY_Y ) {
1173 else if ( myConstructorId == 1 ) { // ARC
1174 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1179 myRadiusStr = vyStr;
1180 myLengthStr = vzStr;
1182 else if ( mySketchType == DIR_PER_LENGTH ) {
1185 myRadiusStr = vxStr;
1186 myLengthStr = vyStr;
1188 else if ( mySketchType == DIR_TAN_LENGTH ) {
1191 myRadiusStr = vxStr;
1192 myLengthStr = vyStr;
1194 else if ( mySketchType == DIR_DXDY_LENGTH ) {
1201 myRadiusStr = vzStr;
1202 myLengthStr = vsStr;
1206 GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
1210 //=================================================================================
1211 // function : GetNewCommand()
1212 // purpose : Build the new command with context
1213 //=================================================================================
1214 QString EntityGUI_SketcherDlg::GetNewCommand( QString& theParameters )
1216 theParameters.clear();
1217 QString myNewCommand = ":";
1218 if ( mySketchState == FIRST_POINT ) {
1219 if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1220 myNewCommand = myNewCommand + "F " + QString::number( myX ) + " " + QString::number( myY );
1221 theParameters = myXStr + ":" + myYStr;
1223 if ( mySketchType == PT_RELATIVE) {
1224 myNewCommand = myNewCommand + "F " + QString::number( myDX ) + " " + QString::number( myDY );
1225 theParameters = myDXStr + ":" + myDYStr;
1227 return myNewCommand;
1230 if ( myConstructorId == 0 ) { // SEGMENT
1231 if ( mySketchType == PT_ABS || mySketchType == PT_SEL ) {
1232 myNewCommand = myNewCommand + "TT " + QString::number( myX ) + " " + QString::number( myY );
1233 theParameters = myXStr + ":" + myYStr;
1235 if ( mySketchType == PT_RELATIVE) {
1236 myNewCommand = myNewCommand + "T " + QString::number( myDX ) + " " + QString::number( myDY );
1237 theParameters = myDXStr + ":" + myDYStr;
1239 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1240 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1241 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1242 theParameters = myAngleStr + ":" + myLengthStr;
1244 if ( mySketchType == DIR_ANGLE_X ) {
1245 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1246 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1247 theParameters = myAngleStr + ":" + myXStr;
1249 if ( mySketchType == DIR_ANGLE_Y ) {
1250 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1251 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1252 theParameters = myAngleStr + ":" + myYStr;
1254 if ( mySketchType == DIR_PER_LENGTH ) {
1255 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1256 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1257 theParameters = QString::number( 90.0 ) + ":" + myLengthStr;
1259 if ( mySketchType == DIR_PER_X ) {
1260 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1261 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1262 theParameters = QString::number( 90.0 ) + ":" + myXStr;
1264 if ( mySketchType == DIR_PER_Y ) {
1265 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1266 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1267 theParameters = QString::number( 90.0 ) + ":" + myYStr;
1269 if ( mySketchType == DIR_TAN_LENGTH ) {
1270 myNewCommand = myNewCommand + "L " + QString::number( myLength );
1271 theParameters = myLengthStr;
1273 if ( mySketchType == DIR_TAN_X ) {
1274 myNewCommand = myNewCommand + "IX " + QString::number( myX );
1275 theParameters = myXStr;
1277 if ( mySketchType == DIR_TAN_Y) {
1278 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1279 theParameters = myYStr;
1281 if ( mySketchType == DIR_DXDY_LENGTH ) {
1282 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1283 myNewCommand = myNewCommand + ":" + "L " + QString::number( myLength );
1284 theParameters = myDXStr + ":" + myDYStr + ":" + myLengthStr;
1286 if ( mySketchType == DIR_DXDY_X ) {
1287 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1288 myNewCommand = myNewCommand + ":" + "IX " + QString::number( myX );
1289 theParameters = myDXStr + ":" + myDYStr + ":" + myXStr;
1291 if ( mySketchType == DIR_DXDY_Y ) {
1292 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1293 myNewCommand = myNewCommand + ":" + "IY " + QString::number( myY );
1294 theParameters = myDXStr + ":" + myDYStr + ":" + myYStr;
1297 else if ( myConstructorId == 1 ) { // ARC
1298 if ( mySketchType == DIR_ANGLE_LENGTH ) {
1299 myNewCommand = myNewCommand + "R " + QString::number( myAngle );
1300 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1301 theParameters = myAngleStr + ":" + myRadiusStr + ":" + myLengthStr;
1303 if ( mySketchType == DIR_PER_LENGTH ) {
1304 myNewCommand = myNewCommand + "R " + QString::number( 90.0 );
1305 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1306 theParameters = QString::number( 90.0 ) + ":" + myRadiusStr + ":" + myLengthStr;
1308 if ( mySketchType == DIR_TAN_LENGTH ) {
1309 myNewCommand = myNewCommand + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1310 theParameters = myRadiusStr + ":" + myLengthStr;
1312 if ( mySketchType == DIR_DXDY_LENGTH ) {
1313 myNewCommand = myNewCommand + "D " + QString::number( myDX ) + " " + QString::number( myDY );
1314 myNewCommand = myNewCommand + ":" + "C " + QString::number( myRadius ) + " " + QString::number( myLength );
1315 theParameters = myDXStr + ":" + myDYStr + ":" + myRadiusStr + ":" + myLengthStr;
1318 return myNewCommand;
1321 //=================================================================================
1322 // function : createOperation
1324 //=================================================================================
1325 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1327 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1330 //=================================================================================
1331 // function : isValid
1333 //=================================================================================
1334 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1337 bool toCorrect = !IsPreview() || myIsApply;
1339 if( Group1Spin->isVisible() ) {
1340 ok = Group1Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1342 else if( Group2Spin->isVisible() ) {
1343 ok = Group2Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1344 ok = Group2Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1346 else if( Group3Spin->isVisible() ) {
1347 ok = Group3Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1348 ok = Group3Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1349 ok = Group3Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1351 else if( Group4Spin->isVisible() ) {
1352 ok = Group4Spin->SpinBox_DX->isValid( msg, toCorrect ) && ok;
1353 ok = Group4Spin->SpinBox_DY->isValid( msg, toCorrect ) && ok;
1354 ok = Group4Spin->SpinBox_DZ->isValid( msg, toCorrect ) && ok;
1355 ok = Group4Spin->SpinBox_DS->isValid( msg, toCorrect ) && ok;
1358 if( myIsApply && !ok )
1364 //=================================================================================
1365 // function : execute
1367 //=================================================================================
1368 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1370 QString aParameters;
1372 if ( mySketchState == FIRST_POINT ) {
1377 //Test if the current point is the same as the last one
1378 TopoDS_Shape myShape1, myShape2;
1381 QString Command1 = myCommand.join( "" );
1382 Sketcher_Profile aProfile1( Command1.toAscii() );
1383 if ( aProfile1.IsDone() )
1384 myShape1 = aProfile1.GetShape();
1387 QString Command2 = Command1 + GetNewCommand( aParameters );
1388 Sketcher_Profile aProfile2( Command2.toAscii() );
1389 if ( aProfile2.IsDone() )
1390 myShape2 = aProfile2.GetShape();
1392 if ( myShape2.IsNull() ) {
1393 //the current point is the same as the last one
1394 myLastX2 = myLastX1;
1395 myLastY2 = myLastY1;
1398 TopoDS_Vertex V1, V2;
1400 if ( myShape1.ShapeType() == TopAbs_VERTEX ) {
1401 //the last shape is the first point
1402 pt = BRep_Tool::Pnt( TopoDS::Vertex( myShape1 ) );
1407 TopExp::Vertices( TopoDS::Wire( myShape1 ), V1, V2 );
1408 pt = BRep_Tool::Pnt( V2 );
1412 TopExp::Vertices( TopoDS::Wire( myShape2 ), V1, V2 );
1413 pt = BRep_Tool::Pnt( V2 );
1420 if ( ( mySketchState != FIRST_POINT &&
1421 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1422 cmd = myCommand.join( "" );
1424 if ( Group1Sel->isVisible() ) {
1425 Group1Sel->buttonApply->setEnabled( false );
1426 //Group1Sel->buttonApply->setFocus();
1428 if ( Group1Spin->isVisible() ) {
1429 Group1Spin->buttonApply->setEnabled( false );
1430 //Group1Spin->buttonApply->setFocus();
1432 if ( Group2Spin->isVisible() ) {
1433 Group2Spin->buttonApply->setEnabled( false );
1434 //Group2Spin->buttonApply->setFocus();
1436 if ( Group3Spin->isVisible() ) {
1437 Group3Spin->buttonApply->setEnabled( false );
1438 //Group3Spin->buttonApply->setFocus();
1440 if ( Group4Spin->isVisible() ) {
1441 Group4Spin->buttonApply->setEnabled( false );
1442 //Group4Spin->buttonApply->setFocus();
1446 cmd = myCommand.join( "" ) + GetNewCommand( aParameters );
1448 if ( Group1Sel->isVisible() ) {
1449 Group1Sel->buttonApply->setEnabled( true );
1450 //Group1Sel->buttonApply->setFocus();
1452 if ( Group1Spin->isVisible() ) {
1453 Group1Spin->buttonApply->setEnabled( true );
1454 //Group1Spin->buttonApply->setFocus();
1456 if ( Group2Spin->isVisible() ) {
1457 Group2Spin->buttonApply->setEnabled( true );
1458 //Group2Spin->buttonApply->setFocus();
1460 if ( Group3Spin->isVisible() ) {
1461 Group3Spin->buttonApply->setEnabled( true );
1462 //Group3Spin->buttonApply->setFocus();
1464 if ( Group4Spin->isVisible() ) {
1465 Group4Spin->buttonApply->setEnabled( true );
1466 //Group4Spin->buttonApply->setFocus();
1470 gp_Ax3 myWPlane = GetActiveLocalCS();
1471 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1472 WPlane->length( 9 );
1473 WPlane[0] = myWPlane.Location().X();
1474 WPlane[1] = myWPlane.Location().Y();
1475 WPlane[2] = myWPlane.Location().Z();
1477 WPlane[3] = myWPlane.Direction().X();
1478 WPlane[4] = myWPlane.Direction().Y();
1479 WPlane[5] = myWPlane.Direction().Z();
1481 WPlane[6] = myWPlane.XDirection().X();
1482 WPlane[7] = myWPlane.XDirection().Y();
1483 WPlane[8] = myWPlane.XDirection().Z();
1485 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1486 GEOM::GEOM_Object_var anObj = anOper->MakeSketcher( cmd.toLatin1().constData(), WPlane );
1488 if ( !anObj->_is_nil() )
1490 if( !IsPreview() ) {
1491 QStringList aCurrentParameters = myParameters;
1492 aCurrentParameters << aParameters;
1493 myNoteBook->setParameters(anObj, aCurrentParameters);
1496 objects.push_back( anObj._retn() );
1502 //================================================================
1503 // Function : displayPreview
1504 // Purpose : Method for displaying preview of resulting shape
1505 // Redefined from GEOMBase_Helper.
1506 //================================================================
1507 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1509 const bool activate,
1511 const double lineWidth,
1512 const int displayMode,
1515 // Set color for preview shape
1516 getDisplayer()->SetColor( Quantity_NOC_RED );
1518 // set width of displayed shape
1519 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1521 // Disable activation of selection
1522 getDisplayer()->SetToActivate( activate );
1524 // Make a reference to GEOM_Object
1525 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1526 getDisplayer()->SetName( objStr.in() );
1528 // Create wire from applayed object
1529 TopoDS_Shape anApplyedWire, aLastSegment;
1530 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1534 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1535 if ( aPrs != 0 && !aPrs->IsNull() )
1536 GEOMBase_Helper::displayPreview( aPrs, append, update );
1538 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1539 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1540 if ( aPrs != 0 && !aPrs->IsNull() )
1541 GEOMBase_Helper::displayPreview( aPrs, append, update );
1543 getDisplayer()->UnsetName();
1545 // Enable activation of displayed objects
1546 getDisplayer()->SetToActivate( true );
1549 //================================================================
1550 // Function : createShapes
1551 // Purpose : Create applyed wire, and last segment from entry object
1552 //================================================================
1553 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1554 TopoDS_Shape& theApplyedWire,
1555 TopoDS_Shape& theLastSegment )
1557 TopoDS_Shape aShape;
1558 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1559 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1562 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1563 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1564 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1565 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1566 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() ) {
1567 theApplyedWire = aShape;
1571 BRepBuilderAPI_MakeWire aBuilder;
1572 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1574 TopoDS_Shape anEdge = anExp.Current();
1576 if ( anExp.More() ) // i.e. non-last edge
1577 aBuilder.Add( TopoDS::Edge( anEdge ) );
1579 theLastSegment = anEdge;
1584 if ( aBuilder.IsDone() )
1585 theApplyedWire = aBuilder.Shape();
1590 //=================================================================================
1591 // function : keyPressEvent()
1593 //=================================================================================
1594 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1596 QDialog::keyPressEvent( e );
1597 if ( e->isAccepted() )
1600 if ( e->key() == Qt::Key_F1 ) {
1606 void EntityGUI_SketcherDlg::initSpinBox( SalomeApp_DoubleSpinBox* spinBox,
1607 double min, double max,
1608 double step, int decimals )
1610 spinBox->setDecimals( decimals );
1611 spinBox->setRange( min, max );
1612 spinBox->setSingleStep( step );
1615 //=================================================================================
1616 // function : SetDoubleSpinBoxStep()
1617 // purpose : Double spin box management
1618 //=================================================================================
1619 void EntityGUI_SketcherDlg::SetDoubleSpinBoxStep( double step )
1621 Group1Spin->SpinBox_DX->setSingleStep(step);
1622 Group2Spin->SpinBox_DX->setSingleStep(step);
1623 Group2Spin->SpinBox_DY->setSingleStep(step);
1624 Group3Spin->SpinBox_DX->setSingleStep(step);
1625 Group3Spin->SpinBox_DY->setSingleStep(step);
1626 Group3Spin->SpinBox_DZ->setSingleStep(step);
1627 Group4Spin->SpinBox_DX->setSingleStep(step);
1628 Group4Spin->SpinBox_DY->setSingleStep(step);
1629 Group4Spin->SpinBox_DZ->setSingleStep(step);
1630 Group4Spin->SpinBox_DS->setSingleStep(step);
1633 //=================================================================================
1634 // function : FindLocalCS()
1635 // purpose : Find All Coordinates systems in study
1636 //=================================================================================
1637 void EntityGUI_SketcherDlg::FindLocalCS()
1641 SalomeApp_Application* app =
1642 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1646 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1650 _PTR(Study) aStudy = appStudy->studyDS();
1653 ComboBox1->addItem(tr("GEOM_GCS"));
1654 gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
1655 gp_Dir aDirZ = gp_Dir(0, 0, 1);
1656 gp_Dir aDirX = gp_Dir(1, 0, 0);
1657 gp_Ax3 globalCS = gp_Ax3(aOrigin, aDirZ, aDirX);
1658 myLCSList.push_back(globalCS);
1660 // get GEOM component
1661 CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
1662 _PTR(SObject) obj = aStudy->FindObjectIOR( geomIOR.in() );
1665 _PTR(SComponent) fc = obj->GetFatherComponent();
1666 QString geomComp = fc->GetID().c_str();
1667 _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
1671 // browse through all GEOM data tree
1672 _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
1673 for ( it->InitEx( true ); it->More(); it->Next() ) {
1674 _PTR(SObject) child( it->Value() );
1675 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
1676 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
1677 if( CORBA::is_nil( geomObj ) )
1679 if (geomObj->GetType() == GEOM_MARKER) {
1680 ComboBox1->addItem(geomObj->GetName());
1681 TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
1684 aLCS.Transform(aShape.Location().Transformation());
1685 if (aShape.ShapeType() == TopAbs_FACE) {
1686 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aShape));
1687 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
1688 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
1689 gp_Pln aPln = aGPlane->Pln();
1690 aLCS = aPln.Position();
1693 myLCSList.push_back(aLCS);
1698 //=================================================================================
1699 // function : GetActiveLocalCS()
1700 // purpose : Find All Coordinates systems in study
1701 //=================================================================================
1702 gp_Ax3 EntityGUI_SketcherDlg::GetActiveLocalCS()
1704 int ind = ComboBox1->currentIndex();
1706 return myGeometryGUI->GetWorkingPlane();
1708 gp_Ax3 aLCS = myLCSList.at(ind);
1710 myGeometryGUI->SetWorkingPlane( aLCS );
1711 myGeometryGUI->ActiveWorkingPlane();