Skip to content

Commit 2736652

Browse files
oandpasukhi
oan
authored andcommitted
0033791: Shape Healing - ShapeCustom not take location of source shape for the cached context and misses root one
Pass ShapeBuild_ReShape to recursive call to retrieve complete change history. Update history of changes by the source shape (if changed), not only by its subshapes. Check the context for a cached shape using a reference shape without location.
1 parent 677f383 commit 2736652

File tree

1 file changed

+94
-34
lines changed

1 file changed

+94
-34
lines changed

src/ShapeCustom/ShapeCustom.cxx

+94-34
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,68 @@
3636

3737
#include <Message_ProgressScope.hxx>
3838

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+
39101
//=======================================================================
40102
//function : ApplyModifier
41103
//purpose : static
@@ -58,25 +120,35 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
58120
BRep_Builder B;
59121
B.MakeCompound ( C );
60122

123+
SF.Location (TopLoc_Location());
61124
Standard_Integer aShapeCount = SF.NbChildren();
62125
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+
{
68128
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+
}
71140
else
72-
res = ApplyModifier ( shape, M, context ,MD, aRange);
141+
{
142+
res = ApplyModifier (shape, M, context, MD, aRange, aReShape);
143+
}
73144

74-
if ( ! res.IsSame ( shape ) ) {
75-
context.Bind ( shape, res );
145+
if ( !res.IsSame (shape) )
146+
{
147+
context.Bind (aShapeNoLoc, res.Located (TopLoc_Location()));
76148
locModified = Standard_True;
77149
}
78-
res.Location ( L, Standard_False );
79-
B.Add ( C, res );
150+
151+
B.Add (C, res);
80152
}
81153

82154
if ( !aPS.More() )
@@ -85,9 +157,16 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
85157
return S;
86158
}
87159

88-
if ( ! locModified ) return S;
160+
if ( !locModified )
161+
{
162+
return S;
163+
}
164+
89165
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;
91170
}
92171

93172
Message_ProgressScope aPS(theProgress, "Modify the Shape", 1);
@@ -98,26 +177,7 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
98177
if ( !aPS.More() || !MD.IsDone() ) return S;
99178
if ( !aReShape.IsNull() )
100179
{
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 );
121181
}
122182

123183
return MD.ModifiedShape(SF).Oriented(S.Orientation());

0 commit comments

Comments
 (0)