0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / samples / mfc / standard / Common / LengthParamsEdgePage.cpp
CommitLineData
a6eb515f 1// LengthParamsEdgePage.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "LengthParamsEdgePage.h"
6#include "DimensionDlg.h"
7
8#include <Standard_Macro.hxx>
9#include <AIS_InteractiveContext.hxx>
10#include <AIS_LocalContext.hxx>
11#include <AIS_LengthDimension.hxx>
12#include <GC_MakePlane.hxx>
13#include <TopExp.hxx>
14
15// CLengthParamsEdgePage dialog
16
17IMPLEMENT_DYNAMIC(CLengthParamsEdgePage, CDialog)
18
19//=======================================================================
20//function : CLengthParamsEdgePage
21//purpose :
22//=======================================================================
23
24CLengthParamsEdgePage::CLengthParamsEdgePage (Handle(AIS_InteractiveContext) theContext,CWnd* pParent /*=NULL*/)
25: CDialog (CLengthParamsEdgePage::IDD, pParent)
26{
27 myAISContext = theContext;
28}
29
30//=======================================================================
31//function : ~CLengthParamsEdgePage
32//purpose :
33//=======================================================================
34
35CLengthParamsEdgePage::~CLengthParamsEdgePage()
36{
37}
38
39//=======================================================================
40//function : DoDataExchange
41//purpose :
42//=======================================================================
43
44void CLengthParamsEdgePage::DoDataExchange (CDataExchange* pDX)
45{
46 CDialog::DoDataExchange(pDX);
47}
48
49BEGIN_MESSAGE_MAP (CLengthParamsEdgePage, CDialog)
50 ON_BN_CLICKED (IDC_ChooseEdgeBtn, &CLengthParamsEdgePage::OnBnClickedChooseEdgeBtn)
51END_MESSAGE_MAP()
52
53//=======================================================================
54//function : GetButton
55//purpose :
56//=======================================================================
57
58CButton* CLengthParamsEdgePage::GetButton()
59{
60 return (CButton*)GetDlgItem (IDC_ChooseEdgeBtn);
61}
62
63//=======================================================================
64//function : OnBnClickedChooseEdgeBtn
65//purpose :
66//=======================================================================
67
68void CLengthParamsEdgePage::OnBnClickedChooseEdgeBtn()
69{
70 myAISContext->LocalContext()->InitSelected();
71
72 if (!myAISContext->LocalContext()->MoreSelected())
73 {
74 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
75 return;
76 }
77
016e5959 78 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
47162471 79 const TopoDS_Edge& anEdge = TopoDS::Edge (aSelShape);
80
a6eb515f 81 myAISContext->LocalContext()->ClearSelected();
82 TopoDS_Vertex aFirstVertex, aSecondVertex;
47162471 83 TopExp::Vertices (TopoDS::Edge (anEdge), aFirstVertex, aSecondVertex);
a6eb515f 84
47162471 85 gp_Pnt aP1 = BRep_Tool::Pnt (aFirstVertex);
86 gp_Pnt aP2 = BRep_Tool::Pnt (aSecondVertex);
87 gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
a6eb515f 88
89 GC_MakePlane aMkPlane (aP1,aP2,aP3);
47162471 90 Handle(Geom_Plane) aPlane = aMkPlane.Value();
a6eb515f 91
92 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
93
47162471 94 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (TopoDS::Edge (anEdge), aPlane->Pln());
a6eb515f 95 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
96 anAspect->MakeArrows3d (Standard_False);
97 anAspect->MakeText3d (aDimDlg->GetTextType());
98 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
99 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
100 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 101 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 102 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 103 {
104 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
105 }
106
107 aLenDim->SetDimensionAspect (anAspect);
108 aLenDim->SetFlyout (aDimDlg->GetFlyout());
109
110 myAISContext->CloseAllContexts();
111 myAISContext->Display (aLenDim);
112 myAISContext->OpenLocalContext();
113 myAISContext->ActivateStandardMode(TopAbs_EDGE);
114}