1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0028707: Simplify type 'BRepTools_ReShape'

Type 'BRepTools_ReShape' was simplified:
- the functionality to process shapes different only in orientation by different ways was removed as it is not used anywhere;
- method 'Apply' with the build mode parameter was moved to type 'ShapeBuild_ReShape' as it is used only through the last type.
This commit is contained in:
abk 2017-04-20 18:24:00 +03:00 committed by bugmaster
parent 177781da92
commit 669cd76e53
4 changed files with 152 additions and 230 deletions

View File

@ -91,7 +91,6 @@ static void CopyRanges (const TopoDS_Shape& toedge, const TopoDS_Shape& fromedge
BRepTools_ReShape::BRepTools_ReShape()
{
myConsiderLocation = Standard_False;
myConsiderOrientation = Standard_False;
}
@ -103,7 +102,6 @@ BRepTools_ReShape::BRepTools_ReShape()
void BRepTools_ReShape::Clear()
{
myNMap.Clear();
myRMap.Clear();
myNewShapes.Clear();
}
@ -113,25 +111,38 @@ void BRepTools_ReShape::Clear()
//purpose :
//=======================================================================
void BRepTools_ReShape::Remove (const TopoDS_Shape& shape,
const Standard_Boolean oriented)
void BRepTools_ReShape::Remove (const TopoDS_Shape& shape)
{
TopoDS_Shape nulshape;
Replace (shape,nulshape,oriented);
Replace (shape,nulshape);
}
//=======================================================================
//function : Replace
//function : replace
//purpose :
//=======================================================================
void BRepTools_ReShape::Replace (const TopoDS_Shape& ashape,
const TopoDS_Shape& anewshape,
const Standard_Boolean oriented)
void BRepTools_ReShape::replace (const TopoDS_Shape& ashape,
const TopoDS_Shape& anewshape)
{
TopoDS_Shape shape = ashape;
TopoDS_Shape newshape = anewshape;
if ( shape.IsNull() || shape == newshape ) return;
if (shape.Orientation() == TopAbs_REVERSED)
{
shape.Reverse();
newshape.Reverse();
}
// protect against INTERNAL or EXTERNAL shape
else if (shape.Orientation() == TopAbs_INTERNAL
|| shape.Orientation() == TopAbs_EXTERNAL)
{
newshape.Orientation((newshape.Orientation() == shape.Orientation()) ?
TopAbs_FORWARD : TopAbs_REVERSED);
shape.Orientation(TopAbs_FORWARD);
}
if (myConsiderLocation) {
//sln 29.11.01 Bug22: Change location of 'newshape' in accordance with location of 'shape'
newshape.Location(newshape.Location().Multiplied(shape.Location().Inverted()));
@ -145,32 +156,8 @@ void BRepTools_ReShape::Replace (const TopoDS_Shape& ashape,
cout << "Warning: BRepTools_ReShape::Replace: shape already recorded" << endl;
#endif
if (oriented) {
if( shape.Orientation()==TopAbs_REVERSED ) {
if( myConsiderOrientation )
myRMap.Bind (shape,newshape);
else {
myNMap.Bind (shape.Reversed(),newshape.Reversed());
}
}
else
myNMap.Bind (shape,newshape);
myNMap.Bind (shape, newshape);
myNewShapes.Add (newshape);
}
else {
// protect against INTERNAL or EXTERNAL shape
if ( shape.Orientation() == TopAbs_INTERNAL ||
shape.Orientation() == TopAbs_EXTERNAL ) {
Replace ( shape.Oriented ( TopAbs_FORWARD ),
newshape.Oriented ( newshape.Orientation() == shape.Orientation() ?
TopAbs_FORWARD : TopAbs_REVERSED ), oriented );
return;
}
Replace (shape,newshape,Standard_True);
if(myConsiderOrientation)
Replace (shape.Reversed(),newshape.Reversed(),Standard_True);
}
}
@ -187,9 +174,6 @@ Standard_Boolean BRepTools_ReShape::IsRecorded (const TopoDS_Shape& ashape) cons
shape.Location ( nullLoc );
}
if (shape.IsNull()) return Standard_False;
if ( myConsiderOrientation && shape.Orientation()==TopAbs_REVERSED )
return myRMap.IsBound (shape);
else
return myNMap.IsBound (shape);
}
@ -211,21 +195,12 @@ TopoDS_Shape BRepTools_ReShape::Value (const TopoDS_Shape& ashape) const
Standard_Boolean fromMap = Standard_False;
if ( shape.Orientation()==TopAbs_REVERSED ) {
if( myConsiderOrientation ) {
if (!myRMap.IsBound (shape)) res = shape;
else {
res = myRMap.Find (shape);
fromMap = Standard_True;
}
}
else {
if (!myNMap.IsBound (shape)) res = shape;
else {
res = myNMap.Find (shape).Reversed();
fromMap = Standard_True;
}
}
}
else {
if (!myNMap.IsBound (shape)) res = shape;
else {
@ -268,14 +243,8 @@ Standard_Integer BRepTools_ReShape::Status(const TopoDS_Shape& ashape,
shape.Location ( nullLoc );
}
if ( myConsiderOrientation && shape.Orientation()==TopAbs_REVERSED ) {
if (!myRMap.IsBound (shape)) { newsh = shape; res = 0; }
else { newsh = myRMap.Find (shape); res = 1; }
}
else {
if (!myNMap.IsBound (shape)) { newsh = shape; res = 0; }
else { newsh = myNMap.Find (shape); res = 1; }
}
if (res > 0) {
if (newsh.IsNull()) res = -1;
else if (newsh.IsEqual (shape)) res = 0;
@ -301,114 +270,6 @@ Standard_Integer BRepTools_ReShape::Status(const TopoDS_Shape& ashape,
return res;
}
//=======================================================================
//function : Apply
//purpose :
//=======================================================================
TopoDS_Shape BRepTools_ReShape::Apply (const TopoDS_Shape& shape,
const TopAbs_ShapeEnum until,
const Standard_Integer buildmode)
{
if (shape.IsNull()) return shape;
TopoDS_Shape newsh;
if (Status (shape,newsh,Standard_False) != 0) return newsh;
TopAbs_ShapeEnum st = shape.ShapeType();
if (st == until) return newsh; // critere d arret
Standard_Integer modif = 0;
if (st == TopAbs_COMPOUND || st == TopAbs_COMPSOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
Standard_Integer stat = Status (sh,newsh,Standard_False);
if (stat != 0) modif = 1;
if (stat >= 0) B.Add (C,newsh);
}
if (modif == 0) return shape;
return C;
}
if (st == TopAbs_SOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Solid S;
B.MakeSolid (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_SHELL) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exh(newsh,TopAbs_SHELL); exh.More(); exh.Next()) {
TopoDS_Shape onesh = exh.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else
return S;
}
if (st == TopAbs_SHELL) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Shell S;
B.MakeShell (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_FACE) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exf(newsh,TopAbs_FACE); exf.More(); exf.Next()) {
TopoDS_Shape onesh = exf.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else
{
S.Closed (BRep_Tool::IsClosed (S));
return S;
}
}
cout<<"BRepTools_ReShape::Apply NOT YET IMPLEMENTED"<<endl;
return shape;
}
//=======================================================================
//function : EncodeStatus
//purpose : static
@ -569,28 +430,6 @@ TopoDS_Shape BRepTools_ReShape::Apply (const TopoDS_Shape& shape,
return ShapeExtend::DecodeStatus ( myStatus, status );
}*/
//=======================================================================
//function : ModeConsiderLocation
//purpose :
//=======================================================================
Standard_Boolean& BRepTools_ReShape::ModeConsiderLocation()
{
return myConsiderLocation;
}
//=======================================================================
//function : ModeConsiderOrientation
//purpose :
//=======================================================================
Standard_Boolean& BRepTools_ReShape::ModeConsiderOrientation()
{
return myConsiderOrientation;
}
//=======================================================================
//function : CopyVertex
//purpose :

View File

@ -57,17 +57,14 @@ public:
//! Clears all substitutions requests
Standard_EXPORT virtual void Clear();
//! Sets a request to Remove a Shape
//! If <oriented> is True, only for a shape with the SAME
//! orientation. Else, whatever the orientation
Standard_EXPORT virtual void Remove (const TopoDS_Shape& shape, const Standard_Boolean oriented = Standard_False);
//! Sets a request to Remove a Shape whatever the orientation
Standard_EXPORT virtual void Remove (const TopoDS_Shape& shape);
//! Sets a request to Replace a Shape by a new one
//! If <oriented> is True, only if the orientation is the same
//! Else, whatever the orientation, and the new shape takes the
//! same orientation as <newshape> if the replaced one has the
//! same as <shape>, else it is reversed
Standard_EXPORT virtual void Replace (const TopoDS_Shape& shape, const TopoDS_Shape& newshape, const Standard_Boolean oriented = Standard_False);
//! Sets a request to Replace a Shape by a new one.
virtual void Replace (const TopoDS_Shape& shape, const TopoDS_Shape& newshape)
{
replace (shape, newshape);
}
//! Tells if a shape is recorded for Replace/Remove
Standard_EXPORT virtual Standard_Boolean IsRecorded (const TopoDS_Shape& shape) const;
@ -87,22 +84,6 @@ public:
//! recursively searches for the last status and new shape.
Standard_EXPORT virtual Standard_Integer Status (const TopoDS_Shape& shape, TopoDS_Shape& newsh, const Standard_Boolean last = Standard_False);
//! Applies the substitutions requests to a shape
//!
//! <until> gives the level of type until which requests are taken
//! into account. For subshapes of the type <until> no rebuild
//! and futher exploring are done.
//! ACTUALLY, NOT IMPLEMENTED BELOW TopAbs_FACE
//!
//! <buildmode> says how to do on a SOLID,SHELL ... if one of its
//! sub-shapes has been changed:
//! 0: at least one Replace or Remove -> COMPOUND, else as such
//! 1: at least one Remove (Replace are ignored) -> COMPOUND
//! 2: Replace and Remove are both ignored
//! If Replace/Remove are ignored or absent, the result as same
//! type as the starting shape
Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& shape, const TopAbs_ShapeEnum until, const Standard_Integer buildmode);
//! Applies the substitutions requests to a shape.
//!
//! <until> gives the level of type until which requests are taken
@ -119,11 +100,10 @@ public:
//! Returns (modifiable) the flag which defines whether Location of shape take into account
//! during replacing shapes.
Standard_EXPORT virtual Standard_Boolean& ModeConsiderLocation();
//! Returns (modifiable) the flag which defines whether Orientation of shape take into account
//! during replacing shapes.
Standard_EXPORT virtual Standard_Boolean& ModeConsiderOrientation();
virtual Standard_Boolean& ModeConsiderLocation()
{
return myConsiderLocation;
}
//! Returns modified copy of vertex if original one is not recorded or returns modified original vertex otherwise.
//@param theV - original vertex.
@ -143,14 +123,24 @@ public:
//@param theShape is the given shape
Standard_EXPORT Standard_Boolean IsNewShape(const TopoDS_Shape& theShape) const;
DEFINE_STANDARD_RTTIEXT(BRepTools_ReShape,MMgt_TShared)
private:
//! Replaces the first shape by the second one
//! after the following reorientation.
//!
//! If the first shape has the reversed orientation
//! then the both shapes are reversed.
//! If the first shape has the internal or external orientation then: <br>
//! - the second shape is oriented forward (reversed) if it's orientation
//! is equal (not equal) to the orientation of the first shape; <br>
//! - the first shape is oriented forward.
Standard_EXPORT virtual void replace (const TopoDS_Shape& shape, const TopoDS_Shape& newshape);
protected:
TopTools_DataMapOfShapeShape myNMap;
TopTools_DataMapOfShapeShape myRMap;
TopTools_MapOfShape myNewShapes;
Standard_Integer myStatus;
@ -159,7 +149,6 @@ private:
Standard_Boolean myConsiderLocation;
Standard_Boolean myConsiderOrientation;
};

View File

@ -46,7 +46,101 @@ TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape,
const TopAbs_ShapeEnum until,
const Standard_Integer buildmode)
{
return BRepTools_ReShape::Apply (shape,until,buildmode);
if (shape.IsNull()) return shape;
TopoDS_Shape newsh;
if (Status (shape,newsh,Standard_False) != 0) return newsh;
TopAbs_ShapeEnum st = shape.ShapeType();
if (st == until) return newsh; // critere d arret
Standard_Integer modif = 0;
if (st == TopAbs_COMPOUND || st == TopAbs_COMPSOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
Standard_Integer stat = Status (sh,newsh,Standard_False);
if (stat != 0) modif = 1;
if (stat >= 0) B.Add (C,newsh);
}
if (modif == 0) return shape;
return C;
}
if (st == TopAbs_SOLID) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Solid S;
B.MakeSolid (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_SHELL) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exh(newsh,TopAbs_SHELL); exh.More(); exh.Next()) {
TopoDS_Shape onesh = exh.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else
return S;
}
if (st == TopAbs_SHELL) {
BRep_Builder B;
TopoDS_Compound C;
B.MakeCompound (C);
TopoDS_Shell S;
B.MakeShell (S);
for (TopoDS_Iterator it (shape); it.More(); it.Next()) {
TopoDS_Shape sh = it.Value();
newsh = Apply (sh,until,buildmode);
if (newsh.IsNull()) {
modif = -1;
}
else if (newsh.ShapeType() != TopAbs_FACE) {
Standard_Integer nbsub = 0;
for (TopExp_Explorer exf(newsh,TopAbs_FACE); exf.More(); exf.Next()) {
TopoDS_Shape onesh = exf.Current ();
B.Add (S,onesh);
nbsub ++;
}
if (nbsub == 0) modif = -1;
B.Add (C,newsh); // c est tout
}
else {
if (modif == 0 && !sh.IsEqual(newsh)) modif = 1;
B.Add (C,newsh);
B.Add (S,newsh);
}
}
if ( (modif < 0 && buildmode < 2) || (modif == 0 && buildmode < 1) )
return C;
else
{
S.Closed (BRep_Tool::IsClosed (S));
return S;
}
}
cout<<"BRepTools_ReShape::Apply NOT YET IMPLEMENTED"<<endl;
return shape;
}
//=======================================================================

View File

@ -66,7 +66,7 @@ public:
//! 2: Replace and Remove are both ignored
//! If Replace/Remove are ignored or absent, the result as same
//! type as the starting shape
Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& shape, const TopAbs_ShapeEnum until, const Standard_Integer buildmode) Standard_OVERRIDE;
Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& shape, const TopAbs_ShapeEnum until, const Standard_Integer buildmode);
//! Applies the substitutions requests to a shape.
//!