LCOV - code coverage report
Current view: top level - svx/source/sdr/contact - viewcontactofe3dpolygon.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 58 64 90.6 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 89 174 51.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <svx/sdr/contact/viewcontactofe3dpolygon.hxx>
      22                 :            : #include <svx/polygn3d.hxx>
      23                 :            : #include <drawinglayer/primitive3d/sdrpolypolygonprimitive3d.hxx>
      24                 :            : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      25                 :            : #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
      26                 :            : #include <basegfx/polygon/b3dpolygon.hxx>
      27                 :            : #include <basegfx/polygon/b3dpolypolygontools.hxx>
      28                 :            : 
      29                 :            : //////////////////////////////////////////////////////////////////////////////
      30                 :            : 
      31                 :            : namespace sdr
      32                 :            : {
      33                 :            :     namespace contact
      34                 :            :     {
      35                 :        438 :         ViewContactOfE3dPolygon::ViewContactOfE3dPolygon(E3dPolygonObj& rPolygon)
      36                 :        438 :         :   ViewContactOfE3d(rPolygon)
      37                 :            :         {
      38                 :        438 :         }
      39                 :            : 
      40                 :        438 :         ViewContactOfE3dPolygon::~ViewContactOfE3dPolygon()
      41                 :            :         {
      42         [ -  + ]:        876 :         }
      43                 :            : 
      44                 :      10134 :         drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dPolygon::createViewIndependentPrimitive3DSequence() const
      45                 :            :         {
      46         [ +  - ]:      10134 :             drawinglayer::primitive3d::Primitive3DSequence xRetval;
      47         [ +  - ]:      10134 :             const SfxItemSet& rItemSet = GetE3dPolygonObj().GetMergedItemSet();
      48                 :      10134 :             const bool bSuppressFill(GetE3dPolygonObj().GetLineOnly());
      49                 :            :             const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
      50         [ +  - ]:      10134 :                 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, bSuppressFill));
      51                 :            : 
      52                 :            :             // get extrude geometry
      53         [ +  - ]:      10134 :             basegfx::B3DPolyPolygon aPolyPolygon3D(GetE3dPolygonObj().GetPolyPolygon3D());
      54         [ +  - ]:      10134 :             const basegfx::B3DPolyPolygon aPolyNormals3D(GetE3dPolygonObj().GetPolyNormals3D());
      55         [ +  - ]:      10134 :             const basegfx::B2DPolyPolygon aPolyTexture2D(GetE3dPolygonObj().GetPolyTexture2D());
      56 [ +  - ][ +  + ]:      10134 :             const bool bNormals(aPolyNormals3D.count() && aPolyNormals3D.count() == aPolyPolygon3D.count());
         [ +  - ][ +  - ]
                 [ +  - ]
      57 [ +  - ][ +  + ]:      10134 :             const bool bTexture(aPolyTexture2D.count() && aPolyTexture2D.count() == aPolyPolygon3D.count());
         [ +  - ][ +  - ]
                 [ +  - ]
      58                 :            : 
      59 [ +  + ][ -  + ]:      10134 :             if(bNormals || bTexture)
      60                 :            :             {
      61 [ +  - ][ +  + ]:      18538 :                 for(sal_uInt32 a(0L); a < aPolyPolygon3D.count(); a++)
      62                 :            :                 {
      63         [ +  - ]:       9269 :                     basegfx::B3DPolygon aCandidate3D(aPolyPolygon3D.getB3DPolygon(a));
      64         [ +  - ]:       9269 :                     basegfx::B3DPolygon aNormals3D;
      65         [ +  - ]:       9269 :                     basegfx::B2DPolygon aTexture2D;
      66                 :            : 
      67         [ +  - ]:       9269 :                     if(bNormals)
      68                 :            :                     {
      69 [ +  - ][ +  - ]:       9269 :                         aNormals3D = aPolyNormals3D.getB3DPolygon(a);
                 [ +  - ]
      70                 :            :                     }
      71                 :            : 
      72         [ +  - ]:       9269 :                     if(bTexture)
      73                 :            :                     {
      74 [ +  - ][ +  - ]:       9269 :                         aTexture2D = aPolyTexture2D.getB2DPolygon(a);
                 [ +  - ]
      75                 :            :                     }
      76                 :            : 
      77 [ +  - ][ +  + ]:      46345 :                     for(sal_uInt32 b(0L); b < aCandidate3D.count(); b++)
      78                 :            :                     {
      79         [ +  - ]:      37076 :                         if(bNormals)
      80                 :            :                         {
      81         [ +  - ]:      37076 :                             sal_uInt32 nNormalCount = aNormals3D.count();
      82         [ +  - ]:      37076 :                             if( b < nNormalCount )
      83 [ +  - ][ +  - ]:      37076 :                                 aCandidate3D.setNormal(b, aNormals3D.getB3DPoint(b));
      84         [ #  # ]:          0 :                             else if( nNormalCount > 0 )
      85 [ #  # ][ #  # ]:          0 :                                 aCandidate3D.setNormal(b, aNormals3D.getB3DPoint(0));
      86                 :            :                         }
      87         [ +  - ]:      37076 :                         if(bTexture)
      88                 :            :                         {
      89         [ +  - ]:      37076 :                             sal_uInt32 nTextureCount = aTexture2D.count();
      90         [ +  - ]:      37076 :                             if( b < nTextureCount )
      91 [ +  - ][ +  - ]:      37076 :                                 aCandidate3D.setTextureCoordinate(b, aTexture2D.getB2DPoint(b));
      92         [ #  # ]:          0 :                             else if( nTextureCount > 0 )
      93 [ #  # ][ #  # ]:          0 :                                 aCandidate3D.setTextureCoordinate(b, aTexture2D.getB2DPoint(0));
      94                 :            :                         }
      95                 :            :                     }
      96                 :            : 
      97         [ +  - ]:       9269 :                     aPolyPolygon3D.setB3DPolygon(a, aCandidate3D);
      98 [ +  - ][ +  - ]:       9269 :                 }
                 [ +  - ]
      99                 :            :             }
     100                 :            : 
     101                 :            :             // get 3D Object Attributes
     102         [ +  - ]:      10134 :             drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
     103                 :            : 
     104                 :            :             // calculate texture size
     105                 :      10134 :             basegfx::B2DVector aTextureSize(1.0, 1.0);
     106                 :            : 
     107         [ +  + ]:      10134 :             if(bTexture)
     108                 :            :             {
     109                 :            :                 // #i98314#
     110                 :            :                 // create texture size from object's size
     111         [ +  - ]:       9269 :                 const basegfx::B3DRange aObjectRange(basegfx::tools::getRange(aPolyPolygon3D));
     112                 :            : 
     113                 :       9269 :                 double fWidth(0.0);
     114                 :       9269 :                 double fHeight(0.0);
     115                 :            : 
     116                 :            :                 // this is a polygon object, so Width/Height and/or Depth may be zero (e.g. left
     117                 :            :                 // wall of chart). Take this into account
     118 [ +  - ][ +  + ]:       9269 :                 if(basegfx::fTools::equalZero(aObjectRange.getWidth()))
     119                 :            :                 {
     120                 :            :                     // width is zero, use height and depth
     121         [ +  - ]:        647 :                     fWidth = aObjectRange.getHeight();
     122         [ +  - ]:        647 :                     fHeight = aObjectRange.getDepth();
     123                 :            :                 }
     124 [ +  - ][ +  + ]:       8622 :                 else if(basegfx::fTools::equalZero(aObjectRange.getHeight()))
     125                 :            :                 {
     126                 :            :                     // height is zero, use width and depth
     127         [ +  - ]:        591 :                     fWidth = aObjectRange.getWidth();
     128         [ +  - ]:        591 :                     fHeight = aObjectRange.getDepth();
     129                 :            :                 }
     130                 :            :                 else
     131                 :            :                 {
     132                 :            :                     // use width and height
     133         [ +  - ]:       8031 :                     fWidth = aObjectRange.getWidth();
     134         [ +  - ]:       8031 :                     fHeight = aObjectRange.getHeight();
     135                 :            :                 }
     136                 :            : 
     137 [ +  - ][ -  + ]:       9269 :                 if(basegfx::fTools::lessOrEqual(fWidth, 0.0) ||basegfx::fTools::lessOrEqual(fHeight, 0.0))
         [ +  - ][ +  - ]
                 [ -  + ]
     138                 :            :                 {
     139                 :            :                     // no texture; fallback to very small size
     140                 :          0 :                     aTextureSize.setX(0.01);
     141                 :          0 :                     aTextureSize.setY(0.01);
     142                 :            :                 }
     143                 :            :                 else
     144                 :            :                 {
     145                 :       9269 :                     aTextureSize.setX(fWidth);
     146                 :       9269 :                     aTextureSize.setY(fHeight);
     147                 :            :                 }
     148                 :            :             }
     149                 :            : 
     150                 :            :             // #i98295#
     151                 :            :             // unfortunately, this SdrObject type which allows a free 3d geometry definition was defined
     152                 :            :             // wrong topologically in relation to it's plane normal and 3D visibility when it was invented
     153                 :            :             // a long time ago. Since the API allows creation of this SDrObject type, it is not possible to
     154                 :            :             // simply change this definition. Only the chart should use it, and at least this object type
     155                 :            :             // only exists at Runtime (is not saved and/or loaded in any FileFormat). Still someone external
     156                 :            :             // may have used it in it's API. To not risk wrong 3D lightings, i have to switch the orientation
     157                 :            :             // of the polygon here
     158         [ +  - ]:      10134 :             aPolyPolygon3D.flip();
     159                 :            : 
     160                 :            :             // create primitive and add
     161         [ +  - ]:      10134 :             const basegfx::B3DHomMatrix aWorldTransform;
     162                 :            :             const drawinglayer::primitive3d::Primitive3DReference xReference(
     163                 :            :                 new drawinglayer::primitive3d::SdrPolyPolygonPrimitive3D(
     164 [ +  - ][ +  - ]:      10134 :                     aPolyPolygon3D, aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute));
                 [ +  - ]
     165 [ +  - ][ +  - ]:      10134 :             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
                 [ +  - ]
     166                 :            : 
     167                 :            :             // delete 3D Object Attributes
     168 [ +  - ][ +  - ]:      10134 :             delete pSdr3DObjectAttribute;
     169                 :            : 
     170 [ +  - ][ +  - ]:      10134 :             return xRetval;
         [ +  - ][ +  - ]
                 [ +  - ]
     171                 :            :         }
     172                 :            :     } // end of namespace contact
     173                 :            : } // end of namespace sdr
     174                 :            : 
     175                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10