Update ooo320-m1
[ooovba.git] / drawinglayer / source / primitive2d / embedded3dprimitive2d.cxx
blob54c71a1196fe5d7414785d52dd31967ba85a7c3c
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: embedded3dprimitive2d.cxx,v $
7 * $Revision: 1.8 $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:08 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
42 #include <basegfx/color/bcolor.hxx>
43 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <drawinglayer/geometry/viewinformation2d.hxx>
46 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
47 #include <drawinglayer/geometry/viewinformation3d.hxx>
48 #include <drawinglayer/processor3d/shadow3dextractor.hxx>
50 //////////////////////////////////////////////////////////////////////////////
52 using namespace com::sun::star;
54 //////////////////////////////////////////////////////////////////////////////
56 namespace drawinglayer
58 namespace primitive2d
60 bool Embedded3DPrimitive2D::impGetShadow3D(const geometry::ViewInformation2D& /*rViewInformation*/) const
62 osl::MutexGuard aGuard( m_aMutex );
64 // create on demand
65 if(!mbShadow3DChecked && getChildren3D().hasElements())
67 // create shadow extraction processor
68 processor3d::Shadow3DExtractingProcessor aShadowProcessor(
69 getViewInformation3D(),
70 getObjectTransformation(),
71 getLightNormal(),
72 getShadowSlant(),
73 getScene3DRange());
75 // process local primitives
76 aShadowProcessor.process(getChildren3D());
78 // fetch result and set checked flag
79 const_cast< Embedded3DPrimitive2D* >(this)->maShadowPrimitives = aShadowProcessor.getPrimitive2DSequence();
80 const_cast< Embedded3DPrimitive2D* >(this)->mbShadow3DChecked = true;
83 // return if there are shadow primitives
84 return maShadowPrimitives.hasElements();
87 Primitive2DSequence Embedded3DPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const
89 // use info to create a yellow 2d rectangle, similar to empty 3d scenes and/or groups
90 const basegfx::B2DRange aLocal2DRange(getB2DRange(rViewInformation));
91 const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aLocal2DRange));
92 const basegfx::BColor aYellow(1.0, 1.0, 0.0);
93 const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aOutline, aYellow));
95 return Primitive2DSequence(&xRef, 1L);
98 Embedded3DPrimitive2D::Embedded3DPrimitive2D(
99 const primitive3d::Primitive3DSequence& rxChildren3D,
100 const basegfx::B2DHomMatrix& rObjectTransformation,
101 const geometry::ViewInformation3D& rViewInformation3D,
102 const basegfx::B3DVector& rLightNormal,
103 double fShadowSlant,
104 const basegfx::B3DRange& rScene3DRange)
105 : BasePrimitive2D(),
106 mxChildren3D(rxChildren3D),
107 maObjectTransformation(rObjectTransformation),
108 maViewInformation3D(rViewInformation3D),
109 maLightNormal(rLightNormal),
110 mfShadowSlant(fShadowSlant),
111 maScene3DRange(rScene3DRange),
112 maShadowPrimitives(),
113 maB2DRange(),
114 mbShadow3DChecked(false)
116 maLightNormal.normalize();
119 bool Embedded3DPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
121 if(BasePrimitive2D::operator==(rPrimitive))
123 const Embedded3DPrimitive2D& rCompare = static_cast< const Embedded3DPrimitive2D& >(rPrimitive);
125 return (primitive3d::arePrimitive3DSequencesEqual(getChildren3D(), rCompare.getChildren3D())
126 && getObjectTransformation() == rCompare.getObjectTransformation()
127 && getViewInformation3D() == rCompare.getViewInformation3D()
128 && getLightNormal() == rCompare.getLightNormal()
129 && getShadowSlant() == rCompare.getShadowSlant()
130 && getScene3DRange() == rCompare.getScene3DRange());
133 return false;
136 basegfx::B2DRange Embedded3DPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
138 if(maB2DRange.isEmpty())
140 // use the 3d transformation stack to create a projection of the 3D range
141 basegfx::B3DRange a3DRange(primitive3d::getB3DRangeFromPrimitive3DSequence(getChildren3D(), getViewInformation3D()));
142 a3DRange.transform(getViewInformation3D().getObjectToView());
144 // create 2d range from projected 3d and transform with scene's object transformation
145 basegfx::B2DRange aNewRange;
146 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMinX(), a3DRange.getMinY()));
147 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMaxX(), a3DRange.getMaxY()));
148 aNewRange.transform(getObjectTransformation());
150 // cehck for 3D shadows and their 2D projections. If those exist, they need to be
151 // taken into account
152 if(impGetShadow3D(rViewInformation))
154 const basegfx::B2DRange aShadow2DRange(getB2DRangeFromPrimitive2DSequence(maShadowPrimitives, rViewInformation));
156 if(!aShadow2DRange.isEmpty())
158 aNewRange.expand(aShadow2DRange);
162 // assign to buffered value
163 const_cast< Embedded3DPrimitive2D* >(this)->maB2DRange = aNewRange;
166 return maB2DRange;
169 // provide unique ID
170 ImplPrimitrive2DIDBlock(Embedded3DPrimitive2D, PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D)
172 } // end of namespace primitive2d
173 } // end of namespace drawinglayer
175 //////////////////////////////////////////////////////////////////////////////
176 // eof