973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | // abv 28.04.99 S4137: ading method Apply for work on all types of shapes |
15 | |
16 | #include <ShapeBuild_ReShape.ixx> |
17 | |
18 | #include <TopoDS_Shell.hxx> |
19 | #include <TopoDS_Solid.hxx> |
20 | #include <TopoDS_Compound.hxx> |
21 | #include <TopoDS_Iterator.hxx> |
22 | #include <TopExp_Explorer.hxx> |
23 | #include <BRep_Builder.hxx> |
24 | #include <ShapeExtend.hxx> |
25 | #include <ShapeBuild_Edge.hxx> |
26 | #include <TopoDS.hxx> |
27 | |
28 | //======================================================================= |
29 | //function : ShapeBuild_ReShape |
30 | //purpose : |
31 | //======================================================================= |
32 | |
33 | ShapeBuild_ReShape::ShapeBuild_ReShape() |
34 | { |
35 | } |
36 | |
37 | //======================================================================= |
38 | //function : Apply |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape, |
43 | const TopAbs_ShapeEnum until, |
44 | const Standard_Integer buildmode) |
45 | { |
46 | return BRepTools_ReShape::Apply (shape,until,buildmode); |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : Apply |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | TopoDS_Shape ShapeBuild_ReShape::Apply (const TopoDS_Shape& shape, |
55 | const TopAbs_ShapeEnum until) |
56 | { |
57 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); |
58 | if ( shape.IsNull() ) return shape; |
59 | |
60 | // apply direct replacement |
61 | TopoDS_Shape newsh = Value ( shape ); |
62 | |
63 | // if shape removed, return NULL |
64 | if ( newsh.IsNull() ) { |
65 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 ); |
66 | return newsh; |
67 | } |
68 | |
69 | // if shape replaced, apply modifications to the result recursively |
70 | Standard_Boolean aConsLoc = ModeConsiderLocation(); |
71 | if ( (aConsLoc && ! newsh.IsPartner (shape)) || |
72 | (!aConsLoc &&! newsh.IsSame ( shape )) ) { |
73 | |
74 | TopoDS_Shape res = Apply ( newsh, until ); |
75 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); |
76 | return res; |
77 | } |
78 | |
6e6cd5d9 |
79 | TopAbs_ShapeEnum st = shape.ShapeType(); |
7fd59977 |
80 | if ( st >= until ) return newsh; // critere d arret |
81 | if(st == TopAbs_VERTEX || st == TopAbs_SHAPE) |
82 | return shape; |
83 | // define allowed types of components |
84 | |
85 | BRep_Builder B; |
86 | |
87 | TopoDS_Shape result = shape.EmptyCopied(); |
88 | TopAbs_Orientation orient = shape.Orientation(); //JR/Hp: or -> orient |
89 | result.Orientation(TopAbs_FORWARD); // protect against INTERNAL or EXTERNAL shapes |
90 | Standard_Boolean modif = Standard_False; |
91 | Standard_Integer locStatus = myStatus; |
92 | |
93 | // apply recorded modifications to subshapes |
94 | for ( TopoDS_Iterator it(shape,Standard_False); it.More(); it.Next() ) { |
95 | TopoDS_Shape sh = it.Value(); |
96 | newsh = Apply ( sh, until ); |
97 | if ( newsh != sh ) { |
98 | if ( ShapeExtend::DecodeStatus ( myStatus, ShapeExtend_DONE4 ) ) |
99 | locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 ); |
100 | modif = 1; |
101 | } |
102 | if ( newsh.IsNull() ) { |
103 | locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 ); |
104 | continue; |
105 | } |
106 | locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 ); |
107 | if ( st == TopAbs_COMPOUND || newsh.ShapeType() == sh.ShapeType()) { //fix for SAMTECH bug OCC322 about abcense internal vertices after sewing. |
108 | B.Add ( result, newsh ); |
109 | continue; |
110 | } |
111 | Standard_Integer nitems = 0; |
112 | for ( TopoDS_Iterator subit(newsh); subit.More(); subit.Next(), nitems++ ) { |
113 | TopoDS_Shape subsh = subit.Value(); |
114 | if ( subsh.ShapeType() == sh.ShapeType() ) B.Add ( result, subsh ); |
115 | else locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); |
116 | } |
117 | if ( ! nitems ) locStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); |
118 | } |
119 | if ( ! modif ) return shape; |
120 | |
121 | // restore Range on edge broken by EmptyCopied() |
122 | if ( st == TopAbs_EDGE ) { |
123 | ShapeBuild_Edge sbe; |
124 | sbe.CopyRanges ( TopoDS::Edge ( result ), TopoDS::Edge ( shape )); |
125 | } |
126 | result.Orientation(orient); |
127 | myStatus = locStatus; |
128 | Replace ( shape, result ); |
129 | return result; |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : Status |
134 | //purpose : |
135 | //======================================================================= |
136 | |
137 | Standard_Integer ShapeBuild_ReShape::Status(const TopoDS_Shape& ashape, |
138 | TopoDS_Shape& newsh, |
139 | const Standard_Boolean last) |
140 | { |
141 | return BRepTools_ReShape::Status(ashape,newsh,last); |
142 | } |
143 | |
144 | //======================================================================= |
145 | //function : Status |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | Standard_Boolean ShapeBuild_ReShape::Status (const ShapeExtend_Status status) const |
150 | { |
151 | return ShapeExtend::DecodeStatus ( myStatus, status ); |
152 | } |