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