Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/engine3d/extrud3d.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
21
#include <svx/strings.hrc>
22
#include <svx/deflt3d.hxx>
23
#include <svx/dialmgr.hxx>
24
#include <svx/svdobjkind.hxx>
25
#include <extrud3d.hxx>
26
27
#include <svx/svdopath.hxx>
28
#include <svx/svdmodel.hxx>
29
#include <svx/svx3ditems.hxx>
30
#include <svx/xlineit0.hxx>
31
#include <sdr/properties/e3dextrudeproperties.hxx>
32
#include <sdr/contact/viewcontactofe3dextrude.hxx>
33
#include <basegfx/matrix/b2dhommatrix.hxx>
34
#include <basegfx/polygon/b2dpolypolygontools.hxx>
35
#include <basegfx/polygon/b2dpolygontools.hxx>
36
#include <basegfx/polygon/b3dpolypolygontools.hxx>
37
#include <utility>
38
39
40
// DrawContact section
41
std::unique_ptr<sdr::contact::ViewContact> E3dExtrudeObj::CreateObjectSpecificViewContact()
42
12.0k
{
43
12.0k
    return std::make_unique<sdr::contact::ViewContactOfE3dExtrude>(*this);
44
12.0k
}
45
46
std::unique_ptr<sdr::properties::BaseProperties> E3dExtrudeObj::CreateObjectSpecificProperties()
47
12.0k
{
48
12.0k
    return std::make_unique<sdr::properties::E3dExtrudeProperties>(*this);
49
12.0k
}
50
51
// Constructor creates a two cover surface tools::PolyPolygon and (point-count 1) side
52
// surfaces rectangles from the passed PolyPolygon
53
E3dExtrudeObj::E3dExtrudeObj(
54
    SdrModel& rSdrModel,
55
    const E3dDefaultAttributes& rDefault,
56
    basegfx::B2DPolyPolygon aPP,
57
    double fDepth)
58
12.0k
:   E3dCompoundObject(rSdrModel),
59
12.0k
    maExtrudePolygon(std::move(aPP))
60
12.0k
{
61
    // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
62
12.0k
    basegfx::B2DHomMatrix aMirrorY;
63
12.0k
    aMirrorY.scale(1.0, -1.0);
64
12.0k
    maExtrudePolygon.transform(aMirrorY);
65
66
    // Set Defaults
67
12.0k
    SetDefaultAttributes(rDefault);
68
69
    // set extrude depth
70
12.0k
    GetProperties().SetObjectItemDirect(makeSvx3DDepthItem(static_cast<sal_uInt32>(fDepth + 0.5)));
71
12.0k
}
72
73
E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel)
74
0
:   E3dCompoundObject(rSdrModel)
75
0
{
76
    // Set Defaults
77
0
    const E3dDefaultAttributes aDefault;
78
79
0
    SetDefaultAttributes(aDefault);
80
0
}
81
82
E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel, E3dExtrudeObj const & rSource)
83
0
:   E3dCompoundObject(rSdrModel, rSource)
84
0
{
85
    // Set Defaults
86
0
    const E3dDefaultAttributes aDefault;
87
88
0
    SetDefaultAttributes(aDefault);
89
90
0
    maExtrudePolygon = rSource.maExtrudePolygon;
91
0
}
92
93
E3dExtrudeObj::~E3dExtrudeObj()
94
12.0k
{
95
12.0k
}
96
97
void E3dExtrudeObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
98
12.0k
{
99
12.0k
    GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
100
12.0k
    GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
101
12.0k
    GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultExtrudeCharacterMode()));
102
12.0k
    GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultExtrudeCloseFront()));
103
12.0k
    GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultExtrudeCloseBack()));
104
105
    // For extrudes use StdTexture in X and Y by default
106
12.0k
    GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
107
12.0k
    GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
108
12.0k
}
109
110
SdrObjKind E3dExtrudeObj::GetObjIdentifier() const
111
0
{
112
0
    return SdrObjKind::E3D_Extrusion;
113
0
}
114
115
rtl::Reference<SdrObject> E3dExtrudeObj::CloneSdrObject(SdrModel& rTargetModel) const
116
0
{
117
0
    return new E3dExtrudeObj(rTargetModel, *this);
118
0
}
119
120
// Set local parameters with geometry re-creating
121
122
void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
123
0
{
124
0
    if(maExtrudePolygon != rNew)
125
0
    {
126
0
        maExtrudePolygon = rNew;
127
0
        ActionChanged();
128
0
    }
129
0
}
130
131
// Get the name of the object (singular)
132
133
OUString E3dExtrudeObj::TakeObjNameSingul() const
134
0
{
135
0
    OUString sName(SvxResId(STR_ObjNameSingulExtrude3d));
136
137
0
    OUString aName(GetName());
138
0
    if (!aName.isEmpty())
139
0
    {
140
0
        sName += " '" + aName + "'";
141
0
    }
142
0
    return sName;
143
0
}
144
145
// Get the name of the object (plural)
146
147
OUString E3dExtrudeObj::TakeObjNamePlural() const
148
0
{
149
0
    return SvxResId(STR_ObjNamePluralExtrude3d);
150
0
}
151
152
bool E3dExtrudeObj::IsBreakObjPossible()
153
0
{
154
0
    return true;
155
0
}
156
157
rtl::Reference<SdrAttrObj> E3dExtrudeObj::GetBreakObj()
158
0
{
159
0
    basegfx::B3DPolyPolygon aFrontSide;
160
0
    basegfx::B3DPolyPolygon aBackSide;
161
162
0
    if(maExtrudePolygon.count())
163
0
    {
164
0
        basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
165
0
        aTemp.removeDoublePoints();
166
0
        aTemp = basegfx::utils::correctOrientations(aTemp);
167
0
        const basegfx::B2VectorOrientation aOrient = basegfx::utils::getOrientation(aTemp.getB2DPolygon(0));
168
169
0
        if(basegfx::B2VectorOrientation::Positive == aOrient)
170
0
        {
171
0
            aTemp.flip();
172
0
        }
173
174
0
        aFrontSide = basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(aTemp);
175
0
    }
176
177
0
    if(aFrontSide.count())
178
0
    {
179
0
        aBackSide = std::move(aFrontSide);
180
181
0
        if(GetExtrudeDepth())
182
0
        {
183
0
            basegfx::B3DHomMatrix aTransform;
184
185
0
            if(100 != GetPercentBackScale())
186
0
            {
187
                // scale polygon from center
188
0
                const double fScaleFactor(GetPercentBackScale() / 100.0);
189
0
                const basegfx::B3DRange aPolyPolyRange(basegfx::utils::getRange(aBackSide));
190
0
                const basegfx::B3DPoint aCenter(aPolyPolyRange.getCenter());
191
192
0
                aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
193
0
                aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
194
0
                aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
195
0
            }
196
197
            // translate by extrude depth
198
0
            aTransform.translate(0.0, 0.0, static_cast<double>(GetExtrudeDepth()));
199
200
0
            aBackSide.transform(aTransform);
201
0
        }
202
0
    }
203
204
0
    if(aBackSide.count())
205
0
    {
206
    // create PathObj
207
0
        basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
208
0
        rtl::Reference<SdrPathObj> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), SdrObjKind::PolyLine, std::move(aPoly)));
209
210
0
        SfxItemSet aSet(GetObjectItemSet());
211
0
        aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
212
0
        pPathObj->SetMergedItemSet(aSet);
213
214
0
        return pPathObj;
215
0
    }
216
217
0
    return nullptr;
218
0
}
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */