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 <xmloff/xmlnamespace.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <xexptran.hxx>
25 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
26 #include <com/sun/star/drawing/Direction3D.hpp>
27 #include <com/sun/star/drawing/Position3D.hpp>
28 #include <sal/log.hxx>
29 #include <osl/diagnose.h>
30 #include <basegfx/polygon/b2dpolypolygon.hxx>
31 #include <basegfx/polygon/b2dpolypolygontools.hxx>
32 #include <basegfx/polygon/b3dpolypolygontools.hxx>
34 using namespace ::com::sun::star
;
35 using namespace ::xmloff::token
;
38 SdXML3DObjectContext::SdXML3DObjectContext(
40 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
41 uno::Reference
< drawing::XShapes
> const & rShapes
)
42 : SdXMLShapeContext( rImport
, xAttrList
, rShapes
, false/*bTemporaryShape*/ ),
43 mbSetTransform( false )
45 for(auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
47 const OUString sValue
= aIter
.toString();
48 switch(aIter
.getToken())
50 case XML_ELEMENT(DRAW
, XML_STYLE_NAME
):
52 maDrawStyleName
= sValue
;
55 case XML_ELEMENT(DR3D
, XML_TRANSFORM
):
57 SdXMLImExTransform3D
aTransform(sValue
, GetImport().GetMM100UnitConverter());
58 if(aTransform
.NeedsAction())
59 mbSetTransform
= aTransform
.GetFullHomogenTransform(mxHomMat
);
63 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
68 SdXML3DObjectContext::~SdXML3DObjectContext()
72 void SdXML3DObjectContext::startFastElement(
74 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
76 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
82 xPropSet
->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat
));
86 SdXMLShapeContext::startFastElement(nElement
, xAttrList
);
90 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
92 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
93 uno::Reference
< drawing::XShapes
> const & rShapes
)
94 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
),
95 maMinEdge(-2500.0, -2500.0, -2500.0),
96 maMaxEdge(2500.0, 2500.0, 2500.0)
98 for(auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
100 switch(aIter
.getToken())
102 case XML_ELEMENT(DR3D
, XML_MIN_EDGE
):
104 ::basegfx::B3DVector aNewVec
;
105 SvXMLUnitConverter::convertB3DVector(aNewVec
, aIter
.toView());
107 if(aNewVec
!= maMinEdge
)
111 case XML_ELEMENT(DR3D
, XML_MAX_EDGE
):
113 ::basegfx::B3DVector aNewVec
;
114 SvXMLUnitConverter::convertB3DVector(aNewVec
, aIter
.toView());
116 if(aNewVec
!= maMaxEdge
)
121 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
126 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
130 void SdXML3DCubeObjectShapeContext::startFastElement(
132 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
135 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
139 // add, set style and properties from base shape
141 SdXML3DObjectContext::startFastElement(nElement
, xAttrList
);
143 // set local parameters on shape
144 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
149 drawing::Position3D aPosition3D
;
150 drawing::Direction3D aDirection3D
;
152 // convert from min, max to size to be set
153 maMaxEdge
= maMaxEdge
- maMinEdge
;
155 aPosition3D
.PositionX
= maMinEdge
.getX();
156 aPosition3D
.PositionY
= maMinEdge
.getY();
157 aPosition3D
.PositionZ
= maMinEdge
.getZ();
159 aDirection3D
.DirectionX
= maMaxEdge
.getX();
160 aDirection3D
.DirectionY
= maMaxEdge
.getY();
161 aDirection3D
.DirectionZ
= maMaxEdge
.getZ();
163 xPropSet
->setPropertyValue("D3DPosition", uno::Any(aPosition3D
));
164 xPropSet
->setPropertyValue("D3DSize", uno::Any(aDirection3D
));
167 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
168 SvXMLImport
& rImport
,
169 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
170 uno::Reference
< drawing::XShapes
> const & rShapes
)
171 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
),
172 maCenter(0.0, 0.0, 0.0),
173 maSphereSize(5000.0, 5000.0, 5000.0)
175 for(auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
177 switch(aIter
.getToken())
179 case XML_ELEMENT(DR3D
, XML_CENTER
):
181 ::basegfx::B3DVector aNewVec
;
182 SvXMLUnitConverter::convertB3DVector(aNewVec
, aIter
.toView());
184 if(aNewVec
!= maCenter
)
188 case XML_ELEMENT(DR3D
, XML_SIZE
):
190 ::basegfx::B3DVector aNewVec
;
191 SvXMLUnitConverter::convertB3DVector(aNewVec
, aIter
.toView());
193 if(aNewVec
!= maSphereSize
)
194 maSphereSize
= aNewVec
;
198 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
203 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
207 void SdXML3DSphereObjectShapeContext::startFastElement(
209 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
212 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
216 // add, set style and properties from base shape
218 SdXML3DObjectContext::startFastElement(nElement
, xAttrList
);
220 // set local parameters on shape
221 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
226 drawing::Position3D aPosition3D
;
227 drawing::Direction3D aDirection3D
;
229 aPosition3D
.PositionX
= maCenter
.getX();
230 aPosition3D
.PositionY
= maCenter
.getY();
231 aPosition3D
.PositionZ
= maCenter
.getZ();
233 aDirection3D
.DirectionX
= maSphereSize
.getX();
234 aDirection3D
.DirectionY
= maSphereSize
.getY();
235 aDirection3D
.DirectionZ
= maSphereSize
.getZ();
237 xPropSet
->setPropertyValue("D3DPosition", uno::Any(aPosition3D
));
238 xPropSet
->setPropertyValue("D3DSize", uno::Any(aDirection3D
));
241 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
242 SvXMLImport
& rImport
,
243 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
244 uno::Reference
< drawing::XShapes
> const & rShapes
)
245 : SdXML3DObjectContext( rImport
, xAttrList
, rShapes
)
247 for(auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
249 OUString sValue
= aIter
.toString();
251 switch(aIter
.getToken())
253 case XML_ELEMENT(SVG
, XML_VIEWBOX
):
254 case XML_ELEMENT(SVG_COMPAT
, XML_VIEWBOX
):
259 case XML_ELEMENT(SVG
, XML_D
):
260 case XML_ELEMENT(SVG_COMPAT
, XML_D
):
266 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
271 SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
275 void SdXML3DPolygonBasedShapeContext::startFastElement(
277 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
279 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
285 if(!maPoints
.isEmpty() && !maViewBox
.isEmpty())
287 // import 2d tools::PolyPolygon from svg:d
288 basegfx::B2DPolyPolygon aPolyPolygon
;
290 if(basegfx::utils::importFromSvgD(aPolyPolygon
, maPoints
, GetImport().needFixPositionAfterZ(), nullptr))
292 // convert to 3D PolyPolygon
293 const basegfx::B3DPolyPolygon
aB3DPolyPolygon(
294 basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(
297 // convert to UNO API class PolyPolygonShape3D
298 drawing::PolyPolygonShape3D aPolyPolygon3D
;
299 basegfx::utils::B3DPolyPolygonToUnoPolyPolygonShape3D(
304 xPropSet
->setPropertyValue("D3DPolyPolygon3D", uno::Any(aPolyPolygon3D
));
308 OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
313 SdXML3DObjectContext::startFastElement(nElement
, xAttrList
);
317 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
318 SvXMLImport
& rImport
,
319 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
320 uno::Reference
< drawing::XShapes
> const & rShapes
)
321 : SdXML3DPolygonBasedShapeContext( rImport
, xAttrList
, rShapes
)
325 SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
329 void SdXML3DLatheObjectShapeContext::startFastElement(
331 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
334 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
337 // add, set style and properties from base shape
339 SdXML3DPolygonBasedShapeContext::startFastElement(nElement
, xAttrList
);
343 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
344 SvXMLImport
& rImport
,
345 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
,
346 uno::Reference
< drawing::XShapes
> const & rShapes
)
347 : SdXML3DPolygonBasedShapeContext( rImport
, xAttrList
, rShapes
)
351 SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
355 void SdXML3DExtrudeObjectShapeContext::startFastElement(
357 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
359 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
362 // add, set style and properties from base shape
364 SdXML3DPolygonBasedShapeContext::startFastElement(nElement
, xAttrList
);
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */