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