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_Iterator_HeaderFile
0015 #define _BRepGraph_Iterator_HeaderFile
0016
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_TopoView.hxx>
0019 #include <NCollection_ForwardRange.hxx>
0020
0021 #include <utility>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 namespace BRepGraph_IteratorDetail
0039 {
0040
0041
0042
0043 template <typename T>
0044 struct NodeTraits;
0045
0046 template <>
0047 struct NodeTraits<BRepGraphInc::SolidDef>
0048 {
0049 using TypedId = BRepGraph_SolidId;
0050
0051 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Solids().Nb(); }
0052
0053 static const BRepGraphInc::SolidDef& Get(const BRepGraph& theGraph, const TypedId theId)
0054 {
0055 return theGraph.Topo().Solids().Definition(theId);
0056 }
0057 };
0058
0059 template <>
0060 struct NodeTraits<BRepGraphInc::ShellDef>
0061 {
0062 using TypedId = BRepGraph_ShellId;
0063
0064 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Shells().Nb(); }
0065
0066 static const BRepGraphInc::ShellDef& Get(const BRepGraph& theGraph, const TypedId theId)
0067 {
0068 return theGraph.Topo().Shells().Definition(theId);
0069 }
0070 };
0071
0072 template <>
0073 struct NodeTraits<BRepGraphInc::FaceDef>
0074 {
0075 using TypedId = BRepGraph_FaceId;
0076
0077 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Faces().Nb(); }
0078
0079 static const BRepGraphInc::FaceDef& Get(const BRepGraph& theGraph, const TypedId theId)
0080 {
0081 return theGraph.Topo().Faces().Definition(theId);
0082 }
0083 };
0084
0085 template <>
0086 struct NodeTraits<BRepGraphInc::WireDef>
0087 {
0088 using TypedId = BRepGraph_WireId;
0089
0090 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Wires().Nb(); }
0091
0092 static const BRepGraphInc::WireDef& Get(const BRepGraph& theGraph, const TypedId theId)
0093 {
0094 return theGraph.Topo().Wires().Definition(theId);
0095 }
0096 };
0097
0098 template <>
0099 struct NodeTraits<BRepGraphInc::EdgeDef>
0100 {
0101 using TypedId = BRepGraph_EdgeId;
0102
0103 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Edges().Nb(); }
0104
0105 static const BRepGraphInc::EdgeDef& Get(const BRepGraph& theGraph, const TypedId theId)
0106 {
0107 return theGraph.Topo().Edges().Definition(theId);
0108 }
0109 };
0110
0111 template <>
0112 struct NodeTraits<BRepGraphInc::VertexDef>
0113 {
0114 using TypedId = BRepGraph_VertexId;
0115
0116 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Vertices().Nb(); }
0117
0118 static const BRepGraphInc::VertexDef& Get(const BRepGraph& theGraph, const TypedId theId)
0119 {
0120 return theGraph.Topo().Vertices().Definition(theId);
0121 }
0122 };
0123
0124 template <>
0125 struct NodeTraits<BRepGraphInc::ProductDef>
0126 {
0127 using TypedId = BRepGraph_ProductId;
0128
0129 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Products().Nb(); }
0130
0131 static const BRepGraphInc::ProductDef& Get(const BRepGraph& theGraph, const TypedId theId)
0132 {
0133 return theGraph.Topo().Products().Definition(theId);
0134 }
0135 };
0136
0137 template <>
0138 struct NodeTraits<BRepGraphInc::OccurrenceDef>
0139 {
0140 using TypedId = BRepGraph_OccurrenceId;
0141
0142 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Occurrences().Nb(); }
0143
0144 static const BRepGraphInc::OccurrenceDef& Get(const BRepGraph& theGraph, const TypedId theId)
0145 {
0146 return theGraph.Topo().Occurrences().Definition(theId);
0147 }
0148 };
0149
0150 template <>
0151 struct NodeTraits<BRepGraphInc::CoEdgeDef>
0152 {
0153 using TypedId = BRepGraph_CoEdgeId;
0154
0155 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().CoEdges().Nb(); }
0156
0157 static const BRepGraphInc::CoEdgeDef& Get(const BRepGraph& theGraph, const TypedId theId)
0158 {
0159 return theGraph.Topo().CoEdges().Definition(theId);
0160 }
0161 };
0162
0163 template <>
0164 struct NodeTraits<BRepGraphInc::CompoundDef>
0165 {
0166 using TypedId = BRepGraph_CompoundId;
0167
0168 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().Compounds().Nb(); }
0169
0170 static const BRepGraphInc::CompoundDef& Get(const BRepGraph& theGraph, const TypedId theId)
0171 {
0172 return theGraph.Topo().Compounds().Definition(theId);
0173 }
0174 };
0175
0176 template <>
0177 struct NodeTraits<BRepGraphInc::CompSolidDef>
0178 {
0179 using TypedId = BRepGraph_CompSolidId;
0180
0181 static uint32_t Count(const BRepGraph& theGraph) { return theGraph.Topo().CompSolids().Nb(); }
0182
0183 static const BRepGraphInc::CompSolidDef& Get(const BRepGraph& theGraph, const TypedId theId)
0184 {
0185 return theGraph.Topo().CompSolids().Definition(theId);
0186 }
0187 };
0188 }
0189
0190
0191
0192
0193
0194 template <typename NodeType, bool TheFullTraverse = false>
0195 class BRepGraph_Iterator
0196 {
0197 public:
0198 using Traits = BRepGraph_IteratorDetail::NodeTraits<NodeType>;
0199 using TypedId = typename Traits::TypedId;
0200
0201 BRepGraph_Iterator(const BRepGraph& theGraph)
0202 : myGraph(theGraph),
0203 myLength(TypedId(Traits::Count(theGraph)))
0204 {
0205 skipRemoved();
0206 }
0207
0208 BRepGraph_Iterator(const BRepGraph& theGraph, const TypedId theStartId)
0209 : myGraph(theGraph),
0210 myCurrent(theStartId),
0211 myLength(TypedId(Traits::Count(theGraph)))
0212 {
0213 if (myCurrent < TypedId::Start())
0214 {
0215 myCurrent = TypedId::Start();
0216 }
0217 skipRemoved();
0218 }
0219
0220 [[nodiscard]] bool More() const { return myCurrent < myLength; }
0221
0222 void Next()
0223 {
0224 ++myCurrent;
0225 skipRemoved();
0226 }
0227
0228 [[nodiscard]] const NodeType& Current() const { return Traits::Get(myGraph, myCurrent); }
0229
0230
0231 [[nodiscard]] TypedId CurrentId() const { return myCurrent; }
0232
0233
0234 NCollection_ForwardRangeIterator<BRepGraph_Iterator> begin()
0235 {
0236 return NCollection_ForwardRangeIterator<BRepGraph_Iterator>(this);
0237 }
0238
0239
0240 NCollection_ForwardRangeSentinel end() const { return NCollection_ForwardRangeSentinel{}; }
0241
0242 private:
0243
0244 void skipRemoved()
0245 {
0246 if constexpr (!TheFullTraverse)
0247 {
0248 while (myCurrent < myLength && myCurrent.IsRemoved(myGraph))
0249 {
0250 ++myCurrent;
0251 }
0252 }
0253 }
0254
0255 const BRepGraph& myGraph;
0256 TypedId myCurrent = TypedId::Start();
0257 TypedId myLength;
0258 };
0259
0260
0261
0262
0263
0264 using BRepGraph_SolidIterator = BRepGraph_Iterator<BRepGraphInc::SolidDef>;
0265 using BRepGraph_ShellIterator = BRepGraph_Iterator<BRepGraphInc::ShellDef>;
0266 using BRepGraph_FaceIterator = BRepGraph_Iterator<BRepGraphInc::FaceDef>;
0267 using BRepGraph_WireIterator = BRepGraph_Iterator<BRepGraphInc::WireDef>;
0268 using BRepGraph_EdgeIterator = BRepGraph_Iterator<BRepGraphInc::EdgeDef>;
0269 using BRepGraph_VertexIterator = BRepGraph_Iterator<BRepGraphInc::VertexDef>;
0270 using BRepGraph_CoEdgeIterator = BRepGraph_Iterator<BRepGraphInc::CoEdgeDef>;
0271 using BRepGraph_CompoundIterator = BRepGraph_Iterator<BRepGraphInc::CompoundDef>;
0272 using BRepGraph_CompSolidIterator = BRepGraph_Iterator<BRepGraphInc::CompSolidDef>;
0273 using BRepGraph_ProductIterator = BRepGraph_Iterator<BRepGraphInc::ProductDef>;
0274 using BRepGraph_OccurrenceIterator = BRepGraph_Iterator<BRepGraphInc::OccurrenceDef>;
0275
0276
0277
0278
0279
0280
0281 using BRepGraph_FullSolidIterator = BRepGraph_Iterator<BRepGraphInc::SolidDef, true>;
0282 using BRepGraph_FullShellIterator = BRepGraph_Iterator<BRepGraphInc::ShellDef, true>;
0283 using BRepGraph_FullFaceIterator = BRepGraph_Iterator<BRepGraphInc::FaceDef, true>;
0284 using BRepGraph_FullWireIterator = BRepGraph_Iterator<BRepGraphInc::WireDef, true>;
0285 using BRepGraph_FullEdgeIterator = BRepGraph_Iterator<BRepGraphInc::EdgeDef, true>;
0286 using BRepGraph_FullVertexIterator = BRepGraph_Iterator<BRepGraphInc::VertexDef, true>;
0287 using BRepGraph_FullCoEdgeIterator = BRepGraph_Iterator<BRepGraphInc::CoEdgeDef, true>;
0288 using BRepGraph_FullCompoundIterator = BRepGraph_Iterator<BRepGraphInc::CompoundDef, true>;
0289 using BRepGraph_FullCompSolidIterator = BRepGraph_Iterator<BRepGraphInc::CompSolidDef, true>;
0290 using BRepGraph_FullProductIterator = BRepGraph_Iterator<BRepGraphInc::ProductDef, true>;
0291 using BRepGraph_FullOccurrenceIterator = BRepGraph_Iterator<BRepGraphInc::OccurrenceDef, true>;
0292
0293
0294
0295
0296
0297 class BRepGraph_RootProductIterator
0298 {
0299 public:
0300 explicit BRepGraph_RootProductIterator(const BRepGraph& theGraph)
0301 : myRoots(theGraph.RootProductIds())
0302 {
0303 }
0304
0305 [[nodiscard]] bool More() const { return myIndex < myRoots.Size(); }
0306
0307 void Next() { ++myIndex; }
0308
0309 [[nodiscard]] const BRepGraph_ProductId& Current() const { return myRoots.Value(myIndex); }
0310
0311 NCollection_ForwardRangeIterator<BRepGraph_RootProductIterator> begin()
0312 {
0313 return NCollection_ForwardRangeIterator<BRepGraph_RootProductIterator>(this);
0314 }
0315
0316 NCollection_ForwardRangeSentinel end() const { return NCollection_ForwardRangeSentinel{}; }
0317
0318 private:
0319 const NCollection_LinearVector<BRepGraph_ProductId>& myRoots;
0320 size_t myIndex = 0;
0321 };
0322
0323 #endif