BRepTools_ReShape::BRepTools_ReShape()
{
myConsiderLocation = Standard_False;
- myConsiderOrientation = Standard_False;
}
void BRepTools_ReShape::Clear()
{
myNMap.Clear();
- myRMap.Clear();
myNewShapes.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()));
(!myConsiderLocation && ! Value ( shape ).IsSame ( newshape ))))
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);
- 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);
- }
+
+ myNMap.Bind (shape, newshape);
+ myNewShapes.Add (newshape);
}
shape.Location ( nullLoc );
}
if (shape.IsNull()) return Standard_False;
- if ( myConsiderOrientation && shape.Orientation()==TopAbs_REVERSED )
- return myRMap.IsBound (shape);
- else
- return myNMap.IsBound (shape);
+ return myNMap.IsBound (shape);
}
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;
- }
+ if (!myNMap.IsBound (shape)) res = shape;
+ else {
+ res = myNMap.Find (shape).Reversed();
+ fromMap = Standard_True;
}
}
else {
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 (!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;
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
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 :
//! 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;
//! the map directly for the shape, if True and status > 0 then
//! 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
//! If incompatible shape type is encountered, it is ignored
//! and flag FAIL1 is set in Status.
Standard_EXPORT virtual TopoDS_Shape Apply (const TopoDS_Shape& shape, const TopAbs_ShapeEnum until = TopAbs_SHAPE);
-
+
//! 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.
//@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;
Standard_Boolean myConsiderLocation;
- Standard_Boolean myConsiderOrientation;
};
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;
}
//=======================================================================