a6eb515f |
1 | // LenghtParamsEdgesPage.cpp : implementation file |
2 | // |
3 | |
4 | #include "stdafx.h" |
5 | #include "LengthParamsEdgesPage.h" |
6 | #include "DimensionDlg.h" |
7 | #include <AIS_InteractiveContext.hxx> |
8 | #include <AIS_LocalContext.hxx> |
9 | #include <AIS_LengthDimension.hxx> |
10 | #include <AIS_AngleDimension.hxx> |
11 | #include <GC_MakePlane.hxx> |
12 | // CLengthParamsEdgesPage dialog |
13 | |
14 | //======================================================================= |
15 | //function : CLengthParamsEdgesPage |
16 | //purpose : |
17 | //======================================================================= |
18 | |
19 | CLengthParamsEdgesPage::CLengthParamsEdgesPage (Handle(AIS_InteractiveContext) theAISContext, |
20 | bool isAngleDimension /*= false*/, |
21 | CWnd* pParent /*=NULL*/) |
22 | : CDialog(CLengthParamsEdgesPage::IDD, pParent) |
23 | { |
24 | myAISContext = theAISContext; |
25 | myIsAngleDimension = isAngleDimension; |
26 | } |
27 | |
28 | //======================================================================= |
29 | //function : ~CLengthParamsEdgesPage |
30 | //purpose : |
31 | //======================================================================= |
32 | |
33 | CLengthParamsEdgesPage::~CLengthParamsEdgesPage() |
34 | { |
35 | } |
36 | |
37 | //======================================================================= |
38 | //function : DoDataExchange |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | void CLengthParamsEdgesPage::DoDataExchange(CDataExchange* pDX) |
43 | { |
44 | CDialog::DoDataExchange(pDX); |
45 | } |
46 | |
47 | |
48 | BEGIN_MESSAGE_MAP(CLengthParamsEdgesPage, CDialog) |
49 | ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsEdgesPage::OnBnClickedEdge1Btn) |
50 | ON_BN_CLICKED(IDC_BUTTON3, &CLengthParamsEdgesPage::OnBnClickedEdge2Btn) |
51 | END_MESSAGE_MAP() |
52 | |
53 | |
54 | //======================================================================= |
55 | //function : OnBnClickedEdge1Btn |
56 | //purpose : |
57 | //======================================================================= |
58 | |
59 | void CLengthParamsEdgesPage::OnBnClickedEdge1Btn() |
60 | { |
61 | // Open local context and choose the edge for length dimensions |
62 | if (!myAISContext->HasOpenedContext()) |
63 | { |
64 | myAISContext->OpenLocalContext(); |
65 | myAISContext->ActivateStandardMode (TopAbs_EDGE); |
66 | AfxMessageBox (_T("Local context was not opened. Choose the edge and press the button again"), |
67 | MB_ICONINFORMATION | MB_OK); |
68 | return; |
69 | } |
70 | |
71 | // Now it's ok, local context is opened and edge selection mode is activated |
72 | // Check if some edge is selected |
73 | myAISContext->LocalContext()->InitSelected(); |
74 | if (!myAISContext->LocalContext()->MoreSelected()) |
75 | { |
76 | AfxMessageBox(_T("Choose the edge and press the button again"), |
77 | MB_ICONINFORMATION | MB_OK); |
78 | return; |
79 | } |
80 | |
81 | myFirstEdge = TopoDS::Edge (myAISContext->LocalContext()->SelectedShape()); |
82 | myAISContext->LocalContext()->ClearSelected(); |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : OnBnClickedEdge2Btn |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void CLengthParamsEdgesPage::OnBnClickedEdge2Btn() |
91 | { |
92 | myAISContext->LocalContext()->InitSelected(); |
93 | if (!myAISContext->LocalContext()->MoreSelected()) |
94 | { |
95 | AfxMessageBox (_T("Choose the edge and press the button again"), |
96 | MB_ICONINFORMATION | MB_OK); |
97 | return; |
98 | } |
99 | |
100 | mySecondEdge = TopoDS::Edge (myAISContext->LocalContext()->SelectedShape()); |
101 | myAISContext->LocalContext()->ClearSelected(); |
102 | |
103 | // Build plane through three points |
104 | BRepAdaptor_Curve aCurve1 (myFirstEdge); |
105 | BRepAdaptor_Curve aCurve2 (mySecondEdge); |
106 | |
107 | gp_Pnt aP1=aCurve1.Value (0.1); |
108 | gp_Pnt aP2=aCurve1.Value (0.9); |
109 | gp_Pnt aP3=aCurve2.Value (0.5); |
110 | |
111 | GC_MakePlane aMkPlane (aP1,aP2,aP3); |
112 | |
113 | Handle(Geom_Plane) aPlane = aMkPlane.Value(); |
114 | |
115 | CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner()); |
116 | |
117 | myAISContext->CloseAllContexts(); |
118 | |
119 | Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); |
120 | anAspect->MakeArrows3d (Standard_False); |
121 | anAspect->MakeText3d (aDimDlg->GetTextType()); |
122 | anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight()); |
123 | anAspect->MakeTextShaded (aDimDlg->IsText3dShaded()); |
124 | anAspect->SetCommonColor (aDimDlg->GetDimensionColor()); |
125 | if (myIsAngleDimension) |
126 | { |
127 | // Build an angle dimension between two non-parallel edges |
128 | Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (myFirstEdge, mySecondEdge); |
129 | anAngleDim->SetDimensionAspect (anAspect); |
130 | anAngleDim->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed()); |
131 | if (anAngleDim->IsUnitsDisplayed()) |
132 | { |
133 | anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ()); |
134 | if ((anAngleDim->DisplayUnits().IsEqual (TCollection_AsciiString ("deg")))) |
135 | { |
136 | anAngleDim->MakeUnitsDisplayed (Standard_False); |
137 | } |
138 | else |
139 | { |
140 | anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No); |
141 | } |
142 | } |
143 | |
144 | anAngleDim->SetFlyout (aDimDlg->GetFlyout()); |
145 | myAISContext->Display (anAngleDim); |
146 | } |
147 | else |
148 | { |
149 | Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (myFirstEdge, mySecondEdge, aPlane->Pln()); |
150 | aLenDim->SetDimensionAspect (anAspect); |
151 | aLenDim->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed()); |
152 | if (aLenDim->IsUnitsDisplayed()) |
153 | { |
154 | aLenDim->SetFlyout (aDimDlg->GetFlyout()); |
155 | aLenDim->SetDisplayUnits (aDimDlg->GetUnits()); |
156 | } |
157 | |
158 | myAISContext->Display (aLenDim); |
159 | } |
160 | |
161 | myAISContext->OpenLocalContext(); |
162 | myAISContext->ActivateStandardMode (TopAbs_EDGE); |
163 | } |