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/globl3d.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 
91 {
92 }
93 
94 void E3dLatheObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
95 {
96  GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
97  GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
98  GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultLatheCharacterMode()));
99  GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultLatheCloseFront()));
100  GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultLatheCloseBack()));
101 }
102 
104 {
105  return E3D_LATHEOBJ_ID;
106 }
107 
109 {
110  return CloneHelper< E3dLatheObj >(rTargetModel);
111 }
112 
114 {
115  if( this == &rObj )
116  return *this;
118 
119  maPolyPoly2D = rObj.maPolyPoly2D;
120 
121  return *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  {
137  maPolyPoly2D = rNew;
139 
140  if(maPolyPoly2D.count())
141  {
143  sal_uInt32 nSegCnt(rPoly.count());
144 
145  if(nSegCnt && !rPoly.isClosed())
146  {
147  nSegCnt -= 1;
148  }
149 
151  }
152 
153  ActionChanged();
154  }
155 }
156 
157 // Get the name of the object (singular)
158 
160 {
161  OUStringBuffer sName(SvxResId(STR_ObjNameSingulLathe3d));
162 
163  OUString aName(GetName());
164  if (!aName.isEmpty())
165  {
166  sName.append(' ');
167  sName.append('\'');
168  sName.append(aName);
169  sName.append('\'');
170  }
171  return sName.makeStringAndClear();
172 }
173 
174 // Get the name of the object (plural)
175 
177 {
178  return SvxResId(STR_ObjNamePluralLathe3d);
179 }
180 
182 {
183  return true;
184 }
185 
186 std::unique_ptr<SdrAttrObj,SdrObjectFreeOp> E3dLatheObj::GetBreakObj()
187 {
188  // create PathObj
190  basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
191  std::unique_ptr<SdrPathObj,SdrObjectFreeOp> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aTransPoly));
192 
193  // Set Attribute
195 
196  // Enable lines to guarantee that the object becomes visible
197  aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
198 
199  pPathObj->SetMergedItemSet(aSet);
200 
201  return std::unique_ptr<SdrAttrObj,SdrObjectFreeOp>(pPathObj.release());
202 }
203 
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_uInt16 E3D_LATHEOBJ_ID
Definition: globl3d.hxx:30
virtual void SetObjectItemDirect(const SfxPoolItem &rItem)=0
virtual OUString TakeObjNamePlural() const override
Definition: lathe3d.cxx:176
SfxUInt32Item makeSvx3DVerticalSegmentsItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:50
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:203
polygon, PolyPolygon
Definition: svdobj.hxx:126
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(const char *pId)
Definition: dialmgr.cxx:28
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1878
virtual sal_uInt16 GetObjIdentifier() const override
Definition: lathe3d.cxx:103
basegfx::B2DPolyPolygon TransformToScreenCoor(const basegfx::B3DPolyPolygon &rCandidate)
Definition: obj3d.cxx:606
OUString sName
E3dCompoundObject & operator=(const E3dCompoundObject &rObj)
Definition: obj3d.cxx:597
E3dLatheObj & operator=(const E3dLatheObj &rObj)
Definition: lathe3d.cxx:113
void ActionChanged() const
Definition: svdobj.cxx:256
void scale(double fX, double fY)
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:272
void transform(const basegfx::B2DHomMatrix &rMatrix)
void SetDefaultAttributes(const E3dDefaultAttributes &rDefault)
Definition: lathe3d.cxx:94
virtual ~E3dLatheObj() override
Definition: lathe3d.cxx:90
OUString GetName() const
Definition: svdobj.cxx:697
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt32 count() const
virtual std::unique_ptr< SdrAttrObj, SdrObjectFreeOp > GetBreakObj() override
Definition: lathe3d.cxx:186
OUString aName
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
Definition: svdobj.hxx:114
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
virtual E3dLatheObj * CloneSdrObject(SdrModel &rTargetModel) const override
Definition: lathe3d.cxx:108
void SetPolyPoly2D(const basegfx::B2DPolyPolygon &rNew)
Definition: lathe3d.cxx:133
virtual bool IsBreakObjPossible() override
Definition: lathe3d.cxx:181