|
|
|||
File indexing completed on 2026-09-17 09:22:36
0001 // Created on: 2022-05-11 0002 // Copyright (c) 2022 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _XCAFDoc_AssemblyGraph_HeaderFile 0016 #define _XCAFDoc_AssemblyGraph_HeaderFile 0017 0018 #include <NCollection_DataMap.hxx> 0019 #include <NCollection_IndexedMap.hxx> 0020 #include <Standard.hxx> 0021 #include <Standard_Type.hxx> 0022 #include <TCollection_AsciiString.hxx> 0023 #include <TColStd_PackedMapOfInteger.hxx> 0024 0025 class TDF_Label; 0026 class TDocStd_Document; 0027 class XCAFDoc_ShapeTool; 0028 0029 // Assembly graph. 0030 class XCAFDoc_AssemblyGraph : public Standard_Transient 0031 { 0032 public: 0033 //! \brief Type of the graph node. 0034 enum NodeType 0035 { 0036 NodeType_UNDEFINED = 0, //!< Undefined node type. 0037 NodeType_AssemblyRoot, //!< Root node. 0038 NodeType_Subassembly, //!< Intermediate node. 0039 NodeType_Occurrence, //!< Assembly/part occurrence node. 0040 NodeType_Part, //!< Leaf node to represent parts. 0041 NodeType_Subshape //!< Subshape node. 0042 }; 0043 0044 //! \brief Type definition for graph adjacency matrix. 0045 //! This is how parent-component links are realized in the assembly graph. 0046 typedef NCollection_DataMap<int, TColStd_PackedMapOfInteger> AdjacencyMap; 0047 0048 public: 0049 //! \brief Graph iterator. 0050 class Iterator 0051 { 0052 public: 0053 //! \brief Accepting the assembly graph and starting node to iterate. 0054 //! Iteration starts from the specified node. 0055 //! \param[in] theGraph - assembly graph to iterate. 0056 //! \param[in] theNode - graph node ID. 0057 Standard_EXPORT Iterator(const occ::handle<XCAFDoc_AssemblyGraph>& theGraph, 0058 const int theNode = 1); 0059 0060 //! Checks if there are more graph nodes to iterate. 0061 //! \return true/false. 0062 bool More() const { return myCurrentIndex <= myGraph->NbNodes(); } 0063 0064 //! \return 1-based ID of the current node. 0065 int Current() const { return myCurrentIndex; } 0066 0067 //! Moves iterator to the next position. 0068 void Next() { ++myCurrentIndex; } 0069 0070 private: 0071 occ::handle<XCAFDoc_AssemblyGraph> myGraph; //!< Assembly graph to iterate. 0072 int myCurrentIndex; //!< Current 1-based node ID. 0073 }; 0074 0075 public: 0076 //! \brief Constructs graph from XCAF document. 0077 //! Construction of a formal graph will be done immediately. 0078 //! \param[in] theDoc - document to iterate. 0079 Standard_EXPORT XCAFDoc_AssemblyGraph(const occ::handle<TDocStd_Document>& theDoc); 0080 0081 //! \brief Constructs graph from XCAF label. 0082 //! Construction of a formal graph will be done immediately. The specified 0083 //! label is used as a starting position. 0084 //! \param[in] theDoc - document to iterate. 0085 //! \param[in] theLabel - starting position. 0086 Standard_EXPORT XCAFDoc_AssemblyGraph(const TDF_Label& theLabel); 0087 0088 //! \return Document shape tool. 0089 const occ::handle<XCAFDoc_ShapeTool>& GetShapeTool() const { return myShapeTool; } 0090 0091 //! \brief Returns IDs of the root nodes. 0092 //! \return IDs of the root nodes. 0093 const TColStd_PackedMapOfInteger& GetRoots() const { return myRoots; } 0094 0095 //! \brief Checks whether the assembly graph contains (n1, n2) directed link. 0096 //! \param[in] theNode1 - one-based ID of the first node. 0097 //! \param[in] theNode2 - one-based ID of the second node. 0098 //! \return true/false. 0099 Standard_EXPORT bool IsDirectLink(const int theNode1, const int theNode2) const; 0100 0101 //! \brief Checks whether direct children exist for the given node. 0102 //! \param[in] theNode - one-based node ID. 0103 //! \return true/false. 0104 bool HasChildren(const int theNode) const { return myAdjacencyMap.IsBound(theNode); } 0105 0106 //! \brief Returns IDs of child nodes for the given node. 0107 //! \param[in] theNode - one-based node ID. 0108 //! \return set of child IDs. 0109 const TColStd_PackedMapOfInteger& GetChildren(const int theNode) const 0110 { 0111 return myAdjacencyMap(theNode); 0112 } 0113 0114 //! \brief Returns the node type from \ref NodeType enum. 0115 //! \param[in] theNode - one-based node ID. 0116 //! \return node type. 0117 //! \sa NodeType 0118 Standard_EXPORT NodeType GetNodeType(const int theNode) const; 0119 0120 //! \brief returns object ID by node ID. 0121 //! \param[in] theNode - one-based node ID. 0122 //! \return persistent ID. 0123 const TDF_Label& GetNode(const int theNode) const { return myNodes(theNode); } 0124 0125 //! \brief Returns the unordered set of graph nodes. 0126 //! \return graph nodes. 0127 const NCollection_IndexedMap<TDF_Label>& GetNodes() const { return myNodes; } 0128 0129 //! \brief Returns the number of graph nodes. 0130 //! \return number of graph nodes. 0131 int NbNodes() const { return myNodes.Extent(); } 0132 0133 //! \brief Returns the collection of graph links in the form of adjacency matrix. 0134 //! \return graph links. 0135 const AdjacencyMap& GetLinks() const { return myAdjacencyMap; } 0136 0137 //! \brief Returns the number of graph links. 0138 //! \return number of graph links. 0139 Standard_EXPORT int NbLinks() const; 0140 0141 //! Returns quantity of part usage occurrences. 0142 //! \param[in] theNode - one-based part ID. 0143 //! \return usage occurrence quantity. 0144 Standard_EXPORT int NbOccurrences(const int theNode) const; 0145 0146 private: 0147 //! Builds graph out of OCAF XDE structure. 0148 //! \param[in] theLabel - optional starting position. 0149 Standard_EXPORT void buildGraph(const TDF_Label& theLabel); 0150 0151 //! Adds components for the given parent to the graph structure. 0152 //! \param[in] theParent - OCAF label of the parent object. 0153 //! \param[in] theParentId - ID of the already registered node representing 0154 //! the parent object in the assembly graph 0155 //! being populated. 0156 Standard_EXPORT void addComponents(const TDF_Label& theParent, const int theParentId); 0157 0158 //! Adds node into the graph. 0159 //! \param[in] theLabel - label at insertion level. 0160 //! \param[in] theParentId - parent one-based node IDS. 0161 //! \return one-based internal ID of the node. 0162 Standard_EXPORT int addNode(const TDF_Label& theLabel, const int theParentId); 0163 0164 private: 0165 occ::handle<XCAFDoc_ShapeTool> myShapeTool; //!< Document shape tool. 0166 TColStd_PackedMapOfInteger myRoots; //!< IDs of the root nodes. 0167 // clang-format off 0168 NCollection_IndexedMap<TDF_Label> myNodes; //!< Maps assembly/part entries to graph node IDs. 0169 // clang-format on 0170 AdjacencyMap myAdjacencyMap; //!< "Part-of" relations. 0171 NCollection_DataMap<int, NodeType> myNodeTypes; //!< Node types. 0172 NCollection_DataMap<int, 0173 int> myUsages; //!< Occurrences usage. 0174 }; 0175 0176 #endif // _XCAFDoc_AssemblyGraph_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|