1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_svx.hxx" 30cdf0e10cSrcweir #include <svx/polygn3d.hxx> 31cdf0e10cSrcweir #include <svx/svdpage.hxx> 32cdf0e10cSrcweir #include "svx/globl3d.hxx" 33cdf0e10cSrcweir #include <basegfx/point/b3dpoint.hxx> 34cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx> 35cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx> 36cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygontools.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir TYPEINIT1(E3dPolygonObj, E3dCompoundObject); 39cdf0e10cSrcweir 40cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 41cdf0e10cSrcweir // #110094# DrawContact section 42cdf0e10cSrcweir 43cdf0e10cSrcweir sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact() 44cdf0e10cSrcweir { 45cdf0e10cSrcweir return new sdr::contact::ViewContactOfE3dPolygon(*this); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir /************************************************************************* 49cdf0e10cSrcweir |* 50cdf0e10cSrcweir |* Konstruktor 51cdf0e10cSrcweir |* 52cdf0e10cSrcweir \************************************************************************/ 53cdf0e10cSrcweir 54cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj( 55cdf0e10cSrcweir E3dDefaultAttributes& rDefault, 56cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyPoly3D, 57cdf0e10cSrcweir sal_Bool bLinOnly) 58cdf0e10cSrcweir : E3dCompoundObject(rDefault), 59cdf0e10cSrcweir bLineOnly(bLinOnly) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir // Geometrie setzen 62cdf0e10cSrcweir SetPolyPolygon3D(rPolyPoly3D); 63cdf0e10cSrcweir 64cdf0e10cSrcweir // Default-Normals erzeugen 65cdf0e10cSrcweir CreateDefaultNormals(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // Default-Texturkoordinaten erzeugen 68cdf0e10cSrcweir CreateDefaultTexture(); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir /************************************************************************* 72cdf0e10cSrcweir |* 73cdf0e10cSrcweir |* Konstruktor 74cdf0e10cSrcweir |* 75cdf0e10cSrcweir \************************************************************************/ 76cdf0e10cSrcweir 77cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj( 78cdf0e10cSrcweir E3dDefaultAttributes& rDefault, 79cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyPoly3D, 80cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyNormals3D, 81cdf0e10cSrcweir sal_Bool bLinOnly) 82cdf0e10cSrcweir : E3dCompoundObject(rDefault), 83cdf0e10cSrcweir bLineOnly(bLinOnly) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir // Geometrie und Normalen setzen 86cdf0e10cSrcweir SetPolyPolygon3D(rPolyPoly3D); 87cdf0e10cSrcweir SetPolyNormals3D(rPolyNormals3D); 88cdf0e10cSrcweir 89cdf0e10cSrcweir // Default-Texturkoordinaten erzeugen 90cdf0e10cSrcweir CreateDefaultTexture(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir /************************************************************************* 94cdf0e10cSrcweir |* 95cdf0e10cSrcweir |* Konstruktor 96cdf0e10cSrcweir |* 97cdf0e10cSrcweir \************************************************************************/ 98cdf0e10cSrcweir 99cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj( 100cdf0e10cSrcweir E3dDefaultAttributes& rDefault, 101cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyPoly3D, 102cdf0e10cSrcweir const basegfx::B3DPolyPolygon& rPolyNormals3D, 103cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rPolyTexture2D, 104cdf0e10cSrcweir sal_Bool bLinOnly) 105cdf0e10cSrcweir : E3dCompoundObject(rDefault), 106cdf0e10cSrcweir bLineOnly(bLinOnly) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir SetPolyPolygon3D(rPolyPoly3D); 109cdf0e10cSrcweir SetPolyNormals3D(rPolyNormals3D); 110cdf0e10cSrcweir SetPolyTexture2D(rPolyTexture2D); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /************************************************************************* 114cdf0e10cSrcweir |* 115cdf0e10cSrcweir |* Leer-Konstruktor 116cdf0e10cSrcweir |* 117cdf0e10cSrcweir \************************************************************************/ 118cdf0e10cSrcweir 119cdf0e10cSrcweir E3dPolygonObj::E3dPolygonObj() 120cdf0e10cSrcweir : E3dCompoundObject(), 121cdf0e10cSrcweir bLineOnly(false) // added missing initialisation 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // Keine Geometrie erzeugen 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir /************************************************************************* 127cdf0e10cSrcweir |* 128cdf0e10cSrcweir |* Default-Normalen erzeugen 129cdf0e10cSrcweir |* 130cdf0e10cSrcweir \************************************************************************/ 131cdf0e10cSrcweir 132cdf0e10cSrcweir void E3dPolygonObj::CreateDefaultNormals() 133cdf0e10cSrcweir { 134cdf0e10cSrcweir basegfx::B3DPolyPolygon aPolyNormals; 135cdf0e10cSrcweir 136cdf0e10cSrcweir // Komplettes PolyPolygon mit den Ebenennormalen anlegen 137cdf0e10cSrcweir for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir // Quellpolygon finden 140cdf0e10cSrcweir const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a)); 141cdf0e10cSrcweir 142cdf0e10cSrcweir // Neues Polygon fuer Normalen anlegen 143cdf0e10cSrcweir basegfx::B3DPolygon aNormals; 144cdf0e10cSrcweir 145cdf0e10cSrcweir // Normale holen (und umdrehen) 146cdf0e10cSrcweir basegfx::B3DVector aNormal(-basegfx::tools::getNormal(aPolygon)); 147cdf0e10cSrcweir 148cdf0e10cSrcweir // Neues Polygon fuellen 149cdf0e10cSrcweir for(sal_uInt32 b(0L); b < aPolygon.count(); b++) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir aNormals.append(aNormal); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir // Neues Polygon in PolyPolygon einfuegen 155cdf0e10cSrcweir aPolyNormals.append(aNormals); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir // Default-Normalen setzen 159cdf0e10cSrcweir SetPolyNormals3D(aPolyNormals); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir /************************************************************************* 163cdf0e10cSrcweir |* 164cdf0e10cSrcweir |* Default-Texturkoordinaten erzeugen 165cdf0e10cSrcweir |* 166cdf0e10cSrcweir \************************************************************************/ 167cdf0e10cSrcweir 168cdf0e10cSrcweir void E3dPolygonObj::CreateDefaultTexture() 169cdf0e10cSrcweir { 170cdf0e10cSrcweir basegfx::B2DPolyPolygon aPolyTexture; 171cdf0e10cSrcweir 172cdf0e10cSrcweir // Komplettes PolyPolygon mit den Texturkoordinaten anlegen 173cdf0e10cSrcweir // Die Texturkoordinaten erstrecken sich ueber X,Y und Z 174cdf0e10cSrcweir // ueber die gesamten Extremwerte im Bereich 0.0 .. 1.0 175cdf0e10cSrcweir for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // Quellpolygon finden 178cdf0e10cSrcweir const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a)); 179cdf0e10cSrcweir 180cdf0e10cSrcweir // Gesamtgroesse des Objektes feststellen 181cdf0e10cSrcweir basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon)); 182cdf0e10cSrcweir 183cdf0e10cSrcweir // Normale holen 184cdf0e10cSrcweir basegfx::B3DVector aNormal(basegfx::tools::getNormal(aPolygon)); 185cdf0e10cSrcweir aNormal.setX(fabs(aNormal.getX())); 186cdf0e10cSrcweir aNormal.setY(fabs(aNormal.getY())); 187cdf0e10cSrcweir aNormal.setZ(fabs(aNormal.getZ())); 188cdf0e10cSrcweir 189cdf0e10cSrcweir // Entscheiden, welche Koordinaten als Source fuer das 190cdf0e10cSrcweir // Mapping benutzt werden sollen 191cdf0e10cSrcweir sal_uInt16 nSourceMode = 0; 192cdf0e10cSrcweir 193cdf0e10cSrcweir // Groessten Freiheitsgrad ermitteln 194cdf0e10cSrcweir if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ())) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir if(aNormal.getY() > aNormal.getZ()) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir // Y ist am groessten, benutze X,Z als mapping 199cdf0e10cSrcweir nSourceMode = 1; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir else 202cdf0e10cSrcweir { 203cdf0e10cSrcweir // Z ist am groessten, benutze X,Y als mapping 204cdf0e10cSrcweir nSourceMode = 2; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir // Neues Polygon fuer Texturkoordinaten anlegen 209cdf0e10cSrcweir basegfx::B2DPolygon aTexture; 210cdf0e10cSrcweir 211cdf0e10cSrcweir // Neues Polygon fuellen 212cdf0e10cSrcweir for(sal_uInt32 b(0L); b < aPolygon.count(); b++) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir basegfx::B2DPoint aTex; 215cdf0e10cSrcweir const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b)); 216cdf0e10cSrcweir 217cdf0e10cSrcweir switch(nSourceMode) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir case 0: // Quelle ist Y,Z 220cdf0e10cSrcweir if(aVolume.getHeight()) 221cdf0e10cSrcweir aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight()); 222cdf0e10cSrcweir if(aVolume.getDepth()) 223cdf0e10cSrcweir aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth()); 224cdf0e10cSrcweir break; 225cdf0e10cSrcweir 226cdf0e10cSrcweir case 1: // Quelle ist X,Z 227cdf0e10cSrcweir if(aVolume.getWidth()) 228cdf0e10cSrcweir aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth()); 229cdf0e10cSrcweir if(aVolume.getDepth()) 230cdf0e10cSrcweir aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth()); 231cdf0e10cSrcweir break; 232cdf0e10cSrcweir 233cdf0e10cSrcweir case 2: // Quelle ist X,Y 234cdf0e10cSrcweir if(aVolume.getWidth()) 235cdf0e10cSrcweir aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth()); 236cdf0e10cSrcweir if(aVolume.getHeight()) 237cdf0e10cSrcweir aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight()); 238cdf0e10cSrcweir break; 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir aTexture.append(aTex); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir // Neues Polygon in PolyPolygon einfuegen 245cdf0e10cSrcweir aPolyTexture.append(aTexture); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir // Default-Texturkoordinaten setzen 249cdf0e10cSrcweir SetPolyTexture2D(aPolyTexture); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir /************************************************************************* 253cdf0e10cSrcweir |* 254cdf0e10cSrcweir |* Destruktor 255cdf0e10cSrcweir |* 256cdf0e10cSrcweir \************************************************************************/ 257cdf0e10cSrcweir 258cdf0e10cSrcweir E3dPolygonObj::~E3dPolygonObj() 259cdf0e10cSrcweir { 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir /************************************************************************* 263cdf0e10cSrcweir |* 264cdf0e10cSrcweir |* Identifier zurueckgeben 265cdf0e10cSrcweir |* 266cdf0e10cSrcweir \************************************************************************/ 267cdf0e10cSrcweir 268cdf0e10cSrcweir sal_uInt16 E3dPolygonObj::GetObjIdentifier() const 269cdf0e10cSrcweir { 270cdf0e10cSrcweir return E3D_POLYGONOBJ_ID; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir /************************************************************************* 274cdf0e10cSrcweir |* 275cdf0e10cSrcweir |* Polygon setzen 276cdf0e10cSrcweir |* 277cdf0e10cSrcweir \************************************************************************/ 278cdf0e10cSrcweir 279cdf0e10cSrcweir void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir if ( aPolyPoly3D != rNewPolyPoly3D ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir // Neues PolyPolygon; kopieren 284cdf0e10cSrcweir aPolyPoly3D = rNewPolyPoly3D; 285cdf0e10cSrcweir 286cdf0e10cSrcweir // Geometrie neu erzeugen 287cdf0e10cSrcweir ActionChanged(); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir if ( aPolyNormals3D != rNewPolyNormals3D ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir // Neue Normalen; kopieren 296cdf0e10cSrcweir aPolyNormals3D = rNewPolyNormals3D; 297cdf0e10cSrcweir 298cdf0e10cSrcweir // Geometrie neu erzeugen 299cdf0e10cSrcweir ActionChanged(); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir if ( aPolyTexture2D != rNewPolyTexture2D ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir // Neue Texturkoordinaten; kopieren 308cdf0e10cSrcweir aPolyTexture2D = rNewPolyTexture2D; 309cdf0e10cSrcweir 310cdf0e10cSrcweir // Geometrie neu erzeugen 311cdf0e10cSrcweir ActionChanged(); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir /************************************************************************* 316cdf0e10cSrcweir |* 317cdf0e10cSrcweir |* Wandle das Objekt in ein Gruppenobjekt bestehend aus 6 Polygonen 318cdf0e10cSrcweir |* 319cdf0e10cSrcweir \************************************************************************/ 320cdf0e10cSrcweir 321*a5258243SPedro Giffuni SdrObject *E3dPolygonObj::DoConvertToPolyObj(sal_Bool /*bBezier*/, bool /*bAddText*/) const 322cdf0e10cSrcweir { 323cdf0e10cSrcweir return NULL; 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir /************************************************************************* 327cdf0e10cSrcweir |* 328cdf0e10cSrcweir |* Zuweisungsoperator 329cdf0e10cSrcweir |* 330cdf0e10cSrcweir \************************************************************************/ 331cdf0e10cSrcweir 332cdf0e10cSrcweir void E3dPolygonObj::operator=(const SdrObject& rObj) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir // erstmal alle Childs kopieren 335cdf0e10cSrcweir E3dCompoundObject::operator=(rObj); 336cdf0e10cSrcweir 337cdf0e10cSrcweir // weitere Parameter kopieren 338cdf0e10cSrcweir const E3dPolygonObj& r3DObj = (const E3dPolygonObj&)rObj; 339cdf0e10cSrcweir 340cdf0e10cSrcweir aPolyPoly3D = r3DObj.aPolyPoly3D; 341cdf0e10cSrcweir aPolyNormals3D = r3DObj.aPolyNormals3D; 342cdf0e10cSrcweir aPolyTexture2D = r3DObj.aPolyTexture2D; 343cdf0e10cSrcweir bLineOnly = r3DObj.bLineOnly; 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir /************************************************************************* 347cdf0e10cSrcweir |* 348cdf0e10cSrcweir |* LineOnly setzen 349cdf0e10cSrcweir |* 350cdf0e10cSrcweir \************************************************************************/ 351cdf0e10cSrcweir 352cdf0e10cSrcweir void E3dPolygonObj::SetLineOnly(sal_Bool bNew) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir if(bNew != bLineOnly) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir bLineOnly = bNew; 357cdf0e10cSrcweir ActionChanged(); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir // eof 362