0027670: Visualization - avoid duplication of structures defining primitive array...
[occt.git] / src / Graphic3d / Graphic3d_AspectMarker3d.hxx
1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Graphic3d_AspectMarker3d_HeaderFile
17 #define _Graphic3d_AspectMarker3d_HeaderFile
18
19 #include <Aspect_AspectMarkerDefinitionError.hxx>
20 #include <Aspect_TypeOfMarker.hxx>
21 #include <Graphic3d_MarkerImage.hxx>
22 #include <Graphic3d_ShaderProgram.hxx>
23 #include <Image_PixMap.hxx>
24 #include <Standard.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Real.hxx>
27 #include <Standard_Type.hxx>
28 #include <TColStd_HArray1OfByte.hxx>
29 #include <Quantity_ColorRGBA.hxx>
30
31 //! Creates and updates an attribute group for marker type primitives.
32 //! This group contains the type of marker, its color, and its scale factor.
33 class Graphic3d_AspectMarker3d : public Standard_Transient
34 {
35   DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectMarker3d, Standard_Transient)
36 public:
37
38   //! Creates a context table for marker primitives
39   //! defined with the following default values:
40   //!
41   //! Marker type : TOM_X
42   //! Color       : YELLOW
43   //! Scale factor: 1.0
44   Standard_EXPORT Graphic3d_AspectMarker3d();
45   
46   Standard_EXPORT Graphic3d_AspectMarker3d(const Aspect_TypeOfMarker theType, const Quantity_Color& theColor, const Standard_Real theScale);
47   
48   //! Creates a context table for marker primitives
49   //! defined with the specified values.
50   Standard_EXPORT Graphic3d_AspectMarker3d(const Quantity_Color& theColor, const Standard_Integer theWidth, const Standard_Integer theHeight, const Handle(TColStd_HArray1OfByte)& theTextureBitmap);
51   
52   //! Creates a context table for marker primitives
53   //! defined with the specified values.
54   Standard_EXPORT Graphic3d_AspectMarker3d(const Handle(Image_PixMap)& theTextureImage);
55
56   //! Return color.
57   const Quantity_ColorRGBA& ColorRGBA() const { return myColor; }
58
59   //! Return the color.
60   const Quantity_Color& Color() const { return myColor.GetRGB(); }
61
62   //! Modifies the color.
63   void SetColor (const Quantity_Color& theColor) { myColor.SetRGB (theColor); }
64
65   //! Return scale factor.
66   Standard_ShortReal Scale() const { return myScale; }
67
68   //! Modifies the scale factor.
69   //! Marker type Aspect_TOM_POINT is not affected by the marker size scale factor.
70   //! It is always the smallest displayable dot.
71   //! Warning: Raises AspectMarkerDefinitionError if the scale is a negative value.
72   void SetScale (const Standard_ShortReal theScale)
73   {
74     if (theScale <= 0.0f)
75     {
76       Aspect_AspectMarkerDefinitionError::Raise ("Bad value for MarkerScale");
77     }
78     myScale = theScale;
79   }
80
81   //! Assign scale factor.
82   void SetScale (const Standard_Real theScale) { SetScale ((float )theScale); }
83
84   //! Return marker type.
85   Aspect_TypeOfMarker Type() const { return myType; }
86
87   //! Modifies the type of marker.
88   void SetType (const Aspect_TypeOfMarker theType) { myType = theType; }
89
90   //! Returns marker's texture size.
91   Standard_EXPORT void GetTextureSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
92   
93   //! Returns marker's image texture.
94   //! Could be null handle if marker aspect has been initialized as default type of marker.
95   const Handle(Graphic3d_MarkerImage)& GetMarkerImage() const { return myMarkerImage; }
96   
97   //! Set marker's image texture.
98   void SetMarkerImage (const Handle(Graphic3d_MarkerImage)& theImage) { myMarkerImage = theImage; }
99
100   Standard_EXPORT void SetBitMap (const Standard_Integer theWidth, const Standard_Integer theHeight, const Handle(TColStd_HArray1OfByte)& theTexture);
101
102   //! Return the program.
103   const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; }
104
105   //! Sets up OpenGL/GLSL shader program.
106   void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; }
107
108 public:
109
110   //! Returns the current values of the group.
111   Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters")
112   void Values (Quantity_Color&      theColor,
113                Aspect_TypeOfMarker& theType,
114                Standard_Real&       theScale) const
115   {
116     theColor = myColor.GetRGB();
117     theType  = myType;
118     theScale = myScale;
119   }
120
121 protected:
122
123   Handle(Graphic3d_ShaderProgram) myProgram;
124   Handle(Graphic3d_MarkerImage)   myMarkerImage;
125   Quantity_ColorRGBA  myColor;
126   Aspect_TypeOfMarker myType;
127   Standard_ShortReal  myScale;
128
129 };
130
131 DEFINE_STANDARD_HANDLE(Graphic3d_AspectMarker3d, Standard_Transient)
132
133 #endif // _Graphic3d_AspectMarker3d_HeaderFile