update dev300-m58
[ooovba.git] / drawinglayer / source / processor3d / geometry2dextractor.cxx
blob790ac05993f4f098cc60d1441f8d96aa7b249a63
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: geometry2dextractor.cxx,v $
7 * $Revision: 1.6 $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:09 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/processor3d/geometry2dextractor.hxx>
40 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
41 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
42 #include <drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx>
43 #include <drawinglayer/primitive3d/polygonprimitive3d.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
46 #include <drawinglayer/primitive3d/polypolygonprimitive3d.hxx>
47 #include <basegfx/polygon/b2dpolypolygontools.hxx>
48 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
49 #include <drawinglayer/primitive3d/textureprimitive3d.hxx>
51 //////////////////////////////////////////////////////////////////////////////
53 using namespace com::sun::star;
55 //////////////////////////////////////////////////////////////////////////////
57 namespace drawinglayer
59 namespace processor3d
61 // as tooling, the process() implementation takes over API handling and calls this
62 // virtual render method when the primitive implementation is BasePrimitive3D-based.
63 void Geometry2DExtractingProcessor::processBasePrimitive3D(const primitive3d::BasePrimitive3D& rCandidate)
65 // it is a BasePrimitive3D implementation, use getPrimitiveID() call for switch
66 switch(rCandidate.getPrimitiveID())
68 case PRIMITIVE3D_ID_TRANSFORMPRIMITIVE3D :
70 // transform group. Remember current transformations
71 const primitive3d::TransformPrimitive3D& rPrimitive = static_cast< const primitive3d::TransformPrimitive3D& >(rCandidate);
72 const geometry::ViewInformation3D aLastViewInformation3D(getViewInformation3D());
74 // create new transformation; add new object transform from right side
75 const geometry::ViewInformation3D aNewViewInformation3D(
76 aLastViewInformation3D.getObjectTransformation() * rPrimitive.getTransformation(),
77 aLastViewInformation3D.getOrientation(),
78 aLastViewInformation3D.getProjection(),
79 aLastViewInformation3D.getDeviceToView(),
80 aLastViewInformation3D.getViewTime(),
81 aLastViewInformation3D.getExtendedInformationSequence());
82 updateViewInformation(aNewViewInformation3D);
84 // let break down recursively
85 process(rPrimitive.getChildren());
87 // restore transformations
88 updateViewInformation(aLastViewInformation3D);
89 break;
91 case PRIMITIVE3D_ID_MODIFIEDCOLORPRIMITIVE3D :
93 // ModifiedColorPrimitive3D; push, process and pop
94 const primitive3d::ModifiedColorPrimitive3D& rModifiedCandidate = static_cast< const primitive3d::ModifiedColorPrimitive3D& >(rCandidate);
95 const primitive3d::Primitive3DSequence& rSubSequence = rModifiedCandidate.getChildren();
97 if(rSubSequence.hasElements())
99 maBColorModifierStack.push(rModifiedCandidate.getColorModifier());
100 process(rModifiedCandidate.getChildren());
101 maBColorModifierStack.pop();
103 break;
105 case PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D :
107 // PolygonHairlinePrimitive3D
108 const primitive3d::PolygonHairlinePrimitive3D& rPrimitive = static_cast< const primitive3d::PolygonHairlinePrimitive3D& >(rCandidate);
109 basegfx::B2DPolygon a2DHairline(basegfx::tools::createB2DPolygonFromB3DPolygon(rPrimitive.getB3DPolygon(), getViewInformation3D().getObjectToView()));
111 if(a2DHairline.count())
113 a2DHairline.transform(getObjectTransformation());
114 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getBColor()));
115 const primitive2d::Primitive2DReference xRef(new primitive2d::PolygonHairlinePrimitive2D(a2DHairline, aModifiedColor));
116 primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
118 break;
120 case PRIMITIVE3D_ID_POLYPOLYGONMATERIALPRIMITIVE3D :
122 // PolyPolygonMaterialPrimitive3D
123 const primitive3d::PolyPolygonMaterialPrimitive3D& rPrimitive = static_cast< const primitive3d::PolyPolygonMaterialPrimitive3D& >(rCandidate);
124 basegfx::B2DPolyPolygon a2DFill(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(rPrimitive.getB3DPolyPolygon(), getViewInformation3D().getObjectToView()));
126 if(a2DFill.count())
128 a2DFill.transform(getObjectTransformation());
129 const basegfx::BColor aModifiedColor(maBColorModifierStack.getModifiedColor(rPrimitive.getMaterial().getColor()));
130 const primitive2d::Primitive2DReference xRef(new primitive2d::PolyPolygonColorPrimitive2D(a2DFill, aModifiedColor));
131 primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(maPrimitive2DSequence, xRef);
133 break;
135 case PRIMITIVE3D_ID_GRADIENTTEXTUREPRIMITIVE3D :
136 case PRIMITIVE3D_ID_HATCHTEXTUREPRIMITIVE3D :
137 case PRIMITIVE3D_ID_BITMAPTEXTUREPRIMITIVE3D :
138 case PRIMITIVE3D_ID_ALPHATEXTUREPRIMITIVE3D :
139 case PRIMITIVE3D_ID_UNIFIEDALPHATEXTUREPRIMITIVE3D :
141 // TexturePrimitive3D: Process children, do not try to decompose
142 const primitive3d::TexturePrimitive3D& rTexturePrimitive = static_cast< const primitive3d::TexturePrimitive3D& >(rCandidate);
143 const primitive3d::Primitive3DSequence aChildren(rTexturePrimitive.getChildren());
145 if(aChildren.hasElements())
147 process(aChildren);
149 break;
151 case PRIMITIVE3D_ID_SHADOWPRIMITIVE3D :
153 // accept but ignore labels and shadow; these should be extracted seperately
154 break;
156 default :
158 // process recursively
159 process(rCandidate.get3DDecomposition(getViewInformation3D()));
160 break;
165 Geometry2DExtractingProcessor::Geometry2DExtractingProcessor(
166 const geometry::ViewInformation3D& rViewInformation,
167 const basegfx::B2DHomMatrix& rObjectTransformation)
168 : BaseProcessor3D(rViewInformation),
169 maPrimitive2DSequence(),
170 maObjectTransformation(rObjectTransformation),
171 maBColorModifierStack()
174 } // end of namespace processor3d
175 } // end of namespace drawinglayer
177 //////////////////////////////////////////////////////////////////////////////
178 // eof