Update ooo320-m1
[ooovba.git] / svx / source / sdr / properties / e3dsceneproperties.cxx
blob28ebae1b9a1a513c4e570331d11ca85490954eee
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: e3dsceneproperties.cxx,v $
10 * $Revision: 1.11.226.1 $
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_svx.hxx"
33 #include <svx/sdr/properties/e3dsceneproperties.hxx>
34 #include <svtools/itemset.hxx>
35 #include <svtools/whiter.hxx>
36 #include <svx/svddef.hxx>
37 #include <svx/scene3d.hxx>
38 #include <svditer.hxx>
40 //////////////////////////////////////////////////////////////////////////////
42 namespace sdr
44 namespace properties
46 E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
47 : E3dProperties(rObj)
51 E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
52 : E3dProperties(rProps, rObj)
56 E3dSceneProperties::~E3dSceneProperties()
60 BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
62 return *(new E3dSceneProperties(*this, rObj));
65 const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
67 //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
68 return E3dProperties::GetObjectItemSet();
71 const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
73 // prepare ItemSet
74 if(mpItemSet)
76 // filter for SDRATTR_3DSCENE_ items, only keep those items
77 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
78 aNew.Put(*mpItemSet);
79 mpItemSet->ClearItem();
80 mpItemSet->Put(aNew);
82 else
84 // No ItemSet yet, force local ItemSet
85 GetObjectItemSet();
88 // collect all ItemSets of contained 3d objects
89 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
90 const sal_uInt32 nCount(pSub->GetObjCount());
92 for(sal_uInt32 a(0L); a < nCount; a++)
94 SdrObject* pObj = pSub->GetObj(a);
96 if(pObj && pObj->ISA(E3dCompoundObject))
98 const SfxItemSet& rSet = pObj->GetMergedItemSet();
99 SfxWhichIter aIter(rSet);
100 sal_uInt16 nWhich(aIter.FirstWhich());
102 while(nWhich)
104 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
105 // and always equal.
106 if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
108 if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, FALSE))
110 mpItemSet->InvalidateItem(nWhich);
112 else
114 mpItemSet->MergeValue(rSet.Get(nWhich), TRUE);
118 nWhich = aIter.NextWhich();
123 // call parent
124 return E3dProperties::GetMergedItemSet();
127 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
129 // Set SDRATTR_3DOBJ_ range at contained objects.
130 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
131 const sal_uInt32 nCount(pSub->GetObjCount());
133 if(nCount)
135 // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
136 // #i50808# Leak fix, Clone produces a new instance and we get ownership here
137 SfxItemSet* pNewSet = rSet.Clone(TRUE);
138 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
140 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
142 pNewSet->ClearItem(b);
145 if(pNewSet->Count())
147 for(sal_uInt32 a(0L); a < nCount; a++)
149 SdrObject* pObj = pSub->GetObj(a);
151 if(pObj && pObj->ISA(E3dCompoundObject))
153 // set merged ItemSet at contained 3d object.
154 pObj->SetMergedItemSet(*pNewSet, bClearAllItems);
159 delete pNewSet;
162 // call parent. This will set items on local object, too.
163 E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
166 void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
168 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
169 const sal_uInt32 nCount(pSub->GetObjCount());
171 for(sal_uInt32 a(0L); a < nCount; a++)
173 pSub->GetObj(a)->SetMergedItem(rItem);
176 // #i43809# call parent. This will set items on local object, too.
177 E3dProperties::SetMergedItem(rItem);
180 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
182 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
183 const sal_uInt32 nCount(pSub->GetObjCount());
185 for(sal_uInt32 a(0L); a < nCount; a++)
187 pSub->GetObj(a)->ClearMergedItem(nWhich);
190 // #i43809# call parent. This will clear items on local object, too.
191 E3dProperties::ClearMergedItem(nWhich);
194 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
196 // call parent
197 E3dProperties::PostItemChange(nWhich);
199 // local changes
200 E3dScene& rObj = (E3dScene&)GetSdrObject();
201 rObj.StructureChanged();
203 switch(nWhich)
205 case SDRATTR_3DSCENE_PERSPECTIVE :
206 case SDRATTR_3DSCENE_DISTANCE :
207 case SDRATTR_3DSCENE_FOCAL_LENGTH :
209 // #83387#, #83391#
210 // one common function for the camera attributes
211 // since SetCamera() sets all three back to the ItemSet
212 Camera3D aSceneCam(rObj.GetCamera());
213 sal_Bool bChange(sal_False);
215 // for SDRATTR_3DSCENE_PERSPECTIVE:
216 if(aSceneCam.GetProjection() != rObj.GetPerspective())
218 aSceneCam.SetProjection(rObj.GetPerspective());
219 bChange = sal_True;
222 // for SDRATTR_3DSCENE_DISTANCE:
223 basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
224 double fNew = rObj.GetDistance();
226 if(fNew != aActualPosition.getZ())
228 aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
229 bChange = sal_True;
232 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
233 fNew = rObj.GetFocalLength() / 100.0;
235 if(aSceneCam.GetFocalLength() != fNew)
237 aSceneCam.SetFocalLength(fNew);
238 bChange = sal_True;
241 // for all
242 if(bChange)
244 rObj.SetCamera(aSceneCam);
247 break;
252 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
254 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
255 const sal_uInt32 nCount(pSub->GetObjCount());
257 for(sal_uInt32 a(0L); a < nCount; a++)
259 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
263 SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
265 SfxStyleSheet* pRetval = 0L;
267 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
268 const sal_uInt32 nCount(pSub->GetObjCount());
270 for(sal_uInt32 a(0L); a < nCount; a++)
272 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
274 if(pRetval)
276 if(pCandidate != pRetval)
278 // different StyleSheelts, return none
279 return 0L;
282 else
284 pRetval = pCandidate;
288 return pRetval;
291 void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
293 if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
295 // call parent
296 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
298 // own reaction, but only with outmost scene
299 E3dScene& rObj = (E3dScene&)GetSdrObject();
300 const SdrObjList* pSubList = rObj.GetSubList();
302 if(pSubList && rObj.GetScene() == &rObj)
304 SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
306 while(a3DIterator.IsMore())
308 E3dObject* pObj = (E3dObject*)a3DIterator.Next();
309 DBG_ASSERT(pObj->ISA(E3dObject), "In scenes there are only 3D objects allowed (!)");
310 pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
316 void E3dSceneProperties::SetSceneItemsFromCamera()
318 // force ItemSet
319 GetObjectItemSet();
321 E3dScene& rObj = (E3dScene&)GetSdrObject();
322 Camera3D aSceneCam(rObj.GetCamera());
324 // ProjectionType
325 mpItemSet->Put(Svx3DPerspectiveItem((UINT16)aSceneCam.GetProjection()));
327 // CamPos
328 mpItemSet->Put(Svx3DDistanceItem((UINT32)(aSceneCam.GetPosition().getZ() + 0.5)));
330 // FocalLength
331 mpItemSet->Put(Svx3DFocalLengthItem((UINT32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
333 } // end of namespace properties
334 } // end of namespace sdr
336 //////////////////////////////////////////////////////////////////////////////
337 // eof