0022869: Group creation support for MakePipeWithShellSections

This commit is contained in:
skv 2015-04-03 18:51:38 +03:00
parent 9592686c26
commit 7e62b8b779
3 changed files with 368 additions and 333 deletions

View File

@ -323,9 +323,11 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFacesByList (const TopoDS_Shape& theShape,
//function : GlueFaces //function : GlueFaces
//purpose : //purpose :
//======================================================================= //=======================================================================
TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape, TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces
const Standard_Real theTolerance, (const TopoDS_Shape &theShape,
const Standard_Boolean doKeepNonSolids) const Standard_Real theTolerance,
const Standard_Boolean doKeepNonSolids,
TopTools_DataMapOfShapeListOfShape *pMapModif)
{ {
TopoDS_Shape aRes; TopoDS_Shape aRes;
@ -409,6 +411,26 @@ TopoDS_Shape GEOMImpl_GlueDriver::GlueFaces (const TopoDS_Shape& theShape,
// 5. Result // 5. Result
aRes = aGA.Shape(); aRes = aGA.Shape();
if (pMapModif) {
// Fill the map of modified shapes.
TopTools_IndexedMapOfShape aMapSubShapes;
TopExp::MapShapes(theShape, aMapSubShapes);
pMapModif->Clear();
const Standard_Integer aNbShapes = aMapSubShapes.Extent();
Standard_Integer i;
for (i = 1; i <= aNbShapes; ++i) {
const TopoDS_Shape &aSubShape = aMapSubShapes.FindKey(i);
const TopTools_ListOfShape &aModif = aGA.Modified(aSubShape);
if (!aModif.IsEmpty()) {
pMapModif->Bind(aSubShape, aModif);
}
}
}
return aRes; return aRes;
} }

View File

@ -63,6 +63,7 @@
#include <TCollection_AsciiString.hxx> #include <TCollection_AsciiString.hxx>
class TColStd_SequenceOfExtendedString; class TColStd_SequenceOfExtendedString;
class TopTools_DataMapOfShapeListOfShape;
#include "GEOM_BaseDriver.hxx" #include "GEOM_BaseDriver.hxx"
@ -86,9 +87,11 @@ Standard_EXPORT ~GEOMImpl_GlueDriver() {};
bool GetCreationInformation(std::string& theOperationName, bool GetCreationInformation(std::string& theOperationName,
std::vector<GEOM_Param>& params); std::vector<GEOM_Param>& params);
Standard_EXPORT static TopoDS_Shape GlueFaces (const TopoDS_Shape& theShape, Standard_EXPORT static TopoDS_Shape GlueFaces
const Standard_Real theTolerance, (const TopoDS_Shape &theShape,
const Standard_Boolean doKeepNonSolids = Standard_True); const Standard_Real theTolerance,
const Standard_Boolean doKeepNonSolids = Standard_True,
TopTools_DataMapOfShapeListOfShape *pMapModif = NULL);
/* /*
Standard_EXPORT TopoDS_Shape GlueFacesWithWarnings (const TopoDS_Shape& theShape, Standard_EXPORT TopoDS_Shape GlueFacesWithWarnings (const TopoDS_Shape& theShape,
const Standard_Real theTolerance, const Standard_Real theTolerance,

View File

@ -106,11 +106,15 @@
#define GROUP_SIDE2 3 #define GROUP_SIDE2 3
#define GROUP_OTHER 4 #define GROUP_OTHER 4
static bool FillGroups(const TopTools_SequenceOfShape *theGroups,
const TopTools_IndexedMapOfShape &theIndices,
Handle(TColStd_HArray1OfInteger) *theGroupIds);
static void StoreGroups(GEOMImpl_IPipe *theCI, static void StoreGroups(GEOMImpl_IPipe *theCI,
Handle(TColStd_HArray1OfInteger) *theGroups); Handle(TColStd_HArray1OfInteger) *theGroups);
static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep, static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
Handle(TColStd_HArray1OfInteger) *theGroups); TopTools_SequenceOfShape *theGroups);
//======================================================================= //=======================================================================
//function : GetID //function : GetID
@ -976,33 +980,15 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
// Create groups. // Create groups.
if (isCreateGroups) { if (isCreateGroups) {
// Make groups. // Make groups.
Handle(TColStd_HArray1OfInteger) aGroups[5]; TopTools_SequenceOfShape aGroups[5];
TopTools_IndexedMapOfShape anIndices;
if (!DoGroups(aBuilder, aGroups)) { if (!DoGroups(aBuilder, aGroups)) {
Standard_ConstructionError::Raise("Generate groups failure"); Standard_ConstructionError::Raise("Generate groups failure");
} }
TopExp::MapShapes(resShape, anIndices);
// Get shapes from all groups. // Get shapes from all groups.
for (iGrp = 0; iGrp < 5; ++iGrp) { for (iGrp = 0; iGrp < 5; ++iGrp) {
aMapResGroups[iGrp].Bind(resShape, TopTools_SequenceOfShape()); aMapResGroups[iGrp].Bind(resShape, aGroups[iGrp]);
if (aGroups[iGrp].IsNull() == Standard_False) {
TopTools_SequenceOfShape &aShapes =
aMapResGroups[iGrp].ChangeFind(resShape);
Standard_Integer i = aGroups[iGrp]->Lower();
Standard_Integer aLastInd = aGroups[iGrp]->Upper();
// Get shapes from IDs.
for (; i <= aLastInd; ++i) {
const Standard_Integer anIndex = aGroups[iGrp]->Value(i);
const TopoDS_Shape &aGrpShape = anIndices.FindKey(anIndex);
aShapes.Append(aGrpShape);
}
}
} }
} }
} }
@ -1042,33 +1028,15 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
// Create groups. // Create groups.
if (isCreateGroups) { if (isCreateGroups) {
// Make groups. // Make groups.
Handle(TColStd_HArray1OfInteger) aGroups[5]; TopTools_SequenceOfShape aGroups[5];
TopTools_IndexedMapOfShape anIndices;
if (!DoGroups(aBuilder, aGroups)) { if (!DoGroups(aBuilder, aGroups)) {
Standard_ConstructionError::Raise("Generate groups failure"); Standard_ConstructionError::Raise("Generate groups failure");
} }
TopExp::MapShapes(resShape, anIndices);
// Get shapes from all groups. // Get shapes from all groups.
for (iGrp = 0; iGrp < 5; ++iGrp) { for (iGrp = 0; iGrp < 5; ++iGrp) {
aMapResGroups[iGrp].Bind(resShape, TopTools_SequenceOfShape()); aMapResGroups[iGrp].Bind(resShape, aGroups[iGrp]);
if (aGroups[iGrp].IsNull() == Standard_False) {
TopTools_SequenceOfShape &aShapes =
aMapResGroups[iGrp].ChangeFind(resShape);
Standard_Integer i = aGroups[iGrp]->Lower();
Standard_Integer aLastInd = aGroups[iGrp]->Upper();
// Get shapes from IDs.
for (; i <= aLastInd; ++i) {
const Standard_Integer anIndex = aGroups[iGrp]->Value(i);
const TopoDS_Shape &aGrpShape = anIndices.FindKey(anIndex);
aShapes.Append(aGrpShape);
}
}
} }
} }
@ -1086,12 +1054,7 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
if (isCreateGroups) { if (isCreateGroups) {
// Replase Group shapes by modified ones. // Replase Group shapes by modified ones.
Standard_Integer aNbShapes[5] = { 0, 0, 0, 0, 0 }; TopTools_SequenceOfShape aSeqGroups[5];
Handle(TColStd_HArray1OfInteger) aGroups[5];
TopTools_ListOfShape aListGroups[5];
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aShape, anIndices);
// For each group. // For each group.
for (iGrp = 0; iGrp < 5; ++iGrp) { for (iGrp = 0; iGrp < 5; ++iGrp) {
@ -1111,9 +1074,7 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
aMapResGroups[iGrp].Find(aSeqRes.Value(i)); aMapResGroups[iGrp].Find(aSeqRes.Value(i));
Standard_Integer j; Standard_Integer j;
aNbShapes[iGrp] += aShapes.Length(); // For each sub-shape of pipe
// For each sug-shape of pipe
for (j = 1; j <= aShapes.Length(); ++j) { for (j = 1; j <= aShapes.Length(); ++j) {
const TopoDS_Shape &aGrpShape = aShapes.Value(j); const TopoDS_Shape &aGrpShape = aShapes.Value(j);
@ -1122,32 +1083,22 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
const TopoDS_Shape &aModifGrpShape = const TopoDS_Shape &aModifGrpShape =
aSewing->ModifiedSubShape(aGrpShape); aSewing->ModifiedSubShape(aGrpShape);
aListGroups[iGrp].Append(aModifGrpShape); aSeqGroups[iGrp].Append(aModifGrpShape);
} else { } else {
// Use the shape as it is. // Use the shape as it is.
aListGroups[iGrp].Append(aGrpShape); aSeqGroups[iGrp].Append(aGrpShape);
} }
} }
} }
}
// Create a group. // Fill groups
if (aNbShapes[iGrp] > 0) { TopTools_IndexedMapOfShape anIndices;
theGroups[iGrp] = new TColStd_HArray1OfInteger(1, aNbShapes[iGrp]);
TopTools_ListIteratorOfListOfShape anIter(aListGroups[iGrp]); TopExp::MapShapes(aShape, anIndices);
for (i = 1; anIter.More(); anIter.Next(), ++i) { if (!FillGroups(aSeqGroups, anIndices, theGroups)) {
const TopoDS_Shape &aGrpShape = anIter.Value(); Standard_ConstructionError::Raise("Generate groups failure");
const Standard_Integer anIndex =
anIndices.FindIndex(aGrpShape);
if (anIndex == 0) {
Standard_ConstructionError::Raise("Generate groups failure");
}
theGroups[iGrp]->SetValue(i, anIndex);
}
}
} }
} }
} }
@ -1202,7 +1153,20 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
if (isCreateGroups) { if (isCreateGroups) {
// Make groups. // Make groups.
if (!DoGroups(aBuilder, theGroups)) { TopTools_SequenceOfShape aSeqGroups[5];
if (!DoGroups(aBuilder, aSeqGroups)) {
Standard_ConstructionError::Raise("Generate groups failure");
}
// Fill the groups.
Handle(TColStd_HArray1OfInteger) aGroupIds[5];
TopTools_IndexedMapOfShape anIndices;
const TopoDS_Shape aResult = aBuilder.Shape();
TopExp::MapShapes(aResult, anIndices);
if (!FillGroups(aSeqGroups, anIndices, theGroups)) {
Standard_ConstructionError::Raise("Generate groups failure"); Standard_ConstructionError::Raise("Generate groups failure");
} }
} }
@ -1222,8 +1186,6 @@ TopoDS_Shape GEOMImpl_PipeDriver::CreatePipeWithDifferentSections
static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath, static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
GEOMImpl_IPipe* aCI) GEOMImpl_IPipe* aCI)
{ {
//cout<<"CreatePipeForShellSections"<<endl;
//TopoDS_Shape res;
int i,j; int i,j;
BRep_Builder B; BRep_Builder B;
@ -1233,6 +1195,7 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations(); Handle(TColStd_HSequenceOfTransient) aLocObjs = aCIDS->GetLocations();
Standard_Boolean aWithContact = (aCIDS->GetWithContactMode()); Standard_Boolean aWithContact = (aCIDS->GetWithContactMode());
Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode()); Standard_Boolean aWithCorrect = (aCIDS->GetWithCorrectionMode());
Standard_Boolean isGenerateGroups = aCIDS->GetGenerateGroups();
Standard_Integer nbBases = aBasesObjs->Length(), Standard_Integer nbBases = aBasesObjs->Length(),
nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()), nbSubBases = (aSubBasesObjs.IsNull() ? 0 :aSubBasesObjs->Length()),
@ -1247,8 +1210,6 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections "); Standard_ConstructionError::Raise("Number of sections is not equal to number of subsections ");
} }
//BRepOffsetAPI_MakePipeShell aBuilder(aWirePath);
TopTools_SequenceOfShape VLocs; TopTools_SequenceOfShape VLocs;
for (i=1; i<=nbBases; i++) { for (i=1; i<=nbBases; i++) {
Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i); Handle(Standard_Transient) anItemLoc = aLocObjs->Value(i);
@ -1420,7 +1381,6 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
for (; i<=Edges.Length(); i++) for (; i<=Edges.Length(); i++)
B.Add(W,Edges.Value(i)); B.Add(W,Edges.Value(i));
Wires.Append(W); Wires.Append(W);
//cout<<"Wires.Length()="<<Wires.Length()<<endl;
} }
if (Wires.Length() != nbLocs-1) { if (Wires.Length() != nbLocs-1) {
@ -1429,10 +1389,8 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
("One of location shapes is not lied on the path"); ("One of location shapes is not lied on the path");
} }
//TopTools_SequenceOfShape aSeqBases; TopTools_SequenceOfShape aGroups[5];
//TopTools_SequenceOfShape aSeqSubBases; TopoDS_Compound aComp;
//TopTools_SequenceOfShape aSeqFaces;
TopoDS_Compound aComp;
B.MakeCompound(aComp); B.MakeCompound(aComp);
for (i = 1; i < nbBases; i++) { for (i = 1; i < nbBases; i++) {
TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i)); TopoDS_Wire WPath = TopoDS::Wire(Wires.Value(i));
@ -1459,8 +1417,6 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
continue; continue;
TopAbs_ShapeEnum aType2 = aShBase2.ShapeType(); TopAbs_ShapeEnum aType2 = aShBase2.ShapeType();
//BRepTools::Write(aShBase1,"/dn02/users_Linux/skl/work/Bugs/14857/base1.brep");
bool OkSec = (aType1==TopAbs_SHELL || aType1==TopAbs_FACE) && bool OkSec = (aType1==TopAbs_SHELL || aType1==TopAbs_FACE) &&
(aType2==TopAbs_SHELL || aType2==TopAbs_FACE); (aType2==TopAbs_SHELL || aType2==TopAbs_FACE);
if (!OkSec) { if (!OkSec) {
@ -1483,153 +1439,6 @@ 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;
@ -1695,7 +1504,22 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
BuildPipeShell(aBuilder); BuildPipeShell(aBuilder);
TopoDS_Shape aShape = aBuilder.Shape(); TopoDS_Shape aShape = aBuilder.Shape();
TopTools_SequenceOfShape aLocalGroups[5];
// Create groups.
if (isGenerateGroups) {
// Make groups.
if (!DoGroups(aBuilder, aLocalGroups)) {
if (aCI) delete aCI;
Standard_ConstructionError::Raise("Generate groups failure");
}
// Clear the groups Down and Up.
aLocalGroups[GROUP_DOWN].Clear();
aLocalGroups[GROUP_UP].Clear();
}
TopoDS_Shell aShell; TopoDS_Shell aShell;
B.MakeShell(aShell); B.MakeShell(aShell);
for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) { for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
@ -1703,9 +1527,17 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
} }
for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) { for (anExp.Init(aShBase1, TopAbs_FACE); anExp.More(); anExp.Next()) {
B.Add(aShell,anExp.Current()); B.Add(aShell,anExp.Current());
if (isGenerateGroups && i == 1) {
aLocalGroups[GROUP_DOWN].Append(anExp.Current());
}
} }
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 (isGenerateGroups && i == nbBases - 1) {
aLocalGroups[GROUP_UP].Append(anExp.Current());
}
} }
// make sewing for this shell // make sewing for this shell
Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing; Handle(BRepBuilderAPI_Sewing) aSewing = new BRepBuilderAPI_Sewing;
@ -1738,6 +1570,30 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
else { else {
B.Add(aComp,aShell); B.Add(aComp,aShell);
} }
if (isGenerateGroups) {
Standard_Integer iGrp;
for (iGrp = 0; iGrp < 5; ++iGrp) {
Standard_Integer j;
// For each sub-shape of pipe
for (j = 1; j <= aLocalGroups[iGrp].Length(); ++j) {
const TopoDS_Shape &aGrpShape = aLocalGroups[iGrp].Value(j);
if (aSewing->IsModifiedSubShape(aGrpShape)) {
// Use the shape modified by sewing.
const TopoDS_Shape &aModifGrpShape =
aSewing->ModifiedSubShape(aGrpShape);
aGroups[iGrp].Append(aModifGrpShape);
} else {
// Use the shape as it is.
aGroups[iGrp].Append(aGrpShape);
}
}
}
}
} }
} }
else { else {
@ -1935,7 +1791,30 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
BuildPipeShell(aBuilder); BuildPipeShell(aBuilder);
TopoDS_Shape aShape = aBuilder.Shape(); TopoDS_Shape aShape = aBuilder.Shape();
TopTools_SequenceOfShape aLocalGroups[5];
// Create groups.
if (isGenerateGroups) {
// Make groups.
if (!DoGroups(aBuilder, aLocalGroups)) {
if (aCI) delete aCI;
Standard_ConstructionError::Raise("Generate groups failure");
}
// Clear the groups Down and Up.
aLocalGroups[GROUP_DOWN].Clear();
aLocalGroups[GROUP_UP].Clear();
if (i == 1) {
aLocalGroups[GROUP_DOWN].Append(F1);
}
if (i == nbBases - 1) {
aLocalGroups[GROUP_UP].Append(F2);
}
}
TopoDS_Shell aShell; TopoDS_Shell aShell;
B.MakeShell(aShell); B.MakeShell(aShell);
for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) { for (anExp.Init(aShape, TopAbs_FACE); anExp.More(); anExp.Next()) {
@ -1976,13 +1855,52 @@ static TopoDS_Shape CreatePipeForShellSections(const TopoDS_Wire& aWirePath,
else { else {
B.Add(aComp,aShell); B.Add(aComp,aShell);
} }
if (isGenerateGroups) {
// Replase Group shapes by modified ones.
Standard_Integer iGrp;
// For each group.
for (iGrp = 0; iGrp < 5; ++iGrp) {
Standard_Integer j;
// For each sub-shape of pipe
for (j = 1; j <= aLocalGroups[iGrp].Length(); ++j) {
const TopoDS_Shape &aGrpShape = aLocalGroups[iGrp].Value(j);
if (aSewing->IsModifiedSubShape(aGrpShape)) {
// Use the shape modified by sewing.
const TopoDS_Shape &aModifGrpShape =
aSewing->ModifiedSubShape(aGrpShape);
aGroups[iGrp].Append(aModifGrpShape);
} else {
// Use the shape as it is.
aGroups[iGrp].Append(aGrpShape);
}
}
}
}
} }
} }
} }
} }
//BRepTools::Write(aComp,"/dn02/users_Linux/skl/work/Bugs/14857/comp.brep"); if (isGenerateGroups) {
// Fill the groups.
Handle(TColStd_HArray1OfInteger) aGroupIds[5];
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aComp, anIndices);
if (!FillGroups(aGroups, anIndices, aGroupIds)) {
if (aCI) delete aCI;
Standard_ConstructionError::Raise("Generate groups failure");
}
StoreGroups(aCI, aGroupIds);
}
return aComp; return aComp;
} }
@ -2528,28 +2446,32 @@ static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
} }
//======================================================================= //=======================================================================
//function : FillGroup //function : FillGroups
//purpose : auxilary for DoGroups() //purpose : auxilary for DoGroups()
//======================================================================= //=======================================================================
static bool FillGroup(const TopTools_IndexedMapOfShape &theMapGroup, bool FillGroups(const TopTools_SequenceOfShape *theGroups,
const TopTools_IndexedMapOfShape &theIndices, const TopTools_IndexedMapOfShape &theIndices,
Handle(TColStd_HArray1OfInteger) &theGroup) Handle(TColStd_HArray1OfInteger) *theGroupIds)
{ {
if (!theMapGroup.IsEmpty()) { Standard_Integer i;
const Standard_Integer aNbShapes = theMapGroup.Extent();
Standard_Integer i;
theGroup = new TColStd_HArray1OfInteger(1, aNbShapes); for (i = 0; i < 5; ++i) {
if (!theGroups[i].IsEmpty()) {
const Standard_Integer aNbShapes = theGroups[i].Length();
Standard_Integer j;
for (i = 1; i <= aNbShapes; ++i) { theGroupIds[i] = new TColStd_HArray1OfInteger(1, aNbShapes);
const TopoDS_Shape &aShape = theMapGroup.FindKey(i);
const Standard_Integer anIndex = theIndices.FindIndex(aShape);
if (anIndex == 0) { for (j = 1; j <= aNbShapes; ++j) {
return false; const TopoDS_Shape &aShape = theGroups[i].Value(j);
const Standard_Integer anIndex = theIndices.FindIndex(aShape);
if (anIndex == 0) {
return false;
}
theGroupIds[i]->SetValue(j, anIndex);
} }
theGroup->SetValue(i, anIndex);
} }
} }
@ -2560,8 +2482,8 @@ static bool FillGroup(const TopTools_IndexedMapOfShape &theMapGroup,
//function : StoreGroups //function : StoreGroups
//purpose : auxilary for CreateGroups() //purpose : auxilary for CreateGroups()
//======================================================================= //=======================================================================
static void StoreGroups(GEOMImpl_IPipe *theCI, void StoreGroups(GEOMImpl_IPipe *theCI,
Handle(TColStd_HArray1OfInteger) *theGroups) Handle(TColStd_HArray1OfInteger) *theGroups)
{ {
if (theGroups[GROUP_DOWN].IsNull() == Standard_False) { if (theGroups[GROUP_DOWN].IsNull() == Standard_False) {
theCI->SetGroupDown(theGroups[GROUP_DOWN]); theCI->SetGroupDown(theGroups[GROUP_DOWN]);
@ -2588,11 +2510,9 @@ static void StoreGroups(GEOMImpl_IPipe *theCI,
//function : CreateDownUpGroups //function : CreateDownUpGroups
//purpose : auxilary for DoGroups() //purpose : auxilary for DoGroups()
//======================================================================= //=======================================================================
static bool CreateDownUpGroups static bool CreateDownUpGroups(BRepPrimAPI_MakeSweep *theSweep,
(const TopTools_IndexedMapOfShape &theIndices, TopTools_SequenceOfShape *theGroups,
BRepPrimAPI_MakeSweep *theSweep, Standard_Boolean &IsDoSides)
Handle(TColStd_HArray1OfInteger) *theGroups,
Standard_Boolean &IsDoSides)
{ {
const TopoDS_Shape aDownShape = theSweep->FirstShape(); const TopoDS_Shape aDownShape = theSweep->FirstShape();
const TopAbs_ShapeEnum aType = aDownShape.ShapeType(); const TopAbs_ShapeEnum aType = aDownShape.ShapeType();
@ -2622,31 +2542,30 @@ static bool CreateDownUpGroups
return false; return false;
} }
const TopoDS_Shape anUpShape = theSweep->LastShape(); TopExp_Explorer anExp(aDownShape, anUpDownType);
TopExp_Explorer anExp(aDownShape, anUpDownType); TopTools_MapOfShape aMapFence;
TopTools_IndexedMapOfShape aMapGroup;
// Create Down group. // Create Down group.
for (; anExp.More(); anExp.Next()) { for (; anExp.More(); anExp.Next()) {
aMapGroup.Add(anExp.Current()); const TopoDS_Shape &aShape = anExp.Current();
}
if (!FillGroup(aMapGroup, theIndices, theGroups[GROUP_DOWN])) { if (aMapFence.Add(aShape)) {
return false; theGroups[GROUP_DOWN].Append(aShape);
}
} }
// Create Up group // Create Up group
aMapGroup.Clear(); const TopoDS_Shape anUpShape = theSweep->LastShape();
aMapFence.Clear();
anExp.Init(anUpShape, anUpDownType); anExp.Init(anUpShape, anUpDownType);
for (; anExp.More(); anExp.Next()) { for (; anExp.More(); anExp.Next()) {
aMapGroup.Add(anExp.Current()); const TopoDS_Shape &aShape = anExp.Current();
}
Handle(TColStd_HArray1OfInteger) aGroupUp; if (aMapFence.Add(aShape)) {
theGroups[GROUP_UP].Append(aShape);
if (!FillGroup(aMapGroup, theIndices, theGroups[GROUP_UP])) { }
return false;
} }
return true; return true;
@ -2656,16 +2575,12 @@ static bool CreateDownUpGroups
//function : DoGroups //function : DoGroups
//purpose : auxilary for CreateGroups() //purpose : auxilary for CreateGroups()
//======================================================================= //=======================================================================
static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep, bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
Handle(TColStd_HArray1OfInteger) *theGroups) TopTools_SequenceOfShape *theGroups)
{ {
TopTools_IndexedMapOfShape anIndices; Standard_Boolean isDoSides = Standard_False;
Standard_Boolean isDoSides = Standard_False;
const TopoDS_Shape aResult = theSweep.Shape();
TopExp::MapShapes(aResult, anIndices); if (!CreateDownUpGroups(&theSweep, theGroups, isDoSides)) {
if (!CreateDownUpGroups(anIndices, &theSweep, theGroups, isDoSides)) {
// Up and Down groups creation failure // Up and Down groups creation failure
return false; return false;
} }
@ -2690,27 +2605,22 @@ static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
if (!aLstSide.IsEmpty()) { if (!aLstSide.IsEmpty()) {
TopTools_ListIteratorOfListOfShape aSideIt(aLstSide); TopTools_ListIteratorOfListOfShape aSideIt(aLstSide);
TopTools_MapOfShape aMapFence;
TopTools_IndexedMapOfShape aMapGroup; const Standard_Integer anIdSide =
(i == 0 ? GROUP_SIDE1 : GROUP_SIDE2);
for (; aSideIt.More(); aSideIt.Next()) { for (; aSideIt.More(); aSideIt.Next()) {
const TopoDS_Shape &aSideShape = aSideIt.Value(); const TopoDS_Shape &aSideShape = aSideIt.Value();
if (aSideShape.ShapeType() == TopAbs_EDGE) { if (aSideShape.ShapeType() == TopAbs_EDGE) {
aMapGroup.Add(aSideShape); if (aMapFence.Add(aSideShape)) {
theGroups[anIdSide].Append(aSideShape);
}
} else { } else {
// Only edges can be is Side1 and Side2 groups. // Only edges can be is Side1 and Side2 groups.
return false; return false;
} }
} }
Handle(TColStd_HArray1OfInteger) &aGroupSide =
theGroups[i == 0 ? GROUP_SIDE1 : GROUP_SIDE2];
if (!FillGroup(aMapGroup, anIndices, aGroupSide)) {
return false;
}
} }
} }
} }
@ -2729,7 +2639,7 @@ static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
// Fill the map of faces generated from profile's boundary edges. // Fill the map of faces generated from profile's boundary edges.
TopTools_MapIteratorOfMapOfShape anIter(aMapBndEdges); TopTools_MapIteratorOfMapOfShape anIter(aMapBndEdges);
TopTools_IndexedMapOfShape aMapGroup; TopTools_MapOfShape aMapFence;
for (; anIter.More(); anIter.Next()) { for (; anIter.More(); anIter.Next()) {
const TopTools_ListOfShape &aLstOther = theSweep.Generated(anIter.Key()); const TopTools_ListOfShape &aLstOther = theSweep.Generated(anIter.Key());
@ -2741,7 +2651,9 @@ static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
const TopoDS_Shape &anOtherShape = anOtherIt.Value(); const TopoDS_Shape &anOtherShape = anOtherIt.Value();
if (anOtherShape.ShapeType() == TopAbs_FACE) { if (anOtherShape.ShapeType() == TopAbs_FACE) {
aMapGroup.Add(anOtherShape); if (aMapFence.Add(anOtherShape)) {
theGroups[GROUP_OTHER].Append(anOtherShape);
}
} else { } else {
// Only faces can be in Other group. // Only faces can be in Other group.
return false; return false;
@ -2749,10 +2661,6 @@ static bool DoGroups(BRepOffsetAPI_MakePipeShell &theSweep,
} }
} }
} }
if (!FillGroup(aMapGroup, anIndices, theGroups[GROUP_OTHER])) {
return false;
}
} }
return true; return true;
@ -2771,14 +2679,25 @@ static bool CreateGroups(BRepOffsetAPI_MakePipeShell &theSweep,
} }
// Make groups. // Make groups.
Handle(TColStd_HArray1OfInteger) aGroups[5]; TopTools_SequenceOfShape aGroups[5];
if (!DoGroups(theSweep, aGroups)) { if (!DoGroups(theSweep, aGroups)) {
return false; return false;
} }
// Fill the groups.
Handle(TColStd_HArray1OfInteger) aGroupIds[5];
TopTools_IndexedMapOfShape anIndices;
const TopoDS_Shape aResult = theSweep.Shape();
TopExp::MapShapes(aResult, anIndices);
if (!FillGroups(aGroups, anIndices, aGroupIds)) {
return false;
}
// Store groups. // Store groups.
StoreGroups(theCI, aGroups); StoreGroups(theCI, aGroupIds);
return true; return true;
} }
@ -2787,18 +2706,14 @@ static bool CreateGroups(BRepOffsetAPI_MakePipeShell &theSweep,
//function : DoGroups //function : DoGroups
//purpose : auxilary for CreateGroups() //purpose : auxilary for CreateGroups()
//======================================================================= //=======================================================================
static bool DoGroups(const TopoDS_Shape &theProfile, static bool DoGroups(const TopoDS_Shape &theProfile,
const TopoDS_Shape &thePath, const TopoDS_Shape &thePath,
BRepOffsetAPI_MakePipe &theSweep, BRepOffsetAPI_MakePipe &theSweep,
Handle(TColStd_HArray1OfInteger) *theGroups) TopTools_SequenceOfShape *theGroups)
{ {
TopTools_IndexedMapOfShape anIndices; Standard_Boolean isDoSides = Standard_False;
Standard_Boolean isDoSides = Standard_False;
const TopoDS_Shape aResult = theSweep.Shape();
TopExp::MapShapes(aResult, anIndices); if (!CreateDownUpGroups(&theSweep, theGroups, isDoSides)) {
if (!CreateDownUpGroups(anIndices, &theSweep, theGroups, isDoSides)) {
// Up and Down groups creation failure // Up and Down groups creation failure
return false; return false;
} }
@ -2817,28 +2732,24 @@ static bool DoGroups(const TopoDS_Shape &theProfile,
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
if (aV[i].IsNull() == Standard_False) { if (aV[i].IsNull() == Standard_False) {
TopExp_Explorer anExpP(thePath, TopAbs_EDGE); TopExp_Explorer anExpP(thePath, TopAbs_EDGE);
TopTools_IndexedMapOfShape aMapGroup; TopTools_MapOfShape aMapFence;
const Standard_Integer anIdSide =
(i == 0 ? GROUP_SIDE1 : GROUP_SIDE2);
for (; anExpP.More(); anExpP.Next()) { for (; anExpP.More(); anExpP.Next()) {
const TopoDS_Shape aSideShape = const TopoDS_Shape aSideShape =
theSweep.Generated(anExpP.Current(), aV[i]); theSweep.Generated(anExpP.Current(), aV[i]);
if (aSideShape.ShapeType() == TopAbs_EDGE) { if (aSideShape.ShapeType() == TopAbs_EDGE) {
aMapGroup.Add(aSideShape); if (aMapFence.Add(aSideShape)) {
theGroups[anIdSide].Append(aSideShape);
}
} else { } else {
// Only edges can be is Side1 and Side2 groups. // Only edges can be is Side1 and Side2 groups.
return false; return false;
} }
} }
Handle(TColStd_HArray1OfInteger) &aGroupSide =
theGroups[i == 0 ? GROUP_SIDE1 : GROUP_SIDE2];
if (!FillGroup(aMapGroup, anIndices, aGroupSide)) {
return false;
}
} }
} }
} else { } else {
@ -2854,8 +2765,8 @@ static bool DoGroups(const TopoDS_Shape &theProfile,
} }
} }
TopExp_Explorer anExpP(thePath, TopAbs_EDGE); TopExp_Explorer anExpP(thePath, TopAbs_EDGE);
TopTools_IndexedMapOfShape aMapGroup; TopTools_MapOfShape aMapFence;
for (; anExpP.More(); anExpP.Next()) { for (; anExpP.More(); anExpP.Next()) {
TopTools_MapIteratorOfMapOfShape anIter(aMapBndEdges); TopTools_MapIteratorOfMapOfShape anIter(aMapBndEdges);
@ -2865,17 +2776,15 @@ static bool DoGroups(const TopoDS_Shape &theProfile,
theSweep.Generated(anExpP.Current(), anIter.Key()); theSweep.Generated(anExpP.Current(), anIter.Key());
if (anOtherShape.ShapeType() == TopAbs_FACE) { if (anOtherShape.ShapeType() == TopAbs_FACE) {
aMapGroup.Add(anOtherShape); if (aMapFence.Add(anOtherShape)) {
theGroups[GROUP_OTHER].Append(anOtherShape);
}
} else { } else {
// Only faces can be in Other group. // Only faces can be in Other group.
return false; return false;
} }
} }
} }
if (!FillGroup(aMapGroup, anIndices, theGroups[GROUP_OTHER])) {
return false;
}
} }
return true; return true;
@ -2896,14 +2805,25 @@ static bool CreateGroups(const TopoDS_Shape &theProfile,
} }
// Make groups. // Make groups.
Handle(TColStd_HArray1OfInteger) aGroups[5]; TopTools_SequenceOfShape aGroups[5];
if (!DoGroups(theProfile, thePath, theSweep, aGroups)) { if (!DoGroups(theProfile, thePath, theSweep, aGroups)) {
return false; return false;
} }
// Fill the groups.
Handle(TColStd_HArray1OfInteger) aGroupIds[5];
TopTools_IndexedMapOfShape anIndices;
const TopoDS_Shape aResult = theSweep.Shape();
TopExp::MapShapes(aResult, anIndices);
if (!FillGroups(aGroups, anIndices, aGroupIds)) {
return false;
}
// Store groups. // Store groups.
StoreGroups(theCI, aGroups); StoreGroups(theCI, aGroupIds);
return true; return true;
} }
@ -3146,6 +3066,8 @@ Standard_Integer GEOMImpl_PipeDriver::Execute (TFunction_Logbook& log) const
aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI); aShape = CreatePipeBiNormalAlongVector(aWirePath, aCI);
} }
const Standard_Boolean isGenerateGroups = aCI->GetGenerateGroups();
if (aCI) { if (aCI) {
delete aCI; delete aCI;
aCI = 0; aCI = 0;
@ -3168,11 +3090,99 @@ Standard_Integer GEOMImpl_PipeDriver::Execute (TFunction_Logbook& log) const
aVertMaxTol = aTol; aVertMaxTol = aTol;
} }
aVertMaxTol += Precision::Confusion(); aVertMaxTol += Precision::Confusion();
aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, aVertMaxTol, Standard_True);
//aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True); TopTools_DataMapOfShapeListOfShape aMapModif;
TopTools_DataMapOfShapeListOfShape *pMapModif = NULL;
if (isGenerateGroups) {
pMapModif = &aMapModif;
}
TopoDS_Shape aNewShape = GEOMImpl_GlueDriver::GlueFaces
(aShape, aVertMaxTol, Standard_True, pMapModif);
if (isGenerateGroups && !aMapModif.IsEmpty()) {
// Update groups.
GEOMImpl_IPipe aCI(aFunction);
Handle(TColStd_HArray1OfInteger) aGroupIDs[5] =
{ aCI.GetGroupDown(), aCI.GetGroupUp(), aCI.GetGroupSide1(),
aCI.GetGroupSide2(), aCI.GetGroupOther() };
TopTools_IndexedMapOfShape anIndices;
TopTools_IndexedMapOfShape aNewIndices;
TopTools_SequenceOfShape aNewShapes[5];
TopTools_MapOfShape aMapReplaced;
TopTools_MapOfShape aMapGlued;
Standard_Integer iGrp;
Standard_Integer i;
TopExp::MapShapes(aShape, anIndices);
TopExp::MapShapes(aNewShape, aNewIndices);
for (iGrp = 0; iGrp < 5; ++iGrp) {
if (aGroupIDs[iGrp].IsNull() == Standard_False) {
const Standard_Integer aLower = aGroupIDs[iGrp]->Lower();
const Standard_Integer anUpper = aGroupIDs[iGrp]->Upper();
for (i = aLower; i <= anUpper; ++i) {
const Standard_Integer anIndex = aGroupIDs[iGrp]->Value(i);
const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex);
if (aMapModif.IsBound(aSubShape)) {
const TopTools_ListOfShape &aListModif =
aMapModif.Find(aSubShape);
TopTools_ListIteratorOfListOfShape anIter(aListModif);
for (; anIter.More(); anIter.Next()) {
const TopoDS_Shape &aNewShape = anIter.Value();
if (aMapReplaced.Add(aNewShape)) {
aNewShapes[iGrp].Append(aNewShape);
} else {
// This is a glued shape. It means that it is internal
// one and should be removed from groups later.
aMapGlued.Add(aNewShape);
}
}
} else {
// Shape is not modified.
aNewShapes[iGrp].Append(aSubShape);
}
}
}
}
if (!aMapGlued.IsEmpty()) {
// Remove glued (internal) shapes from groups.
for (iGrp = 0; iGrp < 5; ++iGrp) {
Standard_Integer aNbShapes = aNewShapes[iGrp].Length();
for (i = 1; i < aNbShapes; ++i) {
const TopoDS_Shape &aNewShape = aNewShapes[iGrp].Value(i);
if (aMapGlued.Contains(aNewShape)) {
aNewShapes[iGrp].Remove(i);
--i;
--aNbShapes;
}
}
}
}
// Store modified groups.
Handle(TColStd_HArray1OfInteger) aNewGroupIDs[5];
if (!FillGroups(aNewShapes, aNewIndices, aNewGroupIDs)) {
Standard_ConstructionError::Raise("Generate groups failure");
}
StoreGroups(&aCI, aNewGroupIDs);
}
aShape = aNewShape;
} }
} }
// Note: group indices should not be changed after the next call.
TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape); TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape);
aFunction->SetValue(aRes); aFunction->SetValue(aRes);