File indexing completed on 2026-09-08 09:18:03
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 DEFINE_STANDARD_ALLOC
0030
0031
0032 Standard_EXPORT XCAFPrs_Style();
0033
0034
0035 Standard_Boolean IsEmpty() const
0036 {
0037 return !myHasColorSurf && !myHasColorCurv && myMaterial.IsNull() && myIsVisible;
0038 }
0039
0040
0041 const Handle(XCAFDoc_VisMaterial)& Material() const { return myMaterial; }
0042
0043
0044 void SetMaterial(const Handle(XCAFDoc_VisMaterial)& theMaterial) { myMaterial = theMaterial; }
0045
0046
0047 Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
0048
0049
0050 const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
0051
0052
0053 void SetColorSurf(const Quantity_Color& theColor) { SetColorSurf(Quantity_ColorRGBA(theColor)); }
0054
0055
0056 const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
0057
0058
0059 Standard_EXPORT void SetColorSurf(const Quantity_ColorRGBA& theColor);
0060
0061
0062 Standard_EXPORT void UnSetColorSurf();
0063
0064
0065 Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
0066
0067
0068 const Quantity_Color& GetColorCurv() const { return myColorCurv; }
0069
0070
0071 Standard_EXPORT void SetColorCurv(const Quantity_Color& col);
0072
0073
0074 Standard_EXPORT void UnSetColorCurv();
0075
0076
0077 void SetVisibility(const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
0078
0079
0080 Standard_Boolean IsVisible() const { return myIsVisible; }
0081
0082
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
0103
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
0122 Standard_Boolean operator==(const XCAFPrs_Style& theOther) const { return IsEqual(theOther); }
0123
0124 template <class T>
0125 friend struct std::hash;
0126
0127
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 }
0168
0169 #endif