Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-04 08:33:33

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_LabelSequence.hxx>
0019 
0020 class TopoDS_Shape;
0021 class XCAFDoc_ShapeTool;
0022 class XCAFDoc_VisMaterial;
0023 
0024 //! Provides tools to store and retrieve attributes (visualization materials) of TopoDS_Shape in and
0025 //! from TDocStd_Document.
0026 //!
0027 //! This attribute defines the list of visualization materials (XCAFDoc_VisMaterial) within the
0028 //! whole document. Particular material is assigned to the shape through tree-nodes links.
0029 //!
0030 //! Visualization materials might co-exists with independent color attributes (XCAFDoc_ColorTool),
0031 //! but beware to preserve consistency between them (it is better using one attribute type at once
0032 //! to avoid ambiguity). Unlike color attributes, list of materials should be managed explicitly by
0033 //! application, so that there is no tool eliminating material duplicates or removing unused
0034 //! materials.
0035 //!
0036 //! @sa XCAFDoc_VisMaterial
0037 class XCAFDoc_VisMaterialTool : public TDF_Attribute
0038 {
0039   DEFINE_STANDARD_RTTIEXT(XCAFDoc_VisMaterialTool, TDF_Attribute)
0040 public:
0041   //! Creates (if not exist) ColorTool.
0042   Standard_EXPORT static Handle(XCAFDoc_VisMaterialTool) Set(const TDF_Label& L);
0043 
0044   Standard_EXPORT static const Standard_GUID& GetID();
0045 
0046 public:
0047   //! Empty constructor.
0048   Standard_EXPORT XCAFDoc_VisMaterialTool();
0049 
0050   //! returns the label under which colors are stored
0051   Standard_EXPORT TDF_Label BaseLabel() const { return Label(); }
0052 
0053   //! Returns internal XCAFDoc_ShapeTool tool
0054   Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
0055 
0056   //! Returns TRUE if Label belongs to a Material Table.
0057   Standard_Boolean IsMaterial(const TDF_Label& theLabel) const
0058   {
0059     return !GetMaterial(theLabel).IsNull();
0060   }
0061 
0062   //! Returns Material defined by specified Label, or NULL if the label is not in Material Table.
0063   Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetMaterial(const TDF_Label& theMatLabel);
0064 
0065   //! Adds Material definition to a Material Table and returns its Label.
0066   Standard_EXPORT TDF_Label AddMaterial(const Handle(XCAFDoc_VisMaterial)& theMat,
0067                                         const TCollection_AsciiString&     theName) const;
0068 
0069   //! Adds Material definition to a Material Table and returns its Label.
0070   Standard_EXPORT TDF_Label AddMaterial(const TCollection_AsciiString& theName) const;
0071 
0072   //! Removes Material from the Material Table
0073   Standard_EXPORT void RemoveMaterial(const TDF_Label& theLabel) const;
0074 
0075   //! Returns a sequence of Materials currently stored in the Material Table.
0076   Standard_EXPORT void GetMaterials(TDF_LabelSequence& Labels) const;
0077 
0078   //! Sets new material to the shape.
0079   Standard_EXPORT void SetShapeMaterial(const TDF_Label& theShapeLabel,
0080                                         const TDF_Label& theMaterialLabel) const;
0081 
0082   //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
0083   Standard_EXPORT void UnSetShapeMaterial(const TDF_Label& theShapeLabel) const;
0084 
0085   //! Returns TRUE if label has a material assignment.
0086   Standard_EXPORT Standard_Boolean IsSetShapeMaterial(const TDF_Label& theLabel) const;
0087 
0088   //! Returns label with material assigned to shape label.
0089   //! @param[in] theShapeLabel  shape label
0090   //! @param[out] theMaterialLabel  material label
0091   //! @return FALSE if no material is assigned
0092   Standard_EXPORT static Standard_Boolean GetShapeMaterial(const TDF_Label& theShapeLabel,
0093                                                            TDF_Label&       theMaterialLabel);
0094 
0095   //! Returns material assigned to the shape label.
0096   Standard_EXPORT static Handle(XCAFDoc_VisMaterial) GetShapeMaterial(
0097     const TDF_Label& theShapeLabel);
0098 
0099   //! Sets a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material label.
0100   //! @param[in] theShape  shape
0101   //! @param[in] theMaterialLabel  material label
0102   //! @return FALSE if cannot find a label for shape
0103   Standard_EXPORT Standard_Boolean SetShapeMaterial(const TopoDS_Shape& theShape,
0104                                                     const TDF_Label&    theMaterialLabel);
0105 
0106   //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
0107   //! @return TRUE if such link existed
0108   Standard_EXPORT Standard_Boolean UnSetShapeMaterial(const TopoDS_Shape& theShape);
0109 
0110   //! Returns TRUE if shape has a material assignment.
0111   Standard_EXPORT Standard_Boolean IsSetShapeMaterial(const TopoDS_Shape& theShape);
0112 
0113   //! Returns label with material assigned to shape.
0114   //! @param[in] theShape  shape
0115   //! @param[out] theMaterialLabel  material label
0116   //! @return FALSE if no material is assigned
0117   Standard_EXPORT Standard_Boolean GetShapeMaterial(const TopoDS_Shape& theShape,
0118                                                     TDF_Label&          theMaterialLabel);
0119 
0120   //! Returns material assigned to shape or NULL if not assigned.
0121   Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial(const TopoDS_Shape& theShape);
0122 
0123 public:
0124   //! Returns GUID of this attribute type.
0125   virtual const Standard_GUID& ID() const Standard_OVERRIDE { return GetID(); }
0126 
0127   //! Does nothing.
0128   virtual void Restore(const Handle(TDF_Attribute)&) Standard_OVERRIDE {}
0129 
0130   //! Creates new instance of this tool.
0131   virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE
0132   {
0133     return new XCAFDoc_VisMaterialTool();
0134   }
0135 
0136   //! Does nothing.
0137   virtual void Paste(const Handle(TDF_Attribute)&,
0138                      const Handle(TDF_RelocationTable)&) const Standard_OVERRIDE
0139   {
0140   }
0141 
0142 private:
0143   Handle(XCAFDoc_ShapeTool) myShapeTool;
0144 };
0145 
0146 DEFINE_STANDARD_HANDLE(XCAFDoc_VisMaterialTool, TDF_Attribute)
0147 
0148 #endif // _XCAFDoc_VisMaterialTool_HeaderFile