1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
30 #include <basegfx/polygon/b3dpolygon.hxx>
31 #include <drawinglayer/attribute/strokeattribute.hxx>
32 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
33 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
34 #include <basegfx/polygon/b3dpolypolygon.hxx>
35 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
36 #include <vcl/vclenum.hxx>
37 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
38 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
39 #include <vcl/bmpacc.hxx>
40 #include <basegfx/polygon/b3dpolypolygontools.hxx>
41 #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
42 #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
43 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
44 #include <drawinglayer/primitive3d/shadowprimitive3d.hxx>
45 #include <basegfx/range/b2drange.hxx>
46 #include <drawinglayer/attribute/sdrlineattribute.hxx>
47 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
48 #include <drawinglayer/attribute/sdrfillattribute.hxx>
49 #include <drawinglayer/attribute/sdrshadowattribute.hxx>
50 #include <drawinglayer/primitive3d/hiddengeometryprimitive3d.hxx>
52 //////////////////////////////////////////////////////////////////////////////
54 namespace drawinglayer
58 basegfx::B3DRange
getRangeFrom3DGeometry(::std::vector
< basegfx::B3DPolyPolygon
>& rFill
)
60 basegfx::B3DRange aRetval
;
62 for(sal_uInt32
a(0); a
< rFill
.size(); a
++)
64 aRetval
.expand(basegfx::tools::getRange(rFill
[a
]));
70 void applyNormalsKindSphereTo3DGeometry(::std::vector
< basegfx::B3DPolyPolygon
>& rFill
, const basegfx::B3DRange
& rRange
)
72 // create sphere normals
73 const basegfx::B3DPoint
aCenter(rRange
.getCenter());
75 for(sal_uInt32
a(0); a
< rFill
.size(); a
++)
77 rFill
[a
] = basegfx::tools::applyDefaultNormalsSphere(rFill
[a
], aCenter
);
81 void applyNormalsKindFlatTo3DGeometry(::std::vector
< basegfx::B3DPolyPolygon
>& rFill
)
83 for(sal_uInt32
a(0); a
< rFill
.size(); a
++)
85 rFill
[a
].clearNormals();
89 void applyNormalsInvertTo3DGeometry(::std::vector
< basegfx::B3DPolyPolygon
>& rFill
)
92 for(sal_uInt32
a(0); a
< rFill
.size(); a
++)
94 rFill
[a
] = basegfx::tools::invertNormals(rFill
[a
]);
98 void applyTextureTo3DGeometry(
99 ::com::sun::star::drawing::TextureProjectionMode eModeX
,
100 ::com::sun::star::drawing::TextureProjectionMode eModeY
,
101 ::std::vector
< basegfx::B3DPolyPolygon
>& rFill
,
102 const basegfx::B3DRange
& rRange
,
103 const basegfx::B2DVector
& rTextureSize
)
107 // handle texture coordinates X
108 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== eModeX
);
109 const bool bSphereX(!bParallelX
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== eModeX
));
111 // handle texture coordinates Y
112 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== eModeY
);
113 const bool bSphereY(!bParallelY
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== eModeY
));
115 if(bParallelX
|| bParallelY
)
117 // apply parallel texture coordinates in X and/or Y
118 for(a
= 0; a
< rFill
.size(); a
++)
120 rFill
[a
] = basegfx::tools::applyDefaultTextureCoordinatesParallel(rFill
[a
], rRange
, bParallelX
, bParallelY
);
124 if(bSphereX
|| bSphereY
)
126 // apply spherical texture coordinates in X and/or Y
127 const basegfx::B3DPoint
aCenter(rRange
.getCenter());
129 for(a
= 0; a
< rFill
.size(); a
++)
131 rFill
[a
] = basegfx::tools::applyDefaultTextureCoordinatesSphere(rFill
[a
], aCenter
, bSphereX
, bSphereY
);
135 // transform texture coordinates to texture size
136 basegfx::B2DHomMatrix aTexMatrix
;
137 aTexMatrix
.scale(rTextureSize
.getX(), rTextureSize
.getY());
139 for(a
= 0; a
< rFill
.size(); a
++)
141 rFill
[a
].transformTextureCoordiantes(aTexMatrix
);
145 Primitive3DSequence
create3DPolyPolygonLinePrimitives(
146 const basegfx::B3DPolyPolygon
& rUnitPolyPolygon
,
147 const basegfx::B3DHomMatrix
& rObjectTransform
,
148 const attribute::SdrLineAttribute
& rLine
)
150 // prepare fully scaled polyPolygon
151 basegfx::B3DPolyPolygon
aScaledPolyPolygon(rUnitPolyPolygon
);
152 aScaledPolyPolygon
.transform(rObjectTransform
);
154 // create line and stroke attribute
155 const attribute::LineAttribute
aLineAttribute(rLine
.getColor(), rLine
.getWidth(), rLine
.getJoin());
156 const attribute::StrokeAttribute
aStrokeAttribute(rLine
.getDotDashArray(), rLine
.getFullDotDashLen());
159 Primitive3DSequence
aRetval(aScaledPolyPolygon
.count());
161 for(sal_uInt32
a(0L); a
< aScaledPolyPolygon
.count(); a
++)
163 const Primitive3DReference
xRef(new PolygonStrokePrimitive3D(aScaledPolyPolygon
.getB3DPolygon(a
), aLineAttribute
, aStrokeAttribute
));
167 if(0.0 != rLine
.getTransparence())
169 // create UnifiedTransparenceTexturePrimitive3D, add created primitives and exchange
170 const Primitive3DReference
xRef(new UnifiedTransparenceTexturePrimitive3D(rLine
.getTransparence(), aRetval
));
171 aRetval
= Primitive3DSequence(&xRef
, 1L);
177 Primitive3DSequence
create3DPolyPolygonFillPrimitives(
178 const ::std::vector
< basegfx::B3DPolyPolygon
>& r3DPolyPolygonVector
,
179 const basegfx::B3DHomMatrix
& rObjectTransform
,
180 const basegfx::B2DVector
& rTextureSize
,
181 const attribute::Sdr3DObjectAttribute
& aSdr3DObjectAttribute
,
182 const attribute::SdrFillAttribute
& rFill
,
183 const attribute::FillGradientAttribute
& rFillGradient
)
185 Primitive3DSequence aRetval
;
187 if(r3DPolyPolygonVector
.size())
189 // create list of simple fill primitives
190 aRetval
.realloc(r3DPolyPolygonVector
.size());
192 for(sal_uInt32
a(0L); a
< r3DPolyPolygonVector
.size(); a
++)
194 // get scaled PolyPolygon
195 basegfx::B3DPolyPolygon
aScaledPolyPolygon(r3DPolyPolygonVector
[a
]);
196 aScaledPolyPolygon
.transform(rObjectTransform
);
198 if(aScaledPolyPolygon
.areNormalsUsed())
200 aScaledPolyPolygon
.transformNormals(rObjectTransform
);
203 const Primitive3DReference
xRef(new PolyPolygonMaterialPrimitive3D(
205 aSdr3DObjectAttribute
.getMaterial(),
206 aSdr3DObjectAttribute
.getDoubleSided()));
210 // look for and evtl. build texture sub-group primitive
211 if(!rFill
.getGradient().isDefault()
212 || !rFill
.getHatch().isDefault()
213 || !rFill
.getBitmap().isDefault())
215 bool bModulate(::com::sun::star::drawing::TextureMode_MODULATE
== aSdr3DObjectAttribute
.getTextureMode());
216 bool bFilter(aSdr3DObjectAttribute
.getTextureFilter());
217 BasePrimitive3D
* pNewTexturePrimitive3D
= 0;
219 if(!rFill
.getGradient().isDefault())
221 // create gradientTexture3D with sublist, add to local aRetval
222 pNewTexturePrimitive3D
= new GradientTexturePrimitive3D(
229 else if(!rFill
.getHatch().isDefault())
231 // create hatchTexture3D with sublist, add to local aRetval
232 pNewTexturePrimitive3D
= new HatchTexturePrimitive3D(
239 else // if(!rFill.getBitmap().isDefault())
241 // create bitmapTexture3D with sublist, add to local aRetval
242 basegfx::B2DRange
aTexRange(0.0, 0.0, rTextureSize
.getX(), rTextureSize
.getY());
244 pNewTexturePrimitive3D
= new BitmapTexturePrimitive3D(
245 rFill
.getBitmap().getFillBitmapAttribute(aTexRange
),
252 // exchange aRetval content with texture group
253 const Primitive3DReference
xRef(pNewTexturePrimitive3D
);
254 aRetval
= Primitive3DSequence(&xRef
, 1L);
256 if(::com::sun::star::drawing::TextureKind2_LUMINANCE
== aSdr3DObjectAttribute
.getTextureKind())
258 // use modified color primitive to force textures to gray
259 const basegfx::BColorModifier
aBColorModifier(basegfx::BColor(), 0.0, basegfx::BCOLORMODIFYMODE_GRAY
);
260 const Primitive3DReference
xRef2(new ModifiedColorPrimitive3D(aRetval
, aBColorModifier
));
261 aRetval
= Primitive3DSequence(&xRef2
, 1L);
265 if(0.0 != rFill
.getTransparence())
267 // create UnifiedTransparenceTexturePrimitive3D with sublist and exchange
268 const Primitive3DReference
xRef(new UnifiedTransparenceTexturePrimitive3D(rFill
.getTransparence(), aRetval
));
269 aRetval
= Primitive3DSequence(&xRef
, 1L);
271 else if(!rFillGradient
.isDefault())
273 // create TransparenceTexturePrimitive3D with sublist and exchange
274 const Primitive3DReference
xRef(new TransparenceTexturePrimitive3D(rFillGradient
, aRetval
, rTextureSize
));
275 aRetval
= Primitive3DSequence(&xRef
, 1L);
282 Primitive3DSequence
createShadowPrimitive3D(
283 const Primitive3DSequence
& rSource
,
284 const attribute::SdrShadowAttribute
& rShadow
,
287 // create Shadow primitives. Uses already created primitives
288 if(rSource
.hasElements() && !basegfx::fTools::moreOrEqual(rShadow
.getTransparence(), 1.0))
290 // prepare new list for shadow geometry
291 basegfx::B2DHomMatrix aShadowOffset
;
292 aShadowOffset
.set(0, 2, rShadow
.getOffset().getX());
293 aShadowOffset
.set(1, 2, rShadow
.getOffset().getY());
295 // create shadow primitive and add primitives
296 const Primitive3DReference
xRef(new ShadowPrimitive3D(aShadowOffset
, rShadow
.getColor(), rShadow
.getTransparence(), bShadow3D
, rSource
));
297 return Primitive3DSequence(&xRef
, 1L);
301 return Primitive3DSequence();
305 Primitive3DSequence
createHiddenGeometryPrimitives3D(
306 const ::std::vector
< basegfx::B3DPolyPolygon
>& r3DPolyPolygonVector
,
307 const basegfx::B3DHomMatrix
& rObjectTransform
,
308 const basegfx::B2DVector
& rTextureSize
,
309 const attribute::Sdr3DObjectAttribute
& aSdr3DObjectAttribute
)
311 // create hidden sub-geometry which can be used for HitTest
312 // and BoundRect calculations, but will not be visualized
313 const attribute::SdrFillAttribute
aSimplifiedFillAttribute(
316 attribute::FillGradientAttribute(),
317 attribute::FillHatchAttribute(),
318 attribute::SdrFillBitmapAttribute());
320 const Primitive3DReference
aHidden(
321 new HiddenGeometryPrimitive3D(
322 create3DPolyPolygonFillPrimitives(
323 r3DPolyPolygonVector
,
326 aSdr3DObjectAttribute
,
327 aSimplifiedFillAttribute
,
328 attribute::FillGradientAttribute())));
330 return Primitive3DSequence(&aHidden
, 1);
333 } // end of namespace primitive3d
334 } // end of namespace drawinglayer
336 //////////////////////////////////////////////////////////////////////////////
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */