Correction of next problem from bug NPAL14857.

This commit is contained in:
skl 2007-06-22 07:40:58 +00:00
parent e3a1162344
commit 1569e9e9fc
2 changed files with 163 additions and 3 deletions

View File

@ -69,6 +69,8 @@
#include "utilities.h" #include "utilities.h"
#include "BRepTools.hxx"
//======================================================================= //=======================================================================
//function : GetID //function : GetID
@ -584,6 +586,152 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
CreateFewSolids = true; CreateFewSolids = true;
} }
// check orientation of sections
bool NeedReverse = false;
{
// first section
anExp.Init( aShBase1, TopAbs_FACE );
TopoDS_Shape aFace = anExp.Current();
TColgp_SequenceOfPnt aPnts;
double xc=0, yc=0, zc=0;
for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
aPnts.Append(BRep_Tool::Pnt(V));
xc += aPnts.Last().X();
yc += aPnts.Last().Y();
zc += aPnts.Last().Z();
}
gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
gp_Vec V1(PC,aPnts.Value(1));
gp_Vec V2(PC,aPnts.Value(2));
gp_Vec VN = V1.Crossed(V2);
for(int ip=2; ip<aPnts.Length(); ip++) {
V1 = gp_Vec(PC,aPnts.Value(ip));
V2 = gp_Vec(PC,aPnts.Value(ip+1));
VN.Add(V1.Crossed(V2));
}
gp_Vec PathNorm;
gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i)));
TopExp_Explorer WE;
for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
TopoDS_Edge edge = TopoDS::Edge(WE.Current());
double tol = BRep_Tool::Tolerance(edge);
TopoDS_Vertex VF = sae.FirstVertex(edge);
gp_Pnt PF = BRep_Tool::Pnt(VF);
if( PF.Distance(PLoc) < tol ) {
double fp,lp;
Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
gp_Pnt P1,P2;
C->D0(fp,P1);
if( P1.Distance(PLoc) < tol ) {
C->D0(fp+(lp-fp)/100,P2);
}
else {
C->D0(lp,P1);
C->D0(lp+(fp-lp)/100,P2);
}
PathNorm = gp_Vec(P1,P2);
break;
}
else {
TopoDS_Vertex VL = sae.LastVertex(edge);
gp_Pnt PL = BRep_Tool::Pnt(VL);
if( PL.Distance(PLoc) < tol ) {
double fp,lp;
Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
gp_Pnt P1,P2;
C->D0(fp,P1);
if( P1.Distance(PLoc) < tol ) {
C->D0(fp+(lp-fp)/100,P2);
}
else {
C->D0(lp,P1);
C->D0(lp+(fp-lp)/100,P2);
}
PathNorm = gp_Vec(P2,P1);
break;
}
}
}
//cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
//cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
if(fabs(VN.Angle(PathNorm)>PI/2.)) {
NeedReverse = true;
aShBase1.Reverse();
}
}
{
// second section
anExp.Init( aShBase2, TopAbs_FACE );
TopoDS_Shape aFace = anExp.Current();
TColgp_SequenceOfPnt aPnts;
double xc=0, yc=0, zc=0;
for ( anExp.Init( aFace, TopAbs_VERTEX ); anExp.More(); anExp.Next() ) {
TopoDS_Vertex V = TopoDS::Vertex(anExp.Current());
aPnts.Append(BRep_Tool::Pnt(V));
xc += aPnts.Last().X();
yc += aPnts.Last().Y();
zc += aPnts.Last().Z();
}
gp_Pnt PC( xc/aPnts.Length(), yc/aPnts.Length(), zc/aPnts.Length() );
gp_Vec V1(PC,aPnts.Value(1));
gp_Vec V2(PC,aPnts.Value(2));
gp_Vec VN = V1.Crossed(V2);
for(int ip=2; ip<aPnts.Length(); ip++) {
V1 = gp_Vec(PC,aPnts.Value(ip));
V2 = gp_Vec(PC,aPnts.Value(ip+1));
VN.Add(V1.Crossed(V2));
}
gp_Vec PathNorm;
gp_Pnt PLoc = BRep_Tool::Pnt(TopoDS::Vertex(VLocs(i+1)));
TopExp_Explorer WE;
for ( WE.Init( WPath, TopAbs_EDGE ); WE.More(); WE.Next() ) {
TopoDS_Edge edge = TopoDS::Edge(WE.Current());
double tol = BRep_Tool::Tolerance(edge);
TopoDS_Vertex VF = sae.FirstVertex(edge);
gp_Pnt PF = BRep_Tool::Pnt(VF);
if( PF.Distance(PLoc) < tol ) {
double fp,lp;
Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
gp_Pnt P1,P2;
C->D0(fp,P1);
if( P1.Distance(PLoc) < tol ) {
C->D0(fp+(lp-fp)/100,P2);
}
else {
C->D0(lp,P1);
C->D0(lp+(fp-lp)/100,P2);
}
PathNorm = gp_Vec(P2,P1);
break;
}
else {
TopoDS_Vertex VL = sae.LastVertex(edge);
gp_Pnt PL = BRep_Tool::Pnt(VL);
if( PL.Distance(PLoc) < tol ) {
double fp,lp;
Handle(Geom_Curve) C = BRep_Tool::Curve(edge,fp,lp);
gp_Pnt P1,P2;
C->D0(fp,P1);
if( P1.Distance(PLoc) < tol ) {
C->D0(fp+(lp-fp)/100,P2);
}
else {
C->D0(lp,P1);
C->D0(lp+(fp-lp)/100,P2);
}
PathNorm = gp_Vec(P2,P1);
break;
}
}
}
//cout<<"VN("<<VN.X()<<","<<VN.Y()<<","<<VN.Z()<<")"<<endl;
//cout<<"PathNorm("<<PathNorm.X()<<","<<PathNorm.Y()<<","<<PathNorm.Z()<<")"<<endl;
if(fabs(VN.Angle(PathNorm)>PI/2.))
aShBase2.Reverse();
}
if(!CreateFewSolids) { if(!CreateFewSolids) {
// we can create only one solid // we can create only one solid
TopoDS_Shape aWire1, aWire2; TopoDS_Shape aWire1, aWire2;
@ -656,6 +804,10 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) { for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
B.Add(aShell,anExp.Current()); B.Add(aShell,anExp.Current());
} }
if(NeedReverse) {
cout<<"shell is reversed"<<endl;
aShell.Reverse();
}
// make sewing for this shell // make sewing for this shell
Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing; Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
aSewing->SetTolerance(Precision::Confusion()); aSewing->SetTolerance(Precision::Confusion());
@ -687,10 +839,12 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
else { else {
// main block - creation few solids (for each pair of faces) // main block - creation few solids (for each pair of faces)
TopTools_MapOfShape aFaces1,aFaces2; TopTools_MapOfShape aFaces1,aFaces2;
for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) for ( anExp.Init( aShBase1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
aFaces1.Add(anExp.Current()); aFaces1.Add(anExp.Current());
for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) }
for ( anExp.Init( aShBase2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
aFaces2.Add(anExp.Current()); aFaces2.Add(anExp.Current());
}
// creating map of edge faces // creating map of edge faces
TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1; TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces1;
TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1); TopExp::MapShapesAndAncestors(aShBase1, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces1);
@ -885,6 +1039,10 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
} }
B.Add(aShell,F1); B.Add(aShell,F1);
B.Add(aShell,F2); B.Add(aShell,F2);
if(NeedReverse) {
//cout<<"shell is reversed"<<endl;
aShell.Reverse();
}
// make sewing for this shell // make sewing for this shell
Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing; Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
aSewing->SetTolerance(Precision::Confusion()); aSewing->SetTolerance(Precision::Confusion());

View File

@ -747,7 +747,9 @@ def MakePipeWithDifferentSections(theSeqBases, theLocations,thePath,theWithConta
# @param theSeqSubBases - list of corresponding subshapes of section shapes. # @param theSeqSubBases - list of corresponding subshapes of section shapes.
# @param theLocations - list of locations on the path corresponding # @param theLocations - list of locations on the path corresponding
# specified list of the Bases shapes. Number of locations # specified list of the Bases shapes. Number of locations
# should be equal to number of bases. # should be equal to number of bases. First and last
# locations must be coincided with first and last vertexes
# of path correspondingly.
# @param thePath - Path shape to extrude the base shape along it. # @param thePath - Path shape to extrude the base shape along it.
# @param theWithContact - the mode defining that the section is translated to be in # @param theWithContact - the mode defining that the section is translated to be in
# contact with the spine. # contact with the spine.