Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / drawinglayer / source / primitive3d / sdrpolypolygonprimitive3d.cxx
blobd94ff20bfebf3254362927323daf87093083710c
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/primitive3d/sdrpolypolygonprimitive3d.hxx>
21 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
22 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
23 #include <basegfx/polygon/b3dpolypolygontools.hxx>
24 #include <drawinglayer/attribute/sdrfillattribute.hxx>
25 #include <drawinglayer/attribute/sdrlineattribute.hxx>
26 #include <drawinglayer/attribute/sdrshadowattribute.hxx>
29 using namespace com::sun::star;
32 namespace drawinglayer
34 namespace primitive3d
36 Primitive3DContainer SdrPolyPolygonPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
38 Primitive3DContainer aRetval;
40 if(getPolyPolygon3D().count())
42 std::vector< basegfx::B3DPolyPolygon > aFill;
43 aFill.push_back(getPolyPolygon3D());
45 // get full range
46 const basegfx::B3DRange aRange(getRangeFrom3DGeometry(aFill));
48 // #i98295# normal creation
49 if(!getSdrLFSAttribute().getFill().isDefault())
51 if(css::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind())
53 applyNormalsKindSphereTo3DGeometry(aFill, aRange);
55 else if(css::drawing::NormalsKind_FLAT == getSdr3DObjectAttribute().getNormalsKind())
57 applyNormalsKindFlatTo3DGeometry(aFill);
60 if(getSdr3DObjectAttribute().getNormalsInvert())
62 applyNormalsInvertTo3DGeometry(aFill);
66 // #i98314# texture coordinates
67 if(!getSdrLFSAttribute().getFill().isDefault())
69 applyTextureTo3DGeometry(
70 getSdr3DObjectAttribute().getTextureProjectionX(),
71 getSdr3DObjectAttribute().getTextureProjectionY(),
72 aFill,
73 aRange,
74 getTextureSize());
77 if(!getSdrLFSAttribute().getFill().isDefault())
79 // add fill
80 aRetval = create3DPolyPolygonFillPrimitives(
81 aFill,
82 getTransform(),
83 getTextureSize(),
84 getSdr3DObjectAttribute(),
85 getSdrLFSAttribute().getFill(),
86 getSdrLFSAttribute().getFillFloatTransGradient());
88 else
90 // create simplified 3d hit test geometry
91 aRetval = createHiddenGeometryPrimitives3D(
92 aFill,
93 getTransform(),
94 getTextureSize(),
95 getSdr3DObjectAttribute());
98 // add line
99 if(!getSdrLFSAttribute().getLine().isDefault())
101 basegfx::B3DPolyPolygon aLine(getPolyPolygon3D());
102 aLine.clearNormals();
103 aLine.clearTextureCoordinates();
104 const Primitive3DContainer aLines(create3DPolyPolygonLinePrimitives(
105 aLine, getTransform(), getSdrLFSAttribute().getLine()));
106 aRetval.append(aLines);
109 // add shadow
110 if(!getSdrLFSAttribute().getShadow().isDefault()
111 && !aRetval.empty())
113 const Primitive3DContainer aShadow(createShadowPrimitive3D(
114 aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
115 aRetval.append(aShadow);
119 return aRetval;
122 SdrPolyPolygonPrimitive3D::SdrPolyPolygonPrimitive3D(
123 const basegfx::B3DPolyPolygon& rPolyPolygon3D,
124 const basegfx::B3DHomMatrix& rTransform,
125 const basegfx::B2DVector& rTextureSize,
126 const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
127 const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute)
128 : SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute),
129 maPolyPolygon3D(rPolyPolygon3D)
133 bool SdrPolyPolygonPrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
135 if(SdrPrimitive3D::operator==(rPrimitive))
137 const SdrPolyPolygonPrimitive3D& rCompare = static_cast< const SdrPolyPolygonPrimitive3D& >(rPrimitive);
139 return (getPolyPolygon3D() == rCompare.getPolyPolygon3D());
142 return false;
145 basegfx::B3DRange SdrPolyPolygonPrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
147 // added this implementation to make sure that non-visible objects of this
148 // kind will deliver their expansion. If not implemented, it would never deliver
149 // the used space for non-visible objects since the decomposition for that
150 // case will be empty (what is correct). To support chart ATM which relies on
151 // non-visible objects occupying space in 3D, this method was added
152 basegfx::B3DRange aRetval;
154 if(getPolyPolygon3D().count())
156 aRetval = basegfx::utils::getRange(getPolyPolygon3D());
157 aRetval.transform(getTransform());
159 if(!getSdrLFSAttribute().getLine().isDefault())
161 const attribute::SdrLineAttribute& rLine = getSdrLFSAttribute().getLine();
163 if(!rLine.isDefault() && !basegfx::fTools::equalZero(rLine.getWidth()))
165 // expand by half LineWidth as tube radius
166 aRetval.grow(rLine.getWidth() / 2.0);
171 return aRetval;
174 // provide unique ID
175 ImplPrimitive3DIDBlock(SdrPolyPolygonPrimitive3D, PRIMITIVE3D_ID_SDRPOLYPOLYGONPRIMITIVE3D)
177 } // end of namespace primitive3d
178 } // end of namespace drawinglayer
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */