Back to home page

EIC code displayed by LXR

 
 

    


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

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_Validate_HeaderFile
0015 #define _BRepGraph_Validate_HeaderFile
0016 
0017 #include <BRepGraph.hxx>
0018 #include <BRepGraph_NodeId.hxx>
0019 #include <NCollection_LinearVector.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <TCollection_AsciiString.hxx>
0022 
0023 //! @brief Structural invariant checker for BRepGraph.
0024 //!
0025 //! Read-only algorithm that verifies the graph's internal consistency:
0026 //! cross-reference bounds, relation symmetry, incidence ref consistency,
0027 //! geometry reference validity, removed-node isolation, and wire connectivity.
0028 //!
0029 //! Distinct from BRepGraphCheck (geometric shape validity). This class
0030 //! checks the graph data structure itself.
0031 //!
0032 //! ### Validation Mode Check Matrix
0033 //!
0034 //! | Check                          | Lightweight | Audit |
0035 //! |--------------------------------|:-----------:|:-----:|
0036 //! | Active entity count boundary   |     YES     |  YES  |
0037 //! | Document root product sanity   |     YES     |  YES  |
0038 //! | Cross-reference bounds         |      -      |  YES  |
0039 //! | Reverse-index consistency      |      -      |  YES  |
0040 //! | Face-count cache consistency   |      -      |  YES  |
0041 //! | Incidence ref consistency      |      -      |  YES  |
0042 //! | Geometry representation refs   |      -      |  YES  |
0043 //! | Removed-node isolation         |     YES     |  YES  |
0044 //! | Wire edge connectivity         |      -      |  YES  |
0045 //! | Entity ID positional integrity |      -      |  YES  |
0046 //! | UID round-trip integrity       |      -      |  YES  |
0047 //! | Assembly DAG cycle detection   |      -      |  YES  |
0048 //!
0049 //! ### Mode Guidance
0050 //!
0051 //! | Mode | What it checks | Cost | Recommended use |
0052 //! |------|----------------|------|-----------------|
0053 //! | `Lightweight` | Active entity count boundary plus removed-node isolation | Low | Hot-path
0054 //! release builds when the graph structure is already trusted | | `Audit` | Full structural audit
0055 //! from cross-reference bounds through assembly DAG cycle detection | Higher | Default validation
0056 //! mode for production pipelines, test gates, and API-boundary verification |
0057 //!
0058 //! For production pipelines, prefer `Mode::Audit`; `Mode::Lightweight` is intended
0059 //! for hot-path release builds where the graph structure is already trusted.
0060 class BRepGraph_Validate
0061 {
0062 public:
0063   DEFINE_STANDARD_ALLOC
0064 
0065   //! Severity level for reported issues.
0066   enum class Severity
0067   {
0068     Warning,
0069     Error
0070   };
0071 
0072   //! Validation mode controlling check depth/performance trade-off.
0073   enum class Mode
0074   {
0075     //! Fast boundary-oriented checks for frequent validation points.
0076     Lightweight,
0077     //! Full structural audit (superset of Lightweight).
0078     Audit
0079   };
0080 
0081   //! A single structural issue found in the graph.
0082   struct Issue
0083   {
0084     Severity                Sev;
0085     BRepGraph_NodeId        NodeId;
0086     TCollection_AsciiString Description;
0087   };
0088 
0089   //! Aggregated validation result.
0090   struct Result
0091   {
0092     NCollection_LinearVector<Issue> Issues;
0093 
0094     //! True if no Error-level issues were found.
0095     [[nodiscard]] Standard_EXPORT bool IsValid() const;
0096 
0097     //! Count issues of a given severity.
0098     [[nodiscard]] Standard_EXPORT int NbIssues(const Severity theSev) const;
0099   };
0100 
0101   //! Validation options.
0102   struct Options
0103   {
0104     //! Default mode for regular validation calls.
0105     Mode ValidationMode = Mode::Lightweight;
0106 
0107     //! Build options for lightweight validation.
0108     static Options Lightweight()
0109     {
0110       Options anOptions;
0111       anOptions.ValidationMode = Mode::Lightweight;
0112       return anOptions;
0113     }
0114 
0115     //! Build options for full-audit validation.
0116     static Options Audit()
0117     {
0118       Options anOptions;
0119       anOptions.ValidationMode = Mode::Audit;
0120       return anOptions;
0121     }
0122   };
0123 
0124   //! Run default lightweight structural checks on a built graph.
0125   //! Uses Mode::Lightweight; for full structural audit use Perform(theGraph, Mode::Audit).
0126   //! @param[in] theGraph graph to validate (const, read-only)
0127   //! @return validation result with all detected issues
0128   [[nodiscard]] Standard_EXPORT static Result Perform(const BRepGraph& theGraph);
0129 
0130   //! Run structural checks on a built graph with explicit mode.
0131   //! @param[in] theGraph graph to validate (const, read-only)
0132   //! @param[in] theMode validation mode
0133   //! @return validation result with all detected issues
0134   [[nodiscard]] Standard_EXPORT static Result Perform(const BRepGraph& theGraph,
0135                                                       const Mode       theMode);
0136 
0137   //! Run structural checks on a built graph with explicit options.
0138   //! @param[in] theGraph graph to validate (const, read-only)
0139   //! @param[in] theOptions validation profile/options
0140   //! @return validation result with all detected issues
0141   [[nodiscard]] Standard_EXPORT static Result Perform(const BRepGraph& theGraph,
0142                                                       const Options&   theOptions);
0143 
0144   BRepGraph_Validate() = delete;
0145 
0146 private:
0147   static void CheckOwnedUseReferences(
0148     const BRepGraph&                                     theGraph,
0149     NCollection_LinearVector<BRepGraph_Validate::Issue>& theIssues);
0150 };
0151 
0152 #endif // _BRepGraph_Validate_HeaderFile