b311480e |
1 | // Created on: 1996-08-20 |
2 | // Created by: Stagiaire Xuan Tang PHAMPHU |
3 | // Copyright (c) 1996-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 <ChFi3d_Builder.jxx> |
18 | #include <ChFi3d.hxx> |
19 | #include <ChFi3d_Builder_0.hxx> |
20 | |
21 | #include <Precision.hxx> |
22 | |
23 | #include <Standard_Failure.hxx> |
24 | #include <Standard_NotImplemented.hxx> |
25 | #include <StdFail_NotDone.hxx> |
26 | |
27 | |
28 | #include <gp_Pnt.hxx> |
29 | #include <gp_Dir.hxx> |
30 | #include <gp_Vec.hxx> |
31 | #include <gp_Ax3.hxx> |
32 | #include <gp_Pnt2d.hxx> |
33 | #include <gp_Vec2d.hxx> |
34 | #include <gp_Dir2d.hxx> |
35 | #include <GeomLib.hxx> |
36 | #include <Extrema_ExtPC.hxx> |
37 | #include <Geom_Curve.hxx> |
38 | #include <Geom2d_Curve.hxx> |
39 | #include <Geom_BoundedCurve.hxx> |
40 | |
41 | #include <Geom2dAdaptor_HCurve.hxx> |
42 | #include <GeomAbs_Shape.hxx> |
43 | #include <GeomAdaptor_HCurve.hxx> |
44 | #include <GeomAdaptor_Surface.hxx> |
45 | #include <GeomAdaptor_HSurface.hxx> |
46 | |
47 | #include <Adaptor3d_HCurveOnSurface.hxx> |
48 | #include <BRepAdaptor_HSurface.hxx> |
49 | #include <BRepAdaptor_Curve.hxx> |
50 | #include <BRepAdaptor_Curve2d.hxx> |
51 | #include <BRepAdaptor_HCurve.hxx> |
52 | #include <BRepAdaptor_Surface.hxx> |
53 | |
54 | #include <BRep_Tool.hxx> |
55 | |
56 | #include <TopoDS.hxx> |
57 | #include <TopoDS_Shape.hxx> |
58 | #include <TopoDS_Face.hxx> |
59 | #include <TopoDS_Edge.hxx> |
60 | #include <TopoDS_Vertex.hxx> |
61 | |
62 | #include <TopAbs.hxx> |
63 | #include <TopAbs_ShapeEnum.hxx> |
64 | #include <TopAbs_Orientation.hxx> |
65 | |
66 | #include <TopExp.hxx> |
67 | #include <TopExp_Explorer.hxx> |
68 | |
69 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
70 | |
71 | #include <TopOpeBRepDS_Point.hxx> |
72 | #include <TopOpeBRepDS_Curve.hxx> |
73 | #include <TopOpeBRepDS_Surface.hxx> |
74 | #include <TopOpeBRepDS_SurfaceCurveInterference.hxx> |
75 | #include <TopOpeBRepDS_CurvePointInterference.hxx> |
76 | #include <TopOpeBRepDS_DataStructure.hxx> |
77 | #include <TopOpeBRepDS_ListOfInterference.hxx> |
78 | |
79 | #include <ChFiDS_HData.hxx> |
80 | #include <ChFiDS_SurfData.hxx> |
81 | #include <ChFiDS_CommonPoint.hxx> |
82 | #include <ChFiDS_FaceInterference.hxx> |
83 | #include <ChFiDS_SequenceOfSurfData.hxx> |
84 | #include <ChFiDS_Stripe.hxx> |
85 | #include <ChFiDS_ListIteratorOfListOfStripe.hxx> |
86 | |
87 | #include <TColStd_Array1OfReal.hxx> |
88 | |
89 | static void Reduce(const Standard_Real& p1, |
90 | const Standard_Real& p2, |
91 | Handle(GeomAdaptor_HSurface)& hs1, |
92 | Handle(GeomAdaptor_HSurface)& hs2) |
93 | { |
94 | GeomAdaptor_Surface& s1 = hs1->ChangeSurface(); |
95 | GeomAdaptor_Surface& s2 = hs2->ChangeSurface(); |
96 | const Handle(Geom_Surface&) surf = s1.Surface(); |
97 | Standard_Real ud,uf,vd,vf; |
98 | surf->Bounds(ud,uf,vd,vf); |
99 | Standard_Real milmoins = 0.51*vd+0.49*vf, milplus = 0.49*vd+0.51*vf; |
100 | if(p1 < p2) { |
101 | s1.Load(surf,ud,uf,vd,milmoins); |
102 | s2.Load(surf,ud,uf,milplus,vf); |
103 | } |
104 | else{ |
105 | s1.Load(surf,ud,uf,milplus,vf); |
106 | s2.Load(surf,ud,uf,vd,milmoins); |
107 | } |
108 | } |
109 | |
110 | static void Reduce(const Standard_Real& p1, |
111 | const Standard_Real& p2, |
112 | Handle(GeomAdaptor_HCurve)& hc) |
113 | { |
114 | GeomAdaptor_Curve& c = hc->ChangeCurve(); |
115 | Standard_Real f = c.FirstParameter(); |
116 | Standard_Real l = c.LastParameter(); |
117 | Standard_Real milmoins = 0.51*f+0.49*l, milplus = 0.49*f+0.51*l; |
118 | if(p1 < p2) { |
119 | c.Load(c.Curve(),f,milmoins); |
120 | } |
121 | else{ |
122 | c.Load(c.Curve(),milplus,l); |
123 | } |
124 | } |
125 | |
126 | |
127 | //======================================================================= |
128 | //function : PerformTwoCornerbyInter |
81bba717 |
129 | //purpose : Performs PerformTwoCorner by intersection. |
130 | // In case of Biseau for all cases the |
131 | // path is used; 3D curve and 2 pcurves are approximated. |
7fd59977 |
132 | //======================================================================= |
133 | |
134 | Standard_Integer ChFi3d_Builder::PerformTwoCornerbyInter(const Standard_Integer Index) |
135 | |
136 | { |
137 | done = 0; |
138 | const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index); |
139 | TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS(); |
140 | |
81bba717 |
141 | //Information on fillets is extracted |
7fd59977 |
142 | //------------------------------------------------------ |
143 | |
81bba717 |
144 | //the first |
7fd59977 |
145 | //---------- |
146 | ChFiDS_ListIteratorOfListOfStripe It; |
147 | It.Initialize(myVDataMap(Index)); |
148 | Handle(ChFiDS_Stripe)& Corner1 = It.Value(); |
149 | Standard_Integer Sens1; |
150 | Standard_Integer IFd1 = |
151 | ChFi3d_IndexOfSurfData(Vtx,Corner1,Sens1); |
152 | ChFiDS_SequenceOfSurfData& SeqFil1 = |
153 | Corner1->ChangeSetOfSurfData()->ChangeSequence(); |
154 | Handle(ChFiDS_SurfData)& Fd1 = SeqFil1.ChangeValue(IFd1); |
155 | |
81bba717 |
156 | //the second |
7fd59977 |
157 | //---------- |
158 | It.Next(); |
159 | Handle(ChFiDS_Stripe)& Corner2 = It.Value(); |
160 | Standard_Integer Sens2; |
161 | Standard_Integer IFd2; |
162 | if(Corner2 == Corner1) { |
163 | Sens2 = -1; |
164 | IFd2 = Corner2->SetOfSurfData()->Length(); |
165 | } |
166 | else{ IFd2 = ChFi3d_IndexOfSurfData(Vtx,Corner2,Sens2); } |
167 | ChFiDS_SequenceOfSurfData& SeqFil2 = |
168 | Corner2->ChangeSetOfSurfData()->ChangeSequence(); |
169 | Handle(ChFiDS_SurfData)& Fd2 = SeqFil2.ChangeValue(IFd2); |
170 | |
81bba717 |
171 | // The concavities are analysed in case of differents concavities, |
172 | // preview an evolutionary connection of type ThreeCorner of R to 0. |
173 | // Otherwise the opposite face |
174 | // and the eventual intersection of 2 pcurves on this face are found. |
7fd59977 |
175 | |
176 | ChFiDS_State Stat1,Stat2; |
177 | Standard_Boolean isfirst1 = (Sens1 == 1); |
178 | Standard_Boolean isfirst2 = (Sens2 == 1); |
179 | Stat1 = Corner1->Spine()->Status(isfirst1); |
180 | Stat2 = Corner2->Spine()->Status(isfirst2); |
181 | /*#ifdef DEB |
182 | Standard_Boolean evolcoin = ((Stat1 == ChFiDS_OnSame && Stat2 == ChFiDS_OnDiff) || |
183 | (Stat2 == ChFiDS_OnSame && Stat1 == ChFiDS_OnDiff)); |
184 | #endif*/ |
185 | Standard_Boolean OkinterCC,Okvisavis,SameSide; |
186 | Standard_Integer IFaCo1,IFaCo2; |
187 | Standard_Real UIntPC1,UIntPC2; |
188 | TopoDS_Face FaCo; |
189 | OkinterCC = ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2, |
190 | UIntPC1,UIntPC2,FaCo,SameSide, |
191 | IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True); |
192 | if (!Okvisavis) { |
63c629aa |
193 | #if CHFI3D_DEB |
7fd59977 |
194 | cout<<"TwoCorner : pas de face commune"<<endl; |
195 | #endif |
196 | done=Standard_False; |
197 | return done; |
198 | } |
199 | if (!OkinterCC) { |
81bba717 |
200 | // The intersection of pcurves is calculated without restricting them by |
201 | // common points. |
7fd59977 |
202 | OkinterCC= ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2, |
203 | UIntPC1,UIntPC2,FaCo,SameSide, |
204 | IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True,1); |
205 | } |
206 | |
207 | if (!Okvisavis) { |
63c629aa |
208 | #if CHFI3D_DEB |
81bba717 |
209 | cout<<"TwoCorner : no common face"<<endl; |
7fd59977 |
210 | #endif |
211 | done=Standard_False; |
212 | return done; |
213 | } |
214 | if (!OkinterCC) { |
63c629aa |
215 | #if CHFI3D_DEB |
81bba717 |
216 | cout<<"biseau : failed intersection of tangency lines on common face"<<endl; |
7fd59977 |
217 | #endif |
218 | done=Standard_False; |
219 | return done; |
220 | } |
221 | Standard_Integer IFaArc1 = 3-IFaCo1, IFaArc2 = 3-IFaCo2; |
222 | |
81bba717 |
223 | // It is checked if the fillets have a commonpoint on a common arc. |
224 | // This edge is the pivot of the bevel or of the kneecap. |
7fd59977 |
225 | |
226 | ChFiDS_CommonPoint& CP1 = Fd1->ChangeVertex(isfirst1,IFaArc1); |
227 | ChFiDS_CommonPoint& CP2 = Fd2->ChangeVertex(isfirst2,IFaArc2); |
228 | |
229 | if (!CP1.IsOnArc() || !CP2.IsOnArc()) { |
63c629aa |
230 | #if CHFI3D_DEB |
81bba717 |
231 | cout<<"fail 1 of 2 fillets are not on arc"<<endl; |
7fd59977 |
232 | #endif |
233 | done=Standard_False; |
234 | return done; |
235 | } |
236 | if ( ! CP1.Arc().IsSame( CP2.Arc()) ) { |
237 | // look like OnSame + OnDiff case (eap, Arp 9 2002, occ266) |
63c629aa |
238 | #if CHFI3D_DEB |
81bba717 |
239 | cout<<"PerformTwoCornerbyInter(): fillets are not on the same arc"<<endl; |
7fd59977 |
240 | #endif |
241 | done = Standard_True; |
242 | PerformMoreThreeCorner(Index, 2); |
243 | return done; |
244 | } |
245 | |
246 | TopoDS_Edge pivot; |
247 | pivot = CP1.Arc(); |
248 | Standard_Real parCP1 = CP1.ParameterOnArc(); |
249 | Standard_Real parCP2 = CP2.ParameterOnArc(); |
250 | Handle(BRepAdaptor_HCurve) Hpivot = new BRepAdaptor_HCurve(pivot); |
251 | if (!pivot.IsSame(CP2.Arc())){ |
252 | Handle(Geom_Curve) csau; |
253 | Standard_Real ubid,vbid; |
254 | csau=BRep_Tool::Curve(pivot,ubid,vbid ); |
255 | Handle(Geom_BoundedCurve) C1= Handle(Geom_BoundedCurve)::DownCast(csau); |
256 | if (! C1.IsNull()) { |
257 | GeomLib::ExtendCurveToPoint(C1,CP2.Point(),1,Standard_False); |
258 | GeomAdaptor_Curve cad; |
259 | cad.Load(C1); |
260 | Extrema_ExtPC ext(CP2.Point(),cad,1.e-4); |
261 | parCP2 = ext.Point(1).Parameter(); |
262 | } |
263 | } |
264 | gp_Pnt psp1 = Hpivot->Value(parCP1); |
265 | gp_Pnt psp2 = Hpivot->Value(parCP2); |
266 | Standard_Real sameparam = (psp1.Distance(psp2) < 10 * tolesp); |
267 | |
268 | TopoDS_Face FF1 = TopoDS::Face(DStr.Shape(Fd1->Index(IFaArc1))); |
269 | TopoDS_Face FF2 = TopoDS::Face(DStr.Shape(Fd2->Index(IFaArc2))); |
270 | TopTools_ListIteratorOfListOfShape Kt; |
271 | Standard_Boolean ok1 = Standard_False, ok2 = Standard_False; |
272 | for (Kt.Initialize(myEFMap(pivot)); Kt.More(); Kt.Next()){ |
273 | TopoDS_Face F = TopoDS::Face(Kt.Value()); |
274 | if(!ok1 && FF1.IsSame(F)){ |
275 | ok1 = Standard_True; |
276 | } |
277 | if(!ok2 && FF2.IsSame(F)){ |
278 | ok2 = Standard_True; |
279 | } |
280 | } |
281 | if(!ok1 || !ok2){ |
63c629aa |
282 | #if CHFI3D_DEB |
81bba717 |
283 | cout<<"fail one of surfaces has no common base face with the pivot edge"<<endl; |
7fd59977 |
284 | #endif |
285 | done=Standard_False; |
286 | return done; |
287 | } |
288 | |
289 | Handle(GeomAdaptor_HSurface) HS1, HS2; |
290 | HS1 = ChFi3d_BoundSurf (DStr,Fd1,IFaCo1,IFaArc1); |
291 | HS2 = ChFi3d_BoundSurf (DStr,Fd2,IFaCo2,IFaArc2); |
292 | |
293 | TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4); |
294 | |
295 | Handle(Geom2d_Curve) PGc1,PGc2; |
296 | Handle(Geom_Curve) Gc; |
297 | |
298 | if(sameparam) { |
81bba717 |
299 | // Side common face, calculation of Pardeb. |
7fd59977 |
300 | ChFi3d_ComputesIntPC (Fd1->Interference(IFaCo1), |
301 | Fd2->Interference(IFaCo2), |
302 | HS1,HS2,UIntPC1,UIntPC2); |
303 | gp_Pnt2d UV; |
304 | UV = Fd1->Interference(IFaCo1).PCurveOnSurf()->Value(UIntPC1); |
305 | Pardeb(1)= UV.X(); Pardeb(2)=UV.Y(); |
306 | UV = Fd2->Interference(IFaCo2).PCurveOnSurf()->Value(UIntPC2); |
307 | Pardeb(3)= UV.X(); Pardeb(4)=UV.Y(); |
308 | gp_Pnt PFaCo = HS1->Surface().Value(Pardeb(1),Pardeb(2)); |
309 | |
81bba717 |
310 | // Side arc, calculation of Parfin. |
7fd59977 |
311 | Standard_Real UIntArc1 = Fd1->Interference(IFaArc1).Parameter(isfirst1); |
312 | Standard_Real UIntArc2 = Fd2->Interference(IFaArc2).Parameter(isfirst2); |
313 | |
314 | ChFi3d_ComputesIntPC (Fd1->Interference(IFaArc1),Fd2->Interference(IFaArc2), |
315 | HS1,HS2,UIntArc1,UIntArc2); |
316 | UV = Fd1->Interference(IFaArc1).PCurveOnSurf()->Value(UIntArc1); |
317 | Parfin(1)= UV.X(); Parfin(2)=UV.Y(); |
318 | UV = Fd2->Interference(IFaArc2).PCurveOnSurf()->Value(UIntArc2); |
319 | Parfin(3)= UV.X(); Parfin(4)=UV.Y(); |
320 | |
321 | if(Fd1->Surf() == Fd2->Surf()){ |
322 | Reduce(UIntPC1,UIntPC2,HS1,HS2); |
323 | } |
324 | |
1d47d8d0 |
325 | Standard_Real tolreached = tolesp; |
7fd59977 |
326 | if (IFaCo1 == 1 && |
327 | !ChFi3d_ComputeCurves(HS1,HS2,Pardeb,Parfin,Gc, |
328 | PGc1,PGc2,tolesp,tol2d,tolreached)) { |
63c629aa |
329 | #if CHFI3D_DEB |
81bba717 |
330 | cout<<"failed to calculate bevel error interSS"<<endl; |
7fd59977 |
331 | #endif |
332 | done=Standard_False; |
333 | return done; |
334 | } |
335 | else if (IFaCo1 == 2 && |
336 | !ChFi3d_ComputeCurves(HS1,HS2,Parfin,Pardeb,Gc, |
337 | PGc1,PGc2,tolesp,tol2d,tolreached)) { |
63c629aa |
338 | #if CHFI3D_DEB |
81bba717 |
339 | cout<<"failed to calculate bevel error interSS"<<endl; |
7fd59977 |
340 | #endif |
341 | done=Standard_False; |
342 | return done; |
343 | } |
81bba717 |
344 | // CornerData are updated with results of the intersection. |
7fd59977 |
345 | Standard_Real WFirst = Gc->FirstParameter(); |
346 | Standard_Real WLast = Gc->LastParameter(); |
347 | Standard_Integer Ipoin1; |
348 | Standard_Integer Ipoin2; |
349 | ChFiDS_CommonPoint& cpco1 = Fd1->ChangeVertex(isfirst1,IFaCo1); |
350 | ChFiDS_CommonPoint& cpco2 = Fd2->ChangeVertex(isfirst2,IFaCo2); |
351 | Standard_Real tolpco = Max(cpco1.Tolerance(),cpco2.Tolerance()); |
352 | ChFiDS_CommonPoint& cparc1 = Fd1->ChangeVertex(isfirst1,IFaArc1); |
353 | ChFiDS_CommonPoint& cparc2 = Fd2->ChangeVertex(isfirst2,IFaArc2); |
354 | Standard_Real tolparc = Max(cparc1.Tolerance(),cparc2.Tolerance()); |
355 | Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached)); |
356 | //Corner1 |
357 | Corner1->SetParameters(isfirst1,WFirst,WLast); |
358 | Corner1->SetCurve(ICurv,isfirst1); |
359 | Corner1->ChangePCurve(isfirst1) = PGc1; |
360 | cpco1.Reset(); |
361 | cpco1.SetPoint(PFaCo); |
362 | cpco1.SetTolerance(Max(tolreached,tolpco)); |
363 | Fd1->ChangeInterference(IFaCo1).SetParameter(UIntPC1,isfirst1); |
364 | tolparc = Max(tolparc,tolreached); |
365 | cparc1.SetTolerance(Max(tolparc,tolreached)); |
366 | Ipoin1 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,1),DStr); |
367 | Corner1->SetIndexPoint(Ipoin1,isfirst1,1); |
368 | Ipoin2 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,2),DStr); |
369 | Corner1->SetIndexPoint(Ipoin2,isfirst1,2); |
370 | //Corner2 |
371 | Corner2->SetParameters(isfirst2,WFirst,WLast); |
372 | Corner2->SetCurve(ICurv,isfirst2); |
373 | Corner2->ChangePCurve(isfirst2) = PGc2; |
374 | Fd2->ChangeInterference(IFaCo2).SetParameter(UIntPC2,isfirst2); |
375 | Fd2->ChangeVertex(isfirst2,IFaCo2) = Fd1->Vertex(isfirst1,IFaCo1); |
376 | Fd2->ChangeVertex(isfirst2,IFaArc2) = Fd1->Vertex(isfirst1,IFaArc1); |
377 | if (IFaCo1!=IFaCo2) Corner2->SetOrientation(TopAbs_REVERSED,isfirst2); |
378 | Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaCo1), |
379 | isfirst2,IFaCo2); |
380 | Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaArc1), |
381 | isfirst2,IFaArc2); |
81bba717 |
382 | //The tolerances of points are updated. |
7fd59977 |
383 | Bnd_Box bco,barc; |
384 | if(IFaCo1 == 1) ChFi3d_EnlargeBox(DStr,Corner1,Fd1,bco,barc,isfirst1); |
385 | else ChFi3d_EnlargeBox(DStr,Corner1,Fd1,barc,bco,isfirst1); |
386 | if(IFaCo2 == 1) ChFi3d_EnlargeBox(DStr,Corner2,Fd2,bco,barc,isfirst2); |
387 | else ChFi3d_EnlargeBox(DStr,Corner2,Fd2,barc,bco,isfirst2); |
388 | const ChFiDS_CommonPoint& cparc = Fd1->Vertex(isfirst1,IFaArc1); |
389 | ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc); |
390 | ChFi3d_SetPointTolerance(DStr,barc,Corner1->IndexPoint(isfirst1,IFaArc1)); |
391 | ChFi3d_SetPointTolerance(DStr,bco,Corner1->IndexPoint(isfirst1,IFaCo1)); |
392 | } |
393 | else { |
81bba717 |
394 | // It is necessary to identify the border surface, |
395 | // find the end point of the intersection Surf/Surf |
396 | // by the intersection of the tangency line of the small |
397 | // on the opposing face with the surface of the big, |
398 | // and finally intersect the big with the face at end |
399 | // between this point and the point on arc. |
7fd59977 |
400 | Standard_Boolean parcrois = Standard_False ; |
7fd59977 |
401 | TopExp_Explorer Expl; |
402 | for(Expl.Init(pivot.Oriented(TopAbs_FORWARD),TopAbs_VERTEX); |
403 | Expl.More(); Expl.Next()){ |
404 | if(Expl.Current().IsSame(Vtx)){ |
405 | parcrois = (Expl.Current().Orientation() == TopAbs_FORWARD); |
406 | break; |
407 | } |
408 | } |
409 | Handle(ChFiDS_Stripe) BigCD, SmaCD; |
410 | Handle(ChFiDS_SurfData) BigFD, SmaFD; |
411 | Handle(GeomAdaptor_HSurface) BigHS, SmaHS; |
412 | Standard_Integer IFaCoBig, IFaCoSma, IFaArcBig, IFaArcSma; |
413 | Standard_Boolean isfirstBig, isfirstSma; |
414 | Standard_Real UIntPCBig, UIntPCSma; |
415 | |
416 | if((parcrois && parCP2 > parCP1) || (!parcrois && parCP2 < parCP1)){ |
417 | UIntPCBig = UIntPC2; UIntPCSma = UIntPC1; |
418 | BigHS = HS2; SmaHS = HS1; |
419 | BigCD = Corner2; SmaCD = Corner1; |
420 | BigFD = Fd2; SmaFD = Fd1; |
421 | IFaCoBig = IFaCo2; IFaCoSma = IFaCo1; |
422 | IFaArcBig = IFaArc2; IFaArcSma = IFaArc1; |
423 | isfirstBig = isfirst2; isfirstSma = isfirst1; |
424 | } |
425 | else{ |
426 | UIntPCBig = UIntPC1, UIntPCSma = UIntPC2; |
427 | BigHS = HS1; SmaHS = HS2; |
428 | BigCD = Corner1; SmaCD = Corner2; |
429 | BigFD = Fd1; SmaFD = Fd2; |
430 | IFaCoBig = IFaCo1; IFaCoSma = IFaCo2; |
431 | IFaArcBig = IFaArc1; IFaArcSma = IFaArc2; |
432 | isfirstBig = isfirst1; isfirstSma = isfirst2; |
433 | } |
434 | |
81bba717 |
435 | //Intersection of the big with the small : |
7fd59977 |
436 | //------------------------------------ |
437 | |
81bba717 |
438 | // Pardeb (parameters of point PFaCo) |
439 | // the intersection is checked |
7fd59977 |
440 | ChFi3d_ComputesIntPC (SmaFD->Interference(IFaCoSma), |
441 | BigFD->Interference(IFaCoBig), |
442 | SmaHS,BigHS,UIntPCSma,UIntPCBig); |
443 | gp_Pnt2d UVi; |
444 | UVi = BigFD->Interference(IFaCoBig).PCurveOnSurf()->Value(UIntPCBig); |
445 | Pardeb(3)= UVi.X(); Pardeb(4)=UVi.Y(); |
446 | UVi = SmaFD->Interference(IFaCoSma).PCurveOnSurf()->Value(UIntPCSma); |
447 | Pardeb(1)= UVi.X(); Pardeb(2)=UVi.Y(); |
448 | gp_Pnt PFaCo = SmaHS->Value(UVi.X(),UVi.Y()); |
449 | |
81bba717 |
450 | // Parfin (parameters of point PMil) |
7fd59977 |
451 | const ChFiDS_FaceInterference& FiArcSma = SmaFD->Interference(IFaArcSma); |
452 | Handle(Geom_Curve) ctg = DStr.Curve(FiArcSma.LineIndex()).Curve(); |
453 | Handle(GeomAdaptor_HCurve) Hctg = new GeomAdaptor_HCurve(); |
454 | GeomAdaptor_Curve& bid = Hctg->ChangeCurve(); |
455 | Standard_Real temp,wi; |
456 | |
457 | if (isfirstSma) { |
458 | wi = temp = FiArcSma.FirstParameter(); |
459 | if (UIntPCSma < temp) |
460 | temp = UIntPCSma; |
461 | bid.Load(ctg,temp,FiArcSma.LastParameter()); |
462 | } |
463 | else { |
464 | wi = temp = FiArcSma.LastParameter(); |
465 | if (UIntPCSma > temp) |
466 | temp = UIntPCSma; |
467 | bid.Load(ctg,FiArcSma.FirstParameter(),temp); |
468 | } |
469 | if(SmaFD->Surf() == BigFD->Surf()){ |
470 | Reduce(UIntPCSma,UIntPCBig,SmaHS,BigHS); |
471 | Reduce(UIntPCSma,UIntPCBig,Hctg); |
472 | } |
473 | if(!ChFi3d_IntCS(BigHS,Hctg,UVi,wi)){ |
63c629aa |
474 | #if CHFI3D_DEB |
81bba717 |
475 | cout<<"bevel : failed inter C S"<<endl; |
7fd59977 |
476 | #endif |
477 | done=Standard_False; |
478 | return done; |
479 | } |
480 | Parfin(3) = UVi.X(); Parfin(4) = UVi.Y(); |
481 | UVi = FiArcSma.PCurveOnSurf()->Value(wi); |
482 | Parfin(1) = UVi.X(); Parfin(2) = UVi.Y(); |
483 | gp_Pnt PMil = SmaHS->Value(Parfin(1),Parfin(2)); |
484 | |
485 | Standard_Real tolreached; |
486 | if (!ChFi3d_ComputeCurves(SmaHS,BigHS,Pardeb,Parfin,Gc, |
487 | PGc1,PGc2,tolesp,tol2d,tolreached)) { |
63c629aa |
488 | #if CHFI3D_DEB |
81bba717 |
489 | cout<<"failed to calculate bevel failed interSS"<<endl; |
7fd59977 |
490 | #endif |
491 | done=Standard_False; |
492 | return done; |
493 | } |
81bba717 |
494 | // SmaCD is updated, for it this is all. |
7fd59977 |
495 | Standard_Real WFirst = Gc->FirstParameter(); |
496 | Standard_Real WLast = Gc->LastParameter(); |
497 | Standard_Integer IpointCo, IpointMil, IpointArc; |
498 | ChFiDS_CommonPoint& psmaco = SmaFD->ChangeVertex(isfirstSma,IFaCoSma); |
499 | ChFiDS_CommonPoint& pbigco = BigFD->ChangeVertex(isfirstBig,IFaCoBig); |
500 | Standard_Real tolpco = Max(psmaco.Tolerance(),pbigco.Tolerance()); |
501 | ChFiDS_CommonPoint& psmamil = SmaFD->ChangeVertex(isfirstSma,IFaArcSma); |
502 | Standard_Real tolpmil = psmamil.Tolerance(); |
503 | Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached)); |
504 | |
505 | SmaCD->SetParameters(isfirstSma,WFirst,WLast); |
506 | SmaCD->SetCurve(ICurv,isfirstSma); |
507 | SmaCD->ChangePCurve(isfirstSma) = PGc1; |
508 | psmaco.Reset(); |
509 | psmaco.SetPoint(PFaCo); |
510 | psmaco.SetTolerance(Max(tolpco,tolreached)); |
511 | SmaFD->ChangeInterference(IFaCoSma).SetParameter(UIntPCSma,isfirstSma); |
512 | psmamil.Reset(); |
513 | psmamil.SetPoint(PMil); |
514 | psmamil.SetTolerance(Max(tolpmil,tolreached)); |
515 | SmaFD->ChangeInterference(IFaArcSma).SetParameter(wi,isfirstSma); |
516 | IpointCo = ChFi3d_IndexPointInDS(psmaco,DStr); |
517 | SmaCD->SetIndexPoint(IpointCo,isfirstSma,IFaCoSma); |
518 | IpointMil = ChFi3d_IndexPointInDS(psmamil,DStr); |
519 | SmaCD->SetIndexPoint(IpointMil,isfirstSma,IFaArcSma); |
520 | if (IFaCoSma == 2) SmaCD->SetOrientation(TopAbs_REVERSED,isfirstSma); |
521 | |
81bba717 |
522 | // For BigCD the first results are met in the DS. |
7fd59977 |
523 | BigCD->SetIndexPoint(IpointCo,isfirstBig,IFaCoBig); |
524 | BigFD->ChangeVertex(isfirstBig,IFaCoBig) = psmaco; |
525 | BigFD->ChangeInterference(IFaCoBig).SetParameter(UIntPCBig,isfirstBig); |
526 | |
527 | TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(ICurv); |
528 | Handle(TopOpeBRepDS_CurvePointInterference) Interfp; |
529 | Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointCo,WFirst); |
530 | Li.Append(Interfp); |
531 | Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointMil,WLast); |
532 | Li.Append(Interfp); |
533 | |
81bba717 |
534 | // the transition of curves of intersection on the Big |
7fd59977 |
535 | TopAbs_Orientation tra = BigFD->InterferenceOnS1().Transition(); |
536 | TopAbs_Orientation ofac = DStr.Shape(BigFD->IndexOfS1()).Orientation(); |
537 | TopAbs_Orientation ofil = BigFD->Orientation(); |
538 | TopAbs_Orientation tracurv = TopAbs::Compose(ofac,ofil); |
539 | tracurv = TopAbs::Compose(tracurv,tra); |
540 | if(!isfirstBig) tracurv = TopAbs::Reverse(tracurv); |
541 | if(IFaCoBig != 1) tracurv = TopAbs::Reverse(tracurv); |
542 | |
543 | Handle(TopOpeBRepDS_SurfaceCurveInterference) Interfc; |
544 | Standard_Integer ISurf = BigFD->Surf(); |
545 | Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv); |
546 | DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc); |
547 | |
81bba717 |
548 | //The tolerances of points are updated (beginning). |
7fd59977 |
549 | Bnd_Box bco,bmil,barc; |
550 | if(IFaCoSma == 1) ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bco,bmil,isfirstSma); |
551 | else ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bmil,bco,isfirstSma); |
552 | ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bco,bmil); |
553 | |
81bba717 |
554 | // Intersection of the big with the face at end : |
7fd59977 |
555 | // ------------------------------------------- |
556 | |
81bba717 |
557 | // Pardeb (parameters of PMil) |
558 | // The intersection curve surface is tried again, now with representation |
559 | // pcurve on face of the curve to be sure. |
7fd59977 |
560 | TopoDS_Face F = TopoDS::Face(DStr.Shape(SmaFD->Index(IFaArcSma))); |
561 | Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface(F); |
562 | Standard_Real fsma = FiArcSma.FirstParameter(); |
563 | Standard_Real lsma = FiArcSma.LastParameter(); |
564 | Standard_Real deltSma = 0.05 * (lsma - fsma); |
565 | Handle(Geom2d_Curve) pcpc = SmaFD->Interference(IFaArcSma).PCurveOnFace(); |
566 | fsma = Max(pcpc->FirstParameter(),wi-deltSma); |
567 | lsma = Min(pcpc->LastParameter(),wi+deltSma); |
568 | if ( lsma<fsma ) { |
569 | done=Standard_False; |
570 | return done; |
571 | } |
572 | Handle(Geom2dAdaptor_HCurve) c2df = |
573 | new Geom2dAdaptor_HCurve(SmaFD->Interference(IFaArcSma).PCurveOnFace(),fsma,lsma); |
574 | Adaptor3d_CurveOnSurface consf(c2df,HF); |
575 | Handle(Adaptor3d_HCurveOnSurface) Hconsf = new Adaptor3d_HCurveOnSurface(consf); |
576 | if(!ChFi3d_IntCS(BigHS,Hconsf,UVi,wi)) { |
63c629aa |
577 | #if CHFI3D_DEB |
81bba717 |
578 | cout<<"bevel : failed inter C S"<<endl; |
7fd59977 |
579 | #endif |
580 | done=Standard_False; |
581 | return done; |
582 | } |
583 | Pardeb(3) = UVi.X(); Pardeb(4) = UVi.Y(); |
584 | UVi = SmaFD->Interference(IFaArcSma).PCurveOnFace()->Value(wi); |
585 | Pardeb(1) = UVi.X(); Pardeb(2) = UVi.Y(); |
586 | gp_Pnt2d ppff1 = UVi; |
587 | |
81bba717 |
588 | // Parfin (parameters of the point cpend) |
7fd59977 |
589 | Standard_Real ptg = BigFD->Interference(IFaArcBig).Parameter(isfirstBig); |
590 | UVi = BigFD->Interference(IFaArcBig).PCurveOnSurf()->Value(ptg); |
591 | Parfin(3) = UVi.X(); Parfin(4) = UVi.Y(); |
592 | ChFiDS_CommonPoint& cpend = BigFD->ChangeVertex(isfirstBig,IFaArcBig); |
593 | TopoDS_Edge etest = cpend.Arc(); |
594 | if(BRep_Tool::IsClosed(etest,F)) etest.Reverse(); |
595 | BRepAdaptor_Curve2d arc(etest,F); |
596 | UVi = arc.Value(cpend.ParameterOnArc()); |
597 | Parfin(1) = UVi.X(); Parfin(2) = UVi.Y(); |
598 | gp_Pnt2d ppff2 = UVi; |
599 | |
600 | // Intersection. |
601 | Standard_Real uu1,uu2,vv1,vv2; |
602 | ChFi3d_Boite(ppff1,ppff2,uu1,uu2,vv1,vv2); |
81bba717 |
603 | // for the case when two chamfers are on two edges OnSame, |
604 | // it is necessary to extend the surface carrying F, or at least |
605 | // not to limit it. |
7fd59977 |
606 | ChFi3d_BoundFac(HF->ChangeSurface(),uu1,uu2,vv1,vv2,Standard_True); |
607 | |
608 | if (!ChFi3d_ComputeCurves(HF,BigHS,Pardeb,Parfin,Gc, |
609 | PGc1,PGc2,tolesp,tol2d,tolreached)) { |
63c629aa |
610 | #if CHFI3D_DEB |
81bba717 |
611 | cout<<"fail calculation bevel fail interSS"<<endl; |
7fd59977 |
612 | #endif |
613 | done=Standard_False; |
614 | return done; |
615 | } |
616 | |
81bba717 |
617 | // End of update of the BigCD and the DS. |
7fd59977 |
618 | WFirst = Gc->FirstParameter(); |
619 | WLast = Gc->LastParameter(); |
620 | ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached)); |
621 | cpend.SetTolerance(Max(cpend.Tolerance(),tolreached)); |
622 | IpointArc = ChFi3d_IndexPointInDS(cpend,DStr); |
623 | BigCD->SetIndexPoint(IpointArc,isfirstBig,IFaArcBig); |
624 | |
625 | TopOpeBRepDS_ListOfInterference& Li7 = DStr.ChangeCurveInterferences(ICurv); |
626 | Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointMil,WFirst); |
627 | Li7.Append(Interfp); |
628 | Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointArc,WLast); |
629 | Li7.Append(Interfp); |
630 | Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv); |
631 | DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc); |
632 | BigCD->InDS(isfirstBig); |
633 | |
81bba717 |
634 | // Finally the information on faces is placed in the DS. |
7fd59977 |
635 | Standard_Integer IShape = DStr.AddShape(F); |
636 | if(SmaFD->Surf() == BigFD->Surf()){ |
637 | tracurv = TopAbs::Compose(etest.Orientation(), |
638 | cpend.TransitionOnArc()); |
639 | } |
640 | else { |
641 | TopExp_Explorer Exp; |
642 | for (Exp.Init(F.Oriented(TopAbs_FORWARD), |
643 | TopAbs_EDGE);Exp.More();Exp.Next()) { |
644 | if (Exp.Current().IsSame(etest)) { |
645 | tracurv = TopAbs::Compose(Exp.Current().Orientation(), |
646 | cpend.TransitionOnArc()); |
647 | break; |
648 | } |
649 | } |
650 | } |
651 | Interfc = ChFi3d_FilCurveInDS(ICurv,IShape,PGc1,tracurv); |
652 | DStr.ChangeShapeInterferences(IShape).Append(Interfc); |
653 | |
81bba717 |
654 | //The tolerances of points are updated (end). |
7fd59977 |
655 | Handle(ChFiDS_Stripe) bidst; |
656 | if(IFaCoBig == 1) ChFi3d_EnlargeBox(DStr,bidst,BigFD,bco,barc,isfirstBig); |
657 | else ChFi3d_EnlargeBox(DStr,bidst,BigFD,barc,bco,isfirstBig); |
658 | ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bmil,barc); |
659 | ChFi3d_EnlargeBox(HF,PGc1,WFirst,WLast,bmil,barc); |
660 | ChFi3d_EnlargeBox(Gc,WFirst,WLast,bmil,barc); |
661 | const ChFiDS_CommonPoint& cparc = BigFD->Vertex(isfirstBig,IFaArcBig); |
662 | ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc); |
663 | |
664 | ChFi3d_SetPointTolerance(DStr,bco,SmaCD->IndexPoint(isfirstSma,IFaCoSma)); |
665 | ChFi3d_SetPointTolerance(DStr,bmil,SmaCD->IndexPoint(isfirstSma,IFaArcSma)); |
666 | ChFi3d_SetPointTolerance(DStr,barc,BigCD->IndexPoint(isfirstBig,IFaArcBig)); |
667 | } |
668 | done = 1; |
669 | |
670 | return done; |
671 | } |
672 | |
673 | |
674 | |
675 | |
676 | |
677 | |