bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / engine3d / lathe3d.cxx
blob9d2c60c57260d55ae09895b5126c2a9ddc7a4a3c
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/svdstr.hrc"
22 #include "svdglob.hxx"
23 #include <tools/poly.hxx>
24 #include <svx/svdpage.hxx>
25 #include "svx/globl3d.hxx"
26 #include <svx/lathe3d.hxx>
27 #include <svx/xpoly.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/svdopath.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <svx/svx3ditems.hxx>
32 #include <sdr/properties/e3dlatheproperties.hxx>
33 #include <sdr/contact/viewcontactofe3dlathe.hxx>
34 #include <basegfx/polygon/b2dpolypolygontools.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
39 // DrawContact section
41 sdr::contact::ViewContact* E3dLatheObj::CreateObjectSpecificViewContact()
43 return new sdr::contact::ViewContactOfE3dLathe(*this);
48 sdr::properties::BaseProperties* E3dLatheObj::CreateObjectSpecificProperties()
50 return new sdr::properties::E3dLatheProperties(*this);
55 TYPEINIT1(E3dLatheObj, E3dCompoundObject);
57 // Constructor from 3D polygon, scale is the conversion factor for the coordinates
59 E3dLatheObj::E3dLatheObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon& rPoly2D)
60 : E3dCompoundObject(rDefault),
61 maPolyPoly2D(rPoly2D)
63 // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
64 basegfx::B2DHomMatrix aMirrorY;
65 aMirrorY.scale(1.0, -1.0);
66 maPolyPoly2D.transform(aMirrorY);
68 // Set Defaults
69 SetDefaultAttributes(rDefault);
71 // Superfluous items removed, in particular to prevent duplicate
72 // start and end points
73 maPolyPoly2D.removeDoublePoints();
75 if(maPolyPoly2D.count())
77 const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
78 sal_uInt32 nSegCnt(rPoly.count());
80 if(nSegCnt && !rPoly.isClosed())
82 nSegCnt -= 1;
85 GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt));
89 E3dLatheObj::E3dLatheObj()
90 : E3dCompoundObject()
92 // Set Defaults
93 E3dDefaultAttributes aDefault;
94 SetDefaultAttributes(aDefault);
97 void E3dLatheObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
99 GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
100 GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
101 GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode()));
102 GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront()));
103 GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack()));
106 sal_uInt16 E3dLatheObj::GetObjIdentifier() const
108 return E3D_LATHEOBJ_ID;
111 E3dLatheObj* E3dLatheObj::Clone() const
113 return CloneHelper< E3dLatheObj >();
116 // Convert the object to group object consisting of n polygons
118 SdrObject *E3dLatheObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const
120 return NULL;
123 // Set Local parameters set to re-create geometry
125 void E3dLatheObj::SetPolyPoly2D(const basegfx::B2DPolyPolygon& rNew)
127 if(maPolyPoly2D != rNew)
129 maPolyPoly2D = rNew;
130 maPolyPoly2D.removeDoublePoints();
132 if(maPolyPoly2D.count())
134 const basegfx::B2DPolygon rPoly(maPolyPoly2D.getB2DPolygon(0L));
135 sal_uInt32 nSegCnt(rPoly.count());
137 if(nSegCnt && !rPoly.isClosed())
139 nSegCnt -= 1;
142 GetProperties().SetObjectItemDirect(makeSvx3DVerticalSegmentsItem(nSegCnt));
145 ActionChanged();
149 // Get the name of the object (singular)
151 OUString E3dLatheObj::TakeObjNameSingul() const
153 OUStringBuffer sName(ImpGetResStr(STR_ObjNameSingulLathe3d));
155 OUString aName(GetName());
156 if (!aName.isEmpty())
158 sName.append(' ');
159 sName.append('\'');
160 sName.append(aName);
161 sName.append('\'');
163 return sName.makeStringAndClear();
166 // Get the name of the object (plural)
168 OUString E3dLatheObj::TakeObjNamePlural() const
170 return ImpGetResStr(STR_ObjNamePluralLathe3d);
173 bool E3dLatheObj::IsBreakObjPossible()
175 return true;
178 SdrAttrObj* E3dLatheObj::GetBreakObj()
180 // create PathObj
181 basegfx::B3DPolyPolygon aLathePoly3D(basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D));
182 basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
183 SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aTransPoly);
185 // Set Attribute
186 SfxItemSet aSet(GetObjectItemSet());
188 // Enable lines to guarantee that the object becomes visible
189 aSet.Put(XLineStyleItem(com::sun::star::drawing::LineStyle_SOLID));
191 pPathObj->SetMergedItemSet(aSet);
193 return pPathObj;
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */