1 /************************************************************************* 2 * 3 * OpenOffice.org - a multi-platform office productivity suite 4 * 5 * $RCSfile: sdrattribute3d.cxx,v $ 6 * 7 * $Revision: 1.5 $ 8 * 9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $ 10 * 11 * The Contents of this file are made available subject to 12 * the terms of GNU Lesser General Public License Version 2.1. 13 * 14 * 15 * GNU Lesser General Public License Version 2.1 16 * ============================================= 17 * Copyright 2005 by Sun Microsystems, Inc. 18 * 901 San Antonio Road, Palo Alto, CA 94303, USA 19 * 20 * This library is free software; you can redistribute it and/or 21 * modify it under the terms of the GNU Lesser General Public 22 * License version 2.1, as published by the Free Software Foundation. 23 * 24 * This library is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 * Lesser General Public License for more details. 28 * 29 * You should have received a copy of the GNU Lesser General Public 30 * License along with this library; if not, write to the Free Software 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 32 * MA 02111-1307 USA 33 * 34 ************************************************************************/ 35 36 // MARKER(update_precomp.py): autogen include statement, do not remove 37 #include "precompiled_drawinglayer.hxx" 38 39 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx> 40 #include <drawinglayer/attribute/materialattribute3d.hxx> 41 42 ////////////////////////////////////////////////////////////////////////////// 43 44 namespace drawinglayer 45 { 46 namespace attribute 47 { 48 class ImpSdr3DObjectAttribute 49 { 50 public: 51 // refcounter 52 sal_uInt32 mnRefCount; 53 54 // 3D object attribute definitions 55 ::com::sun::star::drawing::NormalsKind maNormalsKind; // normals type (0..2) 56 ::com::sun::star::drawing::TextureProjectionMode maTextureProjectionX; // texture projection type X (0..2) 57 ::com::sun::star::drawing::TextureProjectionMode maTextureProjectionY; // texture projection type Y (0..2) 58 ::com::sun::star::drawing::TextureKind2 maTextureKind; // texture kind (see uno API) 59 ::com::sun::star::drawing::TextureMode maTextureMode; // texture kind (see uno API) 60 MaterialAttribute3D maMaterial; // object, specular and emissive colors, SpecularIntensity 61 62 // bitfield 63 unsigned mbNormalsInvert : 1; // invert normals 64 unsigned mbDoubleSided : 1; // surfaces are double sided 65 unsigned mbShadow3D : 1; // display shadow in 3D (if on), params for that are at scene 66 unsigned mbTextureFilter : 1; // filter texture to make more smooth 67 unsigned mbReducedLineGeometry : 1; // use reduced line geometry (object specific) 68 69 ImpSdr3DObjectAttribute( 70 ::com::sun::star::drawing::NormalsKind aNormalsKind, 71 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX, 72 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY, 73 ::com::sun::star::drawing::TextureKind2 aTextureKind, 74 ::com::sun::star::drawing::TextureMode aTextureMode, 75 const MaterialAttribute3D& rMaterial, 76 bool bNormalsInvert, 77 bool bDoubleSided, 78 bool bShadow3D, 79 bool bTextureFilter, 80 bool bReducedLineGeometry) 81 : mnRefCount(0), 82 maNormalsKind(aNormalsKind), 83 maTextureProjectionX(aTextureProjectionX), 84 maTextureProjectionY(aTextureProjectionY), 85 maTextureKind(aTextureKind), 86 maTextureMode(aTextureMode), 87 maMaterial(rMaterial), 88 mbNormalsInvert(bNormalsInvert), 89 mbDoubleSided(bDoubleSided), 90 mbShadow3D(bShadow3D), 91 mbTextureFilter(bTextureFilter), 92 mbReducedLineGeometry(bReducedLineGeometry) 93 { 94 } 95 96 // data read access 97 ::com::sun::star::drawing::NormalsKind getNormalsKind() const { return maNormalsKind; } 98 ::com::sun::star::drawing::TextureProjectionMode getTextureProjectionX() const { return maTextureProjectionX; } 99 ::com::sun::star::drawing::TextureProjectionMode getTextureProjectionY() const { return maTextureProjectionY; } 100 ::com::sun::star::drawing::TextureKind2 getTextureKind() const { return maTextureKind; } 101 ::com::sun::star::drawing::TextureMode getTextureMode() const { return maTextureMode; } 102 const MaterialAttribute3D& getMaterial() const { return maMaterial; } 103 bool getNormalsInvert() const { return mbNormalsInvert; } 104 bool getDoubleSided() const { return mbDoubleSided; } 105 bool getShadow3D() const { return mbShadow3D; } 106 bool getTextureFilter() const { return mbTextureFilter; } 107 bool getReducedLineGeometry() const { return mbReducedLineGeometry; } 108 109 bool operator==(const ImpSdr3DObjectAttribute& rCandidate) const 110 { 111 return (getNormalsKind() == rCandidate.getNormalsKind() 112 && getTextureProjectionX() == rCandidate.getTextureProjectionX() 113 && getTextureProjectionY() == rCandidate.getTextureProjectionY() 114 && getTextureKind() == rCandidate.getTextureKind() 115 && getTextureMode() == rCandidate.getTextureMode() 116 && getMaterial() == rCandidate.getMaterial() 117 && getNormalsInvert() == rCandidate.getNormalsInvert() 118 && getDoubleSided() == rCandidate.getDoubleSided() 119 && getShadow3D() == rCandidate.getShadow3D() 120 && getTextureFilter() == rCandidate.getTextureFilter() 121 && getReducedLineGeometry() == rCandidate.getReducedLineGeometry()); 122 } 123 124 static ImpSdr3DObjectAttribute* get_global_default() 125 { 126 static ImpSdr3DObjectAttribute* pDefault = 0; 127 128 if(!pDefault) 129 { 130 pDefault = new ImpSdr3DObjectAttribute( 131 ::com::sun::star::drawing::NormalsKind_SPECIFIC, 132 ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC, 133 ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC, 134 ::com::sun::star::drawing::TextureKind2_LUMINANCE, 135 ::com::sun::star::drawing::TextureMode_REPLACE, 136 MaterialAttribute3D(), 137 false, 138 false, 139 false, 140 false, 141 false); 142 143 // never delete; start with RefCount 1, not 0 144 pDefault->mnRefCount++; 145 } 146 147 return pDefault; 148 } 149 }; 150 151 Sdr3DObjectAttribute::Sdr3DObjectAttribute( 152 ::com::sun::star::drawing::NormalsKind aNormalsKind, 153 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX, 154 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY, 155 ::com::sun::star::drawing::TextureKind2 aTextureKind, 156 ::com::sun::star::drawing::TextureMode aTextureMode, 157 const MaterialAttribute3D& rMaterial, 158 bool bNormalsInvert, 159 bool bDoubleSided, 160 bool bShadow3D, 161 bool bTextureFilter, 162 bool bReducedLineGeometry) 163 : mpSdr3DObjectAttribute(new ImpSdr3DObjectAttribute( 164 aNormalsKind, aTextureProjectionX, aTextureProjectionY, aTextureKind, aTextureMode, 165 rMaterial, bNormalsInvert, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry)) 166 { 167 } 168 169 Sdr3DObjectAttribute::Sdr3DObjectAttribute() 170 : mpSdr3DObjectAttribute(ImpSdr3DObjectAttribute::get_global_default()) 171 { 172 mpSdr3DObjectAttribute->mnRefCount++; 173 } 174 175 Sdr3DObjectAttribute::Sdr3DObjectAttribute(const Sdr3DObjectAttribute& rCandidate) 176 : mpSdr3DObjectAttribute(rCandidate.mpSdr3DObjectAttribute) 177 { 178 mpSdr3DObjectAttribute->mnRefCount++; 179 } 180 181 Sdr3DObjectAttribute::~Sdr3DObjectAttribute() 182 { 183 if(mpSdr3DObjectAttribute->mnRefCount) 184 { 185 mpSdr3DObjectAttribute->mnRefCount--; 186 } 187 else 188 { 189 delete mpSdr3DObjectAttribute; 190 } 191 } 192 193 bool Sdr3DObjectAttribute::isDefault() const 194 { 195 return mpSdr3DObjectAttribute == ImpSdr3DObjectAttribute::get_global_default(); 196 } 197 198 Sdr3DObjectAttribute& Sdr3DObjectAttribute::operator=(const Sdr3DObjectAttribute& rCandidate) 199 { 200 if(rCandidate.mpSdr3DObjectAttribute != mpSdr3DObjectAttribute) 201 { 202 if(mpSdr3DObjectAttribute->mnRefCount) 203 { 204 mpSdr3DObjectAttribute->mnRefCount--; 205 } 206 else 207 { 208 delete mpSdr3DObjectAttribute; 209 } 210 211 mpSdr3DObjectAttribute = rCandidate.mpSdr3DObjectAttribute; 212 mpSdr3DObjectAttribute->mnRefCount++; 213 } 214 215 return *this; 216 } 217 218 bool Sdr3DObjectAttribute::operator==(const Sdr3DObjectAttribute& rCandidate) const 219 { 220 if(rCandidate.mpSdr3DObjectAttribute == mpSdr3DObjectAttribute) 221 { 222 return true; 223 } 224 225 if(rCandidate.isDefault() != isDefault()) 226 { 227 return false; 228 } 229 230 return (*rCandidate.mpSdr3DObjectAttribute == *mpSdr3DObjectAttribute); 231 } 232 233 ::com::sun::star::drawing::NormalsKind Sdr3DObjectAttribute::getNormalsKind() const 234 { 235 return mpSdr3DObjectAttribute->getNormalsKind(); 236 } 237 238 ::com::sun::star::drawing::TextureProjectionMode Sdr3DObjectAttribute::getTextureProjectionX() const 239 { 240 return mpSdr3DObjectAttribute->getTextureProjectionX(); 241 } 242 243 ::com::sun::star::drawing::TextureProjectionMode Sdr3DObjectAttribute::getTextureProjectionY() const 244 { 245 return mpSdr3DObjectAttribute->getTextureProjectionY(); 246 } 247 248 ::com::sun::star::drawing::TextureKind2 Sdr3DObjectAttribute::getTextureKind() const 249 { 250 return mpSdr3DObjectAttribute->getTextureKind(); 251 } 252 253 ::com::sun::star::drawing::TextureMode Sdr3DObjectAttribute::getTextureMode() const 254 { 255 return mpSdr3DObjectAttribute->getTextureMode(); 256 } 257 258 const MaterialAttribute3D& Sdr3DObjectAttribute::getMaterial() const 259 { 260 return mpSdr3DObjectAttribute->getMaterial(); 261 } 262 263 bool Sdr3DObjectAttribute::getNormalsInvert() const 264 { 265 return mpSdr3DObjectAttribute->getNormalsInvert(); 266 } 267 268 bool Sdr3DObjectAttribute::getDoubleSided() const 269 { 270 return mpSdr3DObjectAttribute->getDoubleSided(); 271 } 272 273 bool Sdr3DObjectAttribute::getShadow3D() const 274 { 275 return mpSdr3DObjectAttribute->getShadow3D(); 276 } 277 278 bool Sdr3DObjectAttribute::getTextureFilter() const 279 { 280 return mpSdr3DObjectAttribute->getTextureFilter(); 281 } 282 283 bool Sdr3DObjectAttribute::getReducedLineGeometry() const 284 { 285 return mpSdr3DObjectAttribute->getReducedLineGeometry(); 286 } 287 288 } // end of namespace attribute 289 } // end of namespace drawinglayer 290 291 ////////////////////////////////////////////////////////////////////////////// 292 // eof 293