1 // Created on: 1994-10-04
2 // Created by: Yves FRICAUD
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 <BRepTest.hxx>
18 #include <Draw_Interpretor.hxx>
19 #include <Draw_Appli.hxx>
20 #include <DrawTrSurf.hxx>
21 #include <DrawTrSurf_Curve2d.hxx>
23 #include <Geom2d_Line.hxx>
24 #include <Geom2d_Circle.hxx>
25 #include <Geom2d_Curve.hxx>
26 #include <Geom2d_TrimmedCurve.hxx>
27 #include <Geom2d_Parabola.hxx>
28 #include <Geom2d_Hyperbola.hxx>
30 #include <MAT_Bisector.hxx>
31 #include <MAT_Zone.hxx>
32 #include <MAT_Graph.hxx>
33 #include <MAT_Arc.hxx>
34 #include <MAT_BasicElt.hxx>
35 #include <MAT_Node.hxx>
36 #include <MAT_Side.hxx>
38 #include <Bisector_Bisec.hxx>
39 #include <Bisector_BisecAna.hxx>
40 #include <Bisector_Curve.hxx>
41 #include <Precision.hxx>
43 #include <BRepMAT2d_Explorer.hxx>
44 #include <BRepMAT2d_BisectingLocus.hxx>
45 #include <BRepMAT2d_LinkTopoBilo.hxx>
47 #include <gp_Parab2d.hxx>
48 #include <gp_Hypr2d.hxx>
54 Standard_IMPORT Draw_Viewer dout;
57 static BRepMAT2d_BisectingLocus MapBiLo;
58 static BRepMAT2d_Explorer anExplo;
59 static BRepMAT2d_LinkTopoBilo TopoBilo;
60 static MAT_Side SideOfMat = MAT_Left;
61 static Standard_Boolean LinkComputed;
63 static void DrawCurve(const Handle(Geom2d_Curve)& aCurve,
64 const Standard_Integer Indice);
66 //==========================================================================
68 // loading of a face in the explorer.
69 //==========================================================================
70 static Standard_Integer topoload (Draw_Interpretor& , Standard_Integer argc, const char** argv)
72 if (argc < 2) return 1;
74 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_FACE);
76 if (C1.IsNull()) return 1;
78 anExplo.Perform (TopoDS::Face(C1));
82 //==========================================================================
84 // visualization of the contour defined by the explorer.
85 //==========================================================================
86 static Standard_Integer drawcont(Draw_Interpretor& , Standard_Integer , const char**)
88 Handle(Geom2d_TrimmedCurve) C;
90 for (Standard_Integer j = 1; j <= anExplo.NumberOfContours(); j ++) {
91 for (anExplo.Init(j);anExplo.More();anExplo.Next()) {
92 DrawCurve(anExplo.Value(),1);
98 //==========================================================================
100 // calculate the map of locations bisector on the contour defined by
102 //==========================================================================
103 static Standard_Integer mat(Draw_Interpretor& , Standard_Integer, const char**)
105 MapBiLo.Compute(anExplo,1,SideOfMat);
106 LinkComputed = Standard_False;
111 //============================================================================
113 // construction and display of the proximity zone associated to the
114 // base elements defined by the edge or the vertex.
115 //============================================================================
116 static Standard_Integer zone(Draw_Interpretor& , Standard_Integer argc , const char** argv)
118 if (argc < 2) return 1;
120 TopoDS_Shape S = DBRep::Get (argv[1],TopAbs_EDGE);
122 S = DBRep::Get (argv[1],TopAbs_VERTEX);
126 TopoBilo.Perform(anExplo,MapBiLo);
127 LinkComputed = Standard_True;
130 Standard_Boolean Reverse;
131 Handle(MAT_Zone) TheZone = new MAT_Zone();
133 for (TopoBilo.Init(S); TopoBilo.More(); TopoBilo.Next()) {
134 const Handle(MAT_BasicElt)& BE = TopoBilo.Value();
135 TheZone->Perform(BE);
136 for (Standard_Integer i=1; i <= TheZone->NumberOfArcs(); i++) {
137 DrawCurve(MapBiLo.GeomBis(TheZone->ArcOnFrontier(i),Reverse).Value(),2);
144 //==========================================================================
146 // side = left => calculation to the left of the contour.
147 // side = right => calculation to the right of the contour.
148 //==========================================================================
150 static Standard_Integer side(Draw_Interpretor& , Standard_Integer, const char** argv)
152 if(!strcmp(argv[1],"right"))
153 SideOfMat = MAT_Right;
155 SideOfMat = MAT_Left;
160 //==========================================================================
162 // Complete display of the calculated map.
163 //==========================================================================
164 static Standard_Integer result(Draw_Interpretor& , Standard_Integer, const char**)
166 Standard_Integer i,NbArcs=0;
167 Standard_Boolean Rev;
169 NbArcs = MapBiLo.Graph()->NumberOfArcs();
171 for (i=1; i <= NbArcs;i++) {
172 DrawCurve(MapBiLo.GeomBis(MapBiLo.Graph()->Arc(i),Rev).Value(),3);
177 //==========================================================================
178 //function : DrawCurve
179 // Display of curve <aCurve> of Geom2d in a color defined by <Indice>.
180 // Indice = 1 yellow,
184 //==========================================================================
185 void DrawCurve(const Handle(Geom2d_Curve)& aCurve,
186 const Standard_Integer Indice)
188 Handle(Standard_Type) type = aCurve->DynamicType();
189 Handle(Geom2d_Curve) curve,CurveDraw;
190 Handle(DrawTrSurf_Curve2d) dr;
193 if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
194 curve = (*(Handle_Geom2d_TrimmedCurve*)&aCurve)->BasisCurve();
195 type = curve->DynamicType();
196 if (type == STANDARD_TYPE(Bisector_BisecAna)) {
197 curve =(*(Handle_Bisector_BisecAna*)&curve)->Geom2dCurve();
198 type = curve->DynamicType();
200 // PB of representation of semi_infinite curves.
201 gp_Parab2d gpParabola;
202 gp_Hypr2d gpHyperbola;
204 Standard_Real Limit = 50000.;
205 Standard_Real delta = 400;
207 // PB of representation of semi_infinite curves.
208 if (aCurve->LastParameter() == Precision::Infinite()) {
210 if (type == STANDARD_TYPE(Geom2d_Parabola)) {
211 gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d();
212 Focus = gpParabola.Focal();
213 Standard_Real Val1 = Sqrt(Limit*Focus);
214 Standard_Real Val2 = Sqrt(Limit*Limit);
215 delta= (Val1 <= Val2 ? Val1:Val2);
217 else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) {
218 gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d();
219 Standard_Real Majr = gpHyperbola.MajorRadius();
220 Standard_Real Minr = gpHyperbola.MinorRadius();
221 Standard_Real Valu1 = Limit/Majr;
222 Standard_Real Valu2 = Limit/Minr;
223 Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
224 Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
225 delta = (Val1 <= Val2 ? Val1:Val2);
227 if (aCurve->FirstParameter() == -Precision::Infinite())
228 CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta);
230 CurveDraw = new Geom2d_TrimmedCurve(aCurve,
231 aCurve->FirstParameter(),
232 aCurve->FirstParameter() + delta);
243 if (Indice == 1) Couleur = Draw_jaune;
244 else if (Indice == 2) Couleur = Draw_bleu;
245 else if (Indice == 3) Couleur = Draw_rouge;
246 else if (Indice == 4) Couleur = Draw_vert;
248 Standard_Integer Discret = 50;
250 if (type == STANDARD_TYPE(Geom2d_Circle))
251 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30,Standard_False);
252 else if (type == STANDARD_TYPE(Geom2d_Line))
253 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2,Standard_False);
255 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False);
261 //==========================================================================
262 //function BRepTest:: MatCommands
263 //==========================================================================
265 void BRepTest::MatCommands (Draw_Interpretor& theCommands)
267 theCommands.Add("topoload","load face",__FILE__,topoload);
268 theCommands.Add("drawcont","display current contour",__FILE__,drawcont);
269 theCommands.Add("mat","computes the mat",__FILE__,mat);
270 theCommands.Add("side","side left/right",__FILE__,side);
271 theCommands.Add("result","result",__FILE__,result);
272 theCommands.Add("zone","zone edge or vertex",__FILE__,zone);