LCOV - code coverage report
Current view: top level - svx/source/engine3d - polygn3d.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 30 92 32.6 %
Date: 2014-04-11 Functions: 12 19 63.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10