LCOV - code coverage report
Current view: top level - svx/source/engine3d - polygn3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 92 30.4 %
Date: 2012-08-25 Functions: 12 19 63.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 15 160 9.4 %

           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                 :            : #include <svx/polygn3d.hxx>
      30                 :            : #include <svx/svdpage.hxx>
      31                 :            : #include "svx/globl3d.hxx"
      32                 :            : #include <basegfx/point/b3dpoint.hxx>
      33                 :            : #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx>
      34                 :            : #include <basegfx/polygon/b3dpolygon.hxx>
      35                 :            : #include <basegfx/polygon/b3dpolygontools.hxx>
      36                 :            : 
      37 [ -  + ][ +  + ]:      35628 : TYPEINIT1(E3dPolygonObj, E3dCompoundObject);
      38                 :            : 
      39                 :            : //////////////////////////////////////////////////////////////////////////////
      40                 :            : // DrawContact section
      41                 :            : 
      42                 :        438 : sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
      43                 :            : {
      44         [ +  - ]:        438 :     return new sdr::contact::ViewContactOfE3dPolygon(*this);
      45                 :            : }
      46                 :            : 
      47                 :          0 : E3dPolygonObj::E3dPolygonObj(
      48                 :            :     E3dDefaultAttributes& rDefault,
      49                 :            :     const basegfx::B3DPolyPolygon& rPolyPoly3D,
      50                 :            :     sal_Bool bLinOnly)
      51                 :            : :   E3dCompoundObject(rDefault),
      52 [ #  # ][ #  # ]:          0 :     bLineOnly(bLinOnly)
                 [ #  # ]
      53                 :            : {
      54                 :            :     // Set geometry
      55         [ #  # ]:          0 :     SetPolyPolygon3D(rPolyPoly3D);
      56                 :            : 
      57                 :            :     // Create default normals
      58         [ #  # ]:          0 :     CreateDefaultNormals();
      59                 :            : 
      60                 :            :     // Create default texture coordinates
      61         [ #  # ]:          0 :     CreateDefaultTexture();
      62                 :          0 : }
      63                 :            : 
      64                 :        438 : E3dPolygonObj::E3dPolygonObj()
      65                 :            : :   E3dCompoundObject(),
      66 [ +  - ][ +  - ]:        438 :     bLineOnly(false) // added missing initialisation
                 [ +  - ]
      67                 :            : {
      68                 :            :     // Create no geometry
      69                 :        438 : }
      70                 :            : 
      71                 :          0 : void E3dPolygonObj::CreateDefaultNormals()
      72                 :            : {
      73         [ #  # ]:          0 :     basegfx::B3DPolyPolygon aPolyNormals;
      74                 :            : 
      75                 :            :     // Create a complete PolyPolygon with the plane normal
      76 [ #  # ][ #  # ]:          0 :     for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
      77                 :            :     {
      78                 :            :         // Find source polygon
      79         [ #  # ]:          0 :         const basegfx::B3DPolygon aPolygon(aPolyPoly3D.getB3DPolygon(a));
      80                 :            : 
      81                 :            :         // Creating a new polygon for the normal
      82         [ #  # ]:          0 :         basegfx::B3DPolygon aNormals;
      83                 :            : 
      84                 :            :         // Get normal (and invert)
      85         [ #  # ]:          0 :         basegfx::B3DVector aNormal(-basegfx::tools::getNormal(aPolygon));
      86                 :            : 
      87                 :            :         // Fill new polygon
      88 [ #  # ][ #  # ]:          0 :         for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
      89                 :            :         {
      90         [ #  # ]:          0 :             aNormals.append(aNormal);
      91                 :            :         }
      92                 :            : 
      93                 :            :         // Insert new polygon into the PolyPolygon
      94         [ #  # ]:          0 :         aPolyNormals.append(aNormals);
      95 [ #  # ][ #  # ]:          0 :     }
      96                 :            : 
      97                 :            :     // Set default normal
      98 [ #  # ][ #  # ]:          0 :     SetPolyNormals3D(aPolyNormals);
      99                 :          0 : }
     100                 :            : 
     101                 :          0 : void E3dPolygonObj::CreateDefaultTexture()
     102                 :            : {
     103         [ #  # ]:          0 :     basegfx::B2DPolyPolygon aPolyTexture;
     104                 :            :     // Create a complete PolyPolygon with the texture coordinates
     105                 :            :     // The texture coordinates extend over X,Y and Z
     106                 :            :     // on the whole extreme values in the range 0.0 .. 1.0
     107 [ #  # ][ #  # ]:          0 :     for(sal_uInt32 a(0L); a < aPolyPoly3D.count(); a++)
     108                 :            :     {
     109                 :            :         // Find source polygon
     110         [ #  # ]:          0 :         const basegfx::B3DPolygon& aPolygon(aPolyPoly3D.getB3DPolygon(a));
     111                 :            : 
     112                 :            :         // Determine the total size of the object
     113         [ #  # ]:          0 :         basegfx::B3DRange aVolume(basegfx::tools::getRange(aPolygon));
     114                 :            : 
     115                 :            :         // Get normal
     116         [ #  # ]:          0 :         basegfx::B3DVector aNormal(basegfx::tools::getNormal(aPolygon));
     117                 :          0 :         aNormal.setX(fabs(aNormal.getX()));
     118                 :          0 :         aNormal.setY(fabs(aNormal.getY()));
     119                 :          0 :         aNormal.setZ(fabs(aNormal.getZ()));
     120                 :            : 
     121                 :            :         // Decide which coordinates should be used as a source for the mapping
     122                 :          0 :         sal_uInt16 nSourceMode = 0;
     123                 :            : 
     124                 :            :         // Determine the greatest degree of freedom
     125 [ #  # ][ #  # ]:          0 :         if(!(aNormal.getX() > aNormal.getY() && aNormal.getX() > aNormal.getZ()))
                 [ #  # ]
     126                 :            :         {
     127         [ #  # ]:          0 :             if(aNormal.getY() > aNormal.getZ())
     128                 :            :             {
     129                 :            :                 // Y is the largest, use X,Z as mapping
     130                 :          0 :                 nSourceMode = 1;
     131                 :            :             }
     132                 :            :             else
     133                 :            :             {
     134                 :            :                 // Z is the largest, use X,Y as mapping
     135                 :          0 :                 nSourceMode = 2;
     136                 :            :             }
     137                 :            :         }
     138                 :            : 
     139                 :            :         // Create new polygon for texture coordinates
     140         [ #  # ]:          0 :         basegfx::B2DPolygon aTexture;
     141                 :            : 
     142                 :            :         // Fill new polygon
     143 [ #  # ][ #  # ]:          0 :         for(sal_uInt32 b(0L); b < aPolygon.count(); b++)
     144                 :            :         {
     145                 :          0 :             basegfx::B2DPoint aTex;
     146         [ #  # ]:          0 :             const basegfx::B3DPoint aCandidate(aPolygon.getB3DPoint(b));
     147                 :            : 
     148   [ #  #  #  # ]:          0 :             switch(nSourceMode)
     149                 :            :             {
     150                 :            :                 case 0: //Source is Y,Z
     151 [ #  # ][ #  # ]:          0 :                     if(aVolume.getHeight())
     152 [ #  # ][ #  # ]:          0 :                         aTex.setX((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
     153 [ #  # ][ #  # ]:          0 :                     if(aVolume.getDepth())
     154 [ #  # ][ #  # ]:          0 :                         aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
     155                 :          0 :                     break;
     156                 :            : 
     157                 :            :                 case 1: // Source is X,Z
     158 [ #  # ][ #  # ]:          0 :                     if(aVolume.getWidth())
     159 [ #  # ][ #  # ]:          0 :                         aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
     160 [ #  # ][ #  # ]:          0 :                     if(aVolume.getDepth())
     161 [ #  # ][ #  # ]:          0 :                         aTex.setY((aCandidate.getZ() - aVolume.getMinZ()) / aVolume.getDepth());
     162                 :          0 :                     break;
     163                 :            : 
     164                 :            :                 case 2: // Source is X,Y
     165 [ #  # ][ #  # ]:          0 :                     if(aVolume.getWidth())
     166 [ #  # ][ #  # ]:          0 :                         aTex.setX((aCandidate.getX() - aVolume.getMinX()) / aVolume.getWidth());
     167 [ #  # ][ #  # ]:          0 :                     if(aVolume.getHeight())
     168 [ #  # ][ #  # ]:          0 :                         aTex.setY((aCandidate.getY() - aVolume.getMinY()) / aVolume.getHeight());
     169                 :          0 :                     break;
     170                 :            :             }
     171                 :            : 
     172         [ #  # ]:          0 :             aTexture.append(aTex);
     173                 :          0 :         }
     174                 :            : 
     175                 :            :         // Insert new polygon into the PolyPolygon
     176         [ #  # ]:          0 :         aPolyTexture.append(aTexture);
     177 [ #  # ][ #  # ]:          0 :     }
     178                 :            : 
     179                 :            :     // Set default Texture coordinates
     180 [ #  # ][ #  # ]:          0 :     SetPolyTexture2D(aPolyTexture);
     181                 :          0 : }
     182                 :            : 
     183 [ +  - ][ +  - ]:        438 : E3dPolygonObj::~E3dPolygonObj()
                 [ +  - ]
     184                 :            : {
     185         [ -  + ]:        876 : }
     186                 :            : 
     187                 :        438 : sal_uInt16 E3dPolygonObj::GetObjIdentifier() const
     188                 :            : {
     189                 :        438 :     return E3D_POLYGONOBJ_ID;
     190                 :            : }
     191                 :            : 
     192                 :        438 : void E3dPolygonObj::SetPolyPolygon3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D)
     193                 :            : {
     194         [ +  - ]:        438 :     if ( aPolyPoly3D != rNewPolyPoly3D )
     195                 :            :     {
     196                 :            :         // New PolyPolygon; copying
     197                 :        438 :         aPolyPoly3D = rNewPolyPoly3D;
     198                 :            : 
     199                 :            :         // Create new geometry
     200                 :        438 :         ActionChanged();
     201                 :            :     }
     202                 :        438 : }
     203                 :            : 
     204                 :        438 : void E3dPolygonObj::SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyNormals3D)
     205                 :            : {
     206         [ +  - ]:        438 :     if ( aPolyNormals3D != rNewPolyNormals3D )
     207                 :            :     {
     208                 :            :         // New PolyPolygon; copying
     209                 :        438 :         aPolyNormals3D = rNewPolyNormals3D;
     210                 :            : 
     211                 :            :         // Create new geometry
     212                 :        438 :         ActionChanged();
     213                 :            :     }
     214                 :        438 : }
     215                 :            : 
     216                 :        438 : void E3dPolygonObj::SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyTexture2D)
     217                 :            : {
     218         [ +  - ]:        438 :     if ( aPolyTexture2D != rNewPolyTexture2D )
     219                 :            :     {
     220                 :            :         // New PolyPolygon; copying
     221                 :        438 :         aPolyTexture2D = rNewPolyTexture2D;
     222                 :            : 
     223                 :            :         // Create new geometry
     224                 :        438 :         ActionChanged();
     225                 :            :     }
     226                 :        438 : }
     227                 :            : 
     228                 :            : // Convert the object into a group object consisting of 6 polygons
     229                 :            : 
     230                 :          0 : SdrObject *E3dPolygonObj::DoConvertToPolyObj(sal_Bool /*bBezier*/) const
     231                 :            : {
     232                 :          0 :     return NULL;
     233                 :            : }
     234                 :            : 
     235                 :          0 : E3dPolygonObj* E3dPolygonObj::Clone() const
     236                 :            : {
     237                 :          0 :     return CloneHelper< E3dPolygonObj >();
     238                 :            : }
     239                 :            : 
     240                 :        438 : void E3dPolygonObj::SetLineOnly(sal_Bool bNew)
     241                 :            : {
     242         [ -  + ]:        438 :     if(bNew != bLineOnly)
     243                 :            :     {
     244                 :          0 :         bLineOnly = bNew;
     245                 :          0 :         ActionChanged();
     246                 :            :     }
     247                 :        438 : }
     248                 :            : 
     249                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10