0028213: Visualization, StdPrs_ShadedShape - compute face edges for triangulation...
[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();
71c089e9 75 if (!myAISContext->LocalContext()->MoreSelected() ||
76 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 77 {
78 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
79 return;
80 }
81
82 myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
83
84 myAISContext->LocalContext()->ClearSelected();
85}
86
87//=======================================================================
88//function : OnBnClickedVertex2Btn
89//purpose :
90//=======================================================================
91
92void CLengthParamsVerticesPage::OnBnClickedVertex2Btn()
93{
94 myAISContext->LocalContext()->InitSelected();
71c089e9 95 if (!myAISContext->LocalContext()->MoreSelected() ||
96 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
a6eb515f 97 {
98 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
99 return;
100 }
101
102 mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
103 myAISContext->LocalContext()->ClearSelected();
104
105 //Build dimension here
106 gp_Pnt aP1=BRep_Tool::Pnt (myFirstVertex);
107 gp_Pnt aP2=BRep_Tool::Pnt (mySecondVertex);
108 gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
109
110 GC_MakePlane aMkPlane (aP1,aP2,aP3);
111 Handle(Geom_Plane) aPlane = aMkPlane.Value();
112
113 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
114
115 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane->Pln());
116
117 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
118 anAspect->MakeArrows3d (Standard_False);
119 anAspect->MakeText3d (aDimDlg->GetTextType());
120 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
121 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
47162471 122 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 123 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 124 {
125 aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
126 }
127
128 aLenDim->SetDimensionAspect (anAspect);
129 aLenDim->SetFlyout (aDimDlg->GetFlyout());
130
131 myAISContext->CloseAllContexts();
132 myAISContext->Display (aLenDim);
133 myAISContext->OpenLocalContext();
134 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
135}
136
137//=======================================================================
138//function : getFirstVertex
139//purpose :
140//=======================================================================
141
142const TopoDS_Vertex& CLengthParamsVerticesPage::getFirstVertex() const
143{
144 return myFirstVertex;
145}
146
147//=======================================================================
148//function : getSecondVertex
149//purpose :
150//=======================================================================
151
152const TopoDS_Vertex& CLengthParamsVerticesPage::getSecondVertex() const
153{
154 return mySecondVertex;
155}