Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:34

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 = 0x01, //!< explore only leaf nodes (skip assembly nodes)
0034   XCAFPrs_DocumentExplorerFlags_NoStyle       = 0x02, //!< do not fetch styles
0035 };
0036 
0037 //! Document iterator through shape nodes.
0038 class XCAFPrs_DocumentExplorer
0039 {
0040 public: //! @name string identification tools
0041 
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 hierarchy from parent to child
0044   //! 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 (const TDF_Label& theLabel,
0053                                                                 const TCollection_AsciiString& theParentId);
0054 
0055   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
0056   //! @sa DefineChildId()
0057   Standard_EXPORT static TDF_Label FindLabelFromPathId (const Handle(TDocStd_Document)& theDocument,
0058                                                         const TCollection_AsciiString& theId,
0059                                                         TopLoc_Location& theParentLocation,
0060                                                         TopLoc_Location& theLocation);
0061 
0062   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
0063   //! @sa DefineChildId()
0064   static TDF_Label FindLabelFromPathId (const Handle(TDocStd_Document)& theDocument,
0065                                         const TCollection_AsciiString& theId,
0066                                         TopLoc_Location& theLocation)
0067   {
0068     TopLoc_Location aDummy;
0069     return FindLabelFromPathId (theDocument, theId, aDummy, theLocation);
0070   }
0071 
0072   //! Find a shape entity based on a text identifier constructed from OCAF labels defining full path.
0073   //! @sa DefineChildId()
0074   Standard_EXPORT static TopoDS_Shape FindShapeFromPathId (const Handle(TDocStd_Document)& theDocument,
0075                                                            const TCollection_AsciiString& theId);
0076 
0077 public:
0078 
0079   //! Empty constructor.
0080   Standard_EXPORT XCAFPrs_DocumentExplorer();
0081 
0082   //! Constructor for exploring the whole document.
0083   //! @param theDocument document to explore
0084   //! @param theFlags    iteration flags
0085   //! @param theDefStyle default style for nodes with undefined style
0086   Standard_EXPORT XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
0087                                             const XCAFPrs_DocumentExplorerFlags theFlags,
0088                                             const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0089 
0090   //! Constructor for exploring specified list of root shapes in the document.
0091   //! @param theDocument  document to explore
0092   //! @param theRoots     root labels to explore within specified document
0093   //! @param theFlags     iteration flags
0094   //! @param theDefStyle  default style for nodes with undefined style
0095   Standard_EXPORT XCAFPrs_DocumentExplorer (const Handle(TDocStd_Document)& theDocument,
0096                                             const TDF_LabelSequence& theRoots,
0097                                             const XCAFPrs_DocumentExplorerFlags theFlags,
0098                                             const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0099 
0100   //! Initialize the iterator from a single root shape in the document.
0101   //! @param theDocument  document to explore
0102   //! @param theRoot      single root label to explore within specified document
0103   //! @param theFlags     iteration flags
0104   //! @param theDefStyle  default style for nodes with undefined style
0105   Standard_EXPORT void Init (const Handle(TDocStd_Document)& theDocument,
0106                              const TDF_Label& theRoot,
0107                              const XCAFPrs_DocumentExplorerFlags theFlags,
0108                              const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0109 
0110   //! Initialize the iterator from the list of root shapes in the document.
0111   //! @param theDocument  document to explore
0112   //! @param theRoots     root labels to explore within specified document
0113   //! @param theFlags     iteration flags
0114   //! @param theDefStyle  default style for nodes with undefined style
0115   Standard_EXPORT void Init (const Handle(TDocStd_Document)& theDocument,
0116                              const TDF_LabelSequence& theRoots,
0117                              const XCAFPrs_DocumentExplorerFlags theFlags,
0118                              const XCAFPrs_Style& theDefStyle = XCAFPrs_Style());
0119 
0120   //! Return TRUE if iterator points to the valid node.
0121   Standard_Boolean More() const { return myHasMore; }
0122 
0123   //! Return current position.
0124   const XCAFPrs_DocumentNode& Current() const { return myCurrent; }
0125 
0126   //! Return current position.
0127   XCAFPrs_DocumentNode& ChangeCurrent() { return myCurrent; }
0128 
0129   //! Return current position within specified assembly depth.
0130   const XCAFPrs_DocumentNode& Current (Standard_Integer theDepth) const
0131   {
0132     const Standard_Integer aCurrDepth = CurrentDepth();
0133     if (theDepth == aCurrDepth)
0134     {
0135       return myCurrent;
0136     }
0137 
0138     Standard_OutOfRange_Raise_if (theDepth < 0 || theDepth > myTop,
0139                                   "XCAFPrs_DocumentExplorer::Current() out of range");
0140     return myNodeStack.Value (theDepth);
0141   }
0142 
0143   //! Return depth of the current node in hierarchy, starting from 0.
0144   //! Zero means Root label.
0145   Standard_Integer CurrentDepth() const { return myCurrent.IsAssembly ? myTop : myTop + 1; }
0146 
0147   //! Go to the next node.
0148   Standard_EXPORT void Next();
0149 
0150   //! Return color tool.
0151   const Handle(XCAFDoc_ColorTool)& ColorTool() const { return myColorTool; }
0152 
0153   //! Return material tool.
0154   const Handle(XCAFDoc_VisMaterialTool)& VisMaterialTool() const { return myVisMatTool; }
0155 
0156 protected:
0157 
0158   //! Initialize root label.
0159   Standard_EXPORT void initRoot();
0160 
0161   //! Initialize properties for a current label.
0162   Standard_EXPORT void initCurrent (Standard_Boolean theIsAssembly);
0163 
0164 protected:
0165 
0166   Handle(XCAFDoc_ColorTool)       myColorTool;  //!< color tool
0167   Handle(XCAFDoc_VisMaterialTool) myVisMatTool; //!< visual material tool
0168   TDF_LabelSequence               myRoots;      //!< sequence of root labels
0169   TDF_LabelSequence::Iterator     myRootIter;   //!< current root label
0170   NCollection_Vector<XCAFPrs_DocumentNode>
0171                                   myNodeStack;  //!< node stack
0172   Standard_Integer                myTop;        //!< top position in the node stack
0173   Standard_Boolean                myHasMore;    //!< global flag indicating that iterator points to the label
0174   XCAFPrs_Style                   myDefStyle;   //!< default style
0175   XCAFPrs_DocumentNode            myCurrent;    //!< current label info
0176   XCAFPrs_DocumentExplorerFlags   myFlags;      //!< iteration flags
0177 
0178 };
0179 
0180 #endif // _XCAFPrs_DocumentExplorer_HeaderFile