3 #include "RadiusParamsPage.h"
4 #include "DimensionDlg.h"
6 #include <AIS_InteractiveContext.hxx>
7 #include <AIS_LocalContext.hxx>
8 #include <AIS_RadiusDimension.hxx>
9 #include <AIS_DiameterDimension.hxx>
11 #include <TopoDS_Shape.hxx>
13 IMPLEMENT_DYNAMIC(CRadiusParamsPage, CDialog)
15 //=======================================================================
16 //function : CRadiusParamsPage
18 //=======================================================================
20 CRadiusParamsPage::CRadiusParamsPage (const Handle(AIS_InteractiveContext)& theAISContext,
21 const Standard_Boolean isDiameterDimension /* =Standard_False*/,
22 CWnd* pParent /*=NULL*/)
23 : CDialog (CRadiusParamsPage::IDD, pParent)
25 myAISContext = theAISContext;
26 myIsDiameterDimension = isDiameterDimension;
29 //=======================================================================
30 //function : ~CRadiusParamsPage
32 //=======================================================================
34 CRadiusParamsPage::~CRadiusParamsPage()
38 //=======================================================================
39 //function : DoDataExchange
41 //=======================================================================
43 void CRadiusParamsPage::DoDataExchange(CDataExchange* pDX)
45 CDialog::DoDataExchange(pDX);
49 BEGIN_MESSAGE_MAP(CRadiusParamsPage, CDialog)
50 ON_BN_CLICKED(IDC_BUTTON1, &CRadiusParamsPage::OnBnClickedObjectBtn)
53 //=======================================================================
54 //function : OnBnClickedObjectBtn
56 //=======================================================================
58 void CRadiusParamsPage::OnBnClickedObjectBtn()
60 //Build dimension here
61 myAISContext->InitSelected();
62 if (!myAISContext->MoreSelected() ||
63 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
65 AfxMessageBox (_T ("Choose the edge and press the button again"), MB_ICONINFORMATION | MB_OK);
70 Standard_Boolean isAttachPoint = Standard_False;
71 Standard_Real aFirstPar = 0, aLastPar = 0;
73 TopoDS_Shape aSelShape = myAISContext->SelectedShape();
75 if (aSelShape.ShapeType() != TopAbs_EDGE &&
76 aSelShape.ShapeType() != TopAbs_FACE &&
77 aSelShape.ShapeType() != TopAbs_WIRE)
80 if (aSelShape.ShapeType() == TopAbs_EDGE)
82 BRepAdaptor_Curve aCurve (TopoDS::Edge (aSelShape));
83 if (aCurve.GetType() != GeomAbs_Circle)
88 aCircle = aCurve.Circle();
89 if (aCurve.FirstParameter() != 0 && aCurve.LastParameter() != M_PI * 2)
91 isAttachPoint = Standard_True;
92 aFirstPar = aCurve.FirstParameter();
93 aLastPar = aCurve.LastParameter();
97 myAISContext->ClearSelected();
98 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
99 // Try to create dimension if it is possible
100 Handle(AIS_Dimension) aDim;
101 if (myIsDiameterDimension)
103 aDim = new AIS_DiameterDimension (aCircle);
104 Handle(AIS_DiameterDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
108 aDim = new AIS_RadiusDimension (aCircle);
109 Handle(AIS_RadiusDimension)::DownCast(aDim)->SetFlyout (aDimDlg->GetFlyout());
112 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
113 anAspect->MakeArrows3d (Standard_False);
114 anAspect->MakeText3d (aDimDlg->GetTextType());
115 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
116 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
117 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
118 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
119 if (aDimDlg->IsUnitsDisplayed())
121 aDim->SetDisplayUnits (aDimDlg->GetUnits());
124 aDim->SetDimensionAspect (anAspect);
126 // Display dimension in the neutral point
128 myAISContext->Display (aDim);
129 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));