xref: /AOO41X/main/svx/source/sdr/contact/viewcontactofsdrpathobj.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
32*cdf0e10cSrcweir #include <svx/svdopath.hxx>
33*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
34*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
35*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
36*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace sdr
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	namespace contact
43*cdf0e10cSrcweir 	{
44*cdf0e10cSrcweir 		ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
45*cdf0e10cSrcweir 		:	ViewContactOfTextObj(rPathObj)
46*cdf0e10cSrcweir 		{
47*cdf0e10cSrcweir 		}
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 		ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 		}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
54*cdf0e10cSrcweir 		{
55*cdf0e10cSrcweir 			const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
56*cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
57*cdf0e10cSrcweir 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
58*cdf0e10cSrcweir 					rItemSet,
59*cdf0e10cSrcweir 					GetPathObj().getText(0)));
60*cdf0e10cSrcweir             basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
61*cdf0e10cSrcweir 			sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
62*cdf0e10cSrcweir 			sal_uInt32 nPointCount(0);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nPolyCount; a++)
65*cdf0e10cSrcweir 			{
66*cdf0e10cSrcweir 				nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
67*cdf0e10cSrcweir 			}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 			if(!nPointCount)
70*cdf0e10cSrcweir 			{
71*cdf0e10cSrcweir 				OSL_ENSURE(false, "PolyPolygon object without geometry detected, this should not be created (!)");
72*cdf0e10cSrcweir 				basegfx::B2DPolygon aFallbackLine;
73*cdf0e10cSrcweir 				aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
74*cdf0e10cSrcweir 				aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
75*cdf0e10cSrcweir 				aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 				nPolyCount = 1;
78*cdf0e10cSrcweir 			}
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 			// prepare object transformation and unit polygon (direct model data)
81*cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectMatrix;
82*cdf0e10cSrcweir 			const bool bIsLine(
83*cdf0e10cSrcweir 				!aUnitPolyPolygon.areControlPointsUsed()
84*cdf0e10cSrcweir 				&& 1 == nPolyCount
85*cdf0e10cSrcweir 				&& 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 			if(bIsLine)
88*cdf0e10cSrcweir 			{
89*cdf0e10cSrcweir 				// special handling for single line mode (2 points)
90*cdf0e10cSrcweir 				const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
91*cdf0e10cSrcweir 				const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
92*cdf0e10cSrcweir 				const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
93*cdf0e10cSrcweir 				const basegfx::B2DVector aLine(aEnd - aStart);
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 				// #i102548# create new unit polygon for line (horizontal)
96*cdf0e10cSrcweir 				basegfx::B2DPolygon aNewPolygon;
97*cdf0e10cSrcweir 				aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
98*cdf0e10cSrcweir 				aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
99*cdf0e10cSrcweir 				aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 				// #i102548# fill objectMatrix with rotation and offset (no shear for lines)
102*cdf0e10cSrcweir 				aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
103*cdf0e10cSrcweir 					aLine.getLength(), 1.0,
104*cdf0e10cSrcweir 					0.0,
105*cdf0e10cSrcweir 					atan2(aLine.getY(), aLine.getX()),
106*cdf0e10cSrcweir 					aStart.getX(), aStart.getY());
107*cdf0e10cSrcweir 			}
108*cdf0e10cSrcweir 			else
109*cdf0e10cSrcweir 			{
110*cdf0e10cSrcweir 				// #i102548# create unscaled, unsheared, unrotated and untranslated polygon
111*cdf0e10cSrcweir 				// (unit polygon) by creating the object matrix and back-transforming the polygon
112*cdf0e10cSrcweir 				const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
113*cdf0e10cSrcweir 				const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
114*cdf0e10cSrcweir 				const double fWidth(aObjectRange.getWidth());
115*cdf0e10cSrcweir 				const double fHeight(aObjectRange.getHeight());
116*cdf0e10cSrcweir 				const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
117*cdf0e10cSrcweir 				const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 				aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
120*cdf0e10cSrcweir 					fScaleX, fScaleY,
121*cdf0e10cSrcweir 					rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
122*cdf0e10cSrcweir 					rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
123*cdf0e10cSrcweir 					aObjectRange.getMinX(), aObjectRange.getMinY());
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 				// ceate unit polygon from object's absolute path
126*cdf0e10cSrcweir 				basegfx::B2DHomMatrix aInverse(aObjectMatrix);
127*cdf0e10cSrcweir 				aInverse.invert();
128*cdf0e10cSrcweir 				aUnitPolyPolygon.transform(aInverse);
129*cdf0e10cSrcweir 			}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 			// create primitive. Always create primitives to allow the decomposition of
132*cdf0e10cSrcweir 			// SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
133*cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DReference xReference(
134*cdf0e10cSrcweir 				new drawinglayer::primitive2d::SdrPathPrimitive2D(
135*cdf0e10cSrcweir 					aObjectMatrix,
136*cdf0e10cSrcweir 					aAttribute,
137*cdf0e10cSrcweir 					aUnitPolyPolygon));
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
140*cdf0e10cSrcweir 		}
141*cdf0e10cSrcweir 	} // end of namespace contact
142*cdf0e10cSrcweir } // end of namespace sdr
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
145*cdf0e10cSrcweir // eof
146