Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-01 09:02:51

0001 // Copyright (c) 2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _XCAFDoc_VisMaterialTool_HeaderFile
0015 #define _XCAFDoc_VisMaterialTool_HeaderFile
0016 
0017 #include <Standard_Type.hxx>
0018 #include <TDF_Label.hxx>
0019 #include <NCollection_Sequence.hxx>
0020 
0021 class TopoDS_Shape;
0022 class XCAFDoc_ShapeTool;
0023 class XCAFDoc_VisMaterial;
0024 
0025 //! Provides tools to store and retrieve attributes (visualization materials) of TopoDS_Shape in and
0026 //! from TDocStd_Document.
0027 //!
0028 //! This attribute defines the list of visualization materials (XCAFDoc_VisMaterial) within the
0029 //! whole document. Particular material is assigned to the shape through tree-nodes links.
0030 //!
0031 //! Visualization materials might co-exists with independent color attributes (XCAFDoc_ColorTool),
0032 //! but beware to preserve consistency between them (it is better using one attribute type at once
0033 //! to avoid ambiguity). Unlike color attributes, list of materials should be managed explicitly by
0034 //! application, so that there is no tool eliminating material duplicates or removing unused
0035 //! materials.
0036 //!
0037 //! @sa XCAFDoc_VisMaterial
0038 class XCAFDoc_VisMaterialTool : public TDF_Attribute
0039 {
0040   DEFINE_STANDARD_RTTIEXT(XCAFDoc_VisMaterialTool, TDF_Attribute)
0041 public:
0042   //! Creates (if not exist) ColorTool.
0043   Standard_EXPORT static occ::handle<XCAFDoc_VisMaterialTool> Set(const TDF_Label& L);
0044 
0045   Standard_EXPORT static const Standard_GUID& GetID();
0046 
0047 public:
0048   //! Empty constructor.
0049   Standard_EXPORT XCAFDoc_VisMaterialTool();
0050 
0051   //! returns the label under which colors are stored
0052   Standard_EXPORT TDF_Label BaseLabel() const { return Label(); }
0053 
0054   //! Returns internal XCAFDoc_ShapeTool tool
0055   Standard_EXPORT const occ::handle<XCAFDoc_ShapeTool>& ShapeTool();
0056 
0057   //! Returns TRUE if Label belongs to a Material Table.
0058   bool IsMaterial(const TDF_Label& theLabel) const { return !GetMaterial(theLabel).IsNull(); }
0059 
0060   //! Returns Material defined by specified Label, or NULL if the label is not in Material Table.
0061   Standard_EXPORT static occ::handle<XCAFDoc_VisMaterial> GetMaterial(const TDF_Label& theMatLabel);
0062 
0063   //! Adds Material definition to a Material Table and returns its Label.
0064   Standard_EXPORT TDF_Label AddMaterial(const occ::handle<XCAFDoc_VisMaterial>& theMat,
0065                                         const TCollection_AsciiString&          theName) const;
0066 
0067   //! Adds Material definition to a Material Table and returns its Label.
0068   Standard_EXPORT TDF_Label AddMaterial(const TCollection_AsciiString& theName) const;
0069 
0070   //! Removes Material from the Material Table
0071   Standard_EXPORT void RemoveMaterial(const TDF_Label& theLabel) const;
0072 
0073   //! Returns a sequence of Materials currently stored in the Material Table.
0074   Standard_EXPORT void GetMaterials(NCollection_Sequence<TDF_Label>& Labels) const;
0075 
0076   //! Sets new material to the shape.
0077   Standard_EXPORT void SetShapeMaterial(const TDF_Label& theShapeLabel,
0078                                         const TDF_Label& theMaterialLabel) const;
0079 
0080   //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
0081   Standard_EXPORT void UnSetShapeMaterial(const TDF_Label& theShapeLabel) const;
0082 
0083   //! Returns TRUE if label has a material assignment.
0084   Standard_EXPORT bool IsSetShapeMaterial(const TDF_Label& theLabel) const;
0085 
0086   //! Returns label with material assigned to shape label.
0087   //! @param[in] theShapeLabel  shape label
0088   //! @param[out] theMaterialLabel  material label
0089   //! @return FALSE if no material is assigned
0090   Standard_EXPORT static bool GetShapeMaterial(const TDF_Label& theShapeLabel,
0091                                                TDF_Label&       theMaterialLabel);
0092 
0093   //! Returns material assigned to the shape label.
0094   Standard_EXPORT static occ::handle<XCAFDoc_VisMaterial> GetShapeMaterial(
0095     const TDF_Label& theShapeLabel);
0096 
0097   //! Sets a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material label.
0098   //! @param[in] theShape  shape
0099   //! @param[in] theMaterialLabel  material label
0100   //! @return FALSE if cannot find a label for shape
0101   Standard_EXPORT bool SetShapeMaterial(const TopoDS_Shape& theShape,
0102                                         const TDF_Label&    theMaterialLabel);
0103 
0104   //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
0105   //! @return TRUE if such link existed
0106   Standard_EXPORT bool UnSetShapeMaterial(const TopoDS_Shape& theShape);
0107 
0108   //! Returns TRUE if shape has a material assignment.
0109   Standard_EXPORT bool IsSetShapeMaterial(const TopoDS_Shape& theShape);
0110 
0111   //! Returns label with material assigned to shape.
0112   //! @param[in] theShape  shape
0113   //! @param[out] theMaterialLabel  material label
0114   //! @return FALSE if no material is assigned
0115   Standard_EXPORT bool GetShapeMaterial(const TopoDS_Shape& theShape, TDF_Label& theMaterialLabel);
0116 
0117   //! Returns material assigned to shape or NULL if not assigned.
0118   Standard_EXPORT occ::handle<XCAFDoc_VisMaterial> GetShapeMaterial(const TopoDS_Shape& theShape);
0119 
0120 public:
0121   //! Returns GUID of this attribute type.
0122   const Standard_GUID& ID() const override { return GetID(); }
0123 
0124   //! Does nothing.
0125   void Restore(const occ::handle<TDF_Attribute>&) override {}
0126 
0127   //! Creates new instance of this tool.
0128   occ::handle<TDF_Attribute> NewEmpty() const override { return new XCAFDoc_VisMaterialTool(); }
0129 
0130   //! Does nothing.
0131   void Paste(const occ::handle<TDF_Attribute>&,
0132              const occ::handle<TDF_RelocationTable>&) const override
0133   {
0134   }
0135 
0136 private:
0137   occ::handle<XCAFDoc_ShapeTool> myShapeTool;
0138 };
0139 
0140 #endif // _XCAFDoc_VisMaterialTool_HeaderFile