Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:36

0001 // Copyright (c) 2026 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepGraph_RefsView_HeaderFile
0015 #define _BRepGraph_RefsView_HeaderFile
0016 
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraphInc_Reference.hxx>
0019 #include <BRepGraph_VersionStamp.hxx>
0020 #include <NCollection_LinearVector.hxx>
0021 
0022 //! @brief Read-only view for RefId/RefUID-based reference storage.
0023 //!
0024 //! This view exposes reference-entry storage:
0025 //! - typed reference entry access (Shell, Face, ...)
0026 //! - reference counts
0027 //! - RefUID lookup and reverse lookup through BRepGraph::UIDs()
0028 //! - freshness checks via BRepGraph_VersionStamp through BRepGraph::UIDs()
0029 //!
0030 //! Identity semantics:
0031 //! - RefId (kind + index) is graph-local and may change after Compact().
0032 //!   Use it for in-graph traversal and short-lived mutation logic.
0033 //! - RefUID (kind + counter) is stable across index remapping and intended
0034 //!   for longer-lived identity tracking. Graph generation is carried by
0035 //!   BRepGraph_VersionStamp when freshness checks are needed.
0036 //!
0037 //! ## RefsView vs TopoView naming
0038 //! RefsView accessors take reference IDs (BRepGraph_ShellRefId, BRepGraph_FaceRefId)
0039 //! and return reference-entry structs carrying per-use orientation and location.
0040 //! TopoView accessors take definition IDs (BRepGraph_ShellId, BRepGraph_FaceId)
0041 //! and return definition structs.
0042 //!
0043 //! ## Iterating over references
0044 //! Reference entries are primarily traversed in parent-owned context through
0045 //! the typed grouped IdsOf accessors. When flat iteration is needed, iterate
0046 //! using the matching typed RefId over the appropriate grouped Nb() or NbActive() count:
0047 //! @code
0048 //!   const BRepGraph::RefsView& aRefs = aGraph.Refs();
0049 //!   const BRepGraph_FaceRefId anEndFaceRefId = aRefs.Faces().EndId();
0050 //!   for (BRepGraph_FaceRefId aFaceRefId = aRefs.Faces().StartId();
0051 //!        aFaceRefId < anEndFaceRefId;
0052 //!        ++aFaceRefId)
0053 //!   {
0054 //!     const BRepGraphInc::FaceRef& aFR = aRefs.Faces().Entry(aFaceRefId);
0055 //!     if (aFR.IsRemoved)
0056 //!       continue;
0057 //!     // use aFR.FaceId, aFR.Orientation, aFR.Location ...
0058 //!   }
0059 //! @endcode
0060 //!
0061 //! To iterate refs belonging to a specific parent, use the grouped IdsOf
0062 //! accessors:
0063 //! @code
0064 //!   for (const BRepGraph_WireRefId& aWireRefId : aRefs.Wires().IdsOf(aFaceId))
0065 //!   {
0066 //!     const BRepGraphInc::WireRef& aWR = aRefs.Wires().Entry(aWireRefId);
0067 //!     // ...
0068 //!   }
0069 //! @endcode
0070 class BRepGraph::RefsView
0071 {
0072 public:
0073   //! @brief Shell reference queries.
0074   class ShellOps
0075   {
0076   public:
0077     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0078     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0079 
0080     [[nodiscard]] BRepGraph_ShellRefId StartId() const { return BRepGraph_ShellRefId::Start(); }
0081 
0082     [[nodiscard]] BRepGraph_ShellRefId EndId() const { return BRepGraph_ShellRefId(Nb()); }
0083 
0084     [[nodiscard]] Standard_EXPORT const BRepGraphInc::ShellRef& Entry(
0085       const BRepGraph_ShellRefId theRefId) const;
0086     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_ShellRefId>& IdsOf(
0087       const BRepGraph_SolidId theSolid) const;
0088 
0089   private:
0090     friend class RefsView;
0091 
0092     explicit ShellOps(BRepGraph* theGraph)
0093         : myGraph(theGraph)
0094     {
0095     }
0096 
0097     BRepGraph* myGraph;
0098   };
0099 
0100   //! @brief Face reference queries.
0101   class FaceOps
0102   {
0103   public:
0104     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0105     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0106 
0107     [[nodiscard]] BRepGraph_FaceRefId StartId() const { return BRepGraph_FaceRefId::Start(); }
0108 
0109     [[nodiscard]] BRepGraph_FaceRefId EndId() const { return BRepGraph_FaceRefId(Nb()); }
0110 
0111     [[nodiscard]] Standard_EXPORT const BRepGraphInc::FaceRef& Entry(
0112       const BRepGraph_FaceRefId theRefId) const;
0113     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_FaceRefId>& IdsOf(
0114       const BRepGraph_ShellId theShell) const;
0115 
0116   private:
0117     friend class RefsView;
0118 
0119     explicit FaceOps(BRepGraph* theGraph)
0120         : myGraph(theGraph)
0121     {
0122     }
0123 
0124     BRepGraph* myGraph;
0125   };
0126 
0127   //! @brief Wire reference queries.
0128   class WireOps
0129   {
0130   public:
0131     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0132     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0133 
0134     [[nodiscard]] BRepGraph_WireRefId StartId() const { return BRepGraph_WireRefId::Start(); }
0135 
0136     [[nodiscard]] BRepGraph_WireRefId EndId() const { return BRepGraph_WireRefId(Nb()); }
0137 
0138     [[nodiscard]] Standard_EXPORT const BRepGraphInc::WireRef& Entry(
0139       const BRepGraph_WireRefId theRefId) const;
0140     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_WireRefId>& IdsOf(
0141       const BRepGraph_FaceId theFace) const;
0142 
0143   private:
0144     friend class RefsView;
0145 
0146     explicit WireOps(BRepGraph* theGraph)
0147         : myGraph(theGraph)
0148     {
0149     }
0150 
0151     BRepGraph* myGraph;
0152   };
0153 
0154   //! @brief Vertex reference queries.
0155   class VertexOps
0156   {
0157   public:
0158     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0159     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0160 
0161     [[nodiscard]] BRepGraph_VertexRefId StartId() const { return BRepGraph_VertexRefId::Start(); }
0162 
0163     [[nodiscard]] BRepGraph_VertexRefId EndId() const { return BRepGraph_VertexRefId(Nb()); }
0164 
0165     [[nodiscard]] Standard_EXPORT const BRepGraphInc::VertexRef& Entry(
0166       const BRepGraph_VertexRefId theRefId) const;
0167 
0168   private:
0169     friend class RefsView;
0170 
0171     explicit VertexOps(BRepGraph* theGraph)
0172         : myGraph(theGraph)
0173     {
0174     }
0175 
0176     BRepGraph* myGraph;
0177   };
0178 
0179   //! @brief Solid reference queries.
0180   class SolidOps
0181   {
0182   public:
0183     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0184     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0185 
0186     [[nodiscard]] BRepGraph_SolidRefId StartId() const { return BRepGraph_SolidRefId::Start(); }
0187 
0188     [[nodiscard]] BRepGraph_SolidRefId EndId() const { return BRepGraph_SolidRefId(Nb()); }
0189 
0190     [[nodiscard]] Standard_EXPORT const BRepGraphInc::SolidRef& Entry(
0191       const BRepGraph_SolidRefId theRefId) const;
0192     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_SolidRefId>& IdsOf(
0193       const BRepGraph_CompSolidId theCompSolid) const;
0194 
0195   private:
0196     friend class RefsView;
0197 
0198     explicit SolidOps(BRepGraph* theGraph)
0199         : myGraph(theGraph)
0200     {
0201     }
0202 
0203     BRepGraph* myGraph;
0204   };
0205 
0206   //! @brief Generic child reference queries.
0207   class ChildOps
0208   {
0209   public:
0210     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0211     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0212 
0213     [[nodiscard]] BRepGraph_ChildRefId StartId() const { return BRepGraph_ChildRefId::Start(); }
0214 
0215     [[nodiscard]] BRepGraph_ChildRefId EndId() const { return BRepGraph_ChildRefId(Nb()); }
0216 
0217     [[nodiscard]] Standard_EXPORT const BRepGraphInc::ChildRef& Entry(
0218       const BRepGraph_ChildRefId theRefId) const;
0219     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_ChildRefId>& IdsOf(
0220       const BRepGraph_CompoundId theCompound) const;
0221     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_ChildRefId>&
0222                                         IdsReferencing(const BRepGraph_NodeId theChild) const;
0223 
0224   private:
0225     friend class RefsView;
0226 
0227     explicit ChildOps(BRepGraph* theGraph)
0228         : myGraph(theGraph)
0229     {
0230     }
0231 
0232     BRepGraph* myGraph;
0233   };
0234 
0235   //! @brief Occurrence reference queries.
0236   class OccurrenceOps
0237   {
0238   public:
0239     [[nodiscard]] Standard_EXPORT uint32_t Nb() const;
0240     [[nodiscard]] Standard_EXPORT uint32_t NbActive() const;
0241 
0242     [[nodiscard]] BRepGraph_OccurrenceRefId StartId() const
0243     {
0244       return BRepGraph_OccurrenceRefId::Start();
0245     }
0246 
0247     [[nodiscard]] BRepGraph_OccurrenceRefId EndId() const
0248     {
0249       return BRepGraph_OccurrenceRefId(Nb());
0250     }
0251 
0252     [[nodiscard]] Standard_EXPORT const BRepGraphInc::OccurrenceRef& Entry(
0253       const BRepGraph_OccurrenceRefId theRefId) const;
0254     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_OccurrenceRefId>& IdsOf(
0255       const BRepGraph_ProductId theProduct) const;
0256     [[nodiscard]] Standard_EXPORT const NCollection_LinearVector<BRepGraph_OccurrenceRefId>&
0257                                         IdsReferencing(const BRepGraph_NodeId theChild) const;
0258 
0259   private:
0260     friend class RefsView;
0261 
0262     explicit OccurrenceOps(BRepGraph* theGraph)
0263         : myGraph(theGraph)
0264     {
0265     }
0266 
0267     BRepGraph* myGraph;
0268   };
0269 
0270   //! @brief Generic reference id queries.
0271   class GenOps
0272   {
0273   public:
0274     //! Return the number of references of the specified kind (including soft-removed).
0275     [[nodiscard]] Standard_EXPORT uint32_t Nb(const BRepGraph_RefId::Kind theKind) const;
0276 
0277     //! Return true if the reference id kind and index are within storage bounds.
0278     [[nodiscard]] Standard_EXPORT bool IsValid(const BRepGraph_RefId theRef) const;
0279 
0280     //! Return true if the reference id is valid and not soft-removed.
0281     [[nodiscard]] Standard_EXPORT bool IsActive(const BRepGraph_RefId theRef) const;
0282 
0283     //! Return true if the specified typed RefId is invalid or marked removed.
0284     [[nodiscard]] Standard_EXPORT bool IsRemoved(const BRepGraph_RefId theRef) const;
0285 
0286     //! Return the direct parent-owned RefId stored at the specified child step.
0287     //! This is a structural lookup over the parent's raw ref arrays and does not
0288     //! skip removed refs or refs targeting removed child defs.
0289     [[nodiscard]] Standard_EXPORT BRepGraph_RefId RefAtStep(const BRepGraph_NodeId theParent,
0290                                                             const int              theStep) const;
0291 
0292     //! Resolve the child definition node referenced by any typed RefId.
0293     [[nodiscard]] Standard_EXPORT BRepGraph_NodeId ChildNode(const BRepGraph_RefId theRef) const;
0294 
0295     //! Return the local location carried by the specified typed RefId.
0296     //! OccurrenceRef and invalid refs return identity.
0297     [[nodiscard]] Standard_EXPORT TopLoc_Location LocalLocation(const BRepGraph_RefId theRef) const;
0298 
0299     //! Return the orientation carried by the specified typed RefId.
0300     //! OccurrenceRef and invalid refs return TopAbs_FORWARD.
0301     [[nodiscard]] Standard_EXPORT TopAbs_Orientation
0302       Orientation(const BRepGraph_RefId theRef) const;
0303 
0304   private:
0305     friend class RefsView;
0306 
0307     explicit GenOps(BRepGraph* theGraph)
0308         : myGraph(theGraph)
0309     {
0310     }
0311 
0312     BRepGraph* myGraph;
0313   };
0314 
0315   //! Grouped shell reference queries.
0316   [[nodiscard]] const ShellOps& Shells() const { return myShells; }
0317 
0318   //! Grouped face reference queries.
0319   [[nodiscard]] const FaceOps& Faces() const { return myFaces; }
0320 
0321   //! Grouped wire reference queries.
0322   [[nodiscard]] const WireOps& Wires() const { return myWires; }
0323 
0324   //! Grouped vertex reference queries.
0325   [[nodiscard]] const VertexOps& Vertices() const { return myVertices; }
0326 
0327   //! Grouped solid reference queries.
0328   [[nodiscard]] const SolidOps& Solids() const { return mySolids; }
0329 
0330   //! Grouped child reference queries.
0331   [[nodiscard]] const ChildOps& Children() const { return myChildren; }
0332 
0333   //! Grouped occurrence reference queries.
0334   [[nodiscard]] const OccurrenceOps& Occurrences() const { return myOccurrences; }
0335 
0336   //! Grouped generic reference id queries.
0337   [[nodiscard]] const GenOps& Gen() const { return myGen; }
0338 
0339 private:
0340   friend class BRepGraph;
0341   friend struct BRepGraph_Data;
0342 
0343   explicit RefsView(BRepGraph* theGraph)
0344       : myGraph(theGraph),
0345         myShells(theGraph),
0346         myFaces(theGraph),
0347         myWires(theGraph),
0348         myVertices(theGraph),
0349         mySolids(theGraph),
0350         myChildren(theGraph),
0351         myOccurrences(theGraph),
0352         myGen(theGraph)
0353   {
0354   }
0355 
0356   BRepGraph*    myGraph;
0357   ShellOps      myShells;
0358   FaceOps       myFaces;
0359   WireOps       myWires;
0360   VertexOps     myVertices;
0361   SolidOps      mySolids;
0362   ChildOps      myChildren;
0363   OccurrenceOps myOccurrences;
0364   GenOps        myGen;
0365 };
0366 
0367 #endif // _BRepGraph_RefsView_HeaderFile