mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-08-30 23:13:16 +08:00
Foundation, Modeling - NCollection modernization and BRepGraph overhaul (#1212)
- Migrate NCollection map/sequence/array size APIs from int to size_t; Size() returns size_t, Length() remains the int accessor; int overloads delegate through NbBucketsFromInt() with a negative-input guard. - Add NCollection_LinearVector: contiguous flat-buffer dynamic array with Standard::Reallocate-based growth for trivial types and move-construction for non-trivial types. - Rewrite NCollection_DynamicArray on top of LinearVector<T*>; switch to power-of-two block sizing with precomputed shift/mask. - Rework NCollection_BaseMap iterator with a forward findFirst() helper (no negative-bucket arithmetic); unify ReSize/BeginResize/EndResize on size_t. - Enable thread-safe fast path in NCollection_IncAllocator via std::shared_mutex + CAS bump allocation on atomic AvailableSize; exclusive lock is taken only for new-block allocation and list reordering. - Remove NCollection_BasePointerVector (superseded by NCollection_LinearVector). - Remove NCollection_BaseMap::Statistics (unused). - Add <cstddef> include in NCollection_Primes.hxx so size_t resolves on clean builds. - Document iterator invalidation contract on NCollection_LinearVector. - Unify BRepGraph programmatic mutation behind EditorView: delete BuilderView (2648+552 lines); EditorView (3186+930 lines) and EditorView_Mut.cxx own both structural creation (Add*/Remove*) and field-level RAII-scoped mutation (Mut*()) with automatic OwnGen and SubtreeGen propagation. - Add BRepGraph_MeshCache and BRepGraph_MeshView: two-tier mesh storage separating algorithm-derived caches from persistent (definition) triangulations; freshness is keyed on FaceDef.OwnGen; cache writes do not mutate the model. - Document the MeshCache invalidation contract in BRepGraph_MeshCache.hxx (which mutations bump Face.OwnGen and how markRepModified closes the loop for Surface/Triangulation reps). - Add BRepGraph_RefsIterator (generic flat ref scan with RefTraits dispatch) and BRepGraph_ReverseIterator (typed parent-traversal wrappers over reverse-index vectors). - Rework RefId entity model: replace inline refs with typed RefId vectors; add OccurrenceRef and Kind::Occurrence=7; BRepGraphInc_WireExplorer now requires a VertexRefLookup. - Rename layers for consistency: BRepGraph_ParamLayer to BRepGraph_LayerParam, BRepGraph_RegularityLayer to BRepGraph_LayerRegularity; rename BRepGraphInc_Usage to BRepGraphInc_Instance. - Replace RootNodeIds() with RootProductIds() returning product roots only. - Update BRepGraph and BRepGraphInc READMEs; fix stale RootNodeIds reference. - Sweep Size() to Length() renames across ~200 callers in TKG2d, TKG3d, TKMath, TKMesh, TKBO, TKOffset, TKShHealing, TKTopAlgo, TKBRep, TKService, TKV3d, TKOpenGl, TKMeshVS, TKDE*, TKXCAF, TKXSBase, TKLCAF, TKStd, and Draw harness. - Add GTest coverage for new containers and the BRepGraph overhaul: NCollection_DynamicArray_Test, NCollection_LinearVector_Test, BRepGraph_Fuzz_Test, BRepGraph_Iterator_Test, BRepGraph_LayerIterator_Test, BRepGraph_MeshCache_Test, BRepGraph_MutGuard_Test, BRepGraph_ReplaceVertex_Test, BRepGraph_ReverseIterator_Test, BRepGraph_ScenarioMatrix_Test, BRepGraph_TypedIdDispatch_Test, BRepGraph_WireExplorer_Test.
This commit is contained in:
@@ -12,10 +12,11 @@
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <BRepGraph.hxx>
|
||||
#include <BRepGraph_BuilderView.hxx>
|
||||
#include <BRepGraph_EditorView.hxx>
|
||||
#include <BRepGraph_TopoView.hxx>
|
||||
#include <BRepGraph_UIDsView.hxx>
|
||||
#include <BRepGraph_VersionStamp.hxx>
|
||||
#include <BRepGraph_Builder.hxx>
|
||||
#include <BRepPrimAPI_MakeBox.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
|
||||
@@ -28,7 +29,7 @@ protected:
|
||||
{
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
const TopoDS_Shape& aBox = aBoxMaker.Shape();
|
||||
myGraph.Build(aBox);
|
||||
BRepGraph_Builder::Perform(myGraph, aBox);
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
}
|
||||
|
||||
@@ -65,36 +66,36 @@ TEST_F(BRepGraph_VersionStampTest, StampOf_InvalidNode_ReturnsInvalid)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsStale_UnmutatedNode_ReturnsFalse)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
EXPECT_FALSE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsStale_MutatedNode_ReturnsTrue)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
// Mutate the face.
|
||||
myGraph.Builder().MutFace(BRepGraph_FaceId(0))->NaturalRestriction = true;
|
||||
myGraph.Editor().Faces().Mut(BRepGraph_FaceId::Start())->NaturalRestriction = true;
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsStale_RemovedNode_ReturnsTrue)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
myGraph.Builder().RemoveNode(BRepGraph_FaceId(0));
|
||||
myGraph.Editor().Gen().RemoveNode(BRepGraph_FaceId::Start());
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsStale_DifferentGeneration_ReturnsTrue)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
// Rebuild the graph - generation changes.
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
myGraph.Build(aBoxMaker.Shape());
|
||||
BRepGraph_Builder::Perform(myGraph, aBoxMaker.Shape());
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
@@ -102,12 +103,12 @@ TEST_F(BRepGraph_VersionStampTest, IsStale_DifferentGeneration_ReturnsTrue)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsStale_DeferredMode_TracksCorrectly)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_EdgeId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_EdgeId::Start());
|
||||
|
||||
// Mutate in deferred mode.
|
||||
myGraph.Builder().BeginDeferredInvalidation();
|
||||
myGraph.Builder().MutEdge(BRepGraph_EdgeId(0))->Tolerance = 0.5;
|
||||
myGraph.Builder().EndDeferredInvalidation();
|
||||
myGraph.Editor().BeginDeferredInvalidation();
|
||||
myGraph.Editor().Edges().Mut(BRepGraph_EdgeId::Start())->Tolerance = 0.5;
|
||||
myGraph.Editor().EndDeferredInvalidation();
|
||||
|
||||
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
||||
}
|
||||
@@ -122,32 +123,32 @@ TEST_F(BRepGraph_VersionStampTest, IsStale_InvalidStamp_ReturnsTrue)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, StampIdentity_SameNode_Equal)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp2 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const BRepGraph_VersionStamp aStamp2 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
EXPECT_EQ(aStamp1, aStamp2);
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, StampIdentity_DifferentNodes_NotEqual)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const BRepGraph_VersionStamp aStamp2 = myGraph.UIDs().StampOf(BRepGraph_FaceId(1));
|
||||
EXPECT_NE(aStamp1, aStamp2);
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameNode_SameVersion_ReturnsTrue)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp2 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
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));
|
||||
}
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, IsSameNode_DifferentVersion_StillSameNode)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStampBefore = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStampBefore = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
myGraph.Builder().MutFace(BRepGraph_FaceId(0))->NaturalRestriction = true;
|
||||
myGraph.Editor().Faces().Mut(BRepGraph_FaceId::Start())->NaturalRestriction = true;
|
||||
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
// Full equality fails (different MutationGen).
|
||||
EXPECT_NE(aStampBefore, aStampAfter);
|
||||
@@ -160,7 +161,7 @@ TEST_F(BRepGraph_VersionStampTest, StampOf_AssemblyNodes_WorksForProductsAndOccu
|
||||
// Box graph auto-creates a root Product.
|
||||
ASSERT_GT(myGraph.Topo().Products().Nb(), 0);
|
||||
|
||||
const BRepGraph_VersionStamp aProdStamp = myGraph.UIDs().StampOf(BRepGraph_ProductId(0));
|
||||
const BRepGraph_VersionStamp aProdStamp = myGraph.UIDs().StampOf(BRepGraph_ProductId::Start());
|
||||
EXPECT_TRUE(aProdStamp.IsValid());
|
||||
EXPECT_FALSE(myGraph.UIDs().IsStale(aProdStamp));
|
||||
}
|
||||
@@ -180,7 +181,7 @@ TEST_F(BRepGraph_VersionStampTest, GraphGUID_Rebuild_Changes)
|
||||
const Standard_GUID aGUID1 = myGraph.UIDs().GraphGUID();
|
||||
|
||||
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
||||
myGraph.Build(aBoxMaker.Shape());
|
||||
BRepGraph_Builder::Perform(myGraph, aBoxMaker.Shape());
|
||||
ASSERT_TRUE(myGraph.IsDone());
|
||||
|
||||
const Standard_GUID aGUID2 = myGraph.UIDs().GraphGUID();
|
||||
@@ -192,7 +193,7 @@ TEST_F(BRepGraph_VersionStampTest, GraphGUID_Rebuild_Changes)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, ToGUID_Deterministic_SameInputSameOutput)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const Standard_GUID& aGraph = myGraph.UIDs().GraphGUID();
|
||||
const Standard_GUID aGUID1 = aStamp.ToGUID(aGraph);
|
||||
const Standard_GUID aGUID2 = aStamp.ToGUID(aGraph);
|
||||
@@ -201,13 +202,13 @@ TEST_F(BRepGraph_VersionStampTest, ToGUID_Deterministic_SameInputSameOutput)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentMutationGen_DifferentGUID)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStampBefore = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStampBefore = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const Standard_GUID& aGraph = myGraph.UIDs().GraphGUID();
|
||||
const Standard_GUID aGUIDBefore = aStampBefore.ToGUID(aGraph);
|
||||
|
||||
myGraph.Builder().MutFace(BRepGraph_FaceId(0))->NaturalRestriction = true;
|
||||
myGraph.Editor().Faces().Mut(BRepGraph_FaceId::Start())->NaturalRestriction = true;
|
||||
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const Standard_GUID aGUIDAfter = aStampAfter.ToGUID(aGraph);
|
||||
|
||||
EXPECT_NE(aGUIDBefore, aGUIDAfter);
|
||||
@@ -215,7 +216,7 @@ TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentMutationGen_DifferentGUID)
|
||||
|
||||
TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentGraphGUID_DifferentGUID)
|
||||
{
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
|
||||
const Standard_GUID aGraphA("a1b2c3d4-e5f6-7890-abcd-ef0123456789");
|
||||
const Standard_GUID aGraphB("11223344-5566-7788-99aa-bbccddeeff00");
|
||||
@@ -230,7 +231,7 @@ TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentNodes_DifferentGUID)
|
||||
{
|
||||
const Standard_GUID& aGraph = myGraph.UIDs().GraphGUID();
|
||||
|
||||
const BRepGraph_VersionStamp aStamp0 = myGraph.UIDs().StampOf(BRepGraph_FaceId(0));
|
||||
const BRepGraph_VersionStamp aStamp0 = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
||||
const BRepGraph_VersionStamp aStamp1 = myGraph.UIDs().StampOf(BRepGraph_FaceId(1));
|
||||
|
||||
EXPECT_NE(aStamp0.ToGUID(aGraph), aStamp1.ToGUID(aGraph));
|
||||
|
||||
Reference in New Issue
Block a user