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