LCOV - code coverage report
Current view: top level - svx/source/svdraw - sdrhittesthelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 30 44 68.2 %
Date: 2014-11-03 Functions: 4 5 80.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             : 
      21             : #include <svx/sdrhittesthelper.hxx>
      22             : #include <svx/obj3d.hxx>
      23             : #include <svx/helperhittest3d.hxx>
      24             : #include <svx/sdrpagewindow.hxx>
      25             : #include <svx/sdr/contact/viewobjectcontact.hxx>
      26             : #include <svx/sdr/contact/displayinfo.hxx>
      27             : #include <svx/sdr/contact/objectcontact.hxx>
      28             : #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
      29             : #include <svx/svdpagv.hxx>
      30             : #include <svx/sdr/contact/viewcontact.hxx>
      31             : 
      32             : 
      33             : // #i101872# new Object HitTest as View-tooling
      34             : 
      35          98 : SdrObject* SdrObjectPrimitiveHit(
      36             :     const SdrObject& rObject,
      37             :     const Point& rPnt,
      38             :     sal_uInt16 nTol,
      39             :     const SdrPageView& rSdrPageView,
      40             :     const SetOfByte* pVisiLayer,
      41             :     bool bTextOnly)
      42             : {
      43          98 :     SdrObject* pResult = 0;
      44             : 
      45          98 :     if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
      46             :     {
      47             :         // group or scene with content. Single 3D objects also have a
      48             :         // true == rObject.GetSubList(), but no content
      49           0 :         pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
      50             :     }
      51             :     else
      52             :     {
      53          98 :         if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
      54             :         {
      55             :             // single object, 3d object, empty scene or empty group. Check if
      56             :             // it's a single 3D object
      57          98 :             const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
      58             : 
      59          98 :             if(pE3dCompoundObject)
      60             :             {
      61           0 :                 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
      62             : 
      63           0 :                 if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
      64             :                 {
      65           0 :                     pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
      66           0 :                 }
      67             :             }
      68             :             else
      69             :             {
      70             :                 // not a single 3D object; Check in first PageWindow using prmitives (only SC
      71             :                 // with split views uses multiple PageWindows nowadays)
      72          98 :                 if(rSdrPageView.PageWindowCount())
      73             :                 {
      74          98 :                     const double fLogicTolerance(nTol);
      75          98 :                     const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
      76          98 :                     const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
      77         196 :                         rSdrPageView.GetPageWindow(0)->GetObjectContact());
      78             : 
      79          98 :                     if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly))
      80             :                     {
      81          10 :                           pResult = const_cast< SdrObject* >(&rObject);
      82          98 :                     }
      83             :                 }
      84             :             }
      85             :         }
      86             :     }
      87             : 
      88          98 :     return pResult;
      89             : }
      90             : 
      91             : 
      92             : 
      93           0 : SdrObject* SdrObjListPrimitiveHit(
      94             :     const SdrObjList& rList,
      95             :     const Point& rPnt,
      96             :     sal_uInt16 nTol,
      97             :     const SdrPageView& rSdrPageView,
      98             :     const SetOfByte* pVisiLayer,
      99             :     bool bTextOnly)
     100             : {
     101           0 :     size_t nObjNum(rList.GetObjCount());
     102           0 :     SdrObject* pRetval = 0;
     103             : 
     104           0 :     while(!pRetval && nObjNum > 0)
     105             :     {
     106           0 :         nObjNum--;
     107           0 :         SdrObject* pObj = rList.GetObj(nObjNum);
     108             : 
     109           0 :         pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
     110             :     }
     111             : 
     112           0 :     return pRetval;
     113             : }
     114             : 
     115             : 
     116             : 
     117          98 : bool ViewObjectContactPrimitiveHit(
     118             :     const sdr::contact::ViewObjectContact& rVOC,
     119             :     const basegfx::B2DPoint& rHitPosition,
     120             :     double fLogicHitTolerance,
     121             :     bool bTextOnly)
     122             : {
     123          98 :     basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
     124             : 
     125          98 :     if(!aObjectRange.isEmpty())
     126             :     {
     127             :         // first do a rough B2DRange based HitTest; do not forget to
     128             :         // include the HitTolerance if given
     129          14 :         if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
     130             :         {
     131          14 :             aObjectRange.grow(fLogicHitTolerance);
     132             :         }
     133             : 
     134          14 :         if(aObjectRange.isInside(rHitPosition))
     135             :         {
     136             :             // get primitive sequence
     137          14 :             sdr::contact::DisplayInfo aDisplayInfo;
     138          14 :             const drawinglayer::primitive2d::Primitive2DSequence& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
     139             : 
     140          14 :             if(rSequence.hasElements())
     141             :             {
     142             :                 // create a HitTest processor
     143          14 :                 const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
     144             :                 drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
     145             :                     rViewInformation2D,
     146             :                     rHitPosition,
     147             :                     fLogicHitTolerance,
     148          14 :                     bTextOnly);
     149             : 
     150             :                 // feed it with the primitives
     151          14 :                 aHitTestProcessor2D.process(rSequence);
     152             : 
     153             :                 // deliver result
     154          14 :                 return aHitTestProcessor2D.getHit();
     155           0 :             }
     156             :         }
     157             :     }
     158             : 
     159          84 :     return false;
     160         651 : }
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10