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 _BRepGraphInc_Instance_HeaderFile
0015 #define _BRepGraphInc_Instance_HeaderFile
0016 
0017 #include <BRepGraph_NodeId.hxx>
0018 #include <Standard_HashUtils.hxx>
0019 #include <TopAbs_Orientation.hxx>
0020 #include <TopLoc_Location.hxx>
0021 
0022 #include <functional>
0023 
0024 //! @file BRepGraphInc_Instance.hxx
0025 //! @brief Unified lightweight container binding a node identity with placement.
0026 //!
0027 //! Instance<T> is the BRepGraph analogue of TopoDS_Shape: a lightweight value type
0028 //! that bundles a definition id with its location and orientation in context.
0029 //!
0030 //! Supports C++17 structured bindings (aggregate type):
0031 //! @code
0032 //!   for (auto [aDefId, aLoc, anOri] : BRepGraph_ChildExplorer(aGraph, aRoot, Kind::Face))
0033 //!   {
0034 //!     // ...
0035 //!   }
0036 //! @endcode
0037 namespace BRepGraphInc
0038 {
0039 
0040 //! @brief Unified instance container template.
0041 //!
0042 //! Bundles a typed definition id with location and orientation.
0043 //!
0044 //! @tparam TypedIdT typed definition id (e.g. BRepGraph_FaceId, BRepGraph_NodeId).
0045 template <typename TypedIdT>
0046 struct Instance
0047 {
0048   TypedIdT           DefId;
0049   TopLoc_Location    Location;
0050   TopAbs_Orientation Orientation = TopAbs_FORWARD;
0051 
0052   //! Returns true if the instance references an existing definition id.
0053   [[nodiscard]] bool IsValid() const { return DefId.IsValid(); }
0054 };
0055 
0056 using VertexInstance     = Instance<BRepGraph_VertexId>;
0057 using CoEdgeInstance     = Instance<BRepGraph_CoEdgeId>;
0058 using WireInstance       = Instance<BRepGraph_WireId>;
0059 using FaceInstance       = Instance<BRepGraph_FaceId>;
0060 using ShellInstance      = Instance<BRepGraph_ShellId>;
0061 using SolidInstance      = Instance<BRepGraph_SolidId>;
0062 using OccurrenceInstance = Instance<BRepGraph_OccurrenceId>;
0063 using CompoundInstance   = Instance<BRepGraph_CompoundId>;
0064 using CompSolidInstance  = Instance<BRepGraph_CompSolidId>;
0065 using ProductInstance    = Instance<BRepGraph_ProductId>;
0066 
0067 //! NodeInstance is Instance<BRepGraph_NodeId>.
0068 //! Returned by BRepGraph_ChildExplorer and BRepGraph_ParentExplorer
0069 //! with accumulated transforms from traversal root to the current node.
0070 //! Implicitly convertible from any typed Instance via BRepGraph_NodeId::Typed
0071 //! implicit conversion to BRepGraph_NodeId.
0072 using NodeInstance = Instance<BRepGraph_NodeId>;
0073 
0074 } // namespace BRepGraphInc
0075 
0076 //! std::hash specialization for BRepGraphInc::Instance<T>.
0077 template <typename TypedIdT>
0078 struct std::hash<BRepGraphInc::Instance<TypedIdT>>
0079 {
0080   size_t operator()(const BRepGraphInc::Instance<TypedIdT>& theInstance) const noexcept
0081   {
0082     size_t aCombination[3];
0083     aCombination[0] = std::hash<TypedIdT>{}(theInstance.DefId);
0084     aCombination[1] = theInstance.Location.HashCode();
0085     aCombination[2] = opencascade::hash(static_cast<int>(theInstance.Orientation));
0086     return opencascade::hashBytes(aCombination, sizeof(aCombination));
0087   }
0088 };
0089 
0090 #endif // _BRepGraphInc_Instance_HeaderFile