1 // Copyright (C) 2007-2008 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 <Standard_Stream.hxx>
24 #include <GEOMImpl_PipeDriver.hxx>
26 #include <GEOMImpl_IShapesOperations.hxx>
27 #include <GEOMImpl_IPipeDiffSect.hxx>
28 #include <GEOMImpl_IPipeShellSect.hxx>
29 #include <GEOMImpl_IPipeBiNormal.hxx>
30 #include <GEOMImpl_IPipe.hxx>
31 #include <GEOMImpl_GlueDriver.hxx>
32 #include <GEOMImpl_Types.hxx>
33 #include <GEOM_Function.hxx>
35 //#include <GEOMAlgo_GlueAnalyser.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_MakeWire.hxx>
47 #include <BRepBuilderAPI_Sewing.hxx>
48 #include <BRepCheck_Analyzer.hxx>
49 #include <BRepOffsetAPI_MakePipe.hxx>
50 #include <BRepOffsetAPI_MakePipeShell.hxx>
51 #include <GProp_GProps.hxx>
52 #include <BRepGProp.hxx>
53 #include <BRepBuilderAPI_MakeFace.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_IndexedDataMapOfShapeShape.hxx>
68 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <GeomAPI_ProjectPointOnCurve.hxx>
72 #include <GeomAPI_Interpolate.hxx>
73 #include <Geom_TrimmedCurve.hxx>
74 #include <Geom_Plane.hxx>
75 #include <Geom_RectangularTrimmedSurface.hxx>
76 #include <Geom_BezierSurface.hxx>
77 #include <Geom_Line.hxx>
78 #include <Geom_Conic.hxx>
79 #include <Geom_BSplineCurve.hxx>
80 #include <Geom_BSplineSurface.hxx>
81 #include <GeomFill_BSplineCurves.hxx>
82 #include <GeomConvert_ApproxCurve.hxx>
83 #include <GeomConvert.hxx>
85 #include <TColgp_SequenceOfPnt.hxx>
86 #include <TColgp_HArray1OfPnt.hxx>
87 #include <TColgp_Array2OfPnt.hxx>
88 #include <TColStd_HSequenceOfTransient.hxx>
90 #include <Precision.hxx>
91 #include <Standard_NullObject.hxx>
92 #include <Standard_TypeMismatch.hxx>
93 #include <Standard_ConstructionError.hxx>
95 #include "utilities.h"
98 //=======================================================================
101 //=======================================================================
102 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
104 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
109 //=======================================================================
110 //function : GEOMImpl_PipeDriver
112 //=======================================================================
113 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
118 //=======================================================================
119 //function : FillForOtherEdges
120 //purpose : auxilary for CreatePipeForShellSections()
121 //=======================================================================
122 static bool FillForOtherEdges(const TopoDS_Shape& F1,
123 const TopoDS_Shape& E1,
124 const TopoDS_Shape& V1,
125 TopTools_IndexedDataMapOfShapeShape& FF)
127 //cout<<"FillForOtherEdges"<<endl;
128 // find other pairs for vertexes and edges
129 // creating map of vertex edges for both faces
130 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
131 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
132 if (!FF.Contains(F1))
133 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
134 if (!FF.Contains(E1))
135 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
136 if (!FF.Contains(V1))
137 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
138 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
139 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
140 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
141 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
142 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
144 TopoDS_Edge ES1 = TopoDS::Edge(E1);
145 TopoDS_Edge ES2 = TopoDS::Edge(E2);
146 TopoDS_Shape VS1 = V1;
147 TopoDS_Shape VS2 = V2;
149 ShapeAnalysis_Edge sae;
151 if(!aMapVertEdge1.Contains(VS1))
152 MESSAGE (" FillForOtherEdges: map aMapVertEdge1 not contains key VS1");
153 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
154 //TopoDS_Shape E1next;
155 TopTools_ListIteratorOfListOfShape anIter1(aList1);
156 if(anIter1.Value().IsSame(ES1)) {
159 //E1next = anIter1.Value();
160 if(!aMapVertEdge2.Contains(VS2))
161 MESSAGE (" FillForOtherEdges: map aMapVertEdge2 not contains key VS2");
162 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
163 //TopoDS_Shape E2next;
164 TopTools_ListIteratorOfListOfShape anIter2(aList2);
165 if(anIter2.Value().IsSame(ES2)) {
168 //E2next = anIter2.Value();
169 //ES1 = TopoDS::Edge(E1next);
170 //ES2 = TopoDS::Edge(E2next);
171 ES1 = TopoDS::Edge(anIter1.Value());
172 ES2 = TopoDS::Edge(anIter2.Value());
173 if(!FF.Contains(ES1)) {
176 if(VS1.IsSame(sae.FirstVertex(ES1)))
177 VS1 = sae.LastVertex(ES1);
179 VS1 = sae.FirstVertex(ES1);
180 if(VS2.IsSame(sae.FirstVertex(ES2)))
181 VS2 = sae.LastVertex(ES2);
183 VS2 = sae.FirstVertex(ES2);
186 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);
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);
431 //=======================================================================
432 //function : FindNextPairOfFaces
433 //purpose : auxilary for CreatePipeForShellSections()
434 //=======================================================================
435 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
436 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
437 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
438 TopTools_IndexedDataMapOfShapeShape& FF,
441 //cout<<"FindNextPairOfFaces"<<endl;
442 TopExp_Explorer anExp;
443 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
444 TopoDS_Shape E1 = anExp.Current();
445 if(!FF.Contains(E1)) {
447 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
450 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
451 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
452 TopExp_Explorer anExpV;
453 anExpV.Init( E1, TopAbs_VERTEX );
454 TopoDS_Shape V1 = anExpV.Current();
455 if(!FF.Contains(V1)) {
457 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
460 if(!aMapEdgeFaces1.Contains(E1))
461 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
462 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
463 if(aList1.Extent()<2)
465 TopTools_ListIteratorOfListOfShape anIter(aList1);
466 if(anIter.Value().IsEqual(aCurFace)) {
469 TopoDS_Shape F1other = anIter.Value();
470 if(FF.Contains(F1other))
473 if(!FF.Contains(aCurFace))
474 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
475 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
476 if(!aMapEdgeFaces2.Contains(E2))
477 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
478 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
479 if(aList2.Extent()<2) {
481 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
483 TopTools_ListIteratorOfListOfShape anIter2(aList2);
484 if(anIter2.Value().IsEqual(F2)) {
487 TopoDS_Shape F2other = anIter2.Value();
488 FF.Add(F1other,F2other);
490 // add pairs of edges to FF
491 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
494 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
497 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
502 //=======================================================================
503 //function : FindFirstPairFaces
504 //purpose : auxilary for Execute()
505 //=======================================================================
506 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
507 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
508 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
510 //cout<<"FindFirstPairFaces"<<endl;
512 // check if vertexes are subshapes of sections
513 gp_Pnt P1 = BRep_Tool::Pnt(V1);
514 gp_Pnt P2 = BRep_Tool::Pnt(V2);
515 TopoDS_Vertex V1new,V2new;
517 double mindist = 1.e10;
518 for( exp.Init( S1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
519 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
520 gp_Pnt P = BRep_Tool::Pnt(V);
521 double dist = P1.Distance(P);
528 for( exp.Init( S2, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
529 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
530 gp_Pnt P = BRep_Tool::Pnt(V);
531 double dist = P2.Distance(P);
538 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
539 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
540 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
541 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
542 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
543 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
545 // replace vertexes if it is needed
546 if(!V1.IsSame(V1new)) {
548 P1 = BRep_Tool::Pnt(V1);
549 MESSAGE (" replace V1");
552 MESSAGE (" not replace V1");
553 if(!V2.IsSame(V2new)) {
555 P2 = BRep_Tool::Pnt(V2);
556 MESSAGE (" replace V2");
559 MESSAGE (" not replace V2");
561 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
562 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
563 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
564 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
566 if(!aMapVertFaces1.Contains(V1))
567 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
568 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
569 TopTools_ListIteratorOfListOfShape anIter1(aList1);
570 FS1 = anIter1.Value();
572 double x1=0., y1=0., z1=0.;
574 for( exp.Init( FS1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
575 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
576 gp_Pnt P = BRep_Tool::Pnt(V);
582 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
584 TColgp_SequenceOfPnt Ps;
585 TopTools_SequenceOfShape Fs;
586 if(!aMapVertFaces2.Contains(V2))
587 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
588 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
589 TopTools_ListIteratorOfListOfShape anIter2(aList2);
590 for(; anIter2.More(); anIter2.Next()) {
591 TopoDS_Shape F = anIter2.Value();
592 double x2=0., y2=0., z2=0.;
594 for( exp.Init( F, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
595 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
596 gp_Pnt P = BRep_Tool::Pnt(V);
602 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
611 for(; i<=Fs.Length(); i++) {
612 gp_Vec tmpDir(PM1,Ps(i));
613 double ang = fabs(aDir.Angle(tmpDir));
623 //=======================================================================
624 //function : CreatePipeForShellSections
625 //purpose : auxilary for Execute()
626 //=======================================================================
627 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
630 //cout<<"CreatePipeForShellSections"<<endl;
635 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
636 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
637 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
638 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
639 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
640 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
642 Standard_Integer nbBases = aBasesObjs->Length(),
643 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
644 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
646 if( nbLocs != nbBases) {
648 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
650 if( nbSubBases && nbSubBases != nbBases) {
652 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
655 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
657 TopTools_SequenceOfShape VLocs;
658 for(i=1; i<=nbBases; i++) {
659 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
660 if(anItemLoc.IsNull())
662 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
663 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
664 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
666 VLocs.Append(aShapeLoc);
668 nbLocs = VLocs.Length();
669 if( nbLocs != nbBases) {
671 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
673 // split wire path by location points
674 TColgp_SequenceOfPnt PLocs;
675 for(i=1; i<=nbLocs; i++) {
676 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
677 PLocs.Append(BRep_Tool::Pnt(V));
680 TopTools_SequenceOfShape Edges;
681 TopTools_SequenceOfShape Wires;
682 ShapeAnalysis_Edge sae;
685 TopExp_Explorer anExp;
686 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
687 Edges.Append(anExp.Current());
689 Standard_Integer Num1 = 0;
690 Standard_Integer Num2 = 0;
691 for(i=1; i<=Edges.Length(); i++) {
692 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
693 double tol = BRep_Tool::Tolerance(E);
694 TopoDS_Vertex V1 = sae.FirstVertex(E);
695 TopoDS_Vertex V2 = sae.LastVertex(E);
696 gp_Pnt P1 = BRep_Tool::Pnt(V1);
697 gp_Pnt P2 = BRep_Tool::Pnt(V2);
698 if( P1.Distance(PLocs.First()) < tol ) {
701 if( P2.Distance(PLocs.Last()) < tol ) {
705 if( Num1>0 && Num2>0 ) {
708 for(i=Num1; i<=Num2; i++) {
709 B.Add(W,Edges.Value(i));
714 Wires.Append(aWirePath);
718 TopExp_Explorer anExp;
719 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
720 Edges.Append(anExp.Current());
722 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
723 double tol = BRep_Tool::Tolerance(edge);
724 TopoDS_Vertex VF = sae.FirstVertex(edge);
725 gp_Pnt PF = BRep_Tool::Pnt(VF);
726 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
727 if( PF.Distance(PLocs.First()) > tol ) {
729 Standard_ConstructionError::Raise
730 ("First location shapes is not coincided with first vertex of aWirePath");
732 VLocs.ChangeValue(1) = VF;
733 edge = TopoDS::Edge(Edges.Last());
734 tol = BRep_Tool::Tolerance(edge);
735 TopoDS_Vertex VL = sae.LastVertex(edge);
736 gp_Pnt PL = BRep_Tool::Pnt(VL);
737 if( PL.Distance(PLocs.Last()) > tol ) {
739 Standard_ConstructionError::Raise
740 ("Last location shapes is not coincided with last vertex of aWirePath");
742 VLocs.ChangeValue(nbLocs) = VL;
744 TopTools_SequenceOfShape tmpEdges;
745 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
746 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
747 tol = BRep_Tool::Tolerance(E);
748 TopoDS_Vertex V1 = sae.FirstVertex(E);
749 TopoDS_Vertex V2 = sae.LastVertex(E);
750 gp_Pnt P1 = BRep_Tool::Pnt(V1);
751 gp_Pnt P2 = BRep_Tool::Pnt(V2);
752 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
753 // make wire from current edge and add created
757 for(j=1; j<=tmpEdges.Length(); j++)
758 B.Add(W,tmpEdges.Value(j));
761 VLocs.ChangeValue(jcurr) = V2;
766 // find distance between E and aLocs(jcurr)
768 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
769 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
770 if( PPC.NbPoints()>0 &&
771 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
772 double param = PPC.Parameter(1);
775 // split current edge
776 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
777 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
781 if(Pfp.Distance(P1)<tol) {
782 B.MakeEdge(E1,tc1,tol);
784 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
785 B.Add(E1,TopoDS::Vertex(tmpV));
787 B.MakeEdge(E2,tc2,tol);
788 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
789 B.Add(E2,TopoDS::Vertex(tmpV));
793 B.MakeEdge(E1,tc2,tol);
794 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
795 B.Add(E1,TopoDS::Vertex(tmpV));
799 B.MakeEdge(E2,tc1,tol);
801 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
802 B.Add(E2,TopoDS::Vertex(tmpV));
805 // create wire from tmpEdges
808 for(j=1; j<=tmpEdges.Length(); j++)
809 B.Add(W,tmpEdges.Value(j));
814 Edges.InsertAfter(i-1,E1);
815 Edges.InsertAfter(i,E2);
822 // create wire from other edges
825 for(; i<=Edges.Length(); i++)
826 B.Add(W,Edges.Value(i));
828 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
831 if( Wires.Length() != nbLocs-1 ) {
833 Standard_ConstructionError::Raise
834 ("One of location shapes is not lied on the path");
837 //TopTools_SequenceOfShape aSeqBases;
838 //TopTools_SequenceOfShape aSeqSubBases;
839 //TopTools_SequenceOfShape aSeqFaces;
840 TopoDS_Compound aComp;
841 B.MakeCompound(aComp);
842 for(i=1 ; i<nbBases; i++) {
843 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
845 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
848 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
849 if(aRefBase1.IsNull())
851 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
852 if(aShBase1.IsNull())
854 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
856 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
859 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
860 if(aRefBase2.IsNull())
862 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
863 if(aShBase2.IsNull())
865 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
867 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
869 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
870 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
873 Standard_ConstructionError::Raise("One of section shapes has invalid type");
876 bool CreateFewSolids = false;
878 TopExp_Explorer anExp;
879 Standard_Integer nbf1 = 0;
880 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
883 Standard_Integer nbf2 = 0;
884 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
888 CreateFewSolids = true;
892 // check orientation of sections
893 bool NeedReverse = false;
896 anExp.Init( aShBase1, TopAbs_FACE );
897 TopoDS_Shape aFace = anExp.Current();
898 TColgp_SequenceOfPnt aPnts;
899 double xc=0, yc=0, zc=0;
900 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
901 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
902 aPnts.Append(BRep_Tool::Pnt(V));
903 xc += aPnts.Last().X();
904 yc += aPnts.Last().Y();
905 zc += aPnts.Last().Z();
907 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
908 gp_Vec V1(PC,aPnts.Value(1));
909 gp_Vec V2(PC,aPnts.Value(2));
910 gp_Vec VN = V1.Crossed(V2);
911 for(int ip=2; ip<aPnts.Length(); ip++) {
912 V1 = gp_Vec(PC,aPnts.Value(ip));
913 V2 = gp_Vec(PC,aPnts.Value(ip+1));
914 VN.Add(V1.Crossed(V2));
917 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
919 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
920 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
921 double tol = BRep_Tool::Tolerance(edge);
922 TopoDS_Vertex VF = sae.FirstVertex(edge);
923 gp_Pnt PF = BRep_Tool::Pnt(VF);
924 if( PF.Distance(PLoc) < tol ) {
926 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
929 if( P1.Distance(PLoc) < tol ) {
930 C->D0(fp+(lp-fp)/100,P2);
934 C->D0(lp+(fp-lp)/100,P2);
936 PathNorm = gp_Vec(P1,P2);
940 TopoDS_Vertex VL = sae.LastVertex(edge);
941 gp_Pnt PL = BRep_Tool::Pnt(VL);
942 if( PL.Distance(PLoc) < tol ) {
944 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
947 if( P1.Distance(PLoc) < tol ) {
948 C->D0(fp+(lp-fp)/100,P2);
952 C->D0(lp+(fp-lp)/100,P2);
954 PathNorm = gp_Vec(P2,P1);
959 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
960 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
961 if(fabs(VN.Angle(PathNorm))>PI/2.) {
968 anExp.Init( aShBase2, TopAbs_FACE );
969 TopoDS_Shape aFace = anExp.Current();
970 TColgp_SequenceOfPnt aPnts;
971 double xc=0, yc=0, zc=0;
972 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
973 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
974 aPnts.Append(BRep_Tool::Pnt(V));
975 xc += aPnts.Last().X();
976 yc += aPnts.Last().Y();
977 zc += aPnts.Last().Z();
979 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
980 gp_Vec V1(PC,aPnts.Value(1));
981 gp_Vec V2(PC,aPnts.Value(2));
982 gp_Vec VN = V1.Crossed(V2);
983 for(int ip=2; ip<aPnts.Length(); ip++) {
984 V1 = gp_Vec(PC,aPnts.Value(ip));
985 V2 = gp_Vec(PC,aPnts.Value(ip+1));
986 VN.Add(V1.Crossed(V2));
989 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
991 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
992 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
993 double tol = BRep_Tool::Tolerance(edge);
994 TopoDS_Vertex VF = sae.FirstVertex(edge);
995 gp_Pnt PF = BRep_Tool::Pnt(VF);
996 if( PF.Distance(PLoc) < tol ) {
998 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1001 if( P1.Distance(PLoc) < tol ) {
1002 C->D0(fp+(lp-fp)/100,P2);
1006 C->D0(lp+(fp-lp)/100,P2);
1008 PathNorm = gp_Vec(P2,P1);
1012 TopoDS_Vertex VL = sae.LastVertex(edge);
1013 gp_Pnt PL = BRep_Tool::Pnt(VL);
1014 if( PL.Distance(PLoc) < tol ) {
1016 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1019 if( P1.Distance(PLoc) < tol ) {
1020 C->D0(fp+(lp-fp)/100,P2);
1024 C->D0(lp+(fp-lp)/100,P2);
1026 PathNorm = gp_Vec(P2,P1);
1031 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1032 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1033 if(fabs(VN.Angle(PathNorm))>PI/2.)
1038 if(!CreateFewSolids) {
1039 // we can create only one solid
1040 TopoDS_Shape aWire1, aWire2;
1042 if(aType1==TopAbs_SHELL) {
1043 // create wire as boundary contour if shell is no closed
1044 // get free boundary shapes
1045 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
1046 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1047 //TopExp_Explorer anExp;
1048 Standard_Integer NbWires = 0;
1049 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1051 aWire1 = anExp.Current();
1056 Standard_ConstructionError::Raise("Bad shell is used as section ");
1059 else { // aType1==TopAbs_FACE
1060 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1061 aWire1 = aExpW.Current();
1064 if(aType2==TopAbs_SHELL) {
1065 // create wire as boundary contour if shell is no closed
1066 // get free boundary shapes
1067 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
1068 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1069 //TopExp_Explorer anExp;
1070 Standard_Integer NbWires = 0;
1071 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1073 aWire2 = anExp.Current();
1078 Standard_ConstructionError::Raise("Bad shell is used as section ");
1081 else { // aType2==TopAbs_FACE
1082 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1083 aWire2 = aExpW.Current();
1085 // make pipe using aWire1 and aWire2
1086 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1087 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1088 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1089 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1090 aWithContact, aWithCorrect);
1091 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1092 aWithContact, aWithCorrect);
1093 if(!aBuilder.IsReady()) {
1095 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1098 TopoDS_Shape aShape = aBuilder.Shape();
1099 TopoDS_Shell aShell;
1100 B.MakeShell(aShell);
1101 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1102 B.Add(aShell,anExp.Current());
1104 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1105 B.Add(aShell,anExp.Current());
1107 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1108 B.Add(aShell,anExp.Current());
1110 // make sewing for this shell
1111 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1112 aSewing->SetTolerance(Precision::Confusion());
1113 aSewing->SetFaceMode(Standard_True);
1114 aSewing->SetFloatingEdgesMode(Standard_False);
1115 aSewing->SetNonManifoldMode(Standard_False);
1116 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1117 aSewing->Add(anExp.Current());
1120 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1121 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1122 aShell = TopoDS::Shell(aSewShape);
1123 GProp_GProps aSystem;
1124 BRepGProp::VolumeProperties(aShell, aSystem);
1125 if(aSystem.Mass()<0) {
1128 if(BRep_Tool::IsClosed(aShell)) {
1129 TopoDS_Solid aSolid;
1130 B.MakeSolid(aSolid);
1131 B.Add(aSolid,aShell);
1132 B.Add(aComp,aSolid);
1135 B.Add(aComp,aShell);
1139 B.Add(aComp,aShell);
1144 // main block - creation few solids (for each pair of faces)
1145 TopTools_MapOfShape aFaces1,aFaces2;
1146 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1147 aFaces1.Add(anExp.Current());
1149 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1150 aFaces2.Add(anExp.Current());
1152 // creating map of edge faces
1153 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1154 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1155 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1156 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1158 // constuct map face->face
1159 TopTools_IndexedDataMapOfShapeShape FF;
1160 TopoDS_Shape FS1,FS2;
1162 // find edge the most distant from location point
1163 // (this edge is not shared by two faces)
1164 double maxdist = 0.;
1166 TopoDS_Vertex V11,V21;
1167 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1168 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1169 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1170 if(aList.Extent()>1)
1172 TopExp_Explorer expv;
1173 expv.Init( tmp, TopAbs_VERTEX );
1174 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1176 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1177 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1178 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1179 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1184 TopTools_ListIteratorOfListOfShape anIter(aList);
1185 FS1 = anIter.Value();
1189 // main direction for comparing
1190 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1191 // find corresponding edge from next section
1193 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1194 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1196 TopoDS_Vertex V12,V22;
1197 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1198 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1199 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1200 if(aList.Extent()>1)
1202 TopExp_Explorer expv;
1203 expv.Init( tmp, TopAbs_VERTEX );
1204 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1206 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1207 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1208 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1209 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1210 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1211 TopoDS_Vertex V1,V2;
1214 V1 = V2tmp; P1 = P2tmp;
1215 V2 = V1tmp; P2 = P1tmp;
1218 V1 = V1tmp; P1 = P1tmp;
1219 V2 = V2tmp; P2 = P2tmp;
1221 gp_Vec Vec1(P11,P1);
1222 gp_Vec Vec2(P21,P2);
1223 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1228 TopTools_ListIteratorOfListOfShape anIter(aList);
1229 FS2 = anIter.Value();
1233 // put all pairs to map FF
1239 // add pairs of edges to FF
1240 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1243 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1249 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1250 if(anItem.IsNull()) {
1252 Standard_ConstructionError::Raise("Invalid subbase shape");
1254 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1255 if(aRefBase.IsNull()) {
1257 Standard_ConstructionError::Raise("Invalid subbase shape");
1259 TopoDS_Shape aSh = aRefBase->GetValue();
1262 Standard_ConstructionError::Raise("Invalid subbase shape");
1264 if(aSh.ShapeType()!=TopAbs_FACE) {
1266 Standard_ConstructionError::Raise("Invalid subbase shape");
1271 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1272 if(anItem.IsNull()) {
1274 Standard_ConstructionError::Raise("Invalid subbase shape");
1276 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1277 if(aRefBase.IsNull()) {
1279 Standard_ConstructionError::Raise("Invalid subbase shape");
1281 TopoDS_Shape aSh = aRefBase->GetValue();
1284 Standard_ConstructionError::Raise("Invalid subbase shape");
1286 if(aSh.ShapeType()!=TopAbs_FACE) {
1288 Standard_ConstructionError::Raise("Invalid subbase shape");
1293 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
1295 Standard_ConstructionError::Raise("Invalid subbase shape");
1300 // add pairs of edges to FF
1301 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1302 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1305 Standard_ConstructionError::Raise("Can not create correct pipe");
1309 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1312 // make pipe for each pair of faces
1313 for(j=1; j<=FF.Extent(); j++) {
1314 TopoDS_Shape F1 = FF.FindKey(j);
1315 if( F1.ShapeType() != TopAbs_FACE )
1317 TopoDS_Shape F2 = FF.FindFromIndex(j);
1318 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1319 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1320 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1321 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1322 // make pipe using aWire1 and aWire2
1323 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1324 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1325 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1326 aWithContact, aWithCorrect);
1327 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1328 aWithContact, aWithCorrect);
1329 if(!aBuilder.IsReady()) {
1331 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1334 TopoDS_Shape aShape = aBuilder.Shape();
1335 TopoDS_Shell aShell;
1336 B.MakeShell(aShell);
1337 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1338 B.Add(aShell,anExp.Current());
1343 // make sewing for this shell
1344 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1345 aSewing->SetTolerance(Precision::Confusion());
1346 aSewing->SetFaceMode(Standard_True);
1347 aSewing->SetFloatingEdgesMode(Standard_False);
1348 aSewing->SetNonManifoldMode(Standard_False);
1349 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1350 aSewing->Add(anExp.Current());
1353 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1354 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1355 aShell = TopoDS::Shell(aSewShape);
1356 GProp_GProps aSystem;
1357 BRepGProp::VolumeProperties(aShell, aSystem);
1358 if(aSystem.Mass()<0) {
1359 //cout<<"aSewShape is reversed"<<endl;
1362 if(BRep_Tool::IsClosed(aShell)) {
1363 TopoDS_Solid aSolid;
1364 B.MakeSolid(aSolid);
1365 B.Add(aSolid,aShell);
1366 B.Add(aComp,aSolid);
1369 B.Add(aComp,aShell);
1373 B.Add(aComp,aShell);
1381 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1386 //=======================================================================
1387 //function : CreatePipeShellsWithoutPath
1388 //purpose : auxilary for Execute()
1389 //=======================================================================
1390 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1392 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1396 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1398 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1399 // vertex for recognition
1400 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1402 Standard_Integer nbBases = aBasesObjs->Length(),
1403 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1405 if( nbv != nbBases ) {
1407 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1411 TopTools_SequenceOfShape SecVs,Bases;
1412 for(i=1; i<=nbBases; i++) {
1414 Handle(Standard_Transient) anItem = VObjs->Value(i);
1417 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1418 TopoDS_Shape V = aRef->GetValue();
1419 if(V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1423 anItem = aBasesObjs->Value(i);
1426 aRef = Handle(GEOM_Function)::DownCast(anItem);
1427 TopoDS_Shape aSh = aRef->GetValue();
1432 nbv = SecVs.Length();
1433 nbBases = Bases.Length();
1434 if( nbv != nbBases ) {
1436 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1439 TopoDS_Compound aComp;
1440 B.MakeCompound(aComp);
1442 for(i=1 ; i<nbBases; i++) {
1443 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1444 TopoDS_Shape aShBase1 = Bases.Value(i);
1445 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1446 TopExp_Explorer anExp;
1447 Standard_Integer nbf1 = 0;
1448 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1451 Standard_Integer nbf2 = 0;
1452 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1455 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1458 Standard_ConstructionError::Raise("Different number of faces in the sections");
1461 TopTools_MapOfShape aFaces1,aFaces2;
1462 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1463 aFaces1.Add(anExp.Current());
1465 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1466 aFaces2.Add(anExp.Current());
1469 // creating map of edge faces
1470 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1471 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1472 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1473 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1475 // constuct map face->face (and subshapes)
1476 TopTools_IndexedDataMapOfShapeShape FF;
1477 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1478 TopoDS_Shape FS1, FS2;
1479 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1480 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1481 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1484 MESSAGE (" first pair of corresponding faces is found");
1486 // add pairs of edges and vertexes to FF
1487 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1490 Standard_ConstructionError::Raise("Can not create correct pipe");
1492 MESSAGE (" correspondences for subshapes of first pair of faces is found");
1494 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1495 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1497 // make pipe for each pair of faces
1498 // auxilary map vertex->edge for created pipe edges
1499 TopTools_IndexedDataMapOfShapeShape VPE;
1500 ShapeAnalysis_Edge sae;
1501 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1503 for(j=1; j<=FF.Extent(); j++) {
1504 TopoDS_Shape F1 = FF.FindKey(j);
1505 if( F1.ShapeType() != TopAbs_FACE )
1507 TopoDS_Shape F2 = FF.FindFromIndex(j);
1510 //if(nbff!=3) continue;
1512 MESSAGE (" make pipe for "<<nbff<<" face");
1514 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1515 if(S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1516 Handle(Geom_RectangularTrimmedSurface) RTS =
1517 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1518 S1 = RTS->BasisSurface();
1520 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1521 if( Pln1.IsNull() ) {
1523 Standard_ConstructionError::Raise("Surface from face is not plane");
1525 gp_Vec aDir1(Pln1->Axis().Direction());
1527 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1528 if(S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1529 Handle(Geom_RectangularTrimmedSurface) RTS =
1530 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1531 S2 = RTS->BasisSurface();
1533 Handle(Geom_Plane) Pln2 =
1534 Handle(Geom_Plane)::DownCast(S2);
1535 if( Pln2.IsNull() ) {
1537 Standard_ConstructionError::Raise("Surface from face is not plane");
1539 gp_Vec aDir2(Pln2->Axis().Direction());
1541 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1542 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1544 if(fabs(aDir.Angle(aDir1))>PI/2.)
1546 if(fabs(aDir.Angle(aDir2))>PI/2.)
1549 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1550 TopTools_SequenceOfShape aNewFs;
1552 for(; anExpE.More(); anExpE.Next()) {
1553 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1555 if(!FF.Contains(E1))
1556 MESSAGE ("map FF not contains key E1");
1558 if(VPE.Contains(E1)) {
1559 aNewFs.Append(VPE.FindFromKey(E1));
1561 MESSAGE (" using existed face");
1566 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1567 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1568 TopoDS_Vertex V2 = sae.LastVertex(E1);
1569 if(!FF.Contains(V1))
1570 MESSAGE ("map FF not contains key V1");
1571 if(!FF.Contains(V2))
1572 MESSAGE ("map FF not contains key V2");
1573 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1574 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1575 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1578 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1579 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1580 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1581 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1584 Handle(Geom_BSplineCurve) C2;
1585 if(VPE.Contains(V2)) {
1586 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1588 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1591 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1592 HAP->SetValue(1,P2);
1593 HAP->SetValue(2,P3);
1594 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1595 anInt.Load(aDir1,aDir2);
1598 B.MakeEdge(E2,C2,1.e-7);
1599 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1600 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1605 Handle(Geom_BSplineCurve) C4;
1606 if(VPE.Contains(V1)) {
1607 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1609 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1612 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1613 HAP->SetValue(1,P1);
1614 HAP->SetValue(2,P4);
1615 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1616 anInt.Load(aDir1,aDir2);
1619 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1620 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1621 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1630 B.Add(W,E4.Reversed());
1631 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1632 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1637 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1638 //bool IsConicC1 = false;
1639 //if( C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1640 // IsConicC1 = true;
1641 // cout<<"C1 - Geom_Conic"<<endl;
1643 if( C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1644 C1 = new Geom_TrimmedCurve(C1,fp,lp);
1647 // double tol = BRep_Tool::Tolerance(E1);
1648 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
1649 // C1 = ApxC1.Curve();
1651 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
1652 if( C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1653 C3 = new Geom_TrimmedCurve(C3,fp,lp);
1658 Handle(Geom_BSplineCurve) CE1 =
1659 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
1661 CE1->IncreaseDegree(3);
1662 Handle(Geom_BSplineCurve) CE2 =
1663 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
1665 CE2->IncreaseDegree(3);
1666 Handle(Geom_BSplineCurve) CE3 =
1667 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
1669 CE3->IncreaseDegree(3);
1670 Handle(Geom_BSplineCurve) CE4 =
1671 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
1673 CE4->IncreaseDegree(3);
1674 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
1675 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
1676 //if(fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
1677 // os<<"DrawTrSurf_BSplineCurve"<<endl;
1678 // GeomTools::Write(CE1,os);
1682 Handle(Geom_Surface) BS;
1684 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
1685 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
1689 MESSAGE (" can not create BSplineSurface - create Bezier");
1691 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
1692 double fp1,lp1,fp2,lp2;
1693 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
1694 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
1703 // get points from C1
1704 if(P1.Distance(P1C1)<1.e-6) {
1712 double step = (lp-fp)/(NbP-1);
1713 Points.SetValue(1,1,P1);
1715 for(n1=2; n1<NbP; n1++) {
1719 Points.SetValue(1,n1,P);
1721 Points.SetValue(1,NbP,P2);
1722 // get points from C3
1723 if(P4.Distance(P1C3)<1.e-6) {
1731 step = (lp-fp)/(NbP-1);
1732 Points.SetValue(NbP,1,P4);
1734 for(n1=2; n1<NbP; n1++) {
1738 Points.SetValue(NbP,n1,P);
1740 Points.SetValue(NbP,NbP,P3);
1741 // create isolines and get points from them
1742 for(n1=1; n1<=NbP; n1++) {
1743 gp_Pnt PI1 = Points.Value(1,n1);
1744 gp_Pnt PI2 = Points.Value(NbP,n1);
1745 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1746 HAP->SetValue(1,PI1);
1747 HAP->SetValue(2,PI2);
1748 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1749 anInt.Load(aDir1,aDir2);
1751 Handle(Geom_Curve) iso = anInt.Curve();
1752 fp = iso->FirstParameter();
1753 lp = iso->LastParameter();
1754 step = (lp-fp)/(NbP-1);
1756 TopoDS_Compound VComp;
1757 B.MakeCompound(VComp);
1758 for(n2=2; n2<NbP; n2++) {
1762 Points.SetValue(n2,n1,P);
1765 // create surface and face
1766 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
1767 BS = new Geom_BezierSurface(Points);
1770 BRepBuilderAPI_MakeFace BB(BS,W);
1771 TopoDS_Face NewF = BB.Face();
1772 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
1774 sff->FixOrientation();
1775 TopoDS_Face FixedFace = sff->Face();
1776 aNewFs.Append(FixedFace);
1777 VPE.Add(E1,FixedFace);
1778 //cout<<" face for edge "<<nbee<<" is created"<<endl;
1779 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
1782 TopoDS_Shell aShell;
1783 B.MakeShell(aShell);
1784 for(int nf=1; nf<=aNewFs.Length(); nf++) {
1785 B.Add(aShell,aNewFs(nf));
1790 // make sewing for this shell
1791 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1792 aSewing->SetTolerance(Precision::Confusion());
1793 aSewing->SetFaceMode(Standard_True);
1794 aSewing->SetFloatingEdgesMode(Standard_False);
1795 aSewing->SetNonManifoldMode(Standard_False);
1796 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1797 aSewing->Add(anExp.Current());
1800 MESSAGE (" shell for face "<<nbff<<" is created");
1801 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1802 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
1803 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1804 aShell = TopoDS::Shell(aSewShape);
1805 GProp_GProps aSystem;
1806 BRepGProp::VolumeProperties(aShell, aSystem);
1807 if(aSystem.Mass()<0) {
1808 //cout<<"aSewShape is reversed"<<endl;
1811 if(BRep_Tool::IsClosed(aShell)) {
1812 TopoDS_Solid aSolid;
1813 B.MakeSolid(aSolid);
1814 B.Add(aSolid,aShell);
1815 B.Add(aComp,aSolid);
1816 MESSAGE (" solid for face "<<nbff<<" is created");
1819 B.Add(aComp,aShell);
1820 MESSAGE (" solid for face "<<nbff<<" is not created");
1824 B.Add(aComp,aShell);
1825 MESSAGE (" solid for face "<<nbff<<" is not created");
1827 //cout<<" solid for face "<<nbff<<" is created"<<endl;
1829 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
1831 //TopoDS_Shell FixedShell = sfs->Shell();
1833 GProp_GProps aSystem;
1834 BRepGProp::VolumeProperties(FixedShell, aSystem);
1835 if(aSystem.Mass()<0) {
1836 //cout<<"aSewShape is reversed"<<endl;
1837 FixedShell.Reverse();
1839 if(BRep_Tool::IsClosed(FixedShell)) {
1840 TopoDS_Solid aSolid;
1841 B.MakeSolid(aSolid);
1842 B.Add(aSolid,aShell);
1843 B.Add(aComp,aSolid);
1846 B.Add(aComp,FixedShell);
1852 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1857 //=======================================================================
1858 //function : CreatePipeBiNormalAlongVector
1859 //purpose : auxilary for Execute()
1860 //=======================================================================
1861 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
1862 GEOMImpl_IPipe* aCI)
1864 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
1866 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
1867 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
1868 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1869 TopoDS_Shape aShapeVec = aRefVec->GetValue();
1871 if (aShapeBase.IsNull()) {
1872 if(aCIBN) delete aCIBN;
1873 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1877 if( aShapeBase.ShapeType() == TopAbs_EDGE) {
1878 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
1880 else if( aShapeBase.ShapeType() == TopAbs_WIRE) {
1883 else if( aShapeBase.ShapeType() == TopAbs_FACE) {
1884 TopExp_Explorer wexp(aShapeBase,TopAbs_WIRE);
1885 aProf = wexp.Current();
1888 Standard_TypeMismatch::Raise
1889 ("MakePipe aborted : invalid type of base");
1891 BRepOffsetAPI_MakePipeShell PipeBuilder(aWirePath);
1892 PipeBuilder.Add(aProf);
1894 if (aShapeVec.IsNull()) {
1895 if(aCIBN) delete aCIBN;
1896 Standard_NullObject::Raise
1897 ("MakePipe aborted : null vector argument");
1899 if (aShapeVec.ShapeType() != TopAbs_EDGE)
1900 Standard_TypeMismatch::Raise
1901 ("MakePipe aborted: invalid type of vector");
1902 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
1903 TopoDS_Vertex V1, V2;
1904 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1905 if (V1.IsNull() || V2.IsNull())
1906 Standard_NullObject::Raise
1907 ("MakePipe aborted: vector is not defined");
1908 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
1909 gp_Dir BiNormal(aVec);
1910 PipeBuilder.SetMode(BiNormal);
1911 PipeBuilder.Build();
1912 if( aShapeBase.ShapeType() == TopAbs_FACE) {
1913 PipeBuilder.MakeSolid();
1916 return PipeBuilder.Shape();
1920 //=======================================================================
1921 //function : Execute
1923 //=======================================================================
1924 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1926 //cout<<"PipeDriver::Execute"<<endl;
1927 if (Label().IsNull()) return 0;
1928 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1929 GEOMImpl_IPipe* aCI= 0;
1930 Standard_Integer aType = aFunction->GetType();
1931 if(aType == PIPE_BASE_PATH)
1932 aCI = new GEOMImpl_IPipe(aFunction);
1933 else if(aType == PIPE_DIFFERENT_SECTIONS)
1934 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1935 else if(aType == PIPE_SHELL_SECTIONS)
1936 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1937 else if(aType == PIPE_SHELLS_WITHOUT_PATH)
1938 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1939 else if(aType == PIPE_BI_NORMAL_ALONG_VECTOR)
1940 aCI = new GEOMImpl_IPipeBiNormal(aFunction);
1944 TopoDS_Wire aWirePath;
1945 if(aType != PIPE_SHELLS_WITHOUT_PATH) {
1946 // working with path
1947 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1948 TopoDS_Shape aShapePath = aRefPath->GetValue();
1950 if (aShapePath.IsNull()) {
1951 MESSAGE ("Driver : path is null");
1953 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1957 if (aShapePath.ShapeType() == TopAbs_WIRE) {
1958 aWirePath = TopoDS::Wire(aShapePath);
1961 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1962 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1963 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1967 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1972 TopoDS_Shape aShape;
1974 if (aType == PIPE_BASE_PATH)
1976 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1977 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1979 if (aShapeBase.IsNull()) {
1981 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1985 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
1988 //building pipe with different sections
1989 else if (aType == PIPE_DIFFERENT_SECTIONS) {
1990 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
1991 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
1992 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1993 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
1994 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
1995 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
1996 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1998 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
1999 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
2001 if(nbLocs && nbLocs != nbBases) {
2003 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
2005 TopTools_SequenceOfShape aSeqBases;
2006 TopTools_SequenceOfShape aSeqLocs;
2007 TopTools_SequenceOfShape aSeqFaces;
2008 for( ; i <= nbBases; i++) {
2009 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2012 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2013 if(aRefBase.IsNull())
2015 TopoDS_Shape aShapeBase = aRefBase->GetValue();
2016 if(aShapeBase.IsNull())
2018 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
2020 //if for section was specified face with a few wires then a few
2021 // pipes were build and make solid
2022 Standard_Boolean NeedCreateSolid = Standard_False;
2023 if(aTypeBase == TopAbs_SHELL) {
2024 // create wire as boundary contour if shell is no closed
2025 // get free boundary shapes
2026 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
2027 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
2028 TopExp_Explorer anExp;
2030 Standard_Integer NbWires = 0;
2031 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
2033 aWire = anExp.Current();
2038 Standard_ConstructionError::Raise("Bad shell is used as section ");
2040 NeedCreateSolid = Standard_True;
2041 aSeqFaces.Append(aShapeBase);
2042 aSeqBases.Append(aWire);
2044 else if(aTypeBase == TopAbs_FACE) {
2045 NeedCreateSolid = Standard_True;
2046 //for case one path should be used other type function
2047 aSeqFaces.Append(aShapeBase);
2048 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
2049 for( ; aExpW.More(); aExpW.Next())
2051 TopoDS_Shape aWireProf = aExpW.Current();
2052 aSeqBases.Append(aWireProf);
2055 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
2056 aSeqBases.Append(aShapeBase);
2058 else if(aTypeBase == TopAbs_EDGE) {
2059 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
2060 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
2061 aSeqBases.Append(aWireProf);
2064 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2065 if(anItemLoc.IsNull())
2067 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2068 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2069 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2071 aSeqLocs.Append(aShapeLoc);
2075 nbLocs = aSeqLocs.Length();
2078 TopTools_SequenceOfShape Edges;
2080 // we have to check that each location shape is a vertex from
2081 // path and update aSeqLocs if it is needed (and possible)
2082 TColgp_SequenceOfPnt PLocs;
2083 for(i=1; i<=nbLocs; i++) {
2084 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
2085 PLocs.Append(BRep_Tool::Pnt(V));
2087 //TopTools_SequenceOfShape Edges;
2088 TopExp_Explorer anExp;
2089 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
2090 Edges.Append(anExp.Current());
2092 int nbEdges = Edges.Length();
2093 ShapeAnalysis_Edge sae;
2094 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
2095 double tol = BRep_Tool::Tolerance(edge);
2096 TopoDS_Vertex VF = sae.FirstVertex(edge);
2097 gp_Pnt PF = BRep_Tool::Pnt(VF);
2098 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
2099 if( PF.Distance(PLocs.First()) > tol ) {
2101 Standard_ConstructionError::Raise
2102 ("First location shapes is not coincided with first vertex of aWirePath");
2104 aSeqLocs.ChangeValue(1) = VF;
2105 edge = TopoDS::Edge(Edges.Last());
2106 tol = BRep_Tool::Tolerance(edge);
2107 TopoDS_Vertex VL = sae.LastVertex(edge);
2108 gp_Pnt PL = BRep_Tool::Pnt(VL);
2109 if( PL.Distance(PLocs.Last()) > tol ) {
2111 Standard_ConstructionError::Raise
2112 ("Last location shapes is not coincided with last vertex of aWirePath");
2114 aSeqLocs.ChangeValue(nbLocs) = VL;
2116 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
2117 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
2118 tol = BRep_Tool::Tolerance(edge);
2119 TopoDS_Vertex V1 = sae.FirstVertex(E);
2120 TopoDS_Vertex V2 = sae.LastVertex(E);
2121 gp_Pnt P1 = BRep_Tool::Pnt(V1);
2122 gp_Pnt P2 = BRep_Tool::Pnt(V2);
2123 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
2124 aSeqLocs.ChangeValue(jcurr) = V2;
2128 // find distance between E and aLocs(jcurr)
2130 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
2131 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
2132 if( PPC.NbPoints()>0 &&
2133 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
2134 double param = PPC.Parameter(1);
2137 // split current edge
2138 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
2139 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
2144 if(Pfp.Distance(P1)<tol) {
2145 B.MakeEdge(E1,tc1,tol);
2147 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2148 B.Add(E1,TopoDS::Vertex(tmpV));
2149 B.MakeEdge(E2,tc2,tol);
2150 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2151 B.Add(E2,TopoDS::Vertex(tmpV));
2155 B.MakeEdge(E1,tc2,tol);
2156 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2157 B.Add(E1,TopoDS::Vertex(tmpV));
2160 B.MakeEdge(E2,tc1,tol);
2162 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2163 B.Add(E2,TopoDS::Vertex(tmpV));
2168 Edges.InsertAfter(i-1,E1);
2169 Edges.InsertAfter(i,E2);
2173 if(nbEdges<Edges.Length()) {
2174 // one of edges was splitted => we have to update WirePath
2178 for(i=1; i<=Edges.Length(); i++) {
2179 B.Add(W,TopoDS::Edge(Edges.Value(i)));
2185 // check curvature of wire for condition that
2186 // max summary angle between directions along
2187 // wire path must be < 4*PI. If not - split wire
2188 // and seguences of shapes, perform pipe for each
2189 // and make sewing after that
2191 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
2196 double SumAng = fabs(Vec1.Angle(Vec2));
2199 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
2201 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
2202 for(i=2; i<=Edges.Length(); i++) {
2203 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
2204 double tol = BRep_Tool::Tolerance(edge);
2205 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
2207 double ang = fabs(Vec1.Angle(Vec2));
2211 SplitEdgeNums.Append(i-1);
2213 for(j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
2214 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
2215 gp_Pnt P = BRep_Tool::Pnt(aVert);
2216 if( P1.Distance(P) < tol ) {
2217 SplitLocNums.Append(j);
2227 //cout<<"SplitEdgeNums.Length()="<<SplitEdgeNums.Length()<<endl;
2228 //cout<<"SplitLocNums.Length()="<<SplitLocNums.Length()<<endl;
2229 if( SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0 ) {
2230 TopTools_SequenceOfShape aSeqRes;
2231 int nn, num1 = 1, num2 = 1;
2232 for(nn=1; nn<=SplitEdgeNums.Length(); nn++) {
2233 // create wirepath and sequences of shapes
2237 for(i=num1; i<=SplitEdgeNums.Value(nn); i++) {
2238 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2240 num1 = SplitEdgeNums.Value(nn) + 1;
2241 TopTools_SequenceOfShape aTmpSeqBases;
2242 TopTools_SequenceOfShape aTmpSeqLocs;
2243 for(i=num2; i<=SplitLocNums.Value(nn); i++) {
2244 aTmpSeqBases.Append(aSeqBases.Value(i));
2245 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2247 num2 = SplitLocNums.Value(nn);
2249 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2250 Standard_Integer nbShapes = aTmpSeqBases.Length();
2251 for(i=1; i<=nbShapes; i++) {
2252 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2253 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2254 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2256 if(!aBuilder.IsReady()) {
2258 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2261 TopoDS_Shape resShape = aBuilder.Shape();
2262 aSeqRes.Append(resShape);
2264 // create wirepath and sequences of shapes for last part
2268 for(i=num1; i<=Edges.Length(); i++) {
2269 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2271 TopTools_SequenceOfShape aTmpSeqBases;
2272 TopTools_SequenceOfShape aTmpSeqLocs;
2273 for(i=num2; i<=aSeqLocs.Length(); i++) {
2274 aTmpSeqBases.Append(aSeqBases.Value(i));
2275 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2277 // make pipe for last part
2278 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2279 Standard_Integer nbShapes = aTmpSeqBases.Length();
2280 for(i=1; i<=nbShapes; i++) {
2281 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2282 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2283 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2285 if(!aBuilder.IsReady()) {
2287 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2290 TopoDS_Shape resShape = aBuilder.Shape();
2291 aSeqRes.Append(resShape);
2292 // make sewing for result
2293 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2294 aSewing->SetTolerance(Precision::Confusion());
2295 aSewing->SetFaceMode(Standard_True);
2296 aSewing->SetFloatingEdgesMode(Standard_False);
2297 aSewing->SetNonManifoldMode(Standard_False);
2298 for(i=1; i<=aSeqRes.Length(); i++) {
2299 aSewing->Add(aSeqRes.Value(i));
2302 aShape = aSewing->SewedShape();
2305 // old implementation without splitting
2306 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2308 Standard_Integer nbShapes = aSeqBases.Length();
2309 Standard_Integer step = nbShapes/nbBases;
2311 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
2313 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
2315 Standard_Integer ind =0;
2316 for( i=1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
2317 TopTools_SequenceOfShape usedBases;
2318 Standard_Integer j = 1;
2319 for( ; j <= nbBases ; j++) {
2320 ind = i + (j-1)*step;
2321 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
2322 usedBases.Append(aWireProf);
2324 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
2325 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2326 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
2329 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
2331 if(!aBuilder.IsReady()) {
2333 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2336 aShape = aBuilder.Shape();
2337 aSeqFaces.Append(aShape);
2338 for( j = 1; j <=usedBases.Length(); j++)
2339 aBuilder.Delete(usedBases.Value(j));
2342 //for case if section is face
2343 if(aSeqFaces.Length() >1) {
2345 TopoDS_Compound aComp;
2346 aB.MakeCompound(aComp);
2347 for( i = 1; i <= aSeqFaces.Length(); i++)
2348 aB.Add(aComp,aSeqFaces.Value(i));
2354 //building pipe with shell sections
2355 else if (aType == PIPE_SHELL_SECTIONS) {
2356 aShape = CreatePipeForShellSections(aWirePath,aCI);
2359 //building pipe shell sections without path
2360 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2361 aShape = CreatePipeShellsWithoutPath(aCI);
2364 //building a pipe with constant bi-normal along given vector
2365 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2366 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2374 if (aShape.IsNull()) return 0;
2376 BRepCheck_Analyzer ana (aShape, Standard_False);
2377 if (!ana.IsValid()) {
2378 ShapeFix_ShapeTolerance aSFT;
2379 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2380 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2381 aSfs->SetPrecision(Precision::Confusion());
2383 aShape = aSfs->Shape();
2385 ana.Init(aShape, Standard_False);
2387 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2390 // Glue (for bug 0020207)
2391 TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
2393 aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
2395 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
2396 aFunction->SetValue(aRes);
2398 log.SetTouched(Label());
2403 //=======================================================================
2404 //function : GEOMImpl_PipeDriver_Type_
2406 //=======================================================================
2407 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2410 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2411 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2412 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2413 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2414 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2415 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2418 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2419 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2420 sizeof(GEOMImpl_PipeDriver),
2422 (Standard_Address)_Ancestors,
2423 (Standard_Address)NULL);
2428 //=======================================================================
2429 //function : DownCast
2431 //=======================================================================
2432 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2434 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2436 if (!AnObject.IsNull()) {
2437 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2438 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2442 return _anOtherObject ;