0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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>
787ff240 9#include <PrsDim_AngleDimension.hxx>
a6eb515f 10#include <BRep_Tool.hxx>
11#include <GC_MakePlane.hxx>
12#include <Prs3d_DimensionAspect.hxx>
13
14// CAngleParamsVerticesPage dialog
15
16IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog)
17
18//=======================================================================
19//function : CAngleParamsVerticesPage
20//purpose :
21//=======================================================================
22
23CAngleParamsVerticesPage::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
35CAngleParamsVerticesPage::~CAngleParamsVerticesPage()
36{
37}
38
39//=======================================================================
40//function : DoDataExchange
41//purpose :
42//=======================================================================
43
44void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
45{
46 CDialog::DoDataExchange (pDX);
47}
48
49
50BEGIN_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)
54END_MESSAGE_MAP()
55
56
57//=======================================================================
58//function : OnBnClickedVertex1Btn
59//purpose :
60//=======================================================================
61
62void CAngleParamsVerticesPage::OnBnClickedVertex1Btn()
63{
404c8936 64 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 65
404c8936 66 // Now it's ok, edge selection mode is activated
a6eb515f 67 // Check if some vertex is selected
404c8936 68 myAISContext->InitSelected();
69 if (!myAISContext->MoreSelected() ||
71c089e9 70 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 71 {
72 AfxMessageBox (_T ("Choose the vertex and press the button again"),
73 MB_ICONINFORMATION | MB_OK);
74 return;
75 }
76
404c8936 77 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
0577ae8c 78 myAISContext->ClearSelected (Standard_True);
a6eb515f 79}
80
81//=======================================================================
82//function : OnBnClickedVertex2Btn
83//purpose :
84//=======================================================================
85
86void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
87{
404c8936 88 myAISContext->InitSelected();
89 if (!myAISContext->MoreSelected() ||
71c089e9 90 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 91 {
92 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
93 return;
94 }
95
404c8936 96 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
a6eb515f 97
0577ae8c 98 myAISContext->ClearSelected (Standard_True);
a6eb515f 99}
100
101//=======================================================================
102//function : OnBnClickedVertex3Btn
103//purpose :
104//=======================================================================
105
106void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
107{
404c8936 108 myAISContext->InitSelected();
109 if (!myAISContext->MoreSelected())
a6eb515f 110 {
111 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
112 return;
113 }
114
404c8936 115 myThirdVertex = TopoDS::Vertex (myAISContext->SelectedShape());
0577ae8c 116 myAISContext->ClearSelected (Standard_False);
a6eb515f 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();
787ff240 130 Handle(PrsDim_AngleDimension) anAngleDim = new PrsDim_AngleDimension (aP1,aP2,aP3);
a6eb515f 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());
47162471 137 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 138 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 139 {
140 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
60bf98ae 141 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
a6eb515f 142 {
47162471 143 // No units - for degree is special symbol that is enabled by default
144 anAspect->MakeUnitsDisplayed (Standard_False);
a6eb515f 145 }
47162471 146 else // radians - no special symbol
a6eb515f 147 {
787ff240 148 anAngleDim->SetDisplaySpecialSymbol (PrsDim_DisplaySpecialSymbol_No);
a6eb515f 149 }
150 }
151 anAngleDim->SetDimensionAspect (anAspect);
0577ae8c 152 myAISContext->Display (anAngleDim, Standard_True);
404c8936 153 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
a6eb515f 154}