Loading files
4f95ecaa3This file is pinned to the selected release. Download the original to open it in your design tool.
// 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 <BRepGraphInc_Definition.hxx>
#include <BRepGraphInc_Reference.hxx>
#include <BRepGraphInc_RepId.hxx>
#include <BRepGraph_Iterator.hxx>
#include <BRepGraph_RefId.hxx>
#include <BRepGraph_RefsView.hxx>
#include <BRepGraph_RefUID.hxx>
#include <BRepGraph_ReverseIterator.hxx>
#include <BRepGraph_TopoView.hxx>
#include <BRepGraph_UIDsView.hxx>
#include <BRepGraph_VersionStamp.hxx>
#include "BRepGraph_RefTestTools.hxx"
#include <BRepGraph_ShapesView.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <Standard_GUID.hxx>
#include <tuple>
#include <cstdint>
#include <gtest/gtest.h>
namespace
{
uint32_t countInlineFaceRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_ShellIterator aShellIt(theGraph); aShellIt.More(); aShellIt.Next())
{
aNb += BRepGraph_TestTools::CountFaceRefsOfShell(theGraph, aShellIt.CurrentId());
}
return aNb;
}
uint32_t countInlineWireRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_FaceIterator aFaceIt(theGraph); aFaceIt.More(); aFaceIt.Next())
{
aNb += BRepGraph_TestTools::CountWireRefsOfFace(theGraph, aFaceIt.CurrentId());
}
return aNb;
}
uint32_t countInlineCoEdges(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_WireIterator aWireIt(theGraph); aWireIt.More(); aWireIt.Next())
{
aNb += BRepGraph_TestTools::CountCoEdgesOfWire(theGraph, aWireIt.CurrentId());
}
return aNb;
}
uint32_t countInlineVertexRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_EdgeIterator anEdgeIt(theGraph); anEdgeIt.More(); anEdgeIt.Next())
{
const BRepGraphInc::EdgeDef& anEdge = anEdgeIt.Current();
if (anEdge.StartVertexRefId.IsValid())
{
++aNb;
}
if (anEdge.EndVertexRefId.IsValid())
{
++aNb;
}
}
return aNb;
}
uint32_t countInlineShellRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_SolidIterator aSolidIt(theGraph); aSolidIt.More(); aSolidIt.Next())
{
aNb += BRepGraph_TestTools::CountShellRefsOfSolid(theGraph, aSolidIt.CurrentId());
}
return aNb;
}
uint32_t countInlineSolidRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_CompSolidIterator aCSIt(theGraph); aCSIt.More(); aCSIt.Next())
{
aNb += BRepGraph_TestTools::CountSolidRefsOfCompSolid(theGraph, aCSIt.CurrentId());
}
return aNb;
}
uint32_t countInlineChildRefs(const BRepGraph& theGraph)
{
uint32_t aNb = 0;
for (BRepGraph_CompoundIterator aCompIt(theGraph); aCompIt.More(); aCompIt.Next())
{
aNb += BRepGraph_TestTools::CountChildRefsOfParent(theGraph, aCompIt.CurrentId());
}
for (BRepGraph_ShellIterator aShellIt(theGraph); aShellIt.More(); aShellIt.Next())
{
aNb += BRepGraph_TestTools::CountChildRefsOfParent(theGraph, aShellIt.CurrentId());
}
for (BRepGraph_SolidIterator aSolidIt(theGraph); aSolidIt.More(); aSolidIt.Next())
{
aNb += BRepGraph_TestTools::CountChildRefsOfParent(theGraph, aSolidIt.CurrentId());
}
return aNb;
}
} // namespace
TEST(BRepGraph_RefIdTest, DefaultRefId_IsInvalid)
{
const BRepGraph_RefId aRefId;
EXPECT_FALSE(aRefId.IsValid());
}
TEST(BRepGraph_RefIdTest, TypedRefId_ConvertsToUntyped)
{
const BRepGraph_FaceRefId aFaceRefId(3);
const BRepGraph_RefId anUntyped = aFaceRefId;
EXPECT_EQ(anUntyped.RefKind, BRepGraph_RefId::Kind::Face);
EXPECT_EQ(anUntyped.Index, 3);
}
TEST(BRepGraph_RefIdTest, UntypedArithmetic_PreservesKindAndIndex)
{
BRepGraph_RefId aRefId(BRepGraph_RefId::Kind::Face, 1);
const BRepGraph_RefId aPrev = aRefId++;
EXPECT_EQ(aPrev.RefKind, BRepGraph_RefId::Kind::Face);
EXPECT_EQ(aPrev.Index, 1);
EXPECT_EQ(aRefId.Index, 2);
++aRefId;
EXPECT_EQ(aRefId.Index, 3);
const BRepGraph_RefId anAdvanced = aRefId + 4;
EXPECT_EQ(anAdvanced.RefKind, BRepGraph_RefId::Kind::Face);
EXPECT_EQ(anAdvanced.Index, 7);
const BRepGraph_RefId aRetreated = anAdvanced - 6;
EXPECT_EQ(aRetreated.RefKind, BRepGraph_RefId::Kind::Face);
EXPECT_EQ(aRetreated.Index, 1);
}
TEST(BRepGraph_RefIdTest, TypedArithmetic_PreservesKindAndIndex)
{
BRepGraph_FaceRefId aFaceRefId(1);
const BRepGraph_FaceRefId aPrev = aFaceRefId++;
EXPECT_EQ(aPrev.Index, 1);
EXPECT_EQ(aFaceRefId.Index, 2);
++aFaceRefId;
EXPECT_EQ(aFaceRefId.Index, 3);
const BRepGraph_FaceRefId anAdvanced = aFaceRefId + 4;
EXPECT_EQ(anAdvanced.Index, 7);
const BRepGraph_FaceRefId aRetreated = anAdvanced - 6;
EXPECT_EQ(aRetreated.Index, 1);
// Verify kind is preserved through implicit conversion.
const BRepGraph_RefId aRefId = anAdvanced;
EXPECT_EQ(aRefId.RefKind, BRepGraph_RefId::Kind::Face);
EXPECT_EQ(aRefId.Index, 7);
}
TEST(BRepGraph_RefIdTest, TypedArithmetic_IndexZeroBoundary)
{
BRepGraph_VertexRefId aVertexRef(0);
EXPECT_TRUE(aVertexRef.IsValid());
// Increment from zero.
++aVertexRef;
EXPECT_EQ(aVertexRef.Index, 1);
// Retreat back to zero still valid.
const BRepGraph_VertexRefId aZero = aVertexRef - 1;
EXPECT_EQ(aZero.Index, 0);
EXPECT_TRUE(aZero.IsValid());
// Subtract to the invalid sentinel produces an invalid id.
const BRepGraph_VertexRefId anInvalid = aZero - 1;
EXPECT_EQ(anInvalid.Index, BRepGraph_VertexRefId::THE_INVALID_INDEX);
EXPECT_FALSE(anInvalid.IsValid());
}
TEST(BRepGraph_RefIdTest, InvalidKind_IsRejected)
{
constexpr uint32_t THE_RESERVED_KIND = 7u;
const BRepGraph_RefId aRef(static_cast<BRepGraph_RefId::Kind>(THE_RESERVED_KIND), 0u);
EXPECT_FALSE(BRepGraph_RefId::IsValidKind(aRef.RefKind));
EXPECT_FALSE(aRef.IsValid());
EXPECT_FALSE(aRef.IsValid(10u));
EXPECT_FALSE(BRepGraph_RefId::IsTopologyRefKind(aRef.RefKind));
}
TEST(BRepGraph_RefIdTest, FromRefId_WrongKindReturnsInvalid)
{
const BRepGraph_RefId aRef(BRepGraph_RefId::Kind::Face, 3u);
const BRepGraph_WireRefId aWire = BRepGraph_WireRefId::FromRefId(aRef);
EXPECT_FALSE(aWire.IsValid());
EXPECT_EQ(aWire.Index, BRepGraph_WireRefId::THE_INVALID_INDEX);
}
TEST(BRepGraph_RefIdTest, RefUID_Default_IsInvalid)
{
const BRepGraph_RefUID aRefUID;
EXPECT_FALSE(aRefUID.IsValid());
}
TEST(BRepGraph_RefIdTest, RefUID_Equality_IgnoresGeneration)
{
const BRepGraph_RefUID aUIDV1(BRepGraph_RefId::Kind::Face, uint32_t(42));
const BRepGraph_RefUID aUIDV2(BRepGraph_RefId::Kind::Face, uint32_t(42));
EXPECT_EQ(aUIDV1, aUIDV2);
}
TEST(BRepGraph_RefIdTest, RefsView_AfterBuild_HasFaceRefs)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes1 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
const uint32_t aFaceRefCount = aGraph.Refs().Faces().Nb();
EXPECT_GE(aFaceRefCount, 0);
if (aFaceRefCount > 0)
{
const BRepGraph_FaceRefId aFaceRefId(0);
const BRepGraphInc::FaceRef& anEntry = aGraph.Refs().Faces().Entry(aFaceRefId);
std::ignore = anEntry;
EXPECT_TRUE(aFaceRefId.IsValid(aFaceRefCount));
}
else
{
EXPECT_FALSE(aGraph.UIDs().Of(BRepGraph_FaceRefId::Start()).IsValid());
}
}
TEST(BRepGraph_RefIdTest, RefDomain_StampGUIDGeneration_IfSupported)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes2 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
if (aGraph.Refs().Faces().Nb() <= 0)
{
GTEST_SKIP() << "Ref-domain entries are not populated at this phase";
}
const BRepGraph_VersionStamp aStamp = aGraph.UIDs().StampOf(BRepGraph_FaceRefId::Start());
if (!aStamp.IsValid())
{
GTEST_SKIP() << "Ref-domain stamping/GUID generation not wired yet";
}
EXPECT_TRUE(aStamp.IsRefStamp());
const Standard_GUID& aGraphGUID = aGraph.UIDs().GraphGUID();
const Standard_GUID aGUID1 = aStamp.ToGUID(aGraphGUID);
const Standard_GUID aGUID2 = aStamp.ToGUID(aGraphGUID);
EXPECT_EQ(aGUID1, aGUID2);
}
TEST(BRepGraph_RefIdTest, RefsView_AfterBuild_CountsDoNotExceedInlineStorage)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes3 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
EXPECT_LE(aGraph.Refs().Faces().Nb(), countInlineFaceRefs(aGraph));
EXPECT_LE(aGraph.Refs().Wires().Nb(), countInlineWireRefs(aGraph));
EXPECT_GT(countInlineCoEdges(aGraph), 0);
EXPECT_EQ(aGraph.Topo().CoEdges().Nb(), countInlineCoEdges(aGraph));
EXPECT_LE(aGraph.Refs().Vertices().Nb(), countInlineVertexRefs(aGraph));
EXPECT_LE(aGraph.Refs().Shells().Nb(), countInlineShellRefs(aGraph));
EXPECT_LE(aGraph.Refs().Solids().Nb(), countInlineSolidRefs(aGraph));
EXPECT_LE(aGraph.Refs().Children().Nb(), countInlineChildRefs(aGraph));
}
TEST(BRepGraph_RefIdTest, RefsView_AfterBuild_UIDRoundtripAndParentKinds)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes4 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
for (BRepGraph_FaceRefId aFaceRefId = BRepGraph_FaceRefId::Start();
aFaceRefId.IsValid(aGraph.Refs().Faces().Nb());
++aFaceRefId)
{
const BRepGraph_RefId aRefId = aFaceRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraph_VersionStamp aStamp = aGraph.UIDs().StampOf(aRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(aGraph.UIDs().Has(aUID));
EXPECT_TRUE(aStamp.IsValid());
EXPECT_TRUE(aStamp.IsRefStamp());
EXPECT_FALSE(aGraph.UIDs().IsStale(aStamp));
const BRepGraphInc::FaceRef& anEntry = aGraph.Refs().Faces().Entry(aFaceRefId);
EXPECT_TRUE(anEntry.ChildFaceId.IsValid(aGraph.Topo().Faces().Nb()));
}
for (BRepGraph_WireRefId aWireRefId = BRepGraph_WireRefId::Start();
aWireRefId.IsValid(aGraph.Refs().Wires().Nb());
++aWireRefId)
{
const BRepGraph_RefId aRefId = aWireRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraphInc::WireRef& anEntry = aGraph.Refs().Wires().Entry(aWireRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(anEntry.ChildWireId.IsValid(aGraph.Topo().Wires().Nb()));
}
for (BRepGraph_CoEdgeId aCoEdgeId = BRepGraph_CoEdgeId::Start();
aCoEdgeId.IsValid(aGraph.Topo().CoEdges().Nb());
++aCoEdgeId)
{
const BRepGraph_UID aUID = aGraph.UIDs().Of(aCoEdgeId);
const BRepGraphInc::CoEdgeDef& anEntry = aGraph.Topo().CoEdges().Definition(aCoEdgeId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().NodeIdFrom(aUID), BRepGraph_NodeId(aCoEdgeId));
EXPECT_TRUE(anEntry.ChildEdgeId.IsValid(aGraph.Topo().Edges().Nb()));
}
for (BRepGraph_ShellRefId aShellRefId = BRepGraph_ShellRefId::Start();
aShellRefId.IsValid(aGraph.Refs().Shells().Nb());
++aShellRefId)
{
const BRepGraph_RefId aRefId = aShellRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraphInc::ShellRef& anEntry = aGraph.Refs().Shells().Entry(aShellRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(anEntry.ChildShellId.IsValid(aGraph.Topo().Shells().Nb()));
}
for (BRepGraph_VertexRefId aVertexRefId = BRepGraph_VertexRefId::Start();
aVertexRefId.IsValid(aGraph.Refs().Vertices().Nb());
++aVertexRefId)
{
const BRepGraph_RefId aRefId = aVertexRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraphInc::VertexRef& anEntry = aGraph.Refs().Vertices().Entry(aVertexRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(anEntry.ChildVertexId.IsValid(aGraph.Topo().Vertices().Nb()));
}
for (BRepGraph_SolidRefId aSolidRefId = BRepGraph_SolidRefId::Start();
aSolidRefId.IsValid(aGraph.Refs().Solids().Nb());
++aSolidRefId)
{
const BRepGraph_RefId aRefId = aSolidRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraphInc::SolidRef& anEntry = aGraph.Refs().Solids().Entry(aSolidRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(anEntry.ChildSolidId.IsValid(aGraph.Topo().Solids().Nb()));
}
for (BRepGraph_ChildRefId aChildRefId = BRepGraph_ChildRefId::Start();
aChildRefId.IsValid(aGraph.Refs().Children().Nb());
++aChildRefId)
{
const BRepGraph_RefId aRefId = aChildRefId;
const BRepGraph_RefUID aUID = aGraph.UIDs().Of(aRefId);
const BRepGraphInc::ChildRef& anEntry = aGraph.Refs().Children().Entry(aChildRefId);
EXPECT_TRUE(aUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aUID), aRefId);
EXPECT_TRUE(anEntry.ChildNodeId.IsValid());
}
}
TEST(BRepGraph_RefIdTest, RefUIDReverseLookupStaysCurrentAfterProgrammaticAdd)
{
BRepGraph aGraph;
const BRepGraph_VertexId aV0 = aGraph.Editor().Vertices().Add(gp_Pnt(0.0, 0.0, 0.0), 0.001);
const BRepGraph_VertexId aV1 = aGraph.Editor().Vertices().Add(gp_Pnt(1.0, 0.0, 0.0), 0.001);
std::ignore = aGraph.Editor().Edges().Add(aV0, aV1, occ::handle<Geom_Curve>(), 0.0, 1.0, 0.001);
const BRepGraph_RefId aFirstRefId = BRepGraph_VertexRefId::Start();
const BRepGraph_RefUID aFirstUID = aGraph.UIDs().Of(aFirstRefId);
ASSERT_TRUE(aFirstUID.IsValid());
ASSERT_EQ(aGraph.UIDs().RefIdFrom(aFirstUID), aFirstRefId);
const BRepGraph_VertexId aV2 = aGraph.Editor().Vertices().Add(gp_Pnt(2.0, 0.0, 0.0), 0.001);
const BRepGraph_VertexId aV3 = aGraph.Editor().Vertices().Add(gp_Pnt(3.0, 0.0, 0.0), 0.001);
std::ignore = aGraph.Editor().Edges().Add(aV2, aV3, occ::handle<Geom_Curve>(), 0.0, 1.0, 0.001);
const BRepGraph_RefId aSecondRefId = BRepGraph_VertexRefId(2);
const BRepGraph_RefUID aSecondUID = aGraph.UIDs().Of(aSecondRefId);
ASSERT_TRUE(aSecondUID.IsValid());
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aFirstUID), aFirstRefId);
EXPECT_EQ(aGraph.UIDs().RefIdFrom(aSecondUID), aSecondRefId);
EXPECT_TRUE(aGraph.UIDs().Has(aFirstUID));
EXPECT_TRUE(aGraph.UIDs().Has(aSecondUID));
}
TEST(BRepGraph_RefIdTest, StaleRefUID_HasReturnsFalseAndLookupBecomesInvalidAfterRebuild)
{
BRepPrimAPI_MakeBox aBoxMaker1(10.0, 20.0, 30.0);
BRepPrimAPI_MakeBox aBoxMaker2(11.0, 21.0, 31.0);
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes5 =
aGraph.Shapes().Add(aBoxMaker1.Shape());
ASSERT_FALSE(aGraph.IsEmpty());
ASSERT_GT(aGraph.Refs().Faces().Nb(), 0);
const BRepGraph_RefUID anOldUID = aGraph.UIDs().Of(BRepGraph_FaceRefId::Start());
ASSERT_TRUE(anOldUID.IsValid());
ASSERT_TRUE(aGraph.UIDs().Has(anOldUID));
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes6 =
aGraph.Shapes().Add(aBoxMaker2.Shape());
EXPECT_FALSE(aGraph.UIDs().Has(anOldUID));
EXPECT_FALSE(aGraph.UIDs().RefIdFrom(anOldUID).IsValid());
}
TEST(BRepGraph_RefIdTest, MutFaceRef_UpdatesRefStampAndParentModifiedFlag)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes7 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
if (aGraph.Refs().Faces().Nb() <= 0)
{
GTEST_SKIP() << "No face references available";
}
const BRepGraph_FaceRefId aFaceRefId(0);
const BRepGraphInc::FaceRef& aBeforeEntry = aGraph.Refs().Faces().Entry(aFaceRefId);
const BRepGraph_VersionStamp aBeforeStamp = aGraph.UIDs().StampOf(aFaceRefId);
ASSERT_TRUE(aBeforeStamp.IsValid());
ASSERT_TRUE(aBeforeStamp.IsRefStamp());
const TopAbs_Orientation anBeforeOri = aBeforeEntry.Orientation;
{
BRepGraph_MutGuard<BRepGraphInc::FaceRef> aMut = aGraph.Editor().Faces().MutRef(aFaceRefId);
aGraph.Editor().Faces().SetRefOrientation(aMut,
(anBeforeOri == TopAbs_FORWARD) ? TopAbs_REVERSED
: TopAbs_FORWARD);
}
const BRepGraphInc::FaceRef& aAfterEntry = aGraph.Refs().Faces().Entry(aFaceRefId);
EXPECT_NE(aAfterEntry.Orientation, anBeforeOri);
EXPECT_TRUE(aGraph.UIDs().IsStale(aBeforeStamp));
bool hasUpdatedParent = false;
for (BRepGraph_RefsShellsOfFace anIt(
aGraph,
aGraph.Topo().Faces().Relations(aAfterEntry.ChildFaceId).ParentFaceRefIds);
anIt.More();
anIt.Next())
{
if (anIt.CurrentRefId() == aFaceRefId)
{
const BRepGraphInc::ShellDef& aParent =
aGraph.Topo().Shells().Definition(anIt.CurrentParentId());
hasUpdatedParent = aParent.SubtreeGen > 0u;
break;
}
}
EXPECT_TRUE(hasUpdatedParent);
}
TEST(BRepGraph_RefIdTest, MutFaceRef_MarkRemoved_PersistsAndInvalidatesStamp)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes8 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
if (aGraph.Refs().Faces().Nb() <= 0)
{
GTEST_SKIP() << "No face references available";
}
const BRepGraph_FaceRefId aFaceRefId(0);
const BRepGraph_VersionStamp aBeforeStamp = aGraph.UIDs().StampOf(aFaceRefId);
ASSERT_TRUE(aBeforeStamp.IsValid());
ASSERT_TRUE(aBeforeStamp.IsRefStamp());
aGraph.Editor().Gen().RemoveRef(aFaceRefId);
EXPECT_TRUE(aFaceRefId.IsRemoved(aGraph));
EXPECT_TRUE(aGraph.UIDs().IsStale(aBeforeStamp));
EXPECT_FALSE(aGraph.UIDs().StampOf(aFaceRefId).IsValid());
}
TEST(BRepGraph_RefIdTest, OutOfRangeMetadataQueriesReturnFalse)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
const BRepGraph_FaceRefId anOutOfRangeFaceRef(aGraph.Refs().Faces().Nb());
EXPECT_FALSE(anOutOfRangeFaceRef.IsRemoved(aGraph));
EXPECT_FALSE(anOutOfRangeFaceRef.IsOwned(aGraph));
const BRepGraph_RefId anOutOfRangeWireRef(BRepGraph_RefId::Kind::Wire,
aGraph.Refs().Wires().Nb());
EXPECT_FALSE(anOutOfRangeWireRef.IsRemoved(aGraph));
EXPECT_FALSE(anOutOfRangeWireRef.IsOwned(aGraph));
}
TEST(BRepGraph_RefIdTest, ChildRefs_CompoundEntriesAreValid)
{
BRepGraph aGraph;
aGraph.Clear();
[[maybe_unused]] const BRepGraph::ShapesView::Result aBuildRes9 =
aGraph.Shapes().Add(BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape());
ASSERT_FALSE(aGraph.IsEmpty());
const BRepGraph::RefsView& aRefs = aGraph.Refs();
for (BRepGraph_CompoundIterator aCompIt(aGraph); aCompIt.More(); aCompIt.Next())
{
const NCollection_LinearVector<BRepGraph_ChildRefId>& aChildRefs =
BRepGraph_TestTools::ChildRefsOfParent(aGraph, aCompIt.CurrentId());
for (const BRepGraph_ChildRefId& aChildRefId : aChildRefs)
{
const BRepGraphInc::ChildRef& aRef = aRefs.Children().Entry(aChildRefId);
EXPECT_TRUE(aRef.ChildNodeId.IsValid());
EXPECT_FALSE(aChildRefId.IsRemoved(aGraph));
}
}
}