0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / samples / mfc / standard / Common / RadiusParamsPage.cpp
1
2 #include "stdafx.h"
3 #include "RadiusParamsPage.h"
4 #include "DimensionDlg.h"
5
6 #include <AIS_InteractiveContext.hxx>
7 #include <PrsDim_RadiusDimension.hxx>
8 #include <PrsDim_DiameterDimension.hxx>
9 #include <ElCLib.hxx>
10 #include <TopoDS_Shape.hxx>
11
12 IMPLEMENT_DYNAMIC(CRadiusParamsPage, CDialog)
13
14 //=======================================================================
15 //function : CRadiusParamsPage
16 //purpose  :
17 //=======================================================================
18
19 CRadiusParamsPage::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
33 CRadiusParamsPage::~CRadiusParamsPage()
34 {
35 }
36
37 //=======================================================================
38 //function : DoDataExchange
39 //purpose  :
40 //=======================================================================
41
42 void CRadiusParamsPage::DoDataExchange(CDataExchange* pDX)
43 {
44   CDialog::DoDataExchange(pDX);
45 }
46
47
48 BEGIN_MESSAGE_MAP(CRadiusParamsPage, CDialog)
49   ON_BN_CLICKED(IDC_BUTTON1, &CRadiusParamsPage::OnBnClickedObjectBtn)
50 END_MESSAGE_MAP()
51
52 //=======================================================================
53 //function : OnBnClickedObjectBtn
54 //purpose  :
55 //=======================================================================
56
57 void CRadiusParamsPage::OnBnClickedObjectBtn()
58 {
59   //Build dimension here
60   myAISContext->InitSelected();
61   if (!myAISContext->MoreSelected() ||
62        myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
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
72   TopoDS_Shape aSelShape = myAISContext->SelectedShape();
73
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->ClearSelected (Standard_False);
97   CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
98   // Try to create dimension if it is possible
99   Handle(PrsDim_Dimension) aDim;
100   if (myIsDiameterDimension)
101   {
102     aDim = new PrsDim_DiameterDimension (aCircle);
103     Handle(PrsDim_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
104   }
105   else
106   {
107     aDim = new PrsDim_RadiusDimension (aCircle);
108     Handle(PrsDim_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());
117   anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
118   if (aDimDlg->IsUnitsDisplayed())
119   {
120     aDim->SetDisplayUnits (aDimDlg->GetUnits());
121   }
122
123   aDim->SetDimensionAspect (anAspect);
124
125   // Display dimension in the neutral point
126
127   myAISContext->Display (aDim, Standard_True);
128   myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
129 }