LibreOffice Module xmloff (master) 1
ximp3dobject.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "ximp3dobject.hxx"
21#include <xmloff/xmluconv.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>
33
34using namespace ::com::sun::star;
35using namespace ::xmloff::token;
36
37
39 SvXMLImport& rImport,
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 )
44{
45 for(auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
46 {
47 const OUString sValue = aIter.toString();
48 switch(aIter.getToken())
49 {
51 {
52 maDrawStyleName = sValue;
53 break;
54 }
55 case XML_ELEMENT(DR3D, XML_TRANSFORM):
56 {
57 SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter());
58 if(aTransform.NeedsAction())
60 break;
61 }
62 default:
63 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
64 }
65 }
66}
67
69{
70}
71
73 sal_Int32 nElement,
74 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
75{
76 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
77 if(xPropSet.is())
78 {
79 // set parameters
81 {
82 xPropSet->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat));
83 }
84
85 // call parent
86 SdXMLShapeContext::startFastElement(nElement, xAttrList);
87 }
88}
89
91 SvXMLImport& rImport,
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)
97{
98 for(auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
99 {
100 switch(aIter.getToken())
101 {
102 case XML_ELEMENT(DR3D, XML_MIN_EDGE):
103 {
104 ::basegfx::B3DVector aNewVec;
105 SvXMLUnitConverter::convertB3DVector(aNewVec, aIter.toView());
106
107 if(aNewVec != maMinEdge)
108 maMinEdge = aNewVec;
109 break;
110 }
111 case XML_ELEMENT(DR3D, XML_MAX_EDGE):
112 {
113 ::basegfx::B3DVector aNewVec;
114 SvXMLUnitConverter::convertB3DVector(aNewVec, aIter.toView());
115
116 if(aNewVec != maMaxEdge)
117 maMaxEdge = aNewVec;
118 break;
119 }
120 default:
121 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
122 }
123 }
124}
125
127{
128}
129
131 sal_Int32 nElement,
132 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
133{
134 // create shape
135 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
136 if(!mxShape.is())
137 return;
138
139 // add, set style and properties from base shape
140 SetStyle();
141 SdXML3DObjectContext::startFastElement(nElement, xAttrList);
142
143 // set local parameters on shape
144 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
145 if(!xPropSet.is())
146 return;
147
148 // set parameters
149 drawing::Position3D aPosition3D;
150 drawing::Direction3D aDirection3D;
151
152 // convert from min, max to size to be set
154
155 aPosition3D.PositionX = maMinEdge.getX();
156 aPosition3D.PositionY = maMinEdge.getY();
157 aPosition3D.PositionZ = maMinEdge.getZ();
158
159 aDirection3D.DirectionX = maMaxEdge.getX();
160 aDirection3D.DirectionY = maMaxEdge.getY();
161 aDirection3D.DirectionZ = maMaxEdge.getZ();
162
163 xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
164 xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
165}
166
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)
174{
175 for(auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
176 {
177 switch(aIter.getToken())
178 {
179 case XML_ELEMENT(DR3D, XML_CENTER):
180 {
181 ::basegfx::B3DVector aNewVec;
182 SvXMLUnitConverter::convertB3DVector(aNewVec, aIter.toView());
183
184 if(aNewVec != maCenter)
185 maCenter = aNewVec;
186 break;
187 }
188 case XML_ELEMENT(DR3D, XML_SIZE):
189 {
190 ::basegfx::B3DVector aNewVec;
191 SvXMLUnitConverter::convertB3DVector(aNewVec, aIter.toView());
192
193 if(aNewVec != maSphereSize)
194 maSphereSize = aNewVec;
195 break;
196 }
197 default:
198 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
199 }
200 }
201}
202
204{
205}
206
208 sal_Int32 nElement,
209 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
210{
211 // create shape
212 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
213 if(!mxShape.is())
214 return;
215
216 // add, set style and properties from base shape
217 SetStyle();
218 SdXML3DObjectContext::startFastElement(nElement, xAttrList);
219
220 // set local parameters on shape
221 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
222 if(!xPropSet.is())
223 return;
224
225 // set parameters
226 drawing::Position3D aPosition3D;
227 drawing::Direction3D aDirection3D;
228
229 aPosition3D.PositionX = maCenter.getX();
230 aPosition3D.PositionY = maCenter.getY();
231 aPosition3D.PositionZ = maCenter.getZ();
232
233 aDirection3D.DirectionX = maSphereSize.getX();
234 aDirection3D.DirectionY = maSphereSize.getY();
235 aDirection3D.DirectionZ = maSphereSize.getZ();
236
237 xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
238 xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
239}
240
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 )
246{
247 for(auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList))
248 {
249 OUString sValue = aIter.toString();
250
251 switch(aIter.getToken())
252 {
254 case XML_ELEMENT(SVG_COMPAT, XML_VIEWBOX):
255 {
256 maViewBox = sValue;
257 break;
258 }
259 case XML_ELEMENT(SVG, XML_D):
260 case XML_ELEMENT(SVG_COMPAT, XML_D):
261 {
262 maPoints = sValue;
263 break;
264 }
265 default:
266 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
267 }
268 }
269}
270
272{
273}
274
276 sal_Int32 nElement,
277 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
278{
279 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
280
281 if(!xPropSet.is())
282 return;
283
284 // set parameters
285 if(!maPoints.isEmpty() && !maViewBox.isEmpty())
286 {
287 // import 2d tools::PolyPolygon from svg:d
288 basegfx::B2DPolyPolygon aPolyPolygon;
289
290 if(basegfx::utils::importFromSvgD(aPolyPolygon, maPoints, GetImport().needFixPositionAfterZ(), nullptr))
291 {
292 // convert to 3D PolyPolygon
293 const basegfx::B3DPolyPolygon aB3DPolyPolygon(
295 aPolyPolygon));
296
297 // convert to UNO API class PolyPolygonShape3D
298 drawing::PolyPolygonShape3D aPolyPolygon3D;
300 aB3DPolyPolygon,
301 aPolyPolygon3D);
302
303 // set polygon data
304 xPropSet->setPropertyValue("D3DPolyPolygon3D", uno::Any(aPolyPolygon3D));
305 }
306 else
307 {
308 OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
309 }
310 }
311
312 // call parent
313 SdXML3DObjectContext::startFastElement(nElement, xAttrList);
314}
315
316
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 )
322{
323}
324
326{
327}
328
330 sal_Int32 nElement,
331 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
332{
333 // create shape
334 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
335 if(mxShape.is())
336 {
337 // add, set style and properties from base shape
338 SetStyle();
340 }
341}
342
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 )
348{
349}
350
352{
353}
354
356 sal_Int32 nElement,
357 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
358{
359 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
360 if(mxShape.is())
361 {
362 // add, set style and properties from base shape
363 SetStyle();
365 }
366}
367
368
369/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
::basegfx::B3DVector maMaxEdge
::basegfx::B3DVector maMinEdge
SdXML3DCubeObjectShapeContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
virtual ~SdXML3DCubeObjectShapeContext() override
SdXML3DExtrudeObjectShapeContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
virtual ~SdXML3DExtrudeObjectShapeContext() override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual ~SdXML3DLatheObjectShapeContext() override
SdXML3DLatheObjectShapeContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
SdXML3DObjectContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
css::drawing::HomogenMatrix mxHomMat
virtual ~SdXML3DObjectContext() override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
SdXML3DPolygonBasedShapeContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual ~SdXML3DPolygonBasedShapeContext() override
SdXML3DSphereObjectShapeContext(SvXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
::basegfx::B3DVector maSphereSize
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
::basegfx::B3DVector maCenter
virtual ~SdXML3DSphereObjectShapeContext() override
bool GetFullHomogenTransform(css::drawing::HomogenMatrix &xHomMat)
Definition: xexptran.cxx:922
bool NeedsAction() const
Definition: xexptran.hxx:75
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: ximpshap.cxx:322
OUString maDrawStyleName
Definition: ximpshap.hxx:54
void AddShape(css::uno::Reference< css::drawing::XShape > &xShape)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
void SetStyle(bool bSupportsStyle=true)
if bSupportsStyle is false, auto styles will be set but not a style
Definition: ximpshap.cxx:599
css::uno::Reference< css::drawing::XShape > mxShape
static bool convertB3DVector(::basegfx::B3DVector &rVector, std::string_view rValue)
convert string to basegfx::B3DVector
Definition: xmluconv.cxx:587
TYPE getX() const
TYPE getZ() const
TYPE getY() const
DRAW
B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon &rCandidate, double fZCoordinate)
void B3DPolyPolygonToUnoPolyPolygonShape3D(const B3DPolyPolygon &rPolyPolygonSource, css::drawing::PolyPolygonShape3D &rPolyPolygonShape3DRetval)
bool importFromSvgD(B2DPolyPolygon &o_rPolyPoly, std::u16string_view rSvgDAttribute, bool bHandleRelativeNextPointCompatible, PointIndexSet *pHelpPointIndexSet)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97