1 // AngleParamsVerticesPage.cpp : implementation file
5 #include "AngleParamsVerticesPage.h"
6 #include "DimensionDlg.h"
8 #include <AIS_InteractiveContext.hxx>
9 #include <PrsDim_AngleDimension.hxx>
10 #include <BRep_Tool.hxx>
11 #include <GC_MakePlane.hxx>
12 #include <Prs3d_DimensionAspect.hxx>
14 // CAngleParamsVerticesPage dialog
16 IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog)
18 //=======================================================================
19 //function : CAngleParamsVerticesPage
21 //=======================================================================
23 CAngleParamsVerticesPage::CAngleParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext,
24 CWnd* pParent /*=NULL*/)
25 : CDialog(CAngleParamsVerticesPage::IDD, pParent)
27 myAISContext = theAISContext;
30 //=======================================================================
31 //function : ~CAngleParamsVerticesPage
33 //=======================================================================
35 CAngleParamsVerticesPage::~CAngleParamsVerticesPage()
39 //=======================================================================
40 //function : DoDataExchange
42 //=======================================================================
44 void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
46 CDialog::DoDataExchange (pDX);
50 BEGIN_MESSAGE_MAP(CAngleParamsVerticesPage, CDialog)
51 ON_BN_CLICKED(IDC_BUTTON1, &CAngleParamsVerticesPage::OnBnClickedVertex1Btn)
52 ON_BN_CLICKED(IDC_BUTTON3, &CAngleParamsVerticesPage::OnBnClickedVertex2Btn)
53 ON_BN_CLICKED(IDC_BUTTON4, &CAngleParamsVerticesPage::OnBnClickedVertex3Btn)
57 //=======================================================================
58 //function : OnBnClickedVertex1Btn
60 //=======================================================================
62 void CAngleParamsVerticesPage::OnBnClickedVertex1Btn()
64 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
66 // Now it's ok, edge selection mode is activated
67 // Check if some vertex is selected
68 myAISContext->InitSelected();
69 if (!myAISContext->MoreSelected() ||
70 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
72 AfxMessageBox (_T ("Choose the vertex and press the button again"),
73 MB_ICONINFORMATION | MB_OK);
77 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
78 myAISContext->ClearSelected (Standard_True);
81 //=======================================================================
82 //function : OnBnClickedVertex2Btn
84 //=======================================================================
86 void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
88 myAISContext->InitSelected();
89 if (!myAISContext->MoreSelected() ||
90 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
92 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
96 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
98 myAISContext->ClearSelected (Standard_True);
101 //=======================================================================
102 //function : OnBnClickedVertex3Btn
104 //=======================================================================
106 void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
108 myAISContext->InitSelected();
109 if (!myAISContext->MoreSelected())
111 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
115 myThirdVertex = TopoDS::Vertex (myAISContext->SelectedShape());
116 myAISContext->ClearSelected (Standard_False);
118 //Build dimension here
119 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
120 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
122 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
124 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
125 aP2 = BRep_Tool::Pnt (mySecondVertex),
126 aP3 = BRep_Tool::Pnt (myThirdVertex);
127 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
129 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
130 Handle(PrsDim_AngleDimension) anAngleDim = new PrsDim_AngleDimension (aP1,aP2,aP3);
131 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
132 anAspect->MakeArrows3d (Standard_False);
133 anAspect->MakeText3d (aDimDlg->GetTextType());
134 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
135 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
136 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
137 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
138 if (aDimDlg->IsUnitsDisplayed())
140 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
141 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
143 // No units - for degree is special symbol that is enabled by default
144 anAspect->MakeUnitsDisplayed (Standard_False);
146 else // radians - no special symbol
148 anAngleDim->SetDisplaySpecialSymbol (PrsDim_DisplaySpecialSymbol_No);
151 anAngleDim->SetDimensionAspect (anAspect);
152 myAISContext->Display (anAngleDim, Standard_True);
153 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));