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"
30 #include <Basics_OCCTVersion.hxx>
33 #include <GeometryGUI.h>
34 #include <Precision.hxx>
37 #include <SUIT_Session.h>
38 #include <SUIT_Desktop.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_ViewWindow.h>
42 #include <SUIT_ViewManager.h>
44 #include <SOCC_ViewModel.h>
45 #include <SalomeApp_Application.h>
46 #include <SalomeApp_DoubleSpinBox.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SalomeApp_Tools.h>
54 #include <TColStd_IndexedMapOfInteger.hxx>
55 #include <BRepBuilderAPI_MakeVertex.hxx>
56 #include <BRepBuilderAPI_MakePolygon.hxx>
57 #include <BRepBuilderAPI_MakeEdge.hxx>
59 #include <AIS_Trihedron.hxx>
60 #include <AIS_AngleDimension.hxx>
61 #include <AIS_LengthDimension.hxx>
62 #include <AIS_Drawer.hxx>
63 #include <Geom_Axis2Placement.hxx>
64 #include <Geom_Plane.hxx>
65 #include <SelectMgr_Selection.hxx>
66 #include <gce_MakePln.hxx>
67 #include <Prs3d_AngleAspect.hxx>
68 #include <Prs3d_LineAspect.hxx>
69 #include <Prs3d_LengthAspect.hxx>
70 #if OCC_VERSION_LARGE > 0x06050300
71 #include <Prs3d_TextAspect.hxx>
72 #include <Prs3d_Presentation.hxx>
73 #include <Prs3d_Text.hxx>
74 #include <Graphic3d_VerticalTextAlignment.hxx>
75 #include <Graphic3d_HorizontalTextAlignment.hxx>
76 #include <Graphic3d_AspectText3d.hxx>
77 #include <Font_FontAspect.hxx>
78 #endif // OCC_VERSION_LARGE > 0x06050300
80 // This include must be *AFTER* SOCC_ViewModel.h because
81 // of the constant ROTATE which is a #define in
82 // GEOMImpl_Types.hxx and an enum in SOCC_ViewModel.h
83 #include <GEOMImpl_Types.hxx>
87 // Avoid duplication of angle coordinates in cylindrical mode
88 // Check spherical mode in absolute
100 Locker(bool& l) : myLock(l) { myLock = true; }
101 ~Locker() { myLock = false; }
106 #if OCC_VERSION_LARGE > 0x06050300
107 DEFINE_STANDARD_HANDLE(AIS_Text, AIS_InteractiveObject)
109 class AIS_Text:public AIS_InteractiveObject
113 DEFINE_STANDARD_RTTI(AIS_Text );
119 const TCollection_ExtendedString& , const gp_Pnt& ,
120 Quantity_Color color,
121 Standard_Integer aHJust,
122 Standard_Integer aVJust ,
123 Standard_Real Angle ,
124 Standard_Boolean Zoom ,
125 Standard_Real Height,
126 Font_FontAspect FontAspect,
127 Standard_CString Font
132 void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
133 const Handle(Prs3d_Presentation)& aPresentation,
134 const Standard_Integer aMode);
136 void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection,
137 const Standard_Integer aMode){} ;
140 TCollection_ExtendedString aText;
145 Standard_Real aAngle;
146 Standard_Real aHeight;
147 Standard_Boolean aZoomable;
148 Quantity_Color aColor;
149 Standard_CString aFont;
150 Font_FontAspect aFontAspect;
151 Graphic3d_HorizontalTextAlignment aHJustification;
152 Graphic3d_VerticalTextAlignment aVJustification;
155 IMPLEMENT_STANDARD_HANDLE(AIS_Text, AIS_InteractiveObject)
156 IMPLEMENT_STANDARD_RTTIEXT(AIS_Text, AIS_InteractiveObject)
158 AIS_Text::AIS_Text( const TCollection_ExtendedString& text, const gp_Pnt& position,
159 Quantity_Color color = Quantity_NOC_YELLOW,
160 Standard_Integer aHJust = Graphic3d_HTA_LEFT,
161 Standard_Integer aVJust = Graphic3d_VTA_BOTTOM,
162 Standard_Real angle = 0.0 ,
163 Standard_Boolean zoomable = Standard_False,
164 Standard_Real height = 16.,
165 Font_FontAspect fontAspect = Font_FA_Regular,
166 Standard_CString font = "Courier")
169 aPosition = position;
170 aHJustification = Graphic3d_HorizontalTextAlignment(aHJust);
171 aVJustification = Graphic3d_VerticalTextAlignment(aVJust);
173 aZoomable = zoomable;
176 aFontAspect = fontAspect;
180 void AIS_Text::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
181 const Handle(Prs3d_Presentation)& aPresentation,
182 const Standard_Integer aMode)
185 aPresentation->Clear();
187 Handle_Prs3d_TextAspect asp = myDrawer->TextAspect();
190 asp->SetColor(aColor);
191 asp->SetHeight(aHeight); // I am changing the myHeight value
193 asp->SetHorizontalJustification(aHJustification);
194 asp->SetVerticalJustification(aVJustification);
195 asp->Aspect()->SetTextZoomable(aZoomable);
196 asp->Aspect()->SetTextAngle(aAngle);
197 asp->Aspect()->SetTextFontAspect(aFontAspect);
198 Prs3d_Text::Draw(aPresentation, asp, aText, aPosition);
200 #endif // OCC_VERSION_LARGE > 0x06050300
202 bool isSame (double d1, double d2)
204 return Abs(d1 - d2) <= Precision::Confusion();
207 //=================================================================================
208 // class : EntityGUI_3DSketcherDlg()
209 // purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
210 // name 'name' and widget flags set to 'f'.
211 // The dialog will by default be modeless, unless you set 'modal' to
212 // TRUE to construct a modal dialog.
213 //=================================================================================
214 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
215 bool modal, Qt::WindowFlags fl,
216 const double lineWidth)
217 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
220 myLineWidth(lineWidth),
221 myGeometryGUI(theGeometryGUI),
224 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
225 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
226 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REDO")));
227 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_3DSKETCH")));
229 setWindowTitle(tr("GEOM_3DSKETCHER_TITLE"));
231 /***************************************************************/
233 mainFrame()->GroupConstructors->setTitle(tr("GEOM_3DSKETCHER"));
234 mainFrame()->RadioButton1->setIcon(image3);;
235 mainFrame()->RadioButton2->close();
236 mainFrame()->RadioButton3->close();
238 GroupType = new EntityGUI_Type(centralWidget());
239 GroupType->GroupType2->setTitle(tr("GEOM_COORDINATES_TYPE"));
240 GroupType->GroupType1->setTitle(tr("GEOM_MODE"));
241 GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
242 GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
243 GroupType->RadioButton3->setText(tr("(X,Y,Z)"));
244 GroupType->RadioButton4->setText(tr("GEOM_ANGLES"));
246 myTypeGroup1 = new QButtonGroup(this);
247 myTypeGroup1->setExclusive(true);
248 myTypeGroup1->addButton(GroupType->RadioButton1, 0);
249 myTypeGroup1->addButton(GroupType->RadioButton2, 1);
251 myTypeGroup2 = new QButtonGroup(this);
252 myTypeGroup2->setExclusive(true);
253 myTypeGroup2->addButton(GroupType->RadioButton3, 0);
254 myTypeGroup2->addButton(GroupType->RadioButton4, 1);
256 Group3Spin = new EntityGUI_3Spin(centralWidget());
257 Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
258 Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
259 Group3Spin->buttonUndo->setIcon(image1);
260 Group3Spin->buttonRedo->setIcon(image2);
261 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
262 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
263 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
265 GroupAngles = new EntityGUI_Angles(centralWidget());
266 GroupAngles->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
267 GroupAngles->buttonUndo->setIcon(image1);
268 GroupAngles->buttonRedo->setIcon(image2);
269 GroupAngles->TextLabel1->setText(tr("GEOM_LENGTH"));
270 GroupAngles->TextLabel2->setText(tr("GEOM_ANGLE"));
271 GroupAngles->checkBox ->setText(tr("GEOM_ANGLE_2"));
272 GroupAngles->checkBox_2->setText(tr("GEOM_HEIGHT"));
274 GroupControls = new EntityGUI_Controls(centralWidget());
275 GroupControls->GroupBox1->setTitle(tr("GEOM_CONTROLS"));
276 GroupControls->CheckBox1->setText(tr("GEOM_SHOW_LENGTH"));
277 GroupControls->CheckBox2->setText(tr("GEOM_SHOW_ANGLE"));
278 GroupControls->CheckBox3->setText(tr("GEOM_SHOW_POINTS_COORD"));
279 GroupControls->lineEdit_1->setReadOnly(true);
280 GroupControls->lineEdit_2->setReadOnly(true);
281 GroupControls->lineEdit_3->setReadOnly(true);
282 GroupControls->lineEdit_4->setReadOnly(true);
283 GroupControls->lineEdit_5->setReadOnly(true);
284 GroupControls->lineEdit_6->setReadOnly(true);
285 GroupControls->label_1->setText(tr("X:"));
286 GroupControls->label_2->setText(tr("Y:"));
287 GroupControls->label_3->setText(tr("Z:"));
288 GroupControls->label_4->setText(tr("X:"));
289 GroupControls->label_5->setText(tr("Y:"));
290 GroupControls->label_6->setText(tr("Z:"));
291 GroupControls->label_7->setText(tr("GEOM_START"));
292 GroupControls->label_8->setText(tr("GEOM_END"));
294 buttonOk()->setText(tr("GEOM_BUT_END_SKETCH"));
295 buttonApply()->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
297 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
298 layout->setMargin(0); layout->setSpacing(6);
299 layout->addWidget(GroupType);
300 layout->addWidget(Group3Spin);
301 layout->addWidget(GroupAngles);
302 layout->addWidget(GroupControls);
304 setHelpFileName("create_3dsketcher_page.html");
310 //=================================================================================
311 // function : ~EntityGUI_3DSketcherDlg()
312 // purpose : Destroys the object and frees any allocated resources
313 //=================================================================================
314 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
316 myGeomGUI->SetActiveDialogBox(0);
319 //=================================================================================
322 //=================================================================================
323 void EntityGUI_3DSketcherDlg::Init()
327 myPrsType = prsType();
329 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
330 myAnglePrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
331 myLengthPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
332 #if OCC_VERSION_LARGE > 0x06050300
333 myTextPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
334 #endif // OCC_VERSION_LARGE > 0x06050300
336 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
338 /* Get setting of step value from file configuration */
339 double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
341 /* min, max, step and decimals for spin boxes */
342 initSpinBox(Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
343 initSpinBox(Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
344 initSpinBox(Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
346 initSpinBox(GroupAngles->SpinBox_DA , -360.0, 360.0, step, "angular_precision");
347 initSpinBox(GroupAngles->SpinBox_DA2, -90.0, 90.0, step, "angular_precision");
348 initSpinBox(GroupAngles->SpinBox_DL , COORD_MIN, COORD_MAX, step, "length_precision");
349 initSpinBox(GroupAngles->SpinBox_DH , COORD_MIN, COORD_MAX, step, "length_precision");
351 Group3Spin->SpinBox_DX->setValue(0.0);
352 Group3Spin->SpinBox_DY->setValue(0.0);
353 Group3Spin->SpinBox_DZ->setValue(0.0);
355 GroupAngles->SpinBox_DA->setValue(0.0);
356 GroupAngles->SpinBox_DA2->setValue(0.0);
357 GroupAngles->SpinBox_DL->setValue(0.0);
358 GroupAngles->SpinBox_DH->setValue(0.0);
360 GroupAngles->radioButton_1->setChecked(true);
361 GroupAngles->checkBox->setChecked(false);
362 GroupAngles->checkBox_2->setChecked(false);
363 GroupAngles->SpinBox_DA2->setEnabled(false);
364 GroupAngles->SpinBox_DH->setEnabled(false);
366 GroupControls->CheckBox1->setChecked(true);
367 GroupControls->CheckBox2->setChecked(true);
368 GroupControls->CheckBox3->setChecked(true);
370 isLengthVisible = true;
371 isAngleVisible = true;
375 /* signals and slots connections */
376 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
377 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
379 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
381 connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
382 connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
383 connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
385 connect(GroupAngles->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
386 connect(GroupAngles->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
387 connect(GroupAngles->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
389 connect(myTypeGroup1, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
390 connect(myTypeGroup2, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
392 connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
393 connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
394 connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
396 connect(GroupAngles->SpinBox_DA, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
397 connect(GroupAngles->SpinBox_DA2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
398 connect(GroupAngles->SpinBox_DL, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
399 connect(GroupAngles->SpinBox_DH, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
401 connect(GroupAngles->radioButton_1, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
402 connect(GroupAngles->radioButton_2, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
403 connect(GroupAngles->radioButton_3, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
405 connect(GroupAngles->checkBox, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
406 connect(GroupAngles->checkBox_2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
407 connect(GroupControls->CheckBox1, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
408 connect(GroupControls->CheckBox2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
409 connect(GroupControls->CheckBox3, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
411 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
413 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
414 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
416 initName(tr("GEOM_3DSKETCHER"));
418 GroupControls->CheckBox3->click();
420 UpdateButtonsState();
425 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
428 //=================================================================================
429 // function : TypeClicked()
430 // purpose : Radio button management
431 //=================================================================================
432 void EntityGUI_3DSketcherDlg::TypeClicked (int id)
434 QButtonGroup* send = (QButtonGroup*) sender();
436 int coordType = myCoordType;
439 if (send == myTypeGroup1)
441 if(id == myMode) return;
444 else if (send == myTypeGroup2)
446 if (id == myCoordType) return;
453 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
454 Group3Spin->SpinBox_DX->blockSignals(true);
455 Group3Spin->SpinBox_DY->blockSignals(true);
456 Group3Spin->SpinBox_DZ->blockSignals(true);
458 // Get setting of step value from file configuration
459 XYZ xyz = getLastPoint();
461 Group3Spin->SpinBox_DX->text().toDouble(&okx);
462 Group3Spin->SpinBox_DY->text().toDouble(&oky);
463 Group3Spin->SpinBox_DZ->text().toDouble(&okz);
465 if (coordType == 0) // Cartesian coordinates
467 if (mode == 0) { // XYZ
468 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
469 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
470 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
471 if (myCoordType == 0 && myMode == 1)
473 if (okx) Group3Spin->SpinBox_DX->setValue(xyz.x + Group3Spin->SpinBox_DX->value());
474 if (oky) Group3Spin->SpinBox_DY->setValue(xyz.y + Group3Spin->SpinBox_DY->value());
475 if (okz) Group3Spin->SpinBox_DZ->setValue(xyz.z + Group3Spin->SpinBox_DZ->value());
477 Group3Spin->buttonApply->setFocus();
479 else if (mode == 1) { // DXDYDZ
480 Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
481 Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
482 Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_DZ2"));
483 if (myCoordType == 0 && myMode == 0)
485 if (okx) Group3Spin->SpinBox_DX->setValue(Group3Spin->SpinBox_DX->value() - xyz.x);
486 if (oky) Group3Spin->SpinBox_DY->setValue(Group3Spin->SpinBox_DY->value() - xyz.y);
487 if (okz) Group3Spin->SpinBox_DZ->setValue(Group3Spin->SpinBox_DZ->value() - xyz.z);
489 Group3Spin->buttonApply->setFocus();
492 else if (coordType == 1) // Angles and Length
496 GroupAngles->buttonApply->setFocus();
499 Group3Spin->SpinBox_DX->blockSignals(blocked);
500 Group3Spin->SpinBox_DY->blockSignals(blocked);
501 Group3Spin->SpinBox_DZ->blockSignals(blocked);
504 myCoordType = coordType;
507 resize(minimumSizeHint());
509 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
512 //=================================================================================
513 // function : ClickOnAddPoint()
514 // purpose : called when the point coordinates is Applyed
515 //=================================================================================
516 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
524 myPrsType = prsType();
527 displayDimensions( /*store = */true);
529 myPointsList.append(getCurrentPoint());
531 myLengthIORedoList.Clear();
532 myAngleIORedoList.Clear();
533 myTextIORedoList.Clear();
535 if (myCoordType == 0 && myMode == 1) // RELATIVE CARTESIAN COORDINATES
537 Group3Spin->SpinBox_DX->setValue(0.0);
538 Group3Spin->SpinBox_DY->setValue(0.0);
539 Group3Spin->SpinBox_DZ->setValue(0.0);
541 else if (myCoordType == 1 && myMode == 1) // RELATIVE ANGULAR COORDINATES
543 GroupAngles->SpinBox_DA->setValue(0.0);
544 GroupAngles->SpinBox_DL->setValue(0.0);
545 GroupAngles->SpinBox_DA2->setValue(0.0);
548 UpdatePointCoordinates();
550 UpdateButtonsState();
551 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
554 //=================================================================================
555 // function : UpdateButtonsState()
557 //=================================================================================
558 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
560 if (myPointsList.count() == 0)
562 GroupType->RadioButton1->click();
563 GroupType->RadioButton3->click();
565 GroupType->RadioButton2->setEnabled(myPointsList.count() > 0);
566 // GroupType->RadioButton3->setEnabled(myPointsList.count() > 0);
567 // GroupType->RadioButton4->setEnabled(myPointsList.count() > 0);
568 Group3Spin->buttonUndo->setEnabled(myPointsList.count() > 0);
569 Group3Spin->buttonRedo->setEnabled(myRedoList.count() > 0);
570 GroupAngles->buttonUndo->setEnabled(myPointsList.count() > 0);
571 GroupAngles->buttonRedo->setEnabled(myRedoList.count() > 0);
574 //=================================================================================
575 // function : UpdatePointCoordinates()
576 // purpose :Update point coordinates in the control groupbox
577 //=================================================================================
578 void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
580 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
581 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
583 if (myPointsList.count() == 0)
585 GroupControls->lineEdit_1->setText("");
586 GroupControls->lineEdit_2->setText("");
587 GroupControls->lineEdit_3->setText("");
589 GroupControls->lineEdit_4->setText("");
590 GroupControls->lineEdit_5->setText("");
591 GroupControls->lineEdit_6->setText("");
593 else if (myPointsList.count() == 1)
595 GroupControls->lineEdit_1->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
596 GroupControls->lineEdit_2->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
597 GroupControls->lineEdit_3->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
599 GroupControls->lineEdit_4->setText("");
600 GroupControls->lineEdit_5->setText("");
601 GroupControls->lineEdit_6->setText("");
605 GroupControls->lineEdit_4->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
606 GroupControls->lineEdit_5->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
607 GroupControls->lineEdit_6->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
612 //=================================================================================
613 // function : ClickOnUndo()
615 //=================================================================================
616 void EntityGUI_3DSketcherDlg::ClickOnUndo()
618 if (myPointsList.count() > 0) {
620 myRedoList.append(myPointsList.last());
622 // Erase dimensions presentations
623 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
624 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
625 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
626 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
628 removeLastIOFromPrs();
630 // Display modified presentation
632 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
634 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
635 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
637 // Remove last point from list
638 myPointsList.removeLast();
639 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
640 UpdateButtonsState();
642 // Update of point coordinates in the control groupbox
643 UpdatePointCoordinates();
649 //=================================================================================
650 // function : ClickOnRedo()
652 //=================================================================================
653 void EntityGUI_3DSketcherDlg::ClickOnRedo()
655 if (myRedoList.count() > 0) {
657 myPointsList.append(myRedoList.last());
659 // Erase dimensions presentations
660 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
661 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
662 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
663 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
665 restoreLastIOToPrs();
667 // Display modified presentation
669 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
671 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
672 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
674 // Remove last point from redo list
675 myRedoList.removeLast();
676 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
677 UpdateButtonsState();
679 // Update of point coordinates in the control groupbox
680 UpdatePointCoordinates();
686 //=================================================================================
687 // function : removeLastIO()
689 //=================================================================================
690 void EntityGUI_3DSketcherDlg::removeLastIOFromPrs ()
692 AIS_ListOfInteractive anIOList;
693 XYZ Last = getLastPoint();
695 for (int l = 0; l<Last.L; l++)
697 myLengthPrs->GetObjects(anIOList);
698 myLengthIORedoList.Prepend(anIOList.First()); // Store last prepended Length IO in redo list
699 myLengthPrs->RemoveFirst(); // Remove it from myLengthPrs
701 for (int a = 0; a<Last.A; a++)
703 myAnglePrs->GetObjects(anIOList);
704 myAngleIORedoList.Prepend(anIOList.First()); // Store last prepended Angle IO in redo list
705 myAnglePrs->RemoveFirst(); // Remove it from myAnglePrs
707 for (int t = 0; t<Last.T; t++)
709 myTextPrs->GetObjects(anIOList);
710 myTextIORedoList.Prepend(anIOList.First()); // Store last prepended Text IO in redo list
711 myTextPrs->RemoveFirst(); // Remove it from myTextPrs
715 //=================================================================================
716 // function : restoreLastIO()
718 //=================================================================================
719 void EntityGUI_3DSketcherDlg::restoreLastIOToPrs ()
721 XYZ LastDeleted = myRedoList.last();
723 for (int l = 0; l<LastDeleted.L; l++)
725 myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
726 myLengthIORedoList.RemoveFirst(); // Remove it from redo list
728 for (int a = 0; a<LastDeleted.A; a++)
730 myAnglePrs->PrependObject(myAngleIORedoList.First()); // Restore last removed IO
731 myAngleIORedoList.RemoveFirst(); // Remove it from redo list
733 for (int t = 0; t<LastDeleted.T; t++)
735 myTextPrs->PrependObject(myTextIORedoList.First()); // Restore last removed IO
736 myTextIORedoList.RemoveFirst(); // Remove it from redo list
740 //=================================================================================
741 // function : SelectionIntoArgument()
742 // purpose : Called when selection as changed
743 //=================================================================================
744 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
746 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
747 SALOME_ListIO aSelList;
748 aSelMgr->selectedObjects(aSelList);
750 int nbSel = aSelList.Extent();
752 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
753 if (!CORBA::is_nil(aSelectedObject)) {
755 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) {
756 // Explore the shape if its a local selection
757 TColStd_IndexedMapOfInteger aMap;
758 aSelMgr->GetIndexes(aSelList.First(), aMap);
759 if (aMap.Extent() == 1) {
760 int anIndex = aMap(1);
761 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
762 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
766 if (aShape.ShapeType() != TopAbs_VERTEX)
767 isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
770 if (GEOMBase::VertexToPoint(aShape, aPnt)) {
771 // set coordinates to the Spin Boxes
776 bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
777 Group3Spin->SpinBox_DX->blockSignals(true);
778 Group3Spin->SpinBox_DY->blockSignals(true);
779 Group3Spin->SpinBox_DZ->blockSignals(true);
780 if (GroupType->RadioButton1->isChecked()) {
781 Group3Spin->SpinBox_DX->setValue(aX);
782 Group3Spin->SpinBox_DY->setValue(aY);
783 Group3Spin->SpinBox_DZ->setValue(aZ);
785 else if (GroupType->RadioButton2->isChecked()) {
786 XYZ xyz = getLastPoint();
787 Group3Spin->SpinBox_DX->setValue(aX - xyz.x);
788 Group3Spin->SpinBox_DY->setValue(aY - xyz.y);
789 Group3Spin->SpinBox_DZ->setValue(aZ - xyz.z);
791 Group3Spin->SpinBox_DX->blockSignals(blocked);
792 Group3Spin->SpinBox_DY->blockSignals(blocked);
793 Group3Spin->SpinBox_DZ->blockSignals(blocked);
798 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
801 //=================================================================================
802 // function : DeactivateActiveDialog()
804 //=================================================================================
805 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
809 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
810 myGeomGUI->SetActiveDialogBox(0);
813 //=================================================================================
814 // function : ActivateThisDialog()
816 //=================================================================================
817 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
819 myGeomGUI->EmitSignalDeactivateDialog();
821 myGeomGUI->SetActiveDialogBox(this);
823 connect(myGeomGUI->getApp()->selectionMgr(),
824 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
826 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
827 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
830 //=================================================================================
831 // function : ValueChangedInSpinBox()
833 //=================================================================================
834 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox (double newValue)
836 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
839 //=================================================================================
840 // function : BoxChecked()
841 // purpose : ChecBoxes management
842 //=================================================================================
843 void EntityGUI_3DSketcherDlg::BoxChecked (bool checked)
845 QCheckBox* send = (QCheckBox*) sender();
846 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
848 if (send == GroupAngles->checkBox)
850 GroupAngles->SpinBox_DA2->setEnabled(checked);
853 GroupAngles->SpinBox_DH->setEnabled(false);
854 GroupAngles->checkBox_2->setChecked(false);
857 else if (send == GroupAngles->checkBox_2)
859 GroupAngles->SpinBox_DH->setEnabled(checked);
862 GroupAngles->SpinBox_DA2->setEnabled(false);
863 GroupAngles->checkBox->setChecked(false);
867 else if (send == GroupControls->CheckBox1)
869 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
871 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
872 isLengthVisible=true;
875 isLengthVisible=false;
877 else if (send == GroupControls->CheckBox2)
879 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
882 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
886 isAngleVisible=false;
888 else if (send == GroupControls->CheckBox3)
890 GroupControls->lineEdit_1->setVisible(checked);
891 GroupControls->lineEdit_2->setVisible(checked);
892 GroupControls->lineEdit_3->setVisible(checked);
893 GroupControls->lineEdit_4->setVisible(checked);
894 GroupControls->lineEdit_5->setVisible(checked);
895 GroupControls->lineEdit_6->setVisible(checked);
897 GroupControls->label_1->setVisible(checked);
898 GroupControls->label_2->setVisible(checked);
899 GroupControls->label_3->setVisible(checked);
900 GroupControls->label_4->setVisible(checked);
901 GroupControls->label_5->setVisible(checked);
902 GroupControls->label_6->setVisible(checked);
903 GroupControls->label_7->setVisible(checked);
904 GroupControls->label_8->setVisible(checked);
906 GroupControls->updateGeometry();
907 GroupControls->resize(minimumSizeHint());
911 resize(minimumSizeHint());
913 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
916 //=================================================================================
917 // function : ButtonClicked()
919 //=================================================================================
920 void EntityGUI_3DSketcherDlg::ButtonClicked (bool checked)
922 if (GroupAngles->radioButton_1->isChecked())
924 else if (GroupAngles->radioButton_2->isChecked())
929 GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
932 //=================================================================================
933 // function : enterEvent()
935 //=================================================================================
936 void EntityGUI_3DSketcherDlg::enterEvent (QEvent*)
938 if (!mainFrame()->GroupConstructors->isEnabled())
939 ActivateThisDialog();
942 //=================================================================================
943 // function : createOperation
945 //=================================================================================
946 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
948 return getGeomEngine()->GetICurvesOperations(getStudyId());
951 //=================================================================================
952 // function : isValid
954 //=================================================================================
955 bool EntityGUI_3DSketcherDlg::isValid (QString& msg)
958 ok = Group3Spin->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
959 ok = Group3Spin->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
960 ok = Group3Spin->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
964 //=================================================================================
965 // function : execute
967 //=================================================================================
968 bool EntityGUI_3DSketcherDlg::execute (ObjectList& objects)
970 //GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
971 //if (!myOK || myPointsList.size() == 0)
972 // aCoordsArray->length((myPointsList.size()+1)*3);
974 // aCoordsArray->length(myPointsList.size()*3);
976 QStringList aCommands;
977 aCommands << "3DSketcher";
978 QStringList aParameters;
981 QList<XYZ>::const_iterator it;
982 for (it = myPointsList.begin(); it != myPointsList.end(); ++it) {
983 //aCoordsArray[i++] = (*it).x;
984 //aCoordsArray[i++] = (*it).y;
985 //aCoordsArray[i++] = (*it).z;
986 aCommands << (*it).command;
987 aParameters << (*it).params;
990 if (!myOK || myPointsList.size() == 0) {
991 XYZ xyz = getCurrentPoint();
992 //aCoordsArray[i++] = xyz.x;
993 //aCoordsArray[i++] = xyz.y;
994 //aCoordsArray[i++] = xyz.z;
995 aCommands << xyz.command;
996 aParameters << xyz.params;
999 // MESSAGE("aCommands.last() = "<< aCommands.last().toStdString());
1000 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
1001 //GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher(aCoordsArray);
1002 GEOM::GEOM_Object_var anObj = anOper->Make3DSketcherCommand(aCommands.join(":").toLatin1().constData());
1004 if (!anObj->_is_nil()) {
1005 if (!IsPreview()) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
1006 objects.push_back(anObj._retn());
1012 //=================================================================================
1013 // function : SetDoubleSpinBoxStep()
1014 // purpose : Double spin box management
1015 //=================================================================================
1016 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep (double step)
1018 Group3Spin->SpinBox_DX->setSingleStep(step);
1019 Group3Spin->SpinBox_DY->setSingleStep(step);
1020 Group3Spin->SpinBox_DZ->setSingleStep(step);
1021 GroupAngles->SpinBox_DA ->setSingleStep(step);
1022 GroupAngles->SpinBox_DA2->setSingleStep(step);
1023 GroupAngles->SpinBox_DL->setSingleStep(step);
1024 GroupAngles->SpinBox_DH->setSingleStep(step);
1027 //=================================================================================
1028 // function : ClickOnOk()
1030 //=================================================================================
1031 void EntityGUI_3DSketcherDlg::ClickOnOk()
1041 //=================================================================================
1042 // function : ClickOnApply()
1044 //=================================================================================
1045 bool EntityGUI_3DSketcherDlg::ClickOnApply()
1048 if (!isValid(msg)) {
1053 if (myPointsList.count() > 0)
1054 myPointsList.append(myPointsList[0]);
1065 //=================================================================================
1066 // function : getLastPoint()
1067 // purpose : return last points from list
1068 //=================================================================================
1069 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
1071 return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
1074 //=================================================================================
1075 // function : getPenultimatePoint()
1076 // purpose : return penultimate point from list
1077 //=================================================================================
1078 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getPenultimatePoint() const
1080 double size = myPointsList.count();
1081 return size > 1 ? myPointsList.at(size - 2) : XYZ();
1084 //=================================================================================
1085 // function : getCurrentPoint()
1086 // purpose : returns current point
1087 //=================================================================================
1088 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
1092 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1093 int aPrecision = resMgr->integerValue("Geometry", "length_precision", 7);
1095 bool spherical = GroupAngles->checkBox->isChecked();
1096 bool cylindrical = GroupAngles->checkBox_2->isChecked();
1098 if (myCoordType == 1)
1100 if (GroupAngles->radioButton_1->isChecked())
1101 xyz.command = "OXY";
1102 else if (GroupAngles->radioButton_2->isChecked())
1103 xyz.command = "OYZ";
1105 xyz.command = "OXZ";
1107 if (cylindrical) // Cylindrical coordinates (radius, angle, height)
1110 xyz.command += "S"; // Spherical coordinates (radius, angle1, angle2) --> polar if angle2 = 0
1112 if (myMode == 0) // Absolute coordinates
1113 xyz.command += "A ";
1114 else if (myMode == 1) // Relative coordinates
1115 xyz.command += "R ";
1118 double anAngle = GroupAngles->SpinBox_DA->value();
1119 double aLength = GroupAngles->SpinBox_DL->value();
1121 double anAngle2 = 0.0;
1123 if (spherical) { // Spherical coordinates (radius, angle1, angle2)
1124 anAngle2 = GroupAngles->SpinBox_DA2->value();
1125 da2 = GroupAngles->SpinBox_DA2->text();
1128 double aHeight = 0.0;
1131 aHeight = GroupAngles->SpinBox_DH->value();
1132 dh = GroupAngles->SpinBox_DH->text();
1136 QString::number(anAngle, 'g', aPrecision) + " ";
1138 GroupAngles->SpinBox_DA->text() + ":";
1143 QString::number(aHeight, 'g', aPrecision) + " ";
1147 else // Spherical or polar coordinates
1150 QString::number(anAngle2, 'g', aPrecision) + " ";
1156 QString::number(aLength, 'g', aPrecision);
1158 GroupAngles->SpinBox_DL->text();
1161 // Calculate point coordinates for preview
1162 anAngle = anAngle * M_PI/180.0;
1163 anAngle2 = anAngle2 * M_PI/180.0;
1164 double aProjectedLength = aLength * cos(anAngle2);
1166 XYZ xyzP = getLastPoint();
1168 xyzP.x=xyzP.y=xyzP.z=0.0;
1169 if (GroupAngles->radioButton_1->isChecked()) // OXY
1171 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1172 xyz.y = xyzP.y + aProjectedLength * sin(anAngle);
1174 xyz.z = xyzP.z + aHeight;
1176 xyz.z = xyzP.z + aLength * sin(anAngle2);
1178 else if (GroupAngles->radioButton_2->isChecked()) // OYZ
1180 xyz.y = xyzP.y + aProjectedLength * cos(anAngle);
1181 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1183 xyz.x = xyzP.x + aHeight;
1185 xyz.x = xyzP.x + aLength * sin(anAngle2);
1189 xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
1190 xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
1192 xyz.y = xyzP.y + aHeight;
1194 xyz.y = xyzP.y + aLength * sin(anAngle2);
1197 else if(myCoordType == 0) {
1198 if (myMode == 0) { // XYZ
1199 xyz.x = Group3Spin->SpinBox_DX->value();
1200 xyz.y = Group3Spin->SpinBox_DY->value();
1201 xyz.z = Group3Spin->SpinBox_DZ->value();
1202 xyz.command = "TT ";
1205 xyz = getLastPoint();
1206 xyz.x += Group3Spin->SpinBox_DX->value();
1207 xyz.y += Group3Spin->SpinBox_DY->value();
1208 xyz.z += Group3Spin->SpinBox_DZ->value();
1212 double aX = Group3Spin->SpinBox_DX->value();
1213 double aY = Group3Spin->SpinBox_DY->value();
1214 double aZ = Group3Spin->SpinBox_DZ->value();
1217 QString::number(aX, 'g', aPrecision) + " " +
1218 QString::number(aY, 'g', aPrecision) + " " +
1219 QString::number(aZ, 'g', aPrecision);
1221 Group3Spin->SpinBox_DX->text() + ":" +
1222 Group3Spin->SpinBox_DY->text() + ":" +
1223 Group3Spin->SpinBox_DZ->text();
1225 // Update point presentation type
1226 xyz.A = myPrsType.A; // Number of angle diomensions
1227 xyz.L = myPrsType.L; // Number of length dimensions
1228 xyz.T = myPrsType.T; // Number of text objects
1234 //=================================================================================
1235 // function : getPresentationPlane()
1236 // purpose : returns the suitable plane for right
1237 // relative positioning of dimension presentations
1238 //=================================================================================
1239 gp_Dir EntityGUI_3DSketcherDlg::getPresentationPlane() const
1241 bool withAngle = (myCoordType == 1);
1242 bool twoAngles = GroupAngles->checkBox->isChecked();
1244 XYZ Last = getLastPoint();
1245 XYZ Current = getCurrentPoint();
1246 XYZ Penultimate = getPenultimatePoint();
1248 gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
1249 if (myMode == 0) // Absolute coordinates
1252 gp_Pnt P2 = gp_Pnt(Current.x,Current.y,Current.z);
1253 gp_Pnt P3 = gp_Pnt(Penultimate.x,Penultimate.y,Penultimate.z);
1258 gp_Dir aNormal; // Normal defining the plane of the presentation
1260 if (withAngle) // If one angle
1262 // Transformation from the current coordinate system
1263 // to the reference coordinate system
1264 gp_Trsf aTransform = toReferenceSystem (P1);
1265 gp_Dir N1 = gp::DZ();
1266 gp_Dir N2 = gp::DY();
1267 N1.Transform(aTransform);
1268 N2.Transform(aTransform);
1270 if (Vec1.CrossMagnitude(N1) > Precision::Confusion())
1272 // The plane is orthogonal to the angle presentation plane
1273 // and contains the current edge
1274 aNormal = N1.Crossed(gp_Dir(Vec1));
1281 gp_Vec V = Vec1.Transformed(aTransform.Inverted());
1282 gp_Vec Vec3(V.X(),V.Y(),0.0);
1284 // Express the coordinates in the refernce coordinate system (OXY)
1285 Vec3.Transform(aTransform);
1286 if(Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
1288 // set the normal as the cross product of the current edge with its projection
1289 // it ensures that the dimension changes side when the angle becomes negative
1290 aNormal = gp_Dir(Vec1.Crossed(Vec3));
1296 // Check colinearity
1297 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1299 Vec2 = gp_Vec(gp::DX());
1300 if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
1302 Vec2 = gp_Vec(gp::DY());
1305 // If no angles, the plane is the one formed by the last edge and the current one
1306 aNormal = gp_Dir(Vec1.Crossed(Vec2));
1311 //================================================================
1312 // Function : displayPreview
1313 // Purpose : Method for displaying preview of resulting shape
1314 // Redefined from GEOMBase_Helper.
1315 //================================================================
1316 void EntityGUI_3DSketcherDlg::displayPreview (GEOM::GEOM_Object_ptr object,
1318 const bool activate,
1320 const double lineWidth,
1321 const int displayMode,
1324 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1326 QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
1327 Quantity_NameOfColor line_color = SalomeApp_Tools::color(aColor).Name();
1329 // set width of displayed shape
1332 lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
1334 getDisplayer()->SetWidth(lw);
1336 // Disable activation of selection
1337 getDisplayer()->SetToActivate(activate);
1339 // Make a reference to GEOM_Object
1340 CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string(object);
1341 getDisplayer()->SetName(objStr.in());
1343 // Create wire from applied object
1344 TopoDS_Shape anApplyedWire, aLastSegment;
1345 if (!createShapes(object, anApplyedWire, aLastSegment))
1348 // Set color for preview shape
1349 getDisplayer()->SetColor(line_color);
1352 SALOME_Prs* aPrs = getDisplayer()->BuildPrs(anApplyedWire);
1353 if (aPrs != 0 && !aPrs->IsNull())
1354 GEOMBase_Helper::displayPreview(aPrs, append, update);
1356 getDisplayer()->SetColor(Quantity_NOC_VIOLET);
1357 aPrs = getDisplayer()->BuildPrs(aLastSegment);
1359 if (aPrs != 0 && !aPrs->IsNull())
1360 GEOMBase_Helper::displayPreview(aPrs, append, update);
1362 getDisplayer()->SetColor(line_color);
1364 // Display local trihedron if the mode is relative
1366 displayTrihedron(2);
1368 // Display preview of suitable dimension presentations
1369 displayDimensions(false);
1371 getDisplayer()->UnsetName();
1373 // Enable activation of displayed objects
1374 getDisplayer()->SetToActivate(true);
1377 //================================================================
1378 // Function : displayTrihedron()
1379 // Purpose : Method for displaying trihedron
1380 //================================================================
1381 void EntityGUI_3DSketcherDlg::displayTrihedron (int selMode)
1383 // Add trihedron to preview
1384 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1386 gp_Pnt P(getLastPoint().x,getLastPoint().y,getLastPoint().z);
1387 Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(P,gp::DZ(),gp::DX());
1388 Handle(AIS_Trihedron) anIO = new AIS_Trihedron(anAxis);
1389 anIO->SetSelectionMode(selMode);
1391 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1392 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1395 aSPrs->PrependObject(anIO);
1396 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1400 //================================================================
1401 // Function : displayDimensions( bool store )
1402 // Purpose : Method for displaying dimensions. If store = true
1403 // the presentation is stored in a list
1404 //================================================================
1405 void EntityGUI_3DSketcherDlg::displayDimensions (bool store)
1407 myPrsType = prsType();
1408 XYZ Last = getLastPoint();
1409 XYZ Current = getCurrentPoint();
1411 gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
1413 gp_Pnt P0 = Last_Pnt;
1414 gp_Pnt Origin = gp::Origin();
1415 if (myMode == 0) // Absolute coordinates
1418 gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
1421 // Check if last end current point are coincident
1422 if (Last_Pnt.IsEqual(Current_Pnt, 1e-7))
1425 gp_Dir aNormal = getPresentationPlane();
1427 if (myCoordType == 0)
1429 bool oneDimensionalMove = (isSame(Last_Pnt.X(), Current_Pnt.X()) &&
1430 isSame(Last_Pnt.Y(), Current_Pnt.Y()) ) ||
1431 (isSame(Last_Pnt.Y(), Current_Pnt.Y()) &&
1432 isSame(Last_Pnt.Z(), Current_Pnt.Z()) ) ||
1433 (isSame(Last_Pnt.X(), Current_Pnt.X()) &&
1434 isSame(Last_Pnt.Z(), Current_Pnt.Z()) );
1438 std::string aCoordText = "( " + doubleToString(Current_Pnt.X()) +
1439 ", " + doubleToString(Current_Pnt.Y()) +
1440 ", " + doubleToString(Current_Pnt.Z()) + " )";
1441 displayText(aCoordText, Current_Pnt, store);
1445 if (oneDimensionalMove)
1447 // For better colocation of dimensions if only one coordinate changes (aNormal is a better choice)
1448 displayLength(P0, Current_Pnt, aNormal, store);
1452 displayLength(gp_Pnt(P0.X(),Current.y,P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ().Reversed(), store);
1453 displayLength(gp_Pnt(Current.x,P0.Y(),P0.Z()), gp_Pnt(Current.x,Current.y,P0.Z()), gp::DZ(), store);
1454 displayLength(gp_Pnt(Current.x,Current.y,P0.Z()), Current_Pnt, gp::DX(), store);
1458 else if (myCoordType == 1) // ANGLES
1460 bool spherical = GroupAngles->checkBox->isChecked();
1461 bool cylindrical = GroupAngles->checkBox_2->isChecked();
1463 double anAngle1 = GroupAngles->SpinBox_DA->value();
1464 double aLength = GroupAngles->SpinBox_DL->value();
1466 // Set the coordinates in the current coordinate system
1467 P1.SetCoord( aLength, 0.0, 0.0); // X direction
1468 P2.SetCoord( aLength * cos(anAngle1 * M_PI / 180. ),
1469 aLength * sin(anAngle1 * M_PI / 180. ),
1472 // Express the coordinates in the refernce coordinate system (OXY)
1473 gp_Trsf aTranform = toReferenceSystem(P0);
1474 P1.Transform(aTranform);
1475 P2.Transform(aTranform);
1476 P1.Translate(Origin, P0);
1477 P2.Translate(Origin, P0);
1479 if(myMode !=0 || !store)
1480 displayAngle(anAngle1, P0, P1, P2, store);
1483 std::string anAngleText = doubleToString(anAngle1) + " deg.";
1484 displayText(anAngleText, Current_Pnt, store);
1489 double anAngle2 = GroupAngles->SpinBox_DA2->value();
1490 displayAngle(anAngle2, P0, P2, Current_Pnt, store);
1491 displayLength(P0, Current_Pnt, aNormal, store);
1495 bool sameRadius = isSame ( radius(Last_Pnt), radius(Current_Pnt) );
1496 bool sameHeight = isSame ( height(Last_Pnt), height(Current_Pnt) );
1498 gp_Vec aVec(P2, Current_Pnt);
1500 if (myMode == 0 && !sameRadius)
1502 displayLength(P0.Translated(aVec), P2.Translated(aVec), aNormal, store); // Radius
1504 else if (myMode == 1)
1505 displayLength(P0, P2, aNormal, store);
1508 (myMode == 1 || !sameHeight) )
1509 displayLength(P2, Current_Pnt, aNormal.Reversed(), store); // Height
1514 //================================================================
1515 // Function : displayAngle()
1516 // Purpose : Method for displaying angle dimensions
1517 //================================================================
1518 void EntityGUI_3DSketcherDlg::displayAngle (double theAngle,
1524 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1526 // Creation of the AIS object
1527 Handle(AIS_AngleDimension) anAngleIO = createAISAngleDimension(theAngle,
1531 if (anAngleIO == NULL)
1536 // Erase dimensions presentations
1537 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
1538 myAnglePrs->PrependObject(anAngleIO);
1540 // Display modified presentation
1542 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
1544 // Update dimension presentation angle count for later undo / redo
1547 else if ( isAngleVisible)
1549 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1550 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1554 aSPrs->AddObject(anAngleIO);
1555 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1561 //================================================================
1562 // Function : displayLength()
1563 // Purpose : Method for displaying length dimensions for a segment
1565 //================================================================
1566 void EntityGUI_3DSketcherDlg::displayLength (gp_Pnt P1,
1571 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1573 double aLength = P1.Distance(P2);
1575 if (aLength < Precision::Confusion())
1578 Handle(AIS_LengthDimension) anIO = createAISLengthDimension(aLength, P1, P2, theNormal);
1582 // Erase length dimensions presentation
1583 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
1584 myLengthPrs->PrependObject(anIO);
1586 // Display modified presentation
1587 if (isLengthVisible)
1588 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
1590 // Update dimension presentation length count for later undo / redo
1593 else if (isLengthVisible)
1595 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1596 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1599 aSPrs->PrependObject(anIO);
1600 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1605 //================================================================
1606 // Function : displayText()
1607 // Purpose : Method for displaying length dimensions for a segment
1609 //================================================================
1610 void EntityGUI_3DSketcherDlg::displayText ( std::string theText,
1614 #if OCC_VERSION_LARGE > 0x06050300
1615 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1617 Handle(AIS_Text) anIO = new AIS_Text(TCollection_ExtendedString(theText.c_str()), P);
1621 // Erase length dimensions presentation
1622 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myTextPrs, true);
1623 myTextPrs->PrependObject(anIO);
1625 // Display modified presentation
1626 ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myTextPrs);
1628 // Update dimension presentation text count for later undo / redo
1633 SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
1634 (((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
1637 aSPrs->PrependObject(anIO);
1638 GEOMBase_Helper::displayPreview(aSPrs, true, true);
1641 #endif // OCC_VERSION_LARGE > 0x06050300
1644 //================================================================
1645 // Function : createAISLengthDimension()
1646 // Purpose : Method for creation of a length dimension object
1647 // Returns an Handle on the AIS_LengthDimension obect
1648 //================================================================
1649 Handle(AIS_LengthDimension) EntityGUI_3DSketcherDlg::createAISLengthDimension(double theLength,
1654 // Convert length to string
1655 std::string aLength_str = doubleToString(theLength);
1657 // Plane construction
1658 gce_MakePln gce_MP(P1, theNormal);
1659 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
1661 TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
1662 TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
1664 Handle(AIS_LengthDimension) anIO =
1665 new AIS_LengthDimension(aVert1,
1669 TCollection_ExtendedString(aLength_str.c_str()));
1670 anIO->SetArrowSize(theLength/20);
1672 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1673 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1674 Handle(Prs3d_LengthAspect) asp = new Prs3d_LengthAspect();
1675 asp->LineAspect()->SetWidth(w);
1676 anIO->Attributes()->SetLengthAspect(asp);
1681 //================================================================
1682 // Function : createAISAngleDimension()
1683 // Purpose : Method for creation of an angle dimension object
1684 // Returns an Handle on the AIS_AngleDimension obect
1685 //================================================================
1686 Handle(AIS_AngleDimension) EntityGUI_3DSketcherDlg::createAISAngleDimension(double theAngle,
1691 // Length of the built segment
1692 double aLength = P0.Distance(P1);
1695 if (Abs(theAngle) < Precision::Angular() ||
1696 aLength < Precision::Confusion())
1699 // Convert angles to string
1700 std::string Angle_str = doubleToString(theAngle);
1702 // Construction of the plane
1703 gce_MakePln gce_MP2(P0, P1, P2);
1704 Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP2.Value());
1706 TopoDS_Vertex V0 = BRepBuilderAPI_MakeVertex(P0);
1707 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
1708 TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
1710 TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(V0, V1);
1711 TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(V0, V2);
1713 Handle(AIS_AngleDimension) anIO =
1714 new AIS_AngleDimension(anEdge1, anEdge2, aPlane, theAngle * M_PI / 180.,
1715 TCollection_ExtendedString(Angle_str.c_str()));
1717 anIO->SetArrowSize((theAngle * M_PI / 180) * (aLength/20));
1719 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1720 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
1721 Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
1722 asp->LineAspect()->SetWidth(w);
1723 anIO->Attributes()->SetAngleAspect(asp);
1728 //================================================================
1729 // Function : createShapes
1730 // Purpose : Create applyed wire, and last segment from entry object
1731 //================================================================
1732 bool EntityGUI_3DSketcherDlg::createShapes (GEOM::GEOM_Object_ptr /*theObject*/,
1733 TopoDS_Shape& theApplyedWire,
1734 TopoDS_Shape& theLastSegment)
1736 QList<gp_Pnt> points;
1737 foreach (XYZ xyz, myPointsList) {
1738 gp_Pnt p(xyz.x, xyz.y, xyz.z);
1739 if (points.isEmpty() || points.last().Distance(p) > gp::Resolution())
1743 if (points.count() == 1) {
1744 // only one point is created
1745 BRepBuilderAPI_MakeVertex mkVertex (points.last());
1746 theApplyedWire = mkVertex.Shape();
1748 else if (points.count() > 1) {
1750 BRepBuilderAPI_MakePolygon mkWire;
1751 foreach(gp_Pnt p, points)
1753 theApplyedWire = mkWire.Shape();
1756 XYZ curxyz = getCurrentPoint();
1757 gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
1759 if (points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution()) {
1760 BRepBuilderAPI_MakeVertex mkVertex (curpnt);
1761 theLastSegment = mkVertex.Shape();
1764 BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
1765 theLastSegment = mkEdge.Shape();
1768 /* VSR: old algorithm does not work properly, see bug 0020899
1769 TopoDS_Shape aShape;
1770 if (!GEOMBase::GetShape(theObject, aShape))
1773 if (aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX)
1776 theApplyedWire = aShape;
1780 BRepBuilderAPI_MakeWire aBuilder;
1781 TopExp_Explorer edgeExp(aShape, TopAbs_EDGE);
1783 TopoDS_Shape anEdge = edgeExp.Current();
1785 if (edgeExp.More()) // i.e. non-last edge
1786 aBuilder.Add(TopoDS::Edge(anEdge));
1788 theLastSegment = anEdge;
1793 if (aBuilder.IsDone()) {
1794 theApplyedWire = aBuilder.Shape();
1796 else if (!theLastSegment.IsNull()) {
1797 TopExp_Explorer vertexExp(theLastSegment, TopAbs_VERTEX);
1798 theApplyedWire = vertexExp.Current();
1805 //================================================================
1806 // Function : doubleToString
1807 // Purpose : converts double to string
1808 //================================================================
1809 std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
1813 char format = 'g'; // truncated to a number of significant digits
1815 return QString::number(num, format, digNum).toStdString();
1818 //================================================================
1819 // Function : toReferenceSystem ()
1821 //================================================================
1822 gp_Trsf EntityGUI_3DSketcherDlg::toReferenceSystem(gp_Pnt origin) const
1824 gp_Trsf T; // Identity transformation
1825 gp_Ax3 reference_system; // OXY
1826 reference_system.SetLocation(origin);
1828 gp_Ax3 current_system = reference_system;
1829 switch (myOrientation)
1833 current_system = gp_Ax3(origin, gp::DX(), gp::DY());
1838 current_system = gp_Ax3(origin, gp::DY().Reversed(), gp::DX());
1843 T.SetTransformation( current_system, reference_system );
1848 //================================================================
1849 // Function : toCurrentSystem ()
1851 //================================================================
1852 gp_Trsf EntityGUI_3DSketcherDlg::toCurrentSystem(gp_Pnt origin) const
1854 return toReferenceSystem(origin).Inverted();
1857 //================================================================
1858 // Function : radius (gp_Pnt) const
1860 //================================================================
1861 double EntityGUI_3DSketcherDlg::radius (gp_Pnt thePnt) const
1863 // Get the point coordinates in the current coordinates system
1864 gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1865 gp_Pnt aPnt = thePnt.Transformed(aTrsf);
1867 double radius = sqrt(aPnt.X()*aPnt.X() + aPnt.Y()*aPnt.Y());
1871 //================================================================
1872 // Function : height (gp_Pnt) const
1874 //================================================================
1875 double EntityGUI_3DSketcherDlg::height (gp_Pnt thePnt) const
1877 // Get the point coordinates in the current coordinates system
1878 gp_Trsf aTrsf = toCurrentSystem(gp::Origin());
1879 gp_Pnt aPnt = thePnt.Transformed(aTrsf);