Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / tools / SceneProperties.cxx
blobeb65d81c94db7e86c37480e9907b8219ca516b4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <SceneProperties.hxx>
21 #include <ChartType.hxx>
22 #include <ChartTypeHelper.hxx>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <com/sun/star/drawing/HomogenMatrix.hpp>
25 #include <com/sun/star/drawing/ShadeMode.hpp>
26 #include <com/sun/star/drawing/Direction3D.hpp>
27 #include <com/sun/star/drawing/ProjectionMode.hpp>
28 #include <com/sun/star/drawing/CameraGeometry.hpp>
30 using namespace ::com::sun::star;
32 using ::com::sun::star::beans::Property;
34 namespace chart
37 void SceneProperties::AddPropertiesToVector(
38 std::vector< Property > & rOutProperties )
40 // transformation matrix
41 rOutProperties.emplace_back( "D3DTransformMatrix",
42 PROP_SCENE_TRANSF_MATRIX,
43 cppu::UnoType<drawing::HomogenMatrix>::get(),
44 beans::PropertyAttribute::BOUND
45 | beans::PropertyAttribute::MAYBEVOID
46 | beans::PropertyAttribute::MAYBEDEFAULT );
48 // distance: deprecated ( this is not used by the chart view; it's only here for compatibility with old chart )
49 rOutProperties.emplace_back( "D3DSceneDistance",
50 PROP_SCENE_DISTANCE,
51 cppu::UnoType<sal_Int32>::get(),
52 beans::PropertyAttribute::BOUND
53 | beans::PropertyAttribute::MAYBEVOID
54 | beans::PropertyAttribute::MAYBEDEFAULT );
56 // focalLength: deprecated ( this is not used by the chart view; it's only here for compatibility with old chart )
57 rOutProperties.emplace_back( "D3DSceneFocalLength",
58 PROP_SCENE_FOCAL_LENGTH,
59 cppu::UnoType<sal_Int32>::get(),
60 beans::PropertyAttribute::BOUND
61 | beans::PropertyAttribute::MAYBEVOID
62 | beans::PropertyAttribute::MAYBEDEFAULT );
64 // shadowSlant
65 rOutProperties.emplace_back( "D3DSceneShadowSlant",
66 PROP_SCENE_SHADOW_SLANT,
67 cppu::UnoType<sal_Int32>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEVOID
70 | beans::PropertyAttribute::MAYBEDEFAULT );
72 // shadeMode
73 rOutProperties.emplace_back( "D3DSceneShadeMode",
74 PROP_SCENE_SHADE_MODE,
75 cppu::UnoType<drawing::ShadeMode>::get(),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEVOID
78 | beans::PropertyAttribute::MAYBEDEFAULT );
80 // ambientColor
81 rOutProperties.emplace_back( "D3DSceneAmbientColor",
82 PROP_SCENE_AMBIENT_COLOR,
83 cppu::UnoType<sal_Int32>::get(),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEVOID
86 | beans::PropertyAttribute::MAYBEDEFAULT );
88 // lightingMode
89 rOutProperties.emplace_back( "D3DSceneTwoSidedLighting",
90 PROP_SCENE_TWO_SIDED_LIGHTING,
91 cppu::UnoType<bool>::get(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEVOID
94 | beans::PropertyAttribute::MAYBEDEFAULT );
96 // camera geometry
97 rOutProperties.emplace_back( "D3DCameraGeometry",
98 PROP_SCENE_CAMERA_GEOMETRY,
99 cppu::UnoType<drawing::CameraGeometry>::get(),
100 beans::PropertyAttribute::BOUND
101 | beans::PropertyAttribute::MAYBEVOID
102 | beans::PropertyAttribute::MAYBEDEFAULT );
104 // perspective
105 rOutProperties.emplace_back( "D3DScenePerspective",
106 PROP_SCENE_PERSPECTIVE,
107 cppu::UnoType<drawing::ProjectionMode>::get(),
108 beans::PropertyAttribute::BOUND
109 | beans::PropertyAttribute::MAYBEVOID
110 | beans::PropertyAttribute::MAYBEDEFAULT );
112 // Light Sources
113 // light source 1
114 rOutProperties.emplace_back( "D3DSceneLightColor1",
115 PROP_SCENE_LIGHT_COLOR_1,
116 cppu::UnoType<sal_Int32>::get(),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::MAYBEVOID
119 | beans::PropertyAttribute::MAYBEDEFAULT );
120 rOutProperties.emplace_back( "D3DSceneLightDirection1",
121 PROP_SCENE_LIGHT_DIRECTION_1,
122 cppu::UnoType<drawing::Direction3D>::get(),
123 beans::PropertyAttribute::BOUND
124 | beans::PropertyAttribute::MAYBEVOID
125 | beans::PropertyAttribute::MAYBEDEFAULT );
126 rOutProperties.emplace_back( "D3DSceneLightOn1",
127 PROP_SCENE_LIGHT_ON_1,
128 cppu::UnoType<bool>::get(),
129 beans::PropertyAttribute::BOUND
130 | beans::PropertyAttribute::MAYBEVOID
131 | beans::PropertyAttribute::MAYBEDEFAULT );
132 // light source 2
133 rOutProperties.emplace_back( "D3DSceneLightColor2",
134 PROP_SCENE_LIGHT_COLOR_2,
135 cppu::UnoType<sal_Int32>::get(),
136 beans::PropertyAttribute::BOUND
137 | beans::PropertyAttribute::MAYBEVOID
138 | beans::PropertyAttribute::MAYBEDEFAULT );
139 rOutProperties.emplace_back( "D3DSceneLightDirection2",
140 PROP_SCENE_LIGHT_DIRECTION_2,
141 cppu::UnoType<drawing::Direction3D>::get(),
142 beans::PropertyAttribute::BOUND
143 | beans::PropertyAttribute::MAYBEVOID
144 | beans::PropertyAttribute::MAYBEDEFAULT );
145 rOutProperties.emplace_back( "D3DSceneLightOn2",
146 PROP_SCENE_LIGHT_ON_2,
147 cppu::UnoType<bool>::get(),
148 beans::PropertyAttribute::BOUND
149 | beans::PropertyAttribute::MAYBEVOID
150 | beans::PropertyAttribute::MAYBEDEFAULT );
151 // light source 3
152 rOutProperties.emplace_back( "D3DSceneLightColor3",
153 PROP_SCENE_LIGHT_COLOR_3,
154 cppu::UnoType<sal_Int32>::get(),
155 beans::PropertyAttribute::BOUND
156 | beans::PropertyAttribute::MAYBEVOID
157 | beans::PropertyAttribute::MAYBEDEFAULT );
158 rOutProperties.emplace_back( "D3DSceneLightDirection3",
159 PROP_SCENE_LIGHT_DIRECTION_3,
160 cppu::UnoType<drawing::Direction3D>::get(),
161 beans::PropertyAttribute::BOUND
162 | beans::PropertyAttribute::MAYBEVOID
163 | beans::PropertyAttribute::MAYBEDEFAULT );
164 rOutProperties.emplace_back( "D3DSceneLightOn3",
165 PROP_SCENE_LIGHT_ON_3,
166 cppu::UnoType<bool>::get(),
167 beans::PropertyAttribute::BOUND
168 | beans::PropertyAttribute::MAYBEVOID
169 | beans::PropertyAttribute::MAYBEDEFAULT );
170 // light source 4
171 rOutProperties.emplace_back( "D3DSceneLightColor4",
172 PROP_SCENE_LIGHT_COLOR_4,
173 cppu::UnoType<sal_Int32>::get(),
174 beans::PropertyAttribute::BOUND
175 | beans::PropertyAttribute::MAYBEVOID
176 | beans::PropertyAttribute::MAYBEDEFAULT );
177 rOutProperties.emplace_back( "D3DSceneLightDirection4",
178 PROP_SCENE_LIGHT_DIRECTION_4,
179 cppu::UnoType<drawing::Direction3D>::get(),
180 beans::PropertyAttribute::BOUND
181 | beans::PropertyAttribute::MAYBEVOID
182 | beans::PropertyAttribute::MAYBEDEFAULT );
183 rOutProperties.emplace_back( "D3DSceneLightOn4",
184 PROP_SCENE_LIGHT_ON_4,
185 cppu::UnoType<bool>::get(),
186 beans::PropertyAttribute::BOUND
187 | beans::PropertyAttribute::MAYBEVOID
188 | beans::PropertyAttribute::MAYBEDEFAULT );
189 // light source 5
190 rOutProperties.emplace_back( "D3DSceneLightColor5",
191 PROP_SCENE_LIGHT_COLOR_5,
192 cppu::UnoType<sal_Int32>::get(),
193 beans::PropertyAttribute::BOUND
194 | beans::PropertyAttribute::MAYBEVOID
195 | beans::PropertyAttribute::MAYBEDEFAULT );
196 rOutProperties.emplace_back( "D3DSceneLightDirection5",
197 PROP_SCENE_LIGHT_DIRECTION_5,
198 cppu::UnoType<drawing::Direction3D>::get(),
199 beans::PropertyAttribute::BOUND
200 | beans::PropertyAttribute::MAYBEVOID
201 | beans::PropertyAttribute::MAYBEDEFAULT );
202 rOutProperties.emplace_back( "D3DSceneLightOn5",
203 PROP_SCENE_LIGHT_ON_5,
204 cppu::UnoType<bool>::get(),
205 beans::PropertyAttribute::BOUND
206 | beans::PropertyAttribute::MAYBEVOID
207 | beans::PropertyAttribute::MAYBEDEFAULT );
208 // light source 6
209 rOutProperties.emplace_back( "D3DSceneLightColor6",
210 PROP_SCENE_LIGHT_COLOR_6,
211 cppu::UnoType<sal_Int32>::get(),
212 beans::PropertyAttribute::BOUND
213 | beans::PropertyAttribute::MAYBEVOID
214 | beans::PropertyAttribute::MAYBEDEFAULT );
215 rOutProperties.emplace_back( "D3DSceneLightDirection6",
216 PROP_SCENE_LIGHT_DIRECTION_6,
217 cppu::UnoType<drawing::Direction3D>::get(),
218 beans::PropertyAttribute::BOUND
219 | beans::PropertyAttribute::MAYBEVOID
220 | beans::PropertyAttribute::MAYBEDEFAULT );
221 rOutProperties.emplace_back( "D3DSceneLightOn6",
222 PROP_SCENE_LIGHT_ON_6,
223 cppu::UnoType<bool>::get(),
224 beans::PropertyAttribute::BOUND
225 | beans::PropertyAttribute::MAYBEVOID
226 | beans::PropertyAttribute::MAYBEDEFAULT );
227 // light source 7
228 rOutProperties.emplace_back( "D3DSceneLightColor7",
229 PROP_SCENE_LIGHT_COLOR_7,
230 cppu::UnoType<sal_Int32>::get(),
231 beans::PropertyAttribute::BOUND
232 | beans::PropertyAttribute::MAYBEVOID
233 | beans::PropertyAttribute::MAYBEDEFAULT );
234 rOutProperties.emplace_back( "D3DSceneLightDirection7",
235 PROP_SCENE_LIGHT_DIRECTION_7,
236 cppu::UnoType<drawing::Direction3D>::get(),
237 beans::PropertyAttribute::BOUND
238 | beans::PropertyAttribute::MAYBEVOID
239 | beans::PropertyAttribute::MAYBEDEFAULT );
240 rOutProperties.emplace_back( "D3DSceneLightOn7",
241 PROP_SCENE_LIGHT_ON_7,
242 cppu::UnoType<bool>::get(),
243 beans::PropertyAttribute::BOUND
244 | beans::PropertyAttribute::MAYBEVOID
245 | beans::PropertyAttribute::MAYBEDEFAULT );
246 // light source 8
247 rOutProperties.emplace_back( "D3DSceneLightColor8",
248 PROP_SCENE_LIGHT_COLOR_8,
249 cppu::UnoType<sal_Int32>::get(),
250 beans::PropertyAttribute::BOUND
251 | beans::PropertyAttribute::MAYBEVOID
252 | beans::PropertyAttribute::MAYBEDEFAULT );
253 rOutProperties.emplace_back( "D3DSceneLightDirection8",
254 PROP_SCENE_LIGHT_DIRECTION_8,
255 cppu::UnoType<drawing::Direction3D>::get(),
256 beans::PropertyAttribute::BOUND
257 | beans::PropertyAttribute::MAYBEVOID
258 | beans::PropertyAttribute::MAYBEDEFAULT );
259 rOutProperties.emplace_back( "D3DSceneLightOn8",
260 PROP_SCENE_LIGHT_ON_8,
261 cppu::UnoType<bool>::get(),
262 beans::PropertyAttribute::BOUND
263 | beans::PropertyAttribute::MAYBEVOID
264 | beans::PropertyAttribute::MAYBEDEFAULT );
267 void SceneProperties::AddDefaultsToMap(
268 ::chart::tPropertyValueMap & rOutMap )
270 // Identity Matrix
271 drawing::HomogenMatrix aMtx;
272 aMtx.Line1.Column1 = aMtx.Line2.Column2 =
273 aMtx.Line3.Column3 = aMtx.Line4.Column4 = 1.0;
274 aMtx.Line1.Column2 = aMtx.Line1.Column3 = aMtx.Line1.Column4 =
275 aMtx.Line2.Column1 = aMtx.Line2.Column3 = aMtx.Line2.Column4 =
276 aMtx.Line3.Column1 = aMtx.Line3.Column2 = aMtx.Line3.Column4 =
277 aMtx.Line4.Column1 = aMtx.Line4.Column2 = aMtx.Line4.Column3 = 0.0;
279 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_TRANSF_MATRIX, aMtx );
280 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_DISTANCE, sal_Int32(4200) );
281 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_FOCAL_LENGTH, sal_Int32(8000) );
283 // PROP_SCENE_SHADOW_SLANT;
284 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_SHADE_MODE, drawing::ShadeMode_SMOOTH );
286 ::chart::PropertyHelper::setPropertyValueDefault(
287 rOutMap, PROP_SCENE_AMBIENT_COLOR, ChartTypeHelper::getDefaultAmbientLightColor(false,nullptr));
289 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_TWO_SIDED_LIGHTING, true );
291 drawing::Position3D vrp( 0.0, 0.0, 1.0 );
292 drawing::Direction3D vpn( 0.0, 0.0, 1.0 );
293 drawing::Direction3D vup( 0.0, 1.0, 0.0 );
294 drawing::CameraGeometry aDefaultCameraGeometry( vrp, vpn, vup );
296 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_CAMERA_GEOMETRY, aDefaultCameraGeometry );
297 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_PERSPECTIVE, drawing::ProjectionMode_PERSPECTIVE );
299 // Light Sources
300 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_1, false );
301 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_2, true );
302 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_3, false );
303 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_4, false );
304 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_5, false );
305 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_6, false );
306 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_7, false );
307 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_ON_8, false );
309 uno::Any aDefaultLightDirection( drawing::Direction3D( 0.0, 0.0, 1.0 ) );
310 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_1, aDefaultLightDirection );
311 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_2, ChartTypeHelper::getDefaultSimpleLightDirection(nullptr));
312 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_3, aDefaultLightDirection );
313 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_4, aDefaultLightDirection );
314 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_5, aDefaultLightDirection );
315 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_6, aDefaultLightDirection );
316 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_7, aDefaultLightDirection );
317 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_DIRECTION_8, aDefaultLightDirection );
319 uno::Any aDefaultLightColor;
320 aDefaultLightColor <<= ChartTypeHelper::getDefaultDirectLightColor(false,nullptr);
321 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_1, aDefaultLightColor );
322 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_2, aDefaultLightColor );
323 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_3, aDefaultLightColor );
324 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_4, aDefaultLightColor );
325 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_5, aDefaultLightColor );
326 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_6, aDefaultLightColor );
327 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_7, aDefaultLightColor );
328 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCENE_LIGHT_COLOR_8, aDefaultLightColor );
331 } // namespace chart
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */