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