xref: /trunk/main/drawinglayer/source/primitive3d/sdrpolypolygonprimitive3d.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrpolypolygonprimitive3d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
30cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx>
31cdf0e10cSrcweir #include <drawinglayer/attribute/sdrfillattribute.hxx>
32cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlineattribute.hxx>
33cdf0e10cSrcweir #include <drawinglayer/attribute/sdrshadowattribute.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace drawinglayer
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     namespace primitive3d
44cdf0e10cSrcweir     {
create3DDecomposition(const geometry::ViewInformation3D &) const45cdf0e10cSrcweir         Primitive3DSequence SdrPolyPolygonPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
46cdf0e10cSrcweir         {
47cdf0e10cSrcweir             Primitive3DSequence aRetval;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir             if(getPolyPolygon3D().count())
50cdf0e10cSrcweir             {
51cdf0e10cSrcweir                 ::std::vector< basegfx::B3DPolyPolygon > aFill;
52cdf0e10cSrcweir                 aFill.push_back(getPolyPolygon3D());
53cdf0e10cSrcweir 
54cdf0e10cSrcweir                 // get full range
55cdf0e10cSrcweir                 const basegfx::B3DRange aRange(getRangeFrom3DGeometry(aFill));
56cdf0e10cSrcweir 
57cdf0e10cSrcweir                 // #i98295# normal creation
58cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getFill().isDefault())
59cdf0e10cSrcweir                 {
60cdf0e10cSrcweir                     if(::com::sun::star::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind())
61cdf0e10cSrcweir                     {
62cdf0e10cSrcweir                         applyNormalsKindSphereTo3DGeometry(aFill, aRange);
63cdf0e10cSrcweir                     }
64cdf0e10cSrcweir                     else if(::com::sun::star::drawing::NormalsKind_FLAT == getSdr3DObjectAttribute().getNormalsKind())
65cdf0e10cSrcweir                     {
66cdf0e10cSrcweir                         applyNormalsKindFlatTo3DGeometry(aFill);
67cdf0e10cSrcweir                     }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir                     if(getSdr3DObjectAttribute().getNormalsInvert())
70cdf0e10cSrcweir                     {
71cdf0e10cSrcweir                         applyNormalsInvertTo3DGeometry(aFill);
72cdf0e10cSrcweir                     }
73cdf0e10cSrcweir                 }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir                 // #i98314# texture coordinates
76cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getFill().isDefault())
77cdf0e10cSrcweir                 {
78cdf0e10cSrcweir                     applyTextureTo3DGeometry(
79cdf0e10cSrcweir                         getSdr3DObjectAttribute().getTextureProjectionX(),
80cdf0e10cSrcweir                         getSdr3DObjectAttribute().getTextureProjectionY(),
81cdf0e10cSrcweir                         aFill,
82cdf0e10cSrcweir                         aRange,
83cdf0e10cSrcweir                         getTextureSize());
84cdf0e10cSrcweir                 }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getFill().isDefault())
87cdf0e10cSrcweir                 {
88cdf0e10cSrcweir                     // add fill
89cdf0e10cSrcweir                     aRetval = create3DPolyPolygonFillPrimitives(
90cdf0e10cSrcweir                         aFill,
91cdf0e10cSrcweir                         getTransform(),
92cdf0e10cSrcweir                         getTextureSize(),
93cdf0e10cSrcweir                         getSdr3DObjectAttribute(),
94cdf0e10cSrcweir                         getSdrLFSAttribute().getFill(),
95cdf0e10cSrcweir                         getSdrLFSAttribute().getFillFloatTransGradient());
96cdf0e10cSrcweir                 }
97cdf0e10cSrcweir                 else
98cdf0e10cSrcweir                 {
99cdf0e10cSrcweir                     // create simplified 3d hit test geometry
100cdf0e10cSrcweir                     aRetval = createHiddenGeometryPrimitives3D(
101cdf0e10cSrcweir                         aFill,
102cdf0e10cSrcweir                         getTransform(),
103cdf0e10cSrcweir                         getTextureSize(),
104cdf0e10cSrcweir                         getSdr3DObjectAttribute());
105cdf0e10cSrcweir                 }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir                 // add line
108cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getLine().isDefault())
109cdf0e10cSrcweir                 {
110cdf0e10cSrcweir                     basegfx::B3DPolyPolygon aLine(getPolyPolygon3D());
111cdf0e10cSrcweir                     aLine.clearNormals();
112cdf0e10cSrcweir                     aLine.clearTextureCoordinates();
113cdf0e10cSrcweir                     const Primitive3DSequence aLines(create3DPolyPolygonLinePrimitives(
114cdf0e10cSrcweir                         aLine, getTransform(), getSdrLFSAttribute().getLine()));
115cdf0e10cSrcweir                     appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aLines);
116cdf0e10cSrcweir                 }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                 // add shadow
119cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getShadow().isDefault()
120cdf0e10cSrcweir                     && aRetval.hasElements())
121cdf0e10cSrcweir                 {
122cdf0e10cSrcweir                     const Primitive3DSequence aShadow(createShadowPrimitive3D(
123cdf0e10cSrcweir                         aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
124cdf0e10cSrcweir                     appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aShadow);
125cdf0e10cSrcweir                 }
126cdf0e10cSrcweir             }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             return aRetval;
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 
SdrPolyPolygonPrimitive3D(const basegfx::B3DPolyPolygon & rPolyPolygon3D,const basegfx::B3DHomMatrix & rTransform,const basegfx::B2DVector & rTextureSize,const attribute::SdrLineFillShadowAttribute3D & rSdrLFSAttribute,const attribute::Sdr3DObjectAttribute & rSdr3DObjectAttribute)131cdf0e10cSrcweir         SdrPolyPolygonPrimitive3D::SdrPolyPolygonPrimitive3D(
132cdf0e10cSrcweir             const basegfx::B3DPolyPolygon& rPolyPolygon3D,
133cdf0e10cSrcweir             const basegfx::B3DHomMatrix& rTransform,
134cdf0e10cSrcweir             const basegfx::B2DVector& rTextureSize,
135cdf0e10cSrcweir             const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
136cdf0e10cSrcweir             const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute)
137cdf0e10cSrcweir         :   SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute),
138cdf0e10cSrcweir             maPolyPolygon3D(rPolyPolygon3D)
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
operator ==(const BasePrimitive3D & rPrimitive) const142cdf0e10cSrcweir         bool SdrPolyPolygonPrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             if(SdrPrimitive3D::operator==(rPrimitive))
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 const SdrPolyPolygonPrimitive3D& rCompare = static_cast< const SdrPolyPolygonPrimitive3D& >(rPrimitive);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir                 return (getPolyPolygon3D() == rCompare.getPolyPolygon3D());
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             return false;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
getB3DRange(const geometry::ViewInformation3D &) const154cdf0e10cSrcweir         basegfx::B3DRange SdrPolyPolygonPrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             // added this implementation to make sure that non-visible objects of this
157cdf0e10cSrcweir             // kind will deliver their expansion. If not implemented, it would never deliver
158cdf0e10cSrcweir             // the used space for non-visible objects since the decomposition for that
159cdf0e10cSrcweir             // case will be empty (what is correct). To support chart ATM which relies on
160cdf0e10cSrcweir             // non-visible objects occupying space in 3D, this method was added
161cdf0e10cSrcweir             basegfx::B3DRange aRetval;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             if(getPolyPolygon3D().count())
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 aRetval = basegfx::tools::getRange(getPolyPolygon3D());
166cdf0e10cSrcweir                 aRetval.transform(getTransform());
167cdf0e10cSrcweir 
168cdf0e10cSrcweir                 if(!getSdrLFSAttribute().getLine().isDefault())
169cdf0e10cSrcweir                 {
170cdf0e10cSrcweir                     const attribute::SdrLineAttribute& rLine = getSdrLFSAttribute().getLine();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir                     if(!rLine.isDefault() && !basegfx::fTools::equalZero(rLine.getWidth()))
173cdf0e10cSrcweir                     {
174cdf0e10cSrcweir                         // expand by half LineWidth as tube radius
175cdf0e10cSrcweir                         aRetval.grow(rLine.getWidth() / 2.0);
176cdf0e10cSrcweir                     }
177cdf0e10cSrcweir                 }
178cdf0e10cSrcweir             }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir             return aRetval;
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir         // provide unique ID
184cdf0e10cSrcweir         ImplPrimitrive3DIDBlock(SdrPolyPolygonPrimitive3D, PRIMITIVE3D_ID_SDRPOLYPOLYGONPRIMITIVE3D)
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     } // end of namespace primitive3d
187cdf0e10cSrcweir } // end of namespace drawinglayer
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
190cdf0e10cSrcweir // eof
191