]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI_SketcherDlg.cxx
Salome HOME
Merging with WPdev
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : EntityGUI_SketcherDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "EntityGUI_SketcherDlg.h"
30 #include "Sketcher_Profile.hxx"
31 #include "GEOM_Displayer.h"
32 #include "GEOMBase.h"
33
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"
41
42 #include <qpushbutton.h>
43 #include <qlabel.h>
44
45 #include <BRep_Tool.hxx>
46 #include <TopExp.hxx>
47 #include <TopExp_Explorer.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS.hxx>
50 #include <BRepBuilderAPI_Transform.hxx>
51 #include <BRepBuilderAPI_MakeWire.hxx>
52
53 #include "GEOMImpl_Types.hxx"
54
55 #include "utilities.h"
56
57 using namespace std;
58
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   :EntityGUI_Skeleton_QTD(parent, name, modal, WStyle_Customize |
69                           WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
70    myIsAllAdded( false ),
71    GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( parent ) ),
72    myGeometryGUI( GUI )
73 {
74   myGeometryGUI->SetActiveDialogBox(this);
75
76   if ( !name ) setName("EntityGUI_SketcherDlg");
77
78   buttonCancel->setText(tr("GEOM_BUT_CANCEL"));
79   buttonEnd->setText(tr("GEOM_BUT_END_SKETCH"));
80   buttonClose->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
81   buttonHelp->setText(tr("GEOM_BUT_HELP"));
82
83   GroupVal->close(TRUE);
84   GroupDest2->close(TRUE);
85   GroupDest3->close(TRUE);
86
87   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
88   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_UNDO")));
89   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REDO")));
90
91   setCaption(tr("GEOM_SKETCHER_TITLE"));
92
93   GroupConstructors->setTitle(tr("GEOM_SKETCHER_EL"));
94   RadioButton1->setText(tr("GEOM_SKETCHER_SEGMENT"));
95   RadioButton2->setText(tr("GEOM_SKETCHER_ARC"));
96   GroupDest->setTitle(tr("GEOM_SKETCHER_DEST"));
97   GroupDest1->setTitle(tr("GEOM_SKETCHER_TYPE"));
98   RB_Dest1->setText(tr("GEOM_SKETCHER_POINT"));
99   RB_Dest2->setText(tr("GEOM_SKETCHER_DIR"));
100
101   /***************************************************************/
102   GroupPt = new EntityGUI_Point_QTD(GroupDest, "GroupPt");
103   GroupPt->GroupPoint->setTitle(tr("GEOM_SKETCHER_POINT"));
104   GroupPt->RB_Point1->setText(tr("GEOM_SKETCHER_ABS"));
105   GroupPt->RB_Point2->setText(tr("GEOM_SKETCHER_REL"));
106   GroupPt->RB_Point3->setText(tr("GEOM_SKETCHER_SEL"));
107
108   GroupD1 = new EntityGUI_Dir1_QTD(GroupDest, "GroupD1");
109   GroupD1->GroupDir1->setTitle(tr("GEOM_SKETCHER_DIR"));
110   GroupD1->RB_Dir11->setText(tr("GEOM_SKETCHER_ANGLE"));
111   GroupD1->RB_Dir12->setText(tr("GEOM_SKETCHER_PER"));
112   GroupD1->RB_Dir13->setText(tr("GEOM_SKETCHER_TAN"));
113   GroupD1->RB_Dir14->setText(tr("GEOM_SKETCHER_VXVY"));
114
115   GroupD2 = new EntityGUI_Dir2_QTD(GroupDest, "GroupD2");
116   GroupD2->GroupDir2->setTitle(tr("GEOM_SKETCHER_DIR"));
117   GroupD2->RB_Dir21->setText(tr("GEOM_SKETCHER_LENGTH"));
118   GroupD2->RB_Dir22->setText(tr("GEOM_SKETCHER_X"));
119   GroupD2->RB_Dir23->setText(tr("GEOM_SKETCHER_Y"));
120
121   Group1Sel = new EntityGUI_1Sel_QTD(this, "Group1Sel");
122   Group1Sel->TextLabel1->setText(tr("GEOM_SKETCHER_POINT2"));
123   Group1Sel->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
124   Group1Sel->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
125   Group1Sel->PushButton1->setPixmap(image0);
126   Group1Sel->buttonUndo->setPixmap(image1);
127   Group1Sel->buttonRedo->setPixmap(image2);
128   Group1Sel->LineEdit1->setReadOnly( true );
129
130   Group1Spin = new EntityGUI_1Spin(this, "Group1Spin");
131   Group1Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
132   Group1Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
133   Group1Spin->buttonUndo->setPixmap(image1);
134   Group1Spin->buttonRedo->setPixmap(image2);
135   QWidget::setTabOrder(Group1Spin->SpinBox_DX , Group1Spin->buttonApply);
136   QWidget::setTabOrder(Group1Spin->buttonApply, Group1Spin->buttonUndo);
137   QWidget::setTabOrder(Group1Spin->buttonUndo , Group1Spin->buttonRedo);
138
139   Group2Spin = new EntityGUI_2Spin(this, "Group2Spin");
140   Group2Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
141   Group2Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
142   Group2Spin->buttonUndo->setPixmap(image1);
143   Group2Spin->buttonRedo->setPixmap(image2);
144   QWidget::setTabOrder(Group2Spin->SpinBox_DX , Group2Spin->SpinBox_DY);
145   QWidget::setTabOrder(Group2Spin->SpinBox_DY , Group2Spin->buttonApply);
146   QWidget::setTabOrder(Group2Spin->buttonApply, Group2Spin->buttonUndo);
147   QWidget::setTabOrder(Group2Spin->buttonUndo , Group2Spin->buttonRedo);
148
149   Group3Spin = new EntityGUI_3Spin(this, "Group3Spin");
150   Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
151   Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
152   Group3Spin->buttonUndo->setPixmap(image1);
153   Group3Spin->buttonRedo->setPixmap(image2);
154   QWidget::setTabOrder(Group3Spin->SpinBox_DX , Group3Spin->SpinBox_DY);
155   QWidget::setTabOrder(Group3Spin->SpinBox_DY , Group3Spin->SpinBox_DZ);
156   QWidget::setTabOrder(Group3Spin->SpinBox_DZ , Group3Spin->buttonApply);
157   QWidget::setTabOrder(Group3Spin->buttonApply, Group3Spin->buttonUndo);
158   QWidget::setTabOrder(Group3Spin->buttonUndo , Group3Spin->buttonRedo);
159
160   Group4Spin = new EntityGUI_4Spin(this, "Group4Spin");
161   Group4Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
162   Group4Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
163   Group4Spin->buttonUndo->setPixmap(image1);
164   Group4Spin->buttonRedo->setPixmap(image2);
165   QWidget::setTabOrder(Group4Spin->SpinBox_DX , Group4Spin->SpinBox_DY);
166   QWidget::setTabOrder(Group4Spin->SpinBox_DY , Group4Spin->SpinBox_DZ);
167   QWidget::setTabOrder(Group4Spin->SpinBox_DZ , Group4Spin->SpinBox_DS);
168   QWidget::setTabOrder(Group4Spin->SpinBox_DS , Group4Spin->buttonApply);
169   QWidget::setTabOrder(Group4Spin->buttonApply, Group4Spin->buttonUndo);
170   QWidget::setTabOrder(Group4Spin->buttonUndo , Group4Spin->buttonRedo);
171
172   Layout5->addMultiCellWidget(GroupPt, 1, 1, 0, 1);
173   Layout5->addWidget(GroupD1, 1, 0);
174   Layout5->addWidget(GroupD2, 1, 1);
175
176   Layout1->addWidget(Group1Sel, 2, 0);
177   Layout1->addWidget(Group1Spin, 2, 0);
178   Layout1->addWidget(Group2Spin, 2, 0);
179   Layout1->addWidget(Group3Spin, 2, 0);
180   Layout1->addWidget(Group4Spin, 2, 0);
181   /***************************************************************/
182
183   /* signals and slots connections */
184   connect(buttonEnd, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
185   connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnEnd()));
186   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
187   connect(buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp()));
188
189   connect(Group1Sel->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
190   connect(Group1Sel->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
191   connect(Group1Sel->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
192   connect(Group1Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
193   connect(Group1Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
194   connect(Group1Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
195   connect(Group2Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
196   connect(Group2Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
197   connect(Group2Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
198   connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
199   connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
200   connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
201   connect(Group4Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
202   connect(Group4Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
203   connect(Group4Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo()));
204
205   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(TypeClicked(int)));
206   connect(GroupDest1, SIGNAL(clicked(int)), this, SLOT(DestClicked(int)));
207   connect(GroupPt->GroupPoint, SIGNAL(clicked(int)), this, SLOT(PointClicked(int)));
208   connect(GroupD1->GroupDir1, SIGNAL(clicked(int)), this, SLOT(Dir1Clicked(int)));
209   connect(GroupD2->GroupDir2, SIGNAL(clicked(int)), this, SLOT(Dir2Clicked(int)));
210
211   connect(Group1Sel->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
212   connect(Group1Sel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
213
214   connect(Group1Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
215   connect(Group2Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
216   connect(Group2Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
217   connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
218   connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
219   connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
220   connect(Group4Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
221   connect(Group4Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
222   connect(Group4Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
223   connect(Group4Spin->SpinBox_DS, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
224
225   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group1Spin->SpinBox_DX, SLOT(SetStep(double)));
226   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DX, SLOT(SetStep(double)));
227   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group2Spin->SpinBox_DY, SLOT(SetStep(double)));
228   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DX, SLOT(SetStep(double)));
229   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DY, SLOT(SetStep(double)));
230   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Spin->SpinBox_DZ, SLOT(SetStep(double)));
231   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DX, SLOT(SetStep(double)));
232   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DY, SLOT(SetStep(double)));
233   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DZ, SLOT(SetStep(double)));
234   connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group4Spin->SpinBox_DS, SLOT(SetStep(double)));
235
236   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
237   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
238
239   // install event filter on spin-boxes to provide Apply action on Return pressed
240   Group1Spin->SpinBox_DX->installEventFilter(this);
241   Group2Spin->SpinBox_DX->installEventFilter(this);
242   Group2Spin->SpinBox_DY->installEventFilter(this);
243   Group3Spin->SpinBox_DX->installEventFilter(this);
244   Group3Spin->SpinBox_DY->installEventFilter(this);
245   Group3Spin->SpinBox_DZ->installEventFilter(this);
246   Group4Spin->SpinBox_DX->installEventFilter(this);
247   Group4Spin->SpinBox_DY->installEventFilter(this);
248   Group4Spin->SpinBox_DZ->installEventFilter(this);
249   Group4Spin->SpinBox_DS->installEventFilter(this);
250
251   Init();
252 }
253
254
255 //=================================================================================
256 // function : ~EntityGUI_SketcherDlg()
257 // purpose  : Destroys the object and frees any allocated resources
258 //=================================================================================
259 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
260 {
261   myGeometryGUI->SetActiveDialogBox( 0 );
262 }
263
264
265 //=================================================================================
266 // function : eventFilter()
267 // purpose  : event filter for spin-boxes to provide Apply action on Return pressed
268 //=================================================================================
269 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
270 {
271   if (event->type() == QEvent::KeyPress) {
272     QKeyEvent* ke = (QKeyEvent*)event;
273     if (ke->key() == Key_Return) {
274       if (object == Group1Spin->SpinBox_DX) {
275         Group1Spin->buttonApply->animateClick();
276         return true;
277       } else if (object == Group2Spin->SpinBox_DX ||
278                  object == Group2Spin->SpinBox_DY) {
279         Group2Spin->buttonApply->animateClick();
280         return true;
281       } else if (object == Group3Spin->SpinBox_DX ||
282                  object == Group3Spin->SpinBox_DY ||
283                  object == Group3Spin->SpinBox_DZ) {
284         Group3Spin->buttonApply->animateClick();
285         return true;
286       } else if (object == Group4Spin->SpinBox_DX ||
287                  object == Group4Spin->SpinBox_DY ||
288                  object == Group4Spin->SpinBox_DZ ||
289                  object == Group4Spin->SpinBox_DS) {
290         Group4Spin->buttonApply->animateClick();
291         return true;
292       }
293     }
294   }
295
296   return EntityGUI_Skeleton_QTD::eventFilter(object, event);
297 }
298
299
300 //=================================================================================
301 // function : Init()
302 // purpose  :
303 //=================================================================================
304 void EntityGUI_SketcherDlg::Init()
305 {
306   /* init variables */
307   myEditCurrentArgument = Group1Sel->LineEdit1;
308   myCommand.append( "Sketcher" );
309   myUndoCommand.append( "Sketcher" );
310
311   mySketchState = FIRST_POINT;
312   globalSelection( GEOM_POINT );
313
314   myLastX1 = 0.0;
315   myLastY1 = 0.0;
316   myLastX2 = 0.0;
317   myLastY2 = 0.0;
318
319   myHelpFileName = "sketcher.htm";
320
321   /* Get setting of step value from file configuration */
322   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
323
324   /* min, max, step and decimals for spin boxes */
325   Group1Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
326   Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
327   Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
328   Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
329   Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
330   Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
331   Group4Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
332   Group4Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
333   Group4Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
334   Group4Spin->SpinBox_DS->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
335
336   /* displays Dialog */
337   GroupConstructors->setEnabled(false);
338   GroupDest1->setEnabled(false);
339   setEnabledUndo(false);
340   setEnabledRedo(false);
341
342   RadioButton1->setChecked(true);
343
344   resize( 0, 0 );
345   TypeClicked(0);
346
347   GEOMBase_Helper::displayPreview();
348 }
349
350
351 //=================================================================================
352 // function : InitClick()
353 // purpose  :
354 //=================================================================================
355 void EntityGUI_SketcherDlg::InitClick()
356 {
357   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
358
359   Group1Sel->hide();
360   Group1Spin->hide();
361   Group2Spin->hide();
362   Group3Spin->hide();
363   Group4Spin->hide();
364
365   resize(0, 0);
366 }
367
368
369 //=================================================================================
370 // function : TypeClicked()
371 // purpose  : Radio button management
372 //=================================================================================
373 void EntityGUI_SketcherDlg::TypeClicked(int constructorId)
374 {
375   myConstructorId = constructorId;
376   if ( myConstructorId == 0 )     // SEGMENT
377   {
378     GroupD2->setEnabled(true);
379     RB_Dest1->setEnabled(true);
380     RB_Dest1->setChecked(true);
381     DestClicked(1);
382   }
383   else if (  myConstructorId == 1 ) // ARC
384   {
385     GroupD2->setEnabled(false);
386     RB_Dest1->setEnabled(false);
387     RB_Dest2->setChecked(true);
388     DestClicked(0);
389   }
390 }
391
392
393 //=================================================================================
394 // function : DestClicked()
395 // purpose  : Radio button management
396 //=================================================================================
397 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
398 {
399   GroupPt->hide();
400   GroupD1->hide();
401   GroupD2->hide();
402
403   if ( constructorId == 1 )
404   {  // Point
405     GroupPt->RB_Point1->setChecked(true);
406     GroupPt->show();
407     PointClicked(1);  // XY
408   }
409   else if (  constructorId == 0 )
410   {  // Direction
411     GroupD1->RB_Dir11->setChecked(true);
412     GroupD1->show();
413     GroupD2->show();
414     Dir1Clicked(2);  // Angle
415   }
416 }
417
418
419 //=================================================================================
420 // function : PointClicked()
421 // purpose  : Radio button management
422 //=================================================================================
423 void EntityGUI_SketcherDlg::PointClicked(int constructorId)
424 {
425   InitClick();
426
427   // Get setting of step value from file configuration
428   double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
429
430   if ( myConstructorId == 0 )
431   {  // SEGMENT
432     if ( constructorId == 1 )
433     {  // XY
434       mySketchType = PT_ABS;
435       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
436       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
437       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
438       Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
439       myX = 0.0;
440       Group2Spin->SpinBox_DX->SetValue(myX);
441       myY = 0.0;
442       Group2Spin->SpinBox_DY->SetValue(myY);
443       Group2Spin->show();
444       Group2Spin->buttonApply->setFocus();
445
446       GEOMBase_Helper::displayPreview();
447     }
448     else if ( constructorId == 0 )
449     {  // DXDY
450       mySketchType = PT_RELATIVE;
451       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
452       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
453       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
454       Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
455       myDX = 0.0;
456       Group2Spin->SpinBox_DX->SetValue(myDX);
457       myDY = 0.0;
458       Group2Spin->SpinBox_DY->SetValue(myDY);
459       Group2Spin->show();
460       Group2Spin->buttonApply->setFocus();
461
462       GEOMBase_Helper::displayPreview();
463     }
464     else if ( constructorId == 2 )
465     {  // Selection
466       mySketchType = PT_SEL;
467       myEditCurrentArgument = Group1Sel->LineEdit1;
468       connect(myGeometryGUI->getApp()->selectionMgr(),
469               SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
470       Group1Sel->show();
471       Group1Sel->buttonApply->setFocus();
472       SelectionIntoArgument();
473     }
474   }
475 }
476
477
478 //=================================================================================
479 // function : Dir1Clicked()
480 // purpose  : Radio button management
481 //=================================================================================
482 void EntityGUI_SketcherDlg::Dir1Clicked(int constructorId)
483 {
484   myConstructorDirId = constructorId;
485   GroupD2->RB_Dir21->setChecked(true);
486   Dir2Clicked(2);
487 }
488
489
490 //=================================================================================
491 // function : Dir2Clicked()
492 // purpose  : Radio button management
493 //=================================================================================
494 void EntityGUI_SketcherDlg::Dir2Clicked(int constructorId)
495 {
496   InitClick();
497   myAngle = 0.0;
498
499   // Get setting of step value from file configuration
500   double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
501
502   if ( myConstructorId == 0 )
503   {  // SEGMENT
504     myX = 0.0;
505     myY = 0.0;
506     myLength = 100.0;
507     if ( myConstructorDirId == 2 )
508     {  // Angle
509       Group2Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
510       Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
511       Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
512       Group2Spin->SpinBox_DX->SetValue(myAngle);
513       Group2Spin->buttonApply->setFocus();
514       Group2Spin->show();
515
516       if ( constructorId == 2 )
517       {  // Length
518                                 mySketchType = DIR_ANGLE_LENGTH;
519                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_LENGTH2"));
520                                 Group2Spin->SpinBox_DY->SetValue(myLength);
521       }
522       else if ( constructorId == 0 )
523       {  // X
524                                 mySketchType = DIR_ANGLE_X;
525                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_X3"));
526                                 Group2Spin->SpinBox_DY->SetValue(myX);
527       }
528       else if ( constructorId == 1 )
529       {  // Y
530                                 mySketchType = DIR_ANGLE_Y;
531                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y3"));
532                                 Group2Spin->SpinBox_DY->SetValue(myY);
533       }
534     }
535     else if ( myConstructorDirId == 0 )
536     {  // Perpendicular
537       Group1Spin->show();
538       Group1Spin->buttonApply->setFocus();
539
540       if ( constructorId == 2 )
541       {  // Length
542                                 mySketchType = DIR_PER_LENGTH;
543                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
544                                 Group1Spin->SpinBox_DX->SetValue(myLength);
545       }
546       else if ( constructorId == 0 )
547       {  // X
548                                 mySketchType = DIR_PER_X;
549                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
550                                 Group1Spin->SpinBox_DX->SetValue(myX);
551       }
552       else if ( constructorId == 1 )
553       {  // Y
554                                 mySketchType = DIR_PER_Y;
555                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
556                                 Group1Spin->SpinBox_DX->SetValue(myY);
557       }
558     }
559     else if ( myConstructorDirId == 1 )
560     {  // Tangent
561       Group1Spin->show();
562       Group1Spin->buttonApply->setFocus();
563
564       if ( constructorId == 2 )
565       {  // Length
566                                 mySketchType = DIR_TAN_LENGTH;
567                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
568                                 Group1Spin->SpinBox_DX->SetValue(myLength);
569       }
570       else if ( constructorId == 0 )
571       {  // X
572                                 mySketchType = DIR_TAN_X;
573                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
574                                 Group1Spin->SpinBox_DX->SetValue(myX);
575       }
576       else if ( constructorId == 1 )
577       {  // Y
578                                 mySketchType = DIR_TAN_Y;
579                                 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
580                                 Group1Spin->SpinBox_DX->SetValue(myY);
581       }
582     }
583     else if ( myConstructorDirId == 3 )
584     {  // DXDY
585       Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
586       Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, 3);
587       Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
588       Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
589       Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
590       myDX = 0.0;
591       Group3Spin->SpinBox_DX->SetValue(myDX);
592       myDY = 0.0;
593       Group3Spin->SpinBox_DY->SetValue(myDY);
594       Group3Spin->show();
595       Group3Spin->buttonApply->setFocus();
596
597       if ( constructorId == 2 )
598       {  // Length
599                                 mySketchType = DIR_DXDY_LENGTH;
600                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_LENGTH2"));
601                                 Group3Spin->SpinBox_DZ->SetValue(myLength);
602       }
603       else if ( constructorId == 0 )
604       {  // X
605                                 mySketchType = DIR_DXDY_X;
606                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_X3"));
607                                 Group3Spin->SpinBox_DZ->SetValue(myX);
608       }
609       else if ( constructorId == 1 )
610       {  // Y
611                                 mySketchType = DIR_DXDY_Y;
612                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Y3"));
613                                 Group3Spin->SpinBox_DZ->SetValue(myY);
614       }
615     }
616   }
617   else if ( myConstructorId == 1 )
618   {  // ARC
619     if ( myConstructorDirId == 2 )
620     {  // Angle
621       if ( constructorId == 2 )
622       {  // Length
623                                 mySketchType = DIR_ANGLE_LENGTH;
624                                 Group3Spin->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
625                                 Group3Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
626                                 Group3Spin->SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
627                                 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_ANGLE2"));
628                                 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_RADIUS2"));
629                                 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_ANGLE2"));
630                                 Group3Spin->SpinBox_DX->SetValue(myAngle);
631                                 myRadius = 100.0;
632                                 Group3Spin->SpinBox_DY->SetValue(myRadius);
633                                 myLength = 30.0;
634                                 Group3Spin->SpinBox_DZ->SetValue(myLength);
635                                 Group3Spin->show();
636                                 Group3Spin->buttonApply->setFocus();
637       }
638     }
639     else if ( myConstructorDirId == 0 )
640     {  // Perpendicular
641       if ( constructorId == 2 )
642       {  // Length
643                                 mySketchType = DIR_PER_LENGTH;
644                                 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
645                                 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
646                                 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
647                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
648                                 myRadius = 100.0;
649                                 Group2Spin->SpinBox_DX->SetValue(myRadius);
650                                 myLength = 30.0;
651                                 Group2Spin->SpinBox_DY->SetValue(myLength);
652                                 Group2Spin->show();
653                                 Group2Spin->buttonApply->setFocus();
654       }
655     }
656     else if ( myConstructorDirId == 1 )
657     {  // Tangent
658       if ( constructorId == 2 )
659       {  // Length
660                                 mySketchType = DIR_TAN_LENGTH;
661                                 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, 3);
662                                 Group2Spin->SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 5., 3);
663                                 Group2Spin->TextLabel1->setText(tr("GEOM_SKETCHER_RADIUS2"));
664                                 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_ANGLE2"));
665                                 myRadius = 100.0;
666                                 Group2Spin->SpinBox_DX->SetValue(myRadius);
667                                 myLength = 30.0;
668                                 Group2Spin->SpinBox_DY->SetValue(myLength);
669                                 Group2Spin->show();
670                                 Group2Spin->buttonApply->setFocus();
671       }
672     }
673     else if ( myConstructorDirId == 3 )
674     {  // DXDY
675       if ( constructorId == 2 )
676       {  // Length
677                                 mySketchType = DIR_DXDY_LENGTH;
678                                 Group4Spin->TextLabel1->setText(tr("GEOM_SKETCHER_VX2"));
679                                 Group4Spin->TextLabel2->setText(tr("GEOM_SKETCHER_VY2"));
680                                 Group4Spin->TextLabel3->setText(tr("GEOM_SKETCHER_RADIUS2"));
681                                 Group4Spin->TextLabel4->setText(tr("GEOM_SKETCHER_ANGLE2"));
682                                 myDX = 0.0;
683                                 Group4Spin->SpinBox_DX->SetValue(myDX);
684                                 myDY = 0.0;
685                                 Group4Spin->SpinBox_DY->SetValue(myDY);
686                                 myRadius = 100.0;
687                                 Group4Spin->SpinBox_DZ->SetValue(myRadius);
688                                 myLength = 30.0;
689                                 Group4Spin->SpinBox_DS->SetValue(myLength);
690                                 Group4Spin->show();
691                                 Group4Spin->buttonApply->setFocus();
692       }
693     }
694   }
695
696   GEOMBase_Helper::displayPreview();
697 }
698
699
700 //=================================================================================
701 // function : ClickOnCancel()
702 // purpose  :
703 //=================================================================================
704 void EntityGUI_SketcherDlg::ClickOnCancel()
705 {
706   close();
707 }
708
709
710 //=================================================================================
711 // function : ClickOnEnd()
712 // purpose  : connected to buttonEnd AND buttonClose
713 //=================================================================================
714 void EntityGUI_SketcherDlg::ClickOnEnd()
715 {
716   if ( sender() == buttonClose )
717   {
718     // Verify validity of commands
719     if ( myCommand.count() <= 2 )
720     {
721       SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
722                                tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
723       return;
724     }
725
726     QString Command = myCommand.join( "" ) + GetNewCommand();
727     Sketcher_Profile aProfile (Command.ascii());
728
729     Command = myCommand.join( "" );
730     aProfile = Sketcher_Profile(Command.ascii());
731     TopoDS_Shape myShape;
732     if ( aProfile.IsDone() )
733       myShape = aProfile.GetShape();
734
735     if(myShape.ShapeType() != TopAbs_VERTEX)
736       myCommand.append( ":WW" );
737   }
738   else
739     myIsAllAdded = true;
740
741   if( myCommand.size() > 2 )
742     if( !onAccept() )
743       return;
744
745   close();
746 }
747
748 //=================================================================================
749 // function : ClickOnApply()
750 // purpose  :
751 //=================================================================================
752 bool EntityGUI_SketcherDlg::ClickOnApply()
753 {
754   ((QPushButton*)sender())->setFocus(); // to update value of currently edited spin-box (PAL11948)
755
756   myCommand.append( GetNewCommand() );
757   mySketchState = NEXT_POINT;
758
759   myUndoCommand.clear();
760   myUndoCommand.append( "Sketcher" );
761
762   GroupConstructors->setEnabled(true);
763   GroupDest1->setEnabled(true);
764   setEnabledUndo(true);
765   setEnabledRedo(false);
766
767   GEOMBase_Helper::displayPreview();
768
769   // Set focus to SpinBox_DX
770   if (sender() == Group1Spin->buttonApply) {
771     (Group1Spin->SpinBox_DX)->setFocus();
772     (Group1Spin->SpinBox_DX)->selectAll();
773   }
774   else if (sender() == Group2Spin->buttonApply) {
775     (Group2Spin->SpinBox_DX)->setFocus();
776     (Group2Spin->SpinBox_DX)->selectAll();
777   }
778   else if (sender() == Group3Spin->buttonApply) {
779     (Group3Spin->SpinBox_DX)->setFocus();
780     (Group3Spin->SpinBox_DX)->selectAll();
781   }
782   else if (sender() == Group4Spin->buttonApply) {
783     (Group4Spin->SpinBox_DX)->setFocus();
784     (Group4Spin->SpinBox_DX)->selectAll();
785   }
786
787   return true;
788 }
789
790 //=================================================================================
791 // function : ClickOnHelp()
792 // purpose  :
793 //=================================================================================
794 void EntityGUI_SketcherDlg::ClickOnHelp()
795 {
796   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
797   if (app)
798     app->onHelpContextModule(myGeometryGUI ? app->moduleName(myGeometryGUI->moduleName()) : QString(""), myHelpFileName);
799   else {
800                 QString platform;
801 #ifdef WIN32
802                 platform = "winapplication";
803 #else
804                 platform = "application";
805 #endif
806
807     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
808                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
809                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
810                            QObject::tr("BUT_OK"));
811   }
812 }
813
814 //=================================================================================
815 // function : ClickOnUndo()
816 // purpose  :
817 //=================================================================================
818 void EntityGUI_SketcherDlg::ClickOnUndo()
819 {
820   myUndoCommand.append( myCommand.last() );
821   myCommand.pop_back();
822
823   if(myCommand.count() == 1) {
824     mySketchState = FIRST_POINT;
825
826     RadioButton1->setChecked(true);
827     TypeClicked(0);
828
829     GroupConstructors->setEnabled(false);
830     GroupDest1->setEnabled(false);
831     setEnabledUndo(false);
832   }
833
834   setEnabledRedo(true);
835
836   GEOMBase_Helper::displayPreview();
837 }
838
839 //=================================================================================
840 // function : ClickOnRedo()
841 // purpose  :
842 //=================================================================================
843 void EntityGUI_SketcherDlg::ClickOnRedo()
844 {
845   myCommand.append( myUndoCommand.last() );
846   myUndoCommand.pop_back();
847
848   mySketchState = NEXT_POINT;
849
850   GroupConstructors->setEnabled(true);
851   GroupDest1->setEnabled(true);
852   setEnabledUndo(true);
853
854   if(myUndoCommand.count() == 1)
855     setEnabledRedo(false);
856
857   GEOMBase_Helper::displayPreview();
858 }
859
860 //=================================================================================
861 // function : setEnabledUndo()
862 // purpose  :
863 //=================================================================================
864 void EntityGUI_SketcherDlg::setEnabledUndo(bool value)
865 {
866   Group1Sel->buttonUndo->setEnabled(value);
867   Group1Spin->buttonUndo->setEnabled(value);
868   Group2Spin->buttonUndo->setEnabled(value);
869   Group3Spin->buttonUndo->setEnabled(value);
870   Group4Spin->buttonUndo->setEnabled(value);
871 }
872
873 //=================================================================================
874 // function : setEnabledRedo()
875 // purpose  :
876 //=================================================================================
877 void EntityGUI_SketcherDlg::setEnabledRedo(bool value)
878 {
879   Group1Sel->buttonRedo->setEnabled(value);
880   Group1Spin->buttonRedo->setEnabled(value);
881   Group2Spin->buttonRedo->setEnabled(value);
882   Group3Spin->buttonRedo->setEnabled(value);
883   Group4Spin->buttonRedo->setEnabled(value);
884 }
885
886 //=================================================================================
887 // function : SelectionIntoArgument()
888 // purpose  : Called when selection as changed
889 //=================================================================================
890 void EntityGUI_SketcherDlg::SelectionIntoArgument()
891 {
892   myEditCurrentArgument->setText("");
893   myX = myLastX1;
894   myY = myLastY1;
895
896   int nbSel = IObjectCount();
897   if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 )
898   {
899     Standard_Boolean aRes = Standard_False;
900     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
901     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
902       TopoDS_Shape aShape;
903       if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
904         gp_Trsf aTrans;
905         gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
906
907         aTrans.SetTransformation(aWPlane);
908         BRepBuilderAPI_Transform aTransformation(aShape, aTrans, Standard_False);
909         aShape = aTransformation.Shape();
910
911         gp_Pnt aPnt;
912         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
913           myX = aPnt.X();
914           myY = aPnt.Y();
915           Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
916         }
917       }
918     }
919   }
920
921   GEOMBase_Helper::displayPreview();
922 }
923
924
925 //=================================================================================
926 // function : SetEditCurrentArgument()
927 // purpose  :
928 //=================================================================================
929 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
930 {
931   if ( sender() == Group1Sel->PushButton1 )
932   {
933     myEditCurrentArgument = Group1Sel->LineEdit1;
934     myEditCurrentArgument->setFocus();
935   }
936   SelectionIntoArgument();
937 }
938
939
940 //=================================================================================
941 // function : LineEditReturnPressed()
942 // purpose  :
943 //=================================================================================
944 void EntityGUI_SketcherDlg::LineEditReturnPressed()
945 {
946   if ( sender() == Group1Sel->LineEdit1 )
947   {
948     myEditCurrentArgument = Group1Sel->LineEdit1;
949
950         /* User name of object input management                          */
951         /* If successfull the selection is changed and signal emitted... */
952         /* so SelectionIntoArgument() is automatically called.           */
953         const QString objectUserName = myEditCurrentArgument->text();
954         QWidget* thisWidget = (QWidget*)this;
955         if(GEOMBase::SelectionByNameInDialogs(thisWidget, objectUserName, selectedIO()))
956         myEditCurrentArgument->setText(objectUserName);
957   }
958 }
959
960
961 //=================================================================================
962 // function : DeactivateActiveDialog()
963 // purpose  :
964 //=================================================================================
965 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
966 {
967   //myGeometryGUI->SetState( -1 );
968
969   setEnabled( false );
970   globalSelection();
971   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
972   myGeometryGUI->SetActiveDialogBox(0);
973 }
974
975
976 //=================================================================================
977 // function : ActivateThisDialog()
978 // purpose  :
979 //=================================================================================
980 void EntityGUI_SketcherDlg::ActivateThisDialog()
981 {
982   myGeometryGUI->EmitSignalDeactivateDialog();
983   setEnabled(true);
984   myGeometryGUI->SetActiveDialogBox((QDialog*)this);
985
986   connect(myGeometryGUI->getApp()->selectionMgr(),
987           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
988
989   //myGeometryGUI->SetState( 0 );
990   globalSelection( GEOM_POINT );
991
992   myEditCurrentArgument = Group1Sel->LineEdit1;
993   myEditCurrentArgument->setFocus();
994
995   GEOMBase_Helper::displayPreview();
996 }
997
998
999 //=================================================================================
1000 // function : enterEvent [REDEFINED]
1001 // purpose  :
1002 //=================================================================================
1003 void EntityGUI_SketcherDlg::enterEvent(QEvent* e)
1004 {
1005   if ( !GroupConstructors->isEnabled())
1006     ActivateThisDialog();
1007 }
1008
1009
1010 //=================================================================================
1011 // function : closeEvent()
1012 // purpose  :
1013 //=================================================================================
1014 void EntityGUI_SketcherDlg::closeEvent(QCloseEvent* e)
1015 {
1016   //myGeometryGUI->SetState( -1 );
1017   disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
1018   QDialog::closeEvent( e );
1019 }
1020
1021
1022 //=================================================================================
1023 // function : ValueChangedInSpinBox()
1024 // purpose  :
1025 //=================================================================================
1026 void EntityGUI_SketcherDlg::ValueChangedInSpinBox(double newValue)
1027 {
1028   QObject* send = (QObject*)sender();
1029   Standard_Real vx, vy, vz, vs;
1030   vx = vy = vz = vs = 0.0;
1031
1032   if ( send == Group1Spin->SpinBox_DX)
1033   {
1034     vx = newValue;
1035   }
1036   else if ( send == Group2Spin->SpinBox_DX )
1037   {
1038     vx = newValue;
1039     vy = Group2Spin->SpinBox_DY->GetValue();
1040   }
1041   else if ( send == Group2Spin->SpinBox_DY)
1042   {
1043     vx = Group2Spin->SpinBox_DX->GetValue();
1044     vy = newValue;
1045   }
1046   else if ( send == Group3Spin->SpinBox_DX)
1047   {
1048     vx = newValue;
1049     vy = Group3Spin->SpinBox_DY->GetValue();
1050     vz = Group3Spin->SpinBox_DZ->GetValue();
1051   }
1052   else if ( send == Group3Spin->SpinBox_DY)
1053   {
1054     vx = Group3Spin->SpinBox_DX->GetValue();
1055     vy = newValue;
1056     vz = Group3Spin->SpinBox_DZ->GetValue();
1057   }
1058   else if ( send == Group3Spin->SpinBox_DZ)
1059   {
1060     vx = Group3Spin->SpinBox_DX->GetValue();
1061     vy = Group3Spin->SpinBox_DY->GetValue();
1062     vz = newValue;
1063   }
1064   else if ( send == Group4Spin->SpinBox_DX)
1065   {
1066     vx = newValue;
1067     vy = Group4Spin->SpinBox_DY->GetValue();
1068     vz = Group4Spin->SpinBox_DZ->GetValue();
1069     vs = Group4Spin->SpinBox_DS->GetValue();
1070   }
1071   else if ( send == Group4Spin->SpinBox_DY)
1072   {
1073     vx = Group4Spin->SpinBox_DX->GetValue();
1074     vy = newValue;
1075     vz = Group4Spin->SpinBox_DZ->GetValue();
1076     vs = Group4Spin->SpinBox_DS->GetValue();
1077   }
1078   else if ( send == Group4Spin->SpinBox_DZ)
1079   {
1080     vx = Group4Spin->SpinBox_DX->GetValue();
1081     vy = Group4Spin->SpinBox_DY->GetValue();
1082     vz = newValue;
1083     vs = Group4Spin->SpinBox_DS->GetValue();
1084   }
1085   else if ( send == Group4Spin->SpinBox_DS)
1086   {
1087     vx = Group4Spin->SpinBox_DX->GetValue();
1088     vy = Group4Spin->SpinBox_DY->GetValue();
1089     vz = Group4Spin->SpinBox_DZ->GetValue();
1090     vs = newValue;
1091   }
1092
1093   if ( myConstructorId == 0 )
1094   {  // SEGMENT
1095     if ( mySketchType == PT_ABS)
1096     {
1097       myX = vx;
1098       myY = vy;
1099     }
1100     else if ( mySketchType == PT_RELATIVE)
1101     {
1102       myDX = vx;
1103       myDY = vy;
1104     }
1105     else if ( mySketchType == DIR_ANGLE_LENGTH)
1106     {
1107       myAngle = vx;
1108       myLength = vy;
1109     }
1110     else if ( mySketchType == DIR_ANGLE_X)
1111     {
1112       myAngle = vx;
1113       myX = vy;
1114     }
1115     else if ( mySketchType == DIR_ANGLE_Y)
1116     {
1117       myAngle = vx;
1118       myY = vy;
1119     }
1120     else if ( mySketchType == DIR_PER_LENGTH)
1121     {
1122       myLength = vx;
1123     }
1124     else if ( mySketchType == DIR_PER_X)
1125     {
1126       myX = vx;
1127     }
1128     else if ( mySketchType == DIR_PER_Y)
1129     {
1130       myY = vx;
1131     }
1132     else if ( mySketchType == DIR_TAN_LENGTH)
1133     {
1134       myLength = vx;
1135     }
1136     else if ( mySketchType == DIR_TAN_X)
1137     {
1138       myX = vx;
1139     }
1140     else if ( mySketchType == DIR_TAN_Y)
1141     {
1142       myY = vx;
1143     }
1144     else if ( mySketchType == DIR_DXDY_LENGTH)
1145     {
1146       myDX = vx;
1147       myDY = vy;
1148       myLength = vz;
1149     }
1150     else if ( mySketchType == DIR_DXDY_X)
1151     {
1152       myDX = vx;
1153       myDY = vy;
1154       myX = vz;
1155     }
1156     else if ( mySketchType == DIR_DXDY_Y)
1157     {
1158       myDX = vx;
1159       myDY = vy;
1160       myY = vz;
1161     }
1162   }
1163   else if ( myConstructorId == 1 )
1164   {  // ARC
1165     if ( mySketchType == DIR_ANGLE_LENGTH)
1166     {
1167       myAngle = vx;
1168       myRadius = vy;
1169       myLength = vz;
1170     }
1171     else if ( mySketchType == DIR_PER_LENGTH)
1172     {
1173       myRadius = vx;
1174       myLength = vy;
1175     }
1176     else if ( mySketchType == DIR_TAN_LENGTH)
1177     {
1178       myRadius = vx;
1179       myLength = vy;
1180     }
1181     else if ( mySketchType == DIR_DXDY_LENGTH)
1182     {
1183       myDX = vx;
1184       myDY = vy;
1185       myRadius = vz;
1186       myLength = vs;
1187     }
1188   }
1189
1190   GEOMBase_Helper::displayPreview();
1191 }
1192
1193
1194 //=================================================================================
1195 // function : GetNewCommand()
1196 // purpose  : Build the new command with context
1197 //=================================================================================
1198 QString EntityGUI_SketcherDlg::GetNewCommand()
1199 {
1200   QString myNewCommand = ":";
1201   if ( mySketchState == FIRST_POINT ) {
1202     if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1203       myNewCommand = myNewCommand + "F " + QString::number(myX) + " " + QString::number(myY);
1204     if ( mySketchType == PT_RELATIVE)
1205       myNewCommand = myNewCommand + "F " + QString::number(myDX) + " " + QString::number(myDY);
1206     return myNewCommand;
1207   }
1208
1209   if ( myConstructorId == 0  )
1210   {  // SEGMENT
1211     if ( mySketchType == PT_ABS || mySketchType == PT_SEL)
1212       myNewCommand = myNewCommand + "TT " + QString::number(myX) + " " + QString::number(myY);
1213     if ( mySketchType == PT_RELATIVE)
1214       myNewCommand = myNewCommand + "T " + QString::number(myDX) + " " + QString::number(myDY);
1215     if ( mySketchType == DIR_ANGLE_LENGTH)
1216     {
1217       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1218       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1219     }
1220     if ( mySketchType == DIR_ANGLE_X)
1221     {
1222       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1223       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1224     }
1225     if ( mySketchType == DIR_ANGLE_Y)
1226     {
1227       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1228       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1229     }
1230     if ( mySketchType == DIR_PER_LENGTH)
1231     {
1232       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1233       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1234     }
1235     if ( mySketchType == DIR_PER_X)
1236     {
1237       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1238       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1239     }
1240     if ( mySketchType == DIR_PER_Y)
1241     {
1242       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1243       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1244     }
1245     if ( mySketchType == DIR_TAN_LENGTH)
1246       myNewCommand = myNewCommand + "L " + QString::number(myLength);
1247     if ( mySketchType == DIR_TAN_X)
1248       myNewCommand = myNewCommand + "IX " + QString::number(myX);
1249     if ( mySketchType == DIR_TAN_Y)
1250       myNewCommand = myNewCommand + "IY " + QString::number(myY);
1251     if ( mySketchType == DIR_DXDY_LENGTH)
1252     {
1253       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1254       myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1255     }
1256     if ( mySketchType == DIR_DXDY_X)
1257     {
1258       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1259       myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1260     }
1261     if ( mySketchType == DIR_DXDY_Y)
1262     {
1263       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1264       myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1265     }
1266   }
1267   else if ( myConstructorId == 1 )
1268   {  // ARC
1269     if ( mySketchType == DIR_ANGLE_LENGTH)
1270     {
1271       myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1272       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1273     }
1274     if ( mySketchType == DIR_PER_LENGTH)
1275     {
1276       myNewCommand = myNewCommand + "R " + QString::number(90.0);
1277       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1278     }
1279     if ( mySketchType == DIR_TAN_LENGTH)
1280     {
1281       myNewCommand = myNewCommand + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1282     }
1283     if ( mySketchType == DIR_DXDY_LENGTH)
1284     {
1285       myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1286       myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1287     }
1288   }
1289   return myNewCommand;
1290 }
1291
1292 //=================================================================================
1293 // function : createOperation
1294 // purpose  :
1295 //=================================================================================
1296 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1297 {
1298   return getGeomEngine()->GetICurvesOperations( getStudyId() );
1299 }
1300
1301 //=================================================================================
1302 // function : isValid
1303 // purpose  :
1304 //=================================================================================
1305 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1306 {
1307   return true;
1308 }
1309
1310 //=================================================================================
1311 // function : execute
1312 // purpose  :
1313 //=================================================================================
1314 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1315 {
1316   if(mySketchState == FIRST_POINT) {
1317     myLastX2 = myX;
1318     myLastY2 = myY;
1319   }
1320   else {
1321     //Test if the current point is the same as the last one
1322     TopoDS_Shape myShape1, myShape2;
1323
1324     //Last Shape
1325     QString Command1 = myCommand.join( "" );
1326     Sketcher_Profile aProfile1 (Command1.ascii());
1327     if(aProfile1.IsDone())
1328       myShape1 = aProfile1.GetShape();
1329
1330     //Current Shape
1331     QString Command2 = Command1 + GetNewCommand();
1332     Sketcher_Profile aProfile2 (Command2.ascii());
1333     if(aProfile2.IsDone())
1334       myShape2 = aProfile2.GetShape();
1335
1336     if(myShape2.IsNull()) {
1337       //the current point is the same as the last one
1338       myLastX2 = myLastX1;
1339       myLastY2 = myLastY1;
1340     }
1341     else {
1342       TopoDS_Vertex V1, V2;
1343       gp_Pnt pt;
1344       if(myShape1.ShapeType() == TopAbs_VERTEX) {
1345         //the last shape is the first point
1346         pt = BRep_Tool::Pnt(TopoDS::Vertex(myShape1));
1347         myLastX1 = pt.X();
1348         myLastY1 = pt.Y();
1349       }
1350       else {
1351         TopExp::Vertices(TopoDS::Wire(myShape1), V1, V2);
1352         pt = BRep_Tool::Pnt(V2);
1353         myLastX1 = pt.X();
1354         myLastY1 = pt.Y();
1355       }
1356       TopExp::Vertices(TopoDS::Wire(myShape2), V1, V2);
1357       pt = BRep_Tool::Pnt(V2);
1358       myLastX2 = pt.X();
1359       myLastY2 = pt.Y();
1360     }
1361   }
1362
1363   QString cmd;
1364   if( ( mySketchState != FIRST_POINT &&
1365         myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1366     cmd = myCommand.join( "" );
1367
1368     if ( Group1Sel->isVisible() ) {
1369       Group1Sel->buttonApply->setEnabled(false);
1370       //Group1Sel->buttonApply->setFocus();
1371     }
1372     if ( Group1Spin->isVisible() ) {
1373       Group1Spin->buttonApply->setEnabled(false);
1374       //Group1Spin->buttonApply->setFocus();
1375     }
1376     if ( Group2Spin->isVisible() ) {
1377       Group2Spin->buttonApply->setEnabled(false);
1378       //Group2Spin->buttonApply->setFocus();
1379     }
1380     if ( Group3Spin->isVisible() ) {
1381       Group3Spin->buttonApply->setEnabled(false);
1382       //Group3Spin->buttonApply->setFocus();
1383     }
1384     if ( Group4Spin->isVisible() ) {
1385       Group4Spin->buttonApply->setEnabled(false);
1386       //Group4Spin->buttonApply->setFocus();
1387     }
1388   }
1389   else {
1390     cmd = myCommand.join( "" ) + GetNewCommand();
1391
1392     if ( Group1Sel->isVisible() ) {
1393       Group1Sel->buttonApply->setEnabled(true);
1394       //Group1Sel->buttonApply->setFocus();
1395     }
1396     if ( Group1Spin->isVisible() ) {
1397       Group1Spin->buttonApply->setEnabled(true);
1398       //Group1Spin->buttonApply->setFocus();
1399     }
1400     if ( Group2Spin->isVisible() ) {
1401       Group2Spin->buttonApply->setEnabled(true);
1402       //Group2Spin->buttonApply->setFocus();
1403     }
1404     if ( Group3Spin->isVisible() ) {
1405       Group3Spin->buttonApply->setEnabled(true);
1406       //Group3Spin->buttonApply->setFocus();
1407     }
1408     if ( Group4Spin->isVisible() ) {
1409       Group4Spin->buttonApply->setEnabled(true);
1410       //Group4Spin->buttonApply->setFocus();
1411     }
1412   }
1413
1414   gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1415   GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1416   WPlane->length(9);
1417   WPlane[0] = myWPlane.Location().X();
1418   WPlane[1] = myWPlane.Location().Y();
1419   WPlane[2] = myWPlane.Location().Z();
1420
1421   WPlane[3] = myWPlane.Direction().X();
1422   WPlane[4] = myWPlane.Direction().Y();
1423   WPlane[5] = myWPlane.Direction().Z();
1424
1425   WPlane[6] = myWPlane.XDirection().X();
1426   WPlane[7] = myWPlane.XDirection().Y();
1427   WPlane[8] = myWPlane.XDirection().Z();
1428
1429   GEOM::GEOM_Object_var anObj =
1430     GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.latin1(), WPlane );
1431
1432   if ( !anObj->_is_nil() )
1433     objects.push_back( anObj._retn() );
1434
1435   return true;
1436 }
1437
1438 //================================================================
1439 // Function : displayPreview
1440 // Purpose  : Method for displaying preview of resulting shape
1441 //            Redefined from GEOMBase_Helper.
1442 //================================================================
1443 void EntityGUI_SketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
1444                                             const bool            append,
1445                                             const bool            activate,
1446                                             const bool            update,
1447                                             const double          lineWidth )
1448 {
1449   // Set color for preview shape
1450   getDisplayer()->SetColor( Quantity_NOC_RED );
1451
1452   // set width of displayed shape
1453   getDisplayer()->SetWidth( lineWidth );
1454
1455   // Disable activation of selection
1456   getDisplayer()->SetToActivate( activate );
1457
1458   // Make a reference to GEOM_Object
1459   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1460   getDisplayer()->SetName( objStr.in() );
1461
1462   // Create wire from applayed object
1463   TopoDS_Shape anApplyedWire, aLastSegment;
1464   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1465     return;
1466
1467   // Build prs
1468   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1469   if ( aPrs != 0 && !aPrs->IsNull() )
1470     GEOMBase_Helper::displayPreview( aPrs, append, update );
1471
1472   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1473   aPrs = getDisplayer()->BuildPrs( aLastSegment );
1474   if ( aPrs != 0 && !aPrs->IsNull() )
1475     GEOMBase_Helper::displayPreview( aPrs, append, update );
1476
1477   getDisplayer()->UnsetName();
1478
1479   // Enable activation of displayed objects
1480   getDisplayer()->SetToActivate( true );
1481 }
1482
1483 //================================================================
1484 // Function : createShapes
1485 // Purpose  : Create applyed wire, and last segment from entry object
1486 //================================================================
1487 bool EntityGUI_SketcherDlg::createShapes( GEOM::GEOM_Object_ptr theObject,
1488                                           TopoDS_Shape&         theApplyedWire,
1489                                           TopoDS_Shape&         theLastSegment )
1490 {
1491   TopoDS_Shape aShape;
1492   if ( !GEOMBase::GetShape( theObject, aShape ) ||
1493        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
1494     return false;
1495
1496   if ( Group1Sel->isVisible()  && !Group1Sel->buttonApply->isEnabled()  ||
1497        Group1Spin->isVisible() && !Group1Spin->buttonApply->isEnabled() ||
1498        Group2Spin->isVisible() && !Group2Spin->buttonApply->isEnabled() ||
1499        Group3Spin->isVisible() && !Group3Spin->buttonApply->isEnabled() ||
1500        Group4Spin->isVisible() && !Group4Spin->buttonApply->isEnabled() )
1501   {
1502      theApplyedWire = aShape;
1503      return true;
1504   }
1505
1506   BRepBuilderAPI_MakeWire aBuilder;
1507   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1508   while( 1 )
1509   {
1510     TopoDS_Shape anEdge = anExp.Current();
1511     anExp.Next();
1512     if ( anExp.More() ) // i.e. non-last edge
1513       aBuilder.Add( TopoDS::Edge( anEdge ) );
1514     else
1515     {
1516       theLastSegment = anEdge;
1517       break;
1518     }
1519   }
1520
1521   if ( aBuilder.IsDone() )
1522     theApplyedWire = aBuilder.Shape();
1523
1524   return true;
1525 }
1526
1527 //=================================================================================
1528 // function : keyPressEvent()
1529 // purpose  :
1530 //=================================================================================
1531 void  EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1532 {
1533   QDialog::keyPressEvent( e );
1534   if ( e->isAccepted() )
1535     return;
1536
1537   if ( e->key() == Key_F1 )
1538     {
1539       e->accept();
1540       ClickOnHelp();
1541     }
1542 }