LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive3d - baseprimitive3d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 92 78.3 %
Date: 2015-06-13 12:38:46 Functions: 11 17 64.7 %
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 <drawinglayer/primitive3d/baseprimitive3d.hxx>
      21             : #include <drawinglayer/geometry/viewinformation3d.hxx>
      22             : #include <basegfx/tools/canvastools.hxx>
      23             : 
      24             : 
      25             : 
      26             : using namespace com::sun::star;
      27             : 
      28             : 
      29             : 
      30             : namespace drawinglayer
      31             : {
      32             :     namespace primitive3d
      33             :     {
      34       60252 :         BasePrimitive3D::BasePrimitive3D()
      35       60252 :         :   BasePrimitive3DImplBase(m_aMutex)
      36             :         {
      37       60252 :         }
      38             : 
      39       60252 :         BasePrimitive3D::~BasePrimitive3D()
      40             :         {
      41       60252 :         }
      42             : 
      43        6421 :         bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
      44             :         {
      45        6421 :             return (getPrimitive3DID() == rPrimitive.getPrimitive3DID());
      46             :         }
      47             : 
      48           0 :         basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const
      49             :         {
      50           0 :             return getB3DRangeFromPrimitive3DSequence(get3DDecomposition(rViewInformation), rViewInformation);
      51             :         }
      52             : 
      53           0 :         Primitive3DSequence BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
      54             :         {
      55           0 :             return Primitive3DSequence();
      56             :         }
      57             : 
      58           0 :         Primitive3DSequence SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      59             :         {
      60           0 :             const geometry::ViewInformation3D aViewInformation(rViewParameters);
      61           0 :             return get3DDecomposition(aViewInformation);
      62             :         }
      63             : 
      64           0 :         com::sun::star::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      65             :         {
      66           0 :             const geometry::ViewInformation3D aViewInformation(rViewParameters);
      67           0 :             return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation));
      68             :         }
      69             :     } // end of namespace primitive3d
      70             : } // end of namespace drawinglayer
      71             : 
      72             : 
      73             : 
      74             : namespace drawinglayer
      75             : {
      76             :     namespace primitive3d
      77             :     {
      78           0 :         Primitive3DSequence BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
      79             :         {
      80           0 :             return Primitive3DSequence();
      81             :         }
      82             : 
      83       10352 :         BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
      84             :         :   BasePrimitive3D(),
      85       10352 :             maBuffered3DDecomposition()
      86             :         {
      87       10352 :         }
      88             : 
      89        1648 :         Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
      90             :         {
      91        1648 :             ::osl::MutexGuard aGuard( m_aMutex );
      92             : 
      93        1648 :             if(!getBuffered3DDecomposition().hasElements())
      94             :             {
      95        1229 :                 const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
      96        1229 :                 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
      97             :             }
      98             : 
      99        1648 :             return getBuffered3DDecomposition();
     100             :         }
     101             :     } // end of namespace primitive3d
     102             : } // end of namespace drawinglayer
     103             : 
     104             : 
     105             : // tooling
     106             : 
     107             : namespace drawinglayer
     108             : {
     109             :     namespace primitive3d
     110             :     {
     111             :         // get range3D from a given Primitive3DReference
     112       19489 :         basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
     113             :         {
     114       19489 :             basegfx::B3DRange aRetval;
     115             : 
     116       19489 :             if(rCandidate.is())
     117             :             {
     118             :                 // try to get C++ implementation base
     119       19489 :                 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
     120             : 
     121       19489 :                 if(pCandidate)
     122             :                 {
     123             :                     // use it if possible
     124       19489 :                     aRetval.expand(pCandidate->getB3DRange(aViewInformation));
     125             :                 }
     126             :                 else
     127             :                 {
     128             :                     // use UNO API call instead
     129           0 :                     const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
     130           0 :                     aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters)));
     131             :                 }
     132             :             }
     133             : 
     134       19489 :             return aRetval;
     135             :         }
     136             : 
     137             :         // get range3D from a given Primitive3DSequence
     138       14864 :         basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
     139             :         {
     140       14864 :             basegfx::B3DRange aRetval;
     141             : 
     142       14864 :             if(rCandidate.hasElements())
     143             :             {
     144       14425 :                 const sal_Int32 nCount(rCandidate.getLength());
     145             : 
     146       33914 :                 for(sal_Int32 a(0L); a < nCount; a++)
     147             :                 {
     148       19489 :                     aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
     149             :                 }
     150             :             }
     151             : 
     152       14864 :             return aRetval;
     153             :         }
     154             : 
     155        6421 :         bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
     156             :         {
     157        6421 :             const bool bAIs(rxA.is());
     158             : 
     159        6421 :             if(bAIs != rxB.is())
     160             :             {
     161           0 :                 return false;
     162             :             }
     163             : 
     164        6421 :             if(!bAIs)
     165             :             {
     166           0 :                 return true;
     167             :             }
     168             : 
     169        6421 :             const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
     170        6421 :             const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
     171        6421 :             const bool bAEqualZero(pA == 0L);
     172             : 
     173        6421 :             if(bAEqualZero != (pB == 0L))
     174             :             {
     175           0 :                 return false;
     176             :             }
     177             : 
     178        6421 :             if(bAEqualZero)
     179             :             {
     180           0 :                 return false;
     181             :             }
     182             : 
     183        6421 :             return (pA->operator==(*pB));
     184             :         }
     185             : 
     186        9987 :         bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
     187             :         {
     188        9987 :             const bool bAHasElements(rA.hasElements());
     189             : 
     190        9987 :             if(bAHasElements != rB.hasElements())
     191             :             {
     192        4644 :                 return false;
     193             :             }
     194             : 
     195        5343 :             if(!bAHasElements)
     196             :             {
     197          58 :                 return true;
     198             :             }
     199             : 
     200        5285 :             const sal_Int32 nCount(rA.getLength());
     201             : 
     202        5285 :             if(nCount != rB.getLength())
     203             :             {
     204           0 :                 return false;
     205             :             }
     206             : 
     207       11417 :             for(sal_Int32 a(0L); a < nCount; a++)
     208             :             {
     209        6421 :                 if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
     210             :                 {
     211         289 :                     return false;
     212             :                 }
     213             :             }
     214             : 
     215        4996 :             return true;
     216             :         }
     217             : 
     218             :         // concatenate sequence
     219        5741 :         void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
     220             :         {
     221        5741 :             if(rSource.hasElements())
     222             :             {
     223        5741 :                 if(rDest.hasElements())
     224             :                 {
     225        3711 :                     const sal_Int32 nSourceCount(rSource.getLength());
     226        3711 :                     const sal_Int32 nDestCount(rDest.getLength());
     227        3711 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     228        3711 :                     sal_Int32 nInsertPos(nDestCount);
     229             : 
     230        3711 :                     rDest.realloc(nTargetCount);
     231             : 
     232        7976 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     233             :                     {
     234        4265 :                         if(rSource[a].is())
     235             :                         {
     236        4265 :                             rDest[nInsertPos++] = rSource[a];
     237             :                         }
     238             :                     }
     239             : 
     240        3711 :                     if(nInsertPos != nTargetCount)
     241             :                     {
     242           0 :                         rDest.realloc(nInsertPos);
     243             :                     }
     244             :                 }
     245             :                 else
     246             :                 {
     247        2030 :                     rDest = rSource;
     248             :                 }
     249             :             }
     250        5741 :         }
     251             : 
     252             :         // concatenate single Primitive3D
     253        4664 :         void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
     254             :         {
     255        4664 :             if(rSource.is())
     256             :             {
     257        4664 :                 const sal_Int32 nDestCount(rDest.getLength());
     258        4664 :                 rDest.realloc(nDestCount + 1L);
     259        4664 :                 rDest[nDestCount] = rSource;
     260             :             }
     261        4664 :         }
     262             : 
     263             :     } // end of namespace primitive3d
     264             : } // end of namespace drawinglayer
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11