1 // LengthParamsVerticesPage.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "LengthParamsVerticesPage.h"
6 #include "DimensionDlg.h"
7 #include <Standard_Macro.hxx>
8 #include <AIS_InteractiveContext.hxx>
9 #include <PrsDim_LengthDimension.hxx>
10 #include <GC_MakePlane.hxx>
11 
12 
13 // CLengthParamsVerticesPage dialog
14 
IMPLEMENT_DYNAMIC(CLengthParamsVerticesPage,CDialog)15 IMPLEMENT_DYNAMIC(CLengthParamsVerticesPage, CDialog)
16 
17 //=======================================================================
18 //function : CLengthParamsVerticesPage
19 //purpose  :
20 //=======================================================================
21 
22 CLengthParamsVerticesPage::CLengthParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext, CWnd* pParent /*=NULL*/)
23 : CDialog (CLengthParamsVerticesPage::IDD, pParent)
24 {
25  myAISContext = theAISContext;
26 }
27 
28 //=======================================================================
29 //function : ~CLengthParamsVerticesPage
30 //purpose  :
31 //=======================================================================
32 
~CLengthParamsVerticesPage()33 CLengthParamsVerticesPage::~CLengthParamsVerticesPage()
34 {
35 }
36 
37 //=======================================================================
38 //function : DoDataExchange
39 //purpose  :
40 //=======================================================================
41 
DoDataExchange(CDataExchange * pDX)42 void CLengthParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
43 {
44   CDialog::DoDataExchange (pDX);
45 }
46 
47 
BEGIN_MESSAGE_MAP(CLengthParamsVerticesPage,CDialog)48 BEGIN_MESSAGE_MAP(CLengthParamsVerticesPage, CDialog)
49   ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsVerticesPage::OnBnClickedVertex1Btn)
50   ON_BN_CLICKED(IDC_BUTTON2, &CLengthParamsVerticesPage::OnBnClickedVertex2Btn)
51 END_MESSAGE_MAP()
52 
53 
54 //=======================================================================
55 //function : OnBnClickedVertex1Btn
56 //purpose  :
57 //=======================================================================
58 
59 void CLengthParamsVerticesPage::OnBnClickedVertex1Btn()
60 {
61   myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
62 
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_VERTEX)
68   {
69     AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
70     return;
71   }
72 
73   myFirstVertex = TopoDS::Vertex (myAISContext->SelectedShape());
74 
75   myAISContext->ClearSelected (Standard_True);
76 }
77 
78 //=======================================================================
79 //function : OnBnClickedVertex2Btn
80 //purpose  :
81 //=======================================================================
82 
OnBnClickedVertex2Btn()83 void CLengthParamsVerticesPage::OnBnClickedVertex2Btn()
84 {
85   myAISContext->InitSelected();
86   if (!myAISContext->MoreSelected() ||
87        myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
88   {
89     AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
90     return;
91   }
92 
93   mySecondVertex = TopoDS::Vertex (myAISContext->SelectedShape());
94   myAISContext->ClearSelected (Standard_False);
95 
96   //Build dimension here
97   gp_Pnt aP1=BRep_Tool::Pnt (myFirstVertex);
98   gp_Pnt aP2=BRep_Tool::Pnt (mySecondVertex);
99   gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
100 
101   GC_MakePlane aMkPlane (aP1,aP2,aP3);
102   Handle(Geom_Plane) aPlane = aMkPlane.Value();
103 
104   CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
105 
106   Handle(PrsDim_LengthDimension) aLenDim = new PrsDim_LengthDimension (aP1, aP2, aPlane->Pln());
107 
108   Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
109   anAspect->MakeArrows3d (Standard_False);
110   anAspect->MakeText3d (aDimDlg->GetTextType());
111   anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
112   anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
113   anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
114   if (aDimDlg->IsUnitsDisplayed())
115   {
116     aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
117   }
118 
119   aLenDim->SetDimensionAspect (anAspect);
120   aLenDim->SetFlyout (aDimDlg->GetFlyout());
121 
122   myAISContext->Display (aLenDim, Standard_True);
123   myAISContext->Activate (AIS_Shape::SelectionMode (TopAbs_VERTEX));
124 }
125 
126 //=======================================================================
127 //function : getFirstVertex
128 //purpose  :
129 //=======================================================================
130 
getFirstVertex() const131 const TopoDS_Vertex& CLengthParamsVerticesPage::getFirstVertex() const
132 {
133   return myFirstVertex;
134 }
135 
136 //=======================================================================
137 //function : getSecondVertex
138 //purpose  :
139 //=======================================================================
140 
getSecondVertex() const141 const TopoDS_Vertex& CLengthParamsVerticesPage::getSecondVertex() const
142 {
143   return mySecondVertex;
144 }
145