Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:35

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 #ifndef _BRepGraph_EditorView_HeaderFile
0015 #define _BRepGraph_EditorView_HeaderFile
0016 
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_ItemId.hxx>
0019 #include <BRepGraph_MutGuard.hxx>
0020 #include <BRepGraph_SupplementEditor.hxx>
0021 #include <BRepGraphInc_Definition.hxx>
0022 #include <BRepGraphInc_ParityOrientation.hxx>
0023 #include <BRepGraphInc_Populate.hxx>
0024 #include <BRepGraphInc_Reference.hxx>
0025 #include <BRepGraphInc_Representation.hxx>
0026 #include <NCollection_Array1.hxx>
0027 #include <NCollection_LinearVector.hxx>
0028 #include <TCollection_AsciiString.hxx>
0029 #include <GeomAbs_Shape.hxx>
0030 #include <gp_Pnt2d.hxx>
0031 #include <TopAbs_Orientation.hxx>
0032 #include <TopLoc_Location.hxx>
0033 
0034 #include <utility>
0035 
0036 class Geom_Surface;
0037 class Geom_Curve;
0038 class Geom2d_Curve;
0039 class Poly_Triangulation;
0040 class Poly_Polygon3D;
0041 class Poly_Polygon2D;
0042 class Poly_PolygonOnTriangulation;
0043 
0044 //! @brief Non-const view for programmatic graph construction and structural editing.
0045 //!
0046 //! The single mutation entry point for a BRepGraph instance. Provides:
0047 //! - Structural creation via entity-scoped nested Ops classes (VertexOps, EdgeOps,
0048 //!   CoEdgeOps, WireOps, FaceOps, ShellOps, SolidOps, CompoundOps, CompSolidOps,
0049 //!   ProductOps, GenOps) to create topology definition nodes (vertices, edges, wires,
0050 //!   faces, shells, solids, compounds) and assembly nodes (products, occurrences)
0051 //!   without an existing TopoDS_Shape.
0052 //! - Field-level RAII-scoped mutation via Mut*() guards (Edges().Mut, Faces().Mut,
0053 //!   Products().Mut, Occurrences().Mut, Edges().Mut, Faces().Mut,
0054 //!   etc.) with automatic cache invalidation and upward SubtreeGen propagation on
0055 //!   guard destruction.
0056 //! - Incremental shape appending, soft-deletion of nodes, and deferred invalidation
0057 //!   mode for batched structural edit loops under external serialization.
0058 //! Obtained via BRepGraph::Editor().
0059 //!
0060 //! Each Ops class is accessed via a non-const reference accessor:
0061 //!   theGraph.Editor().Vertices().Add(...)
0062 //!   theGraph.Editor().Edges().Add(...)
0063 //!   theGraph.Editor().CoEdges().Add(edge, face, curve2d, first, last, ori)
0064 //!   theGraph.Editor().Products().Add(shapeRoot, placement)
0065 //!   theGraph.Editor().Gen().RemoveNode(...)
0066 //!
0067 //! Contract notes:
0068 //! - Add* methods return BRepGraph_NodeId() on invalid inputs and do not
0069 //!   partially modify the graph; call IsValid() on the returned id to check
0070 //!   success
0071 //! - invalid inputs include wrong kind, out-of-range ids, or removed referenced
0072 //!   nodes unless a method documents stricter accepted-input rules
0073 //! - linking methods such as Shells().Add() and Solids().Add()
0074 //!   return an invalid typed RefId on failure and otherwise keep ownership explicit
0075 //!   in the reference layer
0076 //! - use Mut*() guards for scoped field mutation on existing active
0077 //!   definitions, references, and representations
0078 class BRepGraph::EditorView
0079 {
0080 public:
0081   //! @brief Vertex creation operations.
0082   class VertexOps
0083   {
0084   public:
0085     //! Add a vertex definition to the graph.
0086     //! @param[in] thePoint     3D coordinates
0087     //! @param[in] theTolerance vertex tolerance
0088     //! @return typed vertex definition identifier
0089     [[nodiscard]] Standard_EXPORT BRepGraph_VertexId Add(const gp_Pnt& thePoint,
0090                                                          const double  theTolerance);
0091 
0092     //! Return scoped mutable vertex definition guard.
0093     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::VertexDef> Mut(
0094       const BRepGraph_VertexId theVertex);
0095 
0096     //! Return scoped mutable vertex reference guard.
0097     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::VertexRef> MutRef(
0098       const BRepGraph_VertexRefId theVertexRef);
0099 
0100     //! Set the 3D point of a vertex definition and fire immediate notification.
0101     //! @param[in] theVertex typed vertex definition identifier
0102     //! @param[in] thePoint  new 3D coordinates
0103     Standard_EXPORT void SetPoint(const BRepGraph_VertexId theVertex, const gp_Pnt& thePoint);
0104 
0105     //! Set the 3D point of a vertex definition inside a batched mutation scope.
0106     //! Marks the guard dirty so the destructor fires a single notification.
0107     //! @param[in] theMut   active mutable vertex guard
0108     //! @param[in] thePoint new 3D coordinates
0109     Standard_EXPORT void SetPoint(BRepGraph_MutGuard<BRepGraphInc::VertexDef>& theMut,
0110                                   const gp_Pnt&                                thePoint);
0111 
0112     //! Set the tolerance of a vertex definition.
0113     Standard_EXPORT void SetTolerance(const BRepGraph_VertexId theVertex,
0114                                       const double             theTolerance);
0115 
0116     //! Set the tolerance inside a batched mutation scope.
0117     Standard_EXPORT void SetTolerance(BRepGraph_MutGuard<BRepGraphInc::VertexDef>& theMut,
0118                                       const double                                 theTolerance);
0119 
0120     //! Set the orientation of a vertex reference.
0121     Standard_EXPORT void SetRefOrientation(const BRepGraph_VertexRefId           theVertexRef,
0122                                            const BRepGraphInc::ParityOrientation theOrientation);
0123 
0124     //! Set the orientation inside a batched mutation scope.
0125     Standard_EXPORT void SetRefOrientation(BRepGraph_MutGuard<BRepGraphInc::VertexRef>& theMut,
0126                                            const BRepGraphInc::ParityOrientation theOrientation);
0127 
0128     //! Rewire a vertex reference to a different vertex def (rebinds VertexToEdges if parent is
0129     //! Edge).
0130     Standard_EXPORT void SetRefChildVertexId(const BRepGraph_VertexRefId theVertexRef,
0131                                              const BRepGraph_VertexId    theVertex);
0132     Standard_EXPORT void SetRefChildVertexId(BRepGraph_MutGuard<BRepGraphInc::VertexRef>& theMut,
0133                                              const BRepGraph_VertexId theVertex);
0134 
0135   private:
0136     friend class EditorView;
0137 
0138     explicit VertexOps(BRepGraph* theGraph)
0139         : myGraph(theGraph)
0140     {
0141     }
0142 
0143     BRepGraph* myGraph;
0144   };
0145 
0146   //! @brief Edge creation and editing operations.
0147   class EdgeOps
0148   {
0149   public:
0150     //! Add an edge definition to the graph.
0151     //! @param[in] theStartVtx  typed start vertex definition identifier
0152     //! @param[in] theEndVtx    typed end vertex definition identifier
0153     //! @param[in] theCurve     3D curve (may be null for degenerate edges)
0154     //! @param[in] theFirst     first curve parameter
0155     //! @param[in] theLast      last curve parameter
0156     //! @param[in] theTolerance edge tolerance
0157     //! @return typed edge definition identifier, or invalid if either referenced
0158     //!         vertex id is out of range or removed
0159     [[nodiscard]] Standard_EXPORT BRepGraph_EdgeId Add(const BRepGraph_VertexId       theStartVtx,
0160                                                        const BRepGraph_VertexId       theEndVtx,
0161                                                        const occ::handle<Geom_Curve>& theCurve,
0162                                                        const double                   theFirst,
0163                                                        const double                   theLast,
0164                                                        const double                   theTolerance);
0165 
0166     //! Split a single edge definition at a vertex and 3D-curve parameter.
0167     //! Creates two new EdgeDef slots, splits all PCurve nodes at the corresponding
0168     //! 2D parameter, and updates every wire that contained the original edge.
0169     //! @param[in]  theEdgeEntity  edge to split (must not be degenerate)
0170     //! @param[in]  theSplitVertex vertex definition at the split point (already in graph)
0171     //! @param[in]  theSplitParam  parameter on the 3D curve at the split point
0172     //! @param[out] theSubA        sub-edge: StartVertex -> SplitVertex
0173     //! @param[out] theSubB        sub-edge: SplitVertex -> EndVertex
0174     Standard_EXPORT void Split(const BRepGraph_EdgeId   theEdgeEntity,
0175                                const BRepGraph_VertexId theSplitVertex,
0176                                const double             theSplitParam,
0177                                BRepGraph_EdgeId&        theSubA,
0178                                BRepGraph_EdgeId&        theSubB);
0179 
0180     //! Detach one exact edge-owned vertex ref from an edge definition.
0181     //! Supports only the persisted boundary slots (StartVertexRefId /
0182     //! EndVertexRefId). Supplemental direct-vertex usages are stored in
0183     //! BRepGraph_LayerTopoSupplement and are not removed through this API.
0184     //! @param[in] theChildEdgeId   edge definition identifier
0185     //! @param[in] theVertexRefId exact edge-owned vertex reference identifier
0186     //! @return true if the active edge-owned usage was removed
0187     [[nodiscard]] Standard_EXPORT bool RemoveVertex(const BRepGraph_EdgeId      theChildEdgeId,
0188                                                     const BRepGraph_VertexRefId theVertexRefId);
0189 
0190     //! Remap one edge-owned vertex reference to point at a different vertex
0191     //! definition, preserving the existing orientation and local location.
0192     //! Intended for boundary-vertex substitution without a full edge rebuild
0193     //! (e.g. stitching shared endpoints after a ShapeFix pass).
0194     //! @param[in] theChildEdgeId       edge owning the vertex reference
0195     //! @param[in] theOldVertexRefId  exact boundary vertex reference to remap
0196     //! @param[in] theNewChildVertexId  replacement vertex definition
0197     //! @return typed id of the newly created vertex reference, or invalid if
0198     //!         any input was inactive or the old ref did not belong to this edge
0199     [[nodiscard]] Standard_EXPORT BRepGraph_VertexRefId
0200       ReplaceVertex(const BRepGraph_EdgeId      theChildEdgeId,
0201                     const BRepGraph_VertexRefId theOldVertexRefId,
0202                     const BRepGraph_VertexId    theNewChildVertexId);
0203 
0204     //! Return scoped mutable edge definition guard.
0205     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::EdgeDef> Mut(
0206       const BRepGraph_EdgeId theEdge);
0207 
0208     //! Reverse the edge: swap StartVertexRefId and EndVertexRefId. Used by
0209     //! healing/sewing when a caller wants the edge's boundary order flipped.
0210     //! Does not alter the parametric range (callers needing reparametrization
0211     //! should follow up with SetParamRange).
0212     //! @param[in] theEdge edge definition identifier
0213     Standard_EXPORT void Reverse(const BRepGraph_EdgeId theEdge);
0214 
0215     //! Set the tolerance of an edge definition and fire immediate notification.
0216     //! @param[in] theEdge      typed edge definition identifier
0217     //! @param[in] theTolerance new tolerance value
0218     Standard_EXPORT void SetTolerance(const BRepGraph_EdgeId theEdge, double theTolerance);
0219 
0220     //! Set the tolerance of an edge definition inside a batched mutation scope.
0221     //! @param[in] theMut       active mutable edge guard
0222     //! @param[in] theTolerance new tolerance value
0223     Standard_EXPORT void SetTolerance(BRepGraph_MutGuard<BRepGraphInc::EdgeDef>& theMut,
0224                                       double                                     theTolerance);
0225 
0226     //! Set the parametric range of an edge definition.
0227     Standard_EXPORT void SetParamRange(const BRepGraph_EdgeId theEdge,
0228                                        const double           theFirst,
0229                                        const double           theLast);
0230     Standard_EXPORT void SetParamRange(BRepGraph_MutGuard<BRepGraphInc::EdgeDef>& theMut,
0231                                        const double                               theFirst,
0232                                        const double                               theLast);
0233 
0234     //! Set the 3D curve on an edge. Creates an owned EdgeCurve3DRep record
0235     //! and an associated Curve3DRep for edge geometry access.
0236     //! @param[in] theEdge  edge definition identifier
0237     //! @param[in] theCurve 3D curve geometry (must not be null)
0238     //! @param[in] theFirst first curve parameter
0239     //! @param[in] theLast  last curve parameter
0240     Standard_EXPORT void SetCurve(const BRepGraph_EdgeId         theEdge,
0241                                   const occ::handle<Geom_Curve>& theCurve,
0242                                   const double                   theFirst,
0243                                   const double                   theLast);
0244 
0245     //! Clear the 3D curve on an edge. Removes the owned use record binding.
0246     //! @param[in] theEdge edge definition identifier
0247     Standard_EXPORT void ClearCurve(const BRepGraph_EdgeId theEdge);
0248 
0249     //! Set the persistent 3D polygon on an edge. Creates an owned EdgePolygon3DRep record.
0250     //! @param[in] theEdge    edge definition identifier
0251     //! @param[in] thePolygon 3D polygon (must not be null)
0252     Standard_EXPORT void SetPersistentPolygon3D(const BRepGraph_EdgeId             theEdge,
0253                                                 const occ::handle<Poly_Polygon3D>& thePolygon);
0254 
0255     //! Clear the persistent 3D polygon on an edge.
0256     //! @param[in] theEdge edge definition identifier
0257     Standard_EXPORT void ClearPersistentPolygon3D(const BRepGraph_EdgeId theEdge);
0258 
0259     //! Set the start vertex-ref id and rebind the vertex-to-edge relation.
0260     Standard_EXPORT void SetStartVertexRefId(const BRepGraph_EdgeId      theEdge,
0261                                              const BRepGraph_VertexRefId theVertexRef);
0262     Standard_EXPORT void SetStartVertexRefId(BRepGraph_MutGuard<BRepGraphInc::EdgeDef>& theMut,
0263                                              const BRepGraph_VertexRefId theVertexRef);
0264 
0265     //! Set the end vertex-ref id and rebind the vertex-to-edge relation.
0266     Standard_EXPORT void SetEndVertexRefId(const BRepGraph_EdgeId      theEdge,
0267                                            const BRepGraph_VertexRefId theVertexRef);
0268     Standard_EXPORT void SetEndVertexRefId(BRepGraph_MutGuard<BRepGraphInc::EdgeDef>& theMut,
0269                                            const BRepGraph_VertexRefId                theVertexRef);
0270 
0271   private:
0272     friend class EditorView;
0273 
0274     explicit EdgeOps(BRepGraph* theGraph)
0275         : myGraph(theGraph)
0276     {
0277     }
0278 
0279     BRepGraph* myGraph;
0280   };
0281 
0282   //! @brief CoEdge and PCurve operations.
0283   class CoEdgeOps
0284   {
0285   public:
0286     //! Assign or clear the PCurve bound to an existing coedge.
0287     //! Creates a new Curve2DRep for non-null curves and stores its id on the coedge.
0288     //! Pass a null handle to clear the stored PCurve binding.
0289     //! @param[in] theCoEdge  typed coedge identifier to update
0290     //! @param[in] theCurve2d new 2D curve geometry, or null to clear
0291     Standard_EXPORT void SetPCurve(const BRepGraph_CoEdgeId         theCoEdge,
0292                                    const occ::handle<Geom2d_Curve>& theCurve2d);
0293 
0294     //! Create a new CoEdge entity linking an edge with an orientation.
0295     //! The CoEdge is free-floating (no parent wire); bind it to a wire
0296     //! via WireOps::Add().
0297     //! @param[in] theEdge       typed edge definition identifier
0298     //! @param[in] theOrientation orientation of the edge in the wire
0299     //! @return typed coedge identifier, or invalid if the edge is invalid
0300     [[nodiscard]] Standard_EXPORT BRepGraph_CoEdgeId
0301       Add(const BRepGraph_EdgeId theEdge, const BRepGraphInc::ParityOrientation theOrientation);
0302 
0303     //! Create a new CoEdge entity with a PCurve for a given edge-face pair.
0304     //! Creates a new CoEdge entity with Curve2DRep and updates relation tables.
0305     //! This always appends a new CoEdge entry for the edge-face pair; callers
0306     //! should avoid duplicate creation unless multiple bindings are intentional
0307     //! for the modeled topology.
0308     //! For editing an already identified CoEdge inside a larger
0309     //! mutation sequence, use CoEdges().SetPCurve().
0310     //! @param[in] theEdgeEntity      typed edge definition identifier
0311     //! @param[in] theFaceEntity      typed face definition identifier
0312     //! @param[in] theCurve2d         2D curve geometry
0313     //! @param[in] theFirst           first curve parameter
0314     //! @param[in] theLast            last curve parameter
0315     //! @param[in] theEdgeOrientation edge orientation on the face
0316     //! @return typed coedge identifier, or invalid if inputs are not active
0317     [[nodiscard]] Standard_EXPORT BRepGraph_CoEdgeId
0318       Add(const BRepGraph_EdgeId                theEdgeEntity,
0319           const BRepGraph_FaceId                theFaceEntity,
0320           const occ::handle<Geom2d_Curve>&      theCurve2d,
0321           const double                          theFirst,
0322           const double                          theLast,
0323           const BRepGraphInc::ParityOrientation theEdgeOrientation = TopAbs_FORWARD);
0324 
0325     //! Return scoped mutable coedge definition guard.
0326     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef> Mut(
0327       const BRepGraph_CoEdgeId theCoEdge);
0328 
0329     //! Set the parametric range of a coedge definition and fire immediate notification.
0330     //! @param[in] theCoEdge  typed coedge definition identifier
0331     //! @param[in] theFirst   new first parameter value
0332     //! @param[in] theLast    new last parameter value
0333     Standard_EXPORT void SetParamRange(const BRepGraph_CoEdgeId theCoEdge,
0334                                        double                   theFirst,
0335                                        double                   theLast);
0336 
0337     //! Set the parametric range of a coedge definition inside a batched mutation scope.
0338     //! @param[in] theMut   active mutable coedge guard
0339     //! @param[in] theFirst new first parameter value
0340     //! @param[in] theLast  new last parameter value
0341     Standard_EXPORT void SetParamRange(BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef>& theMut,
0342                                        double                                       theFirst,
0343                                        double                                       theLast);
0344 
0345     //! Set the orientation of a coedge definition.
0346     Standard_EXPORT void SetOrientation(const BRepGraph_CoEdgeId              theCoEdge,
0347                                         const BRepGraphInc::ParityOrientation theOrientation);
0348     Standard_EXPORT void SetOrientation(BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef>& theMut,
0349                                         const BRepGraphInc::ParityOrientation theOrientation);
0350 
0351     //! Set the PCurve on a coedge. Creates an owned CoEdgeCurve2DRep record.
0352     //! @param[in] theCoEdge  coedge definition identifier
0353     //! @param[in] theCurve2d 2D curve geometry (must not be null)
0354     //! @param[in] theFirst   first curve parameter
0355     //! @param[in] theLast    last curve parameter
0356     Standard_EXPORT void SetPCurve(const BRepGraph_CoEdgeId         theCoEdge,
0357                                    const occ::handle<Geom2d_Curve>& theCurve2d,
0358                                    const double                     theFirst,
0359                                    const double                     theLast);
0360 
0361     //! Clear the PCurve on a coedge.
0362     //! @param[in] theCoEdge coedge definition identifier
0363     Standard_EXPORT void ClearPCurve(const BRepGraph_CoEdgeId theCoEdge);
0364 
0365     //! Set the persistent 2D polygon on a coedge.
0366     //! @param[in] theCoEdge  coedge definition identifier
0367     //! @param[in] thePolygon 2D polygon (must not be null)
0368     Standard_EXPORT void SetPersistentPolygon2D(const BRepGraph_CoEdgeId           theCoEdge,
0369                                                 const occ::handle<Poly_Polygon2D>& thePolygon);
0370 
0371     //! Set the persistent polygon-on-triangulation on a coedge.
0372     //! The triangulation is resolved via CoEdgeDef.FaceId -> FaceDef.TriangulationRepId.
0373     //! @param[in] theCoEdge       coedge definition identifier
0374     //! @param[in] thePolygon      polygon-on-triangulation (must not be null)
0375     Standard_EXPORT void SetPersistentPolygonOnTri(
0376       const BRepGraph_CoEdgeId                        theCoEdge,
0377       const occ::handle<Poly_PolygonOnTriangulation>& thePolygon);
0378 
0379     //! Drop face-bound parametric representation (PCurve, param range, continuity, UVs)
0380     //! while keeping structural links - used when the owning face is removed.
0381     Standard_EXPORT void ResetPCurveBinding(const BRepGraph_CoEdgeId theCoEdge);
0382     Standard_EXPORT void ResetPCurveBinding(BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef>& theMut);
0383 
0384     //! Set the seam-pair id linking two coedges of a seam edge (invalid breaks the link).
0385     // To establish seam-ness, ensure two CoEdges exist on the same (Edge, Face)
0386     // with opposite orientations; the seam relation is then queryable via
0387     // BRepGraph_Tool::CoEdge::SeamPair.
0388 
0389     //! Rewire a coedge to a different child edge and rebind edge parent/use relations.
0390     Standard_EXPORT void SetChildEdgeId(const BRepGraph_CoEdgeId theCoEdge,
0391                                         const BRepGraph_EdgeId   theEdge);
0392     Standard_EXPORT void SetChildEdgeId(BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef>& theMut,
0393                                         const BRepGraph_EdgeId                       theEdge);
0394 
0395     //! Rewire a coedge to a different owning face and rebind edge-to-face relations.
0396     Standard_EXPORT void SetFaceId(const BRepGraph_CoEdgeId theCoEdge,
0397                                    const BRepGraph_FaceId   theFace);
0398     Standard_EXPORT void SetFaceId(BRepGraph_MutGuard<BRepGraphInc::CoEdgeDef>& theMut,
0399                                    const BRepGraph_FaceId                       theFace);
0400 
0401   private:
0402     friend class EditorView;
0403 
0404     explicit CoEdgeOps(BRepGraph* theGraph)
0405         : myGraph(theGraph)
0406     {
0407     }
0408 
0409     BRepGraph* myGraph;
0410   };
0411 
0412   //! @brief Wire creation and editing operations.
0413   class WireOps
0414   {
0415   public:
0416     //! Status returned by wire coedge-order prechecks.
0417     enum class CoEdgeOrderStatus
0418     {
0419       Ready,                //!< Input is valid and already connected in given order.
0420       Reordered,            //!< Input is valid after internal canonical reordering.
0421       AlreadyCurrent,       //!< Input equals current stored order; mutation can be skipped.
0422       AlreadyContained,     //!< Append precheck found the coedge already in the wire.
0423       Empty,                //!< Input contains no coedges.
0424       InvalidWire,          //!< Wire id is invalid or removed.
0425       SizeMismatch,         //!< Input size differs from current wire coedge count.
0426       DuplicateCoEdge,      //!< Input repeats a coedge id.
0427       InvalidCoEdge,        //!< Input references an invalid, removed, or incomplete coedge.
0428       CoEdgeAlreadyBound,   //!< Add precheck found a coedge already owned by a wire.
0429       CoEdgeNotOwnedByWire, //!< Set-order precheck found a coedge not owned by the wire.
0430       NotPermutation,       //!< Set-order input is not a permutation of current coedges.
0431       Disconnected          //!< Coedges cannot form a connected chain.
0432     };
0433 
0434     //! Status returned by wire edge-replacement prechecks.
0435     enum class ReplaceEdgeStatus
0436     {
0437       Ready,          //!< Replacement is valid and preserves wire connectivity.
0438       AlreadyCurrent, //!< Old and new edge are the same and no mutation is needed.
0439       InvalidWire,    //!< Wire id is invalid or removed.
0440       InvalidOldEdge, //!< Old edge id is invalid, removed, or not used by the wire.
0441       InvalidNewEdge, //!< New edge id is invalid or removed.
0442       Disconnected    //!< Replacement would break the ordered coedge chain.
0443     };
0444 
0445     //! Precheck free-floating CoEdges for WireOps::Add().
0446     //! @param[in] theCoEdgeIds candidate coedge identifiers
0447     //! @return status describing whether the input can form a wire
0448     [[nodiscard]] Standard_EXPORT CoEdgeOrderStatus
0449       CheckCoEdgeOrder(const NCollection_Array1<BRepGraph_CoEdgeId>& theCoEdgeIds) const;
0450 
0451     //! Precheck owned CoEdges for WireOps::SetCoEdgeOrder().
0452     //! @param[in] theWire      wire definition identifier
0453     //! @param[in] theCoEdgeIds candidate coedge identifiers
0454     //! @return status describing whether the input can replace the stored order
0455     [[nodiscard]] Standard_EXPORT CoEdgeOrderStatus
0456       CheckCoEdgeOrder(const BRepGraph_WireId                        theWire,
0457                        const NCollection_Array1<BRepGraph_CoEdgeId>& theCoEdgeIds) const;
0458 
0459     //! Precheck appending a free CoEdge to an existing wire.
0460     //! @param[in] theWire     wire definition identifier
0461     //! @param[in] theCoEdgeId free coedge candidate
0462     //! @return status describing whether the append can preserve connected order
0463     [[nodiscard]] Standard_EXPORT CoEdgeOrderStatus
0464       CheckAppendCoEdge(const BRepGraph_WireId theWire, const BRepGraph_CoEdgeId theCoEdgeId) const;
0465 
0466     //! Precheck replacing one edge by another in an existing wire.
0467     //! @param[in] theWire    wire definition identifier
0468     //! @param[in] theOldEdge edge currently used by one or more wire coedges
0469     //! @param[in] theNewEdge replacement edge
0470     //! @param[in] theReversed if true, replacement coedge orientation is reversed
0471     //! @return status describing whether replacement preserves connected order
0472     [[nodiscard]] Standard_EXPORT ReplaceEdgeStatus
0473       CheckReplaceEdge(const BRepGraph_WireId theWire,
0474                        const BRepGraph_EdgeId theOldEdge,
0475                        const BRepGraph_EdgeId theNewEdge,
0476                        const bool             theReversed) const;
0477 
0478     //! Add a wire definition from pre-created CoEdges.
0479     //! Each CoEdge must be free-floating (no parent wire yet).
0480     //! The method binds all CoEdges to the new wire and updates relation tables.
0481     //! @param[in] theCoEdgeIds ordered coedge identifiers
0482     //! @return typed wire definition identifier, or invalid if any referenced
0483     //!         coedge is invalid or already bound to a wire
0484     [[nodiscard]] Standard_EXPORT BRepGraph_WireId
0485       Add(const NCollection_Array1<BRepGraph_CoEdgeId>& theCoEdgeIds);
0486 
0487     //! Replace one edge with another in a wire definition.
0488     //! Updates the CoEdge's EdgeIdx to point to the new edge, adjusts orientation
0489     //! if theReversed, and incrementally updates relation tables.
0490     //! @param[in] theChildWireId     wire definition identifier
0491     //! @param[in] theOldEdgeEntity edge to replace
0492     //! @param[in] theNewEdgeEntity replacement edge
0493     //! @param[in] theReversed      if true, reverse the orientation of the replacement
0494     Standard_EXPORT void ReplaceEdge(const BRepGraph_WireId theChildWireId,
0495                                      const BRepGraph_EdgeId theOldEdgeEntity,
0496                                      const BRepGraph_EdgeId theNewEdgeEntity,
0497                                      const bool             theReversed);
0498 
0499     //! Detach one exact coedge entry from a wire definition.
0500     //! Use BRepGraph_CoEdgesOfWire::CurrentId() when removing from a wire
0501     //! iterator. The method removes the exact ordered coedge entry, updates
0502     //! relation tables, and prunes the CoEdge node when it has no other active
0503     //! usages.
0504     //! @param[in] theChildWireId wire definition identifier
0505     //! @param[in] theCoEdgeId  exact wire-owned coedge identifier
0506     //! @return true if the active wire-owned usage was removed
0507     [[nodiscard]] Standard_EXPORT bool RemoveCoEdge(const BRepGraph_WireId   theChildWireId,
0508                                                     const BRepGraph_CoEdgeId theCoEdgeId);
0509 
0510     //! Reverse the wire: flip the order of the wire's CoEdgeIds and flip each
0511     //! owned CoEdge's orientation. Used by healing/sewing to invert a loop.
0512     //! @param[in] theWire wire definition identifier
0513     Standard_EXPORT void Reverse(const BRepGraph_WireId theWire);
0514 
0515     //! Replace the ordered CoEdge relation vector with a permutation of its
0516     //! current content.
0517     //! @param[in] theWire       wire definition identifier
0518     //! @param[in] theCoEdgeIds  new ordered CoEdge identifiers
0519     //! @return true if the order was accepted and applied
0520     [[nodiscard]] Standard_EXPORT bool SetCoEdgeOrder(
0521       const BRepGraph_WireId                        theWire,
0522       const NCollection_Array1<BRepGraph_CoEdgeId>& theCoEdgeIds);
0523 
0524     //! Return scoped mutable wire definition guard.
0525     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::WireDef> Mut(
0526       const BRepGraph_WireId theWire);
0527 
0528     //! Return scoped mutable wire reference guard.
0529     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::WireRef> MutRef(
0530       const BRepGraph_WireRefId theWireRef);
0531 
0532     //! Set the orientation of a wire reference.
0533     Standard_EXPORT void SetRefOrientation(const BRepGraph_WireRefId             theWireRef,
0534                                            const BRepGraphInc::ParityOrientation theOrientation);
0535     Standard_EXPORT void SetRefOrientation(BRepGraph_MutGuard<BRepGraphInc::WireRef>& theMut,
0536                                            const BRepGraphInc::ParityOrientation theOrientation);
0537 
0538     //! Rewire a wire reference to a different wire def (rebinds WireToFaces if parent is Face).
0539     Standard_EXPORT void SetRefChildWireId(const BRepGraph_WireRefId theWireRef,
0540                                            const BRepGraph_WireId    theWire);
0541     Standard_EXPORT void SetRefChildWireId(BRepGraph_MutGuard<BRepGraphInc::WireRef>& theMut,
0542                                            const BRepGraph_WireId                     theWire);
0543 
0544   private:
0545     friend class EditorView;
0546 
0547     explicit WireOps(BRepGraph* theGraph)
0548         : myGraph(theGraph)
0549     {
0550     }
0551 
0552     BRepGraph* myGraph;
0553   };
0554 
0555   //! @brief Face creation and editing operations.
0556   class FaceOps
0557   {
0558   public:
0559     //! Add a face definition to the graph.
0560     //! @param[in] theSurface    surface geometry
0561     //! @param[in] theOuterWire  typed outer wire definition identifier
0562     //! @param[in] theInnerWires typed inner wire definition identifiers
0563     //! @param[in] theTolerance  face tolerance
0564     //! @return typed face definition identifier, or invalid if any referenced
0565     //!         wire id is out of range or removed
0566     [[nodiscard]] Standard_EXPORT BRepGraph_FaceId
0567       Add(const occ::handle<Geom_Surface>&            theSurface,
0568           const BRepGraph_WireId                      theOuterWire,
0569           const NCollection_Array1<BRepGraph_WireId>& theInnerWires,
0570           const double                                theTolerance);
0571 
0572     //! Append a wire usage to an existing face definition.
0573     //! @param[in] theFaceEntity typed face definition identifier
0574     //! @param[in] theWireEntity typed wire definition identifier
0575     //! @param[in] theOri        orientation of the wire usage on the face
0576     //! @return typed wire reference identifier, or invalid if inputs are not
0577     //!         active
0578     [[nodiscard]] Standard_EXPORT BRepGraph_WireRefId
0579       Append(const BRepGraph_FaceId                theFaceEntity,
0580              const BRepGraph_WireId                theWireEntity,
0581              const BRepGraphInc::ParityOrientation theOri = TopAbs_FORWARD);
0582 
0583     //! Detach one exact wire ref from a face definition.
0584     //! Use BRepGraph_RefsWireOfFace::CurrentId() when removing from a face
0585     //! iterator. The method removes the exact WireRef entry, erases it from
0586     //! the face's ordered ref sequence, updates relation tables, and prunes the
0587     //! Wire subtree when it has no other active usages.
0588     //! @param[in] theFaceId face definition identifier
0589     //! @param[in] theWireRefId exact face-owned wire reference identifier
0590     //! @return true if the active face-owned usage was removed
0591     [[nodiscard]] Standard_EXPORT bool RemoveWire(const BRepGraph_FaceId    theFaceId,
0592                                                   const BRepGraph_WireRefId theWireRefId);
0593 
0594     //! Return scoped mutable face definition guard.
0595     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::FaceDef> Mut(
0596       const BRepGraph_FaceId theFace);
0597 
0598     //! Return scoped mutable face reference guard.
0599     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::FaceRef> MutRef(
0600       const BRepGraph_FaceRefId theFaceRef);
0601 
0602     //! Set the tolerance of a face definition and fire immediate notification.
0603     //! @param[in] theFace      typed face definition identifier
0604     //! @param[in] theTolerance new tolerance value
0605     Standard_EXPORT void SetTolerance(const BRepGraph_FaceId theFace, double theTolerance);
0606 
0607     //! Set the tolerance of a face definition inside a batched mutation scope.
0608     //! @param[in] theMut       active mutable face guard
0609     //! @param[in] theTolerance new tolerance value
0610     Standard_EXPORT void SetTolerance(BRepGraph_MutGuard<BRepGraphInc::FaceDef>& theMut,
0611                                       double                                     theTolerance);
0612 
0613     //! Set the surface on a face. Creates an owned FaceSurfaceRep record
0614     //! and an associated SurfaceRep for face geometry access.
0615     //! @param[in] theFace    face definition identifier
0616     //! @param[in] theSurface surface geometry (must not be null)
0617     Standard_EXPORT void SetSurface(const BRepGraph_FaceId           theFace,
0618                                     const occ::handle<Geom_Surface>& theSurface);
0619 
0620     //! Clear the surface on a face. Removes the owned use record binding.
0621     //! @param[in] theFace face definition identifier
0622     Standard_EXPORT void ClearSurface(const BRepGraph_FaceId theFace);
0623 
0624     //! Set the persistent triangulation on a face. Creates an owned FaceTriangulationRep record.
0625     //! Also creates a TriangulationRep for backward compatibility.
0626     //! @param[in] theFace         face definition identifier
0627     //! @param[in] theTriangulation triangulation mesh (must not be null)
0628     Standard_EXPORT void SetPersistentTriangulation(
0629       const BRepGraph_FaceId                 theFace,
0630       const occ::handle<Poly_Triangulation>& theTriangulation);
0631 
0632     //! Clear the persistent triangulation on a face.
0633     //! @param[in] theFace face definition identifier
0634     Standard_EXPORT void ClearPersistentTriangulation(const BRepGraph_FaceId theFace);
0635 
0636     //! Set the orientation of a face reference and fire immediate notification.
0637     //! @param[in] theFaceRef     typed face reference identifier
0638     //! @param[in] theOrientation new orientation value
0639     Standard_EXPORT void SetRefOrientation(const BRepGraph_FaceRefId       theFaceRef,
0640                                            BRepGraphInc::ParityOrientation theOrientation);
0641 
0642     //! Set the orientation of a face reference inside a batched mutation scope.
0643     //! @param[in] theMut         active mutable face reference guard
0644     //! @param[in] theOrientation new orientation value
0645     Standard_EXPORT void SetRefOrientation(BRepGraph_MutGuard<BRepGraphInc::FaceRef>& theMut,
0646                                            BRepGraphInc::ParityOrientation theOrientation);
0647 
0648     //! Rewire a face reference to a different face def (rebinds FaceToShells if parent is Shell).
0649     Standard_EXPORT void SetRefFaceId(const BRepGraph_FaceRefId theFaceRef,
0650                                       const BRepGraph_FaceId    theFace);
0651     Standard_EXPORT void SetRefFaceId(BRepGraph_MutGuard<BRepGraphInc::FaceRef>& theMut,
0652                                       const BRepGraph_FaceId                     theFace);
0653 
0654   private:
0655     friend class EditorView;
0656 
0657     explicit FaceOps(BRepGraph* theGraph)
0658         : myGraph(theGraph)
0659     {
0660     }
0661 
0662     BRepGraph* myGraph;
0663   };
0664 
0665   //! @brief Shell creation and editing operations.
0666   class ShellOps
0667   {
0668   public:
0669     //! Add an empty shell definition to the graph.
0670     //! @return typed shell definition identifier
0671     [[nodiscard]] Standard_EXPORT BRepGraph_ShellId Add();
0672 
0673     //! Append a face to a shell.
0674     //! Appends FaceRef and stores its FaceRefId in shell FaceRefIds.
0675     //! @param[in] theShellEntity typed shell definition identifier
0676     //! @param[in] theFaceEntity  typed face definition identifier
0677     //! @param[in] theOri         orientation of the face in the shell
0678     //! @return typed face reference identifier, or invalid if inputs are not active
0679     Standard_EXPORT BRepGraph_FaceRefId
0680       Append(const BRepGraph_ShellId               theShellEntity,
0681              const BRepGraph_FaceId                theFaceEntity,
0682              const BRepGraphInc::ParityOrientation theOri = TopAbs_FORWARD);
0683 
0684     //! Batch-append multiple faces to a shell.
0685     //! Two-pass: validates all inputs first, then links all.
0686     //! @param[in] theShellEntity typed shell definition identifier
0687     //! @param[in] theFaceIds     face definition identifiers to append
0688     //! @param[in] theOrientations optional parity orientations (empty = all FORWARD)
0689     //! @return array of created face reference ids, empty on validation failure
0690     [[nodiscard]] Standard_EXPORT NCollection_Array1<BRepGraph_FaceRefId> Append(
0691       const BRepGraph_ShellId                                    theShellEntity,
0692       const NCollection_Array1<BRepGraph_FaceId>&                theFaceIds,
0693       const NCollection_Array1<BRepGraphInc::ParityOrientation>& theOrientations =
0694         NCollection_Array1<BRepGraphInc::ParityOrientation>());
0695 
0696     //! Detach one exact face ref from a shell definition.
0697     //! Use BRepGraph_RefsFaceOfShell::CurrentId() when removing from a shell
0698     //! iterator. The method removes the exact FaceRef entry, erases it from the
0699     //! shell's ordered ref sequence, updates relation tables, and prunes the
0700     //! Face subtree when it has no other active usages.
0701     //! @param[in] theChildShellId shell definition identifier
0702     //! @param[in] theFaceRefId  exact shell-owned face reference identifier
0703     //! @return true if the active shell-owned usage was removed
0704     [[nodiscard]] Standard_EXPORT bool RemoveFace(const BRepGraph_ShellId   theChildShellId,
0705                                                   const BRepGraph_FaceRefId theFaceRefId);
0706 
0707     //! Batch-remove multiple face refs from a shell definition.
0708     //! All-or-nothing: validates all inputs first, then removes all.
0709     //! @param[in] theShellId   shell definition identifier
0710     //! @param[in] theFaceRefs  face reference identifiers to remove
0711     //! @return true if all refs were successfully removed
0712     [[nodiscard]] Standard_EXPORT bool RemoveFaces(
0713       const BRepGraph_ShellId                        theShellId,
0714       const NCollection_Array1<BRepGraph_FaceRefId>& theFaceRefs);
0715 
0716     //! Return scoped mutable shell definition guard.
0717     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::ShellDef> Mut(
0718       const BRepGraph_ShellId theShell);
0719 
0720     //! Return scoped mutable shell reference guard.
0721     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::ShellRef> MutRef(
0722       const BRepGraph_ShellRefId theShellRef);
0723 
0724     //! Set the orientation of a shell reference.
0725     Standard_EXPORT void SetRefOrientation(const BRepGraph_ShellRefId            theShellRef,
0726                                            const BRepGraphInc::ParityOrientation theOrientation);
0727 
0728     //! Set the orientation inside a batched mutation scope.
0729     Standard_EXPORT void SetRefOrientation(BRepGraph_MutGuard<BRepGraphInc::ShellRef>& theMut,
0730                                            const BRepGraphInc::ParityOrientation theOrientation);
0731 
0732     //! Rewire a shell reference to a different shell def (rebinds ShellToSolid if parent is Solid).
0733     Standard_EXPORT void SetRefChildShellId(const BRepGraph_ShellRefId theShellRef,
0734                                             const BRepGraph_ShellId    theShell);
0735     Standard_EXPORT void SetRefChildShellId(BRepGraph_MutGuard<BRepGraphInc::ShellRef>& theMut,
0736                                             const BRepGraph_ShellId                     theShell);
0737 
0738   private:
0739     friend class EditorView;
0740 
0741     explicit ShellOps(BRepGraph* theGraph)
0742         : myGraph(theGraph)
0743     {
0744     }
0745 
0746     BRepGraph* myGraph;
0747   };
0748 
0749   //! @brief Solid creation and editing operations.
0750   class SolidOps
0751   {
0752   public:
0753     //! Add an empty solid definition to the graph.
0754     //! @return typed solid definition identifier
0755     [[nodiscard]] Standard_EXPORT BRepGraph_SolidId Add();
0756 
0757     //! Append a shell to a solid.
0758     //! Appends ShellRef and stores its ShellRefId in solid ShellRefIds.
0759     //! @param[in] theSolidEntity typed solid definition identifier
0760     //! @param[in] theShellEntity typed shell definition identifier
0761     //! @param[in] theOri         orientation of the shell in the solid
0762     //! @return typed shell reference identifier, or invalid if inputs are not active
0763     Standard_EXPORT BRepGraph_ShellRefId
0764       Append(const BRepGraph_SolidId               theSolidEntity,
0765              const BRepGraph_ShellId               theShellEntity,
0766              const BRepGraphInc::ParityOrientation theOri = TopAbs_FORWARD);
0767 
0768     //! Batch-append multiple shells to a solid.
0769     //! Two-pass: validates all inputs first, then links all.
0770     //! @param[in] theSolidEntity typed solid definition identifier
0771     //! @param[in] theShellIds    shell definition identifiers to append
0772     //! @param[in] theOrientations optional parity orientations (empty = all FORWARD)
0773     //! @return array of created shell reference ids, empty on validation failure
0774     [[nodiscard]] Standard_EXPORT NCollection_Array1<BRepGraph_ShellRefId> Append(
0775       const BRepGraph_SolidId                                    theSolidEntity,
0776       const NCollection_Array1<BRepGraph_ShellId>&               theShellIds,
0777       const NCollection_Array1<BRepGraphInc::ParityOrientation>& theOrientations =
0778         NCollection_Array1<BRepGraphInc::ParityOrientation>());
0779 
0780     //! Detach one exact shell ref from a solid definition.
0781     //! Use BRepGraph_RefsShellOfSolid::CurrentId() when removing from a solid
0782     //! iterator. The method removes the exact ShellRef entry, erases it from the
0783     //! solid's ordered ref sequence, updates relation tables, and prunes the
0784     //! Shell subtree when it has no other active usages.
0785     //! @param[in] theChildSolidId solid definition identifier
0786     //! @param[in] theShellRefId exact solid-owned shell reference identifier
0787     //! @return true if the active solid-owned usage was removed
0788     [[nodiscard]] Standard_EXPORT bool RemoveShell(const BRepGraph_SolidId    theChildSolidId,
0789                                                    const BRepGraph_ShellRefId theShellRefId);
0790 
0791     //! Batch-remove multiple shell refs from a solid definition.
0792     //! All-or-nothing: validates all inputs first, then removes all.
0793     //! @param[in] theSolidId    solid definition identifier
0794     //! @param[in] theShellRefs  shell reference identifiers to remove
0795     //! @return true if all refs were successfully removed
0796     [[nodiscard]] Standard_EXPORT bool RemoveShells(
0797       const BRepGraph_SolidId                         theSolidId,
0798       const NCollection_Array1<BRepGraph_ShellRefId>& theShellRefs);
0799 
0800     //! Return scoped mutable solid definition guard.
0801     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::SolidDef> Mut(
0802       const BRepGraph_SolidId theSolid);
0803 
0804     //! Return scoped mutable solid reference guard.
0805     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::SolidRef> MutRef(
0806       const BRepGraph_SolidRefId theSolidRef);
0807 
0808     //! Set the orientation of a solid reference.
0809     Standard_EXPORT void SetRefOrientation(const BRepGraph_SolidRefId            theSolidRef,
0810                                            const BRepGraphInc::ParityOrientation theOrientation);
0811 
0812     //! Set the orientation inside a batched mutation scope.
0813     Standard_EXPORT void SetRefOrientation(BRepGraph_MutGuard<BRepGraphInc::SolidRef>& theMut,
0814                                            const BRepGraphInc::ParityOrientation theOrientation);
0815 
0816     //! Rewire a solid reference to a different solid def (rebinds SolidToCompSolid if parent is
0817     //! CompSolid).
0818     Standard_EXPORT void SetRefChildSolidId(const BRepGraph_SolidRefId theSolidRef,
0819                                             const BRepGraph_SolidId    theSolid);
0820     Standard_EXPORT void SetRefChildSolidId(BRepGraph_MutGuard<BRepGraphInc::SolidRef>& theMut,
0821                                             const BRepGraph_SolidId                     theSolid);
0822 
0823   private:
0824     friend class EditorView;
0825 
0826     explicit SolidOps(BRepGraph* theGraph)
0827         : myGraph(theGraph)
0828     {
0829     }
0830 
0831     BRepGraph* myGraph;
0832   };
0833 
0834   //! @brief Compound creation and editing operations.
0835   class CompoundOps
0836   {
0837   public:
0838     //! Add a compound entity with ordered child usages.
0839     //! @param[in] theChildEntities child node identifiers
0840     //! @return typed compound definition identifier
0841     [[nodiscard]] Standard_EXPORT BRepGraph_CompoundId
0842       Add(const NCollection_Array1<BRepGraph_NodeId>& theChildEntities);
0843 
0844     //! Append a single child to an existing compound definition.
0845     //! @param[in] theCompoundEntity typed compound definition identifier
0846     //! @param[in] theChildEntity    typed child topology definition identifier
0847     //! @param[in] theOri            orientation of the child in the compound
0848     //! @return typed child reference identifier, or invalid if inputs are not active
0849     [[nodiscard]] Standard_EXPORT BRepGraph_ChildRefId
0850       Append(const BRepGraph_CompoundId            theCompoundEntity,
0851              const BRepGraph_NodeId                theChildEntity,
0852              const BRepGraphInc::ParityOrientation theOri = TopAbs_FORWARD);
0853 
0854     //! Batch-append multiple children to an existing compound definition.
0855     //! Two-pass: validates all inputs first, then links all.
0856     //! @param[in] theCompoundEntity typed compound definition identifier
0857     //! @param[in] theChildIds       child node identifiers to append
0858     //! @param[in] theOrientations   optional parity orientations (empty = all FORWARD)
0859     //! @return array of created child reference ids, empty on validation failure
0860     [[nodiscard]] Standard_EXPORT NCollection_Array1<BRepGraph_ChildRefId> Append(
0861       const BRepGraph_CompoundId                                 theCompoundEntity,
0862       const NCollection_Array1<BRepGraph_NodeId>&                theChildIds,
0863       const NCollection_Array1<BRepGraphInc::ParityOrientation>& theOrientations =
0864         NCollection_Array1<BRepGraphInc::ParityOrientation>());
0865 
0866     //! Detach one exact child ref from a compound definition.
0867     //! Use BRepGraph_RefsChildOfParent::CurrentId() when removing from a compound
0868     //! iterator. The method removes the exact ChildRef entry, erases it from the
0869     //! compound's ordered ref sequence, updates relation tables, and prunes the
0870     //! child subtree when it has no other active usages.
0871     //! @param[in] theCompoundDefId compound definition identifier
0872     //! @param[in] theChildRefId    exact compound-owned child reference identifier
0873     //! @return true if the active compound-owned usage was removed
0874     [[nodiscard]] Standard_EXPORT bool RemoveChild(const BRepGraph_CompoundId theCompoundDefId,
0875                                                    const BRepGraph_ChildRefId theChildRefId);
0876 
0877     //! Batch-remove multiple child refs from a compound definition.
0878     //! All-or-nothing: validates all inputs first, then removes all.
0879     //! @param[in] theCompoundId  compound definition identifier
0880     //! @param[in] theChildRefs   child reference identifiers to remove
0881     //! @return true if all refs were successfully removed
0882     [[nodiscard]] Standard_EXPORT bool RemoveChildren(
0883       const BRepGraph_CompoundId                      theCompoundId,
0884       const NCollection_Array1<BRepGraph_ChildRefId>& theChildRefs);
0885 
0886     //! Return scoped mutable compound definition guard.
0887     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::CompoundDef> Mut(
0888       const BRepGraph_CompoundId theCompound);
0889 
0890     //! Replace the child node of an existing child reference in a compound.
0891     //! Delegates to Gen().SetChildRefChildNodeId().
0892     //! @param[in] theChildRef typed child reference identifier
0893     //! @param[in] theNewChild new child node identifier
0894     Standard_EXPORT void ReplaceChild(const BRepGraph_ChildRefId theChildRef,
0895                                       const BRepGraph_NodeId     theNewChild);
0896 
0897   private:
0898     friend class EditorView;
0899 
0900     explicit CompoundOps(BRepGraph* theGraph)
0901         : myGraph(theGraph)
0902     {
0903     }
0904 
0905     BRepGraph* myGraph;
0906   };
0907 
0908   //! @brief CompSolid creation and editing operations.
0909   class CompSolidOps
0910   {
0911   public:
0912     //! Add a compsolid entity with ordered solid usages.
0913     //! @param[in] theSolidEntities typed child solid identifiers
0914     //! @return typed compsolid definition identifier
0915     [[nodiscard]] Standard_EXPORT BRepGraph_CompSolidId
0916       Add(const NCollection_Array1<BRepGraph_SolidId>& theSolidEntities);
0917 
0918     //! Append a single solid to an existing compsolid definition.
0919     //! @param[in] theCompSolidEntity typed compsolid definition identifier
0920     //! @param[in] theSolidEntity     typed solid definition identifier
0921     //! @param[in] theOri             orientation of the solid in the compsolid
0922     //! @return typed solid reference identifier, or invalid if inputs are not active
0923     [[nodiscard]] Standard_EXPORT BRepGraph_SolidRefId
0924       Append(const BRepGraph_CompSolidId           theCompSolidEntity,
0925              const BRepGraph_SolidId               theSolidEntity,
0926              const BRepGraphInc::ParityOrientation theOri = TopAbs_FORWARD);
0927 
0928     //! Batch-append multiple solids to an existing compsolid definition.
0929     //! Two-pass: validates all inputs first, then links all.
0930     //! @param[in] theCompSolidEntity typed compsolid definition identifier
0931     //! @param[in] theSolidIds        solid definition identifiers to append
0932     //! @param[in] theOrientations    optional parity orientations (empty = all FORWARD)
0933     //! @return array of created solid reference ids, empty on validation failure
0934     [[nodiscard]] Standard_EXPORT NCollection_Array1<BRepGraph_SolidRefId> Append(
0935       const BRepGraph_CompSolidId                                theCompSolidEntity,
0936       const NCollection_Array1<BRepGraph_SolidId>&               theSolidIds,
0937       const NCollection_Array1<BRepGraphInc::ParityOrientation>& theOrientations =
0938         NCollection_Array1<BRepGraphInc::ParityOrientation>());
0939 
0940     //! Detach one exact solid ref from a compsolid definition.
0941     //! Use BRepGraph_RefsSolidOfCompSolid::CurrentId() when removing from a
0942     //! compsolid iterator. The method removes the exact SolidRef entry, erases it
0943     //! from the compsolid's ordered ref sequence, updates relation tables, and
0944     //! prunes the Solid subtree when it has no other active usages.
0945     //! @param[in] theCompChildSolidId compsolid definition identifier
0946     //! @param[in] theSolidRefId     exact compsolid-owned solid reference identifier
0947     //! @return true if the active compsolid-owned usage was removed
0948     [[nodiscard]] Standard_EXPORT bool RemoveSolid(const BRepGraph_CompSolidId theCompChildSolidId,
0949                                                    const BRepGraph_SolidRefId  theSolidRefId);
0950 
0951     //! Batch-remove multiple solid refs from a compsolid definition.
0952     //! All-or-nothing: validates all inputs first, then removes all.
0953     //! @param[in] theCompSolidId compsolid definition identifier
0954     //! @param[in] theSolidRefs   solid reference identifiers to remove
0955     //! @return true if all refs were successfully removed
0956     [[nodiscard]] Standard_EXPORT bool RemoveSolids(
0957       const BRepGraph_CompSolidId                     theCompSolidId,
0958       const NCollection_Array1<BRepGraph_SolidRefId>& theSolidRefs);
0959 
0960     //! Return scoped mutable comp-solid definition guard.
0961     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::CompSolidDef> Mut(
0962       const BRepGraph_CompSolidId theCompSolid);
0963 
0964     //! Replace the solid of an existing solid reference in a compsolid.
0965     //! Delegates to Solids().SetRefChildSolidId().
0966     //! @param[in] theSolidRef typed solid reference identifier
0967     //! @param[in] theNewSolid new solid definition identifier
0968     Standard_EXPORT void ReplaceSolid(const BRepGraph_SolidRefId theSolidRef,
0969                                       const BRepGraph_SolidId    theNewSolid);
0970 
0971   private:
0972     friend class EditorView;
0973 
0974     explicit CompSolidOps(BRepGraph* theGraph)
0975         : myGraph(theGraph)
0976     {
0977     }
0978 
0979     BRepGraph* myGraph;
0980   };
0981 
0982   //! @brief Product and assembly low-level reconstruction primitives.
0983   //! Wire two existing entities together; for shape ingestion use BRepGraph::ShapesView::Add().
0984   class ProductOps
0985   {
0986   public:
0987     //! Create a Product wrapping an existing topology root via an Occurrence.
0988     //! The product is NOT added to document roots; call AppendDocumentRoot() explicitly
0989     //! when this Product is a document root.
0990     //! @param[in] theShapeRoot root topology NodeId for the part
0991     //! @param[in] thePlacement local placement stored on the root OccurrenceRef
0992     //! @return typed product definition identifier, or invalid if the root is
0993     //!         not an active topology definition node
0994     [[nodiscard]] Standard_EXPORT BRepGraph_ProductId
0995       Add(const BRepGraph_NodeId theShapeRoot,
0996           const TopLoc_Location& thePlacement = TopLoc_Location());
0997 
0998     //! Create an empty Product with no direct shape root; can later own child occurrences.
0999     //! The product is NOT added to document roots; call AppendDocumentRoot() explicitly
1000     //! when this Product is a document root.
1001     //! @return typed product definition identifier
1002     [[nodiscard]] Standard_EXPORT BRepGraph_ProductId Add();
1003 
1004     //! Add an active Product to document roots if it is not already listed.
1005     Standard_EXPORT void AppendDocumentRoot(const BRepGraph_ProductId theProductId);
1006 
1007     //! Append two existing Products via a fresh Occurrence.
1008     //! @param[in] theParentProduct       typed parent product identifier
1009     //! @param[in] theReferencedProduct   typed child product identifier being instantiated
1010     //! @param[in] thePlacement           local placement relative to parent
1011     //! @param[in] theParentOccurrence    optional placing occurrence (nested assembly chains)
1012     //! @param[out] theOutOccurrenceRefId optional out: typed ref id of the inserted OccurrenceRef
1013     //! @return typed occurrence definition identifier, or invalid if the chain is not active
1014     [[nodiscard]] Standard_EXPORT BRepGraph_OccurrenceId
1015       Append(const BRepGraph_ProductId    theParentProduct,
1016              const BRepGraph_ProductId    theReferencedProduct,
1017              const TopLoc_Location&       thePlacement,
1018              const BRepGraph_OccurrenceId theParentOccurrence   = BRepGraph_OccurrenceId(),
1019              BRepGraph_OccurrenceRefId*   theOutOccurrenceRefId = nullptr);
1020 
1021     //! Batch-append multiple child products to a parent product via fresh Occurrences.
1022     //! Two-pass: validates all inputs first, then links all.
1023     //! @param[in] theParentProduct  typed parent product identifier
1024     //! @param[in] theChildProducts  child product identifiers to instantiate
1025     //! @param[in] thePlacements     local placements per child (must match child count)
1026     //! @return array of created occurrence reference ids, empty on validation failure
1027     [[nodiscard]] Standard_EXPORT NCollection_Array1<BRepGraph_OccurrenceRefId> Append(
1028       const BRepGraph_ProductId                      theParentProduct,
1029       const NCollection_Array1<BRepGraph_ProductId>& theChildProducts,
1030       const NCollection_Array1<TopLoc_Location>&     thePlacements);
1031 
1032     //! Detach one exact occurrence ref from a product definition.
1033     //! Use BRepGraph_RefsOccurrenceOfProduct::CurrentId() when removing from a
1034     //! product iterator. The method removes the exact OccurrenceRef entry, erases
1035     //! it from the product's ordered ref sequence, updates relation tables, and
1036     //! prunes the occurrence subtree when it has no other active usages.
1037     //! @param[in] theProductDefId    product definition identifier
1038     //! @param[in] theOccurrenceRefId exact product-owned occurrence reference identifier
1039     //! @return true if the active product-owned usage was removed
1040     [[nodiscard]] Standard_EXPORT bool RemoveOccurrence(
1041       const BRepGraph_ProductId       theProductDefId,
1042       const BRepGraph_OccurrenceRefId theOccurrenceRefId);
1043 
1044     //! Batch-remove multiple occurrence refs from a product definition.
1045     //! All-or-nothing: validates all inputs first, then removes all.
1046     //! @param[in] theProductId     product definition identifier
1047     //! @param[in] theOccurrenceRefs occurrence reference identifiers to remove
1048     //! @return true if all refs were successfully removed
1049     [[nodiscard]] Standard_EXPORT bool RemoveOccurrences(
1050       const BRepGraph_ProductId                            theProductId,
1051       const NCollection_Array1<BRepGraph_OccurrenceRefId>& theOccurrenceRefs);
1052 
1053     //! Detach the scalar shape-root ownership from a product definition.
1054     //! If no other active product owns the same topology root afterward, the root
1055     //! subgraph is pruned as orphaned. The product loses its direct shape root;
1056     //! it is no longer a part, and it only remains an assembly if it still owns
1057     //! active child occurrences.
1058     //! @param[in] theProductDefId product definition identifier
1059     //! @return true if an active shape root was detached
1060     [[nodiscard]] Standard_EXPORT bool RemoveShapeRoot(const BRepGraph_ProductId theProductDefId);
1061 
1062     //! Return scoped mutable product definition guard.
1063     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::ProductDef> Mut(
1064       const BRepGraph_ProductId theProduct);
1065 
1066   private:
1067     friend class EditorView;
1068 
1069     explicit ProductOps(BRepGraph* theGraph)
1070         : myGraph(theGraph)
1071     {
1072     }
1073 
1074     BRepGraph* myGraph;
1075   };
1076 
1077   //! @brief Occurrence mutation operations.
1078   class OccurrenceOps
1079   {
1080   public:
1081     //! Return scoped mutable occurrence definition guard.
1082     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::OccurrenceDef> Mut(
1083       const BRepGraph_OccurrenceId theOccurrence);
1084 
1085     //! Return scoped mutable occurrence reference guard.
1086     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::OccurrenceRef> MutRef(
1087       const BRepGraph_OccurrenceRefId theOccurrenceRef);
1088 
1089     //! Set the local location of an occurrence reference and fire immediate notification.
1090     //! @param[in] theOccurrenceRef typed occurrence reference identifier
1091     //! @param[in] theLoc           new local location
1092     Standard_EXPORT void SetRefLocalLocation(const BRepGraph_OccurrenceRefId theOccurrenceRef,
1093                                              const TopLoc_Location&          theLoc);
1094 
1095     //! Set the local location of an occurrence reference inside a batched mutation scope.
1096     //! @param[in] theMut active mutable occurrence reference guard
1097     //! @param[in] theLoc new local location
1098     Standard_EXPORT void SetRefLocalLocation(
1099       BRepGraph_MutGuard<BRepGraphInc::OccurrenceRef>& theMut,
1100       const TopLoc_Location&                           theLoc);
1101 
1102     //! Set the child node referenced by an occurrence definition.
1103     //! Invalid or removed occurrence ids are ignored. The child must be an
1104     //! active topology node or an active Product; invalid, removed, and
1105     //! Occurrence child ids are ignored.
1106     Standard_EXPORT void SetChildNodeId(const BRepGraph_OccurrenceId theOccurrence,
1107                                         const BRepGraph_NodeId       theChildNodeId);
1108 
1109     //! Set the child node id inside a batched mutation scope. Invalid, removed,
1110     //! and Occurrence child ids are ignored.
1111     Standard_EXPORT void SetChildNodeId(BRepGraph_MutGuard<BRepGraphInc::OccurrenceDef>& theMut,
1112                                         const BRepGraph_NodeId theChildNodeId);
1113 
1114     //! Rewire an occurrence reference to a different occurrence def (rebinds ProductToOccurrences).
1115     Standard_EXPORT void SetRefChildOccurrenceId(const BRepGraph_OccurrenceRefId theOccurrenceRef,
1116                                                  const BRepGraph_OccurrenceId    theOccurrence);
1117     Standard_EXPORT void SetRefChildOccurrenceId(
1118       BRepGraph_MutGuard<BRepGraphInc::OccurrenceRef>& theMut,
1119       const BRepGraph_OccurrenceId                     theOccurrence);
1120 
1121   private:
1122     friend class EditorView;
1123 
1124     explicit OccurrenceOps(BRepGraph* theGraph)
1125         : myGraph(theGraph)
1126     {
1127     }
1128 
1129     BRepGraph* myGraph;
1130   };
1131 
1132   //! @brief Generic node, reference, and representation removal operations.
1133   class GenOps
1134   {
1135   public:
1136     //! Mark a node as removed (soft deletion).
1137     //! @param[in] theNode node to remove
1138     Standard_EXPORT void RemoveNode(const BRepGraph_NodeId theNode);
1139 
1140     //! Replace a node by another active node and mark the old node as removed.
1141     //! For Edge nodes: all CoEdges referencing the removed edge are reparented to
1142     //! the replacement edge (ChildEdgeId updated, relation entries rebound). This prevents
1143     //! orphaned CoEdges that would disappear from CoEdgesOfEdge() queries.
1144     //! If the replacement is active, layers receive OnNodeReplaced(theNode,
1145     //! theReplacement) for structural data migration. If the replacement is invalid
1146     //! or inactive, the operation falls back to OnNodeRemoved(theNode), matching pure
1147     //! deletion. Semantic history records are not inferred here; algorithms should
1148     //! record operation-specific history.
1149     //! @param[in] theNode        node to remove
1150     //! @param[in] theReplacement node that replaces theNode
1151     Standard_EXPORT void ReplaceNode(const BRepGraph_NodeId theNode,
1152                                      const BRepGraph_NodeId theReplacement);
1153 
1154     //! Mark a node and all its descendants as removed (cascading soft deletion).
1155     //! @param[in] theNode root node to remove
1156     Standard_EXPORT void RemoveSubgraph(const BRepGraph_NodeId theNode);
1157 
1158     //! Mark a reference entry as removed (soft deletion).
1159     //! This is the builder-level API for detaching a child usage from its parent
1160     //! without removing the referenced definition itself.
1161     //! Invalid or already-removed ids are ignored.
1162     //! @param[in] theRef reference entry to remove
1163     //! @return true if the reference transitioned from active to removed
1164     Standard_EXPORT bool RemoveRef(const BRepGraph_RefId theRef);
1165 
1166     //! Mark an exact parent-owned reference entry as removed (soft deletion).
1167     //! This overload validates that the reference really belongs to the supplied
1168     //! parent and can optionally prune the child subtree when the removed usage
1169     //! was the last active parent usage of that child definition.
1170     //! Use this overload for UI/path-driven detach operations where the parent
1171     //! context is part of the user's selection.
1172     //! @param[in] theParent              expected owning parent of the reference usage
1173     //! @param[in] theRef                 reference entry to remove
1174     //! @param[in] theToPruneOrphanedChild if true, remove the referenced child
1175     //!            subtree when no active parent usages remain after detachment
1176     //! @return true if the reference transitioned from active to removed
1177     Standard_EXPORT bool RemoveRef(const BRepGraph_NodeId theParent,
1178                                    const BRepGraph_RefId  theRef,
1179                                    const bool             theToPruneOrphanedChild);
1180 
1181     //! Return scoped mutable child reference guard. ChildRef is generic (the
1182     //! child node can be of any kind), so its Mut accessor lives on the
1183     //! cross-kind Gen() rather than on a per-kind Ops.
1184     [[nodiscard]] Standard_EXPORT BRepGraph_MutGuard<BRepGraphInc::ChildRef> MutChildRef(
1185       const BRepGraph_ChildRefId theChildRef);
1186 
1187     //! Set the local location of a child reference and fire immediate notification.
1188     //! @param[in] theChildRef typed child reference identifier
1189     //! @param[in] theLoc      new local location
1190     Standard_EXPORT void SetChildRefLocalLocation(const BRepGraph_ChildRefId theChildRef,
1191                                                   const TopLoc_Location&     theLoc);
1192 
1193     //! Set the orientation of a child reference.
1194     Standard_EXPORT void SetChildRefOrientation(
1195       const BRepGraph_ChildRefId            theChildRef,
1196       const BRepGraphInc::ParityOrientation theOrientation);
1197 
1198     //! Set the orientation inside a batched mutation scope.
1199     Standard_EXPORT void SetChildRefOrientation(
1200       BRepGraph_MutGuard<BRepGraphInc::ChildRef>& theMut,
1201       const BRepGraphInc::ParityOrientation       theOrientation);
1202 
1203     //! Rewire a child reference to a different child def (rebinds CompoundsOf<Kind>).
1204     Standard_EXPORT void SetChildRefChildNodeId(const BRepGraph_ChildRefId theChildRef,
1205                                                 const BRepGraph_NodeId     theChild);
1206     Standard_EXPORT void SetChildRefChildNodeId(BRepGraph_MutGuard<BRepGraphInc::ChildRef>& theMut,
1207                                                 const BRepGraph_NodeId theChild);
1208 
1209     //! Set the local location of a child reference inside a batched mutation scope.
1210     //! @param[in] theMut active mutable child reference guard
1211     //! @param[in] theLoc new local location
1212     Standard_EXPORT void SetChildRefLocalLocation(
1213       BRepGraph_MutGuard<BRepGraphInc::ChildRef>& theMut,
1214       const TopLoc_Location&                      theLoc);
1215 
1216     //! Apply a modification operation and record history.
1217     //! @param[in] theTarget   node to modify
1218     //! @param[in] theModifier callback that performs the modification and returns replacements
1219     //! @param[in] theOpLabel  human-readable operation label for history
1220     template <typename ModifierT>
1221     void ApplyModification(const BRepGraph_NodeId         theTarget,
1222                            ModifierT&&                    theModifier,
1223                            const TCollection_AsciiString& theOpLabel)
1224     {
1225       auto aProducedReplacements = std::forward<ModifierT>(theModifier)(*myGraph, theTarget);
1226       NCollection_LinearVector<BRepGraph_NodeId> aReplacements(aProducedReplacements.Size());
1227       for (const BRepGraph_NodeId& aNode : aProducedReplacements)
1228       {
1229         aReplacements.Append(aNode);
1230       }
1231       applyModificationImpl(theTarget, std::move(aReplacements), theOpLabel);
1232     }
1233 
1234     //! Clean up forward references to removed nodes in relation tables and
1235     //! references. After one or more RemoveNode calls, other entities may
1236     //! still hold stale child references pointing to removed nodes. This method
1237     //! marks those stale references as removed, detaches them from parent
1238     //! arrays, and updates relation entries for consistency.
1239     //! @post ValidateRelations() passes.
1240     Standard_EXPORT void CleanupRemovedReferences();
1241 
1242   private:
1243     friend class EditorView;
1244 
1245     explicit GenOps(BRepGraph* theGraph)
1246         : myGraph(theGraph)
1247     {
1248     }
1249 
1250     Standard_EXPORT void applyModificationImpl(
1251       const BRepGraph_NodeId                       theTarget,
1252       NCollection_LinearVector<BRepGraph_NodeId>&& theReplacements,
1253       const TCollection_AsciiString&               theOpLabel);
1254 
1255     BRepGraph* myGraph;
1256   };
1257 
1258 public:
1259   //! Return vertex creation operations.
1260   [[nodiscard]] VertexOps& Vertices() { return myVertexOps; }
1261 
1262   //! Return edge creation and editing operations.
1263   [[nodiscard]] EdgeOps& Edges() { return myEdgeOps; }
1264 
1265   //! Return coedge and PCurve operations.
1266   [[nodiscard]] CoEdgeOps& CoEdges() { return myCoEdgeOps; }
1267 
1268   //! Return wire creation and editing operations.
1269   [[nodiscard]] WireOps& Wires() { return myWireOps; }
1270 
1271   //! Return face creation and editing operations.
1272   [[nodiscard]] FaceOps& Faces() { return myFaceOps; }
1273 
1274   //! Return shell creation and editing operations.
1275   [[nodiscard]] ShellOps& Shells() { return myShellOps; }
1276 
1277   //! Return solid creation and editing operations.
1278   [[nodiscard]] SolidOps& Solids() { return mySolidOps; }
1279 
1280   //! Return compound creation and editing operations.
1281   [[nodiscard]] CompoundOps& Compounds() { return myCompoundOps; }
1282 
1283   //! Return compsolid creation and editing operations.
1284   [[nodiscard]] CompSolidOps& CompSolids() { return myCompSolidOps; }
1285 
1286   //! Return product and assembly creation and editing operations.
1287   [[nodiscard]] ProductOps& Products() { return myProductOps; }
1288 
1289   //! Return occurrence mutation operations.
1290   [[nodiscard]] OccurrenceOps& Occurrences() { return myOccurrenceOps; }
1291 
1292   //! Return generic node, reference, and representation removal operations.
1293   [[nodiscard]] GenOps& Gen() { return myGenOps; }
1294 
1295   //! Return runtime supplement attachment operations.
1296   [[nodiscard]] BRepGraph_SupplementEditor Supplement()
1297   {
1298     return BRepGraph_SupplementEditor(*myGraph);
1299   }
1300 
1301   //! Begin deferred invalidation mode.
1302   //! While active, markModified() only increments OwnGen + SubtreeGen and
1303   //! appends to the deferred list - without acquiring the shape-cache mutex
1304   //! or propagating upward.
1305   //! Call EndDeferredInvalidation() to batch-flush all accumulated changes.
1306   //! Intended for batch mutation loops (SameParameter, Sewing) where many
1307   //! entities are modified sequentially and upward propagation should be
1308   //! deferred until all mutations are complete.
1309   //! Prefer BRepGraph_DeferredScope RAII guard.
1310   //! @warning Deferred mode batches invalidation only; it does NOT serialize
1311   //! the mutation body. Callers must guarantee exclusive Editor() structural
1312   //! edit access for the whole deferred scope; concurrent Editor().Mut*()
1313   //! usage still requires external synchronization around the surrounding batch.
1314   Standard_EXPORT void BeginDeferredInvalidation();
1315 
1316   //! End deferred invalidation mode and batch-flush:
1317   //! propagates SubtreeGen upward for all modified entities from the deferred
1318   //! list. Shape cache entries are validated lazily via SubtreeGen comparison.
1319   Standard_EXPORT void EndDeferredInvalidation() noexcept;
1320 
1321   //! Check if deferred invalidation mode is currently active.
1322   //! @note This is a state flag only. It does not imply mutation ownership
1323   //! or synchronization guarantees.
1324   [[nodiscard]] Standard_EXPORT bool IsDeferredMode() const;
1325 
1326   //! A single boundary invariant issue detected by ValidateMutationBoundary().
1327   struct BoundaryIssue
1328   {
1329     BRepGraph_NodeId        NodeId;
1330     TCollection_AsciiString Description;
1331   };
1332 
1333   //! Finalize a batch of mutations.
1334   //! Validates relation consistency and asserts active entity counts
1335   //! match actual entity state.
1336   //! Call this after manual batch mutation loops, or rely on
1337   //! BRepGraph_DeferredScope to call it automatically at scope exit.
1338   Standard_EXPORT void CommitMutation() noexcept;
1339 
1340   //! Validate lightweight mutation-boundary invariants.
1341   //! @param[out] theIssues optional destination for detailed issues
1342   //! @return true if no issues were found
1343   [[nodiscard]] Standard_EXPORT bool ValidateMutationBoundary(
1344     NCollection_LinearVector<BoundaryIssue>* const theIssues = nullptr) const;
1345 
1346 private:
1347   friend class BRepGraph;
1348   friend struct BRepGraph_Data;
1349 
1350   explicit EditorView(BRepGraph* theGraph)
1351       : myGraph(theGraph),
1352         myVertexOps(theGraph),
1353         myEdgeOps(theGraph),
1354         myCoEdgeOps(theGraph),
1355         myWireOps(theGraph),
1356         myFaceOps(theGraph),
1357         myShellOps(theGraph),
1358         mySolidOps(theGraph),
1359         myCompoundOps(theGraph),
1360         myCompSolidOps(theGraph),
1361         myProductOps(theGraph),
1362         myOccurrenceOps(theGraph),
1363         myGenOps(theGraph)
1364   {
1365   }
1366 
1367   [[nodiscard]] Standard_EXPORT bool isOwned(const BRepGraph_ItemId theItem) const;
1368 
1369   [[nodiscard]] bool isOwned(const BRepGraph_NodeId theNode) const
1370   {
1371     return isOwned(BRepGraph_ItemId(theNode));
1372   }
1373 
1374   [[nodiscard]] bool isOwned(const BRepGraph_RefId theRef) const
1375   {
1376     return isOwned(BRepGraph_ItemId(theRef));
1377   }
1378 
1379   Standard_EXPORT void requireUnlocked(const BRepGraph_ItemId theItem,
1380                                        const char*            theOperation) const;
1381 
1382   void requireUnlocked(const BRepGraph_NodeId theNode, const char* theOperation) const
1383   {
1384     requireUnlocked(BRepGraph_ItemId(theNode), theOperation);
1385   }
1386 
1387   void requireUnlocked(const BRepGraph_RefId theRef, const char* theOperation) const
1388   {
1389     requireUnlocked(BRepGraph_ItemId(theRef), theOperation);
1390   }
1391 
1392   //! Verify no active MutGuard holds the given item.
1393   //! Used by structural operations (Remove*, Replace*, Add*) to prevent
1394   //! topology changes while a guard is active on the target item.
1395   Standard_EXPORT void requireNoActiveGuard(const BRepGraph_ItemId theItem,
1396                                             const char*            theOperation) const;
1397 
1398   void requireNoActiveGuard(const BRepGraph_NodeId theNode, const char* theOperation) const
1399   {
1400     requireNoActiveGuard(BRepGraph_ItemId(theNode), theOperation);
1401   }
1402 
1403   void requireNoActiveGuard(const BRepGraph_RefId theRef, const char* theOperation) const
1404   {
1405     requireNoActiveGuard(BRepGraph_ItemId(theRef), theOperation);
1406   }
1407 
1408   BRepGraph*    myGraph;
1409   VertexOps     myVertexOps;
1410   EdgeOps       myEdgeOps;
1411   CoEdgeOps     myCoEdgeOps;
1412   WireOps       myWireOps;
1413   FaceOps       myFaceOps;
1414   ShellOps      myShellOps;
1415   SolidOps      mySolidOps;
1416   CompoundOps   myCompoundOps;
1417   CompSolidOps  myCompSolidOps;
1418   ProductOps    myProductOps;
1419   OccurrenceOps myOccurrenceOps;
1420   GenOps        myGenOps;
1421 };
1422 
1423 #endif // _BRepGraph_EditorView_HeaderFile