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 "ximp3dobject.hxx"
21 #include <xmloff/xmluconv.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <xexptran.hxx>
24 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
25 #include <com/sun/star/drawing/Direction3D.hpp>
26 #include <com/sun/star/drawing/Position3D.hpp>
27 #include <osl/diagnose.h>
28 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 #include <basegfx/polygon/b2dpolypolygontools.hxx>
30 #include <basegfx/polygon/b3dpolypolygontools.hxx>
32 using namespace ::com::sun::star
;
35 SdXML3DObjectContext::SdXML3DObjectContext(
37 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
38 uno::Reference
< drawing::XShapes
> const & rShapes
)
39 : SdXMLShapeContext( rImport
, xAttrList
, rShapes
, false/*bTemporaryShape*/ ),
40 mbSetTransform( false )
42 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
43 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
45 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
47 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
48 OUString sValue
= xAttrList
->getValueByIndex( i
);
49 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
51 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
53 case XML_TOK_3DOBJECT_DRAWSTYLE_NAME
:
55 maDrawStyleName
= sValue
;
58 case XML_TOK_3DOBJECT_TRANSFORM
:
60 SdXMLImExTransform3D
aTransform(sValue
, GetImport().GetMM100UnitConverter());
61 if(aTransform
.NeedsAction())
62 mbSetTransform
= aTransform
.GetFullHomogenTransform(mxHomMat
);
69 SdXML3DObjectContext::~SdXML3DObjectContext()
73 void SdXML3DObjectContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
75 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
81 xPropSet
->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat
));
85 SdXMLShapeContext::StartElement(xAttrList
);
89 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
91 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
92 uno::Reference
< drawing::XShapes
> const & rShapes
)
93 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
),
94 maMinEdge(-2500.0, -2500.0, -2500.0),
95 maMaxEdge(2500.0, 2500.0, 2500.0)
97 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
98 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
100 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
102 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
103 OUString sValue
= xAttrList
->getValueByIndex( i
);
104 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
106 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
108 case XML_TOK_3DCUBEOBJ_MINEDGE
:
110 ::basegfx::B3DVector aNewVec
;
111 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
113 if(aNewVec
!= maMinEdge
)
117 case XML_TOK_3DCUBEOBJ_MAXEDGE
:
119 ::basegfx::B3DVector aNewVec
;
120 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
122 if(aNewVec
!= maMaxEdge
)
130 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
134 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
137 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
141 // add, set style and properties from base shape
143 SdXML3DObjectContext::StartElement(xAttrList
);
145 // set local parameters on shape
146 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
151 drawing::Position3D aPosition3D
;
152 drawing::Direction3D aDirection3D
;
154 // convert from min, max to size to be set
155 maMaxEdge
= maMaxEdge
- maMinEdge
;
157 aPosition3D
.PositionX
= maMinEdge
.getX();
158 aPosition3D
.PositionY
= maMinEdge
.getY();
159 aPosition3D
.PositionZ
= maMinEdge
.getZ();
161 aDirection3D
.DirectionX
= maMaxEdge
.getX();
162 aDirection3D
.DirectionY
= maMaxEdge
.getY();
163 aDirection3D
.DirectionZ
= maMaxEdge
.getZ();
165 xPropSet
->setPropertyValue("D3DPosition", uno::Any(aPosition3D
));
166 xPropSet
->setPropertyValue("D3DSize", uno::Any(aDirection3D
));
169 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
170 SvXMLImport
& rImport
,
171 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
172 uno::Reference
< drawing::XShapes
> const & rShapes
)
173 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
),
174 maCenter(0.0, 0.0, 0.0),
175 maSphereSize(5000.0, 5000.0, 5000.0)
177 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
178 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
180 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
182 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
183 OUString sValue
= xAttrList
->getValueByIndex( i
);
184 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
186 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
188 case XML_TOK_3DSPHEREOBJ_CENTER
:
190 ::basegfx::B3DVector aNewVec
;
191 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
193 if(aNewVec
!= maCenter
)
197 case XML_TOK_3DSPHEREOBJ_SIZE
:
199 ::basegfx::B3DVector aNewVec
;
200 SvXMLUnitConverter::convertB3DVector(aNewVec
, sValue
);
202 if(aNewVec
!= maSphereSize
)
203 maSphereSize
= aNewVec
;
210 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
214 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
217 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
221 // add, set style and properties from base shape
223 SdXML3DObjectContext::StartElement(xAttrList
);
225 // set local parameters on shape
226 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
231 drawing::Position3D aPosition3D
;
232 drawing::Direction3D aDirection3D
;
234 aPosition3D
.PositionX
= maCenter
.getX();
235 aPosition3D
.PositionY
= maCenter
.getY();
236 aPosition3D
.PositionZ
= maCenter
.getZ();
238 aDirection3D
.DirectionX
= maSphereSize
.getX();
239 aDirection3D
.DirectionY
= maSphereSize
.getY();
240 aDirection3D
.DirectionZ
= maSphereSize
.getZ();
242 xPropSet
->setPropertyValue("D3DPosition", uno::Any(aPosition3D
));
243 xPropSet
->setPropertyValue("D3DSize", uno::Any(aDirection3D
));
246 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
247 SvXMLImport
& rImport
,
248 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
249 uno::Reference
< drawing::XShapes
> const & rShapes
)
250 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
)
252 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
253 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
255 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
257 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
258 OUString sValue
= xAttrList
->getValueByIndex( i
);
259 const SvXMLTokenMap
& rAttrTokenMap
= GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
261 switch(rAttrTokenMap
.Get(nPrefix
, aLocalName
))
263 case XML_TOK_3DPOLYGONBASED_VIEWBOX
:
268 case XML_TOK_3DPOLYGONBASED_D
:
277 SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
281 void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
283 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
289 if(!maPoints
.isEmpty() && !maViewBox
.isEmpty())
291 // import 2d tools::PolyPolygon from svg:d
292 basegfx::B2DPolyPolygon aPolyPolygon
;
294 if(basegfx::utils::importFromSvgD(aPolyPolygon
, maPoints
, GetImport().needFixPositionAfterZ(), nullptr))
296 // convert to 3D PolyPolygon
297 const basegfx::B3DPolyPolygon
aB3DPolyPolygon(
298 basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(
301 // convert to UNO API class PolyPolygonShape3D
302 drawing::PolyPolygonShape3D aPolyPolygon3D
;
303 basegfx::utils::B3DPolyPolygonToUnoPolyPolygonShape3D(
308 xPropSet
->setPropertyValue("D3DPolyPolygon3D", uno::Any(aPolyPolygon3D
));
312 OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
317 SdXML3DObjectContext::StartElement(xAttrList
);
321 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
322 SvXMLImport
& rImport
,
323 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
324 uno::Reference
< drawing::XShapes
> const & rShapes
)
325 : SdXML3DPolygonBasedShapeContext( rImport
, xAttrList
, rShapes
)
329 SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
333 void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
336 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
339 // add, set style and properties from base shape
341 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
345 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
346 SvXMLImport
& rImport
,
347 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
348 uno::Reference
< drawing::XShapes
> const & rShapes
)
349 : SdXML3DPolygonBasedShapeContext( rImport
, xAttrList
, rShapes
)
353 SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
357 void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
359 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
362 // add, set style and properties from base shape
364 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */