1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : EntityGUI_3DSketcherDlg.cxx
26 #include <boost/lexical_cast.hpp>
28 #include "EntityGUI_3DSketcherDlg.h"
29 #include "EntityGUI_Widgets.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 <SalomeApp_DoubleSpinBox.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SalomeApp_Tools.h>
53 #include <TColStd_IndexedMapOfInteger.hxx>
54 #include <BRepBuilderAPI_MakeVertex.hxx>
55 #include <BRepBuilderAPI_MakePolygon.hxx>
56 #include <BRepBuilderAPI_MakeEdge.hxx>
58 #include <AIS_Trihedron.hxx>
59 #include <AIS_AngleDimension.hxx>
60 #include <AIS_LengthDimension.hxx>
61 #include <Geom_Axis2Placement.hxx>
62 #include <Geom_Plane.hxx>
63 #include <SelectMgr_Selection.hxx>
64 #include <gce_MakePln.hxx>
65 #include <Prs3d_LineAspect.hxx>
66 #include <Prs3d_DimensionAspect.hxx>
67 #include <Prs3d_TextAspect.hxx>
68 #include <Prs3d_Presentation.hxx>
69 #include <Prs3d_Text.hxx>
70 #include <Graphic3d_VerticalTextAlignment.hxx>
71 #include <Graphic3d_HorizontalTextAlignment.hxx>
72 #include <Graphic3d_AspectText3d.hxx>
73 #include <Font_FontAspect.hxx>
75 // This include must be *AFTER* SOCC_ViewModel.h because
76 // of the constant ROTATE which is a #define in
77 // GEOMImpl_Types.hxx and an enum in SOCC_ViewModel.h
78 #include <GEOMImpl_Types.hxx>
82 // Avoid duplication of angle coordinates in cylindrical mode
83 // Check spherical mode in absolute
95 Locker(bool& l) : myLock(l) { myLock = true; }
96 ~Locker() { myLock = false; }
101 DEFINE_STANDARD_HANDLE(AIS_Text, AIS_InteractiveObject)
103 class AIS_Text:public AIS_InteractiveObject
106 DEFINE_STANDARD_RTTIEXT(AIS_Text,AIS_InteractiveObject)
112 const TCollection_ExtendedString& , const gp_Pnt& ,
113 Quantity_Color color,
114 Standard_Integer aHJust,
115 Standard_Integer aVJust ,
116 Standard_Real Angle ,
117 Standard_Boolean Zoom ,
118 Standard_Real Height,
119 Font_FontAspect FontAspect,
120 Standard_CString Font
125 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
126 const Handle(Prs3d_Presentation)& aPresentation,
127 const Standard_Integer aMode);
129 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
130 const Standard_Integer aMode){} ;
133 TCollection_ExtendedString aText;
138 Standard_Real aAngle;
139 Standard_Real aHeight;
140 Standard_Boolean aZoomable;
141 Quantity_Color aColor;
142 Standard_CString aFont;
143 Font_FontAspect aFontAspect;
144 Graphic3d_HorizontalTextAlignment aHJustification;
145 Graphic3d_VerticalTextAlignment aVJustification;
148 IMPLEMENT_STANDARD_RTTIEXT(AIS_Text, AIS_InteractiveObject)
150 AIS_Text::AIS_Text( const TCollection_ExtendedString& text, const gp_Pnt& position,
151 Quantity_Color color = Quantity_NOC_YELLOW,
152 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
153 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
154 Standard_Real angle = 0.0 ,
155 Standard_Boolean zoomable = Standard_False,
156 Standard_Real height = 16.,
157 Font_FontAspect fontAspect = Font_FA_Regular,
158 Standard_CString font = "Courier")
161 aPosition = position;
162 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
163 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
165 aZoomable = zoomable;
168 aFontAspect = fontAspect;
172 void AIS_Text::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
173 const Handle(Prs3d_Presentation)& aPresentation,
174 const Standard_Integer aMode)
177 aPresentation->Clear();
179 Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect();
182 asp->SetColor(aColor);
183 asp->SetHeight(aHeight); // I am changing the myHeight value
185 asp->SetHorizontalJustification(aHJustification);
186 asp->SetVerticalJustification(aVJustification);
187 asp->Aspect()->SetTextZoomable(aZoomable);
188 asp->Aspect()->SetTextAngle(aAngle);
189 asp->Aspect()->SetTextFontAspect(aFontAspect);
190 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
193 bool isSame (double d1, double d2)
195 return Abs(d1 - d2) <= Precision::Confusion();
198 //=================================================================================
199 // class : EntityGUI_3DSketcherDlg()
200 // purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
201 // name 'name' and widget flags set to 'f'.
202 // The dialog will by default be modeless, unless you set 'modal' to
203 // TRUE to construct a modal dialog.
204 //=================================================================================
205 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
206 bool modal, Qt::WindowFlags fl,
207 const double lineWidth)
208 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
211 myLineWidth(lineWidth),
212 myGeometryGUI(theGeometryGUI),
213 myLengthIORedoList(),
216 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
217 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
218 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REDO")));
219 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_3DSKETCH")));
221 setWindowTitle(tr("GEOM_3DSKETCHER_TITLE"));
223 /***************************************************************/
225 mainFrame()->GroupConstructors->setTitle(tr("GEOM_3DSKETCHER"));
226 mainFrame()->RadioButton1->setIcon(image3);;
227 mainFrame()->RadioButton2->close();
228 mainFrame()->RadioButton3->close();
230 GroupType = new EntityGUI_Type(centralWidget());
231 GroupType->GroupType2->setTitle(tr("GEOM_COORDINATES_TYPE"));
232 GroupType->GroupType1->setTitle(tr("GEOM_MODE"));
233 GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
234 GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
235 GroupType->RadioButton3->setText(tr("(X,Y,Z)"));
236 GroupType->RadioButton4->setText(tr("GEOM_ANGLES"));
238 myTypeGroup1 = new QButtonGroup(this);
239 myTypeGroup1->setExclusive(true);
240 myTypeGroup1->addButton(GroupType->RadioButton1, 0);
241 myTypeGroup1->addButton(GroupType->RadioButton2, 1);
243 myTypeGroup2 = new QButtonGroup(this);
244 myTypeGroup2->setExclusive(true);
245 myTypeGroup2->addButton(GroupType->RadioButton3, 0);
246 myTypeGroup2->addButton(GroupType->RadioButton4, 1);
248 Group3Spin = new EntityGUI_3Spin(centralWidget());
249 Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
250 Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
251 Group3Spin->buttonUndo->setIcon(image1);
252 Group3Spin->buttonRedo->setIcon(image2);
253 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
254 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
255 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
257 GroupAngles = new EntityGUI_Angles(centralWidget());
258 GroupAngles->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
259 GroupAngles->buttonUndo->setIcon(image1);
260 GroupAngles->buttonRedo->setIcon(image2);
261 GroupAngles->TextLabel1->setText(tr("GEOM_LENGTH"));
262 GroupAngles->TextLabel2->setText(tr("GEOM_ANGLE"));
263 GroupAngles->checkBox ->setText(tr("GEOM_ANGLE_2"));
264 GroupAngles->checkBox_2->setText(tr("GEOM_HEIGHT"));
266 GroupControls = new EntityGUI_Controls(centralWidget());
267 GroupControls->GroupBox1->setTitle(tr("GEOM_CONTROLS"));
268 GroupControls->CheckBox1->setText(tr("GEOM_SHOW_LENGTH"));
269 GroupControls->CheckBox2->setText(tr("GEOM_SHOW_ANGLE"));
270 GroupControls->CheckBox3->setText(tr("GEOM_SHOW_POINTS_COORD"));
271 GroupControls->lineEdit_1->setReadOnly(true);
272 GroupControls->lineEdit_2->setReadOnly(true);
273 GroupControls->lineEdit_3->setReadOnly(true);
274 GroupControls->lineEdit_4->setReadOnly(true);
275 GroupControls->lineEdit_5->setReadOnly(true);
276 GroupControls->lineEdit_6->setReadOnly(true);
277 GroupControls->label_1->setText(tr("X:"));
278 GroupControls->label_2->setText(tr("Y:"));
279 GroupControls->label_3->setText(tr("Z:"));
280 GroupControls->label_4->setText(tr("X:"));
281 GroupControls->label_5->setText(tr("Y:"));
282 GroupControls->label_6->setText(tr("Z:"));
283 GroupControls->label_7->setText(tr("GEOM_START"));
284 GroupControls->label_8->setText(tr("GEOM_END"));
286 buttonOk()->setText(tr("GEOM_BUT_END_SKETCH"));
287 buttonApply()->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
289 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
290 layout->setMargin(0); layout->setSpacing(6);
291 layout->addWidget(GroupType);
292 layout->addWidget(Group3Spin);
293 layout->addWidget(GroupAngles);
294 layout->addWidget(GroupControls);
296 setHelpFileName("create_3dsketcher_page.html");
302 //=================================================================================
303 // function : ~EntityGUI_3DSketcherDlg()
304 // purpose : Destroys the object and frees any allocated resources
305 //=================================================================================
306 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
308 myGeomGUI->SetActiveDialogBox(0);
311 //=================================================================================
314 //=================================================================================
315 void EntityGUI_3DSketcherDlg::Init()
319 myPrsType = prsType();
321 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
322 myAnglePrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
323 myLengthPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
324 myTextPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
326 localSelection(TopAbs_VERTEX);
328 /* Get setting of step value from file configuration */
329 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
331 /* min, max, step and decimals for spin boxes */
332 initSpinBox(Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
333 initSpinBox(Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
334 initSpinBox(Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
336 initSpinBox(GroupAngles->SpinBox_DA , -360.0, 360.0, step, "angular_precision");
337 initSpinBox(GroupAngles->SpinBox_DA2, -90.0, 90.0, step, "angular_precision");
338 initSpinBox(GroupAngles->SpinBox_DL , COORD_MIN, COORD_MAX, step, "length_precision");
339 initSpinBox(GroupAngles->SpinBox_DH , COORD_MIN, COORD_MAX, step, "length_precision");
341 Group3Spin->SpinBox_DX->setValue(0.0);
342 Group3Spin->SpinBox_DY->setValue(0.0);
343 Group3Spin->SpinBox_DZ->setValue(0.0);
345 GroupAngles->SpinBox_DA->setValue(0.0);
346 GroupAngles->SpinBox_DA2->setValue(0.0);
347 GroupAngles->SpinBox_DL->setValue(0.0);
348 GroupAngles->SpinBox_DH->setValue(0.0);
350 GroupAngles->radioButton_1->setChecked(true);
351 GroupAngles->checkBox->setChecked(false);
352 GroupAngles->checkBox_2->setChecked(false);
353 GroupAngles->SpinBox_DA2->setEnabled(false);
354 GroupAngles->SpinBox_DH->setEnabled(false);
356 GroupControls->CheckBox1->setChecked(true);
357 GroupControls->CheckBox2->setChecked(true);
358 GroupControls->CheckBox3->setChecked(true);
360 isLengthVisible = true;
361 isAngleVisible = true;
365 /* signals and slots connections */
366 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
367 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
369 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
371 connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
372 connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
373 connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
375 connect(GroupAngles->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
376 connect(GroupAngles->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
377 connect(GroupAngles->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
379 connect(myTypeGroup1, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
380 connect(myTypeGroup2, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
382 connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
383 connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
384 connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
386 connect(GroupAngles->SpinBox_DA, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
387 connect(GroupAngles->SpinBox_DA2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
388 connect(GroupAngles->SpinBox_DL, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
389 connect(GroupAngles->SpinBox_DH, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
391 connect(GroupAngles->radioButton_1, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
392 connect(GroupAngles->radioButton_2, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
393 connect(GroupAngles->radioButton_3, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
395 connect(GroupAngles->checkBox, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
396 connect(GroupAngles->checkBox_2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
397 connect(GroupControls->CheckBox1, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
398 connect(GroupControls->CheckBox2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
399 connect(GroupControls->CheckBox3, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
401 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
403 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
404 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
406 initName(tr("GEOM_3DSKETCHER"));
408 GroupControls->CheckBox3->click();
410 UpdateButtonsState();
415 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
418 //=================================================================================
419 // function : TypeClicked()
420 // purpose : Radio button management
421 //=================================================================================
422 void EntityGUI_3DSketcherDlg::TypeClicked (int id)
424 QButtonGroup* send = (QButtonGroup*) sender();
426 int coordType = myCoordType;
429 if (send == myTypeGroup1)
431 if(id == myMode) return;
434 else if (send == myTypeGroup2)
436 if (id == myCoordType) return;
443 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
444 Group3Spin->SpinBox_DX->blockSignals(true);
445 Group3Spin->SpinBox_DY->blockSignals(true);
446 Group3Spin->SpinBox_DZ->blockSignals(true);
448 // Get setting of step value from file configuration
449 XYZ xyz = getLastPoint();
451 Group3Spin->SpinBox_DX->text().toDouble(&okx);
452 Group3Spin->SpinBox_DY->text().toDouble(&oky);
453 Group3Spin->SpinBox_DZ->text().toDouble(&okz);
455 if (coordType == 0) // Cartesian coordinates
457 if (mode == 0) { // XYZ
458 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
459 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
460 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
461 if (myCoordType == 0 && myMode == 1)
463 if (okx) Group3Spin->SpinBox_DX->setValue(xyz.x + Group3Spin->SpinBox_DX->value());
464 if (oky) Group3Spin->SpinBox_DY->setValue(xyz.y + Group3Spin->SpinBox_DY->value());
465 if (okz) Group3Spin->SpinBox_DZ->setValue(xyz.z + Group3Spin->SpinBox_DZ->value());
467 Group3Spin->buttonApply->setFocus();
469 else if (mode == 1) { // DXDYDZ
470 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
471 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
472 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_DZ2"));
473 if (myCoordType == 0 && myMode == 0)
475 if (okx) Group3Spin->SpinBox_DX->setValue(Group3Spin->SpinBox_DX->value() - xyz.x);
476 if (oky) Group3Spin->SpinBox_DY->setValue(Group3Spin->SpinBox_DY->value() - xyz.y);
477 if (okz) Group3Spin->SpinBox_DZ->setValue(Group3Spin->SpinBox_DZ->value() - xyz.z);
479 Group3Spin->buttonApply->setFocus();
482 else if (coordType == 1) // Angles and Length
486 GroupAngles->buttonApply->setFocus();
489 Group3Spin->SpinBox_DX->blockSignals(blocked);
490 Group3Spin->SpinBox_DY->blockSignals(blocked);
491 Group3Spin->SpinBox_DZ->blockSignals(blocked);
494 myCoordType = coordType;
497 resize(minimumSizeHint());
499 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
502 //=================================================================================
503 // function : ClickOnAddPoint()
504 // purpose : called when the point coordinates is Applyed
505 //=================================================================================
506 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
514 myPrsType = prsType();
517 displayDimensions( /*store = */true);
519 myPointsList.append(getCurrentPoint());
521 myLengthIORedoList.Clear();
522 myAngleIORedoList.Clear();
523 myTextIORedoList.Clear();
525 if (myCoordType == 0 && myMode == 1) // RELATIVE CARTESIAN COORDINATES
527 Group3Spin->SpinBox_DX->setValue(0.0);
528 Group3Spin->SpinBox_DY->setValue(0.0);
529 Group3Spin->SpinBox_DZ->setValue(0.0);
531 else if (myCoordType == 1 && myMode == 1) // RELATIVE ANGULAR COORDINATES
533 GroupAngles->SpinBox_DA->setValue(0.0);
534 GroupAngles->SpinBox_DL->setValue(0.0);
535 GroupAngles->SpinBox_DA2->setValue(0.0);
538 UpdatePointCoordinates();
540 UpdateButtonsState();
541 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
544 //=================================================================================
545 // function : UpdateButtonsState()
547 //=================================================================================
548 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
550 if (myPointsList.count() == 0)
552 GroupType->RadioButton1->click();
553 GroupType->RadioButton3->click();
555 GroupType->RadioButton2->setEnabled(myPointsList.count() > 0);
556 // GroupType->RadioButton3->setEnabled(myPointsList.count() > 0);
557 // GroupType->RadioButton4->setEnabled(myPointsList.count() > 0);
558 Group3Spin->buttonUndo->setEnabled(myPointsList.count() > 0);
559 Group3Spin->buttonRedo->setEnabled(myRedoList.count() > 0);
560 GroupAngles->buttonUndo->setEnabled(myPointsList.count() > 0);
561 GroupAngles->buttonRedo->setEnabled(myRedoList.count() > 0);
564 //=================================================================================
565 // function : UpdatePointCoordinates()
566 // purpose :Update point coordinates in the control groupbox
567 //=================================================================================
568 void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
570 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
571 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
573 if (myPointsList.count() == 0)
575 GroupControls->lineEdit_1->setText("");
576 GroupControls->lineEdit_2->setText("");
577 GroupControls->lineEdit_3->setText("");
579 GroupControls->lineEdit_4->setText("");
580 GroupControls->lineEdit_5->setText("");
581 GroupControls->lineEdit_6->setText("");
583 else if (myPointsList.count() == 1)
585 GroupControls->lineEdit_1->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
586 GroupControls->lineEdit_2->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
587 GroupControls->lineEdit_3->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
589 GroupControls->lineEdit_4->setText("");
590 GroupControls->lineEdit_5->setText("");
591 GroupControls->lineEdit_6->setText("");
595 GroupControls->lineEdit_4->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
596 GroupControls->lineEdit_5->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
597 GroupControls->lineEdit_6->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
602 //=================================================================================
603 // function : ClickOnUndo()
605 //=================================================================================
606 void EntityGUI_3DSketcherDlg::ClickOnUndo()
609 if (myPointsList.count() > 0) {
611 myRedoList.append(myPointsList.last());
613 // Erase dimensions presentations
614 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
615 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
616 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
617 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
619 removeLastIOFromPrs();
621 // Display modified presentation
623 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
625 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
626 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
628 // Remove last point from list
629 myWorkPoint = myPointsList.last();
630 myPointsList.removeLast();
631 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
632 UpdateButtonsState();
634 // Update of point coordinates in the control groupbox
635 UpdatePointCoordinates();
639 myIsUndoRedo = false;
642 //=================================================================================
643 // function : ClickOnRedo()
645 //=================================================================================
646 void EntityGUI_3DSketcherDlg::ClickOnRedo()
649 if (myRedoList.count() > 0) {
651 myPointsList.append(myRedoList.last());
653 // Erase dimensions presentations
654 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
655 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
656 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
657 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
659 restoreLastIOToPrs();
661 // Display modified presentation
663 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
665 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
666 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
668 // Remove last point from redo list
669 myWorkPoint = myRedoList.last();
670 myRedoList.removeLast();
671 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
672 UpdateButtonsState();
674 // Update of point coordinates in the control groupbox
675 UpdatePointCoordinates();
679 myIsUndoRedo = false;
682 //=================================================================================
683 // function : removeLastIO()
685 //=================================================================================
686 void EntityGUI_3DSketcherDlg::removeLastIOFromPrs ()
688 AIS_ListOfInteractive anIOList;
689 XYZ Last = getLastPoint();
691 for (int l = 0; l<Last.L; l++)
693 myLengthPrs->GetObjects(anIOList);
694 myLengthIORedoList.Prepend(anIOList.First()); // Store last prepended Length IO in redo list
695 myLengthPrs->RemoveFirst(); // Remove it from myLengthPrs
697 for (int a = 0; a<Last.A; a++)
699 myAnglePrs->GetObjects(anIOList);
700 myAngleIORedoList.Prepend(anIOList.First()); // Store last prepended Angle IO in redo list
701 myAnglePrs->RemoveFirst(); // Remove it from myAnglePrs
703 for (int t = 0; t<Last.T; t++)
705 myTextPrs->GetObjects(anIOList);
706 myTextIORedoList.Prepend(anIOList.First()); // Store last prepended Text IO in redo list
707 myTextPrs->RemoveFirst(); // Remove it from myTextPrs
711 //=================================================================================
712 // function : restoreLastIO()
714 //=================================================================================
715 void EntityGUI_3DSketcherDlg::restoreLastIOToPrs ()
717 XYZ LastDeleted = myRedoList.last();
719 for (int l = 0; l<LastDeleted.L; l++)
721 myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
722 myLengthIORedoList.RemoveFirst(); // Remove it from redo list
724 for (int a = 0; a<LastDeleted.A; a++)
726 myAnglePrs->PrependObject(myAngleIORedoList.First()); // Restore last removed IO
727 myAngleIORedoList.RemoveFirst(); // Remove it from redo list
729 for (int t = 0; t<LastDeleted.T; t++)
731 myTextPrs->PrependObject(myTextIORedoList.First()); // Restore last removed IO
732 myTextIORedoList.RemoveFirst(); // Remove it from redo list
736 //=================================================================================
737 // function : SelectionIntoArgument()
738 // purpose : Called when selection as changed
739 //=================================================================================
740 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
742 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
743 SALOME_ListIO aSelList;
744 aSelMgr->selectedObjects(aSelList);
746 int nbSel = aSelList.Extent();
748 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
749 if (!CORBA::is_nil(aSelectedObject)) {
751 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) {
752 // Explore the shape if its a local selection
753 TColStd_IndexedMapOfInteger aMap;
754 aSelMgr->GetIndexes(aSelList.First(), aMap);
755 if (aMap.Extent() == 1) {
756 int anIndex = aMap(1);
757 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations();
758 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
762 if (aShape.ShapeType() != TopAbs_VERTEX)
763 isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
766 if (GEOMBase::VertexToPoint(aShape, aPnt)) {
767 // set coordinates to the Spin Boxes
772 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
773 Group3Spin->SpinBox_DX->blockSignals(true);
774 Group3Spin->SpinBox_DY->blockSignals(true);
775 Group3Spin->SpinBox_DZ->blockSignals(true);
776 if (GroupType->RadioButton1->isChecked()) {
777 Group3Spin->SpinBox_DX->setValue(aX);
778 Group3Spin->SpinBox_DY->setValue(aY);
779 Group3Spin->SpinBox_DZ->setValue(aZ);
781 else if (GroupType->RadioButton2->isChecked()) {
782 XYZ xyz = getLastPoint();
783 Group3Spin->SpinBox_DX->setValue(aX - xyz.x);
784 Group3Spin->SpinBox_DY->setValue(aY - xyz.y);
785 Group3Spin->SpinBox_DZ->setValue(aZ - xyz.z);
787 Group3Spin->SpinBox_DX->blockSignals(blocked);
788 Group3Spin->SpinBox_DY->blockSignals(blocked);
789 Group3Spin->SpinBox_DZ->blockSignals(blocked);
794 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
797 //=================================================================================
798 // function : DeactivateActiveDialog()
800 //=================================================================================
801 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
805 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
806 myGeomGUI->SetActiveDialogBox(0);
809 //=================================================================================
810 // function : ActivateThisDialog()
812 //=================================================================================
813 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
815 myGeomGUI->EmitSignalDeactivateDialog();
817 myGeomGUI->SetActiveDialogBox(this);
819 connect(myGeomGUI->getApp()->selectionMgr(),
820 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
822 localSelection(TopAbs_VERTEX);
823 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
826 //=================================================================================
827 // function : ValueChangedInSpinBox()
829 //=================================================================================
830 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox (double newValue)
832 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
835 //=================================================================================
836 // function : BoxChecked()
837 // purpose : ChecBoxes management
838 //=================================================================================
839 void EntityGUI_3DSketcherDlg::BoxChecked (bool checked)
841 QCheckBox* send = (QCheckBox*) sender();
842 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
844 if (send == GroupAngles->checkBox)
846 GroupAngles->SpinBox_DA2->setEnabled(checked);
849 GroupAngles->SpinBox_DH->setEnabled(false);
850 GroupAngles->checkBox_2->setChecked(false);
853 else if (send == GroupAngles->checkBox_2)
855 GroupAngles->SpinBox_DH->setEnabled(checked);
858 GroupAngles->SpinBox_DA2->setEnabled(false);
859 GroupAngles->checkBox->setChecked(false);
863 else if (send == GroupControls->CheckBox1)
865 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
867 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
868 isLengthVisible=true;
871 isLengthVisible=false;
873 else if (send == GroupControls->CheckBox2)
875 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
878 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
882 isAngleVisible=false;
884 else if (send == GroupControls->CheckBox3)
886 GroupControls->lineEdit_1->setVisible(checked);
887 GroupControls->lineEdit_2->setVisible(checked);
888 GroupControls->lineEdit_3->setVisible(checked);
889 GroupControls->lineEdit_4->setVisible(checked);
890 GroupControls->lineEdit_5->setVisible(checked);
891 GroupControls->lineEdit_6->setVisible(checked);
893 GroupControls->label_1->setVisible(checked);
894 GroupControls->label_2->setVisible(checked);
895 GroupControls->label_3->setVisible(checked);
896 GroupControls->label_4->setVisible(checked);
897 GroupControls->label_5->setVisible(checked);
898 GroupControls->label_6->setVisible(checked);
899 GroupControls->label_7->setVisible(checked);
900 GroupControls->label_8->setVisible(checked);
902 GroupControls->updateGeometry();
903 GroupControls->resize(minimumSizeHint());
907 resize(minimumSizeHint());
909 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
912 //=================================================================================
913 // function : ButtonClicked()
915 //=================================================================================
916 void EntityGUI_3DSketcherDlg::ButtonClicked (bool checked)
918 if (GroupAngles->radioButton_1->isChecked())
920 else if (GroupAngles->radioButton_2->isChecked())
925 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
928 //=================================================================================
929 // function : enterEvent()
931 //=================================================================================
932 void EntityGUI_3DSketcherDlg::enterEvent (QEvent*)
934 if (!mainFrame()->GroupConstructors->isEnabled())
935 ActivateThisDialog();
938 //=================================================================================
939 // function : createOperation
941 //=================================================================================
942 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
944 return getGeomEngine()->GetICurvesOperations();
947 //=================================================================================
948 // function : isValid
950 //=================================================================================
951 bool EntityGUI_3DSketcherDlg::isValid (QString& msg)
954 ok = Group3Spin->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
955 ok = Group3Spin->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
956 ok = Group3Spin->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
960 //=================================================================================
961 // function : execute
963 //=================================================================================
964 bool EntityGUI_3DSketcherDlg::execute (ObjectList& objects)
966 //GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
967 //if (!myOK || myPointsList.size() == 0)
968 // aCoordsArray->length((myPointsList.size()+1)*3);
970 // aCoordsArray->length(myPointsList.size()*3);
972 QStringList aCommands;
973 aCommands << "3DSketcher";
974 QStringList aParameters;
977 QList<XYZ>::const_iterator it;
978 for (it = myPointsList.begin(); it != myPointsList.end(); ++it) {
979 //aCoordsArray[i++] = (*it).x;
980 //aCoordsArray[i++] = (*it).y;
981 //aCoordsArray[i++] = (*it).z;
982 aCommands << (*it).command;
983 aParameters << (*it).params;
986 if (!myOK || myPointsList.size() == 0) {
987 XYZ xyz = getCurrentPoint();
988 //aCoordsArray[i++] = xyz.x;
989 //aCoordsArray[i++] = xyz.y;
990 //aCoordsArray[i++] = xyz.z;
991 aCommands << xyz.command;
992 aParameters << xyz.params;
995 // MESSAGE("aCommands.last() = "<< aCommands.last().toStdString());
996 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
997 //GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher(aCoordsArray);
998 GEOM::GEOM_Object_var anObj = anOper->Make3DSketcherCommand(aCommands.join(":").toUtf8().constData());
1000 if (!anObj->_is_nil()) {
1001 if (!IsPreview()) anObj->SetParameters(aParameters.join(":").toUtf8().constData());
1002 objects.push_back(anObj._retn());
1008 //=================================================================================
1009 // function : SetDoubleSpinBoxStep()
1010 // purpose : Double spin box management
1011 //=================================================================================
1012 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep (double step)
1014 Group3Spin->SpinBox_DX->setSingleStep(step);
1015 Group3Spin->SpinBox_DY->setSingleStep(step);
1016 Group3Spin->SpinBox_DZ->setSingleStep(step);
1017 GroupAngles->SpinBox_DA ->setSingleStep(step);
1018 GroupAngles->SpinBox_DA2->setSingleStep(step);
1019 GroupAngles->SpinBox_DL->setSingleStep(step);
1020 GroupAngles->SpinBox_DH->setSingleStep(step);
1023 //=================================================================================
1024 // function : ClickOnOk()
1026 //=================================================================================
1027 void EntityGUI_3DSketcherDlg::ClickOnOk()
1037 //=================================================================================
1038 // function : ClickOnApply()
1040 //=================================================================================
1041 bool EntityGUI_3DSketcherDlg::ClickOnApply()
1044 if (!isValid(msg)) {
1049 if (myPointsList.count() > 0)
1050 myPointsList.append(myPointsList[0]);
1061 //=================================================================================
1062 // function : getLastPoint()
1063 // purpose : return last points from list
1064 //=================================================================================
1065 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
1067 return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
1070 //=================================================================================
1071 // function : getPenultimatePoint()
1072 // purpose : return penultimate point from list
1073 //=================================================================================
1074 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getPenultimatePoint() const
1076 double size = myPointsList.count();
1077 return size > 1 ? myPointsList.at(size - 2) : XYZ();
1080 //=================================================================================
1081 // function : getCurrentPoint()
1082 // purpose : returns current point
1083 //=================================================================================
1084 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
1088 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1089 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 7);
1091 bool spherical = GroupAngles->checkBox->isChecked();
1092 bool cylindrical = GroupAngles->checkBox_2->isChecked();
1094 if (myCoordType == 1)
1096 if (GroupAngles->radioButton_1->isChecked())
1097 xyz.command = "OXY";
1098 else if (GroupAngles->radioButton_2->isChecked())
1099 xyz.command = "OYZ";
1101 xyz.command = "OXZ";
1103 if (cylindrical) // Cylindrical coordinates (radius, angle, height)
1106 xyz.command += "S"; // Spherical coordinates (radius, angle1, angle2) --> polar if angle2 = 0
1108 if (myMode == 0) // Absolute coordinates
1109 xyz.command += "A ";
1110 else if (myMode == 1) // Relative coordinates
1111 xyz.command += "R ";
1114 double anAngle = GroupAngles->SpinBox_DA->value();
1115 double aLength = GroupAngles->SpinBox_DL->value();
1117 double anAngle2 = 0.0;
1119 if (spherical) { // Spherical coordinates (radius, angle1, angle2)
1120 anAngle2 = GroupAngles->SpinBox_DA2->value();
1121 da2 = GroupAngles->SpinBox_DA2->text();
1124 double aHeight = 0.0;
1127 aHeight = GroupAngles->SpinBox_DH->value();
1128 dh = GroupAngles->SpinBox_DH->text();
1132 QString::number(anAngle, 'g', aPrecision) + " ";
1134 GroupAngles->SpinBox_DA->text() + ":";
1139 QString::number(aHeight, 'g', aPrecision) + " ";
1143 else // Spherical or polar coordinates
1146 QString::number(anAngle2, 'g', aPrecision) + " ";
1152 QString::number(aLength, 'g', aPrecision);
1154 GroupAngles->SpinBox_DL->text();
1157 // Calculate point coordinates for preview
1158 anAngle = anAngle * M_PI/180.0;
1159 anAngle2 = anAngle2 * M_PI/180.0;
1160 double aProjectedLength = aLength * cos(anAngle2);
1162 XYZ xyzP = getLastPoint();
1164 xyzP.x=xyzP.y=xyzP.z=0.0;
1165 if (GroupAngles->radioButton_1->isChecked()) // OXY
1167 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1168 xyz.y = xyzP.y + aProjectedLength * sin(anAngle);
1170 xyz.z = xyzP.z + aHeight;
1172 xyz.z = xyzP.z + aLength * sin(anAngle2);
1174 else if (GroupAngles->radioButton_2->isChecked()) // OYZ
1176 xyz.y = xyzP.y + aProjectedLength * cos(anAngle);
1177 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1179 xyz.x = xyzP.x + aHeight;
1181 xyz.x = xyzP.x + aLength * sin(anAngle2);
1185 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1186 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1188 xyz.y = xyzP.y + aHeight;
1190 xyz.y = xyzP.y + aLength * sin(anAngle2);
1193 else if(myCoordType == 0) {
1194 if (myMode == 0) { // XYZ
1195 xyz.x = Group3Spin->SpinBox_DX->value();
1196 xyz.y = Group3Spin->SpinBox_DY->value();
1197 xyz.z = Group3Spin->SpinBox_DZ->value();
1198 xyz.command = "TT ";
1201 xyz = getLastPoint();
1202 xyz.x += Group3Spin->SpinBox_DX->value();
1203 xyz.y += Group3Spin->SpinBox_DY->value();
1204 xyz.z += Group3Spin->SpinBox_DZ->value();
1208 double aX = Group3Spin->SpinBox_DX->value();
1209 double aY = Group3Spin->SpinBox_DY->value();
1210 double aZ = Group3Spin->SpinBox_DZ->value();
1213 QString::number(aX, 'g', aPrecision) + " " +
1214 QString::number(aY, 'g', aPrecision) + " " +
1215 QString::number(aZ, 'g', aPrecision);
1217 Group3Spin->SpinBox_DX->text() + ":" +
1218 Group3Spin->SpinBox_DY->text() + ":" +
1219 Group3Spin->SpinBox_DZ->text();
1221 // Update point presentation type
1222 xyz.A = myPrsType.A; // Number of angle diomensions
1223 xyz.L = myPrsType.L; // Number of length dimensions
1224 xyz.T = myPrsType.T; // Number of text objects
1230 //=================================================================================
1231 // function : getPresentationPlane()
1232 // purpose : returns the suitable plane for right
1233 // relative positioning of dimension presentations
1234 //=================================================================================
1235 gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
1237 bool withAngle = (myCoordType == 1);
1238 bool twoAngles = GroupAngles->checkBox->isChecked();
1240 XYZ Last = getLastPoint();
1242 if( myIsUndoRedo ) {
1243 Current = myWorkPoint;
1245 Current = getCurrentPoint();
1248 XYZ Penultimate = getPenultimatePoint();
1250 gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
1251 if (myMode == 0) // Absolute coordinates
1254 gp_Pnt P2 = gp_Pnt(Current.x,Current.y,Current.z);
1255 gp_Pnt P3 = gp_Pnt(Penultimate.x,Penultimate.y,Penultimate.z);
1260 gp_Dir aNormal; // Normal defining the plane of the presentation
1262 if (withAngle) // If one angle
1264 // Transformation from the current coordinate system
1265 // to the reference coordinate system
1266 gp_Trsf aTransform = toReferenceSystem (P1);
1267 gp_Dir N1 = gp::DZ();
1268 gp_Dir N2 = gp::DY();
1269 N1.Transform(aTransform);
1270 N2.Transform(aTransform);
1272 if (Vec1.CrossMagnitude(N1) > Precision::Confusion())
1274 // The plane is orthogonal to the angle presentation plane
1275 // and contains the current edge
1276 aNormal = N1.Crossed(gp_Dir(Vec1));
1283 gp_Vec V = Vec1.Transformed(aTransform.Inverted());
1284 gp_Vec Vec3(V.X(),V.Y(),0.0);
1286 // Express the coordinates in the reference coordinate system (OXY)
1287 Vec3.Transform(aTransform);
1288 if(Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
1290 // set the normal as the cross product of the current edge with its projection
1291 // it ensures that the dimension changes side when the angle becomes negative
1292 aNormal = gp_Dir(Vec1.Crossed(Vec3));
1298 // Check colinearity
1299 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1301 Vec2 = gp_Vec(gp::DX());
1302 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1304 Vec2 = gp_Vec(gp::DY());
1307 // If no angles, the plane is the one formed by the last edge and the current one
1308 if(Abs(Vec1.CrossMagnitude(Vec2)) > Precision::Confusion()) {
1309 aNormal = gp_Dir(Vec1.Crossed(Vec2));
1315 //================================================================
1316 // Function : displayPreview
1317 // Purpose : Method for displaying preview of resulting shape
1318 // Redefined from GEOMBase_Helper.
1319 //================================================================
1320 void EntityGUI_3DSketcherDlg::displayPreview (GEOM::GEOM_Object_ptr object,
1322 const bool activate,
1324 const double lineWidth,
1325 const int displayMode,
1328 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1330 QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
1331 Quantity_NameOfColor line_color = SalomeApp_Tools::color(aColor).Name();
1333 // set width of displayed shape
1336 lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
1338 getDisplayer()->SetWidth(lw);
1340 // Disable activation of selection
1341 getDisplayer()->SetToActivate(activate);
1343 // Make a reference to GEOM_Object
1344 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string(object);
1345 getDisplayer()->SetName(objStr.in());
1347 // Create wire from applied object
1348 TopoDS_Shape anApplyedWire, aLastSegment;
1349 if (!createShapes(object, anApplyedWire, aLastSegment))
1352 // Set color for preview shape
1353 getDisplayer()->SetColor(line_color);
1356 SALOME_Prs* aPrs = getDisplayer()->BuildPrs(anApplyedWire);
1357 if (aPrs != 0 && !aPrs->IsNull())
1358 GEOMBase_Helper::displayPreview(aPrs, append, update);
1360 getDisplayer()->SetColor(Quantity_NOC_VIOLET);
1361 aPrs = getDisplayer()->BuildPrs(aLastSegment);
1363 if (aPrs != 0 && !aPrs->IsNull())
1364 GEOMBase_Helper::displayPreview(aPrs, append, update);
1366 getDisplayer()->SetColor(line_color);
1368 // Display local trihedron if the mode is relative
1370 displayTrihedron(2);
1372 // Display preview of suitable dimension presentations
1373 displayDimensions(false);
1375 getDisplayer()->UnsetName();
1377 // Enable activation of displayed objects
1378 getDisplayer()->SetToActivate(true);
1381 //================================================================
1382 // Function : displayTrihedron()
1383 // Purpose : Method for displaying trihedron
1384 //================================================================
1385 void EntityGUI_3DSketcherDlg::displayTrihedron (int selMode)
1387 // Add trihedron to preview
1388 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1390 SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( vw->getViewManager()->getViewModel() );
1394 Handle(AIS_InteractiveContext) anAISContext = anOCCViewer->getAISContext();
1398 gp_Pnt P(getLastPoint().x,getLastPoint().y,getLastPoint().z);
1399 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(P,gp::DZ(),gp::DX());
1400 Handle(AIS_Trihedron) anIO = new AIS_Trihedron(anAxis);
1402 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>( anOCCViewer->CreatePrs(0) );
1405 aSPrs->PrependObject(anIO);
1406 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1408 anAISContext->Activate(anIO, selMode);
1411 //================================================================
1412 // Function : displayDimensions( bool store )
1413 // Purpose : Method for displaying dimensions. If store = true
1414 // the presentation is stored in a list
1415 //================================================================
1416 void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
1418 myPrsType = prsType();
1419 XYZ Last = getLastPoint();
1420 XYZ Current = getCurrentPoint();
1422 gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
1424 gp_Pnt P0 = Last_Pnt;
1425 gp_Pnt Origin = gp::Origin();
1426 if (myMode == 0) // Absolute coordinates
1429 gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
1432 // Check if last end current point are coincident
1433 if (Last_Pnt.IsEqual(Current_Pnt, 1e-7))
1436 gp_Dir aNormal = getPresentationPlane();
1438 if (myCoordType == 0)
1440 bool oneDimensionalMove = (isSame(Last_Pnt.X(), Current_Pnt.X()) &&
1441 isSame(Last_Pnt.Y(), Current_Pnt.Y()) ) ||
1442 (isSame(Last_Pnt.Y(), Current_Pnt.Y()) &&
1443 isSame(Last_Pnt.Z(), Current_Pnt.Z()) ) ||
1444 (isSame(Last_Pnt.X(), Current_Pnt.X()) &&
1445 isSame(Last_Pnt.Z(), Current_Pnt.Z()) );
1449 std::string aCoordText = "( " + doubleToString(Current_Pnt.X()) +
1450 ", " + doubleToString(Current_Pnt.Y()) +
1451 ", " + doubleToString(Current_Pnt.Z()) + " )";
1452 displayText(aCoordText, Current_Pnt, store);
1456 if (oneDimensionalMove)
1458 // For better colocation of dimensions if only one coordinate changes (aNormal is a better choice)
1459 displayLength(P0, Current_Pnt, aNormal, store);
1463 displayLength(gp_Pnt(P0.X(),Current.y,P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ().Reversed(), store);
1464 displayLength(gp_Pnt(Current.x,P0.Y(),P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ(), store);
1465 displayLength(gp_Pnt(Current.x,Current.y,P0.Z()), Current_Pnt, gp::DX(), store);
1469 else if (myCoordType == 1) // ANGLES
1471 bool spherical = GroupAngles->checkBox->isChecked();
1472 bool cylindrical = GroupAngles->checkBox_2->isChecked();
1474 double anAngle1 = GroupAngles->SpinBox_DA->value();
1475 double aLength = GroupAngles->SpinBox_DL->value();
1477 // Set the coordinates in the current coordinate system
1478 P1.SetCoord( aLength, 0.0, 0.0); // X direction
1479 P2.SetCoord( aLength * cos(anAngle1 * M_PI / 180. ),
1480 aLength * sin(anAngle1 * M_PI / 180. ),
1483 // Express the coordinates in the reference coordinate system (OXY)
1484 gp_Trsf aTransform = toReferenceSystem(P0);
1485 P1.Transform(aTransform);
1486 P2.Transform(aTransform);
1487 P1.Translate(Origin, P0);
1488 P2.Translate(Origin, P0);
1490 if(myMode !=0 || !store)
1491 displayAngle(anAngle1, P0, P1, P2, store);
1494 std::string anAngleText = doubleToString(anAngle1) + " deg.";
1495 displayText(anAngleText, Current_Pnt, store);
1500 double anAngle2 = GroupAngles->SpinBox_DA2->value();
1501 displayAngle(anAngle2, P0, P2, Current_Pnt, store);
1502 displayLength(P0, Current_Pnt, aNormal, store);
1506 bool sameRadius = isSame ( radius(Last_Pnt), radius(Current_Pnt) );
1507 bool sameHeight = isSame ( height(Last_Pnt), height(Current_Pnt) );
1509 gp_Vec aVec(P2, Current_Pnt);
1511 if (myMode == 0 && !sameRadius)
1513 displayLength(P0.Translated(aVec), P2.Translated(aVec), aNormal, store); // Radius
1515 else if (myMode == 1)
1516 displayLength(P0, P2, aNormal, store);
1519 (myMode == 1 || !sameHeight) )
1520 displayLength(P2, Current_Pnt, aNormal.Reversed(), store); // Height
1525 //================================================================
1526 // Function : displayAngle()
1527 // Purpose : Method for displaying angle dimensions
1528 //================================================================
1529 void EntityGUI_3DSketcherDlg::displayAngle (double theAngle,
1535 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1537 // Creation of the AIS object
1538 Handle(AIS_AngleDimension) anAngleIO = createAISAngleDimension(theAngle,
1542 if (anAngleIO.IsNull())
1547 // Erase dimensions presentations
1548 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
1549 myAnglePrs->PrependObject(anAngleIO);
1551 // Display modified presentation
1553 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
1555 // Update dimension presentation angle count for later undo / redo
1558 else if ( isAngleVisible)
1560 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1561 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1565 aSPrs->AddObject(anAngleIO);
1566 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1572 //================================================================
1573 // Function : displayLength()
1574 // Purpose : Method for displaying length dimensions for a segment
1576 //================================================================
1577 void EntityGUI_3DSketcherDlg::displayLength (gp_Pnt P1,
1582 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1584 double aLength = P1.Distance(P2);
1586 if (aLength < Precision::Confusion())
1589 Handle(AIS_LengthDimension) anIO = createAISLengthDimension(aLength, P1, P2, theNormal);
1593 // Erase length dimensions presentation
1594 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
1595 myLengthPrs->PrependObject(anIO);
1597 // Display modified presentation
1598 if (isLengthVisible)
1599 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
1601 // Update dimension presentation length count for later undo / redo
1604 else if (isLengthVisible)
1606 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1607 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1610 aSPrs->PrependObject(anIO);
1611 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1616 //================================================================
1617 // Function : displayText()
1618 // Purpose : Method for displaying length dimensions for a segment
1620 //================================================================
1621 void EntityGUI_3DSketcherDlg::displayText ( std::string theText,
1625 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1627 Handle(AIS_Text) anIO = new AIS_Text(TCollection_ExtendedString(theText.c_str()), P);
1631 // Erase length dimensions presentation
1632 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
1633 myTextPrs->PrependObject(anIO);
1635 // Display modified presentation
1636 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
1638 // Update dimension presentation text count for later undo / redo
1643 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1644 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1647 aSPrs->PrependObject(anIO);
1648 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1654 //================================================================
1655 // Function : createAISLengthDimension()
1656 // Purpose : Method for creation of a length dimension object
1657 // Returns an Handle on the AIS_LengthDimension object
1658 //================================================================
1659 Handle(AIS_LengthDimension) EntityGUI_3DSketcherDlg::createAISLengthDimension(double theLength,
1664 // Plane construction
1665 gce_MakePln gce_MP(P1, theNormal);
1666 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
1668 TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
1669 TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
1671 Handle(AIS_LengthDimension) anIO = new AIS_LengthDimension( aVert1, aVert2, aPlane->Pln() );
1673 anIO->SetCustomValue( theLength );
1675 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1676 int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
1678 Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
1680 aDimensionStyle->ArrowAspect()->SetLength( theLength / 20.0 );
1681 aDimensionStyle->LineAspect()->SetWidth( w );
1682 aDimensionStyle->MakeText3d( Standard_False );
1683 aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
1684 aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
1685 aDimensionStyle->MakeArrows3d( Standard_True );
1686 anIO->SetFlyout( 0.0 );
1687 anIO->SetDimensionAspect( aDimensionStyle );
1692 //================================================================
1693 // Function : createAISAngleDimension()
1694 // Purpose : Method for creation of an angle dimension object
1695 // Returns an Handle on the AIS_AngleDimension object
1696 //================================================================
1697 Handle(AIS_AngleDimension) EntityGUI_3DSketcherDlg::createAISAngleDimension(double theAngle,
1702 // Length of the built segment
1703 double aLength = P0.Distance(P1);
1706 if (Abs(theAngle) < Precision::Angular() ||
1707 aLength < Precision::Confusion())
1710 Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension( P1, P0, P2 );
1712 //anIO->SetCustomValue( theAngle );
1714 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1715 int w = resMgr->integerValue( "Geometry", "measures_line_width", 1 );
1717 Handle(Prs3d_DimensionAspect) aDimensionStyle = new Prs3d_DimensionAspect;
1719 aDimensionStyle->ArrowAspect()->SetLength( (theAngle * M_PI / 180.0) * (aLength / 20.0) );
1720 aDimensionStyle->LineAspect()->SetWidth( w );
1721 aDimensionStyle->SetTextHorizontalPosition( Prs3d_DTHP_Center );
1722 aDimensionStyle->SetTextVerticalPosition( Prs3d_DTVP_Center );
1723 aDimensionStyle->MakeText3d( Standard_False );
1724 aDimensionStyle->MakeArrows3d( Standard_True );
1726 anIO->SetDimensionAspect( aDimensionStyle );
1731 //================================================================
1732 // Function : createShapes
1733 // Purpose : Create applyed wire, and last segment from entry object
1734 //================================================================
1735 bool EntityGUI_3DSketcherDlg::createShapes (GEOM::GEOM_Object_ptr /*theObject*/,
1736 TopoDS_Shape& theApplyedWire,
1737 TopoDS_Shape& theLastSegment)
1739 QList<gp_Pnt> points;
1740 foreach (XYZ xyz, myPointsList) {
1741 gp_Pnt p(xyz.x, xyz.y, xyz.z);
1742 if (points.isEmpty() || points.last().Distance(p) > gp::Resolution())
1746 if (points.count() == 1) {
1747 // only one point is created
1748 BRepBuilderAPI_MakeVertex mkVertex (points.last());
1749 theApplyedWire = mkVertex.Shape();
1751 else if (points.count() > 1) {
1753 BRepBuilderAPI_MakePolygon mkWire;
1754 foreach(gp_Pnt p, points)
1756 theApplyedWire = mkWire.Shape();
1759 XYZ curxyz = getCurrentPoint();
1760 gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
1762 if (points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution()) {
1763 BRepBuilderAPI_MakeVertex mkVertex (curpnt);
1764 theLastSegment = mkVertex.Shape();
1767 BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
1768 theLastSegment = mkEdge.Shape();
1771 /* VSR: old algorithm does not work properly, see bug 0020899
1772 TopoDS_Shape aShape;
1773 if (!GEOMBase::GetShape(theObject, aShape))
1776 if (aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX)
1779 theApplyedWire = aShape;
1783 BRepBuilderAPI_MakeWire aBuilder;
1784 TopExp_Explorer edgeExp(aShape, TopAbs_EDGE);
1786 TopoDS_Shape anEdge = edgeExp.Current();
1788 if (edgeExp.More()) // i.e. non-last edge
1789 aBuilder.Add(TopoDS::Edge(anEdge));
1791 theLastSegment = anEdge;
1796 if (aBuilder.IsDone()) {
1797 theApplyedWire = aBuilder.Shape();
1799 else if (!theLastSegment.IsNull()) {
1800 TopExp_Explorer vertexExp(theLastSegment, TopAbs_VERTEX);
1801 theApplyedWire = vertexExp.Current();
1808 //================================================================
1809 // Function : doubleToString
1810 // Purpose : converts double to string
1811 //================================================================
1812 std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
1816 char format = 'g'; // truncated to a number of significant digits
1818 return QString::number(num, format, digNum).toStdString();
1821 //================================================================
1822 // Function : toReferenceSystem ()
1824 //================================================================
1825 gp_Trsf EntityGUI_3DSketcherDlg::toReferenceSystem(gp_Pnt origin) const
1827 gp_Trsf T; // Identity transformation
1828 gp_Ax3 reference_system; // OXY
1829 reference_system.SetLocation(origin);
1831 gp_Ax3 current_system = reference_system;
1832 switch (myOrientation)
1836 current_system = gp_Ax3(origin, gp::DX(), gp::DY());
1841 current_system = gp_Ax3(origin, gp::DY().Reversed(), gp::DX());
1846 T.SetTransformation( current_system, reference_system );
1851 //================================================================
1852 // Function : toCurrentSystem ()
1854 //================================================================
1855 gp_Trsf EntityGUI_3DSketcherDlg::toCurrentSystem(gp_Pnt origin) const
1857 return toReferenceSystem(origin).Inverted();
1860 //================================================================
1861 // Function : radius (gp_Pnt) const
1863 //================================================================
1864 double EntityGUI_3DSketcherDlg::radius (gp_Pnt thePnt) const
1866 // Get the point coordinates in the current coordinates system
1867 gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1868 gp_Pnt aPnt = thePnt.Transformed(aTrsf);
1870 double radius = sqrt(aPnt.X()*aPnt.X() + aPnt.Y()*aPnt.Y());
1874 //================================================================
1875 // Function : height (gp_Pnt) const
1877 //================================================================
1878 double EntityGUI_3DSketcherDlg::height (gp_Pnt thePnt) const
1880 // Get the point coordinates in the current coordinates system
1881 gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1882 gp_Pnt aPnt = thePnt.Transformed(aTrsf);