0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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>
787ff240 8#include <PrsDim_LengthDimension.hxx>
9#include <PrsDim_AngleDimension.hxx>
a6eb515f 10#include <GC_MakePlane.hxx>
11// CLengthParamsEdgesPage dialog
12
13//=======================================================================
14//function : CLengthParamsEdgesPage
15//purpose :
16//=======================================================================
17
18CLengthParamsEdgesPage::CLengthParamsEdgesPage (Handle(AIS_InteractiveContext) theAISContext,
19 bool isAngleDimension /*= false*/,
20 CWnd* pParent /*=NULL*/)
21: CDialog(CLengthParamsEdgesPage::IDD, pParent)
22{
23 myAISContext = theAISContext;
24 myIsAngleDimension = isAngleDimension;
25}
26
27//=======================================================================
28//function : ~CLengthParamsEdgesPage
29//purpose :
30//=======================================================================
31
32CLengthParamsEdgesPage::~CLengthParamsEdgesPage()
33{
34}
35
36//=======================================================================
37//function : DoDataExchange
38//purpose :
39//=======================================================================
40
41void CLengthParamsEdgesPage::DoDataExchange(CDataExchange* pDX)
42{
43 CDialog::DoDataExchange(pDX);
44}
45
46
47BEGIN_MESSAGE_MAP(CLengthParamsEdgesPage, CDialog)
48 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsEdgesPage::OnBnClickedEdge1Btn)
49 ON_BN_CLICKED(IDC_BUTTON3, &CLengthParamsEdgesPage::OnBnClickedEdge2Btn)
50END_MESSAGE_MAP()
51
52
53//=======================================================================
54//function : OnBnClickedEdge1Btn
55//purpose :
56//=======================================================================
57
58void CLengthParamsEdgesPage::OnBnClickedEdge1Btn()
59{
404c8936 60 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
a6eb515f 61
404c8936 62 // Now it's ok, edge selection mode is activated
a6eb515f 63 // Check if some edge is selected
404c8936 64 myAISContext->InitSelected();
65 if (!myAISContext->MoreSelected() ||
71c089e9 66 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
a6eb515f 67 {
68 AfxMessageBox(_T("Choose the edge and press the button again"),
69 MB_ICONINFORMATION | MB_OK);
70 return;
71 }
72
016e5959 73 myFirstEdge = TopoDS::Edge (myAISContext->SelectedShape());
47162471 74
0577ae8c 75 myAISContext->ClearSelected (Standard_True);
a6eb515f 76}
77
78//=======================================================================
79//function : OnBnClickedEdge2Btn
80//purpose :
81//=======================================================================
82
83void CLengthParamsEdgesPage::OnBnClickedEdge2Btn()
84{
404c8936 85 myAISContext->InitSelected();
86 if (!myAISContext->MoreSelected() ||
71c089e9 87 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
a6eb515f 88 {
89 AfxMessageBox (_T("Choose the edge and press the button again"),
90 MB_ICONINFORMATION | MB_OK);
91 return;
92 }
93
016e5959 94 mySecondEdge = TopoDS::Edge (myAISContext->SelectedShape());
47162471 95
0577ae8c 96 myAISContext->ClearSelected (Standard_True);
a6eb515f 97
98 // Build plane through three points
99 BRepAdaptor_Curve aCurve1 (myFirstEdge);
100 BRepAdaptor_Curve aCurve2 (mySecondEdge);
101
102 gp_Pnt aP1=aCurve1.Value (0.1);
103 gp_Pnt aP2=aCurve1.Value (0.9);
104 gp_Pnt aP3=aCurve2.Value (0.5);
105
106 GC_MakePlane aMkPlane (aP1,aP2,aP3);
107
108 Handle(Geom_Plane) aPlane = aMkPlane.Value();
109
110 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
111
a6eb515f 112 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
113 anAspect->MakeArrows3d (Standard_False);
114 anAspect->MakeText3d (aDimDlg->GetTextType());
115 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
116 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
117 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
47162471 118 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
a6eb515f 119 if (myIsAngleDimension)
120 {
121 // Build an angle dimension between two non-parallel edges
787ff240 122 Handle(PrsDim_AngleDimension) anAngleDim = new PrsDim_AngleDimension (myFirstEdge, mySecondEdge);
a6eb515f 123 anAngleDim->SetDimensionAspect (anAspect);
60bf98ae 124 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
125 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 126 {
127 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
60bf98ae 128 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
a6eb515f 129 {
60bf98ae 130 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
a6eb515f 131 }
132 else
133 {
787ff240 134 anAngleDim->SetDisplaySpecialSymbol (PrsDim_DisplaySpecialSymbol_No);
a6eb515f 135 }
136 }
137
138 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
0577ae8c 139 myAISContext->Display (anAngleDim, Standard_True);
a6eb515f 140 }
141 else
142 {
787ff240 143 Handle(PrsDim_LengthDimension) aLenDim = new PrsDim_LengthDimension (myFirstEdge, mySecondEdge, aPlane->Pln());
a6eb515f 144 aLenDim->SetDimensionAspect (anAspect);
47162471 145 aLenDim->SetFlyout (aDimDlg->GetFlyout());
60bf98ae 146 if (aDimDlg->IsUnitsDisplayed())
a6eb515f 147 {
a6eb515f 148 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
149 }
150
0577ae8c 151 myAISContext->Display (aLenDim, Standard_True);
a6eb515f 152 }
153
404c8936 154 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
a6eb515f 155}