0028213: Visualization, StdPrs_ShadedShape - compute face edges for triangulation...
[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{
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();
71c089e9 79 if (!myAISContext->LocalContext()->MoreSelected() ||
80 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 81 {
82 AfxMessageBox (_T ("Choose the vertex and press the button again"),
83 MB_ICONINFORMATION | MB_OK);
84 return;
85 }
86
87 myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
88 myAISContext->LocalContext()->ClearSelected();
89}
90
91//=======================================================================
92//function : OnBnClickedVertex2Btn
93//purpose :
94//=======================================================================
95
96void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
97{
98 myAISContext->LocalContext()->InitSelected();
71c089e9 99 if (!myAISContext->LocalContext()->MoreSelected() ||
100 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 101 {
102 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
103 return;
104 }
105
106 mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
107
108 myAISContext->LocalContext()->ClearSelected();
109}
110
111//=======================================================================
112//function : OnBnClickedVertex3Btn
113//purpose :
114//=======================================================================
115
116void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
117{
118 myAISContext->LocalContext()->InitSelected();
119 if (!myAISContext->LocalContext()->MoreSelected())
120 {
121 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
122 return;
123 }
124
125 myThirdVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
126 myAISContext->LocalContext()->ClearSelected();
127
128 //Build dimension here
129 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
130 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
131
132 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
133
134 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
135 aP2 = BRep_Tool::Pnt (mySecondVertex),
136 aP3 = BRep_Tool::Pnt (myThirdVertex);
137 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
138
139 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
140 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
141 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
142 anAspect->MakeArrows3d (Standard_False);
143 anAspect->MakeText3d (aDimDlg->GetTextType());
144 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
145 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
146 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 147 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 148 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 149 {
150 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
60bf98ae 151 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
a6eb515f 152 {
47162471 153 // No units - for degree is special symbol that is enabled by default
154 anAspect->MakeUnitsDisplayed (Standard_False);
a6eb515f 155 }
47162471 156 else // radians - no special symbol
a6eb515f 157 {
158 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
159 }
160 }
161 anAngleDim->SetDimensionAspect (anAspect);
162 myAISContext->CloseAllContexts();
163 myAISContext->Display (anAngleDim);
164 myAISContext->OpenLocalContext();
165 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
166}