36
36
37
37
#include < Message_ProgressScope.hxx>
38
38
39
+ namespace
40
+ {
41
+ // =======================================================================
42
+ // function : UpdateHistoryShape
43
+ // purpose : Updates ShapeBuild_ReShape by the info of the given shape
44
+ // =======================================================================
45
+ bool UpdateHistoryShape (const TopoDS_Shape& theShape,
46
+ const BRepTools_Modifier& theModifier,
47
+ const Handle (ShapeBuild_ReShape)& theReShape)
48
+ {
49
+ TopoDS_Shape aResult;
50
+ try
51
+ {
52
+ OCC_CATCH_SIGNALS
53
+ aResult = theModifier.ModifiedShape (theShape);
54
+ }
55
+ catch (Standard_NoSuchObject const &)
56
+ {
57
+ // the sub shape isn't in the map
58
+ aResult.Nullify ();
59
+ }
60
+
61
+ if (!aResult.IsNull () && !theShape.IsSame (aResult))
62
+ {
63
+ theReShape->Replace (theShape, aResult);
64
+ return true ;
65
+ }
66
+
67
+ return false ;
68
+ }
69
+
70
+ // =======================================================================
71
+ // function : UpdateHistory
72
+ // purpose : Recursively updates ShapeBuild_ReShape to add information of all sub-shapes
73
+ // =======================================================================
74
+ void UpdateHistory (const TopoDS_Shape& theShape,
75
+ const BRepTools_Modifier& theModifier,
76
+ const Handle (ShapeBuild_ReShape)& theReShape)
77
+ {
78
+ for (TopoDS_Iterator theIterator (theShape, Standard_False); theIterator.More (); theIterator.Next ())
79
+ {
80
+ const TopoDS_Shape& aCurrent = theIterator.Value ();
81
+ if (UpdateHistoryShape (aCurrent, theModifier, theReShape))
82
+ {
83
+ UpdateHistory (aCurrent, theModifier, theReShape);
84
+ }
85
+ }
86
+ }
87
+
88
+ // =======================================================================
89
+ // function : UpdateShapeBuild
90
+ // purpose : Recursively updates ShapeBuild_ReShape to add information of all sub-shapes
91
+ // =======================================================================
92
+ void UpdateShapeBuild (const TopoDS_Shape& theShape,
93
+ const BRepTools_Modifier& theModifier,
94
+ const Handle (ShapeBuild_ReShape)& theReShape)
95
+ {
96
+ UpdateHistoryShape (theShape, theModifier, theReShape);
97
+ UpdateHistory (theShape, theModifier, theReShape);
98
+ }
99
+ }
100
+
39
101
// =======================================================================
40
102
// function : ApplyModifier
41
103
// purpose : static
@@ -58,25 +120,35 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
58
120
BRep_Builder B;
59
121
B.MakeCompound ( C );
60
122
123
+ SF.Location (TopLoc_Location ());
61
124
Standard_Integer aShapeCount = SF.NbChildren ();
62
125
Message_ProgressScope aPS (theProgress, " Applying Modifier For Solids" , aShapeCount);
63
- for ( TopoDS_Iterator it (SF); it.More () && aPS.More (); it.Next ()) {
64
- TopoDS_Shape shape = it.Value ();
65
- TopLoc_Location L = shape.Location (), nullLoc;
66
- shape.Location ( nullLoc );
67
- TopoDS_Shape res;
126
+ for (TopoDS_Iterator it (SF); it.More () && aPS.More (); it.Next ())
127
+ {
68
128
Message_ProgressRange aRange = aPS.Next ();
69
- if ( context.IsBound ( shape ) )
70
- res = context.Find ( shape ).Oriented ( shape.Orientation () );
129
+
130
+ TopoDS_Shape shape = it.Value ();
131
+ TopoDS_Shape aShapeNoLoc = it.Value ();
132
+ aShapeNoLoc.Location (TopLoc_Location ());
133
+
134
+ TopoDS_Shape res;
135
+ if (context.Find (aShapeNoLoc, res))
136
+ {
137
+ res.Orientation (shape.Orientation ());
138
+ res.Location (shape.Location (), Standard_False);
139
+ }
71
140
else
72
- res = ApplyModifier ( shape, M, context ,MD, aRange);
141
+ {
142
+ res = ApplyModifier (shape, M, context, MD, aRange, aReShape);
143
+ }
73
144
74
- if ( ! res.IsSame ( shape ) ) {
75
- context.Bind ( shape, res );
145
+ if ( !res.IsSame (shape) )
146
+ {
147
+ context.Bind (aShapeNoLoc, res.Located (TopLoc_Location ()));
76
148
locModified = Standard_True;
77
149
}
78
- res. Location ( L, Standard_False );
79
- B.Add ( C, res );
150
+
151
+ B.Add (C, res);
80
152
}
81
153
82
154
if ( !aPS.More () )
@@ -85,9 +157,16 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
85
157
return S;
86
158
}
87
159
88
- if ( ! locModified ) return S;
160
+ if ( !locModified )
161
+ {
162
+ return S;
163
+ }
164
+
89
165
context.Bind ( SF, C );
90
- return C.Oriented ( S.Orientation () );
166
+
167
+ C.Orientation (S.Orientation ());
168
+ C.Location (S.Location (), Standard_False);
169
+ return C;
91
170
}
92
171
93
172
Message_ProgressScope aPS (theProgress, " Modify the Shape" , 1 );
@@ -98,26 +177,7 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
98
177
if ( !aPS.More () || !MD.IsDone () ) return S;
99
178
if ( !aReShape.IsNull () )
100
179
{
101
- for (TopoDS_Iterator theIterator (SF,Standard_False);theIterator.More ();theIterator.Next ())
102
- {
103
- const TopoDS_Shape & current = theIterator.Value ();
104
- TopoDS_Shape result;
105
- try
106
- {
107
- OCC_CATCH_SIGNALS
108
- result = MD.ModifiedShape ( current );
109
- }
110
- catch (Standard_NoSuchObject const &)
111
- {
112
- // the sub shape isn't in the map
113
- result.Nullify ();
114
- }
115
-
116
- if (!result.IsNull () && !current.IsSame (result))
117
- {
118
- aReShape->Replace (current, result);
119
- }
120
- }
180
+ UpdateShapeBuild ( SF, MD, aReShape );
121
181
}
122
182
123
183
return MD.ModifiedShape (SF).Oriented (S.Orientation ());
0 commit comments