1 // Created on: 1994-10-24
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepTools.hxx>
22 #include <Draw_Color.hxx>
23 #include <Draw_Display.hxx>
24 #include <Draw_Marker3D.hxx>
25 #include <Draw_Segment3D.hxx>
26 #include <Draw_Text3D.hxx>
27 #include <Geom_Curve.hxx>
28 #include <Geom_RectangularTrimmedSurface.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_TrimmedCurve.hxx>
34 #include <Precision.hxx>
35 #include <Standard_Type.hxx>
36 #include <TestTopOpeDraw_DrawableC3D.hxx>
37 #include <TestTopOpeDraw_DrawableP3D.hxx>
38 #include <TestTopOpeDraw_DrawableSHA.hxx>
39 #include <TestTopOpeDraw_DrawableSUR.hxx>
40 #include <TopExp_Explorer.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopoDS_Shape.hxx>
46 IMPLEMENT_STANDARD_RTTIEXT(TestTopOpeDraw_DrawableSHA,DBRep_DrawableShape)
48 Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation);
50 //=======================================================================
51 //function : TestTopOpeDraw_DrawableSHA
53 //=======================================================================
55 TestTopOpeDraw_DrawableSHA::TestTopOpeDraw_DrawableSHA
56 (const TopoDS_Shape& aShape,
57 const Draw_Color& FreeCol,
58 const Draw_Color& ConnCol,
59 const Draw_Color& EdgeCol,
60 const Draw_Color& IsosCol,
61 const Standard_Real size,
62 const Standard_Integer nbisos,
63 const Standard_Integer discret,
64 const Standard_CString Text,
65 const Draw_Color& TextColor,
66 const Standard_Boolean DisplayGeometry) :
67 DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret),
68 myTol(0.0), myPar(-1.0)
70 myDisplayGeometry = DisplayGeometry;
71 myText = new Draw_Text3D(Pnt(),Text,TextColor);
72 myTextColor = TextColor;
76 //=======================================================================
79 //=======================================================================
81 gp_Pnt TestTopOpeDraw_DrawableSHA::Pnt() const
84 Standard_Real u1,u2,v1,v2;
87 TopoDS_Shape S = Shape();
88 TopAbs_ShapeEnum T = S.ShapeType();
89 Standard_Real facpar = 0.;
91 while ( T == TopAbs_COMPOUND ) {
92 TopoDS_Iterator ti(S);
94 S = ti.Value(); T = S.ShapeType();
100 // si S final = compound --> P = 0 0 0
105 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
110 ex.Init(S,T); S = ex.Current();
112 // no break, in order to execute EDGE case
116 BRepAdaptor_Curve CU(TopoDS::Edge(S));
117 u1 = CU.FirstParameter(); u2 = CU.LastParameter();
118 if (facpar == 0.) facpar = 0.20;
119 if (myPar != -1.0) facpar = myPar;
120 Standard_Real p = u1 + (u2-u1)*facpar;
125 case TopAbs_SHELL : case TopAbs_SOLID : case TopAbs_COMPSOLID :
127 ex.Init(S,T); S = ex.Current();
129 // no break, in order to execute FACE case
133 BRepAdaptor_Surface SU(TopoDS::Face(S));
134 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
135 if (facpar == 0.) facpar = 0.20;
136 Standard_Real u = u1 + (u2-u1)*facpar;
137 Standard_Real v = v1 + (v2-v1)*facpar;
148 //=======================================================================
149 //function : SetDisplayGeometry
151 //=======================================================================
153 void TestTopOpeDraw_DrawableSHA::SetDisplayGeometry(const Standard_Boolean b)
155 myDisplayGeometry = b;
158 //=======================================================================
161 //=======================================================================
163 void TestTopOpeDraw_DrawableSHA::SetTol(const Standard_Real t)
167 myDM3d = new Draw_Marker3D(Pnt(), Draw_CircleZoom , Draw_rouge, myTol);
171 //=======================================================================
174 //=======================================================================
176 void TestTopOpeDraw_DrawableSHA::SetPar(const Standard_Real t)
179 myText->SetPnt(Pnt());
183 //=======================================================================
186 //=======================================================================
188 void TestTopOpeDraw_DrawableSHA::DrawOn(Draw_Display& dis) const
191 DBRep_DrawableShape::DrawOn(dis);
195 if (myDisplayGeometry) DisplayGeometry(dis);
198 //=======================================================================
199 //function : DisplayGeometry
201 //=======================================================================
203 void TestTopOpeDraw_DrawableSHA::DisplayGeometry(Draw_Display& dis) const
205 const TopoDS_Shape& aShape = Shape();
206 const TopAbs_ShapeEnum t = aShape.ShapeType();
208 if ( t == TopAbs_FACE ) {
209 const TopoDS_Face& F = TopoDS::Face(aShape);
211 Handle(Geom_Surface) GS = BRep_Tool::Surface(F,loc);
212 if ( GS.IsNull() ) return;
213 Standard_Real u1,u2,v1,v2; BRepTools::UVBounds(F,u1,u2,v1,v2);
214 GS = Handle(Geom_Surface)::DownCast(GS->Transformed(loc.Transformation()));
215 Handle(Geom_RectangularTrimmedSurface) GRTS;
216 GRTS = new Geom_RectangularTrimmedSurface(GS,u1,u2,v1,v2);
217 Handle(TestTopOpeDraw_DrawableSUR) D;
218 D = new TestTopOpeDraw_DrawableSUR(GRTS,Draw_bleu);
219 Draw_Color norcol = DBRep_ColorOrientation(aShape.Orientation());
220 D->NormalColor(norcol);
224 else if ( t == TopAbs_EDGE ) {
225 const TopoDS_Edge& E = TopoDS::Edge(aShape);
226 TopLoc_Location loc; Standard_Real f,l;
227 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,loc,f,l);
228 if ( GC.IsNull() ) return;
229 GC = Handle(Geom_Curve)::DownCast(GC->Transformed(loc.Transformation()));
230 Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l);
231 Handle(TestTopOpeDraw_DrawableC3D) D;
232 D = new TestTopOpeDraw_DrawableC3D(GTC,myTextColor);
236 else if ( t == TopAbs_VERTEX ) {
237 const TopoDS_Vertex& V = TopoDS::Vertex(aShape);
238 gp_Pnt P = BRep_Tool::Pnt(V);
239 Handle(TestTopOpeDraw_DrawableP3D) D;
240 D = new TestTopOpeDraw_DrawableP3D(P,myTextColor);