mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-08-29 22:38:28 +08:00
0755b6f31d
- 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.
239 lines
8.1 KiB
C++
239 lines
8.1 KiB
C++
// Copyright (c) 2026 OPEN CASCADE SAS
|
|
//
|
|
// This file is part of Open CASCADE Technology software library.
|
|
//
|
|
// This library is free software; you can redistribute it and/or modify it under
|
|
// the terms of the GNU Lesser General Public License version 2.1 as published
|
|
// by the Free Software Foundation, with special exception defined in the file
|
|
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
|
// distribution for complete text of the license and disclaimer of any warranty.
|
|
//
|
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
|
// commercial license or contractual agreement.
|
|
|
|
#include <BRepGraph.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>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
class BRepGraph_VersionStampTest : public testing::Test
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
|
const TopoDS_Shape& aBox = aBoxMaker.Shape();
|
|
BRepGraph_Builder::Perform(myGraph, aBox);
|
|
ASSERT_TRUE(myGraph.IsDone());
|
|
}
|
|
|
|
BRepGraph myGraph;
|
|
};
|
|
|
|
// --- VersionStamp struct tests ---
|
|
|
|
TEST(BRepGraph_VersionStampBasicTest, DefaultStamp_IsInvalid)
|
|
{
|
|
const BRepGraph_VersionStamp aStamp;
|
|
EXPECT_FALSE(aStamp.IsValid());
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, StampOf_ValidNode_ReturnsValidStamp)
|
|
{
|
|
const BRepGraph_FaceId aFaceId(0);
|
|
ASSERT_TRUE(aFaceId.IsValid(myGraph.Topo().Faces().Nb()));
|
|
|
|
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(aFaceId);
|
|
EXPECT_TRUE(aStamp.IsValid());
|
|
EXPECT_TRUE(aStamp.myUID.IsValid());
|
|
EXPECT_EQ(aStamp.myMutationGen, 0u);
|
|
EXPECT_EQ(aStamp.myGeneration, myGraph.UIDs().Generation());
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, StampOf_InvalidNode_ReturnsInvalid)
|
|
{
|
|
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_NodeId());
|
|
EXPECT_FALSE(aStamp.IsValid());
|
|
}
|
|
|
|
// --- IsStale tests ---
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, IsStale_UnmutatedNode_ReturnsFalse)
|
|
{
|
|
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::Start());
|
|
|
|
// Mutate the face.
|
|
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::Start());
|
|
|
|
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::Start());
|
|
|
|
// Rebuild the graph - generation changes.
|
|
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
|
BRepGraph_Builder::Perform(myGraph, aBoxMaker.Shape());
|
|
ASSERT_TRUE(myGraph.IsDone());
|
|
|
|
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, IsStale_DeferredMode_TracksCorrectly)
|
|
{
|
|
const BRepGraph_VersionStamp aStamp = myGraph.UIDs().StampOf(BRepGraph_EdgeId::Start());
|
|
|
|
// Mutate in deferred mode.
|
|
myGraph.Editor().BeginDeferredInvalidation();
|
|
myGraph.Editor().Edges().Mut(BRepGraph_EdgeId::Start())->Tolerance = 0.5;
|
|
myGraph.Editor().EndDeferredInvalidation();
|
|
|
|
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, IsStale_InvalidStamp_ReturnsTrue)
|
|
{
|
|
const BRepGraph_VersionStamp aStamp;
|
|
EXPECT_TRUE(myGraph.UIDs().IsStale(aStamp));
|
|
}
|
|
|
|
// --- Identity and version comparison ---
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, StampIdentity_SameNode_Equal)
|
|
{
|
|
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::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::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::Start());
|
|
|
|
myGraph.Editor().Faces().Mut(BRepGraph_FaceId::Start())->NaturalRestriction = true;
|
|
|
|
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));
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, StampOf_AssemblyNodes_WorksForProductsAndOccurrences)
|
|
{
|
|
// Box graph auto-creates a root Product.
|
|
ASSERT_GT(myGraph.Topo().Products().Nb(), 0);
|
|
|
|
const BRepGraph_VersionStamp aProdStamp = myGraph.UIDs().StampOf(BRepGraph_ProductId::Start());
|
|
EXPECT_TRUE(aProdStamp.IsValid());
|
|
EXPECT_FALSE(myGraph.UIDs().IsStale(aProdStamp));
|
|
}
|
|
|
|
// --- Graph GUID tests ---
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, GraphGUID_AfterBuild_IsValid)
|
|
{
|
|
const Standard_GUID& aGUID = myGraph.UIDs().GraphGUID();
|
|
// A random GUID should not be all zeros.
|
|
const Standard_GUID aZero;
|
|
EXPECT_NE(aGUID, aZero);
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, GraphGUID_Rebuild_Changes)
|
|
{
|
|
const Standard_GUID aGUID1 = myGraph.UIDs().GraphGUID();
|
|
|
|
BRepPrimAPI_MakeBox aBoxMaker(10.0, 20.0, 30.0);
|
|
BRepGraph_Builder::Perform(myGraph, aBoxMaker.Shape());
|
|
ASSERT_TRUE(myGraph.IsDone());
|
|
|
|
const Standard_GUID aGUID2 = myGraph.UIDs().GraphGUID();
|
|
// Two random GUIDs should differ (probability of collision is negligible).
|
|
EXPECT_NE(aGUID1, aGUID2);
|
|
}
|
|
|
|
// --- ToGUID tests ---
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, ToGUID_Deterministic_SameInputSameOutput)
|
|
{
|
|
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);
|
|
EXPECT_EQ(aGUID1, aGUID2);
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentMutationGen_DifferentGUID)
|
|
{
|
|
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.Editor().Faces().Mut(BRepGraph_FaceId::Start())->NaturalRestriction = true;
|
|
|
|
const BRepGraph_VersionStamp aStampAfter = myGraph.UIDs().StampOf(BRepGraph_FaceId::Start());
|
|
const Standard_GUID aGUIDAfter = aStampAfter.ToGUID(aGraph);
|
|
|
|
EXPECT_NE(aGUIDBefore, aGUIDAfter);
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentGraphGUID_DifferentGUID)
|
|
{
|
|
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");
|
|
|
|
const Standard_GUID aGUIDA = aStamp.ToGUID(aGraphA);
|
|
const Standard_GUID aGUIDB = aStamp.ToGUID(aGraphB);
|
|
|
|
EXPECT_NE(aGUIDA, aGUIDB);
|
|
}
|
|
|
|
TEST_F(BRepGraph_VersionStampTest, ToGUID_DifferentNodes_DifferentGUID)
|
|
{
|
|
const Standard_GUID& aGraph = myGraph.UIDs().GraphGUID();
|
|
|
|
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));
|
|
}
|