Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-10-04 |
2 | // Created by: Yves FRICAUD | |
3 | // Copyright (c) 1994-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
17 | #include <BRepTest.hxx> | |
18 | #include <Draw_Interpretor.hxx> | |
19 | #include <Draw_Appli.hxx> | |
20 | #include <DrawTrSurf.hxx> | |
21 | #include <DrawTrSurf_Curve2d.hxx> | |
22 | ||
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> | |
29 | ||
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> | |
37 | ||
38 | #include <Bisector_Bisec.hxx> | |
39 | #include <Bisector_BisecAna.hxx> | |
40 | #include <Bisector_Curve.hxx> | |
41 | #include <Precision.hxx> | |
42 | ||
43 | #include <BRepMAT2d_Explorer.hxx> | |
44 | #include <BRepMAT2d_BisectingLocus.hxx> | |
45 | #include <BRepMAT2d_LinkTopoBilo.hxx> | |
46 | ||
47 | #include <gp_Parab2d.hxx> | |
48 | #include <gp_Hypr2d.hxx> | |
49 | ||
50 | #include <DBRep.hxx> | |
51 | #include <TopoDS.hxx> | |
52 | ||
53 | #ifdef WNT | |
54 | Standard_IMPORT Draw_Viewer dout; | |
55 | #endif | |
56 | ||
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; | |
62 | ||
63 | static void DrawCurve(const Handle(Geom2d_Curve)& aCurve, | |
64 | const Standard_Integer Indice); | |
65 | ||
66 | //========================================================================== | |
67 | //function : topoLoad | |
0d969553 | 68 | // loading of a face in the explorer. |
7fd59977 | 69 | //========================================================================== |
70 | static Standard_Integer topoload (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
71 | { | |
72 | if (argc < 2) return 1; | |
73 | ||
74 | TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_FACE); | |
75 | ||
76 | if (C1.IsNull()) return 1; | |
77 | ||
78 | anExplo.Perform (TopoDS::Face(C1)); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | //========================================================================== | |
83 | //function : drawcont | |
0d969553 | 84 | // visualization of the contour defined by the explorer. |
7fd59977 | 85 | //========================================================================== |
86 | static Standard_Integer drawcont(Draw_Interpretor& , Standard_Integer , const char**) | |
87 | { | |
88 | Handle(Geom2d_TrimmedCurve) C; | |
89 | ||
90 | for (Standard_Integer j = 1; j <= anExplo.NumberOfContours(); j ++) { | |
91 | for (anExplo.Init(j);anExplo.More();anExplo.Next()) { | |
92 | DrawCurve(anExplo.Value(),1); | |
93 | } | |
94 | } | |
95 | return 0; | |
96 | } | |
97 | ||
98 | //========================================================================== | |
99 | //function : mat | |
0d969553 Y |
100 | // calculate the map of locations bisector on the contour defined by |
101 | // the explorer. | |
7fd59977 | 102 | //========================================================================== |
103 | static Standard_Integer mat(Draw_Interpretor& , Standard_Integer, const char**) | |
104 | { | |
105 | MapBiLo.Compute(anExplo,1,SideOfMat); | |
106 | LinkComputed = Standard_False; | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
0d969553 | 111 | //============================================================================ |
7fd59977 | 112 | //function : zone |
0d969553 Y |
113 | // construction and display of the proximity zone associated to the |
114 | // base elements defined by the edge or the vertex. | |
115 | //============================================================================ | |
7fd59977 | 116 | static Standard_Integer zone(Draw_Interpretor& , Standard_Integer argc , const char** argv) |
117 | { | |
118 | if (argc < 2) return 1; | |
119 | ||
120 | TopoDS_Shape S = DBRep::Get (argv[1],TopAbs_EDGE); | |
121 | if (S.IsNull()) { | |
122 | S = DBRep::Get (argv[1],TopAbs_VERTEX); | |
123 | } | |
124 | ||
125 | if (!LinkComputed) { | |
126 | TopoBilo.Perform(anExplo,MapBiLo); | |
127 | LinkComputed = Standard_True; | |
128 | } | |
129 | ||
130 | Standard_Boolean Reverse; | |
131 | Handle(MAT_Zone) TheZone = new MAT_Zone(); | |
132 | ||
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); | |
138 | } | |
139 | } | |
140 | return 0; | |
141 | } | |
142 | ||
143 | ||
144 | //========================================================================== | |
145 | //function : side | |
0d969553 Y |
146 | // side = left => calculation to the left of the contour. |
147 | // side = right => calculation to the right of the contour. | |
7fd59977 | 148 | //========================================================================== |
149 | ||
150 | static Standard_Integer side(Draw_Interpretor& , Standard_Integer, const char** argv) | |
151 | { | |
152 | if(!strcmp(argv[1],"right")) | |
153 | SideOfMat = MAT_Right; | |
154 | else | |
155 | SideOfMat = MAT_Left; | |
156 | ||
157 | return 0; | |
158 | } | |
159 | ||
160 | //========================================================================== | |
161 | //function : result | |
0d969553 | 162 | // Complete display of the calculated map. |
7fd59977 | 163 | //========================================================================== |
164 | static Standard_Integer result(Draw_Interpretor& , Standard_Integer, const char**) | |
165 | { | |
166 | Standard_Integer i,NbArcs=0; | |
167 | Standard_Boolean Rev; | |
168 | ||
169 | NbArcs = MapBiLo.Graph()->NumberOfArcs(); | |
170 | ||
171 | for (i=1; i <= NbArcs;i++) { | |
172 | DrawCurve(MapBiLo.GeomBis(MapBiLo.Graph()->Arc(i),Rev).Value(),3); | |
173 | } | |
174 | return 0; | |
175 | } | |
176 | ||
177 | //========================================================================== | |
178 | //function : DrawCurve | |
0d969553 Y |
179 | // Display of curve <aCurve> of Geom2d in a color defined by <Indice>. |
180 | // Indice = 1 yellow, | |
181 | // Indice = 2 blue, | |
182 | // Indice = 3 red, | |
183 | // Indice = 4 green. | |
7fd59977 | 184 | //========================================================================== |
185 | void DrawCurve(const Handle(Geom2d_Curve)& aCurve, | |
186 | const Standard_Integer Indice) | |
187 | { | |
188 | Handle(Standard_Type) type = aCurve->DynamicType(); | |
189 | Handle(Geom2d_Curve) curve,CurveDraw; | |
190 | Handle(DrawTrSurf_Curve2d) dr; | |
191 | Draw_Color Couleur; | |
192 | ||
193 | if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) { | |
857ffd5e | 194 | curve = (*(Handle(Geom2d_TrimmedCurve)*)&aCurve)->BasisCurve(); |
7fd59977 | 195 | type = curve->DynamicType(); |
196 | if (type == STANDARD_TYPE(Bisector_BisecAna)) { | |
857ffd5e | 197 | curve =(*(Handle(Bisector_BisecAna)*)&curve)->Geom2dCurve(); |
7fd59977 | 198 | type = curve->DynamicType(); |
199 | } | |
0d969553 | 200 | // PB of representation of semi_infinite curves. |
7fd59977 | 201 | gp_Parab2d gpParabola; |
202 | gp_Hypr2d gpHyperbola; | |
203 | Standard_Real Focus; | |
204 | Standard_Real Limit = 50000.; | |
205 | Standard_Real delta = 400; | |
206 | ||
0d969553 | 207 | // PB of representation of semi_infinite curves. |
7fd59977 | 208 | if (aCurve->LastParameter() == Precision::Infinite()) { |
209 | ||
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); | |
216 | } | |
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); | |
226 | } | |
227 | if (aCurve->FirstParameter() == -Precision::Infinite()) | |
228 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta); | |
229 | else | |
230 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, | |
231 | aCurve->FirstParameter(), | |
232 | aCurve->FirstParameter() + delta); | |
233 | } | |
234 | else { | |
235 | CurveDraw = aCurve; | |
236 | } | |
0d969553 | 237 | // end PB. |
7fd59977 | 238 | } |
239 | else { | |
240 | CurveDraw = aCurve; | |
241 | } | |
242 | ||
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; | |
247 | ||
248 | Standard_Integer Discret = 50; | |
249 | ||
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); | |
254 | else | |
255 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False); | |
256 | ||
257 | dout << dr; | |
258 | dout.Flush(); | |
259 | } | |
260 | ||
261 | //========================================================================== | |
262 | //function BRepTest:: MatCommands | |
263 | //========================================================================== | |
264 | ||
265 | void BRepTest::MatCommands (Draw_Interpretor& theCommands) | |
266 | { | |
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); | |
273 | } |