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 | |
18 | IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog) |
19 | |
20 | //======================================================================= |
21 | //function : CAngleParamsVerticesPage |
22 | //purpose : |
23 | //======================================================================= |
24 | |
25 | CAngleParamsVerticesPage::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 | |
37 | CAngleParamsVerticesPage::~CAngleParamsVerticesPage() |
38 | { |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : DoDataExchange |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX) |
47 | { |
48 | CDialog::DoDataExchange (pDX); |
49 | } |
50 | |
51 | |
52 | BEGIN_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) |
56 | END_MESSAGE_MAP() |
57 | |
58 | |
59 | //======================================================================= |
60 | //function : OnBnClickedVertex1Btn |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | void CAngleParamsVerticesPage::OnBnClickedVertex1Btn() |
65 | { |
66 | // Open local context and choose the vertex for angle dimensions |
67 | if (!myAISContext->HasOpenedContext()) |
68 | { |
69 | myAISContext->OpenLocalContext(); |
70 | myAISContext->ActivateStandardMode(TopAbs_VERTEX); |
71 | AfxMessageBox (_T ("Local context was not opened. Choose the edge and press the button again"), |
72 | MB_ICONINFORMATION | MB_OK); |
73 | return; |
74 | } |
75 | |
76 | // Now it's ok, local context is opened and edge selection mode is activated |
77 | // Check if some vertex is selected |
78 | myAISContext->LocalContext()->InitSelected(); |
79 | if (!myAISContext->LocalContext()->MoreSelected()) |
80 | { |
81 | AfxMessageBox (_T ("Choose the vertex and press the button again"), |
82 | MB_ICONINFORMATION | MB_OK); |
83 | return; |
84 | } |
85 | |
86 | myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape()); |
87 | myAISContext->LocalContext()->ClearSelected(); |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : OnBnClickedVertex2Btn |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | void CAngleParamsVerticesPage::OnBnClickedVertex2Btn() |
96 | { |
97 | myAISContext->LocalContext()->InitSelected(); |
98 | if (!myAISContext->LocalContext()->MoreSelected()) |
99 | { |
100 | AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK); |
101 | return; |
102 | } |
103 | |
104 | mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape()); |
105 | |
106 | myAISContext->LocalContext()->ClearSelected(); |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : OnBnClickedVertex3Btn |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | void CAngleParamsVerticesPage::OnBnClickedVertex3Btn() |
115 | { |
116 | myAISContext->LocalContext()->InitSelected(); |
117 | if (!myAISContext->LocalContext()->MoreSelected()) |
118 | { |
119 | AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK); |
120 | return; |
121 | } |
122 | |
123 | myThirdVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape()); |
124 | myAISContext->LocalContext()->ClearSelected(); |
125 | |
126 | //Build dimension here |
127 | TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex); |
128 | TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex); |
129 | |
130 | CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner()); |
131 | |
132 | gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex), |
133 | aP2 = BRep_Tool::Pnt (mySecondVertex), |
134 | aP3 = BRep_Tool::Pnt (myThirdVertex); |
135 | GC_MakePlane aPlaneBuilder (aP1,aP2,aP3); |
136 | |
137 | Handle(Geom_Plane) aPlane = aPlaneBuilder.Value(); |
138 | Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3); |
139 | Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); |
140 | anAspect->MakeArrows3d (Standard_False); |
141 | anAspect->MakeText3d (aDimDlg->GetTextType()); |
142 | anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight()); |
143 | anAspect->MakeTextShaded (aDimDlg->IsText3dShaded()); |
144 | anAspect->SetCommonColor (aDimDlg->GetDimensionColor()); |
47162471 |
145 | anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed()); |
60bf98ae |
146 | if (aDimDlg->IsUnitsDisplayed()) |
a6eb515f |
147 | { |
148 | anAngleDim->SetDisplayUnits (aDimDlg->GetUnits()); |
60bf98ae |
149 | if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg")))) |
a6eb515f |
150 | { |
47162471 |
151 | // No units - for degree is special symbol that is enabled by default |
152 | anAspect->MakeUnitsDisplayed (Standard_False); |
a6eb515f |
153 | } |
47162471 |
154 | else // radians - no special symbol |
a6eb515f |
155 | { |
156 | anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No); |
157 | } |
158 | } |
159 | anAngleDim->SetDimensionAspect (anAspect); |
160 | myAISContext->CloseAllContexts(); |
161 | myAISContext->Display (anAngleDim); |
162 | myAISContext->OpenLocalContext(); |
163 | myAISContext->ActivateStandardMode (TopAbs_VERTEX); |
164 | } |