163bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
363bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
463bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
563bba73cSAndrew Rist  * distributed with this work for additional information
663bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
763bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
863bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
963bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
1063bba73cSAndrew Rist  *
1163bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1263bba73cSAndrew Rist  *
1363bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1463bba73cSAndrew Rist  * software distributed under the License is distributed on an
1563bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1663bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
1763bba73cSAndrew Rist  * specific language governing permissions and limitations
1863bba73cSAndrew Rist  * under the License.
1963bba73cSAndrew Rist  *
2063bba73cSAndrew Rist  *************************************************************/
2163bba73cSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
24*1f882ec4SArmin Le Grand 
25cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix.hpp>
26cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
27cdf0e10cSrcweir #include <com/sun/star/drawing/ProjectionMode.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/ShadeMode.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/Direction3D.hpp>
30cdf0e10cSrcweir #include <com/sun/star/drawing/Position3D.hpp>
31cdf0e10cSrcweir #include <com/sun/star/drawing/CameraGeometry.hpp>
32cdf0e10cSrcweir #include <com/sun/star/drawing/DoubleSequence.hpp>
33cdf0e10cSrcweir #include <tools/gen.hxx>
34cdf0e10cSrcweir #include <xmloff/shapeexport.hxx>
35cdf0e10cSrcweir #include "sdpropls.hxx"
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
39cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
40cdf0e10cSrcweir #include "xexptran.hxx"
41cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
42cdf0e10cSrcweir #include <basegfx/vector/b3dvector.hxx>
43*1f882ec4SArmin Le Grand #include <xmloff/xmlnmspe.hxx>
44*1f882ec4SArmin Le Grand #include <basegfx/polygon/b3dpolypolygon.hxx>
45*1f882ec4SArmin Le Grand #include <basegfx/polygon/b3dpolypolygontools.hxx>
46*1f882ec4SArmin Le Grand #include <basegfx/matrix/b3dhommatrix.hxx>
47*1f882ec4SArmin Le Grand #include <basegfx/polygon/b2dpolypolygon.hxx>
48*1f882ec4SArmin Le Grand #include <basegfx/polygon/b2dpolypolygontools.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using ::rtl::OUString;
51cdf0e10cSrcweir using ::rtl::OUStringBuffer;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace ::com::sun::star;
54cdf0e10cSrcweir using namespace ::xmloff::token;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
58cdf0e10cSrcweir 
59cdf0e10cSrcweir void XMLShapeExport::ImpExport3DSceneShape( const uno::Reference< drawing::XShape >& xShape, XmlShapeType, sal_Int32 nFeatures, awt::Point* pRefPoint)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	uno::Reference< drawing::XShapes > xShapes(xShape, uno::UNO_QUERY);
62cdf0e10cSrcweir 	if(xShapes.is() && xShapes->getCount())
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY );
65cdf0e10cSrcweir 		DBG_ASSERT( xPropSet.is(), "XMLShapeExport::ImpExport3DSceneShape can't export a scene without a propertyset" );
66cdf0e10cSrcweir 		if( xPropSet.is() )
67cdf0e10cSrcweir 		{
68cdf0e10cSrcweir 			// Transformation
69cdf0e10cSrcweir 			ImpExportNewTrans(xPropSet, nFeatures, pRefPoint);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 			// 3d attributes
72cdf0e10cSrcweir 			export3DSceneAttributes( xPropSet );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 			// write 3DScene shape
75cdf0e10cSrcweir 			sal_Bool bCreateNewline( (nFeatures & SEF_EXPORT_NO_WS) == 0 ); // #86116#/#92210#
76cdf0e10cSrcweir 			SvXMLElementExport aOBJ( mrExport, XML_NAMESPACE_DR3D, XML_SCENE, bCreateNewline, sal_True);
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 			ImpExportDescription( xShape ); // #i68101#
79cdf0e10cSrcweir 			ImpExportEvents( xShape );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 			// write 3DSceneLights
82cdf0e10cSrcweir 			export3DLamps( xPropSet );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			// #89764# if export of position is supressed for group shape,
85cdf0e10cSrcweir 			// positions of contained objects should be written relative to
86cdf0e10cSrcweir 			// the upper left edge of the group.
87cdf0e10cSrcweir 			awt::Point aUpperLeft;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 			if(!(nFeatures & SEF_EXPORT_POSITION))
90cdf0e10cSrcweir 			{
91cdf0e10cSrcweir 				nFeatures |= SEF_EXPORT_POSITION;
92cdf0e10cSrcweir 				aUpperLeft = xShape->getPosition();
93cdf0e10cSrcweir 				pRefPoint = &aUpperLeft;
94cdf0e10cSrcweir 			}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			// write members
97cdf0e10cSrcweir 			exportShapes( xShapes, nFeatures, pRefPoint );
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
103cdf0e10cSrcweir 
104cdf0e10cSrcweir void XMLShapeExport::ImpExport3DShape(
105cdf0e10cSrcweir 	const uno::Reference< drawing::XShape >& xShape,
106cdf0e10cSrcweir 	XmlShapeType eShapeType, sal_Int32 /* nFeatures = SEF_DEFAULT */, awt::Point* /*pRefPoint = NULL */)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	const uno::Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY);
109cdf0e10cSrcweir 	if(xPropSet.is())
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		OUString aStr;
112cdf0e10cSrcweir 		OUStringBuffer sStringBuffer;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		// transformation (UNO_NAME_3D_TRANSFORM_MATRIX == "D3DTransformMatrix")
115cdf0e10cSrcweir 		uno::Any aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")));
116cdf0e10cSrcweir 		drawing::HomogenMatrix xHomMat;
117cdf0e10cSrcweir 		aAny >>= xHomMat;
118cdf0e10cSrcweir 		SdXMLImExTransform3D aTransform;
119cdf0e10cSrcweir 		aTransform.AddHomogenMatrix(xHomMat);
120cdf0e10cSrcweir 		if(aTransform.NeedsAction())
121cdf0e10cSrcweir 			mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_TRANSFORM, aTransform.GetExportString(mrExport.GetMM100UnitConverter()));
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		switch(eShapeType)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			case XmlShapeTypeDraw3DCubeObject:
126cdf0e10cSrcweir 			{
127cdf0e10cSrcweir 				// write 3DCube shape
128cdf0e10cSrcweir 				SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_CUBE, sal_True, sal_True);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 				// minEdge
131cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")));
132cdf0e10cSrcweir 				drawing::Position3D aPosition3D;
133cdf0e10cSrcweir 				aAny >>= aPosition3D;
134cdf0e10cSrcweir 				::basegfx::B3DVector aPos3D(aPosition3D.PositionX, aPosition3D.PositionY, aPosition3D.PositionZ);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 				// maxEdge
137cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")));
138cdf0e10cSrcweir 				drawing::Direction3D aDirection3D;
139cdf0e10cSrcweir 				aAny >>= aDirection3D;
140cdf0e10cSrcweir 				::basegfx::B3DVector aDir3D(aDirection3D.DirectionX, aDirection3D.DirectionY, aDirection3D.DirectionZ);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 				// transform maxEdge from distance to pos
143cdf0e10cSrcweir 				aDir3D = aPos3D + aDir3D;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 				// write minEdge
146cdf0e10cSrcweir 				if(aPos3D != ::basegfx::B3DVector(-2500.0, -2500.0, -2500.0)) // write only when not default
147cdf0e10cSrcweir 				{
148cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aPos3D);
149cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
150cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_MIN_EDGE, aStr);
151cdf0e10cSrcweir 				}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 				// write maxEdge
154cdf0e10cSrcweir 				if(aDir3D != ::basegfx::B3DVector(2500.0, 2500.0, 2500.0)) // write only when not default
155cdf0e10cSrcweir 				{
156cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aDir3D);
157cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
158cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_MAX_EDGE, aStr);
159cdf0e10cSrcweir 				}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 				break;
162cdf0e10cSrcweir 			}
163cdf0e10cSrcweir 			case XmlShapeTypeDraw3DSphereObject:
164cdf0e10cSrcweir 			{
165cdf0e10cSrcweir 				// write 3DSphere shape
166cdf0e10cSrcweir 				SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_SPHERE, sal_True, sal_True);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 				// Center
169cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPosition")));
170cdf0e10cSrcweir 				drawing::Position3D aPosition3D;
171cdf0e10cSrcweir 				aAny >>= aPosition3D;
172cdf0e10cSrcweir 				::basegfx::B3DVector aPos3D(aPosition3D.PositionX, aPosition3D.PositionY, aPosition3D.PositionZ);
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 				// Size
175cdf0e10cSrcweir 				aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSize")));
176cdf0e10cSrcweir 				drawing::Direction3D aDirection3D;
177cdf0e10cSrcweir 				aAny >>= aDirection3D;
178cdf0e10cSrcweir 				::basegfx::B3DVector aDir3D(aDirection3D.DirectionX, aDirection3D.DirectionY, aDirection3D.DirectionZ);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 				// write Center
181cdf0e10cSrcweir 				if(aPos3D != ::basegfx::B3DVector(0.0, 0.0, 0.0)) // write only when not default
182cdf0e10cSrcweir 				{
183cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aPos3D);
184cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
185cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_CENTER, aStr);
186cdf0e10cSrcweir 				}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 				// write Size
189cdf0e10cSrcweir 				if(aDir3D != ::basegfx::B3DVector(5000.0, 5000.0, 5000.0)) // write only when not default
190cdf0e10cSrcweir 				{
191cdf0e10cSrcweir 					mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aDir3D);
192cdf0e10cSrcweir 					aStr = sStringBuffer.makeStringAndClear();
193cdf0e10cSrcweir 					mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SIZE, aStr);
194cdf0e10cSrcweir 				}
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 				break;
197cdf0e10cSrcweir 			}
198cdf0e10cSrcweir 			case XmlShapeTypeDraw3DLatheObject:
199cdf0e10cSrcweir 			case XmlShapeTypeDraw3DExtrudeObject:
200cdf0e10cSrcweir 			{
201*1f882ec4SArmin Le Grand                 // write special 3DLathe/3DExtrude attributes, get 3D PolyPolygon as drawing::PolyPolygonShape3D
202*1f882ec4SArmin Le Grand                 aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DPolyPolygon3D")));
203*1f882ec4SArmin Le Grand                 drawing::PolyPolygonShape3D xPolyPolygon3D;
204*1f882ec4SArmin Le Grand                 aAny >>= xPolyPolygon3D;
205*1f882ec4SArmin Le Grand 
206*1f882ec4SArmin Le Grand                 // convert to 3D PolyPolygon
207*1f882ec4SArmin Le Grand                 const basegfx::B3DPolyPolygon aPolyPolygon3D(
208*1f882ec4SArmin Le Grand                     basegfx::tools::UnoPolyPolygonShape3DToB3DPolyPolygon(
209*1f882ec4SArmin Le Grand                         xPolyPolygon3D));
210*1f882ec4SArmin Le Grand 
211*1f882ec4SArmin Le Grand                 // convert to 2D PolyPolygon using identity 3D transformation (just grep X and Y)
212*1f882ec4SArmin Le Grand                 const basegfx::B3DHomMatrix aB3DHomMatrixFor2DConversion;
213*1f882ec4SArmin Le Grand                 const basegfx::B2DPolyPolygon aPolyPolygon(
214*1f882ec4SArmin Le Grand                     basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(
215*1f882ec4SArmin Le Grand                         aPolyPolygon3D,
216*1f882ec4SArmin Le Grand                         aB3DHomMatrixFor2DConversion));
217*1f882ec4SArmin Le Grand 
218*1f882ec4SArmin Le Grand                 // get 2D range of it
219*1f882ec4SArmin Le Grand                 const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange());
220*1f882ec4SArmin Le Grand 
221*1f882ec4SArmin Le Grand                 // export ViewBox
222*1f882ec4SArmin Le Grand                 SdXMLImExViewBox aViewBox(
223*1f882ec4SArmin Le Grand                     aPolyPolygonRange.getMinX(),
224*1f882ec4SArmin Le Grand                     aPolyPolygonRange.getMinY(),
225*1f882ec4SArmin Le Grand                     aPolyPolygonRange.getWidth(),
226*1f882ec4SArmin Le Grand                     aPolyPolygonRange.getHeight());
227*1f882ec4SArmin Le Grand 
228*1f882ec4SArmin Le Grand                 mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString());
229*1f882ec4SArmin Le Grand 
230*1f882ec4SArmin Le Grand                 // prepare svg:d string
231*1f882ec4SArmin Le Grand                 const ::rtl::OUString aPolygonString(
232*1f882ec4SArmin Le Grand                     basegfx::tools::exportToSvgD(
233*1f882ec4SArmin Le Grand                         aPolyPolygon,
234*1f882ec4SArmin Le Grand                         true,           // bUseRelativeCoordinates
235*1f882ec4SArmin Le Grand                         false,          // bDetectQuadraticBeziers TTTT: not used in old, but maybe activated now
236*1f882ec4SArmin Le Grand                         true));         // bHandleRelativeNextPointCompatible
237*1f882ec4SArmin Le Grand 
238*1f882ec4SArmin Le Grand                 // write point array
239*1f882ec4SArmin Le Grand                 mrExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aPolygonString);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 				if(eShapeType == XmlShapeTypeDraw3DLatheObject)
242cdf0e10cSrcweir 				{
243cdf0e10cSrcweir 					// write 3DLathe shape
244cdf0e10cSrcweir 					SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_ROTATE, sal_True, sal_True);
245cdf0e10cSrcweir 				}
246cdf0e10cSrcweir 				else
247cdf0e10cSrcweir 				{
248cdf0e10cSrcweir 					// write 3DExtrude shape
249cdf0e10cSrcweir 					SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_EXTRUDE, sal_True, sal_True);
250cdf0e10cSrcweir 				}
251cdf0e10cSrcweir 				break;
252cdf0e10cSrcweir 			}
253cdf0e10cSrcweir 			default:
254cdf0e10cSrcweir 				break;
255cdf0e10cSrcweir 		}
256cdf0e10cSrcweir 	}
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
260cdf0e10cSrcweir 
261cdf0e10cSrcweir /** helper for chart that adds all attributes of a 3d scene element to the export */
262cdf0e10cSrcweir void XMLShapeExport::export3DSceneAttributes( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	OUString aStr;
265cdf0e10cSrcweir 	OUStringBuffer sStringBuffer;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	// world transformation (UNO_NAME_3D_TRANSFORM_MATRIX == "D3DTransformMatrix")
268cdf0e10cSrcweir 	uno::Any aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DTransformMatrix")));
269cdf0e10cSrcweir 	drawing::HomogenMatrix xHomMat;
270cdf0e10cSrcweir 	aAny >>= xHomMat;
271cdf0e10cSrcweir 	SdXMLImExTransform3D aTransform;
272cdf0e10cSrcweir 	aTransform.AddHomogenMatrix(xHomMat);
273cdf0e10cSrcweir 	if(aTransform.NeedsAction())
274cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_TRANSFORM, aTransform.GetExportString(mrExport.GetMM100UnitConverter()));
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	// VRP, VPN, VUP
277cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DCameraGeometry")));
278cdf0e10cSrcweir 	drawing::CameraGeometry aCamGeo;
279cdf0e10cSrcweir 	aAny >>= aCamGeo;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	::basegfx::B3DVector aVRP(aCamGeo.vrp.PositionX, aCamGeo.vrp.PositionY, aCamGeo.vrp.PositionZ);
282cdf0e10cSrcweir 	if(aVRP != ::basegfx::B3DVector(0.0, 0.0, 1.0)) // write only when not default
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVRP);
285cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
286cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VRP, aStr);
287cdf0e10cSrcweir 	}
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	::basegfx::B3DVector aVPN(aCamGeo.vpn.DirectionX, aCamGeo.vpn.DirectionY, aCamGeo.vpn.DirectionZ);
290cdf0e10cSrcweir 	if(aVPN != ::basegfx::B3DVector(0.0, 0.0, 1.0)) // write only when not default
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVPN);
293cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
294cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VPN, aStr);
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	::basegfx::B3DVector aVUP(aCamGeo.vup.DirectionX, aCamGeo.vup.DirectionY, aCamGeo.vup.DirectionZ);
298cdf0e10cSrcweir 	if(aVUP != ::basegfx::B3DVector(0.0, 1.0, 0.0)) // write only when not default
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aVUP);
301cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
302cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_VUP, aStr);
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	// projection "D3DScenePerspective" drawing::ProjectionMode
306cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DScenePerspective")));
307cdf0e10cSrcweir 	drawing::ProjectionMode xPrjMode;
308cdf0e10cSrcweir 	aAny >>= xPrjMode;
309cdf0e10cSrcweir 	if(xPrjMode == drawing::ProjectionMode_PARALLEL)
310cdf0e10cSrcweir 		aStr = GetXMLToken(XML_PARALLEL);
311cdf0e10cSrcweir 	else
312cdf0e10cSrcweir 		aStr = GetXMLToken(XML_PERSPECTIVE);
313cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_PROJECTION, aStr);
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	// distance
316cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneDistance")));
317cdf0e10cSrcweir 	sal_Int32 nDistance = 0;
318cdf0e10cSrcweir 	aAny >>= nDistance;
319cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(sStringBuffer, nDistance);
320cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
321cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DISTANCE, aStr);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	// focalLength
324cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneFocalLength")));
325cdf0e10cSrcweir 	sal_Int32 nFocalLength = 0;
326cdf0e10cSrcweir 	aAny >>= nFocalLength;
327cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertMeasure(sStringBuffer, nFocalLength);
328cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
329cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_FOCAL_LENGTH, aStr);
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	// shadowSlant
332cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneShadowSlant")));
333cdf0e10cSrcweir 	sal_Int16 nShadowSlant = 0;
334cdf0e10cSrcweir 	aAny >>= nShadowSlant;
335cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertNumber(sStringBuffer, (sal_Int32)nShadowSlant);
336cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
337cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SHADOW_SLANT, aStr);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	// shadeMode
340cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneShadeMode")));
341cdf0e10cSrcweir 	drawing::ShadeMode xShadeMode;
342cdf0e10cSrcweir 	if(aAny >>= xShadeMode)
343cdf0e10cSrcweir 	{
344cdf0e10cSrcweir 		if(xShadeMode == drawing::ShadeMode_FLAT)
345cdf0e10cSrcweir 			aStr = GetXMLToken(XML_FLAT);
346cdf0e10cSrcweir 		else if(xShadeMode == drawing::ShadeMode_PHONG)
347cdf0e10cSrcweir 			aStr = GetXMLToken(XML_PHONG);
348cdf0e10cSrcweir 		else if(xShadeMode == drawing::ShadeMode_SMOOTH)
349cdf0e10cSrcweir 			aStr = GetXMLToken(XML_GOURAUD);
350cdf0e10cSrcweir 		else
351cdf0e10cSrcweir 			aStr = GetXMLToken(XML_DRAFT);
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir 	else
354cdf0e10cSrcweir 	{
355cdf0e10cSrcweir 		// ShadeMode enum not there, write default
356cdf0e10cSrcweir 		aStr = GetXMLToken(XML_GOURAUD);
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SHADE_MODE, aStr);
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	// ambientColor
361cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneAmbientColor")));
362cdf0e10cSrcweir 	sal_Int32 aColTemp = 0;
363cdf0e10cSrcweir 	Color aAmbientColor;
364cdf0e10cSrcweir 	aAny >>= aColTemp; aAmbientColor.SetColor(aColTemp);
365cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertColor(sStringBuffer, aAmbientColor);
366cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
367cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_AMBIENT_COLOR, aStr);
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	// lightingMode
370cdf0e10cSrcweir 	aAny = xPropSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("D3DSceneTwoSidedLighting")));
371cdf0e10cSrcweir 	sal_Bool bTwoSidedLighting = false;
372cdf0e10cSrcweir 	aAny >>= bTwoSidedLighting;
373cdf0e10cSrcweir 	mrExport.GetMM100UnitConverter().convertBool(sStringBuffer, bTwoSidedLighting);
374cdf0e10cSrcweir 	aStr = sStringBuffer.makeStringAndClear();
375cdf0e10cSrcweir 	mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_LIGHTING_MODE, aStr);
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir /** helper for chart that exports all lamps from the propertyset */
379cdf0e10cSrcweir void XMLShapeExport::export3DLamps( const com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >& xPropSet )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir 	// write lamps 1..8 as content
382cdf0e10cSrcweir 	OUString aStr;
383cdf0e10cSrcweir 	OUStringBuffer sStringBuffer;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	const OUString aColorPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightColor") );
386cdf0e10cSrcweir 	const OUString aDirectionPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightDirection") );
387cdf0e10cSrcweir 	const OUString aLightOnPropName(RTL_CONSTASCII_USTRINGPARAM("D3DSceneLightOn") );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 	OUString aPropName;
390cdf0e10cSrcweir 	OUString aIndexStr;
391cdf0e10cSrcweir 	sal_Int32 aColTemp = 0;
392cdf0e10cSrcweir 	Color aLightColor;
393cdf0e10cSrcweir 	::basegfx::B3DVector aLightDirection;
394cdf0e10cSrcweir 	drawing::Direction3D xLightDir;
395cdf0e10cSrcweir 	sal_Bool bLightOnOff = false;
396cdf0e10cSrcweir 	for(sal_Int32 nLamp = 1; nLamp <= 8; nLamp++)
397cdf0e10cSrcweir 	{
398cdf0e10cSrcweir 		aIndexStr = OUString::valueOf( nLamp );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 		// lightcolor
401cdf0e10cSrcweir 		aPropName = aColorPropName;
402cdf0e10cSrcweir 		aPropName += aIndexStr;
403cdf0e10cSrcweir 		xPropSet->getPropertyValue( aPropName ) >>= aColTemp;
404cdf0e10cSrcweir 		aLightColor.SetColor(aColTemp);
405cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertColor(sStringBuffer, aLightColor);
406cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
407cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DIFFUSE_COLOR, aStr);
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 		// lightdirection
410cdf0e10cSrcweir 		aPropName = aDirectionPropName;
411cdf0e10cSrcweir 		aPropName += aIndexStr;
412cdf0e10cSrcweir 		xPropSet->getPropertyValue(aPropName) >>= xLightDir;
413cdf0e10cSrcweir 		aLightDirection = ::basegfx::B3DVector(xLightDir.DirectionX, xLightDir.DirectionY, xLightDir.DirectionZ);
414cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertB3DVector(sStringBuffer, aLightDirection);
415cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
416cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_DIRECTION, aStr);
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 		// lighton
419cdf0e10cSrcweir 		aPropName = aLightOnPropName;
420cdf0e10cSrcweir 		aPropName += aIndexStr;
421cdf0e10cSrcweir 		xPropSet->getPropertyValue(aPropName) >>= bLightOnOff;
422cdf0e10cSrcweir 		mrExport.GetMM100UnitConverter().convertBool(sStringBuffer, bLightOnOff);
423cdf0e10cSrcweir 		aStr = sStringBuffer.makeStringAndClear();
424cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_ENABLED, aStr);
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 		// specular
427cdf0e10cSrcweir 		mrExport.AddAttribute(XML_NAMESPACE_DR3D, XML_SPECULAR,
428cdf0e10cSrcweir 			nLamp == 1 ? XML_TRUE : XML_FALSE);
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 		// write light entry
431cdf0e10cSrcweir 		SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DR3D, XML_LIGHT, sal_True, sal_True);
432cdf0e10cSrcweir 	}
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
436