1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_drawinglayer.hxx"
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
28*b1cdbd2cSJim Jagielski #include <basegfx/polygon/b2dpolygon.hxx>
29*b1cdbd2cSJim Jagielski #include <basegfx/polygon/b2dpolygontools.hxx>
30*b1cdbd2cSJim Jagielski #include <basegfx/color/bcolor.hxx>
31*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
32*b1cdbd2cSJim Jagielski #include <basegfx/tools/canvastools.hxx>
33*b1cdbd2cSJim Jagielski #include <drawinglayer/geometry/viewinformation2d.hxx>
34*b1cdbd2cSJim Jagielski #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
35*b1cdbd2cSJim Jagielski #include <drawinglayer/geometry/viewinformation3d.hxx>
36*b1cdbd2cSJim Jagielski #include <drawinglayer/processor3d/shadow3dextractor.hxx>
37*b1cdbd2cSJim Jagielski 
38*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
39*b1cdbd2cSJim Jagielski 
40*b1cdbd2cSJim Jagielski using namespace com::sun::star;
41*b1cdbd2cSJim Jagielski 
42*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
43*b1cdbd2cSJim Jagielski 
44*b1cdbd2cSJim Jagielski namespace drawinglayer
45*b1cdbd2cSJim Jagielski {
46*b1cdbd2cSJim Jagielski 	namespace primitive2d
47*b1cdbd2cSJim Jagielski 	{
impGetShadow3D(const geometry::ViewInformation2D &) const48*b1cdbd2cSJim Jagielski 		bool Embedded3DPrimitive2D::impGetShadow3D(const geometry::ViewInformation2D& /*rViewInformation*/) const
49*b1cdbd2cSJim Jagielski 		{
50*b1cdbd2cSJim Jagielski 			osl::MutexGuard aGuard( m_aMutex );
51*b1cdbd2cSJim Jagielski 
52*b1cdbd2cSJim Jagielski 			// create on demand
53*b1cdbd2cSJim Jagielski 			if(!mbShadow3DChecked && getChildren3D().hasElements())
54*b1cdbd2cSJim Jagielski 			{
55*b1cdbd2cSJim Jagielski 				// create shadow extraction processor
56*b1cdbd2cSJim Jagielski 				processor3d::Shadow3DExtractingProcessor aShadowProcessor(
57*b1cdbd2cSJim Jagielski 					getViewInformation3D(),
58*b1cdbd2cSJim Jagielski 					getObjectTransformation(),
59*b1cdbd2cSJim Jagielski 					getLightNormal(),
60*b1cdbd2cSJim Jagielski 					getShadowSlant(),
61*b1cdbd2cSJim Jagielski                     getScene3DRange());
62*b1cdbd2cSJim Jagielski 
63*b1cdbd2cSJim Jagielski 				// process local primitives
64*b1cdbd2cSJim Jagielski 				aShadowProcessor.process(getChildren3D());
65*b1cdbd2cSJim Jagielski 
66*b1cdbd2cSJim Jagielski 				// fetch result and set checked flag
67*b1cdbd2cSJim Jagielski 				const_cast< Embedded3DPrimitive2D* >(this)->maShadowPrimitives = aShadowProcessor.getPrimitive2DSequence();
68*b1cdbd2cSJim Jagielski 				const_cast< Embedded3DPrimitive2D* >(this)->mbShadow3DChecked = true;
69*b1cdbd2cSJim Jagielski 			}
70*b1cdbd2cSJim Jagielski 
71*b1cdbd2cSJim Jagielski 			// return if there are shadow primitives
72*b1cdbd2cSJim Jagielski 			return maShadowPrimitives.hasElements();
73*b1cdbd2cSJim Jagielski 		}
74*b1cdbd2cSJim Jagielski 
create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const75*b1cdbd2cSJim Jagielski         Primitive2DSequence Embedded3DPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
76*b1cdbd2cSJim Jagielski 		{
77*b1cdbd2cSJim Jagielski 			// use info to create a yellow 2d rectangle, similar to empty 3d scenes and/or groups
78*b1cdbd2cSJim Jagielski     		const basegfx::B2DRange aLocal2DRange(getB2DRange(rViewInformation));
79*b1cdbd2cSJim Jagielski 			const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aLocal2DRange));
80*b1cdbd2cSJim Jagielski 			const basegfx::BColor aYellow(1.0, 1.0, 0.0);
81*b1cdbd2cSJim Jagielski 			const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aOutline, aYellow));
82*b1cdbd2cSJim Jagielski 
83*b1cdbd2cSJim Jagielski 			return Primitive2DSequence(&xRef, 1L);
84*b1cdbd2cSJim Jagielski 		}
85*b1cdbd2cSJim Jagielski 
Embedded3DPrimitive2D(const primitive3d::Primitive3DSequence & rxChildren3D,const basegfx::B2DHomMatrix & rObjectTransformation,const geometry::ViewInformation3D & rViewInformation3D,const basegfx::B3DVector & rLightNormal,double fShadowSlant,const basegfx::B3DRange & rScene3DRange)86*b1cdbd2cSJim Jagielski 		Embedded3DPrimitive2D::Embedded3DPrimitive2D(
87*b1cdbd2cSJim Jagielski 			const primitive3d::Primitive3DSequence& rxChildren3D,
88*b1cdbd2cSJim Jagielski 			const basegfx::B2DHomMatrix& rObjectTransformation,
89*b1cdbd2cSJim Jagielski 			const geometry::ViewInformation3D& rViewInformation3D,
90*b1cdbd2cSJim Jagielski 			const basegfx::B3DVector& rLightNormal,
91*b1cdbd2cSJim Jagielski 			double fShadowSlant,
92*b1cdbd2cSJim Jagielski             const basegfx::B3DRange& rScene3DRange)
93*b1cdbd2cSJim Jagielski 		:	BufferedDecompositionPrimitive2D(),
94*b1cdbd2cSJim Jagielski 			mxChildren3D(rxChildren3D),
95*b1cdbd2cSJim Jagielski 			maObjectTransformation(rObjectTransformation),
96*b1cdbd2cSJim Jagielski 			maViewInformation3D(rViewInformation3D),
97*b1cdbd2cSJim Jagielski 			maLightNormal(rLightNormal),
98*b1cdbd2cSJim Jagielski 			mfShadowSlant(fShadowSlant),
99*b1cdbd2cSJim Jagielski             maScene3DRange(rScene3DRange),
100*b1cdbd2cSJim Jagielski             maShadowPrimitives(),
101*b1cdbd2cSJim Jagielski 			maB2DRange(),
102*b1cdbd2cSJim Jagielski             mbShadow3DChecked(false)
103*b1cdbd2cSJim Jagielski 		{
104*b1cdbd2cSJim Jagielski 			maLightNormal.normalize();
105*b1cdbd2cSJim Jagielski 		}
106*b1cdbd2cSJim Jagielski 
operator ==(const BasePrimitive2D & rPrimitive) const107*b1cdbd2cSJim Jagielski 		bool Embedded3DPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
108*b1cdbd2cSJim Jagielski 		{
109*b1cdbd2cSJim Jagielski 			if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
110*b1cdbd2cSJim Jagielski 			{
111*b1cdbd2cSJim Jagielski 				const Embedded3DPrimitive2D& rCompare = static_cast< const Embedded3DPrimitive2D& >(rPrimitive);
112*b1cdbd2cSJim Jagielski 
113*b1cdbd2cSJim Jagielski 				return (primitive3d::arePrimitive3DSequencesEqual(getChildren3D(), rCompare.getChildren3D())
114*b1cdbd2cSJim Jagielski 					&& getObjectTransformation() == rCompare.getObjectTransformation()
115*b1cdbd2cSJim Jagielski 					&& getViewInformation3D() == rCompare.getViewInformation3D()
116*b1cdbd2cSJim Jagielski 					&& getLightNormal() == rCompare.getLightNormal()
117*b1cdbd2cSJim Jagielski 					&& getShadowSlant() == rCompare.getShadowSlant()
118*b1cdbd2cSJim Jagielski                     && getScene3DRange() == rCompare.getScene3DRange());
119*b1cdbd2cSJim Jagielski 			}
120*b1cdbd2cSJim Jagielski 
121*b1cdbd2cSJim Jagielski 			return false;
122*b1cdbd2cSJim Jagielski 		}
123*b1cdbd2cSJim Jagielski 
getB2DRange(const geometry::ViewInformation2D & rViewInformation) const124*b1cdbd2cSJim Jagielski 		basegfx::B2DRange Embedded3DPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
125*b1cdbd2cSJim Jagielski 		{
126*b1cdbd2cSJim Jagielski 			if(maB2DRange.isEmpty())
127*b1cdbd2cSJim Jagielski 			{
128*b1cdbd2cSJim Jagielski 				// use the 3d transformation stack to create a projection of the 3D range
129*b1cdbd2cSJim Jagielski 				basegfx::B3DRange a3DRange(primitive3d::getB3DRangeFromPrimitive3DSequence(getChildren3D(), getViewInformation3D()));
130*b1cdbd2cSJim Jagielski 				a3DRange.transform(getViewInformation3D().getObjectToView());
131*b1cdbd2cSJim Jagielski 
132*b1cdbd2cSJim Jagielski 				// create 2d range from projected 3d and transform with scene's object transformation
133*b1cdbd2cSJim Jagielski 				basegfx::B2DRange aNewRange;
134*b1cdbd2cSJim Jagielski 				aNewRange.expand(basegfx::B2DPoint(a3DRange.getMinX(), a3DRange.getMinY()));
135*b1cdbd2cSJim Jagielski 				aNewRange.expand(basegfx::B2DPoint(a3DRange.getMaxX(), a3DRange.getMaxY()));
136*b1cdbd2cSJim Jagielski 				aNewRange.transform(getObjectTransformation());
137*b1cdbd2cSJim Jagielski 
138*b1cdbd2cSJim Jagielski 				// cehck for 3D shadows and their 2D projections. If those exist, they need to be
139*b1cdbd2cSJim Jagielski 				// taken into account
140*b1cdbd2cSJim Jagielski 				if(impGetShadow3D(rViewInformation))
141*b1cdbd2cSJim Jagielski 				{
142*b1cdbd2cSJim Jagielski 					const basegfx::B2DRange aShadow2DRange(getB2DRangeFromPrimitive2DSequence(maShadowPrimitives, rViewInformation));
143*b1cdbd2cSJim Jagielski 
144*b1cdbd2cSJim Jagielski 					if(!aShadow2DRange.isEmpty())
145*b1cdbd2cSJim Jagielski 					{
146*b1cdbd2cSJim Jagielski 						aNewRange.expand(aShadow2DRange);
147*b1cdbd2cSJim Jagielski 					}
148*b1cdbd2cSJim Jagielski 				}
149*b1cdbd2cSJim Jagielski 
150*b1cdbd2cSJim Jagielski 				// assign to buffered value
151*b1cdbd2cSJim Jagielski 				const_cast< Embedded3DPrimitive2D* >(this)->maB2DRange = aNewRange;
152*b1cdbd2cSJim Jagielski 			}
153*b1cdbd2cSJim Jagielski 
154*b1cdbd2cSJim Jagielski 			return maB2DRange;
155*b1cdbd2cSJim Jagielski 		}
156*b1cdbd2cSJim Jagielski 
157*b1cdbd2cSJim Jagielski 		// provide unique ID
158*b1cdbd2cSJim Jagielski 		ImplPrimitrive2DIDBlock(Embedded3DPrimitive2D, PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D)
159*b1cdbd2cSJim Jagielski 
160*b1cdbd2cSJim Jagielski 	} // end of namespace primitive2d
161*b1cdbd2cSJim Jagielski } // end of namespace drawinglayer
162*b1cdbd2cSJim Jagielski 
163*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
164*b1cdbd2cSJim Jagielski // eof
165