LibreOffice Module drawinglayer (master) 1
embedded3dprimitive2d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
29#include <utility>
30
31
32using namespace com::sun::star;
33
34
36{
38 {
39 // create on demand
40 if(!mbShadow3DChecked && !getChildren3D().empty())
41 {
42 // create shadow extraction processor
49
50 // process local primitives
51 aShadowProcessor.process(getChildren3D());
52
53 // fetch result and set checked flag
54 const_cast< Embedded3DPrimitive2D* >(this)->maShadowPrimitives = aShadowProcessor.getPrimitive2DSequence();
55 const_cast< Embedded3DPrimitive2D* >(this)->mbShadow3DChecked = true;
56 }
57
58 // return if there are shadow primitives
59 return !maShadowPrimitives.empty();
60 }
61
63 {
64 // use info to create a yellow 2d rectangle, similar to empty 3d scenes and/or groups
65 const basegfx::B2DRange aLocal2DRange(getB2DRange(rViewInformation));
67 const basegfx::BColor aYellow(1.0, 1.0, 0.0);
68 rContainer.push_back(new PolygonHairlinePrimitive2D(std::move(aOutline), aYellow));
69 }
70
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)
85 {
87 }
88
90 {
91 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
92 {
93 const Embedded3DPrimitive2D& rCompare = static_cast< const Embedded3DPrimitive2D& >(rPrimitive);
94
95 return (getChildren3D() == rCompare.getChildren3D()
98 && getLightNormal() == rCompare.getLightNormal()
99 && getShadowSlant() == rCompare.getShadowSlant()
100 && getScene3DRange() == rCompare.getScene3DRange());
101 }
102
103 return false;
104 }
105
107 {
108 if(maB2DRange.isEmpty())
109 {
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());
113
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()));
119
120 // check for 3D shadows and their 2D projections. If those exist, they need to be
121 // taken into account
122 if(impGetShadow3D())
123 {
124 const basegfx::B2DRange aShadow2DRange(maShadowPrimitives.getB2DRange(rViewInformation));
125
126 if(!aShadow2DRange.isEmpty())
127 {
128 aNewRange.expand(aShadow2DRange);
129 }
130 }
131
132 // assign to buffered value
133 const_cast< Embedded3DPrimitive2D* >(this)->maB2DRange = aNewRange;
134 }
135
136 return maB2DRange;
137 }
138
139 // provide unique ID
141 {
143 }
144
145} // end of namespace
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
BASEGFX_DLLPUBLIC void transform(const B3DHomMatrix &rMatrix)
double getMinX() const
double getMinY() const
double getMaxX() const
double getMaxY() const
B3DVector & normalize()
void expand(const Tuple2D< TYPE > &rTuple)
bool isEmpty() const
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const override
get range
basegfx::B2DRange maB2DRange
#i96669# add simple range buffering for this primitive
Embedded3DPrimitive2D(primitive3d::Primitive3DContainer xChildren3D, basegfx::B2DHomMatrix aObjectTransformation, geometry::ViewInformation3D aViewInformation3D, const basegfx::B3DVector &rLightNormal, double fShadowSlant, const basegfx::B3DRange &rScene3DRange)
constructor
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
bool mbShadow3DChecked
flag if given 3D geometry is already checked for shadow definitions and 2d shadows are created in maS...
const basegfx::B2DHomMatrix & getObjectTransformation() const
const geometry::ViewInformation3D & getViewInformation3D() const
Primitive2DContainer maShadowPrimitives
the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked)
basegfx::B3DVector maLightNormal
if the embedded 3D primitives contain shadow, these parameters are needed to extract the shadow which...
const primitive3d::Primitive3DContainer & getChildren3D() const
data read access
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
void process(const primitive3d::Primitive3DContainer &rSource)
const primitive2d::Primitive2DContainer & getPrimitive2DSequence() const
data read access
#define PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)