b04654e74a6c0c64a89712aa451502be2b55d88c
[occt.git] / src / DrawDim / DrawDim_PlanarDiameter.cxx
1 // Created on: 1998-11-25
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DrawDim_PlanarDiameter.ixx>
18
19 #include <Geom_Curve.hxx>
20 #include <Geom_Circle.hxx>
21 #include <gp_Pnt.hxx>
22 #include <gp_Circ.hxx>
23 #include <BRep_Tool.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <Draw_Color.hxx>
26 #include <ElCLib.hxx>
27 #include <TopExp.hxx>
28 #include <TopoDS.hxx>
29 #include <TopoDS_Vertex.hxx>
30
31 //=======================================================================
32 //function : DrawDim_PlanarDiameter
33 //purpose  : 
34 //=======================================================================
35
36 DrawDim_PlanarDiameter::DrawDim_PlanarDiameter(const TopoDS_Face& face, const TopoDS_Shape& c)
37 {
38   myPlane  = face;
39   myCircle = c;
40 }
41
42
43 //=======================================================================
44 //function : DrawDim_PlanarDiameter
45 //purpose  : 
46 //=======================================================================
47
48 DrawDim_PlanarDiameter::DrawDim_PlanarDiameter(const TopoDS_Shape& c)
49 {
50   myCircle = c;
51 }
52
53
54 //=======================================================================
55 //function : DrawOn
56 //purpose  : 
57 //=======================================================================
58
59 void DrawDim_PlanarDiameter::DrawOn(Draw_Display& dis) const
60 {  
61   if (myCircle.ShapeType() == TopAbs_EDGE) {
62     Standard_Real f,l;
63     Handle(Geom_Curve) curve = BRep_Tool::Curve (TopoDS::Edge(myCircle),f,l);
64     if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
65       gp_Circ circle = Handle(Geom_Circle)::DownCast(curve)->Circ();
66       TopoDS_Vertex vf, vl;
67       TopExp::Vertices(TopoDS::Edge(myCircle),vf,vl);
68       const gp_Pnt first = BRep_Tool::Pnt(vf);
69       Standard_Real parfirst = ElCLib::Parameter(circle,first);
70       Standard_Real parlast = (parfirst + M_PI);
71       gp_Pnt last = ElCLib::Value(parlast,circle);
72       //
73       dis.Draw (first,last);
74       gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2);
75       DrawText(p,dis);
76       return;
77     }
78   }  
79   cout << " DrawDim_PlanarDiameter::DrawOn : dimension error" << endl;
80 }