Back to home page

EIC code displayed by LXR

 
 

    


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