Replacing french comments by english one
[occt.git] / src / ChFi3d / ChFi3d_Debug.cxx
1 // File:        ChFi3d_Debug.cxx
2 // Created:     Wed Sep 21 12:49:56 1994
3 // Author:      Laurent BOURESCHE
4 //              <lbo@phylox>
5
6 #include <stdio.h>
7
8 #include <TopOpeBRepDS_DataStructure.hxx>
9 #include <ChFiDS_SurfData.hxx>
10 #include <TopOpeBRepDS_Surface.hxx>
11 #include <BRep_Builder.hxx>
12 #include <TopoDS_Vertex.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Wire.hxx>
15 #include <TopoDS_Face.hxx>
16 #include <Geom_Surface.hxx>
17 #include <Geom2d_Line.hxx>
18 #include <gp_Pnt.hxx>
19 #include <gp_Pnt2d.hxx>
20 #include <gp_Dir.hxx>
21 #include <gp_Dir2d.hxx>
22 #include <gp_Vec.hxx>
23 #include <gp_Vec2d.hxx>
24 #include <gp_Ax1.hxx>
25 #include <OSD_Chronometer.hxx>
26
27 #ifdef DRAW
28 #include <DBRep.hxx>
29 #endif
30
31 #ifdef DEB
32 OSD_Chronometer simul,elspine,chemine;
33 #endif
34
35 //*********************************
36 // timing of the simulation
37 //*********************************
38
39 static Standard_Boolean ChFi3d_traceCHRON = Standard_False;
40 void ChFi3d_SettraceCHRON(const Standard_Boolean b) 
41 { ChFi3d_traceCHRON = b; }
42 Standard_Boolean ChFi3d_GettraceCHRON() 
43 { return ChFi3d_traceCHRON; }
44
45 //*********************************
46 // trace a line of path
47 //*********************************
48
49 static Standard_Boolean ChFi3d_traceDRAWWALK = Standard_False;
50 void ChFi3d_SettraceDRAWWALK(const Standard_Boolean b) 
51 { ChFi3d_traceDRAWWALK = b; }
52 Standard_Boolean ChFi3d_GettraceDRAWWALK() 
53 { return ChFi3d_traceDRAWWALK; }
54
55 //**********************************
56 // trace a line of intersection
57 //**********************************
58
59 static Standard_Boolean ChFi3d_traceDRAWINT = Standard_False;
60 void ChFi3d_SettraceDRAWINT(const Standard_Boolean b) 
61 { ChFi3d_traceDRAWINT = b; }
62 Standard_Boolean ChFi3d_GettraceDRAWINT() 
63 { return ChFi3d_traceDRAWINT; }
64
65 //*************************************************
66 // return surfaces of approximated fillets.
67 //*************************************************
68
69 static Standard_Boolean ChFi3d_traceDRAWFIL = Standard_False;
70 void ChFi3d_SettraceDRAWFIL(const Standard_Boolean b) 
71 { ChFi3d_traceDRAWFIL = b; }
72 Standard_Boolean ChFi3d_GettraceDRAWFIL() 
73 { return ChFi3d_traceDRAWFIL; }
74
75
76 //*************************************************
77 // return extended faces for the path.
78 //*************************************************
79
80 static Standard_Boolean ChFi3d_traceDRAWENLARGE = Standard_False;
81 void ChFi3d_SettraceDRAWENLARGE(const Standard_Boolean b) 
82 { ChFi3d_traceDRAWENLARGE = b; }
83 Standard_Boolean ChFi3d_GettraceDRAWENLARGE() 
84 { return ChFi3d_traceDRAWENLARGE; }
85
86 //*************************************************
87 // return the guideline for the triple corners.
88 //*************************************************
89
90 static Standard_Boolean ChFi3d_traceDRAWSPINE = Standard_False;
91 void ChFi3d_SettraceDRAWSPINE(const Standard_Boolean b) 
92 { ChFi3d_traceDRAWSPINE = b; }
93 Standard_Boolean ChFi3d_GettraceDRAWSPINE() 
94 { return ChFi3d_traceDRAWSPINE; }
95
96 //*************************************************
97 // set the type of guideline for the triple corners.
98 //*************************************************
99
100 void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b); 
101 void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b);
102 void ChFi3d_SetcontextSPINECE(const Standard_Boolean b);
103
104 static Standard_Boolean ChFi3d_contextSPINEBEZIER = Standard_False;
105 void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b){ 
106   ChFi3d_contextSPINEBEZIER = b;
107   if(b){
108     ChFi3d_SetcontextSPINECIRCLE(Standard_False);
109     ChFi3d_SetcontextSPINECE(Standard_False);
110   }
111 }
112 Standard_Boolean ChFi3d_GetcontextSPINEBEZIER() 
113 { return ChFi3d_contextSPINEBEZIER; }
114
115 static Standard_Boolean ChFi3d_contextSPINECIRCLE = Standard_False;
116 void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b){ 
117   ChFi3d_contextSPINECIRCLE = b; 
118   if(b){
119     ChFi3d_SetcontextSPINEBEZIER(Standard_False);
120     ChFi3d_SetcontextSPINECE(Standard_False);
121   }
122 }
123 Standard_Boolean ChFi3d_GetcontextSPINECIRCLE() 
124 { return ChFi3d_contextSPINECIRCLE; }
125
126 static Standard_Boolean ChFi3d_contextSPINECE = Standard_False;
127 void ChFi3d_SetcontextSPINECE(const Standard_Boolean b){ 
128   ChFi3d_contextSPINECE = b; 
129   if(b){
130     ChFi3d_SetcontextSPINEBEZIER(Standard_False);
131     ChFi3d_SetcontextSPINECIRCLE(Standard_False);
132   }
133 }
134 Standard_Boolean ChFi3d_GetcontextSPINECE()
135 { return ChFi3d_contextSPINECE; }
136
137 //*************************************************
138 // Forced passage by the path for KPart
139 //*************************************************
140 static Standard_Boolean ChFi3d_contextFORCEBLEND = Standard_False;
141 void ChFi3d_SetcontextFORCEBLEND(const Standard_Boolean b) 
142 { ChFi3d_contextFORCEBLEND = b; }
143 Standard_Boolean ChFi3d_GetcontextFORCEBLEND() 
144 { return ChFi3d_contextFORCEBLEND; }
145
146 static Standard_Boolean ChFi3d_contextFORCEFILLING = Standard_False;
147 void ChFi3d_SetcontextFORCEFILLING(const Standard_Boolean b) 
148 { ChFi3d_contextFORCEFILLING = b; }
149 Standard_Boolean ChFi3d_GetcontextFORCEFILLING() 
150 { return ChFi3d_contextFORCEFILLING; }
151
152 //*************************************************
153 // No optimization for approx
154 //*************************************************
155 static Standard_Boolean ChFi3d_contextNOOPT = Standard_False;
156 void ChFi3d_SetcontextNOOPT(const Standard_Boolean b) 
157 { ChFi3d_contextNOOPT = b; }
158 Standard_Boolean ChFi3d_GetcontextNOOPT() 
159 { return ChFi3d_contextNOOPT; }
160
161 // ***********************************************
162 //    initialization and result of a chrono 
163 //************************************************
164 Standard_EXPORT void ChFi3d_InitChron(OSD_Chronometer& ch)
165
166     ch.Reset();
167     ch.Start();
168 }
169
170 Standard_EXPORT void ChFi3d_ResultChron( OSD_Chronometer & ch,
171                                         Standard_Real & time) 
172 {
173     Standard_Real tch ;
174     ch.Stop();
175     ch.Show(tch);
176     time=time +tch;
177 }
178
179
180 //==============================================================
181 // function : ChFi3d_CheckSurfData
182 // purpose  : function allows to trace SurfData to check
183 //            construction of all elements, namely pcurves
184 //==============================================================
185 #ifdef DRAW
186 static Standard_Integer NbSD = 0; 
187 #endif
188 void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr,
189                           const Handle(ChFiDS_SurfData)& Data)
190 {
191   //trace of the surface defined by the chamfer or the fillet
192   // corresponding to SurfData
193   
194   Handle(Geom_Surface) surf = (DStr.Surface( Data->Surf())).Surface();
195   if (!surf.IsNull()){
196     BRep_Builder B;
197     TopoDS_Face F;
198     B.MakeFace(F,surf,0.);
199     TopoDS_Wire W;
200     B.MakeWire(W);
201     
202     TopoDS_Vertex V1,V2,V3,V4;
203     B.MakeVertex(V1,Data->VertexFirstOnS1().Point(),0.);
204     B.MakeVertex(V2,Data->VertexLastOnS1().Point(),0.);
205     B.MakeVertex(V3,Data->VertexLastOnS2().Point(),0.);
206     B.MakeVertex(V4,Data->VertexFirstOnS2().Point(),0.);
207     
208     TopoDS_Edge E1,E2,E3,E4;
209     B.MakeEdge(E1);
210     B.MakeEdge(E2);
211     B.MakeEdge(E3);
212     B.MakeEdge(E4);
213
214     B.UpdateEdge(E1,Data->InterferenceOnS1().PCurveOnSurf(),F,0.);
215     B.UpdateEdge(E3,Data->InterferenceOnS2().PCurveOnSurf(),F,0.);
216     V1.Orientation(TopAbs_FORWARD);
217     B.Add(E1,V1);
218     B.UpdateVertex(V1,Data->InterferenceOnS1().FirstParameter(),E1,0.);
219     V2.Orientation(TopAbs_REVERSED);
220     B.Add(E1,V2);
221     B.UpdateVertex(V2,Data->InterferenceOnS1().LastParameter(),E1,0.);
222     
223
224     V4.Orientation(TopAbs_FORWARD);
225     B.Add(E3,V4);
226     B.UpdateVertex(V4,Data->InterferenceOnS2().FirstParameter(),E3,0.);
227     V3.Orientation(TopAbs_REVERSED);
228     B.Add(E3,V3);
229     B.UpdateVertex(V3,Data->InterferenceOnS2().LastParameter(),E3,0.);
230
231     gp_Pnt2d pp1,pp2,pp3,pp4;
232     pp1 = Data->InterferenceOnS1().PCurveOnSurf()->
233       Value(Data->InterferenceOnS1().FirstParameter());
234     pp2 = Data->InterferenceOnS1().PCurveOnSurf()->
235       Value(Data->InterferenceOnS1().LastParameter());
236     pp3 = Data->InterferenceOnS2().PCurveOnSurf()->
237       Value(Data->InterferenceOnS2().LastParameter());
238     pp4 = Data->InterferenceOnS2().PCurveOnSurf()->
239       Value(Data->InterferenceOnS2().FirstParameter());
240     gp_Dir2d d1(gp_Vec2d(pp1,pp4));
241     gp_Dir2d d2(gp_Vec2d(pp2,pp3));
242     Handle(Geom2d_Line) l1 = new Geom2d_Line(pp1,d1);
243     Handle(Geom2d_Line) l2 = new Geom2d_Line(pp2,d2);
244
245     B.UpdateEdge(E4,l1,F,0.);
246     V1.Orientation(TopAbs_FORWARD);
247     B.Add(E4,V1);
248     B.UpdateVertex(V1,0.,E4,0.);
249     V4.Orientation(TopAbs_REVERSED);
250     B.Add(E4,V4);
251     B.UpdateVertex(V4,pp4.Distance(pp1),E4,0.);
252
253     B.UpdateEdge(E2,l2,F,0.);
254     V2.Orientation(TopAbs_FORWARD);
255     B.Add(E2,V2);
256     B.UpdateVertex(V2,0.,E2,0.);
257     V3.Orientation(TopAbs_REVERSED);
258     B.Add(E2,V3);
259     B.UpdateVertex(V3,pp3.Distance(pp2),E2,0.);
260
261     gp_Pnt pw1,pw2,ppp;
262     ppp = surf->Value(pp1.X(),pp1.Y());
263     pw1 = surf->Value(0.9*pp1.X()+0.1*pp2.X(),0.9*pp1.Y()+0.1*pp2.Y());
264     pw2 = surf->Value(0.9*pp1.X()+0.1*pp4.X(),0.9*pp1.Y()+0.1*pp4.Y());
265     gp_Vec vv1(ppp,pw1);
266     gp_Vec vv2(ppp,pw2);
267     gp_Vec Vwire = vv1^vv2;
268
269     surf->D1(pp1.X(),pp1.Y(),pw1,vv1,vv2);
270     gp_Vec Vsurf = vv1^vv2;
271     Standard_Boolean rev = Vsurf.Dot(Vwire)<=0.;
272
273     E1.Orientation(TopAbs_FORWARD);
274     E2.Orientation(TopAbs_FORWARD);
275     E3.Orientation(TopAbs_REVERSED);
276     E4.Orientation(TopAbs_REVERSED);
277     if(rev){
278       E1.Orientation(TopAbs_REVERSED);
279       E2.Orientation(TopAbs_REVERSED);
280       E3.Orientation(TopAbs_FORWARD);
281       E4.Orientation(TopAbs_FORWARD);
282     }
283     B.Add(W,E1);
284     B.Add(W,E2);
285     B.Add(W,E3);
286     B.Add(W,E4);
287
288     W.Orientation(TopAbs_FORWARD);
289     B.Add(F,W);
290
291 #ifdef DRAW
292 //    char name[100];
293     char* name = new char[100];
294     sprintf(name,"fillet_%d",NbSD++);
295     DBRep::Set(name,F);
296 #endif
297   }
298 }