0026886: Visualization, TKV3d - eliminate global variables
[occt.git] / samples / mfc / standard / Common / LengthParamsEdgesPage.cpp
CommitLineData
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
19CLengthParamsEdgesPage::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
33CLengthParamsEdgesPage::~CLengthParamsEdgesPage()
34{
35}
36
37//=======================================================================
38//function : DoDataExchange
39//purpose :
40//=======================================================================
41
42void CLengthParamsEdgesPage::DoDataExchange(CDataExchange* pDX)
43{
44 CDialog::DoDataExchange(pDX);
45}
46
47
48BEGIN_MESSAGE_MAP(CLengthParamsEdgesPage, CDialog)
49 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsEdgesPage::OnBnClickedEdge1Btn)
50 ON_BN_CLICKED(IDC_BUTTON3, &CLengthParamsEdgesPage::OnBnClickedEdge2Btn)
51END_MESSAGE_MAP()
52
53
54//=======================================================================
55//function : OnBnClickedEdge1Btn
56//purpose :
57//=======================================================================
58
59void 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
016e5959 81 myFirstEdge = TopoDS::Edge (myAISContext->SelectedShape());
47162471 82
a6eb515f 83 myAISContext->LocalContext()->ClearSelected();
84}
85
86//=======================================================================
87//function : OnBnClickedEdge2Btn
88//purpose :
89//=======================================================================
90
91void CLengthParamsEdgesPage::OnBnClickedEdge2Btn()
92{
93 myAISContext->LocalContext()->InitSelected();
94 if (!myAISContext->LocalContext()->MoreSelected())
95 {
96 AfxMessageBox (_T("Choose the edge and press the button again"),
97 MB_ICONINFORMATION | MB_OK);
98 return;
99 }
100
016e5959 101 mySecondEdge = TopoDS::Edge (myAISContext->SelectedShape());
47162471 102
a6eb515f 103 myAISContext->LocalContext()->ClearSelected();
104
105 // Build plane through three points
106 BRepAdaptor_Curve aCurve1 (myFirstEdge);
107 BRepAdaptor_Curve aCurve2 (mySecondEdge);
108
109 gp_Pnt aP1=aCurve1.Value (0.1);
110 gp_Pnt aP2=aCurve1.Value (0.9);
111 gp_Pnt aP3=aCurve2.Value (0.5);
112
113 GC_MakePlane aMkPlane (aP1,aP2,aP3);
114
115 Handle(Geom_Plane) aPlane = aMkPlane.Value();
116
117 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
118
119 myAISContext->CloseAllContexts();
120
121 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
122 anAspect->MakeArrows3d (Standard_False);
123 anAspect->MakeText3d (aDimDlg->GetTextType());
124 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
125 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
126 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 127 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
a6eb515f 128 if (myIsAngleDimension)
129 {
130 // Build an angle dimension between two non-parallel edges
131 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (myFirstEdge, mySecondEdge);
132 anAngleDim->SetDimensionAspect (anAspect);
60bf98ae 133 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
134 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 135 {
136 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
60bf98ae 137 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
a6eb515f 138 {
60bf98ae 139 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
a6eb515f 140 }
141 else
142 {
143 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
144 }
145 }
146
147 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
148 myAISContext->Display (anAngleDim);
149 }
150 else
151 {
152 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (myFirstEdge, mySecondEdge, aPlane->Pln());
153 aLenDim->SetDimensionAspect (anAspect);
47162471 154 aLenDim->SetFlyout (aDimDlg->GetFlyout());
60bf98ae 155 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 156 {
a6eb515f 157 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
158 }
159
160 myAISContext->Display (aLenDim);
161 }
162
163 myAISContext->OpenLocalContext();
164 myAISContext->ActivateStandardMode (TopAbs_EDGE);
165}