Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 09:18:03

0001 // Created on: 2000-08-11
0002 // Created by: Andrey BETENEV
0003 // Copyright (c) 2000-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _XCAFPrs_Style_HeaderFile
0017 #define _XCAFPrs_Style_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <Standard_Handle.hxx>
0022 #include <XCAFDoc_VisMaterial.hxx>
0023 #include <Standard_HashUtils.hxx>
0024 
0025 //! Represents a set of styling settings applicable to a (sub)shape
0026 class XCAFPrs_Style
0027 {
0028 public:
0029   DEFINE_STANDARD_ALLOC
0030 
0031   //! Empty constructor - colors are unset, visibility is TRUE.
0032   Standard_EXPORT XCAFPrs_Style();
0033 
0034   //! Return TRUE if style is empty - does not override any properties.
0035   Standard_Boolean IsEmpty() const
0036   {
0037     return !myHasColorSurf && !myHasColorCurv && myMaterial.IsNull() && myIsVisible;
0038   }
0039 
0040   //! Return material.
0041   const Handle(XCAFDoc_VisMaterial)& Material() const { return myMaterial; }
0042 
0043   //! Set material.
0044   void SetMaterial(const Handle(XCAFDoc_VisMaterial)& theMaterial) { myMaterial = theMaterial; }
0045 
0046   //! Return TRUE if surface color has been defined.
0047   Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
0048 
0049   //! Return surface color.
0050   const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
0051 
0052   //! Set surface color.
0053   void SetColorSurf(const Quantity_Color& theColor) { SetColorSurf(Quantity_ColorRGBA(theColor)); }
0054 
0055   //! Return surface color.
0056   const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
0057 
0058   //! Set surface color.
0059   Standard_EXPORT void SetColorSurf(const Quantity_ColorRGBA& theColor);
0060 
0061   //! Manage surface color setting
0062   Standard_EXPORT void UnSetColorSurf();
0063 
0064   //! Return TRUE if curve color has been defined.
0065   Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
0066 
0067   //! Return curve color.
0068   const Quantity_Color& GetColorCurv() const { return myColorCurv; }
0069 
0070   //! Set curve color.
0071   Standard_EXPORT void SetColorCurv(const Quantity_Color& col);
0072 
0073   //! Manage curve color setting
0074   Standard_EXPORT void UnSetColorCurv();
0075 
0076   //! Assign visibility.
0077   void SetVisibility(const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
0078 
0079   //! Manage visibility.
0080   Standard_Boolean IsVisible() const { return myIsVisible; }
0081 
0082   //! Return base color texture.
0083   const Handle(Image_Texture)& BaseColorTexture() const
0084   {
0085     static const Handle(Image_Texture) THE_NULL_TEXTURE;
0086     if (myMaterial.IsNull())
0087     {
0088       return THE_NULL_TEXTURE;
0089     }
0090     else if (myMaterial->HasPbrMaterial() && !myMaterial->PbrMaterial().BaseColorTexture.IsNull())
0091     {
0092       return myMaterial->PbrMaterial().BaseColorTexture;
0093     }
0094     else if (myMaterial->HasCommonMaterial()
0095              && !myMaterial->CommonMaterial().DiffuseTexture.IsNull())
0096     {
0097       return myMaterial->CommonMaterial().DiffuseTexture;
0098     }
0099     return THE_NULL_TEXTURE;
0100   }
0101 
0102   //! Returns True if styles are the same
0103   //! Methods for using Style as key in maps
0104   Standard_Boolean IsEqual(const XCAFPrs_Style& theOther) const
0105   {
0106     if (myIsVisible != theOther.myIsVisible)
0107     {
0108       return false;
0109     }
0110     else if (!myIsVisible)
0111     {
0112       return true;
0113     }
0114 
0115     return myHasColorSurf == theOther.myHasColorSurf && myHasColorCurv == theOther.myHasColorCurv
0116            && myMaterial == theOther.myMaterial
0117            && (!myHasColorSurf || myColorSurf == theOther.myColorSurf)
0118            && (!myHasColorCurv || myColorCurv == theOther.myColorCurv);
0119   }
0120 
0121   //! Returns True if styles are the same.
0122   Standard_Boolean operator==(const XCAFPrs_Style& theOther) const { return IsEqual(theOther); }
0123 
0124   template <class T>
0125   friend struct std::hash;
0126 
0127   //! Dumps the content of me into the stream
0128   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0129 
0130 protected:
0131   Handle(XCAFDoc_VisMaterial) myMaterial;
0132   Quantity_ColorRGBA          myColorSurf;
0133   Quantity_Color              myColorCurv;
0134   Standard_Boolean            myHasColorSurf;
0135   Standard_Boolean            myHasColorCurv;
0136   Standard_Boolean            myIsVisible;
0137 };
0138 
0139 namespace std
0140 {
0141 template <>
0142 struct hash<XCAFPrs_Style>
0143 {
0144   size_t operator()(const XCAFPrs_Style& theStyle) const
0145   {
0146     if (!theStyle.myIsVisible)
0147     {
0148       return 1;
0149     }
0150     size_t aCombination[3];
0151     int    aCount = 0;
0152     if (theStyle.myHasColorSurf)
0153     {
0154       aCombination[aCount++] = std::hash<Quantity_ColorRGBA>{}(theStyle.myColorSurf);
0155     }
0156     if (theStyle.myHasColorCurv)
0157     {
0158       aCombination[aCount++] = std::hash<Quantity_Color>{}(theStyle.myColorCurv);
0159     }
0160     if (!theStyle.myMaterial.IsNull())
0161     {
0162       aCombination[aCount++] = std::hash<Handle(XCAFDoc_VisMaterial)>{}(theStyle.myMaterial);
0163     }
0164     return aCount > 0 ? opencascade::hashBytes(aCombination, sizeof(size_t) * aCount) : 0;
0165   }
0166 };
0167 } // namespace std
0168 
0169 #endif // _XCAFPrs_Style_HeaderFile