0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / DrawDim / DrawDim_Radius.cxx
1 // Created on: 1997-04-21
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-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
18 #include <BRepAdaptor_Surface.hxx>
19 #include <Draw_Display.hxx>
20 #include <DrawDim_Radius.hxx>
21 #include <GC_MakeCircle.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Surface.hxx>
25 #include <Geom_ToroidalSurface.hxx>
26 #include <gp_Circ.hxx>
27 #include <gp_Pnt.hxx>
28 #include <Standard_Type.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Face.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_Radius,DrawDim_Dimension)
33
34 //=======================================================================
35 //function : DrawDim_Radius
36 //purpose  : 
37 //=======================================================================
38 DrawDim_Radius::DrawDim_Radius(const TopoDS_Face& cylinder)
39 {
40   myCylinder = cylinder;
41 }
42
43 //=======================================================================
44 //function : Cylinder
45 //purpose  : 
46 //=======================================================================
47
48 const TopoDS_Face& DrawDim_Radius::Cylinder() const
49 {
50   return myCylinder;
51 }
52
53 //=======================================================================
54 //function : Cylinder
55 //purpose  : 
56 //=======================================================================
57
58 void DrawDim_Radius::Cylinder(const TopoDS_Face& face) 
59 {
60   myCylinder = face;
61 }
62
63
64 //=======================================================================
65 //function : DrawOn
66 //purpose  : 
67 //=======================================================================
68
69 void DrawDim_Radius::DrawOn(Draw_Display& dis) const
70 {
71   // input  
72   TopoDS_Shape myFShape = myCylinder;
73
74   // output
75   gp_Pnt myPosition;
76   gp_Circ myCircle;
77
78 //=======================================================================
79 //function : ComputeOneFaceRadius
80 //purpose  : 
81 //=======================================================================
82
83 //void AIS_RadiusDimension::ComputeOneFaceRadius(const Handle(Prs3d_Presentation)& aPresentation)
84 //{
85 #ifdef OCCT_DEBUG
86   cout << "entree dans computeonefaceradius"<< endl;
87 #endif
88   BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape));
89   Standard_Real uFirst, uLast, vFirst, vLast;
90   uFirst = surfAlgo.FirstUParameter();
91   uLast = surfAlgo.LastUParameter();
92   vFirst = surfAlgo.FirstVParameter();
93   vLast = surfAlgo.LastVParameter();
94   Standard_Real uMoy = (uFirst + uLast)/2;
95   Standard_Real vMoy = (vFirst + vLast)/2;
96   gp_Pnt curpos ;
97   surfAlgo.D0(uMoy, vMoy, curpos);
98   const Handle(Geom_Surface)& surf = surfAlgo.Surface().Surface();
99   Handle(Geom_Curve) aCurve;
100   if (surf->DynamicType() == STANDARD_TYPE(Geom_ToroidalSurface)) {
101     aCurve = surf->UIso(uMoy);
102     uFirst = vFirst;
103     uLast = vLast;
104   }
105   else {
106     aCurve = surf->VIso(vMoy);
107   }
108
109   if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Circle)) {
110     myCircle = Handle(Geom_Circle)::DownCast(aCurve)->Circ();
111   } // if (aCurve->DynamicType() ...
112
113   else {
114     // compute a circle from 3 points on "aCurve"
115     gp_Pnt P1, P2;
116     surfAlgo.D0(uFirst, vMoy, P1);
117     surfAlgo.D0(uLast, vMoy, P2);
118     GC_MakeCircle mkCirc(P1, curpos, P2);
119     myCircle = mkCirc.Value()->Circ();
120   } // else ...
121
122   myPosition = curpos;
123
124   // DISPLAY
125   // Add(myText, curpos, mCircle, uFirst, uLast)    
126
127   dis.Draw(myCircle,uFirst,uLast);  
128   dis.DrawMarker(myPosition, Draw_Losange);
129 }