1 // Copyright (C) 2007-2012 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
22 #include <GEOMImpl_PipeDriver.hxx>
24 #include <GEOMImpl_IPipeDiffSect.hxx>
25 #include <GEOMImpl_IPipeShellSect.hxx>
26 #include <GEOMImpl_IPipeBiNormal.hxx>
27 #include <GEOMImpl_IPipe.hxx>
28 #include <GEOMImpl_IPipePath.hxx>
29 #include <GEOMImpl_GlueDriver.hxx>
30 #include <GEOMImpl_Types.hxx>
32 #include <GEOM_Function.hxx>
34 #include <GEOMUtils.hxx>
36 #include <ShapeAnalysis_FreeBounds.hxx>
37 #include <ShapeAnalysis_Edge.hxx>
38 #include <ShapeFix_Face.hxx>
39 #include <ShapeFix_Shell.hxx>
40 #include <ShapeFix_Shape.hxx>
41 #include <ShapeFix_ShapeTolerance.hxx>
43 #include <BRep_Tool.hxx>
44 #include <BRep_Builder.hxx>
45 #include <BRepBuilderAPI_Copy.hxx>
46 #include <BRepBuilderAPI_MakeFace.hxx>
47 #include <BRepBuilderAPI_MakeWire.hxx>
48 #include <BRepBuilderAPI_Sewing.hxx>
49 #include <BRepCheck_Analyzer.hxx>
50 #include <BRepGProp.hxx>
51 #include <BRepOffsetAPI_MakePipe.hxx>
52 #include <BRepOffsetAPI_MakePipeShell.hxx>
56 #include <TopExp_Explorer.hxx>
58 #include <TopoDS_Wire.hxx>
59 #include <TopoDS_Edge.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopoDS_Solid.hxx>
62 #include <TopoDS_Shell.hxx>
63 #include <TopoDS_Face.hxx>
64 #include <TopoDS_Compound.hxx>
65 #include <TopTools_SequenceOfShape.hxx>
66 #include <TopTools_HSequenceOfShape.hxx>
67 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
68 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <GProp_GProps.hxx>
73 #include <GeomAPI_ProjectPointOnCurve.hxx>
74 #include <GeomAPI_Interpolate.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_BezierSurface.hxx>
79 #include <Geom_Line.hxx>
80 #include <Geom_Conic.hxx>
81 #include <Geom_BSplineCurve.hxx>
82 #include <Geom_BSplineSurface.hxx>
83 #include <GeomFill_BSplineCurves.hxx>
84 #include <GeomConvert_ApproxCurve.hxx>
85 #include <GeomConvert.hxx>
87 #include <TColgp_SequenceOfPnt.hxx>
88 #include <TColgp_HArray1OfPnt.hxx>
89 #include <TColgp_Array2OfPnt.hxx>
90 #include <TColStd_HSequenceOfTransient.hxx>
92 #include <Precision.hxx>
94 #include <Standard_NullObject.hxx>
95 #include <Standard_TypeMismatch.hxx>
96 #include <Standard_ConstructionError.hxx>
98 #include "utilities.h"
101 //=======================================================================
104 //=======================================================================
105 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
107 static Standard_GUID aPipeDriver ("FF1BBB19-5D14-4df2-980B-3A668264EA16");
111 //=======================================================================
112 //function : GEOMImpl_PipeDriver
114 //=======================================================================
115 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
119 //=======================================================================
120 //function : FillForOtherEdges
121 //purpose : auxilary for CreatePipeForShellSections()
122 //=======================================================================
123 static bool FillForOtherEdges(const TopoDS_Shape& F1,
124 const TopoDS_Shape& E1,
125 const TopoDS_Shape& V1,
126 TopTools_IndexedDataMapOfShapeShape& FF)
128 //cout<<"FillForOtherEdges"<<endl;
129 // find other pairs for vertexes and edges
130 // creating map of vertex edges for both faces
131 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
132 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
133 if (!FF.Contains(F1))
134 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
135 if (!FF.Contains(E1))
136 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
137 if (!FF.Contains(V1))
138 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
139 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
140 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
141 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
142 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
143 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
145 TopoDS_Edge ES1 = TopoDS::Edge(E1);
146 TopoDS_Edge ES2 = TopoDS::Edge(E2);
147 TopoDS_Shape VS1 = V1;
148 TopoDS_Shape VS2 = V2;
150 ShapeAnalysis_Edge sae;
152 if (!aMapVertEdge1.Contains(VS1))
153 MESSAGE (" FillForOtherEdges: map aMapVertEdge1 not contains key VS1");
154 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
155 //TopoDS_Shape E1next;
156 TopTools_ListIteratorOfListOfShape anIter1(aList1);
157 if (anIter1.Value().IsSame(ES1)) {
160 //E1next = anIter1.Value();
161 if (!aMapVertEdge2.Contains(VS2))
162 MESSAGE (" FillForOtherEdges: map aMapVertEdge2 not contains key VS2");
163 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
164 //TopoDS_Shape E2next;
165 TopTools_ListIteratorOfListOfShape anIter2(aList2);
166 if (anIter2.Value().IsSame(ES2)) {
169 //E2next = anIter2.Value();
170 //ES1 = TopoDS::Edge(E1next);
171 //ES2 = TopoDS::Edge(E2next);
172 ES1 = TopoDS::Edge(anIter1.Value());
173 ES2 = TopoDS::Edge(anIter2.Value());
174 if (!FF.Contains(ES1)) {
177 if (VS1.IsSame(sae.FirstVertex(ES1)))
178 VS1 = sae.LastVertex(ES1);
180 VS1 = sae.FirstVertex(ES1);
181 if (VS2.IsSame(sae.FirstVertex(ES2)))
182 VS2 = sae.LastVertex(ES2);
184 VS2 = sae.FirstVertex(ES2);
187 if (!FF.Contains(VS1)) {
195 //=======================================================================
196 //function : FillCorrespondingEdges
197 //purpose : auxilary for CreatePipeForShellSections()
198 //=======================================================================
199 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
200 const TopoDS_Shape& FS2,
201 const TopoDS_Vertex& aLoc1,
202 const TopoDS_Vertex& aLoc2,
203 const TopoDS_Wire& aWirePath,
204 TopTools_IndexedDataMapOfShapeShape& FF)
206 //cout<<"FillCorrespondingEdges"<<endl;
207 // find corresponding edges
208 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
209 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
210 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
211 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
212 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
213 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
214 aBuilder.Add(aWire1, aLoc1);
215 aBuilder.Add(aWire2, aLoc2);
216 if (!aBuilder.IsReady()) {
220 TopoDS_Shape aShape = aBuilder.Shape();
228 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
230 ShapeAnalysis_Edge sae;
231 double tol = Max(BRep_Tool::Tolerance(TopoDS::Face(FS1)),
232 BRep_Tool::Tolerance(TopoDS::Face(FS2)));
233 TopTools_MapOfShape Vs1,Vs2;
235 exp.Init(FS1, TopAbs_EDGE);
236 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
237 TopoDS_Vertex V11 = sae.FirstVertex(E1);
238 TopoDS_Vertex V21 = sae.LastVertex(E1);
239 gp_Pnt P11 = BRep_Tool::Pnt(V11);
240 gp_Pnt P21 = BRep_Tool::Pnt(V21);
241 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
242 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
243 // find corresponding vertexes from created shape
244 TopoDS_Vertex VN11,VN21;
245 for (exp.Init(aShape, TopAbs_VERTEX); exp.More(); exp.Next()) {
246 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
247 gp_Pnt P = BRep_Tool::Pnt(V);
248 if (P.Distance(P11)<tol) {
251 if (P.Distance(P21)<tol) {
255 // find edge contains VN11 and VN21 and corresponding vertexes
256 TopoDS_Vertex VN12,VN22;
257 for (exp.Init(aShape, TopAbs_FACE); exp.More(); exp.Next()) {
258 TopoDS_Shape F = exp.Current();
259 TopExp_Explorer expe;
261 for (expe.Init(F, TopAbs_EDGE); expe.More(); expe.Next()) {
262 TopoDS_Edge E = TopoDS::Edge(expe.Current());
263 TopoDS_Vertex VF = sae.FirstVertex(E);
264 TopoDS_Vertex VL = sae.LastVertex(E);
265 if ((VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11))) {
271 for (expe.Init(F, TopAbs_EDGE); expe.More(); expe.Next()) {
272 TopoDS_Edge E = TopoDS::Edge(expe.Current());
273 TopoDS_Vertex VF = sae.FirstVertex(E);
274 TopoDS_Vertex VL = sae.LastVertex(E);
275 if (VF.IsSame(VN11) && !VL.IsSame(VN21))
277 if (VL.IsSame(VN11) && !VF.IsSame(VN21))
279 if (VF.IsSame(VN21) && !VL.IsSame(VN11))
281 if (VL.IsSame(VN21) && !VF.IsSame(VN11))
287 // find vertexes from FS2 corresponded to VN12 and VN22
288 // and find edge from FS2 contains V12 and V22,
289 // this edge will be corresponded to edge E1
290 TopoDS_Vertex V12,V22;
291 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
292 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
293 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
294 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
296 TopExp_Explorer expe;
297 for (expe.Init(FS2, TopAbs_EDGE); expe.More(); expe.Next()) {
298 TopoDS_Edge E = TopoDS::Edge(expe.Current());
299 TopoDS_Vertex VF = sae.FirstVertex(E);
300 TopoDS_Vertex VL = sae.LastVertex(E);
301 gp_Pnt PF = BRep_Tool::Pnt(VF);
302 gp_Pnt PL = BRep_Tool::Pnt(VL);
303 if (PF.Distance(PN12)<tol && PL.Distance(PN22)<tol) {
309 if (PF.Distance(PN22)<tol && PL.Distance(PN12)<tol) {
320 // find other pairs for vertexes and edges
321 // creating map of vertex edges for both faces
322 return FillForOtherEdges(FS1,E1,V21,FF);
327 //=======================================================================
328 //function : FillCorrespondingEdges
329 //purpose : auxilary for CreatePipeShellsWithoutPath()
330 //=======================================================================
331 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
332 const TopoDS_Shape& FS2,
333 const TopoDS_Vertex& aLoc1,
334 const TopoDS_Vertex& aLoc2,
335 TopTools_IndexedDataMapOfShapeShape& FF)
337 //cout<<"FillCorrespondingEdges"<<endl;
339 gp_Pnt P1 = BRep_Tool::Pnt(aLoc1);
340 gp_Pnt P2 = BRep_Tool::Pnt(aLoc2);
343 ShapeAnalysis_Edge sae;
344 double tol = Max(BRep_Tool::Tolerance(TopoDS::Face(FS1)),
345 BRep_Tool::Tolerance(TopoDS::Face(FS2)));
346 TopTools_MapOfShape Vs1,Vs2;
348 TopoDS_Vertex V11=aLoc1, V12=aLoc2, V21, V22;
351 TopExp_Explorer exp1;
352 for (exp1.Init(FS1,TopAbs_EDGE); exp1.More(); exp1.Next()) {
353 E1 = TopoDS::Edge(exp1.Current());
354 TopoDS_Vertex V1 = sae.FirstVertex(E1);
355 TopoDS_Vertex V2 = sae.LastVertex(E1);
356 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
357 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
358 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
359 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
360 if (P1.Distance(Ptmp1)<tol) {
364 if (P1.Distance(Ptmp2)<tol) {
371 TopoDS_Vertex VE21,VE22;
373 for (exp1.Init(FS2,TopAbs_EDGE); exp1.More() && nbe<2; exp1.Next()) {
374 TopoDS_Edge E = TopoDS::Edge(exp1.Current());
375 TopoDS_Vertex V1 = sae.FirstVertex(E);
376 TopoDS_Vertex V2 = sae.LastVertex(E);
377 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
378 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
379 if (P2.Distance(Ptmp1)<tol) {
391 if (P2.Distance(Ptmp2)<tol) {
405 gp_Pnt PV21 = BRep_Tool::Pnt(V21);
406 gp_Pnt PE21 = BRep_Tool::Pnt(VE21);
407 gp_Pnt PE22 = BRep_Tool::Pnt(VE22);
408 gp_Vec aDir1(PV21,PE21);
409 gp_Vec aDir2(PV21,PE22);
410 double ang1 = aDir.Angle(aDir1);
411 double ang2 = aDir.Angle(aDir2);
412 if (fabs(ang1)<fabs(ang2)) {
425 // find other pairs for vertexes and edges
426 return FillForOtherEdges(FS1,E1,V21,FF);
429 //=======================================================================
430 //function : FindNextPairOfFaces
431 //purpose : auxilary for CreatePipeForShellSections()
432 //=======================================================================
433 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
434 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
435 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
436 TopTools_IndexedDataMapOfShapeShape& FF,
439 //cout<<"FindNextPairOfFaces"<<endl;
440 TopExp_Explorer anExp;
441 for (anExp.Init(aCurFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
442 TopoDS_Shape E1 = anExp.Current();
443 if (!FF.Contains(E1)) {
445 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
447 if (!FF.Contains(E1))
448 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
449 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
450 TopExp_Explorer anExpV;
451 anExpV.Init(E1, TopAbs_VERTEX);
452 TopoDS_Shape V1 = anExpV.Current();
453 if (!FF.Contains(V1)) {
455 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
458 if (!aMapEdgeFaces1.Contains(E1))
459 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
460 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
461 if (aList1.Extent()<2)
463 TopTools_ListIteratorOfListOfShape anIter(aList1);
464 if (anIter.Value().IsEqual(aCurFace)) {
467 TopoDS_Shape F1other = anIter.Value();
468 if (FF.Contains(F1other))
471 if (!FF.Contains(aCurFace))
472 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
473 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
474 if (!aMapEdgeFaces2.Contains(E2))
475 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
476 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
477 if (aList2.Extent()<2) {
479 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
481 TopTools_ListIteratorOfListOfShape anIter2(aList2);
482 if (anIter2.Value().IsEqual(F2)) {
485 TopoDS_Shape F2other = anIter2.Value();
486 FF.Add(F1other,F2other);
488 // add pairs of edges to FF
489 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
492 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
495 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
499 //=======================================================================
500 //function : FindFirstPairFaces
501 //purpose : auxilary for Execute()
502 //=======================================================================
503 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
504 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
505 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
507 //cout<<"FindFirstPairFaces"<<endl;
509 // check if vertexes are sub-shapes of sections
510 gp_Pnt P1 = BRep_Tool::Pnt(V1);
511 gp_Pnt P2 = BRep_Tool::Pnt(V2);
512 TopoDS_Vertex V1new,V2new;
514 double mindist = 1.e10;
515 for (exp.Init(S1, TopAbs_VERTEX); exp.More(); exp.Next()) {
516 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
517 gp_Pnt P = BRep_Tool::Pnt(V);
518 double dist = P1.Distance(P);
525 for (exp.Init(S2, TopAbs_VERTEX); exp.More(); exp.Next()) {
526 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
527 gp_Pnt P = BRep_Tool::Pnt(V);
528 double dist = P2.Distance(P);
535 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
536 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
537 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
538 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
539 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
540 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
542 // replace vertexes if it is needed
543 if (!V1.IsSame(V1new)) {
545 P1 = BRep_Tool::Pnt(V1);
546 MESSAGE (" replace V1");
549 MESSAGE (" not replace V1");
550 if (!V2.IsSame(V2new)) {
552 P2 = BRep_Tool::Pnt(V2);
553 MESSAGE (" replace V2");
556 MESSAGE (" not replace V2");
558 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
559 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
560 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
561 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
563 if (!aMapVertFaces1.Contains(V1))
564 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
565 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
566 TopTools_ListIteratorOfListOfShape anIter1(aList1);
567 FS1 = anIter1.Value();
569 double x1=0., y1=0., z1=0.;
571 for (exp.Init(FS1, TopAbs_VERTEX); exp.More(); exp.Next()) {
572 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
573 gp_Pnt P = BRep_Tool::Pnt(V);
579 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
581 TColgp_SequenceOfPnt Ps;
582 TopTools_SequenceOfShape Fs;
583 if (!aMapVertFaces2.Contains(V2))
584 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
585 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
586 TopTools_ListIteratorOfListOfShape anIter2(aList2);
587 for (; anIter2.More(); anIter2.Next()) {
588 TopoDS_Shape F = anIter2.Value();
589 double x2=0., y2=0., z2=0.;
591 for (exp.Init(F, TopAbs_VERTEX); exp.More(); exp.Next()) {
592 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
593 gp_Pnt P = BRep_Tool::Pnt(V);
599 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
606 double MinAng = M_PI;
608 for (; i<=Fs.Length(); i++) {
609 gp_Vec tmpDir(PM1,Ps(i));
610 double ang = fabs(aDir.Angle(tmpDir));
619 //=======================================================================
620 //function : CreatePipeWithDifferentSections
622 //=======================================================================
623 TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
624 (const TopoDS_Wire& theWirePath,
625 const Handle(TopTools_HSequenceOfShape) theHSeqBases,
626 const Handle(TopTools_HSequenceOfShape) theHSeqLocs,
627 const Standard_Boolean theWithContact,
628 const Standard_Boolean theWithCorrect)
632 TopoDS_Wire aWirePath = theWirePath;
634 Standard_Integer nbBases = theHSeqBases->Length();
635 Standard_Integer nbLocs = (theHSeqLocs.IsNull() ? 0 : theHSeqLocs->Length());
637 if (nbLocs && nbLocs != nbBases) {
638 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
641 TopTools_SequenceOfShape aSeqBases;
642 TopTools_SequenceOfShape aSeqLocs;
643 TopTools_SequenceOfShape aSeqFaces;
645 Standard_Integer i = 1;
646 for (i = 1; i <= nbBases; i++) {
647 if (theHSeqBases->Value(i).IsNull())
650 // Make copy to prevent modifying of base object 0020766 : EDF 1320
651 TopoDS_Shape aShapeBase;
652 BRepBuilderAPI_Copy Copy (theHSeqBases->Value(i));
654 aShapeBase = Copy.Shape();
656 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
658 //if for section was specified face with a few wires then a few
659 // pipes were build and make solid
660 Standard_Boolean NeedCreateSolid = Standard_False;
661 if (aTypeBase == TopAbs_SHELL) {
662 // create wire as boundary contour if shell is no closed
663 // get free boundary shapes
664 ShapeAnalysis_FreeBounds anAnalizer(aShapeBase);
665 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
666 TopExp_Explorer anExp;
668 Standard_Integer NbWires = 0;
669 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
671 aWire = anExp.Current();
675 Standard_ConstructionError::Raise("Bad shell is used as section ");
677 NeedCreateSolid = Standard_True;
678 aSeqFaces.Append(aShapeBase);
679 aSeqBases.Append(aWire);
681 else if (aTypeBase == TopAbs_FACE) {
682 NeedCreateSolid = Standard_True;
683 //for case one path should be used other type function
684 aSeqFaces.Append(aShapeBase);
685 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
686 for (; aExpW.More(); aExpW.Next()) {
687 TopoDS_Shape aWireProf = aExpW.Current();
688 aSeqBases.Append(aWireProf);
691 else if (aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
692 aSeqBases.Append(aShapeBase);
694 else if (aTypeBase == TopAbs_EDGE) {
695 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
696 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
697 aSeqBases.Append(aWireProf);
700 TopoDS_Shape aShapeLoc = theHSeqLocs->Value(i);
701 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
703 aSeqLocs.Append(aShapeLoc);
707 nbLocs = aSeqLocs.Length();
710 TopTools_SequenceOfShape Edges;
712 // we have to check that each location shape is a vertex from
713 // path and update aSeqLocs if it is needed (and possible)
714 TColgp_SequenceOfPnt PLocs;
715 for (i=1; i<=nbLocs; i++) {
716 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
717 PLocs.Append(BRep_Tool::Pnt(V));
719 //TopTools_SequenceOfShape Edges;
720 TopExp_Explorer anExp;
721 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
722 Edges.Append(anExp.Current());
724 int nbEdges = Edges.Length();
725 ShapeAnalysis_Edge sae;
726 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
727 double tol = BRep_Tool::Tolerance(edge);
728 TopoDS_Vertex VF = sae.FirstVertex(edge);
729 gp_Pnt PF = BRep_Tool::Pnt(VF);
730 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
731 if (PF.Distance(PLocs.First()) > tol) {
732 Standard_ConstructionError::Raise
733 ("First location shapes is not coincided with first vertex of aWirePath");
735 aSeqLocs.ChangeValue(1) = VF;
736 edge = TopoDS::Edge(Edges.Last());
737 tol = BRep_Tool::Tolerance(edge);
738 TopoDS_Vertex VL = sae.LastVertex(edge);
739 gp_Pnt PL = BRep_Tool::Pnt(VL);
740 if (PL.Distance(PLocs.Last()) > tol) {
741 Standard_ConstructionError::Raise
742 ("Last location shapes is not coincided with last vertex of aWirePath");
744 aSeqLocs.ChangeValue(nbLocs) = VL;
746 for (i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
747 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
748 tol = BRep_Tool::Tolerance(edge);
749 TopoDS_Vertex V1 = sae.FirstVertex(E);
750 TopoDS_Vertex V2 = sae.LastVertex(E);
751 gp_Pnt P1 = BRep_Tool::Pnt(V1);
752 gp_Pnt P2 = BRep_Tool::Pnt(V2);
753 if (P2.Distance(PLocs.Value(jcurr)) < tol) {
754 aSeqLocs.ChangeValue(jcurr) = V2;
758 // find distance between E and aLocs(jcurr)
760 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
761 GeomAPI_ProjectPointOnCurve PPCurve (PLocs.Value(jcurr),C);
762 if (PPCurve.NbPoints()>0 &&
763 PLocs.Value(jcurr).Distance(PPCurve.Point(1)) < tol) {
764 double param = PPCurve.Parameter(1);
767 // split current edge
768 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
769 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
774 if (Pfp.Distance(P1)<tol) {
775 B.MakeEdge(E1,tc1,tol);
777 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
778 B.Add(E1,TopoDS::Vertex(tmpV));
779 B.MakeEdge(E2,tc2,tol);
780 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
781 B.Add(E2,TopoDS::Vertex(tmpV));
785 B.MakeEdge(E1,tc2,tol);
786 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
787 B.Add(E1,TopoDS::Vertex(tmpV));
790 B.MakeEdge(E2,tc1,tol);
792 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
793 B.Add(E2,TopoDS::Vertex(tmpV));
798 Edges.InsertAfter(i-1,E1);
799 Edges.InsertAfter(i,E2);
803 if (nbEdges<Edges.Length()) {
804 // one of edges was splitted => we have to update WirePath
808 for (i=1; i<=Edges.Length(); i++) {
809 B.Add(W,TopoDS::Edge(Edges.Value(i)));
815 // check curvature of wire for condition that
816 // max summary angle between directions along
817 // wire path must be < 4*PI. If not - split wire
818 // and seguences of shapes, perform pipe for each
819 // and make sewing after that
821 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
826 double SumAng = fabs(Vec1.Angle(Vec2));
829 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
831 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
832 for (i=2; i<=Edges.Length(); i++) {
833 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
834 double tol = BRep_Tool::Tolerance(edge);
835 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
837 double ang = fabs(Vec1.Angle(Vec2));
841 SplitEdgeNums.Append(i-1);
843 for (j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
844 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
845 gp_Pnt P = BRep_Tool::Pnt(aVert);
846 if (P1.Distance(P) < tol) {
847 SplitLocNums.Append(j);
857 if (SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0) {
858 TopTools_SequenceOfShape aSeqRes;
859 int nn, num1 = 1, num2 = 1;
860 for (nn=1; nn<=SplitEdgeNums.Length(); nn++) {
861 // create wirepath and sequences of shapes
865 for (i=num1; i<=SplitEdgeNums.Value(nn); i++) {
866 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
868 num1 = SplitEdgeNums.Value(nn) + 1;
869 TopTools_SequenceOfShape aTmpSeqBases;
870 TopTools_SequenceOfShape aTmpSeqLocs;
871 for (i=num2; i<=SplitLocNums.Value(nn); i++) {
872 aTmpSeqBases.Append(aSeqBases.Value(i));
873 aTmpSeqLocs.Append(aSeqLocs.Value(i));
875 num2 = SplitLocNums.Value(nn);
877 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
878 Standard_Integer nbShapes = aTmpSeqBases.Length();
879 for (i=1; i<=nbShapes; i++) {
880 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
881 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
882 aBuilder.Add(aTmpSeqBases.Value(i), aVert, theWithContact, theWithCorrect);
884 if (!aBuilder.IsReady()) {
885 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
888 TopoDS_Shape resShape = aBuilder.Shape();
889 aSeqRes.Append(resShape);
891 // create wirepath and sequences of shapes for last part
895 for (i=num1; i<=Edges.Length(); i++) {
896 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
898 TopTools_SequenceOfShape aTmpSeqBases;
899 TopTools_SequenceOfShape aTmpSeqLocs;
900 for (i=num2; i<=aSeqLocs.Length(); i++) {
901 aTmpSeqBases.Append(aSeqBases.Value(i));
902 aTmpSeqLocs.Append(aSeqLocs.Value(i));
904 // make pipe for last part
905 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
906 Standard_Integer nbShapes = aTmpSeqBases.Length();
907 for (i=1; i<=nbShapes; i++) {
908 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
909 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
910 aBuilder.Add(aTmpSeqBases.Value(i), aVert, theWithContact, theWithCorrect);
912 if (!aBuilder.IsReady()) {
913 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
916 TopoDS_Shape resShape = aBuilder.Shape();
917 aSeqRes.Append(resShape);
918 // make sewing for result
919 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
920 aSewing->SetTolerance(Precision::Confusion());
921 aSewing->SetFaceMode(Standard_True);
922 aSewing->SetFloatingEdgesMode(Standard_False);
923 aSewing->SetNonManifoldMode(Standard_False);
924 for (i=1; i<=aSeqRes.Length(); i++) {
925 aSewing->Add(aSeqRes.Value(i));
928 aShape = aSewing->SewedShape();
931 // old implementation without splitting
932 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
934 Standard_Integer nbShapes = aSeqBases.Length();
935 Standard_Integer step = nbShapes/nbBases;
937 if (nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
938 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
940 Standard_Integer ind =0;
941 for (i = 1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
942 TopTools_SequenceOfShape usedBases;
943 Standard_Integer j = 1;
944 for (; j <= nbBases; j++) {
945 ind = i + (j-1)*step;
946 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
947 usedBases.Append(aWireProf);
949 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
950 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
951 aBuilder.Add(aWireProf, aVert, theWithContact, theWithCorrect);
954 aBuilder.Add(aWireProf, theWithContact, theWithCorrect);
956 if (!aBuilder.IsReady()) {
957 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
960 aShape = aBuilder.Shape();
961 aSeqFaces.Append(aShape);
962 for (j = 1; j <=usedBases.Length(); j++)
963 aBuilder.Delete(usedBases.Value(j));
966 //for case if section is face
967 if (aSeqFaces.Length() >1) {
969 TopoDS_Compound aComp;
970 aB.MakeCompound(aComp);
971 for (i = 1; i <= aSeqFaces.Length(); i++)
972 aB.Add(aComp,aSeqFaces.Value(i));
980 //=======================================================================
981 //function : CreatePipeForShellSections
982 //purpose : auxilary for Execute()
983 //=======================================================================
984 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
987 //cout<<"CreatePipeForShellSections"<<endl;
992 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
993 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
994 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
995 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
996 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
997 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
999 Standard_Integer nbBases = aBasesObjs->Length(),
1000 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
1001 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
1003 if (nbLocs != nbBases) {
1004 if (aCI) delete aCI;
1005 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
1007 if (nbSubBases && nbSubBases != nbBases) {
1008 if (aCI) delete aCI;
1009 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
1012 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1014 TopTools_SequenceOfShape VLocs;
1015 for (i=1; i<=nbBases; i++) {
1016 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
1017 if (anItemLoc.IsNull())
1019 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
1020 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
1021 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
1023 VLocs.Append(aShapeLoc);
1025 nbLocs = VLocs.Length();
1026 if (nbLocs != nbBases) {
1027 if (aCI) delete aCI;
1028 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
1030 // split wire path by location points
1031 TColgp_SequenceOfPnt PLocs;
1032 for (i=1; i<=nbLocs; i++) {
1033 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
1034 PLocs.Append(BRep_Tool::Pnt(V));
1037 TopTools_SequenceOfShape Edges;
1038 TopTools_SequenceOfShape Wires;
1039 ShapeAnalysis_Edge sae;
1042 TopExp_Explorer anExp;
1043 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
1044 Edges.Append(anExp.Current());
1046 Standard_Integer Num1 = 0;
1047 Standard_Integer Num2 = 0;
1048 for (i=1; i<=Edges.Length(); i++) {
1049 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
1050 double tol = BRep_Tool::Tolerance(E);
1051 TopoDS_Vertex V1 = sae.FirstVertex(E);
1052 TopoDS_Vertex V2 = sae.LastVertex(E);
1053 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1054 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1055 if (P1.Distance(PLocs.First()) < tol) {
1058 if (P2.Distance(PLocs.Last()) < tol) {
1062 if (Num1>0 && Num2>0) {
1065 for (i=Num1; i<=Num2; i++) {
1066 B.Add(W,Edges.Value(i));
1071 Wires.Append(aWirePath);
1075 TopExp_Explorer anExp;
1076 for (anExp.Init(aWirePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
1077 Edges.Append(anExp.Current());
1079 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
1080 double tol = BRep_Tool::Tolerance(edge);
1081 TopoDS_Vertex VF = sae.FirstVertex(edge);
1082 gp_Pnt PF = BRep_Tool::Pnt(VF);
1083 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
1084 if (PF.Distance(PLocs.First()) > tol) {
1085 if (aCI) delete aCI;
1086 Standard_ConstructionError::Raise
1087 ("First location shapes is not coincided with first vertex of aWirePath");
1089 VLocs.ChangeValue(1) = VF;
1090 edge = TopoDS::Edge(Edges.Last());
1091 tol = BRep_Tool::Tolerance(edge);
1092 TopoDS_Vertex VL = sae.LastVertex(edge);
1093 gp_Pnt PL = BRep_Tool::Pnt(VL);
1094 if (PL.Distance(PLocs.Last()) > tol) {
1095 if (aCI) delete aCI;
1096 Standard_ConstructionError::Raise
1097 ("Last location shapes is not coincided with last vertex of aWirePath");
1099 VLocs.ChangeValue(nbLocs) = VL;
1101 TopTools_SequenceOfShape tmpEdges;
1102 for (i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
1103 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
1104 tol = BRep_Tool::Tolerance(E);
1105 TopoDS_Vertex V1 = sae.FirstVertex(E);
1106 TopoDS_Vertex V2 = sae.LastVertex(E);
1107 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1108 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1109 if (P2.Distance(PLocs.Value(jcurr)) < tol) {
1110 // make wire from current edge and add created
1114 for (j=1; j<=tmpEdges.Length(); j++)
1115 B.Add(W,tmpEdges.Value(j));
1118 VLocs.ChangeValue(jcurr) = V2;
1123 // find distance between E and aLocs(jcurr)
1125 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
1126 GeomAPI_ProjectPointOnCurve PPCurve (PLocs.Value(jcurr),C);
1127 if (PPCurve.NbPoints()>0 &&
1128 PLocs.Value(jcurr).Distance(PPCurve.Point(1)) < tol) {
1129 double param = PPCurve.Parameter(1);
1132 // split current edge
1133 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
1134 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
1138 if (Pfp.Distance(P1)<tol) {
1139 B.MakeEdge(E1,tc1,tol);
1141 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1142 B.Add(E1,TopoDS::Vertex(tmpV));
1143 tmpEdges.Append(E1);
1144 B.MakeEdge(E2,tc2,tol);
1145 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1146 B.Add(E2,TopoDS::Vertex(tmpV));
1150 B.MakeEdge(E1,tc2,tol);
1151 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1152 B.Add(E1,TopoDS::Vertex(tmpV));
1155 tmpEdges.Append(E1);
1156 B.MakeEdge(E2,tc1,tol);
1158 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1159 B.Add(E2,TopoDS::Vertex(tmpV));
1162 // create wire from tmpEdges
1165 for (j=1; j<=tmpEdges.Length(); j++)
1166 B.Add(W,tmpEdges.Value(j));
1171 Edges.InsertAfter(i-1,E1);
1172 Edges.InsertAfter(i,E2);
1179 // create wire from other edges
1182 for (; i<=Edges.Length(); i++)
1183 B.Add(W,Edges.Value(i));
1185 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
1188 if (Wires.Length() != nbLocs-1) {
1189 if (aCI) delete aCI;
1190 Standard_ConstructionError::Raise
1191 ("One of location shapes is not lied on the path");
1194 //TopTools_SequenceOfShape aSeqBases;
1195 //TopTools_SequenceOfShape aSeqSubBases;
1196 //TopTools_SequenceOfShape aSeqFaces;
1197 TopoDS_Compound aComp;
1198 B.MakeCompound(aComp);
1199 for (i = 1; i < nbBases; i++) {
1200 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
1202 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
1203 if (anItem1.IsNull())
1205 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
1206 if (aRefBase1.IsNull())
1208 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
1209 if (aShBase1.IsNull())
1211 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
1213 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
1214 if (anItem2.IsNull())
1216 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
1217 if (aRefBase2.IsNull())
1219 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
1220 if (aShBase2.IsNull())
1222 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
1224 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
1226 bool OkSec = (aType1==TopAbs_SHELL || aType1==TopAbs_FACE) &&
1227 (aType2==TopAbs_SHELL || aType2==TopAbs_FACE);
1229 if (aCI) delete aCI;
1230 Standard_ConstructionError::Raise("One of section shapes has invalid type");
1233 bool CreateFewSolids = false;
1235 TopExp_Explorer anExp;
1236 Standard_Integer nbf1 = 0;
1237 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1240 Standard_Integer nbf2 = 0;
1241 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1245 CreateFewSolids = true;
1249 // check orientation of sections
1250 bool NeedReverse = false;
1253 anExp.Init(aShBase1, TopAbs_FACE);
1254 TopoDS_Shape aFace = anExp.Current();
1255 TColgp_SequenceOfPnt aPnts;
1256 double xc=0, yc=0, zc=0;
1257 for (anExp.Init(aFace, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
1258 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
1259 aPnts.Append(BRep_Tool::Pnt(V));
1260 xc += aPnts.Last().X();
1261 yc += aPnts.Last().Y();
1262 zc += aPnts.Last().Z();
1264 gp_Pnt PC(xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length());
1265 gp_Vec V1(PC,aPnts.Value(1));
1266 gp_Vec V2(PC,aPnts.Value(2));
1267 gp_Vec VN = V1.Crossed(V2);
1268 for (int ip=2; ip<aPnts.Length(); ip++) {
1269 V1 = gp_Vec(PC,aPnts.Value(ip));
1270 V2 = gp_Vec(PC,aPnts.Value(ip+1));
1271 VN.Add(V1.Crossed(V2));
1274 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
1276 for (WE.Init(WPath, TopAbs_EDGE); WE.More(); WE.Next()) {
1277 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
1278 double tol = BRep_Tool::Tolerance(edge);
1279 TopoDS_Vertex VF = sae.FirstVertex(edge);
1280 gp_Pnt PF = BRep_Tool::Pnt(VF);
1281 if (PF.Distance(PLoc) < tol) {
1283 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1286 if (P1.Distance(PLoc) < tol) {
1287 C->D0(fp+(lp-fp)/100,P2);
1291 C->D0(lp+(fp-lp)/100,P2);
1293 PathNorm = gp_Vec(P1,P2);
1297 TopoDS_Vertex VL = sae.LastVertex(edge);
1298 gp_Pnt PL = BRep_Tool::Pnt(VL);
1299 if (PL.Distance(PLoc) < tol) {
1301 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1304 if (P1.Distance(PLoc) < tol) {
1305 C->D0(fp+(lp-fp)/100,P2);
1309 C->D0(lp+(fp-lp)/100,P2);
1311 PathNorm = gp_Vec(P2,P1);
1316 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1317 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1318 if (fabs(VN.Angle(PathNorm))>PI/2.) {
1325 anExp.Init(aShBase2, TopAbs_FACE);
1326 TopoDS_Shape aFace = anExp.Current();
1327 TColgp_SequenceOfPnt aPnts;
1328 double xc=0, yc=0, zc=0;
1329 for (anExp.Init(aFace, TopAbs_VERTEX); anExp.More(); anExp.Next()) {
1330 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
1331 aPnts.Append(BRep_Tool::Pnt(V));
1332 xc += aPnts.Last().X();
1333 yc += aPnts.Last().Y();
1334 zc += aPnts.Last().Z();
1336 gp_Pnt PC(xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length());
1337 gp_Vec V1(PC,aPnts.Value(1));
1338 gp_Vec V2(PC,aPnts.Value(2));
1339 gp_Vec VN = V1.Crossed(V2);
1340 for (int ip=2; ip<aPnts.Length(); ip++) {
1341 V1 = gp_Vec(PC,aPnts.Value(ip));
1342 V2 = gp_Vec(PC,aPnts.Value(ip+1));
1343 VN.Add(V1.Crossed(V2));
1346 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
1348 for (WE.Init(WPath, TopAbs_EDGE); WE.More(); WE.Next()) {
1349 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
1350 double tol = BRep_Tool::Tolerance(edge);
1351 TopoDS_Vertex VF = sae.FirstVertex(edge);
1352 gp_Pnt PF = BRep_Tool::Pnt(VF);
1353 if (PF.Distance(PLoc) < tol) {
1355 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1358 if (P1.Distance(PLoc) < tol) {
1359 C->D0(fp+(lp-fp)/100,P2);
1363 C->D0(lp+(fp-lp)/100,P2);
1365 PathNorm = gp_Vec(P2,P1);
1369 TopoDS_Vertex VL = sae.LastVertex(edge);
1370 gp_Pnt PL = BRep_Tool::Pnt(VL);
1371 if (PL.Distance(PLoc) < tol) {
1373 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1376 if (P1.Distance(PLoc) < tol) {
1377 C->D0(fp+(lp-fp)/100,P2);
1381 C->D0(lp+(fp-lp)/100,P2);
1383 PathNorm = gp_Vec(P2,P1);
1388 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1389 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1390 if (fabs(VN.Angle(PathNorm))>PI/2.)
1395 if (!CreateFewSolids) {
1396 // we can create only one solid
1397 TopoDS_Shape aWire1, aWire2;
1399 if (aType1==TopAbs_SHELL) {
1400 // create wire as boundary contour if shell is no closed
1401 // get free boundary shapes
1402 ShapeAnalysis_FreeBounds anAnalizer(aShBase1);
1403 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1404 //TopExp_Explorer anExp;
1405 Standard_Integer NbWires = 0;
1406 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
1408 aWire1 = anExp.Current();
1412 if (aCI) delete aCI;
1413 Standard_ConstructionError::Raise("Bad shell is used as section ");
1416 else { // aType1==TopAbs_FACE
1417 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1418 aWire1 = aExpW.Current();
1421 if (aType2==TopAbs_SHELL) {
1422 // create wire as boundary contour if shell is no closed
1423 // get free boundary shapes
1424 ShapeAnalysis_FreeBounds anAnalizer(aShBase2);
1425 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1426 //TopExp_Explorer anExp;
1427 Standard_Integer NbWires = 0;
1428 for (anExp.Init(aClosed, TopAbs_WIRE); anExp.More(); anExp.Next()) {
1430 aWire2 = anExp.Current();
1434 if (aCI) delete aCI;
1435 Standard_ConstructionError::Raise("Bad shell is used as section ");
1438 else { // aType2==TopAbs_FACE
1439 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1440 aWire2 = aExpW.Current();
1442 // make pipe using aWire1 and aWire2
1443 if (!aWire1.IsNull() && !aWire2.IsNull()) {
1444 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1445 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1446 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1447 aWithContact, aWithCorrect);
1448 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1449 aWithContact, aWithCorrect);
1450 if (!aBuilder.IsReady()) {
1451 if (aCI) delete aCI;
1452 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1455 TopoDS_Shape aShape = aBuilder.Shape();
1456 TopoDS_Shell aShell;
1457 B.MakeShell(aShell);
1458 for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
1459 B.Add(aShell,anExp.Current());
1461 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1462 B.Add(aShell,anExp.Current());
1464 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1465 B.Add(aShell,anExp.Current());
1467 // make sewing for this shell
1468 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1469 aSewing->SetTolerance(Precision::Confusion());
1470 aSewing->SetFaceMode(Standard_True);
1471 aSewing->SetFloatingEdgesMode(Standard_False);
1472 aSewing->SetNonManifoldMode(Standard_False);
1473 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
1474 aSewing->Add(anExp.Current());
1477 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1478 if (aSewShape.ShapeType() == TopAbs_SHELL) {
1479 aShell = TopoDS::Shell(aSewShape);
1480 GProp_GProps aSystem;
1481 BRepGProp::VolumeProperties(aShell, aSystem);
1482 if (aSystem.Mass()<0) {
1485 if (BRep_Tool::IsClosed(aShell)) {
1486 TopoDS_Solid aSolid;
1487 B.MakeSolid(aSolid);
1488 B.Add(aSolid,aShell);
1489 B.Add(aComp,aSolid);
1492 B.Add(aComp,aShell);
1496 B.Add(aComp,aShell);
1501 // main block - creation few solids (for each pair of faces)
1502 TopTools_MapOfShape aFaces1,aFaces2;
1503 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1504 aFaces1.Add(anExp.Current());
1506 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1507 aFaces2.Add(anExp.Current());
1509 // creating map of edge faces
1510 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1511 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1512 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1513 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1515 // constuct map face->face
1516 TopTools_IndexedDataMapOfShapeShape FF;
1517 TopoDS_Shape FS1,FS2;
1518 if (nbSubBases==0) {
1519 // find edge the most distant from location point
1520 // (this edge is not shared by two faces)
1521 double maxdist = 0.;
1523 TopoDS_Vertex V11,V21;
1524 for (j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1525 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1526 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1527 if (aList.Extent()>1)
1529 TopExp_Explorer expv;
1530 expv.Init(tmp, TopAbs_VERTEX);
1531 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1533 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1534 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1535 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1536 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1541 TopTools_ListIteratorOfListOfShape anIter(aList);
1542 FS1 = anIter.Value();
1546 // main direction for comparing
1547 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1548 // find corresponding edge from next section
1549 double minang = M_PI;
1550 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1551 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1553 TopoDS_Vertex V12,V22;
1554 for (j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1555 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1556 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1557 if (aList.Extent()>1)
1559 TopExp_Explorer expv;
1560 expv.Init(tmp, TopAbs_VERTEX);
1561 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1563 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1564 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1565 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1566 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1567 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1568 TopoDS_Vertex V1,V2;
1571 V1 = V2tmp; P1 = P2tmp;
1572 V2 = V1tmp; P2 = P1tmp;
1575 V1 = V1tmp; P1 = P1tmp;
1576 V2 = V2tmp; P2 = P2tmp;
1578 gp_Vec Vec1(P11,P1);
1579 gp_Vec Vec2(P21,P2);
1580 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1585 TopTools_ListIteratorOfListOfShape anIter(aList);
1586 FS2 = anIter.Value();
1590 // put all pairs to map FF
1596 // add pairs of edges to FF
1597 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1599 if (aCI) delete aCI;
1600 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1606 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1607 if (anItem.IsNull()) {
1608 if (aCI) delete aCI;
1609 Standard_ConstructionError::Raise("Invalid subbase shape");
1611 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1612 if (aRefBase.IsNull()) {
1613 if (aCI) delete aCI;
1614 Standard_ConstructionError::Raise("Invalid subbase shape");
1616 TopoDS_Shape aSh = aRefBase->GetValue();
1618 if (aCI) delete aCI;
1619 Standard_ConstructionError::Raise("Invalid subbase shape");
1621 if (aSh.ShapeType()!=TopAbs_FACE) {
1622 if (aCI) delete aCI;
1623 Standard_ConstructionError::Raise("Invalid subbase shape");
1628 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1629 if (anItem.IsNull()) {
1630 if (aCI) delete aCI;
1631 Standard_ConstructionError::Raise("Invalid subbase shape");
1633 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1634 if (aRefBase.IsNull()) {
1635 if (aCI) delete aCI;
1636 Standard_ConstructionError::Raise("Invalid subbase shape");
1638 TopoDS_Shape aSh = aRefBase->GetValue();
1640 if (aCI) delete aCI;
1641 Standard_ConstructionError::Raise("Invalid subbase shape");
1643 if (aSh.ShapeType()!=TopAbs_FACE) {
1644 if (aCI) delete aCI;
1645 Standard_ConstructionError::Raise("Invalid subbase shape");
1650 if (!aFaces1.Contains(FS1) || !aFaces2.Contains(FS2)) {
1651 if (aCI) delete aCI;
1652 Standard_ConstructionError::Raise("Invalid subbase shape");
1657 // add pairs of edges to FF
1658 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1659 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1661 if (aCI) delete aCI;
1662 Standard_ConstructionError::Raise("Can not create correct pipe");
1666 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1668 // make pipe for each pair of faces
1669 for (j=1; j<=FF.Extent(); j++) {
1670 TopoDS_Shape F1 = FF.FindKey(j);
1671 if (F1.ShapeType() != TopAbs_FACE)
1673 TopoDS_Shape F2 = FF.FindFromIndex(j);
1674 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1675 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1676 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1677 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1678 // make pipe using aWire1 and aWire2
1679 if (!aWire1.IsNull() && !aWire2.IsNull()) {
1680 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1681 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1682 aWithContact, aWithCorrect);
1683 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1684 aWithContact, aWithCorrect);
1685 if (!aBuilder.IsReady()) {
1686 if (aCI) delete aCI;
1687 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1690 TopoDS_Shape aShape = aBuilder.Shape();
1691 TopoDS_Shell aShell;
1692 B.MakeShell(aShell);
1693 for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
1694 B.Add(aShell,anExp.Current());
1699 // make sewing for this shell
1700 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1701 aSewing->SetTolerance(Precision::Confusion());
1702 aSewing->SetFaceMode(Standard_True);
1703 aSewing->SetFloatingEdgesMode(Standard_False);
1704 aSewing->SetNonManifoldMode(Standard_False);
1705 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
1706 aSewing->Add(anExp.Current());
1709 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1710 if (aSewShape.ShapeType() == TopAbs_SHELL) {
1711 aShell = TopoDS::Shell(aSewShape);
1712 GProp_GProps aSystem;
1713 BRepGProp::VolumeProperties(aShell, aSystem);
1714 if (aSystem.Mass()<0) {
1715 //cout<<"aSewShape is reversed"<<endl;
1718 if (BRep_Tool::IsClosed(aShell)) {
1719 TopoDS_Solid aSolid;
1720 B.MakeSolid(aSolid);
1721 B.Add(aSolid,aShell);
1722 B.Add(aComp,aSolid);
1725 B.Add(aComp,aShell);
1729 B.Add(aComp,aShell);
1737 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1741 //=======================================================================
1742 //function : CreatePipeShellsWithoutPath
1743 //purpose : auxilary for Execute()
1744 //=======================================================================
1745 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1747 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1751 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1753 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1754 // vertex for recognition
1755 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1757 Standard_Integer nbBases = aBasesObjs->Length(),
1758 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1760 if (nbv != nbBases) {
1761 if (aCI) delete aCI;
1762 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1765 TopTools_SequenceOfShape SecVs,Bases;
1766 for (i=1; i<=nbBases; i++) {
1768 Handle(Standard_Transient) anItem = VObjs->Value(i);
1769 if (anItem.IsNull())
1771 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1772 TopoDS_Shape V = aRef->GetValue();
1773 if (V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1777 anItem = aBasesObjs->Value(i);
1778 if (anItem.IsNull())
1780 aRef = Handle(GEOM_Function)::DownCast(anItem);
1781 TopoDS_Shape aSh = aRef->GetValue();
1786 nbv = SecVs.Length();
1787 nbBases = Bases.Length();
1788 if (nbv != nbBases) {
1789 if (aCI) delete aCI;
1790 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1793 TopoDS_Compound aComp;
1794 B.MakeCompound(aComp);
1796 for (i = 1; i < nbBases; i++) {
1797 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1798 TopoDS_Shape aShBase1 = Bases.Value(i);
1799 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1800 TopExp_Explorer anExp;
1801 Standard_Integer nbf1 = 0;
1802 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1805 Standard_Integer nbf2 = 0;
1806 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1809 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1811 if (aCI) delete aCI;
1812 Standard_ConstructionError::Raise("Different number of faces in the sections");
1815 TopTools_MapOfShape aFaces1,aFaces2;
1816 for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
1817 aFaces1.Add(anExp.Current());
1819 for (anExp.Init(aShBase2, TopAbs_FACE); anExp.More(); anExp.Next()) {
1820 aFaces2.Add(anExp.Current());
1823 // creating map of edge faces
1824 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1825 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1826 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1827 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1829 // constuct map face->face (and sub-shapes)
1830 TopTools_IndexedDataMapOfShapeShape FF;
1831 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1832 TopoDS_Shape FS1, FS2;
1833 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1834 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1835 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1838 MESSAGE (" first pair of corresponding faces is found");
1840 // add pairs of edges and vertexes to FF
1841 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1843 if (aCI) delete aCI;
1844 Standard_ConstructionError::Raise("Can not create correct pipe");
1846 MESSAGE (" correspondences for sub-shapes of first pair of faces is found");
1848 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1849 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1851 // make pipe for each pair of faces
1852 // auxilary map vertex->edge for created pipe edges
1853 TopTools_IndexedDataMapOfShapeShape VPE;
1854 ShapeAnalysis_Edge sae;
1855 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1857 for (j=1; j<=FF.Extent(); j++) {
1858 TopoDS_Shape F1 = FF.FindKey(j);
1859 if (F1.ShapeType() != TopAbs_FACE)
1861 TopoDS_Shape F2 = FF.FindFromIndex(j);
1864 //if (nbff!=3) continue;
1866 MESSAGE (" make pipe for "<<nbff<<" face");
1868 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1869 if (S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1870 Handle(Geom_RectangularTrimmedSurface) RTS =
1871 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1872 S1 = RTS->BasisSurface();
1874 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1875 if (Pln1.IsNull()) {
1876 if (aCI) delete aCI;
1877 Standard_ConstructionError::Raise("Surface from face is not plane");
1879 gp_Vec aDir1(Pln1->Axis().Direction());
1881 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1882 if (S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1883 Handle(Geom_RectangularTrimmedSurface) RTS =
1884 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1885 S2 = RTS->BasisSurface();
1887 Handle(Geom_Plane) Pln2 =
1888 Handle(Geom_Plane)::DownCast(S2);
1889 if (Pln2.IsNull()) {
1890 if (aCI) delete aCI;
1891 Standard_ConstructionError::Raise("Surface from face is not plane");
1893 gp_Vec aDir2(Pln2->Axis().Direction());
1895 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1896 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1898 if (fabs(aDir.Angle(aDir1)) > M_PI/2.)
1900 if (fabs(aDir.Angle(aDir2)) > M_PI/2.)
1903 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1904 TopTools_SequenceOfShape aNewFs;
1906 for (; anExpE.More(); anExpE.Next()) {
1907 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1909 if (!FF.Contains(E1))
1910 MESSAGE ("map FF not contains key E1");
1912 if (VPE.Contains(E1)) {
1913 aNewFs.Append(VPE.FindFromKey(E1));
1915 MESSAGE (" using existed face");
1920 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1921 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1922 TopoDS_Vertex V2 = sae.LastVertex(E1);
1923 if (!FF.Contains(V1))
1924 MESSAGE ("map FF not contains key V1");
1925 if (!FF.Contains(V2))
1926 MESSAGE ("map FF not contains key V2");
1927 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1928 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1929 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1930 if (Vtmp.IsSame(V4))
1932 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1933 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1934 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1935 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1938 Handle(Geom_BSplineCurve) C2;
1939 if (VPE.Contains(V2)) {
1940 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1942 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1945 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1946 HAP->SetValue(1,P2);
1947 HAP->SetValue(2,P3);
1948 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1949 anInt.Load(aDir1,aDir2);
1952 B.MakeEdge(E2,C2,1.e-7);
1953 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1954 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1959 Handle(Geom_BSplineCurve) C4;
1960 if (VPE.Contains(V1)) {
1961 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1963 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1966 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1967 HAP->SetValue(1,P1);
1968 HAP->SetValue(2,P4);
1969 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1970 anInt.Load(aDir1,aDir2);
1973 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1974 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1975 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1984 B.Add(W,E4.Reversed());
1985 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1986 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1991 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1992 //bool IsConicC1 = false;
1993 //if (C1->IsKind(STANDARD_TYPE(Geom_Conic))) {
1994 // IsConicC1 = true;
1995 // cout<<"C1 - Geom_Conic"<<endl;
1997 if (C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic))) {
1998 C1 = new Geom_TrimmedCurve(C1,fp,lp);
2001 // double tol = BRep_Tool::Tolerance(E1);
2002 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
2003 // C1 = ApxC1.Curve();
2005 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
2006 if (C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic))) {
2007 C3 = new Geom_TrimmedCurve(C3,fp,lp);
2012 Handle(Geom_BSplineCurve) CE1 =
2013 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
2014 if (CE1->Degree()<3)
2015 CE1->IncreaseDegree(3);
2016 Handle(Geom_BSplineCurve) CE2 =
2017 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
2018 if (CE2->Degree()<3)
2019 CE2->IncreaseDegree(3);
2020 Handle(Geom_BSplineCurve) CE3 =
2021 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
2022 if (CE3->Degree()<3)
2023 CE3->IncreaseDegree(3);
2024 Handle(Geom_BSplineCurve) CE4 =
2025 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
2026 if (CE4->Degree()<3)
2027 CE4->IncreaseDegree(3);
2028 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
2029 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
2030 //if (fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
2031 // os<<"DrawTrSurf_BSplineCurve"<<endl;
2032 // GeomTools::Write(CE1,os);
2036 Handle(Geom_Surface) BS;
2038 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
2039 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
2043 MESSAGE (" can not create BSplineSurface - create Bezier");
2045 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
2046 double fp1,lp1,fp2,lp2;
2047 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
2048 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
2057 // get points from C1
2058 if (P1.Distance(P1C1)<1.e-6) {
2066 double step = (lp-fp)/(NbP-1);
2067 Points.SetValue(1,1,P1);
2069 for (n1=2; n1<NbP; n1++) {
2073 Points.SetValue(1,n1,P);
2075 Points.SetValue(1,NbP,P2);
2076 // get points from C3
2077 if (P4.Distance(P1C3)<1.e-6) {
2085 step = (lp-fp)/(NbP-1);
2086 Points.SetValue(NbP,1,P4);
2088 for (n1=2; n1<NbP; n1++) {
2092 Points.SetValue(NbP,n1,P);
2094 Points.SetValue(NbP,NbP,P3);
2095 // create isolines and get points from them
2096 for (n1=1; n1<=NbP; n1++) {
2097 gp_Pnt PI1 = Points.Value(1,n1);
2098 gp_Pnt PI2 = Points.Value(NbP,n1);
2099 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
2100 HAP->SetValue(1,PI1);
2101 HAP->SetValue(2,PI2);
2102 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
2103 anInt.Load(aDir1,aDir2);
2105 Handle(Geom_Curve) iso = anInt.Curve();
2106 fp = iso->FirstParameter();
2107 lp = iso->LastParameter();
2108 step = (lp-fp)/(NbP-1);
2110 TopoDS_Compound VComp;
2111 B.MakeCompound(VComp);
2112 for (n2=2; n2<NbP; n2++) {
2116 Points.SetValue(n2,n1,P);
2119 // create surface and face
2120 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
2121 BS = new Geom_BezierSurface(Points);
2124 BRepBuilderAPI_MakeFace BB(BS,W);
2125 TopoDS_Face NewF = BB.Face();
2126 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
2128 sff->FixOrientation();
2129 TopoDS_Face FixedFace = sff->Face();
2130 aNewFs.Append(FixedFace);
2131 VPE.Add(E1,FixedFace);
2132 //cout<<" face for edge "<<nbee<<" is created"<<endl;
2133 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
2136 TopoDS_Shell aShell;
2137 B.MakeShell(aShell);
2138 for (int nf=1; nf<=aNewFs.Length(); nf++) {
2139 B.Add(aShell,aNewFs(nf));
2144 // make sewing for this shell
2145 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2146 aSewing->SetTolerance(Precision::Confusion());
2147 aSewing->SetFaceMode(Standard_True);
2148 aSewing->SetFloatingEdgesMode(Standard_False);
2149 aSewing->SetNonManifoldMode(Standard_False);
2150 for (anExp.Init(aShell, TopAbs_FACE); anExp.More(); anExp.Next()) {
2151 aSewing->Add(anExp.Current());
2154 MESSAGE (" shell for face "<<nbff<<" is created");
2155 const TopoDS_Shape aSewShape = aSewing->SewedShape();
2156 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
2157 if (aSewShape.ShapeType() == TopAbs_SHELL) {
2158 aShell = TopoDS::Shell(aSewShape);
2159 GProp_GProps aSystem;
2160 BRepGProp::VolumeProperties(aShell, aSystem);
2161 if (aSystem.Mass()<0) {
2162 //cout<<"aSewShape is reversed"<<endl;
2165 if (BRep_Tool::IsClosed(aShell)) {
2166 TopoDS_Solid aSolid;
2167 B.MakeSolid(aSolid);
2168 B.Add(aSolid,aShell);
2169 B.Add(aComp,aSolid);
2170 MESSAGE (" solid for face "<<nbff<<" is created");
2173 B.Add(aComp,aShell);
2174 MESSAGE (" solid for face "<<nbff<<" is not created");
2178 B.Add(aComp,aShell);
2179 MESSAGE (" solid for face "<<nbff<<" is not created");
2181 //cout<<" solid for face "<<nbff<<" is created"<<endl;
2183 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
2185 //TopoDS_Shell FixedShell = sfs->Shell();
2187 GProp_GProps aSystem;
2188 BRepGProp::VolumeProperties(FixedShell, aSystem);
2189 if (aSystem.Mass()<0) {
2190 //cout<<"aSewShape is reversed"<<endl;
2191 FixedShell.Reverse();
2193 if (BRep_Tool::IsClosed(FixedShell)) {
2194 TopoDS_Solid aSolid;
2195 B.MakeSolid(aSolid);
2196 B.Add(aSolid,aShell);
2197 B.Add(aComp,aSolid);
2200 B.Add(aComp,FixedShell);
2206 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
2210 //=======================================================================
2211 //function : CreatePipeBiNormalAlongVector
2212 //purpose : auxilary for Execute()
2213 //=======================================================================
2214 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
2215 GEOMImpl_IPipe* aCI)
2217 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
2219 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
2220 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
2221 TopoDS_Shape aShapeBase = aRefBase->GetValue();
2222 TopoDS_Shape aShapeVec = aRefVec->GetValue();
2224 if (aShapeBase.IsNull()) {
2225 if (aCIBN) delete aCIBN;
2226 Standard_NullObject::Raise("MakePipe aborted : null base argument");
2229 // Make copy to prevent modifying of base object: 0021525
2230 BRepBuilderAPI_Copy Copy (aShapeBase);
2232 aShapeBase = Copy.Shape();
2235 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
2238 else if (aShapeBase.ShapeType() == TopAbs_EDGE) {
2239 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
2241 else if (aShapeBase.ShapeType() == TopAbs_WIRE) {
2244 else if (aShapeBase.ShapeType() == TopAbs_FACE) {
2245 TopExp_Explorer wexp (aShapeBase,TopAbs_WIRE);
2246 aProf = wexp.Current();
2249 Standard_TypeMismatch::Raise
2250 ("MakePipe aborted : invalid type of base");
2252 BRepOffsetAPI_MakePipeShell PipeBuilder (aWirePath);
2253 PipeBuilder.Add(aProf);
2255 if (aShapeVec.IsNull()) {
2256 if (aCIBN) delete aCIBN;
2257 Standard_NullObject::Raise
2258 ("MakePipe aborted : null vector argument");
2260 if (aShapeVec.ShapeType() != TopAbs_EDGE)
2261 Standard_TypeMismatch::Raise
2262 ("MakePipe aborted: invalid type of vector");
2263 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
2264 TopoDS_Vertex V1, V2;
2265 TopExp::Vertices(anEdge, V1, V2, Standard_True);
2266 if (V1.IsNull() || V2.IsNull())
2267 Standard_NullObject::Raise
2268 ("MakePipe aborted: vector is not defined");
2269 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
2270 gp_Dir BiNormal(aVec);
2271 PipeBuilder.SetMode(BiNormal);
2272 PipeBuilder.Build();
2273 if (aShapeBase.ShapeType() == TopAbs_FACE) {
2274 PipeBuilder.MakeSolid();
2277 return PipeBuilder.Shape();
2280 //=======================================================================
2281 //function : Execute
2283 //=======================================================================
2284 Standard_Integer GEOMImpl_PipeDriver::Execute (TFunction_Logbook& log) const
2286 if (Label().IsNull()) return 0;
2287 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
2288 Standard_Integer aType = aFunction->GetType();
2290 GEOMImpl_IPipe* aCI = 0;
2291 if (aType == PIPE_BASE_PATH)
2292 aCI = new GEOMImpl_IPipe (aFunction);
2293 else if (aType == PIPE_DIFFERENT_SECTIONS)
2294 aCI = new GEOMImpl_IPipeDiffSect (aFunction);
2295 else if (aType == PIPE_SHELL_SECTIONS)
2296 aCI = new GEOMImpl_IPipeShellSect (aFunction);
2297 else if (aType == PIPE_SHELLS_WITHOUT_PATH)
2298 aCI = new GEOMImpl_IPipeShellSect (aFunction);
2299 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR)
2300 aCI = new GEOMImpl_IPipeBiNormal (aFunction);
2304 TopoDS_Wire aWirePath;
2305 if (aType != PIPE_SHELLS_WITHOUT_PATH) {
2306 // working with path
2307 Handle(GEOM_Function) aRefPath = aCI->GetPath();
2308 TopoDS_Shape aShapePath = aRefPath->GetValue();
2310 if (aShapePath.IsNull()) {
2311 MESSAGE ("Driver : path is null");
2312 if (aCI) delete aCI;
2313 Standard_NullObject::Raise("MakePipe aborted : null path argument");
2318 if (aShapePath.ShapeType() == TopAbs_COMPOUND) {
2319 TopTools_SequenceOfShape anEdges;
2320 TopExp_Explorer anExp;
2324 for (anExp.Init(aShapePath, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2325 B.Add(W, anExp.Current());
2331 else if (aShapePath.ShapeType() == TopAbs_WIRE) {
2332 aWirePath = TopoDS::Wire(aShapePath);
2336 if (aShapePath.ShapeType() == TopAbs_EDGE) {
2337 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
2338 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
2343 if (aCI) delete aCI;
2344 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
2348 TopoDS_Shape aShape;
2350 if (aType == PIPE_BASE_PATH) {
2351 Handle(GEOM_Function) aRefBase = aCI->GetBase();
2352 TopoDS_Shape aShapeBase;
2354 // Make copy to prevent modifying of base object 0020766 : EDF 1320
2355 BRepBuilderAPI_Copy Copy(aRefBase->GetValue());
2357 aShapeBase = Copy.Shape();
2359 if (aShapeBase.IsNull()) {
2360 if (aCI) delete aCI;
2361 Standard_NullObject::Raise("MakePipe aborted : null base argument");
2365 if (aShapeBase.ShapeType() == TopAbs_EDGE ||
2366 aShapeBase.ShapeType() == TopAbs_WIRE)
2368 TopoDS_Wire Profile;
2369 if (aShapeBase.ShapeType() == TopAbs_WIRE)
2370 Profile = TopoDS::Wire(aShapeBase);
2374 BB.MakeWire(Profile);
2375 BB.Add(Profile, aShapeBase);
2378 BRepOffsetAPI_MakePipeShell Sweep (aWirePath);
2379 BRepBuilderAPI_MakeFace FaceBuilder (aWirePath, Standard_True); //to find the plane of spine
2380 if (FaceBuilder.IsDone())
2381 Sweep.SetMode(FaceBuilder.Face());
2385 if (!Sweep.IsDone())
2387 if (aCI) delete aCI;
2388 Standard_ConstructionError::Raise("MakePipeShell failed");
2391 aShape = Sweep.Shape(); //result is good
2395 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
2398 //building pipe with different sections
2399 else if (aType == PIPE_DIFFERENT_SECTIONS) {
2400 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
2401 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
2402 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
2403 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
2404 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
2410 Standard_Integer nbBases = aBasesObjs->Length();
2411 Standard_Integer nbLocs = (aLocObjs.IsNull() ? 0 : aLocObjs->Length());
2413 Handle(TopTools_HSequenceOfShape) aHSeqBases = new TopTools_HSequenceOfShape;
2414 Handle(TopTools_HSequenceOfShape) aHSeqLocs = new TopTools_HSequenceOfShape;
2417 for (i = 1; i <= nbBases; i++) {
2418 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2419 if (anItem.IsNull())
2421 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2422 if (aRefBase.IsNull())
2424 if (aRefBase->GetValue().IsNull())
2427 aHSeqBases->Append(aRefBase->GetValue());
2429 for (i = 1; i <= nbLocs; i++) {
2430 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2431 if (anItemLoc.IsNull())
2433 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2434 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2435 if (aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2438 aHSeqLocs->Append(aShapeLoc);
2441 aShape = CreatePipeWithDifferentSections(aWirePath, aHSeqBases, aHSeqLocs, aWithContact, aWithCorrect);
2444 //building pipe with shell sections
2445 else if (aType == PIPE_SHELL_SECTIONS) {
2446 aShape = CreatePipeForShellSections(aWirePath,aCI);
2449 //building pipe shell sections without path
2450 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2451 aShape = CreatePipeShellsWithoutPath(aCI);
2454 //building a pipe with constant bi-normal along given vector
2455 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2456 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2464 if (aShape.IsNull()) return 0;
2466 BRepCheck_Analyzer ana (aShape, Standard_False);
2467 if (!ana.IsValid()) {
2468 ShapeFix_ShapeTolerance aSFT;
2469 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2470 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2471 aSfs->SetPrecision(Precision::Confusion());
2473 aShape = aSfs->Shape();
2475 ana.Init(aShape, Standard_False);
2477 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2480 if (aType != PIPE_BASE_PATH &&
2481 aType != PIPE_SHELLS_WITHOUT_PATH) {
2482 TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
2483 if (anExpV.More()) {
2484 Standard_Real aVertMaxTol = -RealLast();
2485 for (; anExpV.More(); anExpV.Next()) {
2486 TopoDS_Vertex aVertex = TopoDS::Vertex(anExpV.Current());
2487 Standard_Real aTol = BRep_Tool::Tolerance(aVertex);
2488 if (aTol > aVertMaxTol)
2491 aVertMaxTol += Precision::Confusion();
2492 aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, aVertMaxTol, Standard_True);
2493 //aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
2497 TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape);
2498 aFunction->SetValue(aRes);
2500 log.SetTouched(Label());
2504 //=======================================================================
2505 //function : GEOMImpl_PipeDriver_Type_
2507 //=======================================================================
2508 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2510 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2511 if (aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2512 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2513 if (aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2514 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2515 if (aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2517 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2518 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2519 sizeof(GEOMImpl_PipeDriver),
2521 (Standard_Address)_Ancestors,
2522 (Standard_Address)NULL);
2527 //=======================================================================
2528 //function : DownCast
2530 //=======================================================================
2531 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2533 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2535 if (!AnObject.IsNull()) {
2536 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2537 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2541 return _anOtherObject;