0024133: Development of improvement of dimensions implementation; new length, radius...
[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{
62 // Open local context and choose the edge for length dimensions
63 if (!myAISContext->HasOpenedContext())
64 {
65 myAISContext->OpenLocalContext();
66 myAISContext->ActivateStandardMode(TopAbs_VERTEX);
67 AfxMessageBox(_T("Local context was not opened. Choose the vertices and press the button again"),
68 MB_ICONINFORMATION | MB_OK);
69 return;
70 }
71
72 // Now it's ok, local context is opened and edge selection mode is activated
73 // Check if some edge is selected
74 myAISContext->LocalContext()->InitSelected();
75 if (!myAISContext->LocalContext()->MoreSelected())
76 {
77 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
78 return;
79 }
80
81 myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
82
83 myAISContext->LocalContext()->ClearSelected();
84}
85
86//=======================================================================
87//function : OnBnClickedVertex2Btn
88//purpose :
89//=======================================================================
90
91void CLengthParamsVerticesPage::OnBnClickedVertex2Btn()
92{
93 myAISContext->LocalContext()->InitSelected();
94 if (!myAISContext->LocalContext()->MoreSelected())
95 {
96 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
97 return;
98 }
99
100 mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
101 myAISContext->LocalContext()->ClearSelected();
102
103 //Build dimension here
104 gp_Pnt aP1=BRep_Tool::Pnt (myFirstVertex);
105 gp_Pnt aP2=BRep_Tool::Pnt (mySecondVertex);
106 gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
107
108 GC_MakePlane aMkPlane (aP1,aP2,aP3);
109 Handle(Geom_Plane) aPlane = aMkPlane.Value();
110
111 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
112
113 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane->Pln());
114
115 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
116 anAspect->MakeArrows3d (Standard_False);
117 anAspect->MakeText3d (aDimDlg->GetTextType());
118 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
119 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
120 aLenDim->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
121 if (aLenDim->IsUnitsDisplayed ())
122 {
123 aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
124 }
125
126 aLenDim->SetDimensionAspect (anAspect);
127 aLenDim->SetFlyout (aDimDlg->GetFlyout());
128
129 myAISContext->CloseAllContexts();
130 myAISContext->Display (aLenDim);
131 myAISContext->OpenLocalContext();
132 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
133}
134
135//=======================================================================
136//function : getFirstVertex
137//purpose :
138//=======================================================================
139
140const TopoDS_Vertex& CLengthParamsVerticesPage::getFirstVertex() const
141{
142 return myFirstVertex;
143}
144
145//=======================================================================
146//function : getSecondVertex
147//purpose :
148//=======================================================================
149
150const TopoDS_Vertex& CLengthParamsVerticesPage::getSecondVertex() const
151{
152 return mySecondVertex;
153}