1 // Created on: 1994-01-20
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_NotImplemented.hxx>
18 #include <Precision.hxx>
19 #include <TColStd_SequenceOfInteger.hxx>
20 #include <TColStd_Array1OfInteger.hxx>
21 #include <TColStd_Array1OfReal.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <gp_Dir2d.hxx>
26 #include <gp_Circ.hxx>
27 #include <TColgp_Array1OfPnt2d.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>
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>
55 #include <TopoDS_Edge.hxx>
57 #include <TopOpeBRepDS_Curve.hxx>
58 #include <TopOpeBRepDS_Surface.hxx>
60 #include <ChFiKPart_RstMap.hxx>
62 #include <ChFi3d_Builder.jxx>
63 #include <ChFi3d_Builder_0.hxx>
65 extern Standard_Boolean ChFi3d_GettraceDRAWFIL();
66 extern void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr,
67 const Handle(ChFiDS_SurfData)& Data);
69 //=======================================================================
71 //purpose : Calculate the Transition from start point.
72 //=======================================================================
74 static TopAbs_Orientation CompTra (const TopAbs_Orientation O1,
75 const TopAbs_Orientation O2,
76 const Standard_Boolean isfirst)
78 if(isfirst) return TopAbs::Reverse(TopAbs::Compose(O1,O2));
79 else return TopAbs::Compose(O1,O2);
83 //=======================================================================
84 //function : CompCommonpoint
85 //purpose : Fill the commonpoint in case of a vertex.
86 //=======================================================================
88 static void CompCommonPoint (ChFiDS_CommonPoint& FilPoint,
89 const TopoDS_Edge& arc,
90 const HatchGen_PointOnElement& PE,
91 const TopAbs_Orientation Or)
93 TopAbs_Orientation pos = PE.Position();
95 if ( pos == TopAbs_FORWARD ) {
96 V = TopExp::FirstVertex(arc);
99 V = TopExp::LastVertex(arc);
101 FilPoint.SetVertex(V);
102 FilPoint.SetArc(Precision::PIntersection(),arc,
103 PE.Parameter(),TopAbs::Compose(arc.Orientation(),Or));
107 //=======================================================================
108 //function : CpInterf
109 //purpose : Construct new SurfData sharing faces, surface and curves.
110 //=======================================================================
112 static ChFiDS_FaceInterference CpInterf (TopOpeBRepDS_DataStructure& DStr,
113 const ChFiDS_FaceInterference& FI)
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())));
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());
132 //=======================================================================
134 //purpose : Construct new SurfData sharing faces, surface and curves.
135 //=======================================================================
137 static Handle(ChFiDS_SurfData) CpSD ( TopOpeBRepDS_DataStructure& DStr,
138 const Handle(ChFiDS_SurfData)& Data)
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());
153 //=======================================================================
154 //function : AdjustParam
156 //=======================================================================
158 static Standard_Boolean AdjustParam(const HatchGen_Domain& Dom,
161 const Standard_Real wref,
162 const Standard_Real period,
163 const Standard_Real pitol)
165 if(Dom.HasFirstPoint())
166 f = Dom.FirstPoint().Parameter();
168 if(Dom.HasSecondPoint())
169 l = Dom.SecondPoint().Parameter();
171 if (period == 0.) return Standard_False;
173 f = ElCLib::InPeriod(f,wref - pitol, wref + period - pitol);
174 l = ElCLib::InPeriod(l,wref + pitol, wref + period + pitol);
177 return Standard_True;
179 return Standard_False;
181 //=======================================================================
182 //function : ComputeAbscissa
184 //=======================================================================
186 static Standard_Real ComputeAbscissa(const BRepAdaptor_Curve& C,
187 const Standard_Real U)
189 switch (C.GetType()) {
193 return C.Circle().Radius()*U;
199 //=======================================================================
200 //function : ParamOnSpine
202 //=======================================================================
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)
215 Standard_Real f = Spine->FirstParameter(iedge);
216 Standard_Real l = Spine->LastParameter(iedge);
218 Nl = ComputeAbscissa(Spine->CurrentElementarySpine(iedge),ptg) + f;
219 if ((Nl >= (f - tol) || intf) &&
220 (Nl <= (l + tol) || intl) ) {
225 //construction of the plane containing the section of CD with parameter ptg.
228 Handle(Geom_Curve) c3d;
229 if (CD->InterferenceOnS1().LineIndex() != 0) {
230 c3d = DStr.Curve(CD->InterferenceOnS1().LineIndex()).Curve();
233 c3d = DStr.Curve(CD->InterferenceOnS2().LineIndex()).Curve();
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));
242 // intersection plane spine.
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();
252 else if(ii < 1 || ii > Spine->NbEdges()) {
256 Handle(BRepAdaptor_HCurve) HE = new BRepAdaptor_HCurve();
257 BRepAdaptor_Curve& CE = HE->ChangeCurve();
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);
268 cout<<"******* ParamOnSpine() for edge "<<iedge<<endl;
270 cout<<"point ped "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl;
272 if(found) Nl = Spine->Absc(Nl,ii);
273 point = Spine->Value(Nl);
275 if (found) cout << "found by edge " << ii << " : ";
277 cout<<"point psp "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<endl;
282 if (Spine->IsPeriodic()) {
283 if (ii <= 0) ii += Spine->NbEdges();
284 if (ii > Spine->NbEdges()) ii -= Spine->NbEdges();
285 fini = (ii == iedge);
288 fini = (ii < 1 || ii > Spine->NbEdges());
296 //=======================================================================
297 //function : YaUnVoisin
299 //=======================================================================
301 static Standard_Boolean YaUnVoisin(const Handle(ChFiDS_Spine)& Spine,
302 const Standard_Integer iedge,
303 Standard_Integer& ivois,
304 const Standard_Boolean isfirst)
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;
312 if(ivois == 0) ivois = nbed;
313 if(ivois == nbed+1) ivois = 1;
315 return (ivois > 0 && ivois <= nbed);
318 //=======================================================================
321 //=======================================================================
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)
331 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
332 // Return points and tangents on edge and spine.
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);
338 TopoDS_Vertex bout1,bout2,boutemp;
341 const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge);
342 //Modif against Vertex isolated on spine
343 TopoDS_Edge support = bc.Edge();
344 TopExp::Vertices(support,bout1,bout2);
345 if (support.Orientation() == TopAbs_REVERSED) {
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);
360 bc.D1(-wtg+edl,ped,ded);
363 Spine->D1(wsp,psp,dsp);
365 const Handle(Geom_Surface)& surf = DStr.Surface(SD->Surf()).Surface();
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);
375 if(Ang > M_PI/18.) tron = Standard_True;
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()) {
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);
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());
393 //modification of lvt against isolated vertex
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()) {
400 if(nbed<3) tron = Standard_True;
405 Standard_Real par = 0., x, y, dPar=0;
406 if(!isfirst) par = edglen;
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);
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);
430 //=======================================================================
431 //function : ResetProl
433 //=======================================================================
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)
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;
446 Standard_Real sppar = 0.;
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));
454 sppar = Spine->FirstParameter(iedge);
455 CD->FirstSpineParam(sppar);
458 sppar = Spine->LastParameter(iedge);
459 CD->LastSpineParam (sppar);
464 //=======================================================================
467 //=======================================================================
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)
477 // for (Standard_Integer i = 1; i <= Nbdom; i++) { Ind(i) = 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;
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);
493 Invert = Standard_True;
498 Standard_Integer iSansFirst = 0, iSansLast = 0;
501 for ( i = 1; i <= Nbdom; i++) {
502 if (!H.Domain(iH,Ind(i)).HasFirstPoint()) {
505 if (!H.Domain(iH,Ind(i)).HasSecondPoint()) {
510 if (iSansFirst != 0) {
511 if (iSansLast == 0) {
513 cout<<"Parsing : Pb of Hatcher"<<endl;
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);
525 for (Standard_Integer k = iSansLast; k < Nbdom; k++) {
533 //=======================================================================
536 //=======================================================================
538 static void FillSD (TopOpeBRepDS_DataStructure& DStr,
539 Handle(ChFiDS_SurfData)& CD,
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)
549 Standard_Integer opp = 3 - ons;
550 ChFiDS_CommonPoint& Pons = CD->ChangeVertex(isFirst,ons);
551 ChFiDS_CommonPoint& Popp = CD->ChangeVertex(isFirst,opp);
553 const HatchGen_PointOnHatching* pPH = 0;
554 if(isFirst && Dom.HasFirstPoint()) {
555 const HatchGen_PointOnHatching& PHtemp = Dom.FirstPoint();
558 else if(!isFirst && Dom.HasSecondPoint()) {
559 const HatchGen_PointOnHatching& PHtemp = Dom.SecondPoint();
563 Handle(Geom_Surface) Surf = DStr.Surface(CD->Surf()).Surface();
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));
571 //Modification to find already existing vertexes
572 Standard_Integer LeType = 1;
573 Standard_Integer NbInt = pPH->NbPoints();
575 Standard_Boolean trouve = Standard_True;
577 TopoDS_Vertex V1 , V2;
578 Standard_Boolean suite = Standard_True;
580 const HatchGen_PointOnElement& PEtemp = pPH->Point(LeType);
582 Handle(BRepAdaptor_HCurve2d) HE = Handle(BRepAdaptor_HCurve2d::DownCast(M(IE)));
584 const TopoDS_Edge& Etemp = HE->ChangeCurve2d().Edge();
585 TopExp::Vertices(Etemp,V1,V2);
588 suite = Standard_False;
590 if(((V1.IsSame(bout)) || (V2.IsSame(bout))) && suite) {
591 trouve = Standard_True;
595 suite = Standard_True;
596 trouve = Standard_False;
599 trouve = Standard_True;
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();
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);
618 Pons.SetArc(pitol,E,PE.Parameter(),
619 CompTra(CD->Interference(ons).Transition(),E.Orientation(),isFirst));
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));
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));
634 //=======================================================================
635 //function : SplitKPart
636 //purpose : Reconstruct SurfData depending on restrictions of faces.
637 //=======================================================================
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)
651 //The the hatching of each faces is started by tangency lines.
653 Standard_Real pitol = Precision::PIntersection();
655 ChFiKPart_RstMap M1, M2;
656 Standard_Integer iH1 = 0,iH2 = 0;
657 Standard_Integer Nb1 = 1,Nb2 = 1;
659 // Cutting of tangency lines (hatching).
660 Geom2dHatch_Intersector Inter(pitol,pitol);
661 Geom2dHatch_Hatcher H1(Inter,tol2d,tolesp), H2(Inter,tol2d,tolesp);
663 Handle(Geom2d_Curve) C1 = Data->InterferenceOnS1().PCurveOnFace();
664 Geom2dAdaptor_Curve ll1;
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());
678 H1.ComputeDomains(iH1);
679 if(!H1.IsDone(iH1)) return 0;
680 Nb1 = H1.NbDomains(iH1);
683 cout<<"SplitKPart : tangency line out of the face"<<endl;
685 return Standard_False;
689 Handle(Geom2d_Curve) C2 = Data->InterferenceOnS2().PCurveOnFace();
690 Geom2dAdaptor_Curve ll2;
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());
704 H2.ComputeDomains(iH2);
705 if(!H2.IsDone(iH2)) return 0;
706 Nb2 = H2.NbDomains(iH2);
709 cout<<"SplitKPart : tangency line out of the face"<<endl;
711 return Standard_False;
715 //Return start and end vertexes of the Spine
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) {
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();
735 // Restriction of SurfDatas by cut lines.
736 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
737 Handle(ChFiDS_SurfData) CD = Data;
738 CD->ChangeIndexOfS1(DStr.AddShape(F1));
739 CD->ChangeIndexOfS2(DStr.AddShape(F2));
741 Standard_Real f1,l1,f2,l2;
742 TColStd_Array1OfInteger Ind1(1,Nb1), Ind2(1,Nb2);
743 Standard_Real wref = 0.;
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
749 if (C1.IsNull() && C2.IsNull()) {
751 cout<<"SplitData : 2 zero lines hatching impossible"<<endl;
753 return Standard_False;
755 else if (C1.IsNull() || (Nb1 == 1 && !H1.Domain(iH1,1).HasFirstPoint())) {
756 // It is checked if the point 2d of the degenerated edge is in the face.
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;
763 // Parsing of domains by increasing parameters,
764 if(!Tri(H2,iH2,Ind2,wref,0.,pitol,Nb2)) return 0;
765 // Filling of SurfData
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);
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);
779 else intf = Standard_False;
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);
787 else intl = Standard_False;
790 else if (C2.IsNull() || (Nb2 == 1 && !H2.Domain(iH2,1).HasFirstPoint())) {
791 // It is checked if the point 2d of the degenerated is in the face.
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;
798 // Parsing of domains by increasing parameters,
799 if(!Tri(H1,iH1,Ind1,wref,0.,pitol,Nb1)) return 0;
800 // Filling of SurfData
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);
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);
814 else intf = Standard_False;
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);
822 else intl = Standard_False;
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.
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;
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;
842 // Filling of SurfData
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);
880 // Processing of extensions.
881 // Do not truncate, otherwise, problems of intersection for PerformCorner
882 // -----------------------------------------------------------------
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.
888 // We are at the beginning of the spine
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) {
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) {
915 SetData.Remove(1,ifirst-1);
916 ion1.Remove(1,ifirst-1);
917 ion2.Remove(1,ifirst-1);
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;
925 if(CP1.IsOnArc() && CP2.IsOnArc()) {
926 intf = !SearchFace(Spine,CP1,F1,FBID) && !SearchFace(Spine,CP2,F2,FBID);
928 else if(CP1.IsOnArc()) {
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))) {
935 if(Spine->FirstStatus() != ChFiDS_OnSame) {
936 CD2->ChangeInterference(2).
937 SetParameter(CD2->Interference(1).Parameter(1),1);
938 intf = Standard_False;
942 else intf = Standard_False;
944 else if(CP2.IsOnArc()) {
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))) {
951 if(Spine->FirstStatus() != ChFiDS_OnSame) {
952 CD2->ChangeInterference(1).
953 SetParameter(CD2->Interference(2).Parameter(1),1);
954 intf = Standard_False;
958 else intf = Standard_False;
960 // select <onS> switcher so that to get on spine params from
961 // Interference with a face where both edges at corner are OnSame
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);
968 if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame)
973 if (threeE[0].IsSame(threeE[1]))
974 cout << "SplitKPart(), wrong corner vertex at switcher search" << endl;
980 // we are at the end of the spine
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) {
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) {
1008 Standard_Integer lll = SetData.Length();
1010 SetData.Remove(ilast+1, lll);
1011 ion1.Remove(ilast+1, lll);
1012 ion2.Remove(ilast+1, lll);
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);
1022 else if(CP1.IsOnArc()) {
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))) {
1029 if(Spine->LastStatus() != ChFiDS_OnSame) {
1030 CD4->ChangeInterference(2).
1031 SetParameter(CD4->Interference(1).Parameter(0),0);
1032 intl = Standard_False;
1036 else intl = Standard_False;
1038 else if(CP2.IsOnArc()) {
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))) {
1045 if(Spine->LastStatus() != ChFiDS_OnSame) {
1046 CD4->ChangeInterference(1).
1047 SetParameter(CD4->Interference(2).Parameter(0),0);
1048 intl = Standard_False;
1052 else intl = Standard_False;
1055 // select <onS> switcher so that to get on spine params from
1056 // Interference with a face where both edges at corner are OnSame
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)
1068 if (threeE[0].IsSame(threeE[1]))
1069 cout << "SplitKPart(), wrong corner vertex at switcher search" << endl;
1071 cntlFiOnS = 3 - onS;
1077 // SurfData are entirely suspended before the beginning of the edge.
1078 Standard_Boolean okdoc = SetData.IsEmpty();
1079 Standard_Integer i = 1;
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);
1086 okdoc = (SetData.IsEmpty() || i > SetData.Length());
1090 // SurfData are entirely suspended after the end of the edge.
1091 Standard_Boolean okdoc = SetData.IsEmpty();
1092 Standard_Integer i = 1;
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);
1101 okdoc = (SetData.IsEmpty() || i > SetData.Length());
1104 // Add parameters of the spine on SurfDatas.
1105 // for (Standard_Integer i = 1; i <= SetData.Length(); 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();
1119 else if(Spine->IsPeriodic() && Iedge == 1 && lsp < fsp) {
1120 fsp -= Spine->Period();
1122 CD7->FirstSpineParam(fsp);
1123 CD7->LastSpineParam (lsp);
1126 if (intf && !SetData.IsEmpty()) {
1127 // extension of the spine
1128 Spine->SetFirstParameter(SetData.First()->FirstSpineParam());
1131 // Trnncation at the beginning.
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)) {
1141 Trunc(CD8,Spine,S1,S2,Iedge,1,cntlFiOnS);
1147 SetData.Remove(1,i-1);
1152 if (intl && !SetData.IsEmpty()) {
1153 // extension of the spine
1154 Spine->SetLastParameter(SetData.Last()->LastSpineParam());
1157 // Truncation at the end.
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)) {
1167 Trunc(CD9,Spine,S1,S2,Iedge,0,cntlFiOnS);
1172 if (i < SetData.Length()) {
1173 SetData.Remove(i+1,SetData.Length());
1177 if(ChFi3d_GettraceDRAWFIL()) {
1178 for (i = 1; i <= SetData.Length(); i++) {
1179 ChFi3d_CheckSurfData(DStr,SetData.Value(i));
1183 return Standard_True;