Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BRepTest / BRepTest_MatCommands.cxx
CommitLineData
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
43Standard_IMPORT Draw_Viewer dout;
44#endif
45
46static BRepMAT2d_BisectingLocus MapBiLo;
47static BRepMAT2d_Explorer anExplo;
48static BRepMAT2d_LinkTopoBilo TopoBilo;
49static MAT_Side SideOfMat = MAT_Left;
50static Standard_Boolean LinkComputed;
51
52static void DrawCurve(const Handle(Geom2d_Curve)& aCurve,
53 const Standard_Integer Indice);
54
55//==========================================================================
56//function : topoLoad
57// chargement d une face dans l explorer.
58//==========================================================================
59static 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
73// visualisation du contour defini par l explorateur.
74//==========================================================================
75static 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
89// calcul de la carte des lieux bisecteur sur le contour defini
90// par l explorateur.
91//==========================================================================
92static 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
100//==========================================================================
101//function : zone
102// construction et affichage de la zone de proximite associee aux
103// elements de base definis par l edge ou le vertex.
104//==========================================================================
105static 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
135// side = left => calcul a gauche du contour.
136// side = right => calcul a droite du contour.
137//==========================================================================
138
139static 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
151// Affichage complet de la carte calculee.
152//==========================================================================
153static 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
168// Affichage d une courbe <aCurve> de Geom2d. dans une couleur
169// definie par <Indice>.
170// Indice = 1 jaune,
171// Indice = 2 bleu,
172// Indice = 3 rouge,
173// Indice = 4 vert.
174//==========================================================================
175void DrawCurve(const Handle(Geom2d_Curve)& aCurve,
176 const Standard_Integer Indice)
177{
178 Handle(Standard_Type) type = aCurve->DynamicType();
179 Handle(Geom2d_Curve) curve,CurveDraw;
180 Handle(DrawTrSurf_Curve2d) dr;
181 Draw_Color Couleur;
182
183 if (type == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
184 curve = (*(Handle_Geom2d_TrimmedCurve*)&aCurve)->BasisCurve();
185 type = curve->DynamicType();
186 if (type == STANDARD_TYPE(Bisector_BisecAna)) {
187 curve =(*(Handle_Bisector_BisecAna*)&curve)->Geom2dCurve();
188 type = curve->DynamicType();
189 }
190 // PB de representation des courbes semi_infinies.
191 gp_Parab2d gpParabola;
192 gp_Hypr2d gpHyperbola;
193 Standard_Real Focus;
194 Standard_Real Limit = 50000.;
195 Standard_Real delta = 400;
196
197 // PB de representation des courbes semi_infinies.
198 if (aCurve->LastParameter() == Precision::Infinite()) {
199
200 if (type == STANDARD_TYPE(Geom2d_Parabola)) {
201 gpParabola = Handle(Geom2d_Parabola)::DownCast(curve)->Parab2d();
202 Focus = gpParabola.Focal();
203 Standard_Real Val1 = Sqrt(Limit*Focus);
204 Standard_Real Val2 = Sqrt(Limit*Limit);
205 delta= (Val1 <= Val2 ? Val1:Val2);
206 }
207 else if (type == STANDARD_TYPE(Geom2d_Hyperbola)) {
208 gpHyperbola = Handle(Geom2d_Hyperbola)::DownCast(curve)->Hypr2d();
209 Standard_Real Majr = gpHyperbola.MajorRadius();
210 Standard_Real Minr = gpHyperbola.MinorRadius();
211 Standard_Real Valu1 = Limit/Majr;
212 Standard_Real Valu2 = Limit/Minr;
213 Standard_Real Val1 = Log(Valu1+Sqrt(Valu1*Valu1-1));
214 Standard_Real Val2 = Log(Valu2+Sqrt(Valu2*Valu2+1));
215 delta = (Val1 <= Val2 ? Val1:Val2);
216 }
217 if (aCurve->FirstParameter() == -Precision::Infinite())
218 CurveDraw = new Geom2d_TrimmedCurve(aCurve, -delta, delta);
219 else
220 CurveDraw = new Geom2d_TrimmedCurve(aCurve,
221 aCurve->FirstParameter(),
222 aCurve->FirstParameter() + delta);
223 }
224 else {
225 CurveDraw = aCurve;
226 }
227 // fin PB.
228 }
229 else {
230 CurveDraw = aCurve;
231 }
232
233 if (Indice == 1) Couleur = Draw_jaune;
234 else if (Indice == 2) Couleur = Draw_bleu;
235 else if (Indice == 3) Couleur = Draw_rouge;
236 else if (Indice == 4) Couleur = Draw_vert;
237
238 Standard_Integer Discret = 50;
239
240 if (type == STANDARD_TYPE(Geom2d_Circle))
241 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,30,Standard_False);
242 else if (type == STANDARD_TYPE(Geom2d_Line))
243 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,2,Standard_False);
244 else
245 dr = new DrawTrSurf_Curve2d(CurveDraw,Couleur,Discret,Standard_False);
246
247 dout << dr;
248 dout.Flush();
249}
250
251//==========================================================================
252//function BRepTest:: MatCommands
253//==========================================================================
254
255void BRepTest::MatCommands (Draw_Interpretor& theCommands)
256{
257 theCommands.Add("topoload","load face",__FILE__,topoload);
258 theCommands.Add("drawcont","display current contour",__FILE__,drawcont);
259 theCommands.Add("mat","computes the mat",__FILE__,mat);
260 theCommands.Add("side","side left/right",__FILE__,side);
261 theCommands.Add("result","result",__FILE__,result);
262 theCommands.Add("zone","zone edge or vertex",__FILE__,zone);
263}