1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofsdrcircobj.hxx>
28 #include <svx/svdocirc.hxx>
29 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
30 #include <svx/sdr/primitive2d/sdrellipseprimitive2d.hxx>
31 #include <svl/itemset.hxx>
32 #include <svx/sxciaitm.hxx>
33 #include <basegfx/matrix/b2dhommatrixtools.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace sdr
38 {
39 	namespace contact
40 	{
ViewContactOfSdrCircObj(SdrCircObj & rCircObj)41 		ViewContactOfSdrCircObj::ViewContactOfSdrCircObj(SdrCircObj& rCircObj)
42 		:	ViewContactOfSdrRectObj(rCircObj)
43 		{
44 		}
45 
~ViewContactOfSdrCircObj()46 		ViewContactOfSdrCircObj::~ViewContactOfSdrCircObj()
47 		{
48 		}
49 
createViewIndependentPrimitive2DSequence() const50 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCircObj::createViewIndependentPrimitive2DSequence() const
51 		{
52 			const SfxItemSet& rItemSet = GetCircObj().GetMergedItemSet();
53 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
54 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
55                     rItemSet,
56                     GetCircObj().getText(0),
57                     false));
58 
59 			// take unrotated snap rect (direct model data) for position and size
60 			const Rectangle& rRectangle = GetCircObj().GetGeoRect();
61 			const basegfx::B2DRange aObjectRange(
62 				rRectangle.Left(), rRectangle.Top(),
63 				rRectangle.Right(), rRectangle.Bottom());
64 			const GeoStat& rGeoStat(GetCircObj().GetGeoStat());
65 
66 			// fill object matrix
67 			const basegfx::B2DHomMatrix aObjectMatrix(
68 				basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
69 					aObjectRange.getWidth(), aObjectRange.getHeight(),
70 					rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
71 					rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
72 					aObjectRange.getMinX(), aObjectRange.getMinY()));
73 
74 			// create primitive data
75 			const sal_uInt16 nIdentifier(GetCircObj().GetObjIdentifier());
76 
77 			// always create primitives to allow the decomposition of SdrEllipsePrimitive2D
78 			// or SdrEllipseSegmentPrimitive2D to create needed invisible elements for HitTest
79 			// and/or BoundRect
80 			if(OBJ_CIRC == nIdentifier)
81 			{
82 				const drawinglayer::primitive2d::Primitive2DReference xReference(
83 					new drawinglayer::primitive2d::SdrEllipsePrimitive2D(
84 						aObjectMatrix,
85 						aAttribute));
86 
87 				return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
88 			}
89 			else
90 			{
91 				const sal_Int32 nNewStart(((SdrCircStartAngleItem&)rItemSet.Get(SDRATTR_CIRCSTARTANGLE)).GetValue());
92 				const sal_Int32 nNewEnd(((SdrCircEndAngleItem&)rItemSet.Get(SDRATTR_CIRCENDANGLE)).GetValue());
93 				const double fStart(((36000 - nNewEnd) % 36000) * F_PI18000);
94 				const double fEnd(((36000 - nNewStart) % 36000) * F_PI18000);
95 				const bool bCloseSegment(OBJ_CARC != nIdentifier);
96 				const bool bCloseUsingCenter(OBJ_SECT == nIdentifier);
97 
98 				const drawinglayer::primitive2d::Primitive2DReference xReference(
99 					new drawinglayer::primitive2d::SdrEllipseSegmentPrimitive2D(
100 						aObjectMatrix,
101 						aAttribute,
102 						fStart,
103 						fEnd,
104 						bCloseSegment,
105 						bCloseUsingCenter));
106 
107 				return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
108 			}
109 		}
110 	} // end of namespace contact
111 } // end of namespace sdr
112 
113 //////////////////////////////////////////////////////////////////////////////
114 // eof
115