1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/sdrhittesthelper.hxx>
28cdf0e10cSrcweir #include <svx/obj3d.hxx>
29cdf0e10cSrcweir #include <svx/helperhittest3d.hxx>
30cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx>
31cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontact.hxx>
32cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
33cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
34cdf0e10cSrcweir #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
35cdf0e10cSrcweir #include <svx/svdpagv.hxx>
36cdf0e10cSrcweir #include <svx/sdr/contact/viewcontact.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir // #i101872# new Object HitTest as View-tooling
40cdf0e10cSrcweir 
SdrObjectPrimitiveHit(const SdrObject & rObject,const Point & rPnt,sal_uInt16 nTol,const SdrPageView & rSdrPageView,const SetOfByte * pVisiLayer,bool bTextOnly)41cdf0e10cSrcweir SdrObject* SdrObjectPrimitiveHit(
42cdf0e10cSrcweir 	const SdrObject& rObject,
43cdf0e10cSrcweir 	const Point& rPnt,
44cdf0e10cSrcweir 	sal_uInt16 nTol,
45cdf0e10cSrcweir 	const SdrPageView& rSdrPageView,
46cdf0e10cSrcweir 	const SetOfByte* pVisiLayer,
47cdf0e10cSrcweir     bool bTextOnly)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	SdrObject* pResult = 0;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         // group or scene with content. Single 3D objects also have a
54cdf0e10cSrcweir         // true == rObject.GetSubList(), but no content
55cdf0e10cSrcweir         pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir 	else
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			// single object, 3d object, empty scene or empty group. Check if
62cdf0e10cSrcweir             // it's a single 3D object
63cdf0e10cSrcweir 			const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 			if(pE3dCompoundObject)
66cdf0e10cSrcweir 			{
67cdf0e10cSrcweir 				const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 				if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
70cdf0e10cSrcweir 				{
71cdf0e10cSrcweir     				pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
72cdf0e10cSrcweir 				}
73cdf0e10cSrcweir 			}
74cdf0e10cSrcweir 			else
75cdf0e10cSrcweir 			{
76cdf0e10cSrcweir 				// not a single 3D object; Check in first PageWindow using prmitives (only SC
77cdf0e10cSrcweir 				// with split views uses multiple PageWindows nowadays)
78cdf0e10cSrcweir 				if(rSdrPageView.PageWindowCount())
79cdf0e10cSrcweir 				{
80cdf0e10cSrcweir 					const double fLogicTolerance(nTol);
81cdf0e10cSrcweir 					const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
82cdf0e10cSrcweir 					const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
83cdf0e10cSrcweir 						rSdrPageView.GetPageWindow(0)->GetObjectContact());
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 					if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly))
86cdf0e10cSrcweir 					{
87cdf0e10cSrcweir       					pResult = const_cast< SdrObject* >(&rObject);
88cdf0e10cSrcweir 					}
89cdf0e10cSrcweir 				}
90cdf0e10cSrcweir 			}
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	return pResult;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////
98cdf0e10cSrcweir 
SdrObjListPrimitiveHit(const SdrObjList & rList,const Point & rPnt,sal_uInt16 nTol,const SdrPageView & rSdrPageView,const SetOfByte * pVisiLayer,bool bTextOnly)99cdf0e10cSrcweir SdrObject* SdrObjListPrimitiveHit(
100cdf0e10cSrcweir 	const SdrObjList& rList,
101cdf0e10cSrcweir 	const Point& rPnt,
102cdf0e10cSrcweir 	sal_uInt16 nTol,
103cdf0e10cSrcweir 	const SdrPageView& rSdrPageView,
104cdf0e10cSrcweir 	const SetOfByte* pVisiLayer,
105cdf0e10cSrcweir     bool bTextOnly)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	sal_uInt32 nObjNum(rList.GetObjCount());
108cdf0e10cSrcweir     SdrObject* pRetval = 0;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	while(!pRetval && nObjNum > 0)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		nObjNum--;
113cdf0e10cSrcweir 		SdrObject* pObj = rList.GetObj(nObjNum);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     return pRetval;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////
122cdf0e10cSrcweir 
ViewObjectContactPrimitiveHit(const sdr::contact::ViewObjectContact & rVOC,const basegfx::B2DPoint & rHitPosition,double fLogicHitTolerance,bool bTextOnly)123cdf0e10cSrcweir bool ViewObjectContactPrimitiveHit(
124cdf0e10cSrcweir     const sdr::contact::ViewObjectContact& rVOC,
125cdf0e10cSrcweir 	const basegfx::B2DPoint& rHitPosition,
126cdf0e10cSrcweir     double fLogicHitTolerance,
127cdf0e10cSrcweir     bool bTextOnly)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	if(!aObjectRange.isEmpty())
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		// first do a rough B2DRange based HitTest; do not forget to
134cdf0e10cSrcweir 		// include the HitTolerance if given
135cdf0e10cSrcweir 		if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
136cdf0e10cSrcweir 		{
137cdf0e10cSrcweir 			aObjectRange.grow(fLogicHitTolerance);
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		if(aObjectRange.isInside(rHitPosition))
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir 			// get primitive sequence
143cdf0e10cSrcweir 			sdr::contact::DisplayInfo aDisplayInfo;
144cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DSequence& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 			if(rSequence.hasElements())
147cdf0e10cSrcweir 			{
148cdf0e10cSrcweir 				// create a HitTest processor
149cdf0e10cSrcweir 				const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
150cdf0e10cSrcweir 				drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
151cdf0e10cSrcweir 					rViewInformation2D,
152cdf0e10cSrcweir 					rHitPosition,
153cdf0e10cSrcweir 					fLogicHitTolerance,
154cdf0e10cSrcweir                     bTextOnly);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 				// feed it with the primitives
157cdf0e10cSrcweir 				aHitTestProcessor2D.process(rSequence);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 				// deliver result
160cdf0e10cSrcweir 				return aHitTestProcessor2D.getHit();
161cdf0e10cSrcweir 			}
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 	}
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	return false;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
169cdf0e10cSrcweir // eof
170