1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "svx/svdstr.hrc"
22 #include "svdglob.hxx"
23 #include <svx/svdpage.hxx>
24 #include "svx/globl3d.hxx"
25 #include <svx/extrud3d.hxx>
26 #include <svx/scene3d.hxx>
28 #include <svx/svxids.hrc>
29 #include <svx/xpoly.hxx>
30 #include <svx/svdopath.hxx>
31 #include <svx/svdmodel.hxx>
32 #include <svx/svx3ditems.hxx>
33 #include <sdr/properties/e3dextrudeproperties.hxx>
34 #include <sdr/contact/viewcontactofe3dextrude.hxx>
35 #include <basegfx/polygon/b2dpolypolygontools.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <basegfx/polygon/b3dpolygontools.hxx>
38 #include <basegfx/polygon/b3dpolypolygontools.hxx>
41 // DrawContact section
43 sdr::contact::ViewContact
* E3dExtrudeObj::CreateObjectSpecificViewContact()
45 return new sdr::contact::ViewContactOfE3dExtrude(*this);
50 sdr::properties::BaseProperties
* E3dExtrudeObj::CreateObjectSpecificProperties()
52 return new sdr::properties::E3dExtrudeProperties(*this);
57 TYPEINIT1(E3dExtrudeObj
, E3dCompoundObject
);
59 // Constructor creates a two cover surface tools::PolyPolygon and (point-count 1) side
60 // surfaces rectangles from the passed PolyPolygon
62 E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes
& rDefault
, const basegfx::B2DPolyPolygon
& rPP
, double fDepth
)
63 : E3dCompoundObject(rDefault
),
66 // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
67 basegfx::B2DHomMatrix aMirrorY
;
68 aMirrorY
.scale(1.0, -1.0);
69 maExtrudePolygon
.transform(aMirrorY
);
72 SetDefaultAttributes(rDefault
);
75 GetProperties().SetObjectItemDirect(makeSvx3DDepthItem((sal_uInt32
)(fDepth
+ 0.5)));
78 E3dExtrudeObj::E3dExtrudeObj()
82 E3dDefaultAttributes aDefault
;
83 SetDefaultAttributes(aDefault
);
86 void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes
& rDefault
)
88 GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault
.GetDefaultExtrudeSmoothed()));
89 GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault
.GetDefaultExtrudeSmoothFrontBack()));
90 GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault
.GetDefaultExtrudeCharacterMode()));
91 GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault
.GetDefaultExtrudeCloseFront()));
92 GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault
.GetDefaultExtrudeCloseBack()));
94 // For extrudes use StdTexture in X and Y by default
95 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
96 GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
99 sal_uInt16
E3dExtrudeObj::GetObjIdentifier() const
101 return E3D_EXTRUDEOBJ_ID
;
104 E3dExtrudeObj
* E3dExtrudeObj::Clone() const
106 return CloneHelper
< E3dExtrudeObj
>();
110 // Set local parameters with geometry re-creating
112 void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon
&rNew
)
114 if(maExtrudePolygon
!= rNew
)
116 maExtrudePolygon
= rNew
;
121 // Get the name of the object (singular)
123 OUString
E3dExtrudeObj::TakeObjNameSingul() const
125 OUStringBuffer
sName(ImpGetResStr(STR_ObjNameSingulExtrude3d
));
127 OUString
aName(GetName());
128 if (!aName
.isEmpty())
135 return sName
.makeStringAndClear();
138 // Get the name of the object (plural)
140 OUString
E3dExtrudeObj::TakeObjNamePlural() const
142 return ImpGetResStr(STR_ObjNamePluralExtrude3d
);
145 bool E3dExtrudeObj::IsBreakObjPossible()
150 SdrAttrObj
* E3dExtrudeObj::GetBreakObj()
152 basegfx::B3DPolyPolygon aFrontSide
;
153 basegfx::B3DPolyPolygon aBackSide
;
155 if(maExtrudePolygon
.count())
157 basegfx::B2DPolyPolygon
aTemp(maExtrudePolygon
);
158 aTemp
.removeDoublePoints();
159 aTemp
= basegfx::tools::correctOrientations(aTemp
);
160 const basegfx::B2VectorOrientation aOrient
= basegfx::tools::getOrientation(aTemp
.getB2DPolygon(0L));
162 if(basegfx::ORIENTATION_POSITIVE
== aOrient
)
167 aFrontSide
= basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(aTemp
);
170 if(aFrontSide
.count())
172 aBackSide
= aFrontSide
;
174 if(GetExtrudeDepth())
176 basegfx::B3DHomMatrix aTransform
;
178 if(100 != GetPercentBackScale())
180 // scale polygon from center
181 const double fScaleFactor(GetPercentBackScale() / 100.0);
182 const basegfx::B3DRange
aPolyPolyRange(basegfx::tools::getRange(aBackSide
));
183 const basegfx::B3DPoint
aCenter(aPolyPolyRange
.getCenter());
185 aTransform
.translate(-aCenter
.getX(), -aCenter
.getY(), -aCenter
.getZ());
186 aTransform
.scale(fScaleFactor
, fScaleFactor
, fScaleFactor
);
187 aTransform
.translate(aCenter
.getX(), aCenter
.getY(), aCenter
.getZ());
190 // translate by extrude depth
191 aTransform
.translate(0.0, 0.0, (double)GetExtrudeDepth());
193 aBackSide
.transform(aTransform
);
197 if(aBackSide
.count())
200 basegfx::B2DPolyPolygon aPoly
= TransformToScreenCoor(aBackSide
);
201 SdrPathObj
* pPathObj
= new SdrPathObj(OBJ_PLIN
, aPoly
);
203 SfxItemSet
aSet(GetObjectItemSet());
204 aSet
.Put(XLineStyleItem(com::sun::star::drawing::LineStyle_SOLID
));
205 pPathObj
->SetMergedItemSet(aSet
);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */