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 #include <svx/sdr/overlay/overlayobject.hxx>
27 #include <svx/sdr/overlay/overlaymanager.hxx>
28 #include <tools/debug.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/vector/b2dvector.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/salbtype.hxx>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/polygon/b2dpolypolygon.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 #include <svx/sdr/contact/objectcontacttools.hxx>
38 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace sdr
43 {
44 	namespace overlay
45 	{
46 		void OverlayObject::objectChange()
47 		{
48 			const basegfx::B2DRange aPreviousRange(maBaseRange);
49 			maBaseRange.reset();
50 			setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence());
51 
52 			if(getOverlayManager() && !aPreviousRange.isEmpty())
53 			{
54 				getOverlayManager()->invalidateRange(aPreviousRange);
55 			}
56 
57 			const basegfx::B2DRange& rCurrentRange = getBaseRange();
58 
59 			if(getOverlayManager() && rCurrentRange != aPreviousRange && !rCurrentRange.isEmpty())
60 			{
61 				getOverlayManager()->invalidateRange(rCurrentRange);
62 			}
63 		}
64 
65 		// OverlayObject implementations.
66 		drawinglayer::primitive2d::Primitive2DSequence OverlayObject::createOverlayObjectPrimitive2DSequence()
67         {
68             // Default implementation has to assert a missing implementation. It cannot
69             // be useful to have overlay object derivations which have no visualisation
70             // at all
71             OSL_ENSURE(false, "OverlayObject derivation without visualisation definition (missing createOverlayObjectPrimitive2DSequence implementation) (!)");
72             return drawinglayer::primitive2d::Primitive2DSequence();
73         }
74 
75         sal_uInt32 OverlayObject::impCheckBlinkTimeValueRange(sal_uInt32 nBlinkTime) const
76         {
77             if(nBlinkTime < 25)
78             {
79                 nBlinkTime = 25;
80             }
81             else if(nBlinkTime > 10000)
82             {
83                 nBlinkTime = 10000;
84             }
85 
86             return nBlinkTime;
87         }
88 
89 		void OverlayObject::allowAntiAliase(bool bNew)
90         {
91 			if(bNew != (bool)mbAllowsAntiAliase)
92 			{
93 				// remember new value
94 				mbAllowsAntiAliase = bNew;
95 
96 				// register change (after change)
97 				objectChange();
98 			}
99         }
100 
101 		OverlayObject::OverlayObject(Color aBaseColor)
102 		:	Event(0),
103 			mpOverlayManager(0),
104 			maBaseColor(aBaseColor),
105 			mbIsVisible(true),
106 			mbIsHittable(true),
107 			mbAllowsAnimation(false),
108             mbAllowsAntiAliase(true)
109 		{
110 		}
111 
112 		OverlayObject::~OverlayObject()
113 		{
114 			OSL_ENSURE(0 == getOverlayManager(), "OverlayObject is destructed which is still registered at OverlayManager (!)");
115 		}
116 
117 		drawinglayer::primitive2d::Primitive2DSequence OverlayObject::getOverlayObjectPrimitive2DSequence() const
118 		{
119 			if(!getPrimitive2DSequence().hasElements())
120 			{
121 				// no existing sequence; create one
122 				const_cast< OverlayObject* >(this)->setPrimitive2DSequence(
123 					const_cast< OverlayObject* >(this)->createOverlayObjectPrimitive2DSequence());
124 			}
125 
126 			return getPrimitive2DSequence();
127 		}
128 
129 		const basegfx::B2DRange& OverlayObject::getBaseRange() const
130 		{
131 			if(getOverlayManager() && maBaseRange.isEmpty())
132 			{
133 				const drawinglayer::primitive2d::Primitive2DSequence& rSequence = getOverlayObjectPrimitive2DSequence();
134 
135 				if(rSequence.hasElements())
136 				{
137 					const drawinglayer::geometry::ViewInformation2D aViewInformation2D(getOverlayManager()->getCurrentViewInformation2D());
138 
139 					const_cast< sdr::overlay::OverlayObject* >(this)->maBaseRange =
140 						drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(rSequence, aViewInformation2D);
141 				}
142 			}
143 
144 			return maBaseRange;
145 		}
146 
147 		void OverlayObject::setVisible(bool bNew)
148 		{
149 			if(bNew != (bool)mbIsVisible)
150 			{
151 				// remember new value
152 				mbIsVisible = bNew;
153 
154 				// register change (after change)
155 				objectChange();
156 			}
157 		}
158 
159 		void OverlayObject::setHittable(bool bNew)
160 		{
161 			if(bNew != (bool)mbIsHittable)
162 			{
163 				// remember new value
164 				mbIsHittable = bNew;
165 
166 				// register change (after change)
167 				objectChange();
168 			}
169 		}
170 
171 		void OverlayObject::setBaseColor(Color aNew)
172 		{
173 			if(aNew != maBaseColor)
174 			{
175 				// remember new value
176 				maBaseColor = aNew;
177 
178 				// register change (after change)
179 				objectChange();
180 			}
181 		}
182 
183 		void OverlayObject::Trigger(sal_uInt32 /*nTime*/)
184 		{
185 			// default does not register again
186 		}
187 
188 		void OverlayObject::stripeDefinitionHasChanged()
189 		{
190 			// default does not need to do anything
191 		}
192 	} // end of namespace overlay
193 } // end of namespace sdr
194 
195 //////////////////////////////////////////////////////////////////////////////
196 
197 namespace sdr
198 {
199 	namespace overlay
200 	{
201 		OverlayObjectWithBasePosition::OverlayObjectWithBasePosition(const basegfx::B2DPoint& rBasePos, Color aBaseColor)
202 		:	OverlayObject(aBaseColor),
203 			maBasePosition(rBasePos)
204 		{
205 		}
206 
207 		OverlayObjectWithBasePosition::~OverlayObjectWithBasePosition()
208 		{
209 		}
210 
211 		void OverlayObjectWithBasePosition::setBasePosition(const basegfx::B2DPoint& rNew)
212 		{
213 			if(rNew != maBasePosition)
214 			{
215 				// remember new value
216 				maBasePosition = rNew;
217 
218 				// register change (after change)
219 				objectChange();
220 			}
221 		}
222 	} // end of namespace overlay
223 } // end of namespace sdr
224 
225 //////////////////////////////////////////////////////////////////////////////
226 // eof
227