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.
17 #include <TestTopOpeDraw_DrawableSHA.ixx>
18 #include <TestTopOpeDraw_DrawableSUR.hxx>
19 #include <TestTopOpeDraw_DrawableC3D.hxx>
20 #include <TestTopOpeDraw_DrawableP3D.hxx>
23 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepTools.hxx>
28 #include <BRepAdaptor_Surface.hxx>
29 #include <BRepAdaptor_Curve.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <Geom_RectangularTrimmedSurface.hxx>
33 #include <Precision.hxx>
36 #include <Draw_Color.hxx>
37 #include <Draw_Segment3D.hxx>
39 #include <Geom_Curve.hxx>
41 Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation);
43 //=======================================================================
44 //function : TestTopOpeDraw_DrawableSHA
46 //=======================================================================
48 TestTopOpeDraw_DrawableSHA::TestTopOpeDraw_DrawableSHA
49 (const TopoDS_Shape& aShape,
50 const Draw_Color& FreeCol,
51 const Draw_Color& ConnCol,
52 const Draw_Color& EdgeCol,
53 const Draw_Color& IsosCol,
54 const Standard_Real size,
55 const Standard_Integer nbisos,
56 const Standard_Integer discret,
57 const Standard_CString Text,
58 const Draw_Color& TextColor,
59 const Standard_Boolean DisplayGeometry) :
60 DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret),
61 myTol(0.0), myPar(-1.0)
63 myDisplayGeometry = DisplayGeometry;
64 myText = new Draw_Text3D(Pnt(),Text,TextColor);
65 myTextColor = TextColor;
69 //=======================================================================
72 //=======================================================================
74 gp_Pnt TestTopOpeDraw_DrawableSHA::Pnt() const
77 Standard_Real u1,u2,v1,v2;
80 TopoDS_Shape S = Shape();
81 TopAbs_ShapeEnum T = S.ShapeType();
82 Standard_Real facpar = 0.;
84 while ( T == TopAbs_COMPOUND ) {
85 TopoDS_Iterator ti(S);
87 S = ti.Value(); T = S.ShapeType();
93 // si S final = compound --> P = 0 0 0
98 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
103 ex.Init(S,T); S = ex.Current();
105 // no break, in order to execute EDGE case
109 BRepAdaptor_Curve CU(TopoDS::Edge(S));
110 u1 = CU.FirstParameter(); u2 = CU.LastParameter();
111 if (facpar == 0.) facpar = 0.20;
112 if (myPar != -1.0) facpar = myPar;
113 Standard_Real p = u1 + (u2-u1)*facpar;
118 case TopAbs_SHELL : case TopAbs_SOLID : case TopAbs_COMPSOLID :
120 ex.Init(S,T); S = ex.Current();
122 // no break, in order to execute FACE case
126 BRepAdaptor_Surface SU(TopoDS::Face(S));
127 BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2);
128 if (facpar == 0.) facpar = 0.20;
129 Standard_Real u = u1 + (u2-u1)*facpar;
130 Standard_Real v = v1 + (v2-v1)*facpar;
141 //=======================================================================
142 //function : SetDisplayGeometry
144 //=======================================================================
146 void TestTopOpeDraw_DrawableSHA::SetDisplayGeometry(const Standard_Boolean b)
148 myDisplayGeometry = b;
151 //=======================================================================
154 //=======================================================================
156 void TestTopOpeDraw_DrawableSHA::SetTol(const Standard_Real t)
160 myDM3d = new Draw_Marker3D(Pnt(), Draw_CircleZoom , Draw_rouge, myTol);
164 //=======================================================================
167 //=======================================================================
169 void TestTopOpeDraw_DrawableSHA::SetPar(const Standard_Real t)
172 myText->SetPnt(Pnt());
176 //=======================================================================
179 //=======================================================================
181 void TestTopOpeDraw_DrawableSHA::DrawOn(Draw_Display& dis) const
184 DBRep_DrawableShape::DrawOn(dis);
188 if (myDisplayGeometry) DisplayGeometry(dis);
191 //=======================================================================
192 //function : DisplayGeometry
194 //=======================================================================
196 void TestTopOpeDraw_DrawableSHA::DisplayGeometry(Draw_Display& dis) const
198 const TopoDS_Shape& aShape = Shape();
199 const TopAbs_ShapeEnum t = aShape.ShapeType();
201 if ( t == TopAbs_FACE ) {
202 const TopoDS_Face& F = TopoDS::Face(aShape);
204 Handle(Geom_Surface) GS = BRep_Tool::Surface(F,loc);
205 if ( GS.IsNull() ) return;
206 Standard_Real u1,u2,v1,v2; BRepTools::UVBounds(F,u1,u2,v1,v2);
207 GS = Handle(Geom_Surface)::DownCast(GS->Transformed(loc.Transformation()));
208 Handle(Geom_RectangularTrimmedSurface) GRTS;
209 GRTS = new Geom_RectangularTrimmedSurface(GS,u1,u2,v1,v2);
210 Handle(TestTopOpeDraw_DrawableSUR) D;
211 D = new TestTopOpeDraw_DrawableSUR(GRTS,Draw_bleu);
212 Draw_Color norcol = DBRep_ColorOrientation(aShape.Orientation());
213 D->NormalColor(norcol);
217 else if ( t == TopAbs_EDGE ) {
218 const TopoDS_Edge& E = TopoDS::Edge(aShape);
219 TopLoc_Location loc; Standard_Real f,l;
220 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,loc,f,l);
221 if ( GC.IsNull() ) return;
222 GC = Handle(Geom_Curve)::DownCast(GC->Transformed(loc.Transformation()));
223 Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l);
224 Handle(TestTopOpeDraw_DrawableC3D) D;
225 D = new TestTopOpeDraw_DrawableC3D(GTC,myTextColor);
229 else if ( t == TopAbs_VERTEX ) {
230 const TopoDS_Vertex& V = TopoDS::Vertex(aShape);
231 gp_Pnt P = BRep_Tool::Pnt(V);
232 Handle(TestTopOpeDraw_DrawableP3D) D;
233 D = new TestTopOpeDraw_DrawableP3D(P,myTextColor);