1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
29 #include <svx/svx3ditems.hxx>
30 #include <svl/itemset.hxx>
31 #include <com/sun/star/drawing/NormalsKind.hpp>
32 #include <com/sun/star/drawing/TextureProjectionMode.hpp>
33 #include <com/sun/star/drawing/TextureKind2.hpp>
34 #include <com/sun/star/drawing/TextureMode.hpp>
35 #include <svx/xflclit.hxx>
36 #include <drawinglayer/attribute/materialattribute3d.hxx>
37 #include <drawinglayer/attribute/sdrobjectattribute3d.hxx>
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 namespace drawinglayer
42 {
43 	namespace primitive2d
44 	{
45 		attribute::Sdr3DObjectAttribute* createNewSdr3DObjectAttribute(const SfxItemSet& rSet)
46 		{
47 			// get NormalsKind
48 			::com::sun::star::drawing::NormalsKind aNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC);
49 			const sal_uInt16 nNormalsValue(((const Svx3DNormalsKindItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_KIND)).GetValue());
50 
51 			if(1L == nNormalsValue)
52 			{
53 				aNormalsKind = ::com::sun::star::drawing::NormalsKind_FLAT;
54 			}
55 			else if(2L == nNormalsValue)
56 			{
57 				aNormalsKind = ::com::sun::star::drawing::NormalsKind_SPHERE;
58 			}
59 
60 			// get NoermalsInvert flag
61 			const bool bInvertNormals(((const Svx3DNormalsInvertItem&)rSet.Get(SDRATTR_3DOBJ_NORMALS_INVERT)).GetValue());
62 
63 			// get TextureProjectionX
64 			::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
65 			const sal_uInt16 nTextureValueX(((const Svx3DTextureProjectionXItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_X)).GetValue());
66 
67 			if(1L == nTextureValueX)
68 			{
69 				aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
70 			}
71 			else if(2L == nTextureValueX)
72 			{
73 				aTextureProjectionX = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
74 			}
75 
76 			// get TextureProjectionY
77 			::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC);
78 			const sal_uInt16 nTextureValueY(((const Svx3DTextureProjectionYItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_PROJ_Y)).GetValue());
79 
80 			if(1L == nTextureValueY)
81 			{
82 				aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_PARALLEL;
83 			}
84 			else if(2L == nTextureValueY)
85 			{
86 				aTextureProjectionY = ::com::sun::star::drawing::TextureProjectionMode_SPHERE;
87 			}
88 
89 			// get DoubleSided flag
90 			const bool bDoubleSided(((const Svx3DDoubleSidedItem&)rSet.Get(SDRATTR_3DOBJ_DOUBLE_SIDED)).GetValue());
91 
92 			// get Shadow3D flag
93 			const bool bShadow3D(((const Svx3DShadow3DItem&)rSet.Get(SDRATTR_3DOBJ_SHADOW_3D)).GetValue());
94 
95 			// get TextureFilter flag
96 			const bool bTextureFilter(((const Svx3DTextureFilterItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_FILTER)).GetValue());
97 
98 			// get texture kind
99 			// TextureKind: 1 == Base3DTextureLuminance, 2 == Base3DTextureIntensity, 3 == Base3DTextureColor
100 			::com::sun::star::drawing::TextureKind2 aTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE);
101 			const sal_uInt16 nTextureKind(((const Svx3DTextureKindItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_KIND)).GetValue());
102 
103 			if(2 == nTextureKind)
104 			{
105 				aTextureKind = ::com::sun::star::drawing::TextureKind2_INTENSITY;
106 			}
107 			else if(3 == nTextureKind)
108 			{
109 				aTextureKind = ::com::sun::star::drawing::TextureKind2_COLOR;
110 			}
111 
112 			// get texture mode
113 			// TextureMode: 1 == Base3DTextureReplace, 2 == Base3DTextureModulate, 3 == Base3DTextureBlend
114 			::com::sun::star::drawing::TextureMode aTextureMode(::com::sun::star::drawing::TextureMode_REPLACE);
115 			const sal_uInt16 nTextureMode(((const Svx3DTextureModeItem&)rSet.Get(SDRATTR_3DOBJ_TEXTURE_MODE)).GetValue());
116 
117 			if(2 == nTextureMode)
118 			{
119 				aTextureMode = ::com::sun::star::drawing::TextureMode_MODULATE;
120 			}
121 			else if(3 == nTextureMode)
122 			{
123 				aTextureMode = ::com::sun::star::drawing::TextureMode_BLEND;
124 			}
125 
126 			// get object color
127 			const ::basegfx::BColor aObjectColor(((const XFillColorItem&)rSet.Get(XATTR_FILLCOLOR)).GetColorValue().getBColor());
128 
129 			// get specular color
130 			const ::basegfx::BColor aSpecular(((const Svx3DMaterialSpecularItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR)).GetValue().getBColor());
131 
132 			// get emissive color
133 			const ::basegfx::BColor aEmission(((const Svx3DMaterialEmissionItem&)rSet.Get(SDRATTR_3DOBJ_MAT_EMISSION)).GetValue().getBColor());
134 
135 			// get specular intensity
136 			sal_uInt16 nSpecularIntensity(((const Svx3DMaterialSpecularIntensityItem&)rSet.Get(SDRATTR_3DOBJ_MAT_SPECULAR_INTENSITY)).GetValue());
137 
138 			if(nSpecularIntensity > 128)
139 			{
140 				nSpecularIntensity = 128;
141 			}
142 
143 			// get reduced line geometry
144 			const bool bReducedLineGeometry(((const Svx3DReducedLineGeometryItem&)rSet.Get(SDRATTR_3DOBJ_REDUCED_LINE_GEOMETRY)).GetValue());
145 
146 			// prepare material
147 			attribute::MaterialAttribute3D aMaterial(aObjectColor, aSpecular, aEmission, nSpecularIntensity);
148 
149 			return new attribute::Sdr3DObjectAttribute(
150 				aNormalsKind, aTextureProjectionX, aTextureProjectionY,
151 				aTextureKind, aTextureMode, aMaterial,
152 				bInvertNormals, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry);
153 		}
154 	} // end of namespace primitive2d
155 } // end of namespace sdr
156 
157 //////////////////////////////////////////////////////////////////////////////
158 // eof
159