Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / engine3d / extrud3d.cxx
blobc268bec20baae768585b74273f76d7b10eb1b15a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <svx/strings.hrc>
22 #include <svx/deflt3d.hxx>
23 #include <svx/dialmgr.hxx>
24 #include <svx/svdobjkind.hxx>
25 #include <extrud3d.hxx>
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>
40 // DrawContact section
41 std::unique_ptr<sdr::contact::ViewContact> E3dExtrudeObj::CreateObjectSpecificViewContact()
43 return std::make_unique<sdr::contact::ViewContactOfE3dExtrude>(*this);
46 std::unique_ptr<sdr::properties::BaseProperties> E3dExtrudeObj::CreateObjectSpecificProperties()
48 return std::make_unique<sdr::properties::E3dExtrudeProperties>(*this);
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 : E3dCompoundObject(rSdrModel),
59 maExtrudePolygon(std::move(aPP))
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);
66 // Set Defaults
67 SetDefaultAttributes(rDefault);
69 // set extrude depth
70 GetProperties().SetObjectItemDirect(makeSvx3DDepthItem(static_cast<sal_uInt32>(fDepth + 0.5)));
73 E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel)
74 : E3dCompoundObject(rSdrModel)
76 // Set Defaults
77 const E3dDefaultAttributes aDefault;
79 SetDefaultAttributes(aDefault);
82 E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel, E3dExtrudeObj const & rSource)
83 : E3dCompoundObject(rSdrModel, rSource)
85 // Set Defaults
86 const E3dDefaultAttributes aDefault;
88 SetDefaultAttributes(aDefault);
90 maExtrudePolygon = rSource.maExtrudePolygon;
93 E3dExtrudeObj::~E3dExtrudeObj()
97 void E3dExtrudeObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
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()));
105 // For extrudes use StdTexture in X and Y by default
106 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
107 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
110 SdrObjKind E3dExtrudeObj::GetObjIdentifier() const
112 return SdrObjKind::E3D_Extrusion;
115 rtl::Reference<SdrObject> E3dExtrudeObj::CloneSdrObject(SdrModel& rTargetModel) const
117 return new E3dExtrudeObj(rTargetModel, *this);
120 // Set local parameters with geometry re-creating
122 void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
124 if(maExtrudePolygon != rNew)
126 maExtrudePolygon = rNew;
127 ActionChanged();
131 // Get the name of the object (singular)
133 OUString E3dExtrudeObj::TakeObjNameSingul() const
135 OUString sName(SvxResId(STR_ObjNameSingulExtrude3d));
137 OUString aName(GetName());
138 if (!aName.isEmpty())
140 sName += " '" + aName + "'";
142 return sName;
145 // Get the name of the object (plural)
147 OUString E3dExtrudeObj::TakeObjNamePlural() const
149 return SvxResId(STR_ObjNamePluralExtrude3d);
152 bool E3dExtrudeObj::IsBreakObjPossible()
154 return true;
157 rtl::Reference<SdrAttrObj> E3dExtrudeObj::GetBreakObj()
159 basegfx::B3DPolyPolygon aFrontSide;
160 basegfx::B3DPolyPolygon aBackSide;
162 if(maExtrudePolygon.count())
164 basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
165 aTemp.removeDoublePoints();
166 aTemp = basegfx::utils::correctOrientations(aTemp);
167 const basegfx::B2VectorOrientation aOrient = basegfx::utils::getOrientation(aTemp.getB2DPolygon(0));
169 if(basegfx::B2VectorOrientation::Positive == aOrient)
171 aTemp.flip();
174 aFrontSide = basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(aTemp);
177 if(aFrontSide.count())
179 aBackSide = aFrontSide;
181 if(GetExtrudeDepth())
183 basegfx::B3DHomMatrix aTransform;
185 if(100 != GetPercentBackScale())
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());
192 aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
193 aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
194 aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
197 // translate by extrude depth
198 aTransform.translate(0.0, 0.0, static_cast<double>(GetExtrudeDepth()));
200 aBackSide.transform(aTransform);
204 if(aBackSide.count())
206 // create PathObj
207 basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
208 rtl::Reference<SdrPathObj> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), SdrObjKind::PolyLine, std::move(aPoly)));
210 SfxItemSet aSet(GetObjectItemSet());
211 aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
212 pPathObj->SetMergedItemSet(aSet);
214 return pPathObj;
217 return nullptr;
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */