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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Tool.hxx>
20 #include <Draw_Appli.hxx>
21 #include <Draw_Text3D.hxx>
22 #include <DrawDim.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_Plane.hxx>
28 #include <gp_Circ.hxx>
32 #include <TCollection_AsciiString.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Vertex.hxx>
43 Standard_IMPORT Draw_Viewer dout;
46 //=======================================================================
47 //function : AllCommands
49 //=======================================================================
51 void DrawDim::AllCommands (Draw_Interpretor& theCommands)
53 PlanarDimensionCommands (theCommands);
57 //=======================================================================
58 //function : DrawShapeName
60 //=======================================================================
62 void DrawDim::DrawShapeName (const TopoDS_Shape& ashape,
63 const Standard_CString aname)
66 TCollection_AsciiString t (" ");
67 switch (ashape.ShapeType()) {
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))) {
74 position = ElCLib::Value(parameter,Handle(Geom_Line)::DownCast(curve)->Lin());
76 else if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
78 if (f > l) parameter = parameter + M_PI;
79 position = ElCLib::Value(parameter,Handle(Geom_Circle)::DownCast(curve)->Circ());
85 position = BRep_Tool::Pnt(TopoDS::Vertex(ashape));
92 Handle(Draw_Text3D) text = new Draw_Text3D (position,t.ToCString(),Draw_blanc);
97 //=======================================================================
100 //=======================================================================
102 Standard_Boolean DrawDim::Pln (const TopoDS_Face& f, gp_Pln& p)
104 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(f));
107 return Standard_True;
109 return Standard_False;
114 //=======================================================================
117 //=======================================================================
119 Standard_Boolean DrawDim::Lin (const TopoDS_Edge& e,
121 Standard_Boolean& infinite,
122 Standard_Real& first,
126 Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(BRep_Tool::Curve(e,f1,l1));
128 TopoDS_Vertex vf, vl;
129 TopExp::Vertices(TopoDS::Edge(e),vf,vl);
130 if (vf.IsNull() && vl.IsNull()) {
131 infinite = Standard_True;
133 return Standard_True;
135 else if (vf.IsNull() || vl.IsNull()) {
136 Standard_DomainError::Raise("DrawDim::Lin : semi infinite edge");
140 infinite = Standard_True;
143 return Standard_True;
146 return Standard_False;
150 //=======================================================================
153 //=======================================================================
155 Standard_Boolean DrawDim::Circ (const TopoDS_Edge& e,
157 Standard_Real& first,
161 Handle(Geom_Circle) C = Handle(Geom_Circle)::DownCast(BRep_Tool::Curve(e,f1,l1));
166 return Standard_True;
168 return Standard_False;
174 //=======================================================================
177 //=======================================================================
179 gp_Pnt DrawDim::Nearest(const TopoDS_Shape& ashape, const gp_Pnt& apoint)
181 Standard_Real dist = RealLast();
182 Standard_Real curdist;
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) {