File indexing completed on 2026-09-28 09:19:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraph_DefsIterator_HeaderFile
0015 #define _BRepGraph_DefsIterator_HeaderFile
0016
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_RefsView.hxx>
0019 #include <BRepGraph_TopoView.hxx>
0020 #include <NCollection_ForwardRange.hxx>
0021 #include <NCollection_LinearVector.hxx>
0022 #include <type_traits>
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 namespace BRepGraph_DefsIterator
0035 {
0036 template <typename ParentIdT,
0037 typename RefIdT,
0038 typename RefEntryT,
0039 typename ChildIdT,
0040 typename ChildDefT>
0041 struct BaseTraits
0042 {
0043 using ParentId = ParentIdT;
0044 using RefId = RefIdT;
0045 using RefEntry = RefEntryT;
0046 using ChildId = ChildIdT;
0047 using ChildDef = ChildDefT;
0048
0049 static constexpr bool THE_IS_DIRECT = std::is_same_v<RefId, ChildId>;
0050 };
0051
0052
0053 struct ShellOfSolidTraits : public BaseTraits<BRepGraph_SolidId,
0054 BRepGraph_ShellRefId,
0055 BRepGraphInc::ShellRef,
0056 BRepGraph_ShellId,
0057 BRepGraphInc::ShellDef>
0058 {
0059 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0060 {
0061 return theParent.IsValid(theGraph.Topo().Solids().Nb()) && !theParent.IsRemoved(theGraph);
0062 }
0063
0064 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0065 const ParentId theParent)
0066 {
0067 return theGraph.Topo().Solids().Relations(theParent).ShellRefIds;
0068 }
0069
0070 static const BRepGraphInc::ShellRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0071 {
0072 return theGraph.Refs().Shells().Entry(theRefId);
0073 }
0074
0075 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::ShellRef& theRef)
0076 {
0077 return theRef.ChildShellId;
0078 }
0079
0080 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0081 {
0082 return theGraph.Topo().Shells().Definition(theChildId);
0083 }
0084 };
0085
0086
0087 struct FaceOfShellTraits : public BaseTraits<BRepGraph_ShellId,
0088 BRepGraph_FaceRefId,
0089 BRepGraphInc::FaceRef,
0090 BRepGraph_FaceId,
0091 BRepGraphInc::FaceDef>
0092 {
0093 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0094 {
0095 return theParent.IsValid(theGraph.Topo().Shells().Nb()) && !theParent.IsRemoved(theGraph);
0096 }
0097
0098 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0099 const ParentId theParent)
0100 {
0101 return theGraph.Topo().Shells().Relations(theParent).FaceRefIds;
0102 }
0103
0104 static const BRepGraphInc::FaceRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0105 {
0106 return theGraph.Refs().Faces().Entry(theRefId);
0107 }
0108
0109 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::FaceRef& theRef)
0110 {
0111 return theRef.ChildFaceId;
0112 }
0113
0114 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0115 {
0116 return theGraph.Topo().Faces().Definition(theChildId);
0117 }
0118 };
0119
0120
0121 struct WireOfFaceTraits : public BaseTraits<BRepGraph_FaceId,
0122 BRepGraph_WireRefId,
0123 BRepGraphInc::WireRef,
0124 BRepGraph_WireId,
0125 BRepGraphInc::WireDef>
0126 {
0127 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0128 {
0129 return theParent.IsValid(theGraph.Topo().Faces().Nb()) && !theParent.IsRemoved(theGraph);
0130 }
0131
0132 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0133 const ParentId theParent)
0134 {
0135 return theGraph.Topo().Faces().Relations(theParent).WireRefIds;
0136 }
0137
0138 static const BRepGraphInc::WireRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0139 {
0140 return theGraph.Refs().Wires().Entry(theRefId);
0141 }
0142
0143 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::WireRef& theRef)
0144 {
0145 return theRef.ChildWireId;
0146 }
0147
0148 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0149 {
0150 return theGraph.Topo().Wires().Definition(theChildId);
0151 }
0152 };
0153
0154
0155 struct CoEdgeOfWireTraits : public BaseTraits<BRepGraph_WireId,
0156 BRepGraph_CoEdgeId,
0157 BRepGraphInc::CoEdgeDef,
0158 BRepGraph_CoEdgeId,
0159 BRepGraphInc::CoEdgeDef>
0160 {
0161 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0162 {
0163 return theParent.IsValid(theGraph.Topo().Wires().Nb()) && !theParent.IsRemoved(theGraph);
0164 }
0165
0166 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0167 const ParentId theParent)
0168 {
0169 return theGraph.Topo().Wires().Relations(theParent).CoEdgeIds;
0170 }
0171
0172 static const BRepGraphInc::CoEdgeDef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0173 {
0174 return theGraph.Topo().CoEdges().Definition(theRefId);
0175 }
0176
0177 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0178 {
0179 return theGraph.Topo().CoEdges().Definition(theChildId);
0180 }
0181 };
0182
0183
0184 struct EdgeOfWireTraits : public BaseTraits<BRepGraph_WireId,
0185 BRepGraph_CoEdgeId,
0186 BRepGraphInc::CoEdgeDef,
0187 BRepGraph_EdgeId,
0188 BRepGraphInc::EdgeDef>
0189 {
0190 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0191 {
0192 return theParent.IsValid(theGraph.Topo().Wires().Nb()) && !theParent.IsRemoved(theGraph);
0193 }
0194
0195 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0196 const ParentId theParent)
0197 {
0198 return theGraph.Topo().Wires().Relations(theParent).CoEdgeIds;
0199 }
0200
0201 static const BRepGraphInc::CoEdgeDef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0202 {
0203 return theGraph.Topo().CoEdges().Definition(theRefId);
0204 }
0205
0206 static ChildId ChildIdOf(const BRepGraph& theGraph, const BRepGraphInc::CoEdgeDef& theRef)
0207 {
0208 const BRepGraph_EdgeId aEdgeId = theRef.ChildEdgeId;
0209 if (!aEdgeId.IsValid(theGraph.Topo().Edges().Nb()) || aEdgeId.IsRemoved(theGraph))
0210 {
0211 return ChildId();
0212 }
0213 return aEdgeId;
0214 }
0215
0216 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0217 {
0218 return theGraph.Topo().Edges().Definition(theChildId);
0219 }
0220 };
0221
0222
0223 struct SolidOfCompSolidTraits : public BaseTraits<BRepGraph_CompSolidId,
0224 BRepGraph_SolidRefId,
0225 BRepGraphInc::SolidRef,
0226 BRepGraph_SolidId,
0227 BRepGraphInc::SolidDef>
0228 {
0229 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0230 {
0231 return theParent.IsValid(theGraph.Topo().CompSolids().Nb()) && !theParent.IsRemoved(theGraph);
0232 }
0233
0234 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0235 const ParentId theParent)
0236 {
0237 return theGraph.Topo().CompSolids().Relations(theParent).SolidRefIds;
0238 }
0239
0240 static const BRepGraphInc::SolidRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0241 {
0242 return theGraph.Refs().Solids().Entry(theRefId);
0243 }
0244
0245 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::SolidRef& theRef)
0246 {
0247 return theRef.ChildSolidId;
0248 }
0249
0250 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0251 {
0252 return theGraph.Topo().Solids().Definition(theChildId);
0253 }
0254 };
0255
0256
0257 struct ChildOfCompoundTraits : public BaseTraits<BRepGraph_CompoundId,
0258 BRepGraph_ChildRefId,
0259 BRepGraphInc::ChildRef,
0260 BRepGraph_NodeId,
0261 BRepGraphInc::BaseDef>
0262 {
0263 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0264 {
0265 return theParent.IsValid(theGraph.Topo().Compounds().Nb()) && !theParent.IsRemoved(theGraph);
0266 }
0267
0268 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0269 const ParentId theParent)
0270 {
0271 return theGraph.Topo().Compounds().Relations(theParent).ChildRefIds;
0272 }
0273
0274 static const BRepGraphInc::ChildRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0275 {
0276 return theGraph.Refs().Children().Entry(theRefId);
0277 }
0278
0279 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::ChildRef& theRef)
0280 {
0281 return theRef.ChildNodeId;
0282 }
0283
0284 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0285 {
0286 return *theGraph.Topo().Gen().TopoEntity(theChildId);
0287 }
0288 };
0289
0290
0291 struct OccurrenceOfProductTraits : public BaseTraits<BRepGraph_ProductId,
0292 BRepGraph_OccurrenceRefId,
0293 BRepGraphInc::OccurrenceRef,
0294 BRepGraph_OccurrenceId,
0295 BRepGraphInc::OccurrenceDef>
0296 {
0297 static bool IsParentValid(const BRepGraph& theGraph, const ParentId theParent)
0298 {
0299 return theParent.IsValid(theGraph.Topo().Products().Nb()) && !theParent.IsRemoved(theGraph);
0300 }
0301
0302 static const NCollection_LinearVector<RefId>& RefIds(const BRepGraph& theGraph,
0303 const ParentId theParent)
0304 {
0305 return theGraph.Topo().Products().Relations(theParent).OccurrenceRefIds;
0306 }
0307
0308 static const BRepGraphInc::OccurrenceRef& Ref(const BRepGraph& theGraph, const RefId theRefId)
0309 {
0310 return theGraph.Refs().Occurrences().Entry(theRefId);
0311 }
0312
0313 static ChildId ChildIdOf(const BRepGraph&, const BRepGraphInc::OccurrenceRef& theRef)
0314 {
0315 return theRef.ChildOccurrenceId;
0316 }
0317
0318 static const ChildDef& Child(const BRepGraph& theGraph, const ChildId theChildId)
0319 {
0320 return theGraph.Topo().Occurrences().Definition(theChildId);
0321 }
0322 };
0323
0324 template <typename TraitsT>
0325 class DefsOfParent
0326 {
0327 public:
0328 using ParentId = typename TraitsT::ParentId;
0329 using RefId = typename TraitsT::RefId;
0330 using ChildId = typename TraitsT::ChildId;
0331 using ChildDef = typename TraitsT::ChildDef;
0332
0333 DefsOfParent(const BRepGraph& theGraph, const ParentId theParent)
0334 : myGraph(theGraph)
0335 {
0336 if (!TraitsT::IsParentValid(theGraph, theParent))
0337 {
0338 return;
0339 }
0340
0341 myRefIds = &TraitsT::RefIds(theGraph, theParent);
0342 myLength = static_cast<uint32_t>(myRefIds->Size());
0343 if constexpr (std::is_convertible_v<RefId, BRepGraph_NodeId>)
0344 {
0345 myNbRefs = theGraph.Topo().Gen().Nb(BRepGraph_NodeId(RefId()).NodeKind);
0346 }
0347 else
0348 {
0349 myNbRefs = theGraph.Refs().Gen().Nb(BRepGraph_RefId(RefId()).RefKind);
0350 }
0351
0352 if constexpr (TraitsT::THE_IS_DIRECT)
0353 {
0354 myNbChildren = myNbRefs;
0355 }
0356 else
0357 {
0358 if constexpr (!std::is_same_v<ChildId, BRepGraph_NodeId>)
0359 {
0360 myNbChildren = theGraph.Topo().Gen().Nb(BRepGraph_NodeId(ChildId()).NodeKind);
0361 }
0362 }
0363 skipRemoved();
0364 }
0365
0366 [[nodiscard]] bool More() const { return myRefIds != nullptr && myIndex < myLength; }
0367
0368 void Next()
0369 {
0370 ++myIndex;
0371
0372 if (myRefIds != nullptr && myIndex < myLength)
0373 {
0374 const RefId aRefId = myRefIds->Value(static_cast<size_t>(myIndex));
0375 if (aRefId.IsValid(myNbRefs) && !aRefId.IsRemoved(myGraph))
0376 {
0377 if constexpr (TraitsT::THE_IS_DIRECT)
0378 {
0379 myCurrentChild = ChildId(aRefId);
0380 return;
0381 }
0382 else
0383 {
0384 const typename TraitsT::RefEntry& aRef = TraitsT::Ref(myGraph, aRefId);
0385 const ChildId aChildId = TraitsT::ChildIdOf(myGraph, aRef);
0386 if constexpr (std::is_same_v<ChildId, BRepGraph_NodeId>)
0387 {
0388 if (myGraph.Topo().Gen().IsActive(aChildId))
0389 {
0390 myCurrentChild = aChildId;
0391 return;
0392 }
0393 }
0394 else if (aChildId.IsValid(myNbChildren) && !aChildId.IsRemoved(myGraph))
0395 {
0396 myCurrentChild = aChildId;
0397 return;
0398 }
0399 }
0400 }
0401 }
0402
0403 skipRemoved();
0404 }
0405
0406 [[nodiscard]] ChildId CurrentId() const
0407 {
0408 Standard_ASSERT_VOID(More(), "DefsOfParent::CurrentId() called on exhausted iterator");
0409 return myCurrentChild;
0410 }
0411
0412 [[nodiscard]] const ChildDef& Current() const
0413 {
0414 Standard_ASSERT_VOID(More(), "DefsOfParent::Current() called on exhausted iterator");
0415 return TraitsT::Child(myGraph, CurrentId());
0416 }
0417
0418
0419 [[nodiscard]] RefId CurrentRefId() const
0420 {
0421 return myRefIds != nullptr && myIndex < myLength ? myRefIds->Value(static_cast<size_t>(myIndex))
0422 : RefId();
0423 }
0424
0425 [[nodiscard]] uint32_t Index() const { return myIndex; }
0426
0427
0428 NCollection_ForwardRangeIterator<DefsOfParent> begin()
0429 {
0430 return NCollection_ForwardRangeIterator<DefsOfParent>(this);
0431 }
0432
0433
0434 NCollection_ForwardRangeSentinel end() const { return NCollection_ForwardRangeSentinel{}; }
0435
0436 private:
0437 void skipRemoved()
0438 {
0439 while (myRefIds != nullptr && myIndex < myLength)
0440 {
0441 const RefId aRefId = myRefIds->Value(static_cast<size_t>(myIndex));
0442 if (aRefId.IsValid(myNbRefs) && !aRefId.IsRemoved(myGraph))
0443 {
0444 const ChildId aChildId = [&]() {
0445 if constexpr (TraitsT::THE_IS_DIRECT)
0446 {
0447 return ChildId(aRefId);
0448 }
0449 else
0450 {
0451 const typename TraitsT::RefEntry& aRef = TraitsT::Ref(myGraph, aRefId);
0452 return TraitsT::ChildIdOf(myGraph, aRef);
0453 }
0454 }();
0455 if constexpr (std::is_same_v<ChildId, BRepGraph_NodeId>)
0456 {
0457 if (myGraph.Topo().Gen().IsActive(aChildId))
0458 {
0459 myCurrentChild = aChildId;
0460 return;
0461 }
0462 }
0463 else if (aChildId.IsValid(myNbChildren) && !aChildId.IsRemoved(myGraph))
0464 {
0465 myCurrentChild = aChildId;
0466 return;
0467 }
0468 }
0469 ++myIndex;
0470 }
0471 }
0472
0473 const BRepGraph& myGraph;
0474 const NCollection_LinearVector<RefId>* myRefIds = nullptr;
0475 ChildId myCurrentChild{};
0476 uint32_t myIndex = 0;
0477 uint32_t myLength = 0;
0478 uint32_t myNbRefs = 0;
0479 uint32_t myNbChildren = 0;
0480 };
0481
0482
0483
0484
0485 class DefsVertexOfEdge
0486 {
0487 public:
0488 using ChildId = BRepGraph_VertexId;
0489 using ChildDef = BRepGraphInc::VertexDef;
0490
0491 DefsVertexOfEdge(const BRepGraph& theGraph, const BRepGraph_EdgeId theEdgeId)
0492 : myGraph(theGraph)
0493 {
0494 if (!theEdgeId.IsValid(theGraph.Topo().Edges().Nb()) || theEdgeId.IsRemoved(theGraph))
0495 {
0496 return;
0497 }
0498
0499 myEdge = &theGraph.Topo().Edges().Definition(theEdgeId);
0500 myLength = 2u;
0501 myNbVertexRefs = theGraph.Refs().Vertices().Nb();
0502 myNbVertices = theGraph.Topo().Vertices().Nb();
0503 skipRemoved();
0504 }
0505
0506 [[nodiscard]] bool More() const { return myEdge != nullptr && myIndex < myLength; }
0507
0508 void Next()
0509 {
0510 ++myIndex;
0511 skipRemoved();
0512 }
0513
0514 [[nodiscard]] ChildId CurrentId() const
0515 {
0516 Standard_ASSERT_VOID(More(), "DefsVertexOfEdge::CurrentId() called on exhausted iterator");
0517 return myGraph.Refs().Vertices().Entry(currentRefId()).ChildVertexId;
0518 }
0519
0520 [[nodiscard]] const ChildDef& Current() const
0521 {
0522 Standard_ASSERT_VOID(More(), "DefsVertexOfEdge::Current() called on exhausted iterator");
0523 return myGraph.Topo().Vertices().Definition(CurrentId());
0524 }
0525
0526
0527 [[nodiscard]] BRepGraph_VertexRefId CurrentRefId() const
0528 {
0529 return More() ? currentRefId() : BRepGraph_VertexRefId();
0530 }
0531
0532 [[nodiscard]] uint32_t Index() const { return myIndex; }
0533
0534
0535 NCollection_ForwardRangeIterator<DefsVertexOfEdge> begin()
0536 {
0537 return NCollection_ForwardRangeIterator<DefsVertexOfEdge>(this);
0538 }
0539
0540
0541 NCollection_ForwardRangeSentinel end() const { return NCollection_ForwardRangeSentinel{}; }
0542
0543 private:
0544 [[nodiscard]] BRepGraph_VertexRefId refIdAt(const uint32_t theIndex) const
0545 {
0546 if (theIndex == 0)
0547 {
0548 return myEdge->StartVertexRefId;
0549 }
0550 return myEdge->EndVertexRefId;
0551 }
0552
0553 [[nodiscard]] BRepGraph_VertexRefId currentRefId() const { return refIdAt(myIndex); }
0554
0555 void skipRemoved()
0556 {
0557 while (myEdge != nullptr && myIndex < myLength)
0558 {
0559 const BRepGraph_VertexRefId aRefId = refIdAt(myIndex);
0560 if (aRefId.IsValid(myNbVertexRefs) && !myGraph.Refs().Gen().IsRemoved(aRefId))
0561 {
0562 const BRepGraphInc::VertexRef& aRef = myGraph.Refs().Vertices().Entry(aRefId);
0563 if (!aRef.ChildVertexId.IsValid(myNbVertices) || aRef.ChildVertexId.IsRemoved(myGraph))
0564 {
0565 ++myIndex;
0566 continue;
0567 }
0568 return;
0569 }
0570 ++myIndex;
0571 }
0572 }
0573
0574 const BRepGraph& myGraph;
0575 const BRepGraphInc::EdgeDef* myEdge = nullptr;
0576 uint32_t myIndex = 0;
0577 uint32_t myLength = 0;
0578 uint32_t myNbVertexRefs = 0;
0579 uint32_t myNbVertices = 0;
0580 };
0581
0582 }
0583
0584 using BRepGraph_DefsShellOfSolid =
0585 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::ShellOfSolidTraits>;
0586 using BRepGraph_DefsFaceOfShell =
0587 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::FaceOfShellTraits>;
0588 using BRepGraph_DefsEdgeOfWire =
0589 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::EdgeOfWireTraits>;
0590 using BRepGraph_DefsWireOfFace =
0591 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::WireOfFaceTraits>;
0592 using BRepGraph_DefsCoEdgeOfWire =
0593 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::CoEdgeOfWireTraits>;
0594 using BRepGraph_DefsSolidOfCompSolid =
0595 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::SolidOfCompSolidTraits>;
0596 using BRepGraph_DefsChildOfCompound =
0597 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::ChildOfCompoundTraits>;
0598 using BRepGraph_DefsOccurrenceOfProduct =
0599 BRepGraph_DefsIterator::DefsOfParent<BRepGraph_DefsIterator::OccurrenceOfProductTraits>;
0600 using BRepGraph_DefsVertexOfEdge = BRepGraph_DefsIterator::DefsVertexOfEdge;
0601
0602 #endif