1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_PipeDriver.hxx>
25 #include <GEOMImpl_IShapesOperations.hxx>
26 #include <GEOMImpl_IPipeDiffSect.hxx>
27 #include <GEOMImpl_IPipeShellSect.hxx>
28 #include <GEOMImpl_IPipe.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOM_Function.hxx>
32 #include <GEOMAlgo_GlueAnalyser.hxx>
34 #include <ShapeAnalysis_FreeBounds.hxx>
35 #include <ShapeAnalysis_Edge.hxx>
36 #include <ShapeFix_Face.hxx>
37 #include <ShapeFix_Shell.hxx>
38 #include <ShapeFix_Shape.hxx>
39 #include <ShapeFix_ShapeTolerance.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRep_Builder.hxx>
43 #include <BRepBuilderAPI_MakeWire.hxx>
44 #include <BRepBuilderAPI_Sewing.hxx>
45 #include <BRepCheck_Analyzer.hxx>
46 #include <BRepOffsetAPI_MakePipe.hxx>
47 #include <BRepOffsetAPI_MakePipeShell.hxx>
48 #include <GProp_GProps.hxx>
49 #include <BRepGProp.hxx>
50 #include <BRepBuilderAPI_MakeFace.hxx>
54 #include <TopExp_Explorer.hxx>
56 #include <TopoDS_Wire.hxx>
57 #include <TopoDS_Edge.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopoDS_Solid.hxx>
60 #include <TopoDS_Shell.hxx>
61 #include <TopoDS_Face.hxx>
62 #include <TopoDS_Compound.hxx>
63 #include <TopTools_SequenceOfShape.hxx>
64 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
65 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
66 #include <TopTools_ListIteratorOfListOfShape.hxx>
68 #include <GeomAPI_ProjectPointOnCurve.hxx>
69 #include <GeomAPI_Interpolate.hxx>
70 #include <Geom_TrimmedCurve.hxx>
71 #include <Geom_Plane.hxx>
72 #include <Geom_RectangularTrimmedSurface.hxx>
73 #include <Geom_BezierSurface.hxx>
74 #include <Geom_Line.hxx>
75 #include <Geom_Conic.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_BSplineSurface.hxx>
78 #include <GeomFill_BSplineCurves.hxx>
79 #include <GeomConvert_ApproxCurve.hxx>
80 #include <GeomConvert.hxx>
82 #include <TColgp_SequenceOfPnt.hxx>
83 #include <TColgp_HArray1OfPnt.hxx>
84 #include <TColgp_Array2OfPnt.hxx>
85 #include <TColStd_HSequenceOfTransient.hxx>
87 #include <Precision.hxx>
88 #include <Standard_NullObject.hxx>
89 #include <Standard_TypeMismatch.hxx>
90 #include <Standard_ConstructionError.hxx>
92 #include "utilities.h"
95 //=======================================================================
98 //=======================================================================
99 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
101 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
106 //=======================================================================
107 //function : GEOMImpl_PipeDriver
109 //=======================================================================
110 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
115 //=======================================================================
116 //function : FillForOtherEdges
117 //purpose : auxilary for CreatePipeForShellSections()
118 //=======================================================================
119 static bool FillForOtherEdges(const TopoDS_Shape& F1,
120 const TopoDS_Shape& E1,
121 const TopoDS_Shape& V1,
122 TopTools_IndexedDataMapOfShapeShape& FF)
124 //cout<<"FillForOtherEdges"<<endl;
125 // find other pairs for vertexes and edges
126 // creating map of vertex edges for both faces
127 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
128 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
129 if (!FF.Contains(F1))
130 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
131 if (!FF.Contains(E1))
132 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
133 if (!FF.Contains(V1))
134 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
135 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
136 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
137 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
138 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
139 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
141 TopoDS_Edge ES1 = TopoDS::Edge(E1);
142 TopoDS_Edge ES2 = TopoDS::Edge(E2);
143 TopoDS_Shape VS1 = V1;
144 TopoDS_Shape VS2 = V2;
146 ShapeAnalysis_Edge sae;
148 if(!aMapVertEdge1.Contains(VS1))
149 cout<<" FillForOtherEdges: map aMapVertEdge1 not contains key VS1"<<endl;
150 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
151 //TopoDS_Shape E1next;
152 TopTools_ListIteratorOfListOfShape anIter1(aList1);
153 if(anIter1.Value().IsSame(ES1)) {
156 //E1next = anIter1.Value();
157 if(!aMapVertEdge2.Contains(VS2))
158 cout<<" FillForOtherEdges: map aMapVertEdge2 not contains key VS2"<<endl;
159 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
160 //TopoDS_Shape E2next;
161 TopTools_ListIteratorOfListOfShape anIter2(aList2);
162 if(anIter2.Value().IsSame(ES2)) {
165 //E2next = anIter2.Value();
166 //ES1 = TopoDS::Edge(E1next);
167 //ES2 = TopoDS::Edge(E2next);
168 ES1 = TopoDS::Edge(anIter1.Value());
169 ES2 = TopoDS::Edge(anIter2.Value());
170 if(!FF.Contains(ES1)) {
173 if(VS1.IsSame(sae.FirstVertex(ES1)))
174 VS1 = sae.LastVertex(ES1);
176 VS1 = sae.FirstVertex(ES1);
177 if(VS2.IsSame(sae.FirstVertex(ES2)))
178 VS2 = sae.LastVertex(ES2);
180 VS2 = sae.FirstVertex(ES2);
183 if(!FF.Contains(VS1)) {
192 //=======================================================================
193 //function : FillCorrespondingEdges
194 //purpose : auxilary for CreatePipeForShellSections()
195 //=======================================================================
196 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
197 const TopoDS_Shape& FS2,
198 const TopoDS_Vertex& aLoc1,
199 const TopoDS_Vertex& aLoc2,
200 const TopoDS_Wire& aWirePath,
201 TopTools_IndexedDataMapOfShapeShape& FF)
203 //cout<<"FillCorrespondingEdges"<<endl;
204 // find corresponding edges
205 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
206 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
207 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
208 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
209 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
210 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
211 aBuilder.Add(aWire1, aLoc1);
212 aBuilder.Add(aWire2, aLoc2);
213 if(!aBuilder.IsReady()) {
217 TopoDS_Shape aShape = aBuilder.Shape();
225 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
227 ShapeAnalysis_Edge sae;
228 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
229 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
230 TopTools_MapOfShape Vs1,Vs2;
232 exp.Init( FS1, TopAbs_EDGE );
233 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
234 TopoDS_Vertex V11 = sae.FirstVertex(E1);
235 TopoDS_Vertex V21 = sae.LastVertex(E1);
236 gp_Pnt P11 = BRep_Tool::Pnt(V11);
237 gp_Pnt P21 = BRep_Tool::Pnt(V21);
238 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
239 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
240 // find corresponding vertexes from created shape
241 TopoDS_Vertex VN11,VN21;
242 for( exp.Init( aShape, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
243 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
244 gp_Pnt P = BRep_Tool::Pnt(V);
245 if(P.Distance(P11)<tol) {
248 if(P.Distance(P21)<tol) {
252 // find edge contains VN11 and VN21 and corresponding vertexes
253 TopoDS_Vertex VN12,VN22;
254 for( exp.Init( aShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
255 TopoDS_Shape F = exp.Current();
256 TopExp_Explorer expe;
258 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
259 TopoDS_Edge E = TopoDS::Edge(expe.Current());
260 TopoDS_Vertex VF = sae.FirstVertex(E);
261 TopoDS_Vertex VL = sae.LastVertex(E);
262 if( (VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11)) ) {
268 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
269 TopoDS_Edge E = TopoDS::Edge(expe.Current());
270 TopoDS_Vertex VF = sae.FirstVertex(E);
271 TopoDS_Vertex VL = sae.LastVertex(E);
272 if( VF.IsSame(VN11) && !VL.IsSame(VN21) )
274 if( VL.IsSame(VN11) && !VF.IsSame(VN21) )
276 if( VF.IsSame(VN21) && !VL.IsSame(VN11) )
278 if( VL.IsSame(VN21) && !VF.IsSame(VN11) )
284 // find vertexes from FS2 corresponded to VN12 and VN22
285 // and find edge from FS2 contains V12 and V22,
286 // this edge will be corresponded to edge E1
287 TopoDS_Vertex V12,V22;
288 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
289 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
290 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
291 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
293 TopExp_Explorer expe;
294 for( expe.Init( FS2, TopAbs_EDGE ); expe.More(); expe.Next() ) {
295 TopoDS_Edge E = TopoDS::Edge(expe.Current());
296 TopoDS_Vertex VF = sae.FirstVertex(E);
297 TopoDS_Vertex VL = sae.LastVertex(E);
298 gp_Pnt PF = BRep_Tool::Pnt(VF);
299 gp_Pnt PL = BRep_Tool::Pnt(VL);
300 if( PF.Distance(PN12)<tol && PL.Distance(PN22)<tol ) {
306 if( PF.Distance(PN22)<tol && PL.Distance(PN12)<tol ) {
317 // find other pairs for vertexes and edges
318 // creating map of vertex edges for both faces
319 return FillForOtherEdges(FS1,E1,V21,FF);
325 //=======================================================================
326 //function : FillCorrespondingEdges
327 //purpose : auxilary for CreatePipeShellsWithoutPath()
328 //=======================================================================
329 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
330 const TopoDS_Shape& FS2,
331 const TopoDS_Vertex& aLoc1,
332 const TopoDS_Vertex& aLoc2,
333 TopTools_IndexedDataMapOfShapeShape& FF)
335 //cout<<"FillCorrespondingEdges"<<endl;
337 gp_Pnt P1 = BRep_Tool::Pnt(aLoc1);
338 gp_Pnt P2 = BRep_Tool::Pnt(aLoc2);
341 ShapeAnalysis_Edge sae;
342 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
343 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
344 TopTools_MapOfShape Vs1,Vs2;
346 TopoDS_Vertex V11=aLoc1, V12=aLoc2, V21, V22;
349 TopExp_Explorer exp1;
350 for( exp1.Init(FS1,TopAbs_EDGE); exp1.More(); exp1.Next() ) {
351 E1 = TopoDS::Edge(exp1.Current());
352 TopoDS_Vertex V1 = sae.FirstVertex(E1);
353 TopoDS_Vertex V2 = sae.LastVertex(E1);
354 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
355 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
356 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
357 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
358 if(P1.Distance(Ptmp1)<tol) {
362 if(P1.Distance(Ptmp2)<tol) {
369 TopoDS_Vertex VE21,VE22;
371 for( exp1.Init(FS2,TopAbs_EDGE); exp1.More() && nbe<2; exp1.Next() ) {
372 TopoDS_Edge E = TopoDS::Edge(exp1.Current());
373 TopoDS_Vertex V1 = sae.FirstVertex(E);
374 TopoDS_Vertex V2 = sae.LastVertex(E);
375 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
376 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
377 if(P2.Distance(Ptmp1)<tol) {
389 if(P2.Distance(Ptmp2)<tol) {
403 gp_Pnt PV21 = BRep_Tool::Pnt(V21);
404 gp_Pnt PE21 = BRep_Tool::Pnt(VE21);
405 gp_Pnt PE22 = BRep_Tool::Pnt(VE22);
406 gp_Vec aDir1(PV21,PE21);
407 gp_Vec aDir2(PV21,PE22);
408 double ang1 = aDir.Angle(aDir1);
409 double ang2 = aDir.Angle(aDir2);
410 if(fabs(ang1)<fabs(ang2)) {
423 // find other pairs for vertexes and edges
424 return FillForOtherEdges(FS1,E1,V21,FF);
428 //=======================================================================
429 //function : FindNextPairOfFaces
430 //purpose : auxilary for CreatePipeForShellSections()
431 //=======================================================================
432 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
433 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
434 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
435 TopTools_IndexedDataMapOfShapeShape& FF,
438 //cout<<"FindNextPairOfFaces"<<endl;
439 TopExp_Explorer anExp;
440 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
441 TopoDS_Shape E1 = anExp.Current();
442 if(!FF.Contains(E1)) {
444 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
447 cout<<" FindNextPairOfFaces: map FF not contains key E1"<<endl;
448 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
449 TopExp_Explorer anExpV;
450 anExpV.Init( E1, TopAbs_VERTEX );
451 TopoDS_Shape V1 = anExpV.Current();
452 if(!FF.Contains(V1)) {
454 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
457 if(!aMapEdgeFaces1.Contains(E1))
458 cout<<" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1"<<endl;
459 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
460 if(aList1.Extent()<2)
462 TopTools_ListIteratorOfListOfShape anIter(aList1);
463 if(anIter.Value().IsEqual(aCurFace)) {
466 TopoDS_Shape F1other = anIter.Value();
467 if(FF.Contains(F1other))
470 if(!FF.Contains(aCurFace))
471 cout<<" FindNextPairOfFaces: map FF not contains key aCurFace"<<endl;
472 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
473 if(!aMapEdgeFaces2.Contains(E2))
474 cout<<" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2"<<endl;
475 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
476 if(aList2.Extent()<2) {
478 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
480 TopTools_ListIteratorOfListOfShape anIter2(aList2);
481 if(anIter2.Value().IsEqual(F2)) {
484 TopoDS_Shape F2other = anIter2.Value();
485 FF.Add(F1other,F2other);
487 // add pairs of edges to FF
488 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
491 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
494 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
499 //=======================================================================
500 //function : FindFirstPairFaces
501 //purpose : auxilary for Execute()
502 //=======================================================================
503 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
504 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
505 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
507 //cout<<"FindFirstPairFaces"<<endl;
509 // check if vertexes are subshapes of sections
510 gp_Pnt P1 = BRep_Tool::Pnt(V1);
511 gp_Pnt P2 = BRep_Tool::Pnt(V2);
512 TopoDS_Vertex V1new,V2new;
514 double mindist = 1.e10;
515 for( exp.Init( S1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
516 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
517 gp_Pnt P = BRep_Tool::Pnt(V);
518 double dist = P1.Distance(P);
525 for( exp.Init( S2, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
526 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
527 gp_Pnt P = BRep_Tool::Pnt(V);
528 double dist = P2.Distance(P);
535 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
536 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
537 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
538 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
539 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
540 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
542 // replace vertexes if it is needed
543 if(!V1.IsSame(V1new)) {
545 P1 = BRep_Tool::Pnt(V1);
546 cout<<" replace V1"<<endl;
549 cout<<" not replace V1"<<endl;
550 if(!V2.IsSame(V2new)) {
552 P2 = BRep_Tool::Pnt(V2);
553 cout<<" replace V2"<<endl;
556 cout<<" not replace V2"<<endl;
558 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
559 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
560 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
561 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
563 if(!aMapVertFaces1.Contains(V1))
564 cout<<" FindFirstPairFaces: map aMapVertFaces1 not contains key V1"<<endl;
565 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
566 TopTools_ListIteratorOfListOfShape anIter1(aList1);
567 FS1 = anIter1.Value();
569 double x1=0., y1=0., z1=0.;
571 for( exp.Init( FS1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
572 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
573 gp_Pnt P = BRep_Tool::Pnt(V);
579 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
581 TColgp_SequenceOfPnt Ps;
582 TopTools_SequenceOfShape Fs;
583 if(!aMapVertFaces2.Contains(V2))
584 cout<<" FindFirstPairFaces: map aMapVertFaces2 not contains key V2"<<endl;
585 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
586 TopTools_ListIteratorOfListOfShape anIter2(aList2);
587 for(; anIter2.More(); anIter2.Next()) {
588 TopoDS_Shape F = anIter2.Value();
589 double x2=0., y2=0., z2=0.;
591 for( exp.Init( F, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
592 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
593 gp_Pnt P = BRep_Tool::Pnt(V);
599 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
608 for(; i<=Fs.Length(); i++) {
609 gp_Vec tmpDir(PM1,Ps(i));
610 double ang = fabs(aDir.Angle(tmpDir));
620 //=======================================================================
621 //function : CreatePipeForShellSections
622 //purpose : auxilary for Execute()
623 //=======================================================================
624 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
627 //cout<<"CreatePipeForShellSections"<<endl;
632 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
633 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
634 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
635 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
636 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
637 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
639 Standard_Integer nbBases = aBasesObjs->Length(),
640 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
641 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
643 if( nbLocs != nbBases) {
645 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
647 if( nbSubBases && nbSubBases != nbBases) {
649 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
652 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
654 TopTools_SequenceOfShape VLocs;
655 for(i=1; i<=nbBases; i++) {
656 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
657 if(anItemLoc.IsNull())
659 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
660 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
661 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
663 VLocs.Append(aShapeLoc);
665 nbLocs = VLocs.Length();
666 if( nbLocs != nbBases) {
668 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
670 // split wire path by location points
671 TColgp_SequenceOfPnt PLocs;
672 for(i=1; i<=nbLocs; i++) {
673 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
674 PLocs.Append(BRep_Tool::Pnt(V));
677 TopTools_SequenceOfShape Edges;
678 TopTools_SequenceOfShape Wires;
679 ShapeAnalysis_Edge sae;
682 TopExp_Explorer anExp;
683 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
684 Edges.Append(anExp.Current());
686 Standard_Integer Num1 = 0;
687 Standard_Integer Num2 = 0;
688 for(i=1; i<=Edges.Length(); i++) {
689 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
690 double tol = BRep_Tool::Tolerance(E);
691 TopoDS_Vertex V1 = sae.FirstVertex(E);
692 TopoDS_Vertex V2 = sae.LastVertex(E);
693 gp_Pnt P1 = BRep_Tool::Pnt(V1);
694 gp_Pnt P2 = BRep_Tool::Pnt(V2);
695 if( P1.Distance(PLocs.First()) < tol ) {
698 if( P2.Distance(PLocs.Last()) < tol ) {
702 if( Num1>0 && Num2>0 ) {
705 for(i=Num1; i<=Num2; i++) {
706 B.Add(W,Edges.Value(i));
711 Wires.Append(aWirePath);
715 TopExp_Explorer anExp;
716 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
717 Edges.Append(anExp.Current());
719 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
720 double tol = BRep_Tool::Tolerance(edge);
721 TopoDS_Vertex VF = sae.FirstVertex(edge);
722 gp_Pnt PF = BRep_Tool::Pnt(VF);
723 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
724 if( PF.Distance(PLocs.First()) > tol ) {
726 Standard_ConstructionError::Raise
727 ("First location shapes is not coincided with first vertex of aWirePath");
729 VLocs.ChangeValue(1) = VF;
730 edge = TopoDS::Edge(Edges.Last());
731 tol = BRep_Tool::Tolerance(edge);
732 TopoDS_Vertex VL = sae.LastVertex(edge);
733 gp_Pnt PL = BRep_Tool::Pnt(VL);
734 if( PL.Distance(PLocs.Last()) > tol ) {
736 Standard_ConstructionError::Raise
737 ("Last location shapes is not coincided with last vertex of aWirePath");
739 VLocs.ChangeValue(nbLocs) = VL;
741 TopTools_SequenceOfShape tmpEdges;
742 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
743 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
744 tol = BRep_Tool::Tolerance(E);
745 TopoDS_Vertex V1 = sae.FirstVertex(E);
746 TopoDS_Vertex V2 = sae.LastVertex(E);
747 gp_Pnt P1 = BRep_Tool::Pnt(V1);
748 gp_Pnt P2 = BRep_Tool::Pnt(V2);
749 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
750 // make wire from current edge and add created
754 for(j=1; j<=tmpEdges.Length(); j++)
755 B.Add(W,tmpEdges.Value(j));
758 VLocs.ChangeValue(jcurr) = V2;
763 // find distance between E and aLocs(jcurr)
765 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
766 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
767 if( PPC.NbPoints()>0 &&
768 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
769 double param = PPC.Parameter(1);
772 // split current edge
773 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
774 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
778 if(Pfp.Distance(P1)<tol) {
779 B.MakeEdge(E1,tc1,tol);
781 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
782 B.Add(E1,TopoDS::Vertex(tmpV));
784 B.MakeEdge(E2,tc2,tol);
785 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
786 B.Add(E2,TopoDS::Vertex(tmpV));
790 B.MakeEdge(E1,tc2,tol);
791 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
792 B.Add(E1,TopoDS::Vertex(tmpV));
796 B.MakeEdge(E2,tc1,tol);
798 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
799 B.Add(E2,TopoDS::Vertex(tmpV));
802 // create wire from tmpEdges
805 for(j=1; j<=tmpEdges.Length(); j++)
806 B.Add(W,tmpEdges.Value(j));
811 Edges.InsertAfter(i-1,E1);
812 Edges.InsertAfter(i,E2);
819 // create wire from other edges
822 for(; i<=Edges.Length(); i++)
823 B.Add(W,Edges.Value(i));
825 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
828 if( Wires.Length() != nbLocs-1 ) {
830 Standard_ConstructionError::Raise
831 ("One of location shapes is not lied on the path");
834 //TopTools_SequenceOfShape aSeqBases;
835 //TopTools_SequenceOfShape aSeqSubBases;
836 //TopTools_SequenceOfShape aSeqFaces;
837 TopoDS_Compound aComp;
838 B.MakeCompound(aComp);
839 for(i=1 ; i<nbBases; i++) {
840 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
842 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
845 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
846 if(aRefBase1.IsNull())
848 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
849 if(aShBase1.IsNull())
851 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
853 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
856 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
857 if(aRefBase2.IsNull())
859 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
860 if(aShBase2.IsNull())
862 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
864 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
866 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
867 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
870 Standard_ConstructionError::Raise("One of section shapes has invalid type");
873 bool CreateFewSolids = false;
875 TopExp_Explorer anExp;
876 Standard_Integer nbf1 = 0;
877 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
880 Standard_Integer nbf2 = 0;
881 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
885 CreateFewSolids = true;
889 // check orientation of sections
890 bool NeedReverse = false;
893 anExp.Init( aShBase1, TopAbs_FACE );
894 TopoDS_Shape aFace = anExp.Current();
895 TColgp_SequenceOfPnt aPnts;
896 double xc=0, yc=0, zc=0;
897 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
898 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
899 aPnts.Append(BRep_Tool::Pnt(V));
900 xc += aPnts.Last().X();
901 yc += aPnts.Last().Y();
902 zc += aPnts.Last().Z();
904 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
905 gp_Vec V1(PC,aPnts.Value(1));
906 gp_Vec V2(PC,aPnts.Value(2));
907 gp_Vec VN = V1.Crossed(V2);
908 for(int ip=2; ip<aPnts.Length(); ip++) {
909 V1 = gp_Vec(PC,aPnts.Value(ip));
910 V2 = gp_Vec(PC,aPnts.Value(ip+1));
911 VN.Add(V1.Crossed(V2));
914 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
916 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
917 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
918 double tol = BRep_Tool::Tolerance(edge);
919 TopoDS_Vertex VF = sae.FirstVertex(edge);
920 gp_Pnt PF = BRep_Tool::Pnt(VF);
921 if( PF.Distance(PLoc) < tol ) {
923 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
926 if( P1.Distance(PLoc) < tol ) {
927 C->D0(fp+(lp-fp)/100,P2);
931 C->D0(lp+(fp-lp)/100,P2);
933 PathNorm = gp_Vec(P1,P2);
937 TopoDS_Vertex VL = sae.LastVertex(edge);
938 gp_Pnt PL = BRep_Tool::Pnt(VL);
939 if( PL.Distance(PLoc) < tol ) {
941 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
944 if( P1.Distance(PLoc) < tol ) {
945 C->D0(fp+(lp-fp)/100,P2);
949 C->D0(lp+(fp-lp)/100,P2);
951 PathNorm = gp_Vec(P2,P1);
956 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
957 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
958 if(fabs(VN.Angle(PathNorm))>PI/2.) {
965 anExp.Init( aShBase2, TopAbs_FACE );
966 TopoDS_Shape aFace = anExp.Current();
967 TColgp_SequenceOfPnt aPnts;
968 double xc=0, yc=0, zc=0;
969 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
970 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
971 aPnts.Append(BRep_Tool::Pnt(V));
972 xc += aPnts.Last().X();
973 yc += aPnts.Last().Y();
974 zc += aPnts.Last().Z();
976 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
977 gp_Vec V1(PC,aPnts.Value(1));
978 gp_Vec V2(PC,aPnts.Value(2));
979 gp_Vec VN = V1.Crossed(V2);
980 for(int ip=2; ip<aPnts.Length(); ip++) {
981 V1 = gp_Vec(PC,aPnts.Value(ip));
982 V2 = gp_Vec(PC,aPnts.Value(ip+1));
983 VN.Add(V1.Crossed(V2));
986 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
988 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
989 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
990 double tol = BRep_Tool::Tolerance(edge);
991 TopoDS_Vertex VF = sae.FirstVertex(edge);
992 gp_Pnt PF = BRep_Tool::Pnt(VF);
993 if( PF.Distance(PLoc) < tol ) {
995 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
998 if( P1.Distance(PLoc) < tol ) {
999 C->D0(fp+(lp-fp)/100,P2);
1003 C->D0(lp+(fp-lp)/100,P2);
1005 PathNorm = gp_Vec(P2,P1);
1009 TopoDS_Vertex VL = sae.LastVertex(edge);
1010 gp_Pnt PL = BRep_Tool::Pnt(VL);
1011 if( PL.Distance(PLoc) < tol ) {
1013 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1016 if( P1.Distance(PLoc) < tol ) {
1017 C->D0(fp+(lp-fp)/100,P2);
1021 C->D0(lp+(fp-lp)/100,P2);
1023 PathNorm = gp_Vec(P2,P1);
1028 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1029 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1030 if(fabs(VN.Angle(PathNorm))>PI/2.)
1035 if(!CreateFewSolids) {
1036 // we can create only one solid
1037 TopoDS_Shape aWire1, aWire2;
1039 if(aType1==TopAbs_SHELL) {
1040 // create wire as boundary contour if shell is no closed
1041 // get free boundary shapes
1042 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
1043 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1044 //TopExp_Explorer anExp;
1045 Standard_Integer NbWires = 0;
1046 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1048 aWire1 = anExp.Current();
1053 Standard_ConstructionError::Raise("Bad shell is used as section ");
1056 else { // aType1==TopAbs_FACE
1057 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1058 aWire1 = aExpW.Current();
1061 if(aType2==TopAbs_SHELL) {
1062 // create wire as boundary contour if shell is no closed
1063 // get free boundary shapes
1064 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
1065 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1066 //TopExp_Explorer anExp;
1067 Standard_Integer NbWires = 0;
1068 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1070 aWire2 = anExp.Current();
1075 Standard_ConstructionError::Raise("Bad shell is used as section ");
1078 else { // aType2==TopAbs_FACE
1079 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1080 aWire2 = aExpW.Current();
1082 // make pipe using aWire1 and aWire2
1083 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1084 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1085 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1086 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1087 aWithContact, aWithCorrect);
1088 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1089 aWithContact, aWithCorrect);
1090 if(!aBuilder.IsReady()) {
1092 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1095 TopoDS_Shape aShape = aBuilder.Shape();
1096 TopoDS_Shell aShell;
1097 B.MakeShell(aShell);
1098 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1099 B.Add(aShell,anExp.Current());
1101 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1102 B.Add(aShell,anExp.Current());
1104 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1105 B.Add(aShell,anExp.Current());
1107 // make sewing for this shell
1108 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1109 aSewing->SetTolerance(Precision::Confusion());
1110 aSewing->SetFaceMode(Standard_True);
1111 aSewing->SetFloatingEdgesMode(Standard_False);
1112 aSewing->SetNonManifoldMode(Standard_False);
1113 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1114 aSewing->Add(anExp.Current());
1117 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1118 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1119 aShell = TopoDS::Shell(aSewShape);
1120 GProp_GProps aSystem;
1121 BRepGProp::VolumeProperties(aShell, aSystem);
1122 if(aSystem.Mass()<0) {
1125 if(BRep_Tool::IsClosed(aShell)) {
1126 TopoDS_Solid aSolid;
1127 B.MakeSolid(aSolid);
1128 B.Add(aSolid,aShell);
1129 B.Add(aComp,aSolid);
1132 B.Add(aComp,aShell);
1136 B.Add(aComp,aShell);
1141 // main block - creation few solids (for each pair of faces)
1142 TopTools_MapOfShape aFaces1,aFaces2;
1143 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1144 aFaces1.Add(anExp.Current());
1146 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1147 aFaces2.Add(anExp.Current());
1149 // creating map of edge faces
1150 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1151 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1152 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1153 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1155 // constuct map face->face
1156 TopTools_IndexedDataMapOfShapeShape FF;
1157 TopoDS_Shape FS1,FS2;
1159 // find edge the most distant from location point
1160 // (this edge is not shared by two faces)
1161 double maxdist = 0.;
1163 TopoDS_Vertex V11,V21;
1164 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1165 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1166 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1167 if(aList.Extent()>1)
1169 TopExp_Explorer expv;
1170 expv.Init( tmp, TopAbs_VERTEX );
1171 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1173 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1174 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1175 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1176 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1181 TopTools_ListIteratorOfListOfShape anIter(aList);
1182 FS1 = anIter.Value();
1186 // main direction for comparing
1187 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1188 // find corresponding edge from next section
1190 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1191 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1193 TopoDS_Vertex V12,V22;
1194 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1195 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1196 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1197 if(aList.Extent()>1)
1199 TopExp_Explorer expv;
1200 expv.Init( tmp, TopAbs_VERTEX );
1201 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1203 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1204 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1205 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1206 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1207 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1208 TopoDS_Vertex V1,V2;
1211 V1 = V2tmp; P1 = P2tmp;
1212 V2 = V1tmp; P2 = P1tmp;
1215 V1 = V1tmp; P1 = P1tmp;
1216 V2 = V2tmp; P2 = P2tmp;
1218 gp_Vec Vec1(P11,P1);
1219 gp_Vec Vec2(P21,P2);
1220 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1225 TopTools_ListIteratorOfListOfShape anIter(aList);
1226 FS2 = anIter.Value();
1230 // put all pairs to map FF
1236 // add pairs of edges to FF
1237 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1240 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1246 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1247 if(anItem.IsNull()) {
1249 Standard_ConstructionError::Raise("Invalid subbase shape");
1251 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1252 if(aRefBase.IsNull()) {
1254 Standard_ConstructionError::Raise("Invalid subbase shape");
1256 TopoDS_Shape aSh = aRefBase->GetValue();
1259 Standard_ConstructionError::Raise("Invalid subbase shape");
1261 if(aSh.ShapeType()!=TopAbs_FACE) {
1263 Standard_ConstructionError::Raise("Invalid subbase shape");
1268 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1269 if(anItem.IsNull()) {
1271 Standard_ConstructionError::Raise("Invalid subbase shape");
1273 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1274 if(aRefBase.IsNull()) {
1276 Standard_ConstructionError::Raise("Invalid subbase shape");
1278 TopoDS_Shape aSh = aRefBase->GetValue();
1281 Standard_ConstructionError::Raise("Invalid subbase shape");
1283 if(aSh.ShapeType()!=TopAbs_FACE) {
1285 Standard_ConstructionError::Raise("Invalid subbase shape");
1290 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
1292 Standard_ConstructionError::Raise("Invalid subbase shape");
1297 // add pairs of edges to FF
1298 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1299 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1302 Standard_ConstructionError::Raise("Can not create correct pipe");
1306 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1309 // make pipe for each pair of faces
1310 for(j=1; j<=FF.Extent(); j++) {
1311 TopoDS_Shape F1 = FF.FindKey(j);
1312 if( F1.ShapeType() != TopAbs_FACE )
1314 TopoDS_Shape F2 = FF.FindFromIndex(j);
1315 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1316 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1317 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1318 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1319 // make pipe using aWire1 and aWire2
1320 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1321 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1322 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1323 aWithContact, aWithCorrect);
1324 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1325 aWithContact, aWithCorrect);
1326 if(!aBuilder.IsReady()) {
1328 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1331 TopoDS_Shape aShape = aBuilder.Shape();
1332 TopoDS_Shell aShell;
1333 B.MakeShell(aShell);
1334 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1335 B.Add(aShell,anExp.Current());
1340 // make sewing for this shell
1341 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1342 aSewing->SetTolerance(Precision::Confusion());
1343 aSewing->SetFaceMode(Standard_True);
1344 aSewing->SetFloatingEdgesMode(Standard_False);
1345 aSewing->SetNonManifoldMode(Standard_False);
1346 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1347 aSewing->Add(anExp.Current());
1350 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1351 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1352 aShell = TopoDS::Shell(aSewShape);
1353 GProp_GProps aSystem;
1354 BRepGProp::VolumeProperties(aShell, aSystem);
1355 if(aSystem.Mass()<0) {
1356 //cout<<"aSewShape is reversed"<<endl;
1359 if(BRep_Tool::IsClosed(aShell)) {
1360 TopoDS_Solid aSolid;
1361 B.MakeSolid(aSolid);
1362 B.Add(aSolid,aShell);
1363 B.Add(aComp,aSolid);
1366 B.Add(aComp,aShell);
1370 B.Add(aComp,aShell);
1378 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1383 //=======================================================================
1384 //function : CreatePipeShellsWithoutPath
1385 //purpose : auxilary for Execute()
1386 //=======================================================================
1387 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1389 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1393 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1395 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1396 // vertex for recognition
1397 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1399 Standard_Integer nbBases = aBasesObjs->Length(),
1400 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1402 if( nbv != nbBases ) {
1404 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1408 TopTools_SequenceOfShape SecVs,Bases;
1409 for(i=1; i<=nbBases; i++) {
1411 Handle(Standard_Transient) anItem = VObjs->Value(i);
1414 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1415 TopoDS_Shape V = aRef->GetValue();
1416 if(V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1420 anItem = aBasesObjs->Value(i);
1423 aRef = Handle(GEOM_Function)::DownCast(anItem);
1424 TopoDS_Shape aSh = aRef->GetValue();
1429 nbv = SecVs.Length();
1430 nbBases = Bases.Length();
1431 if( nbv != nbBases ) {
1433 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1436 TopoDS_Compound aComp;
1437 B.MakeCompound(aComp);
1439 for(i=1 ; i<nbBases; i++) {
1440 cout<<"Make pipe between sections "<<i<<" and "<<i+1<<endl;
1441 TopoDS_Shape aShBase1 = Bases.Value(i);
1442 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1443 TopExp_Explorer anExp;
1444 Standard_Integer nbf1 = 0;
1445 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1448 Standard_Integer nbf2 = 0;
1449 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1452 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1455 Standard_ConstructionError::Raise("Different number of faces in the sections");
1458 TopTools_MapOfShape aFaces1,aFaces2;
1459 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1460 aFaces1.Add(anExp.Current());
1462 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1463 aFaces2.Add(anExp.Current());
1466 // creating map of edge faces
1467 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1468 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1469 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1470 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1472 // constuct map face->face (and subshapes)
1473 TopTools_IndexedDataMapOfShapeShape FF;
1474 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1475 TopoDS_Shape FS1, FS2;
1476 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1477 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1478 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1481 cout<<" first pair of corresponding faces is found"<<endl;
1483 // add pairs of edges and vertexes to FF
1484 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1487 Standard_ConstructionError::Raise("Can not create correct pipe");
1489 cout<<" correspondences for subshapes of first pair of faces is found"<<endl;
1491 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1492 cout<<" other correspondences is found, make pipe for all pairs of faces"<<endl;
1494 // make pipe for each pair of faces
1495 // auxilary map vertex->edge for created pipe edges
1496 TopTools_IndexedDataMapOfShapeShape VPE;
1497 ShapeAnalysis_Edge sae;
1498 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1500 for(j=1; j<=FF.Extent(); j++) {
1501 TopoDS_Shape F1 = FF.FindKey(j);
1502 if( F1.ShapeType() != TopAbs_FACE )
1504 TopoDS_Shape F2 = FF.FindFromIndex(j);
1507 //if(nbff!=3) continue;
1509 cout<<" make pipe for "<<nbff<<" face"<<endl;
1511 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1512 if(S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1513 Handle(Geom_RectangularTrimmedSurface) RTS =
1514 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1515 S1 = RTS->BasisSurface();
1517 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1518 if( Pln1.IsNull() ) {
1520 Standard_ConstructionError::Raise("Surface from face is not plane");
1522 gp_Vec aDir1(Pln1->Axis().Direction());
1524 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1525 if(S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1526 Handle(Geom_RectangularTrimmedSurface) RTS =
1527 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1528 S2 = RTS->BasisSurface();
1530 Handle(Geom_Plane) Pln2 =
1531 Handle(Geom_Plane)::DownCast(S2);
1532 if( Pln2.IsNull() ) {
1534 Standard_ConstructionError::Raise("Surface from face is not plane");
1536 gp_Vec aDir2(Pln2->Axis().Direction());
1538 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1539 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1541 if(fabs(aDir.Angle(aDir1))>PI/2.)
1543 if(fabs(aDir.Angle(aDir2))>PI/2.)
1546 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1547 TopTools_SequenceOfShape aNewFs;
1549 for(; anExpE.More(); anExpE.Next()) {
1550 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1552 if(!FF.Contains(E1))
1553 cout<<"map FF not contains key E1"<<endl;
1555 if(VPE.Contains(E1)) {
1556 aNewFs.Append(VPE.FindFromKey(E1));
1558 cout<<" using existed face"<<endl;
1563 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1564 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1565 TopoDS_Vertex V2 = sae.LastVertex(E1);
1566 if(!FF.Contains(V1))
1567 cout<<"map FF not contains key V1"<<endl;
1568 if(!FF.Contains(V2))
1569 cout<<"map FF not contains key V2"<<endl;
1570 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1571 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1572 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1575 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1576 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1577 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1578 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1581 Handle(Geom_BSplineCurve) C2;
1582 if(VPE.Contains(V2)) {
1583 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1585 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1588 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1589 HAP->SetValue(1,P2);
1590 HAP->SetValue(2,P3);
1591 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1592 anInt.Load(aDir1,aDir2);
1595 B.MakeEdge(E2,C2,1.e-7);
1596 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1597 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1602 Handle(Geom_BSplineCurve) C4;
1603 if(VPE.Contains(V1)) {
1604 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1606 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1609 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1610 HAP->SetValue(1,P1);
1611 HAP->SetValue(2,P4);
1612 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1613 anInt.Load(aDir1,aDir2);
1616 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1617 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1618 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1627 B.Add(W,E4.Reversed());
1628 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1629 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1634 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1635 //bool IsConicC1 = false;
1636 //if( C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1637 // IsConicC1 = true;
1638 // cout<<"C1 - Geom_Conic"<<endl;
1640 if( C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1641 C1 = new Geom_TrimmedCurve(C1,fp,lp);
1644 // double tol = BRep_Tool::Tolerance(E1);
1645 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
1646 // C1 = ApxC1.Curve();
1648 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
1649 if( C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1650 C3 = new Geom_TrimmedCurve(C3,fp,lp);
1655 Handle(Geom_BSplineCurve) CE1 =
1656 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
1658 CE1->IncreaseDegree(3);
1659 Handle(Geom_BSplineCurve) CE2 =
1660 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
1662 CE2->IncreaseDegree(3);
1663 Handle(Geom_BSplineCurve) CE3 =
1664 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
1666 CE3->IncreaseDegree(3);
1667 Handle(Geom_BSplineCurve) CE4 =
1668 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
1670 CE4->IncreaseDegree(3);
1671 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
1672 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
1673 //if(fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
1674 // os<<"DrawTrSurf_BSplineCurve"<<endl;
1675 // GeomTools::Write(CE1,os);
1679 Handle(Geom_Surface) BS;
1681 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
1682 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
1686 cout<<" can not create BSplineSurface - create Bezier"<<endl;
1688 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
1689 double fp1,lp1,fp2,lp2;
1690 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
1691 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
1700 // get points from C1
1701 if(P1.Distance(P1C1)<1.e-6) {
1709 double step = (lp-fp)/(NbP-1);
1710 Points.SetValue(1,1,P1);
1712 for(n1=2; n1<NbP; n1++) {
1716 Points.SetValue(1,n1,P);
1718 Points.SetValue(1,NbP,P2);
1719 // get points from C3
1720 if(P4.Distance(P1C3)<1.e-6) {
1728 step = (lp-fp)/(NbP-1);
1729 Points.SetValue(NbP,1,P4);
1731 for(n1=2; n1<NbP; n1++) {
1735 Points.SetValue(NbP,n1,P);
1737 Points.SetValue(NbP,NbP,P3);
1738 // create isolines and get points from them
1739 for(n1=1; n1<=NbP; n1++) {
1740 gp_Pnt PI1 = Points.Value(1,n1);
1741 gp_Pnt PI2 = Points.Value(NbP,n1);
1742 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1743 HAP->SetValue(1,PI1);
1744 HAP->SetValue(2,PI2);
1745 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1746 anInt.Load(aDir1,aDir2);
1748 Handle(Geom_Curve) iso = anInt.Curve();
1749 fp = iso->FirstParameter();
1750 lp = iso->LastParameter();
1751 step = (lp-fp)/(NbP-1);
1753 TopoDS_Compound VComp;
1754 B.MakeCompound(VComp);
1755 for(n2=2; n2<NbP; n2++) {
1759 Points.SetValue(n2,n1,P);
1762 // create surface and face
1763 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
1764 BS = new Geom_BezierSurface(Points);
1767 BRepBuilderAPI_MakeFace BB(BS,W);
1768 TopoDS_Face NewF = BB.Face();
1769 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
1771 sff->FixOrientation();
1772 TopoDS_Face FixedFace = sff->Face();
1773 aNewFs.Append(FixedFace);
1774 VPE.Add(E1,FixedFace);
1775 //cout<<" face for edge "<<nbee<<" is created"<<endl;
1776 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
1779 TopoDS_Shell aShell;
1780 B.MakeShell(aShell);
1781 for(int nf=1; nf<=aNewFs.Length(); nf++) {
1782 B.Add(aShell,aNewFs(nf));
1787 // make sewing for this shell
1788 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1789 aSewing->SetTolerance(Precision::Confusion());
1790 aSewing->SetFaceMode(Standard_True);
1791 aSewing->SetFloatingEdgesMode(Standard_False);
1792 aSewing->SetNonManifoldMode(Standard_False);
1793 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1794 aSewing->Add(anExp.Current());
1797 cout<<" shell for face "<<nbff<<" is created"<<endl;
1798 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1799 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
1800 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1801 aShell = TopoDS::Shell(aSewShape);
1802 GProp_GProps aSystem;
1803 BRepGProp::VolumeProperties(aShell, aSystem);
1804 if(aSystem.Mass()<0) {
1805 //cout<<"aSewShape is reversed"<<endl;
1808 if(BRep_Tool::IsClosed(aShell)) {
1809 TopoDS_Solid aSolid;
1810 B.MakeSolid(aSolid);
1811 B.Add(aSolid,aShell);
1812 B.Add(aComp,aSolid);
1813 cout<<" solid for face "<<nbff<<" is created"<<endl;
1816 B.Add(aComp,aShell);
1817 cout<<" solid for face "<<nbff<<" is not created"<<endl;
1821 B.Add(aComp,aShell);
1822 cout<<" solid for face "<<nbff<<" is not created"<<endl;
1824 //cout<<" solid for face "<<nbff<<" is created"<<endl;
1826 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
1828 //TopoDS_Shell FixedShell = sfs->Shell();
1830 GProp_GProps aSystem;
1831 BRepGProp::VolumeProperties(FixedShell, aSystem);
1832 if(aSystem.Mass()<0) {
1833 //cout<<"aSewShape is reversed"<<endl;
1834 FixedShell.Reverse();
1836 if(BRep_Tool::IsClosed(FixedShell)) {
1837 TopoDS_Solid aSolid;
1838 B.MakeSolid(aSolid);
1839 B.Add(aSolid,aShell);
1840 B.Add(aComp,aSolid);
1843 B.Add(aComp,FixedShell);
1849 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1854 //=======================================================================
1855 //function : Execute
1857 //=======================================================================
1858 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1860 //cout<<"PipeDriver::Execute"<<endl;
1861 if (Label().IsNull()) return 0;
1862 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1863 GEOMImpl_IPipe* aCI= 0;
1864 Standard_Integer aType = aFunction->GetType();
1865 if(aType == PIPE_BASE_PATH)
1866 aCI = new GEOMImpl_IPipe(aFunction);
1867 else if(aType == PIPE_DIFFERENT_SECTIONS)
1868 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1869 else if(aType == PIPE_SHELL_SECTIONS)
1870 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1871 else if(aType == PIPE_SHELLS_WITHOUT_PATH)
1872 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1876 TopoDS_Wire aWirePath;
1877 if(aType != PIPE_SHELLS_WITHOUT_PATH) {
1878 // working with path
1879 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1880 TopoDS_Shape aShapePath = aRefPath->GetValue();
1882 if (aShapePath.IsNull()) {
1883 cout<<"Driver : path is null"<<endl;
1885 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1889 if (aShapePath.ShapeType() == TopAbs_WIRE) {
1890 aWirePath = TopoDS::Wire(aShapePath);
1893 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1894 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1895 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1899 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1904 TopoDS_Shape aShape;
1906 if (aType == PIPE_BASE_PATH)
1908 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1909 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1911 if (aShapeBase.IsNull()) {
1913 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1917 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
1920 //building pipe with different sections
1921 else if (aType == PIPE_DIFFERENT_SECTIONS) {
1922 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
1923 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
1924 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1925 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
1926 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
1927 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
1928 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1930 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
1931 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
1933 if(nbLocs && nbLocs != nbBases) {
1935 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
1937 TopTools_SequenceOfShape aSeqBases;
1938 TopTools_SequenceOfShape aSeqLocs;
1939 TopTools_SequenceOfShape aSeqFaces;
1940 for( ; i <= nbBases; i++) {
1941 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
1944 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1945 if(aRefBase.IsNull())
1947 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1948 if(aShapeBase.IsNull())
1950 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
1952 //if for section was specified face with a few wires then a few
1953 // pipes were build and make solid
1954 Standard_Boolean NeedCreateSolid = Standard_False;
1955 if(aTypeBase == TopAbs_SHELL) {
1956 // create wire as boundary contour if shell is no closed
1957 // get free boundary shapes
1958 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
1959 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1960 TopExp_Explorer anExp;
1962 Standard_Integer NbWires = 0;
1963 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1965 aWire = anExp.Current();
1970 Standard_ConstructionError::Raise("Bad shell is used as section ");
1972 NeedCreateSolid = Standard_True;
1973 aSeqFaces.Append(aShapeBase);
1974 aSeqBases.Append(aWire);
1976 else if(aTypeBase == TopAbs_FACE) {
1977 NeedCreateSolid = Standard_True;
1978 //for case one path should be used other type function
1979 aSeqFaces.Append(aShapeBase);
1980 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
1981 for( ; aExpW.More(); aExpW.Next())
1983 TopoDS_Shape aWireProf = aExpW.Current();
1984 aSeqBases.Append(aWireProf);
1987 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
1988 aSeqBases.Append(aShapeBase);
1990 else if(aTypeBase == TopAbs_EDGE) {
1991 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
1992 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
1993 aSeqBases.Append(aWireProf);
1996 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
1997 if(anItemLoc.IsNull())
1999 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2000 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2001 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2003 aSeqLocs.Append(aShapeLoc);
2007 nbLocs = aSeqLocs.Length();
2010 TopTools_SequenceOfShape Edges;
2012 // we have to check that each location shape is a vertex from
2013 // path and update aSeqLocs if it is needed (and possible)
2014 TColgp_SequenceOfPnt PLocs;
2015 for(i=1; i<=nbLocs; i++) {
2016 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
2017 PLocs.Append(BRep_Tool::Pnt(V));
2019 //TopTools_SequenceOfShape Edges;
2020 TopExp_Explorer anExp;
2021 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
2022 Edges.Append(anExp.Current());
2024 int nbEdges = Edges.Length();
2025 ShapeAnalysis_Edge sae;
2026 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
2027 double tol = BRep_Tool::Tolerance(edge);
2028 TopoDS_Vertex VF = sae.FirstVertex(edge);
2029 gp_Pnt PF = BRep_Tool::Pnt(VF);
2030 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
2031 if( PF.Distance(PLocs.First()) > tol ) {
2033 Standard_ConstructionError::Raise
2034 ("First location shapes is not coincided with first vertex of aWirePath");
2036 aSeqLocs.ChangeValue(1) = VF;
2037 edge = TopoDS::Edge(Edges.Last());
2038 tol = BRep_Tool::Tolerance(edge);
2039 TopoDS_Vertex VL = sae.LastVertex(edge);
2040 gp_Pnt PL = BRep_Tool::Pnt(VL);
2041 if( PL.Distance(PLocs.Last()) > tol ) {
2043 Standard_ConstructionError::Raise
2044 ("Last location shapes is not coincided with last vertex of aWirePath");
2046 aSeqLocs.ChangeValue(nbLocs) = VL;
2048 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
2049 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
2050 tol = BRep_Tool::Tolerance(edge);
2051 TopoDS_Vertex V1 = sae.FirstVertex(E);
2052 TopoDS_Vertex V2 = sae.LastVertex(E);
2053 gp_Pnt P1 = BRep_Tool::Pnt(V1);
2054 gp_Pnt P2 = BRep_Tool::Pnt(V2);
2055 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
2056 aSeqLocs.ChangeValue(jcurr) = V2;
2060 // find distance between E and aLocs(jcurr)
2062 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
2063 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
2064 if( PPC.NbPoints()>0 &&
2065 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
2066 double param = PPC.Parameter(1);
2069 // split current edge
2070 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
2071 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
2076 if(Pfp.Distance(P1)<tol) {
2077 B.MakeEdge(E1,tc1,tol);
2079 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2080 B.Add(E1,TopoDS::Vertex(tmpV));
2081 B.MakeEdge(E2,tc2,tol);
2082 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2083 B.Add(E2,TopoDS::Vertex(tmpV));
2087 B.MakeEdge(E1,tc2,tol);
2088 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2089 B.Add(E1,TopoDS::Vertex(tmpV));
2092 B.MakeEdge(E2,tc1,tol);
2094 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2095 B.Add(E2,TopoDS::Vertex(tmpV));
2100 Edges.InsertAfter(i-1,E1);
2101 Edges.InsertAfter(i,E2);
2105 if(nbEdges<Edges.Length()) {
2106 // one of edges was splitted => we have to update WirePath
2110 for(i=1; i<=Edges.Length(); i++) {
2111 B.Add(W,TopoDS::Edge(Edges.Value(i)));
2117 // check curvature of wire for condition that
2118 // max summary angle between directions along
2119 // wire path must be < 4*PI. If not - split wire
2120 // and seguences of shapes, perform pipe for each
2121 // and make sewing after that
2123 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
2128 double SumAng = fabs(Vec1.Angle(Vec2));
2131 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
2133 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
2134 for(i=2; i<=Edges.Length(); i++) {
2135 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
2136 double tol = BRep_Tool::Tolerance(edge);
2137 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
2139 double ang = fabs(Vec1.Angle(Vec2));
2143 SplitEdgeNums.Append(i-1);
2145 for(j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
2146 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
2147 gp_Pnt P = BRep_Tool::Pnt(aVert);
2148 if( P1.Distance(P) < tol ) {
2149 SplitLocNums.Append(j);
2159 //cout<<"SplitEdgeNums.Length()="<<SplitEdgeNums.Length()<<endl;
2160 //cout<<"SplitLocNums.Length()="<<SplitLocNums.Length()<<endl;
2161 if( SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0 ) {
2162 TopTools_SequenceOfShape aSeqRes;
2163 int nn, num1 = 1, num2 = 1;
2164 for(nn=1; nn<=SplitEdgeNums.Length(); nn++) {
2165 // create wirepath and sequences of shapes
2169 for(i=num1; i<=SplitEdgeNums.Value(nn); i++) {
2170 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2172 num1 = SplitEdgeNums.Value(nn) + 1;
2173 TopTools_SequenceOfShape aTmpSeqBases;
2174 TopTools_SequenceOfShape aTmpSeqLocs;
2175 for(i=num2; i<=SplitLocNums.Value(nn); i++) {
2176 aTmpSeqBases.Append(aSeqBases.Value(i));
2177 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2179 num2 = SplitLocNums.Value(nn);
2181 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2182 Standard_Integer nbShapes = aTmpSeqBases.Length();
2183 for(i=1; i<=nbShapes; i++) {
2184 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2185 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2186 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2188 if(!aBuilder.IsReady()) {
2190 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2193 TopoDS_Shape resShape = aBuilder.Shape();
2194 aSeqRes.Append(resShape);
2196 // create wirepath and sequences of shapes for last part
2200 for(i=num1; i<=Edges.Length(); i++) {
2201 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2203 TopTools_SequenceOfShape aTmpSeqBases;
2204 TopTools_SequenceOfShape aTmpSeqLocs;
2205 for(i=num2; i<=aSeqLocs.Length(); i++) {
2206 aTmpSeqBases.Append(aSeqBases.Value(i));
2207 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2209 // make pipe for last part
2210 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2211 Standard_Integer nbShapes = aTmpSeqBases.Length();
2212 for(i=1; i<=nbShapes; i++) {
2213 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2214 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2215 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2217 if(!aBuilder.IsReady()) {
2219 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2222 TopoDS_Shape resShape = aBuilder.Shape();
2223 aSeqRes.Append(resShape);
2224 // make sewing for result
2225 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2226 aSewing->SetTolerance(Precision::Confusion());
2227 aSewing->SetFaceMode(Standard_True);
2228 aSewing->SetFloatingEdgesMode(Standard_False);
2229 aSewing->SetNonManifoldMode(Standard_False);
2230 for(i=1; i<=aSeqRes.Length(); i++) {
2231 aSewing->Add(aSeqRes.Value(i));
2234 aShape = aSewing->SewedShape();
2237 // old implementation without splitting
2238 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2240 Standard_Integer nbShapes = aSeqBases.Length();
2241 Standard_Integer step = nbShapes/nbBases;
2243 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
2245 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
2247 Standard_Integer ind =0;
2248 for( i=1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
2249 TopTools_SequenceOfShape usedBases;
2250 Standard_Integer j = 1;
2251 for( ; j <= nbBases ; j++) {
2252 ind = i + (j-1)*step;
2253 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
2254 usedBases.Append(aWireProf);
2256 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
2257 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2258 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
2261 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
2263 if(!aBuilder.IsReady()) {
2265 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2268 aShape = aBuilder.Shape();
2269 aSeqFaces.Append(aShape);
2270 for( j = 1; j <=usedBases.Length(); j++)
2271 aBuilder.Delete(usedBases.Value(j));
2274 //for case if section is face
2275 if(aSeqFaces.Length() >1) {
2277 TopoDS_Compound aComp;
2278 aB.MakeCompound(aComp);
2279 for( i = 1; i <= aSeqFaces.Length(); i++)
2280 aB.Add(aComp,aSeqFaces.Value(i));
2286 //building pipe with shell sections
2287 else if (aType == PIPE_SHELL_SECTIONS) {
2288 aShape = CreatePipeForShellSections(aWirePath,aCI);
2291 //building pipe shell sections without path
2292 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2293 aShape = CreatePipeShellsWithoutPath(aCI);
2301 if (aShape.IsNull()) return 0;
2303 BRepCheck_Analyzer ana (aShape, Standard_False);
2304 if (!ana.IsValid()) {
2305 ShapeFix_ShapeTolerance aSFT;
2306 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2307 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2308 aSfs->SetPrecision(Precision::Confusion());
2310 aShape = aSfs->Shape();
2312 ana.Init(aShape, Standard_False);
2314 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2317 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
2318 aFunction->SetValue(aRes);
2320 log.SetTouched(Label());
2325 //=======================================================================
2326 //function : GEOMImpl_PipeDriver_Type_
2328 //=======================================================================
2329 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2332 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2333 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2334 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2335 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2336 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2337 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2340 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2341 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2342 sizeof(GEOMImpl_PipeDriver),
2344 (Standard_Address)_Ancestors,
2345 (Standard_Address)NULL);
2350 //=======================================================================
2351 //function : DownCast
2353 //=======================================================================
2354 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2356 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2358 if (!AnObject.IsNull()) {
2359 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2360 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2364 return _anOtherObject ;