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_svx.hxx"
30*cdf0e10cSrcweir #include <svx/sdr/properties/e3dsceneproperties.hxx>
31*cdf0e10cSrcweir #include <svl/itemset.hxx>
32*cdf0e10cSrcweir #include <svl/whiter.hxx>
33*cdf0e10cSrcweir #include <svx/svddef.hxx>
34*cdf0e10cSrcweir #include <svx/scene3d.hxx>
35*cdf0e10cSrcweir #include <svx/svditer.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir namespace sdr
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir 	namespace properties
42*cdf0e10cSrcweir 	{
43*cdf0e10cSrcweir 		E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
44*cdf0e10cSrcweir 		:	E3dProperties(rObj)
45*cdf0e10cSrcweir 		{
46*cdf0e10cSrcweir 		}
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 		E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
49*cdf0e10cSrcweir 		:	E3dProperties(rProps, rObj)
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 		}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 		E3dSceneProperties::~E3dSceneProperties()
54*cdf0e10cSrcweir 		{
55*cdf0e10cSrcweir 		}
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 		BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
58*cdf0e10cSrcweir 		{
59*cdf0e10cSrcweir 			return *(new E3dSceneProperties(*this, rObj));
60*cdf0e10cSrcweir 		}
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 		const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
63*cdf0e10cSrcweir 		{
64*cdf0e10cSrcweir 			//DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
65*cdf0e10cSrcweir 			return E3dProperties::GetObjectItemSet();
66*cdf0e10cSrcweir 		}
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 		const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
69*cdf0e10cSrcweir 		{
70*cdf0e10cSrcweir 			// prepare ItemSet
71*cdf0e10cSrcweir 			if(mpItemSet)
72*cdf0e10cSrcweir 			{
73*cdf0e10cSrcweir 				// filter for SDRATTR_3DSCENE_ items, only keep those items
74*cdf0e10cSrcweir 				SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
75*cdf0e10cSrcweir 				aNew.Put(*mpItemSet);
76*cdf0e10cSrcweir 				mpItemSet->ClearItem();
77*cdf0e10cSrcweir 				mpItemSet->Put(aNew);
78*cdf0e10cSrcweir 			}
79*cdf0e10cSrcweir 			else
80*cdf0e10cSrcweir 			{
81*cdf0e10cSrcweir 				// No ItemSet yet, force local ItemSet
82*cdf0e10cSrcweir 				GetObjectItemSet();
83*cdf0e10cSrcweir 			}
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 			// collect all ItemSets of contained 3d objects
86*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
87*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 			for(sal_uInt32 a(0L); a < nCount; a++)
90*cdf0e10cSrcweir 			{
91*cdf0e10cSrcweir 				SdrObject* pObj = pSub->GetObj(a);
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 				if(pObj && pObj->ISA(E3dCompoundObject))
94*cdf0e10cSrcweir 				{
95*cdf0e10cSrcweir 					const SfxItemSet& rSet = pObj->GetMergedItemSet();
96*cdf0e10cSrcweir 					SfxWhichIter aIter(rSet);
97*cdf0e10cSrcweir 					sal_uInt16 nWhich(aIter.FirstWhich());
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 					while(nWhich)
100*cdf0e10cSrcweir 					{
101*cdf0e10cSrcweir 						// Leave out the SDRATTR_3DSCENE_ range, this would only be double
102*cdf0e10cSrcweir 						// and always equal.
103*cdf0e10cSrcweir 						if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
104*cdf0e10cSrcweir 						{
105*cdf0e10cSrcweir 							if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False))
106*cdf0e10cSrcweir 							{
107*cdf0e10cSrcweir 								mpItemSet->InvalidateItem(nWhich);
108*cdf0e10cSrcweir 							}
109*cdf0e10cSrcweir 							else
110*cdf0e10cSrcweir 							{
111*cdf0e10cSrcweir 								mpItemSet->MergeValue(rSet.Get(nWhich), sal_True);
112*cdf0e10cSrcweir 							}
113*cdf0e10cSrcweir 						}
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 						nWhich = aIter.NextWhich();
116*cdf0e10cSrcweir 					}
117*cdf0e10cSrcweir 				}
118*cdf0e10cSrcweir 			}
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 			// call parent
121*cdf0e10cSrcweir 			return E3dProperties::GetMergedItemSet();
122*cdf0e10cSrcweir 		}
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 		void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			// Set SDRATTR_3DOBJ_ range at contained objects.
127*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
128*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 			if(nCount)
131*cdf0e10cSrcweir 			{
132*cdf0e10cSrcweir 				// Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
133*cdf0e10cSrcweir 				// #i50808# Leak fix, Clone produces a new instance and we get ownership here
134*cdf0e10cSrcweir 				SfxItemSet* pNewSet = rSet.Clone(sal_True);
135*cdf0e10cSrcweir 				DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 				for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
138*cdf0e10cSrcweir 				{
139*cdf0e10cSrcweir 					pNewSet->ClearItem(b);
140*cdf0e10cSrcweir 				}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 				if(pNewSet->Count())
143*cdf0e10cSrcweir 				{
144*cdf0e10cSrcweir 					for(sal_uInt32 a(0L); a < nCount; a++)
145*cdf0e10cSrcweir 					{
146*cdf0e10cSrcweir 						SdrObject* pObj = pSub->GetObj(a);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 						if(pObj && pObj->ISA(E3dCompoundObject))
149*cdf0e10cSrcweir 						{
150*cdf0e10cSrcweir 							// set merged ItemSet at contained 3d object.
151*cdf0e10cSrcweir 							pObj->SetMergedItemSet(*pNewSet, bClearAllItems);
152*cdf0e10cSrcweir 						}
153*cdf0e10cSrcweir 					}
154*cdf0e10cSrcweir 				}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 				delete pNewSet;
157*cdf0e10cSrcweir 			}
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			// call parent. This will set items on local object, too.
160*cdf0e10cSrcweir 			E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
161*cdf0e10cSrcweir 		}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 		void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
164*cdf0e10cSrcweir 		{
165*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
166*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 			for(sal_uInt32 a(0L); a < nCount; a++)
169*cdf0e10cSrcweir 			{
170*cdf0e10cSrcweir 				pSub->GetObj(a)->SetMergedItem(rItem);
171*cdf0e10cSrcweir 			}
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 			// #i43809# call parent. This will set items on local object, too.
174*cdf0e10cSrcweir 			E3dProperties::SetMergedItem(rItem);
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 		void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
178*cdf0e10cSrcweir 		{
179*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
180*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 			for(sal_uInt32 a(0L); a < nCount; a++)
183*cdf0e10cSrcweir 			{
184*cdf0e10cSrcweir 				pSub->GetObj(a)->ClearMergedItem(nWhich);
185*cdf0e10cSrcweir 			}
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 			// #i43809# call parent. This will clear items on local object, too.
188*cdf0e10cSrcweir 			E3dProperties::ClearMergedItem(nWhich);
189*cdf0e10cSrcweir 		}
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 		void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
192*cdf0e10cSrcweir 		{
193*cdf0e10cSrcweir 			// call parent
194*cdf0e10cSrcweir 			E3dProperties::PostItemChange(nWhich);
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 			// local changes
197*cdf0e10cSrcweir 			E3dScene& rObj = (E3dScene&)GetSdrObject();
198*cdf0e10cSrcweir 			rObj.StructureChanged();
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 			switch(nWhich)
201*cdf0e10cSrcweir 			{
202*cdf0e10cSrcweir 				case SDRATTR_3DSCENE_PERSPECTIVE			:
203*cdf0e10cSrcweir 				case SDRATTR_3DSCENE_DISTANCE				:
204*cdf0e10cSrcweir 				case SDRATTR_3DSCENE_FOCAL_LENGTH			:
205*cdf0e10cSrcweir 				{
206*cdf0e10cSrcweir 					// #83387#, #83391#
207*cdf0e10cSrcweir 					// one common function for the camera attributes
208*cdf0e10cSrcweir 					// since SetCamera() sets all three back to the ItemSet
209*cdf0e10cSrcweir 					Camera3D aSceneCam(rObj.GetCamera());
210*cdf0e10cSrcweir 					sal_Bool bChange(sal_False);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 					// for SDRATTR_3DSCENE_PERSPECTIVE:
213*cdf0e10cSrcweir 					if(aSceneCam.GetProjection() != rObj.GetPerspective())
214*cdf0e10cSrcweir 					{
215*cdf0e10cSrcweir 						aSceneCam.SetProjection(rObj.GetPerspective());
216*cdf0e10cSrcweir 						bChange = sal_True;
217*cdf0e10cSrcweir 					}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 					// for SDRATTR_3DSCENE_DISTANCE:
220*cdf0e10cSrcweir 					basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
221*cdf0e10cSrcweir 					double fNew = rObj.GetDistance();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 					if(fNew != aActualPosition.getZ())
224*cdf0e10cSrcweir 					{
225*cdf0e10cSrcweir 						aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
226*cdf0e10cSrcweir 						bChange = sal_True;
227*cdf0e10cSrcweir 					}
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 					// for SDRATTR_3DSCENE_FOCAL_LENGTH:
230*cdf0e10cSrcweir 					fNew = rObj.GetFocalLength() / 100.0;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 					if(aSceneCam.GetFocalLength() != fNew)
233*cdf0e10cSrcweir 					{
234*cdf0e10cSrcweir 						aSceneCam.SetFocalLength(fNew);
235*cdf0e10cSrcweir 						bChange = sal_True;
236*cdf0e10cSrcweir 					}
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 					// for all
239*cdf0e10cSrcweir 					if(bChange)
240*cdf0e10cSrcweir 					{
241*cdf0e10cSrcweir 						rObj.SetCamera(aSceneCam);
242*cdf0e10cSrcweir 					}
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 					break;
245*cdf0e10cSrcweir 				}
246*cdf0e10cSrcweir 			}
247*cdf0e10cSrcweir 		}
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 		void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
250*cdf0e10cSrcweir 		{
251*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
252*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 			for(sal_uInt32 a(0L); a < nCount; a++)
255*cdf0e10cSrcweir 			{
256*cdf0e10cSrcweir 				pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
257*cdf0e10cSrcweir 			}
258*cdf0e10cSrcweir 		}
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 		SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
261*cdf0e10cSrcweir 		{
262*cdf0e10cSrcweir 			SfxStyleSheet* pRetval = 0L;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 			const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
265*cdf0e10cSrcweir 			const sal_uInt32 nCount(pSub->GetObjCount());
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 			for(sal_uInt32 a(0L); a < nCount; a++)
268*cdf0e10cSrcweir 			{
269*cdf0e10cSrcweir 				SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 				if(pRetval)
272*cdf0e10cSrcweir 				{
273*cdf0e10cSrcweir 					if(pCandidate != pRetval)
274*cdf0e10cSrcweir 					{
275*cdf0e10cSrcweir 						// different StyleSheelts, return none
276*cdf0e10cSrcweir 						return 0L;
277*cdf0e10cSrcweir 					}
278*cdf0e10cSrcweir 				}
279*cdf0e10cSrcweir 				else
280*cdf0e10cSrcweir 				{
281*cdf0e10cSrcweir 					pRetval = pCandidate;
282*cdf0e10cSrcweir 				}
283*cdf0e10cSrcweir 			}
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 			return pRetval;
286*cdf0e10cSrcweir 		}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
289*cdf0e10cSrcweir 		{
290*cdf0e10cSrcweir 			if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
291*cdf0e10cSrcweir 			{
292*cdf0e10cSrcweir 				// call parent
293*cdf0e10cSrcweir 				E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 				// own reaction, but only with outmost scene
296*cdf0e10cSrcweir 				E3dScene& rObj = (E3dScene&)GetSdrObject();
297*cdf0e10cSrcweir 				const SdrObjList* pSubList = rObj.GetSubList();
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 				if(pSubList && rObj.GetScene() == &rObj)
300*cdf0e10cSrcweir 				{
301*cdf0e10cSrcweir 					SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 					while(a3DIterator.IsMore())
304*cdf0e10cSrcweir 					{
305*cdf0e10cSrcweir 						E3dObject* pObj = (E3dObject*)a3DIterator.Next();
306*cdf0e10cSrcweir 						DBG_ASSERT(pObj->ISA(E3dObject), "In scenes there are only 3D objects allowed (!)");
307*cdf0e10cSrcweir 						pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
308*cdf0e10cSrcweir 					}
309*cdf0e10cSrcweir 				}
310*cdf0e10cSrcweir 			}
311*cdf0e10cSrcweir 		}
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 		void E3dSceneProperties::SetSceneItemsFromCamera()
314*cdf0e10cSrcweir 		{
315*cdf0e10cSrcweir 			// force ItemSet
316*cdf0e10cSrcweir 			GetObjectItemSet();
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 			E3dScene& rObj = (E3dScene&)GetSdrObject();
319*cdf0e10cSrcweir 			Camera3D aSceneCam(rObj.GetCamera());
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 			// ProjectionType
322*cdf0e10cSrcweir 			mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 			// CamPos
325*cdf0e10cSrcweir 			mpItemSet->Put(Svx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 			// FocalLength
328*cdf0e10cSrcweir 			mpItemSet->Put(Svx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
329*cdf0e10cSrcweir 		}
330*cdf0e10cSrcweir 	} // end of namespace properties
331*cdf0e10cSrcweir } // end of namespace sdr
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
334*cdf0e10cSrcweir // eof
335