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