merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / ximp3dobject.cxx
blob878f9bcf6ef46d1e69ea4f8db30953cd394c54e0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ximp3dobject.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <comphelper/extract.hxx>
34 #include "ximp3dobject.hxx"
35 #include <xmloff/XMLShapeStyleContext.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
39 #include <com/sun/star/drawing/PointSequence.hpp>
40 #include "xexptran.hxx"
41 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
42 #include <xmloff/families.hxx>
43 #include "ximpstyl.hxx"
44 #include <xmloff/xmltoken.hxx>
45 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
46 #include <com/sun/star/drawing/DoubleSequence.hpp>
48 using ::rtl::OUString;
49 using ::rtl::OUStringBuffer;
51 using namespace ::com::sun::star;
53 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56 TYPEINIT1( SdXML3DObjectContext, SdXMLShapeContext );
58 SdXML3DObjectContext::SdXML3DObjectContext(
59 SvXMLImport& rImport,
60 sal_uInt16 nPrfx,
61 const OUString& rLocalName,
62 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
63 uno::Reference< drawing::XShapes >& rShapes,
64 sal_Bool bTemporaryShape)
65 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
66 mbSetTransform( FALSE )
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 for(sal_Int16 i=0; i < nAttrCount; i++)
71 OUString sAttrName = xAttrList->getNameByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
74 OUString sValue = xAttrList->getValueByIndex( i );
75 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DObjectAttrTokenMap();
77 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
79 case XML_TOK_3DOBJECT_DRAWSTYLE_NAME:
81 maDrawStyleName = sValue;
82 break;
84 case XML_TOK_3DOBJECT_TRANSFORM:
86 SdXMLImExTransform3D aTransform(sValue, GetImport().GetMM100UnitConverter());
87 if(aTransform.NeedsAction())
88 mbSetTransform = aTransform.GetFullHomogenTransform(mxHomMat);
89 break;
95 //////////////////////////////////////////////////////////////////////////////
97 SdXML3DObjectContext::~SdXML3DObjectContext()
101 //////////////////////////////////////////////////////////////////////////////
103 void SdXML3DObjectContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
105 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
106 if(xPropSet.is())
108 // set parameters
109 if(mbSetTransform)
111 uno::Any aAny;
112 aAny <<= mxHomMat;
113 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")), aAny);
116 // call parent
117 SdXMLShapeContext::StartElement(xAttrList);
121 //////////////////////////////////////////////////////////////////////////////
123 void SdXML3DObjectContext::EndElement()
125 // call parent
126 SdXMLShapeContext::EndElement();
129 //////////////////////////////////////////////////////////////////////////////
131 void SdXML3DObjectContext::AddShape(uno::Reference< drawing::XShape >& xShape)
133 if(xShape.is() && mxShapes.is())
135 // set shape local
136 mxShape = xShape;
138 // add new shape to parent
139 mxShapes->add( xShape );
143 //////////////////////////////////////////////////////////////////////////////
145 void SdXML3DObjectContext::SetStyle()
147 // set style on shape
148 if(maDrawStyleName.getLength() && mxShape.is())
150 const SvXMLStyleContext* pStyle = 0L;
151 sal_Bool bAutoStyle(FALSE);
153 if(GetImport().GetShapeImport()->GetAutoStylesContext())
154 pStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(
155 XML_STYLE_FAMILY_SD_GRAPHICS_ID, maDrawStyleName);
157 if(pStyle)
158 bAutoStyle = TRUE;
160 if(!pStyle && GetImport().GetShapeImport()->GetStylesContext())
161 pStyle = GetImport().GetShapeImport()->GetStylesContext()->
162 FindStyleChildContext(XML_STYLE_FAMILY_SD_GRAPHICS_ID, maDrawStyleName);
164 if(pStyle && pStyle->ISA(XMLShapeStyleContext))
166 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
167 if(xPropSet.is())
169 XMLShapeStyleContext* pDocStyle = (XMLShapeStyleContext*)pStyle;
171 if(pDocStyle->GetStyle().is())
173 // set style on object
174 uno::Any aAny;
175 aAny <<= pDocStyle->GetStyle();
176 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style")), aAny);
179 if(bAutoStyle)
181 // set PropertySet on object
182 pDocStyle->FillPropertySet(xPropSet);
189 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
190 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192 TYPEINIT1( SdXML3DCubeObjectShapeContext, SdXML3DObjectContext);
194 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
195 SvXMLImport& rImport,
196 sal_uInt16 nPrfx,
197 const OUString& rLocalName,
198 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
199 uno::Reference< drawing::XShapes >& rShapes,
200 sal_Bool bTemporaryShape)
201 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
202 maMinEdge(-2500.0, -2500.0, -2500.0),
203 maMaxEdge(2500.0, 2500.0, 2500.0),
204 mbMinEdgeUsed(FALSE),
205 mbMaxEdgeUsed(FALSE)
207 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
208 for(sal_Int16 i=0; i < nAttrCount; i++)
210 OUString sAttrName = xAttrList->getNameByIndex( i );
211 OUString aLocalName;
212 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
213 OUString sValue = xAttrList->getValueByIndex( i );
214 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DCubeObjectAttrTokenMap();
216 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
218 case XML_TOK_3DCUBEOBJ_MINEDGE:
220 ::basegfx::B3DVector aNewVec;
221 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
223 if(aNewVec != maMinEdge)
225 maMinEdge = aNewVec;
226 mbMinEdgeUsed = TRUE;
228 break;
230 case XML_TOK_3DCUBEOBJ_MAXEDGE:
232 ::basegfx::B3DVector aNewVec;
233 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
235 if(aNewVec != maMaxEdge)
237 maMaxEdge = aNewVec;
238 mbMaxEdgeUsed = TRUE;
240 break;
246 //////////////////////////////////////////////////////////////////////////////
248 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
252 //////////////////////////////////////////////////////////////////////////////
254 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
256 // create shape
257 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
258 if(mxShape.is())
260 // add, set style and properties from base shape
261 SetStyle();
262 SdXML3DObjectContext::StartElement(xAttrList);
264 // set local parameters on shape
265 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
266 if(xPropSet.is())
268 // set parameters
269 drawing::Position3D aPosition3D;
270 drawing::Direction3D aDirection3D;
272 // convert from min, max to size to be set
273 maMaxEdge = maMaxEdge - maMinEdge;
275 aPosition3D.PositionX = maMinEdge.getX();
276 aPosition3D.PositionY = maMinEdge.getY();
277 aPosition3D.PositionZ = maMinEdge.getZ();
279 aDirection3D.DirectionX = maMaxEdge.getX();
280 aDirection3D.DirectionY = maMaxEdge.getY();
281 aDirection3D.DirectionZ = maMaxEdge.getZ();
283 uno::Any aAny;
284 aAny <<= aPosition3D;
285 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")), aAny);
286 aAny <<= aDirection3D;
287 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")), aAny);
292 //////////////////////////////////////////////////////////////////////////////
294 void SdXML3DCubeObjectShapeContext::EndElement()
296 // call parent
297 SdXML3DObjectContext::EndElement();
300 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
301 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
303 TYPEINIT1( SdXML3DSphereObjectShapeContext, SdXML3DObjectContext);
305 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
306 SvXMLImport& rImport,
307 sal_uInt16 nPrfx,
308 const OUString& rLocalName,
309 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
310 uno::Reference< drawing::XShapes >& rShapes,
311 sal_Bool bTemporaryShape)
312 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
313 maCenter(0.0, 0.0, 0.0),
314 maSize(5000.0, 5000.0, 5000.0),
315 mbCenterUsed(FALSE),
316 mbSizeUsed(FALSE)
318 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
319 for(sal_Int16 i=0; i < nAttrCount; i++)
321 OUString sAttrName = xAttrList->getNameByIndex( i );
322 OUString aLocalName;
323 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
324 OUString sValue = xAttrList->getValueByIndex( i );
325 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DSphereObjectAttrTokenMap();
327 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
329 case XML_TOK_3DSPHEREOBJ_CENTER:
331 ::basegfx::B3DVector aNewVec;
332 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
334 if(aNewVec != maCenter)
336 maCenter = aNewVec;
337 mbCenterUsed = TRUE;
339 break;
341 case XML_TOK_3DSPHEREOBJ_SIZE:
343 ::basegfx::B3DVector aNewVec;
344 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec, sValue);
346 if(aNewVec != maSize)
348 maSize = aNewVec;
349 mbSizeUsed = TRUE;
351 break;
357 //////////////////////////////////////////////////////////////////////////////
359 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
363 //////////////////////////////////////////////////////////////////////////////
365 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
367 // create shape
368 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
369 if(mxShape.is())
371 // add, set style and properties from base shape
372 SetStyle();
373 SdXML3DObjectContext::StartElement(xAttrList);
375 // set local parameters on shape
376 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
377 if(xPropSet.is())
379 // set parameters
380 drawing::Position3D aPosition3D;
381 drawing::Direction3D aDirection3D;
383 aPosition3D.PositionX = maCenter.getX();
384 aPosition3D.PositionY = maCenter.getY();
385 aPosition3D.PositionZ = maCenter.getZ();
387 aDirection3D.DirectionX = maSize.getX();
388 aDirection3D.DirectionY = maSize.getY();
389 aDirection3D.DirectionZ = maSize.getZ();
391 uno::Any aAny;
392 aAny <<= aPosition3D;
393 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")), aAny);
394 aAny <<= aDirection3D;
395 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")), aAny);
400 //////////////////////////////////////////////////////////////////////////////
402 void SdXML3DSphereObjectShapeContext::EndElement()
404 // call parent
405 SdXML3DObjectContext::EndElement();
408 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
411 TYPEINIT1( SdXML3DPolygonBasedShapeContext, SdXML3DObjectContext );
413 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
414 SvXMLImport& rImport,
415 sal_uInt16 nPrfx,
416 const OUString& rLocalName,
417 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
418 uno::Reference< drawing::XShapes >& rShapes,
419 sal_Bool bTemporaryShape)
420 : SdXML3DObjectContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
422 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
423 for(sal_Int16 i=0; i < nAttrCount; i++)
425 OUString sAttrName = xAttrList->getNameByIndex( i );
426 OUString aLocalName;
427 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
428 OUString sValue = xAttrList->getValueByIndex( i );
429 const SvXMLTokenMap& rAttrTokenMap = GetImport().GetShapeImport()->Get3DPolygonBasedAttrTokenMap();
431 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
433 case XML_TOK_3DPOLYGONBASED_VIEWBOX:
435 maViewBox = sValue;
436 break;
438 case XML_TOK_3DPOLYGONBASED_D:
440 maPoints = sValue;
441 break;
447 //////////////////////////////////////////////////////////////////////////////
449 SdXML3DPolygonBasedShapeContext::~SdXML3DPolygonBasedShapeContext()
453 //////////////////////////////////////////////////////////////////////////////
455 void SdXML3DPolygonBasedShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
457 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
458 if(xPropSet.is())
460 // set parameters
461 if(maPoints.getLength() && maViewBox.getLength())
463 SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter());
464 awt::Point aMinPoint(aViewBox.GetX(), aViewBox.GetY());
465 awt::Size aMaxSize(aViewBox.GetWidth(), aViewBox.GetHeight());
466 SdXMLImExSvgDElement aPoints(maPoints, aViewBox,
467 aMinPoint, aMaxSize, GetImport().GetMM100UnitConverter());
469 // convert to double sequences
470 drawing::PointSequenceSequence& xPoSeSe =
471 (drawing::PointSequenceSequence&)aPoints.GetPointSequenceSequence();
472 sal_Int32 nOuterSequenceCount = xPoSeSe.getLength();
473 drawing::PointSequence* pInnerSequence = xPoSeSe.getArray();
475 drawing::PolyPolygonShape3D xPolyPolygon3D;
476 xPolyPolygon3D.SequenceX.realloc(nOuterSequenceCount);
477 xPolyPolygon3D.SequenceY.realloc(nOuterSequenceCount);
478 xPolyPolygon3D.SequenceZ.realloc(nOuterSequenceCount);
479 drawing::DoubleSequence* pOuterSequenceX = xPolyPolygon3D.SequenceX.getArray();
480 drawing::DoubleSequence* pOuterSequenceY = xPolyPolygon3D.SequenceY.getArray();
481 drawing::DoubleSequence* pOuterSequenceZ = xPolyPolygon3D.SequenceZ.getArray();
483 for(sal_Int32 a(0L); a < nOuterSequenceCount; a++)
485 sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
486 awt::Point* pArray = pInnerSequence->getArray();
488 pOuterSequenceX->realloc(nInnerSequenceCount);
489 pOuterSequenceY->realloc(nInnerSequenceCount);
490 pOuterSequenceZ->realloc(nInnerSequenceCount);
491 double* pInnerSequenceX = pOuterSequenceX->getArray();
492 double* pInnerSequenceY = pOuterSequenceY->getArray();
493 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
495 for(sal_Int32 b(0L); b < nInnerSequenceCount; b++)
497 *pInnerSequenceX++ = pArray->X;
498 *pInnerSequenceY++ = pArray->Y;
499 *pInnerSequenceZ++ = 0.0;
500 pArray++;
502 pInnerSequence++;
504 pOuterSequenceX++;
505 pOuterSequenceY++;
506 pOuterSequenceZ++;
509 // set poly
510 uno::Any aAny;
511 aAny <<= xPolyPolygon3D;
512 xPropSet->setPropertyValue(
513 OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPolyPolygon3D")), aAny);
516 // call parent
517 SdXML3DObjectContext::StartElement(xAttrList);
521 //////////////////////////////////////////////////////////////////////////////
523 void SdXML3DPolygonBasedShapeContext::EndElement()
525 // call parent
526 SdXML3DObjectContext::EndElement();
529 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
530 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
532 TYPEINIT1( SdXML3DLatheObjectShapeContext, SdXML3DPolygonBasedShapeContext);
534 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
535 SvXMLImport& rImport,
536 sal_uInt16 nPrfx,
537 const OUString& rLocalName,
538 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
539 uno::Reference< drawing::XShapes >& rShapes,
540 sal_Bool bTemporaryShape)
541 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
545 //////////////////////////////////////////////////////////////////////////////
547 SdXML3DLatheObjectShapeContext::~SdXML3DLatheObjectShapeContext()
551 //////////////////////////////////////////////////////////////////////////////
553 void SdXML3DLatheObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
555 // create shape
556 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
557 if(mxShape.is())
559 // add, set style and properties from base shape
560 SetStyle();
561 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
565 //////////////////////////////////////////////////////////////////////////////
567 void SdXML3DLatheObjectShapeContext::EndElement()
569 // call parent
570 SdXML3DPolygonBasedShapeContext::EndElement();
573 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
576 TYPEINIT1( SdXML3DExtrudeObjectShapeContext, SdXML3DPolygonBasedShapeContext);
578 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
579 SvXMLImport& rImport,
580 sal_uInt16 nPrfx,
581 const OUString& rLocalName,
582 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
583 uno::Reference< drawing::XShapes >& rShapes,
584 sal_Bool bTemporaryShape)
585 : SdXML3DPolygonBasedShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
589 //////////////////////////////////////////////////////////////////////////////
591 SdXML3DExtrudeObjectShapeContext::~SdXML3DExtrudeObjectShapeContext()
595 //////////////////////////////////////////////////////////////////////////////
597 void SdXML3DExtrudeObjectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
599 AddShape( "com.sun.star.drawing.Shape3DExtrudeObject" );
600 if(mxShape.is())
602 // add, set style and properties from base shape
603 SetStyle();
604 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList);
608 //////////////////////////////////////////////////////////////////////////////
610 void SdXML3DExtrudeObjectShapeContext::EndElement()
612 // call parent
613 SdXML3DPolygonBasedShapeContext::EndElement();
616 // EOF