LibreOffice Module svx (master)  1
e3dsceneproperties.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
21 #include <svl/itemset.hxx>
22 #include <svl/whiter.hxx>
23 #include <svx/svddef.hxx>
24 #include <svx/scene3d.hxx>
25 #include <memory>
26 
27 
28 namespace sdr::properties
29 {
31  : E3dProperties(rObj)
32  {
33  }
34 
36  : E3dProperties(rProps, rObj)
37  {
38  }
39 
41  {
42  }
43 
44  std::unique_ptr<BaseProperties> E3dSceneProperties::Clone(SdrObject& rObj) const
45  {
46  return std::unique_ptr<BaseProperties>(new E3dSceneProperties(*this, rObj));
47  }
48 
50  {
51  // prepare ItemSet
52  if(mpItemSet)
53  {
54  // filter for SDRATTR_3DSCENE_ items, only keep those items
56  aNew.Put(*mpItemSet);
57  mpItemSet->ClearItem();
58  mpItemSet->Put(aNew);
59  }
60  else
61  {
62  // No ItemSet yet, force local ItemSet
64  }
65 
66  // collect all ItemSets of contained 3d objects
67  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
68  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
69  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
70 
71  for(size_t a = 0; a < nCount; ++a)
72  {
73  SdrObject* pObj = pSub->GetObj(a);
74 
75  if(dynamic_cast<const E3dCompoundObject* >(pObj))
76  {
77  const SfxItemSet& rSet = pObj->GetMergedItemSet();
78  SfxWhichIter aIter(rSet);
79  sal_uInt16 nWhich(aIter.FirstWhich());
80 
81  while(nWhich)
82  {
83  // Leave out the SDRATTR_3DSCENE_ range, this would only be double
84  // and always equal.
85  if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
86  {
87  if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
88  {
89  mpItemSet->InvalidateItem(nWhich);
90  }
91  else
92  {
93  mpItemSet->MergeValue(rSet.Get(nWhich), true);
94  }
95  }
96 
97  nWhich = aIter.NextWhich();
98  }
99  }
100  }
101 
102  // call parent
104  }
105 
106  void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
107  {
108  // Set SDRATTR_3DOBJ_ range at contained objects.
109  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
110  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
111  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
112 
113  if(nCount)
114  {
115  // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
116  // #i50808# Leak fix, Clone produces a new instance and we get ownership here
117  std::unique_ptr<SfxItemSet> pNewSet(rSet.Clone());
118  DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
119 
120  for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
121  {
122  pNewSet->ClearItem(b);
123  }
124 
125  if(pNewSet->Count())
126  {
127  for(size_t a = 0; a < nCount; ++a)
128  {
129  SdrObject* pObj = pSub->GetObj(a);
130 
131  if(dynamic_cast<const E3dCompoundObject* >(pObj))
132  {
133  // set merged ItemSet at contained 3d object.
134  pObj->SetMergedItemSet(*pNewSet, bClearAllItems);
135  }
136  }
137  }
138  }
139 
140  // call parent. This will set items on local object, too.
141  E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
142  }
143 
145  {
146  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
147  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
148  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
149 
150  for(size_t a = 0; a < nCount; ++a)
151  {
152  pSub->GetObj(a)->SetMergedItem(rItem);
153  }
154 
155  // #i43809# call parent. This will set items on local object, too.
157  }
158 
159  void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
160  {
161  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
162  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
163  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
164 
165  for(size_t a = 0; a < nCount; ++a)
166  {
167  pSub->GetObj(a)->ClearMergedItem(nWhich);
168  }
169 
170  // #i43809# call parent. This will clear items on local object, too.
172  }
173 
174  void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
175  {
176  // call parent
178 
179  // local changes
180  E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
181  rObj.StructureChanged();
182 
183  switch(nWhich)
184  {
188  {
189  // #83387#, #83391#
190  // one common function for the camera attributes
191  // since SetCamera() sets all three back to the ItemSet
192  Camera3D aSceneCam(rObj.GetCamera());
193  bool bChange(false);
194 
195  // for SDRATTR_3DSCENE_PERSPECTIVE:
196  if(aSceneCam.GetProjection() != rObj.GetPerspective())
197  {
198  aSceneCam.SetProjection(rObj.GetPerspective());
199  bChange = true;
200  }
201 
202  // for SDRATTR_3DSCENE_DISTANCE:
203  basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
204  double fNew = rObj.GetDistance();
205 
206  if(fNew != aActualPosition.getZ())
207  {
208  aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
209  bChange = true;
210  }
211 
212  // for SDRATTR_3DSCENE_FOCAL_LENGTH:
213  fNew = rObj.GetFocalLength() / 100.0;
214 
215  if(aSceneCam.GetFocalLength() != fNew)
216  {
217  aSceneCam.SetFocalLength(fNew);
218  bChange = true;
219  }
220 
221  // for all
222  if(bChange)
223  {
224  rObj.SetCamera(aSceneCam);
225  }
226 
227  break;
228  }
229  }
230  }
231 
232  void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
233  {
234  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
235  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
236  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
237 
238  for(size_t a = 0; a < nCount; ++a)
239  {
240  pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
241  }
242  }
243 
245  {
246  SfxStyleSheet* pRetval = nullptr;
247 
248  const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
249  OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
250  const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
251 
252  for(size_t a = 0; a < nCount; ++a)
253  {
254  SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
255 
256  if(pRetval)
257  {
258  if(pCandidate != pRetval)
259  {
260  // different StyleSheelts, return none
261  return nullptr;
262  }
263  }
264  else
265  {
266  pRetval = pCandidate;
267  }
268  }
269 
270  return pRetval;
271  }
272 
274  {
275  // force ItemSet
277 
278  E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
279  const Camera3D& aSceneCam(rObj.GetCamera());
280 
281  // ProjectionType
282  mpItemSet->Put(Svx3DPerspectiveItem(aSceneCam.GetProjection()));
283 
284  // CamPos
285  mpItemSet->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32>(aSceneCam.GetPosition().getZ() + 0.5)));
286 
287  // FocalLength
288  mpItemSet->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32>((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
289  }
290 } // end of namespace
291 
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 SDRATTR_3DSCENE_FIRST(SDRATTR_3DOBJ_LAST+1)
virtual void StructureChanged() override
Definition: scene3d.cxx:344
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2146
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
size_t GetObjCount() const
Definition: svdpage.cxx:752
virtual void PostItemChange(const sal_uInt16 nWhich) override
sal_uInt16 FirstWhich()
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void PostItemChange(const sal_uInt16 nWhich) override
std::unique_ptr< SfxItemSet > mpItemSet
double GetDistance() const
Definition: scene3d.hxx:107
sal_uInt16 NextWhich()
ProjectionType GetPerspective() const
Definition: scene3d.hxx:103
virtual const SfxItemSet & GetMergedItemSet() const
Definition: properties.cxx:69
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: properties.cxx:75
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_DISTANCE(SDRATTR_3DSCENE_FIRST+1)
void ClearMergedItem(const sal_uInt16 nWhich=0)
Definition: svdobj.cxx:1905
void SetCamera(const Camera3D &rNewCamera)
Definition: scene3d.cxx:316
int nCount
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2141
double GetFocalLength() const
Definition: scene3d.hxx:111
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1915
SfxUInt32Item makeSvx3DFocalLengthItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:159
virtual const SfxItemSet & GetMergedItemSet() const override
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
uno_Any a
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) Svx3DPerspectiveItem SfxUInt32Item makeSvx3DDistanceItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:155
void SetMergedItem(const SfxPoolItem &rItem)
Definition: svdobj.cxx:1900
constexpr TypedWhichId< Svx3DPerspectiveItem > SDRATTR_3DSCENE_PERSPECTIVE(SDRATTR_3DSCENE_FIRST+0)
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr) override
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_FOCAL_LENGTH(SDRATTR_3DSCENE_FIRST+2)
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
constexpr sal_uInt16 SDRATTR_3DSCENE_LAST(SDRATTR_3DSCENE_SHADE_MODE)
virtual SfxStyleSheet * GetStyleSheet() const override
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1890
virtual void ClearMergedItem(const sal_uInt16 nWhich) override
virtual void SetMergedItem(const SfxPoolItem &rItem) override
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:87
const SdrObject & GetSdrObject() const
Definition: properties.cxx:59
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false) override
const Camera3D & GetCamera() const
Definition: scene3d.hxx:127
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:93