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