Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-24 09:17:47

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_AssemblyTool_HeaderFile
0016 #define _XCAFDoc_AssemblyTool_HeaderFile
0017 
0018 #include <Standard.hxx>
0019 #include <Standard_NullObject.hxx>
0020 #include <Standard_Type.hxx>
0021 #include <XCAFDoc_AssemblyIterator.hxx>
0022 #include <XCAFDoc_AssemblyGraph.hxx>
0023 
0024 class TDocStd_Document;
0025 class XCAFDoc_ShapeTool;
0026 
0027 //! Provides generic methods for traversing assembly tree and graph
0028 class XCAFDoc_AssemblyTool
0029 {
0030 public:
0031   //! \brief Generic method for traversing assembly tree.
0032   //! Performs in-depth traversing of the assembly tree and calls
0033   //! user defined function for each assembly tree node.
0034   //! User function takes single argument of XCAFDoc_AssemblyItemId type
0035   //! and returns true/false to continue/break.
0036   //! ~~~~~{.cpp}
0037   //! bool Print(const XCAFDoc_AssemblyItemId& theItem)
0038   //! {
0039   //!   std::cout << theItem.ToString() << std::endl;
0040   //!   return true;
0041   //! }
0042   //! ~~~~~
0043   //! \param[in]  theIterator - starting position in the assembly tree.
0044   //! \param[in]  theFunc     - user function called for each assembly tree node.
0045   template <typename Func>
0046   static void Traverse(XCAFDoc_AssemblyIterator theIterator, Func theFunc)
0047   {
0048     for (; theIterator.More(); theIterator.Next())
0049     {
0050       if (!theFunc(theIterator.Current()))
0051         break;
0052     }
0053   }
0054 
0055   //! \brief Generic method for traversing assembly graph.
0056   //! Performs in-depth traversing of the assembly graph beginning from root nodes
0057   //! and calls user defined function for each assembly graph node accepted
0058   //! by the user defined filtering function. Filtering function takes
0059   //! the assembly graph passed for traversing, current graph node ID
0060   //! and returns true/false to accept/reject node.
0061   //! ~~~~~{.cpp}
0062   //! bool AcceptPartOnly(const occ::handle<XCAFDoc_AssemblyGraph>& theGraph,
0063   //!                                 const int               theNode)
0064   //! {
0065   //!   return (theGraph->GetNodeType(theNode) == XCAFDoc_AssemblyGraph::NodeType_Part);
0066   //! }
0067   //! ~~~~~
0068   //! User function theFunc takes the assembly graph passed for traversing, current
0069   //! graph node ID and returns true/false to continue/break.
0070   //! \param[in]  theGraph  - assembly graph.
0071   //! \param[in]  theFilter - user filtering function called for each assembly graph node.
0072   //! \param[in]  theFunc   - user function called for accepted assembly graph node.
0073   //! \param[in]  theNode   - starting positive one-based graph node ID.
0074   template <typename Func, typename Filter>
0075   static void Traverse(const occ::handle<XCAFDoc_AssemblyGraph>& theGraph,
0076                        Filter                                    theFilter,
0077                        Func                                      theFunc,
0078                        const int                                 theNode = 1)
0079   {
0080     Standard_NullObject_Raise_if(theGraph.IsNull(), "Null assembly graph!");
0081 
0082     for (XCAFDoc_AssemblyGraph::Iterator anIt(theGraph, theNode); anIt.More(); anIt.Next())
0083     {
0084       const int aN = anIt.Current();
0085       if (theFilter(theGraph, aN))
0086       {
0087         if (!theFunc(theGraph, aN))
0088           break;
0089       }
0090     }
0091   }
0092 };
0093 
0094 #endif // _XCAFDoc_AssemblyTool_HeaderFile