1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "ximp3dobject.hxx"
#include <xmloff/XMLShapeStyleContext.hxx>
#include <xmloff/xmluconv.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/PointSequenceSequence.hpp>
#include <com/sun/star/drawing/PointSequence.hpp>
#include <xexptran.hxx>
#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
#include <xmloff/families.hxx>
#include "ximpstyl.hxx"
#include <xmloff/xmltoken.hxx>
#include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
#include <com/sun/star/drawing/DoubleSequence.hpp>
#include <com/sun/star/drawing/Direction3D.hpp>
#include <com/sun/star/drawing/Position3D.hpp>
#include <osl/diagnose.h>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/polygon/b3dpolypolygontools.hxx>
using namespace ::com::sun::star;
SdXML3DObjectContext::SdXML3DObjectContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, false/*bTemporaryShape*/ ),
mbSetTransform( false )
{
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_3DOBJECT_DRAWSTYLE_NAME:
{
maDrawStyleName = sValue;
break;
}
case XML_TOK_3DOBJECT_TRANSFORM:
{
SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter());
if(aTransform.NeedsAction())
mbSetTransform = aTransform.GetFullHomogenTransform(mxHomMat);
break;
}
}
}
}
SdXML3DObjectContext::~SdXML3DObjectContext()
{
}
void SdXML3DObjectContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
if(xPropSet.is())
{
// set parameters
if(mbSetTransform)
{
xPropSet->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat));
}
// call parent
SdXMLShapeContext::StartElement(xAttrList);
}
}
SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ),
maMinEdge(-2500.0, -2500.0, -2500.0),
maMaxEdge(2500.0, 2500.0, 2500.0)
{
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_3DCUBEOBJ_MINEDGE:
{
::basegfx::B3DVector aNewVec;
SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
if(aNewVec != maMinEdge)
maMinEdge = aNewVec;
break;
}
case XML_TOK_3DCUBEOBJ_MAXEDGE:
{
::basegfx::B3DVector aNewVec;
SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
if(aNewVec != maMaxEdge)
maMaxEdge = aNewVec;
break;
}
}
}
}
SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
{
}
void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
// create shape
AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
if(mxShape.is())
{
// add, set style and properties from base shape
SetStyle();
SdXML3DObjectContext::StartElement(xAttrList);
// set local parameters on shape
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
if(xPropSet.is())
{
// set parameters
drawing::Position3D aPosition3D;
drawing::Direction3D aDirection3D;
// convert from min, max to size to be set
maMaxEdge = maMaxEdge - maMinEdge;
aPosition3D.PositionX = maMinEdge.getX();
aPosition3D.PositionY = maMinEdge.getY();
aPosition3D.PositionZ = maMinEdge.getZ();
aDirection3D.DirectionX = maMaxEdge.getX();
aDirection3D.DirectionY = maMaxEdge.getY();
aDirection3D.DirectionZ = maMaxEdge.getZ();
xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
}
}
}
SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ),
maCenter(0.0, 0.0, 0.0),
maSphereSize(5000.0, 5000.0, 5000.0)
{
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_3DSPHEREOBJ_CENTER:
{
::basegfx::B3DVector aNewVec;
SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
if(aNewVec != maCenter)
maCenter = aNewVec;
break;
}
case XML_TOK_3DSPHEREOBJ_SIZE:
{
::basegfx::B3DVector aNewVec;
SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
if(aNewVec != maSphereSize)
maSphereSize = aNewVec;
break;
}
}
}
}
SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
{
}
void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
// create shape
AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
if(mxShape.is())
{
// add, set style and properties from base shape
SetStyle();
SdXML3DObjectContext::StartElement(xAttrList);
// set local parameters on shape
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
if(xPropSet.is())
{
// set parameters
drawing::Position3D aPosition3D;
drawing::Direction3D aDirection3D;
aPosition3D.PositionX = maCenter.getX();
aPosition3D.PositionY = maCenter.getY();
aPosition3D.PositionZ = maCenter.getZ();
aDirection3D.DirectionX = maSphereSize.getX();
aDirection3D.DirectionY = maSphereSize.getY();
aDirection3D.DirectionZ = maSphereSize.getZ();
xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
}
}
}
SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
{
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for(sal_Int16 i=0; i < nAttrCount; i++)
{
OUString sAttrName = xAttrList->getNameByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
OUString sValue = xAttrList->getValueByIndex( i );
const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
switch(rAttrTokenMap.Get(nPrefix, aLocalName))
{
case XML_TOK_3DPOLYGONBASED_VIEWBOX:
{
maViewBox = sValue;
break;
}
case XML_TOK_3DPOLYGONBASED_D:
{
maPoints = sValue;
break;
}
}
}
}
SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
{
}
void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
if(xPropSet.is())
{
// set parameters
if(!maPoints.isEmpty() && !maViewBox.isEmpty())
{
// import 2d tools::PolyPolygon from svg:d
basegfx::B2DPolyPolygon aPolyPolygon;
if(basegfx::utils::importFromSvgD(aPolyPolygon, maPoints, GetImport().needFixPositionAfterZ(), nullptr))
{
// convert to 3D PolyPolygon
const basegfx::B3DPolyPolygon aB3DPolyPolygon(
basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(
aPolyPolygon));
// convert to UNO API class PolyPolygonShape3D
drawing::PolyPolygonShape3D aPolyPolygon3D;
basegfx::utils::B3DPolyPolygonToUnoPolyPolygonShape3D(
aB3DPolyPolygon,
aPolyPolygon3D);
// set polygon data
xPropSet->setPropertyValue("D3DPolyPolygon3D", uno::Any(aPolyPolygon3D));
}
else
{
OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
}
}
// call parent
SdXML3DObjectContext::StartElement(xAttrList);
}
}
SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
{
}
SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
{
}
void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
// create shape
AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
if(mxShape.is())
{
// add, set style and properties from base shape
SetStyle();
SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
}
}
SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
uno::Reference< drawing::XShapes > const & rShapes)
: SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
{
}
SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
{
}
void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
{
AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
if(mxShape.is())
{
// add, set style and properties from base shape
SetStyle();
SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|