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