xref: /AOO41X/main/drawinglayer/source/primitive3d/polygonprimitive3d.cxx (revision 5aaf853b3ba91aa8a4f8154519fb0bf086e1a428)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
28 #include <basegfx/polygon/b3dpolygontools.hxx>
29 #include <basegfx/tools/canvastools.hxx>
30 #include <basegfx/polygon/b3dpolypolygontools.hxx>
31 #include <drawinglayer/primitive3d/polygontubeprimitive3d.hxx>
32 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 using namespace com::sun::star;
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace drawinglayer
41 {
42     namespace primitive3d
43     {
PolygonHairlinePrimitive3D(const basegfx::B3DPolygon & rPolygon,const basegfx::BColor & rBColor)44         PolygonHairlinePrimitive3D::PolygonHairlinePrimitive3D(
45             const basegfx::B3DPolygon& rPolygon,
46             const basegfx::BColor& rBColor)
47         :   BasePrimitive3D(),
48             maPolygon(rPolygon),
49             maBColor(rBColor)
50         {
51         }
52 
operator ==(const BasePrimitive3D & rPrimitive) const53         bool PolygonHairlinePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
54         {
55             if(BasePrimitive3D::operator==(rPrimitive))
56             {
57                 const PolygonHairlinePrimitive3D& rCompare = (PolygonHairlinePrimitive3D&)rPrimitive;
58 
59                 return (getB3DPolygon() == rCompare.getB3DPolygon()
60                     && getBColor() == rCompare.getBColor());
61             }
62 
63             return false;
64         }
65 
getB3DRange(const geometry::ViewInformation3D &) const66         basegfx::B3DRange PolygonHairlinePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
67         {
68             return basegfx::tools::getRange(getB3DPolygon());
69         }
70 
71         // provide unique ID
72         ImplPrimitrive3DIDBlock(PolygonHairlinePrimitive3D, PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D)
73 
74     } // end of namespace primitive3d
75 } // end of namespace drawinglayer
76 
77 //////////////////////////////////////////////////////////////////////////////
78 
79 namespace drawinglayer
80 {
81     namespace primitive3d
82     {
create3DDecomposition(const geometry::ViewInformation3D &) const83         Primitive3DSequence PolygonStrokePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
84         {
85             Primitive3DSequence aRetval;
86 
87             if(getB3DPolygon().count())
88             {
89                 basegfx::B3DPolyPolygon aHairLinePolyPolygon;
90 
91                 if(0.0 == getStrokeAttribute().getFullDotDashLen())
92                 {
93                     aHairLinePolyPolygon = basegfx::B3DPolyPolygon(getB3DPolygon());
94                 }
95                 else
96                 {
97                     // apply LineStyle
98                     basegfx::tools::applyLineDashing(getB3DPolygon(), getStrokeAttribute().getDotDashArray(), &aHairLinePolyPolygon, 0, getStrokeAttribute().getFullDotDashLen());
99                 }
100 
101                 // prepare result
102                 aRetval.realloc(aHairLinePolyPolygon.count());
103 
104                 if(getLineAttribute().getWidth())
105                 {
106                     // create fat line data
107                     const double fRadius(getLineAttribute().getWidth() / 2.0);
108                     const basegfx::B2DLineJoin aLineJoin(getLineAttribute().getLineJoin());
109                     const com::sun::star::drawing::LineCap aLineCap(getLineAttribute().getLineCap());
110 
111                     for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
112                     {
113                         // create tube primitives
114                         const Primitive3DReference xRef(
115                             new PolygonTubePrimitive3D(
116                                 aHairLinePolyPolygon.getB3DPolygon(a),
117                                 getLineAttribute().getColor(),
118                                 fRadius,
119                                 aLineJoin,
120                                 aLineCap));
121                         aRetval[a] = xRef;
122                     }
123                 }
124                 else
125                 {
126                     // create hair line data for all sub polygons
127                     for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
128                     {
129                         const basegfx::B3DPolygon aCandidate = aHairLinePolyPolygon.getB3DPolygon(a);
130                         const Primitive3DReference xRef(new PolygonHairlinePrimitive3D(aCandidate, getLineAttribute().getColor()));
131                         aRetval[a] = xRef;
132                     }
133                 }
134             }
135 
136             return aRetval;
137         }
138 
PolygonStrokePrimitive3D(const basegfx::B3DPolygon & rPolygon,const attribute::LineAttribute & rLineAttribute,const attribute::StrokeAttribute & rStrokeAttribute)139         PolygonStrokePrimitive3D::PolygonStrokePrimitive3D(
140             const basegfx::B3DPolygon& rPolygon,
141             const attribute::LineAttribute& rLineAttribute,
142             const attribute::StrokeAttribute& rStrokeAttribute)
143         :   BufferedDecompositionPrimitive3D(),
144             maPolygon(rPolygon),
145             maLineAttribute(rLineAttribute),
146             maStrokeAttribute(rStrokeAttribute)
147         {
148         }
149 
PolygonStrokePrimitive3D(const basegfx::B3DPolygon & rPolygon,const attribute::LineAttribute & rLineAttribute)150         PolygonStrokePrimitive3D::PolygonStrokePrimitive3D(
151             const basegfx::B3DPolygon& rPolygon,
152             const attribute::LineAttribute& rLineAttribute)
153         :   BufferedDecompositionPrimitive3D(),
154             maPolygon(rPolygon),
155             maLineAttribute(rLineAttribute),
156             maStrokeAttribute()
157         {
158         }
159 
operator ==(const BasePrimitive3D & rPrimitive) const160         bool PolygonStrokePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
161         {
162             if(BufferedDecompositionPrimitive3D::operator==(rPrimitive))
163             {
164                 const PolygonStrokePrimitive3D& rCompare = (PolygonStrokePrimitive3D&)rPrimitive;
165 
166                 return (getB3DPolygon() == rCompare.getB3DPolygon()
167                     && getLineAttribute() == rCompare.getLineAttribute()
168                     && getStrokeAttribute() == rCompare.getStrokeAttribute());
169             }
170 
171             return false;
172         }
173 
174         // provide unique ID
175         ImplPrimitrive3DIDBlock(PolygonStrokePrimitive3D, PRIMITIVE3D_ID_POLYGONSTROKEPRIMITIVE3D)
176 
177     } // end of namespace primitive3d
178 } // end of namespace drawinglayer
179 
180 //////////////////////////////////////////////////////////////////////////////
181 // eof
182