1 // AngleParamsVerticesPage.cpp : implementation file
5 #include "AngleParamsVerticesPage.h"
6 #include "DimensionDlg.h"
8 #include <AIS_InteractiveContext.hxx>
9 #include <AIS_LocalContext.hxx>
10 #include <AIS_LengthDimension.hxx>
11 #include <AIS_AngleDimension.hxx>
12 #include <BRep_Tool.hxx>
13 #include <GC_MakePlane.hxx>
14 #include <Prs3d_DimensionAspect.hxx>
16 // CAngleParamsVerticesPage dialog
18 IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog)
20 //=======================================================================
21 //function : CAngleParamsVerticesPage
23 //=======================================================================
25 CAngleParamsVerticesPage::CAngleParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext,
26 CWnd* pParent /*=NULL*/)
27 : CDialog(CAngleParamsVerticesPage::IDD, pParent)
29 myAISContext = theAISContext;
32 //=======================================================================
33 //function : ~CAngleParamsVerticesPage
35 //=======================================================================
37 CAngleParamsVerticesPage::~CAngleParamsVerticesPage()
41 //=======================================================================
42 //function : DoDataExchange
44 //=======================================================================
46 void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
48 CDialog::DoDataExchange (pDX);
52 BEGIN_MESSAGE_MAP(CAngleParamsVerticesPage, CDialog)
53 ON_BN_CLICKED(IDC_BUTTON1, &CAngleParamsVerticesPage::OnBnClickedVertex1Btn)
54 ON_BN_CLICKED(IDC_BUTTON3, &CAngleParamsVerticesPage::OnBnClickedVertex2Btn)
55 ON_BN_CLICKED(IDC_BUTTON4, &CAngleParamsVerticesPage::OnBnClickedVertex3Btn)
59 //=======================================================================
60 //function : OnBnClickedVertex1Btn
62 //=======================================================================
64 void CAngleParamsVerticesPage::OnBnClickedVertex1Btn()
66 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
68 // Now it's ok, edge selection mode is activated
69 // Check if some vertex is selected
70 myAISContext->InitSelected();
71 if (!myAISContext->MoreSelected() ||
72 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
74 AfxMessageBox (_T ("Choose the vertex and press the button again"),
75 MB_ICONINFORMATION | MB_OK);
79 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
80 myAISContext->ClearSelected();
83 //=======================================================================
84 //function : OnBnClickedVertex2Btn
86 //=======================================================================
88 void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
90 myAISContext->InitSelected();
91 if (!myAISContext->MoreSelected() ||
92 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
94 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
98 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
100 myAISContext->ClearSelected();
103 //=======================================================================
104 //function : OnBnClickedVertex3Btn
106 //=======================================================================
108 void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
110 myAISContext->InitSelected();
111 if (!myAISContext->MoreSelected())
113 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
117 myThirdVertex = TopoDS::Vertex (myAISContext->SelectedShape());
118 myAISContext->ClearSelected();
120 //Build dimension here
121 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
122 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
124 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
126 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
127 aP2 = BRep_Tool::Pnt (mySecondVertex),
128 aP3 = BRep_Tool::Pnt (myThirdVertex);
129 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
131 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
132 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
133 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
134 anAspect->MakeArrows3d (Standard_False);
135 anAspect->MakeText3d (aDimDlg->GetTextType());
136 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
137 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
138 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
139 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
140 if (aDimDlg->IsUnitsDisplayed())
142 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
143 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
145 // No units - for degree is special symbol that is enabled by default
146 anAspect->MakeUnitsDisplayed (Standard_False);
148 else // radians - no special symbol
150 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
153 anAngleDim->SetDimensionAspect (anAspect);
154 myAISContext->Display (anAngleDim);
155 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));