calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / embedded3dprimitive2d.cxx
blob96fd4e86dbf404299aebe55a62dddc12257bba46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/color/bcolor.hxx>
24 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
25 #include <drawinglayer/geometry/viewinformation2d.hxx>
26 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
27 #include <drawinglayer/geometry/viewinformation3d.hxx>
28 #include <processor3d/shadow3dextractor.hxx>
29 #include <utility>
32 using namespace com::sun::star;
35 namespace drawinglayer::primitive2d
37 bool Embedded3DPrimitive2D::impGetShadow3D() const
39 // create on demand
40 if(!mbShadow3DChecked && !getChildren3D().empty())
42 // create shadow extraction processor
43 processor3d::Shadow3DExtractingProcessor aShadowProcessor(
44 getViewInformation3D(),
45 getObjectTransformation(),
46 getLightNormal(),
47 getShadowSlant(),
48 getScene3DRange());
50 // process local primitives
51 aShadowProcessor.process(getChildren3D());
53 // fetch result and set checked flag
54 const_cast< Embedded3DPrimitive2D* >(this)->maShadowPrimitives = aShadowProcessor.getPrimitive2DSequence();
55 const_cast< Embedded3DPrimitive2D* >(this)->mbShadow3DChecked = true;
58 // return if there are shadow primitives
59 return !maShadowPrimitives.empty();
62 void Embedded3DPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const
64 // use info to create a yellow 2d rectangle, similar to empty 3d scenes and/or groups
65 const basegfx::B2DRange aLocal2DRange(getB2DRange(rViewInformation));
66 basegfx::B2DPolygon aOutline(basegfx::utils::createPolygonFromRect(aLocal2DRange));
67 const basegfx::BColor aYellow(1.0, 1.0, 0.0);
68 rContainer.push_back(new PolygonHairlinePrimitive2D(std::move(aOutline), aYellow));
71 Embedded3DPrimitive2D::Embedded3DPrimitive2D(
72 primitive3d::Primitive3DContainer aChildren3D,
73 basegfx::B2DHomMatrix aObjectTransformation,
74 geometry::ViewInformation3D aViewInformation3D,
75 const basegfx::B3DVector& rLightNormal,
76 double fShadowSlant,
77 const basegfx::B3DRange& rScene3DRange)
78 : mxChildren3D(std::move(aChildren3D)),
79 maObjectTransformation(std::move(aObjectTransformation)),
80 maViewInformation3D(std::move(aViewInformation3D)),
81 maLightNormal(rLightNormal),
82 mfShadowSlant(fShadowSlant),
83 maScene3DRange(rScene3DRange),
84 mbShadow3DChecked(false)
86 maLightNormal.normalize();
89 bool Embedded3DPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
91 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
93 const Embedded3DPrimitive2D& rCompare = static_cast< const Embedded3DPrimitive2D& >(rPrimitive);
95 return (getChildren3D() == rCompare.getChildren3D()
96 && getObjectTransformation() == rCompare.getObjectTransformation()
97 && getViewInformation3D() == rCompare.getViewInformation3D()
98 && getLightNormal() == rCompare.getLightNormal()
99 && getShadowSlant() == rCompare.getShadowSlant()
100 && getScene3DRange() == rCompare.getScene3DRange());
103 return false;
106 basegfx::B2DRange Embedded3DPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
108 if(maB2DRange.isEmpty())
110 // use the 3d transformation stack to create a projection of the 3D range
111 basegfx::B3DRange a3DRange(getChildren3D().getB3DRange(getViewInformation3D()));
112 a3DRange.transform(getViewInformation3D().getObjectToView());
114 // create 2d range from projected 3d and transform with scene's object transformation
115 basegfx::B2DRange aNewRange;
116 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMinX(), a3DRange.getMinY()));
117 aNewRange.expand(basegfx::B2DPoint(a3DRange.getMaxX(), a3DRange.getMaxY()));
118 aNewRange.transform(getObjectTransformation());
120 // check for 3D shadows and their 2D projections. If those exist, they need to be
121 // taken into account
122 if(impGetShadow3D())
124 const basegfx::B2DRange aShadow2DRange(maShadowPrimitives.getB2DRange(rViewInformation));
126 if(!aShadow2DRange.isEmpty())
128 aNewRange.expand(aShadow2DRange);
132 // assign to buffered value
133 const_cast< Embedded3DPrimitive2D* >(this)->maB2DRange = aNewRange;
136 return maB2DRange;
139 // provide unique ID
140 sal_uInt32 Embedded3DPrimitive2D::getPrimitive2DID() const
142 return PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D;
145 } // end of namespace
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */