b311480e |
1 | // Created on: 1994-01-20 |
2 | // Created by: Isabelle GRIGNON |
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 <Standard_NotImplemented.hxx> |
18 | #include <Precision.hxx> |
19 | #include <TColStd_SequenceOfInteger.hxx> |
20 | #include <TColStd_Array1OfInteger.hxx> |
21 | #include <TColStd_Array1OfReal.hxx> |
22 | #include <gp.hxx> |
23 | #include <gp_Pnt2d.hxx> |
24 | #include <gp_Dir2d.hxx> |
25 | #include <gp_Pnt.hxx> |
26 | #include <gp_Circ.hxx> |
27 | #include <TColgp_Array1OfPnt2d.hxx> |
28 | #include <ElCLib.hxx> |
29 | #include <ElSLib.hxx> |
30 | #include <Geom2d_Curve.hxx> |
31 | #include <Geom2d_Line.hxx> |
32 | #include <Geom2d_BezierCurve.hxx> |
33 | #include <Geom2d_BSplineCurve.hxx> |
34 | #include <Geom_Curve.hxx> |
35 | #include <Geom_Plane.hxx> |
36 | #include <Geom_Surface.hxx> |
37 | #include <GeomAbs_CurveType.hxx> |
38 | #include <GeomAbs_SurfaceType.hxx> |
39 | #include <GeomAdaptor_Curve.hxx> |
40 | #include <Geom2dAdaptor_Curve.hxx> |
41 | #include <Geom2dAdaptor_HCurve.hxx> |
42 | |
43 | #include <GeomAdaptor_HSurface.hxx> |
44 | #include <BRepAdaptor_Curve2d.hxx> |
45 | #include <BRepAdaptor_HCurve.hxx> |
46 | #include <BRepAdaptor_HCurve2d.hxx> |
47 | #include <BRep_Tool.hxx> |
48 | #include <HatchGen_PointOnElement.hxx> |
49 | #include <HatchGen_PointOnHatching.hxx> |
50 | #include <HatchGen_Domain.hxx> |
51 | #include <Geom2dHatch_Intersector.hxx> |
52 | #include <Geom2dHatch_Hatcher.hxx> |
53 | |
54 | #include <TopExp.hxx> |
55 | #include <TopoDS_Edge.hxx> |
56 | |
57 | #include <TopOpeBRepDS_Curve.hxx> |
58 | #include <TopOpeBRepDS_Surface.hxx> |
59 | |
60 | #include <ChFiKPart_RstMap.hxx> |
61 | |
62 | #include <ChFi3d_Builder.jxx> |
63 | #include <ChFi3d_Builder_0.hxx> |
0797d9d3 |
64 | #ifdef OCCT_DEBUG |
7fd59977 |
65 | extern Standard_Boolean ChFi3d_GettraceDRAWFIL(); |
66 | extern void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr, |
67 | const Handle(ChFiDS_SurfData)& Data); |
68 | #endif |
69 | //======================================================================= |
70 | //function : CompTra |
81bba717 |
71 | //purpose : Calculate the Transition from start point. |
7fd59977 |
72 | //======================================================================= |
73 | |
74 | static TopAbs_Orientation CompTra (const TopAbs_Orientation O1, |
75 | const TopAbs_Orientation O2, |
76 | const Standard_Boolean isfirst) |
77 | { |
78 | if(isfirst) return TopAbs::Reverse(TopAbs::Compose(O1,O2)); |
79 | else return TopAbs::Compose(O1,O2); |
80 | } |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : CompCommonpoint |
81bba717 |
85 | //purpose : Fill the commonpoint in case of a vertex. |
7fd59977 |
86 | //======================================================================= |
87 | |
88 | static void CompCommonPoint (ChFiDS_CommonPoint& FilPoint, |
89 | const TopoDS_Edge& arc, |
90 | const HatchGen_PointOnElement& PE, |
91 | const TopAbs_Orientation Or) |
92 | { |
93 | TopAbs_Orientation pos = PE.Position(); |
94 | TopoDS_Vertex V; |
95 | if ( pos == TopAbs_FORWARD ) { |
96 | V = TopExp::FirstVertex(arc); |
97 | } |
98 | else { |
99 | V = TopExp::LastVertex(arc); |
100 | } |
101 | FilPoint.SetVertex(V); |
102 | FilPoint.SetArc(Precision::PIntersection(),arc, |
103 | PE.Parameter(),TopAbs::Compose(arc.Orientation(),Or)); |
104 | } |
105 | |
106 | |
107 | //======================================================================= |
108 | //function : CpInterf |
81bba717 |
109 | //purpose : Construct new SurfData sharing faces, surface and curves. |
7fd59977 |
110 | //======================================================================= |
111 | |
112 | static ChFiDS_FaceInterference CpInterf (TopOpeBRepDS_DataStructure& DStr, |
113 | const ChFiDS_FaceInterference& FI) |
114 | { |
115 | ChFiDS_FaceInterference newF = FI; |
116 | const TopOpeBRepDS_Curve& toc = DStr.Curve(FI.LineIndex()); |
117 | Handle(Geom_Curve) newC; |
118 | if (!toc.Curve().IsNull()) |
119 | newC = Handle(Geom_Curve)::DownCast(toc.Curve()->Copy()); |
120 | newF.SetLineIndex(DStr.AddCurve(TopOpeBRepDS_Curve(newC,toc.Tolerance()))); |
121 | |
122 | if (!FI.PCurveOnFace().IsNull()) |
123 | newF.ChangePCurveOnFace() = |
124 | Handle(Geom2d_Curve)::DownCast(FI.PCurveOnFace()->Copy()); |
125 | if (!FI.PCurveOnSurf().IsNull()) |
126 | newF.ChangePCurveOnSurf() = |
127 | Handle(Geom2d_Curve)::DownCast(FI.PCurveOnSurf()->Copy()); |
128 | return newF; |
129 | } |
130 | |
131 | |
132 | //======================================================================= |
133 | //function : CpSD |
81bba717 |
134 | //purpose : Construct new SurfData sharing faces, surface and curves. |
7fd59977 |
135 | //======================================================================= |
136 | |
137 | static Handle(ChFiDS_SurfData) CpSD ( TopOpeBRepDS_DataStructure& DStr, |
138 | const Handle(ChFiDS_SurfData)& Data) |
139 | { |
140 | Handle(ChFiDS_SurfData) newData = new ChFiDS_SurfData(); |
141 | const TopOpeBRepDS_Surface& tos = DStr.Surface(Data->Surf()); |
142 | Handle(Geom_Surface) newS = Handle(Geom_Surface)::DownCast(tos.Surface()->Copy()); |
143 | Standard_Real tol = tos.Tolerance(); |
144 | newData->ChangeSurf(DStr.AddSurface(TopOpeBRepDS_Surface(newS,tol))); |
145 | newData->ChangeIndexOfS1(Data->IndexOfS1()); |
146 | newData->ChangeIndexOfS2(Data->IndexOfS2()); |
147 | newData->ChangeOrientation() = Data->Orientation(); |
148 | newData->ChangeInterferenceOnS1() = CpInterf(DStr,Data->InterferenceOnS1()); |
149 | newData->ChangeInterferenceOnS2() = CpInterf(DStr,Data->InterferenceOnS2()); |
150 | return newData; |
151 | } |
152 | |
153 | //======================================================================= |
154 | //function : AdjustParam |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | static Standard_Boolean AdjustParam(const HatchGen_Domain& Dom, |
159 | Standard_Real& f, |
160 | Standard_Real& l, |
161 | const Standard_Real wref, |
162 | const Standard_Real period, |
163 | const Standard_Real pitol) |
164 | { |
165 | if(Dom.HasFirstPoint()) |
166 | f = Dom.FirstPoint().Parameter(); |
167 | else f = 0.; |
168 | if(Dom.HasSecondPoint()) |
169 | l = Dom.SecondPoint().Parameter(); |
170 | else l = period; |
171 | if (period == 0.) return Standard_False; |
172 | |
173 | f = ElCLib::InPeriod(f,wref - pitol, wref + period - pitol); |
174 | l = ElCLib::InPeriod(l,wref + pitol, wref + period + pitol); |
175 | if (l < f) { |
176 | f -= period; |
177 | return Standard_True; |
178 | } |
179 | return Standard_False; |
180 | } |
181 | //======================================================================= |
182 | //function : ComputeAbscissa |
183 | //purpose : |
184 | //======================================================================= |
185 | |
186 | static Standard_Real ComputeAbscissa(const BRepAdaptor_Curve& C, |
187 | const Standard_Real U) |
188 | { |
189 | switch (C.GetType()) { |
190 | case GeomAbs_Line: |
191 | return U; |
192 | case GeomAbs_Circle: |
193 | return C.Circle().Radius()*U; |
194 | default: |
195 | return 0; |
196 | } |
7fd59977 |
197 | } |
198 | |
199 | //======================================================================= |
200 | //function : ParamOnSpine |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | static Standard_Real ParamOnSpine(const TopOpeBRepDS_DataStructure& DStr, |
205 | const Standard_Real ptg, |
206 | const Handle(ChFiDS_SurfData)& CD, |
207 | const Handle(ChFiDS_Spine)& Spine, |
208 | const Standard_Integer iedge, |
209 | const Standard_Boolean intf, |
210 | const Standard_Boolean intl, |
211 | const Standard_Real tol, |
212 | Standard_Boolean& pok) |
213 | { |
214 | Standard_Real Nl; |
215 | Standard_Real f = Spine->FirstParameter(iedge); |
216 | Standard_Real l = Spine->LastParameter(iedge); |
217 | |
218 | Nl = ComputeAbscissa(Spine->CurrentElementarySpine(iedge),ptg) + f; |
219 | if ((Nl >= (f - tol) || intf) && |
220 | (Nl <= (l + tol) || intl) ) { |
221 | pok = 1; |
222 | return Nl; |
223 | } |
224 | else { |
81bba717 |
225 | //construction of the plane containing the section of CD with parameter ptg. |
7fd59977 |
226 | gp_Pnt PP; |
227 | gp_Vec VV; |
228 | Handle(Geom_Curve) c3d; |
229 | if (CD->InterferenceOnS1().LineIndex() != 0) { |
230 | c3d = DStr.Curve(CD->InterferenceOnS1().LineIndex()).Curve(); |
231 | } |
232 | if(c3d.IsNull()) { |
233 | c3d = DStr.Curve(CD->InterferenceOnS2().LineIndex()).Curve(); |
234 | } |
235 | c3d->D1(ptg,PP,VV); |
236 | |
237 | gp_Pln nlp(PP,gp_Dir(VV)); |
238 | Handle(Geom_Plane) pln = new Geom_Plane(nlp); |
239 | Handle(GeomAdaptor_HSurface) |
240 | plan = new GeomAdaptor_HSurface(GeomAdaptor_Surface(pln)); |
241 | |
81bba717 |
242 | // intersection plane spine. |
7fd59977 |
243 | Standard_Boolean found = Standard_False; |
244 | Standard_Boolean fini = Standard_False; |
245 | Standard_Integer sens = 1; |
246 | if (Nl <= f) sens = -1; |
247 | Standard_Integer ii = iedge + sens; |
248 | if (Spine->IsPeriodic()) { |
249 | if (ii <= 0) ii += Spine->NbEdges(); |
250 | if (ii > Spine->NbEdges()) ii -= Spine->NbEdges(); |
251 | } |
252 | else if(ii < 1 || ii > Spine->NbEdges()) { |
253 | pok = 1; |
254 | return Nl; |
255 | } |
256 | Handle(BRepAdaptor_HCurve) HE = new BRepAdaptor_HCurve(); |
257 | BRepAdaptor_Curve& CE = HE->ChangeCurve(); |
258 | |
259 | while (!found && !fini) { |
260 | TopAbs_Orientation O = Spine->Edges(ii).Orientation(); |
261 | Standard_Boolean First = ((O == TopAbs_FORWARD && sens == 1) || |
262 | (O == TopAbs_REVERSED && sens == -1)); |
263 | CE.Initialize(Spine->Edges(ii)); |
264 | Standard_Real tolc = CE.Resolution(tol); |
265 | found = ChFi3d_InterPlaneEdge(plan,HE,Nl,First,tolc); |
266 | gp_Pnt point = CE.Value(Nl); |
0797d9d3 |
267 | #ifdef OCCT_DEBUG |
7fd59977 |
268 | cout<<"******* ParamOnSpine() for edge "<<iedge<<endl; |
269 | cout<<Nl<<endl; |
270 | cout<<"point ped "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl; |
271 | #endif |
272 | if(found) Nl = Spine->Absc(Nl,ii); |
273 | point = Spine->Value(Nl); |
0797d9d3 |
274 | #ifdef OCCT_DEBUG |
7fd59977 |
275 | if (found) cout << "found by edge " << ii << " : "; |
276 | cout<<Nl<<endl; |
277 | cout<<"point psp "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl; |
278 | cout<<endl; |
279 | #endif |
280 | |
281 | ii +=sens; |
282 | if (Spine->IsPeriodic()) { |
283 | if (ii <= 0) ii += Spine->NbEdges(); |
284 | if (ii > Spine->NbEdges()) ii -= Spine->NbEdges(); |
285 | fini = (ii == iedge); |
286 | } |
287 | else { |
288 | fini = (ii < 1 || ii > Spine->NbEdges()); |
289 | } |
290 | } |
291 | pok = found; |
292 | return Nl; |
293 | } |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : YaUnVoisin |
298 | //purpose : |
299 | //======================================================================= |
300 | |
301 | static Standard_Boolean YaUnVoisin(const Handle(ChFiDS_Spine)& Spine, |
302 | const Standard_Integer iedge, |
303 | Standard_Integer& ivois, |
304 | const Standard_Boolean isfirst) |
305 | { |
306 | Standard_Integer nbed = Spine->NbEdges(); |
307 | if(nbed == 1) return 0; |
308 | Standard_Boolean periodic = Spine->IsPeriodic(); |
309 | if(isfirst) ivois = iedge - 1; |
310 | else ivois = iedge + 1; |
311 | if(periodic) { |
312 | if(ivois == 0) ivois = nbed; |
313 | if(ivois == nbed+1) ivois = 1; |
314 | } |
315 | return (ivois > 0 && ivois <= nbed); |
316 | } |
317 | |
318 | //======================================================================= |
319 | //function : Trunc |
320 | //purpose : |
321 | //======================================================================= |
322 | |
323 | void ChFi3d_Builder::Trunc(const Handle(ChFiDS_SurfData)& SD, |
324 | const Handle(ChFiDS_Spine)& Spine, |
325 | const Handle(Adaptor3d_HSurface)& S1, |
326 | const Handle(Adaptor3d_HSurface)& S2, |
327 | const Standard_Integer iedge, |
328 | const Standard_Boolean isfirst, |
329 | const Standard_Integer cntlFiOnS) |
330 | { |
331 | TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS(); |
81bba717 |
332 | // Return points and tangents on edge and spine. |
7fd59977 |
333 | Standard_Real wtg = SD->InterferenceOnS1().Parameter(isfirst); |
334 | Standard_Boolean bid; |
335 | Standard_Real wsp = ParamOnSpine(DStr,wtg,SD,Spine,iedge,0,0,tolesp,bid); |
336 | gp_Pnt ped,psp; |
337 | gp_Vec ded,dsp; |
338 | TopoDS_Vertex bout1,bout2,boutemp; |
339 | |
340 | |
341 | const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge); |
81bba717 |
342 | //Modif against Vertex isolated on spine |
7fd59977 |
343 | TopoDS_Edge support = bc.Edge(); |
344 | TopExp::Vertices(support,bout1,bout2); |
345 | if (support.Orientation() == TopAbs_REVERSED) { |
346 | boutemp = bout2; |
347 | bout2 = bout1; |
348 | bout1 = boutemp; |
349 | } |
350 | if (!isfirst) { |
351 | bout1 = bout2; |
352 | } |
353 | //finmodif |
354 | Standard_Real edf = bc.FirstParameter(), edl = bc.LastParameter(); |
355 | Standard_Real edglen = edl - edf; |
356 | if(Spine->Edges(iedge).Orientation() == TopAbs_FORWARD) { |
357 | bc.D1(wtg+edf,ped,ded); |
358 | } |
359 | else{ |
360 | bc.D1(-wtg+edl,ped,ded); |
361 | ded.Reverse(); |
362 | } |
363 | Spine->D1(wsp,psp,dsp); |
364 | gp_Pnt p1,p2; |
365 | const Handle(Geom_Surface)& surf = DStr.Surface(SD->Surf()).Surface(); |
366 | gp_Pnt2d pp1,pp2; |
367 | pp1 = SD->InterferenceOnS1().PCurveOnSurf()->Value(wtg); |
368 | pp2 = SD->InterferenceOnS2().PCurveOnSurf()->Value(wtg); |
369 | p1 = surf->Value(pp1.X(),pp1.Y()); |
370 | p2 = surf->Value(pp2.X(),pp2.Y()); |
371 | Standard_Boolean tron = Standard_False; |
372 | Standard_Real Ang = dsp.Angle(ded); |
373 | Standard_Real dis1 = psp.Distance(ped); |
374 | Standard_Real dis2 = p1.Distance(p2); |
c6541a0c |
375 | if(Ang > M_PI/18.) tron = Standard_True; |
7fd59977 |
376 | if(dis1 >= 0.1*dis2) tron = Standard_True; |
377 | Standard_Integer ivois; |
378 | if(!tron && YaUnVoisin(Spine,iedge,ivois,isfirst)) { |
379 | Handle(BRepAdaptor_HSurface) BS1 = Handle(BRepAdaptor_HSurface)::DownCast(S1); |
380 | Handle(BRepAdaptor_HSurface) BS2 = Handle(BRepAdaptor_HSurface)::DownCast(S2); |
381 | if(!BS1.IsNull() && !BS2.IsNull()) { |
382 | TopoDS_Face FBID; |
383 | TopoDS_Face F1 = BS1->ChangeSurface().Face(); |
384 | TopoDS_Face F2 = BS2->ChangeSurface().Face(); |
385 | const ChFiDS_CommonPoint& cp1 = SD->Vertex(isfirst,1); |
386 | const ChFiDS_CommonPoint& cp2 = SD->Vertex(isfirst,2); |
0ebaa4db |
387 | if(!((cp1.IsOnArc() && SearchFace(Spine,cp1,F1,FBID)) || |
388 | (cp2.IsOnArc() && SearchFace(Spine,cp2,F2,FBID)))) { |
389 | tron = ChFi3d_KParticular(Spine,ivois,BS1->ChangeSurface(),BS2->ChangeSurface()); |
7fd59977 |
390 | } |
391 | } |
392 | } |
81bba717 |
393 | //modification of lvt against isolated vertex |
7fd59977 |
394 | if(!tron && YaUnVoisin(Spine,iedge,ivois,isfirst)) { |
395 | TopTools_ListIteratorOfListOfShape It; |
396 | Standard_Integer nbed = -2; |
397 | for (It.Initialize(myVEMap(bout1));It.More();It.Next()) { |
398 | nbed++; |
399 | } |
400 | if(nbed<3) tron = Standard_True; |
401 | } |
402 | //finmodif |
403 | |
404 | if(tron) { |
405 | Standard_Real par = 0., x, y, dPar=0; |
406 | if(!isfirst) par = edglen; |
407 | if (cntlFiOnS) { |
408 | // detect the case where FaceInterference ends before the place we are |
409 | // going to truncate SD. Then we cut so that FaceInterference length to |
410 | // be at least zero, not negative (eap, occ354) |
411 | Standard_Real fiPar = SD->Interference(cntlFiOnS).Parameter(!isfirst); |
412 | Standard_Boolean isTheCase = isfirst ? (par > fiPar) : (par < fiPar); |
413 | if (isTheCase) { |
414 | dPar = par - fiPar; |
415 | par = fiPar; |
416 | } |
417 | } |
418 | for (Standard_Integer i = 1; i <= 2; i++) { |
419 | SD->ChangeInterference(i).SetParameter(par,isfirst); |
420 | Handle(Geom2d_Curve) pc = SD->Interference(i).PCurveOnSurf(); |
421 | pc->Value(par).Coord(x,y); |
422 | SD->ChangeVertex(isfirst,i).Reset(); |
423 | SD->ChangeVertex(isfirst,i).SetPoint(surf->Value(x,y)); |
424 | if(isfirst) SD->FirstSpineParam(Spine->FirstParameter(iedge)-dPar); |
425 | else SD->LastSpineParam (Spine->LastParameter(iedge) -dPar); |
426 | } |
427 | } |
428 | } |
429 | |
430 | //======================================================================= |
431 | //function : ResetProl |
432 | //purpose : |
433 | //======================================================================= |
434 | |
435 | static Standard_Real ResetProl(const TopOpeBRepDS_DataStructure& DStr, |
436 | const Handle(ChFiDS_SurfData)& CD, |
437 | const Handle(ChFiDS_Spine)& Spine, |
438 | const Standard_Integer iedge, |
439 | const Standard_Boolean isfirst) |
440 | { |
441 | const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge); |
442 | Standard_Real edglen = bc.LastParameter() - bc.FirstParameter(); |
443 | const Handle(Geom_Surface)& surf = DStr.Surface(CD->Surf()).Surface(); |
444 | Standard_Real par = 0., x, y; |
445 | if(!isfirst) par = edglen; |
1d47d8d0 |
446 | Standard_Real sppar = 0.; |
7fd59977 |
447 | for (Standard_Integer i = 1; i <= 2; i++) { |
448 | CD->ChangeInterference(i).SetParameter(par,isfirst); |
449 | Handle(Geom2d_Curve) pc = CD->Interference(i).PCurveOnSurf(); |
450 | pc->Value(par).Coord(x,y); |
451 | CD->ChangeVertex(isfirst,i).Reset(); |
452 | CD->ChangeVertex(isfirst,i).SetPoint(surf->Value(x,y)); |
453 | if(isfirst) { |
454 | sppar = Spine->FirstParameter(iedge); |
455 | CD->FirstSpineParam(sppar); |
456 | } |
457 | else{ |
458 | sppar = Spine->LastParameter(iedge); |
459 | CD->LastSpineParam (sppar); |
460 | } |
461 | } |
462 | return sppar; |
463 | } |
464 | //======================================================================= |
465 | //function : Tri |
466 | //purpose : |
467 | //======================================================================= |
468 | |
469 | static Standard_Boolean Tri(const Geom2dHatch_Hatcher& H, |
470 | const Standard_Integer iH, |
471 | TColStd_Array1OfInteger& Ind, |
472 | const Standard_Real wref, |
473 | const Standard_Real period, |
474 | const Standard_Real pitol, |
475 | Standard_Integer& Nbdom) |
476 | { |
477 | // for (Standard_Integer i = 1; i <= Nbdom; i++) { Ind(i) = i; } |
478 | Standard_Integer i; |
479 | for ( i = 1; i <= Nbdom; i++) { Ind(i) = i; } |
480 | Standard_Real f1,f2,l; |
481 | Standard_Integer tmp; |
482 | Standard_Boolean Invert = Standard_True; |
483 | |
484 | while (Invert) { |
485 | Invert = Standard_False; |
486 | for ( i = 1; i < Nbdom; i++) { |
487 | AdjustParam(H.Domain(iH,Ind(i)),f1,l,wref,period,pitol); |
488 | AdjustParam(H.Domain(iH,Ind(i+1)),f2,l,wref,period,pitol); |
489 | if ( f2 < f1) { |
490 | tmp = Ind(i); |
491 | Ind(i) = Ind(i+1); |
492 | Ind(i+1) = tmp; |
493 | Invert = Standard_True; |
494 | } |
495 | } |
496 | } |
497 | |
498 | Standard_Integer iSansFirst = 0, iSansLast = 0; |
499 | |
500 | if (Nbdom != 1) { |
501 | for ( i = 1; i <= Nbdom; i++) { |
502 | if (!H.Domain(iH,Ind(i)).HasFirstPoint()) { |
503 | iSansFirst = i; |
504 | } |
505 | if (!H.Domain(iH,Ind(i)).HasSecondPoint()) { |
506 | iSansLast = i; |
507 | } |
508 | } |
509 | } |
510 | if (iSansFirst != 0) { |
511 | if (iSansLast == 0) { |
0797d9d3 |
512 | #ifdef OCCT_DEBUG |
81bba717 |
513 | cout<<"Parsing : Pb of Hatcher"<<endl; |
7fd59977 |
514 | #endif |
515 | return 0; |
516 | } |
517 | HatchGen_Domain* Dom = ((HatchGen_Domain*) (void*) &H.Domain(iH,Ind(iSansFirst))); |
518 | HatchGen_PointOnHatching* PH = |
519 | ((HatchGen_PointOnHatching*) (void*) &H.Domain(iH,Ind(iSansLast)).FirstPoint()); |
520 | Standard_Real NewPar = H.HatchingCurve(iH).FirstParameter() - period + |
521 | H.Domain(iH,Ind(iSansLast)).FirstPoint().Parameter(); |
522 | PH->SetParameter(NewPar); |
523 | Dom->SetFirstPoint(*PH); |
524 | |
525 | for (Standard_Integer k = iSansLast; k < Nbdom; k++) { |
526 | Ind(k) = Ind(k+1); |
527 | } |
528 | Nbdom--; |
529 | } |
530 | return 1; |
531 | } |
532 | |
533 | //======================================================================= |
534 | //function : FillSD |
535 | //purpose : |
536 | //======================================================================= |
537 | |
538 | static void FillSD (TopOpeBRepDS_DataStructure& DStr, |
539 | Handle(ChFiDS_SurfData)& CD, |
540 | ChFiKPart_RstMap& M, |
541 | const HatchGen_Domain& Dom, |
542 | const Standard_Real ponH, |
543 | const Standard_Boolean isFirst, |
544 | const Standard_Integer ons, |
545 | const Standard_Real pitol, |
546 | const TopoDS_Vertex bout) |
547 | |
548 | { |
549 | Standard_Integer opp = 3 - ons; |
550 | ChFiDS_CommonPoint& Pons = CD->ChangeVertex(isFirst,ons); |
551 | ChFiDS_CommonPoint& Popp = CD->ChangeVertex(isFirst,opp); |
552 | |
553 | const HatchGen_PointOnHatching* pPH = 0; |
554 | if(isFirst && Dom.HasFirstPoint()) { |
555 | const HatchGen_PointOnHatching& PHtemp = Dom.FirstPoint(); |
556 | pPH = &PHtemp; |
557 | } |
558 | else if(!isFirst && Dom.HasSecondPoint()) { |
559 | const HatchGen_PointOnHatching& PHtemp = Dom.SecondPoint(); |
560 | pPH = &PHtemp; |
561 | } |
562 | Standard_Real x,y; |
563 | Handle(Geom_Surface) Surf = DStr.Surface(CD->Surf()).Surface(); |
564 | if(pPH == 0) { |
565 | CD->ChangeInterference(ons).SetParameter(ponH,isFirst); |
566 | Handle(Geom2d_Curve) pcons = CD->Interference(ons).PCurveOnSurf(); |
567 | pcons->Value(ponH).Coord(x,y); |
568 | CD->ChangeVertex(isFirst,ons).SetPoint(Surf->Value(x,y)); |
569 | } |
570 | else { |
81bba717 |
571 | //Modification to find already existing vertexes |
7fd59977 |
572 | Standard_Integer LeType = 1; |
573 | Standard_Integer NbInt = pPH->NbPoints(); |
574 | if (NbInt>1) { |
575 | Standard_Boolean trouve = Standard_True; |
576 | Standard_Integer IE; |
577 | TopoDS_Vertex V1 , V2; |
578 | Standard_Boolean suite = Standard_True; |
579 | for(;trouve;) { |
580 | const HatchGen_PointOnElement& PEtemp = pPH->Point(LeType); |
581 | IE = PEtemp.Index(); |
582 | Handle(BRepAdaptor_HCurve2d) HE = Handle(BRepAdaptor_HCurve2d::DownCast(M(IE))); |
583 | if(!HE.IsNull()) { |
584 | const TopoDS_Edge& Etemp = HE->ChangeCurve2d().Edge(); |
585 | TopExp::Vertices(Etemp,V1,V2); |
586 | } |
587 | else { |
588 | suite = Standard_False; |
589 | } |
590 | if(((V1.IsSame(bout)) || (V2.IsSame(bout))) && suite) { |
591 | trouve = Standard_True; |
592 | break; |
593 | } |
594 | else { |
595 | suite = Standard_True; |
596 | trouve = Standard_False; |
597 | LeType++; |
598 | if(LeType>NbInt) { |
599 | trouve = Standard_True; |
600 | LeType = 1; |
601 | } |
602 | } |
603 | } |
604 | } |
605 | const HatchGen_PointOnElement& PE = pPH->Point(LeType); |
606 | Standard_Integer IE = PE.Index(); |
607 | Handle(BRepAdaptor_HCurve2d) |
608 | HE = Handle(BRepAdaptor_HCurve2d)::DownCast(M(IE)); |
609 | if(HE.IsNull()) return; |
610 | const TopoDS_Edge& E = HE->ChangeCurve2d().Edge(); |
611 | |
612 | if (PE.Position() != TopAbs_INTERNAL) { |
613 | TopAbs_Orientation O = CD->Interference(ons).Transition(); |
614 | if(isFirst) O = TopAbs::Reverse(O); |
615 | CompCommonPoint(Pons,E,PE,O); |
616 | } |
617 | else{ |
618 | Pons.SetArc(pitol,E,PE.Parameter(), |
619 | CompTra(CD->Interference(ons).Transition(),E.Orientation(),isFirst)); |
620 | } |
621 | Handle(Geom2d_Curve) pcadj = CD->Interference(ons).PCurveOnSurf(); |
622 | pcadj->Value(ponH).Coord(x,y); |
623 | CD->ChangeInterference(ons).SetParameter(ponH,isFirst); |
624 | CD->ChangeVertex(isFirst,ons).SetPoint(Surf->Value(x,y)); |
625 | } |
626 | if(!Popp.IsOnArc()) { |
627 | CD->ChangeInterference(opp).SetParameter(ponH,isFirst); |
628 | Handle(Geom2d_Curve) pcopp = CD->Interference(opp).PCurveOnSurf(); |
629 | pcopp->Value(ponH).Coord(x,y); |
630 | CD->ChangeVertex(isFirst,opp).SetPoint(Surf->Value(x,y)); |
631 | } |
632 | } |
633 | |
634 | //======================================================================= |
635 | //function : SplitKPart |
81bba717 |
636 | //purpose : Reconstruct SurfData depending on restrictions of faces. |
7fd59977 |
637 | //======================================================================= |
638 | |
639 | Standard_Boolean ChFi3d_Builder::SplitKPart |
640 | (const Handle(ChFiDS_SurfData)& Data, |
641 | ChFiDS_SequenceOfSurfData& SetData, |
642 | const Handle(ChFiDS_Spine)& Spine, |
643 | const Standard_Integer Iedge, |
644 | const Handle(Adaptor3d_HSurface)& S1, |
645 | const Handle(Adaptor3d_TopolTool)& I1, |
646 | const Handle(Adaptor3d_HSurface)& S2, |
647 | const Handle(Adaptor3d_TopolTool)& I2, |
648 | Standard_Boolean& intf, |
649 | Standard_Boolean& intl) |
650 | { |
81bba717 |
651 | //The the hatching of each faces is started by tangency lines. |
7fd59977 |
652 | |
653 | Standard_Real pitol = Precision::PIntersection(); |
654 | |
655 | ChFiKPart_RstMap M1, M2; |
7fd59977 |
656 | Standard_Integer iH1 = 0,iH2 = 0; |
7fd59977 |
657 | Standard_Integer Nb1 = 1,Nb2 = 1; |
658 | |
81bba717 |
659 | // Cutting of tangency lines (hatching). |
7fd59977 |
660 | Geom2dHatch_Intersector Inter(pitol,pitol); |
661 | Geom2dHatch_Hatcher H1(Inter,tol2d,tolesp), H2(Inter,tol2d,tolesp); |
662 | Standard_Integer ie; |
663 | Handle(Geom2d_Curve) C1 = Data->InterferenceOnS1().PCurveOnFace(); |
664 | Geom2dAdaptor_Curve ll1; |
665 | if (!C1.IsNull()) { |
666 | ll1.Load(C1); |
667 | for(I1->Init(); I1->More(); I1->Next()) { |
668 | Handle(BRepAdaptor_HCurve2d) |
669 | Bc = Handle(BRepAdaptor_HCurve2d)::DownCast(I1->Value()); |
670 | Handle(Geom2dAdaptor_HCurve) |
671 | Gc = Handle(Geom2dAdaptor_HCurve)::DownCast(I1->Value()); |
672 | if(Bc.IsNull()) ie = H1.AddElement(Gc->ChangeCurve2d(),TopAbs_FORWARD); |
673 | else ie = H1.AddElement(Bc->ChangeCurve2d(), |
674 | Bc->ChangeCurve2d().Edge().Orientation()); |
675 | M1.Bind(ie,I1->Value()); |
676 | } |
677 | iH1 = H1.Trim(ll1); |
678 | H1.ComputeDomains(iH1); |
679 | if(!H1.IsDone(iH1)) return 0; |
680 | Nb1 = H1.NbDomains(iH1); |
681 | if(Nb1 == 0) { |
0797d9d3 |
682 | #ifdef OCCT_DEBUG |
81bba717 |
683 | cout<<"SplitKPart : tangency line out of the face"<<endl; |
7fd59977 |
684 | #endif |
685 | return Standard_False; |
686 | } |
687 | } |
688 | |
689 | Handle(Geom2d_Curve) C2 = Data->InterferenceOnS2().PCurveOnFace(); |
690 | Geom2dAdaptor_Curve ll2; |
691 | if (!C2.IsNull()) { |
692 | ll2.Load(C2); |
693 | for(I2->Init(); I2->More(); I2->Next()) { |
694 | Handle(BRepAdaptor_HCurve2d) |
695 | Bc = Handle(BRepAdaptor_HCurve2d)::DownCast(I2->Value()); |
696 | Handle(Geom2dAdaptor_HCurve) |
697 | Gc = Handle(Geom2dAdaptor_HCurve)::DownCast(I2->Value()); |
698 | if(Bc.IsNull()) ie = H2.AddElement(Gc->ChangeCurve2d(),TopAbs_FORWARD); |
699 | else ie = H2.AddElement(Bc->ChangeCurve2d(), |
700 | Bc->ChangeCurve2d().Edge().Orientation()); |
701 | M2.Bind(ie,I2->Value()); |
702 | } |
703 | iH2 = H2.Trim(ll2); |
704 | H2.ComputeDomains(iH2); |
705 | if(!H2.IsDone(iH2)) return 0; |
706 | Nb2 = H2.NbDomains(iH2); |
707 | if(Nb2 == 0) { |
0797d9d3 |
708 | #ifdef OCCT_DEBUG |
81bba717 |
709 | cout<<"SplitKPart : tangency line out of the face"<<endl; |
7fd59977 |
710 | #endif |
711 | return Standard_False; |
712 | } |
713 | } |
714 | |
81bba717 |
715 | //Return start and end vertexes of the Spine |
7fd59977 |
716 | TopoDS_Vertex bout1,bout2,boutemp; |
717 | const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(Iedge); |
718 | TopoDS_Edge support = bc.Edge(); |
719 | TopExp::Vertices(support,bout1,bout2); |
720 | if(support.Orientation() == TopAbs_REVERSED) { |
721 | boutemp = bout2; |
722 | bout2 = bout1; |
723 | bout1 = boutemp; |
724 | } |
725 | |
81bba717 |
726 | // Return faces. |
7fd59977 |
727 | TopoDS_Face F1, F2; |
728 | Handle(BRepAdaptor_HSurface) |
729 | bhs = Handle(BRepAdaptor_HSurface)::DownCast(S1); |
730 | if(!bhs.IsNull()) F1 = bhs->ChangeSurface().Face(); |
731 | bhs = Handle(BRepAdaptor_HSurface)::DownCast(S2); |
732 | if(!bhs.IsNull()) F2 = bhs->ChangeSurface().Face(); |
733 | TopoDS_Face FBID; |
734 | |
81bba717 |
735 | // Restriction of SurfDatas by cut lines. |
7fd59977 |
736 | TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS(); |
737 | Handle(ChFiDS_SurfData) CD = Data; |
738 | CD->ChangeIndexOfS1(DStr.AddShape(F1)); |
739 | CD->ChangeIndexOfS2(DStr.AddShape(F2)); |
740 | |
741 | Standard_Real f1,l1,f2,l2; |
742 | TColStd_Array1OfInteger Ind1(1,Nb1), Ind2(1,Nb2); |
743 | Standard_Real wref = 0.; |
744 | |
745 | Standard_Integer onS = 1; // switcher of access to surfs of SurfData, eap occ293 |
746 | Standard_Integer cntlFiOnS = 0; // FaceInterference to control length in OnSame |
747 | // situation, eap occ354 |
748 | |
749 | if (C1.IsNull() && C2.IsNull()) { |
0797d9d3 |
750 | #ifdef OCCT_DEBUG |
81bba717 |
751 | cout<<"SplitData : 2 zero lines hatching impossible"<<endl; |
7fd59977 |
752 | #endif |
753 | return Standard_False; |
754 | } |
755 | else if (C1.IsNull() || (Nb1 == 1 && !H1.Domain(iH1,1).HasFirstPoint())) { |
81bba717 |
756 | // It is checked if the point 2d of the degenerated edge is in the face. |
7fd59977 |
757 | if (C1.IsNull()) { |
758 | gp_Pnt2d p2d1 = CD->Get2dPoints(0,1); |
759 | TopAbs_State situ = I1->Classify(p2d1,1.e-8,0); |
760 | if(situ == TopAbs_OUT) return Standard_False; |
761 | } |
762 | |
81bba717 |
763 | // Parsing of domains by increasing parameters, |
7fd59977 |
764 | if(!Tri(H2,iH2,Ind2,wref,0.,pitol,Nb2)) return 0; |
81bba717 |
765 | // Filling of SurfData |
7fd59977 |
766 | for(Standard_Integer i = 1; i <= Nb2; i++) { |
767 | const HatchGen_Domain& Dom2 = H2.Domain(iH2,Ind2(i)); |
768 | FillSD(DStr,CD,M2,Dom2,Dom2.FirstPoint().Parameter(),1,2,pitol,bout1); |
769 | FillSD(DStr,CD,M2,Dom2,Dom2.SecondPoint().Parameter(),0,2,pitol,bout2); |
770 | SetData.Append(CD); |
771 | CD = CpSD(DStr,CD); |
772 | } |
773 | if(intf) { |
774 | Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(1); |
775 | ChFiDS_CommonPoint& CP2 = sd->ChangeVertexFirstOnS2(); |
776 | if(CP2.IsOnArc() && Spine->FirstStatus() == ChFiDS_OnSame) { |
777 | intf = !SearchFace(Spine,CP2,F2,FBID); |
778 | } |
779 | else intf = Standard_False; |
780 | } |
781 | if(intl) { |
782 | Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(SetData.Length()); |
783 | ChFiDS_CommonPoint& CP2 = sd->ChangeVertexLastOnS2(); |
784 | if(CP2.IsOnArc() && Spine->LastStatus() == ChFiDS_OnSame) { |
785 | intl = !SearchFace(Spine,CP2,F2,FBID); |
786 | } |
787 | else intl = Standard_False; |
788 | } |
789 | } |
790 | else if (C2.IsNull() || (Nb2 == 1 && !H2.Domain(iH2,1).HasFirstPoint())) { |
81bba717 |
791 | // It is checked if the point 2d of the degenerated is in the face. |
7fd59977 |
792 | if (C2.IsNull()) { |
793 | gp_Pnt2d p2d2 = CD->Get2dPoints(0,2); |
794 | TopAbs_State situ = I2->Classify(p2d2,1.e-8,0); |
795 | if(situ == TopAbs_OUT) return Standard_False; |
796 | } |
797 | |
81bba717 |
798 | // Parsing of domains by increasing parameters, |
7fd59977 |
799 | if(!Tri(H1,iH1,Ind1,wref,0.,pitol,Nb1)) return 0; |
81bba717 |
800 | // Filling of SurfData |
7fd59977 |
801 | for(Standard_Integer i = 1; i <= Nb1; i++) { |
802 | const HatchGen_Domain& Dom1 = H1.Domain(iH1,Ind1(i)); |
803 | FillSD(DStr,CD,M1,Dom1,Dom1.FirstPoint().Parameter(),1,1,pitol,bout1); |
804 | FillSD(DStr,CD,M1,Dom1,Dom1.SecondPoint().Parameter(),0,1,pitol,bout2); |
805 | SetData.Append(CD); |
806 | CD = CpSD(DStr,CD); |
807 | } |
808 | if(intf) { |
809 | Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(1); |
810 | ChFiDS_CommonPoint& CP1 = sd->ChangeVertexFirstOnS1(); |
811 | if(CP1.IsOnArc() && Spine->FirstStatus() == ChFiDS_OnSame) { |
812 | intf = !SearchFace(Spine,CP1,F1,FBID); |
813 | } |
814 | else intf = Standard_False; |
815 | } |
816 | if(intl) { |
817 | Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(SetData.Length()); |
818 | ChFiDS_CommonPoint& CP1 = sd->ChangeVertexLastOnS1(); |
819 | if(CP1.IsOnArc() && Spine->LastStatus() == ChFiDS_OnSame) { |
820 | intl = !SearchFace(Spine,CP1,F1,FBID); |
821 | } |
822 | else intl = Standard_False; |
823 | } |
824 | } |
825 | else { |
826 | |
81bba717 |
827 | // Parsing of domains by increasing parameters, |
828 | // if there is a 2d circle on a plane, one goes on 2D line of opposite face. |
7fd59977 |
829 | Standard_Real period1 = 0., period2 = 0.; |
830 | if(ll1.IsPeriodic()) { |
831 | if(!Tri(H2,iH2,Ind2,wref,0.,pitol,Nb2)) return 0; |
832 | period1 = ll1.Period(); |
833 | if(!Tri(H1,iH1,Ind1,wref,period1,pitol,Nb1)) return 0; |
834 | } |
835 | else{ |
836 | if(!Tri(H1,iH1,Ind1,wref,0.,pitol,Nb1)) return 0; |
837 | if(ll2.IsPeriodic()) { period2 = ll2.Period(); } |
838 | if(!Tri(H2,iH2,Ind2,wref,period2,pitol,Nb2)) return 0; |
839 | } |
840 | |
841 | |
81bba717 |
842 | // Filling of SurfData |
7fd59977 |
843 | TColStd_SequenceOfInteger ion1, ion2; |
844 | for(Standard_Integer i = 1; i <= Nb1; i++) { |
845 | const HatchGen_Domain& Dom1 = H1.Domain(iH1,Ind1(i)); |
846 | Standard_Integer nbcoup1 = 1; |
847 | Standard_Boolean acheval1 = AdjustParam(Dom1,f1,l1,wref,period1,pitol); |
848 | if(acheval1) nbcoup1 = 2; |
849 | for (Standard_Integer icoup1 = 1; icoup1 <= nbcoup1; icoup1++) { |
850 | for(Standard_Integer j = 1; j <= Nb2; j++) { |
851 | const HatchGen_Domain& Dom2 = H2.Domain(iH2,j); |
852 | Standard_Integer nbcoup2 = 1; |
853 | Standard_Boolean acheval2 = |
854 | AdjustParam(Dom2,f2,l2,wref,period2,pitol); |
855 | if(acheval2) nbcoup2 = 2; |
856 | for (Standard_Integer icoup2 = 1; icoup2 <= nbcoup2; icoup2++) { |
857 | if(f2 <= l1 && f1 <= l2) { |
858 | if (f1 >= f2 - tol2d) |
859 | FillSD(DStr,CD,M1,Dom1,f1,1,1,pitol,bout1); |
860 | if (f2 >= f1 - tol2d) |
861 | FillSD(DStr,CD,M2,Dom2,f2,1,2,pitol,bout1); |
862 | if (l1 >= l2 - tol2d) |
863 | FillSD(DStr,CD,M2,Dom2,l2,0,2,pitol,bout2); |
864 | if (l2 >= l1 - tol2d) |
865 | FillSD(DStr,CD,M1,Dom1,l1,0,1,pitol,bout2); |
866 | SetData.Append(CD); |
867 | CD = CpSD(DStr,CD); |
868 | ion1.Append(i); |
869 | ion2.Append(j); |
870 | } |
871 | f2 += period2; |
872 | l2 += period2; |
873 | } |
874 | } |
875 | f1 += period1; |
876 | l1 += period1; |
877 | } |
878 | } |
879 | |
81bba717 |
880 | // Processing of extensions. |
881 | // Do not truncate, otherwise, problems of intersection for PerformCorner |
7fd59977 |
882 | // ----------------------------------------------------------------- |
81bba717 |
883 | // After call of SplitKPart in PerformSetOfKPart, spines have been |
884 | // extended to the extremities by methods Extent to permit |
885 | // intersections. Extensions of SurfData are preserved. |
7fd59977 |
886 | |
887 | if(intf) { |
81bba717 |
888 | // We are at the beginning of the spine |
7fd59977 |
889 | //------------------------- |
890 | Standard_Integer ifirst = 0; |
891 | Standard_Real dist = RealLast(), ptg, dsp; |
892 | const BRepAdaptor_Curve& ed = Spine->CurrentElementarySpine(Iedge); |
893 | for (Standard_Integer i1 = 1; i1 <= SetData.Length(); i1++) { |
894 | Handle(ChFiDS_SurfData)& CD1 = SetData.ChangeValue(i1); |
895 | ChFiDS_CommonPoint& CP1 = CD1->ChangeVertexFirstOnS1(); |
896 | ChFiDS_CommonPoint& CP2 = CD1->ChangeVertexFirstOnS2(); |
897 | if(CP1.IsOnArc()&&!SearchFace(Spine,CP1,F1,FBID)) { |
898 | ptg = CD1->InterferenceOnS1().FirstParameter(); |
899 | dsp = ComputeAbscissa(ed,ptg); |
900 | if(Abs(dsp) < dist) { |
901 | ifirst = i1; |
902 | dist = Abs(dsp); |
903 | } |
904 | } |
905 | else if(CP2.IsOnArc()&&!SearchFace(Spine,CP2,F2,FBID)) { |
906 | ptg = CD1->InterferenceOnS2().FirstParameter(); |
907 | dsp = ComputeAbscissa(ed,ptg); |
908 | if(Abs(dsp) < dist) { |
909 | ifirst = i1; |
910 | dist = Abs(dsp); |
911 | } |
912 | } |
913 | } |
914 | if (ifirst>1) { |
915 | SetData.Remove(1,ifirst-1); |
916 | ion1.Remove(1,ifirst-1); |
917 | ion2.Remove(1,ifirst-1); |
918 | } |
919 | if(SetData.IsEmpty()) return Standard_False; |
920 | Handle(ChFiDS_SurfData)& CD2 = SetData.ChangeValue(1); |
921 | ChFiDS_CommonPoint& CP1 = CD2->ChangeVertexFirstOnS1(); |
922 | ChFiDS_CommonPoint& CP2 = CD2->ChangeVertexFirstOnS2(); |
923 | ChFiDS_CommonPoint sov; |
924 | |
925 | if(CP1.IsOnArc() && CP2.IsOnArc()) { |
926 | intf = !SearchFace(Spine,CP1,F1,FBID) && !SearchFace(Spine,CP2,F2,FBID); |
927 | } |
928 | else if(CP1.IsOnArc()) { |
929 | sov = CP2; |
930 | if(!SearchFace(Spine,CP1,F1,FBID)) { |
931 | FillSD(DStr,CD2,M2,H2.Domain(iH2,Ind2(ion2.First())), |
932 | H2.Domain(iH2,Ind2(ion2.First())).FirstPoint().Parameter(),1,2,pitol,bout1); |
933 | if(!CP2.IsOnArc() || (CP2.IsOnArc() && SearchFace(Spine,CP2,F2,FBID))) { |
934 | CP2 = sov; |
935 | if(Spine->FirstStatus() != ChFiDS_OnSame) { |
936 | CD2->ChangeInterference(2). |
937 | SetParameter(CD2->Interference(1).Parameter(1),1); |
938 | intf = Standard_False; |
939 | } |
940 | } |
941 | } |
942 | else intf = Standard_False; |
943 | } |
944 | else if(CP2.IsOnArc()) { |
945 | sov = CP1; |
946 | if(!SearchFace(Spine,CP2,F2,FBID)) { |
947 | FillSD(DStr,CD2,M1,H1.Domain(iH1,Ind1(ion1.First())), |
948 | H1.Domain(iH1,Ind1(ion1.First())).FirstPoint().Parameter(),1,1,pitol,bout1); |
949 | if(!CP1.IsOnArc() || (CP1.IsOnArc() && SearchFace(Spine,CP1,F1,FBID))) { |
950 | CP1 = sov; |
951 | if(Spine->FirstStatus() != ChFiDS_OnSame) { |
952 | CD2->ChangeInterference(1). |
953 | SetParameter(CD2->Interference(2).Parameter(1),1); |
954 | intf = Standard_False; |
955 | } |
956 | } |
957 | } |
958 | else intf = Standard_False; |
959 | } |
960 | // select <onS> switcher so that to get on spine params from |
961 | // Interference with a face where both edges at corner are OnSame |
962 | // eap occ293 |
963 | if (intf && Spine->FirstStatus() == ChFiDS_OnSame) { |
964 | TopoDS_Edge threeE[3]; |
965 | ChFi3d_cherche_element(bout1,support,F1,threeE[0],boutemp); |
966 | ChFi3d_cherche_element(bout1,support,F2,threeE[1],boutemp); |
967 | threeE[2] = support; |
968 | if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame) |
969 | onS = 1; |
970 | else |
971 | onS = 2; |
0797d9d3 |
972 | #ifdef OCCT_DEBUG |
7fd59977 |
973 | if (threeE[0].IsSame(threeE[1])) |
974 | cout << "SplitKPart(), wrong corner vertex at switcher search" << endl; |
975 | #endif |
976 | cntlFiOnS = 3 - onS; |
977 | } |
978 | } |
979 | if(intl) { |
81bba717 |
980 | // we are at the end of the spine |
7fd59977 |
981 | //----------------------- |
982 | Standard_Integer ilast = 0; |
983 | Standard_Real dist = RealLast(), ptg, dsp; |
984 | Standard_Real f = Spine->FirstParameter(Iedge); |
985 | Standard_Real l = Spine->LastParameter(Iedge); |
986 | const BRepAdaptor_Curve& ed = Spine->CurrentElementarySpine(Iedge); |
987 | for (Standard_Integer i2 = 1; i2<= SetData.Length(); i2++) { |
988 | Handle(ChFiDS_SurfData)& CD3 = SetData.ChangeValue(i2); |
989 | ChFiDS_CommonPoint& CP1 = CD3->ChangeVertexLastOnS1(); |
990 | ChFiDS_CommonPoint& CP2 = CD3->ChangeVertexLastOnS2(); |
991 | if(CP1.IsOnArc()&&!SearchFace(Spine,CP1,F1,FBID)) { |
992 | ptg = CD3->InterferenceOnS1().LastParameter(); |
993 | dsp = -ComputeAbscissa(ed,ptg) - f + l; |
994 | if(Abs(dsp) < dist) { |
995 | ilast = i2; |
996 | dist = Abs(dsp); |
997 | } |
998 | } |
999 | else if(CP2.IsOnArc()&&!SearchFace(Spine,CP2,F2,FBID)) { |
1000 | ptg = CD3->InterferenceOnS2().LastParameter(); |
1001 | dsp = -ComputeAbscissa(ed,ptg) - f + l; |
1002 | if(Abs(dsp) < dist) { |
1003 | ilast = i2; |
1004 | dist = Abs(dsp); |
1005 | } |
1006 | } |
1007 | } |
1008 | Standard_Integer lll = SetData.Length(); |
1009 | if (ilast<lll) { |
1010 | SetData.Remove(ilast+1, lll); |
1011 | ion1.Remove(ilast+1, lll); |
1012 | ion2.Remove(ilast+1, lll); |
1013 | } |
1014 | if(SetData.IsEmpty()) return Standard_False; |
1015 | Handle(ChFiDS_SurfData)& CD4 = SetData.ChangeValue(SetData.Length()); |
1016 | ChFiDS_CommonPoint& CP1 = CD4->ChangeVertexLastOnS1(); |
1017 | ChFiDS_CommonPoint& CP2 = CD4->ChangeVertexLastOnS2(); |
1018 | ChFiDS_CommonPoint sov; |
1019 | if(CP1.IsOnArc() && CP2.IsOnArc()) { |
1020 | intl = !SearchFace(Spine,CP1,F1,FBID) && !SearchFace(Spine,CP2,F2,FBID); |
1021 | } |
1022 | else if(CP1.IsOnArc()) { |
1023 | sov = CP2; |
1024 | if(!SearchFace(Spine,CP1,F1,FBID)) { |
1025 | FillSD(DStr,CD4,M2,H2.Domain(iH2,Ind2(ion2.Last())), |
1026 | H2.Domain(iH2,Ind2(ion2.Last())).SecondPoint().Parameter(),0,2,pitol,bout2); |
1027 | if(!CP2.IsOnArc() || (CP2.IsOnArc() && SearchFace(Spine,CP2,F2,FBID))) { |
1028 | CP2 = sov; |
1029 | if(Spine->LastStatus() != ChFiDS_OnSame) { |
1030 | CD4->ChangeInterference(2). |
1031 | SetParameter(CD4->Interference(1).Parameter(0),0); |
1032 | intl = Standard_False; |
1033 | } |
1034 | } |
1035 | } |
1036 | else intl = Standard_False; |
1037 | } |
1038 | else if(CP2.IsOnArc()) { |
1039 | sov = CP1; |
1040 | if(!SearchFace(Spine,CP2,F2,FBID)) { |
1041 | FillSD(DStr,CD4,M1,H1.Domain(iH1,Ind1(ion1.Last())), |
1042 | H1.Domain(iH1,Ind1(ion1.Last())).SecondPoint().Parameter(),0,1,pitol,bout2); |
1043 | if(!CP1.IsOnArc() || (CP1.IsOnArc() && SearchFace(Spine,CP1,F1,FBID))) { |
1044 | CP1 = sov; |
1045 | if(Spine->LastStatus() != ChFiDS_OnSame) { |
1046 | CD4->ChangeInterference(1). |
1047 | SetParameter(CD4->Interference(2).Parameter(0),0); |
1048 | intl = Standard_False; |
1049 | } |
1050 | } |
1051 | } |
1052 | else intl = Standard_False; |
1053 | } |
1054 | |
1055 | // select <onS> switcher so that to get on spine params from |
1056 | // Interference with a face where both edges at corner are OnSame |
1057 | // eap occ293 |
1058 | if (intl && Spine->LastStatus() == ChFiDS_OnSame) { |
1059 | TopoDS_Edge threeE[3]; |
1060 | ChFi3d_cherche_element(bout2,support,F1,threeE[0],boutemp); |
1061 | ChFi3d_cherche_element(bout2,support,F2,threeE[1],boutemp); |
1062 | threeE[2] = support; |
1063 | if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame) |
1064 | onS = 1; |
1065 | else |
1066 | onS = 2; |
0797d9d3 |
1067 | #ifdef OCCT_DEBUG |
7fd59977 |
1068 | if (threeE[0].IsSame(threeE[1])) |
1069 | cout << "SplitKPart(), wrong corner vertex at switcher search" << endl; |
1070 | #endif |
1071 | cntlFiOnS = 3 - onS; |
1072 | } |
1073 | } |
1074 | } |
1075 | |
1076 | if(!intf) { |
81bba717 |
1077 | // SurfData are entirely suspended before the beginning of the edge. |
7fd59977 |
1078 | Standard_Boolean okdoc = SetData.IsEmpty(); |
1079 | Standard_Integer i = 1; |
1080 | while(!okdoc) { |
1081 | Handle(ChFiDS_SurfData)& CD5 = SetData.ChangeValue(i); |
1082 | Standard_Real ltg = CD5->Interference(onS).LastParameter(); |
1083 | Standard_Real Nl = ComputeAbscissa(Spine->CurrentElementarySpine(Iedge),ltg); |
1084 | if (Nl < -tolesp) SetData.Remove(i); |
1085 | else i++; |
1086 | okdoc = (SetData.IsEmpty() || i > SetData.Length()); |
1087 | } |
1088 | } |
1089 | if(!intl) { |
81bba717 |
1090 | // SurfData are entirely suspended after the end of the edge. |
7fd59977 |
1091 | Standard_Boolean okdoc = SetData.IsEmpty(); |
1092 | Standard_Integer i = 1; |
1093 | while(!okdoc) { |
1094 | Handle(ChFiDS_SurfData)& CD6 = SetData.ChangeValue(i); |
1095 | Standard_Real ftg = CD6->Interference(onS).FirstParameter(); |
1096 | Standard_Real f = Spine->FirstParameter(Iedge); |
1097 | Standard_Real l = Spine->LastParameter(Iedge); |
1098 | Standard_Real Nl = ComputeAbscissa(Spine->CurrentElementarySpine(Iedge),ftg); |
1099 | if (Nl > (l - f + tolesp)) SetData.Remove(i); |
1100 | else i++; |
1101 | okdoc = (SetData.IsEmpty() || i > SetData.Length()); |
1102 | } |
1103 | } |
81bba717 |
1104 | // Add parameters of the spine on SurfDatas. |
7fd59977 |
1105 | // for (Standard_Integer i = 1; i <= SetData.Length(); i++) { |
1106 | Standard_Integer i; |
1107 | for ( i = 1; i <= SetData.Length(); i++) { |
1108 | Standard_Boolean pokdeb = 0, pokfin = 0; |
1109 | Handle(ChFiDS_SurfData)& CD7 = SetData.ChangeValue(i); |
1110 | Standard_Real ftg = CD7->Interference(onS).FirstParameter(); |
1111 | Standard_Real ltg = CD7->Interference(onS).LastParameter(); |
1112 | Standard_Real fsp = ParamOnSpine(DStr,ftg,CD7,Spine,Iedge,intf,intl,tolesp,pokdeb); |
1113 | if(!pokdeb) fsp = ResetProl(DStr,CD7,Spine,Iedge,1); |
1114 | Standard_Real lsp = ParamOnSpine(DStr,ltg,CD7,Spine,Iedge,intf,intl,tolesp,pokfin); |
1115 | if(!pokfin) lsp = ResetProl(DStr,CD7,Spine,Iedge,0); |
1116 | if(Spine->IsPeriodic() && Iedge == Spine->NbEdges() && lsp < fsp) { |
1117 | lsp += Spine->Period(); |
1118 | } |
1119 | else if(Spine->IsPeriodic() && Iedge == 1 && lsp < fsp) { |
1120 | fsp -= Spine->Period(); |
1121 | } |
1122 | CD7->FirstSpineParam(fsp); |
1123 | CD7->LastSpineParam (lsp); |
1124 | } |
1125 | |
1126 | if (intf && !SetData.IsEmpty()) { |
81bba717 |
1127 | // extension of the spine |
7fd59977 |
1128 | Spine->SetFirstParameter(SetData.First()->FirstSpineParam()); |
1129 | } |
1130 | else { |
81bba717 |
1131 | // Trnncation at the beginning. |
7fd59977 |
1132 | for (i = 1; i <= SetData.Length(); i++) { |
1133 | Handle(ChFiDS_SurfData)& CD8 = SetData.ChangeValue(i); |
1134 | Standard_Real fsp = CD8->FirstSpineParam(); |
1135 | Standard_Real lsp = CD8->LastSpineParam(); |
1136 | if (lsp > Spine->FirstParameter(Iedge)) { |
1137 | if (fsp > Spine->FirstParameter(Iedge)) { |
1138 | break; |
1139 | } |
1140 | else { |
1141 | Trunc(CD8,Spine,S1,S2,Iedge,1,cntlFiOnS); |
1142 | break; |
1143 | } |
1144 | } |
1145 | } |
1146 | if (i > 1 ) { |
1147 | SetData.Remove(1,i-1); |
1148 | } |
1149 | } |
1150 | |
1151 | |
1152 | if (intl && !SetData.IsEmpty()) { |
81bba717 |
1153 | // extension of the spine |
7fd59977 |
1154 | Spine->SetLastParameter(SetData.Last()->LastSpineParam()); |
1155 | } |
1156 | else { |
81bba717 |
1157 | // Truncation at the end. |
7fd59977 |
1158 | for (i = SetData.Length(); i >= 1; i--) { |
1159 | Handle(ChFiDS_SurfData)& CD9 = SetData.ChangeValue(i); |
1160 | Standard_Real fsp = CD9->FirstSpineParam(); |
1161 | Standard_Real lsp = CD9->LastSpineParam(); |
1162 | if (fsp < Spine->LastParameter(Iedge)) { |
1163 | if (lsp < Spine->LastParameter(Iedge)) { |
1164 | break; |
1165 | } |
1166 | else { |
1167 | Trunc(CD9,Spine,S1,S2,Iedge,0,cntlFiOnS); |
1168 | break; |
1169 | } |
1170 | } |
1171 | } |
1172 | if (i < SetData.Length()) { |
1173 | SetData.Remove(i+1,SetData.Length()); |
1174 | } |
1175 | } |
0797d9d3 |
1176 | #ifdef OCCT_DEBUG |
7fd59977 |
1177 | if(ChFi3d_GettraceDRAWFIL()) { |
1178 | for (i = 1; i <= SetData.Length(); i++) { |
1179 | ChFi3d_CheckSurfData(DStr,SetData.Value(i)); |
1180 | } |
1181 | } |
1182 | #endif |
1183 | return Standard_True; |
1184 | } |