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