1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ximp3dobject.cxx,v $
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(
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
);
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
;
84 case XML_TOK_3DOBJECT_TRANSFORM
:
86 SdXMLImExTransform3D
aTransform(sValue
, GetImport().GetMM100UnitConverter());
87 if(aTransform
.NeedsAction())
88 mbSetTransform
= aTransform
.GetFullHomogenTransform(mxHomMat
);
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
);
113 xPropSet
->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")), aAny
);
117 SdXMLShapeContext::StartElement(xAttrList
);
121 //////////////////////////////////////////////////////////////////////////////
123 void SdXML3DObjectContext::EndElement()
126 SdXMLShapeContext::EndElement();
129 //////////////////////////////////////////////////////////////////////////////
131 void SdXML3DObjectContext::AddShape(uno::Reference< drawing::XShape >& xShape)
133 if(xShape.is() && mxShapes.is())
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);
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);
169 XMLShapeStyleContext* pDocStyle = (XMLShapeStyleContext*)pStyle;
171 if(pDocStyle->GetStyle().is())
173 // set style on object
175 aAny <<= pDocStyle->GetStyle();
176 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style")), aAny);
181 // set PropertySet on object
182 pDocStyle->FillPropertySet(xPropSet);
189 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
190 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192 TYPEINIT1( SdXML3DCubeObjectShapeContext
, SdXML3DObjectContext
);
194 SdXML3DCubeObjectShapeContext::SdXML3DCubeObjectShapeContext(
195 SvXMLImport
& rImport
,
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
),
207 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
208 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
210 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
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
)
226 mbMinEdgeUsed
= TRUE
;
230 case XML_TOK_3DCUBEOBJ_MAXEDGE
:
232 ::basegfx::B3DVector aNewVec
;
233 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec
, sValue
);
235 if(aNewVec
!= maMaxEdge
)
238 mbMaxEdgeUsed
= TRUE
;
246 //////////////////////////////////////////////////////////////////////////////
248 SdXML3DCubeObjectShapeContext::~SdXML3DCubeObjectShapeContext()
252 //////////////////////////////////////////////////////////////////////////////
254 void SdXML3DCubeObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
257 AddShape( "com.sun.star.drawing.Shape3DCubeObject" );
260 // add, set style and properties from base shape
262 SdXML3DObjectContext::StartElement(xAttrList
);
264 // set local parameters on shape
265 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
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();
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()
297 SdXML3DObjectContext::EndElement();
300 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
301 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
303 TYPEINIT1( SdXML3DSphereObjectShapeContext
, SdXML3DObjectContext
);
305 SdXML3DSphereObjectShapeContext::SdXML3DSphereObjectShapeContext(
306 SvXMLImport
& rImport
,
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),
318 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
319 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
321 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
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
)
341 case XML_TOK_3DSPHEREOBJ_SIZE
:
343 ::basegfx::B3DVector aNewVec
;
344 GetImport().GetMM100UnitConverter().convertB3DVector(aNewVec
, sValue
);
346 if(aNewVec
!= maSize
)
357 //////////////////////////////////////////////////////////////////////////////
359 SdXML3DSphereObjectShapeContext::~SdXML3DSphereObjectShapeContext()
363 //////////////////////////////////////////////////////////////////////////////
365 void SdXML3DSphereObjectShapeContext::StartElement(const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
368 AddShape( "com.sun.star.drawing.Shape3DSphereObject" );
371 // add, set style and properties from base shape
373 SdXML3DObjectContext::StartElement(xAttrList
);
375 // set local parameters on shape
376 uno::Reference
< beans::XPropertySet
> xPropSet(mxShape
, uno::UNO_QUERY
);
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();
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()
405 SdXML3DObjectContext::EndElement();
408 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
411 TYPEINIT1( SdXML3DPolygonBasedShapeContext
, SdXML3DObjectContext
);
413 SdXML3DPolygonBasedShapeContext::SdXML3DPolygonBasedShapeContext(
414 SvXMLImport
& rImport
,
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
);
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
:
438 case XML_TOK_3DPOLYGONBASED_D
:
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
);
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;
511 aAny
<<= xPolyPolygon3D
;
512 xPropSet
->setPropertyValue(
513 OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPolyPolygon3D")), aAny
);
517 SdXML3DObjectContext::StartElement(xAttrList
);
521 //////////////////////////////////////////////////////////////////////////////
523 void SdXML3DPolygonBasedShapeContext::EndElement()
526 SdXML3DObjectContext::EndElement();
529 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
530 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
532 TYPEINIT1( SdXML3DLatheObjectShapeContext
, SdXML3DPolygonBasedShapeContext
);
534 SdXML3DLatheObjectShapeContext::SdXML3DLatheObjectShapeContext(
535 SvXMLImport
& rImport
,
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
)
556 AddShape( "com.sun.star.drawing.Shape3DLatheObject" );
559 // add, set style and properties from base shape
561 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
565 //////////////////////////////////////////////////////////////////////////////
567 void SdXML3DLatheObjectShapeContext::EndElement()
570 SdXML3DPolygonBasedShapeContext::EndElement();
573 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
576 TYPEINIT1( SdXML3DExtrudeObjectShapeContext
, SdXML3DPolygonBasedShapeContext
);
578 SdXML3DExtrudeObjectShapeContext::SdXML3DExtrudeObjectShapeContext(
579 SvXMLImport
& rImport
,
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" );
602 // add, set style and properties from base shape
604 SdXML3DPolygonBasedShapeContext::StartElement(xAttrList
);
608 //////////////////////////////////////////////////////////////////////////////
610 void SdXML3DExtrudeObjectShapeContext::EndElement()
613 SdXML3DPolygonBasedShapeContext::EndElement();