Skip to content

Commit

Permalink
0033791: Shape Healing - ShapeCustom not take location of source shap…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
oan authored and dpasukhi committed Aug 9, 2024
1 parent 677f383 commit 2736652
Showing 1 changed file with 94 additions and 34 deletions.
128 changes: 94 additions & 34 deletions src/ShapeCustom/ShapeCustom.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,68 @@

#include <Message_ProgressScope.hxx>

namespace
{
//=======================================================================
//function : UpdateHistoryShape
//purpose : Updates ShapeBuild_ReShape by the info of the given shape
//=======================================================================
bool UpdateHistoryShape (const TopoDS_Shape& theShape,
const BRepTools_Modifier& theModifier,
const Handle(ShapeBuild_ReShape)& theReShape)
{
TopoDS_Shape aResult;
try
{
OCC_CATCH_SIGNALS
aResult = theModifier.ModifiedShape (theShape);
}
catch (Standard_NoSuchObject const&)
{
// the sub shape isn't in the map
aResult.Nullify();
}

if (!aResult.IsNull() && !theShape.IsSame (aResult))
{
theReShape->Replace (theShape, aResult);
return true;
}

return false;
}

//=======================================================================
//function : UpdateHistory
//purpose : Recursively updates ShapeBuild_ReShape to add information of all sub-shapes
//=======================================================================
void UpdateHistory (const TopoDS_Shape& theShape,
const BRepTools_Modifier& theModifier,
const Handle(ShapeBuild_ReShape)& theReShape)
{
for (TopoDS_Iterator theIterator (theShape, Standard_False); theIterator.More(); theIterator.Next())
{
const TopoDS_Shape& aCurrent = theIterator.Value();
if (UpdateHistoryShape (aCurrent, theModifier, theReShape))
{
UpdateHistory (aCurrent, theModifier, theReShape);
}
}
}

//=======================================================================
//function : UpdateShapeBuild
//purpose : Recursively updates ShapeBuild_ReShape to add information of all sub-shapes
//=======================================================================
void UpdateShapeBuild (const TopoDS_Shape& theShape,
const BRepTools_Modifier& theModifier,
const Handle(ShapeBuild_ReShape)& theReShape)
{
UpdateHistoryShape (theShape, theModifier, theReShape);
UpdateHistory (theShape, theModifier, theReShape);
}
}

//=======================================================================
//function : ApplyModifier
//purpose : static
Expand All @@ -58,25 +120,35 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
BRep_Builder B;
B.MakeCompound ( C );

SF.Location (TopLoc_Location());
Standard_Integer aShapeCount = SF.NbChildren();
Message_ProgressScope aPS(theProgress, "Applying Modifier For Solids", aShapeCount);
for ( TopoDS_Iterator it(SF); it.More() && aPS.More(); it.Next()) {
TopoDS_Shape shape = it.Value();
TopLoc_Location L = shape.Location(), nullLoc;
shape.Location ( nullLoc );
TopoDS_Shape res;
for (TopoDS_Iterator it(SF); it.More() && aPS.More(); it.Next())
{
Message_ProgressRange aRange = aPS.Next();
if ( context.IsBound ( shape ) )
res = context.Find ( shape ).Oriented ( shape.Orientation() );

TopoDS_Shape shape = it.Value();
TopoDS_Shape aShapeNoLoc = it.Value();
aShapeNoLoc.Location (TopLoc_Location());

TopoDS_Shape res;
if (context.Find (aShapeNoLoc, res))
{
res.Orientation (shape.Orientation());
res.Location (shape.Location(), Standard_False);
}
else
res = ApplyModifier ( shape, M, context ,MD, aRange);
{
res = ApplyModifier (shape, M, context, MD, aRange, aReShape);
}

if ( ! res.IsSame ( shape ) ) {
context.Bind ( shape, res );
if ( !res.IsSame (shape) )
{
context.Bind (aShapeNoLoc, res.Located (TopLoc_Location()));
locModified = Standard_True;
}
res.Location ( L, Standard_False );
B.Add ( C, res );

B.Add (C, res);
}

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

if ( ! locModified ) return S;
if ( !locModified )
{
return S;
}

context.Bind ( SF, C );
return C.Oriented ( S.Orientation() );

C.Orientation (S.Orientation());
C.Location (S.Location(), Standard_False);
return C;
}

Message_ProgressScope aPS(theProgress, "Modify the Shape", 1);
Expand All @@ -98,26 +177,7 @@ TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
if ( !aPS.More() || !MD.IsDone() ) return S;
if ( !aReShape.IsNull() )
{
for(TopoDS_Iterator theIterator(SF,Standard_False);theIterator.More();theIterator.Next())
{
const TopoDS_Shape & current = theIterator.Value();
TopoDS_Shape result;
try
{
OCC_CATCH_SIGNALS
result = MD.ModifiedShape( current );
}
catch (Standard_NoSuchObject const&)
{
// the sub shape isn't in the map
result.Nullify();
}

if (!result.IsNull() && !current.IsSame(result))
{
aReShape->Replace(current, result);
}
}
UpdateShapeBuild ( SF, MD, aReShape );
}

return MD.ModifiedShape(SF).Oriented(S.Orientation());
Expand Down

0 comments on commit 2736652

Please sign in to comment.