Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-08 08:36:10

0001 // Author: Kirill Gavrilov
0002 // Copyright (c) 2017-2019 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 _XCAFPrs_DocumentExplorer_HeaderFile
0016 #define _XCAFPrs_DocumentExplorer_HeaderFile
0017 
0018 #include <NCollection_Vector.hxx>
0019 #include <XCAFPrs_DocumentNode.hxx>
0020 #include <TDF_LabelSequence.hxx>
0021 #include <TopoDS_Shape.hxx>
0022 
0023 class TDocStd_Document;
0024 class XCAFDoc_ColorTool;
0025 class XCAFDoc_VisMaterialTool;
0026 
0027 typedef Standard_Integer XCAFPrs_DocumentExplorerFlags;
0028 
0029 //! Document explorer flags.
0030 enum
0031 {
0032   XCAFPrs_DocumentExplorerFlags_None = 0x00, //!< no flags
0033   XCAFPrs_DocumentExplorerFlags_OnlyLeafNodes =
0034     0x01,                                       //!< explore only leaf nodes (skip assembly nodes)
0035   XCAFPrs_DocumentExplorerFlags_NoStyle = 0x02, //!< do not fetch styles
0036 };
0037 
0038 //! Document iterator through shape nodes.
0039 class XCAFPrs_DocumentExplorer
0040 {
0041 public: //! @name string identification tools
0042   //! Construct a unique string identifier for the given label.
0043   //! The identifier is a concatenation of label entries (TDF_Tool::Entry() with tailing '.') of
0044   //! hierarchy from parent to child joined via '/' and looking like this:
0045   //! @code
0046   //!   0:1:1:1./0:1:1:1:9./0:1:1:5:7.
0047   //! @endcode
0048   //! This generation scheme also allows finding originating labels using TDF_Tool::Label().
0049   //! The tailing dot simplifies parent equality check.
0050   //! @param theLabel child label to define id
0051   //! @param theParentId parent string identifier defined by this method
0052   Standard_EXPORT static TCollection_AsciiString DefineChildId(
0053     const TDF_Label&               theLabel,
0054     const TCollection_AsciiString& theParentId);
0055 
0056   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full
0057   //! path.
0058   //! @sa DefineChildId()
0059   Standard_EXPORT static TDF_Label FindLabelFromPathId(const Handle(TDocStd_Document)& theDocument,
0060                                                        const TCollection_AsciiString&  theId,
0061                                                        TopLoc_Location& theParentLocation,
0062                                                        TopLoc_Location& theLocation);
0063 
0064   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full
0065   //! path.
0066   //! @sa DefineChildId()
0067   static TDF_Label FindLabelFromPathId(const Handle(TDocStd_Document)& theDocument,
0068                                        const TCollection_AsciiString&  theId,
0069                                        TopLoc_Location&                theLocation)
0070   {
0071     TopLoc_Location aDummy;
0072     return FindLabelFromPathId(theDocument, theId, aDummy, theLocation);
0073   }
0074 
0075   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full
0076   //! path.
0077   //! @sa DefineChildId()
0078   Standard_EXPORT static TopoDS_Shape FindShapeFromPathId(
0079     const Handle(TDocStd_Document)& theDocument,
0080     const TCollection_AsciiString&  theId);
0081 
0082 public:
0083   //! Empty constructor.
0084   Standard_EXPORT XCAFPrs_DocumentExplorer();
0085 
0086   //! Constructor for exploring the whole document.
0087   //! @param theDocument document to explore
0088   //! @param theFlags    iteration flags
0089   //! @param theDefStyle default style for nodes with undefined style
0090   Standard_EXPORT XCAFPrs_DocumentExplorer(const Handle(TDocStd_Document)&     theDocument,
0091                                            const XCAFPrs_DocumentExplorerFlags theFlags,
0092                                            const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0093 
0094   //! Constructor for exploring specified list of root shapes in the document.
0095   //! @param theDocument  document to explore
0096   //! @param theRoots     root labels to explore within specified document
0097   //! @param theFlags     iteration flags
0098   //! @param theDefStyle  default style for nodes with undefined style
0099   Standard_EXPORT XCAFPrs_DocumentExplorer(const Handle(TDocStd_Document)&     theDocument,
0100                                            const TDF_LabelSequence&            theRoots,
0101                                            const XCAFPrs_DocumentExplorerFlags theFlags,
0102                                            const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0103 
0104   //! Initialize the iterator from a single root shape in the document.
0105   //! @param theDocument  document to explore
0106   //! @param theRoot      single root label to explore within specified document
0107   //! @param theFlags     iteration flags
0108   //! @param theDefStyle  default style for nodes with undefined style
0109   Standard_EXPORT void Init(const Handle(TDocStd_Document)&     theDocument,
0110                             const TDF_Label&                    theRoot,
0111                             const XCAFPrs_DocumentExplorerFlags theFlags,
0112                             const XCAFPrs_Style&                theDefStyle = XCAFPrs_Style());
0113 
0114   //! Initialize the iterator from the list of root shapes in the document.
0115   //! @param theDocument  document to explore
0116   //! @param theRoots     root labels to explore within specified document
0117   //! @param theFlags     iteration flags
0118   //! @param theDefStyle  default style for nodes with undefined style
0119   Standard_EXPORT void Init(const Handle(TDocStd_Document)&     theDocument,
0120                             const TDF_LabelSequence&            theRoots,
0121                             const XCAFPrs_DocumentExplorerFlags theFlags,
0122                             const XCAFPrs_Style&                theDefStyle = XCAFPrs_Style());
0123 
0124   //! Return TRUE if iterator points to the valid node.
0125   Standard_Boolean More() const { return myHasMore; }
0126 
0127   //! Return current position.
0128   const XCAFPrs_DocumentNode& Current() const { return myCurrent; }
0129 
0130   //! Return current position.
0131   XCAFPrs_DocumentNode& ChangeCurrent() { return myCurrent; }
0132 
0133   //! Return current position within specified assembly depth.
0134   const XCAFPrs_DocumentNode& Current(Standard_Integer theDepth) const
0135   {
0136     const Standard_Integer aCurrDepth = CurrentDepth();
0137     if (theDepth == aCurrDepth)
0138     {
0139       return myCurrent;
0140     }
0141 
0142     Standard_OutOfRange_Raise_if(theDepth < 0 || theDepth > myTop,
0143                                  "XCAFPrs_DocumentExplorer::Current() out of range");
0144     return myNodeStack.Value(theDepth);
0145   }
0146 
0147   //! Return depth of the current node in hierarchy, starting from 0.
0148   //! Zero means Root label.
0149   Standard_Integer CurrentDepth() const { return myCurrent.IsAssembly ? myTop : myTop + 1; }
0150 
0151   //! Go to the next node.
0152   Standard_EXPORT void Next();
0153 
0154   //! Return color tool.
0155   const Handle(XCAFDoc_ColorTool)& ColorTool() const { return myColorTool; }
0156 
0157   //! Return material tool.
0158   const Handle(XCAFDoc_VisMaterialTool)& VisMaterialTool() const { return myVisMatTool; }
0159 
0160 protected:
0161   //! Initialize root label.
0162   Standard_EXPORT void initRoot();
0163 
0164   //! Initialize properties for a current label.
0165   Standard_EXPORT void initCurrent(Standard_Boolean theIsAssembly);
0166 
0167 protected:
0168   Handle(XCAFDoc_ColorTool)                myColorTool;  //!< color tool
0169   Handle(XCAFDoc_VisMaterialTool)          myVisMatTool; //!< visual material tool
0170   TDF_LabelSequence                        myRoots;      //!< sequence of root labels
0171   TDF_LabelSequence::Iterator              myRootIter;   //!< current root label
0172   NCollection_Vector<XCAFPrs_DocumentNode> myNodeStack;  //!< node stack
0173   Standard_Integer                         myTop;        //!< top position in the node stack
0174                                                          // clang-format off
0175   Standard_Boolean                myHasMore;    //!< global flag indicating that iterator points to the label
0176                                                          // clang-format on
0177   XCAFPrs_Style                 myDefStyle;              //!< default style
0178   XCAFPrs_DocumentNode          myCurrent;               //!< current label info
0179   XCAFPrs_DocumentExplorerFlags myFlags;                 //!< iteration flags
0180 };
0181 
0182 #endif // _XCAFPrs_DocumentExplorer_HeaderFile