0031459: Visualization, AIS_TextLabel - add missing getters
[occt.git] / samples / mfc / standard / Common / AngleParamsVerticesPage.cpp
CommitLineData
a6eb515f 1// AngleParamsVerticesPage.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "AngleParamsVerticesPage.h"
6#include "DimensionDlg.h"
7
8#include <AIS_InteractiveContext.hxx>
a6eb515f 9#include <AIS_LengthDimension.hxx>
10#include <AIS_AngleDimension.hxx>
11#include <BRep_Tool.hxx>
12#include <GC_MakePlane.hxx>
13#include <Prs3d_DimensionAspect.hxx>
14
15// CAngleParamsVerticesPage dialog
16
17IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog)
18
19//=======================================================================
20//function : CAngleParamsVerticesPage
21//purpose :
22//=======================================================================
23
24CAngleParamsVerticesPage::CAngleParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext,
25 CWnd* pParent /*=NULL*/)
26: CDialog(CAngleParamsVerticesPage::IDD, pParent)
27{
28 myAISContext = theAISContext;
29}
30
31//=======================================================================
32//function : ~CAngleParamsVerticesPage
33//purpose :
34//=======================================================================
35
36CAngleParamsVerticesPage::~CAngleParamsVerticesPage()
37{
38}
39
40//=======================================================================
41//function : DoDataExchange
42//purpose :
43//=======================================================================
44
45void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
46{
47 CDialog::DoDataExchange (pDX);
48}
49
50
51BEGIN_MESSAGE_MAP(CAngleParamsVerticesPage, CDialog)
52 ON_BN_CLICKED(IDC_BUTTON1, &CAngleParamsVerticesPage::OnBnClickedVertex1Btn)
53 ON_BN_CLICKED(IDC_BUTTON3, &CAngleParamsVerticesPage::OnBnClickedVertex2Btn)
54 ON_BN_CLICKED(IDC_BUTTON4, &CAngleParamsVerticesPage::OnBnClickedVertex3Btn)
55END_MESSAGE_MAP()
56
57
58//=======================================================================
59//function : OnBnClickedVertex1Btn
60//purpose :
61//=======================================================================
62
63void CAngleParamsVerticesPage::OnBnClickedVertex1Btn()
64{
404c8936 65 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 66
404c8936 67 // Now it's ok, edge selection mode is activated
a6eb515f 68 // Check if some vertex is selected
404c8936 69 myAISContext->InitSelected();
70 if (!myAISContext->MoreSelected() ||
71c089e9 71 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 72 {
73 AfxMessageBox (_T ("Choose the vertex and press the button again"),
74 MB_ICONINFORMATION | MB_OK);
75 return;
76 }
77
404c8936 78 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
0577ae8c 79 myAISContext->ClearSelected (Standard_True);
a6eb515f 80}
81
82//=======================================================================
83//function : OnBnClickedVertex2Btn
84//purpose :
85//=======================================================================
86
87void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
88{
404c8936 89 myAISContext->InitSelected();
90 if (!myAISContext->MoreSelected() ||
71c089e9 91 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 92 {
93 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
94 return;
95 }
96
404c8936 97 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
a6eb515f 98
0577ae8c 99 myAISContext->ClearSelected (Standard_True);
a6eb515f 100}
101
102//=======================================================================
103//function : OnBnClickedVertex3Btn
104//purpose :
105//=======================================================================
106
107void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
108{
404c8936 109 myAISContext->InitSelected();
110 if (!myAISContext->MoreSelected())
a6eb515f 111 {
112 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
113 return;
114 }
115
404c8936 116 myThirdVertex = TopoDS::Vertex (myAISContext->SelectedShape());
0577ae8c 117 myAISContext->ClearSelected (Standard_False);
a6eb515f 118
119 //Build dimension here
120 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
121 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
122
123 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
124
125 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
126 aP2 = BRep_Tool::Pnt (mySecondVertex),
127 aP3 = BRep_Tool::Pnt (myThirdVertex);
128 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
129
130 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
131 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
132 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
133 anAspect->MakeArrows3d (Standard_False);
134 anAspect->MakeText3d (aDimDlg->GetTextType());
135 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
136 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
137 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 138 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 139 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 140 {
141 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
60bf98ae 142 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
a6eb515f 143 {
47162471 144 // No units - for degree is special symbol that is enabled by default
145 anAspect->MakeUnitsDisplayed (Standard_False);
a6eb515f 146 }
47162471 147 else // radians - no special symbol
a6eb515f 148 {
149 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
150 }
151 }
152 anAngleDim->SetDimensionAspect (anAspect);
0577ae8c 153 myAISContext->Display (anAngleDim, Standard_True);
404c8936 154 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 155}