xref: /AOO41X/main/drawinglayer/inc/drawinglayer/primitive2d/sceneprimitive2d.hxx (revision 3b8558fd12b4776aa3c54a9fb2322537ca2a5e4c)
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 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
29 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
30 
31 #include <drawinglayer/drawinglayerdllapi.h>
32 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
33 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
34 #include <drawinglayer/geometry/viewinformation3d.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <vcl/bitmapex.hxx>
37 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
38 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
39 #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
40 
41 //////////////////////////////////////////////////////////////////////////////
42 
43 namespace drawinglayer
44 {
45     namespace primitive2d
46     {
47         /** ScenePrimitive2D class
48 
49             This primitive defines a 3D scene as a 2D primitive and is the anchor point
50             for a 3D visualisation. The decomposition is view-dependent and will try to
51             re-use already rendered 3D content.
52 
53             The rendering is done using the default-3D renderer from basegfx which supports
54             AntiAliasing.
55 
56             The 2D primitive's geometric range is defined completely by the
57             ObjectTransformation combined with evtl. 2D shadows from the 3D objects. The
58             shadows of 3D objects are 2D polygons, projected with the 3D transformation.
59 
60             This is the class a renderer may process directly when he wants to implement
61             an own (e.g. system-specific) 3D renderer.
62          */
63         class DRAWINGLAYER_DLLPUBLIC ScenePrimitive2D : public BufferedDecompositionPrimitive2D
64         {
65         private:
66             /// the 3D geometry definition
67             primitive3d::Primitive3DSequence                    mxChildren3D;
68 
69             /// 3D scene attribute set
70             attribute::SdrSceneAttribute                        maSdrSceneAttribute;
71 
72             /// lighting attribute set
73             attribute::SdrLightingAttribute                     maSdrLightingAttribute;
74 
75             /// object transformation for scene for 2D definition
76             basegfx::B2DHomMatrix                               maObjectTransformation;
77 
78             /// scene transformation set and object transformation
79             geometry::ViewInformation3D                         maViewInformation3D;
80 
81             /// the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked)
82             Primitive2DSequence                                 maShadowPrimitives;
83 
84             /// bitfield
85             /** flag if given 3D geometry is already cheched for shadow definitions and 2d shadows
86                 are created in maShadowPrimitives
87              */
88             unsigned                                            mbShadow3DChecked : 1;
89 
90             /// the last used NewDiscreteSize and NewUnitVisiblePart definitions for decomposition
91             double                                              mfOldDiscreteSizeX;
92             double                                              mfOldDiscreteSizeY;
93             basegfx::B2DRange                                   maOldUnitVisiblePart;
94 
95             /** the last created BitmapEx, e.g. for fast HitTest. This does not really need
96                 memory since BitmapEx is internally RefCounted
97              */
98             BitmapEx                                            maOldRenderedBitmap;
99 
100             /// private helpers
101             bool impGetShadow3D(const geometry::ViewInformation2D& rViewInformation) const;
102             void calculateDiscreteSizes(
103                 const geometry::ViewInformation2D& rViewInformation,
104                 basegfx::B2DRange& rDiscreteRange,
105                 basegfx::B2DRange& rVisibleDiscreteRange,
106                 basegfx::B2DRange& rUnitVisibleRange) const;
107 
108         protected:
109             /// local decomposition.
110             virtual Primitive2DSequence create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
111 
112         public:
113             /// public helpers
114             /** Geometry extractor. Shadow will be added as in create2DDecomposition, but
115                 the 3D content is not converted to a bitmap visualisation but to projected 2D gemetry. This
116                 helper is useful e.g. for Contour extraction or HitTests.
117               */
118             Primitive2DSequence getGeometry2D() const;
119             Primitive2DSequence getShadow2D(const geometry::ViewInformation2D& rViewInformation) const;
120 
121             /** Fast HitTest which uses the last buffered BitmapEx from the last
122                 rendered area if available. The return value describes if the check
123                 could be done with the current information, so do NOT use o_rResult
124                 when it returns false. o_rResult will be changed on return true and
125                 then contains a definitive answer if content of this scene is hit or
126                 not. On return false, it is normally necessary to use the geometric
127                 HitTest (see CutFindProcessor usages). The given HitPoint
128                 has to be in logic coordinates in scene's ObjectCoordinateSystem.
129              */
130             bool tryToCheckLastVisualisationDirectHit(const basegfx::B2DPoint& rLogicHitPoint, bool& o_rResult) const;
131 
132             /// constructor
133             ScenePrimitive2D(
134                 const primitive3d::Primitive3DSequence& rxChildren3D,
135                 const attribute::SdrSceneAttribute& rSdrSceneAttribute,
136                 const attribute::SdrLightingAttribute& rSdrLightingAttribute,
137                 const basegfx::B2DHomMatrix& rObjectTransformation,
138                 const geometry::ViewInformation3D& rViewInformation3D);
139 
140             /// data read access
141             const primitive3d::Primitive3DSequence& getChildren3D() const { return mxChildren3D; }
142             const attribute::SdrSceneAttribute& getSdrSceneAttribute() const { return maSdrSceneAttribute; }
143             const attribute::SdrLightingAttribute& getSdrLightingAttribute() const { return maSdrLightingAttribute; }
144             const basegfx::B2DHomMatrix& getObjectTransformation() const { return maObjectTransformation; }
145             const geometry::ViewInformation3D& getViewInformation3D() const { return maViewInformation3D; }
146 
147             /// compare operator
148             virtual bool operator==(const BasePrimitive2D& rPrimitive) const;
149 
150             /// get range
151             virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
152 
153             /// provide unique ID
154             DeclPrimitrive2DIDBlock()
155 
156             /// get local decomposition. Overloaded since this decomposition is view-dependent
157             virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
158         };
159     } // end of namespace primitive2d
160 } // end of namespace drawinglayer
161 
162 //////////////////////////////////////////////////////////////////////////////
163 
164 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
165 
166 //////////////////////////////////////////////////////////////////////////////
167 // eof
168