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
24 // File : EntityGUI_SketcherDlg.cxx
25 // Author : Damien COQUERET
29 #include "EntityGUI_SketcherDlg.h"
30 #include "Sketcher_Profile.hxx"
31 #include "GEOM_Displayer.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_ResourceMgr.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_Application.h"
40 #include "LightApp_SelectionMgr.h"
42 #include <qpushbutton.h>
45 #include <BRep_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopoDS_Vertex.hxx>
50 #include <BRepBuilderAPI_Transform.hxx>
51 #include <BRepBuilderAPI_MakeWire.hxx>
53 #include "GEOMImpl_Types.hxx"
55 #include "utilities.h"
59 //=================================================================================
60 // class : EntityGUI_SketcherDlg()
61 // purpose : Constructs a EntityGUI_SketcherDlg which is a child of 'parent', with the
62 // name 'name' and widget flags set to 'f'.
63 // The dialog will by default be modeless, unless you set 'modal' to
64 // TRUE to construct a modal dialog.
65 //=================================================================================
66 EntityGUI_SketcherDlg::EntityGUI_SketcherDlg(GeometryGUI* GUI, QWidget* parent,
67 const char* name, bool modal, WFlags fl,
68 const double lineWidth)
69 :EntityGUI_Skeleton_QTD(parent, name, modal, WStyle_Customize |
70 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
71 myIsAllAdded( false ),
72 GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
74 myLineWidth( lineWidth )
76 myGeometryGUI->SetActiveDialogBox(this);
78 if ( !name ) setName("EntityGUI_SketcherDlg");
80 buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
81 buttonEnd->setText(tr("GEOM_BUT_END_SKETCH"));
82 buttonClose->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
83 buttonHelp->setText(tr("GEOM_BUT_HELP"));
85 GroupVal->close(TRUE);
86 GroupDest2->close(TRUE);
87 GroupDest3->close(TRUE);
89 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
90 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_UNDO")));
91 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REDO")));
93 setCaption(tr("GEOM_SKETCHER_TITLE"));
95 GroupConstructors->setTitle(tr("GEOM_SKETCHER_EL"));
96 RadioButton1->setText(tr("GEOM_SKETCHER_SEGMENT"));
97 RadioButton2->setText(tr("GEOM_SKETCHER_ARC"));
98 GroupDest->setTitle(tr("GEOM_SKETCHER_DEST"));
99 GroupDest1->setTitle(tr("GEOM_SKETCHER_TYPE"));
100 RB_Dest1->setText(tr("GEOM_SKETCHER_POINT"));
101 RB_Dest2->setText(tr("GEOM_SKETCHER_DIR"));
103 /***************************************************************/
104 GroupPt = new EntityGUI_Point_QTD(GroupDest, "GroupPt");
105 GroupPt->GroupPoint->setTitle(tr("GEOM_SKETCHER_POINT"));
106 GroupPt->RB_Point1->setText(tr("GEOM_SKETCHER_ABS"));
107 GroupPt->RB_Point2->setText(tr("GEOM_SKETCHER_REL"));
108 GroupPt->RB_Point3->setText(tr("GEOM_SKETCHER_SEL"));
110 GroupD1 = new EntityGUI_Dir1_QTD(GroupDest, "GroupD1");
111 GroupD1->GroupDir1->setTitle(tr("GEOM_SKETCHER_DIR"));
112 GroupD1->RB_Dir11->setText(tr("GEOM_SKETCHER_ANGLE"));
113 GroupD1->RB_Dir12->setText(tr("GEOM_SKETCHER_PER"));
114 GroupD1->RB_Dir13->setText(tr("GEOM_SKETCHER_TAN"));
115 GroupD1->RB_Dir14->setText(tr("GEOM_SKETCHER_VXVY"));
117 GroupD2 = new EntityGUI_Dir2_QTD(GroupDest, "GroupD2");
118 GroupD2->GroupDir2->setTitle(tr("GEOM_SKETCHER_DIR"));
119 GroupD2->RB_Dir21->setText(tr("GEOM_SKETCHER_LENGTH"));
120 GroupD2->RB_Dir22->setText(tr("GEOM_SKETCHER_X"));
121 GroupD2->RB_Dir23->setText(tr("GEOM_SKETCHER_Y"));
123 Group1Sel = new EntityGUI_1Sel_QTD(this, "Group1Sel");
124 Group1Sel->TextLabel1->setText(tr("GEOM_SKETCHER_POINT2"));
125 Group1Sel->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
126 Group1Sel->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
127 Group1Sel->PushButton1->setPixmap(image0);
128 Group1Sel->buttonUndo->setPixmap(image1);
129 Group1Sel->buttonRedo->setPixmap(image2);
130 Group1Sel->LineEdit1->setReadOnly( true );
132 Group1Spin = new EntityGUI_1Spin(this, "Group1Spin");
133 Group1Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
134 Group1Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
135 Group1Spin->buttonUndo->setPixmap(image1);
136 Group1Spin->buttonRedo->setPixmap(image2);
137 QWidget::setTabOrder(Group1Spin->SpinBox_DX , Group1Spin->buttonApply);
138 QWidget::setTabOrder(Group1Spin->buttonApply, Group1Spin->buttonUndo);
139 QWidget::setTabOrder(Group1Spin->buttonUndo , Group1Spin->buttonRedo);
141 Group2Spin = new EntityGUI_2Spin(this, "Group2Spin");
142 Group2Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
143 Group2Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
144 Group2Spin->buttonUndo->setPixmap(image1);
145 Group2Spin->buttonRedo->setPixmap(image2);
146 QWidget::setTabOrder(Group2Spin->SpinBox_DX , Group2Spin->SpinBox_DY);
147 QWidget::setTabOrder(Group2Spin->SpinBox_DY , Group2Spin->buttonApply);
148 QWidget::setTabOrder(Group2Spin->buttonApply, Group2Spin->buttonUndo);
149 QWidget::setTabOrder(Group2Spin->buttonUndo , Group2Spin->buttonRedo);
151 Group3Spin = new EntityGUI_3Spin(this, "Group3Spin");
152 Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
153 Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
154 Group3Spin->buttonUndo->setPixmap(image1);
155 Group3Spin->buttonRedo->setPixmap(image2);
156 QWidget::setTabOrder(Group3Spin->SpinBox_DX , Group3Spin->SpinBox_DY);
157 QWidget::setTabOrder(Group3Spin->SpinBox_DY , Group3Spin->SpinBox_DZ);
158 QWidget::setTabOrder(Group3Spin->SpinBox_DZ , Group3Spin->buttonApply);
159 QWidget::setTabOrder(Group3Spin->buttonApply, Group3Spin->buttonUndo);
160 QWidget::setTabOrder(Group3Spin->buttonUndo , Group3Spin->buttonRedo);
162 Group4Spin = new EntityGUI_4Spin(this, "Group4Spin");
163 Group4Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
164 Group4Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
165 Group4Spin->buttonUndo->setPixmap(image1);
166 Group4Spin->buttonRedo->setPixmap(image2);
167 QWidget::setTabOrder(Group4Spin->SpinBox_DX , Group4Spin->SpinBox_DY);
168 QWidget::setTabOrder(Group4Spin->SpinBox_DY , Group4Spin->SpinBox_DZ);
169 QWidget::setTabOrder(Group4Spin->SpinBox_DZ , Group4Spin->SpinBox_DS);
170 QWidget::setTabOrder(Group4Spin->SpinBox_DS , Group4Spin->buttonApply);
171 QWidget::setTabOrder(Group4Spin->buttonApply, Group4Spin->buttonUndo);
172 QWidget::setTabOrder(Group4Spin->buttonUndo , Group4Spin->buttonRedo);
174 Layout5->addMultiCellWidget(GroupPt, 1, 1, 0, 1);
175 Layout5->addWidget(GroupD1, 1, 0);
176 Layout5->addWidget(GroupD2, 1, 1);
178 Layout1->addWidget(Group1Sel, 2, 0);
179 Layout1->addWidget(Group1Spin, 2, 0);
180 Layout1->addWidget(Group2Spin, 2, 0);
181 Layout1->addWidget(Group3Spin, 2, 0);
182 Layout1->addWidget(Group4Spin, 2, 0);
183 /***************************************************************/
185 /* signals and slots connections */
186 connect(buttonEnd, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
187 connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
188 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
189 connect(buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp()));
191 connect(Group1Sel->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
192 connect(Group1Sel->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
193 connect(Group1Sel->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
194 connect(Group1Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
195 connect(Group1Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
196 connect(Group1Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
197 connect(Group2Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
198 connect(Group2Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
199 connect(Group2Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
200 connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
201 connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
202 connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
203 connect(Group4Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
204 connect(Group4Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
205 connect(Group4Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
207 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(TypeClicked(int)));
208 connect(GroupDest1, SIGNAL(clicked(int)), this, SLOT(DestClicked(int)));
209 connect(GroupPt->GroupPoint, SIGNAL(clicked(int)), this, SLOT(PointClicked(int)));
210 connect(GroupD1->GroupDir1, SIGNAL(clicked(int)), this, SLOT(Dir1Clicked(int)));
211 connect(GroupD2->GroupDir2, SIGNAL(clicked(int)), this, SLOT(Dir2Clicked(int)));
213 connect(Group1Sel->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
214 connect(Group1Sel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
216 connect(Group1Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
217 connect(Group2Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
218 connect(Group2Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
219 connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
220 connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
221 connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
222 connect(Group4Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
223 connect(Group4Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
224 connect(Group4Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
225 connect(Group4Spin->SpinBox_DS, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
227 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1Spin->SpinBox_DX, SLOT(SetStep(double)));
228 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DX, SLOT(SetStep(double)));
229 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DY, SLOT(SetStep(double)));
230 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DX, SLOT(SetStep(double)));
231 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DY, SLOT(SetStep(double)));
232 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DZ, SLOT(SetStep(double)));
233 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DX, SLOT(SetStep(double)));
234 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DY, SLOT(SetStep(double)));
235 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DZ, SLOT(SetStep(double)));
236 connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DS, SLOT(SetStep(double)));
238 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
239 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
241 // install event filter on spin-boxes to provide Apply action on Return pressed
242 Group1Spin->SpinBox_DX->installEventFilter(this);
243 Group2Spin->SpinBox_DX->installEventFilter(this);
244 Group2Spin->SpinBox_DY->installEventFilter(this);
245 Group3Spin->SpinBox_DX->installEventFilter(this);
246 Group3Spin->SpinBox_DY->installEventFilter(this);
247 Group3Spin->SpinBox_DZ->installEventFilter(this);
248 Group4Spin->SpinBox_DX->installEventFilter(this);
249 Group4Spin->SpinBox_DY->installEventFilter(this);
250 Group4Spin->SpinBox_DZ->installEventFilter(this);
251 Group4Spin->SpinBox_DS->installEventFilter(this);
257 //=================================================================================
258 // function : ~EntityGUI_SketcherDlg()
259 // purpose : Destroys the object and frees any allocated resources
260 //=================================================================================
261 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
263 myGeometryGUI->SetActiveDialogBox( 0 );
267 //=================================================================================
268 // function : eventFilter()
269 // purpose : event filter for spin-boxes to provide Apply action on Return pressed
270 //=================================================================================
271 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
273 if (event->type() == QEvent::KeyPress) {
274 QKeyEvent* ke = (QKeyEvent*)event;
275 if (ke->key() == Key_Return) {
276 if (object == Group1Spin->SpinBox_DX) {
277 Group1Spin->buttonApply->animateClick();
279 } else if (object == Group2Spin->SpinBox_DX ||
280 object == Group2Spin->SpinBox_DY) {
281 Group2Spin->buttonApply->animateClick();
283 } else if (object == Group3Spin->SpinBox_DX ||
284 object == Group3Spin->SpinBox_DY ||
285 object == Group3Spin->SpinBox_DZ) {
286 Group3Spin->buttonApply->animateClick();
288 } else if (object == Group4Spin->SpinBox_DX ||
289 object == Group4Spin->SpinBox_DY ||
290 object == Group4Spin->SpinBox_DZ ||
291 object == Group4Spin->SpinBox_DS) {
292 Group4Spin->buttonApply->animateClick();
298 return EntityGUI_Skeleton_QTD::eventFilter(object, event);
302 //=================================================================================
305 //=================================================================================
306 void EntityGUI_SketcherDlg::Init()
309 myEditCurrentArgument = Group1Sel->LineEdit1;
310 myCommand.append( "Sketcher" );
311 myUndoCommand.append( "Sketcher" );
313 mySketchState = FIRST_POINT;
314 globalSelection( GEOM_POINT );
321 myHelpFileName = "sketcher.htm";
323 /* Get setting of step value from file configuration */
324 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
326 /* min, max, step and decimals for spin boxes */
327 Group1Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
328 Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
329 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
330 Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
331 Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
332 Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
333 Group4Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
334 Group4Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
335 Group4Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
336 Group4Spin->SpinBox_DS->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
338 /* displays Dialog */
339 GroupConstructors->setEnabled(false);
340 GroupDest1->setEnabled(false);
341 setEnabledUndo(false);
342 setEnabledRedo(false);
344 RadioButton1->setChecked(true);
349 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
353 //=================================================================================
354 // function : InitClick()
356 //=================================================================================
357 void EntityGUI_SketcherDlg::InitClick()
359 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
371 //=================================================================================
372 // function : TypeClicked()
373 // purpose : Radio button management
374 //=================================================================================
375 void EntityGUI_SketcherDlg::TypeClicked(int constructorId)
377 myConstructorId = constructorId;
378 if ( myConstructorId == 0 ) // SEGMENT
380 GroupD2->setEnabled(true);
381 RB_Dest1->setEnabled(true);
382 RB_Dest1->setChecked(true);
385 else if ( myConstructorId == 1 ) // ARC
387 GroupD2->setEnabled(false);
388 RB_Dest1->setEnabled(false);
389 RB_Dest2->setChecked(true);
395 //=================================================================================
396 // function : DestClicked()
397 // purpose : Radio button management
398 //=================================================================================
399 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
405 if ( constructorId == 1 )
407 GroupPt->RB_Point1->setChecked(true);
409 PointClicked(1); // XY
411 else if ( constructorId == 0 )
413 GroupD1->RB_Dir11->setChecked(true);
416 Dir1Clicked(2); // Angle
421 //=================================================================================
422 // function : PointClicked()
423 // purpose : Radio button management
424 //=================================================================================
425 void EntityGUI_SketcherDlg::PointClicked(int constructorId)
429 // Get setting of step value from file configuration
430 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
432 if ( myConstructorId == 0 )
434 if ( constructorId == 1 )
436 mySketchType = PT_ABS;
437 Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
438 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
439 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
440 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
442 Group2Spin->SpinBox_DX->SetValue(myX);
444 Group2Spin->SpinBox_DY->SetValue(myY);
446 Group2Spin->buttonApply->setFocus();
448 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
450 else if ( constructorId == 0 )
452 mySketchType = PT_RELATIVE;
453 Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
454 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
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 )
468 mySketchType = PT_SEL;
469 myEditCurrentArgument = Group1Sel->LineEdit1;
470 connect(myGeometryGUI->getApp()->selectionMgr(),
471 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
473 Group1Sel->buttonApply->setFocus();
474 SelectionIntoArgument();
480 //=================================================================================
481 // function : Dir1Clicked()
482 // purpose : Radio button management
483 //=================================================================================
484 void EntityGUI_SketcherDlg::Dir1Clicked(int constructorId)
486 myConstructorDirId = constructorId;
487 GroupD2->RB_Dir21->setChecked(true);
492 //=================================================================================
493 // function : Dir2Clicked()
494 // purpose : Radio button management
495 //=================================================================================
496 void EntityGUI_SketcherDlg::Dir2Clicked(int constructorId)
501 // Get setting of step value from file configuration
502 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
504 if ( myConstructorId == 0 )
509 if ( myConstructorDirId == 2 )
511 Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
512 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
513 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
514 Group2Spin->SpinBox_DX->SetValue(myAngle);
515 Group2Spin->buttonApply->setFocus();
518 if ( constructorId == 2 )
520 mySketchType = DIR_ANGLE_LENGTH;
521 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_LENGTH2"));
522 Group2Spin->SpinBox_DY->SetValue(myLength);
524 else if ( constructorId == 0 )
526 mySketchType = DIR_ANGLE_X;
527 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_X3"));
528 Group2Spin->SpinBox_DY->SetValue(myX);
530 else if ( constructorId == 1 )
532 mySketchType = DIR_ANGLE_Y;
533 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y3"));
534 Group2Spin->SpinBox_DY->SetValue(myY);
537 else if ( myConstructorDirId == 0 )
540 Group1Spin->buttonApply->setFocus();
542 if ( constructorId == 2 )
544 mySketchType = DIR_PER_LENGTH;
545 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
546 Group1Spin->SpinBox_DX->SetValue(myLength);
548 else if ( constructorId == 0 )
550 mySketchType = DIR_PER_X;
551 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
552 Group1Spin->SpinBox_DX->SetValue(myX);
554 else if ( constructorId == 1 )
556 mySketchType = DIR_PER_Y;
557 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
558 Group1Spin->SpinBox_DX->SetValue(myY);
561 else if ( myConstructorDirId == 1 )
564 Group1Spin->buttonApply->setFocus();
566 if ( constructorId == 2 )
568 mySketchType = DIR_TAN_LENGTH;
569 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
570 Group1Spin->SpinBox_DX->SetValue(myLength);
572 else if ( constructorId == 0 )
574 mySketchType = DIR_TAN_X;
575 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
576 Group1Spin->SpinBox_DX->SetValue(myX);
578 else if ( constructorId == 1 )
580 mySketchType = DIR_TAN_Y;
581 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
582 Group1Spin->SpinBox_DX->SetValue(myY);
585 else if ( myConstructorDirId == 3 )
587 Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
588 Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
589 Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
590 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
591 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
593 Group3Spin->SpinBox_DX->SetValue(myDX);
595 Group3Spin->SpinBox_DY->SetValue(myDY);
597 Group3Spin->buttonApply->setFocus();
599 if ( constructorId == 2 )
601 mySketchType = DIR_DXDY_LENGTH;
602 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_LENGTH2"));
603 Group3Spin->SpinBox_DZ->SetValue(myLength);
605 else if ( constructorId == 0 )
607 mySketchType = DIR_DXDY_X;
608 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_X3"));
609 Group3Spin->SpinBox_DZ->SetValue(myX);
611 else if ( constructorId == 1 )
613 mySketchType = DIR_DXDY_Y;
614 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Y3"));
615 Group3Spin->SpinBox_DZ->SetValue(myY);
619 else if ( myConstructorId == 1 )
621 if ( myConstructorDirId == 2 )
623 if ( constructorId == 2 )
625 mySketchType = DIR_ANGLE_LENGTH;
626 Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
627 Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
628 Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
629 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
630 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_RADIUS2"));
631 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_ANGLE2"));
632 Group3Spin->SpinBox_DX->SetValue(myAngle);
634 Group3Spin->SpinBox_DY->SetValue(myRadius);
636 Group3Spin->SpinBox_DZ->SetValue(myLength);
638 Group3Spin->buttonApply->setFocus();
641 else if ( myConstructorDirId == 0 )
643 if ( constructorId == 2 )
645 mySketchType = DIR_PER_LENGTH;
646 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
647 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
648 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
649 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
651 Group2Spin->SpinBox_DX->SetValue(myRadius);
653 Group2Spin->SpinBox_DY->SetValue(myLength);
655 Group2Spin->buttonApply->setFocus();
658 else if ( myConstructorDirId == 1 )
660 if ( constructorId == 2 )
662 mySketchType = DIR_TAN_LENGTH;
663 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
664 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
665 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
666 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
668 Group2Spin->SpinBox_DX->SetValue(myRadius);
670 Group2Spin->SpinBox_DY->SetValue(myLength);
672 Group2Spin->buttonApply->setFocus();
675 else if ( myConstructorDirId == 3 )
677 if ( constructorId == 2 )
679 mySketchType = DIR_DXDY_LENGTH;
680 Group4Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
681 Group4Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
682 Group4Spin->TextLabel3->setText(tr("GEOM_SKETCHER_RADIUS2"));
683 Group4Spin->TextLabel4->setText(tr("GEOM_SKETCHER_ANGLE2"));
685 Group4Spin->SpinBox_DX->SetValue(myDX);
687 Group4Spin->SpinBox_DY->SetValue(myDY);
689 Group4Spin->SpinBox_DZ->SetValue(myRadius);
691 Group4Spin->SpinBox_DS->SetValue(myLength);
693 Group4Spin->buttonApply->setFocus();
698 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
702 //=================================================================================
703 // function : ClickOnCancel()
705 //=================================================================================
706 void EntityGUI_SketcherDlg::ClickOnCancel()
712 //=================================================================================
713 // function : ClickOnEnd()
714 // purpose : connected to buttonEnd AND buttonClose
715 //=================================================================================
716 void EntityGUI_SketcherDlg::ClickOnEnd()
718 if ( sender() == buttonClose )
720 // Verify validity of commands
721 if ( myCommand.count() <= 2 )
723 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
724 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
728 QString Command = myCommand.join( "" ) + GetNewCommand();
729 Sketcher_Profile aProfile (Command.ascii());
731 Command = myCommand.join( "" );
732 aProfile = Sketcher_Profile(Command.ascii());
733 TopoDS_Shape myShape;
734 if ( aProfile.IsDone() )
735 myShape = aProfile.GetShape();
737 if(myShape.ShapeType() != TopAbs_VERTEX)
738 myCommand.append( ":WW" );
743 if( myCommand.size() > 2 )
750 //=================================================================================
751 // function : ClickOnApply()
753 //=================================================================================
754 bool EntityGUI_SketcherDlg::ClickOnApply()
756 ((QPushButton*)sender())->setFocus(); // to update value of currently edited spin-box (PAL11948)
758 myCommand.append( GetNewCommand() );
759 mySketchState = NEXT_POINT;
761 myUndoCommand.clear();
762 myUndoCommand.append( "Sketcher" );
764 GroupConstructors->setEnabled(true);
765 GroupDest1->setEnabled(true);
766 setEnabledUndo(true);
767 setEnabledRedo(false);
769 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
771 // Set focus to SpinBox_DX
772 if (sender() == Group1Spin->buttonApply) {
773 (Group1Spin->SpinBox_DX)->setFocus();
774 (Group1Spin->SpinBox_DX)->selectAll();
776 else if (sender() == Group2Spin->buttonApply) {
777 (Group2Spin->SpinBox_DX)->setFocus();
778 (Group2Spin->SpinBox_DX)->selectAll();
780 else if (sender() == Group3Spin->buttonApply) {
781 (Group3Spin->SpinBox_DX)->setFocus();
782 (Group3Spin->SpinBox_DX)->selectAll();
784 else if (sender() == Group4Spin->buttonApply) {
785 (Group4Spin->SpinBox_DX)->setFocus();
786 (Group4Spin->SpinBox_DX)->selectAll();
792 //=================================================================================
793 // function : ClickOnHelp()
795 //=================================================================================
796 void EntityGUI_SketcherDlg::ClickOnHelp()
798 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
800 app->onHelpContextModule(myGeometryGUI ? app->moduleName(myGeometryGUI->moduleName()) : QString(""), myHelpFileName);
802 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
803 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
804 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
805 QObject::tr("BUT_OK"));
809 //=================================================================================
810 // function : ClickOnUndo()
812 //=================================================================================
813 void EntityGUI_SketcherDlg::ClickOnUndo()
815 myUndoCommand.append( myCommand.last() );
816 myCommand.pop_back();
818 if(myCommand.count() == 1) {
819 mySketchState = FIRST_POINT;
821 RadioButton1->setChecked(true);
824 GroupConstructors->setEnabled(false);
825 GroupDest1->setEnabled(false);
826 setEnabledUndo(false);
829 setEnabledRedo(true);
831 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
834 //=================================================================================
835 // function : ClickOnRedo()
837 //=================================================================================
838 void EntityGUI_SketcherDlg::ClickOnRedo()
840 myCommand.append( myUndoCommand.last() );
841 myUndoCommand.pop_back();
843 mySketchState = NEXT_POINT;
845 GroupConstructors->setEnabled(true);
846 GroupDest1->setEnabled(true);
847 setEnabledUndo(true);
849 if(myUndoCommand.count() == 1)
850 setEnabledRedo(false);
852 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
855 //=================================================================================
856 // function : setEnabledUndo()
858 //=================================================================================
859 void EntityGUI_SketcherDlg::setEnabledUndo(bool value)
861 Group1Sel->buttonUndo->setEnabled(value);
862 Group1Spin->buttonUndo->setEnabled(value);
863 Group2Spin->buttonUndo->setEnabled(value);
864 Group3Spin->buttonUndo->setEnabled(value);
865 Group4Spin->buttonUndo->setEnabled(value);
868 //=================================================================================
869 // function : setEnabledRedo()
871 //=================================================================================
872 void EntityGUI_SketcherDlg::setEnabledRedo(bool value)
874 Group1Sel->buttonRedo->setEnabled(value);
875 Group1Spin->buttonRedo->setEnabled(value);
876 Group2Spin->buttonRedo->setEnabled(value);
877 Group3Spin->buttonRedo->setEnabled(value);
878 Group4Spin->buttonRedo->setEnabled(value);
881 //=================================================================================
882 // function : SelectionIntoArgument()
883 // purpose : Called when selection as changed
884 //=================================================================================
885 void EntityGUI_SketcherDlg::SelectionIntoArgument()
887 myEditCurrentArgument->setText("");
891 int nbSel = IObjectCount();
892 if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 )
894 Standard_Boolean aRes = Standard_False;
895 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
896 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
898 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
900 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
902 aTrans.SetTransformation(aWPlane);
903 BRepBuilderAPI_Transform aTransformation(aShape, aTrans, Standard_False);
904 aShape = aTransformation.Shape();
907 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
910 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
916 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
920 //=================================================================================
921 // function : SetEditCurrentArgument()
923 //=================================================================================
924 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
926 if ( sender() == Group1Sel->PushButton1 )
928 myEditCurrentArgument = Group1Sel->LineEdit1;
929 myEditCurrentArgument->setFocus();
931 SelectionIntoArgument();
935 //=================================================================================
936 // function : LineEditReturnPressed()
938 //=================================================================================
939 void EntityGUI_SketcherDlg::LineEditReturnPressed()
941 if ( sender() == Group1Sel->LineEdit1 )
943 myEditCurrentArgument = Group1Sel->LineEdit1;
945 /* User name of object input management */
946 /* If successfull the selection is changed and signal emitted... */
947 /* so SelectionIntoArgument() is automatically called. */
948 const QString objectUserName = myEditCurrentArgument->text();
949 QWidget* thisWidget = (QWidget*)this;
950 if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
951 myEditCurrentArgument->setText(objectUserName);
956 //=================================================================================
957 // function : DeactivateActiveDialog()
959 //=================================================================================
960 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
962 //myGeometryGUI->SetState( -1 );
966 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
967 myGeometryGUI->SetActiveDialogBox(0);
971 //=================================================================================
972 // function : ActivateThisDialog()
974 //=================================================================================
975 void EntityGUI_SketcherDlg::ActivateThisDialog()
977 myGeometryGUI->EmitSignalDeactivateDialog();
979 myGeometryGUI->SetActiveDialogBox((QDialog*)this);
981 connect(myGeometryGUI->getApp()->selectionMgr(),
982 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
984 //myGeometryGUI->SetState( 0 );
985 globalSelection( GEOM_POINT );
987 myEditCurrentArgument = Group1Sel->LineEdit1;
988 myEditCurrentArgument->setFocus();
990 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
994 //=================================================================================
995 // function : enterEvent [REDEFINED]
997 //=================================================================================
998 void EntityGUI_SketcherDlg::enterEvent(QEvent* e)
1000 if ( !GroupConstructors->isEnabled())
1001 ActivateThisDialog();
1005 //=================================================================================
1006 // function : closeEvent()
1008 //=================================================================================
1009 void EntityGUI_SketcherDlg::closeEvent(QCloseEvent* e)
1011 //myGeometryGUI->SetState( -1 );
1012 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
1013 QDialog::closeEvent( e );
1017 //=================================================================================
1018 // function : ValueChangedInSpinBox()
1020 //=================================================================================
1021 void EntityGUI_SketcherDlg::ValueChangedInSpinBox(double newValue)
1023 QObject* send = (QObject*)sender();
1024 Standard_Real vx, vy, vz, vs;
1025 vx = vy = vz = vs = 0.0;
1027 if ( send == Group1Spin->SpinBox_DX)
1031 else if ( send == Group2Spin->SpinBox_DX )
1034 vy = Group2Spin->SpinBox_DY->GetValue();
1036 else if ( send == Group2Spin->SpinBox_DY)
1038 vx = Group2Spin->SpinBox_DX->GetValue();
1041 else if ( send == Group3Spin->SpinBox_DX)
1044 vy = Group3Spin->SpinBox_DY->GetValue();
1045 vz = Group3Spin->SpinBox_DZ->GetValue();
1047 else if ( send == Group3Spin->SpinBox_DY)
1049 vx = Group3Spin->SpinBox_DX->GetValue();
1051 vz = Group3Spin->SpinBox_DZ->GetValue();
1053 else if ( send == Group3Spin->SpinBox_DZ)
1055 vx = Group3Spin->SpinBox_DX->GetValue();
1056 vy = Group3Spin->SpinBox_DY->GetValue();
1059 else if ( send == Group4Spin->SpinBox_DX)
1062 vy = Group4Spin->SpinBox_DY->GetValue();
1063 vz = Group4Spin->SpinBox_DZ->GetValue();
1064 vs = Group4Spin->SpinBox_DS->GetValue();
1066 else if ( send == Group4Spin->SpinBox_DY)
1068 vx = Group4Spin->SpinBox_DX->GetValue();
1070 vz = Group4Spin->SpinBox_DZ->GetValue();
1071 vs = Group4Spin->SpinBox_DS->GetValue();
1073 else if ( send == Group4Spin->SpinBox_DZ)
1075 vx = Group4Spin->SpinBox_DX->GetValue();
1076 vy = Group4Spin->SpinBox_DY->GetValue();
1078 vs = Group4Spin->SpinBox_DS->GetValue();
1080 else if ( send == Group4Spin->SpinBox_DS)
1082 vx = Group4Spin->SpinBox_DX->GetValue();
1083 vy = Group4Spin->SpinBox_DY->GetValue();
1084 vz = Group4Spin->SpinBox_DZ->GetValue();
1088 if ( myConstructorId == 0 )
1090 if ( mySketchType == PT_ABS)
1095 else if ( mySketchType == PT_RELATIVE)
1100 else if ( mySketchType == DIR_ANGLE_LENGTH)
1105 else if ( mySketchType == DIR_ANGLE_X)
1110 else if ( mySketchType == DIR_ANGLE_Y)
1115 else if ( mySketchType == DIR_PER_LENGTH)
1119 else if ( mySketchType == DIR_PER_X)
1123 else if ( mySketchType == DIR_PER_Y)
1127 else if ( mySketchType == DIR_TAN_LENGTH)
1131 else if ( mySketchType == DIR_TAN_X)
1135 else if ( mySketchType == DIR_TAN_Y)
1139 else if ( mySketchType == DIR_DXDY_LENGTH)
1145 else if ( mySketchType == DIR_DXDY_X)
1151 else if ( mySketchType == DIR_DXDY_Y)
1158 else if ( myConstructorId == 1 )
1160 if ( mySketchType == DIR_ANGLE_LENGTH)
1166 else if ( mySketchType == DIR_PER_LENGTH)
1171 else if ( mySketchType == DIR_TAN_LENGTH)
1176 else if ( mySketchType == DIR_DXDY_LENGTH)
1185 GEOMBase_Helper::displayPreview(false, true, true, myLineWidth);
1189 //=================================================================================
1190 // function : GetNewCommand()
1191 // purpose : Build the new command with context
1192 //=================================================================================
1193 QString EntityGUI_SketcherDlg::GetNewCommand()
1195 QString myNewCommand = ":";
1196 if ( mySketchState == FIRST_POINT ) {
1197 if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1198 myNewCommand = myNewCommand + "F " + QString::number(myX) + " " + QString::number(myY);
1199 if ( mySketchType == PT_RELATIVE)
1200 myNewCommand = myNewCommand + "F " + QString::number(myDX) + " " + QString::number(myDY);
1201 return myNewCommand;
1204 if ( myConstructorId == 0 )
1206 if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1207 myNewCommand = myNewCommand + "TT " + QString::number(myX) + " " + QString::number(myY);
1208 if ( mySketchType == PT_RELATIVE)
1209 myNewCommand = myNewCommand + "T " + QString::number(myDX) + " " + QString::number(myDY);
1210 if ( mySketchType == DIR_ANGLE_LENGTH)
1212 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1213 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1215 if ( mySketchType == DIR_ANGLE_X)
1217 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1218 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1220 if ( mySketchType == DIR_ANGLE_Y)
1222 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1223 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1225 if ( mySketchType == DIR_PER_LENGTH)
1227 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1228 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1230 if ( mySketchType == DIR_PER_X)
1232 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1233 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1235 if ( mySketchType == DIR_PER_Y)
1237 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1238 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1240 if ( mySketchType == DIR_TAN_LENGTH)
1241 myNewCommand = myNewCommand + "L " + QString::number(myLength);
1242 if ( mySketchType == DIR_TAN_X)
1243 myNewCommand = myNewCommand + "IX " + QString::number(myX);
1244 if ( mySketchType == DIR_TAN_Y)
1245 myNewCommand = myNewCommand + "IY " + QString::number(myY);
1246 if ( mySketchType == DIR_DXDY_LENGTH)
1248 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1249 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1251 if ( mySketchType == DIR_DXDY_X)
1253 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1254 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1256 if ( mySketchType == DIR_DXDY_Y)
1258 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1259 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1262 else if ( myConstructorId == 1 )
1264 if ( mySketchType == DIR_ANGLE_LENGTH)
1266 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1267 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1269 if ( mySketchType == DIR_PER_LENGTH)
1271 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1272 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1274 if ( mySketchType == DIR_TAN_LENGTH)
1276 myNewCommand = myNewCommand + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1278 if ( mySketchType == DIR_DXDY_LENGTH)
1280 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1281 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1284 return myNewCommand;
1287 //=================================================================================
1288 // function : createOperation
1290 //=================================================================================
1291 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1293 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1296 //=================================================================================
1297 // function : isValid
1299 //=================================================================================
1300 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1305 //=================================================================================
1306 // function : execute
1308 //=================================================================================
1309 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1311 if(mySketchState == FIRST_POINT) {
1316 //Test if the current point is the same as the last one
1317 TopoDS_Shape myShape1, myShape2;
1320 QString Command1 = myCommand.join( "" );
1321 Sketcher_Profile aProfile1 (Command1.ascii());
1322 if(aProfile1.IsDone())
1323 myShape1 = aProfile1.GetShape();
1326 QString Command2 = Command1 + GetNewCommand();
1327 Sketcher_Profile aProfile2 (Command2.ascii());
1328 if(aProfile2.IsDone())
1329 myShape2 = aProfile2.GetShape();
1331 if(myShape2.IsNull()) {
1332 //the current point is the same as the last one
1333 myLastX2 = myLastX1;
1334 myLastY2 = myLastY1;
1337 TopoDS_Vertex V1, V2;
1339 if(myShape1.ShapeType() == TopAbs_VERTEX) {
1340 //the last shape is the first point
1341 pt = BRep_Tool::Pnt(TopoDS::Vertex(myShape1));
1346 TopExp::Vertices(TopoDS::Wire(myShape1), V1, V2);
1347 pt = BRep_Tool::Pnt(V2);
1351 TopExp::Vertices(TopoDS::Wire(myShape2), V1, V2);
1352 pt = BRep_Tool::Pnt(V2);
1359 if( ( mySketchState != FIRST_POINT &&
1360 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1361 cmd = myCommand.join( "" );
1363 if ( Group1Sel->isVisible() ) {
1364 Group1Sel->buttonApply->setEnabled(false);
1365 //Group1Sel->buttonApply->setFocus();
1367 if ( Group1Spin->isVisible() ) {
1368 Group1Spin->buttonApply->setEnabled(false);
1369 //Group1Spin->buttonApply->setFocus();
1371 if ( Group2Spin->isVisible() ) {
1372 Group2Spin->buttonApply->setEnabled(false);
1373 //Group2Spin->buttonApply->setFocus();
1375 if ( Group3Spin->isVisible() ) {
1376 Group3Spin->buttonApply->setEnabled(false);
1377 //Group3Spin->buttonApply->setFocus();
1379 if ( Group4Spin->isVisible() ) {
1380 Group4Spin->buttonApply->setEnabled(false);
1381 //Group4Spin->buttonApply->setFocus();
1385 cmd = myCommand.join( "" ) + GetNewCommand();
1387 if ( Group1Sel->isVisible() ) {
1388 Group1Sel->buttonApply->setEnabled(true);
1389 //Group1Sel->buttonApply->setFocus();
1391 if ( Group1Spin->isVisible() ) {
1392 Group1Spin->buttonApply->setEnabled(true);
1393 //Group1Spin->buttonApply->setFocus();
1395 if ( Group2Spin->isVisible() ) {
1396 Group2Spin->buttonApply->setEnabled(true);
1397 //Group2Spin->buttonApply->setFocus();
1399 if ( Group3Spin->isVisible() ) {
1400 Group3Spin->buttonApply->setEnabled(true);
1401 //Group3Spin->buttonApply->setFocus();
1403 if ( Group4Spin->isVisible() ) {
1404 Group4Spin->buttonApply->setEnabled(true);
1405 //Group4Spin->buttonApply->setFocus();
1409 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1410 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1412 WPlane[0] = myWPlane.Location().X();
1413 WPlane[1] = myWPlane.Location().Y();
1414 WPlane[2] = myWPlane.Location().Z();
1416 WPlane[3] = myWPlane.Direction().X();
1417 WPlane[4] = myWPlane.Direction().Y();
1418 WPlane[5] = myWPlane.Direction().Z();
1420 WPlane[6] = myWPlane.XDirection().X();
1421 WPlane[7] = myWPlane.XDirection().Y();
1422 WPlane[8] = myWPlane.XDirection().Z();
1424 GEOM::GEOM_Object_var anObj =
1425 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.latin1(), WPlane );
1427 if ( !anObj->_is_nil() )
1428 objects.push_back( anObj._retn() );
1433 //================================================================
1434 // Function : displayPreview
1435 // Purpose : Method for displaying preview of resulting shape
1436 // Redefined from GEOMBase_Helper.
1437 //================================================================
1438 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1440 const bool activate,
1442 const double lineWidth )
1444 // Set color for preview shape
1445 getDisplayer()->SetColor( Quantity_NOC_RED );
1447 // set width of displayed shape
1448 getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth );
1450 // Disable activation of selection
1451 getDisplayer()->SetToActivate( activate );
1453 // Make a reference to GEOM_Object
1454 getDisplayer()->SetName( myGeometryGUI->getApp()->orb()->object_to_string( object ) );
1456 // Create wire from applayed object
1457 TopoDS_Shape anApplyedWire, aLastSegment;
1458 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1462 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1463 if ( aPrs != 0 && !aPrs->IsNull() )
1464 GEOMBase_Helper::displayPreview( aPrs, append, update );
1466 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1467 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1468 if ( aPrs != 0 && !aPrs->IsNull() )
1469 GEOMBase_Helper::displayPreview( aPrs, append, update );
1471 getDisplayer()->UnsetName();
1473 // Enable activation of displayed objects
1474 getDisplayer()->SetToActivate( true );
1477 //================================================================
1478 // Function : createShapes
1479 // Purpose : Create applyed wire, and last segment from entry object
1480 //================================================================
1481 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1482 TopoDS_Shape& theApplyedWire,
1483 TopoDS_Shape& theLastSegment )
1485 TopoDS_Shape aShape;
1486 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1487 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1490 if ( Group1Sel->isVisible() && !Group1Sel->buttonApply->isEnabled() ||
1491 Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1492 Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1493 Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1494 Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() )
1496 theApplyedWire = aShape;
1500 BRepBuilderAPI_MakeWire aBuilder;
1501 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1504 TopoDS_Shape anEdge = anExp.Current();
1506 if ( anExp.More() ) // i.e. non-last edge
1507 aBuilder.Add( TopoDS::Edge( anEdge ) );
1510 theLastSegment = anEdge;
1515 if ( aBuilder.IsDone() )
1516 theApplyedWire = aBuilder.Shape();
1521 //=================================================================================
1522 // function : keyPressEvent()
1524 //=================================================================================
1525 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1527 QDialog::keyPressEvent( e );
1528 if ( e->isAccepted() )
1531 if ( e->key() == Key_F1 )