LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - helplineprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 88 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
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/primitive2d/helplineprimitive2d.hxx>
      21             : #include <basegfx/polygon/b2dpolygon.hxx>
      22             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      23             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      24             : #include <basegfx/tools/canvastools.hxx>
      25             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      26             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      27             : 
      28             : 
      29             : 
      30             : using namespace com::sun::star;
      31             : 
      32             : 
      33             : 
      34             : namespace drawinglayer
      35             : {
      36             :     namespace primitive2d
      37             :     {
      38           0 :         Primitive2DSequence HelplinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      39             :         {
      40           0 :             std::vector< BasePrimitive2D* > aTempPrimitiveTarget;
      41             : 
      42           0 :             if(!rViewInformation.getViewport().isEmpty() && !getDirection().equalZero())
      43             :             {
      44             :                 // position to view coordinates, DashLen and DashLen in logic
      45           0 :                 const basegfx::B2DPoint aViewPosition(rViewInformation.getObjectToViewTransformation() * getPosition());
      46             : 
      47           0 :                 switch(getStyle())
      48             :                 {
      49             :                     default : // HELPLINESTYLE2D_POINT
      50             :                     {
      51           0 :                         const double fViewFixValue(15.0);
      52           0 :                         basegfx::B2DVector aNormalizedDirection(getDirection());
      53           0 :                         aNormalizedDirection.normalize();
      54           0 :                         aNormalizedDirection *= fViewFixValue;
      55           0 :                         const basegfx::B2DPoint aStartA(aViewPosition - aNormalizedDirection);
      56           0 :                         const basegfx::B2DPoint aEndA(aViewPosition + aNormalizedDirection);
      57           0 :                         basegfx::B2DPolygon aLineA;
      58           0 :                         aLineA.append(aStartA);
      59           0 :                         aLineA.append(aEndA);
      60           0 :                         aLineA.transform(rViewInformation.getInverseObjectToViewTransformation());
      61           0 :                         PolygonMarkerPrimitive2D* pNewA = new PolygonMarkerPrimitive2D(aLineA, getRGBColA(), getRGBColB(), getDiscreteDashLength());
      62           0 :                         aTempPrimitiveTarget.push_back(pNewA);
      63             : 
      64           0 :                         const basegfx::B2DVector aPerpendicularNormalizedDirection(basegfx::getPerpendicular(aNormalizedDirection));
      65           0 :                         const basegfx::B2DPoint aStartB(aViewPosition - aPerpendicularNormalizedDirection);
      66           0 :                         const basegfx::B2DPoint aEndB(aViewPosition + aPerpendicularNormalizedDirection);
      67           0 :                         basegfx::B2DPolygon aLineB;
      68           0 :                         aLineB.append(aStartB);
      69           0 :                         aLineB.append(aEndB);
      70           0 :                         aLineB.transform(rViewInformation.getInverseObjectToViewTransformation());
      71           0 :                         PolygonMarkerPrimitive2D* pNewB = new PolygonMarkerPrimitive2D(aLineB, getRGBColA(), getRGBColB(), getDiscreteDashLength());
      72           0 :                         aTempPrimitiveTarget.push_back(pNewB);
      73             : 
      74           0 :                         break;
      75             :                     }
      76             :                     case HELPLINESTYLE2D_LINE :
      77             :                     {
      78           0 :                         basegfx::B2DPolygon aLine;
      79             : 
      80           0 :                         if(basegfx::areParallel(getDirection(), basegfx::B2DVector(1.0, 0.0)))
      81             :                         {
      82             :                             // parallel to X-Axis, get cuts with Y-Axes
      83           0 :                             const double fCutA((rViewInformation.getDiscreteViewport().getMinX() - aViewPosition.getX()) / getDirection().getX());
      84           0 :                             const double fCutB((rViewInformation.getDiscreteViewport().getMaxX() - aViewPosition.getX()) / getDirection().getX());
      85           0 :                             const basegfx::B2DPoint aPosA(aViewPosition + (fCutA * getDirection()));
      86           0 :                             const basegfx::B2DPoint aPosB(aViewPosition + (fCutB * getDirection()));
      87           0 :                             const bool bBothLeft(aPosA.getX() < rViewInformation.getDiscreteViewport().getMinX() && aPosB.getX() < rViewInformation.getDiscreteViewport().getMinX());
      88           0 :                             const bool bBothRight(aPosA.getX() > rViewInformation.getDiscreteViewport().getMaxX() && aPosB.getX() < rViewInformation.getDiscreteViewport().getMaxX());
      89             : 
      90           0 :                             if(!bBothLeft && !bBothRight)
      91             :                             {
      92           0 :                                 aLine.append(aPosA);
      93           0 :                                 aLine.append(aPosB);
      94           0 :                             }
      95             :                         }
      96             :                         else
      97             :                         {
      98             :                             // get cuts with X-Axes
      99           0 :                             const double fCutA((rViewInformation.getDiscreteViewport().getMinY() - aViewPosition.getY()) / getDirection().getY());
     100           0 :                             const double fCutB((rViewInformation.getDiscreteViewport().getMaxY() - aViewPosition.getY()) / getDirection().getY());
     101           0 :                             const basegfx::B2DPoint aPosA(aViewPosition + (fCutA * getDirection()));
     102           0 :                             const basegfx::B2DPoint aPosB(aViewPosition + (fCutB * getDirection()));
     103           0 :                             const bool bBothAbove(aPosA.getY() < rViewInformation.getDiscreteViewport().getMinY() && aPosB.getY() < rViewInformation.getDiscreteViewport().getMinY());
     104           0 :                             const bool bBothBelow(aPosA.getY() > rViewInformation.getDiscreteViewport().getMaxY() && aPosB.getY() < rViewInformation.getDiscreteViewport().getMaxY());
     105             : 
     106           0 :                             if(!bBothAbove && !bBothBelow)
     107             :                             {
     108           0 :                                 aLine.append(aPosA);
     109           0 :                                 aLine.append(aPosB);
     110           0 :                             }
     111             :                         }
     112             : 
     113           0 :                         if(aLine.count())
     114             :                         {
     115             :                             // clip against visible area
     116           0 :                             const basegfx::B2DPolyPolygon aResult(basegfx::tools::clipPolygonOnRange(aLine, rViewInformation.getDiscreteViewport(), true, true));
     117             : 
     118           0 :                             for(sal_uInt32 a(0L); a < aResult.count(); a++)
     119             :                             {
     120           0 :                                 basegfx::B2DPolygon aPart(aResult.getB2DPolygon(a));
     121           0 :                                 aPart.transform(rViewInformation.getInverseObjectToViewTransformation());
     122           0 :                                 PolygonMarkerPrimitive2D* pNew = new PolygonMarkerPrimitive2D(aPart, getRGBColA(), getRGBColB(), getDiscreteDashLength());
     123           0 :                                 aTempPrimitiveTarget.push_back(pNew);
     124           0 :                             }
     125             :                         }
     126             : 
     127           0 :                         break;
     128             :                     }
     129           0 :                 }
     130             :             }
     131             : 
     132             :             // prepare return value
     133           0 :             Primitive2DSequence aRetval(aTempPrimitiveTarget.size());
     134             : 
     135           0 :             for(sal_uInt32 a(0L); a < aTempPrimitiveTarget.size(); a++)
     136             :             {
     137           0 :                 const Primitive2DReference xRef(aTempPrimitiveTarget[a]);
     138           0 :                 aRetval[a] = xRef;
     139           0 :             }
     140             : 
     141           0 :             return aRetval;
     142             :         }
     143             : 
     144           0 :         HelplinePrimitive2D::HelplinePrimitive2D(
     145             :             const basegfx::B2DPoint& rPosition,
     146             :             const basegfx::B2DVector& rDirection,
     147             :             HelplineStyle2D eStyle,
     148             :             const basegfx::BColor& rRGBColA,
     149             :             const basegfx::BColor& rRGBColB,
     150             :             double fDiscreteDashLength)
     151             :         :   BufferedDecompositionPrimitive2D(),
     152             :             maPosition(rPosition),
     153             :             maDirection(rDirection),
     154             :             meStyle(eStyle),
     155             :             maRGBColA(rRGBColA),
     156             :             maRGBColB(rRGBColB),
     157             :             mfDiscreteDashLength(fDiscreteDashLength),
     158             :             maLastObjectToViewTransformation(),
     159           0 :             maLastViewport()
     160             :         {
     161           0 :         }
     162             : 
     163           0 :         bool HelplinePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     164             :         {
     165           0 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     166             :             {
     167           0 :                 const HelplinePrimitive2D& rCompare = (HelplinePrimitive2D&)rPrimitive;
     168             : 
     169           0 :                 return (getPosition() == rCompare.getPosition()
     170           0 :                     && getDirection() == rCompare.getDirection()
     171           0 :                     && getStyle() == rCompare.getStyle()
     172           0 :                     && getRGBColA() == rCompare.getRGBColA()
     173           0 :                     && getRGBColB() == rCompare.getRGBColB()
     174           0 :                     && getDiscreteDashLength() == rCompare.getDiscreteDashLength());
     175             :             }
     176             : 
     177           0 :             return false;
     178             :         }
     179             : 
     180           0 :         Primitive2DSequence HelplinePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
     181             :         {
     182           0 :             ::osl::MutexGuard aGuard( m_aMutex );
     183             : 
     184           0 :             if(getBuffered2DDecomposition().hasElements())
     185             :             {
     186           0 :                 if(maLastViewport != rViewInformation.getViewport() || maLastObjectToViewTransformation != rViewInformation.getObjectToViewTransformation())
     187             :                 {
     188             :                     // conditions of last local decomposition have changed, delete
     189           0 :                     const_cast< HelplinePrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DSequence());
     190             :                 }
     191             :             }
     192             : 
     193           0 :             if(!getBuffered2DDecomposition().hasElements())
     194             :             {
     195             :                 // remember ViewRange and ViewTransformation
     196           0 :                 const_cast< HelplinePrimitive2D* >(this)->maLastObjectToViewTransformation = rViewInformation.getObjectToViewTransformation();
     197           0 :                 const_cast< HelplinePrimitive2D* >(this)->maLastViewport = rViewInformation.getViewport();
     198             :             }
     199             : 
     200             :             // use parent implementation
     201           0 :             return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
     202             :         }
     203             : 
     204             :         // provide unique ID
     205           0 :         ImplPrimitive2DIDBlock(HelplinePrimitive2D, PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D)
     206             : 
     207             :     } // end of namespace primitive2d
     208             : } // end of namespace drawinglayer
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10