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