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