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