0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / DrawDim / DrawDim_PlanarDistance.cxx
1 // Created on: 1996-01-10
2 // Created by: Denis PASCAL
3 // Copyright (c) 1996-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 <BRep_Tool.hxx>
19 #include <Draw_Display.hxx>
20 #include <DrawDim.hxx>
21 #include <DrawDim_PlanarDistance.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Line.hxx>
24 #include <GeomAPI_ProjectPointOnCurve.hxx>
25 #include <gp_Lin.hxx>
26 #include <gp_Pnt.hxx>
27 #include <Standard_Type.hxx>
28 #include <TopExp.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33
34 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_PlanarDistance,DrawDim_PlanarDimension)
35
36 //=======================================================================
37 //function : Draw
38 //purpose  : 
39 //=======================================================================
40 void DrawDim_PlanarDistance::Draw 
41 (const gp_Pnt& point, const TopoDS_Edge& edge, Draw_Display& dis) const
42 {    
43   Standard_Real f,l;
44   Handle(Geom_Curve) line = BRep_Tool::Curve(edge,f,l);
45   GeomAPI_ProjectPointOnCurve pj (point, line);
46   if (pj.NbPoints() == 1) { 
47     gp_Pnt first = point;
48     gp_Pnt last = pj.Point(1);
49     dis.Draw (first,last);  
50
51     gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2);
52     DrawText(p,dis);
53   }
54 }
55
56 //=======================================================================
57 //function : DrawDim_PlanarDistance
58 //purpose  : 
59 //=======================================================================
60
61 DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Face& face,
62                                                 const TopoDS_Shape& geom1, 
63                                                 const TopoDS_Shape& geom2)
64 {
65   myPlane = face; myGeom1 = geom1; myGeom2 = geom2;
66 }
67
68 //=======================================================================
69 //function : DrawDim_PlanarDistance
70 //purpose  : 
71 //=======================================================================
72
73 DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Shape& geom1, 
74                                                 const TopoDS_Shape&  geom2)
75 {  
76   myGeom1 = geom1; myGeom2 = geom2;
77 }
78
79 //=======================================================================
80 //function : DrawOn
81 //purpose  : 
82 //=======================================================================
83
84 void DrawDim_PlanarDistance::DrawOn(Draw_Display& dis) const 
85 {
86   if (myGeom1.ShapeType() == TopAbs_VERTEX && myGeom2.ShapeType() == TopAbs_VERTEX) {
87     gp_Pnt first = BRep_Tool::Pnt(TopoDS::Vertex(myGeom1));
88     gp_Pnt last  = BRep_Tool::Pnt(TopoDS::Vertex(myGeom2));  
89     dis.Draw (first,last);  
90
91     gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2);
92     DrawText(p,dis);
93     return;
94   }
95
96   else if (myGeom1.ShapeType() == TopAbs_VERTEX && myGeom2.ShapeType() == TopAbs_EDGE) {
97     gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(myGeom1)); 
98     Draw (point,TopoDS::Edge(myGeom2),dis);
99     return;
100   }  
101
102   else if (myGeom1.ShapeType() == TopAbs_EDGE && myGeom2.ShapeType() == TopAbs_VERTEX) {
103     gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(myGeom2)); 
104     Draw (point,TopoDS::Edge(myGeom1),dis);
105     return;
106   }
107
108   else if (myGeom1.ShapeType() == TopAbs_EDGE && myGeom2.ShapeType() == TopAbs_EDGE) {
109     Standard_Real f,l;
110     Handle(Geom_Curve) C = BRep_Tool::Curve (TopoDS::Edge(myGeom1),f,l);  
111     if (!C.IsNull()) {
112       Handle(Geom_Line) L  = Handle(Geom_Line)::DownCast(C);  
113       if (!L.IsNull()) {
114         gp_Pnt point = L->Lin().Location();  
115         TopoDS_Edge edge = TopoDS::Edge(myGeom2); 
116         Draw (point,edge,dis);
117         return;
118       }
119     }
120   } 
121 #ifdef OCCT_DEBUG
122   std::cout << " DrawDim_PlanarDistance::DrawOn : dimension error" << std::endl;
123 #endif
124 }