basctl: fix crash in EditorWindow::Command
[LibreOffice.git] / svx / source / engine3d / lathe3d.cxx
blobe8664cb949adee1db481c123f450133045602a12
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/deflt3d.hxx>
22 #include <svx/strings.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <svx/svdobjkind.hxx>
25 #include <svx/lathe3d.hxx>
26 #include <svx/svdopath.hxx>
27 #include <svx/svdmodel.hxx>
28 #include <svx/svx3ditems.hxx>
29 #include <svx/xlineit0.hxx>
30 #include <sdr/properties/e3dlatheproperties.hxx>
31 #include <sdr/contact/viewcontactofe3dlathe.hxx>
32 #include <basegfx/polygon/b2dpolypolygontools.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <utility>
37 // DrawContact section
38 std::unique_ptr<sdr::contact::ViewContact> E3dLatheObj::CreateObjectSpecificViewContact()
40 return std::make_unique<sdr::contact::ViewContactOfE3dLathe>(*this);
43 std::unique_ptr<sdr::properties::BaseProperties> E3dLatheObj::CreateObjectSpecificProperties()
45 return std::make_unique<sdr::properties::E3dLatheProperties>(*this);
48 // Constructor from 3D polygon, scale is the conversion factor for the coordinates
49 E3dLatheObj::E3dLatheObj(
50 SdrModel& rSdrModel,
51 const E3dDefaultAttributes& rDefault,
52 basegfx::B2DPolyPolygon aPoly2D)
53 : E3dCompoundObject(rSdrModel),
54 maPolyPoly2D(std::move(aPoly2D))
56 // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
57 basegfx::B2DHomMatrix aMirrorY;
58 aMirrorY.scale(1.0, -1.0);
59 maPolyPoly2D.transform(aMirrorY);
61 // Set Defaults
62 SetDefaultAttributes(rDefault);
64 // Superfluous items removed, in particular to prevent duplicate
65 // start and end points
66 maPolyPoly2D.removeDoublePoints();
68 if(maPolyPoly2D.count())
70 const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0));
71 sal_uInt32 nSegCnt(rPoly.count());
73 if(nSegCnt && !rPoly.isClosed())
75 nSegCnt -= 1;
78 GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt));
82 E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel)
83 : E3dCompoundObject(rSdrModel)
85 // Set Defaults
86 const E3dDefaultAttributes aDefault;
88 SetDefaultAttributes(aDefault);
91 E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel, E3dLatheObj const & rSource)
92 : E3dCompoundObject(rSdrModel, rSource)
94 // Set Defaults
95 const E3dDefaultAttributes aDefault;
97 SetDefaultAttributes(aDefault);
99 maPolyPoly2D = rSource.maPolyPoly2D;
102 E3dLatheObj::~E3dLatheObj()
106 void E3dLatheObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
108 GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
109 GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
110 GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode()));
111 GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront()));
112 GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack()));
115 SdrObjKind E3dLatheObj::GetObjIdentifier() const
117 return SdrObjKind::E3D_Lathe;
120 rtl::Reference<SdrObject> E3dLatheObj::CloneSdrObject(SdrModel& rTargetModel) const
122 return new E3dLatheObj(rTargetModel, *this);
125 // Convert the object to group object consisting of n polygons
127 rtl::Reference<SdrObject> E3dLatheObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const
129 return nullptr;
132 // Set Local parameters set to re-create geometry
134 void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon& rNew)
136 if(maPolyPoly2D == rNew)
137 return;
139 maPolyPoly2D = rNew;
140 maPolyPoly2D.removeDoublePoints();
142 if(maPolyPoly2D.count())
144 const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0));
145 sal_uInt32 nSegCnt(rPoly.count());
147 if(nSegCnt && !rPoly.isClosed())
149 nSegCnt -= 1;
152 GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt));
155 ActionChanged();
158 // Get the name of the object (singular)
160 OUString E3dLatheObj::TakeObjNameSingul() const
162 OUString sName(SvxResId(STR_ObjNameSingulLathe3d));
164 OUString aName(GetName());
165 if (!aName.isEmpty())
167 sName += " '" + aName + "'";
169 return sName;
172 // Get the name of the object (plural)
174 OUString E3dLatheObj::TakeObjNamePlural() const
176 return SvxResId(STR_ObjNamePluralLathe3d);
179 bool E3dLatheObj::IsBreakObjPossible()
181 return true;
184 rtl::Reference<SdrAttrObj> E3dLatheObj::GetBreakObj()
186 // create PathObj
187 basegfx::B3DPolyPolygon aLathePoly3D(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D));
188 basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
189 rtl::Reference<SdrPathObj> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), SdrObjKind::PolyLine, std::move(aTransPoly)));
191 // Set Attribute
192 SfxItemSet aSet(GetObjectItemSet());
194 // Enable lines to guarantee that the object becomes visible
195 aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
197 pPathObj->SetMergedItemSet(aSet);
199 return pPathObj;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */