0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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>
787ff240 7#include <PrsDim_RadiusDimension.hxx>
8#include <PrsDim_DiameterDimension.hxx>
a6eb515f 9#include <ElCLib.hxx>
10#include <TopoDS_Shape.hxx>
11
12IMPLEMENT_DYNAMIC(CRadiusParamsPage, CDialog)
13
14//=======================================================================
15//function : CRadiusParamsPage
16//purpose :
17//=======================================================================
18
19CRadiusParamsPage::CRadiusParamsPage (const Handle(AIS_InteractiveContext)& theAISContext,
20 const Standard_Boolean isDiameterDimension /* =Standard_False*/,
21 CWnd* pParent /*=NULL*/)
22 : CDialog (CRadiusParamsPage::IDD, pParent)
23{
24 myAISContext = theAISContext;
25 myIsDiameterDimension = isDiameterDimension;
26}
27
28//=======================================================================
29//function : ~CRadiusParamsPage
30//purpose :
31//=======================================================================
32
33CRadiusParamsPage::~CRadiusParamsPage()
34{
35}
36
37//=======================================================================
38//function : DoDataExchange
39//purpose :
40//=======================================================================
41
42void CRadiusParamsPage::DoDataExchange(CDataExchange* pDX)
43{
44 CDialog::DoDataExchange(pDX);
45}
46
47
48BEGIN_MESSAGE_MAP(CRadiusParamsPage, CDialog)
49 ON_BN_CLICKED(IDC_BUTTON1, &CRadiusParamsPage::OnBnClickedObjectBtn)
50END_MESSAGE_MAP()
51
52//=======================================================================
53//function : OnBnClickedObjectBtn
54//purpose :
55//=======================================================================
56
57void CRadiusParamsPage::OnBnClickedObjectBtn()
58{
59 //Build dimension here
404c8936 60 myAISContext->InitSelected();
61 if (!myAISContext->MoreSelected() ||
71c089e9 62 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
a6eb515f 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
0577ae8c 96 myAISContext->ClearSelected (Standard_False);
a6eb515f 97 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
98 // Try to create dimension if it is possible
787ff240 99 Handle(PrsDim_Dimension) aDim;
a6eb515f 100 if (myIsDiameterDimension)
101 {
787ff240 102 aDim = new PrsDim_DiameterDimension (aCircle);
103 Handle(PrsDim_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
a6eb515f 104 }
105 else
106 {
787ff240 107 aDim = new PrsDim_RadiusDimension (aCircle);
108 Handle(PrsDim_RadiusDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
a6eb515f 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
a6eb515f 126
0577ae8c 127 myAISContext->Display (aDim, Standard_True);
404c8936 128 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
a6eb515f 129}