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 :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 ) ),
74 myGeometryGUI->SetActiveDialogBox(this);
76 if ( !name ) setName("EntityGUI_SketcherDlg");
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"));
83 GroupVal->close(TRUE);
84 GroupDest2->close(TRUE);
85 GroupDest3->close(TRUE);
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")));
91 setCaption(tr("GEOM_SKETCHER_TITLE"));
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"));
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"));
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"));
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"));
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 );
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);
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);
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);
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);
172 Layout5->addMultiCellWidget(GroupPt, 1, 1, 0, 1);
173 Layout5->addWidget(GroupD1, 1, 0);
174 Layout5->addWidget(GroupD2, 1, 1);
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 /***************************************************************/
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()));
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()));
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)));
211 connect(Group1Sel->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
212 connect(Group1Sel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
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)));
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)));
236 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
237 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
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);
255 //=================================================================================
256 // function : ~EntityGUI_SketcherDlg()
257 // purpose : Destroys the object and frees any allocated resources
258 //=================================================================================
259 EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
261 myGeometryGUI->SetActiveDialogBox( 0 );
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)
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();
277 } else if (object == Group2Spin->SpinBox_DX ||
278 object == Group2Spin->SpinBox_DY) {
279 Group2Spin->buttonApply->animateClick();
281 } else if (object == Group3Spin->SpinBox_DX ||
282 object == Group3Spin->SpinBox_DY ||
283 object == Group3Spin->SpinBox_DZ) {
284 Group3Spin->buttonApply->animateClick();
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();
296 return EntityGUI_Skeleton_QTD::eventFilter(object, event);
300 //=================================================================================
303 //=================================================================================
304 void EntityGUI_SketcherDlg::Init()
307 myEditCurrentArgument = Group1Sel->LineEdit1;
308 myCommand.append( "Sketcher" );
309 myUndoCommand.append( "Sketcher" );
311 mySketchState = FIRST_POINT;
312 globalSelection( GEOM_POINT );
319 myHelpFileName = "sketcher.htm";
321 /* Get setting of step value from file configuration */
322 double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
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);
336 /* displays Dialog */
337 GroupConstructors->setEnabled(false);
338 GroupDest1->setEnabled(false);
339 setEnabledUndo(false);
340 setEnabledRedo(false);
342 RadioButton1->setChecked(true);
347 GEOMBase_Helper::displayPreview();
351 //=================================================================================
352 // function : InitClick()
354 //=================================================================================
355 void EntityGUI_SketcherDlg::InitClick()
357 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
369 //=================================================================================
370 // function : TypeClicked()
371 // purpose : Radio button management
372 //=================================================================================
373 void EntityGUI_SketcherDlg::TypeClicked(int constructorId)
375 myConstructorId = constructorId;
376 if ( myConstructorId == 0 ) // SEGMENT
378 GroupD2->setEnabled(true);
379 RB_Dest1->setEnabled(true);
380 RB_Dest1->setChecked(true);
383 else if ( myConstructorId == 1 ) // ARC
385 GroupD2->setEnabled(false);
386 RB_Dest1->setEnabled(false);
387 RB_Dest2->setChecked(true);
393 //=================================================================================
394 // function : DestClicked()
395 // purpose : Radio button management
396 //=================================================================================
397 void EntityGUI_SketcherDlg::DestClicked( int constructorId )
403 if ( constructorId == 1 )
405 GroupPt->RB_Point1->setChecked(true);
407 PointClicked(1); // XY
409 else if ( constructorId == 0 )
411 GroupD1->RB_Dir11->setChecked(true);
414 Dir1Clicked(2); // Angle
419 //=================================================================================
420 // function : PointClicked()
421 // purpose : Radio button management
422 //=================================================================================
423 void EntityGUI_SketcherDlg::PointClicked(int constructorId)
427 // Get setting of step value from file configuration
428 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
430 if ( myConstructorId == 0 )
432 if ( constructorId == 1 )
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"));
440 Group2Spin->SpinBox_DX->SetValue(myX);
442 Group2Spin->SpinBox_DY->SetValue(myY);
444 Group2Spin->buttonApply->setFocus();
446 GEOMBase_Helper::displayPreview();
448 else if ( constructorId == 0 )
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"));
456 Group2Spin->SpinBox_DX->SetValue(myDX);
458 Group2Spin->SpinBox_DY->SetValue(myDY);
460 Group2Spin->buttonApply->setFocus();
462 GEOMBase_Helper::displayPreview();
464 else if ( constructorId == 2 )
466 mySketchType = PT_SEL;
467 myEditCurrentArgument = Group1Sel->LineEdit1;
468 connect(myGeometryGUI->getApp()->selectionMgr(),
469 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
471 Group1Sel->buttonApply->setFocus();
472 SelectionIntoArgument();
478 //=================================================================================
479 // function : Dir1Clicked()
480 // purpose : Radio button management
481 //=================================================================================
482 void EntityGUI_SketcherDlg::Dir1Clicked(int constructorId)
484 myConstructorDirId = constructorId;
485 GroupD2->RB_Dir21->setChecked(true);
490 //=================================================================================
491 // function : Dir2Clicked()
492 // purpose : Radio button management
493 //=================================================================================
494 void EntityGUI_SketcherDlg::Dir2Clicked(int constructorId)
499 // Get setting of step value from file configuration
500 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
502 if ( myConstructorId == 0 )
507 if ( myConstructorDirId == 2 )
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();
516 if ( constructorId == 2 )
518 mySketchType = DIR_ANGLE_LENGTH;
519 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_LENGTH2"));
520 Group2Spin->SpinBox_DY->SetValue(myLength);
522 else if ( constructorId == 0 )
524 mySketchType = DIR_ANGLE_X;
525 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_X3"));
526 Group2Spin->SpinBox_DY->SetValue(myX);
528 else if ( constructorId == 1 )
530 mySketchType = DIR_ANGLE_Y;
531 Group2Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y3"));
532 Group2Spin->SpinBox_DY->SetValue(myY);
535 else if ( myConstructorDirId == 0 )
538 Group1Spin->buttonApply->setFocus();
540 if ( constructorId == 2 )
542 mySketchType = DIR_PER_LENGTH;
543 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
544 Group1Spin->SpinBox_DX->SetValue(myLength);
546 else if ( constructorId == 0 )
548 mySketchType = DIR_PER_X;
549 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
550 Group1Spin->SpinBox_DX->SetValue(myX);
552 else if ( constructorId == 1 )
554 mySketchType = DIR_PER_Y;
555 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
556 Group1Spin->SpinBox_DX->SetValue(myY);
559 else if ( myConstructorDirId == 1 )
562 Group1Spin->buttonApply->setFocus();
564 if ( constructorId == 2 )
566 mySketchType = DIR_TAN_LENGTH;
567 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_LENGTH2"));
568 Group1Spin->SpinBox_DX->SetValue(myLength);
570 else if ( constructorId == 0 )
572 mySketchType = DIR_TAN_X;
573 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X3"));
574 Group1Spin->SpinBox_DX->SetValue(myX);
576 else if ( constructorId == 1 )
578 mySketchType = DIR_TAN_Y;
579 Group1Spin->TextLabel1->setText(tr("GEOM_SKETCHER_Y3"));
580 Group1Spin->SpinBox_DX->SetValue(myY);
583 else if ( myConstructorDirId == 3 )
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"));
591 Group3Spin->SpinBox_DX->SetValue(myDX);
593 Group3Spin->SpinBox_DY->SetValue(myDY);
595 Group3Spin->buttonApply->setFocus();
597 if ( constructorId == 2 )
599 mySketchType = DIR_DXDY_LENGTH;
600 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_LENGTH2"));
601 Group3Spin->SpinBox_DZ->SetValue(myLength);
603 else if ( constructorId == 0 )
605 mySketchType = DIR_DXDY_X;
606 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_X3"));
607 Group3Spin->SpinBox_DZ->SetValue(myX);
609 else if ( constructorId == 1 )
611 mySketchType = DIR_DXDY_Y;
612 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Y3"));
613 Group3Spin->SpinBox_DZ->SetValue(myY);
617 else if ( myConstructorId == 1 )
619 if ( myConstructorDirId == 2 )
621 if ( constructorId == 2 )
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);
632 Group3Spin->SpinBox_DY->SetValue(myRadius);
634 Group3Spin->SpinBox_DZ->SetValue(myLength);
636 Group3Spin->buttonApply->setFocus();
639 else if ( myConstructorDirId == 0 )
641 if ( constructorId == 2 )
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"));
649 Group2Spin->SpinBox_DX->SetValue(myRadius);
651 Group2Spin->SpinBox_DY->SetValue(myLength);
653 Group2Spin->buttonApply->setFocus();
656 else if ( myConstructorDirId == 1 )
658 if ( constructorId == 2 )
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"));
666 Group2Spin->SpinBox_DX->SetValue(myRadius);
668 Group2Spin->SpinBox_DY->SetValue(myLength);
670 Group2Spin->buttonApply->setFocus();
673 else if ( myConstructorDirId == 3 )
675 if ( constructorId == 2 )
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"));
683 Group4Spin->SpinBox_DX->SetValue(myDX);
685 Group4Spin->SpinBox_DY->SetValue(myDY);
687 Group4Spin->SpinBox_DZ->SetValue(myRadius);
689 Group4Spin->SpinBox_DS->SetValue(myLength);
691 Group4Spin->buttonApply->setFocus();
696 GEOMBase_Helper::displayPreview();
700 //=================================================================================
701 // function : ClickOnCancel()
703 //=================================================================================
704 void EntityGUI_SketcherDlg::ClickOnCancel()
710 //=================================================================================
711 // function : ClickOnEnd()
712 // purpose : connected to buttonEnd AND buttonClose
713 //=================================================================================
714 void EntityGUI_SketcherDlg::ClickOnEnd()
716 if ( sender() == buttonClose )
718 // Verify validity of commands
719 if ( myCommand.count() <= 2 )
721 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
722 tr( "GEOM_ERROR_STATUS" ), tr( "CANNOT_CLOSE" ), tr( "BUT_OK" ) );
726 QString Command = myCommand.join( "" ) + GetNewCommand();
727 Sketcher_Profile aProfile (Command.ascii());
729 Command = myCommand.join( "" );
730 aProfile = Sketcher_Profile(Command.ascii());
731 TopoDS_Shape myShape;
732 if ( aProfile.IsDone() )
733 myShape = aProfile.GetShape();
735 if(myShape.ShapeType() != TopAbs_VERTEX)
736 myCommand.append( ":WW" );
741 if( myCommand.size() > 2 )
748 //=================================================================================
749 // function : ClickOnApply()
751 //=================================================================================
752 bool EntityGUI_SketcherDlg::ClickOnApply()
754 ((QPushButton*)sender())->setFocus(); // to update value of currently edited spin-box (PAL11948)
756 myCommand.append( GetNewCommand() );
757 mySketchState = NEXT_POINT;
759 myUndoCommand.clear();
760 myUndoCommand.append( "Sketcher" );
762 GroupConstructors->setEnabled(true);
763 GroupDest1->setEnabled(true);
764 setEnabledUndo(true);
765 setEnabledRedo(false);
767 GEOMBase_Helper::displayPreview();
769 // Set focus to SpinBox_DX
770 if (sender() == Group1Spin->buttonApply) {
771 (Group1Spin->SpinBox_DX)->setFocus();
772 (Group1Spin->SpinBox_DX)->selectAll();
774 else if (sender() == Group2Spin->buttonApply) {
775 (Group2Spin->SpinBox_DX)->setFocus();
776 (Group2Spin->SpinBox_DX)->selectAll();
778 else if (sender() == Group3Spin->buttonApply) {
779 (Group3Spin->SpinBox_DX)->setFocus();
780 (Group3Spin->SpinBox_DX)->selectAll();
782 else if (sender() == Group4Spin->buttonApply) {
783 (Group4Spin->SpinBox_DX)->setFocus();
784 (Group4Spin->SpinBox_DX)->selectAll();
790 //=================================================================================
791 // function : ClickOnHelp()
793 //=================================================================================
794 void EntityGUI_SketcherDlg::ClickOnHelp()
796 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
798 app->onHelpContextModule(myGeometryGUI ? app->moduleName(myGeometryGUI->moduleName()) : QString(""), myHelpFileName);
802 platform = "winapplication";
804 platform = "application";
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"));
814 //=================================================================================
815 // function : ClickOnUndo()
817 //=================================================================================
818 void EntityGUI_SketcherDlg::ClickOnUndo()
820 myUndoCommand.append( myCommand.last() );
821 myCommand.pop_back();
823 if(myCommand.count() == 1) {
824 mySketchState = FIRST_POINT;
826 RadioButton1->setChecked(true);
829 GroupConstructors->setEnabled(false);
830 GroupDest1->setEnabled(false);
831 setEnabledUndo(false);
834 setEnabledRedo(true);
836 GEOMBase_Helper::displayPreview();
839 //=================================================================================
840 // function : ClickOnRedo()
842 //=================================================================================
843 void EntityGUI_SketcherDlg::ClickOnRedo()
845 myCommand.append( myUndoCommand.last() );
846 myUndoCommand.pop_back();
848 mySketchState = NEXT_POINT;
850 GroupConstructors->setEnabled(true);
851 GroupDest1->setEnabled(true);
852 setEnabledUndo(true);
854 if(myUndoCommand.count() == 1)
855 setEnabledRedo(false);
857 GEOMBase_Helper::displayPreview();
860 //=================================================================================
861 // function : setEnabledUndo()
863 //=================================================================================
864 void EntityGUI_SketcherDlg::setEnabledUndo(bool value)
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);
873 //=================================================================================
874 // function : setEnabledRedo()
876 //=================================================================================
877 void EntityGUI_SketcherDlg::setEnabledRedo(bool value)
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);
886 //=================================================================================
887 // function : SelectionIntoArgument()
888 // purpose : Called when selection as changed
889 //=================================================================================
890 void EntityGUI_SketcherDlg::SelectionIntoArgument()
892 myEditCurrentArgument->setText("");
896 int nbSel = IObjectCount();
897 if ( nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1 )
899 Standard_Boolean aRes = Standard_False;
900 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
901 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
903 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_VERTEX ) ) {
905 gp_Ax3 aWPlane = myGeometryGUI->GetWorkingPlane();
907 aTrans.SetTransformation(aWPlane);
908 BRepBuilderAPI_Transform aTransformation(aShape, aTrans, Standard_False);
909 aShape = aTransformation.Shape();
912 if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
915 Group1Sel->LineEdit1->setText( GEOMBase::GetName( aSelectedObject ) );
921 GEOMBase_Helper::displayPreview();
925 //=================================================================================
926 // function : SetEditCurrentArgument()
928 //=================================================================================
929 void EntityGUI_SketcherDlg::SetEditCurrentArgument()
931 if ( sender() == Group1Sel->PushButton1 )
933 myEditCurrentArgument = Group1Sel->LineEdit1;
934 myEditCurrentArgument->setFocus();
936 SelectionIntoArgument();
940 //=================================================================================
941 // function : LineEditReturnPressed()
943 //=================================================================================
944 void EntityGUI_SketcherDlg::LineEditReturnPressed()
946 if ( sender() == Group1Sel->LineEdit1 )
948 myEditCurrentArgument = Group1Sel->LineEdit1;
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);
961 //=================================================================================
962 // function : DeactivateActiveDialog()
964 //=================================================================================
965 void EntityGUI_SketcherDlg::DeactivateActiveDialog()
967 //myGeometryGUI->SetState( -1 );
971 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
972 myGeometryGUI->SetActiveDialogBox(0);
976 //=================================================================================
977 // function : ActivateThisDialog()
979 //=================================================================================
980 void EntityGUI_SketcherDlg::ActivateThisDialog()
982 myGeometryGUI->EmitSignalDeactivateDialog();
984 myGeometryGUI->SetActiveDialogBox((QDialog*)this);
986 connect(myGeometryGUI->getApp()->selectionMgr(),
987 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
989 //myGeometryGUI->SetState( 0 );
990 globalSelection( GEOM_POINT );
992 myEditCurrentArgument = Group1Sel->LineEdit1;
993 myEditCurrentArgument->setFocus();
995 GEOMBase_Helper::displayPreview();
999 //=================================================================================
1000 // function : enterEvent [REDEFINED]
1002 //=================================================================================
1003 void EntityGUI_SketcherDlg::enterEvent(QEvent* e)
1005 if ( !GroupConstructors->isEnabled())
1006 ActivateThisDialog();
1010 //=================================================================================
1011 // function : closeEvent()
1013 //=================================================================================
1014 void EntityGUI_SketcherDlg::closeEvent(QCloseEvent* e)
1016 //myGeometryGUI->SetState( -1 );
1017 disconnect(myGeometryGUI->getApp()->selectionMgr(), 0, this, 0);
1018 QDialog::closeEvent( e );
1022 //=================================================================================
1023 // function : ValueChangedInSpinBox()
1025 //=================================================================================
1026 void EntityGUI_SketcherDlg::ValueChangedInSpinBox(double newValue)
1028 QObject* send = (QObject*)sender();
1029 Standard_Real vx, vy, vz, vs;
1030 vx = vy = vz = vs = 0.0;
1032 if ( send == Group1Spin->SpinBox_DX)
1036 else if ( send == Group2Spin->SpinBox_DX )
1039 vy = Group2Spin->SpinBox_DY->GetValue();
1041 else if ( send == Group2Spin->SpinBox_DY)
1043 vx = Group2Spin->SpinBox_DX->GetValue();
1046 else if ( send == Group3Spin->SpinBox_DX)
1049 vy = Group3Spin->SpinBox_DY->GetValue();
1050 vz = Group3Spin->SpinBox_DZ->GetValue();
1052 else if ( send == Group3Spin->SpinBox_DY)
1054 vx = Group3Spin->SpinBox_DX->GetValue();
1056 vz = Group3Spin->SpinBox_DZ->GetValue();
1058 else if ( send == Group3Spin->SpinBox_DZ)
1060 vx = Group3Spin->SpinBox_DX->GetValue();
1061 vy = Group3Spin->SpinBox_DY->GetValue();
1064 else if ( send == Group4Spin->SpinBox_DX)
1067 vy = Group4Spin->SpinBox_DY->GetValue();
1068 vz = Group4Spin->SpinBox_DZ->GetValue();
1069 vs = Group4Spin->SpinBox_DS->GetValue();
1071 else if ( send == Group4Spin->SpinBox_DY)
1073 vx = Group4Spin->SpinBox_DX->GetValue();
1075 vz = Group4Spin->SpinBox_DZ->GetValue();
1076 vs = Group4Spin->SpinBox_DS->GetValue();
1078 else if ( send == Group4Spin->SpinBox_DZ)
1080 vx = Group4Spin->SpinBox_DX->GetValue();
1081 vy = Group4Spin->SpinBox_DY->GetValue();
1083 vs = Group4Spin->SpinBox_DS->GetValue();
1085 else if ( send == Group4Spin->SpinBox_DS)
1087 vx = Group4Spin->SpinBox_DX->GetValue();
1088 vy = Group4Spin->SpinBox_DY->GetValue();
1089 vz = Group4Spin->SpinBox_DZ->GetValue();
1093 if ( myConstructorId == 0 )
1095 if ( mySketchType == PT_ABS)
1100 else if ( mySketchType == PT_RELATIVE)
1105 else if ( mySketchType == DIR_ANGLE_LENGTH)
1110 else if ( mySketchType == DIR_ANGLE_X)
1115 else if ( mySketchType == DIR_ANGLE_Y)
1120 else if ( mySketchType == DIR_PER_LENGTH)
1124 else if ( mySketchType == DIR_PER_X)
1128 else if ( mySketchType == DIR_PER_Y)
1132 else if ( mySketchType == DIR_TAN_LENGTH)
1136 else if ( mySketchType == DIR_TAN_X)
1140 else if ( mySketchType == DIR_TAN_Y)
1144 else if ( mySketchType == DIR_DXDY_LENGTH)
1150 else if ( mySketchType == DIR_DXDY_X)
1156 else if ( mySketchType == DIR_DXDY_Y)
1163 else if ( myConstructorId == 1 )
1165 if ( mySketchType == DIR_ANGLE_LENGTH)
1171 else if ( mySketchType == DIR_PER_LENGTH)
1176 else if ( mySketchType == DIR_TAN_LENGTH)
1181 else if ( mySketchType == DIR_DXDY_LENGTH)
1190 GEOMBase_Helper::displayPreview();
1194 //=================================================================================
1195 // function : GetNewCommand()
1196 // purpose : Build the new command with context
1197 //=================================================================================
1198 QString EntityGUI_SketcherDlg::GetNewCommand()
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;
1209 if ( myConstructorId == 0 )
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)
1217 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1218 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1220 if ( mySketchType == DIR_ANGLE_X)
1222 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1223 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1225 if ( mySketchType == DIR_ANGLE_Y)
1227 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1228 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1230 if ( mySketchType == DIR_PER_LENGTH)
1232 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1233 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1235 if ( mySketchType == DIR_PER_X)
1237 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1238 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1240 if ( mySketchType == DIR_PER_Y)
1242 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1243 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
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)
1253 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1254 myNewCommand = myNewCommand + ":" + "L " + QString::number(myLength);
1256 if ( mySketchType == DIR_DXDY_X)
1258 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1259 myNewCommand = myNewCommand + ":" + "IX " + QString::number(myX);
1261 if ( mySketchType == DIR_DXDY_Y)
1263 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1264 myNewCommand = myNewCommand + ":" + "IY " + QString::number(myY);
1267 else if ( myConstructorId == 1 )
1269 if ( mySketchType == DIR_ANGLE_LENGTH)
1271 myNewCommand = myNewCommand + "R " + QString::number(myAngle);
1272 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1274 if ( mySketchType == DIR_PER_LENGTH)
1276 myNewCommand = myNewCommand + "R " + QString::number(90.0);
1277 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1279 if ( mySketchType == DIR_TAN_LENGTH)
1281 myNewCommand = myNewCommand + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1283 if ( mySketchType == DIR_DXDY_LENGTH)
1285 myNewCommand = myNewCommand + "D " + QString::number(myDX) + " " + QString::number(myDY);
1286 myNewCommand = myNewCommand + ":" + "C " + QString::number(myRadius) + " " + QString::number(myLength);
1289 return myNewCommand;
1292 //=================================================================================
1293 // function : createOperation
1295 //=================================================================================
1296 GEOM::GEOM_IOperations_ptr EntityGUI_SketcherDlg::createOperation()
1298 return getGeomEngine()->GetICurvesOperations( getStudyId() );
1301 //=================================================================================
1302 // function : isValid
1304 //=================================================================================
1305 bool EntityGUI_SketcherDlg::isValid( QString& msg )
1310 //=================================================================================
1311 // function : execute
1313 //=================================================================================
1314 bool EntityGUI_SketcherDlg::execute( ObjectList& objects )
1316 if(mySketchState == FIRST_POINT) {
1321 //Test if the current point is the same as the last one
1322 TopoDS_Shape myShape1, myShape2;
1325 QString Command1 = myCommand.join( "" );
1326 Sketcher_Profile aProfile1 (Command1.ascii());
1327 if(aProfile1.IsDone())
1328 myShape1 = aProfile1.GetShape();
1331 QString Command2 = Command1 + GetNewCommand();
1332 Sketcher_Profile aProfile2 (Command2.ascii());
1333 if(aProfile2.IsDone())
1334 myShape2 = aProfile2.GetShape();
1336 if(myShape2.IsNull()) {
1337 //the current point is the same as the last one
1338 myLastX2 = myLastX1;
1339 myLastY2 = myLastY1;
1342 TopoDS_Vertex V1, V2;
1344 if(myShape1.ShapeType() == TopAbs_VERTEX) {
1345 //the last shape is the first point
1346 pt = BRep_Tool::Pnt(TopoDS::Vertex(myShape1));
1351 TopExp::Vertices(TopoDS::Wire(myShape1), V1, V2);
1352 pt = BRep_Tool::Pnt(V2);
1356 TopExp::Vertices(TopoDS::Wire(myShape2), V1, V2);
1357 pt = BRep_Tool::Pnt(V2);
1364 if( ( mySketchState != FIRST_POINT &&
1365 myLastX1 == myLastX2 && myLastY1 == myLastY2 ) || myIsAllAdded ) {
1366 cmd = myCommand.join( "" );
1368 if ( Group1Sel->isVisible() ) {
1369 Group1Sel->buttonApply->setEnabled(false);
1370 //Group1Sel->buttonApply->setFocus();
1372 if ( Group1Spin->isVisible() ) {
1373 Group1Spin->buttonApply->setEnabled(false);
1374 //Group1Spin->buttonApply->setFocus();
1376 if ( Group2Spin->isVisible() ) {
1377 Group2Spin->buttonApply->setEnabled(false);
1378 //Group2Spin->buttonApply->setFocus();
1380 if ( Group3Spin->isVisible() ) {
1381 Group3Spin->buttonApply->setEnabled(false);
1382 //Group3Spin->buttonApply->setFocus();
1384 if ( Group4Spin->isVisible() ) {
1385 Group4Spin->buttonApply->setEnabled(false);
1386 //Group4Spin->buttonApply->setFocus();
1390 cmd = myCommand.join( "" ) + GetNewCommand();
1392 if ( Group1Sel->isVisible() ) {
1393 Group1Sel->buttonApply->setEnabled(true);
1394 //Group1Sel->buttonApply->setFocus();
1396 if ( Group1Spin->isVisible() ) {
1397 Group1Spin->buttonApply->setEnabled(true);
1398 //Group1Spin->buttonApply->setFocus();
1400 if ( Group2Spin->isVisible() ) {
1401 Group2Spin->buttonApply->setEnabled(true);
1402 //Group2Spin->buttonApply->setFocus();
1404 if ( Group3Spin->isVisible() ) {
1405 Group3Spin->buttonApply->setEnabled(true);
1406 //Group3Spin->buttonApply->setFocus();
1408 if ( Group4Spin->isVisible() ) {
1409 Group4Spin->buttonApply->setEnabled(true);
1410 //Group4Spin->buttonApply->setFocus();
1414 gp_Ax3 myWPlane = myGeometryGUI->GetWorkingPlane();
1415 GEOM::ListOfDouble_var WPlane = new GEOM::ListOfDouble;
1417 WPlane[0] = myWPlane.Location().X();
1418 WPlane[1] = myWPlane.Location().Y();
1419 WPlane[2] = myWPlane.Location().Z();
1421 WPlane[3] = myWPlane.Direction().X();
1422 WPlane[4] = myWPlane.Direction().Y();
1423 WPlane[5] = myWPlane.Direction().Z();
1425 WPlane[6] = myWPlane.XDirection().X();
1426 WPlane[7] = myWPlane.XDirection().Y();
1427 WPlane[8] = myWPlane.XDirection().Z();
1429 GEOM::GEOM_Object_var anObj =
1430 GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSketcher( cmd.latin1(), WPlane );
1432 if ( !anObj->_is_nil() )
1433 objects.push_back( anObj._retn() );
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,
1445 const bool activate,
1447 const double lineWidth )
1449 // Set color for preview shape
1450 getDisplayer()->SetColor( Quantity_NOC_RED );
1452 // set width of displayed shape
1453 getDisplayer()->SetWidth( lineWidth );
1455 // Disable activation of selection
1456 getDisplayer()->SetToActivate( activate );
1458 // Make a reference to GEOM_Object
1459 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
1460 getDisplayer()->SetName( objStr.in() );
1462 // Create wire from applayed object
1463 TopoDS_Shape anApplyedWire, aLastSegment;
1464 if ( !createShapes( object, anApplyedWire, aLastSegment ) )
1468 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
1469 if ( aPrs != 0 && !aPrs->IsNull() )
1470 GEOMBase_Helper::displayPreview( aPrs, append, update );
1472 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
1473 aPrs = getDisplayer()->BuildPrs( aLastSegment );
1474 if ( aPrs != 0 && !aPrs->IsNull() )
1475 GEOMBase_Helper::displayPreview( aPrs, append, update );
1477 getDisplayer()->UnsetName();
1479 // Enable activation of displayed objects
1480 getDisplayer()->SetToActivate( true );
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 )
1491 TopoDS_Shape aShape;
1492 if ( !GEOMBase::GetShape( theObject, aShape ) ||
1493 aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
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() )
1502 theApplyedWire = aShape;
1506 BRepBuilderAPI_MakeWire aBuilder;
1507 TopExp_Explorer anExp( aShape, TopAbs_EDGE );
1510 TopoDS_Shape anEdge = anExp.Current();
1512 if ( anExp.More() ) // i.e. non-last edge
1513 aBuilder.Add( TopoDS::Edge( anEdge ) );
1516 theLastSegment = anEdge;
1521 if ( aBuilder.IsDone() )
1522 theApplyedWire = aBuilder.Shape();
1527 //=================================================================================
1528 // function : keyPressEvent()
1530 //=================================================================================
1531 void EntityGUI_SketcherDlg::keyPressEvent( QKeyEvent* e )
1533 QDialog::keyPressEvent( e );
1534 if ( e->isAccepted() )
1537 if ( e->key() == Key_F1 )