1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_PipeDriver.hxx>
25 #include <GEOMImpl_IPipeDiffSect.hxx>
26 #include <GEOMImpl_IPipeShellSect.hxx>
27 #include <GEOMImpl_IPipeBiNormal.hxx>
28 #include <GEOMImpl_IPipe.hxx>
29 #include <GEOMImpl_IPipePath.hxx>
30 #include <GEOMImpl_GlueDriver.hxx>
31 #include <GEOMImpl_Types.hxx>
33 #include <GEOM_Function.hxx>
35 #include <GEOMUtils.hxx>
37 #include <ShapeAnalysis_FreeBounds.hxx>
38 #include <ShapeAnalysis_Edge.hxx>
39 #include <ShapeFix_Face.hxx>
40 #include <ShapeFix_Shell.hxx>
41 #include <ShapeFix_Shape.hxx>
42 #include <ShapeFix_ShapeTolerance.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRep_Builder.hxx>
46 #include <BRepBuilderAPI_Copy.hxx>
47 #include <BRepBuilderAPI_MakeFace.hxx>
48 #include <BRepBuilderAPI_MakeWire.hxx>
49 #include <BRepBuilderAPI_Sewing.hxx>
50 #include <BRepCheck_Analyzer.hxx>
51 #include <BRepGProp.hxx>
52 #include <BRepOffsetAPI_MakePipe.hxx>
53 #include <BRepOffsetAPI_MakePipeShell.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <TopoDS_Wire.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TopoDS_Solid.hxx>
63 #include <TopoDS_Shell.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Compound.hxx>
66 #include <TopTools_SequenceOfShape.hxx>
67 #include <TopTools_HSequenceOfShape.hxx>
68 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
69 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <GProp_GProps.hxx>
74 #include <GeomAPI_ProjectPointOnCurve.hxx>
75 #include <GeomAPI_Interpolate.hxx>
76 #include <Geom_TrimmedCurve.hxx>
77 #include <Geom_Plane.hxx>
78 #include <Geom_RectangularTrimmedSurface.hxx>
79 #include <Geom_BezierSurface.hxx>
80 #include <Geom_Line.hxx>
81 #include <Geom_Conic.hxx>
82 #include <Geom_BSplineCurve.hxx>
83 #include <Geom_BSplineSurface.hxx>
84 #include <GeomFill_BSplineCurves.hxx>
85 #include <GeomConvert_ApproxCurve.hxx>
86 #include <GeomConvert.hxx>
88 #include <TColgp_SequenceOfPnt.hxx>
89 #include <TColgp_HArray1OfPnt.hxx>
90 #include <TColgp_Array2OfPnt.hxx>
91 #include <TColStd_HSequenceOfTransient.hxx>
93 #include <Precision.hxx>
95 #include <Standard_NullObject.hxx>
96 #include <Standard_TypeMismatch.hxx>
97 #include <Standard_ConstructionError.hxx>
99 #include "utilities.h"
102 //=======================================================================
105 //=======================================================================
106 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
108 static Standard_GUID aPipeDriver ("FF1BBB19-5D14-4df2-980B-3A668264EA16");
112 //=======================================================================
113 //function : GEOMImpl_PipeDriver
115 //=======================================================================
116 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
120 //=======================================================================
121 //function : FillForOtherEdges
122 //purpose : auxilary for CreatePipeForShellSections()
123 //=======================================================================
124 static bool FillForOtherEdges(const TopoDS_Shape& F1,
125 const TopoDS_Shape& E1,
126 const TopoDS_Shape& V1,
127 TopTools_IndexedDataMapOfShapeShape& FF)
129 //cout<<"FillForOtherEdges"<<endl;
130 // find other pairs for vertexes and edges
131 // creating map of vertex edges for both faces
132 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
133 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
134 if (!FF.Contains(F1))
135 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
136 if (!FF.Contains(E1))
137 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
138 if (!FF.Contains(V1))
139 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
140 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
141 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
142 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
143 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
144 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
146 TopoDS_Edge ES1 = TopoDS::Edge(E1);
147 TopoDS_Edge ES2 = TopoDS::Edge(E2);
148 TopoDS_Shape VS1 = V1;
149 TopoDS_Shape VS2 = V2;
151 ShapeAnalysis_Edge sae;
153 if (!aMapVertEdge1.Contains(VS1))
154 MESSAGE (" FillForOtherEdges: map aMapVertEdge1 not contains key VS1");
155 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
156 //TopoDS_Shape E1next;
157 TopTools_ListIteratorOfListOfShape anIter1(aList1);
158 if (anIter1.Value().IsSame(ES1)) {
161 //E1next = anIter1.Value();
162 if (!aMapVertEdge2.Contains(VS2))
163 MESSAGE (" FillForOtherEdges: map aMapVertEdge2 not contains key VS2");
164 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
165 //TopoDS_Shape E2next;
166 TopTools_ListIteratorOfListOfShape anIter2(aList2);
167 if (anIter2.Value().IsSame(ES2)) {
170 //E2next = anIter2.Value();
171 //ES1 = TopoDS::Edge(E1next);
172 //ES2 = TopoDS::Edge(E2next);
173 ES1 = TopoDS::Edge(anIter1.Value());
174 ES2 = TopoDS::Edge(anIter2.Value());
175 if (!FF.Contains(ES1)) {
178 if (VS1.IsSame(sae.FirstVertex(ES1)))
179 VS1 = sae.LastVertex(ES1);
181 VS1 = sae.FirstVertex(ES1);
182 if (VS2.IsSame(sae.FirstVertex(ES2)))
183 VS2 = sae.LastVertex(ES2);
185 VS2 = sae.FirstVertex(ES2);
188 if (!FF.Contains(VS1)) {
196 //=======================================================================
197 //function : FillCorrespondingEdges
198 //purpose : auxilary for CreatePipeForShellSections()
199 //=======================================================================
200 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
201 const TopoDS_Shape& FS2,
202 const TopoDS_Vertex& aLoc1,
203 const TopoDS_Vertex& aLoc2,
204 const TopoDS_Wire& aWirePath,
205 TopTools_IndexedDataMapOfShapeShape& FF)
207 //cout<<"FillCorrespondingEdges"<<endl;
208 // find corresponding edges
209 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
210 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
211 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
212 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
213 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
214 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
215 aBuilder.Add(aWire1, aLoc1);
216 aBuilder.Add(aWire2, aLoc2);
217 if (!aBuilder.IsReady()) {
221 TopoDS_Shape aShape = aBuilder.Shape();
229 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
231 ShapeAnalysis_Edge sae;
232 double tol = Max(BRep_Tool::Tolerance(TopoDS::Face(FS1)),
233 BRep_Tool::Tolerance(TopoDS::Face(FS2)));
234 TopTools_MapOfShape Vs1,Vs2;
236 exp.Init(FS1, TopAbs_EDGE);
237 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
238 TopoDS_Vertex V11 = sae.FirstVertex(E1);
239 TopoDS_Vertex V21 = sae.LastVertex(E1);
240 gp_Pnt P11 = BRep_Tool::Pnt(V11);
241 gp_Pnt P21 = BRep_Tool::Pnt(V21);
242 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
243 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
244 // find corresponding vertexes from created shape
245 TopoDS_Vertex VN11,VN21;
246 for (exp.Init(aShape, TopAbs_VERTEX); exp.More(); exp.Next()) {
247 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
248 gp_Pnt P = BRep_Tool::Pnt(V);
249 if (P.Distance(P11)<tol) {
252 if (P.Distance(P21)<tol) {
256 // find edge contains VN11 and VN21 and corresponding vertexes
257 TopoDS_Vertex VN12,VN22;
258 for (exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
259 TopoDS_Shape F = exp.Current();
260 TopExp_Explorer expe;
262 for (expe.Init(F, TopAbs_EDGE); expe.More(); expe.Next()) {
263 TopoDS_Edge E = TopoDS::Edge(expe.Current());
264 TopoDS_Vertex VF = sae.FirstVertex(E);
265 TopoDS_Vertex VL = sae.LastVertex(E);
266 if ((VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11))) {
272 for (expe.Init(F, TopAbs_EDGE); expe.More(); expe.Next()) {
273 TopoDS_Edge E = TopoDS::Edge(expe.Current());
274 TopoDS_Vertex VF = sae.FirstVertex(E);
275 TopoDS_Vertex VL = sae.LastVertex(E);
276 if (VF.IsSame(VN11) && !VL.IsSame(VN21))
278 if (VL.IsSame(VN11) && !VF.IsSame(VN21))
280 if (VF.IsSame(VN21) && !VL.IsSame(VN11))
282 if (VL.IsSame(VN21) && !VF.IsSame(VN11))
288 // find vertexes from FS2 corresponded to VN12 and VN22
289 // and find edge from FS2 contains V12 and V22,
290 // this edge will be corresponded to edge E1
291 TopoDS_Vertex V12,V22;
292 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
293 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
294 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
295 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
297 TopExp_Explorer expe;
298 for (expe.Init(FS2, TopAbs_EDGE); expe.More(); expe.Next()) {
299 TopoDS_Edge E = TopoDS::Edge(expe.Current());
300 TopoDS_Vertex VF = sae.FirstVertex(E);
301 TopoDS_Vertex VL = sae.LastVertex(E);
302 gp_Pnt PF = BRep_Tool::Pnt(VF);
303 gp_Pnt PL = BRep_Tool::Pnt(VL);
304 if (PF.Distance(PN12)<tol && PL.Distance(PN22)<tol) {
310 if (PF.Distance(PN22)<tol && PL.Distance(PN12)<tol) {
321 // find other pairs for vertexes and edges
322 // creating map of vertex edges for both faces
323 return FillForOtherEdges(FS1,E1,V21,FF);
328 //=======================================================================
329 //function : FillCorrespondingEdges
330 //purpose : auxilary for CreatePipeShellsWithoutPath()
331 //=======================================================================
332 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
333 const TopoDS_Shape& FS2,
334 const TopoDS_Vertex& aLoc1,
335 const TopoDS_Vertex& aLoc2,
336 TopTools_IndexedDataMapOfShapeShape& FF)
338 //cout<<"FillCorrespondingEdges"<<endl;
340 gp_Pnt P1 = BRep_Tool::Pnt(aLoc1);
341 gp_Pnt P2 = BRep_Tool::Pnt(aLoc2);
344 ShapeAnalysis_Edge sae;
345 double tol = Max(BRep_Tool::Tolerance(TopoDS::Face(FS1)),
346 BRep_Tool::Tolerance(TopoDS::Face(FS2)));
347 TopTools_MapOfShape Vs1,Vs2;
349 TopoDS_Vertex V11=aLoc1, V12=aLoc2, V21, V22;
352 TopExp_Explorer exp1;
353 for (exp1.Init(FS1,TopAbs_EDGE); exp1.More(); exp1.Next()) {
354 E1 = TopoDS::Edge(exp1.Current());
355 TopoDS_Vertex V1 = sae.FirstVertex(E1);
356 TopoDS_Vertex V2 = sae.LastVertex(E1);
357 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
358 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
359 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
360 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
361 if (P1.Distance(Ptmp1)<tol) {
365 if (P1.Distance(Ptmp2)<tol) {
372 TopoDS_Vertex VE21,VE22;
374 for (exp1.Init(FS2,TopAbs_EDGE); exp1.More() && nbe<2; exp1.Next()) {
375 TopoDS_Edge E = TopoDS::Edge(exp1.Current());
376 TopoDS_Vertex V1 = sae.FirstVertex(E);
377 TopoDS_Vertex V2 = sae.LastVertex(E);
378 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
379 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
380 if (P2.Distance(Ptmp1)<tol) {
392 if (P2.Distance(Ptmp2)<tol) {
406 gp_Pnt PV21 = BRep_Tool::Pnt(V21);
407 gp_Pnt PE21 = BRep_Tool::Pnt(VE21);
408 gp_Pnt PE22 = BRep_Tool::Pnt(VE22);
409 gp_Vec aDir1(PV21,PE21);
410 gp_Vec aDir2(PV21,PE22);
411 double ang1 = aDir.Angle(aDir1);
412 double ang2 = aDir.Angle(aDir2);
413 if (fabs(ang1)<fabs(ang2)) {
426 // find other pairs for vertexes and edges
427 return FillForOtherEdges(FS1,E1,V21,FF);
430 //=======================================================================
431 //function : FindNextPairOfFaces
432 //purpose : auxilary for CreatePipeForShellSections()
433 //=======================================================================
434 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
435 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
436 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
437 TopTools_IndexedDataMapOfShapeShape& FF,
440 //cout<<"FindNextPairOfFaces"<<endl;
441 TopExp_Explorer anExp;
442 for (anExp.Init(aCurFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
443 TopoDS_Shape E1 = anExp.Current();
444 if (!FF.Contains(E1)) {
446 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
448 if (!FF.Contains(E1))
449 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
450 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
451 TopExp_Explorer anExpV;
452 anExpV.Init(E1, TopAbs_VERTEX);
453 TopoDS_Shape V1 = anExpV.Current();
454 if (!FF.Contains(V1)) {
456 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
459 if (!aMapEdgeFaces1.Contains(E1))
460 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
461 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
462 if (aList1.Extent()<2)
464 TopTools_ListIteratorOfListOfShape anIter(aList1);
465 if (anIter.Value().IsEqual(aCurFace)) {
468 TopoDS_Shape F1other = anIter.Value();
469 if (FF.Contains(F1other))
472 if (!FF.Contains(aCurFace))
473 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
474 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
475 if (!aMapEdgeFaces2.Contains(E2))
476 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
477 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
478 if (aList2.Extent()<2) {
480 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
482 TopTools_ListIteratorOfListOfShape anIter2(aList2);
483 if (anIter2.Value().IsEqual(F2)) {
486 TopoDS_Shape F2other = anIter2.Value();
487 FF.Add(F1other,F2other);
489 // add pairs of edges to FF
490 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
493 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
496 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
500 //=======================================================================
501 //function : FindFirstPairFaces
502 //purpose : auxilary for Execute()
503 //=======================================================================
504 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
505 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
506 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
508 //cout<<"FindFirstPairFaces"<<endl;
510 // check if vertexes are sub-shapes of sections
511 gp_Pnt P1 = BRep_Tool::Pnt(V1);
512 gp_Pnt P2 = BRep_Tool::Pnt(V2);
513 TopoDS_Vertex V1new,V2new;
515 double mindist = 1.e10;
516 for (exp.Init(S1, TopAbs_VERTEX); exp.More(); exp.Next()) {
517 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
518 gp_Pnt P = BRep_Tool::Pnt(V);
519 double dist = P1.Distance(P);
526 for (exp.Init(S2, TopAbs_VERTEX); exp.More(); exp.Next()) {
527 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
528 gp_Pnt P = BRep_Tool::Pnt(V);
529 double dist = P2.Distance(P);
536 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
537 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
538 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
539 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
540 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
541 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
543 // replace vertexes if it is needed
544 if (!V1.IsSame(V1new)) {
546 P1 = BRep_Tool::Pnt(V1);
547 MESSAGE (" replace V1");
550 MESSAGE (" not replace V1");
551 if (!V2.IsSame(V2new)) {
553 P2 = BRep_Tool::Pnt(V2);
554 MESSAGE (" replace V2");
557 MESSAGE (" not replace V2");
559 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
560 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
561 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
562 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
564 if (!aMapVertFaces1.Contains(V1))
565 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
566 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
567 TopTools_ListIteratorOfListOfShape anIter1(aList1);
568 FS1 = anIter1.Value();
570 double x1=0., y1=0., z1=0.;
572 for (exp.Init(FS1, TopAbs_VERTEX); exp.More(); exp.Next()) {
573 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
574 gp_Pnt P = BRep_Tool::Pnt(V);
580 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
582 TColgp_SequenceOfPnt Ps;
583 TopTools_SequenceOfShape Fs;
584 if (!aMapVertFaces2.Contains(V2))
585 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
586 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
587 TopTools_ListIteratorOfListOfShape anIter2(aList2);
588 for (; anIter2.More(); anIter2.Next()) {
589 TopoDS_Shape F = anIter2.Value();
590 double x2=0., y2=0., z2=0.;
592 for (exp.Init(F, TopAbs_VERTEX); exp.More(); exp.Next()) {
593 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
594 gp_Pnt P = BRep_Tool::Pnt(V);
600 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
607 double MinAng = M_PI;
609 for (; i<=Fs.Length(); i++) {
610 gp_Vec tmpDir(PM1,Ps(i));
611 double ang = fabs(aDir.Angle(tmpDir));
620 //=======================================================================
621 //function : CreatePipeWithDifferentSections
623 //=======================================================================
624 TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
625 (const TopoDS_Wire& theWirePath,
626 const Handle(TopTools_HSequenceOfShape) theHSeqBases,
627 const Handle(TopTools_HSequenceOfShape) theHSeqLocs,
628 const Standard_Boolean theWithContact,
629 const Standard_Boolean theWithCorrect)
633 TopoDS_Wire aWirePath = theWirePath;
635 Standard_Integer nbBases = theHSeqBases->Length();
636 Standard_Integer nbLocs = (theHSeqLocs.IsNull() ? 0 : theHSeqLocs->Length());
638 if (nbLocs && nbLocs != nbBases) {
639 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
642 TopTools_SequenceOfShape aSeqBases;
643 TopTools_SequenceOfShape aSeqLocs;
644 TopTools_SequenceOfShape aSeqFaces;
646 Standard_Integer i = 1;
647 for (i = 1; i <= nbBases; i++) {
648 if (theHSeqBases->Value(i).IsNull())
651 // Make copy to prevent modifying of base object 0020766 : EDF 1320
652 TopoDS_Shape aShapeBase;
653 BRepBuilderAPI_Copy Copy (theHSeqBases->Value(i));
655 aShapeBase = Copy.Shape();
657 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
659 //if for section was specified face with a few wires then a few
660 // pipes were build and make solid
661 Standard_Boolean NeedCreateSolid = Standard_False;
662 if (aTypeBase == TopAbs_SHELL) {
663 // create wire as boundary contour if shell is no closed
664 // get free boundary shapes
665 ShapeAnalysis_FreeBounds anAnalizer(aShapeBase);
666 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
667 TopExp_Explorer anExp;
669 Standard_Integer NbWires = 0;
670 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
672 aWire = anExp.Current();
676 Standard_ConstructionError::Raise("Bad shell is used as section ");
678 NeedCreateSolid = Standard_True;
679 aSeqFaces.Append(aShapeBase);
680 aSeqBases.Append(aWire);
682 else if (aTypeBase == TopAbs_FACE) {
683 NeedCreateSolid = Standard_True;
684 //for case one path should be used other type function
685 aSeqFaces.Append(aShapeBase);
686 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
687 for (; aExpW.More(); aExpW.Next()) {
688 TopoDS_Shape aWireProf = aExpW.Current();
689 aSeqBases.Append(aWireProf);
692 else if (aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
693 aSeqBases.Append(aShapeBase);
695 else if (aTypeBase == TopAbs_EDGE) {
696 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
697 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
698 aSeqBases.Append(aWireProf);
701 TopoDS_Shape aShapeLoc = theHSeqLocs->Value(i);
702 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
704 aSeqLocs.Append(aShapeLoc);
708 nbLocs = aSeqLocs.Length();
711 TopTools_SequenceOfShape Edges;
713 // we have to check that each location shape is a vertex from
714 // path and update aSeqLocs if it is needed (and possible)
715 TColgp_SequenceOfPnt PLocs;
716 for (i=1; i<=nbLocs; i++) {
717 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
718 PLocs.Append(BRep_Tool::Pnt(V));
720 //TopTools_SequenceOfShape Edges;
721 TopExp_Explorer anExp;
722 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
723 Edges.Append(anExp.Current());
725 int nbEdges = Edges.Length();
726 ShapeAnalysis_Edge sae;
727 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
728 double tol = BRep_Tool::Tolerance(edge);
729 TopoDS_Vertex VF = sae.FirstVertex(edge);
730 gp_Pnt PF = BRep_Tool::Pnt(VF);
731 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
732 if (PF.Distance(PLocs.First()) > tol) {
733 Standard_ConstructionError::Raise
734 ("First location shapes is not coincided with first vertex of aWirePath");
736 aSeqLocs.ChangeValue(1) = VF;
737 edge = TopoDS::Edge(Edges.Last());
738 tol = BRep_Tool::Tolerance(edge);
739 TopoDS_Vertex VL = sae.LastVertex(edge);
740 gp_Pnt PL = BRep_Tool::Pnt(VL);
741 if (PL.Distance(PLocs.Last()) > tol) {
742 Standard_ConstructionError::Raise
743 ("Last location shapes is not coincided with last vertex of aWirePath");
745 aSeqLocs.ChangeValue(nbLocs) = VL;
747 for (i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
748 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
749 tol = BRep_Tool::Tolerance(edge);
750 TopoDS_Vertex V1 = sae.FirstVertex(E);
751 TopoDS_Vertex V2 = sae.LastVertex(E);
752 gp_Pnt P1 = BRep_Tool::Pnt(V1);
753 gp_Pnt P2 = BRep_Tool::Pnt(V2);
754 if (P2.Distance(PLocs.Value(jcurr)) < tol) {
755 aSeqLocs.ChangeValue(jcurr) = V2;
759 // find distance between E and aLocs(jcurr)
761 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
762 GeomAPI_ProjectPointOnCurve PPCurve (PLocs.Value(jcurr),C);
763 if (PPCurve.NbPoints()>0 &&
764 PLocs.Value(jcurr).Distance(PPCurve.Point(1)) < tol) {
765 double param = PPCurve.Parameter(1);
768 // split current edge
769 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
770 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
775 if (Pfp.Distance(P1)<tol) {
776 B.MakeEdge(E1,tc1,tol);
778 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
779 B.Add(E1,TopoDS::Vertex(tmpV));
780 B.MakeEdge(E2,tc2,tol);
781 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
782 B.Add(E2,TopoDS::Vertex(tmpV));
786 B.MakeEdge(E1,tc2,tol);
787 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
788 B.Add(E1,TopoDS::Vertex(tmpV));
791 B.MakeEdge(E2,tc1,tol);
793 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
794 B.Add(E2,TopoDS::Vertex(tmpV));
799 Edges.InsertAfter(i-1,E1);
800 Edges.InsertAfter(i,E2);
804 if (nbEdges<Edges.Length()) {
805 // one of edges was splitted => we have to update WirePath
809 for (i=1; i<=Edges.Length(); i++) {
810 B.Add(W,TopoDS::Edge(Edges.Value(i)));
816 // check curvature of wire for condition that
817 // max summary angle between directions along
818 // wire path must be < 4*PI. If not - split wire
819 // and seguences of shapes, perform pipe for each
820 // and make sewing after that
822 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
827 double SumAng = fabs(Vec1.Angle(Vec2));
830 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
832 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
833 for (i=2; i<=Edges.Length(); i++) {
834 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
835 double tol = BRep_Tool::Tolerance(edge);
836 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
838 double ang = fabs(Vec1.Angle(Vec2));
842 SplitEdgeNums.Append(i-1);
844 for (j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
845 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
846 gp_Pnt P = BRep_Tool::Pnt(aVert);
847 if (P1.Distance(P) < tol) {
848 SplitLocNums.Append(j);
858 if (SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0) {
859 TopTools_SequenceOfShape aSeqRes;
860 int nn, num1 = 1, num2 = 1;
861 for (nn=1; nn<=SplitEdgeNums.Length(); nn++) {
862 // create wirepath and sequences of shapes
866 for (i=num1; i<=SplitEdgeNums.Value(nn); i++) {
867 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
869 num1 = SplitEdgeNums.Value(nn) + 1;
870 TopTools_SequenceOfShape aTmpSeqBases;
871 TopTools_SequenceOfShape aTmpSeqLocs;
872 for (i=num2; i<=SplitLocNums.Value(nn); i++) {
873 aTmpSeqBases.Append(aSeqBases.Value(i));
874 aTmpSeqLocs.Append(aSeqLocs.Value(i));
876 num2 = SplitLocNums.Value(nn);
878 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
879 Standard_Integer nbShapes = aTmpSeqBases.Length();
880 for (i=1; i<=nbShapes; i++) {
881 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
882 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
883 aBuilder.Add(aTmpSeqBases.Value(i), aVert, theWithContact, theWithCorrect);
885 if (!aBuilder.IsReady()) {
886 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
889 TopoDS_Shape resShape = aBuilder.Shape();
890 aSeqRes.Append(resShape);
892 // create wirepath and sequences of shapes for last part
896 for (i=num1; i<=Edges.Length(); i++) {
897 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
899 TopTools_SequenceOfShape aTmpSeqBases;
900 TopTools_SequenceOfShape aTmpSeqLocs;
901 for (i=num2; i<=aSeqLocs.Length(); i++) {
902 aTmpSeqBases.Append(aSeqBases.Value(i));
903 aTmpSeqLocs.Append(aSeqLocs.Value(i));
905 // make pipe for last part
906 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
907 Standard_Integer nbShapes = aTmpSeqBases.Length();
908 for (i=1; i<=nbShapes; i++) {
909 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
910 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
911 aBuilder.Add(aTmpSeqBases.Value(i), aVert, theWithContact, theWithCorrect);
913 if (!aBuilder.IsReady()) {
914 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
917 TopoDS_Shape resShape = aBuilder.Shape();
918 aSeqRes.Append(resShape);
919 // make sewing for result
920 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
921 aSewing->SetTolerance(Precision::Confusion());
922 aSewing->SetFaceMode(Standard_True);
923 aSewing->SetFloatingEdgesMode(Standard_False);
924 aSewing->SetNonManifoldMode(Standard_False);
925 for (i=1; i<=aSeqRes.Length(); i++) {
926 aSewing->Add(aSeqRes.Value(i));
929 aShape = aSewing->SewedShape();
932 // old implementation without splitting
933 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
935 Standard_Integer nbShapes = aSeqBases.Length();
936 Standard_Integer step = nbShapes/nbBases;
938 if (nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
939 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
941 Standard_Integer ind =0;
942 for (i = 1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
943 TopTools_SequenceOfShape usedBases;
944 Standard_Integer j = 1;
945 for (; j <= nbBases; j++) {
946 ind = i + (j-1)*step;
947 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
948 usedBases.Append(aWireProf);
950 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
951 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
952 aBuilder.Add(aWireProf, aVert, theWithContact, theWithCorrect);
955 aBuilder.Add(aWireProf, theWithContact, theWithCorrect);
957 if (!aBuilder.IsReady()) {
958 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
961 aShape = aBuilder.Shape();
962 aSeqFaces.Append(aShape);
963 for (j = 1; j <=usedBases.Length(); j++)
964 aBuilder.Delete(usedBases.Value(j));
967 //for case if section is face
968 if (aSeqFaces.Length() >1) {
970 TopoDS_Compound aComp;
971 aB.MakeCompound(aComp);
972 for (i = 1; i <= aSeqFaces.Length(); i++)
973 aB.Add(aComp,aSeqFaces.Value(i));
981 //=======================================================================
982 //function : CreatePipeForShellSections
983 //purpose : auxilary for Execute()
984 //=======================================================================
985 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
988 //cout<<"CreatePipeForShellSections"<<endl;
993 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
994 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
995 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
996 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
997 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
998 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1000 Standard_Integer nbBases = aBasesObjs->Length(),
1001 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
1002 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
1004 if (nbLocs != nbBases) {
1005 if (aCI) delete aCI;
1006 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
1008 if (nbSubBases && nbSubBases != nbBases) {
1009 if (aCI) delete aCI;
1010 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
1013 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1015 TopTools_SequenceOfShape VLocs;
1016 for (i=1; i<=nbBases; i++) {
1017 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
1018 if (anItemLoc.IsNull())
1020 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
1021 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
1022 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
1024 VLocs.Append(aShapeLoc);
1026 nbLocs = VLocs.Length();
1027 if (nbLocs != nbBases) {
1028 if (aCI) delete aCI;
1029 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
1031 // split wire path by location points
1032 TColgp_SequenceOfPnt PLocs;
1033 for (i=1; i<=nbLocs; i++) {
1034 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
1035 PLocs.Append(BRep_Tool::Pnt(V));
1038 TopTools_SequenceOfShape Edges;
1039 TopTools_SequenceOfShape Wires;
1040 ShapeAnalysis_Edge sae;
1043 TopExp_Explorer anExp;
1044 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
1045 Edges.Append(anExp.Current());
1047 Standard_Integer Num1 = 0;
1048 Standard_Integer Num2 = 0;
1049 for (i=1; i<=Edges.Length(); i++) {
1050 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
1051 double tol = BRep_Tool::Tolerance(E);
1052 TopoDS_Vertex V1 = sae.FirstVertex(E);
1053 TopoDS_Vertex V2 = sae.LastVertex(E);
1054 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1055 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1056 if (P1.Distance(PLocs.First()) < tol) {
1059 if (P2.Distance(PLocs.Last()) < tol) {
1063 if (Num1>0 && Num2>0) {
1066 for (i=Num1; i<=Num2; i++) {
1067 B.Add(W,Edges.Value(i));
1072 Wires.Append(aWirePath);
1076 TopExp_Explorer anExp;
1077 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
1078 Edges.Append(anExp.Current());
1080 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
1081 double tol = BRep_Tool::Tolerance(edge);
1082 TopoDS_Vertex VF = sae.FirstVertex(edge);
1083 gp_Pnt PF = BRep_Tool::Pnt(VF);
1084 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
1085 if (PF.Distance(PLocs.First()) > tol) {
1086 if (aCI) delete aCI;
1087 Standard_ConstructionError::Raise
1088 ("First location shapes is not coincided with first vertex of aWirePath");
1090 VLocs.ChangeValue(1) = VF;
1091 edge = TopoDS::Edge(Edges.Last());
1092 tol = BRep_Tool::Tolerance(edge);
1093 TopoDS_Vertex VL = sae.LastVertex(edge);
1094 gp_Pnt PL = BRep_Tool::Pnt(VL);
1095 if (PL.Distance(PLocs.Last()) > tol) {
1096 if (aCI) delete aCI;
1097 Standard_ConstructionError::Raise
1098 ("Last location shapes is not coincided with last vertex of aWirePath");
1100 VLocs.ChangeValue(nbLocs) = VL;
1102 TopTools_SequenceOfShape tmpEdges;
1103 for (i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
1104 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
1105 tol = BRep_Tool::Tolerance(E);
1106 TopoDS_Vertex V1 = sae.FirstVertex(E);
1107 TopoDS_Vertex V2 = sae.LastVertex(E);
1108 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1109 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1110 if (P2.Distance(PLocs.Value(jcurr)) < tol) {
1111 // make wire from current edge and add created
1115 for (j=1; j<=tmpEdges.Length(); j++)
1116 B.Add(W,tmpEdges.Value(j));
1119 VLocs.ChangeValue(jcurr) = V2;
1124 // find distance between E and aLocs(jcurr)
1126 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
1127 GeomAPI_ProjectPointOnCurve PPCurve (PLocs.Value(jcurr),C);
1128 if (PPCurve.NbPoints()>0 &&
1129 PLocs.Value(jcurr).Distance(PPCurve.Point(1)) < tol) {
1130 double param = PPCurve.Parameter(1);
1133 // split current edge
1134 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
1135 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
1139 if (Pfp.Distance(P1)<tol) {
1140 B.MakeEdge(E1,tc1,tol);
1142 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1143 B.Add(E1,TopoDS::Vertex(tmpV));
1144 tmpEdges.Append(E1);
1145 B.MakeEdge(E2,tc2,tol);
1146 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1147 B.Add(E2,TopoDS::Vertex(tmpV));
1151 B.MakeEdge(E1,tc2,tol);
1152 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1153 B.Add(E1,TopoDS::Vertex(tmpV));
1156 tmpEdges.Append(E1);
1157 B.MakeEdge(E2,tc1,tol);
1159 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1160 B.Add(E2,TopoDS::Vertex(tmpV));
1163 // create wire from tmpEdges
1166 for (j=1; j<=tmpEdges.Length(); j++)
1167 B.Add(W,tmpEdges.Value(j));
1172 Edges.InsertAfter(i-1,E1);
1173 Edges.InsertAfter(i,E2);
1180 // create wire from other edges
1183 for (; i<=Edges.Length(); i++)
1184 B.Add(W,Edges.Value(i));
1186 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
1189 if (Wires.Length() != nbLocs-1) {
1190 if (aCI) delete aCI;
1191 Standard_ConstructionError::Raise
1192 ("One of location shapes is not lied on the path");
1195 //TopTools_SequenceOfShape aSeqBases;
1196 //TopTools_SequenceOfShape aSeqSubBases;
1197 //TopTools_SequenceOfShape aSeqFaces;
1198 TopoDS_Compound aComp;
1199 B.MakeCompound(aComp);
1200 for (i = 1; i < nbBases; i++) {
1201 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
1203 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
1204 if (anItem1.IsNull())
1206 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
1207 if (aRefBase1.IsNull())
1209 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
1210 if (aShBase1.IsNull())
1212 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
1214 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
1215 if (anItem2.IsNull())
1217 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
1218 if (aRefBase2.IsNull())
1220 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
1221 if (aShBase2.IsNull())
1223 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
1225 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
1227 bool OkSec = (aType1==TopAbs_SHELL || aType1==TopAbs_FACE) &&
1228 (aType2==TopAbs_SHELL || aType2==TopAbs_FACE);
1230 if (aCI) delete aCI;
1231 Standard_ConstructionError::Raise("One of section shapes has invalid type");
1234 bool CreateFewSolids = false;
1236 TopExp_Explorer anExp;
1237 Standard_Integer nbf1 = 0;
1238 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1241 Standard_Integer nbf2 = 0;
1242 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1246 CreateFewSolids = true;
1250 // check orientation of sections
1251 bool NeedReverse = false;
1254 anExp.Init(aShBase1, TopAbs_FACE);
1255 TopoDS_Shape aFace = anExp.Current();
1256 TColgp_SequenceOfPnt aPnts;
1257 double xc=0, yc=0, zc=0;
1258 for (anExp.Init(aFace, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
1259 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
1260 aPnts.Append(BRep_Tool::Pnt(V));
1261 xc += aPnts.Last().X();
1262 yc += aPnts.Last().Y();
1263 zc += aPnts.Last().Z();
1265 gp_Pnt PC(xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length());
1266 gp_Vec V1(PC,aPnts.Value(1));
1267 gp_Vec V2(PC,aPnts.Value(2));
1268 gp_Vec VN = V1.Crossed(V2);
1269 for (int ip=2; ip<aPnts.Length(); ip++) {
1270 V1 = gp_Vec(PC,aPnts.Value(ip));
1271 V2 = gp_Vec(PC,aPnts.Value(ip+1));
1272 VN.Add(V1.Crossed(V2));
1275 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
1277 for (WE.Init(WPath, TopAbs_EDGE); WE.More(); WE.Next()) {
1278 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
1279 double tol = BRep_Tool::Tolerance(edge);
1280 TopoDS_Vertex VF = sae.FirstVertex(edge);
1281 gp_Pnt PF = BRep_Tool::Pnt(VF);
1282 if (PF.Distance(PLoc) < tol) {
1284 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1287 if (P1.Distance(PLoc) < tol) {
1288 C->D0(fp+(lp-fp)/100,P2);
1292 C->D0(lp+(fp-lp)/100,P2);
1294 PathNorm = gp_Vec(P1,P2);
1298 TopoDS_Vertex VL = sae.LastVertex(edge);
1299 gp_Pnt PL = BRep_Tool::Pnt(VL);
1300 if (PL.Distance(PLoc) < tol) {
1302 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1305 if (P1.Distance(PLoc) < tol) {
1306 C->D0(fp+(lp-fp)/100,P2);
1310 C->D0(lp+(fp-lp)/100,P2);
1312 PathNorm = gp_Vec(P2,P1);
1317 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1318 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1319 if (fabs(VN.Angle(PathNorm))>PI/2.) {
1326 anExp.Init(aShBase2, TopAbs_FACE);
1327 TopoDS_Shape aFace = anExp.Current();
1328 TColgp_SequenceOfPnt aPnts;
1329 double xc=0, yc=0, zc=0;
1330 for (anExp.Init(aFace, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
1331 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
1332 aPnts.Append(BRep_Tool::Pnt(V));
1333 xc += aPnts.Last().X();
1334 yc += aPnts.Last().Y();
1335 zc += aPnts.Last().Z();
1337 gp_Pnt PC(xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length());
1338 gp_Vec V1(PC,aPnts.Value(1));
1339 gp_Vec V2(PC,aPnts.Value(2));
1340 gp_Vec VN = V1.Crossed(V2);
1341 for (int ip=2; ip<aPnts.Length(); ip++) {
1342 V1 = gp_Vec(PC,aPnts.Value(ip));
1343 V2 = gp_Vec(PC,aPnts.Value(ip+1));
1344 VN.Add(V1.Crossed(V2));
1347 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
1349 for (WE.Init(WPath, TopAbs_EDGE); WE.More(); WE.Next()) {
1350 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
1351 double tol = BRep_Tool::Tolerance(edge);
1352 TopoDS_Vertex VF = sae.FirstVertex(edge);
1353 gp_Pnt PF = BRep_Tool::Pnt(VF);
1354 if (PF.Distance(PLoc) < tol) {
1356 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1359 if (P1.Distance(PLoc) < tol) {
1360 C->D0(fp+(lp-fp)/100,P2);
1364 C->D0(lp+(fp-lp)/100,P2);
1366 PathNorm = gp_Vec(P2,P1);
1370 TopoDS_Vertex VL = sae.LastVertex(edge);
1371 gp_Pnt PL = BRep_Tool::Pnt(VL);
1372 if (PL.Distance(PLoc) < tol) {
1374 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1377 if (P1.Distance(PLoc) < tol) {
1378 C->D0(fp+(lp-fp)/100,P2);
1382 C->D0(lp+(fp-lp)/100,P2);
1384 PathNorm = gp_Vec(P2,P1);
1389 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1390 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1391 if (fabs(VN.Angle(PathNorm))>PI/2.)
1396 if (!CreateFewSolids) {
1397 // we can create only one solid
1398 TopoDS_Shape aWire1, aWire2;
1400 if (aType1==TopAbs_SHELL) {
1401 // create wire as boundary contour if shell is no closed
1402 // get free boundary shapes
1403 ShapeAnalysis_FreeBounds anAnalizer(aShBase1);
1404 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1405 //TopExp_Explorer anExp;
1406 Standard_Integer NbWires = 0;
1407 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
1409 aWire1 = anExp.Current();
1413 if (aCI) delete aCI;
1414 Standard_ConstructionError::Raise("Bad shell is used as section ");
1417 else { // aType1==TopAbs_FACE
1418 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1419 aWire1 = aExpW.Current();
1422 if (aType2==TopAbs_SHELL) {
1423 // create wire as boundary contour if shell is no closed
1424 // get free boundary shapes
1425 ShapeAnalysis_FreeBounds anAnalizer(aShBase2);
1426 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1427 //TopExp_Explorer anExp;
1428 Standard_Integer NbWires = 0;
1429 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
1431 aWire2 = anExp.Current();
1435 if (aCI) delete aCI;
1436 Standard_ConstructionError::Raise("Bad shell is used as section ");
1439 else { // aType2==TopAbs_FACE
1440 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1441 aWire2 = aExpW.Current();
1443 // make pipe using aWire1 and aWire2
1444 if (!aWire1.IsNull() && !aWire2.IsNull()) {
1445 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1446 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1447 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1448 aWithContact, aWithCorrect);
1449 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1450 aWithContact, aWithCorrect);
1451 if (!aBuilder.IsReady()) {
1452 if (aCI) delete aCI;
1453 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1456 TopoDS_Shape aShape = aBuilder.Shape();
1457 TopoDS_Shell aShell;
1458 B.MakeShell(aShell);
1459 for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
1460 B.Add(aShell,anExp.Current());
1462 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1463 B.Add(aShell,anExp.Current());
1465 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1466 B.Add(aShell,anExp.Current());
1468 // make sewing for this shell
1469 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1470 aSewing->SetTolerance(Precision::Confusion());
1471 aSewing->SetFaceMode(Standard_True);
1472 aSewing->SetFloatingEdgesMode(Standard_False);
1473 aSewing->SetNonManifoldMode(Standard_False);
1474 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
1475 aSewing->Add(anExp.Current());
1478 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1479 if (aSewShape.ShapeType() == TopAbs_SHELL) {
1480 aShell = TopoDS::Shell(aSewShape);
1481 GProp_GProps aSystem;
1482 BRepGProp::VolumeProperties(aShell, aSystem);
1483 if (aSystem.Mass()<0) {
1486 if (BRep_Tool::IsClosed(aShell)) {
1487 TopoDS_Solid aSolid;
1488 B.MakeSolid(aSolid);
1489 B.Add(aSolid,aShell);
1490 B.Add(aComp,aSolid);
1493 B.Add(aComp,aShell);
1497 B.Add(aComp,aShell);
1502 // main block - creation few solids (for each pair of faces)
1503 TopTools_MapOfShape aFaces1,aFaces2;
1504 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1505 aFaces1.Add(anExp.Current());
1507 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1508 aFaces2.Add(anExp.Current());
1510 // creating map of edge faces
1511 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1512 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1513 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1514 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1516 // constuct map face->face
1517 TopTools_IndexedDataMapOfShapeShape FF;
1518 TopoDS_Shape FS1,FS2;
1519 if (nbSubBases==0) {
1520 // find edge the most distant from location point
1521 // (this edge is not shared by two faces)
1522 double maxdist = 0.;
1524 TopoDS_Vertex V11,V21;
1525 for (j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1526 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1527 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1528 if (aList.Extent()>1)
1530 TopExp_Explorer expv;
1531 expv.Init(tmp, TopAbs_VERTEX);
1532 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1534 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1535 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1536 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1537 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1542 TopTools_ListIteratorOfListOfShape anIter(aList);
1543 FS1 = anIter.Value();
1547 // main direction for comparing
1548 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1549 // find corresponding edge from next section
1550 double minang = M_PI;
1551 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1552 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1554 TopoDS_Vertex V12,V22;
1555 for (j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1556 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1557 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1558 if (aList.Extent()>1)
1560 TopExp_Explorer expv;
1561 expv.Init(tmp, TopAbs_VERTEX);
1562 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1564 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1565 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1566 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1567 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1568 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1569 TopoDS_Vertex V1,V2;
1572 V1 = V2tmp; P1 = P2tmp;
1573 V2 = V1tmp; P2 = P1tmp;
1576 V1 = V1tmp; P1 = P1tmp;
1577 V2 = V2tmp; P2 = P2tmp;
1579 gp_Vec Vec1(P11,P1);
1580 gp_Vec Vec2(P21,P2);
1581 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1586 TopTools_ListIteratorOfListOfShape anIter(aList);
1587 FS2 = anIter.Value();
1591 // put all pairs to map FF
1597 // add pairs of edges to FF
1598 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1600 if (aCI) delete aCI;
1601 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1607 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1608 if (anItem.IsNull()) {
1609 if (aCI) delete aCI;
1610 Standard_ConstructionError::Raise("Invalid subbase shape");
1612 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1613 if (aRefBase.IsNull()) {
1614 if (aCI) delete aCI;
1615 Standard_ConstructionError::Raise("Invalid subbase shape");
1617 TopoDS_Shape aSh = aRefBase->GetValue();
1619 if (aCI) delete aCI;
1620 Standard_ConstructionError::Raise("Invalid subbase shape");
1622 if (aSh.ShapeType()!=TopAbs_FACE) {
1623 if (aCI) delete aCI;
1624 Standard_ConstructionError::Raise("Invalid subbase shape");
1629 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1630 if (anItem.IsNull()) {
1631 if (aCI) delete aCI;
1632 Standard_ConstructionError::Raise("Invalid subbase shape");
1634 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1635 if (aRefBase.IsNull()) {
1636 if (aCI) delete aCI;
1637 Standard_ConstructionError::Raise("Invalid subbase shape");
1639 TopoDS_Shape aSh = aRefBase->GetValue();
1641 if (aCI) delete aCI;
1642 Standard_ConstructionError::Raise("Invalid subbase shape");
1644 if (aSh.ShapeType()!=TopAbs_FACE) {
1645 if (aCI) delete aCI;
1646 Standard_ConstructionError::Raise("Invalid subbase shape");
1651 if (!aFaces1.Contains(FS1) || !aFaces2.Contains(FS2)) {
1652 if (aCI) delete aCI;
1653 Standard_ConstructionError::Raise("Invalid subbase shape");
1658 // add pairs of edges to FF
1659 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1660 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1662 if (aCI) delete aCI;
1663 Standard_ConstructionError::Raise("Can not create correct pipe");
1667 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1669 // make pipe for each pair of faces
1670 for (j=1; j<=FF.Extent(); j++) {
1671 TopoDS_Shape F1 = FF.FindKey(j);
1672 if (F1.ShapeType() != TopAbs_FACE)
1674 TopoDS_Shape F2 = FF.FindFromIndex(j);
1675 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1676 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1677 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1678 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1679 // make pipe using aWire1 and aWire2
1680 if (!aWire1.IsNull() && !aWire2.IsNull()) {
1681 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1682 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1683 aWithContact, aWithCorrect);
1684 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1685 aWithContact, aWithCorrect);
1686 if (!aBuilder.IsReady()) {
1687 if (aCI) delete aCI;
1688 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1691 TopoDS_Shape aShape = aBuilder.Shape();
1692 TopoDS_Shell aShell;
1693 B.MakeShell(aShell);
1694 for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
1695 B.Add(aShell,anExp.Current());
1700 // make sewing for this shell
1701 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1702 aSewing->SetTolerance(Precision::Confusion());
1703 aSewing->SetFaceMode(Standard_True);
1704 aSewing->SetFloatingEdgesMode(Standard_False);
1705 aSewing->SetNonManifoldMode(Standard_False);
1706 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
1707 aSewing->Add(anExp.Current());
1710 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1711 if (aSewShape.ShapeType() == TopAbs_SHELL) {
1712 aShell = TopoDS::Shell(aSewShape);
1713 GProp_GProps aSystem;
1714 BRepGProp::VolumeProperties(aShell, aSystem);
1715 if (aSystem.Mass()<0) {
1716 //cout<<"aSewShape is reversed"<<endl;
1719 if (BRep_Tool::IsClosed(aShell)) {
1720 TopoDS_Solid aSolid;
1721 B.MakeSolid(aSolid);
1722 B.Add(aSolid,aShell);
1723 B.Add(aComp,aSolid);
1726 B.Add(aComp,aShell);
1730 B.Add(aComp,aShell);
1738 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1742 //=======================================================================
1743 //function : CreatePipeShellsWithoutPath
1744 //purpose : auxilary for Execute()
1745 //=======================================================================
1746 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1748 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1752 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1754 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1755 // vertex for recognition
1756 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1758 Standard_Integer nbBases = aBasesObjs->Length(),
1759 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1761 if (nbv != nbBases) {
1762 if (aCI) delete aCI;
1763 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1766 TopTools_SequenceOfShape SecVs,Bases;
1767 for (i=1; i<=nbBases; i++) {
1769 Handle(Standard_Transient) anItem = VObjs->Value(i);
1770 if (anItem.IsNull())
1772 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1773 TopoDS_Shape V = aRef->GetValue();
1774 if (V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1778 anItem = aBasesObjs->Value(i);
1779 if (anItem.IsNull())
1781 aRef = Handle(GEOM_Function)::DownCast(anItem);
1782 TopoDS_Shape aSh = aRef->GetValue();
1787 nbv = SecVs.Length();
1788 nbBases = Bases.Length();
1789 if (nbv != nbBases) {
1790 if (aCI) delete aCI;
1791 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1794 TopoDS_Compound aComp;
1795 B.MakeCompound(aComp);
1797 for (i = 1; i < nbBases; i++) {
1798 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1799 TopoDS_Shape aShBase1 = Bases.Value(i);
1800 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1801 TopExp_Explorer anExp;
1802 Standard_Integer nbf1 = 0;
1803 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1806 Standard_Integer nbf2 = 0;
1807 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1810 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1812 if (aCI) delete aCI;
1813 Standard_ConstructionError::Raise("Different number of faces in the sections");
1816 TopTools_MapOfShape aFaces1,aFaces2;
1817 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1818 aFaces1.Add(anExp.Current());
1820 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1821 aFaces2.Add(anExp.Current());
1824 // creating map of edge faces
1825 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1826 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1827 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1828 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1830 // constuct map face->face (and sub-shapes)
1831 TopTools_IndexedDataMapOfShapeShape FF;
1832 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1833 TopoDS_Shape FS1, FS2;
1834 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1835 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1836 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1839 MESSAGE (" first pair of corresponding faces is found");
1841 // add pairs of edges and vertexes to FF
1842 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1844 if (aCI) delete aCI;
1845 Standard_ConstructionError::Raise("Can not create correct pipe");
1847 MESSAGE (" correspondences for sub-shapes of first pair of faces is found");
1849 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1850 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1852 // make pipe for each pair of faces
1853 // auxilary map vertex->edge for created pipe edges
1854 TopTools_IndexedDataMapOfShapeShape VPE;
1855 ShapeAnalysis_Edge sae;
1856 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1858 for (j=1; j<=FF.Extent(); j++) {
1859 TopoDS_Shape F1 = FF.FindKey(j);
1860 if (F1.ShapeType() != TopAbs_FACE)
1862 TopoDS_Shape F2 = FF.FindFromIndex(j);
1865 //if (nbff!=3) continue;
1867 MESSAGE (" make pipe for "<<nbff<<" face");
1869 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1870 if (S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1871 Handle(Geom_RectangularTrimmedSurface) RTS =
1872 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1873 S1 = RTS->BasisSurface();
1875 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1876 if (Pln1.IsNull()) {
1877 if (aCI) delete aCI;
1878 Standard_ConstructionError::Raise("Surface from face is not plane");
1880 gp_Vec aDir1(Pln1->Axis().Direction());
1882 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1883 if (S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1884 Handle(Geom_RectangularTrimmedSurface) RTS =
1885 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1886 S2 = RTS->BasisSurface();
1888 Handle(Geom_Plane) Pln2 =
1889 Handle(Geom_Plane)::DownCast(S2);
1890 if (Pln2.IsNull()) {
1891 if (aCI) delete aCI;
1892 Standard_ConstructionError::Raise("Surface from face is not plane");
1894 gp_Vec aDir2(Pln2->Axis().Direction());
1896 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1897 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1899 if (fabs(aDir.Angle(aDir1)) > M_PI/2.)
1901 if (fabs(aDir.Angle(aDir2)) > M_PI/2.)
1904 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1905 TopTools_SequenceOfShape aNewFs;
1907 for (; anExpE.More(); anExpE.Next()) {
1908 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1910 if (!FF.Contains(E1))
1911 MESSAGE ("map FF not contains key E1");
1913 if (VPE.Contains(E1)) {
1914 aNewFs.Append(VPE.FindFromKey(E1));
1916 MESSAGE (" using existed face");
1921 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1922 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1923 TopoDS_Vertex V2 = sae.LastVertex(E1);
1924 if (!FF.Contains(V1))
1925 MESSAGE ("map FF not contains key V1");
1926 if (!FF.Contains(V2))
1927 MESSAGE ("map FF not contains key V2");
1928 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1929 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1930 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1931 if (Vtmp.IsSame(V4))
1933 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1934 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1935 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1936 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1939 Handle(Geom_BSplineCurve) C2;
1940 if (VPE.Contains(V2)) {
1941 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1943 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1946 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1947 HAP->SetValue(1,P2);
1948 HAP->SetValue(2,P3);
1949 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1950 anInt.Load(aDir1,aDir2);
1953 B.MakeEdge(E2,C2,1.e-7);
1954 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1955 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1960 Handle(Geom_BSplineCurve) C4;
1961 if (VPE.Contains(V1)) {
1962 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1964 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1967 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1968 HAP->SetValue(1,P1);
1969 HAP->SetValue(2,P4);
1970 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1971 anInt.Load(aDir1,aDir2);
1974 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1975 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1976 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1985 B.Add(W,E4.Reversed());
1986 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1987 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1992 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1993 //bool IsConicC1 = false;
1994 //if (C1->IsKind(STANDARD_TYPE(Geom_Conic))) {
1995 // IsConicC1 = true;
1996 // cout<<"C1 - Geom_Conic"<<endl;
1998 if (C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic))) {
1999 C1 = new Geom_TrimmedCurve(C1,fp,lp);
2002 // double tol = BRep_Tool::Tolerance(E1);
2003 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
2004 // C1 = ApxC1.Curve();
2006 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
2007 if (C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic))) {
2008 C3 = new Geom_TrimmedCurve(C3,fp,lp);
2013 Handle(Geom_BSplineCurve) CE1 =
2014 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
2015 if (CE1->Degree()<3)
2016 CE1->IncreaseDegree(3);
2017 Handle(Geom_BSplineCurve) CE2 =
2018 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
2019 if (CE2->Degree()<3)
2020 CE2->IncreaseDegree(3);
2021 Handle(Geom_BSplineCurve) CE3 =
2022 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
2023 if (CE3->Degree()<3)
2024 CE3->IncreaseDegree(3);
2025 Handle(Geom_BSplineCurve) CE4 =
2026 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
2027 if (CE4->Degree()<3)
2028 CE4->IncreaseDegree(3);
2029 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
2030 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
2031 //if (fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
2032 // os<<"DrawTrSurf_BSplineCurve"<<endl;
2033 // GeomTools::Write(CE1,os);
2037 Handle(Geom_Surface) BS;
2039 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
2040 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
2044 MESSAGE (" can not create BSplineSurface - create Bezier");
2046 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
2047 double fp1,lp1,fp2,lp2;
2048 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
2049 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
2058 // get points from C1
2059 if (P1.Distance(P1C1)<1.e-6) {
2067 double step = (lp-fp)/(NbP-1);
2068 Points.SetValue(1,1,P1);
2070 for (n1=2; n1<NbP; n1++) {
2074 Points.SetValue(1,n1,P);
2076 Points.SetValue(1,NbP,P2);
2077 // get points from C3
2078 if (P4.Distance(P1C3)<1.e-6) {
2086 step = (lp-fp)/(NbP-1);
2087 Points.SetValue(NbP,1,P4);
2089 for (n1=2; n1<NbP; n1++) {
2093 Points.SetValue(NbP,n1,P);
2095 Points.SetValue(NbP,NbP,P3);
2096 // create isolines and get points from them
2097 for (n1=1; n1<=NbP; n1++) {
2098 gp_Pnt PI1 = Points.Value(1,n1);
2099 gp_Pnt PI2 = Points.Value(NbP,n1);
2100 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
2101 HAP->SetValue(1,PI1);
2102 HAP->SetValue(2,PI2);
2103 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
2104 anInt.Load(aDir1,aDir2);
2106 Handle(Geom_Curve) iso = anInt.Curve();
2107 fp = iso->FirstParameter();
2108 lp = iso->LastParameter();
2109 step = (lp-fp)/(NbP-1);
2111 TopoDS_Compound VComp;
2112 B.MakeCompound(VComp);
2113 for (n2=2; n2<NbP; n2++) {
2117 Points.SetValue(n2,n1,P);
2120 // create surface and face
2121 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
2122 BS = new Geom_BezierSurface(Points);
2125 BRepBuilderAPI_MakeFace BB(BS,W);
2126 TopoDS_Face NewF = BB.Face();
2127 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
2129 sff->FixOrientation();
2130 TopoDS_Face FixedFace = sff->Face();
2131 aNewFs.Append(FixedFace);
2132 VPE.Add(E1,FixedFace);
2133 //cout<<" face for edge "<<nbee<<" is created"<<endl;
2134 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
2137 TopoDS_Shell aShell;
2138 B.MakeShell(aShell);
2139 for (int nf=1; nf<=aNewFs.Length(); nf++) {
2140 B.Add(aShell,aNewFs(nf));
2145 // make sewing for this shell
2146 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2147 aSewing->SetTolerance(Precision::Confusion());
2148 aSewing->SetFaceMode(Standard_True);
2149 aSewing->SetFloatingEdgesMode(Standard_False);
2150 aSewing->SetNonManifoldMode(Standard_False);
2151 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
2152 aSewing->Add(anExp.Current());
2155 MESSAGE (" shell for face "<<nbff<<" is created");
2156 const TopoDS_Shape aSewShape = aSewing->SewedShape();
2157 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
2158 if (aSewShape.ShapeType() == TopAbs_SHELL) {
2159 aShell = TopoDS::Shell(aSewShape);
2160 GProp_GProps aSystem;
2161 BRepGProp::VolumeProperties(aShell, aSystem);
2162 if (aSystem.Mass()<0) {
2163 //cout<<"aSewShape is reversed"<<endl;
2166 if (BRep_Tool::IsClosed(aShell)) {
2167 TopoDS_Solid aSolid;
2168 B.MakeSolid(aSolid);
2169 B.Add(aSolid,aShell);
2170 B.Add(aComp,aSolid);
2171 MESSAGE (" solid for face "<<nbff<<" is created");
2174 B.Add(aComp,aShell);
2175 MESSAGE (" solid for face "<<nbff<<" is not created");
2179 B.Add(aComp,aShell);
2180 MESSAGE (" solid for face "<<nbff<<" is not created");
2182 //cout<<" solid for face "<<nbff<<" is created"<<endl;
2184 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
2186 //TopoDS_Shell FixedShell = sfs->Shell();
2188 GProp_GProps aSystem;
2189 BRepGProp::VolumeProperties(FixedShell, aSystem);
2190 if (aSystem.Mass()<0) {
2191 //cout<<"aSewShape is reversed"<<endl;
2192 FixedShell.Reverse();
2194 if (BRep_Tool::IsClosed(FixedShell)) {
2195 TopoDS_Solid aSolid;
2196 B.MakeSolid(aSolid);
2197 B.Add(aSolid,aShell);
2198 B.Add(aComp,aSolid);
2201 B.Add(aComp,FixedShell);
2207 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
2211 //=======================================================================
2212 //function : CreatePipeBiNormalAlongVector
2213 //purpose : auxilary for Execute()
2214 //=======================================================================
2215 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
2216 GEOMImpl_IPipe* aCI)
2218 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
2220 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
2221 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
2222 TopoDS_Shape aShapeBase = aRefBase->GetValue();
2223 TopoDS_Shape aShapeVec = aRefVec->GetValue();
2225 if (aShapeBase.IsNull()) {
2226 if (aCIBN) delete aCIBN;
2227 Standard_NullObject::Raise("MakePipe aborted : null base argument");
2230 // Make copy to prevent modifying of base object: 0021525
2231 BRepBuilderAPI_Copy Copy (aShapeBase);
2233 aShapeBase = Copy.Shape();
2236 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
2239 else if (aShapeBase.ShapeType() == TopAbs_EDGE) {
2240 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
2242 else if (aShapeBase.ShapeType() == TopAbs_WIRE) {
2245 else if (aShapeBase.ShapeType() == TopAbs_FACE) {
2246 TopExp_Explorer wexp (aShapeBase,TopAbs_WIRE);
2247 aProf = wexp.Current();
2250 Standard_TypeMismatch::Raise
2251 ("MakePipe aborted : invalid type of base");
2253 BRepOffsetAPI_MakePipeShell PipeBuilder (aWirePath);
2254 PipeBuilder.Add(aProf);
2256 if (aShapeVec.IsNull()) {
2257 if (aCIBN) delete aCIBN;
2258 Standard_NullObject::Raise
2259 ("MakePipe aborted : null vector argument");
2261 if (aShapeVec.ShapeType() != TopAbs_EDGE)
2262 Standard_TypeMismatch::Raise
2263 ("MakePipe aborted: invalid type of vector");
2264 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
2265 TopoDS_Vertex V1, V2;
2266 TopExp::Vertices(anEdge, V1, V2, Standard_True);
2267 if (V1.IsNull() || V2.IsNull())
2268 Standard_NullObject::Raise
2269 ("MakePipe aborted: vector is not defined");
2270 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
2271 gp_Dir BiNormal(aVec);
2272 PipeBuilder.SetMode(BiNormal);
2273 PipeBuilder.Build();
2274 if (aShapeBase.ShapeType() == TopAbs_FACE) {
2275 PipeBuilder.MakeSolid();
2278 return PipeBuilder.Shape();
2281 //=======================================================================
2282 //function : Execute
2284 //=======================================================================
2285 Standard_Integer GEOMImpl_PipeDriver::Execute (TFunction_Logbook& log) const
2287 if (Label().IsNull()) return 0;
2288 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
2289 Standard_Integer aType = aFunction->GetType();
2291 GEOMImpl_IPipe* aCI = 0;
2292 if (aType == PIPE_BASE_PATH)
2293 aCI = new GEOMImpl_IPipe (aFunction);
2294 else if (aType == PIPE_DIFFERENT_SECTIONS)
2295 aCI = new GEOMImpl_IPipeDiffSect (aFunction);
2296 else if (aType == PIPE_SHELL_SECTIONS)
2297 aCI = new GEOMImpl_IPipeShellSect (aFunction);
2298 else if (aType == PIPE_SHELLS_WITHOUT_PATH)
2299 aCI = new GEOMImpl_IPipeShellSect (aFunction);
2300 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR)
2301 aCI = new GEOMImpl_IPipeBiNormal (aFunction);
2305 TopoDS_Wire aWirePath;
2306 if (aType != PIPE_SHELLS_WITHOUT_PATH) {
2307 // working with path
2308 Handle(GEOM_Function) aRefPath = aCI->GetPath();
2309 TopoDS_Shape aShapePath = aRefPath->GetValue();
2311 if (aShapePath.IsNull()) {
2312 MESSAGE ("Driver : path is null");
2313 if (aCI) delete aCI;
2314 Standard_NullObject::Raise("MakePipe aborted : null path argument");
2319 if (aShapePath.ShapeType() == TopAbs_COMPOUND) {
2320 TopTools_SequenceOfShape anEdges;
2321 TopExp_Explorer anExp;
2325 for (anExp.Init(aShapePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2326 B.Add(W, anExp.Current());
2332 else if (aShapePath.ShapeType() == TopAbs_WIRE) {
2333 aWirePath = TopoDS::Wire(aShapePath);
2337 if (aShapePath.ShapeType() == TopAbs_EDGE) {
2338 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
2339 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
2344 if (aCI) delete aCI;
2345 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
2349 TopoDS_Shape aShape;
2351 if (aType == PIPE_BASE_PATH) {
2352 Handle(GEOM_Function) aRefBase = aCI->GetBase();
2353 TopoDS_Shape aShapeBase;
2355 // Make copy to prevent modifying of base object 0020766 : EDF 1320
2356 BRepBuilderAPI_Copy Copy(aRefBase->GetValue());
2358 aShapeBase = Copy.Shape();
2360 if (aShapeBase.IsNull()) {
2361 if (aCI) delete aCI;
2362 Standard_NullObject::Raise("MakePipe aborted : null base argument");
2366 if (aShapeBase.ShapeType() == TopAbs_EDGE ||
2367 aShapeBase.ShapeType() == TopAbs_WIRE)
2369 TopoDS_Wire Profile;
2370 if (aShapeBase.ShapeType() == TopAbs_WIRE)
2371 Profile = TopoDS::Wire(aShapeBase);
2375 BB.MakeWire(Profile);
2376 BB.Add(Profile, aShapeBase);
2379 BRepOffsetAPI_MakePipeShell Sweep (aWirePath);
2380 BRepBuilderAPI_MakeFace FaceBuilder (aWirePath, Standard_True); //to find the plane of spine
2381 if (FaceBuilder.IsDone())
2382 Sweep.SetMode(FaceBuilder.Face());
2386 if (!Sweep.IsDone())
2388 if (aCI) delete aCI;
2389 Standard_ConstructionError::Raise("MakePipeShell failed");
2392 aShape = Sweep.Shape(); //result is good
2396 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
2399 //building pipe with different sections
2400 else if (aType == PIPE_DIFFERENT_SECTIONS) {
2401 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
2402 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
2403 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
2404 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
2405 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
2411 Standard_Integer nbBases = aBasesObjs->Length();
2412 Standard_Integer nbLocs = (aLocObjs.IsNull() ? 0 : aLocObjs->Length());
2414 Handle(TopTools_HSequenceOfShape) aHSeqBases = new TopTools_HSequenceOfShape;
2415 Handle(TopTools_HSequenceOfShape) aHSeqLocs = new TopTools_HSequenceOfShape;
2418 for (i = 1; i <= nbBases; i++) {
2419 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2420 if (anItem.IsNull())
2422 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2423 if (aRefBase.IsNull())
2425 if (aRefBase->GetValue().IsNull())
2428 aHSeqBases->Append(aRefBase->GetValue());
2430 for (i = 1; i <= nbLocs; i++) {
2431 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2432 if (anItemLoc.IsNull())
2434 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2435 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2436 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2439 aHSeqLocs->Append(aShapeLoc);
2442 aShape = CreatePipeWithDifferentSections(aWirePath, aHSeqBases, aHSeqLocs, aWithContact, aWithCorrect);
2445 //building pipe with shell sections
2446 else if (aType == PIPE_SHELL_SECTIONS) {
2447 aShape = CreatePipeForShellSections(aWirePath,aCI);
2450 //building pipe shell sections without path
2451 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2452 aShape = CreatePipeShellsWithoutPath(aCI);
2455 //building a pipe with constant bi-normal along given vector
2456 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2457 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2465 if (aShape.IsNull()) return 0;
2467 BRepCheck_Analyzer ana (aShape, Standard_False);
2468 if (!ana.IsValid()) {
2469 ShapeFix_ShapeTolerance aSFT;
2470 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2471 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2472 aSfs->SetPrecision(Precision::Confusion());
2474 aShape = aSfs->Shape();
2476 ana.Init(aShape, Standard_False);
2478 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2481 if (aType != PIPE_BASE_PATH &&
2482 aType != PIPE_SHELLS_WITHOUT_PATH) {
2483 TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
2484 if (anExpV.More()) {
2485 Standard_Real aVertMaxTol = -RealLast();
2486 for (; anExpV.More(); anExpV.Next()) {
2487 TopoDS_Vertex aVertex = TopoDS::Vertex(anExpV.Current());
2488 Standard_Real aTol = BRep_Tool::Tolerance(aVertex);
2489 if (aTol > aVertMaxTol)
2492 aVertMaxTol += Precision::Confusion();
2493 aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, aVertMaxTol, Standard_True);
2494 //aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
2498 TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape);
2499 aFunction->SetValue(aRes);
2501 log.SetTouched(Label());
2505 //=======================================================================
2506 //function : GEOMImpl_PipeDriver_Type_
2508 //=======================================================================
2509 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2511 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2512 if (aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2513 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2514 if (aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2515 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2516 if (aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2518 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2519 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2520 sizeof(GEOMImpl_PipeDriver),
2522 (Standard_Address)_Ancestors,
2523 (Standard_Address)NULL);
2528 //=======================================================================
2529 //function : DownCast
2531 //=======================================================================
2532 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2534 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2536 if (!AnObject.IsNull()) {
2537 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2538 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2542 return _anOtherObject;