0023024: Update headers of OCCT files
[occt.git] / src / BOPTest / BOPTest_DrawableShape.cxx
CommitLineData
b311480e 1// Created on: 2000-05-25
2// Created by: Peter KURNEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOPTest_DrawableShape.ixx>
23
24#include <TopoDS.hxx>
25#include <TopoDS_Iterator.hxx>
26#include <TopoDS_Face.hxx>
27
28#include <TopExp_Explorer.hxx>
29
30
31#include <BRep_Tool.hxx>
32#include <BRepTools.hxx>
33#include <BRepAdaptor_Surface.hxx>
34#include <BRepAdaptor_Curve.hxx>
35#include <Geom_Surface.hxx>
36#include <Geom_TrimmedCurve.hxx>
37#include <Geom_RectangularTrimmedSurface.hxx>
38#include <Precision.hxx>
39#include <gp_Vec.hxx>
40#include <gp_Pnt.hxx>
41#include <Draw_Color.hxx>
42#include <Draw_Segment3D.hxx>
43#include <gp.hxx>
44#include <TopoDS_Shape.hxx>
45#include <DBRep_DrawableShape.hxx>
46#include <BRepAdaptor_Curve.hxx>
47#include <TopoDS.hxx>
48#include <gp_Pnt.hxx>
49#include <gp_Vec.hxx>
50#include <Draw_Circle3D.hxx>
51#include <gp_Ax1.hxx>
52#include <gp_Circ.hxx>
53#include <Draw_Color.hxx>
54#include <TopTools_IndexedMapOfShape.hxx>
55#include <TopExp.hxx>
56#include <TopoDS_Edge.hxx>
57#include <TopoDS.hxx>
58#include <TopoDS_Face.hxx>
59
60
61
62//=======================================================================
63//function : BOPTest_DrawableShape::BOPTest_DrawableShape
64//purpose :
65//=======================================================================
b311480e 66BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
7fd59977 67 const Draw_Color& FreeCol,
68 const Draw_Color& ConnCol,
69 const Draw_Color& EdgeCol,
70 const Draw_Color& IsosCol,
71 const Standard_Real size,
72 const Standard_Integer nbisos,
73 const Standard_Integer discret,
74 const Standard_CString Text,
75 const Draw_Color& TextColor)
76:
77 DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret)
78{
79 myText = new Draw_Text3D(Pnt(),Text,TextColor);
80 myTextColor = TextColor;
81}
82
83//=======================================================================
84//function : BOPTest_DrawableShape::BOPTest_DrawableShape
85//purpose :
86//=======================================================================
87 BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
88 const Standard_CString Text,
89 const Draw_Color& TextColor)
90: DBRep_DrawableShape(
91 aShape,
92 Draw_vert,
93 Draw_jaune,
94 Draw_rouge,
95 Draw_bleu,
96 100., //size
97 2, //nbIsos
98 30 //discret
99 )
100{
101 myText = new Draw_Text3D(Pnt(),Text,TextColor);
102 myTextColor = TextColor;
103}
104
105//=======================================================================
106//function : Pnt
107//purpose :
108//=======================================================================
109 gp_Pnt BOPTest_DrawableShape::Pnt() const
110{
111 gp_Pnt P(0,0,0);
112 Standard_Real u, v, u1, u2, v1, v2, p;
113 TopExp_Explorer ex;
114
115 TopoDS_Shape S = Shape();
116 TopAbs_ShapeEnum T = S.ShapeType();
117 Standard_Real facpar = 0.;
118
119 while ( T == TopAbs_COMPOUND ) {
120 TopoDS_Iterator ti(S);
121 if ( ti.More() ) {
122 S = ti.Value();
123 T = S.ShapeType();
124 }
125 else {
126 break;
127 }
128 }
129 // si S final = compound --> P = 0 0 0
130
131 switch (T)
132 {
133 case TopAbs_VERTEX :
134 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
135 break;
136
137 case TopAbs_EDGE :
138 {
139 BRepAdaptor_Curve CU(TopoDS::Edge(S));
140 u1 = CU.FirstParameter();
141 u2 = CU.LastParameter();
142 if (facpar == 0.) facpar = 0.20;
143 p = u1 + (u2-u1)*facpar;
144 P = CU.Value(p);
145 }
146 break;
147
148 case TopAbs_WIRE :
149 {
150 TopTools_IndexedMapOfShape aME;
151 TopExp::MapShapes(S, TopAbs_EDGE, aME);
152 const TopoDS_Edge& anEdge=TopoDS::Edge(aME(1));
153 BRepAdaptor_Curve CU(anEdge);
154 u1 = CU.FirstParameter();
155 u2 = CU.LastParameter();
156 if (facpar == 0.) facpar = 0.40;
157 p = u1 + (u2-u1)*facpar;
158 P = CU.Value(p);
159 }
160 break;
161
162 case TopAbs_FACE :
163 {
164 BRepAdaptor_Surface SU(TopoDS::Face(S));
165 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
166 //
167 facpar = .2;
168 u = u1 + (u2-u1)*facpar;
169 v = v1 + (v2-v1)*facpar;
170 P = SU.Value(u,v);
171 }
172 break;
173
174 case TopAbs_SHELL :
175 case TopAbs_SOLID :
176 {
177 TopTools_IndexedMapOfShape aMF;
178 TopExp::MapShapes(S, TopAbs_FACE, aMF);
179 const TopoDS_Face& aF=TopoDS::Face(aMF(1));
180
181 BRepAdaptor_Surface SU(TopoDS::Face(aF));
182 BRepTools::UVBounds(aF,u1,u2,v1,v2);
183 facpar = .4;
184 u = u1 + (u2-u1)*facpar;
185 v = v1 + (v2-v1)*facpar;
186 P = SU.Value(u,v);
187 }
188 break;
189
190 default:
191 break;
192 }
193 return P;
194}
195
196
197//=======================================================================
198//function : DrawOn
199//purpose :
200//=======================================================================
201 void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
202{
203 DBRep_DrawableShape::DrawOn(dis);
204 myText->SetPnt(Pnt());
205 myText->DrawOn(dis);
206}
207