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