1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx> 32 #include <basegfx/polygon/b2dpolygon.hxx> 33 #include <basegfx/polygon/b2dpolygontools.hxx> 34 #include <basegfx/color/bcolor.hxx> 35 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 36 #include <basegfx/tools/canvastools.hxx> 37 #include <drawinglayer/geometry/viewinformation2d.hxx> 38 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 39 #include <drawinglayer/geometry/viewinformation3d.hxx> 40 #include <drawinglayer/processor3d/shadow3dextractor.hxx> 41 42 ////////////////////////////////////////////////////////////////////////////// 43 44 using namespace com::sun::star; 45 46 ////////////////////////////////////////////////////////////////////////////// 47 48 namespace drawinglayer 49 { 50 namespace primitive2d 51 { 52 bool Embedded3DPrimitive2D::impGetShadow3D(const geometry::ViewInformation2D& /*rViewInformation*/) const 53 { 54 osl::MutexGuard aGuard( m_aMutex ); 55 56 // create on demand 57 if(!mbShadow3DChecked && getChildren3D().hasElements()) 58 { 59 // create shadow extraction processor 60 processor3d::Shadow3DExtractingProcessor aShadowProcessor( 61 getViewInformation3D(), 62 getObjectTransformation(), 63 getLightNormal(), 64 getShadowSlant(), 65 getScene3DRange()); 66 67 // process local primitives 68 aShadowProcessor.process(getChildren3D()); 69 70 // fetch result and set checked flag 71 const_cast< Embedded3DPrimitive2D* >(this)->maShadowPrimitives = aShadowProcessor.getPrimitive2DSequence(); 72 const_cast< Embedded3DPrimitive2D* >(this)->mbShadow3DChecked = true; 73 } 74 75 // return if there are shadow primitives 76 return maShadowPrimitives.hasElements(); 77 } 78 79 Primitive2DSequence Embedded3DPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 80 { 81 // use info to create a yellow 2d rectangle, similar to empty 3d scenes and/or groups 82 const basegfx::B2DRange aLocal2DRange(getB2DRange(rViewInformation)); 83 const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(aLocal2DRange)); 84 const basegfx::BColor aYellow(1.0, 1.0, 0.0); 85 const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aOutline, aYellow)); 86 87 return Primitive2DSequence(&xRef, 1L); 88 } 89 90 Embedded3DPrimitive2D::Embedded3DPrimitive2D( 91 const primitive3d::Primitive3DSequence& rxChildren3D, 92 const basegfx::B2DHomMatrix& rObjectTransformation, 93 const geometry::ViewInformation3D& rViewInformation3D, 94 const basegfx::B3DVector& rLightNormal, 95 double fShadowSlant, 96 const basegfx::B3DRange& rScene3DRange) 97 : BufferedDecompositionPrimitive2D(), 98 mxChildren3D(rxChildren3D), 99 maObjectTransformation(rObjectTransformation), 100 maViewInformation3D(rViewInformation3D), 101 maLightNormal(rLightNormal), 102 mfShadowSlant(fShadowSlant), 103 maScene3DRange(rScene3DRange), 104 maShadowPrimitives(), 105 maB2DRange(), 106 mbShadow3DChecked(false) 107 { 108 maLightNormal.normalize(); 109 } 110 111 bool Embedded3DPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 112 { 113 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 114 { 115 const Embedded3DPrimitive2D& rCompare = static_cast< const Embedded3DPrimitive2D& >(rPrimitive); 116 117 return (primitive3d::arePrimitive3DSequencesEqual(getChildren3D(), rCompare.getChildren3D()) 118 && getObjectTransformation() == rCompare.getObjectTransformation() 119 && getViewInformation3D() == rCompare.getViewInformation3D() 120 && getLightNormal() == rCompare.getLightNormal() 121 && getShadowSlant() == rCompare.getShadowSlant() 122 && getScene3DRange() == rCompare.getScene3DRange()); 123 } 124 125 return false; 126 } 127 128 basegfx::B2DRange Embedded3DPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 129 { 130 if(maB2DRange.isEmpty()) 131 { 132 // use the 3d transformation stack to create a projection of the 3D range 133 basegfx::B3DRange a3DRange(primitive3d::getB3DRangeFromPrimitive3DSequence(getChildren3D(), getViewInformation3D())); 134 a3DRange.transform(getViewInformation3D().getObjectToView()); 135 136 // create 2d range from projected 3d and transform with scene's object transformation 137 basegfx::B2DRange aNewRange; 138 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMinX(), a3DRange.getMinY())); 139 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMaxX(), a3DRange.getMaxY())); 140 aNewRange.transform(getObjectTransformation()); 141 142 // cehck for 3D shadows and their 2D projections. If those exist, they need to be 143 // taken into account 144 if(impGetShadow3D(rViewInformation)) 145 { 146 const basegfx::B2DRange aShadow2DRange(getB2DRangeFromPrimitive2DSequence(maShadowPrimitives, rViewInformation)); 147 148 if(!aShadow2DRange.isEmpty()) 149 { 150 aNewRange.expand(aShadow2DRange); 151 } 152 } 153 154 // assign to buffered value 155 const_cast< Embedded3DPrimitive2D* >(this)->maB2DRange = aNewRange; 156 } 157 158 return maB2DRange; 159 } 160 161 // provide unique ID 162 ImplPrimitrive2DIDBlock(Embedded3DPrimitive2D, PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D) 163 164 } // end of namespace primitive2d 165 } // end of namespace drawinglayer 166 167 ////////////////////////////////////////////////////////////////////////////// 168 // eof 169