0025284: Problems with standard MFC samples
[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
47162471 72 // Workaround for AIS_LocalContext::SelectedShape()
73 TopoDS_Shape aSelShape = CDimensionDlg::SelectedShape();
74 //TopoDS_Shape aSelShape = myAISContext->LocalContext()->SelectedShape();
75
a6eb515f 76 if (aSelShape.ShapeType() != TopAbs_EDGE &&
77 aSelShape.ShapeType() != TopAbs_FACE &&
78 aSelShape.ShapeType() != TopAbs_WIRE)
79 return;
80
81 if (aSelShape.ShapeType() == TopAbs_EDGE)
82 {
83 BRepAdaptor_Curve aCurve (TopoDS::Edge (aSelShape));
84 if (aCurve.GetType() != GeomAbs_Circle)
85 {
86 return;
87 }
88
89 aCircle = aCurve.Circle();
90 if (aCurve.FirstParameter() != 0 && aCurve.LastParameter() != M_PI * 2)
91 {
92 isAttachPoint = Standard_True;
93 aFirstPar = aCurve.FirstParameter();
94 aLastPar = aCurve.LastParameter();
95 }
96 }
97
98 myAISContext->LocalContext()->ClearSelected();
99 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
100 // Try to create dimension if it is possible
101 Handle(AIS_Dimension) aDim;
102 if (myIsDiameterDimension)
103 {
60bf98ae 104 aDim = new AIS_DiameterDimension (aCircle);
a6eb515f 105 Handle(AIS_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
106 }
107 else
108 {
60bf98ae 109 aDim = new AIS_RadiusDimension (aCircle);
a6eb515f 110 Handle(AIS_RadiusDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
111 }
112
113 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
114 anAspect->MakeArrows3d (Standard_False);
115 anAspect->MakeText3d (aDimDlg->GetTextType());
116 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
117 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
118 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 119 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 120 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 121 {
122 aDim->SetDisplayUnits (aDimDlg->GetUnits());
123 }
124
125 aDim->SetDimensionAspect (anAspect);
126
127 // Display dimension in the neutral point
128 myAISContext->CloseAllContexts();
129
130 myAISContext->Display (aDim);
131
132 myAISContext->OpenLocalContext();
133 myAISContext->ActivateStandardMode (TopAbs_EDGE);
134}