File indexing completed on 2025-01-18 10:05:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
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
0026 class XCAFPrs_Style
0027 {
0028 public:
0029
0030 DEFINE_STANDARD_ALLOC
0031
0032
0033 Standard_EXPORT XCAFPrs_Style();
0034
0035
0036 Standard_Boolean IsEmpty() const
0037 {
0038 return !myHasColorSurf
0039 && !myHasColorCurv
0040 && myMaterial.IsNull()
0041 && myIsVisible;
0042 }
0043
0044
0045 const Handle(XCAFDoc_VisMaterial)& Material() const { return myMaterial; }
0046
0047
0048 void SetMaterial (const Handle(XCAFDoc_VisMaterial)& theMaterial) { myMaterial = theMaterial; }
0049
0050
0051 Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
0052
0053
0054 const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
0055
0056
0057 void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf (Quantity_ColorRGBA (theColor)); }
0058
0059
0060 const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
0061
0062
0063 Standard_EXPORT void SetColorSurf (const Quantity_ColorRGBA& theColor);
0064
0065
0066 Standard_EXPORT void UnSetColorSurf();
0067
0068
0069 Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
0070
0071
0072 const Quantity_Color& GetColorCurv() const { return myColorCurv; }
0073
0074
0075 Standard_EXPORT void SetColorCurv (const Quantity_Color& col);
0076
0077
0078 Standard_EXPORT void UnSetColorCurv();
0079
0080
0081 void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
0082
0083
0084 Standard_Boolean IsVisible() const { return myIsVisible; }
0085
0086
0087 const Handle(Image_Texture)& BaseColorTexture() const
0088 {
0089 static const Handle(Image_Texture) THE_NULL_TEXTURE;
0090 if (myMaterial.IsNull())
0091 {
0092 return THE_NULL_TEXTURE;
0093 }
0094 else if (myMaterial->HasPbrMaterial()
0095 && !myMaterial->PbrMaterial().BaseColorTexture.IsNull())
0096 {
0097 return myMaterial->PbrMaterial().BaseColorTexture;
0098 }
0099 else if (myMaterial->HasCommonMaterial()
0100 && !myMaterial->CommonMaterial().DiffuseTexture.IsNull())
0101 {
0102 return myMaterial->CommonMaterial().DiffuseTexture;
0103 }
0104 return THE_NULL_TEXTURE;
0105 }
0106
0107
0108
0109 Standard_Boolean IsEqual (const XCAFPrs_Style& theOther) const
0110 {
0111 if (myIsVisible != theOther.myIsVisible)
0112 {
0113 return false;
0114 }
0115 else if (!myIsVisible)
0116 {
0117 return true;
0118 }
0119
0120 return myHasColorSurf == theOther.myHasColorSurf
0121 && myHasColorCurv == theOther.myHasColorCurv
0122 && myMaterial == theOther.myMaterial
0123 && (!myHasColorSurf || myColorSurf == theOther.myColorSurf)
0124 && (!myHasColorCurv || myColorCurv == theOther.myColorCurv);
0125 }
0126
0127
0128 Standard_Boolean operator== (const XCAFPrs_Style& theOther) const
0129 {
0130 return IsEqual (theOther);
0131 }
0132
0133 template<class T>
0134 friend struct std::hash;
0135
0136
0137 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0138
0139 protected:
0140
0141 Handle(XCAFDoc_VisMaterial) myMaterial;
0142 Quantity_ColorRGBA myColorSurf;
0143 Quantity_Color myColorCurv;
0144 Standard_Boolean myHasColorSurf;
0145 Standard_Boolean myHasColorCurv;
0146 Standard_Boolean myIsVisible;
0147
0148 };
0149
0150 namespace std
0151 {
0152 template <>
0153 struct hash<XCAFPrs_Style>
0154 {
0155 size_t operator()(const XCAFPrs_Style& theStyle) const
0156 {
0157 if (!theStyle.myIsVisible)
0158 {
0159 return 1;
0160 }
0161 size_t aCombination[3];
0162 int aCount = 0;
0163 if (theStyle.myHasColorSurf)
0164 {
0165 aCombination[aCount++] = std::hash<Quantity_ColorRGBA>{}(theStyle.myColorSurf);
0166 }
0167 if (theStyle.myHasColorCurv)
0168 {
0169 aCombination[aCount++] = std::hash<Quantity_Color>{}(theStyle.myColorCurv);
0170 }
0171 if (!theStyle.myMaterial.IsNull())
0172 {
0173 aCombination[aCount++] = std::hash<Handle(XCAFDoc_VisMaterial)>{}(theStyle.myMaterial);
0174 }
0175 return aCount > 0 ? opencascade::hashBytes(aCombination, sizeof(size_t) * aCount) : 0;
0176 }
0177 };
0178 }
0179
0180 #endif