LibreOffice Module svx (master)  1
lathe3d.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/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>
34 #include <rtl/ustrbuf.hxx>
35 
36 
37 // DrawContact section
38 std::unique_ptr<sdr::contact::ViewContact> E3dLatheObj::CreateObjectSpecificViewContact()
39 {
40  return std::make_unique<sdr::contact::ViewContactOfE3dLathe>(*this);
41 }
42 
43 std::unique_ptr<sdr::properties::BaseProperties> E3dLatheObj::CreateObjectSpecificProperties()
44 {
45  return std::make_unique<sdr::properties::E3dLatheProperties>(*this);
46 }
47 
48 // Constructor from 3D polygon, scale is the conversion factor for the coordinates
50  SdrModel& rSdrModel,
51  const E3dDefaultAttributes& rDefault,
52  const basegfx::B2DPolyPolygon& rPoly2D)
53 : E3dCompoundObject(rSdrModel),
54  maPolyPoly2D(rPoly2D)
55 {
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);
60 
61  // Set Defaults
62  SetDefaultAttributes(rDefault);
63 
64  // Superfluous items removed, in particular to prevent duplicate
65  // start and end points
67 
68  if(maPolyPoly2D.count())
69  {
71  sal_uInt32 nSegCnt(rPoly.count());
72 
73  if(nSegCnt && !rPoly.isClosed())
74  {
75  nSegCnt -= 1;
76  }
77 
79  }
80 }
81 
83 : E3dCompoundObject(rSdrModel)
84 {
85  // Set Defaults
86  const E3dDefaultAttributes aDefault;
87 
88  SetDefaultAttributes(aDefault);
89 }
90 
91 E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel, E3dLatheObj const & rSource)
92 : E3dCompoundObject(rSdrModel, rSource)
93 {
94  // Set Defaults
95  const E3dDefaultAttributes aDefault;
96 
97  SetDefaultAttributes(aDefault);
98 
99  maPolyPoly2D = rSource.maPolyPoly2D;
100 }
101 
103 {
104 }
105 
106 void E3dLatheObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
107 {
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()));
113 }
114 
116 {
117  return E3D_LATHEOBJ_ID;
118 }
119 
121 {
122  return new E3dLatheObj(rTargetModel, *this);
123 }
124 
125 // Convert the object to group object consisting of n polygons
126 
127 SdrObjectUniquePtr E3dLatheObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) const
128 {
129  return nullptr;
130 }
131 
132 // Set Local parameters set to re-create geometry
133 
135 {
136  if(maPolyPoly2D == rNew)
137  return;
138 
139  maPolyPoly2D = rNew;
141 
142  if(maPolyPoly2D.count())
143  {
145  sal_uInt32 nSegCnt(rPoly.count());
146 
147  if(nSegCnt && !rPoly.isClosed())
148  {
149  nSegCnt -= 1;
150  }
151 
153  }
154 
155  ActionChanged();
156 }
157 
158 // Get the name of the object (singular)
159 
161 {
162  OUString sName(SvxResId(STR_ObjNameSingulLathe3d));
163 
164  OUString aName(GetName());
165  if (!aName.isEmpty())
166  {
167  sName += " '" + aName + "'";
168  }
169  return sName;
170 }
171 
172 // Get the name of the object (plural)
173 
175 {
176  return SvxResId(STR_ObjNamePluralLathe3d);
177 }
178 
180 {
181  return true;
182 }
183 
184 std::unique_ptr<SdrAttrObj,SdrObjectFreeOp> E3dLatheObj::GetBreakObj()
185 {
186  // create PathObj
188  basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
189  std::unique_ptr<SdrPathObj,SdrObjectFreeOp> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aTransPoly));
190 
191  // Set Attribute
193 
194  // Enable lines to guarantee that the object becomes visible
195  aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
196 
197  pPathObj->SetMergedItemSet(aSet);
198 
199  return std::unique_ptr<SdrAttrObj,SdrObjectFreeOp>(pPathObj.release());
200 }
201 
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetObjectItemDirect(const SfxPoolItem &rItem)=0
virtual OUString TakeObjNamePlural() const override
Definition: lathe3d.cxx:174
SfxUInt32Item makeSvx3DVerticalSegmentsItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:50
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:210
SdrObjKind
Definition: svdobjkind.hxx:24
E3dLatheObj(SdrModel &rSdrModel, const E3dDefaultAttributes &rDefault, const basegfx::B2DPolyPolygon &rPoly2D)
Definition: lathe3d.cxx:49
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
virtual OUString TakeObjNameSingul() const override
Definition: lathe3d.cxx:160
B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon &rCandidate, double fZCoordinate)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:25
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1976
basegfx::B2DPolyPolygon TransformToScreenCoor(const basegfx::B3DPolyPolygon &rCandidate)
Definition: obj3d.cxx:606
OUString sName
void ActionChanged() const
Definition: svdobj.cxx:263
void scale(double fX, double fY)
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:279
void transform(const basegfx::B2DHomMatrix &rMatrix)
polygon, PolyPolygon
Definition: svdobjkind.hxx:35
void SetDefaultAttributes(const E3dDefaultAttributes &rDefault)
Definition: lathe3d.cxx:106
virtual ~E3dLatheObj() override
Definition: lathe3d.cxx:102
OUString GetName() const
Definition: svdobj.cxx:804
virtual SdrObjKind GetObjIdentifier() const override
Definition: lathe3d.cxx:115
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt32 count() const
virtual std::unique_ptr< SdrAttrObj, SdrObjectFreeOp > GetBreakObj() override
Definition: lathe3d.cxx:184
OUString aName
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
Definition: svdobj.hxx:96
virtual std::unique_ptr< sdr::contact::ViewContact > CreateObjectSpecificViewContact() override
Definition: lathe3d.cxx:38
basegfx::B2DPolyPolygon maPolyPoly2D
Definition: lathe3d.hxx:44
virtual SdrObjectUniquePtr DoConvertToPolyObj(bool bBezier, bool bAddText) const override
Definition: lathe3d.cxx:127
virtual std::unique_ptr< sdr::properties::BaseProperties > CreateObjectSpecificProperties() override
Definition: lathe3d.cxx:43
virtual E3dLatheObj * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: lathe3d.cxx:120
void SetPolyPoly2D(const basegfx::B2DPolyPolygon &rNew)
Definition: lathe3d.cxx:134
virtual bool IsBreakObjPossible() override
Definition: lathe3d.cxx:179