1 // File: ChFi3d_Builder_SpKP.cxx
2 // Created: Thu Jan 20 14:41:30 1994
3 // Author: Isabelle GRIGNON
6 #include <Standard_NotImplemented.hxx>
7 #include <Precision.hxx>
8 #include <TColStd_SequenceOfInteger.hxx>
9 #include <TColStd_Array1OfInteger.hxx>
10 #include <TColStd_Array1OfReal.hxx>
12 #include <gp_Pnt2d.hxx>
13 #include <gp_Dir2d.hxx>
15 #include <gp_Circ.hxx>
16 #include <TColgp_Array1OfPnt2d.hxx>
19 #include <Geom2d_Curve.hxx>
20 #include <Geom2d_Line.hxx>
21 #include <Geom2d_BezierCurve.hxx>
22 #include <Geom2d_BSplineCurve.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_Surface.hxx>
26 #include <GeomAbs_CurveType.hxx>
27 #include <GeomAbs_SurfaceType.hxx>
28 #include <GeomAdaptor_Curve.hxx>
29 #include <Geom2dAdaptor_Curve.hxx>
30 #include <Geom2dAdaptor_HCurve.hxx>
32 #include <GeomAdaptor_HSurface.hxx>
33 #include <BRepAdaptor_Curve2d.hxx>
34 #include <BRepAdaptor_HCurve.hxx>
35 #include <BRepAdaptor_HCurve2d.hxx>
36 #include <BRep_Tool.hxx>
37 #include <HatchGen_PointOnElement.hxx>
38 #include <HatchGen_PointOnHatching.hxx>
39 #include <HatchGen_Domain.hxx>
40 #include <Geom2dHatch_Intersector.hxx>
41 #include <Geom2dHatch_Hatcher.hxx>
44 #include <TopoDS_Edge.hxx>
46 #include <TopOpeBRepDS_Curve.hxx>
47 #include <TopOpeBRepDS_Surface.hxx>
49 #include <ChFiKPart_RstMap.hxx>
51 #include <ChFi3d_Builder.jxx>
52 #include <ChFi3d_Builder_0.hxx>
54 extern Standard_Boolean ChFi3d_GettraceDRAWFIL();
55 extern void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr,
56 const Handle(ChFiDS_SurfData)& Data);
58 //=======================================================================
60 //purpose : Calculate the Transition from start point.
61 //=======================================================================
63 static TopAbs_Orientation CompTra (const TopAbs_Orientation O1,
64 const TopAbs_Orientation O2,
65 const Standard_Boolean isfirst)
67 if(isfirst) return TopAbs::Reverse(TopAbs::Compose(O1,O2));
68 else return TopAbs::Compose(O1,O2);
72 //=======================================================================
73 //function : CompCommonpoint
74 //purpose : Fill the commonpoint in case of a vertex.
75 //=======================================================================
77 static void CompCommonPoint (ChFiDS_CommonPoint& FilPoint,
78 const TopoDS_Edge& arc,
79 const HatchGen_PointOnElement& PE,
80 const TopAbs_Orientation Or)
82 TopAbs_Orientation pos = PE.Position();
84 if ( pos == TopAbs_FORWARD ) {
85 V = TopExp::FirstVertex(arc);
88 V = TopExp::LastVertex(arc);
90 FilPoint.SetVertex(V);
91 FilPoint.SetArc(Precision::PIntersection(),arc,
92 PE.Parameter(),TopAbs::Compose(arc.Orientation(),Or));
96 //=======================================================================
98 //purpose : Construct new SurfData sharing faces, surface and curves.
99 //=======================================================================
101 static ChFiDS_FaceInterference CpInterf (TopOpeBRepDS_DataStructure& DStr,
102 const ChFiDS_FaceInterference& FI)
104 ChFiDS_FaceInterference newF = FI;
105 const TopOpeBRepDS_Curve& toc = DStr.Curve(FI.LineIndex());
106 Handle(Geom_Curve) newC;
107 if (!toc.Curve().IsNull())
108 newC = Handle(Geom_Curve)::DownCast(toc.Curve()->Copy());
109 newF.SetLineIndex(DStr.AddCurve(TopOpeBRepDS_Curve(newC,toc.Tolerance())));
111 if (!FI.PCurveOnFace().IsNull())
112 newF.ChangePCurveOnFace() =
113 Handle(Geom2d_Curve)::DownCast(FI.PCurveOnFace()->Copy());
114 if (!FI.PCurveOnSurf().IsNull())
115 newF.ChangePCurveOnSurf() =
116 Handle(Geom2d_Curve)::DownCast(FI.PCurveOnSurf()->Copy());
121 //=======================================================================
123 //purpose : Construct new SurfData sharing faces, surface and curves.
124 //=======================================================================
126 static Handle(ChFiDS_SurfData) CpSD ( TopOpeBRepDS_DataStructure& DStr,
127 const Handle(ChFiDS_SurfData)& Data)
129 Handle(ChFiDS_SurfData) newData = new ChFiDS_SurfData();
130 const TopOpeBRepDS_Surface& tos = DStr.Surface(Data->Surf());
131 Handle(Geom_Surface) newS = Handle(Geom_Surface)::DownCast(tos.Surface()->Copy());
132 Standard_Real tol = tos.Tolerance();
133 newData->ChangeSurf(DStr.AddSurface(TopOpeBRepDS_Surface(newS,tol)));
134 newData->ChangeIndexOfS1(Data->IndexOfS1());
135 newData->ChangeIndexOfS2(Data->IndexOfS2());
136 newData->ChangeOrientation() = Data->Orientation();
137 newData->ChangeInterferenceOnS1() = CpInterf(DStr,Data->InterferenceOnS1());
138 newData->ChangeInterferenceOnS2() = CpInterf(DStr,Data->InterferenceOnS2());
142 //=======================================================================
143 //function : AdjustParam
145 //=======================================================================
147 static Standard_Boolean AdjustParam(const HatchGen_Domain& Dom,
150 const Standard_Real wref,
151 const Standard_Real period,
152 const Standard_Real pitol)
154 if(Dom.HasFirstPoint())
155 f = Dom.FirstPoint().Parameter();
157 if(Dom.HasSecondPoint())
158 l = Dom.SecondPoint().Parameter();
160 if (period == 0.) return Standard_False;
162 f = ElCLib::InPeriod(f,wref - pitol, wref + period - pitol);
163 l = ElCLib::InPeriod(l,wref + pitol, wref + period + pitol);
166 return Standard_True;
168 return Standard_False;
170 //=======================================================================
171 //function : ComputeAbscissa
173 //=======================================================================
175 static Standard_Real ComputeAbscissa(const BRepAdaptor_Curve& C,
176 const Standard_Real U)
178 switch (C.GetType()) {
182 return C.Circle().Radius()*U;
186 Standard_NotImplemented::Raise("calculate abscisse non-processed");
190 //=======================================================================
191 //function : ParamOnSpine
193 //=======================================================================
195 static Standard_Real ParamOnSpine(const TopOpeBRepDS_DataStructure& DStr,
196 const Standard_Real ptg,
197 const Handle(ChFiDS_SurfData)& CD,
198 const Handle(ChFiDS_Spine)& Spine,
199 const Standard_Integer iedge,
200 const Standard_Boolean intf,
201 const Standard_Boolean intl,
202 const Standard_Real tol,
203 Standard_Boolean& pok)
206 Standard_Real f = Spine->FirstParameter(iedge);
207 Standard_Real l = Spine->LastParameter(iedge);
209 Nl = ComputeAbscissa(Spine->CurrentElementarySpine(iedge),ptg) + f;
210 if ((Nl >= (f - tol) || intf) &&
211 (Nl <= (l + tol) || intl) ) {
216 //construction of the plane containing the section of CD with parameter ptg.
219 Handle(Geom_Curve) c3d;
220 if (CD->InterferenceOnS1().LineIndex() != 0) {
221 c3d = DStr.Curve(CD->InterferenceOnS1().LineIndex()).Curve();
224 c3d = DStr.Curve(CD->InterferenceOnS2().LineIndex()).Curve();
228 gp_Pln nlp(PP,gp_Dir(VV));
229 Handle(Geom_Plane) pln = new Geom_Plane(nlp);
230 Handle(GeomAdaptor_HSurface)
231 plan = new GeomAdaptor_HSurface(GeomAdaptor_Surface(pln));
233 // intersection plane spine.
234 Standard_Boolean found = Standard_False;
235 Standard_Boolean fini = Standard_False;
236 Standard_Integer sens = 1;
237 if (Nl <= f) sens = -1;
238 Standard_Integer ii = iedge + sens;
239 if (Spine->IsPeriodic()) {
240 if (ii <= 0) ii += Spine->NbEdges();
241 if (ii > Spine->NbEdges()) ii -= Spine->NbEdges();
243 else if(ii < 1 || ii > Spine->NbEdges()) {
247 Handle(BRepAdaptor_HCurve) HE = new BRepAdaptor_HCurve();
248 BRepAdaptor_Curve& CE = HE->ChangeCurve();
250 while (!found && !fini) {
251 TopAbs_Orientation O = Spine->Edges(ii).Orientation();
252 Standard_Boolean First = ((O == TopAbs_FORWARD && sens == 1) ||
253 (O == TopAbs_REVERSED && sens == -1));
254 CE.Initialize(Spine->Edges(ii));
255 Standard_Real tolc = CE.Resolution(tol);
256 found = ChFi3d_InterPlaneEdge(plan,HE,Nl,First,tolc);
257 gp_Pnt point = CE.Value(Nl);
259 cout<<"******* ParamOnSpine() for edge "<<iedge<<endl;
261 cout<<"point ped "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl;
263 if(found) Nl = Spine->Absc(Nl,ii);
264 point = Spine->Value(Nl);
266 if (found) cout << "found by edge " << ii << " : ";
268 cout<<"point psp "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl;
273 if (Spine->IsPeriodic()) {
274 if (ii <= 0) ii += Spine->NbEdges();
275 if (ii > Spine->NbEdges()) ii -= Spine->NbEdges();
276 fini = (ii == iedge);
279 fini = (ii < 1 || ii > Spine->NbEdges());
287 //=======================================================================
288 //function : YaUnVoisin
290 //=======================================================================
292 static Standard_Boolean YaUnVoisin(const Handle(ChFiDS_Spine)& Spine,
293 const Standard_Integer iedge,
294 Standard_Integer& ivois,
295 const Standard_Boolean isfirst)
297 Standard_Integer nbed = Spine->NbEdges();
298 if(nbed == 1) return 0;
299 Standard_Boolean periodic = Spine->IsPeriodic();
300 if(isfirst) ivois = iedge - 1;
301 else ivois = iedge + 1;
303 if(ivois == 0) ivois = nbed;
304 if(ivois == nbed+1) ivois = 1;
306 return (ivois > 0 && ivois <= nbed);
309 //=======================================================================
312 //=======================================================================
314 void ChFi3d_Builder::Trunc(const Handle(ChFiDS_SurfData)& SD,
315 const Handle(ChFiDS_Spine)& Spine,
316 const Handle(Adaptor3d_HSurface)& S1,
317 const Handle(Adaptor3d_HSurface)& S2,
318 const Standard_Integer iedge,
319 const Standard_Boolean isfirst,
320 const Standard_Integer cntlFiOnS)
322 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
323 // Return points and tangents on edge and spine.
324 Standard_Real wtg = SD->InterferenceOnS1().Parameter(isfirst);
325 Standard_Boolean bid;
326 Standard_Real wsp = ParamOnSpine(DStr,wtg,SD,Spine,iedge,0,0,tolesp,bid);
329 TopoDS_Vertex bout1,bout2,boutemp;
332 const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge);
333 //Modif against Vertex isolated on spine
334 TopoDS_Edge support = bc.Edge();
335 TopExp::Vertices(support,bout1,bout2);
336 if (support.Orientation() == TopAbs_REVERSED) {
345 Standard_Real edf = bc.FirstParameter(), edl = bc.LastParameter();
346 Standard_Real edglen = edl - edf;
347 if(Spine->Edges(iedge).Orientation() == TopAbs_FORWARD) {
348 bc.D1(wtg+edf,ped,ded);
351 bc.D1(-wtg+edl,ped,ded);
354 Spine->D1(wsp,psp,dsp);
356 const Handle(Geom_Surface)& surf = DStr.Surface(SD->Surf()).Surface();
358 pp1 = SD->InterferenceOnS1().PCurveOnSurf()->Value(wtg);
359 pp2 = SD->InterferenceOnS2().PCurveOnSurf()->Value(wtg);
360 p1 = surf->Value(pp1.X(),pp1.Y());
361 p2 = surf->Value(pp2.X(),pp2.Y());
362 Standard_Boolean tron = Standard_False;
363 Standard_Real Ang = dsp.Angle(ded);
364 Standard_Real dis1 = psp.Distance(ped);
365 Standard_Real dis2 = p1.Distance(p2);
366 if(Ang > PI/18.) tron = Standard_True;
367 if(dis1 >= 0.1*dis2) tron = Standard_True;
368 Standard_Integer ivois;
369 if(!tron && YaUnVoisin(Spine,iedge,ivois,isfirst)) {
370 Handle(BRepAdaptor_HSurface) BS1 = Handle(BRepAdaptor_HSurface)::DownCast(S1);
371 Handle(BRepAdaptor_HSurface) BS2 = Handle(BRepAdaptor_HSurface)::DownCast(S2);
372 if(!BS1.IsNull() && !BS2.IsNull()) {
374 TopoDS_Face F1 = BS1->ChangeSurface().Face();
375 TopoDS_Face F2 = BS2->ChangeSurface().Face();
376 const ChFiDS_CommonPoint& cp1 = SD->Vertex(isfirst,1);
377 const ChFiDS_CommonPoint& cp2 = SD->Vertex(isfirst,2);
378 if(!(cp1.IsOnArc() && SearchFace(Spine,cp1,F1,FBID) ||
379 cp2.IsOnArc() && SearchFace(Spine,cp2,F2,FBID))) {
380 tron = ChFi3d_KParticular(Spine,ivois,BS1->ChangeSurface(),BS2->ChangeSurface());
384 //modification of lvt against isolated vertex
385 if(!tron && YaUnVoisin(Spine,iedge,ivois,isfirst)) {
386 TopTools_ListIteratorOfListOfShape It;
387 Standard_Integer nbed = -2;
388 for (It.Initialize(myVEMap(bout1));It.More();It.Next()) {
391 if(nbed<3) tron = Standard_True;
396 Standard_Real par = 0., x, y, dPar=0;
397 if(!isfirst) par = edglen;
399 // detect the case where FaceInterference ends before the place we are
400 // going to truncate SD. Then we cut so that FaceInterference length to
401 // be at least zero, not negative (eap, occ354)
402 Standard_Real fiPar = SD->Interference(cntlFiOnS).Parameter(!isfirst);
403 Standard_Boolean isTheCase = isfirst ? (par > fiPar) : (par < fiPar);
409 for (Standard_Integer i = 1; i <= 2; i++) {
410 SD->ChangeInterference(i).SetParameter(par,isfirst);
411 Handle(Geom2d_Curve) pc = SD->Interference(i).PCurveOnSurf();
412 pc->Value(par).Coord(x,y);
413 SD->ChangeVertex(isfirst,i).Reset();
414 SD->ChangeVertex(isfirst,i).SetPoint(surf->Value(x,y));
415 if(isfirst) SD->FirstSpineParam(Spine->FirstParameter(iedge)-dPar);
416 else SD->LastSpineParam (Spine->LastParameter(iedge) -dPar);
421 //=======================================================================
422 //function : ResetProl
424 //=======================================================================
426 static Standard_Real ResetProl(const TopOpeBRepDS_DataStructure& DStr,
427 const Handle(ChFiDS_SurfData)& CD,
428 const Handle(ChFiDS_Spine)& Spine,
429 const Standard_Integer iedge,
430 const Standard_Boolean isfirst)
432 const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge);
433 Standard_Real edglen = bc.LastParameter() - bc.FirstParameter();
434 const Handle(Geom_Surface)& surf = DStr.Surface(CD->Surf()).Surface();
435 Standard_Real par = 0., x, y;
436 if(!isfirst) par = edglen;
438 for (Standard_Integer i = 1; i <= 2; i++) {
439 CD->ChangeInterference(i).SetParameter(par,isfirst);
440 Handle(Geom2d_Curve) pc = CD->Interference(i).PCurveOnSurf();
441 pc->Value(par).Coord(x,y);
442 CD->ChangeVertex(isfirst,i).Reset();
443 CD->ChangeVertex(isfirst,i).SetPoint(surf->Value(x,y));
445 sppar = Spine->FirstParameter(iedge);
446 CD->FirstSpineParam(sppar);
449 sppar = Spine->LastParameter(iedge);
450 CD->LastSpineParam (sppar);
455 //=======================================================================
458 //=======================================================================
460 static Standard_Boolean Tri(const Geom2dHatch_Hatcher& H,
461 const Standard_Integer iH,
462 TColStd_Array1OfInteger& Ind,
463 const Standard_Real wref,
464 const Standard_Real period,
465 const Standard_Real pitol,
466 Standard_Integer& Nbdom)
468 // for (Standard_Integer i = 1; i <= Nbdom; i++) { Ind(i) = i; }
470 for ( i = 1; i <= Nbdom; i++) { Ind(i) = i; }
471 Standard_Real f1,f2,l;
472 Standard_Integer tmp;
473 Standard_Boolean Invert = Standard_True;
476 Invert = Standard_False;
477 for ( i = 1; i < Nbdom; i++) {
478 AdjustParam(H.Domain(iH,Ind(i)),f1,l,wref,period,pitol);
479 AdjustParam(H.Domain(iH,Ind(i+1)),f2,l,wref,period,pitol);
484 Invert = Standard_True;
489 Standard_Integer iSansFirst = 0, iSansLast = 0;
492 for ( i = 1; i <= Nbdom; i++) {
493 if (!H.Domain(iH,Ind(i)).HasFirstPoint()) {
496 if (!H.Domain(iH,Ind(i)).HasSecondPoint()) {
501 if (iSansFirst != 0) {
502 if (iSansLast == 0) {
504 cout<<"Parsing : Pb of Hatcher"<<endl;
508 HatchGen_Domain* Dom = ((HatchGen_Domain*) (void*) &H.Domain(iH,Ind(iSansFirst)));
509 HatchGen_PointOnHatching* PH =
510 ((HatchGen_PointOnHatching*) (void*) &H.Domain(iH,Ind(iSansLast)).FirstPoint());
511 Standard_Real NewPar = H.HatchingCurve(iH).FirstParameter() - period +
512 H.Domain(iH,Ind(iSansLast)).FirstPoint().Parameter();
513 PH->SetParameter(NewPar);
514 Dom->SetFirstPoint(*PH);
516 for (Standard_Integer k = iSansLast; k < Nbdom; k++) {
524 //=======================================================================
527 //=======================================================================
529 static void FillSD (TopOpeBRepDS_DataStructure& DStr,
530 Handle(ChFiDS_SurfData)& CD,
532 const HatchGen_Domain& Dom,
533 const Standard_Real ponH,
534 const Standard_Boolean isFirst,
535 const Standard_Integer ons,
536 const Standard_Real pitol,
537 const TopoDS_Vertex bout)
540 Standard_Integer opp = 3 - ons;
541 ChFiDS_CommonPoint& Pons = CD->ChangeVertex(isFirst,ons);
542 ChFiDS_CommonPoint& Popp = CD->ChangeVertex(isFirst,opp);
544 const HatchGen_PointOnHatching* pPH = 0;
545 if(isFirst && Dom.HasFirstPoint()) {
546 const HatchGen_PointOnHatching& PHtemp = Dom.FirstPoint();
549 else if(!isFirst && Dom.HasSecondPoint()) {
550 const HatchGen_PointOnHatching& PHtemp = Dom.SecondPoint();
554 Handle(Geom_Surface) Surf = DStr.Surface(CD->Surf()).Surface();
556 CD->ChangeInterference(ons).SetParameter(ponH,isFirst);
557 Handle(Geom2d_Curve) pcons = CD->Interference(ons).PCurveOnSurf();
558 pcons->Value(ponH).Coord(x,y);
559 CD->ChangeVertex(isFirst,ons).SetPoint(Surf->Value(x,y));
562 //Modification to find already existing vertexes
563 Standard_Integer LeType = 1;
564 Standard_Integer NbInt = pPH->NbPoints();
566 Standard_Boolean trouve = Standard_True;
568 TopoDS_Vertex V1 , V2;
569 Standard_Boolean suite = Standard_True;
571 const HatchGen_PointOnElement& PEtemp = pPH->Point(LeType);
573 Handle(BRepAdaptor_HCurve2d) HE = Handle(BRepAdaptor_HCurve2d::DownCast(M(IE)));
575 const TopoDS_Edge& Etemp = HE->ChangeCurve2d().Edge();
576 TopExp::Vertices(Etemp,V1,V2);
579 suite = Standard_False;
581 if(((V1.IsSame(bout)) || (V2.IsSame(bout))) && suite) {
582 trouve = Standard_True;
586 suite = Standard_True;
587 trouve = Standard_False;
590 trouve = Standard_True;
596 const HatchGen_PointOnElement& PE = pPH->Point(LeType);
597 Standard_Integer IE = PE.Index();
598 Handle(BRepAdaptor_HCurve2d)
599 HE = Handle(BRepAdaptor_HCurve2d)::DownCast(M(IE));
600 if(HE.IsNull()) return;
601 const TopoDS_Edge& E = HE->ChangeCurve2d().Edge();
603 if (PE.Position() != TopAbs_INTERNAL) {
604 TopAbs_Orientation O = CD->Interference(ons).Transition();
605 if(isFirst) O = TopAbs::Reverse(O);
606 CompCommonPoint(Pons,E,PE,O);
609 Pons.SetArc(pitol,E,PE.Parameter(),
610 CompTra(CD->Interference(ons).Transition(),E.Orientation(),isFirst));
612 Handle(Geom2d_Curve) pcadj = CD->Interference(ons).PCurveOnSurf();
613 pcadj->Value(ponH).Coord(x,y);
614 CD->ChangeInterference(ons).SetParameter(ponH,isFirst);
615 CD->ChangeVertex(isFirst,ons).SetPoint(Surf->Value(x,y));
617 if(!Popp.IsOnArc()) {
618 CD->ChangeInterference(opp).SetParameter(ponH,isFirst);
619 Handle(Geom2d_Curve) pcopp = CD->Interference(opp).PCurveOnSurf();
620 pcopp->Value(ponH).Coord(x,y);
621 CD->ChangeVertex(isFirst,opp).SetPoint(Surf->Value(x,y));
625 //=======================================================================
626 //function : SplitKPart
627 //purpose : Reconstruct SurfData depending on restrictions of faces.
628 //=======================================================================
630 Standard_Boolean ChFi3d_Builder::SplitKPart
631 (const Handle(ChFiDS_SurfData)& Data,
632 ChFiDS_SequenceOfSurfData& SetData,
633 const Handle(ChFiDS_Spine)& Spine,
634 const Standard_Integer Iedge,
635 const Handle(Adaptor3d_HSurface)& S1,
636 const Handle(Adaptor3d_TopolTool)& I1,
637 const Handle(Adaptor3d_HSurface)& S2,
638 const Handle(Adaptor3d_TopolTool)& I2,
639 Standard_Boolean& intf,
640 Standard_Boolean& intl)
642 //The the hatching of each faces is started by tangency lines.
644 Standard_Real pitol = Precision::PIntersection();
646 ChFiKPart_RstMap M1, M2;
648 Standard_Integer iH1 = 0,iH2 = 0;
650 Standard_Integer iH1,iH2;
652 Standard_Integer Nb1 = 1,Nb2 = 1;
654 // Cutting of tangency lines (hatching).
655 Geom2dHatch_Intersector Inter(pitol,pitol);
656 Geom2dHatch_Hatcher H1(Inter,tol2d,tolesp), H2(Inter,tol2d,tolesp);
658 Handle(Geom2d_Curve) C1 = Data->InterferenceOnS1().PCurveOnFace();
659 Geom2dAdaptor_Curve ll1;
662 for(I1->Init(); I1->More(); I1->Next()) {
663 Handle(BRepAdaptor_HCurve2d)
664 Bc = Handle(BRepAdaptor_HCurve2d)::DownCast(I1->Value());
665 Handle(Geom2dAdaptor_HCurve)
666 Gc = Handle(Geom2dAdaptor_HCurve)::DownCast(I1->Value());
667 if(Bc.IsNull()) ie = H1.AddElement(Gc->ChangeCurve2d(),TopAbs_FORWARD);
668 else ie = H1.AddElement(Bc->ChangeCurve2d(),
669 Bc->ChangeCurve2d().Edge().Orientation());
670 M1.Bind(ie,I1->Value());
673 H1.ComputeDomains(iH1);
674 if(!H1.IsDone(iH1)) return 0;
675 Nb1 = H1.NbDomains(iH1);
678 cout<<"SplitKPart : tangency line out of the face"<<endl;
680 return Standard_False;
684 Handle(Geom2d_Curve) C2 = Data->InterferenceOnS2().PCurveOnFace();
685 Geom2dAdaptor_Curve ll2;
688 for(I2->Init(); I2->More(); I2->Next()) {
689 Handle(BRepAdaptor_HCurve2d)
690 Bc = Handle(BRepAdaptor_HCurve2d)::DownCast(I2->Value());
691 Handle(Geom2dAdaptor_HCurve)
692 Gc = Handle(Geom2dAdaptor_HCurve)::DownCast(I2->Value());
693 if(Bc.IsNull()) ie = H2.AddElement(Gc->ChangeCurve2d(),TopAbs_FORWARD);
694 else ie = H2.AddElement(Bc->ChangeCurve2d(),
695 Bc->ChangeCurve2d().Edge().Orientation());
696 M2.Bind(ie,I2->Value());
699 H2.ComputeDomains(iH2);
700 if(!H2.IsDone(iH2)) return 0;
701 Nb2 = H2.NbDomains(iH2);
704 cout<<"SplitKPart : tangency line out of the face"<<endl;
706 return Standard_False;
710 //Return start and end vertexes of the Spine
711 TopoDS_Vertex bout1,bout2,boutemp;
712 const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(Iedge);
713 TopoDS_Edge support = bc.Edge();
714 TopExp::Vertices(support,bout1,bout2);
715 if(support.Orientation() == TopAbs_REVERSED) {
723 Handle(BRepAdaptor_HSurface)
724 bhs = Handle(BRepAdaptor_HSurface)::DownCast(S1);
725 if(!bhs.IsNull()) F1 = bhs->ChangeSurface().Face();
726 bhs = Handle(BRepAdaptor_HSurface)::DownCast(S2);
727 if(!bhs.IsNull()) F2 = bhs->ChangeSurface().Face();
730 // Restriction of SurfDatas by cut lines.
731 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
732 Handle(ChFiDS_SurfData) CD = Data;
733 CD->ChangeIndexOfS1(DStr.AddShape(F1));
734 CD->ChangeIndexOfS2(DStr.AddShape(F2));
736 Standard_Real f1,l1,f2,l2;
737 TColStd_Array1OfInteger Ind1(1,Nb1), Ind2(1,Nb2);
738 Standard_Real wref = 0.;
740 Standard_Integer onS = 1; // switcher of access to surfs of SurfData, eap occ293
741 Standard_Integer cntlFiOnS = 0; // FaceInterference to control length in OnSame
742 // situation, eap occ354
744 if (C1.IsNull() && C2.IsNull()) {
746 cout<<"SplitData : 2 zero lines hatching impossible"<<endl;
748 return Standard_False;
750 else if (C1.IsNull() || (Nb1 == 1 && !H1.Domain(iH1,1).HasFirstPoint())) {
751 // It is checked if the point 2d of the degenerated edge is in the face.
753 gp_Pnt2d p2d1 = CD->Get2dPoints(0,1);
754 TopAbs_State situ = I1->Classify(p2d1,1.e-8,0);
755 if(situ == TopAbs_OUT) return Standard_False;
758 // Parsing of domains by increasing parameters,
759 if(!Tri(H2,iH2,Ind2,wref,0.,pitol,Nb2)) return 0;
760 // Filling of SurfData
761 for(Standard_Integer i = 1; i <= Nb2; i++) {
762 const HatchGen_Domain& Dom2 = H2.Domain(iH2,Ind2(i));
763 FillSD(DStr,CD,M2,Dom2,Dom2.FirstPoint().Parameter(),1,2,pitol,bout1);
764 FillSD(DStr,CD,M2,Dom2,Dom2.SecondPoint().Parameter(),0,2,pitol,bout2);
769 Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(1);
770 ChFiDS_CommonPoint& CP2 = sd->ChangeVertexFirstOnS2();
771 if(CP2.IsOnArc() && Spine->FirstStatus() == ChFiDS_OnSame) {
772 intf = !SearchFace(Spine,CP2,F2,FBID);
774 else intf = Standard_False;
777 Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(SetData.Length());
778 ChFiDS_CommonPoint& CP2 = sd->ChangeVertexLastOnS2();
779 if(CP2.IsOnArc() && Spine->LastStatus() == ChFiDS_OnSame) {
780 intl = !SearchFace(Spine,CP2,F2,FBID);
782 else intl = Standard_False;
785 else if (C2.IsNull() || (Nb2 == 1 && !H2.Domain(iH2,1).HasFirstPoint())) {
786 // It is checked if the point 2d of the degenerated is in the face.
788 gp_Pnt2d p2d2 = CD->Get2dPoints(0,2);
789 TopAbs_State situ = I2->Classify(p2d2,1.e-8,0);
790 if(situ == TopAbs_OUT) return Standard_False;
793 // Parsing of domains by increasing parameters,
794 if(!Tri(H1,iH1,Ind1,wref,0.,pitol,Nb1)) return 0;
795 // Filling of SurfData
796 for(Standard_Integer i = 1; i <= Nb1; i++) {
797 const HatchGen_Domain& Dom1 = H1.Domain(iH1,Ind1(i));
798 FillSD(DStr,CD,M1,Dom1,Dom1.FirstPoint().Parameter(),1,1,pitol,bout1);
799 FillSD(DStr,CD,M1,Dom1,Dom1.SecondPoint().Parameter(),0,1,pitol,bout2);
804 Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(1);
805 ChFiDS_CommonPoint& CP1 = sd->ChangeVertexFirstOnS1();
806 if(CP1.IsOnArc() && Spine->FirstStatus() == ChFiDS_OnSame) {
807 intf = !SearchFace(Spine,CP1,F1,FBID);
809 else intf = Standard_False;
812 Handle(ChFiDS_SurfData)& sd = SetData.ChangeValue(SetData.Length());
813 ChFiDS_CommonPoint& CP1 = sd->ChangeVertexLastOnS1();
814 if(CP1.IsOnArc() && Spine->LastStatus() == ChFiDS_OnSame) {
815 intl = !SearchFace(Spine,CP1,F1,FBID);
817 else intl = Standard_False;
822 // Parsing of domains by increasing parameters,
823 // if there is a 2d circle on a plane, one goes on 2D line of opposite face.
824 Standard_Real period1 = 0., period2 = 0.;
825 if(ll1.IsPeriodic()) {
826 if(!Tri(H2,iH2,Ind2,wref,0.,pitol,Nb2)) return 0;
827 period1 = ll1.Period();
828 if(!Tri(H1,iH1,Ind1,wref,period1,pitol,Nb1)) return 0;
831 if(!Tri(H1,iH1,Ind1,wref,0.,pitol,Nb1)) return 0;
832 if(ll2.IsPeriodic()) { period2 = ll2.Period(); }
833 if(!Tri(H2,iH2,Ind2,wref,period2,pitol,Nb2)) return 0;
837 // Filling of SurfData
838 TColStd_SequenceOfInteger ion1, ion2;
839 for(Standard_Integer i = 1; i <= Nb1; i++) {
840 const HatchGen_Domain& Dom1 = H1.Domain(iH1,Ind1(i));
841 Standard_Integer nbcoup1 = 1;
842 Standard_Boolean acheval1 = AdjustParam(Dom1,f1,l1,wref,period1,pitol);
843 if(acheval1) nbcoup1 = 2;
844 for (Standard_Integer icoup1 = 1; icoup1 <= nbcoup1; icoup1++) {
845 for(Standard_Integer j = 1; j <= Nb2; j++) {
846 const HatchGen_Domain& Dom2 = H2.Domain(iH2,j);
847 Standard_Integer nbcoup2 = 1;
848 Standard_Boolean acheval2 =
849 AdjustParam(Dom2,f2,l2,wref,period2,pitol);
850 if(acheval2) nbcoup2 = 2;
851 for (Standard_Integer icoup2 = 1; icoup2 <= nbcoup2; icoup2++) {
852 if(f2 <= l1 && f1 <= l2) {
853 if (f1 >= f2 - tol2d)
854 FillSD(DStr,CD,M1,Dom1,f1,1,1,pitol,bout1);
855 if (f2 >= f1 - tol2d)
856 FillSD(DStr,CD,M2,Dom2,f2,1,2,pitol,bout1);
857 if (l1 >= l2 - tol2d)
858 FillSD(DStr,CD,M2,Dom2,l2,0,2,pitol,bout2);
859 if (l2 >= l1 - tol2d)
860 FillSD(DStr,CD,M1,Dom1,l1,0,1,pitol,bout2);
875 // Processing of extensions.
876 // Do not truncate, otherwise, problems of intersection for PerformCorner
877 // -----------------------------------------------------------------
878 // After call of SplitKPart in PerformSetOfKPart, spines have been
879 // extended to the extremities by methods Extent to permit
880 // intersections. Extensions of SurfData are preserved.
883 // We are at the beginning of the spine
884 //-------------------------
885 Standard_Integer ifirst = 0;
886 Standard_Real dist = RealLast(), ptg, dsp;
887 const BRepAdaptor_Curve& ed = Spine->CurrentElementarySpine(Iedge);
888 for (Standard_Integer i1 = 1; i1 <= SetData.Length(); i1++) {
889 Handle(ChFiDS_SurfData)& CD1 = SetData.ChangeValue(i1);
890 ChFiDS_CommonPoint& CP1 = CD1->ChangeVertexFirstOnS1();
891 ChFiDS_CommonPoint& CP2 = CD1->ChangeVertexFirstOnS2();
892 if(CP1.IsOnArc()&&!SearchFace(Spine,CP1,F1,FBID)) {
893 ptg = CD1->InterferenceOnS1().FirstParameter();
894 dsp = ComputeAbscissa(ed,ptg);
895 if(Abs(dsp) < dist) {
900 else if(CP2.IsOnArc()&&!SearchFace(Spine,CP2,F2,FBID)) {
901 ptg = CD1->InterferenceOnS2().FirstParameter();
902 dsp = ComputeAbscissa(ed,ptg);
903 if(Abs(dsp) < dist) {
910 SetData.Remove(1,ifirst-1);
911 ion1.Remove(1,ifirst-1);
912 ion2.Remove(1,ifirst-1);
914 if(SetData.IsEmpty()) return Standard_False;
915 Handle(ChFiDS_SurfData)& CD2 = SetData.ChangeValue(1);
916 ChFiDS_CommonPoint& CP1 = CD2->ChangeVertexFirstOnS1();
917 ChFiDS_CommonPoint& CP2 = CD2->ChangeVertexFirstOnS2();
918 ChFiDS_CommonPoint sov;
920 if(CP1.IsOnArc() && CP2.IsOnArc()) {
921 intf = !SearchFace(Spine,CP1,F1,FBID) && !SearchFace(Spine,CP2,F2,FBID);
923 else if(CP1.IsOnArc()) {
925 if(!SearchFace(Spine,CP1,F1,FBID)) {
926 FillSD(DStr,CD2,M2,H2.Domain(iH2,Ind2(ion2.First())),
927 H2.Domain(iH2,Ind2(ion2.First())).FirstPoint().Parameter(),1,2,pitol,bout1);
928 if(!CP2.IsOnArc() || (CP2.IsOnArc() && SearchFace(Spine,CP2,F2,FBID))) {
930 if(Spine->FirstStatus() != ChFiDS_OnSame) {
931 CD2->ChangeInterference(2).
932 SetParameter(CD2->Interference(1).Parameter(1),1);
933 intf = Standard_False;
937 else intf = Standard_False;
939 else if(CP2.IsOnArc()) {
941 if(!SearchFace(Spine,CP2,F2,FBID)) {
942 FillSD(DStr,CD2,M1,H1.Domain(iH1,Ind1(ion1.First())),
943 H1.Domain(iH1,Ind1(ion1.First())).FirstPoint().Parameter(),1,1,pitol,bout1);
944 if(!CP1.IsOnArc() || (CP1.IsOnArc() && SearchFace(Spine,CP1,F1,FBID))) {
946 if(Spine->FirstStatus() != ChFiDS_OnSame) {
947 CD2->ChangeInterference(1).
948 SetParameter(CD2->Interference(2).Parameter(1),1);
949 intf = Standard_False;
953 else intf = Standard_False;
955 // select <onS> switcher so that to get on spine params from
956 // Interference with a face where both edges at corner are OnSame
958 if (intf && Spine->FirstStatus() == ChFiDS_OnSame) {
959 TopoDS_Edge threeE[3];
960 ChFi3d_cherche_element(bout1,support,F1,threeE[0],boutemp);
961 ChFi3d_cherche_element(bout1,support,F2,threeE[1],boutemp);
963 if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame)
968 if (threeE[0].IsSame(threeE[1]))
969 cout << "SplitKPart(), wrong corner vertex at switcher search" << endl;
975 // we are at the end of the spine
976 //-----------------------
977 Standard_Integer ilast = 0;
978 Standard_Real dist = RealLast(), ptg, dsp;
979 Standard_Real f = Spine->FirstParameter(Iedge);
980 Standard_Real l = Spine->LastParameter(Iedge);
981 const BRepAdaptor_Curve& ed = Spine->CurrentElementarySpine(Iedge);
982 for (Standard_Integer i2 = 1; i2<= SetData.Length(); i2++) {
983 Handle(ChFiDS_SurfData)& CD3 = SetData.ChangeValue(i2);
984 ChFiDS_CommonPoint& CP1 = CD3->ChangeVertexLastOnS1();
985 ChFiDS_CommonPoint& CP2 = CD3->ChangeVertexLastOnS2();
986 if(CP1.IsOnArc()&&!SearchFace(Spine,CP1,F1,FBID)) {
987 ptg = CD3->InterferenceOnS1().LastParameter();
988 dsp = -ComputeAbscissa(ed,ptg) - f + l;
989 if(Abs(dsp) < dist) {
994 else if(CP2.IsOnArc()&&!SearchFace(Spine,CP2,F2,FBID)) {
995 ptg = CD3->InterferenceOnS2().LastParameter();
996 dsp = -ComputeAbscissa(ed,ptg) - f + l;
997 if(Abs(dsp) < dist) {
1003 Standard_Integer lll = SetData.Length();
1005 SetData.Remove(ilast+1, lll);
1006 ion1.Remove(ilast+1, lll);
1007 ion2.Remove(ilast+1, lll);
1009 if(SetData.IsEmpty()) return Standard_False;
1010 Handle(ChFiDS_SurfData)& CD4 = SetData.ChangeValue(SetData.Length());
1011 ChFiDS_CommonPoint& CP1 = CD4->ChangeVertexLastOnS1();
1012 ChFiDS_CommonPoint& CP2 = CD4->ChangeVertexLastOnS2();
1013 ChFiDS_CommonPoint sov;
1014 if(CP1.IsOnArc() && CP2.IsOnArc()) {
1015 intl = !SearchFace(Spine,CP1,F1,FBID) && !SearchFace(Spine,CP2,F2,FBID);
1017 else if(CP1.IsOnArc()) {
1019 if(!SearchFace(Spine,CP1,F1,FBID)) {
1020 FillSD(DStr,CD4,M2,H2.Domain(iH2,Ind2(ion2.Last())),
1021 H2.Domain(iH2,Ind2(ion2.Last())).SecondPoint().Parameter(),0,2,pitol,bout2);
1022 if(!CP2.IsOnArc() || (CP2.IsOnArc() && SearchFace(Spine,CP2,F2,FBID))) {
1024 if(Spine->LastStatus() != ChFiDS_OnSame) {
1025 CD4->ChangeInterference(2).
1026 SetParameter(CD4->Interference(1).Parameter(0),0);
1027 intl = Standard_False;
1031 else intl = Standard_False;
1033 else if(CP2.IsOnArc()) {
1035 if(!SearchFace(Spine,CP2,F2,FBID)) {
1036 FillSD(DStr,CD4,M1,H1.Domain(iH1,Ind1(ion1.Last())),
1037 H1.Domain(iH1,Ind1(ion1.Last())).SecondPoint().Parameter(),0,1,pitol,bout2);
1038 if(!CP1.IsOnArc() || (CP1.IsOnArc() && SearchFace(Spine,CP1,F1,FBID))) {
1040 if(Spine->LastStatus() != ChFiDS_OnSame) {
1041 CD4->ChangeInterference(1).
1042 SetParameter(CD4->Interference(2).Parameter(0),0);
1043 intl = Standard_False;
1047 else intl = Standard_False;
1050 // select <onS> switcher so that to get on spine params from
1051 // Interference with a face where both edges at corner are OnSame
1053 if (intl && Spine->LastStatus() == ChFiDS_OnSame) {
1054 TopoDS_Edge threeE[3];
1055 ChFi3d_cherche_element(bout2,support,F1,threeE[0],boutemp);
1056 ChFi3d_cherche_element(bout2,support,F2,threeE[1],boutemp);
1057 threeE[2] = support;
1058 if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame)
1063 if (threeE[0].IsSame(threeE[1]))
1064 cout << "SplitKPart(), wrong corner vertex at switcher search" << endl;
1066 cntlFiOnS = 3 - onS;
1072 // SurfData are entirely suspended before the beginning of the edge.
1073 Standard_Boolean okdoc = SetData.IsEmpty();
1074 Standard_Integer i = 1;
1076 Handle(ChFiDS_SurfData)& CD5 = SetData.ChangeValue(i);
1077 Standard_Real ltg = CD5->Interference(onS).LastParameter();
1078 Standard_Real Nl = ComputeAbscissa(Spine->CurrentElementarySpine(Iedge),ltg);
1079 if (Nl < -tolesp) SetData.Remove(i);
1081 okdoc = (SetData.IsEmpty() || i > SetData.Length());
1085 // SurfData are entirely suspended after the end of the edge.
1086 Standard_Boolean okdoc = SetData.IsEmpty();
1087 Standard_Integer i = 1;
1089 Handle(ChFiDS_SurfData)& CD6 = SetData.ChangeValue(i);
1090 Standard_Real ftg = CD6->Interference(onS).FirstParameter();
1091 Standard_Real f = Spine->FirstParameter(Iedge);
1092 Standard_Real l = Spine->LastParameter(Iedge);
1093 Standard_Real Nl = ComputeAbscissa(Spine->CurrentElementarySpine(Iedge),ftg);
1094 if (Nl > (l - f + tolesp)) SetData.Remove(i);
1096 okdoc = (SetData.IsEmpty() || i > SetData.Length());
1099 // Add parameters of the spine on SurfDatas.
1100 // for (Standard_Integer i = 1; i <= SetData.Length(); i++) {
1102 for ( i = 1; i <= SetData.Length(); i++) {
1103 Standard_Boolean pokdeb = 0, pokfin = 0;
1104 Handle(ChFiDS_SurfData)& CD7 = SetData.ChangeValue(i);
1105 Standard_Real ftg = CD7->Interference(onS).FirstParameter();
1106 Standard_Real ltg = CD7->Interference(onS).LastParameter();
1107 Standard_Real fsp = ParamOnSpine(DStr,ftg,CD7,Spine,Iedge,intf,intl,tolesp,pokdeb);
1108 if(!pokdeb) fsp = ResetProl(DStr,CD7,Spine,Iedge,1);
1109 Standard_Real lsp = ParamOnSpine(DStr,ltg,CD7,Spine,Iedge,intf,intl,tolesp,pokfin);
1110 if(!pokfin) lsp = ResetProl(DStr,CD7,Spine,Iedge,0);
1111 if(Spine->IsPeriodic() && Iedge == Spine->NbEdges() && lsp < fsp) {
1112 lsp += Spine->Period();
1114 else if(Spine->IsPeriodic() && Iedge == 1 && lsp < fsp) {
1115 fsp -= Spine->Period();
1117 CD7->FirstSpineParam(fsp);
1118 CD7->LastSpineParam (lsp);
1121 if (intf && !SetData.IsEmpty()) {
1122 // extension of the spine
1123 Spine->SetFirstParameter(SetData.First()->FirstSpineParam());
1126 // Trnncation at the beginning.
1127 for (i = 1; i <= SetData.Length(); i++) {
1128 Handle(ChFiDS_SurfData)& CD8 = SetData.ChangeValue(i);
1129 Standard_Real fsp = CD8->FirstSpineParam();
1130 Standard_Real lsp = CD8->LastSpineParam();
1131 if (lsp > Spine->FirstParameter(Iedge)) {
1132 if (fsp > Spine->FirstParameter(Iedge)) {
1136 Trunc(CD8,Spine,S1,S2,Iedge,1,cntlFiOnS);
1142 SetData.Remove(1,i-1);
1147 if (intl && !SetData.IsEmpty()) {
1148 // extension of the spine
1149 Spine->SetLastParameter(SetData.Last()->LastSpineParam());
1152 // Truncation at the end.
1153 for (i = SetData.Length(); i >= 1; i--) {
1154 Handle(ChFiDS_SurfData)& CD9 = SetData.ChangeValue(i);
1155 Standard_Real fsp = CD9->FirstSpineParam();
1156 Standard_Real lsp = CD9->LastSpineParam();
1157 if (fsp < Spine->LastParameter(Iedge)) {
1158 if (lsp < Spine->LastParameter(Iedge)) {
1162 Trunc(CD9,Spine,S1,S2,Iedge,0,cntlFiOnS);
1167 if (i < SetData.Length()) {
1168 SetData.Remove(i+1,SetData.Length());
1172 if(ChFi3d_GettraceDRAWFIL()) {
1173 for (i = 1; i <= SetData.Length(); i++) {
1174 ChFi3d_CheckSurfData(DStr,SetData.Value(i));
1178 return Standard_True;