0026619: Tolerances of operands are modified using bop
[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>
92efcf78 48IMPLEMENT_STANDARD_RTTIEXT(BOPTest_DrawableShape,DBRep_DrawableShape)
49
7fd59977 50//=======================================================================
4e57c75e 51//function :
7fd59977 52//purpose :
53//=======================================================================
43cb0011 54BOPTest_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)
7fd59977 65:
43cb0011 66 DBRep_DrawableShape(aShape,FreeCol,ConnCol,
67 EdgeCol,IsosCol,size,nbisos,discret)
7fd59977 68{
69 myText = new Draw_Text3D(Pnt(),Text,TextColor);
70 myTextColor = TextColor;
71}
7fd59977 72//=======================================================================
4e57c75e 73//function :
7fd59977 74//purpose :
75//=======================================================================
43cb0011 76BOPTest_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
7fd59977 88{
89 myText = new Draw_Text3D(Pnt(),Text,TextColor);
90 myTextColor = TextColor;
91}
92
93//=======================================================================
94//function : Pnt
95//purpose :
96//=======================================================================
43cb0011 97gp_Pnt BOPTest_DrawableShape::Pnt() const
7fd59977 98{
99 gp_Pnt P(0,0,0);
100 Standard_Real u, v, u1, u2, v1, v2, p;
101 TopExp_Explorer ex;
43cb0011 102
7fd59977 103 TopoDS_Shape S = Shape();
104 TopAbs_ShapeEnum T = S.ShapeType();
105 Standard_Real facpar = 0.;
43cb0011 106
7fd59977 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
43cb0011 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 }
7fd59977 176 return P;
177}
7fd59977 178//=======================================================================
179//function : DrawOn
180//purpose :
181//=======================================================================
43cb0011 182void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
7fd59977 183{
184 DBRep_DrawableShape::DrawOn(dis);
185 myText->SetPnt(Pnt());
186 myText->DrawOn(dis);
187}
188