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