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>
24 #include <GEOMImpl_IPipe.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRepOffsetAPI_MakePipe.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Shell.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <BRepOffsetAPI_MakePipeShell.hxx>
42 #include <TColStd_HSequenceOfTransient.hxx>
43 #include <GEOMImpl_IPipeDiffSect.hxx>
44 #include <GEOMImpl_IPipeShellSect.hxx>
46 #include <Standard_NullObject.hxx>
47 #include <Standard_TypeMismatch.hxx>
48 #include <Standard_ConstructionError.hxx>
49 #include "utilities.h"
50 #include <TopExp_Explorer.hxx>
51 #include <TopTools_SequenceOfShape.hxx>
52 #include <BRep_Builder.hxx>
53 #include <TopoDS_Compound.hxx>
54 #include <ShapeAnalysis_FreeBounds.hxx>
55 #include <TColgp_SequenceOfPnt.hxx>
56 #include <ShapeAnalysis_Edge.hxx>
57 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
58 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <GeomAPI_ProjectPointOnCurve.hxx>
62 #include <Precision.hxx>
63 #include <Geom_TrimmedCurve.hxx>
64 #include <BRepBuilderAPI_Sewing.hxx>
66 //#include <BRepTools.hxx>
69 //=======================================================================
72 //=======================================================================
73 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
75 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
80 //=======================================================================
81 //function : GEOMImpl_PipeDriver
83 //=======================================================================
84 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
89 //=======================================================================
90 //function : FillForOtherEdges
91 //purpose : auxilary for CreatePipeForShellSections()
92 //=======================================================================
93 static bool FillForOtherEdges(const TopoDS_Shape& F1,
94 const TopoDS_Shape& E1,
95 const TopoDS_Shape& V1,
96 TopTools_IndexedDataMapOfShapeShape& FF)
98 //cout<<"FillForOtherEdges"<<endl;
99 // find other pairs for vertexes and edges
100 // creating map of vertex edges for both faces
101 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
102 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
103 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
104 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
105 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
106 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
107 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
109 TopoDS_Edge ES1 = TopoDS::Edge(E1);
110 TopoDS_Edge ES2 = TopoDS::Edge(E2);
111 TopoDS_Shape VS1 = V1;
112 TopoDS_Shape VS2 = V2;
114 ShapeAnalysis_Edge sae;
116 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
117 //TopoDS_Shape E1next;
118 TopTools_ListIteratorOfListOfShape anIter1(aList1);
119 if(anIter1.Value().IsSame(ES1)) {
122 //E1next = anIter1.Value();
123 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
124 //TopoDS_Shape E2next;
125 TopTools_ListIteratorOfListOfShape anIter2(aList2);
126 if(anIter2.Value().IsSame(ES2)) {
129 //E2next = anIter2.Value();
130 //ES1 = TopoDS::Edge(E1next);
131 //ES2 = TopoDS::Edge(E2next);
132 ES1 = TopoDS::Edge(anIter1.Value());
133 ES2 = TopoDS::Edge(anIter2.Value());
134 if(!FF.Contains(ES1)) {
137 if(VS1.IsSame(sae.FirstVertex(ES1)))
138 VS1 = sae.LastVertex(ES1);
140 VS1 = sae.FirstVertex(ES1);
141 if(VS2.IsSame(sae.FirstVertex(ES2)))
142 VS2 = sae.LastVertex(ES2);
144 VS2 = sae.FirstVertex(ES2);
147 if(!FF.Contains(VS1)) {
156 //=======================================================================
157 //function : FillCorrespondingEdges
158 //purpose : auxilary for CreatePipeForShellSections()
159 //=======================================================================
160 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
161 const TopoDS_Shape& FS2,
162 const TopoDS_Vertex& aLoc1,
163 const TopoDS_Vertex& aLoc2,
164 const TopoDS_Wire& aWirePath,
165 TopTools_IndexedDataMapOfShapeShape& FF)
167 //cout<<"FillCorrespondingEdges"<<endl;
168 // find corresponding edges
169 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
170 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
171 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
172 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
173 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
174 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
175 aBuilder.Add(aWire1, aLoc1);
176 aBuilder.Add(aWire2, aLoc2);
177 if(!aBuilder.IsReady()) {
181 TopoDS_Shape aShape = aBuilder.Shape();
189 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
191 ShapeAnalysis_Edge sae;
192 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
193 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
194 TopTools_MapOfShape Vs1,Vs2;
196 exp.Init( FS1, TopAbs_EDGE );
197 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
198 TopoDS_Vertex V11 = sae.FirstVertex(E1);
199 TopoDS_Vertex V21 = sae.LastVertex(E1);
200 gp_Pnt P11 = BRep_Tool::Pnt(V11);
201 gp_Pnt P21 = BRep_Tool::Pnt(V21);
202 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
203 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
204 // find corresponding vertexes from created shape
205 TopoDS_Vertex VN11,VN21;
206 for( exp.Init( aShape, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
207 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
208 gp_Pnt P = BRep_Tool::Pnt(V);
209 if(P.Distance(P11)<tol) {
212 if(P.Distance(P21)<tol) {
216 // find edge contains VN11 and VN21 and corresponding vertexes
217 TopoDS_Vertex VN12,VN22;
218 for( exp.Init( aShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
219 TopoDS_Shape F = exp.Current();
220 TopExp_Explorer expe;
222 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
223 TopoDS_Edge E = TopoDS::Edge(expe.Current());
224 TopoDS_Vertex VF = sae.FirstVertex(E);
225 TopoDS_Vertex VL = sae.LastVertex(E);
226 if( (VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11)) ) {
232 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
233 TopoDS_Edge E = TopoDS::Edge(expe.Current());
234 TopoDS_Vertex VF = sae.FirstVertex(E);
235 TopoDS_Vertex VL = sae.LastVertex(E);
236 if( VF.IsSame(VN11) && !VL.IsSame(VN21) )
238 if( VL.IsSame(VN11) && !VF.IsSame(VN21) )
240 if( VF.IsSame(VN21) && !VL.IsSame(VN11) )
242 if( VL.IsSame(VN21) && !VF.IsSame(VN11) )
248 // find vertexes from FS2 corresponded to VN12 and VN22
249 // and find edge from FS2 contains V12 and V22,
250 // this edge will be corresponded to edge E1
251 TopoDS_Vertex V12,V22;
252 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
253 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
254 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
255 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
257 TopExp_Explorer expe;
258 for( expe.Init( FS2, TopAbs_EDGE ); expe.More(); expe.Next() ) {
259 TopoDS_Edge E = TopoDS::Edge(expe.Current());
260 TopoDS_Vertex VF = sae.FirstVertex(E);
261 TopoDS_Vertex VL = sae.LastVertex(E);
262 gp_Pnt PF = BRep_Tool::Pnt(VF);
263 gp_Pnt PL = BRep_Tool::Pnt(VL);
264 if( PF.Distance(PN12)<tol && PL.Distance(PN22)<tol ) {
270 if( PF.Distance(PN22)<tol && PL.Distance(PN12)<tol ) {
281 // find other pairs for vertexes and edges
282 // creating map of vertex edges for both faces
283 return FillForOtherEdges(FS1,E1,V21,FF);
289 //=======================================================================
290 //function : FindNextPairOfFaces
291 //purpose : auxilary for CreatePipeForShellSections()
292 //=======================================================================
293 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
294 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
295 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
296 TopTools_IndexedDataMapOfShapeShape& FF,
299 //cout<<"FindNextPairOfFaces"<<endl;
300 TopExp_Explorer anExp;
301 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
302 TopoDS_Shape E1 = anExp.Current();
303 if(!FF.Contains(E1)) {
305 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
307 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
308 TopExp_Explorer anExpV;
309 anExpV.Init( E1, TopAbs_VERTEX );
310 TopoDS_Shape V1 = anExpV.Current();
311 if(!FF.Contains(V1)) {
313 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
316 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
317 if(aList1.Extent()<2)
319 TopTools_ListIteratorOfListOfShape anIter(aList1);
320 if(anIter.Value().IsEqual(aCurFace)) {
323 TopoDS_Shape F1other = anIter.Value();
324 if(FF.Contains(F1other))
327 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
328 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
329 if(aList2.Extent()<2) {
331 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
333 TopTools_ListIteratorOfListOfShape anIter2(aList2);
334 if(anIter2.Value().IsEqual(F2)) {
337 TopoDS_Shape F2other = anIter2.Value();
338 FF.Add(F1other,F2other);
340 // add pairs of edges to FF
341 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
344 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
347 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
353 //=======================================================================
354 //function : CreatePipeForShellSections
355 //purpose : auxilary for Execute()
356 //=======================================================================
357 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
360 //cout<<"CreatePipeForShellSections"<<endl;
365 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
366 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
367 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
368 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
369 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
370 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
372 Standard_Integer nbBases = aBasesObjs->Length(),
373 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
374 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
376 if( nbLocs != nbBases) {
378 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
380 if( nbSubBases && nbSubBases != nbBases) {
382 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
385 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
387 TopTools_SequenceOfShape VLocs;
388 for(i=1; i<=nbBases; i++) {
389 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
390 if(anItemLoc.IsNull())
392 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
393 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
394 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
396 VLocs.Append(aShapeLoc);
398 nbLocs = VLocs.Length();
399 if( nbLocs != nbBases) {
401 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
403 // split wire path by location points
404 TColgp_SequenceOfPnt PLocs;
405 for(i=1; i<=nbLocs; i++) {
406 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
407 PLocs.Append(BRep_Tool::Pnt(V));
409 TopTools_SequenceOfShape Edges;
410 TopTools_SequenceOfShape Wires;
411 TopExp_Explorer anExp;
412 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
413 Edges.Append(anExp.Current());
415 ShapeAnalysis_Edge sae;
416 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
417 double tol = BRep_Tool::Tolerance(edge);
418 TopoDS_Vertex VF = sae.FirstVertex(edge);
419 gp_Pnt PF = BRep_Tool::Pnt(VF);
420 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
421 if( PF.Distance(PLocs.First()) > tol ) {
423 Standard_ConstructionError::Raise
424 ("First location shapes is not coincided with first vertex of aWirePath");
426 edge = TopoDS::Edge(Edges.Last());
427 tol = BRep_Tool::Tolerance(edge);
428 TopoDS_Vertex VL = sae.LastVertex(edge);
429 gp_Pnt PL = BRep_Tool::Pnt(VL);
430 if( PL.Distance(PLocs.Last()) > tol ) {
432 Standard_ConstructionError::Raise
433 ("Last location shapes is not coincided with last vertex of aWirePath");
436 TopTools_SequenceOfShape tmpEdges;
437 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
438 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
439 tol = BRep_Tool::Tolerance(edge);
440 TopoDS_Vertex V1 = sae.FirstVertex(E);
441 TopoDS_Vertex V2 = sae.LastVertex(E);
442 gp_Pnt P1 = BRep_Tool::Pnt(V1);
443 gp_Pnt P2 = BRep_Tool::Pnt(V2);
444 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
445 // make wire from current edge and add created
449 for(j=1; j<=tmpEdges.Length(); j++)
450 B.Add(W,tmpEdges.Value(j));
457 // find distance between E and aLocs(icurr)
459 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
460 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
461 if( PPC.NbPoints()>0 &&
462 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
463 double param = PPC.Parameter(1);
466 // split current edge
467 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
468 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
470 if(PC1.Distance(P1)<tol) {
471 B.MakeEdge(E1,tc1,tol);
473 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
474 B.Add(E1,TopoDS::Vertex(tmpV));
476 B.MakeEdge(E2,tc2,tol);
477 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
478 B.Add(E2,TopoDS::Vertex(tmpV));
482 B.MakeEdge(E1,tc2,tol);
483 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
484 B.Add(E1,TopoDS::Vertex(tmpV));
488 B.MakeEdge(E2,tc1,tol);
490 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
491 B.Add(E2,TopoDS::Vertex(tmpV));
494 // create wire from tmpEdges
497 for(j=1; j<=tmpEdges.Length(); j++)
498 B.Add(W,tmpEdges.Value(j));
503 Edges.InsertAfter(i-1,E1);
504 Edges.InsertAfter(i,E2);
507 tmpEdges.Append(edge);
511 // create wire from other edges
514 for(; i<=Edges.Length(); i++)
515 B.Add(W,Edges.Value(i));
517 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
519 if( Wires.Length() != nbLocs-1 ) {
521 Standard_ConstructionError::Raise
522 ("One of location shapes is not lied on the path");
525 //TopTools_SequenceOfShape aSeqBases;
526 //TopTools_SequenceOfShape aSeqSubBases;
527 //TopTools_SequenceOfShape aSeqFaces;
528 TopoDS_Compound aComp;
529 B.MakeCompound(aComp);
530 for(i=1 ; i<nbBases; i++) {
531 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
533 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
536 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
537 if(aRefBase1.IsNull())
539 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
540 if(aShBase1.IsNull())
542 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
544 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
547 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
548 if(aRefBase2.IsNull())
550 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
551 if(aShBase2.IsNull())
553 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
555 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
557 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
558 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
561 Standard_ConstructionError::Raise("One of section shapes has invalid type");
564 bool CreateFewSolids = false;
566 TopExp_Explorer anExp;
567 Standard_Integer nbf1 = 0;
568 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
571 Standard_Integer nbf2 = 0;
572 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
576 CreateFewSolids = true;
579 if(!CreateFewSolids) {
580 // we can create only one solid
581 TopoDS_Shape aWire1, aWire2;
583 if(aType1==TopAbs_SHELL) {
584 // create wire as boundary contour if shell is no closed
585 // get free boundary shapes
586 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
587 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
588 //TopExp_Explorer anExp;
589 Standard_Integer NbWires = 0;
590 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
592 aWire1 = anExp.Current();
597 Standard_ConstructionError::Raise("Bad shell is used as section ");
600 else { // aType1==TopAbs_FACE
601 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
602 aWire1 = aExpW.Current();
605 if(aType2==TopAbs_SHELL) {
606 // create wire as boundary contour if shell is no closed
607 // get free boundary shapes
608 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
609 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
610 //TopExp_Explorer anExp;
611 Standard_Integer NbWires = 0;
612 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
614 aWire2 = anExp.Current();
619 Standard_ConstructionError::Raise("Bad shell is used as section ");
622 else { // aType2==TopAbs_FACE
623 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
624 aWire2 = aExpW.Current();
626 // make pipe using aWire1 and aWire2
627 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
628 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
629 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
630 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
631 aWithContact, aWithCorrect);
632 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
633 aWithContact, aWithCorrect);
634 if(!aBuilder.IsReady()) {
636 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
639 TopoDS_Shape aShape = aBuilder.Shape();
642 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
643 B.Add(aShell,anExp.Current());
645 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
646 B.Add(aShell,anExp.Current());
648 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
649 B.Add(aShell,anExp.Current());
651 // make sewing for this shell
652 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
653 aSewing->SetTolerance(Precision::Confusion());
654 aSewing->SetFaceMode(Standard_True);
655 aSewing->SetFloatingEdgesMode(Standard_False);
656 aSewing->SetNonManifoldMode(Standard_False);
657 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
658 aSewing->Add(anExp.Current());
661 const TopoDS_Shape aSewShape = aSewing->SewedShape();
662 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
663 aShell = TopoDS::Shell(aSewShape);
664 if(BRep_Tool::IsClosed(aShell)) {
667 B.Add(aSolid,aShell);
680 // main block - creation few solids (for each pair of faces)
681 TopTools_MapOfShape aFaces1,aFaces2;
682 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() )
683 aFaces1.Add(anExp.Current());
684 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() )
685 aFaces2.Add(anExp.Current());
686 // creating map of edge faces
687 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
688 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
689 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
690 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
692 // constuct map face->face
693 TopTools_IndexedDataMapOfShapeShape FF;
694 TopoDS_Shape FS1,FS2;
696 // find edge the most distant from location point
697 // (this edge is not shared by two faces)
700 TopoDS_Vertex V11,V21;
701 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
702 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
703 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
706 TopExp_Explorer expv;
707 expv.Init( tmp, TopAbs_VERTEX );
708 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
710 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
711 gp_Pnt P1 = BRep_Tool::Pnt(V1);
712 gp_Pnt P2 = BRep_Tool::Pnt(V2);
713 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
718 TopTools_ListIteratorOfListOfShape anIter(aList);
719 FS1 = anIter.Value();
723 // main direction for comparing
724 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
725 // find corresponding edge from next section
727 gp_Pnt P11 = BRep_Tool::Pnt(V11);
728 gp_Pnt P21 = BRep_Tool::Pnt(V21);
730 TopoDS_Vertex V12,V22;
731 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
732 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
733 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
736 TopExp_Explorer expv;
737 expv.Init( tmp, TopAbs_VERTEX );
738 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
740 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
741 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
742 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
743 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
744 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
748 V1 = V2tmp; P1 = P2tmp;
749 V2 = V1tmp; P2 = P1tmp;
752 V1 = V1tmp; P1 = P1tmp;
753 V2 = V2tmp; P2 = P2tmp;
757 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
762 TopTools_ListIteratorOfListOfShape anIter(aList);
763 FS2 = anIter.Value();
767 // put all pairs to map FF
773 // add pairs of edges to FF
774 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
777 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
783 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
784 if(anItem.IsNull()) {
786 Standard_ConstructionError::Raise("Invalid subbase shape");
788 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
789 if(aRefBase.IsNull()) {
791 Standard_ConstructionError::Raise("Invalid subbase shape");
793 TopoDS_Shape aSh = aRefBase->GetValue();
796 Standard_ConstructionError::Raise("Invalid subbase shape");
798 if(aSh.ShapeType()!=TopAbs_FACE) {
800 Standard_ConstructionError::Raise("Invalid subbase shape");
805 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
806 if(anItem.IsNull()) {
808 Standard_ConstructionError::Raise("Invalid subbase shape");
810 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
811 if(aRefBase.IsNull()) {
813 Standard_ConstructionError::Raise("Invalid subbase shape");
815 TopoDS_Shape aSh = aRefBase->GetValue();
818 Standard_ConstructionError::Raise("Invalid subbase shape");
820 if(aSh.ShapeType()!=TopAbs_FACE) {
822 Standard_ConstructionError::Raise("Invalid subbase shape");
827 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
829 Standard_ConstructionError::Raise("Invalid subbase shape");
834 // add pairs of edges to FF
835 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
836 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
839 Standard_ConstructionError::Raise("Can not create correct pipe");
843 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
846 // make pipe for each pair of faces
847 //BRepTools::Write(WPath,"/dn02/users_Linux/skl/work/Bugs/14857/wpath.brep");
848 for(j=1; j<=FF.Extent(); j++) {
849 TopoDS_Shape F1 = FF.FindKey(j);
850 if( F1.ShapeType() != TopAbs_FACE )
852 TopoDS_Shape F2 = FF.FindFromIndex(j);
853 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
854 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
855 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
856 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
857 // make pipe using aWire1 and aWire2
858 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
859 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
860 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
861 aWithContact, aWithCorrect);
862 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
863 aWithContact, aWithCorrect);
864 if(!aBuilder.IsReady()) {
866 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
869 TopoDS_Shape aShape = aBuilder.Shape();
873 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
875 //cout<<"nbf="<<nbf<<endl;
876 B.Add(aShell,anExp.Current());
880 // make sewing for this shell
881 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
882 aSewing->SetTolerance(Precision::Confusion());
883 aSewing->SetFaceMode(Standard_True);
884 aSewing->SetFloatingEdgesMode(Standard_False);
885 aSewing->SetNonManifoldMode(Standard_False);
886 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
887 aSewing->Add(anExp.Current());
890 const TopoDS_Shape aSewShape = aSewing->SewedShape();
891 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
892 aShell = TopoDS::Shell(aSewShape);
893 if(BRep_Tool::IsClosed(aShell)) {
896 B.Add(aSolid,aShell);
916 //=======================================================================
919 //=======================================================================
920 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
922 if (Label().IsNull()) return 0;
923 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
924 GEOMImpl_IPipe* aCI= 0;
925 Standard_Integer aType = aFunction->GetType();
926 if(aType == PIPE_BASE_PATH)
927 aCI = new GEOMImpl_IPipe(aFunction);
928 else if(aType == PIPE_DIFFERENT_SECTIONS)
929 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
930 else if(aType == PIPE_SHELL_SECTIONS)
931 aCI = new GEOMImpl_IPipeShellSect(aFunction);
935 Handle(GEOM_Function) aRefPath = aCI->GetPath();
936 TopoDS_Shape aShapePath = aRefPath->GetValue();
939 if (aShapePath.IsNull()) {
940 cout<<"Driver : path is null"<<endl;
942 Standard_NullObject::Raise("MakePipe aborted : null path argument");
946 TopoDS_Wire aWirePath;
947 if (aShapePath.ShapeType() == TopAbs_WIRE) {
948 aWirePath = TopoDS::Wire(aShapePath);
951 if (aShapePath.ShapeType() == TopAbs_EDGE) {
952 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
953 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
957 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
963 if (aType == PIPE_BASE_PATH) {
965 Handle(GEOM_Function) aRefBase = aCI->GetBase();
967 TopoDS_Shape aShapeBase = aRefBase->GetValue();
969 if (aShapeBase.IsNull()) {
971 Standard_NullObject::Raise("MakePipe aborted : null base argument");
975 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
978 //building pipe with different sections
979 else if (aType == PIPE_DIFFERENT_SECTIONS)
981 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
982 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
983 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
984 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
985 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
986 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
987 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
989 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
990 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
992 if(nbLocs && nbLocs != nbBases)
995 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
997 TopTools_SequenceOfShape aSeqBases;
998 TopTools_SequenceOfShape aSeqLocs;
999 TopTools_SequenceOfShape aSeqFaces;
1000 for( ; i <= nbBases; i++)
1002 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
1005 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1006 if(aRefBase.IsNull())
1008 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1009 if(aShapeBase.IsNull())
1011 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
1013 //if for section was specified face with a few wires then a few
1014 // pipes were build and make solid
1015 Standard_Boolean NeedCreateSolid = Standard_False;
1016 if(aTypeBase == TopAbs_SHELL) {
1017 // create wire as boundary contour if shell is no closed
1018 // get free boundary shapes
1019 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
1020 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1021 TopExp_Explorer anExp;
1023 Standard_Integer NbWires = 0;
1024 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1026 aWire = anExp.Current();
1031 Standard_ConstructionError::Raise("Bad shell is used as section ");
1033 NeedCreateSolid = Standard_True;
1034 aSeqFaces.Append(aShapeBase);
1035 aSeqBases.Append(aWire);
1037 else if(aTypeBase == TopAbs_FACE)
1039 NeedCreateSolid = Standard_True;
1040 //for case one path should be used other type function
1041 aSeqFaces.Append(aShapeBase);
1042 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
1043 for( ; aExpW.More(); aExpW.Next())
1045 TopoDS_Shape aWireProf = aExpW.Current();
1046 aSeqBases.Append(aWireProf);
1049 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
1050 aSeqBases.Append(aShapeBase);
1052 else if(aTypeBase == TopAbs_EDGE)
1054 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
1055 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
1056 aSeqBases.Append(aWireProf);
1060 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
1061 if(anItemLoc.IsNull())
1063 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
1064 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
1065 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
1067 aSeqLocs.Append(aShapeLoc);
1071 nbLocs = aSeqLocs.Length();
1072 Standard_Integer nbShapes = aSeqBases.Length();
1073 Standard_Integer step = nbShapes/nbBases;
1075 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases))
1078 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
1081 Standard_Integer ind =0;
1082 for( i=1; i <= nbShapes && ind < nbShapes; i++) //i+nbBases <= nbShapes
1084 TopTools_SequenceOfShape usedBases;
1085 Standard_Integer j = 1;
1086 for( ; j <= nbBases ; j++)
1088 ind = i + (j-1)*step;
1090 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
1091 usedBases.Append(aWireProf);
1094 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
1095 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
1096 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
1099 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
1101 if(!aBuilder.IsReady())
1104 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1107 aShape = aBuilder.Shape();
1108 aSeqFaces.Append(aShape);
1109 for( j = 1; j <=usedBases.Length(); j++)
1110 aBuilder.Delete(usedBases.Value(j));
1113 //for case if section is face
1114 if(aSeqFaces.Length() >1)
1117 TopoDS_Compound aComp;
1118 aB.MakeCompound(aComp);
1119 for( i = 1; i <= aSeqFaces.Length(); i++)
1120 aB.Add(aComp,aSeqFaces.Value(i));
1125 //building pipe with shell sections
1126 else if (aType == PIPE_SHELL_SECTIONS) {
1127 aShape = CreatePipeForShellSections(aWirePath,aCI);
1130 if (aShape.IsNull()) return 0;
1132 BRepCheck_Analyzer ana (aShape, Standard_False);
1133 if (!ana.IsValid()) {
1135 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
1138 aFunction->SetValue(aShape);
1140 log.SetTouched(Label());
1146 //=======================================================================
1147 //function : GEOMImpl_PipeDriver_Type_
1149 //=======================================================================
1150 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
1153 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
1154 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
1155 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
1156 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
1157 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
1158 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
1161 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
1162 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
1163 sizeof(GEOMImpl_PipeDriver),
1165 (Standard_Address)_Ancestors,
1166 (Standard_Address)NULL);
1171 //=======================================================================
1172 //function : DownCast
1174 //=======================================================================
1175 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
1177 Handle(GEOMImpl_PipeDriver) _anOtherObject;
1179 if (!AnObject.IsNull()) {
1180 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
1181 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
1185 return _anOtherObject ;