0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / DrawDim / DrawDim_Distance.cxx
CommitLineData
b311480e 1// Created on: 1997-04-21
2// Created by: Denis PASCAL
3// Copyright (c) 1997-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
42cf5bc1 17
18#include <BRep_Tool.hxx>
7fd59977 19#include <BRepAdaptor_Surface.hxx>
42cf5bc1 20#include <Draw_Display.hxx>
21#include <DrawDim.hxx>
22#include <DrawDim_Distance.hxx>
7fd59977 23#include <gp_Ax1.hxx>
24#include <gp_Ax2.hxx>
25#include <gp_Dir.hxx>
42cf5bc1 26#include <gp_Pln.hxx>
7fd59977 27#include <gp_Vec.hxx>
7fd59977 28#include <Precision.hxx>
42cf5bc1 29#include <Standard_Type.hxx>
7fd59977 30#include <TCollection_AsciiString.hxx>
42cf5bc1 31#include <TopExp_Explorer.hxx>
32#include <TopoDS.hxx>
33#include <TopoDS_Face.hxx>
34#include <TopoDS_Shape.hxx>
35#include <TopoDS_Vertex.hxx>
7fd59977 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(DrawDim_Distance,DrawDim_Dimension)
38
7fd59977 39//=======================================================================
40//function : DrawDim_Distance
41//purpose :
42//=======================================================================
7fd59977 43DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1,
44 const TopoDS_Face& plane2)
45{
46 myPlane1 = plane1;
47 myPlane2 = plane2;
48}
49
50
51//=======================================================================
52//function : DrawDim_Distance
53//purpose :
54//=======================================================================
55
56DrawDim_Distance::DrawDim_Distance (const TopoDS_Face& plane1)
57
58{
59 myPlane1 = plane1;
60}
61
62//=======================================================================
63//function : Plane1
64//purpose :
65//=======================================================================
66
67const TopoDS_Face& DrawDim_Distance::Plane1() const
68{
69 return myPlane1;
70}
71
72//=======================================================================
73//function : Plane1
74//purpose :
75//=======================================================================
76
77 void DrawDim_Distance::Plane1(const TopoDS_Face& face)
78{
79 myPlane1 = face;
80}
81
82//=======================================================================
83//function : Plane2
84//purpose :
85//=======================================================================
86
87const TopoDS_Face& DrawDim_Distance::Plane2() const
88{
89 return myPlane2;
90}
91
92//=======================================================================
93//function : Plane2
94//purpose :
95//=======================================================================
96
97void DrawDim_Distance::Plane2(const TopoDS_Face& face)
98{
99 myPlane2 = face;
100}
101
102
103//=======================================================================
104//function : DrawOn
105//purpose :
106//=======================================================================
107
108void DrawDim_Distance::DrawOn(Draw_Display& dis) const
109{
110
111 // compute the points and the direction
112 BRepAdaptor_Surface surf1(myPlane1);
113
114 // today we process only planar faces
115 if (surf1.GetType() != GeomAbs_Plane)
116 return;
9b372aa8 117
118 gp_Ax1 anAx1 = surf1.Plane().Axis();
7fd59977 119 gp_Vec V = anAx1.Direction();
120
121 // output
122 gp_Pnt FAttach; // first attach point
123 gp_Pnt SAttach; // second attach point
124
125 // first point, try a vertex
126 TopExp_Explorer explo(myPlane1,TopAbs_VERTEX);
127 if (explo.More()) {
128 FAttach = BRep_Tool::Pnt(TopoDS::Vertex(explo.Current()));
129 }
130 else {
131 // no vertex, use the origin
132 FAttach = anAx1.Location();
133 }
134
135
136 if (!myPlane2.IsNull()) {
137 // translate the point until the second face
138 BRepAdaptor_Surface surf2(myPlane2);
139 surf2.D0(0,0,SAttach);
140 Standard_Real r = V.Dot(gp_Vec(FAttach,SAttach));
141 V *= r;
142 }
143
144 SAttach = FAttach;
145 SAttach.Translate(V);
146
147 // DISPLAY
148 dis.Draw (FAttach,SAttach);
149 V *= 0.5;
150 FAttach.Translate(V);
151 dis.DrawMarker(FAttach, Draw_Losange);
152 DrawText(FAttach,dis);
153}