xref: /AOO41X/main/drawinglayer/source/attribute/sdrobjectattribute3d.cxx (revision 4bfbcde8d64cc5d114df10dce4a9ed79eff32278)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_drawinglayer.hxx"
24 
25 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
26 #include <drawinglayer/attribute/materialattribute3d.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 
30 namespace drawinglayer
31 {
32     namespace attribute
33     {
34         class ImpSdr3DObjectAttribute
35         {
36         public:
37             // refcounter
38             sal_uInt32                              mnRefCount;
39 
40             // 3D object attribute definitions
41             ::com::sun::star::drawing::NormalsKind              maNormalsKind;              // normals type (0..2)
42             ::com::sun::star::drawing::TextureProjectionMode    maTextureProjectionX;       // texture projection type X (0..2)
43             ::com::sun::star::drawing::TextureProjectionMode    maTextureProjectionY;       // texture projection type Y (0..2)
44             ::com::sun::star::drawing::TextureKind2             maTextureKind;              // texture kind (see uno API)
45             ::com::sun::star::drawing::TextureMode              maTextureMode;              // texture kind (see uno API)
46             MaterialAttribute3D                                 maMaterial;                 // object, specular and emissive colors, SpecularIntensity
47 
48             // bitfield
49             unsigned                                            mbNormalsInvert : 1;        // invert normals
50             unsigned                                            mbDoubleSided : 1;          // surfaces are double sided
51             unsigned                                            mbShadow3D : 1;             // display shadow in 3D (if on), params for that are at scene
52             unsigned                                            mbTextureFilter : 1;        // filter texture to make more smooth
53             unsigned                                            mbReducedLineGeometry : 1;  // use reduced line geometry (object specific)
54 
ImpSdr3DObjectAttribute(::com::sun::star::drawing::NormalsKind aNormalsKind,::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX,::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY,::com::sun::star::drawing::TextureKind2 aTextureKind,::com::sun::star::drawing::TextureMode aTextureMode,const MaterialAttribute3D & rMaterial,bool bNormalsInvert,bool bDoubleSided,bool bShadow3D,bool bTextureFilter,bool bReducedLineGeometry)55             ImpSdr3DObjectAttribute(
56                 ::com::sun::star::drawing::NormalsKind  aNormalsKind,
57                 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX,
58                 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY,
59                 ::com::sun::star::drawing::TextureKind2 aTextureKind,
60                 ::com::sun::star::drawing::TextureMode aTextureMode,
61                 const MaterialAttribute3D& rMaterial,
62                 bool bNormalsInvert,
63                 bool bDoubleSided,
64                 bool bShadow3D,
65                 bool bTextureFilter,
66                 bool bReducedLineGeometry)
67             :   mnRefCount(0),
68                 maNormalsKind(aNormalsKind),
69                 maTextureProjectionX(aTextureProjectionX),
70                 maTextureProjectionY(aTextureProjectionY),
71                 maTextureKind(aTextureKind),
72                 maTextureMode(aTextureMode),
73                 maMaterial(rMaterial),
74                 mbNormalsInvert(bNormalsInvert),
75                 mbDoubleSided(bDoubleSided),
76                 mbShadow3D(bShadow3D),
77                 mbTextureFilter(bTextureFilter),
78                 mbReducedLineGeometry(bReducedLineGeometry)
79             {
80             }
81 
82             // data read access
getNormalsKind() const83             ::com::sun::star::drawing::NormalsKind getNormalsKind() const { return maNormalsKind; }
getTextureProjectionX() const84             ::com::sun::star::drawing::TextureProjectionMode getTextureProjectionX() const { return maTextureProjectionX; }
getTextureProjectionY() const85             ::com::sun::star::drawing::TextureProjectionMode getTextureProjectionY() const { return maTextureProjectionY; }
getTextureKind() const86             ::com::sun::star::drawing::TextureKind2 getTextureKind() const { return maTextureKind; }
getTextureMode() const87             ::com::sun::star::drawing::TextureMode getTextureMode() const { return maTextureMode; }
getMaterial() const88             const MaterialAttribute3D& getMaterial() const { return maMaterial; }
getNormalsInvert() const89             bool getNormalsInvert() const { return mbNormalsInvert; }
getDoubleSided() const90             bool getDoubleSided() const { return mbDoubleSided; }
getShadow3D() const91             bool getShadow3D() const { return mbShadow3D; }
getTextureFilter() const92             bool getTextureFilter() const { return mbTextureFilter; }
getReducedLineGeometry() const93             bool getReducedLineGeometry() const { return mbReducedLineGeometry; }
94 
operator ==(const ImpSdr3DObjectAttribute & rCandidate) const95             bool operator==(const ImpSdr3DObjectAttribute& rCandidate) const
96             {
97                 return (getNormalsKind() == rCandidate.getNormalsKind()
98                     && getTextureProjectionX() == rCandidate.getTextureProjectionX()
99                     && getTextureProjectionY() == rCandidate.getTextureProjectionY()
100                     && getTextureKind() == rCandidate.getTextureKind()
101                     && getTextureMode() == rCandidate.getTextureMode()
102                     && getMaterial() == rCandidate.getMaterial()
103                     && getNormalsInvert() == rCandidate.getNormalsInvert()
104                     && getDoubleSided() == rCandidate.getDoubleSided()
105                     && getShadow3D() == rCandidate.getShadow3D()
106                     && getTextureFilter() == rCandidate.getTextureFilter()
107                     && getReducedLineGeometry() == rCandidate.getReducedLineGeometry());
108             }
109 
get_global_default()110             static ImpSdr3DObjectAttribute* get_global_default()
111             {
112                 static ImpSdr3DObjectAttribute* pDefault = 0;
113 
114                 if(!pDefault)
115                 {
116                     pDefault = new ImpSdr3DObjectAttribute(
117                         ::com::sun::star::drawing::NormalsKind_SPECIFIC,
118                         ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC,
119                         ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC,
120                         ::com::sun::star::drawing::TextureKind2_LUMINANCE,
121                         ::com::sun::star::drawing::TextureMode_REPLACE,
122                         MaterialAttribute3D(),
123                         false,
124                         false,
125                         false,
126                         false,
127                         false);
128 
129                     // never delete; start with RefCount 1, not 0
130                     pDefault->mnRefCount++;
131                 }
132 
133                 return pDefault;
134             }
135         };
136 
Sdr3DObjectAttribute(::com::sun::star::drawing::NormalsKind aNormalsKind,::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX,::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY,::com::sun::star::drawing::TextureKind2 aTextureKind,::com::sun::star::drawing::TextureMode aTextureMode,const MaterialAttribute3D & rMaterial,bool bNormalsInvert,bool bDoubleSided,bool bShadow3D,bool bTextureFilter,bool bReducedLineGeometry)137         Sdr3DObjectAttribute::Sdr3DObjectAttribute(
138             ::com::sun::star::drawing::NormalsKind  aNormalsKind,
139             ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX,
140             ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY,
141             ::com::sun::star::drawing::TextureKind2 aTextureKind,
142             ::com::sun::star::drawing::TextureMode aTextureMode,
143             const MaterialAttribute3D& rMaterial,
144             bool bNormalsInvert,
145             bool bDoubleSided,
146             bool bShadow3D,
147             bool bTextureFilter,
148             bool bReducedLineGeometry)
149         :   mpSdr3DObjectAttribute(new ImpSdr3DObjectAttribute(
150                 aNormalsKind, aTextureProjectionX, aTextureProjectionY, aTextureKind, aTextureMode,
151                 rMaterial, bNormalsInvert, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry))
152         {
153         }
154 
Sdr3DObjectAttribute()155         Sdr3DObjectAttribute::Sdr3DObjectAttribute()
156         :   mpSdr3DObjectAttribute(ImpSdr3DObjectAttribute::get_global_default())
157         {
158             mpSdr3DObjectAttribute->mnRefCount++;
159         }
160 
Sdr3DObjectAttribute(const Sdr3DObjectAttribute & rCandidate)161         Sdr3DObjectAttribute::Sdr3DObjectAttribute(const Sdr3DObjectAttribute& rCandidate)
162         :   mpSdr3DObjectAttribute(rCandidate.mpSdr3DObjectAttribute)
163         {
164             mpSdr3DObjectAttribute->mnRefCount++;
165         }
166 
~Sdr3DObjectAttribute()167         Sdr3DObjectAttribute::~Sdr3DObjectAttribute()
168         {
169             if(mpSdr3DObjectAttribute->mnRefCount)
170             {
171                 mpSdr3DObjectAttribute->mnRefCount--;
172             }
173             else
174             {
175                 delete mpSdr3DObjectAttribute;
176             }
177         }
178 
isDefault() const179         bool Sdr3DObjectAttribute::isDefault() const
180         {
181             return mpSdr3DObjectAttribute == ImpSdr3DObjectAttribute::get_global_default();
182         }
183 
operator =(const Sdr3DObjectAttribute & rCandidate)184         Sdr3DObjectAttribute& Sdr3DObjectAttribute::operator=(const Sdr3DObjectAttribute& rCandidate)
185         {
186             if(rCandidate.mpSdr3DObjectAttribute != mpSdr3DObjectAttribute)
187             {
188                 if(mpSdr3DObjectAttribute->mnRefCount)
189                 {
190                     mpSdr3DObjectAttribute->mnRefCount--;
191                 }
192                 else
193                 {
194                     delete mpSdr3DObjectAttribute;
195                 }
196 
197                 mpSdr3DObjectAttribute = rCandidate.mpSdr3DObjectAttribute;
198                 mpSdr3DObjectAttribute->mnRefCount++;
199             }
200 
201             return *this;
202         }
203 
operator ==(const Sdr3DObjectAttribute & rCandidate) const204         bool Sdr3DObjectAttribute::operator==(const Sdr3DObjectAttribute& rCandidate) const
205         {
206             if(rCandidate.mpSdr3DObjectAttribute == mpSdr3DObjectAttribute)
207             {
208                 return true;
209             }
210 
211             if(rCandidate.isDefault() != isDefault())
212             {
213                 return false;
214             }
215 
216             return (*rCandidate.mpSdr3DObjectAttribute == *mpSdr3DObjectAttribute);
217         }
218 
getNormalsKind() const219         ::com::sun::star::drawing::NormalsKind Sdr3DObjectAttribute::getNormalsKind() const
220         {
221             return mpSdr3DObjectAttribute->getNormalsKind();
222         }
223 
getTextureProjectionX() const224         ::com::sun::star::drawing::TextureProjectionMode Sdr3DObjectAttribute::getTextureProjectionX() const
225         {
226             return mpSdr3DObjectAttribute->getTextureProjectionX();
227         }
228 
getTextureProjectionY() const229         ::com::sun::star::drawing::TextureProjectionMode Sdr3DObjectAttribute::getTextureProjectionY() const
230         {
231             return mpSdr3DObjectAttribute->getTextureProjectionY();
232         }
233 
getTextureKind() const234         ::com::sun::star::drawing::TextureKind2 Sdr3DObjectAttribute::getTextureKind() const
235         {
236             return mpSdr3DObjectAttribute->getTextureKind();
237         }
238 
getTextureMode() const239         ::com::sun::star::drawing::TextureMode Sdr3DObjectAttribute::getTextureMode() const
240         {
241             return mpSdr3DObjectAttribute->getTextureMode();
242         }
243 
getMaterial() const244         const MaterialAttribute3D& Sdr3DObjectAttribute::getMaterial() const
245         {
246             return mpSdr3DObjectAttribute->getMaterial();
247         }
248 
getNormalsInvert() const249         bool Sdr3DObjectAttribute::getNormalsInvert() const
250         {
251             return mpSdr3DObjectAttribute->getNormalsInvert();
252         }
253 
getDoubleSided() const254         bool Sdr3DObjectAttribute::getDoubleSided() const
255         {
256             return mpSdr3DObjectAttribute->getDoubleSided();
257         }
258 
getShadow3D() const259         bool Sdr3DObjectAttribute::getShadow3D() const
260         {
261             return mpSdr3DObjectAttribute->getShadow3D();
262         }
263 
getTextureFilter() const264         bool Sdr3DObjectAttribute::getTextureFilter() const
265         {
266             return mpSdr3DObjectAttribute->getTextureFilter();
267         }
268 
getReducedLineGeometry() const269         bool Sdr3DObjectAttribute::getReducedLineGeometry() const
270         {
271             return mpSdr3DObjectAttribute->getReducedLineGeometry();
272         }
273 
274     } // end of namespace attribute
275 } // end of namespace drawinglayer
276 
277 //////////////////////////////////////////////////////////////////////////////
278 // eof
279