0025284: Problems with standard MFC samples
[occt.git] / samples / mfc / standard / Common / ParamsFacesPage.cpp
CommitLineData
60bf98ae 1// ParamsFacesPage.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "ParamsFacesPage.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
12// CParamsFacesPage dialog
13
14IMPLEMENT_DYNAMIC(CParamsFacesPage, CDialog)
15
16CParamsFacesPage::CParamsFacesPage (Handle(AIS_InteractiveContext) theAISContext,
17 bool isAngleDimension /*= false*/,
18 CWnd* pParent /*=NULL*/)
19 : CDialog(CParamsFacesPage::IDD, pParent),
20 myAISContext (theAISContext),
21 myIsAngleDimension (isAngleDimension)
22{
23}
24
25CParamsFacesPage::~CParamsFacesPage()
26{
27}
28
29void CParamsFacesPage::DoDataExchange(CDataExchange* pDX)
30{
31 CDialog::DoDataExchange(pDX);
32}
33
34
35BEGIN_MESSAGE_MAP(CParamsFacesPage, CDialog)
36 ON_BN_CLICKED(IDC_FacesBtn1, &CParamsFacesPage::OnBnClickedFacesbtn1)
37 ON_BN_CLICKED(IDC_FacesBtn2, &CParamsFacesPage::OnBnClickedFacesbtn2)
38END_MESSAGE_MAP()
39
40
41// CParamsFacesPage message handlers
42
43void CParamsFacesPage::OnBnClickedFacesbtn1()
44{
45 // Check if face is selected
46 myAISContext->LocalContext()->InitSelected();
47 if (!myAISContext->LocalContext()->MoreSelected())
48 {
49 AfxMessageBox(_T("Choose the face and press the button again"),
50 MB_ICONINFORMATION | MB_OK);
51 return;
52 }
53
47162471 54 // Workaround for AIS_LocalContext::SelectedShape()
55 myFirstFace = TopoDS::Face (CDimensionDlg::SelectedShape());
56 //myFirstFace = TopoDS::Face (myAISContext->LocalContext()->SelectedShape());
57
60bf98ae 58 myAISContext->LocalContext()->ClearSelected();
59}
60
61void CParamsFacesPage::OnBnClickedFacesbtn2()
62{
63 // Check if face is selected
64 myAISContext->LocalContext()->InitSelected();
65 if (!myAISContext->LocalContext()->MoreSelected())
66 {
67 AfxMessageBox(_T("Choose the face and press the button again"),
68 MB_ICONINFORMATION | MB_OK);
69 return;
70 }
71
47162471 72 // Workaround for AIS_LocalContext::SelectedShape()
73 mySecondFace = TopoDS::Face (CDimensionDlg::SelectedShape());
74 //mySecondFace = TopoDS::Face (myAISContext->LocalContext()->SelectedShape());
60bf98ae 75 myAISContext->LocalContext()->ClearSelected();
76
77 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
78
79 myAISContext->CloseAllContexts();
80
81 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
82 anAspect->MakeArrows3d (Standard_False);
83 anAspect->MakeText3d (aDimDlg->GetTextType());
84 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
85 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
86 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 87 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 88 if (myIsAngleDimension)
89 {
90 // Build an angle dimension between two non-parallel edges
91 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (myFirstFace, mySecondFace);
92 anAngleDim->SetDimensionAspect (anAspect);
47162471 93
60bf98ae 94 if (aDimDlg->IsUnitsDisplayed())
95 {
96 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
97 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
98 {
99 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
100 }
101 else
102 {
103 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
104 }
105 }
106
107 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
108 myAISContext->Display (anAngleDim);
109 }
110 else
111 {
112 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (myFirstFace, mySecondFace);
113 aLenDim->SetDimensionAspect (anAspect);
47162471 114
60bf98ae 115 if (aLenDim->DimensionAspect()->IsUnitsDisplayed())
116 {
117 aLenDim->SetFlyout (aDimDlg->GetFlyout());
118 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
119 }
120
121 myAISContext->Display (aLenDim);
122 }
123
124 myAISContext->OpenLocalContext();
125 myAISContext->ActivateStandardMode (TopAbs_FACE);
126}