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_IPipeBiNormal.hxx>
29 #include <GEOMImpl_IPipe.hxx>
30 #include <GEOMImpl_Types.hxx>
31 #include <GEOM_Function.hxx>
33 #include <GEOMAlgo_GlueAnalyser.hxx>
35 #include <ShapeAnalysis_FreeBounds.hxx>
36 #include <ShapeAnalysis_Edge.hxx>
37 #include <ShapeFix_Face.hxx>
38 #include <ShapeFix_Shell.hxx>
39 #include <ShapeFix_Shape.hxx>
40 #include <ShapeFix_ShapeTolerance.hxx>
42 #include <BRep_Tool.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepBuilderAPI_MakeWire.hxx>
45 #include <BRepBuilderAPI_Sewing.hxx>
46 #include <BRepCheck_Analyzer.hxx>
47 #include <BRepOffsetAPI_MakePipe.hxx>
48 #include <BRepOffsetAPI_MakePipeShell.hxx>
49 #include <GProp_GProps.hxx>
50 #include <BRepGProp.hxx>
51 #include <BRepBuilderAPI_MakeFace.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Wire.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Solid.hxx>
61 #include <TopoDS_Shell.hxx>
62 #include <TopoDS_Face.hxx>
63 #include <TopoDS_Compound.hxx>
64 #include <TopTools_SequenceOfShape.hxx>
65 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
66 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
67 #include <TopTools_ListIteratorOfListOfShape.hxx>
69 #include <GeomAPI_ProjectPointOnCurve.hxx>
70 #include <GeomAPI_Interpolate.hxx>
71 #include <Geom_TrimmedCurve.hxx>
72 #include <Geom_Plane.hxx>
73 #include <Geom_RectangularTrimmedSurface.hxx>
74 #include <Geom_BezierSurface.hxx>
75 #include <Geom_Line.hxx>
76 #include <Geom_Conic.hxx>
77 #include <Geom_BSplineCurve.hxx>
78 #include <Geom_BSplineSurface.hxx>
79 #include <GeomFill_BSplineCurves.hxx>
80 #include <GeomConvert_ApproxCurve.hxx>
81 #include <GeomConvert.hxx>
83 #include <TColgp_SequenceOfPnt.hxx>
84 #include <TColgp_HArray1OfPnt.hxx>
85 #include <TColgp_Array2OfPnt.hxx>
86 #include <TColStd_HSequenceOfTransient.hxx>
88 #include <Precision.hxx>
89 #include <Standard_NullObject.hxx>
90 #include <Standard_TypeMismatch.hxx>
91 #include <Standard_ConstructionError.hxx>
93 #include "utilities.h"
96 //=======================================================================
99 //=======================================================================
100 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
102 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
107 //=======================================================================
108 //function : GEOMImpl_PipeDriver
110 //=======================================================================
111 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
116 //=======================================================================
117 //function : FillForOtherEdges
118 //purpose : auxilary for CreatePipeForShellSections()
119 //=======================================================================
120 static bool FillForOtherEdges(const TopoDS_Shape& F1,
121 const TopoDS_Shape& E1,
122 const TopoDS_Shape& V1,
123 TopTools_IndexedDataMapOfShapeShape& FF)
125 //cout<<"FillForOtherEdges"<<endl;
126 // find other pairs for vertexes and edges
127 // creating map of vertex edges for both faces
128 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
129 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
130 if (!FF.Contains(F1))
131 MESSAGE(" FillForOtherEdges: map FF not contains key F1");
132 if (!FF.Contains(E1))
133 MESSAGE(" FillForOtherEdges: map FF not contains key E1");
134 if (!FF.Contains(V1))
135 MESSAGE(" FillForOtherEdges: map FF not contains key V1");
136 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
137 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
138 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
139 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
140 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
142 TopoDS_Edge ES1 = TopoDS::Edge(E1);
143 TopoDS_Edge ES2 = TopoDS::Edge(E2);
144 TopoDS_Shape VS1 = V1;
145 TopoDS_Shape VS2 = V2;
147 ShapeAnalysis_Edge sae;
149 if(!aMapVertEdge1.Contains(VS1))
150 MESSAGE (" FillForOtherEdges: map aMapVertEdge1 not contains key VS1");
151 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
152 //TopoDS_Shape E1next;
153 TopTools_ListIteratorOfListOfShape anIter1(aList1);
154 if(anIter1.Value().IsSame(ES1)) {
157 //E1next = anIter1.Value();
158 if(!aMapVertEdge2.Contains(VS2))
159 MESSAGE (" FillForOtherEdges: map aMapVertEdge2 not contains key VS2");
160 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
161 //TopoDS_Shape E2next;
162 TopTools_ListIteratorOfListOfShape anIter2(aList2);
163 if(anIter2.Value().IsSame(ES2)) {
166 //E2next = anIter2.Value();
167 //ES1 = TopoDS::Edge(E1next);
168 //ES2 = TopoDS::Edge(E2next);
169 ES1 = TopoDS::Edge(anIter1.Value());
170 ES2 = TopoDS::Edge(anIter2.Value());
171 if(!FF.Contains(ES1)) {
174 if(VS1.IsSame(sae.FirstVertex(ES1)))
175 VS1 = sae.LastVertex(ES1);
177 VS1 = sae.FirstVertex(ES1);
178 if(VS2.IsSame(sae.FirstVertex(ES2)))
179 VS2 = sae.LastVertex(ES2);
181 VS2 = sae.FirstVertex(ES2);
184 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);
326 //=======================================================================
327 //function : FillCorrespondingEdges
328 //purpose : auxilary for CreatePipeShellsWithoutPath()
329 //=======================================================================
330 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
331 const TopoDS_Shape& FS2,
332 const TopoDS_Vertex& aLoc1,
333 const TopoDS_Vertex& aLoc2,
334 TopTools_IndexedDataMapOfShapeShape& FF)
336 //cout<<"FillCorrespondingEdges"<<endl;
338 gp_Pnt P1 = BRep_Tool::Pnt(aLoc1);
339 gp_Pnt P2 = BRep_Tool::Pnt(aLoc2);
342 ShapeAnalysis_Edge sae;
343 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
344 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
345 TopTools_MapOfShape Vs1,Vs2;
347 TopoDS_Vertex V11=aLoc1, V12=aLoc2, V21, V22;
350 TopExp_Explorer exp1;
351 for( exp1.Init(FS1,TopAbs_EDGE); exp1.More(); exp1.Next() ) {
352 E1 = TopoDS::Edge(exp1.Current());
353 TopoDS_Vertex V1 = sae.FirstVertex(E1);
354 TopoDS_Vertex V2 = sae.LastVertex(E1);
355 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
356 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
357 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
358 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
359 if(P1.Distance(Ptmp1)<tol) {
363 if(P1.Distance(Ptmp2)<tol) {
370 TopoDS_Vertex VE21,VE22;
372 for( exp1.Init(FS2,TopAbs_EDGE); exp1.More() && nbe<2; exp1.Next() ) {
373 TopoDS_Edge E = TopoDS::Edge(exp1.Current());
374 TopoDS_Vertex V1 = sae.FirstVertex(E);
375 TopoDS_Vertex V2 = sae.LastVertex(E);
376 gp_Pnt Ptmp1 = BRep_Tool::Pnt(V1);
377 gp_Pnt Ptmp2 = BRep_Tool::Pnt(V2);
378 if(P2.Distance(Ptmp1)<tol) {
390 if(P2.Distance(Ptmp2)<tol) {
404 gp_Pnt PV21 = BRep_Tool::Pnt(V21);
405 gp_Pnt PE21 = BRep_Tool::Pnt(VE21);
406 gp_Pnt PE22 = BRep_Tool::Pnt(VE22);
407 gp_Vec aDir1(PV21,PE21);
408 gp_Vec aDir2(PV21,PE22);
409 double ang1 = aDir.Angle(aDir1);
410 double ang2 = aDir.Angle(aDir2);
411 if(fabs(ang1)<fabs(ang2)) {
424 // find other pairs for vertexes and edges
425 return FillForOtherEdges(FS1,E1,V21,FF);
429 //=======================================================================
430 //function : FindNextPairOfFaces
431 //purpose : auxilary for CreatePipeForShellSections()
432 //=======================================================================
433 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
434 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
435 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
436 TopTools_IndexedDataMapOfShapeShape& FF,
439 //cout<<"FindNextPairOfFaces"<<endl;
440 TopExp_Explorer anExp;
441 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
442 TopoDS_Shape E1 = anExp.Current();
443 if(!FF.Contains(E1)) {
445 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
448 MESSAGE (" FindNextPairOfFaces: map FF not contains key E1");
449 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
450 TopExp_Explorer anExpV;
451 anExpV.Init( E1, TopAbs_VERTEX );
452 TopoDS_Shape V1 = anExpV.Current();
453 if(!FF.Contains(V1)) {
455 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
458 if(!aMapEdgeFaces1.Contains(E1))
459 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces1 not contains key E1");
460 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
461 if(aList1.Extent()<2)
463 TopTools_ListIteratorOfListOfShape anIter(aList1);
464 if(anIter.Value().IsEqual(aCurFace)) {
467 TopoDS_Shape F1other = anIter.Value();
468 if(FF.Contains(F1other))
471 if(!FF.Contains(aCurFace))
472 MESSAGE (" FindNextPairOfFaces: map FF not contains key aCurFace");
473 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
474 if(!aMapEdgeFaces2.Contains(E2))
475 MESSAGE (" FindNextPairOfFaces: map aMapEdgeFaces2 not contains key E2");
476 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
477 if(aList2.Extent()<2) {
479 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
481 TopTools_ListIteratorOfListOfShape anIter2(aList2);
482 if(anIter2.Value().IsEqual(F2)) {
485 TopoDS_Shape F2other = anIter2.Value();
486 FF.Add(F1other,F2other);
488 // add pairs of edges to FF
489 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
492 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
495 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
500 //=======================================================================
501 //function : FindFirstPairFaces
502 //purpose : auxilary for Execute()
503 //=======================================================================
504 static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
505 TopoDS_Vertex& V1, TopoDS_Vertex& V2,
506 TopoDS_Shape& FS1, TopoDS_Shape& FS2)
508 //cout<<"FindFirstPairFaces"<<endl;
510 // check if vertexes are subshapes of sections
511 gp_Pnt P1 = BRep_Tool::Pnt(V1);
512 gp_Pnt P2 = BRep_Tool::Pnt(V2);
513 TopoDS_Vertex V1new,V2new;
515 double mindist = 1.e10;
516 for( exp.Init( S1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
517 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
518 gp_Pnt P = BRep_Tool::Pnt(V);
519 double dist = P1.Distance(P);
526 for( exp.Init( S2, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
527 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
528 gp_Pnt P = BRep_Tool::Pnt(V);
529 double dist = P2.Distance(P);
536 //gp_Pnt P1new = BRep_Tool::Pnt(V1new);
537 //gp_Pnt P2new = BRep_Tool::Pnt(V2new);
538 //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
539 //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
540 //cout<<" P1new("<<P1new.X()<<","<<P1new.Y()<<","<<P1new.Z()<<")"<<endl;
541 //cout<<" P2new("<<P2new.X()<<","<<P2new.Y()<<","<<P2new.Z()<<")"<<endl;
543 // replace vertexes if it is needed
544 if(!V1.IsSame(V1new)) {
546 P1 = BRep_Tool::Pnt(V1);
547 MESSAGE (" replace V1");
550 MESSAGE (" not replace V1");
551 if(!V2.IsSame(V2new)) {
553 P2 = BRep_Tool::Pnt(V2);
554 MESSAGE (" replace V2");
557 MESSAGE (" not replace V2");
559 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces1;
560 TopExp::MapShapesAndAncestors(S1, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces1);
561 TopTools_IndexedDataMapOfShapeListOfShape aMapVertFaces2;
562 TopExp::MapShapesAndAncestors(S2, TopAbs_VERTEX, TopAbs_FACE, aMapVertFaces2);
564 if(!aMapVertFaces1.Contains(V1))
565 MESSAGE (" FindFirstPairFaces: map aMapVertFaces1 not contains key V1");
566 const TopTools_ListOfShape& aList1 = aMapVertFaces1.FindFromKey(V1);
567 TopTools_ListIteratorOfListOfShape anIter1(aList1);
568 FS1 = anIter1.Value();
570 double x1=0., y1=0., z1=0.;
572 for( exp.Init( FS1, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
573 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
574 gp_Pnt P = BRep_Tool::Pnt(V);
580 gp_Pnt PM1(x1/nbv1, y1/nbv1, z1/nbv1);
582 TColgp_SequenceOfPnt Ps;
583 TopTools_SequenceOfShape Fs;
584 if(!aMapVertFaces2.Contains(V2))
585 MESSAGE (" FindFirstPairFaces: map aMapVertFaces2 not contains key V2");
586 const TopTools_ListOfShape& aList2 = aMapVertFaces2.FindFromKey(V2);
587 TopTools_ListIteratorOfListOfShape anIter2(aList2);
588 for(; anIter2.More(); anIter2.Next()) {
589 TopoDS_Shape F = anIter2.Value();
590 double x2=0., y2=0., z2=0.;
592 for( exp.Init( F, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
593 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
594 gp_Pnt P = BRep_Tool::Pnt(V);
600 gp_Pnt PM(x2/nbv1, y2/nbv1, z2/nbv1);
609 for(; i<=Fs.Length(); i++) {
610 gp_Vec tmpDir(PM1,Ps(i));
611 double ang = fabs(aDir.Angle(tmpDir));
621 //=======================================================================
622 //function : CreatePipeForShellSections
623 //purpose : auxilary for Execute()
624 //=======================================================================
625 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
628 //cout<<"CreatePipeForShellSections"<<endl;
633 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
634 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
635 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
636 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
637 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
638 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
640 Standard_Integer nbBases = aBasesObjs->Length(),
641 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
642 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
644 if( nbLocs != nbBases) {
646 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
648 if( nbSubBases && nbSubBases != nbBases) {
650 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
653 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
655 TopTools_SequenceOfShape VLocs;
656 for(i=1; i<=nbBases; i++) {
657 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
658 if(anItemLoc.IsNull())
660 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
661 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
662 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
664 VLocs.Append(aShapeLoc);
666 nbLocs = VLocs.Length();
667 if( nbLocs != nbBases) {
669 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
671 // split wire path by location points
672 TColgp_SequenceOfPnt PLocs;
673 for(i=1; i<=nbLocs; i++) {
674 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
675 PLocs.Append(BRep_Tool::Pnt(V));
678 TopTools_SequenceOfShape Edges;
679 TopTools_SequenceOfShape Wires;
680 ShapeAnalysis_Edge sae;
683 TopExp_Explorer anExp;
684 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
685 Edges.Append(anExp.Current());
687 Standard_Integer Num1 = 0;
688 Standard_Integer Num2 = 0;
689 for(i=1; i<=Edges.Length(); i++) {
690 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
691 double tol = BRep_Tool::Tolerance(E);
692 TopoDS_Vertex V1 = sae.FirstVertex(E);
693 TopoDS_Vertex V2 = sae.LastVertex(E);
694 gp_Pnt P1 = BRep_Tool::Pnt(V1);
695 gp_Pnt P2 = BRep_Tool::Pnt(V2);
696 if( P1.Distance(PLocs.First()) < tol ) {
699 if( P2.Distance(PLocs.Last()) < tol ) {
703 if( Num1>0 && Num2>0 ) {
706 for(i=Num1; i<=Num2; i++) {
707 B.Add(W,Edges.Value(i));
712 Wires.Append(aWirePath);
716 TopExp_Explorer anExp;
717 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
718 Edges.Append(anExp.Current());
720 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
721 double tol = BRep_Tool::Tolerance(edge);
722 TopoDS_Vertex VF = sae.FirstVertex(edge);
723 gp_Pnt PF = BRep_Tool::Pnt(VF);
724 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
725 if( PF.Distance(PLocs.First()) > tol ) {
727 Standard_ConstructionError::Raise
728 ("First location shapes is not coincided with first vertex of aWirePath");
730 VLocs.ChangeValue(1) = VF;
731 edge = TopoDS::Edge(Edges.Last());
732 tol = BRep_Tool::Tolerance(edge);
733 TopoDS_Vertex VL = sae.LastVertex(edge);
734 gp_Pnt PL = BRep_Tool::Pnt(VL);
735 if( PL.Distance(PLocs.Last()) > tol ) {
737 Standard_ConstructionError::Raise
738 ("Last location shapes is not coincided with last vertex of aWirePath");
740 VLocs.ChangeValue(nbLocs) = VL;
742 TopTools_SequenceOfShape tmpEdges;
743 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
744 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
745 tol = BRep_Tool::Tolerance(E);
746 TopoDS_Vertex V1 = sae.FirstVertex(E);
747 TopoDS_Vertex V2 = sae.LastVertex(E);
748 gp_Pnt P1 = BRep_Tool::Pnt(V1);
749 gp_Pnt P2 = BRep_Tool::Pnt(V2);
750 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
751 // make wire from current edge and add created
755 for(j=1; j<=tmpEdges.Length(); j++)
756 B.Add(W,tmpEdges.Value(j));
759 VLocs.ChangeValue(jcurr) = V2;
764 // find distance between E and aLocs(jcurr)
766 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
767 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
768 if( PPC.NbPoints()>0 &&
769 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
770 double param = PPC.Parameter(1);
773 // split current edge
774 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
775 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
779 if(Pfp.Distance(P1)<tol) {
780 B.MakeEdge(E1,tc1,tol);
782 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
783 B.Add(E1,TopoDS::Vertex(tmpV));
785 B.MakeEdge(E2,tc2,tol);
786 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
787 B.Add(E2,TopoDS::Vertex(tmpV));
791 B.MakeEdge(E1,tc2,tol);
792 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
793 B.Add(E1,TopoDS::Vertex(tmpV));
797 B.MakeEdge(E2,tc1,tol);
799 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
800 B.Add(E2,TopoDS::Vertex(tmpV));
803 // create wire from tmpEdges
806 for(j=1; j<=tmpEdges.Length(); j++)
807 B.Add(W,tmpEdges.Value(j));
812 Edges.InsertAfter(i-1,E1);
813 Edges.InsertAfter(i,E2);
820 // create wire from other edges
823 for(; i<=Edges.Length(); i++)
824 B.Add(W,Edges.Value(i));
826 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
829 if( Wires.Length() != nbLocs-1 ) {
831 Standard_ConstructionError::Raise
832 ("One of location shapes is not lied on the path");
835 //TopTools_SequenceOfShape aSeqBases;
836 //TopTools_SequenceOfShape aSeqSubBases;
837 //TopTools_SequenceOfShape aSeqFaces;
838 TopoDS_Compound aComp;
839 B.MakeCompound(aComp);
840 for(i=1 ; i<nbBases; i++) {
841 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
843 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
846 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
847 if(aRefBase1.IsNull())
849 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
850 if(aShBase1.IsNull())
852 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
854 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
857 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
858 if(aRefBase2.IsNull())
860 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
861 if(aShBase2.IsNull())
863 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
865 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
867 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
868 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
871 Standard_ConstructionError::Raise("One of section shapes has invalid type");
874 bool CreateFewSolids = false;
876 TopExp_Explorer anExp;
877 Standard_Integer nbf1 = 0;
878 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
881 Standard_Integer nbf2 = 0;
882 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
886 CreateFewSolids = true;
890 // check orientation of sections
891 bool NeedReverse = false;
894 anExp.Init( aShBase1, TopAbs_FACE );
895 TopoDS_Shape aFace = anExp.Current();
896 TColgp_SequenceOfPnt aPnts;
897 double xc=0, yc=0, zc=0;
898 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
899 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
900 aPnts.Append(BRep_Tool::Pnt(V));
901 xc += aPnts.Last().X();
902 yc += aPnts.Last().Y();
903 zc += aPnts.Last().Z();
905 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
906 gp_Vec V1(PC,aPnts.Value(1));
907 gp_Vec V2(PC,aPnts.Value(2));
908 gp_Vec VN = V1.Crossed(V2);
909 for(int ip=2; ip<aPnts.Length(); ip++) {
910 V1 = gp_Vec(PC,aPnts.Value(ip));
911 V2 = gp_Vec(PC,aPnts.Value(ip+1));
912 VN.Add(V1.Crossed(V2));
915 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
917 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
918 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
919 double tol = BRep_Tool::Tolerance(edge);
920 TopoDS_Vertex VF = sae.FirstVertex(edge);
921 gp_Pnt PF = BRep_Tool::Pnt(VF);
922 if( PF.Distance(PLoc) < tol ) {
924 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
927 if( P1.Distance(PLoc) < tol ) {
928 C->D0(fp+(lp-fp)/100,P2);
932 C->D0(lp+(fp-lp)/100,P2);
934 PathNorm = gp_Vec(P1,P2);
938 TopoDS_Vertex VL = sae.LastVertex(edge);
939 gp_Pnt PL = BRep_Tool::Pnt(VL);
940 if( PL.Distance(PLoc) < tol ) {
942 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
945 if( P1.Distance(PLoc) < tol ) {
946 C->D0(fp+(lp-fp)/100,P2);
950 C->D0(lp+(fp-lp)/100,P2);
952 PathNorm = gp_Vec(P2,P1);
957 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
958 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
959 if(fabs(VN.Angle(PathNorm))>PI/2.) {
966 anExp.Init( aShBase2, TopAbs_FACE );
967 TopoDS_Shape aFace = anExp.Current();
968 TColgp_SequenceOfPnt aPnts;
969 double xc=0, yc=0, zc=0;
970 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
971 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
972 aPnts.Append(BRep_Tool::Pnt(V));
973 xc += aPnts.Last().X();
974 yc += aPnts.Last().Y();
975 zc += aPnts.Last().Z();
977 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
978 gp_Vec V1(PC,aPnts.Value(1));
979 gp_Vec V2(PC,aPnts.Value(2));
980 gp_Vec VN = V1.Crossed(V2);
981 for(int ip=2; ip<aPnts.Length(); ip++) {
982 V1 = gp_Vec(PC,aPnts.Value(ip));
983 V2 = gp_Vec(PC,aPnts.Value(ip+1));
984 VN.Add(V1.Crossed(V2));
987 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
989 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
990 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
991 double tol = BRep_Tool::Tolerance(edge);
992 TopoDS_Vertex VF = sae.FirstVertex(edge);
993 gp_Pnt PF = BRep_Tool::Pnt(VF);
994 if( PF.Distance(PLoc) < tol ) {
996 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
999 if( P1.Distance(PLoc) < tol ) {
1000 C->D0(fp+(lp-fp)/100,P2);
1004 C->D0(lp+(fp-lp)/100,P2);
1006 PathNorm = gp_Vec(P2,P1);
1010 TopoDS_Vertex VL = sae.LastVertex(edge);
1011 gp_Pnt PL = BRep_Tool::Pnt(VL);
1012 if( PL.Distance(PLoc) < tol ) {
1014 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
1017 if( P1.Distance(PLoc) < tol ) {
1018 C->D0(fp+(lp-fp)/100,P2);
1022 C->D0(lp+(fp-lp)/100,P2);
1024 PathNorm = gp_Vec(P2,P1);
1029 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
1030 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
1031 if(fabs(VN.Angle(PathNorm))>PI/2.)
1036 if(!CreateFewSolids) {
1037 // we can create only one solid
1038 TopoDS_Shape aWire1, aWire2;
1040 if(aType1==TopAbs_SHELL) {
1041 // create wire as boundary contour if shell is no closed
1042 // get free boundary shapes
1043 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
1044 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1045 //TopExp_Explorer anExp;
1046 Standard_Integer NbWires = 0;
1047 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1049 aWire1 = anExp.Current();
1054 Standard_ConstructionError::Raise("Bad shell is used as section ");
1057 else { // aType1==TopAbs_FACE
1058 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
1059 aWire1 = aExpW.Current();
1062 if(aType2==TopAbs_SHELL) {
1063 // create wire as boundary contour if shell is no closed
1064 // get free boundary shapes
1065 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
1066 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1067 //TopExp_Explorer anExp;
1068 Standard_Integer NbWires = 0;
1069 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1071 aWire2 = anExp.Current();
1076 Standard_ConstructionError::Raise("Bad shell is used as section ");
1079 else { // aType2==TopAbs_FACE
1080 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
1081 aWire2 = aExpW.Current();
1083 // make pipe using aWire1 and aWire2
1084 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1085 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1086 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1087 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1088 aWithContact, aWithCorrect);
1089 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1090 aWithContact, aWithCorrect);
1091 if(!aBuilder.IsReady()) {
1093 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1096 TopoDS_Shape aShape = aBuilder.Shape();
1097 TopoDS_Shell aShell;
1098 B.MakeShell(aShell);
1099 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1100 B.Add(aShell,anExp.Current());
1102 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1103 B.Add(aShell,anExp.Current());
1105 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1106 B.Add(aShell,anExp.Current());
1108 // make sewing for this shell
1109 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1110 aSewing->SetTolerance(Precision::Confusion());
1111 aSewing->SetFaceMode(Standard_True);
1112 aSewing->SetFloatingEdgesMode(Standard_False);
1113 aSewing->SetNonManifoldMode(Standard_False);
1114 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1115 aSewing->Add(anExp.Current());
1118 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1119 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1120 aShell = TopoDS::Shell(aSewShape);
1121 GProp_GProps aSystem;
1122 BRepGProp::VolumeProperties(aShell, aSystem);
1123 if(aSystem.Mass()<0) {
1126 if(BRep_Tool::IsClosed(aShell)) {
1127 TopoDS_Solid aSolid;
1128 B.MakeSolid(aSolid);
1129 B.Add(aSolid,aShell);
1130 B.Add(aComp,aSolid);
1133 B.Add(aComp,aShell);
1137 B.Add(aComp,aShell);
1142 // main block - creation few solids (for each pair of faces)
1143 TopTools_MapOfShape aFaces1,aFaces2;
1144 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1145 aFaces1.Add(anExp.Current());
1147 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1148 aFaces2.Add(anExp.Current());
1150 // creating map of edge faces
1151 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1152 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1153 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1154 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1156 // constuct map face->face
1157 TopTools_IndexedDataMapOfShapeShape FF;
1158 TopoDS_Shape FS1,FS2;
1160 // find edge the most distant from location point
1161 // (this edge is not shared by two faces)
1162 double maxdist = 0.;
1164 TopoDS_Vertex V11,V21;
1165 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
1166 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
1167 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
1168 if(aList.Extent()>1)
1170 TopExp_Explorer expv;
1171 expv.Init( tmp, TopAbs_VERTEX );
1172 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
1174 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
1175 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1176 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1177 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
1182 TopTools_ListIteratorOfListOfShape anIter(aList);
1183 FS1 = anIter.Value();
1187 // main direction for comparing
1188 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
1189 // find corresponding edge from next section
1191 gp_Pnt P11 = BRep_Tool::Pnt(V11);
1192 gp_Pnt P21 = BRep_Tool::Pnt(V21);
1194 TopoDS_Vertex V12,V22;
1195 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
1196 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
1197 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
1198 if(aList.Extent()>1)
1200 TopExp_Explorer expv;
1201 expv.Init( tmp, TopAbs_VERTEX );
1202 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
1204 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
1205 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
1206 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
1207 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
1208 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
1209 TopoDS_Vertex V1,V2;
1212 V1 = V2tmp; P1 = P2tmp;
1213 V2 = V1tmp; P2 = P1tmp;
1216 V1 = V1tmp; P1 = P1tmp;
1217 V2 = V2tmp; P2 = P2tmp;
1219 gp_Vec Vec1(P11,P1);
1220 gp_Vec Vec2(P21,P2);
1221 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
1226 TopTools_ListIteratorOfListOfShape anIter(aList);
1227 FS2 = anIter.Value();
1231 // put all pairs to map FF
1237 // add pairs of edges to FF
1238 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
1241 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
1247 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
1248 if(anItem.IsNull()) {
1250 Standard_ConstructionError::Raise("Invalid subbase shape");
1252 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1253 if(aRefBase.IsNull()) {
1255 Standard_ConstructionError::Raise("Invalid subbase shape");
1257 TopoDS_Shape aSh = aRefBase->GetValue();
1260 Standard_ConstructionError::Raise("Invalid subbase shape");
1262 if(aSh.ShapeType()!=TopAbs_FACE) {
1264 Standard_ConstructionError::Raise("Invalid subbase shape");
1269 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
1270 if(anItem.IsNull()) {
1272 Standard_ConstructionError::Raise("Invalid subbase shape");
1274 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1275 if(aRefBase.IsNull()) {
1277 Standard_ConstructionError::Raise("Invalid subbase shape");
1279 TopoDS_Shape aSh = aRefBase->GetValue();
1282 Standard_ConstructionError::Raise("Invalid subbase shape");
1284 if(aSh.ShapeType()!=TopAbs_FACE) {
1286 Standard_ConstructionError::Raise("Invalid subbase shape");
1291 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
1293 Standard_ConstructionError::Raise("Invalid subbase shape");
1298 // add pairs of edges to FF
1299 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1300 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1303 Standard_ConstructionError::Raise("Can not create correct pipe");
1307 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1310 // make pipe for each pair of faces
1311 for(j=1; j<=FF.Extent(); j++) {
1312 TopoDS_Shape F1 = FF.FindKey(j);
1313 if( F1.ShapeType() != TopAbs_FACE )
1315 TopoDS_Shape F2 = FF.FindFromIndex(j);
1316 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1317 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1318 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1319 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1320 // make pipe using aWire1 and aWire2
1321 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1322 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1323 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1324 aWithContact, aWithCorrect);
1325 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1326 aWithContact, aWithCorrect);
1327 if(!aBuilder.IsReady()) {
1329 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1332 TopoDS_Shape aShape = aBuilder.Shape();
1333 TopoDS_Shell aShell;
1334 B.MakeShell(aShell);
1335 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1336 B.Add(aShell,anExp.Current());
1341 // make sewing for this shell
1342 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1343 aSewing->SetTolerance(Precision::Confusion());
1344 aSewing->SetFaceMode(Standard_True);
1345 aSewing->SetFloatingEdgesMode(Standard_False);
1346 aSewing->SetNonManifoldMode(Standard_False);
1347 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1348 aSewing->Add(anExp.Current());
1351 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1352 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1353 aShell = TopoDS::Shell(aSewShape);
1354 GProp_GProps aSystem;
1355 BRepGProp::VolumeProperties(aShell, aSystem);
1356 if(aSystem.Mass()<0) {
1357 //cout<<"aSewShape is reversed"<<endl;
1360 if(BRep_Tool::IsClosed(aShell)) {
1361 TopoDS_Solid aSolid;
1362 B.MakeSolid(aSolid);
1363 B.Add(aSolid,aShell);
1364 B.Add(aComp,aSolid);
1367 B.Add(aComp,aShell);
1371 B.Add(aComp,aShell);
1379 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1384 //=======================================================================
1385 //function : CreatePipeShellsWithoutPath
1386 //purpose : auxilary for Execute()
1387 //=======================================================================
1388 static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
1390 //cout<<"CreatePipeShellsWithoutPath"<<endl;
1394 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
1396 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
1397 // vertex for recognition
1398 Handle(TColStd_HSequenceOfTransient) VObjs = aCIDS->GetLocations();
1400 Standard_Integer nbBases = aBasesObjs->Length(),
1401 nbv = (VObjs.IsNull() ? 0 :VObjs->Length());
1403 if( nbv != nbBases ) {
1405 Standard_ConstructionError::Raise("Number of shapes for recognition is invalid");
1409 TopTools_SequenceOfShape SecVs,Bases;
1410 for(i=1; i<=nbBases; i++) {
1412 Handle(Standard_Transient) anItem = VObjs->Value(i);
1415 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(anItem);
1416 TopoDS_Shape V = aRef->GetValue();
1417 if(V.IsNull() || V.ShapeType() != TopAbs_VERTEX)
1421 anItem = aBasesObjs->Value(i);
1424 aRef = Handle(GEOM_Function)::DownCast(anItem);
1425 TopoDS_Shape aSh = aRef->GetValue();
1430 nbv = SecVs.Length();
1431 nbBases = Bases.Length();
1432 if( nbv != nbBases ) {
1434 Standard_ConstructionError::Raise("One of shapes for recognition is not a vertex");
1437 TopoDS_Compound aComp;
1438 B.MakeCompound(aComp);
1440 for(i=1 ; i<nbBases; i++) {
1441 MESSAGE ("Make pipe between sections "<<i<<" and "<<i+1);
1442 TopoDS_Shape aShBase1 = Bases.Value(i);
1443 TopoDS_Shape aShBase2 = Bases.Value(i+1);
1444 TopExp_Explorer anExp;
1445 Standard_Integer nbf1 = 0;
1446 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1449 Standard_Integer nbf2 = 0;
1450 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1453 //cout<<"nbf1="<<nbf1<<" nbf2="<<nbf2<<endl;
1456 Standard_ConstructionError::Raise("Different number of faces in the sections");
1459 TopTools_MapOfShape aFaces1,aFaces2;
1460 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1461 aFaces1.Add(anExp.Current());
1463 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1464 aFaces2.Add(anExp.Current());
1467 // creating map of edge faces
1468 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
1469 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
1470 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
1471 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
1473 // constuct map face->face (and subshapes)
1474 TopTools_IndexedDataMapOfShapeShape FF;
1475 //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
1476 TopoDS_Shape FS1, FS2;
1477 TopoDS_Vertex V1 = TopoDS::Vertex(SecVs(i));
1478 TopoDS_Vertex V2 = TopoDS::Vertex(SecVs(i+1));
1479 FindFirstPairFaces(aShBase1, aShBase2, V1, V2, FS1, FS2);
1482 MESSAGE (" first pair of corresponding faces is found");
1484 // add pairs of edges and vertexes to FF
1485 bool stat = FillCorrespondingEdges(FS1, FS2, V1, V2, FF);
1488 Standard_ConstructionError::Raise("Can not create correct pipe");
1490 MESSAGE (" correspondences for subshapes of first pair of faces is found");
1492 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1493 MESSAGE (" other correspondences is found, make pipe for all pairs of faces");
1495 // make pipe for each pair of faces
1496 // auxilary map vertex->edge for created pipe edges
1497 TopTools_IndexedDataMapOfShapeShape VPE;
1498 ShapeAnalysis_Edge sae;
1499 //cout<<"FF.Extent()="<<FF.Extent()<<endl;
1501 for(j=1; j<=FF.Extent(); j++) {
1502 TopoDS_Shape F1 = FF.FindKey(j);
1503 if( F1.ShapeType() != TopAbs_FACE )
1505 TopoDS_Shape F2 = FF.FindFromIndex(j);
1508 //if(nbff!=3) continue;
1510 MESSAGE (" make pipe for "<<nbff<<" face");
1512 Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(F1));
1513 if(S1->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1514 Handle(Geom_RectangularTrimmedSurface) RTS =
1515 Handle(Geom_RectangularTrimmedSurface)::DownCast(S1);
1516 S1 = RTS->BasisSurface();
1518 Handle(Geom_Plane) Pln1 = Handle(Geom_Plane)::DownCast(S1);
1519 if( Pln1.IsNull() ) {
1521 Standard_ConstructionError::Raise("Surface from face is not plane");
1523 gp_Vec aDir1(Pln1->Axis().Direction());
1525 Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(F2));
1526 if(S2->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1527 Handle(Geom_RectangularTrimmedSurface) RTS =
1528 Handle(Geom_RectangularTrimmedSurface)::DownCast(S2);
1529 S2 = RTS->BasisSurface();
1531 Handle(Geom_Plane) Pln2 =
1532 Handle(Geom_Plane)::DownCast(S2);
1533 if( Pln2.IsNull() ) {
1535 Standard_ConstructionError::Raise("Surface from face is not plane");
1537 gp_Vec aDir2(Pln2->Axis().Direction());
1539 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i)));
1540 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(SecVs(i+1)));
1542 if(fabs(aDir.Angle(aDir1))>PI/2.)
1544 if(fabs(aDir.Angle(aDir2))>PI/2.)
1547 TopExp_Explorer anExpE(F1,TopAbs_EDGE);
1548 TopTools_SequenceOfShape aNewFs;
1550 for(; anExpE.More(); anExpE.Next()) {
1551 TopoDS_Edge E1 = TopoDS::Edge(anExpE.Current());
1553 if(!FF.Contains(E1))
1554 MESSAGE ("map FF not contains key E1");
1556 if(VPE.Contains(E1)) {
1557 aNewFs.Append(VPE.FindFromKey(E1));
1559 MESSAGE (" using existed face");
1564 TopoDS_Edge E3 = TopoDS::Edge(FF.FindFromKey(E1));
1565 TopoDS_Vertex V1 = sae.FirstVertex(E1);
1566 TopoDS_Vertex V2 = sae.LastVertex(E1);
1567 if(!FF.Contains(V1))
1568 MESSAGE ("map FF not contains key V1");
1569 if(!FF.Contains(V2))
1570 MESSAGE ("map FF not contains key V2");
1571 TopoDS_Vertex V3 = TopoDS::Vertex(FF.FindFromKey(V2));
1572 TopoDS_Vertex V4 = TopoDS::Vertex(FF.FindFromKey(V1));
1573 TopoDS_Vertex Vtmp = sae.FirstVertex(E3);
1576 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1577 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1578 gp_Pnt P3 = BRep_Tool::Pnt(V3);
1579 gp_Pnt P4 = BRep_Tool::Pnt(V4);
1582 Handle(Geom_BSplineCurve) C2;
1583 if(VPE.Contains(V2)) {
1584 E2 = TopoDS::Edge(VPE.FindFromKey(V2));
1586 C2 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E2,fp,lp));
1589 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1590 HAP->SetValue(1,P2);
1591 HAP->SetValue(2,P3);
1592 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1593 anInt.Load(aDir1,aDir2);
1596 B.MakeEdge(E2,C2,1.e-7);
1597 B.Add(E2,TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD)));
1598 B.Add(E2,TopoDS::Vertex(V3.Oriented(TopAbs_REVERSED)));
1603 Handle(Geom_BSplineCurve) C4;
1604 if(VPE.Contains(V1)) {
1605 E4 = TopoDS::Edge(VPE.FindFromKey(V1));
1607 C4 = Handle(Geom_BSplineCurve)::DownCast(BRep_Tool::Curve(E4,fp,lp));
1610 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1611 HAP->SetValue(1,P1);
1612 HAP->SetValue(2,P4);
1613 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1614 anInt.Load(aDir1,aDir2);
1617 B.MakeEdge(E4,anInt.Curve(),1.e-7);
1618 B.Add(E4,TopoDS::Vertex(V1.Oriented(TopAbs_FORWARD)));
1619 B.Add(E4,TopoDS::Vertex(V4.Oriented(TopAbs_REVERSED)));
1628 B.Add(W,E4.Reversed());
1629 //cout<<" wire for edge "<<nbee<<" is created"<<endl;
1630 //BRepTools::Write(W,"/dn02/users_Linux/skl/work/Bugs/14857/w.brep");
1635 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1636 //bool IsConicC1 = false;
1637 //if( C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1638 // IsConicC1 = true;
1639 // cout<<"C1 - Geom_Conic"<<endl;
1641 if( C1->IsKind(STANDARD_TYPE(Geom_Line)) || C1->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1642 C1 = new Geom_TrimmedCurve(C1,fp,lp);
1645 // double tol = BRep_Tool::Tolerance(E1);
1646 // GeomConvert_ApproxCurve ApxC1(C1,tol,GeomAbs_C1,10,5);
1647 // C1 = ApxC1.Curve();
1649 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp,lp);
1650 if( C3->IsKind(STANDARD_TYPE(Geom_Line)) || C3->IsKind(STANDARD_TYPE(Geom_Conic)) ) {
1651 C3 = new Geom_TrimmedCurve(C3,fp,lp);
1656 Handle(Geom_BSplineCurve) CE1 =
1657 GeomConvert::CurveToBSplineCurve(C1,Convert_RationalC1);
1659 CE1->IncreaseDegree(3);
1660 Handle(Geom_BSplineCurve) CE2 =
1661 GeomConvert::CurveToBSplineCurve(C2,Convert_RationalC1);
1663 CE2->IncreaseDegree(3);
1664 Handle(Geom_BSplineCurve) CE3 =
1665 GeomConvert::CurveToBSplineCurve(C3,Convert_RationalC1);
1667 CE3->IncreaseDegree(3);
1668 Handle(Geom_BSplineCurve) CE4 =
1669 GeomConvert::CurveToBSplineCurve(C4,Convert_RationalC1);
1671 CE4->IncreaseDegree(3);
1672 //cout<<"CE1->Degree()="<<CE1->Degree()<<" CE2->Degree()="<<CE2->Degree()
1673 // <<" CE3->Degree()="<<CE3->Degree()<<" CE4->Degree()="<<CE4->Degree()<<endl;
1674 //if(fic.open("/dn02/users_Linux/skl/work/Bugs/14857/ce1.brep",ios::out)) {
1675 // os<<"DrawTrSurf_BSplineCurve"<<endl;
1676 // GeomTools::Write(CE1,os);
1680 Handle(Geom_Surface) BS;
1682 GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_CoonsStyle);
1683 //GeomFill_BSplineCurves GF(CE1,CE2,CE3,CE4,GeomFill_StretchStyle);
1687 MESSAGE (" can not create BSplineSurface - create Bezier");
1689 TColgp_Array2OfPnt Points(1,NbP,1,NbP);
1690 double fp1,lp1,fp2,lp2;
1691 Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp1,lp1);
1692 Handle(Geom_Curve) C3 = BRep_Tool::Curve(E3,fp2,lp2);
1701 // get points from C1
1702 if(P1.Distance(P1C1)<1.e-6) {
1710 double step = (lp-fp)/(NbP-1);
1711 Points.SetValue(1,1,P1);
1713 for(n1=2; n1<NbP; n1++) {
1717 Points.SetValue(1,n1,P);
1719 Points.SetValue(1,NbP,P2);
1720 // get points from C3
1721 if(P4.Distance(P1C3)<1.e-6) {
1729 step = (lp-fp)/(NbP-1);
1730 Points.SetValue(NbP,1,P4);
1732 for(n1=2; n1<NbP; n1++) {
1736 Points.SetValue(NbP,n1,P);
1738 Points.SetValue(NbP,NbP,P3);
1739 // create isolines and get points from them
1740 for(n1=1; n1<=NbP; n1++) {
1741 gp_Pnt PI1 = Points.Value(1,n1);
1742 gp_Pnt PI2 = Points.Value(NbP,n1);
1743 Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,2);
1744 HAP->SetValue(1,PI1);
1745 HAP->SetValue(2,PI2);
1746 GeomAPI_Interpolate anInt(HAP,Standard_False,1.e-7);
1747 anInt.Load(aDir1,aDir2);
1749 Handle(Geom_Curve) iso = anInt.Curve();
1750 fp = iso->FirstParameter();
1751 lp = iso->LastParameter();
1752 step = (lp-fp)/(NbP-1);
1754 TopoDS_Compound VComp;
1755 B.MakeCompound(VComp);
1756 for(n2=2; n2<NbP; n2++) {
1760 Points.SetValue(n2,n1,P);
1763 // create surface and face
1764 //Handle(Geom_BezierSurface) BS = new Geom_BezierSurface(Points);
1765 BS = new Geom_BezierSurface(Points);
1768 BRepBuilderAPI_MakeFace BB(BS,W);
1769 TopoDS_Face NewF = BB.Face();
1770 Handle(ShapeFix_Face) sff = new ShapeFix_Face(NewF);
1772 sff->FixOrientation();
1773 TopoDS_Face FixedFace = sff->Face();
1774 aNewFs.Append(FixedFace);
1775 VPE.Add(E1,FixedFace);
1776 //cout<<" face for edge "<<nbee<<" is created"<<endl;
1777 //BRepTools::Write(FixedFace,"/dn02/users_Linux/skl/work/Bugs/14857/f.brep");
1780 TopoDS_Shell aShell;
1781 B.MakeShell(aShell);
1782 for(int nf=1; nf<=aNewFs.Length(); nf++) {
1783 B.Add(aShell,aNewFs(nf));
1788 // make sewing for this shell
1789 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1790 aSewing->SetTolerance(Precision::Confusion());
1791 aSewing->SetFaceMode(Standard_True);
1792 aSewing->SetFloatingEdgesMode(Standard_False);
1793 aSewing->SetNonManifoldMode(Standard_False);
1794 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1795 aSewing->Add(anExp.Current());
1798 MESSAGE (" shell for face "<<nbff<<" is created");
1799 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1800 //BRepTools::Write(aSewShape,"/dn02/users_Linux/skl/work/Bugs/14857/sew.brep");
1801 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1802 aShell = TopoDS::Shell(aSewShape);
1803 GProp_GProps aSystem;
1804 BRepGProp::VolumeProperties(aShell, aSystem);
1805 if(aSystem.Mass()<0) {
1806 //cout<<"aSewShape is reversed"<<endl;
1809 if(BRep_Tool::IsClosed(aShell)) {
1810 TopoDS_Solid aSolid;
1811 B.MakeSolid(aSolid);
1812 B.Add(aSolid,aShell);
1813 B.Add(aComp,aSolid);
1814 MESSAGE (" solid for face "<<nbff<<" is created");
1817 B.Add(aComp,aShell);
1818 MESSAGE (" solid for face "<<nbff<<" is not created");
1822 B.Add(aComp,aShell);
1823 MESSAGE (" solid for face "<<nbff<<" is not created");
1825 //cout<<" solid for face "<<nbff<<" is created"<<endl;
1827 //Handle(ShapeFix_Shell) sfs = new ShapeFix_Shell(aShell);
1829 //TopoDS_Shell FixedShell = sfs->Shell();
1831 GProp_GProps aSystem;
1832 BRepGProp::VolumeProperties(FixedShell, aSystem);
1833 if(aSystem.Mass()<0) {
1834 //cout<<"aSewShape is reversed"<<endl;
1835 FixedShell.Reverse();
1837 if(BRep_Tool::IsClosed(FixedShell)) {
1838 TopoDS_Solid aSolid;
1839 B.MakeSolid(aSolid);
1840 B.Add(aSolid,aShell);
1841 B.Add(aComp,aSolid);
1844 B.Add(aComp,FixedShell);
1850 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1855 //=======================================================================
1856 //function : CreatePipeBiNormalAlongVector
1857 //purpose : auxilary for Execute()
1858 //=======================================================================
1859 static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
1860 GEOMImpl_IPipe* aCI)
1862 GEOMImpl_IPipeBiNormal* aCIBN = (GEOMImpl_IPipeBiNormal*)aCI;
1864 Handle(GEOM_Function) aRefBase = aCIBN->GetBase();
1865 Handle(GEOM_Function) aRefVec = aCIBN->GetVector();
1866 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1867 TopoDS_Shape aShapeVec = aRefVec->GetValue();
1869 if (aShapeBase.IsNull()) {
1870 if(aCIBN) delete aCIBN;
1871 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1875 if( aShapeBase.ShapeType() == TopAbs_VERTEX ) {
1878 else if( aShapeBase.ShapeType() == TopAbs_EDGE) {
1879 aProf = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)).Shape();
1881 else if( aShapeBase.ShapeType() == TopAbs_WIRE) {
1884 else if( aShapeBase.ShapeType() == TopAbs_FACE) {
1885 TopExp_Explorer wexp(aShapeBase,TopAbs_WIRE);
1886 aProf = wexp.Current();
1889 Standard_TypeMismatch::Raise
1890 ("MakePipe aborted : invalid type of base");
1892 BRepOffsetAPI_MakePipeShell PipeBuilder(aWirePath);
1893 PipeBuilder.Add(aProf);
1895 if (aShapeVec.IsNull()) {
1896 if(aCIBN) delete aCIBN;
1897 Standard_NullObject::Raise
1898 ("MakePipe aborted : null vector argument");
1900 if (aShapeVec.ShapeType() != TopAbs_EDGE)
1901 Standard_TypeMismatch::Raise
1902 ("MakePipe aborted: invalid type of vector");
1903 TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec);
1904 TopoDS_Vertex V1, V2;
1905 TopExp::Vertices(anEdge, V1, V2, Standard_True);
1906 if (V1.IsNull() || V2.IsNull())
1907 Standard_NullObject::Raise
1908 ("MakePipe aborted: vector is not defined");
1909 gp_Vec aVec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
1910 gp_Dir BiNormal(aVec);
1911 PipeBuilder.SetMode(BiNormal);
1912 PipeBuilder.Build();
1913 if( aShapeBase.ShapeType() == TopAbs_FACE) {
1914 PipeBuilder.MakeSolid();
1917 return PipeBuilder.Shape();
1921 //=======================================================================
1922 //function : Execute
1924 //=======================================================================
1925 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1927 //cout<<"PipeDriver::Execute"<<endl;
1928 if (Label().IsNull()) return 0;
1929 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1930 GEOMImpl_IPipe* aCI= 0;
1931 Standard_Integer aType = aFunction->GetType();
1932 if(aType == PIPE_BASE_PATH)
1933 aCI = new GEOMImpl_IPipe(aFunction);
1934 else if(aType == PIPE_DIFFERENT_SECTIONS)
1935 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1936 else if(aType == PIPE_SHELL_SECTIONS)
1937 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1938 else if(aType == PIPE_SHELLS_WITHOUT_PATH)
1939 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1940 else if(aType == PIPE_BI_NORMAL_ALONG_VECTOR)
1941 aCI = new GEOMImpl_IPipeBiNormal(aFunction);
1945 TopoDS_Wire aWirePath;
1946 if(aType != PIPE_SHELLS_WITHOUT_PATH) {
1947 // working with path
1948 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1949 TopoDS_Shape aShapePath = aRefPath->GetValue();
1951 if (aShapePath.IsNull()) {
1952 MESSAGE ("Driver : path is null");
1954 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1958 if (aShapePath.ShapeType() == TopAbs_WIRE) {
1959 aWirePath = TopoDS::Wire(aShapePath);
1962 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1963 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1964 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1968 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1973 TopoDS_Shape aShape;
1975 if (aType == PIPE_BASE_PATH)
1977 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1978 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1980 if (aShapeBase.IsNull()) {
1982 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1986 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
1989 //building pipe with different sections
1990 else if (aType == PIPE_DIFFERENT_SECTIONS) {
1991 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
1992 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
1993 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1994 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
1995 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
1996 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
1997 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1999 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
2000 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
2002 if(nbLocs && nbLocs != nbBases) {
2004 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
2006 TopTools_SequenceOfShape aSeqBases;
2007 TopTools_SequenceOfShape aSeqLocs;
2008 TopTools_SequenceOfShape aSeqFaces;
2009 for( ; i <= nbBases; i++) {
2010 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
2013 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
2014 if(aRefBase.IsNull())
2016 TopoDS_Shape aShapeBase = aRefBase->GetValue();
2017 if(aShapeBase.IsNull())
2019 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
2021 //if for section was specified face with a few wires then a few
2022 // pipes were build and make solid
2023 Standard_Boolean NeedCreateSolid = Standard_False;
2024 if(aTypeBase == TopAbs_SHELL) {
2025 // create wire as boundary contour if shell is no closed
2026 // get free boundary shapes
2027 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
2028 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
2029 TopExp_Explorer anExp;
2031 Standard_Integer NbWires = 0;
2032 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
2034 aWire = anExp.Current();
2039 Standard_ConstructionError::Raise("Bad shell is used as section ");
2041 NeedCreateSolid = Standard_True;
2042 aSeqFaces.Append(aShapeBase);
2043 aSeqBases.Append(aWire);
2045 else if(aTypeBase == TopAbs_FACE) {
2046 NeedCreateSolid = Standard_True;
2047 //for case one path should be used other type function
2048 aSeqFaces.Append(aShapeBase);
2049 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
2050 for( ; aExpW.More(); aExpW.Next())
2052 TopoDS_Shape aWireProf = aExpW.Current();
2053 aSeqBases.Append(aWireProf);
2056 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
2057 aSeqBases.Append(aShapeBase);
2059 else if(aTypeBase == TopAbs_EDGE) {
2060 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
2061 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
2062 aSeqBases.Append(aWireProf);
2065 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
2066 if(anItemLoc.IsNull())
2068 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
2069 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
2070 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
2072 aSeqLocs.Append(aShapeLoc);
2076 nbLocs = aSeqLocs.Length();
2079 TopTools_SequenceOfShape Edges;
2081 // we have to check that each location shape is a vertex from
2082 // path and update aSeqLocs if it is needed (and possible)
2083 TColgp_SequenceOfPnt PLocs;
2084 for(i=1; i<=nbLocs; i++) {
2085 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
2086 PLocs.Append(BRep_Tool::Pnt(V));
2088 //TopTools_SequenceOfShape Edges;
2089 TopExp_Explorer anExp;
2090 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
2091 Edges.Append(anExp.Current());
2093 int nbEdges = Edges.Length();
2094 ShapeAnalysis_Edge sae;
2095 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
2096 double tol = BRep_Tool::Tolerance(edge);
2097 TopoDS_Vertex VF = sae.FirstVertex(edge);
2098 gp_Pnt PF = BRep_Tool::Pnt(VF);
2099 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
2100 if( PF.Distance(PLocs.First()) > tol ) {
2102 Standard_ConstructionError::Raise
2103 ("First location shapes is not coincided with first vertex of aWirePath");
2105 aSeqLocs.ChangeValue(1) = VF;
2106 edge = TopoDS::Edge(Edges.Last());
2107 tol = BRep_Tool::Tolerance(edge);
2108 TopoDS_Vertex VL = sae.LastVertex(edge);
2109 gp_Pnt PL = BRep_Tool::Pnt(VL);
2110 if( PL.Distance(PLocs.Last()) > tol ) {
2112 Standard_ConstructionError::Raise
2113 ("Last location shapes is not coincided with last vertex of aWirePath");
2115 aSeqLocs.ChangeValue(nbLocs) = VL;
2117 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
2118 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
2119 tol = BRep_Tool::Tolerance(edge);
2120 TopoDS_Vertex V1 = sae.FirstVertex(E);
2121 TopoDS_Vertex V2 = sae.LastVertex(E);
2122 gp_Pnt P1 = BRep_Tool::Pnt(V1);
2123 gp_Pnt P2 = BRep_Tool::Pnt(V2);
2124 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
2125 aSeqLocs.ChangeValue(jcurr) = V2;
2129 // find distance between E and aLocs(jcurr)
2131 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
2132 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
2133 if( PPC.NbPoints()>0 &&
2134 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
2135 double param = PPC.Parameter(1);
2138 // split current edge
2139 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
2140 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
2145 if(Pfp.Distance(P1)<tol) {
2146 B.MakeEdge(E1,tc1,tol);
2148 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2149 B.Add(E1,TopoDS::Vertex(tmpV));
2150 B.MakeEdge(E2,tc2,tol);
2151 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2152 B.Add(E2,TopoDS::Vertex(tmpV));
2156 B.MakeEdge(E1,tc2,tol);
2157 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
2158 B.Add(E1,TopoDS::Vertex(tmpV));
2161 B.MakeEdge(E2,tc1,tol);
2163 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
2164 B.Add(E2,TopoDS::Vertex(tmpV));
2169 Edges.InsertAfter(i-1,E1);
2170 Edges.InsertAfter(i,E2);
2174 if(nbEdges<Edges.Length()) {
2175 // one of edges was splitted => we have to update WirePath
2179 for(i=1; i<=Edges.Length(); i++) {
2180 B.Add(W,TopoDS::Edge(Edges.Value(i)));
2186 // check curvature of wire for condition that
2187 // max summary angle between directions along
2188 // wire path must be < 4*PI. If not - split wire
2189 // and seguences of shapes, perform pipe for each
2190 // and make sewing after that
2192 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(Edges.Value(1)),fp,lp);
2197 double SumAng = fabs(Vec1.Angle(Vec2));
2200 TColStd_SequenceOfInteger SplitEdgeNums,SplitLocNums;
2202 //cout<<"Edges.Length()="<<Edges.Length()<<endl;
2203 for(i=2; i<=Edges.Length(); i++) {
2204 TopoDS_Edge edge = TopoDS::Edge(Edges.Value(i));
2205 double tol = BRep_Tool::Tolerance(edge);
2206 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
2208 double ang = fabs(Vec1.Angle(Vec2));
2212 SplitEdgeNums.Append(i-1);
2214 for(j=LastLoc+1; j<=aSeqLocs.Length(); j++) {
2215 TopoDS_Vertex aVert = TopoDS::Vertex(aSeqLocs.Value(j));
2216 gp_Pnt P = BRep_Tool::Pnt(aVert);
2217 if( P1.Distance(P) < tol ) {
2218 SplitLocNums.Append(j);
2228 //cout<<"SplitEdgeNums.Length()="<<SplitEdgeNums.Length()<<endl;
2229 //cout<<"SplitLocNums.Length()="<<SplitLocNums.Length()<<endl;
2230 if( SplitLocNums.Length()==SplitEdgeNums.Length() && SplitEdgeNums.Length()>0 ) {
2231 TopTools_SequenceOfShape aSeqRes;
2232 int nn, num1 = 1, num2 = 1;
2233 for(nn=1; nn<=SplitEdgeNums.Length(); nn++) {
2234 // create wirepath and sequences of shapes
2238 for(i=num1; i<=SplitEdgeNums.Value(nn); i++) {
2239 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2241 num1 = SplitEdgeNums.Value(nn) + 1;
2242 TopTools_SequenceOfShape aTmpSeqBases;
2243 TopTools_SequenceOfShape aTmpSeqLocs;
2244 for(i=num2; i<=SplitLocNums.Value(nn); i++) {
2245 aTmpSeqBases.Append(aSeqBases.Value(i));
2246 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2248 num2 = SplitLocNums.Value(nn);
2250 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2251 Standard_Integer nbShapes = aTmpSeqBases.Length();
2252 for(i=1; i<=nbShapes; i++) {
2253 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2254 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2255 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2257 if(!aBuilder.IsReady()) {
2259 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2262 TopoDS_Shape resShape = aBuilder.Shape();
2263 aSeqRes.Append(resShape);
2265 // create wirepath and sequences of shapes for last part
2269 for(i=num1; i<=Edges.Length(); i++) {
2270 B.Add(tmpW,TopoDS::Edge(Edges.Value(i)));
2272 TopTools_SequenceOfShape aTmpSeqBases;
2273 TopTools_SequenceOfShape aTmpSeqLocs;
2274 for(i=num2; i<=aSeqLocs.Length(); i++) {
2275 aTmpSeqBases.Append(aSeqBases.Value(i));
2276 aTmpSeqLocs.Append(aSeqLocs.Value(i));
2278 // make pipe for last part
2279 BRepOffsetAPI_MakePipeShell aBuilder(tmpW);
2280 Standard_Integer nbShapes = aTmpSeqBases.Length();
2281 for(i=1; i<=nbShapes; i++) {
2282 TopoDS_Shape aShapeLoc = aTmpSeqLocs.Value(i);
2283 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2284 aBuilder.Add(aTmpSeqBases.Value(i), aVert, aWithContact, aWithCorrect);
2286 if(!aBuilder.IsReady()) {
2288 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2291 TopoDS_Shape resShape = aBuilder.Shape();
2292 aSeqRes.Append(resShape);
2293 // make sewing for result
2294 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
2295 aSewing->SetTolerance(Precision::Confusion());
2296 aSewing->SetFaceMode(Standard_True);
2297 aSewing->SetFloatingEdgesMode(Standard_False);
2298 aSewing->SetNonManifoldMode(Standard_False);
2299 for(i=1; i<=aSeqRes.Length(); i++) {
2300 aSewing->Add(aSeqRes.Value(i));
2303 aShape = aSewing->SewedShape();
2306 // old implementation without splitting
2307 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
2309 Standard_Integer nbShapes = aSeqBases.Length();
2310 Standard_Integer step = nbShapes/nbBases;
2312 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases)) {
2314 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
2316 Standard_Integer ind =0;
2317 for( i=1; i <= nbShapes && ind < nbShapes; i++) { //i+nbBases <= nbShapes
2318 TopTools_SequenceOfShape usedBases;
2319 Standard_Integer j = 1;
2320 for( ; j <= nbBases ; j++) {
2321 ind = i + (j-1)*step;
2322 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
2323 usedBases.Append(aWireProf);
2325 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
2326 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
2327 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
2330 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
2332 if(!aBuilder.IsReady()) {
2334 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
2337 aShape = aBuilder.Shape();
2338 aSeqFaces.Append(aShape);
2339 for( j = 1; j <=usedBases.Length(); j++)
2340 aBuilder.Delete(usedBases.Value(j));
2343 //for case if section is face
2344 if(aSeqFaces.Length() >1) {
2346 TopoDS_Compound aComp;
2347 aB.MakeCompound(aComp);
2348 for( i = 1; i <= aSeqFaces.Length(); i++)
2349 aB.Add(aComp,aSeqFaces.Value(i));
2355 //building pipe with shell sections
2356 else if (aType == PIPE_SHELL_SECTIONS) {
2357 aShape = CreatePipeForShellSections(aWirePath,aCI);
2360 //building pipe shell sections without path
2361 else if (aType == PIPE_SHELLS_WITHOUT_PATH) {
2362 aShape = CreatePipeShellsWithoutPath(aCI);
2365 //building a pipe with constant bi-normal along given vector
2366 else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR) {
2367 aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
2375 if (aShape.IsNull()) return 0;
2377 BRepCheck_Analyzer ana (aShape, Standard_False);
2378 if (!ana.IsValid()) {
2379 ShapeFix_ShapeTolerance aSFT;
2380 aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion());
2381 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
2382 aSfs->SetPrecision(Precision::Confusion());
2384 aShape = aSfs->Shape();
2386 ana.Init(aShape, Standard_False);
2388 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
2391 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
2392 aFunction->SetValue(aRes);
2394 log.SetTouched(Label());
2399 //=======================================================================
2400 //function : GEOMImpl_PipeDriver_Type_
2402 //=======================================================================
2403 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
2406 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
2407 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
2408 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
2409 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
2410 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
2411 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
2414 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
2415 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
2416 sizeof(GEOMImpl_PipeDriver),
2418 (Standard_Address)_Ancestors,
2419 (Standard_Address)NULL);
2424 //=======================================================================
2425 //function : DownCast
2427 //=======================================================================
2428 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
2430 Handle(GEOMImpl_PipeDriver) _anOtherObject;
2432 if (!AnObject.IsNull()) {
2433 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
2434 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
2438 return _anOtherObject ;