0021762: Integration of new Boolean Operation algorithm to OCCT.
[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
7fd59977 21#include <BOPTest_DrawableShape.ixx>
4e57c75e 22#include <stdio.h>
7fd59977 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
7fd59977 60//=======================================================================
4e57c75e 61//function :
7fd59977 62//purpose :
63//=======================================================================
b311480e 64BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
7fd59977 65 const Draw_Color& FreeCol,
66 const Draw_Color& ConnCol,
67 const Draw_Color& EdgeCol,
68 const Draw_Color& IsosCol,
69 const Standard_Real size,
70 const Standard_Integer nbisos,
71 const Standard_Integer discret,
72 const Standard_CString Text,
73 const Draw_Color& TextColor)
74:
75 DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret)
76{
77 myText = new Draw_Text3D(Pnt(),Text,TextColor);
78 myTextColor = TextColor;
79}
80
81//=======================================================================
4e57c75e 82//function :
7fd59977 83//purpose :
84//=======================================================================
85 BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
86 const Standard_CString Text,
87 const Draw_Color& TextColor)
88: DBRep_DrawableShape(
89 aShape,
90 Draw_vert,
91 Draw_jaune,
92 Draw_rouge,
93 Draw_bleu,
94 100., //size
95 2, //nbIsos
96 30 //discret
97 )
98{
99 myText = new Draw_Text3D(Pnt(),Text,TextColor);
100 myTextColor = TextColor;
101}
102
103//=======================================================================
104//function : Pnt
105//purpose :
106//=======================================================================
107 gp_Pnt BOPTest_DrawableShape::Pnt() const
108{
109 gp_Pnt P(0,0,0);
110 Standard_Real u, v, u1, u2, v1, v2, p;
111 TopExp_Explorer ex;
112
113 TopoDS_Shape S = Shape();
114 TopAbs_ShapeEnum T = S.ShapeType();
115 Standard_Real facpar = 0.;
116
117 while ( T == TopAbs_COMPOUND ) {
118 TopoDS_Iterator ti(S);
119 if ( ti.More() ) {
120 S = ti.Value();
121 T = S.ShapeType();
122 }
123 else {
124 break;
125 }
126 }
127 // si S final = compound --> P = 0 0 0
128
129 switch (T)
130 {
131 case TopAbs_VERTEX :
132 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
133 break;
134
135 case TopAbs_EDGE :
136 {
137 BRepAdaptor_Curve CU(TopoDS::Edge(S));
138 u1 = CU.FirstParameter();
139 u2 = CU.LastParameter();
140 if (facpar == 0.) facpar = 0.20;
141 p = u1 + (u2-u1)*facpar;
142 P = CU.Value(p);
143 }
144 break;
145
146 case TopAbs_WIRE :
147 {
148 TopTools_IndexedMapOfShape aME;
149 TopExp::MapShapes(S, TopAbs_EDGE, aME);
150 const TopoDS_Edge& anEdge=TopoDS::Edge(aME(1));
151 BRepAdaptor_Curve CU(anEdge);
152 u1 = CU.FirstParameter();
153 u2 = CU.LastParameter();
154 if (facpar == 0.) facpar = 0.40;
155 p = u1 + (u2-u1)*facpar;
156 P = CU.Value(p);
157 }
158 break;
159
160 case TopAbs_FACE :
161 {
162 BRepAdaptor_Surface SU(TopoDS::Face(S));
163 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
164 //
165 facpar = .2;
166 u = u1 + (u2-u1)*facpar;
167 v = v1 + (v2-v1)*facpar;
168 P = SU.Value(u,v);
169 }
170 break;
171
172 case TopAbs_SHELL :
173 case TopAbs_SOLID :
174 {
175 TopTools_IndexedMapOfShape aMF;
176 TopExp::MapShapes(S, TopAbs_FACE, aMF);
177 const TopoDS_Face& aF=TopoDS::Face(aMF(1));
178
179 BRepAdaptor_Surface SU(TopoDS::Face(aF));
180 BRepTools::UVBounds(aF,u1,u2,v1,v2);
181 facpar = .4;
182 u = u1 + (u2-u1)*facpar;
183 v = v1 + (v2-v1)*facpar;
184 P = SU.Value(u,v);
185 }
186 break;
187
188 default:
189 break;
190 }
191 return P;
192}
193
194
195//=======================================================================
196//function : DrawOn
197//purpose :
198//=======================================================================
199 void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
200{
201 DBRep_DrawableShape::DrawOn(dis);
202 myText->SetPnt(Pnt());
203 myText->DrawOn(dis);
204}
205