0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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>
787ff240 8#include <PrsDim_LengthDimension.hxx>
9#include <PrsDim_AngleDimension.hxx>
60bf98ae 10
11// CParamsFacesPage dialog
12
13IMPLEMENT_DYNAMIC(CParamsFacesPage, CDialog)
14
15CParamsFacesPage::CParamsFacesPage (Handle(AIS_InteractiveContext) theAISContext,
16 bool isAngleDimension /*= false*/,
17 CWnd* pParent /*=NULL*/)
18 : CDialog(CParamsFacesPage::IDD, pParent),
19 myAISContext (theAISContext),
20 myIsAngleDimension (isAngleDimension)
21{
22}
23
24CParamsFacesPage::~CParamsFacesPage()
25{
26}
27
28void CParamsFacesPage::DoDataExchange(CDataExchange* pDX)
29{
30 CDialog::DoDataExchange(pDX);
31}
32
33
34BEGIN_MESSAGE_MAP(CParamsFacesPage, CDialog)
35 ON_BN_CLICKED(IDC_FacesBtn1, &CParamsFacesPage::OnBnClickedFacesbtn1)
36 ON_BN_CLICKED(IDC_FacesBtn2, &CParamsFacesPage::OnBnClickedFacesbtn2)
37END_MESSAGE_MAP()
38
39
40// CParamsFacesPage message handlers
41
42void CParamsFacesPage::OnBnClickedFacesbtn1()
43{
44 // Check if face is selected
404c8936 45 myAISContext->InitSelected();
46 if (!myAISContext->MoreSelected() ||
71c089e9 47 myAISContext->SelectedShape().ShapeType() != TopAbs_FACE)
60bf98ae 48 {
49 AfxMessageBox(_T("Choose the face and press the button again"),
50 MB_ICONINFORMATION | MB_OK);
51 return;
52 }
53
016e5959 54 myFirstFace = TopoDS::Face (myAISContext->SelectedShape());
47162471 55
0577ae8c 56 myAISContext->ClearSelected (Standard_True);
60bf98ae 57}
58
59void CParamsFacesPage::OnBnClickedFacesbtn2()
60{
404c8936 61 const Standard_Integer aSelectionMode = AIS_Shape::SelectionMode (TopAbs_FACE);
62
60bf98ae 63 // Check if face is selected
404c8936 64 myAISContext->InitSelected();
65 if (!myAISContext->MoreSelected() ||
71c089e9 66 myAISContext->SelectedShape().ShapeType() != TopAbs_FACE)
60bf98ae 67 {
68 AfxMessageBox(_T("Choose the face and press the button again"),
69 MB_ICONINFORMATION | MB_OK);
70 return;
71 }
72
016e5959 73 mySecondFace = TopoDS::Face (myAISContext->SelectedShape());
0577ae8c 74 myAISContext->ClearSelected (Standard_False);
60bf98ae 75
76 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
77
404c8936 78 myAISContext->Deactivate (aSelectionMode);
60bf98ae 79
80 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
81 anAspect->MakeArrows3d (Standard_False);
82 anAspect->MakeText3d (aDimDlg->GetTextType());
83 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
84 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
85 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 86 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
60bf98ae 87 if (myIsAngleDimension)
88 {
89 // Build an angle dimension between two non-parallel edges
787ff240 90 Handle(PrsDim_AngleDimension) anAngleDim = new PrsDim_AngleDimension (myFirstFace, mySecondFace);
60bf98ae 91 anAngleDim->SetDimensionAspect (anAspect);
47162471 92
60bf98ae 93 if (aDimDlg->IsUnitsDisplayed())
94 {
95 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
96 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
97 {
98 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
99 }
100 else
101 {
787ff240 102 anAngleDim->SetDisplaySpecialSymbol (PrsDim_DisplaySpecialSymbol_No);
60bf98ae 103 }
104 }
105
106 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
0577ae8c 107 myAISContext->Display (anAngleDim, Standard_True);
60bf98ae 108 }
109 else
110 {
787ff240 111 Handle(PrsDim_LengthDimension) aLenDim = new PrsDim_LengthDimension (myFirstFace, mySecondFace);
60bf98ae 112 aLenDim->SetDimensionAspect (anAspect);
47162471 113
60bf98ae 114 if (aLenDim->DimensionAspect()->IsUnitsDisplayed())
115 {
116 aLenDim->SetFlyout (aDimDlg->GetFlyout());
117 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
118 }
119
0577ae8c 120 myAISContext->Display (aLenDim, Standard_True);
60bf98ae 121 }
122
404c8936 123 myAISContext->Activate (aSelectionMode);
60bf98ae 124}