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>
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>
27 #include <Standard_Type.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_PlanarDistance,DrawDim_PlanarDimension)
36 //=======================================================================
39 //=======================================================================
40 void DrawDim_PlanarDistance::Draw
41 (const gp_Pnt& point, const TopoDS_Edge& edge, Draw_Display& dis) const
44 Handle(Geom_Curve) line = BRep_Tool::Curve(edge,f,l);
45 GeomAPI_ProjectPointOnCurve pj (point, line);
46 if (pj.NbPoints() == 1) {
48 gp_Pnt last = pj.Point(1);
49 dis.Draw (first,last);
51 gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2);
56 //=======================================================================
57 //function : DrawDim_PlanarDistance
59 //=======================================================================
61 DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Face& face,
62 const TopoDS_Shape& geom1,
63 const TopoDS_Shape& geom2)
65 myPlane = face; myGeom1 = geom1; myGeom2 = geom2;
68 //=======================================================================
69 //function : DrawDim_PlanarDistance
71 //=======================================================================
73 DrawDim_PlanarDistance::DrawDim_PlanarDistance (const TopoDS_Shape& geom1,
74 const TopoDS_Shape& geom2)
76 myGeom1 = geom1; myGeom2 = geom2;
79 //=======================================================================
82 //=======================================================================
84 void DrawDim_PlanarDistance::DrawOn(Draw_Display& dis) const
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);
91 gp_Pnt p ((first.X()+ last.X())/2,(first.Y()+ last.Y())/2,(first.Z()+ last.Z())/2);
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);
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);
108 else if (myGeom1.ShapeType() == TopAbs_EDGE && myGeom2.ShapeType() == TopAbs_EDGE) {
110 Handle(Geom_Curve) C = BRep_Tool::Curve (TopoDS::Edge(myGeom1),f,l);
112 Handle(Geom_Line) L = Handle(Geom_Line)::DownCast(C);
114 gp_Pnt point = L->Lin().Location();
115 TopoDS_Edge edge = TopoDS::Edge(myGeom2);
116 Draw (point,edge,dis);
122 std::cout << " DrawDim_PlanarDistance::DrawOn : dimension error" << std::endl;