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_Types.hxx>
32 #include <GEOM_Function.hxx>
34 #include <GEOMAlgo_GlueAnalyser.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_MakeWire.hxx>
46 #include <BRepBuilderAPI_Sewing.hxx>
47 #include <BRepCheck_Analyzer.hxx>
48 #include <BRepOffsetAPI_MakePipe.hxx>
49 #include <BRepOffsetAPI_MakePipeShell.hxx>
50 #include <GProp_GProps.hxx>
51 #include <BRepGProp.hxx>
52 #include <BRepBuilderAPI_MakeFace.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_IndexedDataMapOfShapeShape.hxx>
67 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
68 #include <TopTools_ListIteratorOfListOfShape.hxx>
70 #include <GeomAPI_ProjectPointOnCurve.hxx>
71 #include <GeomAPI_Interpolate.hxx>
72 #include <Geom_TrimmedCurve.hxx>
73 #include <Geom_Plane.hxx>
74 #include <Geom_RectangularTrimmedSurface.hxx>
75 #include <Geom_BezierSurface.hxx>
76 #include <Geom_Line.hxx>
77 #include <Geom_Conic.hxx>
78 #include <Geom_BSplineCurve.hxx>
79 #include <Geom_BSplineSurface.hxx>
80 #include <GeomFill_BSplineCurves.hxx>
81 #include <GeomConvert_ApproxCurve.hxx>
82 #include <GeomConvert.hxx>
84 #include <TColgp_SequenceOfPnt.hxx>
85 #include <TColgp_HArray1OfPnt.hxx>
86 #include <TColgp_Array2OfPnt.hxx>
87 #include <TColStd_HSequenceOfTransient.hxx>
89 #include <Precision.hxx>
90 #include <Standard_NullObject.hxx>
91 #include <Standard_TypeMismatch.hxx>
92 #include <Standard_ConstructionError.hxx>
94 #include "utilities.h"
97 //=======================================================================
100 //=======================================================================
101 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
103 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
108 //=======================================================================
109 //function : GEOMImpl_PipeDriver
111 //=======================================================================
112 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
117 //=======================================================================
118 //function : FillForOtherEdges
119 //purpose : auxilary for CreatePipeForShellSections()
120 //=======================================================================
121 static bool FillForOtherEdges(const TopoDS_Shape& F1,
122 const TopoDS_Shape& E1,
123 const TopoDS_Shape& V1,
124 TopTools_IndexedDataMapOfShapeShape& FF)
126 //cout<<"FillForOtherEdges"<<endl;
127 // find other pairs for vertexes and edges
128 // creating map of vertex edges for both faces
129 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
130 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
131 if (!FF.Contains(F1))
132 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
133 if (!FF.Contains(E1))
134 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
135 if (!FF.Contains(V1))
136 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
137 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
138 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
139 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
140 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
141 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
143 TopoDS_Edge ES1 = TopoDS::Edge(E1);
144 TopoDS_Edge ES2 = TopoDS::Edge(E2);
145 TopoDS_Shape VS1 = V1;
146 TopoDS_Shape VS2 = V2;
148 ShapeAnalysis_Edge sae;
150 if(!aMapVertEdge1.Contains(VS1))
151 MESSAGE (" FillForOtherEdges: map aMapVertEdge1 not contains key VS1");
152 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
153 //TopoDS_Shape E1next;
154 TopTools_ListIteratorOfListOfShape anIter1(aList1);
155 if(anIter1.Value().IsSame(ES1)) {
158 //E1next = anIter1.Value();
159 if(!aMapVertEdge2.Contains(VS2))
160 MESSAGE (" FillForOtherEdges: map aMapVertEdge2 not contains key VS2");
161 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
162 //TopoDS_Shape E2next;
163 TopTools_ListIteratorOfListOfShape anIter2(aList2);
164 if(anIter2.Value().IsSame(ES2)) {
167 //E2next = anIter2.Value();
168 //ES1 = TopoDS::Edge(E1next);
169 //ES2 = TopoDS::Edge(E2next);
170 ES1 = TopoDS::Edge(anIter1.Value());
171 ES2 = TopoDS::Edge(anIter2.Value());
172 if(!FF.Contains(ES1)) {
175 if(VS1.IsSame(sae.FirstVertex(ES1)))
176 VS1 = sae.LastVertex(ES1);
178 VS1 = sae.FirstVertex(ES1);
179 if(VS2.IsSame(sae.FirstVertex(ES2)))
180 VS2 = sae.LastVertex(ES2);
182 VS2 = sae.FirstVertex(ES2);
185 if(!FF.Contains(VS1)) {
194 //=======================================================================
195 //function : FillCorrespondingEdges
196 //purpose : auxilary for CreatePipeForShellSections()
197 //=======================================================================
198 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
199 const TopoDS_Shape& FS2,
200 const TopoDS_Vertex& aLoc1,
201 const TopoDS_Vertex& aLoc2,
202 const TopoDS_Wire& aWirePath,
203 TopTools_IndexedDataMapOfShapeShape& FF)
205 //cout<<"FillCorrespondingEdges"<<endl;
206 // find corresponding edges
207 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
208 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
209 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
210 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
211 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
212 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
213 aBuilder.Add(aWire1, aLoc1);
214 aBuilder.Add(aWire2, aLoc2);
215 if(!aBuilder.IsReady()) {
219 TopoDS_Shape aShape = aBuilder.Shape();
227 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
229 ShapeAnalysis_Edge sae;
230 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
231 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
232 TopTools_MapOfShape Vs1,Vs2;
234 exp.Init( FS1, TopAbs_EDGE );
235 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
236 TopoDS_Vertex V11 = sae.FirstVertex(E1);
237 TopoDS_Vertex V21 = sae.LastVertex(E1);
238 gp_Pnt P11 = BRep_Tool::Pnt(V11);
239 gp_Pnt P21 = BRep_Tool::Pnt(V21);
240 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
241 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
242 // find corresponding vertexes from created shape
243 TopoDS_Vertex VN11,VN21;
244 for( exp.Init( aShape, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
245 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
246 gp_Pnt P = BRep_Tool::Pnt(V);
247 if(P.Distance(P11)<tol) {
250 if(P.Distance(P21)<tol) {
254 // find edge contains VN11 and VN21 and corresponding vertexes
255 TopoDS_Vertex VN12,VN22;
256 for( exp.Init( aShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
257 TopoDS_Shape F = exp.Current();
258 TopExp_Explorer expe;
260 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
261 TopoDS_Edge E = TopoDS::Edge(expe.Current());
262 TopoDS_Vertex VF = sae.FirstVertex(E);
263 TopoDS_Vertex VL = sae.LastVertex(E);
264 if( (VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11)) ) {
270 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
271 TopoDS_Edge E = TopoDS::Edge(expe.Current());
272 TopoDS_Vertex VF = sae.FirstVertex(E);
273 TopoDS_Vertex VL = sae.LastVertex(E);
274 if( VF.IsSame(VN11) && !VL.IsSame(VN21) )
276 if( VL.IsSame(VN11) && !VF.IsSame(VN21) )
278 if( VF.IsSame(VN21) && !VL.IsSame(VN11) )
280 if( VL.IsSame(VN21) && !VF.IsSame(VN11) )
286 // find vertexes from FS2 corresponded to VN12 and VN22
287 // and find edge from FS2 contains V12 and V22,
288 // this edge will be corresponded to edge E1
289 TopoDS_Vertex V12,V22;
290 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
291 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
292 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
293 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
295 TopExp_Explorer expe;
296 for( expe.Init( FS2, TopAbs_EDGE ); expe.More(); expe.Next() ) {
297 TopoDS_Edge E = TopoDS::Edge(expe.Current());
298 TopoDS_Vertex VF = sae.FirstVertex(E);
299 TopoDS_Vertex VL = sae.LastVertex(E);
300 gp_Pnt PF = BRep_Tool::Pnt(VF);
301 gp_Pnt PL = BRep_Tool::Pnt(VL);
302 if( PF.Distance(PN12)<tol && PL.Distance(PN22)<tol ) {
308 if( PF.Distance(PN22)<tol && PL.Distance(PN12)<tol ) {
319 // find other pairs for vertexes and edges
320 // creating map of vertex edges for both faces
321 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);
430 //=======================================================================
431 //function : FindNextPairOfFaces
432 //purpose : auxilary for CreatePipeForShellSections()
433 //=======================================================================
434 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
435 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
436 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
437 TopTools_IndexedDataMapOfShapeShape& FF,
440 //cout<<"FindNextPairOfFaces"<<endl;
441 TopExp_Explorer anExp;
442 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
443 TopoDS_Shape E1 = anExp.Current();
444 if(!FF.Contains(E1)) {
446 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
449 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
450 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
451 TopExp_Explorer anExpV;
452 anExpV.Init( E1, TopAbs_VERTEX );
453 TopoDS_Shape V1 = anExpV.Current();
454 if(!FF.Contains(V1)) {
456 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
459 if(!aMapEdgeFaces1.Contains(E1))
460 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
461 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
462 if(aList1.Extent()<2)
464 TopTools_ListIteratorOfListOfShape anIter(aList1);
465 if(anIter.Value().IsEqual(aCurFace)) {
468 TopoDS_Shape F1other = anIter.Value();
469 if(FF.Contains(F1other))
472 if(!FF.Contains(aCurFace))
473 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
474 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
475 if(!aMapEdgeFaces2.Contains(E2))
476 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
477 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
478 if(aList2.Extent()<2) {
480 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
482 TopTools_ListIteratorOfListOfShape anIter2(aList2);
483 if(anIter2.Value().IsEqual(F2)) {
486 TopoDS_Shape F2other = anIter2.Value();
487 FF.Add(F1other,F2other);
489 // add pairs of edges to FF
490 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
493 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
496 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
501 //=======================================================================
502 //function : FindFirstPairFaces
503 //purpose : auxilary for Execute()
504 //=======================================================================
505 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
506 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
507 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
509 //cout<<"FindFirstPairFaces"<<endl;
511 // check if vertexes are subshapes of sections
512 gp_Pnt P1 = BRep_Tool::Pnt(V1);
513 gp_Pnt P2 = BRep_Tool::Pnt(V2);
514 TopoDS_Vertex V1new,V2new;
516 double mindist = 1.e10;
517 for( exp.Init( S1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
518 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
519 gp_Pnt P = BRep_Tool::Pnt(V);
520 double dist = P1.Distance(P);
527 for( exp.Init( S2, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
528 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
529 gp_Pnt P = BRep_Tool::Pnt(V);
530 double dist = P2.Distance(P);
537 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
538 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
539 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
540 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
541 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
542 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
544 // replace vertexes if it is needed
545 if(!V1.IsSame(V1new)) {
547 P1 = BRep_Tool::Pnt(V1);
548 MESSAGE (" replace V1");
551 MESSAGE (" not replace V1");
552 if(!V2.IsSame(V2new)) {
554 P2 = BRep_Tool::Pnt(V2);
555 MESSAGE (" replace V2");
558 MESSAGE (" not replace V2");
560 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
561 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
562 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
563 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
565 if(!aMapVertFaces1.Contains(V1))
566 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
567 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
568 TopTools_ListIteratorOfListOfShape anIter1(aList1);
569 FS1 = anIter1.Value();
571 double x1=0., y1=0., z1=0.;
573 for( exp.Init( FS1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
574 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
575 gp_Pnt P = BRep_Tool::Pnt(V);
581 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
583 TColgp_SequenceOfPnt Ps;
584 TopTools_SequenceOfShape Fs;
585 if(!aMapVertFaces2.Contains(V2))
586 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
587 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
588 TopTools_ListIteratorOfListOfShape anIter2(aList2);
589 for(; anIter2.More(); anIter2.Next()) {
590 TopoDS_Shape F = anIter2.Value();
591 double x2=0., y2=0., z2=0.;
593 for( exp.Init( F, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
594 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
595 gp_Pnt P = BRep_Tool::Pnt(V);
601 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
610 for(; i<=Fs.Length(); i++) {
611 gp_Vec tmpDir(PM1,Ps(i));
612 double ang = fabs(aDir.Angle(tmpDir));
622 //=======================================================================
623 //function : CreatePipeForShellSections
624 //purpose : auxilary for Execute()
625 //=======================================================================
626 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
629 //cout<<"CreatePipeForShellSections"<<endl;
634 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
635 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
636 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
637 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
638 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
639 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
641 Standard_Integer nbBases = aBasesObjs->Length(),
642 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
643 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
645 if( nbLocs != nbBases) {
647 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
649 if( nbSubBases && nbSubBases != nbBases) {
651 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
654 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
656 TopTools_SequenceOfShape VLocs;
657 for(i=1; i<=nbBases; i++) {
658 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
659 if(anItemLoc.IsNull())
661 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
662 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
663 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
665 VLocs.Append(aShapeLoc);
667 nbLocs = VLocs.Length();
668 if( nbLocs != nbBases) {
670 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
672 // split wire path by location points
673 TColgp_SequenceOfPnt PLocs;
674 for(i=1; i<=nbLocs; i++) {
675 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
676 PLocs.Append(BRep_Tool::Pnt(V));
679 TopTools_SequenceOfShape Edges;
680 TopTools_SequenceOfShape Wires;
681 ShapeAnalysis_Edge sae;
684 TopExp_Explorer anExp;
685 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
686 Edges.Append(anExp.Current());
688 Standard_Integer Num1 = 0;
689 Standard_Integer Num2 = 0;
690 for(i=1; i<=Edges.Length(); i++) {
691 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
692 double tol = BRep_Tool::Tolerance(E);
693 TopoDS_Vertex V1 = sae.FirstVertex(E);
694 TopoDS_Vertex V2 = sae.LastVertex(E);
695 gp_Pnt P1 = BRep_Tool::Pnt(V1);
696 gp_Pnt P2 = BRep_Tool::Pnt(V2);
697 if( P1.Distance(PLocs.First()) < tol ) {
700 if( P2.Distance(PLocs.Last()) < tol ) {
704 if( Num1>0 && Num2>0 ) {
707 for(i=Num1; i<=Num2; i++) {
708 B.Add(W,Edges.Value(i));
713 Wires.Append(aWirePath);
717 TopExp_Explorer anExp;
718 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
719 Edges.Append(anExp.Current());
721 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
722 double tol = BRep_Tool::Tolerance(edge);
723 TopoDS_Vertex VF = sae.FirstVertex(edge);
724 gp_Pnt PF = BRep_Tool::Pnt(VF);
725 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
726 if( PF.Distance(PLocs.First()) > tol ) {
728 Standard_ConstructionError::Raise
729 ("First location shapes is not coincided with first vertex of aWirePath");
731 VLocs.ChangeValue(1) = VF;
732 edge = TopoDS::Edge(Edges.Last());
733 tol = BRep_Tool::Tolerance(edge);
734 TopoDS_Vertex VL = sae.LastVertex(edge);
735 gp_Pnt PL = BRep_Tool::Pnt(VL);
736 if( PL.Distance(PLocs.Last()) > tol ) {
738 Standard_ConstructionError::Raise
739 ("Last location shapes is not coincided with last vertex of aWirePath");
741 VLocs.ChangeValue(nbLocs) = VL;
743 TopTools_SequenceOfShape tmpEdges;
744 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
745 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
746 tol = BRep_Tool::Tolerance(E);
747 TopoDS_Vertex V1 = sae.FirstVertex(E);
748 TopoDS_Vertex V2 = sae.LastVertex(E);
749 gp_Pnt P1 = BRep_Tool::Pnt(V1);
750 gp_Pnt P2 = BRep_Tool::Pnt(V2);
751 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
752 // make wire from current edge and add created
756 for(j=1; j<=tmpEdges.Length(); j++)
757 B.Add(W,tmpEdges.Value(j));
760 VLocs.ChangeValue(jcurr) = V2;
765 // find distance between E and aLocs(jcurr)
767 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
768 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
769 if( PPC.NbPoints()>0 &&
770 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
771 double param = PPC.Parameter(1);
774 // split current edge
775 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
776 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
780 if(Pfp.Distance(P1)<tol) {
781 B.MakeEdge(E1,tc1,tol);
783 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
784 B.Add(E1,TopoDS::Vertex(tmpV));
786 B.MakeEdge(E2,tc2,tol);
787 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
788 B.Add(E2,TopoDS::Vertex(tmpV));
792 B.MakeEdge(E1,tc2,tol);
793 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
794 B.Add(E1,TopoDS::Vertex(tmpV));
798 B.MakeEdge(E2,tc1,tol);
800 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
801 B.Add(E2,TopoDS::Vertex(tmpV));
804 // create wire from tmpEdges
807 for(j=1; j<=tmpEdges.Length(); j++)
808 B.Add(W,tmpEdges.Value(j));
813 Edges.InsertAfter(i-1,E1);
814 Edges.InsertAfter(i,E2);
821 // create wire from other edges
824 for(; i<=Edges.Length(); i++)
825 B.Add(W,Edges.Value(i));
827 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
830 if( Wires.Length() != nbLocs-1 ) {
832 Standard_ConstructionError::Raise
833 ("One of location shapes is not lied on the path");
836 //TopTools_SequenceOfShape aSeqBases;
837 //TopTools_SequenceOfShape aSeqSubBases;
838 //TopTools_SequenceOfShape aSeqFaces;
839 TopoDS_Compound aComp;
840 B.MakeCompound(aComp);
841 for(i=1 ; i<nbBases; i++) {
842 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
844 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
847 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
848 if(aRefBase1.IsNull())
850 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
851 if(aShBase1.IsNull())
853 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
855 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
858 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
859 if(aRefBase2.IsNull())
861 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
862 if(aShBase2.IsNull())
864 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
866 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
868 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
869 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
872 Standard_ConstructionError::Raise("One of section shapes has invalid type");
875 bool CreateFewSolids = false;
877 TopExp_Explorer anExp;
878 Standard_Integer nbf1 = 0;
879 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
882 Standard_Integer nbf2 = 0;
883 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
887 CreateFewSolids = true;
891 // check orientation of sections
892 bool NeedReverse = false;
895 anExp.Init( aShBase1, TopAbs_FACE );
896 TopoDS_Shape aFace = anExp.Current();
897 TColgp_SequenceOfPnt aPnts;
898 double xc=0, yc=0, zc=0;
899 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
900 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
901 aPnts.Append(BRep_Tool::Pnt(V));
902 xc += aPnts.Last().X();
903 yc += aPnts.Last().Y();
904 zc += aPnts.Last().Z();
906 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
907 gp_Vec V1(PC,aPnts.Value(1));
908 gp_Vec V2(PC,aPnts.Value(2));
909 gp_Vec VN = V1.Crossed(V2);
910 for(int ip=2; ip<aPnts.Length(); ip++) {
911 V1 = gp_Vec(PC,aPnts.Value(ip));
912 V2 = gp_Vec(PC,aPnts.Value(ip+1));
913 VN.Add(V1.Crossed(V2));
916 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
918 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
919 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
920 double tol = BRep_Tool::Tolerance(edge);
921 TopoDS_Vertex VF = sae.FirstVertex(edge);
922 gp_Pnt PF = BRep_Tool::Pnt(VF);
923 if( PF.Distance(PLoc) < tol ) {
925 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
928 if( P1.Distance(PLoc) < tol ) {
929 C->D0(fp+(lp-fp)/100,P2);
933 C->D0(lp+(fp-lp)/100,P2);
935 PathNorm = gp_Vec(P1,P2);
939 TopoDS_Vertex VL = sae.LastVertex(edge);
940 gp_Pnt PL = BRep_Tool::Pnt(VL);
941 if( PL.Distance(PLoc) < tol ) {
943 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
946 if( P1.Distance(PLoc) < tol ) {
947 C->D0(fp+(lp-fp)/100,P2);
951 C->D0(lp+(fp-lp)/100,P2);
953 PathNorm = gp_Vec(P2,P1);
958 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
959 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
960 if(fabs(VN.Angle(PathNorm))>PI/2.) {
967 anExp.Init( aShBase2, TopAbs_FACE );
968 TopoDS_Shape aFace = anExp.Current();
969 TColgp_SequenceOfPnt aPnts;
970 double xc=0, yc=0, zc=0;
971 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
972 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
973 aPnts.Append(BRep_Tool::Pnt(V));
974 xc += aPnts.Last().X();
975 yc += aPnts.Last().Y();
976 zc += aPnts.Last().Z();
978 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
979 gp_Vec V1(PC,aPnts.Value(1));
980 gp_Vec V2(PC,aPnts.Value(2));
981 gp_Vec VN = V1.Crossed(V2);
982 for(int ip=2; ip<aPnts.Length(); ip++) {
983 V1 = gp_Vec(PC,aPnts.Value(ip));
984 V2 = gp_Vec(PC,aPnts.Value(ip+1));
985 VN.Add(V1.Crossed(V2));
988 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
990 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
991 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
992 double tol = BRep_Tool::Tolerance(edge);
993 TopoDS_Vertex VF = sae.FirstVertex(edge);
994 gp_Pnt PF = BRep_Tool::Pnt(VF);
995 if( PF.Distance(PLoc) < tol ) {
997 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1000 if( P1.Distance(PLoc) < tol ) {
1001 C->D0(fp+(lp-fp)/100,P2);
1005 C->D0(lp+(fp-lp)/100,P2);
1007 PathNorm = gp_Vec(P2,P1);
1011 TopoDS_Vertex VL = sae.LastVertex(edge);
1012 gp_Pnt PL = BRep_Tool::Pnt(VL);
1013 if( PL.Distance(PLoc) < tol ) {
1015 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1018 if( P1.Distance(PLoc) < tol ) {
1019 C->D0(fp+(lp-fp)/100,P2);
1023 C->D0(lp+(fp-lp)/100,P2);
1025 PathNorm = gp_Vec(P2,P1);
1030 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1031 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1032 if(fabs(VN.Angle(PathNorm))>PI/2.)
1037 if(!CreateFewSolids) {
1038 // we can create only one solid
1039 TopoDS_Shape aWire1, aWire2;
1041 if(aType1==TopAbs_SHELL) {
1042 // create wire as boundary contour if shell is no closed
1043 // get free boundary shapes
1044 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
1045 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1046 //TopExp_Explorer anExp;
1047 Standard_Integer NbWires = 0;
1048 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1050 aWire1 = anExp.Current();
1055 Standard_ConstructionError::Raise("Bad shell is used as section ");
1058 else { // aType1==TopAbs_FACE
1059 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1060 aWire1 = aExpW.Current();
1063 if(aType2==TopAbs_SHELL) {
1064 // create wire as boundary contour if shell is no closed
1065 // get free boundary shapes
1066 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
1067 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1068 //TopExp_Explorer anExp;
1069 Standard_Integer NbWires = 0;
1070 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1072 aWire2 = anExp.Current();
1077 Standard_ConstructionError::Raise("Bad shell is used as section ");
1080 else { // aType2==TopAbs_FACE
1081 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1082 aWire2 = aExpW.Current();
1084 // make pipe using aWire1 and aWire2
1085 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1086 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1087 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1088 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1089 aWithContact, aWithCorrect);
1090 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1091 aWithContact, aWithCorrect);
1092 if(!aBuilder.IsReady()) {
1094 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1097 TopoDS_Shape aShape = aBuilder.Shape();
1098 TopoDS_Shell aShell;
1099 B.MakeShell(aShell);
1100 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1101 B.Add(aShell,anExp.Current());
1103 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1104 B.Add(aShell,anExp.Current());
1106 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1107 B.Add(aShell,anExp.Current());
1109 // make sewing for this shell
1110 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1111 aSewing->SetTolerance(Precision::Confusion());
1112 aSewing->SetFaceMode(Standard_True);
1113 aSewing->SetFloatingEdgesMode(Standard_False);
1114 aSewing->SetNonManifoldMode(Standard_False);
1115 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1116 aSewing->Add(anExp.Current());
1119 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1120 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1121 aShell = TopoDS::Shell(aSewShape);
1122 GProp_GProps aSystem;
1123 BRepGProp::VolumeProperties(aShell, aSystem);
1124 if(aSystem.Mass()<0) {
1127 if(BRep_Tool::IsClosed(aShell)) {
1128 TopoDS_Solid aSolid;
1129 B.MakeSolid(aSolid);
1130 B.Add(aSolid,aShell);
1131 B.Add(aComp,aSolid);
1134 B.Add(aComp,aShell);
1138 B.Add(aComp,aShell);
1143 // main block - creation few solids (for each pair of faces)
1144 TopTools_MapOfShape aFaces1,aFaces2;
1145 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1146 aFaces1.Add(anExp.Current());
1148 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1149 aFaces2.Add(anExp.Current());
1151 // creating map of edge faces
1152 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1153 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1154 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1155 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1157 // constuct map face->face
1158 TopTools_IndexedDataMapOfShapeShape FF;
1159 TopoDS_Shape FS1,FS2;
1161 // find edge the most distant from location point
1162 // (this edge is not shared by two faces)
1163 double maxdist = 0.;
1165 TopoDS_Vertex V11,V21;
1166 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1167 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1168 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1169 if(aList.Extent()>1)
1171 TopExp_Explorer expv;
1172 expv.Init( tmp, TopAbs_VERTEX );
1173 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1175 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1176 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1177 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1178 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1183 TopTools_ListIteratorOfListOfShape anIter(aList);
1184 FS1 = anIter.Value();
1188 // main direction for comparing
1189 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1190 // find corresponding edge from next section
1192 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1193 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1195 TopoDS_Vertex V12,V22;
1196 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1197 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1198 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1199 if(aList.Extent()>1)
1201 TopExp_Explorer expv;
1202 expv.Init( tmp, TopAbs_VERTEX );
1203 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1205 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1206 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1207 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1208 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1209 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1210 TopoDS_Vertex V1,V2;
1213 V1 = V2tmp; P1 = P2tmp;
1214 V2 = V1tmp; P2 = P1tmp;
1217 V1 = V1tmp; P1 = P1tmp;
1218 V2 = V2tmp; P2 = P2tmp;
1220 gp_Vec Vec1(P11,P1);
1221 gp_Vec Vec2(P21,P2);
1222 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1227 TopTools_ListIteratorOfListOfShape anIter(aList);
1228 FS2 = anIter.Value();
1232 // put all pairs to map FF
1238 // add pairs of edges to FF
1239 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1242 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1248 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1249 if(anItem.IsNull()) {
1251 Standard_ConstructionError::Raise("Invalid subbase shape");
1253 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1254 if(aRefBase.IsNull()) {
1256 Standard_ConstructionError::Raise("Invalid subbase shape");
1258 TopoDS_Shape aSh = aRefBase->GetValue();
1261 Standard_ConstructionError::Raise("Invalid subbase shape");
1263 if(aSh.ShapeType()!=TopAbs_FACE) {
1265 Standard_ConstructionError::Raise("Invalid subbase shape");
1270 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1271 if(anItem.IsNull()) {
1273 Standard_ConstructionError::Raise("Invalid subbase shape");
1275 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1276 if(aRefBase.IsNull()) {
1278 Standard_ConstructionError::Raise("Invalid subbase shape");
1280 TopoDS_Shape aSh = aRefBase->GetValue();
1283 Standard_ConstructionError::Raise("Invalid subbase shape");
1285 if(aSh.ShapeType()!=TopAbs_FACE) {
1287 Standard_ConstructionError::Raise("Invalid subbase shape");
1292 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
1294 Standard_ConstructionError::Raise("Invalid subbase shape");
1299 // add pairs of edges to FF
1300 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1301 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1304 Standard_ConstructionError::Raise("Can not create correct pipe");
1308 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1311 // make pipe for each pair of faces
1312 for(j=1; j<=FF.Extent(); j++) {
1313 TopoDS_Shape F1 = FF.FindKey(j);
1314 if( F1.ShapeType() != TopAbs_FACE )
1316 TopoDS_Shape F2 = FF.FindFromIndex(j);
1317 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1318 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1319 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1320 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1321 // make pipe using aWire1 and aWire2
1322 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1323 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1324 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1325 aWithContact, aWithCorrect);
1326 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1327 aWithContact, aWithCorrect);
1328 if(!aBuilder.IsReady()) {
1330 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1333 TopoDS_Shape aShape = aBuilder.Shape();
1334 TopoDS_Shell aShell;
1335 B.MakeShell(aShell);
1336 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1337 B.Add(aShell,anExp.Current());
1342 // make sewing for this shell
1343 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1344 aSewing->SetTolerance(Precision::Confusion());
1345 aSewing->SetFaceMode(Standard_True);
1346 aSewing->SetFloatingEdgesMode(Standard_False);
1347 aSewing->SetNonManifoldMode(Standard_False);
1348 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1349 aSewing->Add(anExp.Current());
1352 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1353 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1354 aShell = TopoDS::Shell(aSewShape);
1355 GProp_GProps aSystem;
1356 BRepGProp::VolumeProperties(aShell, aSystem);
1357 if(aSystem.Mass()<0) {
1358 //cout<<"aSewShape is reversed"<<endl;
1361 if(BRep_Tool::IsClosed(aShell)) {
1362 TopoDS_Solid aSolid;
1363 B.MakeSolid(aSolid);
1364 B.Add(aSolid,aShell);
1365 B.Add(aComp,aSolid);
1368 B.Add(aComp,aShell);
1372 B.Add(aComp,aShell);
1380 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1385 //=======================================================================
1386 //function : CreatePipeShellsWithoutPath
1387 //purpose : auxilary for Execute()
1388 //=======================================================================
1389 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1391 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1395 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1397 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1398 // vertex for recognition
1399 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1401 Standard_Integer nbBases = aBasesObjs->Length(),
1402 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1404 if( nbv != nbBases ) {
1406 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1410 TopTools_SequenceOfShape SecVs,Bases;
1411 for(i=1; i<=nbBases; i++) {
1413 Handle(Standard_Transient) anItem = VObjs->Value(i);
1416 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1417 TopoDS_Shape V = aRef->GetValue();
1418 if(V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1422 anItem = aBasesObjs->Value(i);
1425 aRef = Handle(GEOM_Function)::DownCast(anItem);
1426 TopoDS_Shape aSh = aRef->GetValue();
1431 nbv = SecVs.Length();
1432 nbBases = Bases.Length();
1433 if( nbv != nbBases ) {
1435 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1438 TopoDS_Compound aComp;
1439 B.MakeCompound(aComp);
1441 for(i=1 ; i<nbBases; i++) {
1442 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1443 TopoDS_Shape aShBase1 = Bases.Value(i);
1444 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1445 TopExp_Explorer anExp;
1446 Standard_Integer nbf1 = 0;
1447 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1450 Standard_Integer nbf2 = 0;
1451 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1454 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1457 Standard_ConstructionError::Raise("Different number of faces in the sections");
1460 TopTools_MapOfShape aFaces1,aFaces2;
1461 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1462 aFaces1.Add(anExp.Current());
1464 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1465 aFaces2.Add(anExp.Current());
1468 // creating map of edge faces
1469 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1470 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1471 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1472 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1474 // constuct map face->face (and subshapes)
1475 TopTools_IndexedDataMapOfShapeShape FF;
1476 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1477 TopoDS_Shape FS1, FS2;
1478 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1479 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1480 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1483 MESSAGE (" first pair of corresponding faces is found");
1485 // add pairs of edges and vertexes to FF
1486 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1489 Standard_ConstructionError::Raise("Can not create correct pipe");
1491 MESSAGE (" correspondences for subshapes of first pair of faces is found");
1493 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1494 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1496 // make pipe for each pair of faces
1497 // auxilary map vertex->edge for created pipe edges
1498 TopTools_IndexedDataMapOfShapeShape VPE;
1499 ShapeAnalysis_Edge sae;
1500 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1502 for(j=1; j<=FF.Extent(); j++) {
1503 TopoDS_Shape F1 = FF.FindKey(j);
1504 if( F1.ShapeType() != TopAbs_FACE )
1506 TopoDS_Shape F2 = FF.FindFromIndex(j);
1509 //if(nbff!=3) continue;
1511 MESSAGE (" make pipe for "<<nbff<<" face");
1513 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1514 if(S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1515 Handle(Geom_RectangularTrimmedSurface) RTS =
1516 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1517 S1 = RTS->BasisSurface();
1519 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1520 if( Pln1.IsNull() ) {
1522 Standard_ConstructionError::Raise("Surface from face is not plane");
1524 gp_Vec aDir1(Pln1->Axis().Direction());
1526 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1527 if(S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1528 Handle(Geom_RectangularTrimmedSurface) RTS =
1529 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1530 S2 = RTS->BasisSurface();
1532 Handle(Geom_Plane) Pln2 =
1533 Handle(Geom_Plane)::DownCast(S2);
1534 if( Pln2.IsNull() ) {
1536 Standard_ConstructionError::Raise("Surface from face is not plane");
1538 gp_Vec aDir2(Pln2->Axis().Direction());
1540 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1541 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1543 if(fabs(aDir.Angle(aDir1))>PI/2.)
1545 if(fabs(aDir.Angle(aDir2))>PI/2.)
1548 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1549 TopTools_SequenceOfShape aNewFs;
1551 for(; anExpE.More(); anExpE.Next()) {
1552 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1554 if(!FF.Contains(E1))
1555 MESSAGE ("map FF not contains key E1");
1557 if(VPE.Contains(E1)) {
1558 aNewFs.Append(VPE.FindFromKey(E1));
1560 MESSAGE (" using existed face");
1565 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1566 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1567 TopoDS_Vertex V2 = sae.LastVertex(E1);
1568 if(!FF.Contains(V1))
1569 MESSAGE ("map FF not contains key V1");
1570 if(!FF.Contains(V2))
1571 MESSAGE ("map FF not contains key V2");
1572 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1573 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1574 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1577 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1578 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1579 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1580 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1583 Handle(Geom_BSplineCurve) C2;
1584 if(VPE.Contains(V2)) {
1585 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1587 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1590 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1591 HAP->SetValue(1,P2);
1592 HAP->SetValue(2,P3);
1593 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1594 anInt.Load(aDir1,aDir2);
1597 B.MakeEdge(E2,C2,1.e-7);
1598 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1599 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1604 Handle(Geom_BSplineCurve) C4;
1605 if(VPE.Contains(V1)) {
1606 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1608 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1611 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1612 HAP->SetValue(1,P1);
1613 HAP->SetValue(2,P4);
1614 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1615 anInt.Load(aDir1,aDir2);
1618 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1619 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1620 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1629 B.Add(W,E4.Reversed());
1630 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1631 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1636 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1637 //bool IsConicC1 = false;
1638 //if( C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1639 // IsConicC1 = true;
1640 // cout<<"C1 - Geom_Conic"<<endl;
1642 if( C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1643 C1 = new Geom_TrimmedCurve(C1,fp,lp);
1646 // double tol = BRep_Tool::Tolerance(E1);
1647 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
1648 // C1 = ApxC1.Curve();
1650 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
1651 if( C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1652 C3 = new Geom_TrimmedCurve(C3,fp,lp);
1657 Handle(Geom_BSplineCurve) CE1 =
1658 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
1660 CE1->IncreaseDegree(3);
1661 Handle(Geom_BSplineCurve) CE2 =
1662 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
1664 CE2->IncreaseDegree(3);
1665 Handle(Geom_BSplineCurve) CE3 =
1666 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
1668 CE3->IncreaseDegree(3);
1669 Handle(Geom_BSplineCurve) CE4 =
1670 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
1672 CE4->IncreaseDegree(3);
1673 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
1674 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
1675 //if(fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
1676 // os<<"DrawTrSurf_BSplineCurve"<<endl;
1677 // GeomTools::Write(CE1,os);
1681 Handle(Geom_Surface) BS;
1683 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
1684 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
1688 MESSAGE (" can not create BSplineSurface - create Bezier");
1690 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
1691 double fp1,lp1,fp2,lp2;
1692 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
1693 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
1702 // get points from C1
1703 if(P1.Distance(P1C1)<1.e-6) {
1711 double step = (lp-fp)/(NbP-1);
1712 Points.SetValue(1,1,P1);
1714 for(n1=2; n1<NbP; n1++) {
1718 Points.SetValue(1,n1,P);
1720 Points.SetValue(1,NbP,P2);
1721 // get points from C3
1722 if(P4.Distance(P1C3)<1.e-6) {
1730 step = (lp-fp)/(NbP-1);
1731 Points.SetValue(NbP,1,P4);
1733 for(n1=2; n1<NbP; n1++) {
1737 Points.SetValue(NbP,n1,P);
1739 Points.SetValue(NbP,NbP,P3);
1740 // create isolines and get points from them
1741 for(n1=1; n1<=NbP; n1++) {
1742 gp_Pnt PI1 = Points.Value(1,n1);
1743 gp_Pnt PI2 = Points.Value(NbP,n1);
1744 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1745 HAP->SetValue(1,PI1);
1746 HAP->SetValue(2,PI2);
1747 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1748 anInt.Load(aDir1,aDir2);
1750 Handle(Geom_Curve) iso = anInt.Curve();
1751 fp = iso->FirstParameter();
1752 lp = iso->LastParameter();
1753 step = (lp-fp)/(NbP-1);
1755 TopoDS_Compound VComp;
1756 B.MakeCompound(VComp);
1757 for(n2=2; n2<NbP; n2++) {
1761 Points.SetValue(n2,n1,P);
1764 // create surface and face
1765 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
1766 BS = new Geom_BezierSurface(Points);
1769 BRepBuilderAPI_MakeFace BB(BS,W);
1770 TopoDS_Face NewF = BB.Face();
1771 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
1773 sff->FixOrientation();
1774 TopoDS_Face FixedFace = sff->Face();
1775 aNewFs.Append(FixedFace);
1776 VPE.Add(E1,FixedFace);
1777 //cout<<" face for edge "<<nbee<<" is created"<<endl;
1778 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
1781 TopoDS_Shell aShell;
1782 B.MakeShell(aShell);
1783 for(int nf=1; nf<=aNewFs.Length(); nf++) {
1784 B.Add(aShell,aNewFs(nf));
1789 // make sewing for this shell
1790 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1791 aSewing->SetTolerance(Precision::Confusion());
1792 aSewing->SetFaceMode(Standard_True);
1793 aSewing->SetFloatingEdgesMode(Standard_False);
1794 aSewing->SetNonManifoldMode(Standard_False);
1795 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1796 aSewing->Add(anExp.Current());
1799 MESSAGE (" shell for face "<<nbff<<" is created");
1800 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1801 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
1802 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1803 aShell = TopoDS::Shell(aSewShape);
1804 GProp_GProps aSystem;
1805 BRepGProp::VolumeProperties(aShell, aSystem);
1806 if(aSystem.Mass()<0) {
1807 //cout<<"aSewShape is reversed"<<endl;
1810 if(BRep_Tool::IsClosed(aShell)) {
1811 TopoDS_Solid aSolid;
1812 B.MakeSolid(aSolid);
1813 B.Add(aSolid,aShell);
1814 B.Add(aComp,aSolid);
1815 MESSAGE (" solid for face "<<nbff<<" is created");
1818 B.Add(aComp,aShell);
1819 MESSAGE (" solid for face "<<nbff<<" is not created");
1823 B.Add(aComp,aShell);
1824 MESSAGE (" solid for face "<<nbff<<" is not created");
1826 //cout<<" solid for face "<<nbff<<" is created"<<endl;
1828 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
1830 //TopoDS_Shell FixedShell = sfs->Shell();
1832 GProp_GProps aSystem;
1833 BRepGProp::VolumeProperties(FixedShell, aSystem);
1834 if(aSystem.Mass()<0) {
1835 //cout<<"aSewShape is reversed"<<endl;
1836 FixedShell.Reverse();
1838 if(BRep_Tool::IsClosed(FixedShell)) {
1839 TopoDS_Solid aSolid;
1840 B.MakeSolid(aSolid);
1841 B.Add(aSolid,aShell);
1842 B.Add(aComp,aSolid);
1845 B.Add(aComp,FixedShell);
1851 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1856 //=======================================================================
1857 //function : CreatePipeBiNormalAlongVector
1858 //purpose : auxilary for Execute()
1859 //=======================================================================
1860 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
1861 GEOMImpl_IPipe* aCI)
1863 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
1865 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
1866 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
1867 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1868 TopoDS_Shape aShapeVec = aRefVec->GetValue();
1870 if (aShapeBase.IsNull()) {
1871 if(aCIBN) delete aCIBN;
1872 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1876 if( aShapeBase.ShapeType() == TopAbs_EDGE) {
1877 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
1879 else if( aShapeBase.ShapeType() == TopAbs_WIRE) {
1882 else if( aShapeBase.ShapeType() == TopAbs_FACE) {
1883 TopExp_Explorer wexp(aShapeBase,TopAbs_WIRE);
1884 aProf = wexp.Current();
1887 Standard_TypeMismatch::Raise
1888 ("MakePipe aborted : invalid type of base");
1890 BRepOffsetAPI_MakePipeShell PipeBuilder(aWirePath);
1891 PipeBuilder.Add(aProf);
1893 if (aShapeVec.IsNull()) {
1894 if(aCIBN) delete aCIBN;
1895 Standard_NullObject::Raise
1896 ("MakePipe aborted : null vector argument");
1898 if (aShapeVec.ShapeType() != TopAbs_EDGE)
1899 Standard_TypeMismatch::Raise
1900 ("MakePipe aborted: invalid type of vector");
1901 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
1902 TopoDS_Vertex V1, V2;
1903 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1904 if (V1.IsNull() || V2.IsNull())
1905 Standard_NullObject::Raise
1906 ("MakePipe aborted: vector is not defined");
1907 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
1908 gp_Dir BiNormal(aVec);
1909 PipeBuilder.SetMode(BiNormal);
1910 PipeBuilder.Build();
1911 if( aShapeBase.ShapeType() == TopAbs_FACE) {
1912 PipeBuilder.MakeSolid();
1915 return PipeBuilder.Shape();
1919 //=======================================================================
1920 //function : Execute
1922 //=======================================================================
1923 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1925 //cout<<"PipeDriver::Execute"<<endl;
1926 if (Label().IsNull()) return 0;
1927 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1928 GEOMImpl_IPipe* aCI= 0;
1929 Standard_Integer aType = aFunction->GetType();
1930 if(aType == PIPE_BASE_PATH)
1931 aCI = new GEOMImpl_IPipe(aFunction);
1932 else if(aType == PIPE_DIFFERENT_SECTIONS)
1933 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1934 else if(aType == PIPE_SHELL_SECTIONS)
1935 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1936 else if(aType == PIPE_SHELLS_WITHOUT_PATH)
1937 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1938 else if(aType == PIPE_BI_NORMAL_ALONG_VECTOR)
1939 aCI = new GEOMImpl_IPipeBiNormal(aFunction);
1943 TopoDS_Wire aWirePath;
1944 if(aType != PIPE_SHELLS_WITHOUT_PATH) {
1945 // working with path
1946 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1947 TopoDS_Shape aShapePath = aRefPath->GetValue();
1949 if (aShapePath.IsNull()) {
1950 MESSAGE ("Driver : path is null");
1952 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1956 if (aShapePath.ShapeType() == TopAbs_WIRE) {
1957 aWirePath = TopoDS::Wire(aShapePath);
1960 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1961 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1962 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1966 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1971 TopoDS_Shape aShape;
1973 if (aType == PIPE_BASE_PATH)
1975 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1976 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1978 if (aShapeBase.IsNull()) {
1980 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1984 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
1987 //building pipe with different sections
1988 else if (aType == PIPE_DIFFERENT_SECTIONS) {
1989 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
1990 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
1991 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1992 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
1993 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
1994 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
1995 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1997 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
1998 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
2000 if(nbLocs && nbLocs != nbBases) {
2002 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
2004 TopTools_SequenceOfShape aSeqBases;
2005 TopTools_SequenceOfShape aSeqLocs;
2006 TopTools_SequenceOfShape aSeqFaces;
2007 for( ; i <= nbBases; i++) {
2008 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2011 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2012 if(aRefBase.IsNull())
2014 TopoDS_Shape aShapeBase = aRefBase->GetValue();
2015 if(aShapeBase.IsNull())
2017 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
2019 //if for section was specified face with a few wires then a few
2020 // pipes were build and make solid
2021 Standard_Boolean NeedCreateSolid = Standard_False;
2022 if(aTypeBase == TopAbs_SHELL) {
2023 // create wire as boundary contour if shell is no closed
2024 // get free boundary shapes
2025 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
2026 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
2027 TopExp_Explorer anExp;
2029 Standard_Integer NbWires = 0;
2030 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
2032 aWire = anExp.Current();
2037 Standard_ConstructionError::Raise("Bad shell is used as section ");
2039 NeedCreateSolid = Standard_True;
2040 aSeqFaces.Append(aShapeBase);
2041 aSeqBases.Append(aWire);
2043 else if(aTypeBase == TopAbs_FACE) {
2044 NeedCreateSolid = Standard_True;
2045 //for case one path should be used other type function
2046 aSeqFaces.Append(aShapeBase);
2047 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
2048 for( ; aExpW.More(); aExpW.Next())
2050 TopoDS_Shape aWireProf = aExpW.Current();
2051 aSeqBases.Append(aWireProf);
2054 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
2055 aSeqBases.Append(aShapeBase);
2057 else if(aTypeBase == TopAbs_EDGE) {
2058 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
2059 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
2060 aSeqBases.Append(aWireProf);
2063 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2064 if(anItemLoc.IsNull())
2066 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2067 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2068 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2070 aSeqLocs.Append(aShapeLoc);
2074 nbLocs = aSeqLocs.Length();
2077 TopTools_SequenceOfShape Edges;
2079 // we have to check that each location shape is a vertex from
2080 // path and update aSeqLocs if it is needed (and possible)
2081 TColgp_SequenceOfPnt PLocs;
2082 for(i=1; i<=nbLocs; i++) {
2083 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
2084 PLocs.Append(BRep_Tool::Pnt(V));
2086 //TopTools_SequenceOfShape Edges;
2087 TopExp_Explorer anExp;
2088 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
2089 Edges.Append(anExp.Current());
2091 int nbEdges = Edges.Length();
2092 ShapeAnalysis_Edge sae;
2093 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
2094 double tol = BRep_Tool::Tolerance(edge);
2095 TopoDS_Vertex VF = sae.FirstVertex(edge);
2096 gp_Pnt PF = BRep_Tool::Pnt(VF);
2097 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
2098 if( PF.Distance(PLocs.First()) > tol ) {
2100 Standard_ConstructionError::Raise
2101 ("First location shapes is not coincided with first vertex of aWirePath");
2103 aSeqLocs.ChangeValue(1) = VF;
2104 edge = TopoDS::Edge(Edges.Last());
2105 tol = BRep_Tool::Tolerance(edge);
2106 TopoDS_Vertex VL = sae.LastVertex(edge);
2107 gp_Pnt PL = BRep_Tool::Pnt(VL);
2108 if( PL.Distance(PLocs.Last()) > tol ) {
2110 Standard_ConstructionError::Raise
2111 ("Last location shapes is not coincided with last vertex of aWirePath");
2113 aSeqLocs.ChangeValue(nbLocs) = VL;
2115 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
2116 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
2117 tol = BRep_Tool::Tolerance(edge);
2118 TopoDS_Vertex V1 = sae.FirstVertex(E);
2119 TopoDS_Vertex V2 = sae.LastVertex(E);
2120 gp_Pnt P1 = BRep_Tool::Pnt(V1);
2121 gp_Pnt P2 = BRep_Tool::Pnt(V2);
2122 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
2123 aSeqLocs.ChangeValue(jcurr) = V2;
2127 // find distance between E and aLocs(jcurr)
2129 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
2130 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
2131 if( PPC.NbPoints()>0 &&
2132 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
2133 double param = PPC.Parameter(1);
2136 // split current edge
2137 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
2138 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
2143 if(Pfp.Distance(P1)<tol) {
2144 B.MakeEdge(E1,tc1,tol);
2146 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2147 B.Add(E1,TopoDS::Vertex(tmpV));
2148 B.MakeEdge(E2,tc2,tol);
2149 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2150 B.Add(E2,TopoDS::Vertex(tmpV));
2154 B.MakeEdge(E1,tc2,tol);
2155 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2156 B.Add(E1,TopoDS::Vertex(tmpV));
2159 B.MakeEdge(E2,tc1,tol);
2161 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2162 B.Add(E2,TopoDS::Vertex(tmpV));
2167 Edges.InsertAfter(i-1,E1);
2168 Edges.InsertAfter(i,E2);
2172 if(nbEdges<Edges.Length()) {
2173 // one of edges was splitted => we have to update WirePath
2177 for(i=1; i<=Edges.Length(); i++) {
2178 B.Add(W,TopoDS::Edge(Edges.Value(i)));
2184 // check curvature of wire for condition that
2185 // max summary angle between directions along
2186 // wire path must be < 4*PI. If not - split wire
2187 // and seguences of shapes, perform pipe for each
2188 // and make sewing after that
2190 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
2195 double SumAng = fabs(Vec1.Angle(Vec2));
2198 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
2200 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
2201 for(i=2; i<=Edges.Length(); i++) {
2202 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
2203 double tol = BRep_Tool::Tolerance(edge);
2204 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
2206 double ang = fabs(Vec1.Angle(Vec2));
2210 SplitEdgeNums.Append(i-1);
2212 for(j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
2213 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
2214 gp_Pnt P = BRep_Tool::Pnt(aVert);
2215 if( P1.Distance(P) < tol ) {
2216 SplitLocNums.Append(j);
2226 //cout<<"SplitEdgeNums.Length()="<<SplitEdgeNums.Length()<<endl;
2227 //cout<<"SplitLocNums.Length()="<<SplitLocNums.Length()<<endl;
2228 if( SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0 ) {
2229 TopTools_SequenceOfShape aSeqRes;
2230 int nn, num1 = 1, num2 = 1;
2231 for(nn=1; nn<=SplitEdgeNums.Length(); nn++) {
2232 // create wirepath and sequences of shapes
2236 for(i=num1; i<=SplitEdgeNums.Value(nn); i++) {
2237 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2239 num1 = SplitEdgeNums.Value(nn) + 1;
2240 TopTools_SequenceOfShape aTmpSeqBases;
2241 TopTools_SequenceOfShape aTmpSeqLocs;
2242 for(i=num2; i<=SplitLocNums.Value(nn); i++) {
2243 aTmpSeqBases.Append(aSeqBases.Value(i));
2244 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2246 num2 = SplitLocNums.Value(nn);
2248 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2249 Standard_Integer nbShapes = aTmpSeqBases.Length();
2250 for(i=1; i<=nbShapes; i++) {
2251 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2252 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2253 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2255 if(!aBuilder.IsReady()) {
2257 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2260 TopoDS_Shape resShape = aBuilder.Shape();
2261 aSeqRes.Append(resShape);
2263 // create wirepath and sequences of shapes for last part
2267 for(i=num1; i<=Edges.Length(); i++) {
2268 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2270 TopTools_SequenceOfShape aTmpSeqBases;
2271 TopTools_SequenceOfShape aTmpSeqLocs;
2272 for(i=num2; i<=aSeqLocs.Length(); i++) {
2273 aTmpSeqBases.Append(aSeqBases.Value(i));
2274 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2276 // make pipe for last part
2277 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2278 Standard_Integer nbShapes = aTmpSeqBases.Length();
2279 for(i=1; i<=nbShapes; i++) {
2280 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2281 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2282 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2284 if(!aBuilder.IsReady()) {
2286 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2289 TopoDS_Shape resShape = aBuilder.Shape();
2290 aSeqRes.Append(resShape);
2291 // make sewing for result
2292 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2293 aSewing->SetTolerance(Precision::Confusion());
2294 aSewing->SetFaceMode(Standard_True);
2295 aSewing->SetFloatingEdgesMode(Standard_False);
2296 aSewing->SetNonManifoldMode(Standard_False);
2297 for(i=1; i<=aSeqRes.Length(); i++) {
2298 aSewing->Add(aSeqRes.Value(i));
2301 aShape = aSewing->SewedShape();
2304 // old implementation without splitting
2305 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2307 Standard_Integer nbShapes = aSeqBases.Length();
2308 Standard_Integer step = nbShapes/nbBases;
2310 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
2312 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
2314 Standard_Integer ind =0;
2315 for( i=1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
2316 TopTools_SequenceOfShape usedBases;
2317 Standard_Integer j = 1;
2318 for( ; j <= nbBases ; j++) {
2319 ind = i + (j-1)*step;
2320 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
2321 usedBases.Append(aWireProf);
2323 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
2324 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2325 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
2328 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
2330 if(!aBuilder.IsReady()) {
2332 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2335 aShape = aBuilder.Shape();
2336 aSeqFaces.Append(aShape);
2337 for( j = 1; j <=usedBases.Length(); j++)
2338 aBuilder.Delete(usedBases.Value(j));
2341 //for case if section is face
2342 if(aSeqFaces.Length() >1) {
2344 TopoDS_Compound aComp;
2345 aB.MakeCompound(aComp);
2346 for( i = 1; i <= aSeqFaces.Length(); i++)
2347 aB.Add(aComp,aSeqFaces.Value(i));
2353 //building pipe with shell sections
2354 else if (aType == PIPE_SHELL_SECTIONS) {
2355 aShape = CreatePipeForShellSections(aWirePath,aCI);
2358 //building pipe shell sections without path
2359 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2360 aShape = CreatePipeShellsWithoutPath(aCI);
2363 //building a pipe with constant bi-normal along given vector
2364 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2365 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2373 if (aShape.IsNull()) return 0;
2375 BRepCheck_Analyzer ana (aShape, Standard_False);
2376 if (!ana.IsValid()) {
2377 ShapeFix_ShapeTolerance aSFT;
2378 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2379 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2380 aSfs->SetPrecision(Precision::Confusion());
2382 aShape = aSfs->Shape();
2384 ana.Init(aShape, Standard_False);
2386 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2389 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
2390 aFunction->SetValue(aRes);
2392 log.SetTouched(Label());
2397 //=======================================================================
2398 //function : GEOMImpl_PipeDriver_Type_
2400 //=======================================================================
2401 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2404 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2405 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2406 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2407 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2408 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2409 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2412 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2413 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2414 sizeof(GEOMImpl_PipeDriver),
2416 (Standard_Address)_Ancestors,
2417 (Standard_Address)NULL);
2422 //=======================================================================
2423 //function : DownCast
2425 //=======================================================================
2426 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2428 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2430 if (!AnObject.IsNull()) {
2431 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2432 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2436 return _anOtherObject ;