File indexing completed on 2026-09-28 09:19:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraph_LayerDeferred_HeaderFile
0015 #define _BRepGraph_LayerDeferred_HeaderFile
0016
0017 #include <BRepGraph_ItemId.hxx>
0018 #include <BRepGraph_Layer.hxx>
0019 #include <NCollection_DataMap.hxx>
0020 #include <Standard_Assert.hxx>
0021 #include <TCollection_AsciiString.hxx>
0022
0023 #include <limits>
0024 #include <new>
0025 #include <type_traits>
0026 #include <utility>
0027
0028
0029
0030
0031
0032
0033
0034 class BRepGraph_LayerDeferred : public BRepGraph_Layer
0035 {
0036 public:
0037
0038 Standard_EXPORT BRepGraph_LayerDeferred();
0039
0040
0041 enum class RepresentationKind
0042 {
0043 Unknown,
0044 Geometry,
0045 Mesh,
0046 Topology,
0047 Assembly,
0048 Parametric
0049 };
0050
0051
0052 struct Representation
0053 {
0054 static constexpr uint32_t THE_INVALID_SOURCE_INDEX = std::numeric_limits<uint32_t>::max();
0055
0056 RepresentationKind Kind = RepresentationKind::Unknown;
0057 uint32_t Role = 0;
0058 TCollection_AsciiString Name;
0059 uint32_t SourceIndex = THE_INVALID_SOURCE_INDEX;
0060 };
0061
0062
0063 struct Entry
0064 {
0065
0066
0067 class RepresentationStorage
0068 {
0069 public:
0070 static constexpr size_t THE_MAX_REPRESENTATIONS_PER_ITEM = 8;
0071
0072 RepresentationStorage() = default;
0073
0074 RepresentationStorage(const RepresentationStorage& theOther) { copyFrom(theOther); }
0075
0076 RepresentationStorage(RepresentationStorage&& theOther) noexcept { moveFrom(theOther); }
0077
0078 Standard_EXPORT RepresentationStorage& operator=(const RepresentationStorage& theOther);
0079 Standard_EXPORT RepresentationStorage& operator=(RepresentationStorage&& theOther) noexcept;
0080
0081 ~RepresentationStorage() { Clear(); }
0082
0083 [[nodiscard]] size_t Size() const { return mySize; }
0084
0085 [[nodiscard]] bool IsEmpty() const { return mySize == 0; }
0086
0087 [[nodiscard]] Standard_EXPORT bool ContainsKind(const RepresentationKind theKind) const;
0088
0089 [[nodiscard]] const Representation& Value(const size_t theIndex) const
0090 {
0091 Standard_ASSERT_RAISE(theIndex < mySize, "Deferred representation index is out of range");
0092 return *representationPtr(theIndex);
0093 }
0094
0095 [[nodiscard]] Representation& ChangeValue(const size_t theIndex)
0096 {
0097 Standard_ASSERT_RAISE(theIndex < mySize, "Deferred representation index is out of range");
0098 return *representationPtr(theIndex);
0099 }
0100
0101 [[nodiscard]] const Representation& First() const
0102 {
0103 Standard_ASSERT_RAISE(mySize > 0, "Deferred representation list is empty");
0104 return *representationPtr(0);
0105 }
0106
0107 Standard_EXPORT void Append(const Representation& theRepresentation);
0108
0109 Standard_EXPORT void Clear();
0110
0111 private:
0112 [[nodiscard]] const Representation* representationPtr(const size_t theIndex) const
0113 {
0114 return reinterpret_cast<const Representation*>(&myRepresentationStorage[theIndex]);
0115 }
0116
0117 [[nodiscard]] Representation* representationPtr(const size_t theIndex)
0118 {
0119 return reinterpret_cast<Representation*>(&myRepresentationStorage[theIndex]);
0120 }
0121
0122 Standard_EXPORT void copyFrom(const RepresentationStorage& theOther);
0123 Standard_EXPORT void moveFrom(RepresentationStorage& theOther);
0124
0125 using RepresentationSlot =
0126 std::aligned_storage_t<sizeof(Representation), alignof(Representation)>;
0127
0128 RepresentationSlot myRepresentationStorage[THE_MAX_REPRESENTATIONS_PER_ITEM];
0129 size_t mySize = 0;
0130 };
0131
0132 TCollection_AsciiString Provider;
0133 TCollection_AsciiString SourceKey;
0134 RepresentationStorage Representations;
0135 };
0136
0137
0138 [[nodiscard]] Standard_EXPORT static const Standard_GUID& GetID();
0139
0140
0141 [[nodiscard]] Standard_EXPORT const Standard_GUID& ID() const override;
0142
0143
0144 [[nodiscard]] Standard_EXPORT const Entry* FindDeferred(const BRepGraph_ItemId theItem) const;
0145
0146
0147 [[nodiscard]] const Entry* FindDeferred(const BRepGraph_NodeId theNode) const
0148 {
0149 return FindDeferred(BRepGraph_ItemId(theNode));
0150 }
0151
0152
0153 [[nodiscard]] const Entry* FindDeferred(const BRepGraph_RefId theRef) const
0154 {
0155 return FindDeferred(BRepGraph_ItemId(theRef));
0156 }
0157
0158
0159 [[nodiscard]] Standard_EXPORT bool HasDeferred(const BRepGraph_ItemId theItem) const;
0160
0161
0162 [[nodiscard]] bool HasDeferred(const BRepGraph_NodeId theNode) const
0163 {
0164 return HasDeferred(BRepGraph_ItemId(theNode));
0165 }
0166
0167
0168 [[nodiscard]] bool HasDeferred(const BRepGraph_RefId theRef) const
0169 {
0170 return HasDeferred(BRepGraph_ItemId(theRef));
0171 }
0172
0173
0174 Standard_EXPORT void RegisterDeferred(const BRepGraph_ItemId theItem,
0175 const TCollection_AsciiString& theProvider,
0176 const TCollection_AsciiString& theSourceKey,
0177 const RepresentationKind theRepresentationKind,
0178 const TCollection_AsciiString& theRepresentationName,
0179 const uint32_t theSourceIndex);
0180
0181
0182 Standard_EXPORT void RegisterDeferredRepresentations(const BRepGraph_ItemId theItem,
0183 const TCollection_AsciiString& theProvider,
0184 const TCollection_AsciiString& theSourceKey,
0185 const Representation* theRepresentations,
0186 const size_t theNbRepresentations);
0187
0188
0189
0190
0191
0192 Standard_EXPORT void RegisterDeferredRepresentationsDirect(
0193 const BRepGraph_ItemId theItem,
0194 const TCollection_AsciiString& theProvider,
0195 const TCollection_AsciiString& theSourceKey,
0196 const Representation* theRepresentations,
0197 const size_t theNbRepresentations);
0198
0199
0200 void RegisterDeferred(const BRepGraph_NodeId theNode,
0201 const TCollection_AsciiString& theProvider,
0202 const TCollection_AsciiString& theSourceKey,
0203 const RepresentationKind theRepresentationKind,
0204 const TCollection_AsciiString& theRepresentationName,
0205 const uint32_t theSourceIndex)
0206 {
0207 RegisterDeferred(BRepGraph_ItemId(theNode),
0208 theProvider,
0209 theSourceKey,
0210 theRepresentationKind,
0211 theRepresentationName,
0212 theSourceIndex);
0213 }
0214
0215
0216 void RegisterDeferred(const BRepGraph_RefId theRef,
0217 const TCollection_AsciiString& theProvider,
0218 const TCollection_AsciiString& theSourceKey,
0219 const RepresentationKind theRepresentationKind,
0220 const TCollection_AsciiString& theRepresentationName,
0221 const uint32_t theSourceIndex)
0222 {
0223 RegisterDeferred(BRepGraph_ItemId(theRef),
0224 theProvider,
0225 theSourceKey,
0226 theRepresentationKind,
0227 theRepresentationName,
0228 theSourceIndex);
0229 }
0230
0231
0232 Standard_EXPORT void UnregisterDeferred(const BRepGraph_ItemId theItem);
0233
0234
0235 void UnregisterDeferred(const BRepGraph_NodeId theNode)
0236 {
0237 UnregisterDeferred(BRepGraph_ItemId(theNode));
0238 }
0239
0240
0241 void UnregisterDeferred(const BRepGraph_RefId theRef)
0242 {
0243 UnregisterDeferred(BRepGraph_ItemId(theRef));
0244 }
0245
0246
0247 [[nodiscard]] bool HasDeferredItems() const { return myEntries.Extent() != 0; }
0248
0249
0250 [[nodiscard]] Standard_EXPORT const Entry* FindFirstDeferred(
0251 const RepresentationKind theKind,
0252 BRepGraph_ItemId* theItem = nullptr) const;
0253
0254
0255 Standard_EXPORT void ReserveDeferredItems(const size_t theNbItems);
0256
0257
0258 Standard_EXPORT void BeginBulkRegistration();
0259
0260
0261 Standard_EXPORT void EndBulkRegistration();
0262
0263
0264 template <typename VisitorT>
0265 void ForEachDeferred(VisitorT&& theVisitor) const
0266 {
0267 for (NCollection_DataMap<BRepGraph_ItemId, Entry>::Iterator anIt(myEntries); anIt.More();)
0268 {
0269 const BRepGraph_ItemId anItem = anIt.Key();
0270 const Entry anEntry = anIt.Value();
0271 anIt.Next();
0272 if (!theVisitor(anItem, anEntry))
0273 {
0274 break;
0275 }
0276 }
0277 }
0278
0279
0280
0281 template <typename VisitorT>
0282 void ForEachDeferred(const RepresentationKind theKind, VisitorT&& theVisitor) const
0283 {
0284 for (NCollection_DataMap<BRepGraph_ItemId, Entry>::Iterator anIt(myEntries); anIt.More();)
0285 {
0286 if (!anIt.Value().Representations.ContainsKind(theKind))
0287 {
0288 anIt.Next();
0289 continue;
0290 }
0291
0292 const BRepGraph_ItemId anItem = anIt.Key();
0293 const Entry anEntry = anIt.Value();
0294 anIt.Next();
0295 if (!theVisitor(anItem, anEntry))
0296 {
0297 break;
0298 }
0299 }
0300 }
0301
0302 Standard_EXPORT const TCollection_AsciiString& Name() const override;
0303 Standard_EXPORT void OnNodeRemoved(const BRepGraph_NodeId theNode) noexcept override;
0304 Standard_EXPORT void OnNodeReplaced(const BRepGraph_NodeId theOldNode,
0305 const BRepGraph_NodeId theNewNode) noexcept override;
0306 Standard_EXPORT void CopyTo(const BRepGraph_CopyRemap& theCopy) const override;
0307 Standard_EXPORT void OnRefRemoved(const BRepGraph_RefId theRef) noexcept override;
0308 Standard_EXPORT void InvalidateAll() noexcept override;
0309 Standard_EXPORT void Clear() noexcept override;
0310
0311 DEFINE_STANDARD_RTTIEXT(BRepGraph_LayerDeferred, BRepGraph_Layer)
0312
0313 private:
0314 void removeItem(const BRepGraph_ItemId theItem) noexcept;
0315 void lockItem(const BRepGraph_ItemId theItem);
0316 void unlockItem(const BRepGraph_ItemId theItem);
0317
0318 private:
0319 NCollection_DataMap<BRepGraph_ItemId, Entry> myEntries;
0320 uint32_t myBulkRegistrationDepth = 0;
0321 bool myHasBulkChanges = false;
0322 };
0323
0324 #endif