1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_PipeDriver.hxx>
25 #include <GEOMImpl_IShapesOperations.hxx>
26 #include <GEOMImpl_IPipeDiffSect.hxx>
27 #include <GEOMImpl_IPipeShellSect.hxx>
28 #include <GEOMImpl_IPipe.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOM_Function.hxx>
32 #include <ShapeAnalysis_FreeBounds.hxx>
33 #include <ShapeAnalysis_Edge.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepBuilderAPI_MakeWire.hxx>
38 #include <BRepBuilderAPI_Sewing.hxx>
39 #include <BRepCheck_Analyzer.hxx>
40 #include <BRepOffsetAPI_MakePipe.hxx>
41 #include <BRepOffsetAPI_MakePipeShell.hxx>
42 #include <GProp_GProps.hxx>
43 #include <BRepGProp.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Wire.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <TopoDS_Solid.hxx>
53 #include <TopoDS_Shell.hxx>
54 #include <TopoDS_Face.hxx>
55 #include <TopoDS_Compound.hxx>
56 #include <TopTools_SequenceOfShape.hxx>
57 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
58 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
59 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <GeomAPI_ProjectPointOnCurve.hxx>
62 #include <Geom_TrimmedCurve.hxx>
64 #include <TColgp_SequenceOfPnt.hxx>
65 #include <TColStd_HSequenceOfTransient.hxx>
67 #include <Precision.hxx>
68 #include <Standard_NullObject.hxx>
69 #include <Standard_TypeMismatch.hxx>
70 #include <Standard_ConstructionError.hxx>
72 #include "utilities.h"
74 //#include "BRepTools.hxx"
77 //=======================================================================
80 //=======================================================================
81 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
83 static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
88 //=======================================================================
89 //function : GEOMImpl_PipeDriver
91 //=======================================================================
92 GEOMImpl_PipeDriver::GEOMImpl_PipeDriver()
97 //=======================================================================
98 //function : FillForOtherEdges
99 //purpose : auxilary for CreatePipeForShellSections()
100 //=======================================================================
101 static bool FillForOtherEdges(const TopoDS_Shape& F1,
102 const TopoDS_Shape& E1,
103 const TopoDS_Shape& V1,
104 TopTools_IndexedDataMapOfShapeShape& FF)
106 //cout<<"FillForOtherEdges"<<endl;
107 // find other pairs for vertexes and edges
108 // creating map of vertex edges for both faces
109 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge1;
110 TopExp::MapShapesAndAncestors(F1, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge1);
111 const TopoDS_Shape& F2 = FF.FindFromKey(F1);
112 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
113 const TopoDS_Shape& V2 = FF.FindFromKey(V1);
114 TopTools_IndexedDataMapOfShapeListOfShape aMapVertEdge2;
115 TopExp::MapShapesAndAncestors(F2, TopAbs_VERTEX, TopAbs_EDGE, aMapVertEdge2);
117 TopoDS_Edge ES1 = TopoDS::Edge(E1);
118 TopoDS_Edge ES2 = TopoDS::Edge(E2);
119 TopoDS_Shape VS1 = V1;
120 TopoDS_Shape VS2 = V2;
122 ShapeAnalysis_Edge sae;
124 const TopTools_ListOfShape& aList1 = aMapVertEdge1.FindFromKey(VS1);
125 //TopoDS_Shape E1next;
126 TopTools_ListIteratorOfListOfShape anIter1(aList1);
127 if(anIter1.Value().IsSame(ES1)) {
130 //E1next = anIter1.Value();
131 const TopTools_ListOfShape& aList2 = aMapVertEdge2.FindFromKey(VS2);
132 //TopoDS_Shape E2next;
133 TopTools_ListIteratorOfListOfShape anIter2(aList2);
134 if(anIter2.Value().IsSame(ES2)) {
137 //E2next = anIter2.Value();
138 //ES1 = TopoDS::Edge(E1next);
139 //ES2 = TopoDS::Edge(E2next);
140 ES1 = TopoDS::Edge(anIter1.Value());
141 ES2 = TopoDS::Edge(anIter2.Value());
142 if(!FF.Contains(ES1)) {
145 if(VS1.IsSame(sae.FirstVertex(ES1)))
146 VS1 = sae.LastVertex(ES1);
148 VS1 = sae.FirstVertex(ES1);
149 if(VS2.IsSame(sae.FirstVertex(ES2)))
150 VS2 = sae.LastVertex(ES2);
152 VS2 = sae.FirstVertex(ES2);
155 if(!FF.Contains(VS1)) {
164 //=======================================================================
165 //function : FillCorrespondingEdges
166 //purpose : auxilary for CreatePipeForShellSections()
167 //=======================================================================
168 static bool FillCorrespondingEdges(const TopoDS_Shape& FS1,
169 const TopoDS_Shape& FS2,
170 const TopoDS_Vertex& aLoc1,
171 const TopoDS_Vertex& aLoc2,
172 const TopoDS_Wire& aWirePath,
173 TopTools_IndexedDataMapOfShapeShape& FF)
175 //cout<<"FillCorrespondingEdges"<<endl;
176 // find corresponding edges
177 TopExp_Explorer expw1(FS1,TopAbs_WIRE);
178 TopoDS_Wire aWire1 = TopoDS::Wire(expw1.Current());
179 //exp = TopExp_Explorer(FS2,TopAbs_WIRE);
180 TopExp_Explorer expw2(FS2,TopAbs_WIRE);
181 TopoDS_Wire aWire2 = TopoDS::Wire(expw2.Current());
182 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
183 aBuilder.Add(aWire1, aLoc1);
184 aBuilder.Add(aWire2, aLoc2);
185 if(!aBuilder.IsReady()) {
189 TopoDS_Shape aShape = aBuilder.Shape();
197 BRepTools::Write(C,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
199 ShapeAnalysis_Edge sae;
200 double tol = Max( BRep_Tool::Tolerance(TopoDS::Face(FS1)),
201 BRep_Tool::Tolerance(TopoDS::Face(FS2)) );
202 TopTools_MapOfShape Vs1,Vs2;
204 exp.Init( FS1, TopAbs_EDGE );
205 TopoDS_Edge E1 = TopoDS::Edge(exp.Current());
206 TopoDS_Vertex V11 = sae.FirstVertex(E1);
207 TopoDS_Vertex V21 = sae.LastVertex(E1);
208 gp_Pnt P11 = BRep_Tool::Pnt(V11);
209 gp_Pnt P21 = BRep_Tool::Pnt(V21);
210 //cout<<"P11("<<P11.X()<<","<<P11.Y()<<","<<P11.Z()<<")"<<endl;
211 //cout<<"P21("<<P21.X()<<","<<P21.Y()<<","<<P21.Z()<<")"<<endl;
212 // find corresponding vertexes from created shape
213 TopoDS_Vertex VN11,VN21;
214 for( exp.Init( aShape, TopAbs_VERTEX ); exp.More(); exp.Next() ) {
215 TopoDS_Vertex V = TopoDS::Vertex(exp.Current());
216 gp_Pnt P = BRep_Tool::Pnt(V);
217 if(P.Distance(P11)<tol) {
220 if(P.Distance(P21)<tol) {
224 // find edge contains VN11 and VN21 and corresponding vertexes
225 TopoDS_Vertex VN12,VN22;
226 for( exp.Init( aShape, TopAbs_FACE ); exp.More(); exp.Next() ) {
227 TopoDS_Shape F = exp.Current();
228 TopExp_Explorer expe;
230 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
231 TopoDS_Edge E = TopoDS::Edge(expe.Current());
232 TopoDS_Vertex VF = sae.FirstVertex(E);
233 TopoDS_Vertex VL = sae.LastVertex(E);
234 if( (VF.IsSame(VN11) && VL.IsSame(VN21)) || (VF.IsSame(VN21) && VL.IsSame(VN11)) ) {
240 for( expe.Init( F, TopAbs_EDGE ); expe.More(); expe.Next() ) {
241 TopoDS_Edge E = TopoDS::Edge(expe.Current());
242 TopoDS_Vertex VF = sae.FirstVertex(E);
243 TopoDS_Vertex VL = sae.LastVertex(E);
244 if( VF.IsSame(VN11) && !VL.IsSame(VN21) )
246 if( VL.IsSame(VN11) && !VF.IsSame(VN21) )
248 if( VF.IsSame(VN21) && !VL.IsSame(VN11) )
250 if( VL.IsSame(VN21) && !VF.IsSame(VN11) )
256 // find vertexes from FS2 corresponded to VN12 and VN22
257 // and find edge from FS2 contains V12 and V22,
258 // this edge will be corresponded to edge E1
259 TopoDS_Vertex V12,V22;
260 gp_Pnt PN12 = BRep_Tool::Pnt(VN12);
261 gp_Pnt PN22 = BRep_Tool::Pnt(VN22);
262 //cout<<"PN12("<<PN12.X()<<","<<PN12.Y()<<","<<PN12.Z()<<")"<<endl;
263 //cout<<"PN22("<<PN22.X()<<","<<PN22.Y()<<","<<PN22.Z()<<")"<<endl;
265 TopExp_Explorer expe;
266 for( expe.Init( FS2, TopAbs_EDGE ); expe.More(); expe.Next() ) {
267 TopoDS_Edge E = TopoDS::Edge(expe.Current());
268 TopoDS_Vertex VF = sae.FirstVertex(E);
269 TopoDS_Vertex VL = sae.LastVertex(E);
270 gp_Pnt PF = BRep_Tool::Pnt(VF);
271 gp_Pnt PL = BRep_Tool::Pnt(VL);
272 if( PF.Distance(PN12)<tol && PL.Distance(PN22)<tol ) {
278 if( PF.Distance(PN22)<tol && PL.Distance(PN12)<tol ) {
289 // find other pairs for vertexes and edges
290 // creating map of vertex edges for both faces
291 return FillForOtherEdges(FS1,E1,V21,FF);
297 //=======================================================================
298 //function : FindNextPairOfFaces
299 //purpose : auxilary for CreatePipeForShellSections()
300 //=======================================================================
301 static void FindNextPairOfFaces(const TopoDS_Shape& aCurFace,
302 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces1,
303 TopTools_IndexedDataMapOfShapeListOfShape& aMapEdgeFaces2,
304 TopTools_IndexedDataMapOfShapeShape& FF,
307 //cout<<"FindNextPairOfFaces"<<endl;
308 TopExp_Explorer anExp;
309 for ( anExp.Init( aCurFace, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
310 TopoDS_Shape E1 = anExp.Current();
311 if(!FF.Contains(E1)) {
313 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find edge in map");
315 const TopoDS_Shape& E2 = FF.FindFromKey(E1);
316 TopExp_Explorer anExpV;
317 anExpV.Init( E1, TopAbs_VERTEX );
318 TopoDS_Shape V1 = anExpV.Current();
319 if(!FF.Contains(V1)) {
321 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find vertex in map");
324 const TopTools_ListOfShape& aList1 = aMapEdgeFaces1.FindFromKey(E1);
325 if(aList1.Extent()<2)
327 TopTools_ListIteratorOfListOfShape anIter(aList1);
328 if(anIter.Value().IsEqual(aCurFace)) {
331 TopoDS_Shape F1other = anIter.Value();
332 if(FF.Contains(F1other))
335 const TopoDS_Shape& F2 = FF.FindFromKey(aCurFace);
336 const TopTools_ListOfShape& aList2 = aMapEdgeFaces2.FindFromKey(E2);
337 if(aList2.Extent()<2) {
339 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not find corresponding face");
341 TopTools_ListIteratorOfListOfShape anIter2(aList2);
342 if(anIter2.Value().IsEqual(F2)) {
345 TopoDS_Shape F2other = anIter2.Value();
346 FF.Add(F1other,F2other);
348 // add pairs of edges to FF
349 bool stat = FillForOtherEdges(F1other,E1,V1,FF);
352 Standard_ConstructionError::Raise("FindNextPairOfFaces: Can not mapping other egdes");
355 FindNextPairOfFaces(F1other, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
360 //=======================================================================
361 //function : CreatePipeForShellSections
362 //purpose : auxilary for Execute()
363 //=======================================================================
364 static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
367 //cout<<"CreatePipeForShellSections"<<endl;
372 GEOMImpl_IPipeShellSect* aCIDS = (GEOMImpl_IPipeShellSect*)aCI;
373 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases();
374 Handle(TColStd_HSequenceOfTransient) aSubBasesObjs = aCIDS->GetSubBases();
375 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
376 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
377 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
379 Standard_Integer nbBases = aBasesObjs->Length(),
380 nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
381 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
383 if( nbLocs != nbBases) {
385 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
387 if( nbSubBases && nbSubBases != nbBases) {
389 Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
392 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
394 TopTools_SequenceOfShape VLocs;
395 for(i=1; i<=nbBases; i++) {
396 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
397 if(anItemLoc.IsNull())
399 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
400 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
401 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
403 VLocs.Append(aShapeLoc);
405 nbLocs = VLocs.Length();
406 if( nbLocs != nbBases) {
408 Standard_ConstructionError::Raise("One of location shapes is not a vertex");
410 // split wire path by location points
411 TColgp_SequenceOfPnt PLocs;
412 for(i=1; i<=nbLocs; i++) {
413 TopoDS_Vertex V = TopoDS::Vertex(VLocs.Value(i));
414 PLocs.Append(BRep_Tool::Pnt(V));
416 TopTools_SequenceOfShape Edges;
417 TopTools_SequenceOfShape Wires;
418 TopExp_Explorer anExp;
419 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
420 Edges.Append(anExp.Current());
422 ShapeAnalysis_Edge sae;
423 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
424 double tol = BRep_Tool::Tolerance(edge);
425 TopoDS_Vertex VF = sae.FirstVertex(edge);
426 gp_Pnt PF = BRep_Tool::Pnt(VF);
427 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
428 if( PF.Distance(PLocs.First()) > tol ) {
430 Standard_ConstructionError::Raise
431 ("First location shapes is not coincided with first vertex of aWirePath");
433 VLocs.ChangeValue(1) = VF;
434 edge = TopoDS::Edge(Edges.Last());
435 tol = BRep_Tool::Tolerance(edge);
436 TopoDS_Vertex VL = sae.LastVertex(edge);
437 gp_Pnt PL = BRep_Tool::Pnt(VL);
438 if( PL.Distance(PLocs.Last()) > tol ) {
440 Standard_ConstructionError::Raise
441 ("Last location shapes is not coincided with last vertex of aWirePath");
443 VLocs.ChangeValue(nbLocs) = VL;
445 TopTools_SequenceOfShape tmpEdges;
446 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
447 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
448 tol = BRep_Tool::Tolerance(E);
449 TopoDS_Vertex V1 = sae.FirstVertex(E);
450 TopoDS_Vertex V2 = sae.LastVertex(E);
451 gp_Pnt P1 = BRep_Tool::Pnt(V1);
452 gp_Pnt P2 = BRep_Tool::Pnt(V2);
453 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
454 // make wire from current edge and add created
458 for(j=1; j<=tmpEdges.Length(); j++)
459 B.Add(W,tmpEdges.Value(j));
462 VLocs.ChangeValue(jcurr) = V2;
467 // find distance between E and aLocs(jcurr)
469 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
470 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
471 if( PPC.NbPoints()>0 &&
472 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
473 double param = PPC.Parameter(1);
476 // split current edge
477 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
478 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
482 if(Pfp.Distance(P1)<tol) {
483 B.MakeEdge(E1,tc1,tol);
485 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
486 B.Add(E1,TopoDS::Vertex(tmpV));
488 B.MakeEdge(E2,tc2,tol);
489 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
490 B.Add(E2,TopoDS::Vertex(tmpV));
494 B.MakeEdge(E1,tc2,tol);
495 TopoDS_Shape tmpV = VLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
496 B.Add(E1,TopoDS::Vertex(tmpV));
500 B.MakeEdge(E2,tc1,tol);
502 tmpV = VLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
503 B.Add(E2,TopoDS::Vertex(tmpV));
506 // create wire from tmpEdges
509 for(j=1; j<=tmpEdges.Length(); j++)
510 B.Add(W,tmpEdges.Value(j));
515 Edges.InsertAfter(i-1,E1);
516 Edges.InsertAfter(i,E2);
523 // create wire from other edges
526 for(; i<=Edges.Length(); i++)
527 B.Add(W,Edges.Value(i));
529 //cout<<"Wires.Length()="<<Wires.Length()<<endl;
531 if( Wires.Length() != nbLocs-1 ) {
533 Standard_ConstructionError::Raise
534 ("One of location shapes is not lied on the path");
537 //TopTools_SequenceOfShape aSeqBases;
538 //TopTools_SequenceOfShape aSeqSubBases;
539 //TopTools_SequenceOfShape aSeqFaces;
540 TopoDS_Compound aComp;
541 B.MakeCompound(aComp);
542 for(i=1 ; i<nbBases; i++) {
543 TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
545 Handle(Standard_Transient) anItem1 = aBasesObjs->Value(i);
548 Handle(GEOM_Function) aRefBase1 = Handle(GEOM_Function)::DownCast(anItem1);
549 if(aRefBase1.IsNull())
551 TopoDS_Shape aShBase1 = aRefBase1->GetValue();
552 if(aShBase1.IsNull())
554 TopAbs_ShapeEnum aType1 = aShBase1.ShapeType();
556 Handle(Standard_Transient) anItem2 = aBasesObjs->Value(i+1);
559 Handle(GEOM_Function) aRefBase2 = Handle(GEOM_Function)::DownCast(anItem2);
560 if(aRefBase2.IsNull())
562 TopoDS_Shape aShBase2 = aRefBase2->GetValue();
563 if(aShBase2.IsNull())
565 TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
567 //BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
569 bool OkSec = ( aType1==TopAbs_SHELL || aType1==TopAbs_FACE ) &&
570 ( aType2==TopAbs_SHELL || aType2==TopAbs_FACE );
573 Standard_ConstructionError::Raise("One of section shapes has invalid type");
576 bool CreateFewSolids = false;
578 TopExp_Explorer anExp;
579 Standard_Integer nbf1 = 0;
580 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
583 Standard_Integer nbf2 = 0;
584 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
588 CreateFewSolids = true;
592 // check orientation of sections
593 bool NeedReverse = false;
596 anExp.Init( aShBase1, TopAbs_FACE );
597 TopoDS_Shape aFace = anExp.Current();
598 TColgp_SequenceOfPnt aPnts;
599 double xc=0, yc=0, zc=0;
600 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
601 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
602 aPnts.Append(BRep_Tool::Pnt(V));
603 xc += aPnts.Last().X();
604 yc += aPnts.Last().Y();
605 zc += aPnts.Last().Z();
607 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
608 gp_Vec V1(PC,aPnts.Value(1));
609 gp_Vec V2(PC,aPnts.Value(2));
610 gp_Vec VN = V1.Crossed(V2);
611 for(int ip=2; ip<aPnts.Length(); ip++) {
612 V1 = gp_Vec(PC,aPnts.Value(ip));
613 V2 = gp_Vec(PC,aPnts.Value(ip+1));
614 VN.Add(V1.Crossed(V2));
617 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
619 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
620 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
621 double tol = BRep_Tool::Tolerance(edge);
622 TopoDS_Vertex VF = sae.FirstVertex(edge);
623 gp_Pnt PF = BRep_Tool::Pnt(VF);
624 if( PF.Distance(PLoc) < tol ) {
626 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
629 if( P1.Distance(PLoc) < tol ) {
630 C->D0(fp+(lp-fp)/100,P2);
634 C->D0(lp+(fp-lp)/100,P2);
636 PathNorm = gp_Vec(P1,P2);
640 TopoDS_Vertex VL = sae.LastVertex(edge);
641 gp_Pnt PL = BRep_Tool::Pnt(VL);
642 if( PL.Distance(PLoc) < tol ) {
644 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
647 if( P1.Distance(PLoc) < tol ) {
648 C->D0(fp+(lp-fp)/100,P2);
652 C->D0(lp+(fp-lp)/100,P2);
654 PathNorm = gp_Vec(P2,P1);
659 cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
660 cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
661 if(fabs(VN.Angle(PathNorm))>PI/2.) {
668 anExp.Init( aShBase2, TopAbs_FACE );
669 TopoDS_Shape aFace = anExp.Current();
670 TColgp_SequenceOfPnt aPnts;
671 double xc=0, yc=0, zc=0;
672 for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
673 TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
674 aPnts.Append(BRep_Tool::Pnt(V));
675 xc += aPnts.Last().X();
676 yc += aPnts.Last().Y();
677 zc += aPnts.Last().Z();
679 gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
680 gp_Vec V1(PC,aPnts.Value(1));
681 gp_Vec V2(PC,aPnts.Value(2));
682 gp_Vec VN = V1.Crossed(V2);
683 for(int ip=2; ip<aPnts.Length(); ip++) {
684 V1 = gp_Vec(PC,aPnts.Value(ip));
685 V2 = gp_Vec(PC,aPnts.Value(ip+1));
686 VN.Add(V1.Crossed(V2));
689 gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
691 for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
692 TopoDS_Edge edge = TopoDS::Edge(WE.Current());
693 double tol = BRep_Tool::Tolerance(edge);
694 TopoDS_Vertex VF = sae.FirstVertex(edge);
695 gp_Pnt PF = BRep_Tool::Pnt(VF);
696 if( PF.Distance(PLoc) < tol ) {
698 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
701 if( P1.Distance(PLoc) < tol ) {
702 C->D0(fp+(lp-fp)/100,P2);
706 C->D0(lp+(fp-lp)/100,P2);
708 PathNorm = gp_Vec(P2,P1);
712 TopoDS_Vertex VL = sae.LastVertex(edge);
713 gp_Pnt PL = BRep_Tool::Pnt(VL);
714 if( PL.Distance(PLoc) < tol ) {
716 Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
719 if( P1.Distance(PLoc) < tol ) {
720 C->D0(fp+(lp-fp)/100,P2);
724 C->D0(lp+(fp-lp)/100,P2);
726 PathNorm = gp_Vec(P2,P1);
731 //cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
732 //cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
733 if(fabs(VN.Angle(PathNorm))>PI/2.)
738 if(!CreateFewSolids) {
739 // we can create only one solid
740 TopoDS_Shape aWire1, aWire2;
742 if(aType1==TopAbs_SHELL) {
743 // create wire as boundary contour if shell is no closed
744 // get free boundary shapes
745 ShapeAnalysis_FreeBounds anAnalizer( aShBase1 );
746 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
747 //TopExp_Explorer anExp;
748 Standard_Integer NbWires = 0;
749 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
751 aWire1 = anExp.Current();
756 Standard_ConstructionError::Raise("Bad shell is used as section ");
759 else { // aType1==TopAbs_FACE
760 TopExp_Explorer aExpW(aShBase1,TopAbs_WIRE);
761 aWire1 = aExpW.Current();
764 if(aType2==TopAbs_SHELL) {
765 // create wire as boundary contour if shell is no closed
766 // get free boundary shapes
767 ShapeAnalysis_FreeBounds anAnalizer( aShBase2 );
768 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
769 //TopExp_Explorer anExp;
770 Standard_Integer NbWires = 0;
771 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
773 aWire2 = anExp.Current();
778 Standard_ConstructionError::Raise("Bad shell is used as section ");
781 else { // aType2==TopAbs_FACE
782 TopExp_Explorer aExpW(aShBase2,TopAbs_WIRE);
783 aWire2 = aExpW.Current();
785 // make pipe using aWire1 and aWire2
786 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
787 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
788 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
789 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
790 aWithContact, aWithCorrect);
791 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
792 aWithContact, aWithCorrect);
793 if(!aBuilder.IsReady()) {
795 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
798 TopoDS_Shape aShape = aBuilder.Shape();
801 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
802 B.Add(aShell,anExp.Current());
804 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
805 B.Add(aShell,anExp.Current());
807 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
808 B.Add(aShell,anExp.Current());
810 // make sewing for this shell
811 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
812 aSewing->SetTolerance(Precision::Confusion());
813 aSewing->SetFaceMode(Standard_True);
814 aSewing->SetFloatingEdgesMode(Standard_False);
815 aSewing->SetNonManifoldMode(Standard_False);
816 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
817 aSewing->Add(anExp.Current());
820 const TopoDS_Shape aSewShape = aSewing->SewedShape();
821 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
822 aShell = TopoDS::Shell(aSewShape);
823 GProp_GProps aSystem;
824 BRepGProp::VolumeProperties(aShell, aSystem);
825 if(aSystem.Mass()<0) {
828 if(BRep_Tool::IsClosed(aShell)) {
831 B.Add(aSolid,aShell);
844 // main block - creation few solids (for each pair of faces)
845 TopTools_MapOfShape aFaces1,aFaces2;
846 for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
847 aFaces1.Add(anExp.Current());
849 for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
850 aFaces2.Add(anExp.Current());
852 // creating map of edge faces
853 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
854 TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
855 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
856 TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
858 // constuct map face->face
859 TopTools_IndexedDataMapOfShapeShape FF;
860 TopoDS_Shape FS1,FS2;
862 // find edge the most distant from location point
863 // (this edge is not shared by two faces)
866 TopoDS_Vertex V11,V21;
867 for(j=1; j<=aMapEdgeFaces1.Extent(); j++) {
868 TopoDS_Shape tmp = aMapEdgeFaces1.FindKey(j);
869 const TopTools_ListOfShape& aList = aMapEdgeFaces1.FindFromKey(tmp);
872 TopExp_Explorer expv;
873 expv.Init( tmp, TopAbs_VERTEX );
874 TopoDS_Vertex V1 = TopoDS::Vertex(expv.Current());
876 TopoDS_Vertex V2 = TopoDS::Vertex(expv.Current());
877 gp_Pnt P1 = BRep_Tool::Pnt(V1);
878 gp_Pnt P2 = BRep_Tool::Pnt(V2);
879 double dist = PLocs.Value(i).Distance(P1) + PLocs.Value(i).Distance(P2);
884 TopTools_ListIteratorOfListOfShape anIter(aList);
885 FS1 = anIter.Value();
889 // main direction for comparing
890 gp_Vec VM(PLocs.Value(i),PLocs.Value(i+1));
891 // find corresponding edge from next section
893 gp_Pnt P11 = BRep_Tool::Pnt(V11);
894 gp_Pnt P21 = BRep_Tool::Pnt(V21);
896 TopoDS_Vertex V12,V22;
897 for(j=1; j<=aMapEdgeFaces2.Extent(); j++) {
898 TopoDS_Shape tmp = aMapEdgeFaces2.FindKey(j);
899 const TopTools_ListOfShape& aList = aMapEdgeFaces2.FindFromKey(tmp);
902 TopExp_Explorer expv;
903 expv.Init( tmp, TopAbs_VERTEX );
904 TopoDS_Vertex V1tmp = TopoDS::Vertex(expv.Current());
906 TopoDS_Vertex V2tmp = TopoDS::Vertex(expv.Current());
907 gp_Pnt P1tmp = BRep_Tool::Pnt(V1tmp);
908 gp_Pnt P2tmp = BRep_Tool::Pnt(V2tmp);
909 double d1 = P1tmp.Distance(P11) + P2tmp.Distance(P21);
910 double d2 = P1tmp.Distance(P21) + P2tmp.Distance(P11);
914 V1 = V2tmp; P1 = P2tmp;
915 V2 = V1tmp; P2 = P1tmp;
918 V1 = V1tmp; P1 = P1tmp;
919 V2 = V2tmp; P2 = P2tmp;
923 double ang = fabs(Vec1.Angle(VM)) + fabs(Vec2.Angle(VM));
928 TopTools_ListIteratorOfListOfShape anIter(aList);
929 FS2 = anIter.Value();
933 // put all pairs to map FF
939 // add pairs of edges to FF
940 bool stat = FillForOtherEdges(FS1,E1,V11,FF);
943 Standard_ConstructionError::Raise("FindForOtherEdges: Can not mapping other egdes");
949 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i);
950 if(anItem.IsNull()) {
952 Standard_ConstructionError::Raise("Invalid subbase shape");
954 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
955 if(aRefBase.IsNull()) {
957 Standard_ConstructionError::Raise("Invalid subbase shape");
959 TopoDS_Shape aSh = aRefBase->GetValue();
962 Standard_ConstructionError::Raise("Invalid subbase shape");
964 if(aSh.ShapeType()!=TopAbs_FACE) {
966 Standard_ConstructionError::Raise("Invalid subbase shape");
971 Handle(Standard_Transient) anItem = aSubBasesObjs->Value(i+1);
972 if(anItem.IsNull()) {
974 Standard_ConstructionError::Raise("Invalid subbase shape");
976 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
977 if(aRefBase.IsNull()) {
979 Standard_ConstructionError::Raise("Invalid subbase shape");
981 TopoDS_Shape aSh = aRefBase->GetValue();
984 Standard_ConstructionError::Raise("Invalid subbase shape");
986 if(aSh.ShapeType()!=TopAbs_FACE) {
988 Standard_ConstructionError::Raise("Invalid subbase shape");
993 if( !aFaces1.Contains(FS1) || !aFaces2.Contains(FS2) ) {
995 Standard_ConstructionError::Raise("Invalid subbase shape");
1000 // add pairs of edges to FF
1001 bool stat = FillCorrespondingEdges(FS1, FS2, TopoDS::Vertex(VLocs(i)),
1002 TopoDS::Vertex(VLocs(i+1)), WPath, FF);
1005 Standard_ConstructionError::Raise("Can not create correct pipe");
1009 FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
1012 // make pipe for each pair of faces
1013 for(j=1; j<=FF.Extent(); j++) {
1014 TopoDS_Shape F1 = FF.FindKey(j);
1015 if( F1.ShapeType() != TopAbs_FACE )
1017 TopoDS_Shape F2 = FF.FindFromIndex(j);
1018 TopExp_Explorer aExpW1(F1,TopAbs_WIRE);
1019 TopoDS_Wire aWire1 = TopoDS::Wire(aExpW1.Current());
1020 TopExp_Explorer aExpW2(F2,TopAbs_WIRE);
1021 TopoDS_Wire aWire2 = TopoDS::Wire(aExpW2.Current());
1022 // make pipe using aWire1 and aWire2
1023 if( !aWire1.IsNull() && !aWire2.IsNull() ) {
1024 BRepOffsetAPI_MakePipeShell aBuilder(WPath);
1025 aBuilder.Add(aWire1, TopoDS::Vertex(VLocs(i)),
1026 aWithContact, aWithCorrect);
1027 aBuilder.Add(aWire2, TopoDS::Vertex(VLocs(i+1)),
1028 aWithContact, aWithCorrect);
1029 if(!aBuilder.IsReady()) {
1031 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1034 TopoDS_Shape aShape = aBuilder.Shape();
1035 TopoDS_Shell aShell;
1036 B.MakeShell(aShell);
1037 for ( anExp.Init( aShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1038 B.Add(aShell,anExp.Current());
1043 // make sewing for this shell
1044 Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
1045 aSewing->SetTolerance(Precision::Confusion());
1046 aSewing->SetFaceMode(Standard_True);
1047 aSewing->SetFloatingEdgesMode(Standard_False);
1048 aSewing->SetNonManifoldMode(Standard_False);
1049 for ( anExp.Init( aShell, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1050 aSewing->Add(anExp.Current());
1053 const TopoDS_Shape aSewShape = aSewing->SewedShape();
1054 if( aSewShape.ShapeType() == TopAbs_SHELL ) {
1055 aShell = TopoDS::Shell(aSewShape);
1056 GProp_GProps aSystem;
1057 BRepGProp::VolumeProperties(aShell, aSystem);
1058 if(aSystem.Mass()<0) {
1059 //cout<<"aSewShape is reversed"<<endl;
1062 if(BRep_Tool::IsClosed(aShell)) {
1063 TopoDS_Solid aSolid;
1064 B.MakeSolid(aSolid);
1065 B.Add(aSolid,aShell);
1066 B.Add(aComp,aSolid);
1069 B.Add(aComp,aShell);
1073 B.Add(aComp,aShell);
1081 //BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep");
1086 //=======================================================================
1087 //function : Execute
1089 //=======================================================================
1090 Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
1092 if (Label().IsNull()) return 0;
1093 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
1094 GEOMImpl_IPipe* aCI= 0;
1095 Standard_Integer aType = aFunction->GetType();
1096 if(aType == PIPE_BASE_PATH)
1097 aCI = new GEOMImpl_IPipe(aFunction);
1098 else if(aType == PIPE_DIFFERENT_SECTIONS)
1099 aCI = new GEOMImpl_IPipeDiffSect(aFunction);
1100 else if(aType == PIPE_SHELL_SECTIONS)
1101 aCI = new GEOMImpl_IPipeShellSect(aFunction);
1105 Handle(GEOM_Function) aRefPath = aCI->GetPath();
1106 TopoDS_Shape aShapePath = aRefPath->GetValue();
1109 if (aShapePath.IsNull()) {
1110 cout<<"Driver : path is null"<<endl;
1112 Standard_NullObject::Raise("MakePipe aborted : null path argument");
1116 TopoDS_Wire aWirePath;
1117 if (aShapePath.ShapeType() == TopAbs_WIRE) {
1118 aWirePath = TopoDS::Wire(aShapePath);
1121 if (aShapePath.ShapeType() == TopAbs_EDGE) {
1122 TopoDS_Edge anEdge = TopoDS::Edge(aShapePath);
1123 aWirePath = BRepBuilderAPI_MakeWire(anEdge);
1127 Standard_TypeMismatch::Raise("MakePipe aborted : path shape is neither a wire nor an edge");
1131 TopoDS_Shape aShape;
1133 if (aType == PIPE_BASE_PATH) {
1135 Handle(GEOM_Function) aRefBase = aCI->GetBase();
1137 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1139 if (aShapeBase.IsNull()) {
1141 Standard_NullObject::Raise("MakePipe aborted : null base argument");
1145 aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
1148 //building pipe with different sections
1149 else if (aType == PIPE_DIFFERENT_SECTIONS)
1151 GEOMImpl_IPipeDiffSect* aCIDS = (GEOMImpl_IPipeDiffSect*)aCI;
1152 //GEOMImpl_IPipeDiffSect* aCIDS = static_cast<GEOMImpl_IPipeDiffSect*>(aCI);
1153 //BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1154 Handle(TColStd_HSequenceOfTransient) aBasesObjs = aCIDS->GetBases ();
1155 Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations ();
1156 Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
1157 Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
1159 Standard_Integer i =1, nbBases = aBasesObjs->Length(),
1160 nbLocs = (aLocObjs.IsNull() ? 0 :aLocObjs->Length());
1162 if(nbLocs && nbLocs != nbBases)
1165 Standard_ConstructionError::Raise("Number of sections is not equal to number of locations ");
1167 TopTools_SequenceOfShape aSeqBases;
1168 TopTools_SequenceOfShape aSeqLocs;
1169 TopTools_SequenceOfShape aSeqFaces;
1170 for( ; i <= nbBases; i++)
1172 Handle(Standard_Transient) anItem = aBasesObjs->Value(i);
1175 Handle(GEOM_Function) aRefBase = Handle(GEOM_Function)::DownCast(anItem);
1176 if(aRefBase.IsNull())
1178 TopoDS_Shape aShapeBase = aRefBase->GetValue();
1179 if(aShapeBase.IsNull())
1181 TopAbs_ShapeEnum aTypeBase = aShapeBase.ShapeType();
1183 //if for section was specified face with a few wires then a few
1184 // pipes were build and make solid
1185 Standard_Boolean NeedCreateSolid = Standard_False;
1186 if(aTypeBase == TopAbs_SHELL) {
1187 // create wire as boundary contour if shell is no closed
1188 // get free boundary shapes
1189 ShapeAnalysis_FreeBounds anAnalizer( aShapeBase );
1190 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
1191 TopExp_Explorer anExp;
1193 Standard_Integer NbWires = 0;
1194 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() ) {
1196 aWire = anExp.Current();
1201 Standard_ConstructionError::Raise("Bad shell is used as section ");
1203 NeedCreateSolid = Standard_True;
1204 aSeqFaces.Append(aShapeBase);
1205 aSeqBases.Append(aWire);
1207 else if(aTypeBase == TopAbs_FACE)
1209 NeedCreateSolid = Standard_True;
1210 //for case one path should be used other type function
1211 aSeqFaces.Append(aShapeBase);
1212 TopExp_Explorer aExpW(aShapeBase,TopAbs_WIRE);
1213 for( ; aExpW.More(); aExpW.Next())
1215 TopoDS_Shape aWireProf = aExpW.Current();
1216 aSeqBases.Append(aWireProf);
1219 else if(aTypeBase == TopAbs_WIRE || aTypeBase == TopAbs_VERTEX) {
1220 aSeqBases.Append(aShapeBase);
1222 else if(aTypeBase == TopAbs_EDGE)
1224 TopoDS_Edge anEdge = TopoDS::Edge(aShapeBase);
1225 TopoDS_Shape aWireProf = BRepBuilderAPI_MakeWire(anEdge);
1226 aSeqBases.Append(aWireProf);
1230 Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
1231 if(anItemLoc.IsNull())
1233 Handle(GEOM_Function) aRefLoc = Handle(GEOM_Function)::DownCast(anItemLoc);
1234 TopoDS_Shape aShapeLoc = aRefLoc->GetValue();
1235 if(aShapeLoc.IsNull() || aShapeLoc.ShapeType() != TopAbs_VERTEX)
1237 aSeqLocs.Append(aShapeLoc);
1241 nbLocs = aSeqLocs.Length();
1245 // we have to check that each location shape is a vertex from
1246 // path and update aSeqLocs if it is needed (and possible)
1247 TColgp_SequenceOfPnt PLocs;
1248 for(i=1; i<=nbLocs; i++) {
1249 TopoDS_Vertex V = TopoDS::Vertex(aSeqLocs.Value(i));
1250 PLocs.Append(BRep_Tool::Pnt(V));
1252 TopTools_SequenceOfShape Edges;
1253 TopExp_Explorer anExp;
1254 for ( anExp.Init( aWirePath, TopAbs_EDGE ); anExp.More(); anExp.Next() ) {
1255 Edges.Append(anExp.Current());
1257 int nbEdges = Edges.Length();
1258 ShapeAnalysis_Edge sae;
1259 TopoDS_Edge edge = TopoDS::Edge(Edges.First());
1260 double tol = BRep_Tool::Tolerance(edge);
1261 TopoDS_Vertex VF = sae.FirstVertex(edge);
1262 gp_Pnt PF = BRep_Tool::Pnt(VF);
1263 //cout<<"PF("<<PF.X()<<","<<PF.Y()<<","<<PF.Z()<<")"<<endl;
1264 if( PF.Distance(PLocs.First()) > tol ) {
1266 Standard_ConstructionError::Raise
1267 ("First location shapes is not coincided with first vertex of aWirePath");
1269 aSeqLocs.ChangeValue(1) = VF;
1270 edge = TopoDS::Edge(Edges.Last());
1271 tol = BRep_Tool::Tolerance(edge);
1272 TopoDS_Vertex VL = sae.LastVertex(edge);
1273 gp_Pnt PL = BRep_Tool::Pnt(VL);
1274 if( PL.Distance(PLocs.Last()) > tol ) {
1276 Standard_ConstructionError::Raise
1277 ("Last location shapes is not coincided with last vertex of aWirePath");
1279 aSeqLocs.ChangeValue(nbLocs) = VL;
1281 for(i=1; i<=Edges.Length() && jcurr<nbLocs; i++) {
1282 TopoDS_Edge E = TopoDS::Edge(Edges.Value(i));
1283 tol = BRep_Tool::Tolerance(edge);
1284 TopoDS_Vertex V1 = sae.FirstVertex(E);
1285 TopoDS_Vertex V2 = sae.LastVertex(E);
1286 gp_Pnt P1 = BRep_Tool::Pnt(V1);
1287 gp_Pnt P2 = BRep_Tool::Pnt(V2);
1288 if( P2.Distance(PLocs.Value(jcurr)) < tol ) {
1289 aSeqLocs.ChangeValue(jcurr) = V2;
1293 // find distance between E and aLocs(jcurr)
1295 Handle(Geom_Curve) C = BRep_Tool::Curve(E,fp,lp);
1296 GeomAPI_ProjectPointOnCurve PPC (PLocs.Value(jcurr),C);
1297 if( PPC.NbPoints()>0 &&
1298 PLocs.Value(jcurr).Distance(PPC.Point(1)) < tol ) {
1299 double param = PPC.Parameter(1);
1302 // split current edge
1303 Handle(Geom_TrimmedCurve) tc1 = new Geom_TrimmedCurve(C,fp,param);
1304 Handle(Geom_TrimmedCurve) tc2 = new Geom_TrimmedCurve(C,param,lp);
1309 if(Pfp.Distance(P1)<tol) {
1310 B.MakeEdge(E1,tc1,tol);
1312 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1313 B.Add(E1,TopoDS::Vertex(tmpV));
1314 B.MakeEdge(E2,tc2,tol);
1315 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1316 B.Add(E2,TopoDS::Vertex(tmpV));
1320 B.MakeEdge(E1,tc2,tol);
1321 TopoDS_Shape tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_FORWARD);
1322 B.Add(E1,TopoDS::Vertex(tmpV));
1325 B.MakeEdge(E2,tc1,tol);
1327 tmpV = aSeqLocs.Value(jcurr).Oriented(TopAbs_REVERSED);
1328 B.Add(E2,TopoDS::Vertex(tmpV));
1333 Edges.InsertAfter(i-1,E1);
1334 Edges.InsertAfter(i,E2);
1338 if(nbEdges<Edges.Length()) {
1339 // one of edges was splitted => we have to update WirePath
1343 for(i=1; i<=Edges.Length(); i++) {
1344 B.Add(W,TopoDS::Edge(Edges.Value(i)));
1350 BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
1352 Standard_Integer nbShapes = aSeqBases.Length();
1353 Standard_Integer step = nbShapes/nbBases;
1355 if(nbShapes < nbBases || fmod((double)nbShapes, (double)nbBases))
1358 Standard_ConstructionError::Raise("Invalid sections were specified for building pipe");
1361 Standard_Integer ind =0;
1362 for( i=1; i <= nbShapes && ind < nbShapes; i++) //i+nbBases <= nbShapes
1364 TopTools_SequenceOfShape usedBases;
1365 Standard_Integer j = 1;
1366 for( ; j <= nbBases ; j++)
1368 ind = i + (j-1)*step;
1370 TopoDS_Shape aWireProf = aSeqBases.Value(ind);
1371 usedBases.Append(aWireProf);
1374 TopoDS_Shape aShapeLoc = aSeqLocs.Value(j);
1375 TopoDS_Vertex aVert = TopoDS::Vertex(aShapeLoc);
1376 aBuilder.Add(aWireProf,aVert,aWithContact,aWithCorrect);
1379 aBuilder.Add(aWireProf,aWithContact,aWithCorrect);
1381 if(!aBuilder.IsReady())
1384 Standard_ConstructionError::Raise("Invalid input data for building PIPE: bases are invalid");
1387 aShape = aBuilder.Shape();
1388 aSeqFaces.Append(aShape);
1389 for( j = 1; j <=usedBases.Length(); j++)
1390 aBuilder.Delete(usedBases.Value(j));
1393 //for case if section is face
1394 if(aSeqFaces.Length() >1)
1397 TopoDS_Compound aComp;
1398 aB.MakeCompound(aComp);
1399 for( i = 1; i <= aSeqFaces.Length(); i++)
1400 aB.Add(aComp,aSeqFaces.Value(i));
1405 //building pipe with shell sections
1406 else if (aType == PIPE_SHELL_SECTIONS) {
1407 aShape = CreatePipeForShellSections(aWirePath,aCI);
1410 if (aShape.IsNull()) return 0;
1412 BRepCheck_Analyzer ana (aShape, Standard_False);
1413 if (!ana.IsValid()) {
1415 Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
1418 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
1419 aFunction->SetValue(aRes);
1421 log.SetTouched(Label());
1427 //=======================================================================
1428 //function : GEOMImpl_PipeDriver_Type_
1430 //=======================================================================
1431 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PipeDriver_Type_()
1434 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
1435 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
1436 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
1437 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
1438 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
1439 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
1442 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
1443 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PipeDriver",
1444 sizeof(GEOMImpl_PipeDriver),
1446 (Standard_Address)_Ancestors,
1447 (Standard_Address)NULL);
1452 //=======================================================================
1453 //function : DownCast
1455 //=======================================================================
1456 const Handle(GEOMImpl_PipeDriver) Handle(GEOMImpl_PipeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
1458 Handle(GEOMImpl_PipeDriver) _anOtherObject;
1460 if (!AnObject.IsNull()) {
1461 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PipeDriver))) {
1462 _anOtherObject = Handle(GEOMImpl_PipeDriver)((Handle(GEOMImpl_PipeDriver)&)AnObject);
1466 return _anOtherObject ;