LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive3d - baseprimitive3d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 72 92 78.3 %
Date: 2014-11-03 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       93268 :         BasePrimitive3D::BasePrimitive3D()
      35       93268 :         :   BasePrimitive3DImplBase(m_aMutex)
      36             :         {
      37       93268 :         }
      38             : 
      39       93268 :         BasePrimitive3D::~BasePrimitive3D()
      40             :         {
      41       93268 :         }
      42             : 
      43        6521 :         bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const
      44             :         {
      45        6521 :             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        8960 :         BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D()
      84             :         :   BasePrimitive3D(),
      85        8960 :             maBuffered3DDecomposition()
      86             :         {
      87        8960 :         }
      88             : 
      89        3130 :         Primitive3DSequence BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const
      90             :         {
      91        3130 :             ::osl::MutexGuard aGuard( m_aMutex );
      92             : 
      93        3130 :             if(!getBuffered3DDecomposition().hasElements())
      94             :             {
      95        2379 :                 const Primitive3DSequence aNewSequence(create3DDecomposition(rViewInformation));
      96        2379 :                 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence);
      97             :             }
      98             : 
      99        3130 :             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       15195 :         basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation)
     113             :         {
     114       15195 :             basegfx::B3DRange aRetval;
     115             : 
     116       15195 :             if(rCandidate.is())
     117             :             {
     118             :                 // try to get C++ implementation base
     119       15195 :                 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get()));
     120             : 
     121       15195 :                 if(pCandidate)
     122             :                 {
     123             :                     // use it if possible
     124       15195 :                     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       15195 :             return aRetval;
     135             :         }
     136             : 
     137             :         // get range3D from a given Primitive3DSequence
     138       11330 :         basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation)
     139             :         {
     140       11330 :             basegfx::B3DRange aRetval;
     141             : 
     142       11330 :             if(rCandidate.hasElements())
     143             :             {
     144       10951 :                 const sal_Int32 nCount(rCandidate.getLength());
     145             : 
     146       26146 :                 for(sal_Int32 a(0L); a < nCount; a++)
     147             :                 {
     148       15195 :                     aRetval.expand(getB3DRangeFromPrimitive3DReference(rCandidate[a], aViewInformation));
     149             :                 }
     150             :             }
     151             : 
     152       11330 :             return aRetval;
     153             :         }
     154             : 
     155        6521 :         bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB)
     156             :         {
     157        6521 :             const bool bAIs(rxA.is());
     158             : 
     159        6521 :             if(bAIs != rxB.is())
     160             :             {
     161           0 :                 return false;
     162             :             }
     163             : 
     164        6521 :             if(!bAIs)
     165             :             {
     166           0 :                 return true;
     167             :             }
     168             : 
     169        6521 :             const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get()));
     170        6521 :             const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get()));
     171        6521 :             const bool bAEqualZero(pA == 0L);
     172             : 
     173        6521 :             if(bAEqualZero != (pB == 0L))
     174             :             {
     175           0 :                 return false;
     176             :             }
     177             : 
     178        6521 :             if(bAEqualZero)
     179             :             {
     180           0 :                 return false;
     181             :             }
     182             : 
     183        6521 :             return (pA->operator==(*pB));
     184             :         }
     185             : 
     186        8265 :         bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB)
     187             :         {
     188        8265 :             const bool bAHasElements(rA.hasElements());
     189             : 
     190        8265 :             if(bAHasElements != rB.hasElements())
     191             :             {
     192        4000 :                 return false;
     193             :             }
     194             : 
     195        4265 :             if(!bAHasElements)
     196             :             {
     197         120 :                 return true;
     198             :             }
     199             : 
     200        4145 :             const sal_Int32 nCount(rA.getLength());
     201             : 
     202        4145 :             if(nCount != rB.getLength())
     203             :             {
     204           0 :                 return false;
     205             :             }
     206             : 
     207       10514 :             for(sal_Int32 a(0L); a < nCount; a++)
     208             :             {
     209        6521 :                 if(!arePrimitive3DReferencesEqual(rA[a], rB[a]))
     210             :                 {
     211         152 :                     return false;
     212             :                 }
     213             :             }
     214             : 
     215        3993 :             return true;
     216             :         }
     217             : 
     218             :         // concatenate sequence
     219        4563 :         void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource)
     220             :         {
     221        4563 :             if(rSource.hasElements())
     222             :             {
     223        4563 :                 if(rDest.hasElements())
     224             :                 {
     225        3231 :                     const sal_Int32 nSourceCount(rSource.getLength());
     226        3231 :                     const sal_Int32 nDestCount(rDest.getLength());
     227        3231 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     228        3231 :                     sal_Int32 nInsertPos(nDestCount);
     229             : 
     230        3231 :                     rDest.realloc(nTargetCount);
     231             : 
     232        7570 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     233             :                     {
     234        4339 :                         if(rSource[a].is())
     235             :                         {
     236        4339 :                             rDest[nInsertPos++] = rSource[a];
     237             :                         }
     238             :                     }
     239             : 
     240        3231 :                     if(nInsertPos != nTargetCount)
     241             :                     {
     242           0 :                         rDest.realloc(nInsertPos);
     243             :                     }
     244             :                 }
     245             :                 else
     246             :                 {
     247        1332 :                     rDest = rSource;
     248             :                 }
     249             :             }
     250        4563 :         }
     251             : 
     252             :         // concatenate single Primitive3D
     253        3195 :         void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource)
     254             :         {
     255        3195 :             if(rSource.is())
     256             :             {
     257        3195 :                 const sal_Int32 nDestCount(rDest.getLength());
     258        3195 :                 rDest.realloc(nDestCount + 1L);
     259        3195 :                 rDest[nDestCount] = rSource;
     260             :             }
     261        3195 :         }
     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.10