update credits
[LibreOffice.git] / svx / source / sdr / properties / e3dsceneproperties.cxx
blob5b9fbed8dd3e7a12ecacba8923e7cd058a73b0af
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/properties/e3dsceneproperties.hxx>
21 #include <svl/itemset.hxx>
22 #include <svl/whiter.hxx>
23 #include <svx/svddef.hxx>
24 #include <svx/scene3d.hxx>
25 #include <svx/svditer.hxx>
27 //////////////////////////////////////////////////////////////////////////////
29 namespace sdr
31 namespace properties
33 E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
34 : E3dProperties(rObj)
38 E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
39 : E3dProperties(rProps, rObj)
43 E3dSceneProperties::~E3dSceneProperties()
47 BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
49 return *(new E3dSceneProperties(*this, rObj));
52 const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
54 //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
55 return E3dProperties::GetObjectItemSet();
58 const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
60 // prepare ItemSet
61 if(mpItemSet)
63 // filter for SDRATTR_3DSCENE_ items, only keep those items
64 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
65 aNew.Put(*mpItemSet);
66 mpItemSet->ClearItem();
67 mpItemSet->Put(aNew);
69 else
71 // No ItemSet yet, force local ItemSet
72 GetObjectItemSet();
75 // collect all ItemSets of contained 3d objects
76 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
77 const sal_uInt32 nCount(pSub->GetObjCount());
79 for(sal_uInt32 a(0L); a < nCount; a++)
81 SdrObject* pObj = pSub->GetObj(a);
83 if(pObj && pObj->ISA(E3dCompoundObject))
85 const SfxItemSet& rSet = pObj->GetMergedItemSet();
86 SfxWhichIter aIter(rSet);
87 sal_uInt16 nWhich(aIter.FirstWhich());
89 while(nWhich)
91 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
92 // and always equal.
93 if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
95 if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False))
97 mpItemSet->InvalidateItem(nWhich);
99 else
101 mpItemSet->MergeValue(rSet.Get(nWhich), sal_True);
105 nWhich = aIter.NextWhich();
110 // call parent
111 return E3dProperties::GetMergedItemSet();
114 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
116 // Set SDRATTR_3DOBJ_ range at contained objects.
117 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
118 const sal_uInt32 nCount(pSub->GetObjCount());
120 if(nCount)
122 // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
123 // #i50808# Leak fix, Clone produces a new instance and we get ownership here
124 SfxItemSet* pNewSet = rSet.Clone(sal_True);
125 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
127 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
129 pNewSet->ClearItem(b);
132 if(pNewSet->Count())
134 for(sal_uInt32 a(0L); a < nCount; a++)
136 SdrObject* pObj = pSub->GetObj(a);
138 if(pObj && pObj->ISA(E3dCompoundObject))
140 // set merged ItemSet at contained 3d object.
141 pObj->SetMergedItemSet(*pNewSet, bClearAllItems);
146 delete pNewSet;
149 // call parent. This will set items on local object, too.
150 E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
153 void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
155 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
156 const sal_uInt32 nCount(pSub->GetObjCount());
158 for(sal_uInt32 a(0L); a < nCount; a++)
160 pSub->GetObj(a)->SetMergedItem(rItem);
163 // #i43809# call parent. This will set items on local object, too.
164 E3dProperties::SetMergedItem(rItem);
167 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
169 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
170 const sal_uInt32 nCount(pSub->GetObjCount());
172 for(sal_uInt32 a(0L); a < nCount; a++)
174 pSub->GetObj(a)->ClearMergedItem(nWhich);
177 // #i43809# call parent. This will clear items on local object, too.
178 E3dProperties::ClearMergedItem(nWhich);
181 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
183 // call parent
184 E3dProperties::PostItemChange(nWhich);
186 // local changes
187 E3dScene& rObj = (E3dScene&)GetSdrObject();
188 rObj.StructureChanged();
190 switch(nWhich)
192 case SDRATTR_3DSCENE_PERSPECTIVE :
193 case SDRATTR_3DSCENE_DISTANCE :
194 case SDRATTR_3DSCENE_FOCAL_LENGTH :
196 // #83387#, #83391#
197 // one common function for the camera attributes
198 // since SetCamera() sets all three back to the ItemSet
199 Camera3D aSceneCam(rObj.GetCamera());
200 bool bChange(false);
202 // for SDRATTR_3DSCENE_PERSPECTIVE:
203 if(aSceneCam.GetProjection() != rObj.GetPerspective())
205 aSceneCam.SetProjection(rObj.GetPerspective());
206 bChange = true;
209 // for SDRATTR_3DSCENE_DISTANCE:
210 basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
211 double fNew = rObj.GetDistance();
213 if(fNew != aActualPosition.getZ())
215 aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
216 bChange = true;
219 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
220 fNew = rObj.GetFocalLength() / 100.0;
222 if(aSceneCam.GetFocalLength() != fNew)
224 aSceneCam.SetFocalLength(fNew);
225 bChange = true;
228 // for all
229 if(bChange)
231 rObj.SetCamera(aSceneCam);
234 break;
239 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
241 const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
242 const sal_uInt32 nCount(pSub->GetObjCount());
244 for(sal_uInt32 a(0L); a < nCount; a++)
246 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
250 SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
252 SfxStyleSheet* pRetval = 0L;
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 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
261 if(pRetval)
263 if(pCandidate != pRetval)
265 // different StyleSheelts, return none
266 return 0L;
269 else
271 pRetval = pCandidate;
275 return pRetval;
278 void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
280 if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
282 // call parent
283 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
285 // own reaction, but only with outmost scene
286 E3dScene& rObj = (E3dScene&)GetSdrObject();
287 const SdrObjList* pSubList = rObj.GetSubList();
289 if(pSubList && rObj.GetScene() == &rObj)
291 SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
293 while(a3DIterator.IsMore())
295 E3dObject* pObj = (E3dObject*)a3DIterator.Next();
296 DBG_ASSERT(pObj->ISA(E3dObject), "In scenes there are only 3D objects allowed (!)");
297 pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
303 void E3dSceneProperties::SetSceneItemsFromCamera()
305 // force ItemSet
306 GetObjectItemSet();
308 E3dScene& rObj = (E3dScene&)GetSdrObject();
309 Camera3D aSceneCam(rObj.GetCamera());
311 // ProjectionType
312 mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
314 // CamPos
315 mpItemSet->Put(Svx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
317 // FocalLength
318 mpItemSet->Put(Svx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
320 } // end of namespace properties
321 } // end of namespace sdr
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */