1 // AngleParamsVerticesPage.cpp : implementation file
5 #include "AngleParamsVerticesPage.h"
6 #include "DimensionDlg.h"
8 #include <AIS_InteractiveContext.hxx>
9 #include <AIS_LengthDimension.hxx>
10 #include <AIS_AngleDimension.hxx>
11 #include <BRep_Tool.hxx>
12 #include <GC_MakePlane.hxx>
13 #include <Prs3d_DimensionAspect.hxx>
15 // CAngleParamsVerticesPage dialog
17 IMPLEMENT_DYNAMIC(CAngleParamsVerticesPage, CDialog)
19 //=======================================================================
20 //function : CAngleParamsVerticesPage
22 //=======================================================================
24 CAngleParamsVerticesPage::CAngleParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext,
25 CWnd* pParent /*=NULL*/)
26 : CDialog(CAngleParamsVerticesPage::IDD, pParent)
28 myAISContext = theAISContext;
31 //=======================================================================
32 //function : ~CAngleParamsVerticesPage
34 //=======================================================================
36 CAngleParamsVerticesPage::~CAngleParamsVerticesPage()
40 //=======================================================================
41 //function : DoDataExchange
43 //=======================================================================
45 void CAngleParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
47 CDialog::DoDataExchange (pDX);
51 BEGIN_MESSAGE_MAP(CAngleParamsVerticesPage, CDialog)
52 ON_BN_CLICKED(IDC_BUTTON1, &CAngleParamsVerticesPage::OnBnClickedVertex1Btn)
53 ON_BN_CLICKED(IDC_BUTTON3, &CAngleParamsVerticesPage::OnBnClickedVertex2Btn)
54 ON_BN_CLICKED(IDC_BUTTON4, &CAngleParamsVerticesPage::OnBnClickedVertex3Btn)
58 //=======================================================================
59 //function : OnBnClickedVertex1Btn
61 //=======================================================================
63 void CAngleParamsVerticesPage::OnBnClickedVertex1Btn()
65 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
67 // Now it's ok, edge selection mode is activated
68 // Check if some vertex is selected
69 myAISContext->InitSelected();
70 if (!myAISContext->MoreSelected() ||
71 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
73 AfxMessageBox (_T ("Choose the vertex and press the button again"),
74 MB_ICONINFORMATION | MB_OK);
78 myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
79 myAISContext->ClearSelected (Standard_True);
82 //=======================================================================
83 //function : OnBnClickedVertex2Btn
85 //=======================================================================
87 void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
89 myAISContext->InitSelected();
90 if (!myAISContext->MoreSelected() ||
91 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
93 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
97 mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
99 myAISContext->ClearSelected (Standard_True);
102 //=======================================================================
103 //function : OnBnClickedVertex3Btn
105 //=======================================================================
107 void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
109 myAISContext->InitSelected();
110 if (!myAISContext->MoreSelected())
112 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
116 myThirdVertex = TopoDS::Vertex (myAISContext->SelectedShape());
117 myAISContext->ClearSelected (Standard_False);
119 //Build dimension here
120 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
121 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
123 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
125 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
126 aP2 = BRep_Tool::Pnt (mySecondVertex),
127 aP3 = BRep_Tool::Pnt (myThirdVertex);
128 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
130 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
131 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
132 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
133 anAspect->MakeArrows3d (Standard_False);
134 anAspect->MakeText3d (aDimDlg->GetTextType());
135 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
136 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
137 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
138 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
139 if (aDimDlg->IsUnitsDisplayed())
141 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
142 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
144 // No units - for degree is special symbol that is enabled by default
145 anAspect->MakeUnitsDisplayed (Standard_False);
147 else // radians - no special symbol
149 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
152 anAngleDim->SetDimensionAspect (anAspect);
153 myAISContext->Display (anAngleDim, Standard_True);
154 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));