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
22#include <svx/obj3d.hxx>
24#include <svx/svdpage.hxx>
25#include <svx/sdrpagewindow.hxx>
30#include <svx/svdpagv.hxx>
32
33
34// #i101872# new Object HitTest as View-tooling
35
37 const SdrObject& rObject,
38 const Point& rPnt,
39 sal_uInt16 nTol,
40 const SdrPageView& rSdrPageView,
41 const SdrLayerIDSet* pVisiLayer,
42 bool bTextOnly,
44{
45 SdrObject* pResult = nullptr;
46
47 if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
48 {
49 // group or scene with content. Single 3D objects also have a
50 // true == rObject.GetSubList(), but no content
51 pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
52 }
53 else
54 {
55 if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
56 {
57 // single object, 3d object, empty scene or empty group. Check if
58 // it's a single 3D object
59 const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
60
61 if(pE3dCompoundObject)
62 {
63 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
64
65 if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
66 {
67 pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
68 }
69 }
70 else
71 {
72 // not a single 3D object; Check in first PageWindow using primitives (only SC
73 // with split views uses multiple PageWindows nowadays)
74 if(rSdrPageView.PageWindowCount())
75 {
76 const double fLogicTolerance(nTol);
77 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
79 rSdrPageView.GetPageWindow(0)->GetObjectContact());
80
81 if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly, pHitContainer))
82 {
83 pResult = const_cast< SdrObject* >(&rObject);
84 }
85 }
86 }
87 }
88 }
89
90 return pResult;
91}
92
93
95 const SdrObjList& rList,
96 const Point& rPnt,
97 sal_uInt16 nTol,
98 const SdrPageView& rSdrPageView,
99 const SdrLayerIDSet* pVisiLayer,
100 bool bTextOnly)
101{
102 size_t nObjNum(rList.GetObjCount());
103 SdrObject* pRetval = nullptr;
104
105 while(!pRetval && nObjNum > 0)
106 {
107 nObjNum--;
108 SdrObject* pObj = rList.GetObj(nObjNum);
109
110 pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
111 }
112
113 return pRetval;
114}
115
116
119 const basegfx::B2DPoint& rHitPosition,
120 double fLogicHitTolerance,
121 bool bTextOnly,
123{
124 basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
125
126 if(!aObjectRange.isEmpty())
127 {
128 // first do a rough B2DRange based HitTest; do not forget to
129 // include the HitTolerance if given
130 if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
131 {
132 aObjectRange.grow(fLogicHitTolerance);
133 }
134
135 if(aObjectRange.isInside(rHitPosition))
136 {
137 // get primitive sequence
138 sdr::contact::DisplayInfo aDisplayInfo;
139 // have to make a copy of this container here, because it might be changed underneath us
141
142 if(!aSequence.empty())
143 {
144 // create a HitTest processor
147 rViewInformation2D,
148 rHitPosition,
149 fLogicHitTolerance,
150 bTextOnly);
151
152 // ask for HitStack
153 aHitTestProcessor2D.collectHitStack(pHitContainer != nullptr);
154
155 // feed it with the primitives
156 aHitTestProcessor2D.process(aSequence);
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: */
bool IsSet(SdrLayerID a) const
Definition: svdsob.hxx:69
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:784
size_t GetObjCount() const
Definition: svdpage.cxx:778
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:717
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:261
bool IsVisible() const
Definition: svdobj.hxx:760
virtual SdrLayerID GetLayer() const
Definition: svdobj.cxx:645
sal_uInt32 PageWindowCount() const
Definition: svdpagv.hxx:89
SdrPageWindow * GetPageWindow(sal_uInt32 nIndex) const
Definition: svdpagv.cxx:83
const sdr::contact::ObjectContact & GetObjectContact() const
void grow(TYPE fValue)
bool isInside(const Tuple2D< TYPE > &rTuple) const
bool isEmpty() const
void process(const primitive2d::Primitive2DContainer &rSource)
const primitive2d::Primitive2DContainer & getHitStack() const
const drawinglayer::geometry::ViewInformation2D & getViewInformation2D() const
ViewObjectContact & GetViewObjectContact(ObjectContact &rObjectContact)
Definition: viewcontact.cxx:65
drawinglayer::primitive2d::Primitive2DContainer const & getPrimitive2DSequence(const DisplayInfo &rDisplayInfo) const
ObjectContact & GetObjectContact() const
const basegfx::B2DRange & getObjectRange() const
bool checkHitSingle3DObject(const basegfx::B2DPoint &rPoint, const E3dCompoundObject &rCandidate)
support for checking if the single given 3d object is hit at position
bool more(const T &rfValA, const T &rfValB)
bool ViewObjectContactPrimitiveHit(const sdr::contact::ViewObjectContact &rVOC, const basegfx::B2DPoint &rHitPosition, double fLogicHitTolerance, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)
SdrObject * SdrObjListPrimitiveHit(const SdrObjList &rList, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly)
SdrObject * SdrObjectPrimitiveHit(const SdrObject &rObject, const Point &rPnt, sal_uInt16 nTol, const SdrPageView &rSdrPageView, const SdrLayerIDSet *pVisiLayer, bool bTextOnly, drawinglayer::primitive2d::Primitive2DContainer *pHitContainer)