0024023: Revamp the OCCT Handle -- ambiguity
[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//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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//=======================================================================
43cb0011 59BOPTest_DrawableShape::BOPTest_DrawableShape
60 (const TopoDS_Shape& aShape,
61 const Draw_Color& FreeCol,
62 const Draw_Color& ConnCol,
63 const Draw_Color& EdgeCol,
64 const Draw_Color& IsosCol,
65 const Standard_Real size,
66 const Standard_Integer nbisos,
67 const Standard_Integer discret,
68 const Standard_CString Text,
69 const Draw_Color& TextColor)
7fd59977 70:
43cb0011 71 DBRep_DrawableShape(aShape,FreeCol,ConnCol,
72 EdgeCol,IsosCol,size,nbisos,discret)
7fd59977 73{
74 myText = new Draw_Text3D(Pnt(),Text,TextColor);
75 myTextColor = TextColor;
76}
7fd59977 77//=======================================================================
4e57c75e 78//function :
7fd59977 79//purpose :
80//=======================================================================
43cb0011 81BOPTest_DrawableShape::BOPTest_DrawableShape
82 (const TopoDS_Shape& aShape,
83 const Standard_CString Text,
84 const Draw_Color& TextColor)
85: DBRep_DrawableShape(aShape,
86 Draw_vert,
87 Draw_jaune,
88 Draw_rouge,
89 Draw_bleu,
90 100., //size
91 2, //nbIsos
92 30) //discret
7fd59977 93{
94 myText = new Draw_Text3D(Pnt(),Text,TextColor);
95 myTextColor = TextColor;
96}
97
98//=======================================================================
99//function : Pnt
100//purpose :
101//=======================================================================
43cb0011 102gp_Pnt BOPTest_DrawableShape::Pnt() const
7fd59977 103{
104 gp_Pnt P(0,0,0);
105 Standard_Real u, v, u1, u2, v1, v2, p;
106 TopExp_Explorer ex;
43cb0011 107
7fd59977 108 TopoDS_Shape S = Shape();
109 TopAbs_ShapeEnum T = S.ShapeType();
110 Standard_Real facpar = 0.;
43cb0011 111
7fd59977 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
43cb0011 124 switch (T) {
125 case TopAbs_VERTEX :
126 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
127 break;
128
129 case TopAbs_EDGE : {
130 BRepAdaptor_Curve CU(TopoDS::Edge(S));
131 u1 = CU.FirstParameter();
132 u2 = CU.LastParameter();
133 if (facpar == 0.) facpar = 0.20;
134 p = u1 + (u2-u1)*facpar;
135 P = CU.Value(p);
136 }
137 break;
138
139 case TopAbs_WIRE : {
140 TopTools_IndexedMapOfShape aME;
141 TopExp::MapShapes(S, TopAbs_EDGE, aME);
142 const TopoDS_Edge& anEdge=TopoDS::Edge(aME(1));
143 BRepAdaptor_Curve CU(anEdge);
144 u1 = CU.FirstParameter();
145 u2 = CU.LastParameter();
146 if (facpar == 0.) facpar = 0.40;
147 p = u1 + (u2-u1)*facpar;
148 P = CU.Value(p);
149 }
150 break;
151
152 case TopAbs_FACE : {
153 BRepAdaptor_Surface SU(TopoDS::Face(S));
154 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
155 //
156 facpar = .2;
157 u = u1 + (u2-u1)*facpar;
158 v = v1 + (v2-v1)*facpar;
159 P = SU.Value(u,v);
160 }
161 break;
162
163 case TopAbs_SHELL :
164 case TopAbs_SOLID : {
165 TopTools_IndexedMapOfShape aMF;
166 TopExp::MapShapes(S, TopAbs_FACE, aMF);
167 const TopoDS_Face& aF=TopoDS::Face(aMF(1));
168
169 BRepAdaptor_Surface SU(TopoDS::Face(aF));
170 BRepTools::UVBounds(aF,u1,u2,v1,v2);
171 facpar = .4;
172 u = u1 + (u2-u1)*facpar;
173 v = v1 + (v2-v1)*facpar;
174 P = SU.Value(u,v);
175 }
176 break;
177
178 default:
179 break;
180 }
7fd59977 181 return P;
182}
7fd59977 183//=======================================================================
184//function : DrawOn
185//purpose :
186//=======================================================================
43cb0011 187void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
7fd59977 188{
189 DBRep_DrawableShape::DrawOn(dis);
190 myText->SetPnt(Pnt());
191 myText->DrawOn(dis);
192}
193