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 n, const char** a)
105 GeomAbs_JoinType theJoinType = GeomAbs_Arc;
106 if (n >= 2 && strcmp(a[1], "i") == 0)
107 theJoinType = GeomAbs_Intersection;
109 Standard_Boolean IsOpenResult = Standard_False;
110 if (n == 3 && strcmp(a[2], "o") == 0)
111 IsOpenResult = Standard_True;
113 MapBiLo.Compute(anExplo, 1, SideOfMat, theJoinType, IsOpenResult);
114 LinkComputed = Standard_False;
119 //============================================================================
121 // construction and display of the proximity zone associated to the
122 // base elements defined by the edge or the vertex.
123 //============================================================================
124 static Standard_Integer zone(Draw_Interpretor& , Standard_Integer argc , const char** argv)
126 if (argc < 2) return 1;
128 TopoDS_Shape S = DBRep::Get (argv[1],TopAbs_EDGE);
130 S = DBRep::Get (argv[1],TopAbs_VERTEX);
134 TopoBilo.Perform(anExplo,MapBiLo);
135 LinkComputed = Standard_True;
138 Standard_Boolean Reverse;
139 Handle(MAT_Zone) TheZone = new MAT_Zone();
141 for (TopoBilo.Init(S); TopoBilo.More(); TopoBilo.Next()) {
142 const Handle(MAT_BasicElt)& BE = TopoBilo.Value();
143 TheZone->Perform(BE);
144 for (Standard_Integer i=1; i <= TheZone->NumberOfArcs(); i++) {
145 DrawCurve(MapBiLo.GeomBis(TheZone->ArcOnFrontier(i),Reverse).Value(),2);
152 //==========================================================================
154 // side = left => calculation to the left of the contour.
155 // side = right => calculation to the right of the contour.
156 //==========================================================================
158 static Standard_Integer side(Draw_Interpretor& , Standard_Integer, const char** argv)
160 if(!strcmp(argv[1],"right"))
161 SideOfMat = MAT_Right;
163 SideOfMat = MAT_Left;
168 //==========================================================================
170 // Complete display of the calculated map.
171 //==========================================================================
172 static Standard_Integer result(Draw_Interpretor& , Standard_Integer, const char**)
174 Standard_Integer i,NbArcs=0;
175 Standard_Boolean Rev;
177 NbArcs = MapBiLo.Graph()->NumberOfArcs();
179 for (i=1; i <= NbArcs;i++) {
180 DrawCurve(MapBiLo.GeomBis(MapBiLo.Graph()->Arc(i),Rev).Value(),3);
185 //==========================================================================
186 //function : DrawCurve
187 // Display of curve <aCurve> of Geom2d in a color defined by <Indice>.
188 // Indice = 1 yellow,
192 //==========================================================================
193 void DrawCurve(const Handle(Geom2d_Curve)& aCurve,
194 const Standard_Integer Indice)
196 Handle(Standard_Type) type = aCurve->DynamicType();
197 Handle(Geom2d_Curve) curve,CurveDraw;
198 Handle(DrawTrSurf_Curve2d) dr;
201 if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
202 curve = (*(Handle(Geom2d_TrimmedCurve)*)&aCurve)->BasisCurve();
203 type = curve->DynamicType();
204 if (type == STANDARD_TYPE(Bisector_BisecAna)) {
205 curve =(*(Handle(Bisector_BisecAna)*)&curve)->Geom2dCurve();
206 type = curve->DynamicType();
208 // PB of representation of semi_infinite curves.
209 gp_Parab2d gpParabola;
210 gp_Hypr2d gpHyperbola;
212 Standard_Real Limit = 50000.;
213 Standard_Real delta = 400;
215 // PB of representation of semi_infinite curves.
216 if (aCurve->LastParameter() == Precision::Infinite()) {
218 if (type == STANDARD_TYPE(Geom2d_Parabola)) {
219 gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d();
220 Focus = gpParabola.Focal();
221 Standard_Real Val1 = Sqrt(Limit*Focus);
222 Standard_Real Val2 = Sqrt(Limit*Limit);
223 delta= (Val1 <= Val2 ? Val1:Val2);
225 else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) {
226 gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d();
227 Standard_Real Majr = gpHyperbola.MajorRadius();
228 Standard_Real Minr = gpHyperbola.MinorRadius();
229 Standard_Real Valu1 = Limit/Majr;
230 Standard_Real Valu2 = Limit/Minr;
231 Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
232 Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
233 delta = (Val1 <= Val2 ? Val1:Val2);
235 if (aCurve->FirstParameter() == -Precision::Infinite())
236 CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta);
238 CurveDraw = new Geom2d_TrimmedCurve(aCurve,
239 aCurve->FirstParameter(),
240 aCurve->FirstParameter() + delta);
251 if (Indice == 1) Couleur = Draw_jaune;
252 else if (Indice == 2) Couleur = Draw_bleu;
253 else if (Indice == 3) Couleur = Draw_rouge;
254 else if (Indice == 4) Couleur = Draw_vert;
256 Standard_Integer Discret = 50;
258 if (type == STANDARD_TYPE(Geom2d_Circle))
259 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30,Standard_False);
260 else if (type == STANDARD_TYPE(Geom2d_Line))
261 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2,Standard_False);
263 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False);
269 //==========================================================================
270 //function BRepTest:: MatCommands
271 //==========================================================================
273 void BRepTest::MatCommands (Draw_Interpretor& theCommands)
275 theCommands.Add("topoload","load face",__FILE__,topoload);
276 theCommands.Add("drawcont","display current contour",__FILE__,drawcont);
277 theCommands.Add("mat","computes the mat: mat [a/i [o]]",__FILE__,mat);
278 theCommands.Add("side","side left/right",__FILE__,side);
279 theCommands.Add("result","result",__FILE__,result);
280 theCommands.Add("zone","zone edge or vertex",__FILE__,zone);