~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/App/Material.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
Import upstream version 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) J�rgen Riegel          (juergen.riegel@web.de) 2005     *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
 
 
25
 
 
26
#ifndef APP_MATERIAL_H
 
27
#define APP_MATERIAL_H
 
28
 
 
29
#ifdef __GNUC__
 
30
# include <stdint.h>
 
31
#endif
 
32
 
 
33
namespace Base
 
34
{
 
35
  class PyObjectBase;
 
36
}
 
37
 
 
38
namespace App
 
39
{
 
40
 
 
41
 
 
42
/** Color class
 
43
 */
 
44
class AppExport Color
 
45
{
 
46
public:
 
47
  /**
 
48
   * Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
 
49
   * \a A defines the transparency.
 
50
   */
 
51
  explicit Color(float R=0.0,float G=0.0, float B=0.0, float A=0.0)
 
52
    :r(R),g(G),b(B),a(A){}
 
53
  /**
 
54
   * Does basically the same as the constructor above unless that (R,G,B,A) is
 
55
   * encoded as an unsigned int.
 
56
   */
 
57
  Color(uint32_t rgba)
 
58
  { setPackedValue( rgba ); }
 
59
  /** Copy constructor. */
 
60
  Color(const Color& c)
 
61
    :r(c.r),g(c.g),b(c.b),a(c.a){}
 
62
  /** Returns true if both colors are equal. Therefore all components must be equal. */
 
63
  bool operator==(const Color& c) const
 
64
  {
 
65
    return getPackedValue() == c.getPackedValue();
 
66
    //return (c.r==r && c.g==g && c.b==b && c.a==a); 
 
67
  }
 
68
  bool operator!=(const Color& c) const 
 
69
  {
 
70
    return !operator==(c);
 
71
  }
 
72
  /**
 
73
   * Defines the color as (R,G,B,A) whereas all values are in the range [0,1].
 
74
   * \a A defines the transparency, 0 means complete opaque and 1 invisible.
 
75
   */
 
76
  void set(float R,float G, float B, float A=0.0)
 
77
  {
 
78
    r=R;g=G;b=B;a=A;
 
79
  }
 
80
  Color& operator=(const Color& c)
 
81
  {
 
82
    r=c.r;g=c.g;b=c.b;a=c.a;
 
83
    return *this;
 
84
  }
 
85
  /**
 
86
   * Sets the color value as a 32 bit combined red/green/blue/alpha value.
 
87
   * Each component is 8 bit wide (i.e. from 0x00 to 0xff), and the red
 
88
   * value should be stored leftmost, like this: 0xRRGGBBAA.
 
89
   *
 
90
   * \sa getPackedValue().
 
91
   */
 
92
  Color& setPackedValue(uint32_t rgba)
 
93
  {
 
94
    this->set( (rgba >> 24)/255.0f, ((rgba >> 16)&0xff)/255.0f, ((rgba >> 8)&0xff)/255.0f, (rgba&0xff)/255.0f );
 
95
    return *this;
 
96
  }
 
97
  /**
 
98
   * Returns color as a 32 bit packed unsigned int in the form 0xRRGGBBAA.
 
99
   *
 
100
   *  \sa setPackedValue().
 
101
   */
 
102
  uint32_t getPackedValue() const
 
103
  {
 
104
    return ((uint32_t)(r*255.0f + 0.5f) << 24 |
 
105
            (uint32_t)(g*255.0f + 0.5f) << 16 |
 
106
            (uint32_t)(b*255.0f + 0.5f) << 8  |
 
107
            (uint32_t)(a*255.0f + 0.5f));
 
108
  }
 
109
 
 
110
  /// color values, public accesible
 
111
  float r,g,b,a;
 
112
};
 
113
 
 
114
/** Material class
 
115
 */
 
116
class MaterialPy;
 
117
class AppExport Material
 
118
{
 
119
public:
 
120
  enum MaterialType { 
 
121
    BRASS,
 
122
    BRONZE,
 
123
    COPPER,
 
124
    GOLD,
 
125
    PEWTER,
 
126
    PLASTER,
 
127
    PLASTIC,
 
128
    SILVER,
 
129
    STEEL,
 
130
    STONE,
 
131
    SHINY_PLASTIC,
 
132
    SATIN,
 
133
    METALIZED,
 
134
    NEON_GNC,
 
135
    CHROME,
 
136
    ALUMINIUM,
 
137
    OBSIDIAN,
 
138
    NEON_PHC,
 
139
    JADE,
 
140
    RUBY,
 
141
    EMERALD,
 
142
    DEFAULT,
 
143
    USER_DEFINED
 
144
  };
 
145
 
 
146
public:
 
147
  /** @name Constructors
 
148
   */
 
149
  //@{
 
150
  /** Sets the USER_DEFINED material type. The user must set the colors afterwards. */
 
151
  Material(void);
 
152
  /** Defines the colors and shininess for the material \a MatName. If \a MatName isn't defined then USER_DEFINED is
 
153
   * set and the user must define the colors itself.
 
154
   */
 
155
  Material(const char* MatName);
 
156
  /** Does basically the same as the constructor above unless that it accepts a MaterialType as argument. */
 
157
  Material(const MaterialType MatType);
 
158
  //@}
 
159
  virtual ~Material();
 
160
 
 
161
  /** Set a material by name
 
162
   *  There are some standard materials defined which are:
 
163
   *  \li Brass
 
164
   *  \li Bronze
 
165
   *  \li Copper
 
166
   *  \li Gold
 
167
   *  \li Pewter
 
168
   *  \li Plaster
 
169
   *  \li Plastic
 
170
   *  \li Silver
 
171
   *  \li Steel
 
172
   *  \li Stone
 
173
   *  \li Shiny plastic
 
174
   *  \li Satin
 
175
   *  \li Metalized
 
176
   *  \li Neon GNC
 
177
   *  \li Chrome
 
178
   *  \li Aluminium
 
179
   *  \li Obsidian
 
180
   *  \li Neon PHC
 
181
   *  \li Jade
 
182
   *  \li Ruby
 
183
   *  \li Emerald
 
184
   * Furthermore there two additional modes \a Default which defines a kind of grey metalic and user defined that
 
185
   * does nothing.
 
186
   * The Color and the other properties of the material are defined in the range [0-1].
 
187
   * If \a MatName is an unknown material name then the type USER_DEFINED is set and the material doesn't get changed.
 
188
   */
 
189
  void set(const char* MatName);
 
190
  /**
 
191
   * This method is provided for convenience which does basically the same as the method above unless that it accepts a MaterialType 
 
192
   * as argument.
 
193
   */
 
194
  void setType(const MaterialType MatType);
 
195
  /**
 
196
   * Returns the currently set material type.
 
197
   */
 
198
  MaterialType getType() const
 
199
  { return _matType; }
 
200
 
 
201
  //Base::PyObjectBase* GetPyObject(void);
 
202
 
 
203
  /** @name Properties */
 
204
  //@{
 
205
  Color ambientColor;  /**< Defines the ambient color. */
 
206
  Color diffuseColor;  /**< Defines the diffuse color. */
 
207
  Color specularColor; /**< Defines the specular color. */
 
208
  Color emissiveColor; /**< Defines the emissive color. */
 
209
  float shininess;
 
210
  float transparency;
 
211
  //@}
 
212
 
 
213
private:
 
214
  MaterialPy* _materialPy;
 
215
  MaterialType _matType;
 
216
};
 
217
 
 
218
} //namespace App
 
219
 
 
220
#endif // APP_MATERIAL_H