LibreOffice Module svx (master)  1
extrud3d.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/strings.hrc>
22 #include <svx/deflt3d.hxx>
23 #include <svx/dialmgr.hxx>
24 #include <svx/globl3d.hxx>
25 #include <extrud3d.hxx>
26 
27 #include <svx/svdopath.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svx3ditems.hxx>
30 #include <svx/xlineit0.hxx>
37 
38 
39 // DrawContact section
40 std::unique_ptr<sdr::contact::ViewContact> E3dExtrudeObj::CreateObjectSpecificViewContact()
41 {
42  return std::make_unique<sdr::contact::ViewContactOfE3dExtrude>(*this);
43 }
44 
45 std::unique_ptr<sdr::properties::BaseProperties> E3dExtrudeObj::CreateObjectSpecificProperties()
46 {
47  return std::make_unique<sdr::properties::E3dExtrudeProperties>(*this);
48 }
49 
50 // Constructor creates a two cover surface tools::PolyPolygon and (point-count 1) side
51 // surfaces rectangles from the passed PolyPolygon
52 E3dExtrudeObj::E3dExtrudeObj(
53  SdrModel& rSdrModel,
54  const E3dDefaultAttributes& rDefault,
55  const basegfx::B2DPolyPolygon& rPP,
56  double fDepth)
57 : E3dCompoundObject(rSdrModel),
58  maExtrudePolygon(rPP)
59 {
60  // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
61  basegfx::B2DHomMatrix aMirrorY;
62  aMirrorY.scale(1.0, -1.0);
63  maExtrudePolygon.transform(aMirrorY);
64 
65  // Set Defaults
66  SetDefaultAttributes(rDefault);
67 
68  // set extrude depth
69  GetProperties().SetObjectItemDirect(makeSvx3DDepthItem(static_cast<sal_uInt32>(fDepth + 0.5)));
70 }
71 
72 E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel)
73 : E3dCompoundObject(rSdrModel)
74 {
75  // Set Defaults
76  const E3dDefaultAttributes aDefault;
77 
78  SetDefaultAttributes(aDefault);
79 }
80 
81 E3dExtrudeObj::~E3dExtrudeObj()
82 {
83 }
84 
85 void E3dExtrudeObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
86 {
87  GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
88  GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
89  GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultExtrudeCharacterMode()));
90  GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultExtrudeCloseFront()));
91  GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultExtrudeCloseBack()));
92 
93  // For extrudes use StdTexture in X and Y by default
94  GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
95  GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
96 }
97 
98 sal_uInt16 E3dExtrudeObj::GetObjIdentifier() const
99 {
100  return E3D_EXTRUDEOBJ_ID;
101 }
102 
103 E3dExtrudeObj* E3dExtrudeObj::CloneSdrObject(SdrModel& rTargetModel) const
104 {
105  return CloneHelper< E3dExtrudeObj >(rTargetModel);
106 }
107 
108 E3dExtrudeObj& E3dExtrudeObj::operator=(const E3dExtrudeObj& rObj)
109 {
110  if( this == &rObj )
111  return *this;
113 
114  maExtrudePolygon = rObj.maExtrudePolygon;
115 
116  return *this;
117 }
118 
119 // Set local parameters with geometry re-creating
120 
121 void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
122 {
123  if(maExtrudePolygon != rNew)
124  {
125  maExtrudePolygon = rNew;
126  ActionChanged();
127  }
128 }
129 
130 // Get the name of the object (singular)
131 
132 OUString E3dExtrudeObj::TakeObjNameSingul() const
133 {
134  OUStringBuffer sName(SvxResId(STR_ObjNameSingulExtrude3d));
135 
136  OUString aName(GetName());
137  if (!aName.isEmpty())
138  {
139  sName.append(' ');
140  sName.append('\'');
141  sName.append(aName);
142  sName.append('\'');
143  }
144  return sName.makeStringAndClear();
145 }
146 
147 // Get the name of the object (plural)
148 
149 OUString E3dExtrudeObj::TakeObjNamePlural() const
150 {
151  return SvxResId(STR_ObjNamePluralExtrude3d);
152 }
153 
154 bool E3dExtrudeObj::IsBreakObjPossible()
155 {
156  return true;
157 }
158 
159 std::unique_ptr<SdrAttrObj,SdrObjectFreeOp> E3dExtrudeObj::GetBreakObj()
160 {
161  basegfx::B3DPolyPolygon aFrontSide;
162  basegfx::B3DPolyPolygon aBackSide;
163 
164  if(maExtrudePolygon.count())
165  {
166  basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
167  aTemp.removeDoublePoints();
169  const basegfx::B2VectorOrientation aOrient = basegfx::utils::getOrientation(aTemp.getB2DPolygon(0));
170 
172  {
173  aTemp.flip();
174  }
175 
177  }
178 
179  if(aFrontSide.count())
180  {
181  aBackSide = aFrontSide;
182 
183  if(GetExtrudeDepth())
184  {
185  basegfx::B3DHomMatrix aTransform;
186 
187  if(100 != GetPercentBackScale())
188  {
189  // scale polygon from center
190  const double fScaleFactor(GetPercentBackScale() / 100.0);
191  const basegfx::B3DRange aPolyPolyRange(basegfx::utils::getRange(aBackSide));
192  const basegfx::B3DPoint aCenter(aPolyPolyRange.getCenter());
193 
194  aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
195  aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
196  aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
197  }
198 
199  // translate by extrude depth
200  aTransform.translate(0.0, 0.0, static_cast<double>(GetExtrudeDepth()));
201 
202  aBackSide.transform(aTransform);
203  }
204  }
205 
206  if(aBackSide.count())
207  {
208  // create PathObj
209  basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
210  std::unique_ptr<SdrPathObj,SdrObjectFreeOp> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aPoly));
211 
212  SfxItemSet aSet(GetObjectItemSet());
213  aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
214  pPathObj->SetMergedItemSet(aSet);
215 
216  return std::unique_ptr<SdrAttrObj,SdrObjectFreeOp>(pPathObj.release());
217  }
218 
219  return nullptr;
220 }
221 
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void transform(const basegfx::B3DHomMatrix &rMatrix)
void scale(double fX, double fY, double fZ)
polygon, PolyPolygon
Definition: svdobj.hxx:126
B3DPolyPolygon createB3DPolyPolygonFromB2DPolyPolygon(const B2DPolyPolygon &rCandidate, double fZCoordinate)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
B2VectorOrientation getOrientation(const B2DPolygon &rCandidate)
sal_uInt32 count() const
OUString sName
E3dCompoundObject & operator=(const E3dCompoundObject &rObj)
Definition: obj3d.cxx:597
void scale(double fX, double fY)
const sal_uInt16 E3D_EXTRUDEOBJ_ID
Definition: globl3d.hxx:29
B2DRange getRange(const B2DPolygon &rCandidate)
B2VectorOrientation
void translate(double fX, double fY, double fZ)
SfxUInt32Item makeSvx3DDepthItem(sal_uInt32 nVal)
Definition: svx3ditems.hxx:42
OUString aName
B2DPolyPolygon correctOrientations(const B2DPolyPolygon &rCandidate)