summaryrefslogtreecommitdiff
path: root/src/BOPTest/BOPTest_DrawableShape.cxx
blob: b3d9d9a88f8ec605f622bb44d6bfdd0c2ca3dcc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// File:	BOPTest_DrawableShape.cxx
// Created:	Thu May 25 14:58:58 2000
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOPTest_DrawableShape.ixx>

#include <TopoDS.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Face.hxx>

#include <TopExp_Explorer.hxx>


#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <Geom_Surface.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Precision.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <Draw_Color.hxx>
#include <Draw_Segment3D.hxx>
#include <gp.hxx>
#include <TopoDS_Shape.hxx>
#include <DBRep_DrawableShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopoDS.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <Draw_Circle3D.hxx>
#include <gp_Ax1.hxx>
#include <gp_Circ.hxx>
#include <Draw_Color.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>



//=======================================================================
//function : BOPTest_DrawableShape::BOPTest_DrawableShape
//purpose  : 
//=======================================================================
  BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
						const Draw_Color& FreeCol,
						const Draw_Color& ConnCol,
						const Draw_Color& EdgeCol,
						const Draw_Color& IsosCol,
						const Standard_Real size,
						const Standard_Integer nbisos,
						const Standard_Integer discret,
						const Standard_CString Text,
						const Draw_Color& TextColor) 
:
  DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret)
{
  myText = new Draw_Text3D(Pnt(),Text,TextColor);
  myTextColor = TextColor;
}

//=======================================================================
//function : BOPTest_DrawableShape::BOPTest_DrawableShape
//purpose  : 
//=======================================================================
  BOPTest_DrawableShape::BOPTest_DrawableShape (const TopoDS_Shape& aShape,
						const Standard_CString Text,
						const Draw_Color& TextColor) 
:  DBRep_DrawableShape(
		       aShape,
		       Draw_vert,
		       Draw_jaune,
		       Draw_rouge,
		       Draw_bleu,
		       100., //size
		       2,    //nbIsos
		       30    //discret
		       )
{
  myText = new Draw_Text3D(Pnt(),Text,TextColor);
  myTextColor = TextColor;
}

//=======================================================================
//function : Pnt
//purpose  : 
//=======================================================================
  gp_Pnt BOPTest_DrawableShape::Pnt() const
{
  gp_Pnt P(0,0,0);
  Standard_Real u, v, u1, u2, v1, v2, p;
  TopExp_Explorer ex;

  TopoDS_Shape S = Shape();
  TopAbs_ShapeEnum T = S.ShapeType();
  Standard_Real facpar = 0.;

  while ( T == TopAbs_COMPOUND ) {
    TopoDS_Iterator ti(S);
    if ( ti.More() ) {
      S = ti.Value(); 
      T = S.ShapeType();
    }
    else {
      break;
    }
  }
  // si S final = compound --> P = 0 0 0 

  switch (T) 
    {
    case TopAbs_VERTEX : 
      P = BRep_Tool::Pnt(TopoDS::Vertex(S)); 
      break;

    case TopAbs_EDGE : 
      {
	BRepAdaptor_Curve CU(TopoDS::Edge(S));
	u1 = CU.FirstParameter(); 
	u2 = CU.LastParameter();
	if (facpar == 0.) facpar = 0.20;
	p = u1 + (u2-u1)*facpar;
	P = CU.Value(p);
      }
      break;

    case TopAbs_WIRE :
      {
	TopTools_IndexedMapOfShape aME;
	TopExp::MapShapes(S, TopAbs_EDGE, aME);
	const TopoDS_Edge& anEdge=TopoDS::Edge(aME(1));
	BRepAdaptor_Curve CU(anEdge);
	u1 = CU.FirstParameter(); 
	u2 = CU.LastParameter();
	if (facpar == 0.) facpar = 0.40;
	p = u1 + (u2-u1)*facpar;
	P = CU.Value(p);
      }
      break;

    case TopAbs_FACE : 
      {
	BRepAdaptor_Surface SU(TopoDS::Face(S));
	BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
	//
	facpar = .2;
	u = u1 + (u2-u1)*facpar;
	v = v1 + (v2-v1)*facpar;
	P = SU.Value(u,v);
      }
      break;

     case TopAbs_SHELL : 
     case TopAbs_SOLID : 
      {
	TopTools_IndexedMapOfShape aMF;
	TopExp::MapShapes(S, TopAbs_FACE, aMF);
	const TopoDS_Face& aF=TopoDS::Face(aMF(1));
	
	BRepAdaptor_Surface SU(TopoDS::Face(aF));
	BRepTools::UVBounds(aF,u1,u2,v1,v2);
	facpar = .4;
	u = u1 + (u2-u1)*facpar;
	v = v1 + (v2-v1)*facpar;
	P = SU.Value(u,v);
      }
      break; 

    default: 
      break;
    }
  return P;
}


//=======================================================================
//function : DrawOn
//purpose  : 
//=======================================================================
  void BOPTest_DrawableShape::DrawOn(Draw_Display& dis) const
{
  DBRep_DrawableShape::DrawOn(dis);
  myText->SetPnt(Pnt());
  myText->DrawOn(dis);
}