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(*mxItemSet
->GetPool());
58 mxItemSet
->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 (!)");
70 const size_t nCount(nullptr == pSub
? 0 : pSub
->GetObjCount());
72 for(size_t a
= 0; a
< nCount
; ++a
)
74 SdrObject
* pObj
= pSub
->GetObj(a
);
76 if(dynamic_cast<const E3dCompoundObject
* >(pObj
))
78 const SfxItemSet
& rSet
= pObj
->GetMergedItemSet();
79 SfxWhichIter
aIter(rSet
);
80 sal_uInt16
nWhich(aIter
.FirstWhich());
84 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
86 if(nWhich
<= SDRATTR_3DSCENE_FIRST
|| nWhich
>= SDRATTR_3DSCENE_LAST
)
88 if(SfxItemState::DONTCARE
== aIter
.GetItemState(false))
90 mxItemSet
->InvalidateItem(nWhich
);
94 mxItemSet
->MergeValue(rSet
.Get(nWhich
), true);
98 nWhich
= aIter
.NextWhich();
104 return E3dProperties::GetMergedItemSet();
107 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet
& rSet
, bool bClearAllItems
)
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());
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());
120 for(sal_uInt16
b(SDRATTR_3DSCENE_FIRST
); b
<= SDRATTR_3DSCENE_LAST
; b
++)
122 xNewSet
->ClearItem(b
);
127 for(size_t a
= 0; a
< nCount
; ++a
)
129 SdrObject
* pObj
= pSub
->GetObj(a
);
131 if(dynamic_cast<const E3dCompoundObject
* >(pObj
))
133 // set merged ItemSet at contained 3d object.
134 pObj
->SetMergedItemSet(*xNewSet
, bClearAllItems
);
140 // call parent. This will set items on local object, too.
141 E3dProperties::SetMergedItemSet(rSet
, bClearAllItems
);
144 void E3dSceneProperties::SetMergedItem(const SfxPoolItem
& rItem
)
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());
150 for(size_t a
= 0; a
< nCount
; ++a
)
152 pSub
->GetObj(a
)->SetMergedItem(rItem
);
155 // #i43809# call parent. This will set items on local object, too.
156 E3dProperties::SetMergedItem(rItem
);
159 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich
)
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());
165 for(size_t a
= 0; a
< nCount
; ++a
)
167 pSub
->GetObj(a
)->ClearMergedItem(nWhich
);
170 // #i43809# call parent. This will clear items on local object, too.
171 E3dProperties::ClearMergedItem(nWhich
);
174 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich
)
177 E3dProperties::PostItemChange(nWhich
);
180 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
181 rObj
.StructureChanged();
185 case SDRATTR_3DSCENE_PERSPECTIVE
:
186 case SDRATTR_3DSCENE_DISTANCE
:
187 case SDRATTR_3DSCENE_FOCAL_LENGTH
:
190 // one common function for the camera attributes
191 // since SetCamera() sets all three back to the ItemSet
192 Camera3D
aSceneCam(rObj
.GetCamera());
195 // for SDRATTR_3DSCENE_PERSPECTIVE:
196 if(aSceneCam
.GetProjection() != rObj
.GetPerspective())
198 aSceneCam
.SetProjection(rObj
.GetPerspective());
202 // for SDRATTR_3DSCENE_DISTANCE:
203 basegfx::B3DPoint
aActualPosition(aSceneCam
.GetPosition());
204 double fNew
= rObj
.GetDistance();
206 if(fNew
!= aActualPosition
.getZ())
208 aSceneCam
.SetPosition(basegfx::B3DPoint(aActualPosition
.getX(), aActualPosition
.getY(), fNew
));
212 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
213 fNew
= rObj
.GetFocalLength() / 100.0;
215 if(aSceneCam
.GetFocalLength() != fNew
)
217 aSceneCam
.SetFocalLength(fNew
);
224 rObj
.SetCamera(aSceneCam
);
232 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
,
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());
239 for(size_t a
= 0; a
< nCount
; ++a
)
242 pSub
->GetObj(a
)->SetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
);
244 pSub
->GetObj(a
)->NbcSetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
);
248 SfxStyleSheet
* E3dSceneProperties::GetStyleSheet() const
250 SfxStyleSheet
* pRetval
= nullptr;
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());
256 for(size_t a
= 0; a
< nCount
; ++a
)
258 SfxStyleSheet
* pCandidate
= pSub
->GetObj(a
)->GetStyleSheet();
262 if(pCandidate
!= pRetval
)
264 // different StyleSheelts, return none
270 pRetval
= pCandidate
;
277 void E3dSceneProperties::SetSceneItemsFromCamera()
282 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
283 const Camera3D
& aSceneCam(rObj
.GetCamera());
286 mxItemSet
->Put(Svx3DPerspectiveItem(aSceneCam
.GetProjection()));
289 mxItemSet
->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32
>(aSceneCam
.GetPosition().getZ() + 0.5)));
292 mxItemSet
->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32
>((aSceneCam
.GetFocalLength() * 100.0) + 0.5)));
294 } // end of namespace
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */