1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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 <osl/diagnose.h>
29 namespace sdr::properties
31 E3dSceneProperties::E3dSceneProperties(SdrObject
& rObj
)
36 E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties
& rProps
, SdrObject
& rObj
)
37 : E3dProperties(rProps
, rObj
)
41 E3dSceneProperties::~E3dSceneProperties()
45 std::unique_ptr
<BaseProperties
> E3dSceneProperties::Clone(SdrObject
& rObj
) const
47 return std::unique_ptr
<BaseProperties
>(new E3dSceneProperties(*this, rObj
));
50 const SfxItemSet
& E3dSceneProperties::GetMergedItemSet() const
55 // filter for SDRATTR_3DSCENE_ items, only keep those items
56 SfxItemSetFixed
<SDRATTR_3DSCENE_FIRST
, SDRATTR_3DSCENE_LAST
> aNew(*moItemSet
->GetPool());
58 moItemSet
->ClearItem();
63 // No ItemSet yet, force local ItemSet
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 (!)");
72 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
74 if(dynamic_cast<const E3dCompoundObject
* >(pObj
.get()))
76 const SfxItemSet
& rSet
= pObj
->GetMergedItemSet();
77 SfxWhichIter
aIter(rSet
);
78 sal_uInt16
nWhich(aIter
.FirstWhich());
82 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
84 if(nWhich
<= SDRATTR_3DSCENE_FIRST
|| nWhich
>= SDRATTR_3DSCENE_LAST
)
86 if(SfxItemState::INVALID
== aIter
.GetItemState(false))
88 moItemSet
->InvalidateItem(nWhich
);
92 moItemSet
->MergeValue(rSet
.Get(nWhich
));
96 nWhich
= aIter
.NextWhich();
102 return E3dProperties::GetMergedItemSet();
105 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet
& rSet
, bool bClearAllItems
, bool bAdjustTextFrameWidthAndHeight
)
107 // Set SDRATTR_3DOBJ_ range at contained objects.
108 const SdrObjList
* pSub(static_cast<const E3dScene
&>(GetSdrObject()).GetSubList());
109 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
110 const size_t nCount(nullptr == pSub
? 0 : pSub
->GetObjCount());
114 // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
115 // #i50808# Leak fix, Clone produces a new instance and we get ownership here
116 std::unique_ptr
<SfxItemSet
> xNewSet(rSet
.Clone());
118 for(sal_uInt16
b(SDRATTR_3DSCENE_FIRST
); b
<= SDRATTR_3DSCENE_LAST
; b
++)
120 xNewSet
->ClearItem(b
);
125 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
127 if(dynamic_cast<const E3dCompoundObject
* >(pObj
.get()))
129 // set merged ItemSet at contained 3d object.
130 pObj
->SetMergedItemSet(*xNewSet
, bClearAllItems
, bAdjustTextFrameWidthAndHeight
);
136 // call parent. This will set items on local object, too.
137 E3dProperties::SetMergedItemSet(rSet
, bClearAllItems
, bAdjustTextFrameWidthAndHeight
);
140 void E3dSceneProperties::SetMergedItem(const SfxPoolItem
& rItem
)
142 const SdrObjList
* pSub(static_cast<const E3dScene
&>(GetSdrObject()).GetSubList());
143 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
145 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
146 pObj
->SetMergedItem(rItem
);
148 // #i43809# call parent. This will set items on local object, too.
149 E3dProperties::SetMergedItem(rItem
);
152 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich
)
154 const SdrObjList
* pSub(static_cast<const E3dScene
&>(GetSdrObject()).GetSubList());
155 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
157 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
158 pObj
->ClearMergedItem(nWhich
);
160 // #i43809# call parent. This will clear items on local object, too.
161 E3dProperties::ClearMergedItem(nWhich
);
164 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich
)
167 E3dProperties::PostItemChange(nWhich
);
170 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
171 rObj
.StructureChanged();
175 case SDRATTR_3DSCENE_PERSPECTIVE
:
176 case SDRATTR_3DSCENE_DISTANCE
:
177 case SDRATTR_3DSCENE_FOCAL_LENGTH
:
180 // one common function for the camera attributes
181 // since SetCamera() sets all three back to the ItemSet
182 Camera3D
aSceneCam(rObj
.GetCamera());
185 // for SDRATTR_3DSCENE_PERSPECTIVE:
186 if(aSceneCam
.GetProjection() != rObj
.GetPerspective())
188 aSceneCam
.SetProjection(rObj
.GetPerspective());
192 // for SDRATTR_3DSCENE_DISTANCE:
193 basegfx::B3DPoint
aActualPosition(aSceneCam
.GetPosition());
194 double fNew
= rObj
.GetDistance();
196 if(fNew
!= aActualPosition
.getZ())
198 aSceneCam
.SetPosition(basegfx::B3DPoint(aActualPosition
.getX(), aActualPosition
.getY(), fNew
));
202 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
203 fNew
= rObj
.GetFocalLength() / 100.0;
205 if(aSceneCam
.GetFocalLength() != fNew
)
207 aSceneCam
.SetFocalLength(fNew
);
214 rObj
.SetCamera(aSceneCam
);
222 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
,
223 bool bBroadcast
, bool bAdjustTextFrameWidthAndHeight
)
225 const SdrObjList
* pSub(static_cast<const E3dScene
&>(GetSdrObject()).GetSubList());
226 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
229 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
232 pObj
->SetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
);
234 pObj
->NbcSetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
, bAdjustTextFrameWidthAndHeight
);
238 SfxStyleSheet
* E3dSceneProperties::GetStyleSheet() const
240 SfxStyleSheet
* pRetval
= nullptr;
242 const SdrObjList
* pSub(static_cast<const E3dScene
&>(GetSdrObject()).GetSubList());
243 OSL_ENSURE(nullptr != pSub
, "Children of SdrObject expected (!)");
246 for (const rtl::Reference
<SdrObject
>& pObj
: *pSub
)
248 SfxStyleSheet
* pCandidate
= pObj
->GetStyleSheet();
252 if(pCandidate
!= pRetval
)
254 // different StyleSheelts, return none
260 pRetval
= pCandidate
;
267 void E3dSceneProperties::SetSceneItemsFromCamera()
272 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
273 const Camera3D
& aSceneCam(rObj
.GetCamera());
276 moItemSet
->Put(Svx3DPerspectiveItem(aSceneCam
.GetProjection()));
279 moItemSet
->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32
>(aSceneCam
.GetPosition().getZ() + 0.5)));
282 moItemSet
->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32
>((aSceneCam
.GetFocalLength() * 100.0) + 0.5)));
284 } // end of namespace
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */