0024428: Implementation of LGPL license
[occt.git] / src / BOPTest / BOPTest_DrawableShape.cxx
CommitLineData
b311480e 1// Created on: 2000-05-25
2// Created by: Peter KURNEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16#include <BOPTest_DrawableShape.ixx>
4e57c75e 17#include <stdio.h>
7fd59977 18
19#include <TopoDS.hxx>
20#include <TopoDS_Iterator.hxx>
21#include <TopoDS_Face.hxx>
22
23#include <TopExp_Explorer.hxx>
24
25
26#include <BRep_Tool.hxx>
27#include <BRepTools.hxx>
28#include <BRepAdaptor_Surface.hxx>
29#include <BRepAdaptor_Curve.hxx>
30#include <Geom_Surface.hxx>
31#include <Geom_TrimmedCurve.hxx>
32#include <Geom_RectangularTrimmedSurface.hxx>
33#include <Precision.hxx>
34#include <gp_Vec.hxx>
35#include <gp_Pnt.hxx>
36#include <Draw_Color.hxx>
37#include <Draw_Segment3D.hxx>
38#include <gp.hxx>
39#include <TopoDS_Shape.hxx>
40#include <DBRep_DrawableShape.hxx>
41#include <BRepAdaptor_Curve.hxx>
42#include <TopoDS.hxx>
43#include <gp_Pnt.hxx>
44#include <gp_Vec.hxx>
45#include <Draw_Circle3D.hxx>
46#include <gp_Ax1.hxx>
47#include <gp_Circ.hxx>
48#include <Draw_Color.hxx>
49#include <TopTools_IndexedMapOfShape.hxx>
50#include <TopExp.hxx>
51#include <TopoDS_Edge.hxx>
52#include <TopoDS.hxx>
53#include <TopoDS_Face.hxx>
54
7fd59977 55//=======================================================================
4e57c75e 56//function :
7fd59977 57//purpose :
58//=======================================================================
b311480e 59BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
7fd59977 60 const Draw_Color& FreeCol,
61 const Draw_Color& ConnCol,
62 const Draw_Color& EdgeCol,
63 const Draw_Color& IsosCol,
64 const Standard_Real size,
65 const Standard_Integer nbisos,
66 const Standard_Integer discret,
67 const Standard_CString Text,
68 const Draw_Color& TextColor)
69:
70 DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret)
71{
72 myText = new Draw_Text3D(Pnt(),Text,TextColor);
73 myTextColor = TextColor;
74}
75
76//=======================================================================
4e57c75e 77//function :
7fd59977 78//purpose :
79//=======================================================================
80 BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
81 const Standard_CString Text,
82 const Draw_Color& TextColor)
83: DBRep_DrawableShape(
84 aShape,
85 Draw_vert,
86 Draw_jaune,
87 Draw_rouge,
88 Draw_bleu,
89 100., //size
90 2, //nbIsos
91 30 //discret
92 )
93{
94 myText = new Draw_Text3D(Pnt(),Text,TextColor);
95 myTextColor = TextColor;
96}
97
98//=======================================================================
99//function : Pnt
100//purpose :
101//=======================================================================
102 gp_Pnt BOPTest_DrawableShape::Pnt() const
103{
104 gp_Pnt P(0,0,0);
105 Standard_Real u, v, u1, u2, v1, v2, p;
106 TopExp_Explorer ex;
107
108 TopoDS_Shape S = Shape();
109 TopAbs_ShapeEnum T = S.ShapeType();
110 Standard_Real facpar = 0.;
111
112 while ( T == TopAbs_COMPOUND ) {
113 TopoDS_Iterator ti(S);
114 if ( ti.More() ) {
115 S = ti.Value();
116 T = S.ShapeType();
117 }
118 else {
119 break;
120 }
121 }
122 // si S final = compound --> P = 0 0 0
123
124 switch (T)
125 {
126 case TopAbs_VERTEX :
127 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
128 break;
129
130 case TopAbs_EDGE :
131 {
132 BRepAdaptor_Curve CU(TopoDS::Edge(S));
133 u1 = CU.FirstParameter();
134 u2 = CU.LastParameter();
135 if (facpar == 0.) facpar = 0.20;
136 p = u1 + (u2-u1)*facpar;
137 P = CU.Value(p);
138 }
139 break;
140
141 case TopAbs_WIRE :
142 {
143 TopTools_IndexedMapOfShape aME;
144 TopExp::MapShapes(S, TopAbs_EDGE, aME);
145 const TopoDS_Edge& anEdge=TopoDS::Edge(aME(1));
146 BRepAdaptor_Curve CU(anEdge);
147 u1 = CU.FirstParameter();
148 u2 = CU.LastParameter();
149 if (facpar == 0.) facpar = 0.40;
150 p = u1 + (u2-u1)*facpar;
151 P = CU.Value(p);
152 }
153 break;
154
155 case TopAbs_FACE :
156 {
157 BRepAdaptor_Surface SU(TopoDS::Face(S));
158 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
159 //
160 facpar = .2;
161 u = u1 + (u2-u1)*facpar;
162 v = v1 + (v2-v1)*facpar;
163 P = SU.Value(u,v);
164 }
165 break;
166
167 case TopAbs_SHELL :
168 case TopAbs_SOLID :
169 {
170 TopTools_IndexedMapOfShape aMF;
171 TopExp::MapShapes(S, TopAbs_FACE, aMF);
172 const TopoDS_Face& aF=TopoDS::Face(aMF(1));
173
174 BRepAdaptor_Surface SU(TopoDS::Face(aF));
175 BRepTools::UVBounds(aF,u1,u2,v1,v2);
176 facpar = .4;
177 u = u1 + (u2-u1)*facpar;
178 v = v1 + (v2-v1)*facpar;
179 P = SU.Value(u,v);
180 }
181 break;
182
183 default:
184 break;
185 }
186 return P;
187}
188
189
190//=======================================================================
191//function : DrawOn
192//purpose :
193//=======================================================================
194 void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
195{
196 DBRep_DrawableShape::DrawOn(dis);
197 myText->SetPnt(Pnt());
198 myText->DrawOn(dis);
199}
200