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
10*464702f4SAndrew Rist  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*464702f4SAndrew Rist  *
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.
19*464702f4SAndrew Rist  *
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/processor3d/geometry2dextractor.hxx>
28cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
34cdf0e10cSrcweir #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
35cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
36cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
37cdf0e10cSrcweir #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace com::sun::star;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace drawinglayer
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	namespace processor3d
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 		// as tooling, the process() implementation takes over API handling and calls this
50cdf0e10cSrcweir 		// virtual render method when the primitive implementation is BasePrimitive3D-based.
processBasePrimitive3D(const primitive3d::BasePrimitive3D & rCandidate)51cdf0e10cSrcweir 		void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
52cdf0e10cSrcweir 		{
53cdf0e10cSrcweir 			// it is a BasePrimitive3D implementation, use getPrimitive3DID() call for switch
54cdf0e10cSrcweir 			switch(rCandidate.getPrimitive3DID())
55cdf0e10cSrcweir 			{
56cdf0e10cSrcweir 				case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
57cdf0e10cSrcweir 				{
58cdf0e10cSrcweir 					// transform group. Remember current transformations
59cdf0e10cSrcweir 					const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
60cdf0e10cSrcweir 					const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 					// create new transformation; add new object transform from right side
63cdf0e10cSrcweir 					const geometry::ViewInformation3D aNewViewInformation3D(
64cdf0e10cSrcweir 						aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
65cdf0e10cSrcweir 						aLastViewInformation3D.getOrientation(),
66cdf0e10cSrcweir 						aLastViewInformation3D.getProjection(),
67cdf0e10cSrcweir 						aLastViewInformation3D.getDeviceToView(),
68cdf0e10cSrcweir 						aLastViewInformation3D.getViewTime(),
69cdf0e10cSrcweir 						aLastViewInformation3D.getExtendedInformationSequence());
70cdf0e10cSrcweir 					updateViewInformation(aNewViewInformation3D);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 					// let break down recursively
73cdf0e10cSrcweir 					process(rPrimitive.getChildren());
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 					// restore transformations
76cdf0e10cSrcweir 					updateViewInformation(aLastViewInformation3D);
77cdf0e10cSrcweir 					break;
78cdf0e10cSrcweir 				}
79cdf0e10cSrcweir 				case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D :
80cdf0e10cSrcweir 				{
81cdf0e10cSrcweir 					// ModifiedColorPrimitive3D; push, process and pop
82cdf0e10cSrcweir 					const primitive3d::ModifiedColorPrimitive3D& rModifiedCandidate = static_cast< const primitive3d::ModifiedColorPrimitive3D& >(rCandidate);
83cdf0e10cSrcweir 					const primitive3d::Primitive3DSequence& rSubSequence = rModifiedCandidate.getChildren();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 					if(rSubSequence.hasElements())
86cdf0e10cSrcweir 					{
87cdf0e10cSrcweir 						maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
88cdf0e10cSrcweir 						process(rModifiedCandidate.getChildren());
89cdf0e10cSrcweir 						maBColorModifierStack.pop();
90cdf0e10cSrcweir 					}
91cdf0e10cSrcweir 					break;
92cdf0e10cSrcweir 				}
93cdf0e10cSrcweir 				case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
94cdf0e10cSrcweir 				{
95cdf0e10cSrcweir 					// PolygonHairlinePrimitive3D
96cdf0e10cSrcweir 					const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate);
97cdf0e10cSrcweir 					basegfx::B2DPolygon a2DHairline(basegfx::tools::createB2DPolygonFromB3DPolygon(rPrimitive.getB3DPolygon(), getViewInformation3D().getObjectToView()));
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 					if(a2DHairline.count())
100cdf0e10cSrcweir 					{
101cdf0e10cSrcweir 						a2DHairline.transform(getObjectTransformation());
102cdf0e10cSrcweir 						const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getBColor()));
103cdf0e10cSrcweir 						const primitive2d::Primitive2DReference xRef(new primitive2d::PolygonHairlinePrimitive2D(a2DHairline, aModifiedColor));
104cdf0e10cSrcweir 						primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
105cdf0e10cSrcweir 					}
106cdf0e10cSrcweir 					break;
107cdf0e10cSrcweir 				}
108cdf0e10cSrcweir 				case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
109cdf0e10cSrcweir 				{
110cdf0e10cSrcweir 					// PolyPolygonMaterialPrimitive3D
111cdf0e10cSrcweir 					const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
112cdf0e10cSrcweir 					basegfx::B2DPolyPolygon a2DFill(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive.getB3DPolyPolygon(), getViewInformation3D().getObjectToView()));
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 					if(a2DFill.count())
115cdf0e10cSrcweir 					{
116cdf0e10cSrcweir 						a2DFill.transform(getObjectTransformation());
117cdf0e10cSrcweir 						const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getMaterial().getColor()));
118cdf0e10cSrcweir 						const primitive2d::Primitive2DReference xRef(new primitive2d::PolyPolygonColorPrimitive2D(a2DFill, aModifiedColor));
119cdf0e10cSrcweir 						primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
120cdf0e10cSrcweir 					}
121cdf0e10cSrcweir 					break;
122cdf0e10cSrcweir 				}
123cdf0e10cSrcweir 				case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D :
124cdf0e10cSrcweir 				case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
125cdf0e10cSrcweir 				case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D :
126cdf0e10cSrcweir 				case PRIMITIVE3D_ID_TRANSPARENCETEXTUREPRIMITIVE3D :
127cdf0e10cSrcweir 				case PRIMITIVE3D_ID_UNIFIEDTRANSPARENCETEXTUREPRIMITIVE3D :
128cdf0e10cSrcweir 				{
129cdf0e10cSrcweir 					// TexturePrimitive3D: Process children, do not try to decompose
130cdf0e10cSrcweir 					const primitive3d::TexturePrimitive3D& rTexturePrimitive = static_cast< const primitive3d::TexturePrimitive3D& >(rCandidate);
131cdf0e10cSrcweir 					const primitive3d::Primitive3DSequence aChildren(rTexturePrimitive.getChildren());
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 					if(aChildren.hasElements())
134cdf0e10cSrcweir 					{
135cdf0e10cSrcweir 						process(aChildren);
136cdf0e10cSrcweir 					}
137cdf0e10cSrcweir 					break;
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 				case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D :
140cdf0e10cSrcweir 				{
141cdf0e10cSrcweir 					// accept but ignore labels and shadow; these should be extracted seperately
142cdf0e10cSrcweir 					break;
143cdf0e10cSrcweir 				}
144cdf0e10cSrcweir 				default :
145cdf0e10cSrcweir 				{
146cdf0e10cSrcweir 					// process recursively
147cdf0e10cSrcweir 					process(rCandidate.get3DDecomposition(getViewInformation3D()));
148cdf0e10cSrcweir 					break;
149cdf0e10cSrcweir 				}
150cdf0e10cSrcweir 			}
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 
Geometry2DExtractingProcessor(const geometry::ViewInformation3D & rViewInformation,const basegfx::B2DHomMatrix & rObjectTransformation)153cdf0e10cSrcweir 		Geometry2DExtractingProcessor::Geometry2DExtractingProcessor(
154cdf0e10cSrcweir 			const geometry::ViewInformation3D& rViewInformation,
155cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rObjectTransformation)
156cdf0e10cSrcweir 		:	BaseProcessor3D(rViewInformation),
157cdf0e10cSrcweir 			maPrimitive2DSequence(),
158cdf0e10cSrcweir 			maObjectTransformation(rObjectTransformation),
159cdf0e10cSrcweir 			maBColorModifierStack()
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 	} // end of namespace processor3d
163cdf0e10cSrcweir } // end of namespace drawinglayer
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
166cdf0e10cSrcweir // eof
167