a6eb515f |
1 | // LengthParamsEdgePage.cpp : implementation file |
2 | // |
3 | |
4 | #include "stdafx.h" |
5 | #include "LengthParamsEdgePage.h" |
6 | #include "DimensionDlg.h" |
7 | |
8 | #include <Standard_Macro.hxx> |
9 | #include <AIS_InteractiveContext.hxx> |
a6eb515f |
10 | #include <AIS_LengthDimension.hxx> |
11 | #include <GC_MakePlane.hxx> |
12 | #include <TopExp.hxx> |
13 | |
14 | // CLengthParamsEdgePage dialog |
15 | |
16 | IMPLEMENT_DYNAMIC(CLengthParamsEdgePage, CDialog) |
17 | |
18 | //======================================================================= |
19 | //function : CLengthParamsEdgePage |
20 | //purpose : |
21 | //======================================================================= |
22 | |
23 | CLengthParamsEdgePage::CLengthParamsEdgePage (Handle(AIS_InteractiveContext) theContext,CWnd* pParent /*=NULL*/) |
24 | : CDialog (CLengthParamsEdgePage::IDD, pParent) |
25 | { |
26 | myAISContext = theContext; |
27 | } |
28 | |
29 | //======================================================================= |
30 | //function : ~CLengthParamsEdgePage |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | CLengthParamsEdgePage::~CLengthParamsEdgePage() |
35 | { |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : DoDataExchange |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | void CLengthParamsEdgePage::DoDataExchange (CDataExchange* pDX) |
44 | { |
45 | CDialog::DoDataExchange(pDX); |
46 | } |
47 | |
48 | BEGIN_MESSAGE_MAP (CLengthParamsEdgePage, CDialog) |
49 | ON_BN_CLICKED (IDC_ChooseEdgeBtn, &CLengthParamsEdgePage::OnBnClickedChooseEdgeBtn) |
50 | END_MESSAGE_MAP() |
51 | |
52 | //======================================================================= |
53 | //function : GetButton |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | CButton* CLengthParamsEdgePage::GetButton() |
58 | { |
59 | return (CButton*)GetDlgItem (IDC_ChooseEdgeBtn); |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : OnBnClickedChooseEdgeBtn |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | void CLengthParamsEdgePage::OnBnClickedChooseEdgeBtn() |
68 | { |
404c8936 |
69 | myAISContext->InitSelected(); |
a6eb515f |
70 | |
404c8936 |
71 | if (!myAISContext->MoreSelected() || |
71c089e9 |
72 | myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE) |
a6eb515f |
73 | { |
71c089e9 |
74 | AfxMessageBox ( _T("Choose the edge and press the button again"), MB_ICONINFORMATION | MB_OK); |
a6eb515f |
75 | return; |
76 | } |
77 | |
016e5959 |
78 | TopoDS_Shape aSelShape = myAISContext->SelectedShape(); |
47162471 |
79 | const TopoDS_Edge& anEdge = TopoDS::Edge (aSelShape); |
80 | |
0577ae8c |
81 | myAISContext->ClearSelected (Standard_False); |
a6eb515f |
82 | TopoDS_Vertex aFirstVertex, aSecondVertex; |
47162471 |
83 | TopExp::Vertices (TopoDS::Edge (anEdge), aFirstVertex, aSecondVertex); |
a6eb515f |
84 | |
47162471 |
85 | gp_Pnt aP1 = BRep_Tool::Pnt (aFirstVertex); |
86 | gp_Pnt aP2 = BRep_Tool::Pnt (aSecondVertex); |
87 | gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10); |
a6eb515f |
88 | |
89 | GC_MakePlane aMkPlane (aP1,aP2,aP3); |
47162471 |
90 | Handle(Geom_Plane) aPlane = aMkPlane.Value(); |
a6eb515f |
91 | |
92 | CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner()); |
93 | |
47162471 |
94 | Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (TopoDS::Edge (anEdge), aPlane->Pln()); |
a6eb515f |
95 | Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); |
96 | anAspect->MakeArrows3d (Standard_False); |
97 | anAspect->MakeText3d (aDimDlg->GetTextType()); |
98 | anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight()); |
99 | anAspect->MakeTextShaded (aDimDlg->IsText3dShaded()); |
100 | anAspect->SetCommonColor (aDimDlg->GetDimensionColor()); |
47162471 |
101 | anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed()); |
60bf98ae |
102 | if (aDimDlg->IsUnitsDisplayed()) |
a6eb515f |
103 | { |
104 | aLenDim->SetDisplayUnits (aDimDlg->GetUnits()); |
105 | } |
106 | |
107 | aLenDim->SetDimensionAspect (anAspect); |
108 | aLenDim->SetFlyout (aDimDlg->GetFlyout()); |
109 | |
0577ae8c |
110 | myAISContext->Display (aLenDim, Standard_True); |
404c8936 |
111 | myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE)); |
a6eb515f |
112 | } |