b311480e |
1 | // Created on: 1996-01-10 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <DrawDim_PlanarDistance.ixx> |
18 | #include <DrawDim.hxx> |
19 | #include <BRep_Tool.hxx> |
20 | #include <TopoDS.hxx> |
21 | #include <Geom_Curve.hxx> |
22 | #include <Geom_Line.hxx> |
23 | #include <gp_Lin.hxx> |
24 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
25 | #include <TopExp.hxx> |
26 | |
27 | |
28 | |
29 | //======================================================================= |
30 | //function : Draw |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | void DrawDim_PlanarDistance::Draw |
35 | (const gp_Pnt& point, const TopoDS_Edge& edge, Draw_Display& dis) const |
36 | { |
37 | Standard_Real f,l; |
38 | Handle(Geom_Curve) line = BRep_Tool::Curve(edge,f,l); |
39 | GeomAPI_ProjectPointOnCurve pj (point,Handle(Geom_Curve)::DownCast(line)); |
40 | if (pj.NbPoints() == 1) { |
41 | gp_Pnt first = point; |
42 | gp_Pnt last = pj.Point(1); |
43 | dis.Draw (first,last); |
44 | |
45 | gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2); |
46 | DrawText(p,dis); |
47 | } |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : DrawDim_PlanarDistance |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Face& face, |
56 | const TopoDS_Shape& geom1, |
57 | const TopoDS_Shape& geom2) |
58 | { |
59 | myPlane = face; myGeom1 = geom1; myGeom2 = geom2; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : DrawDim_PlanarDistance |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Shape& geom1, |
68 | const TopoDS_Shape& geom2) |
69 | { |
70 | myGeom1 = geom1; myGeom2 = geom2; |
71 | } |
72 | |
73 | //======================================================================= |
74 | //function : DrawOn |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | void DrawDim_PlanarDistance::DrawOn(Draw_Display& dis) const |
79 | { |
80 | if (myGeom1.ShapeType() == TopAbs_VERTEX && myGeom2.ShapeType() == TopAbs_VERTEX) { |
81 | gp_Pnt first = BRep_Tool::Pnt(TopoDS::Vertex(myGeom1)); |
82 | gp_Pnt last = BRep_Tool::Pnt(TopoDS::Vertex(myGeom2)); |
83 | dis.Draw (first,last); |
84 | |
85 | gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2); |
86 | DrawText(p,dis); |
87 | return; |
88 | } |
89 | |
90 | else if (myGeom1.ShapeType() == TopAbs_VERTEX && myGeom2.ShapeType() == TopAbs_EDGE) { |
91 | gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(myGeom1)); |
92 | Draw (point,TopoDS::Edge(myGeom2),dis); |
93 | return; |
94 | } |
95 | |
96 | else if (myGeom1.ShapeType() == TopAbs_EDGE && myGeom2.ShapeType() == TopAbs_VERTEX) { |
97 | gp_Pnt point = BRep_Tool::Pnt(TopoDS::Vertex(myGeom2)); |
98 | Draw (point,TopoDS::Edge(myGeom1),dis); |
99 | return; |
100 | } |
101 | |
102 | else if (myGeom1.ShapeType() == TopAbs_EDGE && myGeom2.ShapeType() == TopAbs_EDGE) { |
103 | Standard_Real f,l; |
104 | Handle(Geom_Curve) C = BRep_Tool::Curve (TopoDS::Edge(myGeom1),f,l); |
105 | if (!C.IsNull()) { |
106 | Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(C); |
107 | if (!L.IsNull()) { |
108 | gp_Pnt point = L->Lin().Location(); |
109 | TopoDS_Edge edge = TopoDS::Edge(myGeom2); |
110 | Draw (point,edge,dis); |
111 | return; |
112 | } |
113 | } |
114 | } |
0797d9d3 |
115 | #ifdef OCCT_DEBUG |
7fd59977 |
116 | cout << " DrawDim_PlanarDistance::DrawOn : dimension error" << endl; |
63c629aa |
117 | #endif |
7fd59977 |
118 | } |