Back to home page

EIC code displayed by LXR

 
 

    


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

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_CopyRemap_HeaderFile
0015 #define _BRepGraph_CopyRemap_HeaderFile
0016 
0017 #include <BRepGraph_ItemId.hxx>
0018 #include <BRepGraph_ItemUID.hxx>
0019 #include <NCollection_FlatDataMap.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 
0022 #include <cstdint>
0023 
0024 class BRepGraph;
0025 
0026 //! Immutable context passed to layer copy callbacks.
0027 //!
0028 //! The structural copy algorithm owns remap construction. Layers receive this
0029 //! context and decide how to copy their own representation without exposing layer
0030 //! details back to BRepGraph_Copy.
0031 class BRepGraph_CopyRemap
0032 {
0033 public:
0034   DEFINE_STANDARD_ALLOC
0035 
0036   //! Distinguishes copy vs. compact migration semantics.
0037   enum class Mode : std::uint8_t
0038   {
0039     Copy    = 0, //!< Full graph copy: source and target are distinct graphs.
0040     Compact = 1  //!< In-place compaction: layers migrate into the same (rebuilt) graph.
0041   };
0042 
0043   //! Distinguishes explicit item map vs. identity mapping.
0044   enum class MappingKind : std::uint8_t
0045   {
0046     Explicit = 0, //!< Use theItemRemap for source->target resolution.
0047     Identity = 1  //!< Source and target ids are identical (full identity copy).
0048   };
0049 
0050   using ItemMap = NCollection_FlatDataMap<BRepGraph_ItemId, BRepGraph_ItemId>;
0051 
0052   BRepGraph_CopyRemap(const BRepGraph& theSourceGraph,
0053                       BRepGraph&       theTargetGraph,
0054                       const ItemMap&   theItemRemap,
0055                       const Mode       theMode) noexcept;
0056 
0057   //! Identity-mapping constructor for full identity copy into an empty target.
0058   //! Source item ids are returned directly as target item ids after validation.
0059   BRepGraph_CopyRemap(const BRepGraph& theSourceGraph,
0060                       BRepGraph&       theTargetGraph,
0061                       MappingKind      theMappingKind,
0062                       Mode             theMode) noexcept;
0063 
0064   //! Migration mode of this context.
0065   [[nodiscard]] Mode CopyMode() const noexcept { return myMode; }
0066 
0067   //! True if this is a compaction migration (not a full copy).
0068   [[nodiscard]] bool IsCompact() const noexcept { return myMode == Mode::Compact; }
0069 
0070   //! Source graph the copied layer is attached to.
0071   [[nodiscard]] const BRepGraph& SourceGraph() const noexcept { return *mySourceGraph; }
0072 
0073   //! Target graph whose structural contents have already been copied.
0074   [[nodiscard]] BRepGraph& TargetGraph() const noexcept { return *myTargetGraph; }
0075 
0076   //! Target graph as const.
0077   [[nodiscard]] const BRepGraph& TargetGraphConst() const noexcept { return *myTargetGraph; }
0078 
0079   //! Source item id -> target item id map for copied definitions, refs, and reps.
0080   [[nodiscard]] const ItemMap& Items() const noexcept { return *myItemRemap; }
0081 
0082   //! Return the target item for a source item, or an invalid item if not copied.
0083   [[nodiscard]] Standard_EXPORT BRepGraph_ItemId
0084     TargetItem(const BRepGraph_ItemId theSourceItem) const;
0085 
0086   //! Return the target item for a source item, or an invalid item id.
0087   [[nodiscard]] Standard_EXPORT BRepGraph_ItemId
0088     TargetItemOrInvalid(const BRepGraph_ItemId theSourceItem) const;
0089 
0090   //! Return true if the source item has a valid copied target item.
0091   [[nodiscard]] Standard_EXPORT bool HasTargetItem(const BRepGraph_ItemId theSourceItem) const;
0092 
0093   //! Return source UID for a source item.
0094   [[nodiscard]] Standard_EXPORT BRepGraph_ItemUID
0095     SourceUID(const BRepGraph_ItemId theSourceItem) const;
0096 
0097   //! Return target UID for a target item.
0098   [[nodiscard]] Standard_EXPORT BRepGraph_ItemUID
0099     TargetUID(const BRepGraph_ItemId theTargetItem) const;
0100 
0101   //! Return target UID for a source item by source->target remap.
0102   [[nodiscard]] Standard_EXPORT BRepGraph_ItemUID
0103     TargetUIDFromSource(const BRepGraph_ItemId theSourceItem) const;
0104 
0105 private:
0106   const BRepGraph* mySourceGraph = nullptr;
0107   BRepGraph*       myTargetGraph = nullptr;
0108   const ItemMap*   myItemRemap   = nullptr;
0109   Mode             myMode        = Mode::Copy;
0110   MappingKind      myMappingKind = MappingKind::Explicit;
0111 };
0112 
0113 #endif // _BRepGraph_CopyRemap_HeaderFile