1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_PipeDriver.hxx>
27 #include <GEOMImpl_IShapesOperations.hxx>
28 #include <GEOMImpl_IPipeDiffSect.hxx>
29 #include <GEOMImpl_IPipeShellSect.hxx>
30 #include <GEOMImpl_IPipeBiNormal.hxx>
31 #include <GEOMImpl_IPipe.hxx>
32 #include <GEOMImpl_GlueDriver.hxx>
33 #include <GEOMImpl_Types.hxx>
34 #include <GEOM_Function.hxx>
36 //#include <GEOMAlgo_GlueAnalyser.hxx>
38 #include <ShapeAnalysis_FreeBounds.hxx>
39 #include <ShapeAnalysis_Edge.hxx>
40 #include <ShapeFix_Face.hxx>
41 #include <ShapeFix_Shell.hxx>
42 #include <ShapeFix_Shape.hxx>
43 #include <ShapeFix_ShapeTolerance.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRep_Builder.hxx>
47 #include <BRepBuilderAPI_MakeWire.hxx>
48 #include <BRepBuilderAPI_Sewing.hxx>
49 #include <BRepCheck_Analyzer.hxx>
50 #include <BRepOffsetAPI_MakePipe.hxx>
51 #include <BRepOffsetAPI_MakePipeShell.hxx>
52 #include <GProp_GProps.hxx>
53 #include <BRepGProp.hxx>
54 #include <BRepBuilderAPI_MakeFace.hxx>
55 #include <BRepBuilderAPI_Copy.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopoDS_Wire.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopoDS_Solid.hxx>
65 #include <TopoDS_Shell.hxx>
66 #include <TopoDS_Face.hxx>
67 #include <TopoDS_Compound.hxx>
68 #include <TopTools_SequenceOfShape.hxx>
69 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
70 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
73 #include <GeomAPI_ProjectPointOnCurve.hxx>
74 #include <GeomAPI_Interpolate.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_BezierSurface.hxx>
79 #include <Geom_Line.hxx>
80 #include <Geom_Conic.hxx>
81 #include <Geom_BSplineCurve.hxx>
82 #include <Geom_BSplineSurface.hxx>
83 #include <GeomFill_BSplineCurves.hxx>
84 #include <GeomConvert_ApproxCurve.hxx>
85 #include <GeomConvert.hxx>
87 #include <TColgp_SequenceOfPnt.hxx>
88 #include <TColgp_HArray1OfPnt.hxx>
89 #include <TColgp_Array2OfPnt.hxx>
90 #include <TColStd_HSequenceOfTransient.hxx>
92 #include <Precision.hxx>
93 #include <Standard_NullObject.hxx>
94 #include <Standard_TypeMismatch.hxx>
95 #include <Standard_ConstructionError.hxx>
97 #include "utilities.h"
99 //=======================================================================
102 //=======================================================================
103 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
105 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
109 //=======================================================================
110 //function : GEOMImpl_PipeDriver
112 //=======================================================================
113 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)) {
193 //=======================================================================
194 //function : FillCorrespondingEdges
195 //purpose : auxilary for CreatePipeForShellSections()
196 //=======================================================================
197 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
198 const TopoDS_Shape& FS2,
199 const TopoDS_Vertex& aLoc1,
200 const TopoDS_Vertex& aLoc2,
201 const TopoDS_Wire& aWirePath,
202 TopTools_IndexedDataMapOfShapeShape& FF)
204 //cout<<"FillCorrespondingEdges"<<endl;
205 // find corresponding edges
206 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
207 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
208 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
209 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
210 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
211 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
212 aBuilder.Add(aWire1, aLoc1);
213 aBuilder.Add(aWire2, aLoc2);
214 if(!aBuilder.IsReady()) {
218 TopoDS_Shape aShape = aBuilder.Shape();
226 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
228 ShapeAnalysis_Edge sae;
229 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
230 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
231 TopTools_MapOfShape Vs1,Vs2;
233 exp.Init( FS1, TopAbs_EDGE );
234 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
235 TopoDS_Vertex V11 = sae.FirstVertex(E1);
236 TopoDS_Vertex V21 = sae.LastVertex(E1);
237 gp_Pnt P11 = BRep_Tool::Pnt(V11);
238 gp_Pnt P21 = BRep_Tool::Pnt(V21);
239 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
240 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
241 // find corresponding vertexes from created shape
242 TopoDS_Vertex VN11,VN21;
243 for( exp.Init( aShape, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
244 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
245 gp_Pnt P = BRep_Tool::Pnt(V);
246 if(P.Distance(P11)<tol) {
249 if(P.Distance(P21)<tol) {
253 // find edge contains VN11 and VN21 and corresponding vertexes
254 TopoDS_Vertex VN12,VN22;
255 for( exp.Init( aShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
256 TopoDS_Shape F = exp.Current();
257 TopExp_Explorer expe;
259 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
260 TopoDS_Edge E = TopoDS::Edge(expe.Current());
261 TopoDS_Vertex VF = sae.FirstVertex(E);
262 TopoDS_Vertex VL = sae.LastVertex(E);
263 if( (VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11)) ) {
269 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
270 TopoDS_Edge E = TopoDS::Edge(expe.Current());
271 TopoDS_Vertex VF = sae.FirstVertex(E);
272 TopoDS_Vertex VL = sae.LastVertex(E);
273 if( VF.IsSame(VN11) && !VL.IsSame(VN21) )
275 if( VL.IsSame(VN11) && !VF.IsSame(VN21) )
277 if( VF.IsSame(VN21) && !VL.IsSame(VN11) )
279 if( VL.IsSame(VN21) && !VF.IsSame(VN11) )
285 // find vertexes from FS2 corresponded to VN12 and VN22
286 // and find edge from FS2 contains V12 and V22,
287 // this edge will be corresponded to edge E1
288 TopoDS_Vertex V12,V22;
289 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
290 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
291 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
292 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
294 TopExp_Explorer expe;
295 for( expe.Init( FS2, TopAbs_EDGE ); expe.More(); expe.Next() ) {
296 TopoDS_Edge E = TopoDS::Edge(expe.Current());
297 TopoDS_Vertex VF = sae.FirstVertex(E);
298 TopoDS_Vertex VL = sae.LastVertex(E);
299 gp_Pnt PF = BRep_Tool::Pnt(VF);
300 gp_Pnt PL = BRep_Tool::Pnt(VL);
301 if( PF.Distance(PN12)<tol && PL.Distance(PN22)<tol ) {
307 if( PF.Distance(PN22)<tol && PL.Distance(PN12)<tol ) {
318 // find other pairs for vertexes and edges
319 // creating map of vertex edges for both faces
320 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);
427 //=======================================================================
428 //function : FindNextPairOfFaces
429 //purpose : auxilary for CreatePipeForShellSections()
430 //=======================================================================
431 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
432 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
433 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
434 TopTools_IndexedDataMapOfShapeShape& FF,
437 //cout<<"FindNextPairOfFaces"<<endl;
438 TopExp_Explorer anExp;
439 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
440 TopoDS_Shape E1 = anExp.Current();
441 if(!FF.Contains(E1)) {
443 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
446 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
447 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
448 TopExp_Explorer anExpV;
449 anExpV.Init( E1, TopAbs_VERTEX );
450 TopoDS_Shape V1 = anExpV.Current();
451 if(!FF.Contains(V1)) {
453 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
456 if(!aMapEdgeFaces1.Contains(E1))
457 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
458 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
459 if(aList1.Extent()<2)
461 TopTools_ListIteratorOfListOfShape anIter(aList1);
462 if(anIter.Value().IsEqual(aCurFace)) {
465 TopoDS_Shape F1other = anIter.Value();
466 if(FF.Contains(F1other))
469 if(!FF.Contains(aCurFace))
470 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
471 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
472 if(!aMapEdgeFaces2.Contains(E2))
473 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
474 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
475 if(aList2.Extent()<2) {
477 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
479 TopTools_ListIteratorOfListOfShape anIter2(aList2);
480 if(anIter2.Value().IsEqual(F2)) {
483 TopoDS_Shape F2other = anIter2.Value();
484 FF.Add(F1other,F2other);
486 // add pairs of edges to FF
487 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
490 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
493 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
497 //=======================================================================
498 //function : FindFirstPairFaces
499 //purpose : auxilary for Execute()
500 //=======================================================================
501 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
502 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
503 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
505 //cout<<"FindFirstPairFaces"<<endl;
507 // check if vertexes are subshapes of sections
508 gp_Pnt P1 = BRep_Tool::Pnt(V1);
509 gp_Pnt P2 = BRep_Tool::Pnt(V2);
510 TopoDS_Vertex V1new,V2new;
512 double mindist = 1.e10;
513 for( exp.Init( S1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
514 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
515 gp_Pnt P = BRep_Tool::Pnt(V);
516 double dist = P1.Distance(P);
523 for( exp.Init( S2, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
524 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
525 gp_Pnt P = BRep_Tool::Pnt(V);
526 double dist = P2.Distance(P);
533 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
534 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
535 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
536 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
537 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
538 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
540 // replace vertexes if it is needed
541 if(!V1.IsSame(V1new)) {
543 P1 = BRep_Tool::Pnt(V1);
544 MESSAGE (" replace V1");
547 MESSAGE (" not replace V1");
548 if(!V2.IsSame(V2new)) {
550 P2 = BRep_Tool::Pnt(V2);
551 MESSAGE (" replace V2");
554 MESSAGE (" not replace V2");
556 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
557 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
558 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
559 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
561 if(!aMapVertFaces1.Contains(V1))
562 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
563 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
564 TopTools_ListIteratorOfListOfShape anIter1(aList1);
565 FS1 = anIter1.Value();
567 double x1=0., y1=0., z1=0.;
569 for( exp.Init( FS1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
570 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
571 gp_Pnt P = BRep_Tool::Pnt(V);
577 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
579 TColgp_SequenceOfPnt Ps;
580 TopTools_SequenceOfShape Fs;
581 if(!aMapVertFaces2.Contains(V2))
582 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
583 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
584 TopTools_ListIteratorOfListOfShape anIter2(aList2);
585 for(; anIter2.More(); anIter2.Next()) {
586 TopoDS_Shape F = anIter2.Value();
587 double x2=0., y2=0., z2=0.;
589 for( exp.Init( F, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
590 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
591 gp_Pnt P = BRep_Tool::Pnt(V);
597 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
606 for(; i<=Fs.Length(); i++) {
607 gp_Vec tmpDir(PM1,Ps(i));
608 double ang = fabs(aDir.Angle(tmpDir));
617 //=======================================================================
618 //function : CreatePipeForShellSections
619 //purpose : auxilary for Execute()
620 //=======================================================================
621 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
624 //cout<<"CreatePipeForShellSections"<<endl;
629 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
630 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
631 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
632 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
633 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
634 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
636 Standard_Integer nbBases = aBasesObjs->Length(),
637 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
638 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
640 if( nbLocs != nbBases) {
642 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
644 if( nbSubBases && nbSubBases != nbBases) {
646 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
649 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
651 TopTools_SequenceOfShape VLocs;
652 for(i=1; i<=nbBases; i++) {
653 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
654 if(anItemLoc.IsNull())
656 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
657 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
658 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
660 VLocs.Append(aShapeLoc);
662 nbLocs = VLocs.Length();
663 if( nbLocs != nbBases) {
665 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
667 // split wire path by location points
668 TColgp_SequenceOfPnt PLocs;
669 for(i=1; i<=nbLocs; i++) {
670 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
671 PLocs.Append(BRep_Tool::Pnt(V));
674 TopTools_SequenceOfShape Edges;
675 TopTools_SequenceOfShape Wires;
676 ShapeAnalysis_Edge sae;
679 TopExp_Explorer anExp;
680 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
681 Edges.Append(anExp.Current());
683 Standard_Integer Num1 = 0;
684 Standard_Integer Num2 = 0;
685 for(i=1; i<=Edges.Length(); i++) {
686 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
687 double tol = BRep_Tool::Tolerance(E);
688 TopoDS_Vertex V1 = sae.FirstVertex(E);
689 TopoDS_Vertex V2 = sae.LastVertex(E);
690 gp_Pnt P1 = BRep_Tool::Pnt(V1);
691 gp_Pnt P2 = BRep_Tool::Pnt(V2);
692 if( P1.Distance(PLocs.First()) < tol ) {
695 if( P2.Distance(PLocs.Last()) < tol ) {
699 if( Num1>0 && Num2>0 ) {
702 for(i=Num1; i<=Num2; i++) {
703 B.Add(W,Edges.Value(i));
708 Wires.Append(aWirePath);
712 TopExp_Explorer anExp;
713 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
714 Edges.Append(anExp.Current());
716 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
717 double tol = BRep_Tool::Tolerance(edge);
718 TopoDS_Vertex VF = sae.FirstVertex(edge);
719 gp_Pnt PF = BRep_Tool::Pnt(VF);
720 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
721 if( PF.Distance(PLocs.First()) > tol ) {
723 Standard_ConstructionError::Raise
724 ("First location shapes is not coincided with first vertex of aWirePath");
726 VLocs.ChangeValue(1) = VF;
727 edge = TopoDS::Edge(Edges.Last());
728 tol = BRep_Tool::Tolerance(edge);
729 TopoDS_Vertex VL = sae.LastVertex(edge);
730 gp_Pnt PL = BRep_Tool::Pnt(VL);
731 if( PL.Distance(PLocs.Last()) > tol ) {
733 Standard_ConstructionError::Raise
734 ("Last location shapes is not coincided with last vertex of aWirePath");
736 VLocs.ChangeValue(nbLocs) = VL;
738 TopTools_SequenceOfShape tmpEdges;
739 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
740 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
741 tol = BRep_Tool::Tolerance(E);
742 TopoDS_Vertex V1 = sae.FirstVertex(E);
743 TopoDS_Vertex V2 = sae.LastVertex(E);
744 gp_Pnt P1 = BRep_Tool::Pnt(V1);
745 gp_Pnt P2 = BRep_Tool::Pnt(V2);
746 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
747 // make wire from current edge and add created
751 for(j=1; j<=tmpEdges.Length(); j++)
752 B.Add(W,tmpEdges.Value(j));
755 VLocs.ChangeValue(jcurr) = V2;
760 // find distance between E and aLocs(jcurr)
762 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
763 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
764 if( PPC.NbPoints()>0 &&
765 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
766 double param = PPC.Parameter(1);
769 // split current edge
770 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
771 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
775 if(Pfp.Distance(P1)<tol) {
776 B.MakeEdge(E1,tc1,tol);
778 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
779 B.Add(E1,TopoDS::Vertex(tmpV));
781 B.MakeEdge(E2,tc2,tol);
782 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
783 B.Add(E2,TopoDS::Vertex(tmpV));
787 B.MakeEdge(E1,tc2,tol);
788 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
789 B.Add(E1,TopoDS::Vertex(tmpV));
793 B.MakeEdge(E2,tc1,tol);
795 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
796 B.Add(E2,TopoDS::Vertex(tmpV));
799 // create wire from tmpEdges
802 for(j=1; j<=tmpEdges.Length(); j++)
803 B.Add(W,tmpEdges.Value(j));
808 Edges.InsertAfter(i-1,E1);
809 Edges.InsertAfter(i,E2);
816 // create wire from other edges
819 for(; i<=Edges.Length(); i++)
820 B.Add(W,Edges.Value(i));
822 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
825 if( Wires.Length() != nbLocs-1 ) {
827 Standard_ConstructionError::Raise
828 ("One of location shapes is not lied on the path");
831 //TopTools_SequenceOfShape aSeqBases;
832 //TopTools_SequenceOfShape aSeqSubBases;
833 //TopTools_SequenceOfShape aSeqFaces;
834 TopoDS_Compound aComp;
835 B.MakeCompound(aComp);
836 for (i = 1; i < nbBases; i++) {
837 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
839 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
842 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
843 if(aRefBase1.IsNull())
845 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
846 if(aShBase1.IsNull())
848 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
850 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
853 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
854 if(aRefBase2.IsNull())
856 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
857 if(aShBase2.IsNull())
859 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
861 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
863 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
864 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
867 Standard_ConstructionError::Raise("One of section shapes has invalid type");
870 bool CreateFewSolids = false;
872 TopExp_Explorer anExp;
873 Standard_Integer nbf1 = 0;
874 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
877 Standard_Integer nbf2 = 0;
878 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
882 CreateFewSolids = true;
886 // check orientation of sections
887 bool NeedReverse = false;
890 anExp.Init( aShBase1, TopAbs_FACE );
891 TopoDS_Shape aFace = anExp.Current();
892 TColgp_SequenceOfPnt aPnts;
893 double xc=0, yc=0, zc=0;
894 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
895 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
896 aPnts.Append(BRep_Tool::Pnt(V));
897 xc += aPnts.Last().X();
898 yc += aPnts.Last().Y();
899 zc += aPnts.Last().Z();
901 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
902 gp_Vec V1(PC,aPnts.Value(1));
903 gp_Vec V2(PC,aPnts.Value(2));
904 gp_Vec VN = V1.Crossed(V2);
905 for(int ip=2; ip<aPnts.Length(); ip++) {
906 V1 = gp_Vec(PC,aPnts.Value(ip));
907 V2 = gp_Vec(PC,aPnts.Value(ip+1));
908 VN.Add(V1.Crossed(V2));
911 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
913 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
914 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
915 double tol = BRep_Tool::Tolerance(edge);
916 TopoDS_Vertex VF = sae.FirstVertex(edge);
917 gp_Pnt PF = BRep_Tool::Pnt(VF);
918 if( PF.Distance(PLoc) < tol ) {
920 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
923 if( P1.Distance(PLoc) < tol ) {
924 C->D0(fp+(lp-fp)/100,P2);
928 C->D0(lp+(fp-lp)/100,P2);
930 PathNorm = gp_Vec(P1,P2);
934 TopoDS_Vertex VL = sae.LastVertex(edge);
935 gp_Pnt PL = BRep_Tool::Pnt(VL);
936 if( PL.Distance(PLoc) < tol ) {
938 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
941 if( P1.Distance(PLoc) < tol ) {
942 C->D0(fp+(lp-fp)/100,P2);
946 C->D0(lp+(fp-lp)/100,P2);
948 PathNorm = gp_Vec(P2,P1);
953 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
954 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
955 if(fabs(VN.Angle(PathNorm))>PI/2.) {
962 anExp.Init( aShBase2, TopAbs_FACE );
963 TopoDS_Shape aFace = anExp.Current();
964 TColgp_SequenceOfPnt aPnts;
965 double xc=0, yc=0, zc=0;
966 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
967 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
968 aPnts.Append(BRep_Tool::Pnt(V));
969 xc += aPnts.Last().X();
970 yc += aPnts.Last().Y();
971 zc += aPnts.Last().Z();
973 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
974 gp_Vec V1(PC,aPnts.Value(1));
975 gp_Vec V2(PC,aPnts.Value(2));
976 gp_Vec VN = V1.Crossed(V2);
977 for(int ip=2; ip<aPnts.Length(); ip++) {
978 V1 = gp_Vec(PC,aPnts.Value(ip));
979 V2 = gp_Vec(PC,aPnts.Value(ip+1));
980 VN.Add(V1.Crossed(V2));
983 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
985 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
986 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
987 double tol = BRep_Tool::Tolerance(edge);
988 TopoDS_Vertex VF = sae.FirstVertex(edge);
989 gp_Pnt PF = BRep_Tool::Pnt(VF);
990 if( PF.Distance(PLoc) < tol ) {
992 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
995 if( P1.Distance(PLoc) < tol ) {
996 C->D0(fp+(lp-fp)/100,P2);
1000 C->D0(lp+(fp-lp)/100,P2);
1002 PathNorm = gp_Vec(P2,P1);
1006 TopoDS_Vertex VL = sae.LastVertex(edge);
1007 gp_Pnt PL = BRep_Tool::Pnt(VL);
1008 if( PL.Distance(PLoc) < tol ) {
1010 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1013 if( P1.Distance(PLoc) < tol ) {
1014 C->D0(fp+(lp-fp)/100,P2);
1018 C->D0(lp+(fp-lp)/100,P2);
1020 PathNorm = gp_Vec(P2,P1);
1025 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1026 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1027 if(fabs(VN.Angle(PathNorm))>PI/2.)
1032 if(!CreateFewSolids) {
1033 // we can create only one solid
1034 TopoDS_Shape aWire1, aWire2;
1036 if(aType1==TopAbs_SHELL) {
1037 // create wire as boundary contour if shell is no closed
1038 // get free boundary shapes
1039 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
1040 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1041 //TopExp_Explorer anExp;
1042 Standard_Integer NbWires = 0;
1043 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1045 aWire1 = anExp.Current();
1050 Standard_ConstructionError::Raise("Bad shell is used as section ");
1053 else { // aType1==TopAbs_FACE
1054 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1055 aWire1 = aExpW.Current();
1058 if(aType2==TopAbs_SHELL) {
1059 // create wire as boundary contour if shell is no closed
1060 // get free boundary shapes
1061 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
1062 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1063 //TopExp_Explorer anExp;
1064 Standard_Integer NbWires = 0;
1065 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1067 aWire2 = anExp.Current();
1072 Standard_ConstructionError::Raise("Bad shell is used as section ");
1075 else { // aType2==TopAbs_FACE
1076 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1077 aWire2 = aExpW.Current();
1079 // make pipe using aWire1 and aWire2
1080 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1081 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1082 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1083 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1084 aWithContact, aWithCorrect);
1085 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1086 aWithContact, aWithCorrect);
1087 if(!aBuilder.IsReady()) {
1089 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1092 TopoDS_Shape aShape = aBuilder.Shape();
1093 TopoDS_Shell aShell;
1094 B.MakeShell(aShell);
1095 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1096 B.Add(aShell,anExp.Current());
1098 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1099 B.Add(aShell,anExp.Current());
1101 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1102 B.Add(aShell,anExp.Current());
1104 // make sewing for this shell
1105 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1106 aSewing->SetTolerance(Precision::Confusion());
1107 aSewing->SetFaceMode(Standard_True);
1108 aSewing->SetFloatingEdgesMode(Standard_False);
1109 aSewing->SetNonManifoldMode(Standard_False);
1110 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1111 aSewing->Add(anExp.Current());
1114 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1115 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1116 aShell = TopoDS::Shell(aSewShape);
1117 GProp_GProps aSystem;
1118 BRepGProp::VolumeProperties(aShell, aSystem);
1119 if(aSystem.Mass()<0) {
1122 if(BRep_Tool::IsClosed(aShell)) {
1123 TopoDS_Solid aSolid;
1124 B.MakeSolid(aSolid);
1125 B.Add(aSolid,aShell);
1126 B.Add(aComp,aSolid);
1129 B.Add(aComp,aShell);
1133 B.Add(aComp,aShell);
1138 // main block - creation few solids (for each pair of faces)
1139 TopTools_MapOfShape aFaces1,aFaces2;
1140 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1141 aFaces1.Add(anExp.Current());
1143 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1144 aFaces2.Add(anExp.Current());
1146 // creating map of edge faces
1147 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1148 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1149 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1150 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1152 // constuct map face->face
1153 TopTools_IndexedDataMapOfShapeShape FF;
1154 TopoDS_Shape FS1,FS2;
1156 // find edge the most distant from location point
1157 // (this edge is not shared by two faces)
1158 double maxdist = 0.;
1160 TopoDS_Vertex V11,V21;
1161 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1162 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1163 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1164 if(aList.Extent()>1)
1166 TopExp_Explorer expv;
1167 expv.Init( tmp, TopAbs_VERTEX );
1168 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1170 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1171 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1172 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1173 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1178 TopTools_ListIteratorOfListOfShape anIter(aList);
1179 FS1 = anIter.Value();
1183 // main direction for comparing
1184 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1185 // find corresponding edge from next section
1187 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1188 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1190 TopoDS_Vertex V12,V22;
1191 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1192 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1193 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1194 if(aList.Extent()>1)
1196 TopExp_Explorer expv;
1197 expv.Init( tmp, TopAbs_VERTEX );
1198 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1200 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1201 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1202 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1203 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1204 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1205 TopoDS_Vertex V1,V2;
1208 V1 = V2tmp; P1 = P2tmp;
1209 V2 = V1tmp; P2 = P1tmp;
1212 V1 = V1tmp; P1 = P1tmp;
1213 V2 = V2tmp; P2 = P2tmp;
1215 gp_Vec Vec1(P11,P1);
1216 gp_Vec Vec2(P21,P2);
1217 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1222 TopTools_ListIteratorOfListOfShape anIter(aList);
1223 FS2 = anIter.Value();
1227 // put all pairs to map FF
1233 // add pairs of edges to FF
1234 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1237 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1243 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1244 if(anItem.IsNull()) {
1246 Standard_ConstructionError::Raise("Invalid subbase shape");
1248 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1249 if(aRefBase.IsNull()) {
1251 Standard_ConstructionError::Raise("Invalid subbase shape");
1253 TopoDS_Shape aSh = aRefBase->GetValue();
1256 Standard_ConstructionError::Raise("Invalid subbase shape");
1258 if(aSh.ShapeType()!=TopAbs_FACE) {
1260 Standard_ConstructionError::Raise("Invalid subbase shape");
1265 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1266 if(anItem.IsNull()) {
1268 Standard_ConstructionError::Raise("Invalid subbase shape");
1270 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1271 if(aRefBase.IsNull()) {
1273 Standard_ConstructionError::Raise("Invalid subbase shape");
1275 TopoDS_Shape aSh = aRefBase->GetValue();
1278 Standard_ConstructionError::Raise("Invalid subbase shape");
1280 if(aSh.ShapeType()!=TopAbs_FACE) {
1282 Standard_ConstructionError::Raise("Invalid subbase shape");
1287 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
1289 Standard_ConstructionError::Raise("Invalid subbase shape");
1294 // add pairs of edges to FF
1295 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1296 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1299 Standard_ConstructionError::Raise("Can not create correct pipe");
1303 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1305 // make pipe for each pair of faces
1306 for(j=1; j<=FF.Extent(); j++) {
1307 TopoDS_Shape F1 = FF.FindKey(j);
1308 if( F1.ShapeType() != TopAbs_FACE )
1310 TopoDS_Shape F2 = FF.FindFromIndex(j);
1311 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1312 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1313 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1314 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1315 // make pipe using aWire1 and aWire2
1316 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1317 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1318 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1319 aWithContact, aWithCorrect);
1320 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1321 aWithContact, aWithCorrect);
1322 if(!aBuilder.IsReady()) {
1324 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1327 TopoDS_Shape aShape = aBuilder.Shape();
1328 TopoDS_Shell aShell;
1329 B.MakeShell(aShell);
1330 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1331 B.Add(aShell,anExp.Current());
1336 // make sewing for this shell
1337 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1338 aSewing->SetTolerance(Precision::Confusion());
1339 aSewing->SetFaceMode(Standard_True);
1340 aSewing->SetFloatingEdgesMode(Standard_False);
1341 aSewing->SetNonManifoldMode(Standard_False);
1342 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1343 aSewing->Add(anExp.Current());
1346 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1347 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1348 aShell = TopoDS::Shell(aSewShape);
1349 GProp_GProps aSystem;
1350 BRepGProp::VolumeProperties(aShell, aSystem);
1351 if(aSystem.Mass()<0) {
1352 //cout<<"aSewShape is reversed"<<endl;
1355 if(BRep_Tool::IsClosed(aShell)) {
1356 TopoDS_Solid aSolid;
1357 B.MakeSolid(aSolid);
1358 B.Add(aSolid,aShell);
1359 B.Add(aComp,aSolid);
1362 B.Add(aComp,aShell);
1366 B.Add(aComp,aShell);
1374 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1378 //=======================================================================
1379 //function : CreatePipeShellsWithoutPath
1380 //purpose : auxilary for Execute()
1381 //=======================================================================
1382 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1384 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1388 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1390 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1391 // vertex for recognition
1392 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1394 Standard_Integer nbBases = aBasesObjs->Length(),
1395 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1397 if( nbv != nbBases ) {
1399 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1402 TopTools_SequenceOfShape SecVs,Bases;
1403 for(i=1; i<=nbBases; i++) {
1405 Handle(Standard_Transient) anItem = VObjs->Value(i);
1408 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1409 TopoDS_Shape V = aRef->GetValue();
1410 if(V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1414 anItem = aBasesObjs->Value(i);
1417 aRef = Handle(GEOM_Function)::DownCast(anItem);
1418 TopoDS_Shape aSh = aRef->GetValue();
1423 nbv = SecVs.Length();
1424 nbBases = Bases.Length();
1425 if( nbv != nbBases ) {
1427 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1430 TopoDS_Compound aComp;
1431 B.MakeCompound(aComp);
1433 for (i = 1; i < nbBases; i++) {
1434 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1435 TopoDS_Shape aShBase1 = Bases.Value(i);
1436 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1437 TopExp_Explorer anExp;
1438 Standard_Integer nbf1 = 0;
1439 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1442 Standard_Integer nbf2 = 0;
1443 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1446 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1449 Standard_ConstructionError::Raise("Different number of faces in the sections");
1452 TopTools_MapOfShape aFaces1,aFaces2;
1453 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1454 aFaces1.Add(anExp.Current());
1456 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1457 aFaces2.Add(anExp.Current());
1460 // creating map of edge faces
1461 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1462 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1463 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1464 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1466 // constuct map face->face (and subshapes)
1467 TopTools_IndexedDataMapOfShapeShape FF;
1468 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1469 TopoDS_Shape FS1, FS2;
1470 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1471 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1472 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1475 MESSAGE (" first pair of corresponding faces is found");
1477 // add pairs of edges and vertexes to FF
1478 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1481 Standard_ConstructionError::Raise("Can not create correct pipe");
1483 MESSAGE (" correspondences for subshapes of first pair of faces is found");
1485 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1486 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1488 // make pipe for each pair of faces
1489 // auxilary map vertex->edge for created pipe edges
1490 TopTools_IndexedDataMapOfShapeShape VPE;
1491 ShapeAnalysis_Edge sae;
1492 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1494 for(j=1; j<=FF.Extent(); j++) {
1495 TopoDS_Shape F1 = FF.FindKey(j);
1496 if( F1.ShapeType() != TopAbs_FACE )
1498 TopoDS_Shape F2 = FF.FindFromIndex(j);
1501 //if(nbff!=3) continue;
1503 MESSAGE (" make pipe for "<<nbff<<" face");
1505 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1506 if(S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1507 Handle(Geom_RectangularTrimmedSurface) RTS =
1508 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1509 S1 = RTS->BasisSurface();
1511 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1512 if( Pln1.IsNull() ) {
1514 Standard_ConstructionError::Raise("Surface from face is not plane");
1516 gp_Vec aDir1(Pln1->Axis().Direction());
1518 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1519 if(S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1520 Handle(Geom_RectangularTrimmedSurface) RTS =
1521 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1522 S2 = RTS->BasisSurface();
1524 Handle(Geom_Plane) Pln2 =
1525 Handle(Geom_Plane)::DownCast(S2);
1526 if( Pln2.IsNull() ) {
1528 Standard_ConstructionError::Raise("Surface from face is not plane");
1530 gp_Vec aDir2(Pln2->Axis().Direction());
1532 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1533 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1535 if(fabs(aDir.Angle(aDir1))>PI/2.)
1537 if(fabs(aDir.Angle(aDir2))>PI/2.)
1540 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1541 TopTools_SequenceOfShape aNewFs;
1543 for(; anExpE.More(); anExpE.Next()) {
1544 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1546 if(!FF.Contains(E1))
1547 MESSAGE ("map FF not contains key E1");
1549 if(VPE.Contains(E1)) {
1550 aNewFs.Append(VPE.FindFromKey(E1));
1552 MESSAGE (" using existed face");
1557 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1558 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1559 TopoDS_Vertex V2 = sae.LastVertex(E1);
1560 if(!FF.Contains(V1))
1561 MESSAGE ("map FF not contains key V1");
1562 if(!FF.Contains(V2))
1563 MESSAGE ("map FF not contains key V2");
1564 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1565 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1566 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1569 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1570 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1571 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1572 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1575 Handle(Geom_BSplineCurve) C2;
1576 if(VPE.Contains(V2)) {
1577 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1579 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1582 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1583 HAP->SetValue(1,P2);
1584 HAP->SetValue(2,P3);
1585 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1586 anInt.Load(aDir1,aDir2);
1589 B.MakeEdge(E2,C2,1.e-7);
1590 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1591 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1596 Handle(Geom_BSplineCurve) C4;
1597 if(VPE.Contains(V1)) {
1598 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1600 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1603 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1604 HAP->SetValue(1,P1);
1605 HAP->SetValue(2,P4);
1606 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1607 anInt.Load(aDir1,aDir2);
1610 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1611 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1612 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1621 B.Add(W,E4.Reversed());
1622 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1623 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1628 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1629 //bool IsConicC1 = false;
1630 //if( C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1631 // IsConicC1 = true;
1632 // cout<<"C1 - Geom_Conic"<<endl;
1634 if( C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1635 C1 = new Geom_TrimmedCurve(C1,fp,lp);
1638 // double tol = BRep_Tool::Tolerance(E1);
1639 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
1640 // C1 = ApxC1.Curve();
1642 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
1643 if( C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1644 C3 = new Geom_TrimmedCurve(C3,fp,lp);
1649 Handle(Geom_BSplineCurve) CE1 =
1650 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
1652 CE1->IncreaseDegree(3);
1653 Handle(Geom_BSplineCurve) CE2 =
1654 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
1656 CE2->IncreaseDegree(3);
1657 Handle(Geom_BSplineCurve) CE3 =
1658 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
1660 CE3->IncreaseDegree(3);
1661 Handle(Geom_BSplineCurve) CE4 =
1662 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
1664 CE4->IncreaseDegree(3);
1665 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
1666 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
1667 //if(fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
1668 // os<<"DrawTrSurf_BSplineCurve"<<endl;
1669 // GeomTools::Write(CE1,os);
1673 Handle(Geom_Surface) BS;
1675 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
1676 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
1680 MESSAGE (" can not create BSplineSurface - create Bezier");
1682 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
1683 double fp1,lp1,fp2,lp2;
1684 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
1685 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
1694 // get points from C1
1695 if(P1.Distance(P1C1)<1.e-6) {
1703 double step = (lp-fp)/(NbP-1);
1704 Points.SetValue(1,1,P1);
1706 for(n1=2; n1<NbP; n1++) {
1710 Points.SetValue(1,n1,P);
1712 Points.SetValue(1,NbP,P2);
1713 // get points from C3
1714 if(P4.Distance(P1C3)<1.e-6) {
1722 step = (lp-fp)/(NbP-1);
1723 Points.SetValue(NbP,1,P4);
1725 for(n1=2; n1<NbP; n1++) {
1729 Points.SetValue(NbP,n1,P);
1731 Points.SetValue(NbP,NbP,P3);
1732 // create isolines and get points from them
1733 for(n1=1; n1<=NbP; n1++) {
1734 gp_Pnt PI1 = Points.Value(1,n1);
1735 gp_Pnt PI2 = Points.Value(NbP,n1);
1736 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1737 HAP->SetValue(1,PI1);
1738 HAP->SetValue(2,PI2);
1739 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1740 anInt.Load(aDir1,aDir2);
1742 Handle(Geom_Curve) iso = anInt.Curve();
1743 fp = iso->FirstParameter();
1744 lp = iso->LastParameter();
1745 step = (lp-fp)/(NbP-1);
1747 TopoDS_Compound VComp;
1748 B.MakeCompound(VComp);
1749 for(n2=2; n2<NbP; n2++) {
1753 Points.SetValue(n2,n1,P);
1756 // create surface and face
1757 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
1758 BS = new Geom_BezierSurface(Points);
1761 BRepBuilderAPI_MakeFace BB(BS,W);
1762 TopoDS_Face NewF = BB.Face();
1763 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
1765 sff->FixOrientation();
1766 TopoDS_Face FixedFace = sff->Face();
1767 aNewFs.Append(FixedFace);
1768 VPE.Add(E1,FixedFace);
1769 //cout<<" face for edge "<<nbee<<" is created"<<endl;
1770 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
1773 TopoDS_Shell aShell;
1774 B.MakeShell(aShell);
1775 for(int nf=1; nf<=aNewFs.Length(); nf++) {
1776 B.Add(aShell,aNewFs(nf));
1781 // make sewing for this shell
1782 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1783 aSewing->SetTolerance(Precision::Confusion());
1784 aSewing->SetFaceMode(Standard_True);
1785 aSewing->SetFloatingEdgesMode(Standard_False);
1786 aSewing->SetNonManifoldMode(Standard_False);
1787 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1788 aSewing->Add(anExp.Current());
1791 MESSAGE (" shell for face "<<nbff<<" is created");
1792 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1793 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
1794 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1795 aShell = TopoDS::Shell(aSewShape);
1796 GProp_GProps aSystem;
1797 BRepGProp::VolumeProperties(aShell, aSystem);
1798 if(aSystem.Mass()<0) {
1799 //cout<<"aSewShape is reversed"<<endl;
1802 if(BRep_Tool::IsClosed(aShell)) {
1803 TopoDS_Solid aSolid;
1804 B.MakeSolid(aSolid);
1805 B.Add(aSolid,aShell);
1806 B.Add(aComp,aSolid);
1807 MESSAGE (" solid for face "<<nbff<<" is created");
1810 B.Add(aComp,aShell);
1811 MESSAGE (" solid for face "<<nbff<<" is not created");
1815 B.Add(aComp,aShell);
1816 MESSAGE (" solid for face "<<nbff<<" is not created");
1818 //cout<<" solid for face "<<nbff<<" is created"<<endl;
1820 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
1822 //TopoDS_Shell FixedShell = sfs->Shell();
1824 GProp_GProps aSystem;
1825 BRepGProp::VolumeProperties(FixedShell, aSystem);
1826 if(aSystem.Mass()<0) {
1827 //cout<<"aSewShape is reversed"<<endl;
1828 FixedShell.Reverse();
1830 if(BRep_Tool::IsClosed(FixedShell)) {
1831 TopoDS_Solid aSolid;
1832 B.MakeSolid(aSolid);
1833 B.Add(aSolid,aShell);
1834 B.Add(aComp,aSolid);
1837 B.Add(aComp,FixedShell);
1843 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1847 //=======================================================================
1848 //function : CreatePipeBiNormalAlongVector
1849 //purpose : auxilary for Execute()
1850 //=======================================================================
1851 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
1852 GEOMImpl_IPipe* aCI)
1854 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
1856 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
1857 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
1858 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1859 TopoDS_Shape aShapeVec = aRefVec->GetValue();
1861 if (aShapeBase.IsNull()) {
1862 if(aCIBN) delete aCIBN;
1863 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1867 if( aShapeBase.ShapeType() == TopAbs_VERTEX ) {
1870 else if( aShapeBase.ShapeType() == TopAbs_EDGE) {
1871 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
1873 else if( aShapeBase.ShapeType() == TopAbs_WIRE) {
1876 else if( aShapeBase.ShapeType() == TopAbs_FACE) {
1877 TopExp_Explorer wexp(aShapeBase,TopAbs_WIRE);
1878 aProf = wexp.Current();
1881 Standard_TypeMismatch::Raise
1882 ("MakePipe aborted : invalid type of base");
1884 BRepOffsetAPI_MakePipeShell PipeBuilder(aWirePath);
1885 PipeBuilder.Add(aProf);
1887 if (aShapeVec.IsNull()) {
1888 if(aCIBN) delete aCIBN;
1889 Standard_NullObject::Raise
1890 ("MakePipe aborted : null vector argument");
1892 if (aShapeVec.ShapeType() != TopAbs_EDGE)
1893 Standard_TypeMismatch::Raise
1894 ("MakePipe aborted: invalid type of vector");
1895 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
1896 TopoDS_Vertex V1, V2;
1897 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1898 if (V1.IsNull() || V2.IsNull())
1899 Standard_NullObject::Raise
1900 ("MakePipe aborted: vector is not defined");
1901 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
1902 gp_Dir BiNormal(aVec);
1903 PipeBuilder.SetMode(BiNormal);
1904 PipeBuilder.Build();
1905 if( aShapeBase.ShapeType() == TopAbs_FACE) {
1906 PipeBuilder.MakeSolid();
1909 return PipeBuilder.Shape();
1912 //=======================================================================
1913 //function : Execute
1915 //=======================================================================
1916 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1918 //cout<<"PipeDriver::Execute"<<endl;
1919 if (Label().IsNull()) return 0;
1920 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1921 GEOMImpl_IPipe* aCI= 0;
1922 Standard_Integer aType = aFunction->GetType();
1923 if(aType == PIPE_BASE_PATH)
1924 aCI = new GEOMImpl_IPipe(aFunction);
1925 else if(aType == PIPE_DIFFERENT_SECTIONS)
1926 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1927 else if(aType == PIPE_SHELL_SECTIONS)
1928 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1929 else if(aType == PIPE_SHELLS_WITHOUT_PATH)
1930 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1931 else if(aType == PIPE_BI_NORMAL_ALONG_VECTOR)
1932 aCI = new GEOMImpl_IPipeBiNormal(aFunction);
1936 TopoDS_Wire aWirePath;
1937 if(aType != PIPE_SHELLS_WITHOUT_PATH) {
1938 // working with path
1939 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1940 TopoDS_Shape aShapePath = aRefPath->GetValue();
1942 if (aShapePath.IsNull()) {
1943 MESSAGE ("Driver : path is null");
1945 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1950 if ( aShapePath.ShapeType() == TopAbs_COMPOUND ) {
1951 TopTools_SequenceOfShape anEdges;
1952 TopExp_Explorer anExp;
1956 for ( anExp.Init( aShapePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
1957 B.Add( W, anExp.Current() );
1963 else if (aShapePath.ShapeType() == TopAbs_WIRE) {
1964 aWirePath = TopoDS::Wire(aShapePath);
1968 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1969 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1970 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1976 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1980 TopoDS_Shape aShape;
1982 if (aType == PIPE_BASE_PATH)
1984 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1985 TopoDS_Shape aShapeBase;
1987 // Make copy to prevent modifying of base object 0020766 : EDF 1320
1988 BRepBuilderAPI_Copy Copy(aRefBase->GetValue());
1990 aShapeBase = Copy.Shape();
1992 if (aShapeBase.IsNull()) {
1994 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1998 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
2001 //building pipe with different sections
2002 else if (aType == PIPE_DIFFERENT_SECTIONS) {
2003 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
2004 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
2005 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2006 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
2007 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
2008 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
2009 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
2011 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
2012 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
2014 if(nbLocs && nbLocs != nbBases) {
2016 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
2018 TopTools_SequenceOfShape aSeqBases;
2019 TopTools_SequenceOfShape aSeqLocs;
2020 TopTools_SequenceOfShape aSeqFaces;
2021 for (; i <= nbBases; i++) {
2022 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2025 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2026 if(aRefBase.IsNull())
2029 if(aRefBase->GetValue().IsNull())
2032 // Make copy to prevent modifying of base object 0020766 : EDF 1320
2033 TopoDS_Shape aShapeBase;
2034 BRepBuilderAPI_Copy Copy(aRefBase->GetValue());
2036 aShapeBase = Copy.Shape();
2038 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
2040 //if for section was specified face with a few wires then a few
2041 // pipes were build and make solid
2042 Standard_Boolean NeedCreateSolid = Standard_False;
2043 if(aTypeBase == TopAbs_SHELL) {
2044 // create wire as boundary contour if shell is no closed
2045 // get free boundary shapes
2046 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
2047 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
2048 TopExp_Explorer anExp;
2050 Standard_Integer NbWires = 0;
2051 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
2053 aWire = anExp.Current();
2058 Standard_ConstructionError::Raise("Bad shell is used as section ");
2060 NeedCreateSolid = Standard_True;
2061 aSeqFaces.Append(aShapeBase);
2062 aSeqBases.Append(aWire);
2064 else if(aTypeBase == TopAbs_FACE) {
2065 NeedCreateSolid = Standard_True;
2066 //for case one path should be used other type function
2067 aSeqFaces.Append(aShapeBase);
2068 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
2069 for (; aExpW.More(); aExpW.Next())
2071 TopoDS_Shape aWireProf = aExpW.Current();
2072 aSeqBases.Append(aWireProf);
2075 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
2076 aSeqBases.Append(aShapeBase);
2078 else if(aTypeBase == TopAbs_EDGE) {
2079 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
2080 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
2081 aSeqBases.Append(aWireProf);
2084 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2085 if(anItemLoc.IsNull())
2087 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2088 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2089 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2091 aSeqLocs.Append(aShapeLoc);
2095 nbLocs = aSeqLocs.Length();
2098 TopTools_SequenceOfShape Edges;
2100 // we have to check that each location shape is a vertex from
2101 // path and update aSeqLocs if it is needed (and possible)
2102 TColgp_SequenceOfPnt PLocs;
2103 for(i=1; i<=nbLocs; i++) {
2104 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
2105 PLocs.Append(BRep_Tool::Pnt(V));
2107 //TopTools_SequenceOfShape Edges;
2108 TopExp_Explorer anExp;
2109 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
2110 Edges.Append(anExp.Current());
2112 int nbEdges = Edges.Length();
2113 ShapeAnalysis_Edge sae;
2114 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
2115 double tol = BRep_Tool::Tolerance(edge);
2116 TopoDS_Vertex VF = sae.FirstVertex(edge);
2117 gp_Pnt PF = BRep_Tool::Pnt(VF);
2118 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
2119 if( PF.Distance(PLocs.First()) > tol ) {
2121 Standard_ConstructionError::Raise
2122 ("First location shapes is not coincided with first vertex of aWirePath");
2124 aSeqLocs.ChangeValue(1) = VF;
2125 edge = TopoDS::Edge(Edges.Last());
2126 tol = BRep_Tool::Tolerance(edge);
2127 TopoDS_Vertex VL = sae.LastVertex(edge);
2128 gp_Pnt PL = BRep_Tool::Pnt(VL);
2129 if( PL.Distance(PLocs.Last()) > tol ) {
2131 Standard_ConstructionError::Raise
2132 ("Last location shapes is not coincided with last vertex of aWirePath");
2134 aSeqLocs.ChangeValue(nbLocs) = VL;
2136 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
2137 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
2138 tol = BRep_Tool::Tolerance(edge);
2139 TopoDS_Vertex V1 = sae.FirstVertex(E);
2140 TopoDS_Vertex V2 = sae.LastVertex(E);
2141 gp_Pnt P1 = BRep_Tool::Pnt(V1);
2142 gp_Pnt P2 = BRep_Tool::Pnt(V2);
2143 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
2144 aSeqLocs.ChangeValue(jcurr) = V2;
2148 // find distance between E and aLocs(jcurr)
2150 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
2151 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
2152 if( PPC.NbPoints()>0 &&
2153 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
2154 double param = PPC.Parameter(1);
2157 // split current edge
2158 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
2159 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
2164 if(Pfp.Distance(P1)<tol) {
2165 B.MakeEdge(E1,tc1,tol);
2167 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2168 B.Add(E1,TopoDS::Vertex(tmpV));
2169 B.MakeEdge(E2,tc2,tol);
2170 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2171 B.Add(E2,TopoDS::Vertex(tmpV));
2175 B.MakeEdge(E1,tc2,tol);
2176 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2177 B.Add(E1,TopoDS::Vertex(tmpV));
2180 B.MakeEdge(E2,tc1,tol);
2182 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2183 B.Add(E2,TopoDS::Vertex(tmpV));
2188 Edges.InsertAfter(i-1,E1);
2189 Edges.InsertAfter(i,E2);
2193 if(nbEdges<Edges.Length()) {
2194 // one of edges was splitted => we have to update WirePath
2198 for(i=1; i<=Edges.Length(); i++) {
2199 B.Add(W,TopoDS::Edge(Edges.Value(i)));
2205 // check curvature of wire for condition that
2206 // max summary angle between directions along
2207 // wire path must be < 4*PI. If not - split wire
2208 // and seguences of shapes, perform pipe for each
2209 // and make sewing after that
2211 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
2216 double SumAng = fabs(Vec1.Angle(Vec2));
2219 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
2221 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
2222 for(i=2; i<=Edges.Length(); i++) {
2223 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
2224 double tol = BRep_Tool::Tolerance(edge);
2225 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
2227 double ang = fabs(Vec1.Angle(Vec2));
2231 SplitEdgeNums.Append(i-1);
2233 for(j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
2234 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
2235 gp_Pnt P = BRep_Tool::Pnt(aVert);
2236 if( P1.Distance(P) < tol ) {
2237 SplitLocNums.Append(j);
2247 //cout<<"SplitEdgeNums.Length()="<<SplitEdgeNums.Length()<<endl;
2248 //cout<<"SplitLocNums.Length()="<<SplitLocNums.Length()<<endl;
2249 if( SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0 ) {
2250 TopTools_SequenceOfShape aSeqRes;
2251 int nn, num1 = 1, num2 = 1;
2252 for(nn=1; nn<=SplitEdgeNums.Length(); nn++) {
2253 // create wirepath and sequences of shapes
2257 for(i=num1; i<=SplitEdgeNums.Value(nn); i++) {
2258 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2260 num1 = SplitEdgeNums.Value(nn) + 1;
2261 TopTools_SequenceOfShape aTmpSeqBases;
2262 TopTools_SequenceOfShape aTmpSeqLocs;
2263 for(i=num2; i<=SplitLocNums.Value(nn); i++) {
2264 aTmpSeqBases.Append(aSeqBases.Value(i));
2265 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2267 num2 = SplitLocNums.Value(nn);
2269 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2270 Standard_Integer nbShapes = aTmpSeqBases.Length();
2271 for(i=1; i<=nbShapes; i++) {
2272 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2273 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2274 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2276 if(!aBuilder.IsReady()) {
2278 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2281 TopoDS_Shape resShape = aBuilder.Shape();
2282 aSeqRes.Append(resShape);
2284 // create wirepath and sequences of shapes for last part
2288 for(i=num1; i<=Edges.Length(); i++) {
2289 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2291 TopTools_SequenceOfShape aTmpSeqBases;
2292 TopTools_SequenceOfShape aTmpSeqLocs;
2293 for(i=num2; i<=aSeqLocs.Length(); i++) {
2294 aTmpSeqBases.Append(aSeqBases.Value(i));
2295 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2297 // make pipe for last part
2298 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2299 Standard_Integer nbShapes = aTmpSeqBases.Length();
2300 for(i=1; i<=nbShapes; i++) {
2301 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2302 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2303 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2305 if(!aBuilder.IsReady()) {
2307 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2310 TopoDS_Shape resShape = aBuilder.Shape();
2311 aSeqRes.Append(resShape);
2312 // make sewing for result
2313 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2314 aSewing->SetTolerance(Precision::Confusion());
2315 aSewing->SetFaceMode(Standard_True);
2316 aSewing->SetFloatingEdgesMode(Standard_False);
2317 aSewing->SetNonManifoldMode(Standard_False);
2318 for(i=1; i<=aSeqRes.Length(); i++) {
2319 aSewing->Add(aSeqRes.Value(i));
2322 aShape = aSewing->SewedShape();
2325 // old implementation without splitting
2326 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2328 Standard_Integer nbShapes = aSeqBases.Length();
2329 Standard_Integer step = nbShapes/nbBases;
2331 if (nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
2333 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
2335 Standard_Integer ind =0;
2336 for (i = 1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
2337 TopTools_SequenceOfShape usedBases;
2338 Standard_Integer j = 1;
2339 for (; j <= nbBases; j++) {
2340 ind = i + (j-1)*step;
2341 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
2342 usedBases.Append(aWireProf);
2344 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
2345 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2346 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
2349 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
2351 if(!aBuilder.IsReady()) {
2353 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2356 aShape = aBuilder.Shape();
2357 aSeqFaces.Append(aShape);
2358 for( j = 1; j <=usedBases.Length(); j++)
2359 aBuilder.Delete(usedBases.Value(j));
2362 //for case if section is face
2363 if(aSeqFaces.Length() >1) {
2365 TopoDS_Compound aComp;
2366 aB.MakeCompound(aComp);
2367 for( i = 1; i <= aSeqFaces.Length(); i++)
2368 aB.Add(aComp,aSeqFaces.Value(i));
2374 //building pipe with shell sections
2375 else if (aType == PIPE_SHELL_SECTIONS) {
2376 aShape = CreatePipeForShellSections(aWirePath,aCI);
2379 //building pipe shell sections without path
2380 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2381 aShape = CreatePipeShellsWithoutPath(aCI);
2384 //building a pipe with constant bi-normal along given vector
2385 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2386 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2394 if (aShape.IsNull()) return 0;
2396 BRepCheck_Analyzer ana (aShape, Standard_False);
2397 if (!ana.IsValid()) {
2398 ShapeFix_ShapeTolerance aSFT;
2399 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2400 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2401 aSfs->SetPrecision(Precision::Confusion());
2403 aShape = aSfs->Shape();
2405 ana.Init(aShape, Standard_False);
2407 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2410 // Glue (for bug 0020207)
2411 TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
2413 aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
2415 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
2416 aFunction->SetValue(aRes);
2418 log.SetTouched(Label());
2422 //=======================================================================
2423 //function : GEOMImpl_PipeDriver_Type_
2425 //=======================================================================
2426 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2429 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2430 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2431 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2432 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2433 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2434 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2436 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2437 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2438 sizeof(GEOMImpl_PipeDriver),
2440 (Standard_Address)_Ancestors,
2441 (Standard_Address)NULL);
2446 //=======================================================================
2447 //function : DownCast
2449 //=======================================================================
2450 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2452 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2454 if (!AnObject.IsNull()) {
2455 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2456 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2460 return _anOtherObject;