mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-08-31 23:37:52 +08:00
Modeling Data - Rework BRepGraph storage and layers (#1305)
- Introduce item-level identifiers/remapping and move graph metadata to registered layers for history, locks, deferred state, parametric data, and supplemental topology. - Replace the old reverse-index/cache/history helpers with storage-owned relations, version stamps, cache registry services, and copy/compact remapping paths. - Preserve layer data, product occurrence refs, persistent mesh handles, deleted history, lock propagation, and topology supplement attachments across copy, compact, transform, reconstruct, and mutation flows. - Update BRepGraph populate/reconstruct/editor traversal and add/refresh GTests for layers, cache services, copy, transform, compact, sparse models, IDs, and storage behavior.
This commit is contained in:
@@ -13,11 +13,15 @@
|
||||
|
||||
#include <BRepGraph.hxx>
|
||||
#include <BRepGraph_EditorView.hxx>
|
||||
#include <BRepGraph_ItemId.hxx>
|
||||
#include <BRepGraph_ItemUID.hxx>
|
||||
#include <BRepGraph_TopoView.hxx>
|
||||
#include <BRepGraph_UIDsView.hxx>
|
||||
#include <BRepGraph_Tool.hxx>
|
||||
#include <BRepGraph_VersionStamp.hxx>
|
||||
#include <BRepGraph_Builder.hxx>
|
||||
#include <BRepGraph_ShapesView.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <Geom_Surface.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -30,9 +34,8 @@ protected:
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
const TopoDS_Shape& aBox = aBoxMaker.Shape();
|
||||
myGraph.Clear();
|
||||
[[maybe_unused]] const BRepGraph_Builder::Result aBuildRes1 =
|
||||
BRepGraph_Builder::Add(myGraph, aBox);
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes1 = myGraph.Shapes().Add(aBox);
|
||||
ASSERT_FALSE(myGraph.IsEmpty());
|
||||
}
|
||||
|
||||
BRepGraph myGraph;
|
||||
@@ -53,7 +56,7 @@ TEST_F(BRepGraph_VersionStampTest, StampOf_ValidNode_ReturnsValidStamp)
|
||||
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(aFaceId);
|
||||
EXPECT_TRUE(aStamp.IsValid());
|
||||
EXPECT_TRUE(aStamp.myUID.IsValid());
|
||||
EXPECT_TRUE(aStamp.myNodeUID.IsValid());
|
||||
EXPECT_EQ(aStamp.myMutationGen, 0u);
|
||||
EXPECT_EQ(aStamp.myGeneration, myGraph.UIDs().Generation());
|
||||
}
|
||||
@@ -77,7 +80,9 @@ TEST_F(BRepGraph_VersionStampTest, IsStale_MutatedNode_ReturnsTrue)
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
// Mutate the face.
|
||||
myGraph.Editor().Faces().SetNaturalRestriction(BRepGraph_FaceId::Start(), true);
|
||||
myGraph.Editor().Faces().SetTolerance(
|
||||
BRepGraph_FaceId::Start(),
|
||||
BRepGraph_Tool::Face::Tolerance(myGraph, BRepGraph_FaceId::Start()) + 0.01);
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
@@ -98,9 +103,9 @@ TEST_F(BRepGraph_VersionStampTest, IsStale_DifferentGeneration_ReturnsTrue)
|
||||
// Rebuild the graph - generation changes.
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
myGraph.Clear();
|
||||
[[maybe_unused]] const BRepGraph_Builder::Result aBuildRes2 =
|
||||
BRepGraph_Builder::Add(myGraph, aBoxMaker.Shape());
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes2 =
|
||||
myGraph.Shapes().Add(aBoxMaker.Shape());
|
||||
ASSERT_FALSE(myGraph.IsEmpty());
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
@@ -139,25 +144,27 @@ TEST_F(BRepGraph_VersionStampTest, StampIdentity_DifferentNodes_NotEqual)
|
||||
EXPECT_NE(aStamp1, aStamp2);
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameNode_SameVersion_ReturnsTrue)
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameItem_SameVersion_ReturnsTrue)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const BRepGraph_VersionStamp aStamp2 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
EXPECT_TRUE(aStamp1.IsSameNode(aStamp2));
|
||||
EXPECT_TRUE(aStamp1.IsSameItem(aStamp2));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameNode_DifferentVersion_StillSameNode)
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameItem_DifferentVersion_StillSameItem)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStampBefore = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
myGraph.Editor().Faces().SetNaturalRestriction(BRepGraph_FaceId::Start(), true);
|
||||
myGraph.Editor().Faces().SetTolerance(
|
||||
BRepGraph_FaceId::Start(),
|
||||
BRepGraph_Tool::Face::Tolerance(myGraph, BRepGraph_FaceId::Start()) + 0.01);
|
||||
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
// Full equality fails (different MutationGen).
|
||||
EXPECT_NE(aStampBefore, aStampAfter);
|
||||
// But they refer to the same node (same UID).
|
||||
EXPECT_TRUE(aStampBefore.IsSameNode(aStampAfter));
|
||||
// But they refer to the same item identity.
|
||||
EXPECT_TRUE(aStampBefore.IsSameItem(aStampAfter));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, StampOf_AssemblyNodes_WorksForProductsAndOccurrences)
|
||||
@@ -170,6 +177,55 @@ TEST_F(BRepGraph_VersionStampTest, StampOf_AssemblyNodes_WorksForProductsAndOccu
|
||||
EXPECT_FALSE(myGraph.UIDs().IsStale(aProdStamp));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, GenericItemUID_NodeAndReferenceItems_RoundTrip)
|
||||
{
|
||||
const BRepGraph_FaceId aFaceId = BRepGraph_FaceId::Start();
|
||||
const BRepGraph_ItemId aFaceItem(aFaceId);
|
||||
const BRepGraph_ItemUID aFaceUID = myGraph.UIDs().Of(aFaceItem);
|
||||
ASSERT_TRUE(aFaceUID.IsValid());
|
||||
EXPECT_TRUE(aFaceUID.IsNode());
|
||||
EXPECT_EQ(aFaceUID.NodeKind(), BRepGraph_NodeId::Kind::Face);
|
||||
EXPECT_EQ(myGraph.UIDs().ItemIdFrom(aFaceUID), aFaceItem);
|
||||
EXPECT_TRUE(myGraph.UIDs().Has(aFaceUID));
|
||||
|
||||
const BRepGraph_VersionStamp aFaceStamp = myGraph.UIDs().StampOf(aFaceItem);
|
||||
EXPECT_TRUE(aFaceStamp.IsValid());
|
||||
EXPECT_TRUE(aFaceStamp.IsNodeStamp());
|
||||
EXPECT_EQ(aFaceStamp.ItemUID(), aFaceUID);
|
||||
|
||||
const BRepGraph_FaceRefId aFaceRefId = BRepGraph_FaceRefId::Start();
|
||||
const BRepGraph_ItemId aFaceRefItem(aFaceRefId);
|
||||
const BRepGraph_ItemUID aFaceRefUID = myGraph.UIDs().Of(aFaceRefItem);
|
||||
ASSERT_TRUE(aFaceRefUID.IsValid());
|
||||
EXPECT_TRUE(aFaceRefUID.IsReference());
|
||||
EXPECT_EQ(aFaceRefUID.RefKind(), BRepGraph_RefId::Kind::Face);
|
||||
EXPECT_EQ(myGraph.UIDs().ItemIdFrom(aFaceRefUID), aFaceRefItem);
|
||||
EXPECT_TRUE(myGraph.UIDs().Has(aFaceRefUID));
|
||||
|
||||
const BRepGraph_VersionStamp aFaceRefStamp = myGraph.UIDs().StampOf(aFaceRefItem);
|
||||
EXPECT_TRUE(aFaceRefStamp.IsValid());
|
||||
EXPECT_TRUE(aFaceRefStamp.IsRefStamp());
|
||||
EXPECT_EQ(aFaceRefStamp.ItemUID(), aFaceRefUID);
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, StampOf_RemovedUse_ReturnsInvalidUntilReused)
|
||||
{
|
||||
const BRepGraph_FaceId aFaceId = BRepGraph_FaceId::Start();
|
||||
const BRepGraph_FaceSurfaceRepId aRepId = myGraph.Topo().Faces().Definition(aFaceId).SurfaceRepId;
|
||||
ASSERT_TRUE(aRepId.IsValid());
|
||||
|
||||
const occ::handle<Geom_Surface> aSurface = BRepGraph_Tool::Face::Surface(myGraph, aFaceId);
|
||||
ASSERT_FALSE(aSurface.IsNull());
|
||||
EXPECT_TRUE(myGraph.UIDs().StampOf(aRepId).IsValid());
|
||||
|
||||
myGraph.Editor().Faces().ClearSurface(aFaceId);
|
||||
EXPECT_FALSE(myGraph.UIDs().StampOf(aRepId).IsValid());
|
||||
|
||||
myGraph.Editor().Faces().SetSurface(aFaceId, aSurface);
|
||||
EXPECT_EQ(myGraph.Topo().Faces().Definition(aFaceId).SurfaceRepId, aRepId);
|
||||
EXPECT_TRUE(myGraph.UIDs().StampOf(aRepId).IsValid());
|
||||
}
|
||||
|
||||
// --- Graph GUID tests ---
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, GraphGUID_AfterBuild_IsValid)
|
||||
@@ -186,9 +242,9 @@ TEST_F(BRepGraph_VersionStampTest, GraphGUID_Rebuild_Changes)
|
||||
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
myGraph.Clear();
|
||||
[[maybe_unused]] const BRepGraph_Builder::Result aBuildRes3 =
|
||||
BRepGraph_Builder::Add(myGraph, aBoxMaker.Shape());
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes3 =
|
||||
myGraph.Shapes().Add(aBoxMaker.Shape());
|
||||
ASSERT_FALSE(myGraph.IsEmpty());
|
||||
|
||||
const Standard_GUID aGUID2 = myGraph.UIDs().GraphGUID();
|
||||
// Two random GUIDs should differ (probability of collision is negligible).
|
||||
@@ -212,7 +268,9 @@ TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentMutationGen_DifferentGUID)
|
||||
const Standard_GUID& aGraph = myGraph.UIDs().GraphGUID();
|
||||
const Standard_GUID aGUIDBefore = aStampBefore.ToGUID(aGraph);
|
||||
|
||||
myGraph.Editor().Faces().SetNaturalRestriction(BRepGraph_FaceId::Start(), true);
|
||||
myGraph.Editor().Faces().SetTolerance(
|
||||
BRepGraph_FaceId::Start(),
|
||||
BRepGraph_Tool::Face::Tolerance(myGraph, BRepGraph_FaceId::Start()) + 0.01);
|
||||
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const Standard_GUID aGUIDAfter = aStampAfter.ToGUID(aGraph);
|
||||
|
||||
Reference in New Issue
Block a user