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