Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: BRepTest_MatCommands.cxx |
2 | // Created: Tue Oct 4 09:25:21 1994 | |
3 | // Author: Yves FRICAUD | |
4 | // <yfr@stylox> | |
5 | ||
6 | #include <BRepTest.hxx> | |
7 | #include <Draw_Interpretor.hxx> | |
8 | #include <Draw_Appli.hxx> | |
9 | #include <DrawTrSurf.hxx> | |
10 | #include <DrawTrSurf_Curve2d.hxx> | |
11 | ||
12 | #include <Geom2d_Line.hxx> | |
13 | #include <Geom2d_Circle.hxx> | |
14 | #include <Geom2d_Curve.hxx> | |
15 | #include <Geom2d_TrimmedCurve.hxx> | |
16 | #include <Geom2d_Parabola.hxx> | |
17 | #include <Geom2d_Hyperbola.hxx> | |
18 | ||
19 | #include <MAT_Bisector.hxx> | |
20 | #include <MAT_Zone.hxx> | |
21 | #include <MAT_Graph.hxx> | |
22 | #include <MAT_Arc.hxx> | |
23 | #include <MAT_BasicElt.hxx> | |
24 | #include <MAT_Node.hxx> | |
25 | #include <MAT_Side.hxx> | |
26 | ||
27 | #include <Bisector_Bisec.hxx> | |
28 | #include <Bisector_BisecAna.hxx> | |
29 | #include <Bisector_Curve.hxx> | |
30 | #include <Precision.hxx> | |
31 | ||
32 | #include <BRepMAT2d_Explorer.hxx> | |
33 | #include <BRepMAT2d_BisectingLocus.hxx> | |
34 | #include <BRepMAT2d_LinkTopoBilo.hxx> | |
35 | ||
36 | #include <gp_Parab2d.hxx> | |
37 | #include <gp_Hypr2d.hxx> | |
38 | ||
39 | #include <DBRep.hxx> | |
40 | #include <TopoDS.hxx> | |
41 | ||
42 | #ifdef WNT | |
43 | Standard_IMPORT Draw_Viewer dout; | |
44 | #endif | |
45 | ||
46 | static BRepMAT2d_BisectingLocus MapBiLo; | |
47 | static BRepMAT2d_Explorer anExplo; | |
48 | static BRepMAT2d_LinkTopoBilo TopoBilo; | |
49 | static MAT_Side SideOfMat = MAT_Left; | |
50 | static Standard_Boolean LinkComputed; | |
51 | ||
52 | static void DrawCurve(const Handle(Geom2d_Curve)& aCurve, | |
53 | const Standard_Integer Indice); | |
54 | ||
55 | //========================================================================== | |
56 | //function : topoLoad | |
0d969553 | 57 | // loading of a face in the explorer. |
7fd59977 | 58 | //========================================================================== |
59 | static Standard_Integer topoload (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
60 | { | |
61 | if (argc < 2) return 1; | |
62 | ||
63 | TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_FACE); | |
64 | ||
65 | if (C1.IsNull()) return 1; | |
66 | ||
67 | anExplo.Perform (TopoDS::Face(C1)); | |
68 | return 0; | |
69 | } | |
70 | ||
71 | //========================================================================== | |
72 | //function : drawcont | |
0d969553 | 73 | // visualization of the contour defined by the explorer. |
7fd59977 | 74 | //========================================================================== |
75 | static Standard_Integer drawcont(Draw_Interpretor& , Standard_Integer , const char**) | |
76 | { | |
77 | Handle(Geom2d_TrimmedCurve) C; | |
78 | ||
79 | for (Standard_Integer j = 1; j <= anExplo.NumberOfContours(); j ++) { | |
80 | for (anExplo.Init(j);anExplo.More();anExplo.Next()) { | |
81 | DrawCurve(anExplo.Value(),1); | |
82 | } | |
83 | } | |
84 | return 0; | |
85 | } | |
86 | ||
87 | //========================================================================== | |
88 | //function : mat | |
0d969553 Y |
89 | // calculate the map of locations bisector on the contour defined by |
90 | // the explorer. | |
7fd59977 | 91 | //========================================================================== |
92 | static Standard_Integer mat(Draw_Interpretor& , Standard_Integer, const char**) | |
93 | { | |
94 | MapBiLo.Compute(anExplo,1,SideOfMat); | |
95 | LinkComputed = Standard_False; | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
0d969553 | 100 | //============================================================================ |
7fd59977 | 101 | //function : zone |
0d969553 Y |
102 | // construction and display of the proximity zone associated to the |
103 | // base elements defined by the edge or the vertex. | |
104 | //============================================================================ | |
7fd59977 | 105 | static Standard_Integer zone(Draw_Interpretor& , Standard_Integer argc , const char** argv) |
106 | { | |
107 | if (argc < 2) return 1; | |
108 | ||
109 | TopoDS_Shape S = DBRep::Get (argv[1],TopAbs_EDGE); | |
110 | if (S.IsNull()) { | |
111 | S = DBRep::Get (argv[1],TopAbs_VERTEX); | |
112 | } | |
113 | ||
114 | if (!LinkComputed) { | |
115 | TopoBilo.Perform(anExplo,MapBiLo); | |
116 | LinkComputed = Standard_True; | |
117 | } | |
118 | ||
119 | Standard_Boolean Reverse; | |
120 | Handle(MAT_Zone) TheZone = new MAT_Zone(); | |
121 | ||
122 | for (TopoBilo.Init(S); TopoBilo.More(); TopoBilo.Next()) { | |
123 | const Handle(MAT_BasicElt)& BE = TopoBilo.Value(); | |
124 | TheZone->Perform(BE); | |
125 | for (Standard_Integer i=1; i <= TheZone->NumberOfArcs(); i++) { | |
126 | DrawCurve(MapBiLo.GeomBis(TheZone->ArcOnFrontier(i),Reverse).Value(),2); | |
127 | } | |
128 | } | |
129 | return 0; | |
130 | } | |
131 | ||
132 | ||
133 | //========================================================================== | |
134 | //function : side | |
0d969553 Y |
135 | // side = left => calculation to the left of the contour. |
136 | // side = right => calculation to the right of the contour. | |
7fd59977 | 137 | //========================================================================== |
138 | ||
139 | static Standard_Integer side(Draw_Interpretor& , Standard_Integer, const char** argv) | |
140 | { | |
141 | if(!strcmp(argv[1],"right")) | |
142 | SideOfMat = MAT_Right; | |
143 | else | |
144 | SideOfMat = MAT_Left; | |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | //========================================================================== | |
150 | //function : result | |
0d969553 | 151 | // Complete display of the calculated map. |
7fd59977 | 152 | //========================================================================== |
153 | static Standard_Integer result(Draw_Interpretor& , Standard_Integer, const char**) | |
154 | { | |
155 | Standard_Integer i,NbArcs=0; | |
156 | Standard_Boolean Rev; | |
157 | ||
158 | NbArcs = MapBiLo.Graph()->NumberOfArcs(); | |
159 | ||
160 | for (i=1; i <= NbArcs;i++) { | |
161 | DrawCurve(MapBiLo.GeomBis(MapBiLo.Graph()->Arc(i),Rev).Value(),3); | |
162 | } | |
163 | return 0; | |
164 | } | |
165 | ||
166 | //========================================================================== | |
167 | //function : DrawCurve | |
0d969553 Y |
168 | // Display of curve <aCurve> of Geom2d in a color defined by <Indice>. |
169 | // Indice = 1 yellow, | |
170 | // Indice = 2 blue, | |
171 | // Indice = 3 red, | |
172 | // Indice = 4 green. | |
7fd59977 | 173 | //========================================================================== |
174 | void DrawCurve(const Handle(Geom2d_Curve)& aCurve, | |
175 | const Standard_Integer Indice) | |
176 | { | |
177 | Handle(Standard_Type) type = aCurve->DynamicType(); | |
178 | Handle(Geom2d_Curve) curve,CurveDraw; | |
179 | Handle(DrawTrSurf_Curve2d) dr; | |
180 | Draw_Color Couleur; | |
181 | ||
182 | if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) { | |
183 | curve = (*(Handle_Geom2d_TrimmedCurve*)&aCurve)->BasisCurve(); | |
184 | type = curve->DynamicType(); | |
185 | if (type == STANDARD_TYPE(Bisector_BisecAna)) { | |
186 | curve =(*(Handle_Bisector_BisecAna*)&curve)->Geom2dCurve(); | |
187 | type = curve->DynamicType(); | |
188 | } | |
0d969553 | 189 | // PB of representation of semi_infinite curves. |
7fd59977 | 190 | gp_Parab2d gpParabola; |
191 | gp_Hypr2d gpHyperbola; | |
192 | Standard_Real Focus; | |
193 | Standard_Real Limit = 50000.; | |
194 | Standard_Real delta = 400; | |
195 | ||
0d969553 | 196 | // PB of representation of semi_infinite curves. |
7fd59977 | 197 | if (aCurve->LastParameter() == Precision::Infinite()) { |
198 | ||
199 | if (type == STANDARD_TYPE(Geom2d_Parabola)) { | |
200 | gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d(); | |
201 | Focus = gpParabola.Focal(); | |
202 | Standard_Real Val1 = Sqrt(Limit*Focus); | |
203 | Standard_Real Val2 = Sqrt(Limit*Limit); | |
204 | delta= (Val1 <= Val2 ? Val1:Val2); | |
205 | } | |
206 | else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) { | |
207 | gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d(); | |
208 | Standard_Real Majr = gpHyperbola.MajorRadius(); | |
209 | Standard_Real Minr = gpHyperbola.MinorRadius(); | |
210 | Standard_Real Valu1 = Limit/Majr; | |
211 | Standard_Real Valu2 = Limit/Minr; | |
212 | Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1)); | |
213 | Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1)); | |
214 | delta = (Val1 <= Val2 ? Val1:Val2); | |
215 | } | |
216 | if (aCurve->FirstParameter() == -Precision::Infinite()) | |
217 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta); | |
218 | else | |
219 | CurveDraw = new Geom2d_TrimmedCurve(aCurve, | |
220 | aCurve->FirstParameter(), | |
221 | aCurve->FirstParameter() + delta); | |
222 | } | |
223 | else { | |
224 | CurveDraw = aCurve; | |
225 | } | |
0d969553 | 226 | // end PB. |
7fd59977 | 227 | } |
228 | else { | |
229 | CurveDraw = aCurve; | |
230 | } | |
231 | ||
232 | if (Indice == 1) Couleur = Draw_jaune; | |
233 | else if (Indice == 2) Couleur = Draw_bleu; | |
234 | else if (Indice == 3) Couleur = Draw_rouge; | |
235 | else if (Indice == 4) Couleur = Draw_vert; | |
236 | ||
237 | Standard_Integer Discret = 50; | |
238 | ||
239 | if (type == STANDARD_TYPE(Geom2d_Circle)) | |
240 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30,Standard_False); | |
241 | else if (type == STANDARD_TYPE(Geom2d_Line)) | |
242 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2,Standard_False); | |
243 | else | |
244 | dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False); | |
245 | ||
246 | dout << dr; | |
247 | dout.Flush(); | |
248 | } | |
249 | ||
250 | //========================================================================== | |
251 | //function BRepTest:: MatCommands | |
252 | //========================================================================== | |
253 | ||
254 | void BRepTest::MatCommands (Draw_Interpretor& theCommands) | |
255 | { | |
256 | theCommands.Add("topoload","load face",__FILE__,topoload); | |
257 | theCommands.Add("drawcont","display current contour",__FILE__,drawcont); | |
258 | theCommands.Add("mat","computes the mat",__FILE__,mat); | |
259 | theCommands.Add("side","side left/right",__FILE__,side); | |
260 | theCommands.Add("result","result",__FILE__,result); | |
261 | theCommands.Add("zone","zone edge or vertex",__FILE__,zone); | |
262 | } |