1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/extract.hxx>
21 #include "ximp3dobject.hxx"
22 #include <xmloff/XMLShapeStyleContext.hxx>
23 #include <xmloff/xmluconv.hxx>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
26 #include <com/sun/star/drawing/PointSequence.hpp>
27 #include "xexptran.hxx"
28 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
29 #include <xmloff/families.hxx>
30 #include "ximpstyl.hxx"
31 #include <xmloff/xmltoken.hxx>
32 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
33 #include <com/sun/star/drawing/DoubleSequence.hpp>
34 #include <osl/diagnose.h>
35 #include <basegfx/polygon/b2dpolypolygon.hxx>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 #include <basegfx/polygon/b3dpolypolygontools.hxx>
39 using namespace ::com::sun::star
;
41 TYPEINIT1( SdXML3DObjectContext
, SdXMLShapeContext
);
43 SdXML3DObjectContext::SdXML3DObjectContext(
46 const OUString
& rLocalName
,
47 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
48 uno::Reference
< drawing::XShapes
>& rShapes
,
50 : SdXMLShapeContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
),
51 mbSetTransform( false )
53 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
54 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
56 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
58 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
59 OUString sValue
= xAttrList
->getValueByIndex( i
);
60 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
62 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
64 case XML_TOK_3DOBJECT_DRAWSTYLE_NAME
:
66 maDrawStyleName
= sValue
;
69 case XML_TOK_3DOBJECT_TRANSFORM
:
71 SdXMLImExTransform3D
aTransform(sValue
, GetImport().GetMM100UnitConverter());
72 if(aTransform
.NeedsAction())
73 mbSetTransform
= aTransform
.GetFullHomogenTransform(mxHomMat
);
80 SdXML3DObjectContext::~SdXML3DObjectContext()
84 void SdXML3DObjectContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
86 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
94 xPropSet
->setPropertyValue("D3DTransformMatrix", aAny
);
98 SdXMLShapeContext::StartElement(xAttrList
);
102 void SdXML3DObjectContext::EndElement()
105 SdXMLShapeContext::EndElement();
108 TYPEINIT1( SdXML3DCubeObjectShapeContext
, SdXML3DObjectContext
);
110 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
111 SvXMLImport
& rImport
,
113 const OUString
& rLocalName
,
114 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
115 uno::Reference
< drawing::XShapes
>& rShapes
,
116 bool bTemporaryShape
)
117 : SdXML3DObjectContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
),
118 maMinEdge(-2500.0, -2500.0, -2500.0),
119 maMaxEdge(2500.0, 2500.0, 2500.0),
120 mbMinEdgeUsed(false),
123 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
124 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
126 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
128 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
129 OUString sValue
= xAttrList
->getValueByIndex( i
);
130 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
132 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
134 case XML_TOK_3DCUBEOBJ_MINEDGE
:
136 ::basegfx::B3DVector aNewVec
;
137 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
139 if(aNewVec
!= maMinEdge
)
142 mbMinEdgeUsed
= true;
146 case XML_TOK_3DCUBEOBJ_MAXEDGE
:
148 ::basegfx::B3DVector aNewVec
;
149 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
151 if(aNewVec
!= maMaxEdge
)
154 mbMaxEdgeUsed
= true;
162 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
166 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
169 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
172 // add, set style and properties from base shape
174 SdXML3DObjectContext::StartElement(xAttrList
);
176 // set local parameters on shape
177 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
181 drawing::Position3D aPosition3D
;
182 drawing::Direction3D aDirection3D
;
184 // convert from min, max to size to be set
185 maMaxEdge
= maMaxEdge
- maMinEdge
;
187 aPosition3D
.PositionX
= maMinEdge
.getX();
188 aPosition3D
.PositionY
= maMinEdge
.getY();
189 aPosition3D
.PositionZ
= maMinEdge
.getZ();
191 aDirection3D
.DirectionX
= maMaxEdge
.getX();
192 aDirection3D
.DirectionY
= maMaxEdge
.getY();
193 aDirection3D
.DirectionZ
= maMaxEdge
.getZ();
196 aAny
<<= aPosition3D
;
197 xPropSet
->setPropertyValue("D3DPosition", aAny
);
198 aAny
<<= aDirection3D
;
199 xPropSet
->setPropertyValue("D3DSize", aAny
);
204 void SdXML3DCubeObjectShapeContext::EndElement()
207 SdXML3DObjectContext::EndElement();
210 TYPEINIT1( SdXML3DSphereObjectShapeContext
, SdXML3DObjectContext
);
212 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
213 SvXMLImport
& rImport
,
215 const OUString
& rLocalName
,
216 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
217 uno::Reference
< drawing::XShapes
>& rShapes
,
218 bool bTemporaryShape
)
219 : SdXML3DObjectContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
),
220 maCenter(0.0, 0.0, 0.0),
221 maSize(5000.0, 5000.0, 5000.0),
225 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
226 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
228 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
230 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
231 OUString sValue
= xAttrList
->getValueByIndex( i
);
232 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
234 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
236 case XML_TOK_3DSPHEREOBJ_CENTER
:
238 ::basegfx::B3DVector aNewVec
;
239 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
241 if(aNewVec
!= maCenter
)
248 case XML_TOK_3DSPHEREOBJ_SIZE
:
250 ::basegfx::B3DVector aNewVec
;
251 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
253 if(aNewVec
!= maSize
)
264 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
268 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
271 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
274 // add, set style and properties from base shape
276 SdXML3DObjectContext::StartElement(xAttrList
);
278 // set local parameters on shape
279 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
283 drawing::Position3D aPosition3D
;
284 drawing::Direction3D aDirection3D
;
286 aPosition3D
.PositionX
= maCenter
.getX();
287 aPosition3D
.PositionY
= maCenter
.getY();
288 aPosition3D
.PositionZ
= maCenter
.getZ();
290 aDirection3D
.DirectionX
= maSize
.getX();
291 aDirection3D
.DirectionY
= maSize
.getY();
292 aDirection3D
.DirectionZ
= maSize
.getZ();
295 aAny
<<= aPosition3D
;
296 xPropSet
->setPropertyValue("D3DPosition", aAny
);
297 aAny
<<= aDirection3D
;
298 xPropSet
->setPropertyValue("D3DSize", aAny
);
303 void SdXML3DSphereObjectShapeContext::EndElement()
306 SdXML3DObjectContext::EndElement();
309 TYPEINIT1( SdXML3DPolygonBasedShapeContext
, SdXML3DObjectContext
);
311 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
312 SvXMLImport
& rImport
,
314 const OUString
& rLocalName
,
315 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
316 uno::Reference
< drawing::XShapes
>& rShapes
,
317 bool bTemporaryShape
)
318 : SdXML3DObjectContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
)
320 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
321 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
323 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
325 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
326 OUString sValue
= xAttrList
->getValueByIndex( i
);
327 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
329 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
331 case XML_TOK_3DPOLYGONBASED_VIEWBOX
:
336 case XML_TOK_3DPOLYGONBASED_D
:
345 SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
349 void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
351 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
356 if(!maPoints
.isEmpty() && !maViewBox
.isEmpty())
358 // import 2d tools::PolyPolygon from svg:d
359 basegfx::B2DPolyPolygon aPolyPolygon
;
361 if(basegfx::tools::importFromSvgD(aPolyPolygon
, maPoints
, GetImport().needFixPositionAfterZ(), 0))
363 // convert to 3D PolyPolygon
364 const basegfx::B3DPolyPolygon
aB3DPolyPolygon(
365 basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(
368 // convert to UNO API class PolyPolygonShape3D
369 drawing::PolyPolygonShape3D xPolyPolygon3D
;
370 basegfx::tools::B3DPolyPolygonToUnoPolyPolygonShape3D(
376 aAny
<<= xPolyPolygon3D
;
377 xPropSet
->setPropertyValue(OUString("D3DPolyPolygon3D"), aAny
);
381 OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
386 SdXML3DObjectContext::StartElement(xAttrList
);
390 void SdXML3DPolygonBasedShapeContext::EndElement()
393 SdXML3DObjectContext::EndElement();
396 TYPEINIT1( SdXML3DLatheObjectShapeContext
, SdXML3DPolygonBasedShapeContext
);
398 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
399 SvXMLImport
& rImport
,
401 const OUString
& rLocalName
,
402 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
403 uno::Reference
< drawing::XShapes
>& rShapes
,
404 bool bTemporaryShape
)
405 : SdXML3DPolygonBasedShapeContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
)
409 SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
413 void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
416 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
419 // add, set style and properties from base shape
421 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
425 void SdXML3DLatheObjectShapeContext::EndElement()
428 SdXML3DPolygonBasedShapeContext::EndElement();
431 TYPEINIT1( SdXML3DExtrudeObjectShapeContext
, SdXML3DPolygonBasedShapeContext
);
433 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
434 SvXMLImport
& rImport
,
436 const OUString
& rLocalName
,
437 const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
,
438 uno::Reference
< drawing::XShapes
>& rShapes
,
439 bool bTemporaryShape
)
440 : SdXML3DPolygonBasedShapeContext( rImport
, nPrfx
, rLocalName
, xAttrList
, rShapes
, bTemporaryShape
)
444 SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
448 void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
450 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
453 // add, set style and properties from base shape
455 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
459 void SdXML3DExtrudeObjectShapeContext::EndElement()
462 SdXML3DPolygonBasedShapeContext::EndElement();
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */