Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0030   DEFINE_STANDARD_ALLOC
0031 
0032   //! Empty constructor - colors are unset, visibility is TRUE.
0033   Standard_EXPORT XCAFPrs_Style();
0034 
0035   //! Return TRUE if style is empty - does not override any properties.
0036   Standard_Boolean IsEmpty() const
0037   {
0038     return !myHasColorSurf
0039         && !myHasColorCurv
0040         &&  myMaterial.IsNull()
0041         &&  myIsVisible;
0042   }
0043 
0044   //! Return material.
0045   const Handle(XCAFDoc_VisMaterial)& Material() const { return myMaterial; }
0046 
0047   //! Set material.
0048   void SetMaterial (const Handle(XCAFDoc_VisMaterial)& theMaterial) { myMaterial = theMaterial; }
0049 
0050   //! Return TRUE if surface color has been defined.
0051   Standard_Boolean IsSetColorSurf() const { return myHasColorSurf; }
0052 
0053   //! Return surface color.
0054   const Quantity_Color& GetColorSurf() const { return myColorSurf.GetRGB(); }
0055 
0056   //! Set surface color.
0057   void SetColorSurf (const Quantity_Color& theColor) { SetColorSurf  (Quantity_ColorRGBA (theColor)); }
0058 
0059   //! Return surface color.
0060   const Quantity_ColorRGBA& GetColorSurfRGBA() const { return myColorSurf; }
0061 
0062   //! Set surface color.
0063   Standard_EXPORT void SetColorSurf  (const Quantity_ColorRGBA& theColor);
0064 
0065   //! Manage surface color setting
0066   Standard_EXPORT void UnSetColorSurf();
0067   
0068   //! Return TRUE if curve color has been defined.
0069   Standard_Boolean IsSetColorCurv() const { return myHasColorCurv; }
0070 
0071   //! Return curve color.
0072   const Quantity_Color& GetColorCurv() const { return myColorCurv; }
0073 
0074   //! Set curve color.
0075   Standard_EXPORT void SetColorCurv (const Quantity_Color& col);
0076   
0077   //! Manage curve color setting
0078   Standard_EXPORT void UnSetColorCurv();
0079 
0080   //! Assign visibility.
0081   void SetVisibility (const Standard_Boolean theVisibility) { myIsVisible = theVisibility; }
0082 
0083   //! Manage visibility.
0084   Standard_Boolean IsVisible() const { return myIsVisible; }
0085 
0086   //! Return base color texture.
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   //! Returns True if styles are the same
0108   //! Methods for using Style as key in maps
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   //! Returns True if styles are the same.
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   //! Dumps the content of me into the stream
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 // _XCAFPrs_Style_HeaderFile