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 <svx/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
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 
73 : E3dCompoundObject(rSdrModel)
74 {
75  // Set Defaults
76  const E3dDefaultAttributes aDefault;
77 
78  SetDefaultAttributes(aDefault);
79 }
80 
82 {
83 }
84 
86 {
92 
93  // For extrudes use StdTexture in X and Y by default
96 }
97 
99 {
100  return E3D_EXTRUDEOBJ_ID;
101 }
102 
104 {
105  return CloneHelper< E3dExtrudeObj >(rTargetModel);
106 }
107 
109 {
110  if( this == &rObj )
111  return *this;
113 
115 
116  return *this;
117 }
118 
119 // Set local parameters with geometry re-creating
120 
122 {
123  if(maExtrudePolygon != rNew)
124  {
125  maExtrudePolygon = rNew;
126  ActionChanged();
127  }
128 }
129 
130 // Get the name of the object (singular)
131 
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 
150 {
151  return SvxResId(STR_ObjNamePluralExtrude3d);
152 }
153 
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  {
167  aTemp.removeDoublePoints();
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
210  std::unique_ptr<SdrPathObj,SdrObjectFreeOp> pPathObj(new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aPoly));
211 
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)
virtual void SetObjectItemDirect(const SfxPoolItem &rItem)=0
virtual std::unique_ptr< SdrAttrObj, SdrObjectFreeOp > GetBreakObj() override
Definition: extrud3d.cxx:159
bool GetDefaultExtrudeCharacterMode() const
Definition: deflt3d.hxx:86
virtual OUString TakeObjNamePlural() const override
Definition: extrud3d.cxx:149
sal_uInt16 GetPercentBackScale() const
Definition: extrud3d.hxx:68
virtual sdr::properties::BaseProperties & GetProperties() const
Definition: svdobj.cxx:228
void scale(double fX, double fY, double fZ)
polygon, PolyPolygon
Definition: svdobj.hxx:126
void SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
Definition: extrud3d.cxx:121
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:132
sal_uInt32 count() const
E3dExtrudeObj & operator=(const E3dExtrudeObj &rObj)
Definition: extrud3d.cxx:108
const SfxItemSet & GetObjectItemSet() const
Definition: svdobj.cxx:1903
basegfx::B2DPolyPolygon TransformToScreenCoor(const basegfx::B3DPolyPolygon &rCandidate)
Definition: obj3d.cxx:606
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:81
OUString sName
E3dCompoundObject & operator=(const E3dCompoundObject &rObj)
Definition: obj3d.cxx:597
void ActionChanged() const
Definition: svdobj.cxx:281
void scale(double fX, double fY)
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:297
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:722
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:40
virtual bool IsBreakObjPossible() override
Definition: extrud3d.cxx:154
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:103
virtual std::unique_ptr< sdr::properties::BaseProperties > CreateObjectSpecificProperties() override
Definition: extrud3d.cxx:45
B2DPolyPolygon correctOrientations(const B2DPolyPolygon &rCandidate)
void SetDefaultAttributes(const E3dDefaultAttributes &rDefault)
Definition: extrud3d.cxx:85
virtual sal_uInt16 GetObjIdentifier() const override
Definition: extrud3d.cxx:98
E3dExtrudeObj(SdrModel &rSdrModel, const E3dDefaultAttributes &rDefault, const basegfx::B2DPolyPolygon &rPP, double fDepth)
Definition: extrud3d.cxx:52