1 // LenghtParamsEdgesPage.cpp : implementation file
5 #include "LengthParamsEdgesPage.h"
6 #include "DimensionDlg.h"
7 #include <AIS_InteractiveContext.hxx>
8 #include <AIS_LengthDimension.hxx>
9 #include <AIS_AngleDimension.hxx>
10 #include <GC_MakePlane.hxx>
11 // CLengthParamsEdgesPage dialog
13 //=======================================================================
14 //function : CLengthParamsEdgesPage
16 //=======================================================================
18 CLengthParamsEdgesPage::CLengthParamsEdgesPage (Handle(AIS_InteractiveContext) theAISContext,
19 bool isAngleDimension /*= false*/,
20 CWnd* pParent /*=NULL*/)
21 : CDialog(CLengthParamsEdgesPage::IDD, pParent)
23 myAISContext = theAISContext;
24 myIsAngleDimension = isAngleDimension;
27 //=======================================================================
28 //function : ~CLengthParamsEdgesPage
30 //=======================================================================
32 CLengthParamsEdgesPage::~CLengthParamsEdgesPage()
36 //=======================================================================
37 //function : DoDataExchange
39 //=======================================================================
41 void CLengthParamsEdgesPage::DoDataExchange(CDataExchange* pDX)
43 CDialog::DoDataExchange(pDX);
47 BEGIN_MESSAGE_MAP(CLengthParamsEdgesPage, CDialog)
48 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsEdgesPage::OnBnClickedEdge1Btn)
49 ON_BN_CLICKED(IDC_BUTTON3, &CLengthParamsEdgesPage::OnBnClickedEdge2Btn)
53 //=======================================================================
54 //function : OnBnClickedEdge1Btn
56 //=======================================================================
58 void CLengthParamsEdgesPage::OnBnClickedEdge1Btn()
60 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));
62 // Now it's ok, edge selection mode is activated
63 // Check if some edge is selected
64 myAISContext->InitSelected();
65 if (!myAISContext->MoreSelected() ||
66 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
68 AfxMessageBox(_T("Choose the edge and press the button again"),
69 MB_ICONINFORMATION | MB_OK);
73 myFirstEdge = TopoDS::Edge (myAISContext->SelectedShape());
75 myAISContext->ClearSelected (Standard_True);
78 //=======================================================================
79 //function : OnBnClickedEdge2Btn
81 //=======================================================================
83 void CLengthParamsEdgesPage::OnBnClickedEdge2Btn()
85 myAISContext->InitSelected();
86 if (!myAISContext->MoreSelected() ||
87 myAISContext->SelectedShape().ShapeType() != TopAbs_EDGE)
89 AfxMessageBox (_T("Choose the edge and press the button again"),
90 MB_ICONINFORMATION | MB_OK);
94 mySecondEdge = TopoDS::Edge (myAISContext->SelectedShape());
96 myAISContext->ClearSelected (Standard_True);
98 // Build plane through three points
99 BRepAdaptor_Curve aCurve1 (myFirstEdge);
100 BRepAdaptor_Curve aCurve2 (mySecondEdge);
102 gp_Pnt aP1=aCurve1.Value (0.1);
103 gp_Pnt aP2=aCurve1.Value (0.9);
104 gp_Pnt aP3=aCurve2.Value (0.5);
106 GC_MakePlane aMkPlane (aP1,aP2,aP3);
108 Handle(Geom_Plane) aPlane = aMkPlane.Value();
110 CDimensionDlg *aDimDlg = (CDimensionDlg*)(GetParentOwner());
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());
118 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
119 if (myIsAngleDimension)
121 // Build an angle dimension between two non-parallel edges
122 Handle(AIS_AngleDimension) anAngleDim = new AIS_AngleDimension (myFirstEdge, mySecondEdge);
123 anAngleDim->SetDimensionAspect (anAspect);
124 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
125 if (aDimDlg->IsUnitsDisplayed())
127 anAngleDim->SetDisplayUnits (aDimDlg->GetUnits ());
128 if ((anAngleDim->GetDisplayUnits().IsEqual (TCollection_AsciiString ("deg"))))
130 anAngleDim->DimensionAspect()->MakeUnitsDisplayed (Standard_False);
134 anAngleDim->SetDisplaySpecialSymbol (AIS_DSS_No);
138 anAngleDim->SetFlyout (aDimDlg->GetFlyout());
139 myAISContext->Display (anAngleDim, Standard_True);
143 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (myFirstEdge, mySecondEdge, aPlane->Pln());
144 aLenDim->SetDimensionAspect (anAspect);
145 aLenDim->SetFlyout (aDimDlg->GetFlyout());
146 if (aDimDlg->IsUnitsDisplayed())
148 aLenDim->SetDisplayUnits (aDimDlg->GetUnits());
151 myAISContext->Display (aLenDim, Standard_True);
154 myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_EDGE));