0023604: Uninitialized variables in debug mode
[occt.git] / src / DrawDim / DrawDim.cxx
CommitLineData
b311480e 1// Created on: 1996-01-10
2// Created by: Denis PASCAL
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <DrawDim.ixx>
24
25#include <Draw_Text3D.hxx>
26#include <gp_Pnt.hxx>
27#include <TCollection_AsciiString.hxx>
28#include <Geom_Curve.hxx>
29#include <BRep_Tool.hxx>
30#include <TopExp.hxx>
31#include <TopExp_Explorer.hxx>
32#include <TopExp_Explorer.hxx>
33#include <TopoDS.hxx>
34#include <TopAbs.hxx>
35#include <Geom_Line.hxx>
36#include <Geom_Circle.hxx>
37#include <Geom_Plane.hxx>
38#include <ElCLib.hxx>
39#include <Draw.hxx>
40#include <Draw_Appli.hxx>
41#include <TopoDS_Vertex.hxx>
42#ifdef WNT
43Standard_IMPORT Draw_Viewer dout;
44#endif
45
46//=======================================================================
47//function : AllCommands
48//purpose :
49//=======================================================================
50
51void DrawDim::AllCommands (Draw_Interpretor& theCommands)
52{
53 PlanarDimensionCommands (theCommands);
54}
55
56
57//=======================================================================
58//function : DrawShapeName
59//purpose :
60//=======================================================================
61
62void DrawDim::DrawShapeName (const TopoDS_Shape& ashape,
63 const Standard_CString aname)
64{
65 gp_Pnt position;
66 TCollection_AsciiString t (" ");
67 switch (ashape.ShapeType()) {
68 case TopAbs_EDGE :
69 {
70 Standard_Real f,l,parameter;
71 Handle(Geom_Curve) curve = BRep_Tool::Curve(TopoDS::Edge(ashape),f,l);
72 if (curve->IsKind(STANDARD_TYPE(Geom_Line))) {
73 parameter = (f+l)/2.;
74 position = ElCLib::Value(parameter,Handle(Geom_Line)::DownCast(curve)->Lin());
75 }
76 else if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
77 parameter = (f+l)/2.;
c6541a0c 78 if (f > l) parameter = parameter + M_PI;
7fd59977 79 position = ElCLib::Value(parameter,Handle(Geom_Circle)::DownCast(curve)->Circ());
80 }
81 }
82 break;
83 case TopAbs_VERTEX :
84 {
85 position = BRep_Tool::Pnt(TopoDS::Vertex(ashape));
86 }
87 break;
7fd59977 88 default:
89 break;
7fd59977 90 }
91 t+=aname; //Name();
92 Handle(Draw_Text3D) text = new Draw_Text3D (position,t.ToCString(),Draw_blanc);
93 dout << text;
94}
95
96
97//=======================================================================
98//function : Pln
99//purpose :
100//=======================================================================
101
102Standard_Boolean DrawDim::Pln (const TopoDS_Face& f, gp_Pln& p)
103{
104 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(f));
105 if (!P.IsNull()) {
106 p = P->Pln();
107 return Standard_True;
108 }
109 return Standard_False;
110}
111
112
113
114//=======================================================================
115//function : Lin
116//purpose :
117//=======================================================================
118
119Standard_Boolean DrawDim::Lin (const TopoDS_Edge& e,
120 gp_Lin& l,
121 Standard_Boolean& infinite,
122 Standard_Real& first,
123 Standard_Real& last)
124{
125 Standard_Real f1,l1;
126 Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(BRep_Tool::Curve(e,f1,l1));
127 if (!L.IsNull()) {
128 TopoDS_Vertex vf, vl;
129 TopExp::Vertices(TopoDS::Edge(e),vf,vl);
130 if (vf.IsNull() && vl.IsNull()) {
131 infinite = Standard_True;
132 l = L->Lin();
133 return Standard_True;
134 }
135 else if (vf.IsNull() || vl.IsNull()) {
136 Standard_DomainError::Raise("DrawDim::Lin : semi infinite edge");
137 }
138 else {
139 l = L->Lin();
140 infinite = Standard_True;
141 first = f1;
142 last = l1;
143 return Standard_True;
144 }
145 }
146 return Standard_False;
147}
148
149
150//=======================================================================
151//function : Lin
152//purpose :
153//=======================================================================
154
155Standard_Boolean DrawDim::Circ (const TopoDS_Edge& e,
156 gp_Circ& c,
157 Standard_Real& first,
158 Standard_Real& last)
159{
160 Standard_Real f1,l1;
161 Handle(Geom_Circle) C = Handle(Geom_Circle)::DownCast(BRep_Tool::Curve(e,f1,l1));
162 if (!C.IsNull()) {
163 c = C->Circ();
164 first = f1;
165 last = l1;
166 return Standard_True;
167 }
168 return Standard_False;
169}
170
171
172
173
174//=======================================================================
175//function : Nearest
176//purpose :
177//=======================================================================
178
179gp_Pnt DrawDim::Nearest(const TopoDS_Shape& ashape, const gp_Pnt& apoint)
180{
181 Standard_Real dist = RealLast();
182 Standard_Real curdist;
183 gp_Pnt result;
184 gp_Pnt curpnt;
185 TopExp_Explorer explo(ashape,TopAbs_VERTEX);
186 while (explo.More()) {
187 curpnt = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
188 curdist = apoint.Distance(curpnt);
189 if (curdist < dist) {
190 result = curpnt;
191 dist = curdist;
192 }
193 explo.Next();
194 }
195 return result;
196}