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>
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>
31 
32 using namespace ::com::sun::star;
33 
34 
36  SvXMLImport& rImport,
37  sal_uInt16 nPrfx,
38  const OUString& rLocalName,
39  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
40  uno::Reference< drawing::XShapes > const & rShapes)
41 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, false/*bTemporaryShape*/ ),
42  mbSetTransform( false )
43 {
44  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
45  for(sal_Int16 i=0; i < nAttrCount; i++)
46  {
47  OUString sAttrName = xAttrList->getNameByIndex( i );
48  OUString aLocalName;
49  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
50  OUString sValue = xAttrList->getValueByIndex( i );
51  const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
52 
53  switch(rAttrTokenMap.Get(nPrefix, aLocalName))
54  {
56  {
57  maDrawStyleName = sValue;
58  break;
59  }
61  {
62  SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter());
63  if(aTransform.NeedsAction())
65  break;
66  }
67  }
68  }
69 }
70 
72 {
73 }
74 
75 void SdXML3DObjectContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
76 {
77  uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
78  if(xPropSet.is())
79  {
80  // set parameters
81  if(mbSetTransform)
82  {
83  xPropSet->setPropertyValue("D3DTransformMatrix", uno::Any(mxHomMat));
84  }
85 
86  // call parent
88  }
89 }
90 
92  SvXMLImport& rImport,
93  sal_uInt16 nPrfx,
94  const OUString& rLocalName,
95  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
96  uno::Reference< drawing::XShapes > const & rShapes)
97 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ),
98  maMinEdge(-2500.0, -2500.0, -2500.0),
99  maMaxEdge(2500.0, 2500.0, 2500.0)
100 {
101  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
102  for(sal_Int16 i=0; i < nAttrCount; i++)
103  {
104  OUString sAttrName = xAttrList->getNameByIndex( i );
105  OUString aLocalName;
106  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
107  OUString sValue = xAttrList->getValueByIndex( i );
108  const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
109 
110  switch(rAttrTokenMap.Get(nPrefix, aLocalName))
111  {
113  {
114  ::basegfx::B3DVector aNewVec;
115  SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
116 
117  if(aNewVec != maMinEdge)
118  maMinEdge = aNewVec;
119  break;
120  }
122  {
123  ::basegfx::B3DVector aNewVec;
124  SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
125 
126  if(aNewVec != maMaxEdge)
127  maMaxEdge = aNewVec;
128  break;
129  }
130  }
131  }
132 }
133 
135 {
136 }
137 
138 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
139 {
140  // create shape
141  AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
142  if(!mxShape.is())
143  return;
144 
145  // add, set style and properties from base shape
146  SetStyle();
148 
149  // set local parameters on shape
150  uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
151  if(!xPropSet.is())
152  return;
153 
154  // set parameters
155  drawing::Position3D aPosition3D;
156  drawing::Direction3D aDirection3D;
157 
158  // convert from min, max to size to be set
160 
161  aPosition3D.PositionX = maMinEdge.getX();
162  aPosition3D.PositionY = maMinEdge.getY();
163  aPosition3D.PositionZ = maMinEdge.getZ();
164 
165  aDirection3D.DirectionX = maMaxEdge.getX();
166  aDirection3D.DirectionY = maMaxEdge.getY();
167  aDirection3D.DirectionZ = maMaxEdge.getZ();
168 
169  xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
170  xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
171 }
172 
174  SvXMLImport& rImport,
175  sal_uInt16 nPrfx,
176  const OUString& rLocalName,
177  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
178  uno::Reference< drawing::XShapes > const & rShapes)
179 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ),
180  maCenter(0.0, 0.0, 0.0),
181  maSphereSize(5000.0, 5000.0, 5000.0)
182 {
183  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
184  for(sal_Int16 i=0; i < nAttrCount; i++)
185  {
186  OUString sAttrName = xAttrList->getNameByIndex( i );
187  OUString aLocalName;
188  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
189  OUString sValue = xAttrList->getValueByIndex( i );
190  const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
191 
192  switch(rAttrTokenMap.Get(nPrefix, aLocalName))
193  {
195  {
196  ::basegfx::B3DVector aNewVec;
197  SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
198 
199  if(aNewVec != maCenter)
200  maCenter = aNewVec;
201  break;
202  }
204  {
205  ::basegfx::B3DVector aNewVec;
206  SvXMLUnitConverter::convertB3DVector(aNewVec, sValue);
207 
208  if(aNewVec != maSphereSize)
209  maSphereSize = aNewVec;
210  break;
211  }
212  }
213  }
214 }
215 
217 {
218 }
219 
220 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
221 {
222  // create shape
223  AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
224  if(!mxShape.is())
225  return;
226 
227  // add, set style and properties from base shape
228  SetStyle();
230 
231  // set local parameters on shape
232  uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
233  if(!xPropSet.is())
234  return;
235 
236  // set parameters
237  drawing::Position3D aPosition3D;
238  drawing::Direction3D aDirection3D;
239 
240  aPosition3D.PositionX = maCenter.getX();
241  aPosition3D.PositionY = maCenter.getY();
242  aPosition3D.PositionZ = maCenter.getZ();
243 
244  aDirection3D.DirectionX = maSphereSize.getX();
245  aDirection3D.DirectionY = maSphereSize.getY();
246  aDirection3D.DirectionZ = maSphereSize.getZ();
247 
248  xPropSet->setPropertyValue("D3DPosition", uno::Any(aPosition3D));
249  xPropSet->setPropertyValue("D3DSize", uno::Any(aDirection3D));
250 }
251 
253  SvXMLImport& rImport,
254  sal_uInt16 nPrfx,
255  const OUString& rLocalName,
256  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
257  uno::Reference< drawing::XShapes > const & rShapes)
258 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
259 {
260  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
261  for(sal_Int16 i=0; i < nAttrCount; i++)
262  {
263  OUString sAttrName = xAttrList->getNameByIndex( i );
264  OUString aLocalName;
265  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
266  OUString sValue = xAttrList->getValueByIndex( i );
267  const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
268 
269  switch(rAttrTokenMap.Get(nPrefix, aLocalName))
270  {
272  {
273  maViewBox = sValue;
274  break;
275  }
277  {
278  maPoints = sValue;
279  break;
280  }
281  }
282  }
283 }
284 
286 {
287 }
288 
289 void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
290 {
291  uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
292 
293  if(!xPropSet.is())
294  return;
295 
296  // set parameters
297  if(!maPoints.isEmpty() && !maViewBox.isEmpty())
298  {
299  // import 2d tools::PolyPolygon from svg:d
300  basegfx::B2DPolyPolygon aPolyPolygon;
301 
302  if(basegfx::utils::importFromSvgD(aPolyPolygon, maPoints, GetImport().needFixPositionAfterZ(), nullptr))
303  {
304  // convert to 3D PolyPolygon
305  const basegfx::B3DPolyPolygon aB3DPolyPolygon(
307  aPolyPolygon));
308 
309  // convert to UNO API class PolyPolygonShape3D
310  drawing::PolyPolygonShape3D aPolyPolygon3D;
312  aB3DPolyPolygon,
313  aPolyPolygon3D);
314 
315  // set polygon data
316  xPropSet->setPropertyValue("D3DPolyPolygon3D", uno::Any(aPolyPolygon3D));
317  }
318  else
319  {
320  OSL_ENSURE(false, "Error on importing svg:d for 3D tools::PolyPolygon (!)");
321  }
322  }
323 
324  // call parent
326 }
327 
328 
330  SvXMLImport& rImport,
331  sal_uInt16 nPrfx,
332  const OUString& rLocalName,
333  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
334  uno::Reference< drawing::XShapes > const & rShapes)
335 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
336 {
337 }
338 
340 {
341 }
342 
343 void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
344 {
345  // create shape
346  AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
347  if(mxShape.is())
348  {
349  // add, set style and properties from base shape
350  SetStyle();
352  }
353 }
354 
356  SvXMLImport& rImport,
357  sal_uInt16 nPrfx,
358  const OUString& rLocalName,
359  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
360  uno::Reference< drawing::XShapes > const & rShapes)
361 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
362 {
363 }
364 
366 {
367 }
368 
369 void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
370 {
371  AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
372  if(mxShape.is())
373  {
374  // add, set style and properties from base shape
375  SetStyle();
377  }
378 }
379 
380 
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
void B3DPolyPolygonToUnoPolyPolygonShape3D(const B3DPolyPolygon &rPolyPolygonSource, css::drawing::PolyPolygonShape3D &rPolyPolygonShape3DRetval)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:402
bool importFromSvgD(B2DPolyPolygon &o_rPolyPoly, const OUString &rSvgDAttribute, bool bHandleRelativeNextPointCompatible, PointIndexSet *pHelpPointIndexSet)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
bool GetFullHomogenTransform(css::drawing::HomogenMatrix &xHomMat)
Definition: xexptran.cxx:918
void AddShape(css::uno::Reference< css::drawing::XShape > &xShape)
virtual ~SdXML3DPolygonBasedShapeContext() override
B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon &rCandidate, double fZCoordinate)
SdXML3DObjectContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
css::drawing::HomogenMatrix mxHomMat
virtual ~SdXML3DCubeObjectShapeContext() override
SdXML3DSphereObjectShapeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
SdXML3DPolygonBasedShapeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
int i
::basegfx::B3DVector maMinEdge
::basegfx::B3DVector maMaxEdge
SdXML3DExtrudeObjectShapeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
bool NeedsAction() const
Definition: xexptran.hxx:76
css::uno::Reference< css::drawing::XShape > mxShape
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
Definition: xmltkmap.cxx:99
OUString maDrawStyleName
Definition: ximpshap.hxx:55
virtual ~SdXML3DObjectContext() override
SdXML3DCubeObjectShapeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
static bool convertB3DVector(::basegfx::B3DVector &rVector, const OUString &rValue)
convert string to basegfx::B3DVector
Definition: xmluconv.cxx:507
virtual ~SdXML3DExtrudeObjectShapeContext() override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
Definition: ximpshap.cxx:341
virtual ~SdXML3DLatheObjectShapeContext() override
::basegfx::B3DVector maCenter
void SetStyle(bool bSupportsStyle=true)
if bSupportsStyle is false, auto styles will be set but not a style
Definition: ximpshap.cxx:611
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
virtual ~SdXML3DSphereObjectShapeContext() override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
SdXML3DLatheObjectShapeContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
::basegfx::B3DVector maSphereSize
rtl::Reference< XMLShapeImportHelper > const & GetShapeImport()
Definition: xmlimp.hxx:608