1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_drawinglayer.hxx"
30 
31 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
32 #include <basegfx/polygon/b3dpolygontools.hxx>
33 #include <basegfx/tools/canvastools.hxx>
34 #include <basegfx/polygon/b3dpolypolygontools.hxx>
35 #include <drawinglayer/primitive3d/polygontubeprimitive3d.hxx>
36 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 using namespace com::sun::star;
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace drawinglayer
45 {
46 	namespace primitive3d
47 	{
48 		PolygonHairlinePrimitive3D::PolygonHairlinePrimitive3D(
49 			const basegfx::B3DPolygon& rPolygon,
50 			const basegfx::BColor& rBColor)
51 		:	BasePrimitive3D(),
52 			maPolygon(rPolygon),
53 			maBColor(rBColor)
54 		{
55 		}
56 
57 		bool PolygonHairlinePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
58 		{
59 			if(BasePrimitive3D::operator==(rPrimitive))
60 			{
61 				const PolygonHairlinePrimitive3D& rCompare = (PolygonHairlinePrimitive3D&)rPrimitive;
62 
63 				return (getB3DPolygon() == rCompare.getB3DPolygon()
64 					&& getBColor() == rCompare.getBColor());
65 			}
66 
67 			return false;
68 		}
69 
70 		basegfx::B3DRange PolygonHairlinePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
71 		{
72 			return basegfx::tools::getRange(getB3DPolygon());
73 		}
74 
75 		// provide unique ID
76 		ImplPrimitrive3DIDBlock(PolygonHairlinePrimitive3D, PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D)
77 
78 	} // end of namespace primitive3d
79 } // end of namespace drawinglayer
80 
81 //////////////////////////////////////////////////////////////////////////////
82 
83 namespace drawinglayer
84 {
85 	namespace primitive3d
86 	{
87 		Primitive3DSequence PolygonStrokePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
88 		{
89 			Primitive3DSequence aRetval;
90 
91 			if(getB3DPolygon().count())
92 			{
93 				basegfx::B3DPolyPolygon aHairLinePolyPolygon;
94 
95 				if(0.0 == getStrokeAttribute().getFullDotDashLen())
96 				{
97 					aHairLinePolyPolygon = basegfx::B3DPolyPolygon(getB3DPolygon());
98 				}
99 				else
100 				{
101 					// apply LineStyle
102 					basegfx::tools::applyLineDashing(getB3DPolygon(), getStrokeAttribute().getDotDashArray(), &aHairLinePolyPolygon, 0, getStrokeAttribute().getFullDotDashLen());
103 				}
104 
105 				// prepare result
106 				aRetval.realloc(aHairLinePolyPolygon.count());
107 
108 				if(getLineAttribute().getWidth())
109 				{
110 					// create fat line data
111 					const double fRadius(getLineAttribute().getWidth() / 2.0);
112 					const basegfx::B2DLineJoin aLineJoin(getLineAttribute().getLineJoin());
113 
114 					for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
115 					{
116 						// create tube primitives
117 						const Primitive3DReference xRef(new PolygonTubePrimitive3D(aHairLinePolyPolygon.getB3DPolygon(a), getLineAttribute().getColor(), fRadius, aLineJoin));
118 						aRetval[a] = xRef;
119 					}
120 				}
121 				else
122 				{
123 					// create hair line data for all sub polygons
124 					for(sal_uInt32 a(0L); a < aHairLinePolyPolygon.count(); a++)
125 					{
126 						const basegfx::B3DPolygon aCandidate = aHairLinePolyPolygon.getB3DPolygon(a);
127 						const Primitive3DReference xRef(new PolygonHairlinePrimitive3D(aCandidate, getLineAttribute().getColor()));
128 						aRetval[a] = xRef;
129 					}
130 				}
131 			}
132 
133 			return aRetval;
134 		}
135 
136 		PolygonStrokePrimitive3D::PolygonStrokePrimitive3D(
137 			const basegfx::B3DPolygon& rPolygon,
138             const attribute::LineAttribute& rLineAttribute,
139 			const attribute::StrokeAttribute& rStrokeAttribute)
140 		:	BufferedDecompositionPrimitive3D(),
141 			maPolygon(rPolygon),
142             maLineAttribute(rLineAttribute),
143 			maStrokeAttribute(rStrokeAttribute)
144 		{
145 		}
146 
147 		PolygonStrokePrimitive3D::PolygonStrokePrimitive3D(
148 			const basegfx::B3DPolygon& rPolygon,
149             const attribute::LineAttribute& rLineAttribute)
150 		:	BufferedDecompositionPrimitive3D(),
151 			maPolygon(rPolygon),
152             maLineAttribute(rLineAttribute),
153 			maStrokeAttribute()
154 		{
155 		}
156 
157 		bool PolygonStrokePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
158 		{
159 			if(BufferedDecompositionPrimitive3D::operator==(rPrimitive))
160 			{
161 				const PolygonStrokePrimitive3D& rCompare = (PolygonStrokePrimitive3D&)rPrimitive;
162 
163 				return (getB3DPolygon() == rCompare.getB3DPolygon()
164 					&& getLineAttribute() == rCompare.getLineAttribute()
165 					&& getStrokeAttribute() == rCompare.getStrokeAttribute());
166 			}
167 
168 			return false;
169 		}
170 
171 		// provide unique ID
172 		ImplPrimitrive3DIDBlock(PolygonStrokePrimitive3D, PRIMITIVE3D_ID_POLYGONSTROKEPRIMITIVE3D)
173 
174 	} // end of namespace primitive3d
175 } // end of namespace drawinglayer
176 
177 //////////////////////////////////////////////////////////////////////////////
178 // eof
179