1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/drawing/ProjectionMode.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/drawing/ShadeMode.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/drawing/Direction3D.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/drawing/Position3D.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/drawing/CameraGeometry.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/drawing/DoubleSequence.hpp>
38*cdf0e10cSrcweir #include <tools/gen.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #ifndef _XMLOFF_SHAPEEXPORT_HXX
41*cdf0e10cSrcweir #include <xmloff/shapeexport.hxx>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #include "sdpropls.hxx"
44*cdf0e10cSrcweir #include <tools/debug.hxx>
45*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
46*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
47*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
48*cdf0e10cSrcweir #include "xexptran.hxx"
49*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
50*cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using ::rtl::OUString;
55*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir using namespace ::xmloff::token;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir void XMLShapeExport::ImpExport3DSceneShape( const uno::Reference< drawing::XShape >& xShape, XmlShapeType, sal_Int32 nFeatures, awt::Point* pRefPoint)
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir 	uno::Reference< drawing::XShapes > xShapes(xShape, uno::UNO_QUERY);
66*cdf0e10cSrcweir 	if(xShapes.is() && xShapes->getCount())
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
69*cdf0e10cSrcweir 		DBG_ASSERT( xPropSet.is(), "XMLShapeExport::ImpExport3DSceneShape can't export a scene without a propertyset" );
70*cdf0e10cSrcweir 		if( xPropSet.is() )
71*cdf0e10cSrcweir 		{
72*cdf0e10cSrcweir 			// Transformation
73*cdf0e10cSrcweir 			ImpExportNewTrans(xPropSet, nFeatures, pRefPoint);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 			// 3d attributes
76*cdf0e10cSrcweir 			export3DSceneAttributes( xPropSet );
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 			// write 3DScene shape
79*cdf0e10cSrcweir 			sal_Bool bCreateNewline( (nFeatures & SEF_EXPORT_NO_WS) == 0 ); // #86116#/#92210#
80*cdf0e10cSrcweir 			SvXMLElementExport aOBJ( mrExport, XML_NAMESPACE_DR3D, XML_SCENE, bCreateNewline, sal_True);
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 			ImpExportDescription( xShape ); // #i68101#
83*cdf0e10cSrcweir 			ImpExportEvents( xShape );
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 			// write 3DSceneLights
86*cdf0e10cSrcweir 			export3DLamps( xPropSet );
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 			// #89764# if export of position is supressed for group shape,
89*cdf0e10cSrcweir 			// positions of contained objects should be written relative to
90*cdf0e10cSrcweir 			// the upper left edge of the group.
91*cdf0e10cSrcweir 			awt::Point aUpperLeft;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 			if(!(nFeatures & SEF_EXPORT_POSITION))
94*cdf0e10cSrcweir 			{
95*cdf0e10cSrcweir 				nFeatures |= SEF_EXPORT_POSITION;
96*cdf0e10cSrcweir 				aUpperLeft = xShape->getPosition();
97*cdf0e10cSrcweir 				pRefPoint = &aUpperLeft;
98*cdf0e10cSrcweir 			}
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 			// write members
101*cdf0e10cSrcweir 			exportShapes( xShapes, nFeatures, pRefPoint );
102*cdf0e10cSrcweir 		}
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void XMLShapeExport::ImpExport3DShape(
109*cdf0e10cSrcweir 	const uno::Reference< drawing::XShape >& xShape,
110*cdf0e10cSrcweir 	XmlShapeType eShapeType, sal_Int32 /* nFeatures = SEF_DEFAULT */, awt::Point* /*pRefPoint = NULL */)
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir 	const uno::Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY);
113*cdf0e10cSrcweir 	if(xPropSet.is())
114*cdf0e10cSrcweir 	{
115*cdf0e10cSrcweir 		OUString aStr;
116*cdf0e10cSrcweir 		OUStringBuffer sStringBuffer;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 		// transformation (UNO_NAME_3D_TRANSFORM_MATRIX == "D3DTransformMatrix")
119*cdf0e10cSrcweir 		uno::Any aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")));
120*cdf0e10cSrcweir 		drawing::HomogenMatrix xHomMat;
121*cdf0e10cSrcweir 		aAny >>= xHomMat;
122*cdf0e10cSrcweir 		SdXMLImExTransform3D aTransform;
123*cdf0e10cSrcweir 		aTransform.AddHomogenMatrix(xHomMat);
124*cdf0e10cSrcweir 		if(aTransform.NeedsAction())
125*cdf0e10cSrcweir 			mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_TRANSFORM, aTransform.GetExportString(mrExport.GetMM100UnitConverter()));
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 		switch(eShapeType)
128*cdf0e10cSrcweir 		{
129*cdf0e10cSrcweir 			case XmlShapeTypeDraw3DCubeObject:
130*cdf0e10cSrcweir 			{
131*cdf0e10cSrcweir 				// write 3DCube shape
132*cdf0e10cSrcweir 				SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_CUBE, sal_True, sal_True);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 				// minEdge
135*cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")));
136*cdf0e10cSrcweir 				drawing::Position3D aPosition3D;
137*cdf0e10cSrcweir 				aAny >>= aPosition3D;
138*cdf0e10cSrcweir 				::basegfx::B3DVector aPos3D(aPosition3D.PositionX, aPosition3D.PositionY, aPosition3D.PositionZ);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 				// maxEdge
141*cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")));
142*cdf0e10cSrcweir 				drawing::Direction3D aDirection3D;
143*cdf0e10cSrcweir 				aAny >>= aDirection3D;
144*cdf0e10cSrcweir 				::basegfx::B3DVector aDir3D(aDirection3D.DirectionX, aDirection3D.DirectionY, aDirection3D.DirectionZ);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 				// transform maxEdge from distance to pos
147*cdf0e10cSrcweir 				aDir3D = aPos3D + aDir3D;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 				// write minEdge
150*cdf0e10cSrcweir 				if(aPos3D != ::basegfx::B3DVector(-2500.0, -2500.0, -2500.0)) // write only when not default
151*cdf0e10cSrcweir 				{
152*cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aPos3D);
153*cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
154*cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_MIN_EDGE, aStr);
155*cdf0e10cSrcweir 				}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 				// write maxEdge
158*cdf0e10cSrcweir 				if(aDir3D != ::basegfx::B3DVector(2500.0, 2500.0, 2500.0)) // write only when not default
159*cdf0e10cSrcweir 				{
160*cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aDir3D);
161*cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
162*cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_MAX_EDGE, aStr);
163*cdf0e10cSrcweir 				}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 				break;
166*cdf0e10cSrcweir 			}
167*cdf0e10cSrcweir 			case XmlShapeTypeDraw3DSphereObject:
168*cdf0e10cSrcweir 			{
169*cdf0e10cSrcweir 				// write 3DSphere shape
170*cdf0e10cSrcweir 				SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_SPHERE, sal_True, sal_True);
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 				// Center
173*cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")));
174*cdf0e10cSrcweir 				drawing::Position3D aPosition3D;
175*cdf0e10cSrcweir 				aAny >>= aPosition3D;
176*cdf0e10cSrcweir 				::basegfx::B3DVector aPos3D(aPosition3D.PositionX, aPosition3D.PositionY, aPosition3D.PositionZ);
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 				// Size
179*cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")));
180*cdf0e10cSrcweir 				drawing::Direction3D aDirection3D;
181*cdf0e10cSrcweir 				aAny >>= aDirection3D;
182*cdf0e10cSrcweir 				::basegfx::B3DVector aDir3D(aDirection3D.DirectionX, aDirection3D.DirectionY, aDirection3D.DirectionZ);
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 				// write Center
185*cdf0e10cSrcweir 				if(aPos3D != ::basegfx::B3DVector(0.0, 0.0, 0.0)) // write only when not default
186*cdf0e10cSrcweir 				{
187*cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aPos3D);
188*cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
189*cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_CENTER, aStr);
190*cdf0e10cSrcweir 				}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 				// write Size
193*cdf0e10cSrcweir 				if(aDir3D != ::basegfx::B3DVector(5000.0, 5000.0, 5000.0)) // write only when not default
194*cdf0e10cSrcweir 				{
195*cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aDir3D);
196*cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
197*cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SIZE, aStr);
198*cdf0e10cSrcweir 				}
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 				break;
201*cdf0e10cSrcweir 			}
202*cdf0e10cSrcweir 			case XmlShapeTypeDraw3DLatheObject:
203*cdf0e10cSrcweir 			case XmlShapeTypeDraw3DExtrudeObject:
204*cdf0e10cSrcweir 			{
205*cdf0e10cSrcweir 				// write special 3DLathe/3DExtrude attributes
206*cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPolyPolygon3D")));
207*cdf0e10cSrcweir 				drawing::PolyPolygonShape3D xPolyPolygon3D;
208*cdf0e10cSrcweir 				aAny >>= xPolyPolygon3D;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 				// look for maximal values
211*cdf0e10cSrcweir 				double fXMin = 0;
212*cdf0e10cSrcweir 				double fXMax = 0;
213*cdf0e10cSrcweir 				double fYMin = 0;
214*cdf0e10cSrcweir 				double fYMax = 0;
215*cdf0e10cSrcweir 				sal_Bool bInit(sal_False);
216*cdf0e10cSrcweir 				sal_Int32 nOuterSequenceCount(xPolyPolygon3D.SequenceX.getLength());
217*cdf0e10cSrcweir 				drawing::DoubleSequence* pInnerSequenceX = xPolyPolygon3D.SequenceX.getArray();
218*cdf0e10cSrcweir 				drawing::DoubleSequence* pInnerSequenceY = xPolyPolygon3D.SequenceY.getArray();
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 				sal_Int32 a;
221*cdf0e10cSrcweir                 for (a = 0; a < nOuterSequenceCount; a++)
222*cdf0e10cSrcweir 				{
223*cdf0e10cSrcweir 					sal_Int32 nInnerSequenceCount(pInnerSequenceX->getLength());
224*cdf0e10cSrcweir 					double* pArrayX = pInnerSequenceX->getArray();
225*cdf0e10cSrcweir 					double* pArrayY = pInnerSequenceY->getArray();
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 					for(sal_Int32 b(0L); b < nInnerSequenceCount; b++)
228*cdf0e10cSrcweir 					{
229*cdf0e10cSrcweir 						double fX = *pArrayX++;
230*cdf0e10cSrcweir 						double fY = *pArrayY++;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 						if(bInit)
233*cdf0e10cSrcweir 						{
234*cdf0e10cSrcweir 							if(fX > fXMax)
235*cdf0e10cSrcweir 								fXMax = fX;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 							if(fX < fXMin)
238*cdf0e10cSrcweir 								fXMin = fX;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 							if(fY > fYMax)
241*cdf0e10cSrcweir 								fYMax = fY;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 							if(fY < fYMin)
244*cdf0e10cSrcweir 								fYMin = fY;
245*cdf0e10cSrcweir 						}
246*cdf0e10cSrcweir 						else
247*cdf0e10cSrcweir 						{
248*cdf0e10cSrcweir 							fXMin = fXMax = fX;
249*cdf0e10cSrcweir 							fYMin = fYMax = fY;
250*cdf0e10cSrcweir 							bInit = sal_True;
251*cdf0e10cSrcweir 						}
252*cdf0e10cSrcweir 					}
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 					pInnerSequenceX++;
255*cdf0e10cSrcweir 					pInnerSequenceY++;
256*cdf0e10cSrcweir 				}
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 				// export ViewBox
259*cdf0e10cSrcweir 				awt::Point aMinPoint(FRound(fXMin), FRound(fYMin));
260*cdf0e10cSrcweir 				awt::Size aMaxSize(FRound(fXMax) - aMinPoint.X, FRound(fYMax) - aMinPoint.Y);
261*cdf0e10cSrcweir 				SdXMLImExViewBox aViewBox(
262*cdf0e10cSrcweir 					aMinPoint.X, aMinPoint.Y, aMaxSize.Width, aMaxSize.Height);
263*cdf0e10cSrcweir 				mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX,
264*cdf0e10cSrcweir 					aViewBox.GetExportString());
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 				// prepare svx:d element export
267*cdf0e10cSrcweir 				SdXMLImExSvgDElement aSvgDElement(aViewBox);
268*cdf0e10cSrcweir 				pInnerSequenceX = xPolyPolygon3D.SequenceX.getArray();
269*cdf0e10cSrcweir 				pInnerSequenceY = xPolyPolygon3D.SequenceY.getArray();
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir                 for (a = 0; a < nOuterSequenceCount; a++)
272*cdf0e10cSrcweir 				{
273*cdf0e10cSrcweir 					sal_Int32 nInnerSequenceCount(pInnerSequenceX->getLength());
274*cdf0e10cSrcweir 					double* pArrayX = pInnerSequenceX->getArray();
275*cdf0e10cSrcweir 					double* pArrayY = pInnerSequenceY->getArray();
276*cdf0e10cSrcweir 					drawing::PointSequence aPoly(nInnerSequenceCount);
277*cdf0e10cSrcweir 					awt::Point* pInnerSequence = aPoly.getArray();
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 					for(sal_Int32 b(0L); b < nInnerSequenceCount; b++)
280*cdf0e10cSrcweir 					{
281*cdf0e10cSrcweir 						double fX = *pArrayX++;
282*cdf0e10cSrcweir 						double fY = *pArrayY++;
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 						*pInnerSequence = awt::Point(FRound(fX), FRound(fY));
285*cdf0e10cSrcweir 						pInnerSequence++;
286*cdf0e10cSrcweir 					}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 					// calculate closed flag
289*cdf0e10cSrcweir 					awt::Point* pFirst = aPoly.getArray();
290*cdf0e10cSrcweir 					awt::Point* pLast = pFirst + (nInnerSequenceCount - 1);
291*cdf0e10cSrcweir 					sal_Bool bClosed = (pFirst->X == pLast->X && pFirst->Y == pLast->Y);
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 					aSvgDElement.AddPolygon(&aPoly, 0L, aMinPoint,
294*cdf0e10cSrcweir 						aMaxSize, bClosed);
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 					// #80594# corrected error in PolyPolygon3D export for 3D XML
297*cdf0e10cSrcweir 					pInnerSequenceX++;
298*cdf0e10cSrcweir 					pInnerSequenceY++;
299*cdf0e10cSrcweir 				}
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 				// write point array
302*cdf0e10cSrcweir 				mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString());
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 				if(eShapeType == XmlShapeTypeDraw3DLatheObject)
305*cdf0e10cSrcweir 				{
306*cdf0e10cSrcweir 					// write 3DLathe shape
307*cdf0e10cSrcweir 					SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_ROTATE, sal_True, sal_True);
308*cdf0e10cSrcweir 				}
309*cdf0e10cSrcweir 				else
310*cdf0e10cSrcweir 				{
311*cdf0e10cSrcweir 					// write 3DExtrude shape
312*cdf0e10cSrcweir 					SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_EXTRUDE, sal_True, sal_True);
313*cdf0e10cSrcweir 				}
314*cdf0e10cSrcweir 				break;
315*cdf0e10cSrcweir 			}
316*cdf0e10cSrcweir 			default:
317*cdf0e10cSrcweir 				break;
318*cdf0e10cSrcweir 		}
319*cdf0e10cSrcweir 	}
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir /** helper for chart that adds all attributes of a 3d scene element to the export */
325*cdf0e10cSrcweir void XMLShapeExport::export3DSceneAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet )
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir 	OUString aStr;
328*cdf0e10cSrcweir 	OUStringBuffer sStringBuffer;
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	// world transformation (UNO_NAME_3D_TRANSFORM_MATRIX == "D3DTransformMatrix")
331*cdf0e10cSrcweir 	uno::Any aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")));
332*cdf0e10cSrcweir 	drawing::HomogenMatrix xHomMat;
333*cdf0e10cSrcweir 	aAny >>= xHomMat;
334*cdf0e10cSrcweir 	SdXMLImExTransform3D aTransform;
335*cdf0e10cSrcweir 	aTransform.AddHomogenMatrix(xHomMat);
336*cdf0e10cSrcweir 	if(aTransform.NeedsAction())
337*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_TRANSFORM, aTransform.GetExportString(mrExport.GetMM100UnitConverter()));
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	// VRP, VPN, VUP
340*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DCameraGeometry")));
341*cdf0e10cSrcweir 	drawing::CameraGeometry aCamGeo;
342*cdf0e10cSrcweir 	aAny >>= aCamGeo;
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 	::basegfx::B3DVector aVRP(aCamGeo.vrp.PositionX, aCamGeo.vrp.PositionY, aCamGeo.vrp.PositionZ);
345*cdf0e10cSrcweir 	if(aVRP != ::basegfx::B3DVector(0.0, 0.0, 1.0)) // write only when not default
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVRP);
348*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
349*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VRP, aStr);
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 	::basegfx::B3DVector aVPN(aCamGeo.vpn.DirectionX, aCamGeo.vpn.DirectionY, aCamGeo.vpn.DirectionZ);
353*cdf0e10cSrcweir 	if(aVPN != ::basegfx::B3DVector(0.0, 0.0, 1.0)) // write only when not default
354*cdf0e10cSrcweir 	{
355*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVPN);
356*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
357*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VPN, aStr);
358*cdf0e10cSrcweir 	}
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	::basegfx::B3DVector aVUP(aCamGeo.vup.DirectionX, aCamGeo.vup.DirectionY, aCamGeo.vup.DirectionZ);
361*cdf0e10cSrcweir 	if(aVUP != ::basegfx::B3DVector(0.0, 1.0, 0.0)) // write only when not default
362*cdf0e10cSrcweir 	{
363*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVUP);
364*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
365*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VUP, aStr);
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 	// projection "D3DScenePerspective" drawing::ProjectionMode
369*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DScenePerspective")));
370*cdf0e10cSrcweir 	drawing::ProjectionMode xPrjMode;
371*cdf0e10cSrcweir 	aAny >>= xPrjMode;
372*cdf0e10cSrcweir 	if(xPrjMode == drawing::ProjectionMode_PARALLEL)
373*cdf0e10cSrcweir 		aStr = GetXMLToken(XML_PARALLEL);
374*cdf0e10cSrcweir 	else
375*cdf0e10cSrcweir 		aStr = GetXMLToken(XML_PERSPECTIVE);
376*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_PROJECTION, aStr);
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	// distance
379*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneDistance")));
380*cdf0e10cSrcweir 	sal_Int32 nDistance = 0;
381*cdf0e10cSrcweir 	aAny >>= nDistance;
382*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(sStringBuffer, nDistance);
383*cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
384*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DISTANCE, aStr);
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 	// focalLength
387*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneFocalLength")));
388*cdf0e10cSrcweir 	sal_Int32 nFocalLength = 0;
389*cdf0e10cSrcweir 	aAny >>= nFocalLength;
390*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(sStringBuffer, nFocalLength);
391*cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
392*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_FOCAL_LENGTH, aStr);
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 	// shadowSlant
395*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneShadowSlant")));
396*cdf0e10cSrcweir 	sal_Int16 nShadowSlant = 0;
397*cdf0e10cSrcweir 	aAny >>= nShadowSlant;
398*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertNumber(sStringBuffer, (sal_Int32)nShadowSlant);
399*cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
400*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SHADOW_SLANT, aStr);
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	// shadeMode
403*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneShadeMode")));
404*cdf0e10cSrcweir 	drawing::ShadeMode xShadeMode;
405*cdf0e10cSrcweir 	if(aAny >>= xShadeMode)
406*cdf0e10cSrcweir 	{
407*cdf0e10cSrcweir 		if(xShadeMode == drawing::ShadeMode_FLAT)
408*cdf0e10cSrcweir 			aStr = GetXMLToken(XML_FLAT);
409*cdf0e10cSrcweir 		else if(xShadeMode == drawing::ShadeMode_PHONG)
410*cdf0e10cSrcweir 			aStr = GetXMLToken(XML_PHONG);
411*cdf0e10cSrcweir 		else if(xShadeMode == drawing::ShadeMode_SMOOTH)
412*cdf0e10cSrcweir 			aStr = GetXMLToken(XML_GOURAUD);
413*cdf0e10cSrcweir 		else
414*cdf0e10cSrcweir 			aStr = GetXMLToken(XML_DRAFT);
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir 	else
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		// ShadeMode enum not there, write default
419*cdf0e10cSrcweir 		aStr = GetXMLToken(XML_GOURAUD);
420*cdf0e10cSrcweir 	}
421*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SHADE_MODE, aStr);
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 	// ambientColor
424*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneAmbientColor")));
425*cdf0e10cSrcweir 	sal_Int32 aColTemp = 0;
426*cdf0e10cSrcweir 	Color aAmbientColor;
427*cdf0e10cSrcweir 	aAny >>= aColTemp; aAmbientColor.SetColor(aColTemp);
428*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertColor(sStringBuffer, aAmbientColor);
429*cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
430*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_AMBIENT_COLOR, aStr);
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 	// lightingMode
433*cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneTwoSidedLighting")));
434*cdf0e10cSrcweir 	sal_Bool bTwoSidedLighting = false;
435*cdf0e10cSrcweir 	aAny >>= bTwoSidedLighting;
436*cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertBool(sStringBuffer, bTwoSidedLighting);
437*cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
438*cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_LIGHTING_MODE, aStr);
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir /** helper for chart that exports all lamps from the propertyset */
442*cdf0e10cSrcweir void XMLShapeExport::export3DLamps( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet )
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir 	// write lamps 1..8 as content
445*cdf0e10cSrcweir 	OUString aStr;
446*cdf0e10cSrcweir 	OUStringBuffer sStringBuffer;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	const OUString aColorPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightColor") );
449*cdf0e10cSrcweir 	const OUString aDirectionPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightDirection") );
450*cdf0e10cSrcweir 	const OUString aLightOnPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightOn") );
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir 	OUString aPropName;
453*cdf0e10cSrcweir 	OUString aIndexStr;
454*cdf0e10cSrcweir 	sal_Int32 aColTemp = 0;
455*cdf0e10cSrcweir 	Color aLightColor;
456*cdf0e10cSrcweir 	::basegfx::B3DVector aLightDirection;
457*cdf0e10cSrcweir 	drawing::Direction3D xLightDir;
458*cdf0e10cSrcweir 	sal_Bool bLightOnOff = false;
459*cdf0e10cSrcweir 	for(sal_Int32 nLamp = 1; nLamp <= 8; nLamp++)
460*cdf0e10cSrcweir 	{
461*cdf0e10cSrcweir 		aIndexStr = OUString::valueOf( nLamp );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 		// lightcolor
464*cdf0e10cSrcweir 		aPropName = aColorPropName;
465*cdf0e10cSrcweir 		aPropName += aIndexStr;
466*cdf0e10cSrcweir 		xPropSet->getPropertyValue( aPropName ) >>= aColTemp;
467*cdf0e10cSrcweir 		aLightColor.SetColor(aColTemp);
468*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertColor(sStringBuffer, aLightColor);
469*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
470*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DIFFUSE_COLOR, aStr);
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 		// lightdirection
473*cdf0e10cSrcweir 		aPropName = aDirectionPropName;
474*cdf0e10cSrcweir 		aPropName += aIndexStr;
475*cdf0e10cSrcweir 		xPropSet->getPropertyValue(aPropName) >>= xLightDir;
476*cdf0e10cSrcweir 		aLightDirection = ::basegfx::B3DVector(xLightDir.DirectionX, xLightDir.DirectionY, xLightDir.DirectionZ);
477*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aLightDirection);
478*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
479*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DIRECTION, aStr);
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 		// lighton
482*cdf0e10cSrcweir 		aPropName = aLightOnPropName;
483*cdf0e10cSrcweir 		aPropName += aIndexStr;
484*cdf0e10cSrcweir 		xPropSet->getPropertyValue(aPropName) >>= bLightOnOff;
485*cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertBool(sStringBuffer, bLightOnOff);
486*cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
487*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_ENABLED, aStr);
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 		// specular
490*cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SPECULAR,
491*cdf0e10cSrcweir 			nLamp == 1 ? XML_TRUE : XML_FALSE);
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 		// write light entry
494*cdf0e10cSrcweir 		SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_LIGHT, sal_True, sal_True);
495*cdf0e10cSrcweir 	}
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
499