1 // Copyright (c) 2019 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _XCAFDoc_VisMaterialTool_HeaderFile
15 #define _XCAFDoc_VisMaterialTool_HeaderFile
17 #include <Standard_Type.hxx>
18 #include <TDF_Attribute.hxx>
19 #include <TDF_LabelSequence.hxx>
22 class Quantity_ColorRGBA;
23 class XCAFDoc_ShapeTool;
24 class XCAFDoc_VisMaterial;
26 //! Provides tools to store and retrieve attributes (visualization materials) of TopoDS_Shape in and from TDocStd_Document.
28 //! This attribute defines the list of visualization materials (XCAFDoc_VisMaterial) within the whole document.
29 //! Particular material is assigned to the shape through tree-nodes links.
31 //! Visualization materials might co-exists with independent color attributes (XCAFDoc_ColorTool),
32 //! but beware to preserve consistency between them (it is better using one attribute type at once to avoid ambiguity).
33 //! Unlike color attributes, list of materials should be managed explicitly by application,
34 //! so that there is no tool eliminating material duplicates or removing unused materials.
36 //! @sa XCAFDoc_VisMaterial
37 class XCAFDoc_VisMaterialTool : public TDF_Attribute
39 DEFINE_STANDARD_RTTIEXT(XCAFDoc_VisMaterialTool, TDF_Attribute)
42 //! Creates (if not exist) ColorTool.
43 Standard_EXPORT static Handle(XCAFDoc_VisMaterialTool) Set (const TDF_Label& L);
45 Standard_EXPORT static const Standard_GUID& GetID();
48 //! Empty constructor.
49 Standard_EXPORT XCAFDoc_VisMaterialTool();
51 //! returns the label under which colors are stored
52 Standard_EXPORT TDF_Label BaseLabel() const { return Label(); }
54 //! Returns internal XCAFDoc_ShapeTool tool
55 Standard_EXPORT const Handle(XCAFDoc_ShapeTool)& ShapeTool();
57 //! Returns TRUE if Label belongs to a Material Table.
58 Standard_Boolean IsMaterial (const TDF_Label& theLabel) const { return !GetMaterial (theLabel).IsNull(); }
60 //! Returns Material defined by specified Label, or NULL if the label is not in Material Table.
61 Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetMaterial (const TDF_Label& theMatLabel) const;
63 //! Adds Material definition to a Material Table and returns its Label.
64 Standard_EXPORT TDF_Label AddMaterial (const Handle(XCAFDoc_VisMaterial)& theMat,
65 const TCollection_AsciiString& theName) const;
67 //! Adds Material definition to a Material Table and returns its Label.
68 Standard_EXPORT TDF_Label AddMaterial(const TCollection_AsciiString& theName) const;
70 //! Removes Material from the Material Table
71 Standard_EXPORT void RemoveMaterial (const TDF_Label& theLabel) const;
73 //! Returns a sequence of Materials currently stored in the Material Table.
74 Standard_EXPORT void GetMaterials (TDF_LabelSequence& Labels) const;
76 //! Sets new material to the shape.
77 Standard_EXPORT void SetShapeMaterial (const TDF_Label& theShapeLabel,
78 const TDF_Label& theMaterialLabel) const;
80 //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
81 Standard_EXPORT void UnSetShapeMaterial (const TDF_Label& theShapeLabel) const;
83 //! Returns TRUE if label has a material assignment.
84 Standard_EXPORT Standard_Boolean IsSetShapeMaterial (const TDF_Label& theLabel) const;
86 //! Returns label with material assigned to shape label.
87 //! @param theShapeLabel [in] shape label
88 //! @param theMaterialLabel [out] material label
89 //! @return FALSE if no material is assigned
90 Standard_EXPORT static Standard_Boolean GetShapeMaterial (const TDF_Label& theShapeLabel, TDF_Label& theMaterialLabel);
92 //! Returns material assigned to the shape label.
93 Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TDF_Label& theShapeLabel);
95 //! Sets a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material label.
96 //! @param theShape [in] shape
97 //! @param theMaterialLabel [in] material label
98 //! @return FALSE if cannot find a label for shape
99 Standard_EXPORT Standard_Boolean SetShapeMaterial (const TopoDS_Shape& theShape,
100 const TDF_Label& theMaterialLabel);
102 //! Removes a link with GUID XCAFDoc::VisMaterialRefGUID() from shape label to material.
103 //! @return TRUE if such link existed
104 Standard_EXPORT Standard_Boolean UnSetShapeMaterial (const TopoDS_Shape& theShape);
106 //! Returns TRUE if shape has a material assignment.
107 Standard_EXPORT Standard_Boolean IsSetShapeMaterial (const TopoDS_Shape& theShape);
109 //! Returns label with material assigned to shape.
110 //! @param theShape [in] shape
111 //! @param theMaterialLabel [out] material label
112 //! @return FALSE if no material is assigned
113 Standard_EXPORT Standard_Boolean GetShapeMaterial (const TopoDS_Shape& theShape, TDF_Label& theMaterialLabel);
115 //! Returns material assigned to shape or NULL if not assigned.
116 Standard_EXPORT Handle(XCAFDoc_VisMaterial) GetShapeMaterial (const TopoDS_Shape& theShape);
120 //! Returns GUID of this attribute type.
121 virtual const Standard_GUID& ID() const Standard_OVERRIDE { return GetID(); }
124 virtual void Restore (const Handle(TDF_Attribute)& ) Standard_OVERRIDE {}
126 //! Creates new instance of this tool.
127 virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE { return new XCAFDoc_VisMaterialTool(); }
130 virtual void Paste (const Handle(TDF_Attribute)& ,
131 const Handle(TDF_RelocationTable)& ) const Standard_OVERRIDE {}
135 Handle(XCAFDoc_ShapeTool) myShapeTool;
139 DEFINE_STANDARD_HANDLE(XCAFDoc_VisMaterialTool, TDF_Attribute)
141 #endif // _XCAFDoc_VisMaterialTool_HeaderFile