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 // Open local context and choose the vertex for angle dimensions
67 if (!myAISContext->HasOpenedContext())
69 myAISContext->OpenLocalContext();
70 myAISContext->ActivateStandardMode(TopAbs_VERTEX);
71 AfxMessageBox (_T ("Local context was not opened. Choose the edge and press the button again"),
72 MB_ICONINFORMATION | MB_OK);
76 // Now it's ok, local context is opened and edge selection mode is activated
77 // Check if some vertex is selected
78 myAISContext->LocalContext()->InitSelected();
79 if (!myAISContext->LocalContext()->MoreSelected() ||
80 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
82 AfxMessageBox (_T ("Choose the vertex and press the button again"),
83 MB_ICONINFORMATION | MB_OK);
87 myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
88 myAISContext->LocalContext()->ClearSelected();
91 //=======================================================================
92 //function : OnBnClickedVertex2Btn
94 //=======================================================================
96 void CAngleParamsVerticesPage::OnBnClickedVertex2Btn()
98 myAISContext->LocalContext()->InitSelected();
99 if (!myAISContext->LocalContext()->MoreSelected() ||
100 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
102 AfxMessageBox ( _T("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
106 mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
108 myAISContext->LocalContext()->ClearSelected();
111 //=======================================================================
112 //function : OnBnClickedVertex3Btn
114 //=======================================================================
116 void CAngleParamsVerticesPage::OnBnClickedVertex3Btn()
118 myAISContext->LocalContext()->InitSelected();
119 if (!myAISContext->LocalContext()->MoreSelected())
121 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
125 myThirdVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
126 myAISContext->LocalContext()->ClearSelected();
128 //Build dimension here
129 TopoDS_Edge anEdge12 = BRepBuilderAPI_MakeEdge (myFirstVertex, mySecondVertex);
130 TopoDS_Edge anEdge23 = BRepBuilderAPI_MakeEdge (mySecondVertex, myThirdVertex);
132 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
134 gp_Pnt aP1 = BRep_Tool::Pnt (myFirstVertex),
135 aP2 = BRep_Tool::Pnt (mySecondVertex),
136 aP3 = BRep_Tool::Pnt (myThirdVertex);
137 GC_MakePlane aPlaneBuilder (aP1,aP2,aP3);
139 Handle(Geom_Plane) aPlane = aPlaneBuilder.Value();
140 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (aP1,aP2,aP3);
141 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
142 anAspect->MakeArrows3d (Standard_False);
143 anAspect->MakeText3d (aDimDlg->GetTextType());
144 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
145 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
146 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
147 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
148 if (aDimDlg->IsUnitsDisplayed())
150 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits());
151 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
153 // No units - for degree is special symbol that is enabled by default
154 anAspect->MakeUnitsDisplayed (Standard_False);
156 else // radians - no special symbol
158 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
161 anAngleDim->SetDimensionAspect (anAspect);
162 myAISContext->CloseAllContexts();
163 myAISContext->Display (anAngleDim);
164 myAISContext->OpenLocalContext();
165 myAISContext->ActivateStandardMode (TopAbs_VERTEX);