1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // GEOM GEOMGUI : GUI for Geometry component
20 // File : EntityGUI_3DSketcherDlg.cxx
25 #include <boost/lexical_cast.hpp>
27 #include "EntityGUI_3DSketcherDlg.h"
28 #include "EntityGUI_Widgets.h"
29 #include <SalomeApp_DoubleSpinBox.h>
32 #include <GeometryGUI.h>
33 #include <Precision.hxx>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_ViewWindow.h>
41 #include <SUIT_ViewManager.h>
43 #include <SOCC_ViewModel.h>
44 #include <SalomeApp_Application.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
48 #include <SalomeApp_Tools.h>
52 #include <TColStd_IndexedMapOfInteger.hxx>
53 #include <BRepBuilderAPI_MakeVertex.hxx>
54 #include <BRepBuilderAPI_MakePolygon.hxx>
55 #include <BRepBuilderAPI_MakeEdge.hxx>
57 #include <AIS_Trihedron.hxx>
58 #include <AIS_AngleDimension.hxx>
59 #include <AIS_LengthDimension.hxx>
60 #include <AIS_Drawer.hxx>
61 #include <Geom_Axis2Placement.hxx>
62 #include <Geom_Plane.hxx>
63 #include <SelectMgr_Selection.hxx>
64 #include <gce_MakePln.hxx>
65 #include <Prs3d_AngleAspect.hxx>
66 #include <Prs3d_LineAspect.hxx>
67 #include <Prs3d_LengthAspect.hxx>
69 // This include must be *AFTER* SOCC_ViewModel.h because
70 // of the constant ROTATE which is a #define in
71 // GEOMImpl_Types.hxx and an enum in SOCC_ViewModel.h
72 #include <GEOMImpl_Types.hxx>
92 Locker(bool& l) : myLock(l) { myLock = true; }
93 ~Locker() { myLock = false; }
98 //=================================================================================
99 // class : EntityGUI_3DSketcherDlg()
100 // purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
101 // name 'name' and widget flags set to 'f'.
102 // The dialog will by default be modeless, unless you set 'modal' to
103 // TRUE to construct a modal dialog.
104 //=================================================================================
105 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
106 bool modal, Qt::WindowFlags fl,
107 const double lineWidth)
108 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
111 myLineWidth(lineWidth),
112 myGeometryGUI(theGeometryGUI),
114 // myLastAngleNormal()
116 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
117 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
118 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REDO")));
119 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_3DSKETCH")));
121 setWindowTitle(tr("GEOM_3DSKETCHER_TITLE"));
123 /***************************************************************/
125 mainFrame()->GroupConstructors->setTitle(tr("GEOM_3DSKETCHER"));
126 mainFrame()->RadioButton1->setIcon(image3);;
127 mainFrame()->RadioButton2->close();
128 mainFrame()->RadioButton3->close();
130 GroupType = new DlgRef_3Radio(centralWidget());
131 GroupType->GroupBox1->setTitle(tr("GEOM_COORDINATES_TYPE"));
132 GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
133 GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
134 GroupType->RadioButton3->setText(tr("Angles")); //TODO translation
135 // GroupType->RadioButton3->close();
136 myTypeGroup = new QButtonGroup(this);
137 myTypeGroup->addButton(GroupType->RadioButton1, 0);
138 myTypeGroup->addButton(GroupType->RadioButton2, 1);
139 myTypeGroup->addButton(GroupType->RadioButton3, 2);
141 Group3Spin = new EntityGUI_3Spin(centralWidget());
142 Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
143 Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
144 Group3Spin->buttonUndo->setIcon(image1);
145 Group3Spin->buttonRedo->setIcon(image2);
146 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
147 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
148 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
150 GroupAngles = new EntityGUI_Angles(centralWidget());
151 GroupAngles->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
152 GroupAngles->buttonUndo->setIcon(image1);
153 GroupAngles->buttonRedo->setIcon(image2);
154 GroupAngles->checkBox->setText(tr("Angle 2")); //TODO translation
156 GroupControls = new EntityGUI_Controls(centralWidget());
157 GroupControls->GroupBox1->setTitle(tr("GEOM_CONTROLS"));
158 GroupControls->CheckBox1->setText(tr("Show length dimensions")); //TODO translation
159 GroupControls->CheckBox2->setText(tr("Show angle dimensions")); //TODO translation
160 GroupControls->CheckBox3->setText(tr("Show start/end point coordinates")); //TODO translation
161 GroupControls->lineEdit_1->setReadOnly(true);
162 GroupControls->lineEdit_2->setReadOnly(true);
163 GroupControls->lineEdit_3->setReadOnly(true);
164 GroupControls->lineEdit_4->setReadOnly(true);
165 GroupControls->lineEdit_5->setReadOnly(true);
166 GroupControls->lineEdit_6->setReadOnly(true);
167 GroupControls->label_1->setText(tr("X:"));
168 GroupControls->label_2->setText(tr("Y:"));
169 GroupControls->label_3->setText(tr("Z:"));
170 GroupControls->label_4->setText(tr("X:"));
171 GroupControls->label_5->setText(tr("Y:"));
172 GroupControls->label_6->setText(tr("Z:"));
174 buttonOk()->setText(tr("GEOM_BUT_END_SKETCH"));
175 buttonApply()->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
177 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
178 layout->setMargin(0); layout->setSpacing(6);
179 layout->addWidget(GroupType);
180 layout->addWidget(Group3Spin);
181 layout->addWidget(GroupAngles);
182 layout->addWidget(GroupControls);
184 setHelpFileName("create_3dsketcher_page.html");
190 //=================================================================================
191 // function : ~EntityGUI_3DSketcherDlg()
192 // purpose : Destroys the object and frees any allocated resources
193 //=================================================================================
194 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
196 myGeomGUI->SetActiveDialogBox(0);
199 //=================================================================================
202 //=================================================================================
203 void EntityGUI_3DSketcherDlg::Init()
209 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
210 myAnglePrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
211 myLengthPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
214 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
215 // globalSelection(GEOM_PREVIEW);
216 // setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
218 /* Get setting of step value from file configuration */
219 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
221 /* min, max, step and decimals for spin boxes */
222 initSpinBox(Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
223 initSpinBox(Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
224 initSpinBox(Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
226 initSpinBox(GroupAngles->SpinBox_DA , -180.0, 180.0, step, "angular_precision");
227 initSpinBox(GroupAngles->SpinBox_DA2, -90.0, 90.0, step, "angular_precision");
228 initSpinBox(GroupAngles->SpinBox_DL , COORD_MIN, COORD_MAX, step, "length_precision");
230 Group3Spin->SpinBox_DX->setValue(0.0);
231 Group3Spin->SpinBox_DY->setValue(0.0);
232 Group3Spin->SpinBox_DZ->setValue(0.0);
234 GroupAngles->SpinBox_DA->setValue(0.0);
235 GroupAngles->SpinBox_DA2->setValue(0.0);
236 GroupAngles->SpinBox_DL->setValue(0.0);
238 GroupAngles->radioButton_1->setChecked(true);
239 GroupAngles->checkBox->setChecked(false);
240 GroupAngles->SpinBox_DA2->setEnabled(false);
242 GroupControls->CheckBox1->setChecked(true);
243 GroupControls->CheckBox2->setChecked(true);
244 GroupControls->CheckBox3->setChecked(true);
246 isLengthVisible = true;
247 isAngleVisible = true;
251 /* signals and slots connections */
252 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
253 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
255 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
258 connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
259 connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
261 connect(GroupAngles->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
262 connect(GroupAngles->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
263 connect(GroupAngles->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
265 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
267 connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
268 connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
269 connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
271 connect(GroupAngles->SpinBox_DA, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
272 connect(GroupAngles->SpinBox_DA2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
273 connect(GroupAngles->SpinBox_DL, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
275 connect(GroupAngles->radioButton_1, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
276 connect(GroupAngles->radioButton_2, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
277 connect(GroupAngles->radioButton_3, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
279 connect(GroupAngles->checkBox, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
280 connect(GroupControls->CheckBox1, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
281 connect(GroupControls->CheckBox2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
282 connect(GroupControls->CheckBox3, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
284 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
286 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
287 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
289 initName(tr("GEOM_3DSKETCHER"));
291 GroupControls->CheckBox3->click();
293 UpdateButtonsState();
294 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
297 //=================================================================================
298 // function : TypeClicked()
299 // purpose : Radio button management
300 //=================================================================================
301 void EntityGUI_3DSketcherDlg::TypeClicked (int mode)
303 if (mode == myMode) return;
308 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
309 Group3Spin->SpinBox_DX->blockSignals(true);
310 Group3Spin->SpinBox_DY->blockSignals(true);
311 Group3Spin->SpinBox_DZ->blockSignals(true);
313 // Get setting of step value from file configuration
314 XYZ xyz = getLastPoint();
316 Group3Spin->SpinBox_DX->text().toDouble(&okx);
317 Group3Spin->SpinBox_DY->text().toDouble(&oky);
318 Group3Spin->SpinBox_DZ->text().toDouble(&okz);
320 if (mode == 0) { // XYZ
321 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
322 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
323 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
326 if (okx) Group3Spin->SpinBox_DX->setValue(xyz.x + Group3Spin->SpinBox_DX->value());
327 if (oky) Group3Spin->SpinBox_DY->setValue(xyz.y + Group3Spin->SpinBox_DY->value());
328 if (okz) Group3Spin->SpinBox_DZ->setValue(xyz.z + Group3Spin->SpinBox_DZ->value());
330 Group3Spin->buttonApply->setFocus();
332 else if (mode == 1) { // DXDYDZ
333 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
334 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
335 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_DZ2"));
338 if (okx) Group3Spin->SpinBox_DX->setValue(Group3Spin->SpinBox_DX->value() - xyz.x);
339 if (oky) Group3Spin->SpinBox_DY->setValue(Group3Spin->SpinBox_DY->value() - xyz.y);
340 if (okz) Group3Spin->SpinBox_DZ->setValue(Group3Spin->SpinBox_DZ->value() - xyz.z);
342 Group3Spin->buttonApply->setFocus();
344 else if (mode == 2) { // Angles and Length
347 GroupAngles->buttonApply->setFocus();
350 Group3Spin->SpinBox_DX->blockSignals(blocked);
351 Group3Spin->SpinBox_DY->blockSignals(blocked);
352 Group3Spin->SpinBox_DZ->blockSignals(blocked);
357 resize(minimumSizeHint());
359 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
362 //=================================================================================
363 // function : ClickOnAddPoint()
364 // purpose : called when the point coordinates is Applyed
365 //=================================================================================
366 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
374 // Display and store angle dimensions interactive objects in Prs
375 if (GroupType->RadioButton3->isChecked()) // ANGLES
377 double anAngle2 = 0.0;
378 if (GroupAngles->checkBox->isChecked())
379 anAngle2 = GroupAngles->SpinBox_DA2->value();
381 // Store angle dimensions
382 displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2,
383 GroupAngles->SpinBox_DL->value(), myOrientation, /*store =*/true);
384 // Store length dimensions
385 displayLength(GroupAngles->SpinBox_DL->value(), /*store =*/true, /*type=*/myPrsType);
388 // Display and store store length dimension interactive object in Prs
389 if (GroupType->RadioButton1->isChecked() || // ABSOLUTE or RELATIVE coordinates
390 GroupType->RadioButton2->isChecked())
392 displayLength(-1, /*store=*/true);
395 myPointsList.append(getCurrentPoint());
396 myPrsTypeList.push_back(myPrsType);
400 myPrsTypeRedoList.clear();
401 myLengthIORedoList.Clear();
402 myAngleIORedoList.Clear();
406 Group3Spin->SpinBox_DX->setValue(0.0);
407 Group3Spin->SpinBox_DY->setValue(0.0);
408 Group3Spin->SpinBox_DZ->setValue(0.0);
410 else if (myMode == 2)
412 GroupAngles->SpinBox_DA->setValue(0.0);
413 GroupAngles->SpinBox_DL->setValue(0.0);
414 GroupAngles->SpinBox_DA2->setValue(0.0);
417 UpdatePointCoordinates();
419 UpdateButtonsState();
420 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
423 //=================================================================================
424 // function : UpdateButtonsState()
426 //=================================================================================
427 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
429 if (myPointsList.count() == 0) GroupType->RadioButton1->click();
430 GroupType->RadioButton2->setEnabled(myPointsList.count() > 0);
431 GroupType->RadioButton3->setEnabled(myPointsList.count() > 0);
432 Group3Spin->buttonUndo->setEnabled(myPointsList.count() > 0);
433 Group3Spin->buttonRedo->setEnabled(myRedoList.count() > 0);
434 GroupAngles->buttonUndo->setEnabled(myPointsList.count() > 0);
435 GroupAngles->buttonRedo->setEnabled(myRedoList.count() > 0);
438 //=================================================================================
439 // function : UpdatePointCoordinates()
440 // purpose :Update point coordinates in the control groupbox
441 //=================================================================================
442 void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
444 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
445 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
447 if (myPointsList.count() == 0)
449 GroupControls->lineEdit_1->setText("");
450 GroupControls->lineEdit_2->setText("");
451 GroupControls->lineEdit_3->setText("");
453 GroupControls->lineEdit_4->setText("");
454 GroupControls->lineEdit_5->setText("");
455 GroupControls->lineEdit_6->setText("");
457 else if (myPointsList.count() == 1)
459 GroupControls->lineEdit_1->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
460 GroupControls->lineEdit_2->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
461 GroupControls->lineEdit_3->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
463 GroupControls->lineEdit_4->setText("");
464 GroupControls->lineEdit_5->setText("");
465 GroupControls->lineEdit_6->setText("");
469 GroupControls->lineEdit_4->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
470 GroupControls->lineEdit_5->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
471 GroupControls->lineEdit_6->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
476 //=================================================================================
477 // function : ClickOnUndo()
479 //=================================================================================
480 void EntityGUI_3DSketcherDlg::ClickOnUndo()
482 if (myPointsList.count() > 0) {
483 myRedoList.append(myPointsList.takeLast());
484 UpdateButtonsState();
485 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
487 // Erase dimensions presentations
488 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
489 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
490 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
492 if (myPrsTypeList.back() != NONE)
494 // Remove last prepended IO
495 removeLastIOFromPrs(TYPE_LENGTH);
497 if (myPrsTypeList.back() == TYPE_ANGLE ||
498 myPrsTypeList.back() == TYPE_TWO_ANGLES)
500 // Remove first Angle IO from presentation
501 removeLastIOFromPrs(TYPE_ANGLE);
502 if (myPrsTypeList.back() == TYPE_TWO_ANGLES)
504 // Remove second Angle IO
505 removeLastIOFromPrs(TYPE_ANGLE);
509 // Erase last action type and store it in redo list
510 myPrsTypeRedoList.push_back(myPrsTypeList.back());
511 myPrsTypeList.pop_back();
513 // Display modified presentation
515 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
517 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
519 // Update of point coordinates in the control groupbox
520 UpdatePointCoordinates();
526 //=================================================================================
527 // function : ClickOnRedo()
529 //=================================================================================
530 void EntityGUI_3DSketcherDlg::ClickOnRedo()
532 if (myRedoList.count() > 0) {
533 myPointsList.append(myRedoList.takeLast());
534 UpdateButtonsState();
535 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
537 // Erase dimensions presentations
538 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
539 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
540 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
542 if (myPrsTypeRedoList.back() != NONE)
543 restoreLastIOToPrs(TYPE_LENGTH);
545 if (myPrsTypeRedoList.back() == TYPE_ANGLE ||
546 myPrsTypeRedoList.back() == TYPE_TWO_ANGLES)
548 // Add a first IO from the Redo list
549 restoreLastIOToPrs(TYPE_ANGLE);
550 if (myPrsTypeRedoList.back() == TYPE_TWO_ANGLES)
552 // Add a second IO from the Redo list
553 restoreLastIOToPrs(TYPE_ANGLE);
557 // Record last prs type
558 myPrsTypeList.push_back(myPrsTypeRedoList.back());
559 myPrsTypeRedoList.pop_back();
561 // Display modified presentation
563 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
565 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
567 // Update of point coordinates in the control groupbox
568 UpdatePointCoordinates();
574 //=================================================================================
575 // function : removeLastIO()
577 //=================================================================================
578 void EntityGUI_3DSketcherDlg::removeLastIOFromPrs (int type)
580 AIS_ListOfInteractive anIOList;
582 if (type == TYPE_LENGTH)
584 myLengthPrs->GetObjects(anIOList);
585 myLengthIORedoList.Prepend(anIOList.First()); // Store last prepended Length IO in redo list
586 myLengthPrs->RemoveFirst(); // Remove it from myLengthPrs
588 if (type == TYPE_ANGLE)
590 myAnglePrs->GetObjects(anIOList);
591 myAngleIORedoList.Prepend(anIOList.First()); // Store last prepended Angle IO in redo list
592 myAnglePrs->RemoveFirst(); // Remove it from myAnglePrs
596 //=================================================================================
597 // function : restoreLastIO()
599 //=================================================================================
600 void EntityGUI_3DSketcherDlg::restoreLastIOToPrs (int type)
602 if (type == TYPE_LENGTH)
604 myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
605 myLengthIORedoList.RemoveFirst(); // Remove it from redo list
607 if (type == TYPE_ANGLE)
609 myAnglePrs->PrependObject(myAngleIORedoList.First()); // Restore last removed IO
610 myAngleIORedoList.RemoveFirst(); // Remove it from redo list
614 //=================================================================================
615 // function : SelectionIntoArgument()
616 // purpose : Called when selection as changed
617 //=================================================================================
618 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
620 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
621 SALOME_ListIO aSelList;
622 aSelMgr->selectedObjects(aSelList);
624 int nbSel = aSelList.Extent();
626 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
627 if (!CORBA::is_nil(aSelectedObject)) {
629 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) {
630 // Explore the shape if its a local selection
631 TColStd_IndexedMapOfInteger aMap;
632 aSelMgr->GetIndexes(aSelList.First(), aMap);
633 if (aMap.Extent() == 1) {
634 int anIndex = aMap(1);
635 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
636 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
640 if (aShape.ShapeType() != TopAbs_VERTEX)
641 isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
644 if (GEOMBase::VertexToPoint(aShape, aPnt)) {
645 // set coordinates to the Spin Boxes
650 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
651 Group3Spin->SpinBox_DX->blockSignals(true);
652 Group3Spin->SpinBox_DY->blockSignals(true);
653 Group3Spin->SpinBox_DZ->blockSignals(true);
654 if (GroupType->RadioButton1->isChecked()) {
655 Group3Spin->SpinBox_DX->setValue(aX);
656 Group3Spin->SpinBox_DY->setValue(aY);
657 Group3Spin->SpinBox_DZ->setValue(aZ);
659 else if (GroupType->RadioButton2->isChecked()) {
660 XYZ xyz = getLastPoint();
661 Group3Spin->SpinBox_DX->setValue(aX - xyz.x);
662 Group3Spin->SpinBox_DY->setValue(aY - xyz.y);
663 Group3Spin->SpinBox_DZ->setValue(aZ - xyz.z);
665 Group3Spin->SpinBox_DX->blockSignals(blocked);
666 Group3Spin->SpinBox_DY->blockSignals(blocked);
667 Group3Spin->SpinBox_DZ->blockSignals(blocked);
672 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
675 //=================================================================================
676 // function : DeactivateActiveDialog()
678 //=================================================================================
679 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
683 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
684 myGeomGUI->SetActiveDialogBox(0);
687 //=================================================================================
688 // function : ActivateThisDialog()
690 //=================================================================================
691 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
693 myGeomGUI->EmitSignalDeactivateDialog();
695 myGeomGUI->SetActiveDialogBox(this);
697 connect(myGeomGUI->getApp()->selectionMgr(),
698 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
700 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
701 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
704 //=================================================================================
705 // function : ValueChangedInSpinBox()
707 //=================================================================================
708 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox (double newValue)
710 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
713 //=================================================================================
714 // function : BoxChecked()
715 // purpose : ChecBoxes management
716 //=================================================================================
717 void EntityGUI_3DSketcherDlg::BoxChecked (bool checked)
719 QCheckBox* send = (QCheckBox*) sender();
720 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
722 if (send == GroupAngles->checkBox)
723 GroupAngles->SpinBox_DA2->setEnabled(checked);
725 else if (send == GroupControls->CheckBox1)
727 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
729 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
730 isLengthVisible=true;
733 isLengthVisible=false;
735 else if (send == GroupControls->CheckBox2)
737 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
740 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
744 isAngleVisible=false;
746 else if (send == GroupControls->CheckBox3)
748 GroupControls->lineEdit_1->setVisible(checked);
749 GroupControls->lineEdit_2->setVisible(checked);
750 GroupControls->lineEdit_3->setVisible(checked);
751 GroupControls->lineEdit_4->setVisible(checked);
752 GroupControls->lineEdit_5->setVisible(checked);
753 GroupControls->lineEdit_6->setVisible(checked);
755 GroupControls->label_1->setVisible(checked);
756 GroupControls->label_2->setVisible(checked);
757 GroupControls->label_3->setVisible(checked);
758 GroupControls->label_4->setVisible(checked);
759 GroupControls->label_5->setVisible(checked);
760 GroupControls->label_6->setVisible(checked);
761 GroupControls->label_7->setVisible(checked);
762 GroupControls->label_8->setVisible(checked);
764 GroupControls->updateGeometry();
765 GroupControls->resize(minimumSizeHint());
769 resize(minimumSizeHint());
771 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
774 //=================================================================================
775 // function : ButtonClicked()
777 //=================================================================================
778 void EntityGUI_3DSketcherDlg::ButtonClicked (bool checked)
780 if (GroupAngles->radioButton_1->isChecked())
782 else if (GroupAngles->radioButton_2->isChecked())
787 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
790 //=================================================================================
791 // function : enterEvent()
793 //=================================================================================
794 void EntityGUI_3DSketcherDlg::enterEvent (QEvent*)
796 if (!mainFrame()->GroupConstructors->isEnabled())
797 ActivateThisDialog();
800 //=================================================================================
801 // function : createOperation
803 //=================================================================================
804 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
806 return getGeomEngine()->GetICurvesOperations(getStudyId());
809 //=================================================================================
810 // function : isValid
812 //=================================================================================
813 bool EntityGUI_3DSketcherDlg::isValid (QString& msg)
816 ok = Group3Spin->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
817 ok = Group3Spin->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
818 ok = Group3Spin->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
822 //=================================================================================
823 // function : execute
825 //=================================================================================
826 bool EntityGUI_3DSketcherDlg::execute (ObjectList& objects)
828 //GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
829 //if (!myOK || myPointsList.size() == 0)
830 // aCoordsArray->length((myPointsList.size()+1)*3);
832 // aCoordsArray->length(myPointsList.size()*3);
834 QStringList aCommands;
835 aCommands << "3DSketcher";
836 QStringList aParameters;
839 QList<XYZ>::const_iterator it;
840 for (it = myPointsList.begin(); it != myPointsList.end(); ++it) {
841 //aCoordsArray[i++] = (*it).x;
842 //aCoordsArray[i++] = (*it).y;
843 //aCoordsArray[i++] = (*it).z;
844 aCommands << (*it).command;
845 aParameters << (*it).params;
848 if (!myOK || myPointsList.size() == 0) {
849 XYZ xyz = getCurrentPoint();
850 //aCoordsArray[i++] = xyz.x;
851 //aCoordsArray[i++] = xyz.y;
852 //aCoordsArray[i++] = xyz.z;
853 aCommands << xyz.command;
854 aParameters << xyz.params;
857 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
858 //GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher(aCoordsArray);
859 GEOM::GEOM_Object_var anObj = anOper->Make3DSketcherCommand(aCommands.join(":").toLatin1().constData());
861 if (!anObj->_is_nil()) {
862 if (!IsPreview()) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
863 objects.push_back(anObj._retn());
869 //=================================================================================
870 // function : SetDoubleSpinBoxStep()
871 // purpose : Double spin box management
872 //=================================================================================
873 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep (double step)
875 Group3Spin->SpinBox_DX->setSingleStep(step);
876 Group3Spin->SpinBox_DY->setSingleStep(step);
877 Group3Spin->SpinBox_DZ->setSingleStep(step);
878 GroupAngles->SpinBox_DA->setSingleStep(step);
879 GroupAngles->SpinBox_DL->setSingleStep(step);
880 GroupAngles->SpinBox_DA2->setSingleStep(step);
883 //=================================================================================
884 // function : ClickOnOk()
886 //=================================================================================
887 void EntityGUI_3DSketcherDlg::ClickOnOk()
897 //=================================================================================
898 // function : ClickOnApply()
900 //=================================================================================
901 bool EntityGUI_3DSketcherDlg::ClickOnApply()
909 if (myPointsList.count() > 0)
910 myPointsList.append(myPointsList[0]);
921 //=================================================================================
922 // function : getLastPoint()
923 // purpose : return last points from list
924 //=================================================================================
925 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
927 return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
930 //=================================================================================
931 // function : getPenultimatePoint()
932 // purpose : return penultimate point from list
933 //=================================================================================
934 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getPenultimatePoint() const
936 double size = myPointsList.count();
937 return size > 1 ? myPointsList.at(size - 2) : XYZ();
940 //=================================================================================
941 // function : getCurrentPoint()
942 // purpose : returns current point
943 //=================================================================================
944 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
948 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
949 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 7);
952 if (GroupAngles->radioButton_1->isChecked())
953 xyz.command = "OXY ";
954 else if (GroupAngles->radioButton_2->isChecked())
955 xyz.command = "OYZ ";
957 xyz.command = "OXZ ";
959 double anAngle = GroupAngles->SpinBox_DA->value();
960 double aLength = GroupAngles->SpinBox_DL->value();
962 double anAngle2 = 0.0;
964 if (GroupAngles->checkBox->isChecked()) {
965 anAngle2 = GroupAngles->SpinBox_DA2->value();
966 da2 = GroupAngles->SpinBox_DA2->text();
970 QString::number(anAngle, 'g', aPrecision) + " " +
971 QString::number(anAngle2, 'g', aPrecision) + " " +
972 QString::number(aLength, 'g', aPrecision);
974 GroupAngles->SpinBox_DA->text() + ":" +
976 GroupAngles->SpinBox_DL->text();
978 // Calculate point coordinates for preview
979 anAngle = anAngle * M_PI/180.0;
980 anAngle2 = anAngle2 * M_PI/180.0;
981 double aProjectedLength = aLength * cos(anAngle2);
983 XYZ xyzP = getLastPoint();
984 if (GroupAngles->radioButton_1->isChecked()) // OXY
986 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
987 xyz.y = xyzP.y + aProjectedLength * sin(anAngle);
988 xyz.z = xyzP.z + aLength * sin(anAngle2);
990 else if (GroupAngles->radioButton_2->isChecked()) // OYZ
992 xyz.y = xyzP.y + aProjectedLength * cos(anAngle);
993 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
994 xyz.x = xyzP.x + aLength * sin(anAngle2);
998 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
999 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1000 xyz.y = xyzP.y + aLength * sin(anAngle2);
1004 if (myMode == 0) { // XYZ
1005 xyz.x = Group3Spin->SpinBox_DX->value();
1006 xyz.y = Group3Spin->SpinBox_DY->value();
1007 xyz.z = Group3Spin->SpinBox_DZ->value();
1008 xyz.command = "TT ";
1011 xyz = getLastPoint();
1012 xyz.x += Group3Spin->SpinBox_DX->value();
1013 xyz.y += Group3Spin->SpinBox_DY->value();
1014 xyz.z += Group3Spin->SpinBox_DZ->value();
1018 double aX = Group3Spin->SpinBox_DX->value();
1019 double aY = Group3Spin->SpinBox_DY->value();
1020 double aZ = Group3Spin->SpinBox_DZ->value();
1023 QString::number(aX, 'g', aPrecision) + " " +
1024 QString::number(aY, 'g', aPrecision) + " " +
1025 QString::number(aZ, 'g', aPrecision);
1027 Group3Spin->SpinBox_DX->text() + ":" +
1028 Group3Spin->SpinBox_DY->text() + ":" +
1029 Group3Spin->SpinBox_DZ->text();
1034 //================================================================
1035 // Function : displayPreview
1036 // Purpose : Method for displaying preview of resulting shape
1037 // Redefined from GEOMBase_Helper.
1038 //================================================================
1039 void EntityGUI_3DSketcherDlg::displayPreview (GEOM::GEOM_Object_ptr object,
1041 const bool activate,
1043 const double lineWidth,
1044 const int displayMode,
1047 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1049 QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
1050 Quantity_NameOfColor line_color = SalomeApp_Tools::color(aColor).Name();
1052 // set width of displayed shape
1055 lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
1057 getDisplayer()->SetWidth(lw);
1059 // Disable activation of selection
1060 getDisplayer()->SetToActivate(activate);
1062 // Make a reference to GEOM_Object
1063 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string(object);
1064 getDisplayer()->SetName(objStr.in());
1066 // Create wire from applied object
1067 TopoDS_Shape anApplyedWire, aLastSegment;
1068 if (!createShapes(object, anApplyedWire, aLastSegment))
1071 // Set color for preview shape
1072 getDisplayer()->SetColor(line_color);
1075 SALOME_Prs* aPrs = getDisplayer()->BuildPrs(anApplyedWire);
1076 if (aPrs != 0 && !aPrs->IsNull())
1077 GEOMBase_Helper::displayPreview(aPrs, append, update);
1079 getDisplayer()->SetColor(Quantity_NOC_VIOLET);
1080 aPrs = getDisplayer()->BuildPrs(aLastSegment);
1082 if (aPrs != 0 && !aPrs->IsNull())
1083 GEOMBase_Helper::displayPreview(aPrs, append, update);
1085 getDisplayer()->SetColor(line_color);
1087 // Display local trihedron if the mode is relatives coordinates or angles
1088 if (myMode == 1 || myMode == 2)
1089 displayTrihedron(2);
1091 // Display preview of suitable dimension presentations
1092 if (myMode == 2) // ANGLES
1094 double anAngle2 = 0.0;
1095 if (GroupAngles->checkBox->isChecked())
1096 anAngle2 = GroupAngles->SpinBox_DA2->value();
1098 displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2, GroupAngles->SpinBox_DL->value(), myOrientation);
1099 displayLength(GroupAngles->SpinBox_DL->value(), /*store=*/false, /*type=*/myPrsType);
1101 if (myMode == 0 || myMode == 1) // COORDINATES
1104 getDisplayer()->UnsetName();
1106 // Enable activation of displayed objects
1107 getDisplayer()->SetToActivate(true);
1110 //================================================================
1111 // Function : displayTrihedron()
1112 // Purpose : Method for displaying trihedron
1113 //================================================================
1114 void EntityGUI_3DSketcherDlg::displayTrihedron (int selMode)
1116 // Add trihedron to preview
1117 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1119 gp_Pnt P(getLastPoint().x,getLastPoint().y,getLastPoint().z);
1120 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(P,gp::DZ(),gp::DX());
1121 Handle(AIS_Trihedron) anIO = new AIS_Trihedron(anAxis);
1122 anIO->SetSelectionMode(selMode);
1124 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1125 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1128 aSPrs->PrependObject(anIO);
1129 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1133 //================================================================
1134 // Function : displayAngle()
1135 // Purpose : Method for displaying angle dimensions
1136 //================================================================
1137 void EntityGUI_3DSketcherDlg::displayAngle (double theAngle1, double theAngle2,
1138 double theLength, int theOrientation, bool store)
1140 if (Abs(theAngle2 - 90.0) < Precision::Angular() ||
1141 theLength < Precision::Confusion())
1144 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1146 XYZ Last = getLastPoint();
1147 XYZ Current = getCurrentPoint();
1149 gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
1150 gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
1153 bool twoAngles = GroupAngles->checkBox->isChecked();
1155 switch(theOrientation)
1159 P1 = gp_Pnt(Last.x + theLength,Last.y,Last.z); // X direction
1160 P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.),
1161 Last.y + theLength * sin(theAngle1 * M_PI / 180.),
1167 P1 = gp_Pnt(Last.x, Last.y + theLength,Last.z); // Y direction
1169 Last.y + theLength * cos(theAngle1 * M_PI / 180.),
1170 Last.z + theLength * sin(theAngle1 * M_PI / 180.));
1175 P1 = gp_Pnt(Last.x + theLength,Last.y,Last.z); // X direction
1176 P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.) ,
1178 Last.z + theLength * sin(theAngle1 * M_PI / 180.));
1183 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
1184 TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
1185 TopoDS_Vertex LastV = BRepBuilderAPI_MakeVertex(Last_Pnt);
1186 TopoDS_Vertex CurV = BRepBuilderAPI_MakeVertex(Current_Pnt);
1187 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(LastV, V1);
1188 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(LastV, V2);
1189 TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(LastV, CurV);
1191 gce_MakePln gce_MP (Last_Pnt, P1, P2);
1192 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
1194 // Convert angles to string
1195 std::string Angle1_str = doubleToString(theAngle1);
1196 std::string Angle2_str = doubleToString(theAngle2);
1198 // Create interactive object
1199 Handle(AIS_AngleDimension) anAngleIO = new AIS_AngleDimension
1200 (anEdge1, anEdge2, aPlane, theAngle1 * M_PI / 180.,
1201 TCollection_ExtendedString(Angle1_str.c_str()));
1202 anAngleIO->SetArrowSize((theAngle1 * M_PI / 180) * (theLength/20));
1204 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1205 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1207 Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
1208 asp->LineAspect()->SetWidth(w);
1209 anAngleIO->Attributes()->SetAngleAspect(asp);
1211 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1212 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1216 // Erase dimensions presentations
1217 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
1218 myAnglePrs->PrependObject(anAngleIO);
1220 // Display modified presentation
1222 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
1226 aSPrs->AddObject(anAngleIO);
1228 myPrsType = TYPE_ANGLE; // Overwrite type with ANGLE
1232 gce_MakePln gce_MP2(Last_Pnt, P2, Current_Pnt);
1233 Handle(Geom_Plane) aPlane2 = new Geom_Plane(gce_MP2.Value());
1235 Handle(AIS_AngleDimension) anAngle2IO =
1236 new AIS_AngleDimension(anEdge2, anEdge3, aPlane2, theAngle2 * M_PI / 180.,
1237 TCollection_ExtendedString(Angle2_str.c_str()));
1238 anAngle2IO->SetArrowSize((theAngle2 * M_PI / 180) * (theLength/20));
1240 anAngle2IO->Attributes()->SetAngleAspect(asp);
1244 // Erase dimensions presentations
1245 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
1246 myAnglePrs->PrependObject(anAngle2IO);
1248 // Display modified presentation
1250 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
1254 aSPrs->AddObject(anAngle2IO);
1257 myPrsType = TYPE_TWO_ANGLES; // Overwrite type with TWO_ANGLES
1260 if (!store && isAngleVisible)
1262 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1266 //================================================================
1267 // Function : displayLength()
1268 // Purpose : Method for displaying length dimensions
1269 //================================================================
1270 void EntityGUI_3DSketcherDlg::displayLength (double theLength, bool store, int type)
1272 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1274 XYZ Last = getLastPoint();
1275 XYZ Current = getCurrentPoint();
1276 XYZ Penultimate = getPenultimatePoint();
1278 bool withAngle = (type == TYPE_ANGLE || type == TYPE_TWO_ANGLES);
1279 bool twoAngles = (type == TYPE_TWO_ANGLES);
1281 double aLength = 0.0;
1283 if (theLength < 0) // Calculate length if not given
1285 aLength = sqrt((Last.x - Current.x)*(Last.x - Current.x) +
1286 (Last.y - Current.y)*(Last.y - Current.y) +
1287 (Last.z - Current.z)*(Last.z - Current.z));
1290 aLength = theLength;
1292 if (aLength<Precision::Confusion())
1295 gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
1296 gp_Pnt P2 = gp_Pnt(Current.x,Current.y,Current.z);
1297 gp_Pnt P3 = gp_Pnt(Penultimate.x,Penultimate.y,Penultimate.z);
1303 TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
1304 TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
1306 // Convert length to string
1307 std::string aLength_str = doubleToString(aLength);
1309 // Define the suitable plane for right relative positioning of dimension presentations
1311 gp_Dir aNormal; // Normal defining the plane of the presentation
1312 if (withAngle) // If one angle
1314 switch(myOrientation)
1318 aNormal = gp::DZ().Crossed(gp_Dir(Vec1));//--> the plane is orthogonal to the angle presentation
1319 // plane and contains the current edge
1320 if (twoAngles) // If two angles
1322 gp_XYZ Vec1_XY(Vec1.X(),Vec1.Y(),0.0);// --> define Vec3 as the projection of the current
1323 Vec3 = gp_Vec(Vec1_XY); // edge on the plane chosen for the first angle
1329 aNormal = gp::DX().Crossed(gp_Dir(Vec1));
1332 gp_XYZ Vec1_YZ(0.0,Vec1.Y(),Vec1.Z());
1333 Vec3 = gp_Vec(Vec1_YZ);
1339 aNormal = gp::DY().Crossed(gp_Dir(Vec1));
1342 gp_XYZ Vec1_XZ(Vec1.X(),0.0,Vec1.Z());
1343 Vec3 = gp_Vec(Vec1_XZ);
1348 if(twoAngles // If two angles
1349 && Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
1351 aNormal = gp_Dir(Vec1.Crossed(Vec3));// --> set the normal as the cross product of
1352 } // the current edge with its projection
1353 } // it ensures that the dimension changes
1356 // Check colinearity
1357 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1359 Vec2 = gp_Vec(gp::DX());
1360 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1362 Vec2 = gp_Vec(gp::DY());
1365 aNormal = gp_Dir(Vec1.Crossed(Vec2)); // If no angles --> the plane is the one formed by
1366 } // the last edge and the current one
1368 // Plane construction
1369 gce_MakePln gce_MP(P1, aNormal);
1370 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
1372 Handle(AIS_LengthDimension) anIO =
1373 new AIS_LengthDimension(aVert1,
1377 TCollection_ExtendedString(aLength_str.c_str()));
1378 anIO->SetArrowSize(aLength/20);
1380 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1381 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1382 Handle(Prs3d_LengthAspect) asp = new Prs3d_LengthAspect();
1383 asp->LineAspect()->SetWidth(w);
1384 anIO->Attributes()->SetLengthAspect(asp);
1388 // Erase length dimensions presentation
1389 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
1390 myLengthPrs->PrependObject(anIO);
1392 // Display modified presentation
1393 if (isLengthVisible)
1394 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
1396 else if (isLengthVisible)
1398 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1399 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1402 aSPrs->PrependObject(anIO);
1403 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1407 myPrsType = TYPE_LENGTH;
1410 //================================================================
1411 // Function : createShapes
1412 // Purpose : Create applyed wire, and last segment from entry object
1413 //================================================================
1414 bool EntityGUI_3DSketcherDlg::createShapes (GEOM::GEOM_Object_ptr /*theObject*/,
1415 TopoDS_Shape& theApplyedWire,
1416 TopoDS_Shape& theLastSegment)
1418 QList<gp_Pnt> points;
1419 foreach (XYZ xyz, myPointsList) {
1420 gp_Pnt p(xyz.x, xyz.y, xyz.z);
1421 if (points.isEmpty() || points.last().Distance(p) > gp::Resolution())
1425 if (points.count() == 1) {
1426 // only one point is created
1427 BRepBuilderAPI_MakeVertex mkVertex (points.last());
1428 theApplyedWire = mkVertex.Shape();
1430 else if (points.count() > 1) {
1432 BRepBuilderAPI_MakePolygon mkWire;
1433 foreach(gp_Pnt p, points)
1435 theApplyedWire = mkWire.Shape();
1438 XYZ curxyz = getCurrentPoint();
1439 gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
1441 if (points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution()) {
1442 BRepBuilderAPI_MakeVertex mkVertex (curpnt);
1443 theLastSegment = mkVertex.Shape();
1446 BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
1447 theLastSegment = mkEdge.Shape();
1450 /* VSR: old algorithm does not work properly, see bug 0020899
1451 TopoDS_Shape aShape;
1452 if (!GEOMBase::GetShape(theObject, aShape))
1455 if (aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX)
1458 theApplyedWire = aShape;
1462 BRepBuilderAPI_MakeWire aBuilder;
1463 TopExp_Explorer edgeExp(aShape, TopAbs_EDGE);
1465 TopoDS_Shape anEdge = edgeExp.Current();
1467 if (edgeExp.More()) // i.e. non-last edge
1468 aBuilder.Add(TopoDS::Edge(anEdge));
1470 theLastSegment = anEdge;
1475 if (aBuilder.IsDone()) {
1476 theApplyedWire = aBuilder.Shape();
1478 else if (!theLastSegment.IsNull()) {
1479 TopExp_Explorer vertexExp(theLastSegment, TopAbs_VERTEX);
1480 theApplyedWire = vertexExp.Current();
1487 //================================================================
1488 // Function : doubleToString
1489 // Purpose : converts double to string
1490 //================================================================
1491 std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
1495 char format = 'g'; // truncated to a number of significant digits
1497 return QString::number(num, format, digNum).toStdString();