Fix compilation error on vc12 (MSVC++ 12.0)
[occt.git] / samples / mfc / standard / Common / LengthParamsVerticesPage.cpp
CommitLineData
a6eb515f 1// LengthParamsVerticesPage.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "LengthParamsVerticesPage.h"
6#include "DimensionDlg.h"
7#include <Standard_Macro.hxx>
8#include <AIS_InteractiveContext.hxx>
9#include <AIS_LocalContext.hxx>
10#include <AIS_LengthDimension.hxx>
11#include <GC_MakePlane.hxx>
12
13
14// CLengthParamsVerticesPage dialog
15
16IMPLEMENT_DYNAMIC(CLengthParamsVerticesPage, CDialog)
17
18//=======================================================================
19//function : CLengthParamsVerticesPage
20//purpose :
21//=======================================================================
22
23CLengthParamsVerticesPage::CLengthParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext, CWnd* pParent /*=NULL*/)
24: CDialog (CLengthParamsVerticesPage::IDD, pParent)
25{
26 myAISContext = theAISContext;
27}
28
29//=======================================================================
30//function : ~CLengthParamsVerticesPage
31//purpose :
32//=======================================================================
33
34CLengthParamsVerticesPage::~CLengthParamsVerticesPage()
35{
36}
37
38//=======================================================================
39//function : DoDataExchange
40//purpose :
41//=======================================================================
42
43void CLengthParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
44{
45 CDialog::DoDataExchange (pDX);
46}
47
48
49BEGIN_MESSAGE_MAP(CLengthParamsVerticesPage, CDialog)
50 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsVerticesPage::OnBnClickedVertex1Btn)
51 ON_BN_CLICKED(IDC_BUTTON2, &CLengthParamsVerticesPage::OnBnClickedVertex2Btn)
52END_MESSAGE_MAP()
53
54
55//=======================================================================
56//function : OnBnClickedVertex1Btn
57//purpose :
58//=======================================================================
59
60void CLengthParamsVerticesPage::OnBnClickedVertex1Btn()
61{
404c8936 62 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 63
404c8936 64 // Now it's ok, edge selection mode is activated
a6eb515f 65 // Check if some edge is selected
404c8936 66 myAISContext->InitSelected();
67 if (!myAISContext->MoreSelected() ||
71c089e9 68 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 69 {
70 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
71 return;
72 }
73
404c8936 74 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
a6eb515f 75
404c8936 76 myAISContext->ClearSelected();
a6eb515f 77}
78
79//=======================================================================
80//function : OnBnClickedVertex2Btn
81//purpose :
82//=======================================================================
83
84void CLengthParamsVerticesPage::OnBnClickedVertex2Btn()
85{
404c8936 86 myAISContext->InitSelected();
87 if (!myAISContext->MoreSelected() ||
71c089e9 88 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 89 {
90 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
91 return;
92 }
93
404c8936 94 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
95 myAISContext->ClearSelected();
a6eb515f 96
97 //Build dimension here
98 gp_Pnt aP1=BRep_Tool::Pnt (myFirstVertex);
99 gp_Pnt aP2=BRep_Tool::Pnt (mySecondVertex);
100 gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
101
102 GC_MakePlane aMkPlane (aP1,aP2,aP3);
103 Handle(Geom_Plane) aPlane = aMkPlane.Value();
104
105 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
106
107 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane->Pln());
108
109 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
110 anAspect->MakeArrows3d (Standard_False);
111 anAspect->MakeText3d (aDimDlg->GetTextType());
112 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
113 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
47162471 114 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 115 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 116 {
117 aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
118 }
119
120 aLenDim->SetDimensionAspect (anAspect);
121 aLenDim->SetFlyout (aDimDlg->GetFlyout());
122
a6eb515f 123 myAISContext->Display (aLenDim);
404c8936 124 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 125}
126
127//=======================================================================
128//function : getFirstVertex
129//purpose :
130//=======================================================================
131
132const TopoDS_Vertex& CLengthParamsVerticesPage::getFirstVertex() const
133{
134 return myFirstVertex;
135}
136
137//=======================================================================
138//function : getSecondVertex
139//purpose :
140//=======================================================================
141
142const TopoDS_Vertex& CLengthParamsVerticesPage::getSecondVertex() const
143{
144 return mySecondVertex;
145}