Warning, /include/opencascade/BRepGraphInc_Storage.lxx is written in an unsupported language. File is not indexed.
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 //! @name TypedStorePlanes specializations for entity and reference stores.
0015 //!
0016 //! Each store (e.g. myVertices, myEdges) is a DefStore or RefStore that owns
0017 //! per-entity bit-flag planes. The specialization exposes those planes through
0018 //! a uniform static interface so that generic template methods (IsRemoved,
0019 //! SetRemoved, IsGuarded, ...) can operate on any typed ID without a virtual
0020 //! dispatch.
0021 //!
0022 //! Parameter T is the typed identifier (e.g. BRepGraph_VertexId).
0023 //! Parameter F is the member store field name (e.g. myVertices).
0024 #define OCCT_BG_STORE_PLANES(T, F) \
0025 template <> \
0026 struct BRepGraphInc_Storage::TypedStorePlanes<T> \
0027 { \
0028 static uint32_t Nb(const BRepGraphInc_Storage& theStorage) \
0029 { \
0030 return theStorage.F.Nb(); \
0031 } \
0032 static uint32_t& NbActive(BRepGraphInc_Storage& theStorage) \
0033 { \
0034 return theStorage.F.NbActive; \
0035 } \
0036 static BRepGraphInc_BitFlags& Removed(BRepGraphInc_Storage& theStorage) \
0037 { \
0038 return theStorage.F.RemovedFlags; \
0039 } \
0040 static const BRepGraphInc_BitFlags& Removed(const BRepGraphInc_Storage& theStorage) \
0041 { \
0042 return theStorage.F.RemovedFlags; \
0043 } \
0044 static BRepGraphInc_BitFlags& Owned(BRepGraphInc_Storage& theStorage) \
0045 { \
0046 return theStorage.F.OwnedFlags; \
0047 } \
0048 static const BRepGraphInc_BitFlags& Owned(const BRepGraphInc_Storage& theStorage) \
0049 { \
0050 return theStorage.F.OwnedFlags; \
0051 } \
0052 static BRepGraphInc_BitFlags& Guard(BRepGraphInc_Storage& theStorage) \
0053 { \
0054 return theStorage.F.GuardFlags; \
0055 } \
0056 static const BRepGraphInc_BitFlags& Guard(const BRepGraphInc_Storage& theStorage) \
0057 { \
0058 return theStorage.F.GuardFlags; \
0059 } \
0060 static BRepGraphInc_BitFlags& HasCompoundParent(BRepGraphInc_Storage& theStorage) \
0061 { \
0062 return theStorage.F.HasCompoundParentFlags; \
0063 } \
0064 static const BRepGraphInc_BitFlags& HasCompoundParent(const BRepGraphInc_Storage& theStorage) \
0065 { \
0066 return theStorage.F.HasCompoundParentFlags; \
0067 } \
0068 static BRepGraphInc_BitFlags& HasOccurrenceParent(BRepGraphInc_Storage& theStorage) \
0069 { \
0070 return theStorage.F.HasOccurrenceParentFlags; \
0071 } \
0072 static const BRepGraphInc_BitFlags& HasOccurrenceParent( \
0073 const BRepGraphInc_Storage& theStorage) \
0074 { \
0075 return theStorage.F.HasOccurrenceParentFlags; \
0076 } \
0077 };
0078
0079 OCCT_BG_STORE_PLANES(BRepGraph_VertexId, myVertices)
0080 OCCT_BG_STORE_PLANES(BRepGraph_EdgeId, myEdges)
0081 OCCT_BG_STORE_PLANES(BRepGraph_CoEdgeId, myCoEdges)
0082 OCCT_BG_STORE_PLANES(BRepGraph_WireId, myWires)
0083 OCCT_BG_STORE_PLANES(BRepGraph_FaceId, myFaces)
0084 OCCT_BG_STORE_PLANES(BRepGraph_ShellId, myShells)
0085 OCCT_BG_STORE_PLANES(BRepGraph_SolidId, mySolids)
0086 OCCT_BG_STORE_PLANES(BRepGraph_CompoundId, myCompounds)
0087 OCCT_BG_STORE_PLANES(BRepGraph_CompSolidId, myCompSolids)
0088 OCCT_BG_STORE_PLANES(BRepGraph_ProductId, myProducts)
0089 OCCT_BG_STORE_PLANES(BRepGraph_OccurrenceId, myOccurrences)
0090
0091 OCCT_BG_STORE_PLANES(BRepGraph_VertexRefId, myVertexRefs)
0092 OCCT_BG_STORE_PLANES(BRepGraph_ShellRefId, myShellRefs)
0093 OCCT_BG_STORE_PLANES(BRepGraph_FaceRefId, myFaceRefs)
0094 OCCT_BG_STORE_PLANES(BRepGraph_WireRefId, myWireRefs)
0095 OCCT_BG_STORE_PLANES(BRepGraph_SolidRefId, mySolidRefs)
0096 OCCT_BG_STORE_PLANES(BRepGraph_ChildRefId, myChildRefs)
0097 OCCT_BG_STORE_PLANES(BRepGraph_OccurrenceRefId, myOccurrenceRefs)
0098
0099 #undef OCCT_BG_STORE_PLANES
0100
0101 //! @name TypedStorePlanes specializations for representation-use stores.
0102 //!
0103 //! Representation stores (e.g. myFaceSurfaces, myEdgeCurves3D) track geometric
0104 //! or triangulation data attached to topology entities. They have Removed
0105 //! flags and an NbActive counter but no Owned, Guard, HasCompoundParent, or
0106 //! HasOccurrenceParent planes. Those methods are intentionally omitted --
0107 //! calling IsOwned/IsGuarded/HasCompoundParentTyped/HasOccurrenceParentTyped
0108 //! on a representation ID will produce a compile error, which is the desired
0109 //! behavior since representation entities have no ownership or guard lifecycle.
0110 #define OCCT_BG_REP_PLANES(T, F) \
0111 template <> \
0112 struct BRepGraphInc_Storage::TypedStorePlanes<T> \
0113 { \
0114 static uint32_t Nb(const BRepGraphInc_Storage& theStorage) \
0115 { \
0116 return theStorage.F.Nb(); \
0117 } \
0118 static uint32_t& NbActive(BRepGraphInc_Storage& theStorage) \
0119 { \
0120 return theStorage.F.NbActive; \
0121 } \
0122 static BRepGraphInc_BitFlags& Removed(BRepGraphInc_Storage& theStorage) \
0123 { \
0124 return theStorage.F.RemovedFlags; \
0125 } \
0126 static const BRepGraphInc_BitFlags& Removed(const BRepGraphInc_Storage& theStorage) \
0127 { \
0128 return theStorage.F.RemovedFlags; \
0129 } \
0130 };
0131
0132 OCCT_BG_REP_PLANES(BRepGraph_FaceSurfaceRepId, myFaceSurfaces)
0133 OCCT_BG_REP_PLANES(BRepGraph_FaceTriangulationRepId, myFaceTriangulations)
0134 OCCT_BG_REP_PLANES(BRepGraph_EdgeCurve3DRepId, myEdgeCurves3D)
0135 OCCT_BG_REP_PLANES(BRepGraph_EdgePolygon3DRepId, myEdgePolygons3D)
0136 OCCT_BG_REP_PLANES(BRepGraph_CoEdgeCurve2DRepId, myCoEdgeCurves2D)
0137 OCCT_BG_REP_PLANES(BRepGraph_CoEdgePolygon2DRepId, myCoEdgePolygons2D)
0138 OCCT_BG_REP_PLANES(BRepGraph_CoEdgePolygonOnTriRepId, myCoEdgePolygonsOnTri)
0139
0140 #undef OCCT_BG_REP_PLANES
0141
0142 //=================================================================================================
0143
0144 template <typename T>
0145 bool BRepGraphInc_Storage::isInRange(const T theId) const
0146 {
0147 return theId.IsValid(TypedStorePlanes<T>::Nb(*this))
0148 && TypedStorePlanes<T>::Removed(*this).IsValidIndex(theId.Index);
0149 }
0150
0151 //=================================================================================================
0152
0153 template <typename FuncT>
0154 bool BRepGraphInc_Storage::dispatchItemId(const BRepGraph_ItemId& theId, FuncT&& theFunc) const
0155 {
0156 switch (theId.ItemDomain())
0157 {
0158 case BRepGraph_ItemId::Domain::Node:
0159 switch (static_cast<BRepGraph_NodeId::Kind>(theId.RawKind()))
0160 {
0161 case BRepGraph_NodeId::Kind::Vertex:
0162 return std::forward<FuncT>(theFunc)(BRepGraph_VertexId(theId.Index()));
0163 case BRepGraph_NodeId::Kind::Edge:
0164 return std::forward<FuncT>(theFunc)(BRepGraph_EdgeId(theId.Index()));
0165 case BRepGraph_NodeId::Kind::CoEdge:
0166 return std::forward<FuncT>(theFunc)(BRepGraph_CoEdgeId(theId.Index()));
0167 case BRepGraph_NodeId::Kind::Wire:
0168 return std::forward<FuncT>(theFunc)(BRepGraph_WireId(theId.Index()));
0169 case BRepGraph_NodeId::Kind::Face:
0170 return std::forward<FuncT>(theFunc)(BRepGraph_FaceId(theId.Index()));
0171 case BRepGraph_NodeId::Kind::Shell:
0172 return std::forward<FuncT>(theFunc)(BRepGraph_ShellId(theId.Index()));
0173 case BRepGraph_NodeId::Kind::Solid:
0174 return std::forward<FuncT>(theFunc)(BRepGraph_SolidId(theId.Index()));
0175 case BRepGraph_NodeId::Kind::Compound:
0176 return std::forward<FuncT>(theFunc)(BRepGraph_CompoundId(theId.Index()));
0177 case BRepGraph_NodeId::Kind::CompSolid:
0178 return std::forward<FuncT>(theFunc)(BRepGraph_CompSolidId(theId.Index()));
0179 case BRepGraph_NodeId::Kind::Product:
0180 return std::forward<FuncT>(theFunc)(BRepGraph_ProductId(theId.Index()));
0181 case BRepGraph_NodeId::Kind::Occurrence:
0182 return std::forward<FuncT>(theFunc)(BRepGraph_OccurrenceId(theId.Index()));
0183 }
0184 break;
0185 case BRepGraph_ItemId::Domain::Reference:
0186 switch (static_cast<BRepGraph_RefId::Kind>(theId.RawKind()))
0187 {
0188 case BRepGraph_RefId::Kind::Shell:
0189 return std::forward<FuncT>(theFunc)(BRepGraph_ShellRefId(theId.Index()));
0190 case BRepGraph_RefId::Kind::Face:
0191 return std::forward<FuncT>(theFunc)(BRepGraph_FaceRefId(theId.Index()));
0192 case BRepGraph_RefId::Kind::Wire:
0193 return std::forward<FuncT>(theFunc)(BRepGraph_WireRefId(theId.Index()));
0194 case BRepGraph_RefId::Kind::Vertex:
0195 return std::forward<FuncT>(theFunc)(BRepGraph_VertexRefId(theId.Index()));
0196 case BRepGraph_RefId::Kind::Solid:
0197 return std::forward<FuncT>(theFunc)(BRepGraph_SolidRefId(theId.Index()));
0198 case BRepGraph_RefId::Kind::Child:
0199 return std::forward<FuncT>(theFunc)(BRepGraph_ChildRefId(theId.Index()));
0200 case BRepGraph_RefId::Kind::Occurrence:
0201 return std::forward<FuncT>(theFunc)(BRepGraph_OccurrenceRefId(theId.Index()));
0202 }
0203 break;
0204 default:
0205 break;
0206 }
0207 return false;
0208 }
0209
0210 //=================================================================================================
0211
0212 template <typename T>
0213 bool BRepGraphInc_Storage::IsRemoved(const T theId) const
0214 {
0215 return isInRange(theId) && TypedStorePlanes<T>::Removed(*this).Test(theId.Index);
0216 }
0217
0218 //=================================================================================================
0219
0220 template <typename T>
0221 void BRepGraphInc_Storage::SetRemoved(const T theId, const bool theVal)
0222 {
0223 if (!isInRange(theId))
0224 {
0225 return;
0226 }
0227 auto& aF = TypedStorePlanes<T>::Removed(*this);
0228 const bool aWasRemoved = aF.Test(theId.Index);
0229 if (aWasRemoved == theVal)
0230 {
0231 return;
0232 }
0233 uint32_t& aNbActive = TypedStorePlanes<T>::NbActive(*this);
0234 if (theVal)
0235 {
0236 aF.Set(theId.Index);
0237 Standard_ASSERT_VOID(aNbActive > 0u,
0238 "BRepGraphInc_Storage::SetRemoved: active count underflow");
0239 if (aNbActive > 0u)
0240 {
0241 --aNbActive;
0242 }
0243 }
0244 else
0245 {
0246 aF.Clear(theId.Index);
0247 ++aNbActive;
0248 }
0249 }
0250
0251 //=================================================================================================
0252
0253 template <typename T>
0254 bool BRepGraphInc_Storage::IsOwned(const T theId) const
0255 {
0256 return isInRange(theId) && TypedStorePlanes<T>::Owned(*this).Test(theId.Index);
0257 }
0258
0259 //=================================================================================================
0260
0261 template <typename T>
0262 void BRepGraphInc_Storage::SetOwned(const T theId, const bool theVal)
0263 {
0264 if (!isInRange(theId))
0265 {
0266 return;
0267 }
0268 auto& aF = TypedStorePlanes<T>::Owned(*this);
0269 theVal ? aF.Set(theId.Index) : aF.Clear(theId.Index);
0270 }
0271
0272 //=================================================================================================
0273
0274 template <typename T>
0275 bool BRepGraphInc_Storage::IsGuarded(const T theId) const
0276 {
0277 return isInRange(theId) && TypedStorePlanes<T>::Guard(*this).Test(theId.Index);
0278 }
0279
0280 //=================================================================================================
0281
0282 template <typename T>
0283 void BRepGraphInc_Storage::SetGuarded(const T theId)
0284 {
0285 if (isInRange(theId))
0286 {
0287 TypedStorePlanes<T>::Guard(*this).Set(theId.Index);
0288 }
0289 }
0290
0291 //=================================================================================================
0292
0293 template <typename T>
0294 void BRepGraphInc_Storage::ClearGuarded(const T theId)
0295 {
0296 if (isInRange(theId))
0297 {
0298 TypedStorePlanes<T>::Guard(*this).Clear(theId.Index);
0299 }
0300 }
0301
0302 //=================================================================================================
0303
0304 template <typename T>
0305 bool BRepGraphInc_Storage::HasCompoundParentTyped(const T theId) const
0306 {
0307 return isInRange(theId) && TypedStorePlanes<T>::HasCompoundParent(*this).Test(theId.Index);
0308 }
0309
0310 //=================================================================================================
0311
0312 template <typename T>
0313 void BRepGraphInc_Storage::SetHasCompoundParentTyped(const T theId, const bool theVal)
0314 {
0315 if (!isInRange(theId))
0316 {
0317 return;
0318 }
0319 auto& aF = TypedStorePlanes<T>::HasCompoundParent(*this);
0320 theVal ? aF.Set(theId.Index) : aF.Clear(theId.Index);
0321 }
0322
0323 //=================================================================================================
0324
0325 template <typename T>
0326 bool BRepGraphInc_Storage::HasOccurrenceParentTyped(const T theId) const
0327 {
0328 return isInRange(theId) && TypedStorePlanes<T>::HasOccurrenceParent(*this).Test(theId.Index);
0329 }
0330
0331 //=================================================================================================
0332
0333 template <typename T>
0334 void BRepGraphInc_Storage::SetHasOccurrenceParentTyped(const T theId, const bool theVal)
0335 {
0336 if (!isInRange(theId))
0337 {
0338 return;
0339 }
0340 auto& aF = TypedStorePlanes<T>::HasOccurrenceParent(*this);
0341 theVal ? aF.Set(theId.Index) : aF.Clear(theId.Index);
0342 }
0343
0344 //=================================================================================================
0345
0346 inline bool BRepGraphInc_Storage::IsGuarded(const BRepGraph_ItemId& theId) const
0347 {
0348 return dispatchItemId(theId, [this](const auto theTypedId) { return IsGuarded(theTypedId); });
0349 }
0350
0351 //=================================================================================================
0352
0353 inline void BRepGraphInc_Storage::SetGuarded(const BRepGraph_ItemId& theId)
0354 {
0355 if (!dispatchItemId(theId, [this](const auto theTypedId) {
0356 SetGuarded(theTypedId);
0357 return true;
0358 }))
0359 {
0360 Standard_ASSERT_VOID(false, "BRepGraphInc_Storage::SetGuarded: invalid item id");
0361 }
0362 }
0363
0364 //=================================================================================================
0365
0366 inline void BRepGraphInc_Storage::ClearGuarded(const BRepGraph_ItemId& theId)
0367 {
0368 if (!dispatchItemId(theId, [this](const auto theTypedId) {
0369 ClearGuarded(theTypedId);
0370 return true;
0371 }))
0372 {
0373 Standard_ASSERT_VOID(false, "BRepGraphInc_Storage::ClearGuarded: invalid item id");
0374 }
0375 }