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 <osl/diagnose.h>
26#include <memory>
27
28
29namespace 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(mxItemSet)
54 {
55 // filter for SDRATTR_3DSCENE_ items, only keep those items
57 aNew.Put(*mxItemSet);
58 mxItemSet->ClearItem();
59 mxItemSet->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 == aIter.GetItemState(false))
89 {
90 mxItemSet->InvalidateItem(nWhich);
91 }
92 else
93 {
94 mxItemSet->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> xNewSet(rSet.Clone());
119
120 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
121 {
122 xNewSet->ClearItem(b);
123 }
124
125 if(xNewSet->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(*xNewSet, 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 bool bBroadcast)
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 if(bBroadcast)
242 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
243 else
244 pSub->GetObj(a)->NbcSetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
245 }
246 }
247
249 {
250 SfxStyleSheet* pRetval = nullptr;
251
252 const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
253 OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
254 const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
255
256 for(size_t a = 0; a < nCount; ++a)
257 {
258 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
259
260 if(pRetval)
261 {
262 if(pCandidate != pRetval)
263 {
264 // different StyleSheelts, return none
265 return nullptr;
266 }
267 }
268 else
269 {
270 pRetval = pCandidate;
271 }
272 }
273
274 return pRetval;
275 }
276
278 {
279 // force ItemSet
281
282 E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
283 const Camera3D& aSceneCam(rObj.GetCamera());
284
285 // ProjectionType
286 mxItemSet->Put(Svx3DPerspectiveItem(aSceneCam.GetProjection()));
287
288 // CamPos
289 mxItemSet->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32>(aSceneCam.GetPosition().getZ() + 0.5)));
290
291 // FocalLength
292 mxItemSet->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32>((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
293 }
294} // end of namespace
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetPosition(const basegfx::B3DPoint &rNewPos)
Definition: camera3d.cxx:48
void SetFocalLength(double fLen)
Definition: camera3d.cxx:172
const basegfx::B3DPoint & GetPosition() const
Definition: camera3d.hxx:51
double GetFocalLength() const
Definition: camera3d.hxx:57
virtual void StructureChanged() override
Definition: scene3d.cxx:371
double GetFocalLength() const
Definition: scene3d.hxx:109
ProjectionType GetPerspective() const
Definition: scene3d.hxx:101
double GetDistance() const
Definition: scene3d.hxx:105
void SetCamera(const Camera3D &rNewCamera)
Definition: scene3d.cxx:343
const Camera3D & GetCamera() const
Definition: scene3d.hxx:125
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:785
size_t GetObjCount() const
Definition: svdpage.cxx:779
Abstract DrawObject.
Definition: svdobj.hxx:260
void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2249
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: svdobj.cxx:1999
void NbcSetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr)
Definition: svdobj.cxx:2262
SfxStyleSheet * GetStyleSheet() const
Definition: svdobj.cxx:2244
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1974
void ClearMergedItem(const sal_uInt16 nWhich=0)
Definition: svdobj.cxx:1989
void SetMergedItem(const SfxPoolItem &rItem)
Definition: svdobj.cxx:1984
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
void SetProjection(ProjectionType ePrj)
Definition: viewpt3d.hxx:80
ProjectionType GetProjection() const
Definition: viewpt3d.hxx:82
TYPE getX() const
TYPE getZ() const
TYPE getY() const
virtual const SfxItemSet & GetObjectItemSet() const override
virtual void ClearMergedItem(const sal_uInt16 nWhich)
Definition: properties.cxx:77
const SdrObject & GetSdrObject() const
Definition: properties.cxx:43
virtual const SfxItemSet & GetMergedItemSet() const
Definition: properties.cxx:53
virtual void SetMergedItem(const SfxPoolItem &rItem)
Definition: properties.cxx:71
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
Definition: properties.cxx:59
std::optional< SfxItemSet > mxItemSet
virtual void PostItemChange(const sal_uInt16 nWhich)
virtual void PostItemChange(const sal_uInt16 nWhich) override
virtual SfxStyleSheet * GetStyleSheet() const override
virtual void SetMergedItem(const SfxPoolItem &rItem) override
virtual const SfxItemSet & GetMergedItemSet() const override
virtual void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false) override
virtual void SetStyleSheet(SfxStyleSheet *pNewStyleSheet, bool bDontRemoveHardAttr, bool bBroadcast) override
virtual void ClearMergedItem(const sal_uInt16 nWhich) override
virtual std::unique_ptr< BaseProperties > Clone(SdrObject &rObj) const override
int nCount
uno_Any a
static SfxItemSet & rSet
constexpr TypedWhichId< Svx3DPerspectiveItem > SDRATTR_3DSCENE_PERSPECTIVE(SDRATTR_3DSCENE_FIRST+0)
constexpr sal_uInt16 SDRATTR_3DSCENE_FIRST(SDRATTR_3DOBJ_LAST+1)
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_FOCAL_LENGTH(SDRATTR_3DSCENE_FIRST+2)
constexpr TypedWhichId< SfxUInt32Item > SDRATTR_3DSCENE_DISTANCE(SDRATTR_3DSCENE_FIRST+1)
constexpr sal_uInt16 SDRATTR_3DSCENE_LAST(SDRATTR_3DSCENE_SHADE_MODE)
class UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC) Svx3DPerspectiveItem final SfxUInt32Item makeSvx3DDistanceItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:155
SfxUInt32Item makeSvx3DFocalLengthItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:159