1 // LengthParamsVerticesPage.cpp : implementation file
5 #include "LengthParamsVerticesPage.h"
6 #include "DimensionDlg.h"
7 #include <Standard_Macro.hxx>
8 #include <AIS_InteractiveContext.hxx>
9 #include <AIS_LocalContext.hxx>
10 #include <AIS_LengthDimension.hxx>
11 #include <GC_MakePlane.hxx>
14 // CLengthParamsVerticesPage dialog
16 IMPLEMENT_DYNAMIC(CLengthParamsVerticesPage, CDialog)
18 //=======================================================================
19 //function : CLengthParamsVerticesPage
21 //=======================================================================
23 CLengthParamsVerticesPage::CLengthParamsVerticesPage (Handle(AIS_InteractiveContext) theAISContext, CWnd* pParent /*=NULL*/)
24 : CDialog (CLengthParamsVerticesPage::IDD, pParent)
26 myAISContext = theAISContext;
29 //=======================================================================
30 //function : ~CLengthParamsVerticesPage
32 //=======================================================================
34 CLengthParamsVerticesPage::~CLengthParamsVerticesPage()
38 //=======================================================================
39 //function : DoDataExchange
41 //=======================================================================
43 void CLengthParamsVerticesPage::DoDataExchange (CDataExchange* pDX)
45 CDialog::DoDataExchange (pDX);
49 BEGIN_MESSAGE_MAP(CLengthParamsVerticesPage, CDialog)
50 ON_BN_CLICKED(IDC_BUTTON1, &CLengthParamsVerticesPage::OnBnClickedVertex1Btn)
51 ON_BN_CLICKED(IDC_BUTTON2, &CLengthParamsVerticesPage::OnBnClickedVertex2Btn)
55 //=======================================================================
56 //function : OnBnClickedVertex1Btn
58 //=======================================================================
60 void CLengthParamsVerticesPage::OnBnClickedVertex1Btn()
62 // Open local context and choose the edge for length dimensions
63 if (!myAISContext->HasOpenedContext())
65 myAISContext->OpenLocalContext();
66 myAISContext->ActivateStandardMode(TopAbs_VERTEX);
67 AfxMessageBox(_T("Local context was not opened. Choose the vertices and press the button again"),
68 MB_ICONINFORMATION | MB_OK);
72 // Now it's ok, local context is opened and edge selection mode is activated
73 // Check if some edge is selected
74 myAISContext->LocalContext()->InitSelected();
75 if (!myAISContext->LocalContext()->MoreSelected() ||
76 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
78 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
82 myFirstVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
84 myAISContext->LocalContext()->ClearSelected();
87 //=======================================================================
88 //function : OnBnClickedVertex2Btn
90 //=======================================================================
92 void CLengthParamsVerticesPage::OnBnClickedVertex2Btn()
94 myAISContext->LocalContext()->InitSelected();
95 if (!myAISContext->LocalContext()->MoreSelected() ||
96 myAISContext->SelectedShape().ShapeType() != TopAbs_VERTEX)
98 AfxMessageBox (_T ("Choose the vertex and press the button again"), MB_ICONINFORMATION | MB_OK);
102 mySecondVertex = TopoDS::Vertex (myAISContext->LocalContext()->SelectedShape());
103 myAISContext->LocalContext()->ClearSelected();
105 //Build dimension here
106 gp_Pnt aP1=BRep_Tool::Pnt (myFirstVertex);
107 gp_Pnt aP2=BRep_Tool::Pnt (mySecondVertex);
108 gp_Pnt aP3 (aP2.X() + 10, aP2.Y() + 10, aP2.Z() + 10);
110 GC_MakePlane aMkPlane (aP1,aP2,aP3);
111 Handle(Geom_Plane) aPlane = aMkPlane.Value();
113 CDimensionDlg *aDimDlg = (CDimensionDlg*)(this->GetParentOwner());
115 Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane->Pln());
117 Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
118 anAspect->MakeArrows3d (Standard_False);
119 anAspect->MakeText3d (aDimDlg->GetTextType());
120 anAspect->TextAspect()->SetHeight (aDimDlg->GetFontHeight());
121 anAspect->MakeTextShaded (aDimDlg->IsText3dShaded());
122 anAspect->MakeUnitsDisplayed (aDimDlg->IsUnitsDisplayed());
123 if (aDimDlg->IsUnitsDisplayed())
125 aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
128 aLenDim->SetDimensionAspect (anAspect);
129 aLenDim->SetFlyout (aDimDlg->GetFlyout());
131 myAISContext->CloseAllContexts();
132 myAISContext->Display (aLenDim);
133 myAISContext->OpenLocalContext();
134 myAISContext->ActivateStandardMode (TopAbs_VERTEX);
137 //=======================================================================
138 //function : getFirstVertex
140 //=======================================================================
142 const TopoDS_Vertex& CLengthParamsVerticesPage::getFirstVertex() const
144 return myFirstVertex;
147 //=======================================================================
148 //function : getSecondVertex
150 //=======================================================================
152 const TopoDS_Vertex& CLengthParamsVerticesPage::getSecondVertex() const
154 return mySecondVertex;