1 // LenghtParamsEdgesPage.cpp : implementation file
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
14 //=======================================================================
15 //function : CLengthParamsEdgesPage
17 //=======================================================================
19 CLengthParamsEdgesPage::CLengthParamsEdgesPage (Handle(AIS_InteractiveContext) theAISContext,
20 bool isAngleDimension /*= false*/,
21 CWnd* pParent /*=NULL*/)
22 : CDialog(CLengthParamsEdgesPage::IDD, pParent)
24 myAISContext = theAISContext;
25 myIsAngleDimension = isAngleDimension;
28 //=======================================================================
29 //function : ~CLengthParamsEdgesPage
31 //=======================================================================
33 CLengthParamsEdgesPage::~CLengthParamsEdgesPage()
37 //=======================================================================
38 //function : DoDataExchange
40 //=======================================================================
42 void CLengthParamsEdgesPage::DoDataExchange(CDataExchange* pDX)
44 CDialog::DoDataExchange(pDX);
48 BEGIN_MESSAGE_MAP(CLengthParamsEdgesPage, CDialog)
49 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsEdgesPage::OnBnClickedEdge1Btn)
50 ON_BN_CLICKED(IDC_BUTTON3, &CLengthParamsEdgesPage::OnBnClickedEdge2Btn)
54 //=======================================================================
55 //function : OnBnClickedEdge1Btn
57 //=======================================================================
59 void CLengthParamsEdgesPage::OnBnClickedEdge1Btn()
61 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
63 // Now it's ok, edge selection mode is activated
64 // Check if some edge is selected
65 myAISContext->InitSelected();
66 if (!myAISContext->MoreSelected() ||
67 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
69 AfxMessageBox(_T("Choose the edge and press the button again"),
70 MB_ICONINFORMATION | MB_OK);
74 myFirstEdge = TopoDS::Edge (myAISContext->SelectedShape());
76 myAISContext->ClearSelected();
79 //=======================================================================
80 //function : OnBnClickedEdge2Btn
82 //=======================================================================
84 void CLengthParamsEdgesPage::OnBnClickedEdge2Btn()
86 myAISContext->InitSelected();
87 if (!myAISContext->MoreSelected() ||
88 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
90 AfxMessageBox (_T("Choose the edge and press the button again"),
91 MB_ICONINFORMATION | MB_OK);
95 mySecondEdge = TopoDS::Edge (myAISContext->SelectedShape());
97 myAISContext->ClearSelected();
99 // Build plane through three points
100 BRepAdaptor_Curve aCurve1 (myFirstEdge);
101 BRepAdaptor_Curve aCurve2 (mySecondEdge);
103 gp_Pnt aP1=aCurve1.Value (0.1);
104 gp_Pnt aP2=aCurve1.Value (0.9);
105 gp_Pnt aP3=aCurve2.Value (0.5);
107 GC_MakePlane aMkPlane (aP1,aP2,aP3);
109 Handle(Geom_Plane) aPlane = aMkPlane.Value();
111 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
113 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
114 anAspect->MakeArrows3d (Standard_False);
115 anAspect->MakeText3d (aDimDlg->GetTextType());
116 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
117 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
118 anAspect->SetCommonColor (aDimDlg->GetDimensionColor());
119 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
120 if (myIsAngleDimension)
122 // Build an angle dimension between two non-parallel edges
123 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (myFirstEdge, mySecondEdge);
124 anAngleDim->SetDimensionAspect (anAspect);
125 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
126 if (aDimDlg->IsUnitsDisplayed())
128 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
129 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
131 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
135 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
139 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
140 myAISContext->Display (anAngleDim);
144 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (myFirstEdge, mySecondEdge, aPlane->Pln());
145 aLenDim->SetDimensionAspect (anAspect);
146 aLenDim->SetFlyout (aDimDlg->GetFlyout());
147 if (aDimDlg->IsUnitsDisplayed())
149 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
152 myAISContext->Display (aLenDim);
155 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));