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 <svx/svditer.hxx>
33 E3dSceneProperties::E3dSceneProperties(SdrObject
& rObj
)
38 E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties
& rProps
, SdrObject
& rObj
)
39 : E3dProperties(rProps
, rObj
)
43 E3dSceneProperties::~E3dSceneProperties()
47 std::unique_ptr
<BaseProperties
> E3dSceneProperties::Clone(SdrObject
& rObj
) const
49 return std::unique_ptr
<BaseProperties
>(new E3dSceneProperties(*this, rObj
));
52 const SfxItemSet
& E3dSceneProperties::GetMergedItemSet() const
57 // filter for SDRATTR_3DSCENE_ items, only keep those items
58 SfxItemSet
aNew(*mpItemSet
->GetPool(), svl::Items
<SDRATTR_3DSCENE_FIRST
, SDRATTR_3DSCENE_LAST
>{});
60 mpItemSet
->ClearItem();
65 // No ItemSet yet, force local ItemSet
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());
74 for(size_t a
= 0; a
< nCount
; ++a
)
76 SdrObject
* pObj
= pSub
->GetObj(a
);
78 if(dynamic_cast<const E3dCompoundObject
* >(pObj
))
80 const SfxItemSet
& rSet
= pObj
->GetMergedItemSet();
81 SfxWhichIter
aIter(rSet
);
82 sal_uInt16
nWhich(aIter
.FirstWhich());
86 // Leave out the SDRATTR_3DSCENE_ range, this would only be double
88 if(nWhich
<= SDRATTR_3DSCENE_FIRST
|| nWhich
>= SDRATTR_3DSCENE_LAST
)
90 if(SfxItemState::DONTCARE
== rSet
.GetItemState(nWhich
, false))
92 mpItemSet
->InvalidateItem(nWhich
);
96 mpItemSet
->MergeValue(rSet
.Get(nWhich
), true);
100 nWhich
= aIter
.NextWhich();
106 return E3dProperties::GetMergedItemSet();
109 void E3dSceneProperties::SetMergedItemSet(const SfxItemSet
& rSet
, bool bClearAllItems
)
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());
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 (!)");
123 for(sal_uInt16
b(SDRATTR_3DSCENE_FIRST
); b
<= SDRATTR_3DSCENE_LAST
; b
++)
125 pNewSet
->ClearItem(b
);
130 for(size_t a
= 0; a
< nCount
; ++a
)
132 SdrObject
* pObj
= pSub
->GetObj(a
);
134 if(dynamic_cast<const E3dCompoundObject
* >(pObj
))
136 // set merged ItemSet at contained 3d object.
137 pObj
->SetMergedItemSet(*pNewSet
, bClearAllItems
);
143 // call parent. This will set items on local object, too.
144 E3dProperties::SetMergedItemSet(rSet
, bClearAllItems
);
147 void E3dSceneProperties::SetMergedItem(const SfxPoolItem
& rItem
)
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());
153 for(size_t a
= 0; a
< nCount
; ++a
)
155 pSub
->GetObj(a
)->SetMergedItem(rItem
);
158 // #i43809# call parent. This will set items on local object, too.
159 E3dProperties::SetMergedItem(rItem
);
162 void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich
)
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());
168 for(size_t a
= 0; a
< nCount
; ++a
)
170 pSub
->GetObj(a
)->ClearMergedItem(nWhich
);
173 // #i43809# call parent. This will clear items on local object, too.
174 E3dProperties::ClearMergedItem(nWhich
);
177 void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich
)
180 E3dProperties::PostItemChange(nWhich
);
183 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
184 rObj
.StructureChanged();
188 case SDRATTR_3DSCENE_PERSPECTIVE
:
189 case SDRATTR_3DSCENE_DISTANCE
:
190 case SDRATTR_3DSCENE_FOCAL_LENGTH
:
193 // one common function for the camera attributes
194 // since SetCamera() sets all three back to the ItemSet
195 Camera3D
aSceneCam(rObj
.GetCamera());
198 // for SDRATTR_3DSCENE_PERSPECTIVE:
199 if(aSceneCam
.GetProjection() != rObj
.GetPerspective())
201 aSceneCam
.SetProjection(rObj
.GetPerspective());
205 // for SDRATTR_3DSCENE_DISTANCE:
206 basegfx::B3DPoint
aActualPosition(aSceneCam
.GetPosition());
207 double fNew
= rObj
.GetDistance();
209 if(fNew
!= aActualPosition
.getZ())
211 aSceneCam
.SetPosition(basegfx::B3DPoint(aActualPosition
.getX(), aActualPosition
.getY(), fNew
));
215 // for SDRATTR_3DSCENE_FOCAL_LENGTH:
216 fNew
= rObj
.GetFocalLength() / 100.0;
218 if(aSceneCam
.GetFocalLength() != fNew
)
220 aSceneCam
.SetFocalLength(fNew
);
227 rObj
.SetCamera(aSceneCam
);
235 void E3dSceneProperties::SetStyleSheet(SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
)
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());
241 for(size_t a
= 0; a
< nCount
; ++a
)
243 pSub
->GetObj(a
)->SetStyleSheet(pNewStyleSheet
, bDontRemoveHardAttr
);
247 SfxStyleSheet
* E3dSceneProperties::GetStyleSheet() const
249 SfxStyleSheet
* pRetval
= nullptr;
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());
255 for(size_t a
= 0; a
< nCount
; ++a
)
257 SfxStyleSheet
* pCandidate
= pSub
->GetObj(a
)->GetStyleSheet();
261 if(pCandidate
!= pRetval
)
263 // different StyleSheelts, return none
269 pRetval
= pCandidate
;
276 void E3dSceneProperties::SetSceneItemsFromCamera()
281 E3dScene
& rObj
= static_cast<E3dScene
&>(GetSdrObject());
282 const Camera3D
& aSceneCam(rObj
.GetCamera());
285 mpItemSet
->Put(Svx3DPerspectiveItem(aSceneCam
.GetProjection()));
288 mpItemSet
->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32
>(aSceneCam
.GetPosition().getZ() + 0.5)));
291 mpItemSet
->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32
>((aSceneCam
.GetFocalLength() * 100.0) + 0.5)));
293 } // end of namespace properties
294 } // end of namespace sdr
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */