1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/processor3d/geometry2dextractor.hxx>
32*cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
33*cdf0e10cSrcweir #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
34*cdf0e10cSrcweir #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
35*cdf0e10cSrcweir #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
38*cdf0e10cSrcweir #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
39*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
40*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
41*cdf0e10cSrcweir #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir using namespace com::sun::star;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace drawinglayer
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	namespace processor3d
52*cdf0e10cSrcweir 	{
53*cdf0e10cSrcweir 		// as tooling, the process() implementation takes over API handling and calls this
54*cdf0e10cSrcweir 		// virtual render method when the primitive implementation is BasePrimitive3D-based.
55*cdf0e10cSrcweir 		void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
56*cdf0e10cSrcweir 		{
57*cdf0e10cSrcweir 			// it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
58*cdf0e10cSrcweir 			switch(rCandidate.getPrimitive3DID())
59*cdf0e10cSrcweir 			{
60*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
61*cdf0e10cSrcweir 				{
62*cdf0e10cSrcweir 					// transform group. Remember current transformations
63*cdf0e10cSrcweir 					const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
64*cdf0e10cSrcweir 					const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 					// create new transformation; add new object transform from right side
67*cdf0e10cSrcweir 					const geometry::ViewInformation3D aNewViewInformation3D(
68*cdf0e10cSrcweir 						aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
69*cdf0e10cSrcweir 						aLastViewInformation3D.getOrientation(),
70*cdf0e10cSrcweir 						aLastViewInformation3D.getProjection(),
71*cdf0e10cSrcweir 						aLastViewInformation3D.getDeviceToView(),
72*cdf0e10cSrcweir 						aLastViewInformation3D.getViewTime(),
73*cdf0e10cSrcweir 						aLastViewInformation3D.getExtendedInformationSequence());
74*cdf0e10cSrcweir 					updateViewInformation(aNewViewInformation3D);
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 					// let break down recursively
77*cdf0e10cSrcweir 					process(rPrimitive.getChildren());
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 					// restore transformations
80*cdf0e10cSrcweir 					updateViewInformation(aLastViewInformation3D);
81*cdf0e10cSrcweir 					break;
82*cdf0e10cSrcweir 				}
83*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D :
84*cdf0e10cSrcweir 				{
85*cdf0e10cSrcweir 					// ModifiedColorPrimitive3D; push, process and pop
86*cdf0e10cSrcweir 					const primitive3d::ModifiedColorPrimitive3D& rModifiedCandidate = static_cast< const primitive3d::ModifiedColorPrimitive3D& >(rCandidate);
87*cdf0e10cSrcweir 					const primitive3d::Primitive3DSequence& rSubSequence = rModifiedCandidate.getChildren();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 					if(rSubSequence.hasElements())
90*cdf0e10cSrcweir 					{
91*cdf0e10cSrcweir 						maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
92*cdf0e10cSrcweir 						process(rModifiedCandidate.getChildren());
93*cdf0e10cSrcweir 						maBColorModifierStack.pop();
94*cdf0e10cSrcweir 					}
95*cdf0e10cSrcweir 					break;
96*cdf0e10cSrcweir 				}
97*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
98*cdf0e10cSrcweir 				{
99*cdf0e10cSrcweir 					// PolygonHairlinePrimitive3D
100*cdf0e10cSrcweir 					const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate);
101*cdf0e10cSrcweir 					basegfx::B2DPolygon a2DHairline(basegfx::tools::createB2DPolygonFromB3DPolygon(rPrimitive.getB3DPolygon(), getViewInformation3D().getObjectToView()));
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 					if(a2DHairline.count())
104*cdf0e10cSrcweir 					{
105*cdf0e10cSrcweir 						a2DHairline.transform(getObjectTransformation());
106*cdf0e10cSrcweir 						const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getBColor()));
107*cdf0e10cSrcweir 						const primitive2d::Primitive2DReference xRef(new primitive2d::PolygonHairlinePrimitive2D(a2DHairline, aModifiedColor));
108*cdf0e10cSrcweir 						primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
109*cdf0e10cSrcweir 					}
110*cdf0e10cSrcweir 					break;
111*cdf0e10cSrcweir 				}
112*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
113*cdf0e10cSrcweir 				{
114*cdf0e10cSrcweir 					// PolyPolygonMaterialPrimitive3D
115*cdf0e10cSrcweir 					const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
116*cdf0e10cSrcweir 					basegfx::B2DPolyPolygon a2DFill(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive.getB3DPolyPolygon(), getViewInformation3D().getObjectToView()));
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 					if(a2DFill.count())
119*cdf0e10cSrcweir 					{
120*cdf0e10cSrcweir 						a2DFill.transform(getObjectTransformation());
121*cdf0e10cSrcweir 						const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getMaterial().getColor()));
122*cdf0e10cSrcweir 						const primitive2d::Primitive2DReference xRef(new primitive2d::PolyPolygonColorPrimitive2D(a2DFill, aModifiedColor));
123*cdf0e10cSrcweir 						primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
124*cdf0e10cSrcweir 					}
125*cdf0e10cSrcweir 					break;
126*cdf0e10cSrcweir 				}
127*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D :
128*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
129*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D :
130*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_TRANSPARENCETEXTUREPRIMITIVE3D :
131*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D :
132*cdf0e10cSrcweir 				{
133*cdf0e10cSrcweir 					// TexturePrimitive3D: Process children, do not try to decompose
134*cdf0e10cSrcweir 					const primitive3d::TexturePrimitive3D& rTexturePrimitive = static_cast< const primitive3d::TexturePrimitive3D& >(rCandidate);
135*cdf0e10cSrcweir 					const primitive3d::Primitive3DSequence aChildren(rTexturePrimitive.getChildren());
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 					if(aChildren.hasElements())
138*cdf0e10cSrcweir 					{
139*cdf0e10cSrcweir 						process(aChildren);
140*cdf0e10cSrcweir 					}
141*cdf0e10cSrcweir 					break;
142*cdf0e10cSrcweir 				}
143*cdf0e10cSrcweir 				case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D :
144*cdf0e10cSrcweir 				{
145*cdf0e10cSrcweir 					// accept but ignore labels and shadow; these should be extracted seperately
146*cdf0e10cSrcweir 					break;
147*cdf0e10cSrcweir 				}
148*cdf0e10cSrcweir 				default :
149*cdf0e10cSrcweir 				{
150*cdf0e10cSrcweir 					// process recursively
151*cdf0e10cSrcweir 					process(rCandidate.get3DDecomposition(getViewInformation3D()));
152*cdf0e10cSrcweir 					break;
153*cdf0e10cSrcweir 				}
154*cdf0e10cSrcweir 			}
155*cdf0e10cSrcweir 		}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		Geometry2DExtractingProcessor::Geometry2DExtractingProcessor(
158*cdf0e10cSrcweir 			const geometry::ViewInformation3D& rViewInformation,
159*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rObjectTransformation)
160*cdf0e10cSrcweir 		:	BaseProcessor3D(rViewInformation),
161*cdf0e10cSrcweir 			maPrimitive2DSequence(),
162*cdf0e10cSrcweir 			maObjectTransformation(rObjectTransformation),
163*cdf0e10cSrcweir 			maBColorModifierStack()
164*cdf0e10cSrcweir 		{
165*cdf0e10cSrcweir 		}
166*cdf0e10cSrcweir 	} // end of namespace processor3d
167*cdf0e10cSrcweir } // end of namespace drawinglayer
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
170*cdf0e10cSrcweir // eof
171