3 #include "RadiusParamsPage.h"
4 #include "DimensionDlg.h"
6 #include <AIS_InteractiveContext.hxx>
7 #include <AIS_RadiusDimension.hxx>
8 #include <AIS_DiameterDimension.hxx>
10 #include <TopoDS_Shape.hxx>
12 IMPLEMENT_DYNAMIC(CRadiusParamsPage, CDialog)
14 //=======================================================================
15 //function : CRadiusParamsPage
17 //=======================================================================
19 CRadiusParamsPage::CRadiusParamsPage (const Handle(AIS_InteractiveContext)& theAISContext,
20 const Standard_Boolean isDiameterDimension /* =Standard_False*/,
21 CWnd* pParent /*=NULL*/)
22 : CDialog (CRadiusParamsPage::IDD, pParent)
24 myAISContext = theAISContext;
25 myIsDiameterDimension = isDiameterDimension;
28 //=======================================================================
29 //function : ~CRadiusParamsPage
31 //=======================================================================
33 CRadiusParamsPage::~CRadiusParamsPage()
37 //=======================================================================
38 //function : DoDataExchange
40 //=======================================================================
42 void CRadiusParamsPage::DoDataExchange(CDataExchange* pDX)
44 CDialog::DoDataExchange(pDX);
48 BEGIN_MESSAGE_MAP(CRadiusParamsPage, CDialog)
49 ON_BN_CLICKED(IDC_BUTTON1, &CRadiusParamsPage::OnBnClickedObjectBtn)
52 //=======================================================================
53 //function : OnBnClickedObjectBtn
55 //=======================================================================
57 void CRadiusParamsPage::OnBnClickedObjectBtn()
59 //Build dimension here
60 myAISContext->InitSelected();
61 if (!myAISContext->MoreSelected() ||
62 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
64 AfxMessageBox (_T ("Choose the edge and press the button again"), MB_ICONINFORMATION | MB_OK);
69 Standard_Boolean isAttachPoint = Standard_False;
70 Standard_Real aFirstPar = 0, aLastPar = 0;
72 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
74 if (aSelShape.ShapeType() != TopAbs_EDGE &&
75 aSelShape.ShapeType() != TopAbs_FACE &&
76 aSelShape.ShapeType() != TopAbs_WIRE)
79 if (aSelShape.ShapeType() == TopAbs_EDGE)
81 BRepAdaptor_Curve aCurve (TopoDS::Edge (aSelShape));
82 if (aCurve.GetType() != GeomAbs_Circle)
87 aCircle = aCurve.Circle();
88 if (aCurve.FirstParameter() != 0 && aCurve.LastParameter() != M_PI * 2)
90 isAttachPoint = Standard_True;
91 aFirstPar = aCurve.FirstParameter();
92 aLastPar = aCurve.LastParameter();
96 myAISContext->ClearSelected (Standard_False);
97 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
98 // Try to create dimension if it is possible
99 Handle(AIS_Dimension) aDim;
100 if (myIsDiameterDimension)
102 aDim = new AIS_DiameterDimension (aCircle);
103 Handle(AIS_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
107 aDim = new AIS_RadiusDimension (aCircle);
108 Handle(AIS_RadiusDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
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())
120 aDim->SetDisplayUnits (aDimDlg->GetUnits());
123 aDim->SetDimensionAspect (anAspect);
125 // Display dimension in the neutral point
127 myAISContext->Display (aDim, Standard_True);
128 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));