Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "svx/svdstr.hrc"
31 : : #include "svx/svdglob.hxx"
32 : : #include <svx/svdpage.hxx>
33 : : #include "svx/globl3d.hxx"
34 : : #include <svx/extrud3d.hxx>
35 : : #include <svx/scene3d.hxx>
36 : :
37 : : #include <svx/svxids.hrc>
38 : : #include <svx/xpoly.hxx>
39 : : #include <svx/svdopath.hxx>
40 : : #include <svx/svdmodel.hxx>
41 : : #include <svx/svx3ditems.hxx>
42 : : #include <svx/sdr/properties/e3dextrudeproperties.hxx>
43 : : #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
44 : : #include <basegfx/polygon/b2dpolypolygontools.hxx>
45 : : #include <basegfx/polygon/b2dpolygontools.hxx>
46 : : #include <basegfx/polygon/b3dpolygontools.hxx>
47 : : #include <basegfx/polygon/b3dpolypolygontools.hxx>
48 : :
49 : : //////////////////////////////////////////////////////////////////////////////
50 : : // DrawContact section
51 : :
52 : 1501 : sdr::contact::ViewContact* E3dExtrudeObj::CreateObjectSpecificViewContact()
53 : : {
54 [ + - ]: 1501 : return new sdr::contact::ViewContactOfE3dExtrude(*this);
55 : : }
56 : :
57 : : //////////////////////////////////////////////////////////////////////////////
58 : :
59 : 1501 : sdr::properties::BaseProperties* E3dExtrudeObj::CreateObjectSpecificProperties()
60 : : {
61 [ + - ]: 1501 : return new sdr::properties::E3dExtrudeProperties(*this);
62 : : }
63 : :
64 : : //////////////////////////////////////////////////////////////////////////////
65 : :
66 [ + + ][ + + ]: 180414 : TYPEINIT1(E3dExtrudeObj, E3dCompoundObject);
67 : :
68 : : // Constructor creates a two cover surface PolyPolygon and (point-count 1) side
69 : : // surfaces rectangles from the passed PolyPolygon
70 : :
71 : 0 : E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes& rDefault, const basegfx::B2DPolyPolygon& rPP, double fDepth)
72 : : : E3dCompoundObject(rDefault),
73 [ # # ]: 0 : maExtrudePolygon(rPP)
74 : : {
75 : : // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
76 [ # # ]: 0 : basegfx::B2DHomMatrix aMirrorY;
77 [ # # ]: 0 : aMirrorY.scale(1.0, -1.0);
78 [ # # ]: 0 : maExtrudePolygon.transform(aMirrorY);
79 : :
80 : : // Set Defaults
81 [ # # ]: 0 : SetDefaultAttributes(rDefault);
82 : :
83 : : // set extrude depth
84 [ # # ][ # # ]: 0 : GetProperties().SetObjectItemDirect(Svx3DDepthItem((sal_uInt32)(fDepth + 0.5)));
[ # # ][ # # ]
[ # # ]
85 : 0 : }
86 : :
87 : 1501 : E3dExtrudeObj::E3dExtrudeObj()
88 [ + - ]: 1501 : : E3dCompoundObject()
89 : : {
90 : : // Set Defaults
91 [ + - ]: 1501 : E3dDefaultAttributes aDefault;
92 [ + - ][ + - ]: 1501 : SetDefaultAttributes(aDefault);
93 : 1501 : }
94 : :
95 : 1501 : void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
96 : : {
97 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
98 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
99 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DCharacterModeItem(rDefault.GetDefaultExtrudeCharacterMode()));
100 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DCloseFrontItem(rDefault.GetDefaultExtrudeCloseFront()));
101 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DCloseBackItem(rDefault.GetDefaultExtrudeCloseBack()));
102 : :
103 : : // For extrudes use StdTexture in X and Y by default
104 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DTextureProjectionXItem(1));
105 [ + - ]: 1501 : GetProperties().SetObjectItemDirect(Svx3DTextureProjectionYItem(1));
106 : 1501 : }
107 : :
108 : 1501 : sal_uInt16 E3dExtrudeObj::GetObjIdentifier() const
109 : : {
110 : 1501 : return E3D_EXTRUDEOBJ_ID;
111 : : }
112 : :
113 : 0 : E3dExtrudeObj* E3dExtrudeObj::Clone() const
114 : : {
115 : 0 : return CloneHelper< E3dExtrudeObj >();
116 : : }
117 : :
118 : :
119 : : // Set local parameters with geometry re-creating
120 : :
121 : 3002 : void E3dExtrudeObj::SetExtrudePolygon(const basegfx::B2DPolyPolygon &rNew)
122 : : {
123 [ + - ]: 3002 : if(maExtrudePolygon != rNew)
124 : : {
125 : 3002 : maExtrudePolygon = rNew;
126 : 3002 : ActionChanged();
127 : : }
128 : 3002 : }
129 : :
130 : : // Get the name of the object (singular)
131 : :
132 : 0 : void E3dExtrudeObj::TakeObjNameSingul(XubString& rName) const
133 : : {
134 [ # # ][ # # ]: 0 : rName=ImpGetResStr(STR_ObjNameSingulExtrude3d);
[ # # ]
135 : :
136 [ # # ][ # # ]: 0 : String aName( GetName() );
137 [ # # ]: 0 : if(aName.Len())
138 : : {
139 [ # # ]: 0 : rName += sal_Unicode(' ');
140 [ # # ]: 0 : rName += sal_Unicode('\'');
141 [ # # ]: 0 : rName += aName;
142 [ # # ]: 0 : rName += sal_Unicode('\'');
143 [ # # ]: 0 : }
144 : 0 : }
145 : :
146 : : // Get the name of the object (plural)
147 : :
148 : 0 : void E3dExtrudeObj::TakeObjNamePlural(XubString& rName) const
149 : : {
150 [ # # ]: 0 : rName=ImpGetResStr(STR_ObjNamePluralExtrude3d);
151 : 0 : }
152 : :
153 : 0 : sal_Bool E3dExtrudeObj::IsBreakObjPossible()
154 : : {
155 : 0 : return sal_True;
156 : : }
157 : :
158 : 0 : SdrAttrObj* E3dExtrudeObj::GetBreakObj()
159 : : {
160 [ # # ]: 0 : basegfx::B3DPolyPolygon aFrontSide;
161 [ # # ]: 0 : basegfx::B3DPolyPolygon aBackSide;
162 : :
163 [ # # ][ # # ]: 0 : if(maExtrudePolygon.count())
164 : : {
165 [ # # ]: 0 : basegfx::B2DPolyPolygon aTemp(maExtrudePolygon);
166 [ # # ]: 0 : aTemp.removeDoublePoints();
167 [ # # ][ # # ]: 0 : aTemp = basegfx::tools::correctOrientations(aTemp);
[ # # ]
168 [ # # ][ # # ]: 0 : const basegfx::B2VectorOrientation aOrient = basegfx::tools::getOrientation(aTemp.getB2DPolygon(0L));
[ # # ]
169 : :
170 [ # # ]: 0 : if(basegfx::ORIENTATION_POSITIVE == aOrient)
171 : : {
172 [ # # ]: 0 : aTemp.flip();
173 : : }
174 : :
175 [ # # ][ # # ]: 0 : aFrontSide = basegfx::tools::createB3DPolyPolygonFromB2DPolyPolygon(aTemp);
[ # # ][ # # ]
176 : : }
177 : :
178 [ # # ][ # # ]: 0 : if(aFrontSide.count())
179 : : {
180 [ # # ]: 0 : aBackSide = aFrontSide;
181 : :
182 [ # # ][ # # ]: 0 : if(GetExtrudeDepth())
183 : : {
184 [ # # ]: 0 : basegfx::B3DHomMatrix aTransform;
185 : :
186 [ # # ][ # # ]: 0 : if(100 != GetPercentBackScale())
187 : : {
188 : : // scale polygon from center
189 [ # # ]: 0 : const double fScaleFactor(GetPercentBackScale() / 100.0);
190 [ # # ]: 0 : const basegfx::B3DRange aPolyPolyRange(basegfx::tools::getRange(aBackSide));
191 [ # # ]: 0 : const basegfx::B3DPoint aCenter(aPolyPolyRange.getCenter());
192 : :
193 [ # # ]: 0 : aTransform.translate(-aCenter.getX(), -aCenter.getY(), -aCenter.getZ());
194 [ # # ]: 0 : aTransform.scale(fScaleFactor, fScaleFactor, fScaleFactor);
195 [ # # ]: 0 : aTransform.translate(aCenter.getX(), aCenter.getY(), aCenter.getZ());
196 : : }
197 : :
198 : : // translate by extrude depth
199 [ # # ][ # # ]: 0 : aTransform.translate(0.0, 0.0, (double)GetExtrudeDepth());
200 : :
201 [ # # ][ # # ]: 0 : aBackSide.transform(aTransform);
202 : : }
203 : : }
204 : :
205 [ # # ][ # # ]: 0 : if(aBackSide.count())
206 : : {
207 : : // create PathObj
208 [ # # ]: 0 : basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
209 [ # # ][ # # ]: 0 : SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aPoly);
210 : :
211 [ # # ]: 0 : if(pPathObj)
212 : : {
213 [ # # ][ # # ]: 0 : SfxItemSet aSet(GetObjectItemSet());
214 [ # # ][ # # ]: 0 : aSet.Put(XLineStyleItem(XLINE_SOLID));
[ # # ]
215 [ # # ][ # # ]: 0 : pPathObj->SetMergedItemSet(aSet);
216 : : }
217 : :
218 [ # # ]: 0 : return pPathObj;
219 : : }
220 : :
221 [ # # ][ # # ]: 0 : return 0;
222 : : }
223 : :
224 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|