LibreOffice Module svx (master)  1
sdrhittesthelper.cxx
Go to the documentation of this file.
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/svdpage.hxx>
25 #include <svx/sdrpagewindow.hxx>
30 #include <svx/svdpagv.hxx>
32 #include <svx/svdmodel.hxx>
33 
34 
35 // #i101872# new Object HitTest as View-tooling
36 
38  const SdrObject& rObject,
39  const Point& rPnt,
40  sal_uInt16 nTol,
41  const SdrPageView& rSdrPageView,
42  const SdrLayerIDSet* pVisiLayer,
43  bool bTextOnly,
45 {
46  SdrObject* pResult = nullptr;
47 
48  if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
49  {
50  // group or scene with content. Single 3D objects also have a
51  // true == rObject.GetSubList(), but no content
52  pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
53  }
54  else
55  {
56  if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
57  {
58  // single object, 3d object, empty scene or empty group. Check if
59  // it's a single 3D object
60  const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
61 
62  if(pE3dCompoundObject)
63  {
64  const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
65 
66  if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
67  {
68  pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
69  }
70  }
71  else
72  {
73  // not a single 3D object; Check in first PageWindow using primitives (only SC
74  // with split views uses multiple PageWindows nowadays)
75  if(rSdrPageView.PageWindowCount())
76  {
77  const double fLogicTolerance(nTol);
78  const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
80  rSdrPageView.GetPageWindow(0)->GetObjectContact());
81 
82  if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly, pHitContainer))
83  {
84  pResult = const_cast< SdrObject* >(&rObject);
85  }
86  }
87  }
88  }
89  }
90 
91  return pResult;
92 }
93 
94 
96  const SdrObjList& rList,
97  const Point& rPnt,
98  sal_uInt16 nTol,
99  const SdrPageView& rSdrPageView,
100  const SdrLayerIDSet* pVisiLayer,
101  bool bTextOnly)
102 {
103  size_t nObjNum(rList.GetObjCount());
104  SdrObject* pRetval = nullptr;
105 
106  while(!pRetval && nObjNum > 0)
107  {
108  nObjNum--;
109  SdrObject* pObj = rList.GetObj(nObjNum);
110 
111  pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
112  }
113 
114  return pRetval;
115 }
116 
117 
120  const basegfx::B2DPoint& rHitPosition,
121  double fLogicHitTolerance,
122  bool bTextOnly,
124 {
125  basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
126 
127  if(!aObjectRange.isEmpty())
128  {
129  // first do a rough B2DRange based HitTest; do not forget to
130  // include the HitTolerance if given
131  if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
132  {
133  aObjectRange.grow(fLogicHitTolerance);
134  }
135 
136  if(aObjectRange.isInside(rHitPosition))
137  {
138  // get primitive sequence
139  sdr::contact::DisplayInfo aDisplayInfo;
140  const drawinglayer::primitive2d::Primitive2DContainer& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
141 
142  if(!rSequence.empty())
143  {
144  // create a HitTest processor
147  rViewInformation2D,
148  rHitPosition,
149  fLogicHitTolerance,
150  bTextOnly);
151 
152  // ask for HitStack
153  aHitTestProcessor2D.collectHitStack(true);
154 
155  // feed it with the primitives
156  aHitTestProcessor2D.process(rSequence);
157 
158  // deliver result
159  if (aHitTestProcessor2D.getHit())
160  {
161  if (pHitContainer)
162  {
163  // fetch HitStack primitives if requested
164  *pHitContainer = aHitTestProcessor2D.getHitStack();
165  }
166 
167  return true;
168  }
169  }
170  }
171  }
172 
173  return false;
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool more(const double &rfValA, const double &rfValB)
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:773
size_t GetObjCount() const
Definition: svdpage.cxx:767
ViewObjectContact & GetViewObjectContact(ObjectContact &rObjectContact)
Definition: viewcontact.cxx:73
const primitive2d::Primitive2DContainer & getHitStack() const
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:674
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:271
drawinglayer::primitive2d::Primitive2DContainer const & getPrimitive2DSequence(const DisplayInfo &rDisplayInfo) const
bool IsVisible() const
Definition: svdobj.hxx:804
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
Definition: svdpagv.cxx:93
SdrObject * SdrObjectPrimitiveHit(const SdrObject &rObject, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)
void grow(double fValue)
SdrObject * SdrObjListPrimitiveHit(const SdrObjList &rList, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly)
ObjectContact & GetObjectContact() const
const drawinglayer::geometry::ViewInformation2D & getViewInformation2D() const
void process(const primitive2d::Primitive2DContainer &rSource)
const sdr::contact::ObjectContact & GetObjectContact() const
Abstract DrawObject.
Definition: svdobj.hxx:312
long X() const
bool checkHitSingle3DObject(const basegfx::B2DPoint &rPoint, const E3dCompoundObject &rCandidate)
support for checking if the single given 3d object is hit at position
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:604
bool IsSet(SdrLayerID a) const
Definition: svdsob.hxx:66
bool ViewObjectContactPrimitiveHit(const sdr::contact::ViewObjectContact &rVOC, const basegfx::B2DPoint &rHitPosition, double fLogicHitTolerance, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)
const basegfx::B2DRange & getObjectRange() const
long Y() const
sal_uInt32 PageWindowCount() const
Definition: svdpagv.hxx:96