1 // abv 28.04.99 S4137: ading method Apply for work on all types of shapes
3 #include <ShapeBuild_ReShape.ixx>
5 #include <TopoDS_Shell.hxx>
6 #include <TopoDS_Solid.hxx>
7 #include <TopoDS_Compound.hxx>
8 #include <TopoDS_Iterator.hxx>
9 #include <TopExp_Explorer.hxx>
10 #include <BRep_Builder.hxx>
11 #include <ShapeExtend.hxx>
12 #include <ShapeBuild_Edge.hxx>
15 //=======================================================================
16 //function : ShapeBuild_ReShape
18 //=======================================================================
20 ShapeBuild_ReShape::ShapeBuild_ReShape()
24 //=======================================================================
27 //=======================================================================
29 TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape,
30 const TopAbs_ShapeEnum until,
31 const Standard_Integer buildmode)
33 return BRepTools_ReShape::Apply (shape,until,buildmode);
36 //=======================================================================
39 //=======================================================================
41 TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape,
42 const TopAbs_ShapeEnum until)
44 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
45 if ( shape.IsNull() ) return shape;
47 // apply direct replacement
48 TopoDS_Shape newsh = Value ( shape );
50 // if shape removed, return NULL
51 if ( newsh.IsNull() ) {
52 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
56 // if shape replaced, apply modifications to the result recursively
57 Standard_Boolean aConsLoc = ModeConsiderLocation();
58 if ( (aConsLoc && ! newsh.IsPartner (shape)) ||
59 (!aConsLoc &&! newsh.IsSame ( shape )) ) {
61 TopoDS_Shape res = Apply ( newsh, until );
62 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
66 TopAbs_ShapeEnum st = shape.ShapeType();
67 if ( st >= until ) return newsh; // critere d arret
68 if(st == TopAbs_VERTEX || st == TopAbs_SHAPE)
70 // define allowed types of components
74 TopoDS_Shape result = shape.EmptyCopied();
75 TopAbs_Orientation orient = shape.Orientation(); //JR/Hp: or -> orient
76 result.Orientation(TopAbs_FORWARD); // protect against INTERNAL or EXTERNAL shapes
77 Standard_Boolean modif = Standard_False;
78 Standard_Integer locStatus = myStatus;
80 // apply recorded modifications to subshapes
81 for ( TopoDS_Iterator it(shape,Standard_False); it.More(); it.Next() ) {
82 TopoDS_Shape sh = it.Value();
83 newsh = Apply ( sh, until );
85 if ( ShapeExtend::DecodeStatus ( myStatus, ShapeExtend_DONE4 ) )
86 locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
89 if ( newsh.IsNull() ) {
90 locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
93 locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
94 if ( st == TopAbs_COMPOUND || newsh.ShapeType() == sh.ShapeType()) { //fix for SAMTECH bug OCC322 about abcense internal vertices after sewing.
95 B.Add ( result, newsh );
98 Standard_Integer nitems = 0;
99 for ( TopoDS_Iterator subit(newsh); subit.More(); subit.Next(), nitems++ ) {
100 TopoDS_Shape subsh = subit.Value();
101 if ( subsh.ShapeType() == sh.ShapeType() ) B.Add ( result, subsh );
102 else locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
104 if ( ! nitems ) locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 );
106 if ( ! modif ) return shape;
108 // restore Range on edge broken by EmptyCopied()
109 if ( st == TopAbs_EDGE ) {
111 sbe.CopyRanges ( TopoDS::Edge ( result ), TopoDS::Edge ( shape ));
113 result.Orientation(orient);
114 myStatus = locStatus;
115 Replace ( shape, result );
119 //=======================================================================
122 //=======================================================================
124 Standard_Integer ShapeBuild_ReShape::Status(const TopoDS_Shape& ashape,
126 const Standard_Boolean last)
128 return BRepTools_ReShape::Status(ashape,newsh,last);
131 //=======================================================================
134 //=======================================================================
136 Standard_Boolean ShapeBuild_ReShape::Status (const ShapeExtend_Status status) const
138 return ShapeExtend::DecodeStatus ( myStatus, status );