Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/properties/e3dsceneproperties.cxx
Line
Count
Source
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
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>
26
#include <memory>
27
28
29
namespace sdr::properties
30
{
31
        E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
32
2.94k
        :   E3dProperties(rObj)
33
2.94k
        {
34
2.94k
        }
35
36
        E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
37
0
        :   E3dProperties(rProps, rObj)
38
0
        {
39
0
        }
40
41
        E3dSceneProperties::~E3dSceneProperties()
42
2.94k
        {
43
2.94k
        }
44
45
        std::unique_ptr<BaseProperties> E3dSceneProperties::Clone(SdrObject& rObj) const
46
0
        {
47
0
            return std::unique_ptr<BaseProperties>(new E3dSceneProperties(*this, rObj));
48
0
        }
49
50
        const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
51
0
        {
52
            // prepare ItemSet
53
0
            if(moItemSet)
54
0
            {
55
                // filter for SDRATTR_3DSCENE_ items, only keep those items
56
0
                SfxItemSet aNew(SfxItemSet::makeFixedSfxItemSet<SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST>(*moItemSet->GetPool()));
57
0
                aNew.Put(*moItemSet);
58
0
                moItemSet->ClearItem();
59
0
                moItemSet->Put(aNew);
60
0
            }
61
0
            else
62
0
            {
63
                // No ItemSet yet, force local ItemSet
64
0
                GetObjectItemSet();
65
0
            }
66
67
            // collect all ItemSets of contained 3d objects
68
0
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
69
0
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
70
71
0
            if (pSub)
72
0
                for (const rtl::Reference<SdrObject>& pObj : *pSub)
73
0
                {
74
0
                    if(dynamic_cast<const E3dCompoundObject* >(pObj.get()))
75
0
                    {
76
0
                        const SfxItemSet& rSet = pObj->GetMergedItemSet();
77
0
                        SfxWhichIter aIter(rSet);
78
0
                        sal_uInt16 nWhich(aIter.FirstWhich());
79
80
0
                        while(nWhich)
81
0
                        {
82
                            // Leave out the SDRATTR_3DSCENE_ range, this would only be double
83
                            // and always equal.
84
0
                            if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
85
0
                            {
86
0
                                if(SfxItemState::INVALID == aIter.GetItemState(false))
87
0
                                {
88
0
                                    moItemSet->InvalidateItem(nWhich);
89
0
                                }
90
0
                                else
91
0
                                {
92
0
                                    moItemSet->MergeValue(rSet.Get(nWhich));
93
0
                                }
94
0
                            }
95
96
0
                            nWhich = aIter.NextWhich();
97
0
                        }
98
0
                    }
99
0
                }
100
101
            // call parent
102
0
            return E3dProperties::GetMergedItemSet();
103
0
        }
104
105
        void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems, bool bAdjustTextFrameWidthAndHeight)
106
0
        {
107
            // Set SDRATTR_3DOBJ_ range at contained objects.
108
0
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
109
0
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
110
0
            const size_t nCount(nullptr == pSub ? 0 : pSub->GetObjCount());
111
112
0
            if(nCount)
113
0
            {
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
0
                std::unique_ptr<SfxItemSet> xNewSet(rSet.Clone());
117
118
0
                for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
119
0
                {
120
0
                    xNewSet->ClearItem(b);
121
0
                }
122
123
0
                if(xNewSet->Count())
124
0
                {
125
0
                    for (const rtl::Reference<SdrObject>& pObj : *pSub)
126
0
                    {
127
0
                        if(dynamic_cast<const E3dCompoundObject* >(pObj.get()))
128
0
                        {
129
                            // set merged ItemSet at contained 3d object.
130
0
                            pObj->SetMergedItemSet(*xNewSet, bClearAllItems, bAdjustTextFrameWidthAndHeight);
131
0
                        }
132
0
                    }
133
0
                }
134
0
            }
135
136
            // call parent. This will set items on local object, too.
137
0
            E3dProperties::SetMergedItemSet(rSet, bClearAllItems, bAdjustTextFrameWidthAndHeight);
138
0
        }
139
140
        void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
141
0
        {
142
0
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
143
0
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
144
0
            if (pSub)
145
0
                for (const rtl::Reference<SdrObject>& pObj : *pSub)
146
0
                    pObj->SetMergedItem(rItem);
147
148
            // #i43809# call parent. This will set items on local object, too.
149
0
            E3dProperties::SetMergedItem(rItem);
150
0
        }
151
152
        void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
153
0
        {
154
0
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
155
0
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
156
0
            if (pSub)
157
0
                for (const rtl::Reference<SdrObject>& pObj : *pSub)
158
0
                    pObj->ClearMergedItem(nWhich);
159
160
            // #i43809# call parent. This will clear items on local object, too.
161
0
            E3dProperties::ClearMergedItem(nWhich);
162
0
        }
163
164
        void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
165
71.1k
        {
166
            // call parent
167
71.1k
            E3dProperties::PostItemChange(nWhich);
168
169
            // local changes
170
71.1k
            E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
171
71.1k
            rObj.StructureChanged();
172
173
71.1k
            switch(nWhich)
174
71.1k
            {
175
0
                case SDRATTR_3DSCENE_PERSPECTIVE            :
176
0
                case SDRATTR_3DSCENE_DISTANCE               :
177
0
                case SDRATTR_3DSCENE_FOCAL_LENGTH           :
178
0
                {
179
                    // #83387#, #83391#
180
                    // one common function for the camera attributes
181
                    // since SetCamera() sets all three back to the ItemSet
182
0
                    Camera3D aSceneCam(rObj.GetCamera());
183
0
                    bool bChange(false);
184
185
                    // for SDRATTR_3DSCENE_PERSPECTIVE:
186
0
                    if(aSceneCam.GetProjection() != rObj.GetPerspective())
187
0
                    {
188
0
                        aSceneCam.SetProjection(rObj.GetPerspective());
189
0
                        bChange = true;
190
0
                    }
191
192
                    // for SDRATTR_3DSCENE_DISTANCE:
193
0
                    basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
194
0
                    double fNew = rObj.GetDistance();
195
196
0
                    if(fNew != aActualPosition.getZ())
197
0
                    {
198
0
                        aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
199
0
                        bChange = true;
200
0
                    }
201
202
                    // for SDRATTR_3DSCENE_FOCAL_LENGTH:
203
0
                    fNew = rObj.GetFocalLength() / 100.0;
204
205
0
                    if(aSceneCam.GetFocalLength() != fNew)
206
0
                    {
207
0
                        aSceneCam.SetFocalLength(fNew);
208
0
                        bChange = true;
209
0
                    }
210
211
                    // for all
212
0
                    if(bChange)
213
0
                    {
214
0
                        rObj.SetCamera(aSceneCam);
215
0
                    }
216
217
0
                    break;
218
0
                }
219
71.1k
            }
220
71.1k
        }
221
222
        void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr,
223
                bool bBroadcast, bool bAdjustTextFrameWidthAndHeight)
224
0
        {
225
0
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
226
0
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
227
0
            if (!pSub)
228
0
                return;
229
0
            for (const rtl::Reference<SdrObject>& pObj : *pSub)
230
0
            {
231
0
                if(bBroadcast)
232
0
                    pObj->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
233
0
                else
234
0
                    pObj->NbcSetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr, bAdjustTextFrameWidthAndHeight);
235
0
            }
236
0
        }
237
238
        SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
239
2.94k
        {
240
2.94k
            SfxStyleSheet* pRetval = nullptr;
241
242
2.94k
            const SdrObjList* pSub(static_cast<const E3dScene&>(GetSdrObject()).GetSubList());
243
2.94k
            OSL_ENSURE(nullptr != pSub, "Children of SdrObject expected (!)");
244
2.94k
            if (!pSub)
245
0
                return pRetval;
246
2.94k
            for (const rtl::Reference<SdrObject>& pObj : *pSub)
247
0
            {
248
0
                SfxStyleSheet* pCandidate = pObj->GetStyleSheet();
249
250
0
                if(pRetval)
251
0
                {
252
0
                    if(pCandidate != pRetval)
253
0
                    {
254
                        // different StyleSheelts, return none
255
0
                        return nullptr;
256
0
                    }
257
0
                }
258
0
                else
259
0
                {
260
0
                    pRetval = pCandidate;
261
0
                }
262
0
            }
263
264
2.94k
            return pRetval;
265
2.94k
        }
266
267
        void E3dSceneProperties::SetSceneItemsFromCamera()
268
5.88k
        {
269
            // force ItemSet
270
5.88k
            GetObjectItemSet();
271
272
5.88k
            E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
273
5.88k
            const Camera3D& aSceneCam(rObj.GetCamera());
274
275
            // ProjectionType
276
5.88k
            moItemSet->Put(Svx3DPerspectiveItem(aSceneCam.GetProjection()));
277
278
            // CamPos
279
5.88k
            moItemSet->Put(makeSvx3DDistanceItem(static_cast<sal_uInt32>(aSceneCam.GetPosition().getZ() + 0.5)));
280
281
            // FocalLength
282
5.88k
            moItemSet->Put(makeSvx3DFocalLengthItem(static_cast<sal_uInt32>((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
283
5.88k
        }
284
} // end of namespace
285
286
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */