File indexing completed on 2026-09-28 09:19:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraphInc_Storage_HeaderFile
0015 #define _BRepGraphInc_Storage_HeaderFile
0016
0017 #include <BRepGraph_ItemId.hxx>
0018 #include <BRepGraph_NodeId.hxx>
0019 #include <BRepGraph_RefUID.hxx>
0020 #include <BRepGraph_UID.hxx>
0021 #include <BRepGraphInc_BitFlags.hxx>
0022 #include <BRepGraphInc_Definition.hxx>
0023 #include <BRepGraphInc_Load.hxx>
0024 #include <BRepGraphInc_Reference.hxx>
0025 #include <BRepGraphInc_Relations.hxx>
0026 #include <BRepGraphInc_Representation.hxx>
0027 #include <NCollection_Array1.hxx>
0028 #include <NCollection_IncAllocator.hxx>
0029 #include <NCollection_DataMap.hxx>
0030 #include <NCollection_FlatDataMap.hxx>
0031 #include <NCollection_DynamicArray.hxx>
0032 #include <NCollection_LinearVector.hxx>
0033 #include <Standard_GUID.hxx>
0034 #include <Standard_Assert.hxx>
0035 #include <Standard_DefineAlloc.hxx>
0036 #include <TopoDS_Shape.hxx>
0037 #include <TopoDS_TShape.hxx>
0038 #include <TopTools_ShapeMapHasher.hxx>
0039
0040 #include <atomic>
0041 #include <shared_mutex>
0042 #include <utility>
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 class BRepGraphInc_Storage
0055 {
0056 public:
0057 DEFINE_STANDARD_ALLOC
0058
0059
0060 struct CachedShape
0061 {
0062
0063 TopoDS_Shape Shape;
0064
0065
0066 uint32_t StoredSubtreeGen = 0;
0067 };
0068
0069
0070 Standard_EXPORT BRepGraphInc_Storage();
0071
0072
0073 Standard_EXPORT ~BRepGraphInc_Storage();
0074
0075
0076 [[nodiscard]] const occ::handle<NCollection_BaseAllocator>& Allocator() const
0077 {
0078 return myAllocator;
0079 }
0080
0081
0082 [[nodiscard]] const NCollection_LinearVector<BRepGraph_ProductId>& RootProductIds() const
0083 {
0084 return myRootProductIds;
0085 }
0086
0087
0088 NCollection_LinearVector<BRepGraph_ProductId>& ChangeRootProductIds() { return myRootProductIds; }
0089
0090
0091 [[nodiscard]] const NCollection_LinearVector<BRepGraph_NodeId>& DeferredModified() const
0092 {
0093 return myDeferredModified;
0094 }
0095
0096
0097 NCollection_LinearVector<BRepGraph_NodeId>& ChangeDeferredModified()
0098 {
0099 return myDeferredModified;
0100 }
0101
0102
0103 [[nodiscard]] const NCollection_LinearVector<BRepGraph_RefId>& DeferredRefModified() const
0104 {
0105 return myDeferredRefModified;
0106 }
0107
0108
0109 NCollection_LinearVector<BRepGraph_RefId>& ChangeDeferredRefModified()
0110 {
0111 return myDeferredRefModified;
0112 }
0113
0114
0115
0116
0117 [[nodiscard]] Standard_EXPORT bool IsEmpty() const;
0118
0119
0120 [[nodiscard]] Standard_EXPORT uint32_t NextNodeUIDCounter(BRepGraph_NodeId::Kind theKind) const;
0121
0122
0123 Standard_EXPORT void SetNextNodeUIDCounter(BRepGraph_NodeId::Kind theKind, uint32_t theCounter);
0124
0125
0126 [[nodiscard]] Standard_EXPORT uint32_t NextRefUIDCounter(BRepGraph_RefId::Kind theKind) const;
0127
0128
0129 Standard_EXPORT void SetNextRefUIDCounter(BRepGraph_RefId::Kind theKind, uint32_t theCounter);
0130
0131
0132 Standard_EXPORT BRepGraph_UID AllocateNodeUID(BRepGraph_NodeId theNodeId);
0133
0134
0135 Standard_EXPORT BRepGraph_RefUID AllocateRefUID(BRepGraph_RefId theRefId);
0136
0137
0138 [[nodiscard]] uint32_t Generation() const { return myGeneration.load(std::memory_order_relaxed); }
0139
0140
0141 void SetGeneration(const uint32_t theGeneration)
0142 {
0143 myGeneration.store(theGeneration, std::memory_order_relaxed);
0144 }
0145
0146
0147 void IncrementGeneration() { myGeneration.fetch_add(1, std::memory_order_relaxed); }
0148
0149
0150 [[nodiscard]] const Standard_GUID& GraphGUID() const { return myGraphGUID; }
0151
0152
0153 void SetGraphGUID(const Standard_GUID& theGuid) { myGraphGUID = theGuid; }
0154
0155
0156 [[nodiscard]] bool DeferredMode() const { return myDeferredMode.load(std::memory_order_relaxed); }
0157
0158
0159 void SetDeferredMode(const bool theEnabled)
0160 {
0161 myDeferredMode.store(theEnabled, std::memory_order_relaxed);
0162 }
0163
0164
0165 [[nodiscard]] uint32_t PropagationWave() const
0166 {
0167 return myPropagationWave.load(std::memory_order_relaxed);
0168 }
0169
0170
0171 [[nodiscard]] uint32_t AdvancePropagationWave()
0172 {
0173 return myPropagationWave.fetch_add(1, std::memory_order_relaxed) + 1;
0174 }
0175
0176
0177 void IncrementPropagationWave() { myPropagationWave.fetch_add(1, std::memory_order_relaxed); }
0178
0179
0180 [[nodiscard]] uint32_t RemoveSubgraphDepth() const { return myRemoveSubgraphDepth; }
0181
0182
0183 void IncrementRemoveSubgraphDepth() { ++myRemoveSubgraphDepth; }
0184
0185
0186 void DecrementRemoveSubgraphDepth()
0187 {
0188 Standard_ASSERT_VOID(myRemoveSubgraphDepth > 0, "RemoveSubgraphDepth underflow");
0189 if (myRemoveSubgraphDepth > 0)
0190 {
0191 --myRemoveSubgraphDepth;
0192 }
0193 }
0194
0195
0196 [[nodiscard]] uint32_t NbVertices() const { return myVertices.Nb(); }
0197
0198
0199 [[nodiscard]] uint32_t NbEdges() const { return myEdges.Nb(); }
0200
0201
0202 [[nodiscard]] uint32_t NbCoEdges() const { return myCoEdges.Nb(); }
0203
0204
0205 [[nodiscard]] uint32_t NbWires() const { return myWires.Nb(); }
0206
0207
0208 [[nodiscard]] uint32_t NbFaces() const { return myFaces.Nb(); }
0209
0210
0211 [[nodiscard]] uint32_t NbShells() const { return myShells.Nb(); }
0212
0213
0214 [[nodiscard]] uint32_t NbSolids() const { return mySolids.Nb(); }
0215
0216
0217 [[nodiscard]] uint32_t NbCompounds() const { return myCompounds.Nb(); }
0218
0219
0220 [[nodiscard]] uint32_t NbCompSolids() const { return myCompSolids.Nb(); }
0221
0222
0223 [[nodiscard]] uint32_t NbProducts() const { return myProducts.Nb(); }
0224
0225
0226 [[nodiscard]] uint32_t NbOccurrences() const { return myOccurrences.Nb(); }
0227
0228
0229 [[nodiscard]] uint32_t NbShellRefs() const { return myShellRefs.Nb(); }
0230
0231
0232 [[nodiscard]] uint32_t NbFaceRefs() const { return myFaceRefs.Nb(); }
0233
0234
0235 [[nodiscard]] uint32_t NbWireRefs() const { return myWireRefs.Nb(); }
0236
0237
0238 [[nodiscard]] uint32_t NbVertexRefs() const { return myVertexRefs.Nb(); }
0239
0240
0241 [[nodiscard]] uint32_t NbSolidRefs() const { return mySolidRefs.Nb(); }
0242
0243
0244 [[nodiscard]] uint32_t NbChildRefs() const { return myChildRefs.Nb(); }
0245
0246
0247 [[nodiscard]] uint32_t NbOccurrenceRefs() const { return myOccurrenceRefs.Nb(); }
0248
0249
0250 [[nodiscard]] uint32_t NbActiveVertices() const { return myVertices.NbActive; }
0251
0252
0253 [[nodiscard]] uint32_t NbActiveEdges() const { return myEdges.NbActive; }
0254
0255
0256 [[nodiscard]] uint32_t NbActiveCoEdges() const { return myCoEdges.NbActive; }
0257
0258
0259 [[nodiscard]] uint32_t NbActiveWires() const { return myWires.NbActive; }
0260
0261
0262 [[nodiscard]] uint32_t NbActiveFaces() const { return myFaces.NbActive; }
0263
0264
0265 [[nodiscard]] uint32_t NbActiveShells() const { return myShells.NbActive; }
0266
0267
0268 [[nodiscard]] uint32_t NbActiveSolids() const { return mySolids.NbActive; }
0269
0270
0271 [[nodiscard]] uint32_t NbActiveCompounds() const { return myCompounds.NbActive; }
0272
0273
0274 [[nodiscard]] uint32_t NbActiveCompSolids() const { return myCompSolids.NbActive; }
0275
0276
0277 [[nodiscard]] uint32_t NbActiveProducts() const { return myProducts.NbActive; }
0278
0279
0280 [[nodiscard]] uint32_t NbActiveOccurrences() const { return myOccurrences.NbActive; }
0281
0282
0283 [[nodiscard]] uint32_t NbActiveShellRefs() const { return myShellRefs.NbActive; }
0284
0285
0286 [[nodiscard]] uint32_t NbActiveFaceRefs() const { return myFaceRefs.NbActive; }
0287
0288
0289 [[nodiscard]] uint32_t NbActiveWireRefs() const { return myWireRefs.NbActive; }
0290
0291
0292 [[nodiscard]] uint32_t NbActiveVertexRefs() const { return myVertexRefs.NbActive; }
0293
0294
0295 [[nodiscard]] uint32_t NbActiveSolidRefs() const { return mySolidRefs.NbActive; }
0296
0297
0298 [[nodiscard]] uint32_t NbActiveChildRefs() const { return myChildRefs.NbActive; }
0299
0300
0301 [[nodiscard]] uint32_t NbActiveOccurrenceRefs() const { return myOccurrenceRefs.NbActive; }
0302
0303
0304
0305
0306 Standard_EXPORT bool MarkRemoved(const BRepGraph_NodeId theNodeId);
0307
0308
0309
0310
0311 Standard_EXPORT bool MarkRemovedRef(const BRepGraph_RefId theRefId);
0312
0313
0314 [[nodiscard]] uint32_t NbEdgeCurves3D() const { return myEdgeCurves3D.Nb(); }
0315
0316
0317 [[nodiscard]] uint32_t NbEdgePolygons3D() const { return myEdgePolygons3D.Nb(); }
0318
0319
0320 [[nodiscard]] uint32_t NbCoEdgeCurves2D() const { return myCoEdgeCurves2D.Nb(); }
0321
0322
0323 [[nodiscard]] uint32_t NbCoEdgePolygons2D() const { return myCoEdgePolygons2D.Nb(); }
0324
0325
0326 [[nodiscard]] uint32_t NbCoEdgePolygonsOnTri() const { return myCoEdgePolygonsOnTri.Nb(); }
0327
0328
0329 [[nodiscard]] uint32_t NbFaceSurfaces() const { return myFaceSurfaces.Nb(); }
0330
0331
0332 [[nodiscard]] uint32_t NbFaceTriangulations() const { return myFaceTriangulations.Nb(); }
0333
0334
0335 [[nodiscard]] Standard_EXPORT uint32_t NbActiveEdgeCurves3D() const;
0336
0337
0338 [[nodiscard]] Standard_EXPORT uint32_t NbActiveCoEdgeCurves2D() const;
0339
0340
0341 [[nodiscard]] Standard_EXPORT uint32_t NbActiveFaceSurfaces() const;
0342
0343
0344 [[nodiscard]] Standard_EXPORT uint32_t NbActiveFaceTriangulations() const;
0345
0346
0347 [[nodiscard]] Standard_EXPORT uint32_t NbActiveEdgePolygons3D() const;
0348
0349
0350 [[nodiscard]] Standard_EXPORT uint32_t NbActiveCoEdgePolygons2D() const;
0351
0352
0353 [[nodiscard]] Standard_EXPORT uint32_t NbActiveCoEdgePolygonsOnTri() const;
0354
0355
0356 [[nodiscard]] const BRepGraphInc::EdgeCurve3DRep& EdgeCurve3DRep(
0357 const BRepGraph_EdgeCurve3DRepId theId) const
0358 {
0359 return myEdgeCurves3D.Get(theId);
0360 }
0361
0362
0363 BRepGraphInc::EdgeCurve3DRep& ChangeEdgeCurve3DRep(const BRepGraph_EdgeCurve3DRepId theId)
0364 {
0365 return myEdgeCurves3D.Change(theId);
0366 }
0367
0368
0369 [[nodiscard]] const BRepGraphInc::EdgePolygon3DRep& EdgePolygon3DRep(
0370 const BRepGraph_EdgePolygon3DRepId theId) const
0371 {
0372 return myEdgePolygons3D.Get(theId);
0373 }
0374
0375
0376 BRepGraphInc::EdgePolygon3DRep& ChangeEdgePolygon3DRep(const BRepGraph_EdgePolygon3DRepId theId)
0377 {
0378 return myEdgePolygons3D.Change(theId);
0379 }
0380
0381
0382 [[nodiscard]] const BRepGraphInc::CoEdgeCurve2DRep& CoEdgeCurve2DRep(
0383 const BRepGraph_CoEdgeCurve2DRepId theId) const
0384 {
0385 return myCoEdgeCurves2D.Get(theId);
0386 }
0387
0388
0389 BRepGraphInc::CoEdgeCurve2DRep& ChangeCoEdgeCurve2DRep(const BRepGraph_CoEdgeCurve2DRepId theId)
0390 {
0391 return myCoEdgeCurves2D.Change(theId);
0392 }
0393
0394
0395 [[nodiscard]] const BRepGraphInc::CoEdgePolygon2DRep& CoEdgePolygon2DRep(
0396 const BRepGraph_CoEdgePolygon2DRepId theId) const
0397 {
0398 return myCoEdgePolygons2D.Get(theId);
0399 }
0400
0401
0402 BRepGraphInc::CoEdgePolygon2DRep& ChangeCoEdgePolygon2DRep(
0403 const BRepGraph_CoEdgePolygon2DRepId theId)
0404 {
0405 return myCoEdgePolygons2D.Change(theId);
0406 }
0407
0408
0409 [[nodiscard]] const BRepGraphInc::CoEdgePolygonOnTriRep& CoEdgePolygonOnTriRep(
0410 const BRepGraph_CoEdgePolygonOnTriRepId theId) const
0411 {
0412 return myCoEdgePolygonsOnTri.Get(theId);
0413 }
0414
0415
0416 BRepGraphInc::CoEdgePolygonOnTriRep& ChangeCoEdgePolygonOnTriRep(
0417 const BRepGraph_CoEdgePolygonOnTriRepId theId)
0418 {
0419 return myCoEdgePolygonsOnTri.Change(theId);
0420 }
0421
0422
0423 [[nodiscard]] const BRepGraphInc::FaceSurfaceRep& FaceSurfaceRep(
0424 const BRepGraph_FaceSurfaceRepId theId) const
0425 {
0426 return myFaceSurfaces.Get(theId);
0427 }
0428
0429
0430 BRepGraphInc::FaceSurfaceRep& ChangeFaceSurfaceRep(const BRepGraph_FaceSurfaceRepId theId)
0431 {
0432 return myFaceSurfaces.Change(theId);
0433 }
0434
0435
0436 [[nodiscard]] const BRepGraphInc::FaceTriangulationRep& FaceTriangulationRep(
0437 const BRepGraph_FaceTriangulationRepId theId) const
0438 {
0439 return myFaceTriangulations.Get(theId);
0440 }
0441
0442
0443 BRepGraphInc::FaceTriangulationRep& ChangeFaceTriangulationRep(
0444 const BRepGraph_FaceTriangulationRepId theId)
0445 {
0446 return myFaceTriangulations.Change(theId);
0447 }
0448
0449
0450 BRepGraph_EdgeCurve3DRepId AppendEdgeCurve3DRep() { return myEdgeCurves3D.Append(); }
0451
0452
0453 BRepGraph_EdgePolygon3DRepId AppendEdgePolygon3DRep() { return myEdgePolygons3D.Append(); }
0454
0455
0456 BRepGraph_CoEdgeCurve2DRepId AppendCoEdgeCurve2DRep() { return myCoEdgeCurves2D.Append(); }
0457
0458
0459 BRepGraph_CoEdgePolygon2DRepId AppendCoEdgePolygon2DRep() { return myCoEdgePolygons2D.Append(); }
0460
0461
0462 BRepGraph_CoEdgePolygonOnTriRepId AppendCoEdgePolygonOnTriRep()
0463 {
0464 return myCoEdgePolygonsOnTri.Append();
0465 }
0466
0467
0468 BRepGraph_FaceSurfaceRepId AppendFaceSurfaceRep() { return myFaceSurfaces.Append(); }
0469
0470
0471 BRepGraph_FaceTriangulationRepId AppendFaceTriangulationRep()
0472 {
0473 return myFaceTriangulations.Append();
0474 }
0475
0476
0477
0478
0479 Standard_EXPORT bool MarkRemoved(const BRepGraph_RepId theRepId);
0480
0481
0482
0483
0484 Standard_EXPORT void SetRemoved(const BRepGraph_RepId theRepId, const bool theVal);
0485
0486
0487
0488 [[nodiscard]] const BRepGraphInc::VertexDef& Vertex(const BRepGraph_VertexId theVertex) const
0489 {
0490 return myVertices.Get(theVertex);
0491 }
0492
0493
0494
0495 [[nodiscard]] const BRepGraphInc::EdgeDef& Edge(const BRepGraph_EdgeId theEdge) const
0496 {
0497 return myEdges.Get(theEdge);
0498 }
0499
0500
0501
0502 [[nodiscard]] const BRepGraphInc::CoEdgeDef& CoEdge(const BRepGraph_CoEdgeId theCoEdge) const
0503 {
0504 return myCoEdges.Get(theCoEdge);
0505 }
0506
0507
0508
0509 [[nodiscard]] const BRepGraphInc::WireDef& Wire(const BRepGraph_WireId theWire) const
0510 {
0511 return myWires.Get(theWire);
0512 }
0513
0514
0515
0516 [[nodiscard]] const BRepGraphInc::FaceDef& Face(const BRepGraph_FaceId theFace) const
0517 {
0518 return myFaces.Get(theFace);
0519 }
0520
0521
0522
0523 [[nodiscard]] const BRepGraphInc::ShellDef& Shell(const BRepGraph_ShellId theShell) const
0524 {
0525 return myShells.Get(theShell);
0526 }
0527
0528
0529
0530 [[nodiscard]] const BRepGraphInc::SolidDef& Solid(const BRepGraph_SolidId theSolid) const
0531 {
0532 return mySolids.Get(theSolid);
0533 }
0534
0535
0536
0537 [[nodiscard]] const BRepGraphInc::CompoundDef& Compound(
0538 const BRepGraph_CompoundId theCompound) const
0539 {
0540 return myCompounds.Get(theCompound);
0541 }
0542
0543
0544
0545 [[nodiscard]] const BRepGraphInc::CompSolidDef& CompSolid(
0546 const BRepGraph_CompSolidId theCompSolid) const
0547 {
0548 return myCompSolids.Get(theCompSolid);
0549 }
0550
0551
0552
0553 [[nodiscard]] const BRepGraphInc::ProductDef& Product(const BRepGraph_ProductId theProduct) const
0554 {
0555 return myProducts.Get(theProduct);
0556 }
0557
0558
0559
0560 [[nodiscard]] const BRepGraphInc::OccurrenceDef& Occurrence(
0561 const BRepGraph_OccurrenceId theOccurrence) const
0562 {
0563 return myOccurrences.Get(theOccurrence);
0564 }
0565
0566
0567 [[nodiscard]] const BRepGraphInc::ShellRef& ShellRef(const BRepGraph_ShellRefId theRefId) const
0568 {
0569 return myShellRefs.Get(theRefId);
0570 }
0571
0572
0573 [[nodiscard]] const BRepGraphInc::FaceRef& FaceRef(const BRepGraph_FaceRefId theRefId) const
0574 {
0575 return myFaceRefs.Get(theRefId);
0576 }
0577
0578
0579 [[nodiscard]] const BRepGraphInc::WireRef& WireRef(const BRepGraph_WireRefId theRefId) const
0580 {
0581 return myWireRefs.Get(theRefId);
0582 }
0583
0584
0585 [[nodiscard]] const BRepGraphInc::VertexRef& VertexRef(const BRepGraph_VertexRefId theRefId) const
0586 {
0587 return myVertexRefs.Get(theRefId);
0588 }
0589
0590
0591 [[nodiscard]] const BRepGraphInc::SolidRef& SolidRef(const BRepGraph_SolidRefId theRefId) const
0592 {
0593 return mySolidRefs.Get(theRefId);
0594 }
0595
0596
0597 [[nodiscard]] const BRepGraphInc::ChildRef& ChildRef(const BRepGraph_ChildRefId theRefId) const
0598 {
0599 return myChildRefs.Get(theRefId);
0600 }
0601
0602
0603 [[nodiscard]] const BRepGraphInc::OccurrenceRef& OccurrenceRef(
0604 const BRepGraph_OccurrenceRefId theRefId) const
0605 {
0606 return myOccurrenceRefs.Get(theRefId);
0607 }
0608
0609
0610
0611 BRepGraphInc::VertexDef& ChangeVertex(const BRepGraph_VertexId theVertex)
0612 {
0613 return myVertices.Change(theVertex);
0614 }
0615
0616
0617
0618 BRepGraphInc::EdgeDef& ChangeEdge(const BRepGraph_EdgeId theEdge)
0619 {
0620 return myEdges.Change(theEdge);
0621 }
0622
0623
0624
0625 BRepGraphInc::CoEdgeDef& ChangeCoEdge(const BRepGraph_CoEdgeId theCoEdge)
0626 {
0627 return myCoEdges.Change(theCoEdge);
0628 }
0629
0630
0631
0632 BRepGraphInc::WireDef& ChangeWire(const BRepGraph_WireId theWire)
0633 {
0634 return myWires.Change(theWire);
0635 }
0636
0637
0638
0639 BRepGraphInc::FaceDef& ChangeFace(const BRepGraph_FaceId theFace)
0640 {
0641 return myFaces.Change(theFace);
0642 }
0643
0644
0645
0646 BRepGraphInc::ShellDef& ChangeShell(const BRepGraph_ShellId theShell)
0647 {
0648 return myShells.Change(theShell);
0649 }
0650
0651
0652
0653 BRepGraphInc::SolidDef& ChangeSolid(const BRepGraph_SolidId theSolid)
0654 {
0655 return mySolids.Change(theSolid);
0656 }
0657
0658
0659
0660 BRepGraphInc::CompoundDef& ChangeCompound(const BRepGraph_CompoundId theCompound)
0661 {
0662 return myCompounds.Change(theCompound);
0663 }
0664
0665
0666
0667 BRepGraphInc::CompSolidDef& ChangeCompSolid(const BRepGraph_CompSolidId theCompSolid)
0668 {
0669 return myCompSolids.Change(theCompSolid);
0670 }
0671
0672
0673
0674 BRepGraphInc::ProductDef& ChangeProduct(const BRepGraph_ProductId theProduct)
0675 {
0676 return myProducts.Change(theProduct);
0677 }
0678
0679
0680
0681 BRepGraphInc::OccurrenceDef& ChangeOccurrence(const BRepGraph_OccurrenceId theOccurrence)
0682 {
0683 return myOccurrences.Change(theOccurrence);
0684 }
0685
0686
0687 BRepGraphInc::ShellRef& ChangeShellRef(const BRepGraph_ShellRefId theRefId)
0688 {
0689 return myShellRefs.Change(theRefId);
0690 }
0691
0692
0693 BRepGraphInc::FaceRef& ChangeFaceRef(const BRepGraph_FaceRefId theRefId)
0694 {
0695 return myFaceRefs.Change(theRefId);
0696 }
0697
0698
0699 BRepGraphInc::WireRef& ChangeWireRef(const BRepGraph_WireRefId theRefId)
0700 {
0701 return myWireRefs.Change(theRefId);
0702 }
0703
0704
0705 BRepGraphInc::VertexRef& ChangeVertexRef(const BRepGraph_VertexRefId theRefId)
0706 {
0707 return myVertexRefs.Change(theRefId);
0708 }
0709
0710
0711 BRepGraphInc::SolidRef& ChangeSolidRef(const BRepGraph_SolidRefId theRefId)
0712 {
0713 return mySolidRefs.Change(theRefId);
0714 }
0715
0716
0717 BRepGraphInc::ChildRef& ChangeChildRef(const BRepGraph_ChildRefId theRefId)
0718 {
0719 return myChildRefs.Change(theRefId);
0720 }
0721
0722
0723 BRepGraphInc::OccurrenceRef& ChangeOccurrenceRef(const BRepGraph_OccurrenceRefId theRefId)
0724 {
0725 return myOccurrenceRefs.Change(theRefId);
0726 }
0727
0728
0729
0730
0731 [[nodiscard]] const BRepGraphInc::FaceRelations& FaceRelations(const BRepGraph_FaceId theId) const
0732 {
0733 return myFaceRelations.Value(static_cast<size_t>(theId.Index));
0734 }
0735
0736
0737
0738
0739 [[nodiscard]] const BRepGraphInc::WireRelations& WireRelations(const BRepGraph_WireId theId) const
0740 {
0741 return myWireRelations.Value(static_cast<size_t>(theId.Index));
0742 }
0743
0744
0745
0746
0747 [[nodiscard]] const BRepGraphInc::EdgeRelations& EdgeRelations(const BRepGraph_EdgeId theId) const
0748 {
0749 return myEdgeRelations.Value(static_cast<size_t>(theId.Index));
0750 }
0751
0752
0753
0754
0755 [[nodiscard]] const BRepGraphInc::ShellRelations& ShellRelations(
0756 const BRepGraph_ShellId theId) const
0757 {
0758 return myShellRelations.Value(static_cast<size_t>(theId.Index));
0759 }
0760
0761
0762
0763
0764 [[nodiscard]] const BRepGraphInc::SolidRelations& SolidRelations(
0765 const BRepGraph_SolidId theId) const
0766 {
0767 return mySolidRelations.Value(static_cast<size_t>(theId.Index));
0768 }
0769
0770
0771
0772
0773 [[nodiscard]] const BRepGraphInc::CompoundRelations& CompoundRelations(
0774 const BRepGraph_CompoundId theId) const
0775 {
0776 return myCompoundRelations.Value(static_cast<size_t>(theId.Index));
0777 }
0778
0779
0780
0781
0782 [[nodiscard]] const BRepGraphInc::CompSolidRelations& CompSolidRelations(
0783 const BRepGraph_CompSolidId theId) const
0784 {
0785 return myCompSolidRelations.Value(static_cast<size_t>(theId.Index));
0786 }
0787
0788
0789
0790
0791 [[nodiscard]] const BRepGraphInc::VertexRelations& VertexRelations(
0792 const BRepGraph_VertexId theId) const
0793 {
0794 return myVertexRelations.Value(static_cast<size_t>(theId.Index));
0795 }
0796
0797
0798
0799
0800 [[nodiscard]] const BRepGraphInc::ProductRelations& ProductRelations(
0801 const BRepGraph_ProductId theId) const
0802 {
0803 return myProductRelations.Value(static_cast<size_t>(theId.Index));
0804 }
0805
0806
0807
0808
0809 [[nodiscard]] const BRepGraphInc::OccurrenceRelations& OccurrenceRelations(
0810 const BRepGraph_OccurrenceId theId) const
0811 {
0812 return myOccurrenceRelations.Value(static_cast<size_t>(theId.Index));
0813 }
0814
0815
0816
0817
0818 [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_ChildRefId>&
0819 CompoundRefsOfNode(const BRepGraph_NodeId theNode) const;
0820
0821
0822
0823
0824 [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_OccurrenceRefId>&
0825 OccurrenceRefsOfNode(const BRepGraph_NodeId theNode) const;
0826
0827
0828 BRepGraph_VertexId AppendVertex()
0829 {
0830 const BRepGraph_VertexId anId = myVertices.Append();
0831 myVertexRelations.Appended();
0832 return anId;
0833 }
0834
0835
0836 BRepGraph_EdgeId AppendEdge()
0837 {
0838 const BRepGraph_EdgeId anId = myEdges.Append();
0839 myEdgeRelations.Appended();
0840 return anId;
0841 }
0842
0843
0844 BRepGraph_CoEdgeId AppendCoEdge() { return myCoEdges.Append(); }
0845
0846
0847 BRepGraph_WireId AppendWire()
0848 {
0849 const BRepGraph_WireId anId = myWires.Append();
0850 myWireRelations.Appended();
0851 return anId;
0852 }
0853
0854
0855 BRepGraph_FaceId AppendFace()
0856 {
0857 const BRepGraph_FaceId anId = myFaces.Append();
0858 myFaceRelations.Appended();
0859 return anId;
0860 }
0861
0862
0863 BRepGraph_ShellId AppendShell()
0864 {
0865 const BRepGraph_ShellId anId = myShells.Append();
0866 myShellRelations.Appended();
0867 return anId;
0868 }
0869
0870
0871 BRepGraph_SolidId AppendSolid()
0872 {
0873 const BRepGraph_SolidId anId = mySolids.Append();
0874 mySolidRelations.Appended();
0875 return anId;
0876 }
0877
0878
0879 BRepGraph_CompoundId AppendCompound()
0880 {
0881 const BRepGraph_CompoundId anId = myCompounds.Append();
0882 myCompoundRelations.Appended();
0883 return anId;
0884 }
0885
0886
0887 BRepGraph_CompSolidId AppendCompSolid()
0888 {
0889 const BRepGraph_CompSolidId anId = myCompSolids.Append();
0890 myCompSolidRelations.Appended();
0891 return anId;
0892 }
0893
0894
0895 BRepGraph_ProductId AppendProduct()
0896 {
0897 const BRepGraph_ProductId anId = myProducts.Append();
0898 myProductRelations.Appended();
0899 return anId;
0900 }
0901
0902
0903 BRepGraph_OccurrenceId AppendOccurrence()
0904 {
0905 const BRepGraph_OccurrenceId anId = myOccurrences.Append();
0906 myOccurrenceRelations.Appended();
0907 return anId;
0908 }
0909
0910
0911 BRepGraph_ShellRefId AppendShellRef() { return myShellRefs.Append(); }
0912
0913
0914 BRepGraph_FaceRefId AppendFaceRef() { return myFaceRefs.Append(); }
0915
0916
0917 BRepGraph_WireRefId AppendWireRef() { return myWireRefs.Append(); }
0918
0919
0920 BRepGraph_VertexRefId AppendVertexRef() { return myVertexRefs.Append(); }
0921
0922
0923 BRepGraph_SolidRefId AppendSolidRef() { return mySolidRefs.Append(); }
0924
0925
0926 BRepGraph_ChildRefId AppendChildRef() { return myChildRefs.Append(); }
0927
0928
0929 BRepGraph_OccurrenceRefId AppendOccurrenceRef() { return myOccurrenceRefs.Append(); }
0930
0931
0932
0933
0934
0935
0936
0937 Standard_EXPORT BRepGraph_CoEdgeId
0938 CreateCoEdgeUse(const BRepGraph_WireId theParentWireId,
0939 const BRepGraph_EdgeId theChildEdgeId,
0940 const BRepGraph_FaceId theFaceId,
0941 const BRepGraphInc::ParityOrientation theOrientation);
0942
0943
0944
0945
0946 Standard_EXPORT void AttachEdgeToVertex(const BRepGraph_EdgeId theEdgeId,
0947 const BRepGraph_VertexId theVertexId);
0948
0949
0950
0951
0952
0953
0954 Standard_EXPORT BRepGraph_WireRefId
0955 AttachWireToFace(const BRepGraph_FaceId theParentFaceId,
0956 const BRepGraph_WireId theChildWireId,
0957 const BRepGraphInc::ParityOrientation theOrientation = TopAbs_FORWARD);
0958
0959
0960
0961
0962
0963
0964 Standard_EXPORT BRepGraph_FaceRefId
0965 AttachFaceToShell(const BRepGraph_ShellId theParentShellId,
0966 const BRepGraph_FaceId theChildFaceId,
0967 const BRepGraphInc::ParityOrientation theOrientation = TopAbs_FORWARD);
0968
0969
0970
0971
0972
0973
0974 Standard_EXPORT BRepGraph_ShellRefId
0975 AttachShellToSolid(const BRepGraph_SolidId theParentSolidId,
0976 const BRepGraph_ShellId theChildShellId,
0977 const BRepGraphInc::ParityOrientation theOrientation = TopAbs_FORWARD);
0978
0979
0980
0981
0982
0983
0984 Standard_EXPORT BRepGraph_SolidRefId
0985 AttachSolidToCompSolid(const BRepGraph_CompSolidId theParentCompSolidId,
0986 const BRepGraph_SolidId theChildSolidId,
0987 const BRepGraphInc::ParityOrientation theOrientation = TopAbs_FORWARD);
0988
0989
0990
0991
0992
0993
0994
0995 Standard_EXPORT BRepGraph_ChildRefId
0996 AttachChildToCompound(const BRepGraph_CompoundId theParentCompoundId,
0997 const BRepGraph_NodeId theChildNodeId,
0998 const TopLoc_Location& theLocation = TopLoc_Location(),
0999 const BRepGraphInc::ParityOrientation theOrientation = TopAbs_FORWARD);
1000
1001
1002
1003
1004
1005
1006 Standard_EXPORT BRepGraph_OccurrenceRefId
1007 AttachOccurrenceToProduct(const BRepGraph_ProductId theParentProductId,
1008 const BRepGraph_OccurrenceId theChildOccurrenceId,
1009 const TopLoc_Location& theLocation = TopLoc_Location());
1010
1011
1012
1013
1014
1015 Standard_EXPORT bool DetachCoEdgeUse(const BRepGraph_WireId theParentWireId,
1016 const BRepGraph_CoEdgeId theCoEdgeId);
1017
1018
1019
1020
1021
1022
1023
1024 Standard_EXPORT bool ReplaceCoEdgeUseWithPair(const BRepGraph_WireId theParentWireId,
1025 const BRepGraph_CoEdgeId theOldCoEdgeId,
1026 const BRepGraph_CoEdgeId theNewFirstCoEdgeId,
1027 const BRepGraph_CoEdgeId theNewSecondCoEdgeId);
1028
1029
1030
1031
1032
1033 Standard_EXPORT bool DetachWireFromFace(const BRepGraph_FaceId theParentFaceId,
1034 const BRepGraph_WireRefId theRefId);
1035
1036
1037
1038
1039
1040 Standard_EXPORT bool DetachFaceFromShell(const BRepGraph_ShellId theParentShellId,
1041 const BRepGraph_FaceRefId theRefId);
1042
1043
1044
1045
1046
1047 Standard_EXPORT bool DetachShellFromSolid(const BRepGraph_SolidId theParentSolidId,
1048 const BRepGraph_ShellRefId theRefId);
1049
1050
1051
1052
1053
1054 Standard_EXPORT bool DetachSolidFromCompSolid(const BRepGraph_CompSolidId theParentCompSolidId,
1055 const BRepGraph_SolidRefId theRefId);
1056
1057
1058
1059
1060
1061 Standard_EXPORT bool DetachChildFromCompound(const BRepGraph_CompoundId theParentCompoundId,
1062 const BRepGraph_ChildRefId theRefId);
1063
1064
1065
1066
1067
1068 Standard_EXPORT bool DetachOccurrenceFromProduct(const BRepGraph_ProductId theParentProductId,
1069 const BRepGraph_OccurrenceRefId theRefId);
1070
1071
1072
1073
1074
1075 Standard_EXPORT void RebindOccurrenceChild(const BRepGraph_OccurrenceId theOccurrence,
1076 const BRepGraph_NodeId theOldChild,
1077 const BRepGraph_NodeId theNewChild);
1078
1079
1080
1081
1082
1083
1084 Standard_EXPORT void RebindVertexEdge(const BRepGraph_VertexId theOldVertex,
1085 const BRepGraph_VertexId theNewVertex,
1086 const BRepGraph_EdgeId theEdge,
1087 const BRepGraph_VertexRefId theExcludingRef);
1088
1089
1090
1091
1092
1093 Standard_EXPORT void RebindVertexRef(const BRepGraph_VertexRefId theRefId,
1094 const BRepGraph_VertexId theOldVertex,
1095 const BRepGraph_VertexId theNewVertex);
1096
1097
1098
1099
1100
1101 Standard_EXPORT void RebindCoEdgeEdge(const BRepGraph_CoEdgeId theCoEdge,
1102 const BRepGraph_EdgeId theOldEdge,
1103 const BRepGraph_EdgeId theNewEdge);
1104
1105
1106
1107
1108
1109 Standard_EXPORT void RebindWireRef(const BRepGraph_WireRefId theRefId,
1110 const BRepGraph_WireId theOldWire,
1111 const BRepGraph_WireId theNewWire);
1112
1113
1114
1115
1116
1117 Standard_EXPORT void RebindFaceRef(const BRepGraph_FaceRefId theRefId,
1118 const BRepGraph_FaceId theOldFace,
1119 const BRepGraph_FaceId theNewFace);
1120
1121
1122
1123
1124
1125 Standard_EXPORT void RebindShellRef(const BRepGraph_ShellRefId theRefId,
1126 const BRepGraph_ShellId theOldShell,
1127 const BRepGraph_ShellId theNewShell);
1128
1129
1130
1131
1132
1133 Standard_EXPORT void RebindSolidRef(const BRepGraph_SolidRefId theRefId,
1134 const BRepGraph_SolidId theOldSolid,
1135 const BRepGraph_SolidId theNewSolid);
1136
1137
1138
1139
1140
1141 Standard_EXPORT void RebindChildRef(const BRepGraph_ChildRefId theRefId,
1142 const BRepGraph_NodeId theOldChild,
1143 const BRepGraph_NodeId theNewChild);
1144
1145
1146
1147
1148
1149 Standard_EXPORT void RebindOccurrenceRef(const BRepGraph_OccurrenceRefId theRefId,
1150 const BRepGraph_OccurrenceId theOldOccurrence,
1151 const BRepGraph_OccurrenceId theNewOccurrence);
1152
1153
1154
1155 Standard_EXPORT void ReverseWireCoEdges(const BRepGraph_WireId theWireId);
1156
1157
1158
1159
1160 Standard_EXPORT void SetWireCoEdges(const BRepGraph_WireId theWireId,
1161 const NCollection_Array1<BRepGraph_CoEdgeId>& theCoEdgeIds);
1162
1163
1164
1165
1166 Standard_EXPORT void SetFaceWireRefs(
1167 const BRepGraph_FaceId theFaceId,
1168 const NCollection_Array1<BRepGraph_WireRefId>& theWireRefIds);
1169
1170
1171
1172
1173 Standard_EXPORT void SetShellFaceRefs(
1174 const BRepGraph_ShellId theShellId,
1175 const NCollection_Array1<BRepGraph_FaceRefId>& theFaceRefIds);
1176
1177
1178
1179
1180 Standard_EXPORT void SetSolidShellRefs(
1181 const BRepGraph_SolidId theSolidId,
1182 const NCollection_Array1<BRepGraph_ShellRefId>& theShellRefIds);
1183
1184
1185
1186
1187 Standard_EXPORT void SetCompSolidSolidRefs(
1188 const BRepGraph_CompSolidId theCompSolidId,
1189 const NCollection_Array1<BRepGraph_SolidRefId>& theSolidRefIds);
1190
1191
1192
1193
1194 Standard_EXPORT void SetCompoundChildRefs(
1195 const BRepGraph_CompoundId theCompoundId,
1196 const NCollection_Array1<BRepGraph_ChildRefId>& theChildRefIds);
1197
1198
1199
1200
1201 Standard_EXPORT void SetProductOccurrenceRefs(
1202 const BRepGraph_ProductId theProductId,
1203 const NCollection_Array1<BRepGraph_OccurrenceRefId>& theOccurrenceRefIds);
1204
1205
1206
1207
1208 [[nodiscard]] Standard_EXPORT const BRepGraphInc::BaseRef& BaseRef(
1209 const BRepGraph_RefId theRefId) const;
1210
1211
1212
1213
1214 [[nodiscard]] Standard_EXPORT BRepGraphInc::BaseRef* ChangeBaseRef(
1215 const BRepGraph_RefId theRefId);
1216
1217
1218 [[nodiscard]] Standard_EXPORT BRepGraph_NodeId FindNodeIdByUID(const BRepGraph_UID& theUID) const;
1219
1220
1221 [[nodiscard]] Standard_EXPORT BRepGraph_RefId
1222 FindRefIdByUID(const BRepGraph_RefUID& theUID) const;
1223
1224
1225 [[nodiscard]] Standard_EXPORT BRepGraph_NodeId
1226 FindDefinitionByShape(const TopoDS_Shape& theShape) const;
1227
1228
1229 [[nodiscard]] Standard_EXPORT bool HasShapeBinding(const TopoDS_Shape& theShape) const;
1230
1231
1232
1233 Standard_EXPORT void SetDefinitionShapeBinding(const TopoDS_Shape& theShape,
1234 const BRepGraph_NodeId theNodeId);
1235
1236
1237
1238 Standard_EXPORT bool RemoveDefinitionShapeBinding(const TopoDS_Shape& theShape,
1239 const BRepGraph_NodeId theExpectedNodeId);
1240
1241
1242
1243
1244
1245 [[nodiscard]] Standard_EXPORT TopoDS_Shape FindOriginal(const BRepGraph_NodeId theNodeId) const;
1246
1247
1248 [[nodiscard]] Standard_EXPORT bool HasOriginal(const BRepGraph_NodeId theNodeId) const;
1249
1250
1251 Standard_EXPORT void BindOriginal(const BRepGraph_NodeId theNodeId, const TopoDS_Shape& theShape);
1252
1253
1254 Standard_EXPORT void UnBindOriginal(const BRepGraph_NodeId theNodeId);
1255
1256
1257
1258 template <typename FuncT>
1259 void ForEachShapeBinding(FuncT&& theFunc) const
1260 {
1261 std::shared_lock<std::shared_mutex> aLock(myShapeBindingsMutex);
1262 for (NCollection_FlatDataMap<TopoDS_Shape, BRepGraph_NodeId, TopTools_ShapeMapHasher>::Iterator
1263 anIt(myShapeToNodeId);
1264 anIt.More();
1265 anIt.Next())
1266 {
1267 theFunc(anIt.Key(), anIt.Value());
1268 }
1269 }
1270
1271
1272
1273 template <typename FuncT>
1274 void ForEachOriginalBinding(FuncT&& theFunc) const
1275 {
1276 std::shared_lock<std::shared_mutex> aLock(myShapeBindingsMutex);
1277 for (NCollection_FlatDataMap<BRepGraph_NodeId, TopoDS_Shape>::Iterator anIt(myOriginalShapes);
1278 anIt.More();
1279 anIt.Next())
1280 {
1281 theFunc(anIt.Key(), anIt.Value());
1282 }
1283 }
1284
1285
1286
1287 Standard_EXPORT void CopyShapeBindingsFrom(const BRepGraphInc_Storage& theSource);
1288
1289
1290 [[nodiscard]] const NCollection_FlatDataMap<BRepGraph_NodeId, CachedShape>& CurrentShapes() const
1291 {
1292 return myCurrentShapes;
1293 }
1294
1295
1296 NCollection_FlatDataMap<BRepGraph_NodeId, CachedShape>& ChangeCurrentShapes()
1297 {
1298 return myCurrentShapes;
1299 }
1300
1301
1302 [[nodiscard]] std::shared_mutex& CurrentShapesMutex() const { return myCurrentShapesMutex; }
1303
1304
1305 Standard_EXPORT void ClearCurrentShapes();
1306
1307
1308 Standard_EXPORT void UnbindCurrentShape(const BRepGraph_NodeId theNode);
1309
1310
1311 Standard_EXPORT void ClearDeferredQueues();
1312
1313
1314 Standard_EXPORT void Clear();
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324 Standard_EXPORT void PrepareForLoad(const BRepGraphInc_Load::Counts& theCounts);
1325
1326
1327
1328
1329
1330
1331
1332 Standard_EXPORT void SetActiveCounts(const BRepGraphInc_Load::Counts& theCounts);
1333
1334
1335 [[nodiscard]] Standard_EXPORT BRepGraphInc_Load::Counts Counts() const;
1336
1337
1338 [[nodiscard]] Standard_EXPORT BRepGraphInc_Load::Counts ActiveCounts() const;
1339
1340
1341 Standard_EXPORT void RecountActiveCounts();
1342
1343
1344
1345
1346 Standard_EXPORT void RebuildDerivedRelations();
1347
1348
1349 Standard_EXPORT void RebuildDerivedRelationsPreservingActiveCounts();
1350
1351
1352
1353 Standard_EXPORT void CopyRemovedFlagsFrom(const BRepGraphInc_Storage& theSource);
1354
1355
1356
1357 Standard_EXPORT bool ValidateRelations() const;
1358
1359
1360
1361
1362 Standard_EXPORT bool ValidateWireCoEdgeOrder(const BRepGraph_WireId theWireId) const;
1363
1364
1365
1366 Standard_EXPORT bool ValidateWireCoEdgeOrders() const;
1367
1368
1369 enum class WireCoEdgeOrderStatus
1370 {
1371 Connected,
1372 Reordered,
1373 ToleranceOrdered,
1374 Partial,
1375 InvalidInput
1376 };
1377
1378
1379
1380
1381 Standard_EXPORT WireCoEdgeOrderStatus
1382 CanonicalizeWireCoEdgeOrderStatus(const BRepGraph_WireId theWireId);
1383
1384
1385
1386
1387 Standard_EXPORT bool CanonicalizeWireCoEdgeOrder(const BRepGraph_WireId theWireId);
1388
1389
1390
1391
1392 Standard_EXPORT void RebuildUIDReverseIndexes();
1393
1394
1395 Standard_EXPORT void MarkUIDReverseIndexesDirty();
1396
1397
1398 Standard_EXPORT void EnsureUIDReverseIndex() const;
1399
1400
1401 Standard_EXPORT void EnsureRefUIDReverseIndex() const;
1402
1403
1404
1405 Standard_EXPORT void CopyDerivedRelationsFrom(const BRepGraphInc_Storage& theSource);
1406
1407 private:
1408 friend class BRepGraphInc_Populate;
1409 friend class BRepGraph;
1410
1411 Standard_EXPORT void ClearStorageForReuse();
1412 Standard_EXPORT void ClearUIDIndexes();
1413 Standard_EXPORT void ClearShapeCache();
1414 Standard_EXPORT void ClearRelations();
1415
1416 BRepGraphInc::FaceRelations& ChangeFaceRelationsInternal(const BRepGraph_FaceId theId)
1417 {
1418 return myFaceRelations.ChangeValue(static_cast<size_t>(theId.Index));
1419 }
1420
1421 BRepGraphInc::WireRelations& ChangeWireRelationsInternal(const BRepGraph_WireId theId)
1422 {
1423 return myWireRelations.ChangeValue(static_cast<size_t>(theId.Index));
1424 }
1425
1426 BRepGraphInc::EdgeRelations& ChangeEdgeRelationsInternal(const BRepGraph_EdgeId theId)
1427 {
1428 return myEdgeRelations.ChangeValue(static_cast<size_t>(theId.Index));
1429 }
1430
1431 BRepGraphInc::ShellRelations& ChangeShellRelationsInternal(const BRepGraph_ShellId theId)
1432 {
1433 return myShellRelations.ChangeValue(static_cast<size_t>(theId.Index));
1434 }
1435
1436 BRepGraphInc::SolidRelations& ChangeSolidRelationsInternal(const BRepGraph_SolidId theId)
1437 {
1438 return mySolidRelations.ChangeValue(static_cast<size_t>(theId.Index));
1439 }
1440
1441 BRepGraphInc::CompoundRelations& ChangeCompoundRelationsInternal(const BRepGraph_CompoundId theId)
1442 {
1443 return myCompoundRelations.ChangeValue(static_cast<size_t>(theId.Index));
1444 }
1445
1446 BRepGraphInc::CompSolidRelations& ChangeCompSolidRelationsInternal(
1447 const BRepGraph_CompSolidId theId)
1448 {
1449 return myCompSolidRelations.ChangeValue(static_cast<size_t>(theId.Index));
1450 }
1451
1452 BRepGraphInc::VertexRelations& ChangeVertexRelationsInternal(const BRepGraph_VertexId theId)
1453 {
1454 return myVertexRelations.ChangeValue(static_cast<size_t>(theId.Index));
1455 }
1456
1457 BRepGraphInc::ProductRelations& ChangeProductRelationsInternal(const BRepGraph_ProductId theId)
1458 {
1459 return myProductRelations.ChangeValue(static_cast<size_t>(theId.Index));
1460 }
1461
1462 BRepGraphInc::OccurrenceRelations& ChangeOccurrenceRelationsInternal(
1463 const BRepGraph_OccurrenceId theId)
1464 {
1465 return myOccurrenceRelations.ChangeValue(static_cast<size_t>(theId.Index));
1466 }
1467
1468 Standard_EXPORT NCollection_LinearVector<BRepGraph_ChildRefId>& ChangeCompoundRefsOfNodeInternal(
1469 const BRepGraph_NodeId theNode);
1470
1471 Standard_EXPORT NCollection_LinearVector<BRepGraph_OccurrenceRefId>&
1472 ChangeOccurrenceRefsOfNodeInternal(const BRepGraph_NodeId theNode);
1473
1474 Standard_EXPORT void rebuildDerivedRelationsInternal(const bool theRecountActiveCounts);
1475
1476
1477 template <typename T>
1478 [[nodiscard]] bool HasCompoundParentTyped(const T theId) const;
1479
1480
1481 template <typename T>
1482 void SetHasCompoundParentTyped(const T theId, const bool theVal);
1483
1484
1485 template <typename T>
1486 [[nodiscard]] bool HasOccurrenceParentTyped(const T theId) const;
1487
1488
1489 template <typename T>
1490 void SetHasOccurrenceParentTyped(const T theId, const bool theVal);
1491
1492
1493 Standard_EXPORT void SetHasCompoundParent(const BRepGraph_NodeId theNode, bool theVal);
1494
1495
1496 Standard_EXPORT void SetHasOccurrenceParent(const BRepGraph_NodeId theNode, bool theVal);
1497
1498
1499 template <typename EntityT>
1500 struct DefStore
1501 {
1502 using TypeId = typename EntityT::TypeId;
1503 using ValueType = EntityT;
1504
1505
1506 NCollection_DynamicArray<EntityT> Entities;
1507
1508
1509 BRepGraphInc_BitFlags RemovedFlags;
1510
1511
1512 BRepGraphInc_BitFlags OwnedFlags;
1513
1514
1515 BRepGraphInc_BitFlags GuardFlags;
1516
1517
1518 BRepGraphInc_BitFlags HasCompoundParentFlags;
1519
1520
1521 BRepGraphInc_BitFlags HasOccurrenceParentFlags;
1522
1523
1524 uint32_t NbActive = 0;
1525
1526
1527 std::atomic<uint32_t> NextUIDCounter{1};
1528
1529 DefStore() = delete;
1530
1531 DefStore(const int theBlockSize, const occ::handle<NCollection_BaseAllocator>& theAlloc)
1532 : Entities(theBlockSize, theAlloc)
1533 {
1534 }
1535
1536 uint32_t Nb() const { return static_cast<uint32_t>(Entities.Size()); }
1537
1538 const EntityT& Get(const TypeId theId) const
1539 {
1540 return Entities.Value(static_cast<size_t>(theId.Index));
1541 }
1542
1543 EntityT& Change(const TypeId theId)
1544 {
1545 return Entities.ChangeValue(static_cast<size_t>(theId.Index));
1546 }
1547
1548
1549 TypeId Append()
1550 {
1551 const TypeId anId(static_cast<uint32_t>(Entities.Size()));
1552 ++NbActive;
1553 Entities.Appended();
1554 RemovedFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1555 OwnedFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1556 GuardFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1557 HasCompoundParentFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1558 HasOccurrenceParentFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1559 return anId;
1560 }
1561
1562 void DecrementActive()
1563 {
1564 Standard_ASSERT_VOID(NbActive > 0u, "DefStore::DecrementActive: underflow");
1565 if (NbActive > 0u)
1566 {
1567 --NbActive;
1568 }
1569 }
1570
1571 bool MarkRemoved(const TypeId theId)
1572 {
1573 if (!theId.IsValid(Nb()))
1574 {
1575 return false;
1576 }
1577
1578 if (RemovedFlags.Test(theId.Index))
1579 {
1580 return false;
1581 }
1582 RemovedFlags.Set(theId.Index);
1583 DecrementActive();
1584 return true;
1585 }
1586
1587 void Clear(const bool theReleaseMemory = false)
1588 {
1589 Entities.Clear(theReleaseMemory);
1590 RemovedFlags.ClearAll();
1591 OwnedFlags.ClearAll();
1592 GuardFlags.ClearAll();
1593 HasCompoundParentFlags.ClearAll();
1594 HasOccurrenceParentFlags.ClearAll();
1595 NbActive = 0;
1596
1597
1598 }
1599 };
1600
1601
1602 template <typename RefT>
1603 struct RefStore
1604 {
1605 using TypeId = typename RefT::TypeId;
1606 using ValueType = RefT;
1607
1608
1609 NCollection_DynamicArray<RefT> Refs;
1610
1611
1612 BRepGraphInc_BitFlags RemovedFlags;
1613
1614
1615 BRepGraphInc_BitFlags OwnedFlags;
1616
1617
1618 BRepGraphInc_BitFlags GuardFlags;
1619
1620
1621
1622 BRepGraphInc_BitFlags HasCompoundParentFlags;
1623
1624
1625
1626 BRepGraphInc_BitFlags HasOccurrenceParentFlags;
1627
1628
1629 uint32_t NbActive = 0;
1630
1631
1632 std::atomic<uint32_t> NextUIDCounter{1};
1633
1634 RefStore() = delete;
1635
1636 RefStore(const int theBlockSize, const occ::handle<NCollection_BaseAllocator>& theAlloc)
1637 : Refs(theBlockSize, theAlloc)
1638 {
1639 }
1640
1641 uint32_t Nb() const { return static_cast<uint32_t>(Refs.Size()); }
1642
1643 const RefT& Get(const TypeId theId) const
1644 {
1645 return Refs.Value(static_cast<size_t>(theId.Index));
1646 }
1647
1648 RefT& Change(const TypeId theId) { return Refs.ChangeValue(static_cast<size_t>(theId.Index)); }
1649
1650
1651 TypeId Append()
1652 {
1653 const TypeId anId(static_cast<uint32_t>(Refs.Size()));
1654 ++NbActive;
1655 Refs.Appended();
1656 RemovedFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1657 OwnedFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1658 GuardFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1659 HasCompoundParentFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1660 HasOccurrenceParentFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1661 return anId;
1662 }
1663
1664 void DecrementActive()
1665 {
1666 Standard_ASSERT_VOID(NbActive > 0u, "RefStore::DecrementActive: underflow");
1667 if (NbActive > 0u)
1668 {
1669 --NbActive;
1670 }
1671 }
1672
1673 bool MarkRemoved(const TypeId theId)
1674 {
1675 if (!theId.IsValid(Nb()))
1676 {
1677 return false;
1678 }
1679
1680 if (RemovedFlags.Test(theId.Index))
1681 {
1682 return false;
1683 }
1684 RemovedFlags.Set(theId.Index);
1685 DecrementActive();
1686 return true;
1687 }
1688
1689 void Clear(const bool theReleaseMemory = false)
1690 {
1691 Refs.Clear(theReleaseMemory);
1692 RemovedFlags.ClearAll();
1693 OwnedFlags.ClearAll();
1694 GuardFlags.ClearAll();
1695 HasCompoundParentFlags.ClearAll();
1696 HasOccurrenceParentFlags.ClearAll();
1697 NbActive = 0;
1698
1699 }
1700 };
1701
1702
1703 occ::handle<NCollection_IncAllocator> myAllocator = new NCollection_IncAllocator;
1704
1705
1706 NCollection_LinearVector<BRepGraph_ProductId> myRootProductIds;
1707 NCollection_LinearVector<BRepGraph_NodeId> myDeferredModified;
1708 NCollection_LinearVector<BRepGraph_RefId> myDeferredRefModified;
1709
1710
1711 DefStore<BRepGraphInc::VertexDef> myVertices;
1712
1713
1714 DefStore<BRepGraphInc::EdgeDef> myEdges;
1715
1716
1717 DefStore<BRepGraphInc::CoEdgeDef> myCoEdges;
1718
1719
1720 DefStore<BRepGraphInc::WireDef> myWires;
1721
1722
1723 DefStore<BRepGraphInc::FaceDef> myFaces;
1724
1725
1726 DefStore<BRepGraphInc::ShellDef> myShells;
1727
1728
1729 DefStore<BRepGraphInc::SolidDef> mySolids;
1730
1731
1732 DefStore<BRepGraphInc::CompoundDef> myCompounds;
1733
1734
1735 DefStore<BRepGraphInc::CompSolidDef> myCompSolids;
1736
1737
1738 DefStore<BRepGraphInc::ProductDef> myProducts;
1739
1740
1741 DefStore<BRepGraphInc::OccurrenceDef> myOccurrences;
1742
1743
1744 RefStore<BRepGraphInc::ShellRef> myShellRefs;
1745
1746
1747 RefStore<BRepGraphInc::FaceRef> myFaceRefs;
1748
1749
1750 RefStore<BRepGraphInc::WireRef> myWireRefs;
1751
1752
1753 RefStore<BRepGraphInc::VertexRef> myVertexRefs;
1754
1755
1756 RefStore<BRepGraphInc::SolidRef> mySolidRefs;
1757
1758
1759 RefStore<BRepGraphInc::ChildRef> myChildRefs;
1760
1761
1762 RefStore<BRepGraphInc::OccurrenceRef> myOccurrenceRefs;
1763
1764
1765 NCollection_DynamicArray<BRepGraphInc::FaceRelations> myFaceRelations;
1766 NCollection_DynamicArray<BRepGraphInc::WireRelations> myWireRelations;
1767 NCollection_DynamicArray<BRepGraphInc::EdgeRelations> myEdgeRelations;
1768 NCollection_DynamicArray<BRepGraphInc::ShellRelations> myShellRelations;
1769 NCollection_DynamicArray<BRepGraphInc::SolidRelations> mySolidRelations;
1770 NCollection_DynamicArray<BRepGraphInc::CompoundRelations> myCompoundRelations;
1771 NCollection_DynamicArray<BRepGraphInc::CompSolidRelations> myCompSolidRelations;
1772 NCollection_DynamicArray<BRepGraphInc::VertexRelations> myVertexRelations;
1773 NCollection_DynamicArray<BRepGraphInc::ProductRelations> myProductRelations;
1774 NCollection_DynamicArray<BRepGraphInc::OccurrenceRelations> myOccurrenceRelations;
1775
1776
1777 NCollection_DataMap<BRepGraph_NodeId, NCollection_LinearVector<BRepGraph_ChildRefId>>
1778 myNodeToCompounds;
1779
1780
1781 NCollection_DataMap<BRepGraph_NodeId, NCollection_LinearVector<BRepGraph_OccurrenceRefId>>
1782 myNodeToOccurrences;
1783
1784
1785 template <typename UseT>
1786 struct RepStore
1787 {
1788 using TypeId = typename UseT::TypeId;
1789
1790 NCollection_DynamicArray<UseT> Uses;
1791 BRepGraphInc_BitFlags RemovedFlags;
1792 uint32_t NbActive = 0;
1793
1794 RepStore() = delete;
1795
1796 RepStore(const int theBlockSize, const occ::handle<NCollection_BaseAllocator>& theAlloc)
1797 : Uses(theBlockSize, theAlloc)
1798 {
1799 }
1800
1801 uint32_t Nb() const { return static_cast<uint32_t>(Uses.Size()); }
1802
1803 const UseT& Get(const TypeId theId) const
1804 {
1805 return Uses.Value(static_cast<size_t>(theId.Index));
1806 }
1807
1808 UseT& Change(const TypeId theId) { return Uses.ChangeValue(static_cast<size_t>(theId.Index)); }
1809
1810 TypeId Append()
1811 {
1812 const TypeId anId(static_cast<uint32_t>(Uses.Size()));
1813 ++NbActive;
1814 Uses.Appended();
1815 RemovedFlags.Resize(static_cast<size_t>(anId.Index) + 1);
1816 return anId;
1817 }
1818
1819 void DecrementActive()
1820 {
1821 Standard_ASSERT_VOID(NbActive > 0u, "RepStore::DecrementActive: underflow");
1822 if (NbActive > 0u)
1823 {
1824 --NbActive;
1825 }
1826 }
1827
1828 bool MarkRemoved(const TypeId theId)
1829 {
1830 if (!theId.IsValid(Nb()))
1831 {
1832 return false;
1833 }
1834 if (RemovedFlags.Test(theId.Index))
1835 {
1836 return false;
1837 }
1838 RemovedFlags.Set(theId.Index);
1839 DecrementActive();
1840 return true;
1841 }
1842
1843 bool IsRemoved(const TypeId theId) const
1844 {
1845 return theId.IsValid(Nb()) && RemovedFlags.Test(theId.Index);
1846 }
1847
1848 void Clear(const bool theReleaseMemory = false)
1849 {
1850 Uses.Clear(theReleaseMemory);
1851 RemovedFlags.ClearAll();
1852 NbActive = 0;
1853 }
1854 };
1855
1856
1857 RepStore<BRepGraphInc::EdgeCurve3DRep> myEdgeCurves3D;
1858
1859
1860 RepStore<BRepGraphInc::EdgePolygon3DRep> myEdgePolygons3D;
1861
1862
1863 RepStore<BRepGraphInc::CoEdgeCurve2DRep> myCoEdgeCurves2D;
1864
1865
1866 RepStore<BRepGraphInc::CoEdgePolygon2DRep> myCoEdgePolygons2D;
1867
1868
1869 RepStore<BRepGraphInc::CoEdgePolygonOnTriRep> myCoEdgePolygonsOnTri;
1870
1871
1872 RepStore<BRepGraphInc::FaceSurfaceRep> myFaceSurfaces;
1873
1874
1875 RepStore<BRepGraphInc::FaceTriangulationRep> myFaceTriangulations;
1876
1877
1878 mutable NCollection_FlatDataMap<BRepGraph_UID, BRepGraph_NodeId> myUIDToNodeId;
1879 mutable std::shared_mutex myUIDToNodeIdMutex;
1880 mutable NCollection_FlatDataMap<BRepGraph_RefUID, BRepGraph_RefId> myRefUIDToRefId;
1881 mutable std::shared_mutex myRefUIDToRefIdMutex;
1882 mutable std::atomic<bool> myUIDToNodeIdDirty{false};
1883 mutable std::atomic<bool> myRefUIDToRefIdDirty{false};
1884
1885
1886 NCollection_FlatDataMap<TopoDS_Shape, BRepGraph_NodeId, TopTools_ShapeMapHasher> myShapeToNodeId;
1887 NCollection_FlatDataMap<BRepGraph_NodeId, TopoDS_Shape> myOriginalShapes;
1888 mutable std::shared_mutex myShapeBindingsMutex;
1889
1890
1891 std::atomic<uint32_t> myGeneration{0};
1892 Standard_GUID myGraphGUID;
1893
1894
1895 std::atomic<bool> myDeferredMode{false};
1896 std::atomic<uint32_t> myPropagationWave{0};
1897 uint32_t myRemoveSubgraphDepth = 0;
1898
1899
1900 mutable NCollection_FlatDataMap<BRepGraph_NodeId, CachedShape> myCurrentShapes;
1901 mutable std::shared_mutex myCurrentShapesMutex;
1902
1903 private:
1904
1905
1906 template <typename T>
1907 struct TypedStorePlanes;
1908
1909 template <typename T>
1910 friend struct TypedStorePlanes;
1911
1912 template <typename T>
1913 [[nodiscard]] bool isInRange(const T theId) const;
1914
1915 template <typename FuncT>
1916 [[nodiscard]] bool dispatchItemId(const BRepGraph_ItemId& theId, FuncT&& theFunc) const;
1917
1918 public:
1919
1920
1921 template <typename T>
1922 [[nodiscard]] bool IsRemoved(const T theId) const;
1923
1924
1925
1926
1927 template <typename T>
1928 void SetRemoved(const T theId, const bool theVal);
1929
1930
1931
1932 template <typename T>
1933 [[nodiscard]] bool IsOwned(const T theId) const;
1934
1935
1936
1937
1938 template <typename T>
1939 void SetOwned(const T theId, const bool theVal);
1940
1941
1942
1943 template <typename T>
1944 [[nodiscard]] bool IsGuarded(const T theId) const;
1945
1946
1947
1948 template <typename T>
1949 void SetGuarded(const T theId);
1950
1951
1952
1953 template <typename T>
1954 void ClearGuarded(const T theId);
1955
1956
1957
1958
1959 [[nodiscard]] Standard_EXPORT bool HasCompoundParent(const BRepGraph_NodeId theNode) const;
1960
1961
1962
1963
1964 [[nodiscard]] Standard_EXPORT bool HasOccurrenceParent(const BRepGraph_NodeId theNode) const;
1965
1966
1967
1968 [[nodiscard]] bool IsGuarded(const BRepGraph_ItemId& theId) const;
1969
1970
1971
1972 void SetGuarded(const BRepGraph_ItemId& theId);
1973
1974
1975
1976 void ClearGuarded(const BRepGraph_ItemId& theId);
1977
1978
1979
1980 [[nodiscard]] Standard_EXPORT bool HasAnyGuard() const;
1981 };
1982
1983 #include <BRepGraphInc_Storage.lxx>
1984
1985 #endif