0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / samples / mfc / standard / Common / RadiusParamsPage.cpp
CommitLineData
a6eb515f 1
2#include "stdafx.h"
3#include "RadiusParamsPage.h"
4#include "DimensionDlg.h"
5
6#include <AIS_InteractiveContext.hxx>
7#include <AIS_LocalContext.hxx>
8#include <AIS_RadiusDimension.hxx>
9#include <AIS_DiameterDimension.hxx>
10#include <ElCLib.hxx>
11#include <TopoDS_Shape.hxx>
12
13IMPLEMENT_DYNAMIC(CRadiusParamsPage, CDialog)
14
15//=======================================================================
16//function : CRadiusParamsPage
17//purpose :
18//=======================================================================
19
20CRadiusParamsPage::CRadiusParamsPage (const Handle(AIS_InteractiveContext)& theAISContext,
21 const Standard_Boolean isDiameterDimension /* =Standard_False*/,
22 CWnd* pParent /*=NULL*/)
23 : CDialog (CRadiusParamsPage::IDD, pParent)
24{
25 myAISContext = theAISContext;
26 myIsDiameterDimension = isDiameterDimension;
27}
28
29//=======================================================================
30//function : ~CRadiusParamsPage
31//purpose :
32//=======================================================================
33
34CRadiusParamsPage::~CRadiusParamsPage()
35{
36}
37
38//=======================================================================
39//function : DoDataExchange
40//purpose :
41//=======================================================================
42
43void CRadiusParamsPage::DoDataExchange(CDataExchange* pDX)
44{
45 CDialog::DoDataExchange(pDX);
46}
47
48
49BEGIN_MESSAGE_MAP(CRadiusParamsPage, CDialog)
50 ON_BN_CLICKED(IDC_BUTTON1, &CRadiusParamsPage::OnBnClickedObjectBtn)
51END_MESSAGE_MAP()
52
53//=======================================================================
54//function : OnBnClickedObjectBtn
55//purpose :
56//=======================================================================
57
58void CRadiusParamsPage::OnBnClickedObjectBtn()
59{
60 //Build dimension here
61 myAISContext->LocalContext()->InitSelected();
62 if (!myAISContext->LocalContext()->MoreSelected())
63 {
64 AfxMessageBox (_T ("Choose the edge and press the button again"), MB_ICONINFORMATION | MB_OK);
65 return;
66 }
67
68 gp_Circ aCircle;
69 Standard_Boolean isAttachPoint = Standard_False;
70 Standard_Real aFirstPar = 0, aLastPar = 0;
71
016e5959 72 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
47162471 73
a6eb515f 74 if (aSelShape.ShapeType() != TopAbs_EDGE &&
75 aSelShape.ShapeType() != TopAbs_FACE &&
76 aSelShape.ShapeType() != TopAbs_WIRE)
77 return;
78
79 if (aSelShape.ShapeType() == TopAbs_EDGE)
80 {
81 BRepAdaptor_Curve aCurve (TopoDS::Edge (aSelShape));
82 if (aCurve.GetType() != GeomAbs_Circle)
83 {
84 return;
85 }
86
87 aCircle = aCurve.Circle();
88 if (aCurve.FirstParameter() != 0 && aCurve.LastParameter() != M_PI * 2)
89 {
90 isAttachPoint = Standard_True;
91 aFirstPar = aCurve.FirstParameter();
92 aLastPar = aCurve.LastParameter();
93 }
94 }
95
96 myAISContext->LocalContext()->ClearSelected();
97 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
98 // Try to create dimension if it is possible
99 Handle(AIS_Dimension) aDim;
100 if (myIsDiameterDimension)
101 {
60bf98ae 102 aDim = new AIS_DiameterDimension (aCircle);
a6eb515f 103 Handle(AIS_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
104 }
105 else
106 {
60bf98ae 107 aDim = new AIS_RadiusDimension (aCircle);
a6eb515f 108 Handle(AIS_RadiusDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
109 }
110
111 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
112 anAspect->MakeArrows3d (Standard_False);
113 anAspect->MakeText3d (aDimDlg->GetTextType());
114 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
115 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
116 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 117 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 118 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 119 {
120 aDim->SetDisplayUnits (aDimDlg->GetUnits());
121 }
122
123 aDim->SetDimensionAspect (anAspect);
124
125 // Display dimension in the neutral point
126 myAISContext->CloseAllContexts();
127
128 myAISContext->Display (aDim);
129
130 myAISContext->OpenLocalContext();
131 myAISContext->ActivateStandardMode (TopAbs_EDGE);
132}