File indexing completed on 2026-09-28 09:19:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraph_RelatedIterator_HeaderFile
0015 #define _BRepGraph_RelatedIterator_HeaderFile
0016
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_DefsIterator.hxx>
0019 #include <BRepGraph_RefsIterator.hxx>
0020 #include <BRepGraph_ReverseIterator.hxx>
0021 #include <BRepGraph_RefsView.hxx>
0022 #include <BRepGraph_Tool.hxx>
0023 #include <BRepGraph_TopoView.hxx>
0024 #include <NCollection_ForwardRange.hxx>
0025 #include <NCollection_LinearVector.hxx>
0026
0027
0028
0029
0030
0031
0032
0033 class BRepGraph_RelatedIterator
0034 {
0035 public:
0036
0037
0038
0039
0040 enum class RelationKind
0041 {
0042 BoundaryEdge,
0043 AdjacentFace,
0044 OuterWire,
0045 ReferencedByFace,
0046 IncidentVertex,
0047 WireCoEdge,
0048 OwningFace,
0049 IncidentEdge,
0050 ParentEdge,
0051 SeamPair,
0052 };
0053
0054
0055 enum class Stage
0056 {
0057 First,
0058 Second,
0059 Third,
0060 Finished,
0061 };
0062
0063
0064
0065
0066 BRepGraph_RelatedIterator(const BRepGraph& theGraph, const BRepGraph_NodeId theNode)
0067 : myGraph(&theGraph),
0068 myNode(theNode)
0069 {
0070 advance();
0071 }
0072
0073
0074 [[nodiscard]] bool More() const { return myHasCurrent; }
0075
0076
0077 void Next()
0078 {
0079 if (!myHasCurrent)
0080 {
0081 return;
0082 }
0083 advance();
0084 }
0085
0086
0087 [[nodiscard]] const BRepGraph_NodeId& Current() const { return myCurrent; }
0088
0089
0090 [[nodiscard]] RelationKind CurrentRelation() const { return myRelation; }
0091
0092
0093 NCollection_ForwardRangeIterator<BRepGraph_RelatedIterator> begin()
0094 {
0095 return NCollection_ForwardRangeIterator<BRepGraph_RelatedIterator>(this);
0096 }
0097
0098
0099 NCollection_ForwardRangeSentinel end() const { return NCollection_ForwardRangeSentinel{}; }
0100
0101 private:
0102 [[nodiscard]] bool setCurrent(const BRepGraph_NodeId theNode, const RelationKind theRelation);
0103
0104 template <class IteratorT>
0105 [[nodiscard]] bool advanceRefChildren(IteratorT theIterator, const RelationKind theRelation)
0106 {
0107 for (; theIterator.More(); theIterator.Next())
0108 {
0109 if (theIterator.Index() < myIndex)
0110 {
0111 continue;
0112 }
0113
0114 myIndex = theIterator.Index() + 1;
0115 BRepGraph_NodeId aChildNode;
0116 if constexpr (std::is_convertible_v<decltype(theIterator.CurrentId()), BRepGraph_RefId>)
0117 {
0118 aChildNode = myGraph->Refs().Gen().ChildNode(theIterator.CurrentId());
0119 }
0120 else
0121 {
0122 aChildNode = BRepGraph_NodeId(theIterator.CurrentId());
0123 }
0124 return setCurrent(aChildNode, theRelation);
0125 }
0126
0127 return false;
0128 }
0129
0130 template <class IteratorT>
0131 [[nodiscard]] bool advanceDefChildren(IteratorT theIterator, const RelationKind theRelation)
0132 {
0133 for (; theIterator.More(); theIterator.Next())
0134 {
0135 if (theIterator.Index() < myIndex)
0136 {
0137 continue;
0138 }
0139
0140 myIndex = theIterator.Index() + 1;
0141 return setCurrent(BRepGraph_NodeId(theIterator.CurrentId()), theRelation);
0142 }
0143
0144 return false;
0145 }
0146
0147 [[nodiscard]] bool advanceFaceBoundaryEdge();
0148
0149 [[nodiscard]] bool advanceAdjacentFace();
0150
0151 [[nodiscard]] bool advanceEdgeVertex()
0152 {
0153 return advanceDefChildren(
0154 BRepGraph_DefsVertexOfEdge(*myGraph, BRepGraph_EdgeId::FromNodeId(myNode)),
0155 RelationKind::IncidentVertex);
0156 }
0157
0158
0159
0160 template <typename TypedIdT>
0161 [[nodiscard]] bool advanceParents(const NCollection_LinearVector<TypedIdT>& theParents,
0162 const RelationKind theRelation)
0163 {
0164 BRepGraph_ReverseIterator::ParentsOf<TypedIdT, NCollection_LinearVector<TypedIdT>> anIt(
0165 *myGraph,
0166 theParents,
0167 myIndex);
0168 if (anIt.More())
0169 {
0170 myIndex = anIt.Index() + 1;
0171 return setCurrent(BRepGraph_NodeId(anIt.CurrentId()), theRelation);
0172 }
0173
0174 return false;
0175 }
0176
0177 template <typename IteratorT>
0178 [[nodiscard]] bool advanceParentIterator(IteratorT theIterator, const RelationKind theRelation)
0179 {
0180 if (theIterator.More())
0181 {
0182 myIndex = theIterator.Index() + 1;
0183 return setCurrent(BRepGraph_NodeId(theIterator.CurrentId()), theRelation);
0184 }
0185 return false;
0186 }
0187
0188 Standard_EXPORT void advance();
0189
0190 private:
0191 const BRepGraph* myGraph;
0192 BRepGraph_NodeId myNode;
0193 BRepGraph_NodeId myCurrent;
0194 RelationKind myRelation = RelationKind::BoundaryEdge;
0195 Stage myStage = Stage::First;
0196 uint32_t myIndex = 0;
0197 uint32_t myInnerIndex = 0;
0198 uint32_t myDeepIndex = 0;
0199 bool myHasCurrent = false;
0200 };
0201
0202 #endif