merge the formfield patch from ooo-build
[ooovba.git] / drawinglayer / source / primitive3d / sdrdecompositiontools3d.cxx
blobdf15cc8a3cc7273da8ba56baa76afa9e35efc926
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: sdrdecompositiontools3d.cxx,v $
7 * $Revision: 1.7 $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:21 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
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
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.
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.
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
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
40 #include <basegfx/polygon/b3dpolygon.hxx>
41 #include <drawinglayer/attribute/strokeattribute.hxx>
42 #include <drawinglayer/attribute/sdrattribute.hxx>
43 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
44 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
45 #include <basegfx/polygon/b3dpolypolygon.hxx>
46 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
47 #include <drawinglayer/attribute/sdrattribute.hxx>
48 #include <vcl/vclenum.hxx>
49 #include <drawinglayer/attribute/fillattribute.hxx>
50 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
51 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
52 #include <vcl/bmpacc.hxx>
53 #include <basegfx/polygon/b3dpolypolygontools.hxx>
54 #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
55 #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
56 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
57 #include <drawinglayer/primitive3d/shadowprimitive3d.hxx>
58 #include <drawinglayer/attribute/sdrattribute3d.hxx>
59 #include <basegfx/range/b2drange.hxx>
61 //////////////////////////////////////////////////////////////////////////////
63 namespace drawinglayer
65 namespace primitive3d
67 basegfx::B3DRange getRangeFrom3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
69 basegfx::B3DRange aRetval;
71 for(sal_uInt32 a(0); a < rFill.size(); a++)
73 aRetval.expand(basegfx::tools::getRange(rFill[a]));
76 return aRetval;
79 void applyNormalsKindSphereTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill, const basegfx::B3DRange& rRange)
81 // create sphere normals
82 const basegfx::B3DPoint aCenter(rRange.getCenter());
84 for(sal_uInt32 a(0); a < rFill.size(); a++)
86 rFill[a] = basegfx::tools::applyDefaultNormalsSphere(rFill[a], aCenter);
90 void applyNormalsKindFlatTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
92 for(sal_uInt32 a(0); a < rFill.size(); a++)
94 rFill[a].clearNormals();
98 void applyNormalsInvertTo3DGeometry(::std::vector< basegfx::B3DPolyPolygon >& rFill)
100 // invert normals
101 for(sal_uInt32 a(0); a < rFill.size(); a++)
103 rFill[a] = basegfx::tools::invertNormals(rFill[a]);
107 void applyTextureTo3DGeometry(
108 ::com::sun::star::drawing::TextureProjectionMode eModeX,
109 ::com::sun::star::drawing::TextureProjectionMode eModeY,
110 ::std::vector< basegfx::B3DPolyPolygon >& rFill,
111 const basegfx::B3DRange& rRange,
112 const basegfx::B2DVector& rTextureSize)
114 sal_uInt32 a;
116 // handle texture coordinates X
117 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == eModeX);
118 const bool bSphereX(!bParallelX && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == eModeX));
120 // handle texture coordinates Y
121 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == eModeY);
122 const bool bSphereY(!bParallelY && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == eModeY));
124 if(bParallelX || bParallelY)
126 // apply parallel texture coordinates in X and/or Y
127 for(a = 0; a < rFill.size(); a++)
129 rFill[a] = basegfx::tools::applyDefaultTextureCoordinatesParallel(rFill[a], rRange, bParallelX, bParallelY);
133 if(bSphereX || bSphereY)
135 // apply spherical texture coordinates in X and/or Y
136 const basegfx::B3DPoint aCenter(rRange.getCenter());
138 for(a = 0; a < rFill.size(); a++)
140 rFill[a] = basegfx::tools::applyDefaultTextureCoordinatesSphere(rFill[a], aCenter, bSphereX, bSphereY);
144 // transform texture coordinates to texture size
145 basegfx::B2DHomMatrix aTexMatrix;
146 aTexMatrix.scale(rTextureSize.getX(), rTextureSize.getY());
148 for(a = 0; a < rFill.size(); a++)
150 rFill[a].transformTextureCoordiantes(aTexMatrix);
154 Primitive3DSequence create3DPolyPolygonLinePrimitives(
155 const basegfx::B3DPolyPolygon& rUnitPolyPolygon,
156 const basegfx::B3DHomMatrix& rObjectTransform,
157 const attribute::SdrLineAttribute& rLine)
159 // prepare fully scaled polyPolygon
160 basegfx::B3DPolyPolygon aScaledPolyPolygon(rUnitPolyPolygon);
161 aScaledPolyPolygon.transform(rObjectTransform);
163 // create line and stroke attribute
164 const attribute::LineAttribute aLineAttribute(rLine.getColor(), rLine.getWidth(), rLine.getJoin());
165 const attribute::StrokeAttribute aStrokeAttribute(rLine.getDotDashArray(), rLine.getFullDotDashLen());
167 // create primitives
168 Primitive3DSequence aRetval(aScaledPolyPolygon.count());
170 for(sal_uInt32 a(0L); a < aScaledPolyPolygon.count(); a++)
172 const Primitive3DReference xRef(new PolygonStrokePrimitive3D(aScaledPolyPolygon.getB3DPolygon(a), aLineAttribute, aStrokeAttribute));
173 aRetval[a] = xRef;
176 if(0.0 != rLine.getTransparence())
178 // create UnifiedAlphaTexturePrimitive3D, add created primitives and exchange
179 const Primitive3DReference xRef(new UnifiedAlphaTexturePrimitive3D(rLine.getTransparence(), aRetval));
180 aRetval = Primitive3DSequence(&xRef, 1L);
183 return aRetval;
186 Primitive3DSequence create3DPolyPolygonFillPrimitives(
187 const ::std::vector< basegfx::B3DPolyPolygon >& r3DPolyPolygonVector,
188 const basegfx::B3DHomMatrix& rObjectTransform,
189 const basegfx::B2DVector& rTextureSize,
190 const attribute::Sdr3DObjectAttribute& aSdr3DObjectAttribute,
191 const attribute::SdrFillAttribute& rFill,
192 const attribute::FillGradientAttribute* pFillGradient)
194 Primitive3DSequence aRetval;
196 if(r3DPolyPolygonVector.size())
198 // create list of simple fill primitives
199 aRetval.realloc(r3DPolyPolygonVector.size());
201 for(sal_uInt32 a(0L); a < r3DPolyPolygonVector.size(); a++)
203 // get scaled PolyPolygon
204 basegfx::B3DPolyPolygon aScaledPolyPolygon(r3DPolyPolygonVector[a]);
205 aScaledPolyPolygon.transform(rObjectTransform);
207 if(aScaledPolyPolygon.areNormalsUsed())
209 aScaledPolyPolygon.transformNormals(rObjectTransform);
212 const Primitive3DReference xRef(new PolyPolygonMaterialPrimitive3D(
213 aScaledPolyPolygon,
214 aSdr3DObjectAttribute.getMaterial(),
215 aSdr3DObjectAttribute.getDoubleSided()));
216 aRetval[a] = xRef;
219 // look for and evtl. build texture sub-group primitive
220 if(rFill.isGradient() || rFill.isHatch() || rFill.isBitmap())
222 bool bModulate(::com::sun::star::drawing::TextureMode_MODULATE == aSdr3DObjectAttribute.getTextureMode());
223 bool bFilter(aSdr3DObjectAttribute.getTextureFilter());
224 BasePrimitive3D* pNewTexturePrimitive3D = 0L;
226 if(rFill.isGradient())
228 // create gradientTexture3D with sublist, add to local aRetval
229 pNewTexturePrimitive3D = new GradientTexturePrimitive3D(*rFill.getGradient(), aRetval, rTextureSize, bModulate, bFilter);
231 else if(rFill.isHatch())
233 // create hatchTexture3D with sublist, add to local aRetval
234 pNewTexturePrimitive3D = new HatchTexturePrimitive3D(*rFill.getHatch(), aRetval, rTextureSize, bModulate, bFilter);
236 else // if(rFill.isBitmap())
238 // create bitmapTexture3D with sublist, add to local aRetval
239 basegfx::B2DRange aTexRange(0.0, 0.0, rTextureSize.getX(), rTextureSize.getY());
240 pNewTexturePrimitive3D = new BitmapTexturePrimitive3D(rFill.getBitmap()->getFillBitmapAttribute(aTexRange), aRetval, rTextureSize, bModulate, bFilter);
243 // exchange aRetval content with texture group
244 const Primitive3DReference xRef(pNewTexturePrimitive3D);
245 aRetval = Primitive3DSequence(&xRef, 1L);
247 if(::com::sun::star::drawing::TextureKind2_LUMINANCE == aSdr3DObjectAttribute.getTextureKind())
249 // use modified color primitive to force textures to gray
250 const basegfx::BColorModifier aBColorModifier(basegfx::BColor(), 0.0, basegfx::BCOLORMODIFYMODE_GRAY);
251 const Primitive3DReference xRef2(new ModifiedColorPrimitive3D(aRetval, aBColorModifier));
252 aRetval = Primitive3DSequence(&xRef2, 1L);
256 if(0.0 != rFill.getTransparence())
258 // create UnifiedAlphaTexturePrimitive3D with sublist and exchange
259 const Primitive3DReference xRef(new UnifiedAlphaTexturePrimitive3D(rFill.getTransparence(), aRetval));
260 aRetval = Primitive3DSequence(&xRef, 1L);
262 else if(pFillGradient)
264 // create AlphaTexturePrimitive3D with sublist and exchange
265 const Primitive3DReference xRef(new AlphaTexturePrimitive3D(*pFillGradient, aRetval, rTextureSize));
266 aRetval = Primitive3DSequence(&xRef, 1L);
270 return aRetval;
273 Primitive3DSequence createShadowPrimitive3D(
274 const Primitive3DSequence& rSource,
275 const attribute::SdrShadowAttribute& rShadow,
276 bool bShadow3D)
278 // create Shadow primitives. Uses already created primitives
279 if(rSource.hasElements() && !basegfx::fTools::moreOrEqual(rShadow.getTransparence(), 1.0))
281 // prepare new list for shadow geometry
282 basegfx::B2DHomMatrix aShadowOffset;
283 aShadowOffset.set(0, 2, rShadow.getOffset().getX());
284 aShadowOffset.set(1, 2, rShadow.getOffset().getY());
286 // create shadow primitive and add primitives
287 const Primitive3DReference xRef(new ShadowPrimitive3D(aShadowOffset, rShadow.getColor(), rShadow.getTransparence(), bShadow3D, rSource));
288 return Primitive3DSequence(&xRef, 1L);
290 else
292 return Primitive3DSequence();
295 } // end of namespace primitive3d
296 } // end of namespace drawinglayer
298 //////////////////////////////////////////////////////////////////////////////
299 // eof