|
||||
File indexing completed on 2025-01-18 10:05:33
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 #include <TDF_LabelIndexedMap.hxx> 0025 0026 class TDF_Label; 0027 class TDocStd_Document; 0028 class XCAFDoc_ShapeTool; 0029 0030 class XCAFDoc_AssemblyGraph; 0031 DEFINE_STANDARD_HANDLE(XCAFDoc_AssemblyGraph, Standard_Transient) 0032 0033 // Assembly graph. 0034 class XCAFDoc_AssemblyGraph : public Standard_Transient 0035 { 0036 public: 0037 0038 //! \brief Type of the graph node. 0039 enum NodeType 0040 { 0041 NodeType_UNDEFINED = 0, //!< Undefined node type. 0042 NodeType_AssemblyRoot, //!< Root node. 0043 NodeType_Subassembly, //!< Intermediate node. 0044 NodeType_Occurrence, //!< Assembly/part occurrence node. 0045 NodeType_Part, //!< Leaf node to represent parts. 0046 NodeType_Subshape //!< Subshape node. 0047 }; 0048 0049 //! \brief Type definition for graph adjacency matrix. 0050 //! This is how parent-component links are realized in the assembly graph. 0051 typedef NCollection_DataMap<Standard_Integer, TColStd_PackedMapOfInteger> AdjacencyMap; 0052 0053 public: 0054 0055 //! \brief Graph iterator. 0056 class Iterator 0057 { 0058 public: 0059 0060 //! \brief Accepting the assembly graph and starting node to iterate. 0061 //! Iteration starts from the specified node. 0062 //! \param [in] theGraph - assembly graph to iterate. 0063 //! \param [in] theNode - graph node ID. 0064 Standard_EXPORT Iterator(const Handle(XCAFDoc_AssemblyGraph)& theGraph, 0065 const Standard_Integer theNode = 1); 0066 0067 //! Checks if there are more graph nodes to iterate. 0068 //! \return true/false. 0069 Standard_Boolean More() const 0070 { 0071 return myCurrentIndex <= myGraph->NbNodes(); 0072 } 0073 0074 //! \return 1-based ID of the current node. 0075 Standard_Integer Current() const 0076 { 0077 return myCurrentIndex; 0078 } 0079 0080 //! Moves iterator to the next position. 0081 void Next() 0082 { 0083 ++myCurrentIndex; 0084 } 0085 0086 private: 0087 0088 Handle(XCAFDoc_AssemblyGraph) myGraph; //!< Assembly graph to iterate. 0089 Standard_Integer myCurrentIndex; //!< Current 1-based node ID. 0090 0091 }; 0092 0093 public: 0094 0095 //! \brief Constructs graph from XCAF document. 0096 //! Construction of a formal graph will be done immediately. 0097 //! \param [in] theDoc - document to iterate. 0098 Standard_EXPORT XCAFDoc_AssemblyGraph(const Handle(TDocStd_Document)& theDoc); 0099 0100 //! \brief Constructs graph from XCAF label. 0101 //! Construction of a formal graph will be done immediately. The specified 0102 //! label is used as a starting position. 0103 //! \param [in] theDoc - document to iterate. 0104 //! \param [in] theLabel - starting position. 0105 Standard_EXPORT XCAFDoc_AssemblyGraph(const TDF_Label& theLabel); 0106 0107 //! \return Document shape tool. 0108 const Handle(XCAFDoc_ShapeTool)& GetShapeTool() const 0109 { 0110 return myShapeTool; 0111 } 0112 0113 //! \brief Returns IDs of the root nodes. 0114 //! \return IDs of the root nodes. 0115 const TColStd_PackedMapOfInteger& GetRoots() const 0116 { 0117 return myRoots; 0118 } 0119 0120 //! \brief Checks whether the assembly graph contains (n1, n2) directed link. 0121 //! \param [in] theNode1 - one-based ID of the first node. 0122 //! \param [in] theNode2 - one-based ID of the second node. 0123 //! \return true/false. 0124 Standard_EXPORT Standard_Boolean IsDirectLink(const Standard_Integer theNode1, 0125 const Standard_Integer theNode2) const; 0126 0127 //! \brief Checks whether direct children exist for the given node. 0128 //! \param [in] theNode - one-based node ID. 0129 //! \return true/false. 0130 Standard_Boolean HasChildren(const Standard_Integer theNode) const 0131 { 0132 return myAdjacencyMap.IsBound(theNode); 0133 } 0134 0135 //! \brief Returns IDs of child nodes for the given node. 0136 //! \param [in] theNode - one-based node ID. 0137 //! \return set of child IDs. 0138 const TColStd_PackedMapOfInteger& GetChildren(const Standard_Integer theNode) const 0139 { 0140 return myAdjacencyMap(theNode); 0141 } 0142 0143 //! \brief Returns the node type from \ref NodeType enum. 0144 //! \param [in] theNode - one-based node ID. 0145 //! \return node type. 0146 //! \sa NodeType 0147 Standard_EXPORT NodeType GetNodeType(const Standard_Integer theNode) const; 0148 0149 //! \brief returns object ID by node ID. 0150 //! \param [in] theNode - one-based node ID. 0151 //! \return persistent ID. 0152 const TDF_Label& GetNode(const Standard_Integer theNode) const 0153 { 0154 return myNodes(theNode); 0155 } 0156 0157 //! \brief Returns the unordered set of graph nodes. 0158 //! \return graph nodes. 0159 const TDF_LabelIndexedMap& GetNodes() const 0160 { 0161 return myNodes; 0162 } 0163 0164 //! \brief Returns the number of graph nodes. 0165 //! \return number of graph nodes. 0166 Standard_Integer NbNodes() const 0167 { 0168 return myNodes.Extent(); 0169 } 0170 0171 //! \brief Returns the collection of graph links in the form of adjacency matrix. 0172 //! \return graph links. 0173 const AdjacencyMap& GetLinks() const 0174 { 0175 return myAdjacencyMap; 0176 } 0177 0178 //! \brief Returns the number of graph links. 0179 //! \return number of graph links. 0180 Standard_EXPORT Standard_Integer NbLinks() const; 0181 0182 //! Returns quantity of part usage occurrences. 0183 //! \param [in] theNode - one-based part ID. 0184 //! \return usage occurrence quantity. 0185 Standard_EXPORT Standard_Integer NbOccurrences(const Standard_Integer theNode) const; 0186 0187 private: 0188 0189 //! Builds graph out of OCAF XDE structure. 0190 //! \param [in] theLabel - optional starting position. 0191 Standard_EXPORT void buildGraph(const TDF_Label& theLabel); 0192 0193 //! Adds components for the given parent to the graph structure. 0194 //! \param [in] theParent - OCAF label of the parent object. 0195 //! \param [in] theParentId - ID of the already registered node representing 0196 //! the parent object in the assembly graph 0197 //! being populated. 0198 Standard_EXPORT void addComponents(const TDF_Label& theParent, 0199 const Standard_Integer theParentId); 0200 0201 //! Adds node into the graph. 0202 //! \param [in] theLabel - label at insertion level. 0203 //! \param [in] theParentId - parent one-based node IDS. 0204 //! \return one-based internal ID of the node. 0205 Standard_EXPORT Standard_Integer addNode(const TDF_Label& theLabel, 0206 const Standard_Integer theParentId); 0207 0208 private: 0209 0210 Handle(XCAFDoc_ShapeTool) myShapeTool; //!< Document shape tool. 0211 TColStd_PackedMapOfInteger myRoots; //!< IDs of the root nodes. 0212 TDF_LabelIndexedMap myNodes; //!< Maps assembly/part entries to graph node IDs. 0213 AdjacencyMap myAdjacencyMap; //!< "Part-of" relations. 0214 NCollection_DataMap<Standard_Integer, NodeType> myNodeTypes; //!< Node types. 0215 NCollection_DataMap<Standard_Integer, 0216 Standard_Integer> myUsages; //!< Occurrences usage. 0217 0218 }; 0219 0220 #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 |