Back to home page

EIC code displayed by LXR

 
 

    


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

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