xref: /trunk/main/drawinglayer/inc/drawinglayer/primitive3d/baseprimitive3d.hxx (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 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
29 #define INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
30 
31 #include <cppuhelper/compbase1.hxx>
32 #include <boost/utility.hpp>
33 #include <com/sun/star/graphic/XPrimitive3D.hpp>
34 #include <comphelper/broadcasthelper.hxx>
35 #include <basegfx/range/b3drange.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 /** defines for DeclPrimitrive3DIDBlock and ImplPrimitrive3DIDBlock
39     Added to be able to simply change identification stuff later, e.g. add
40     a identification string and/or ID to the interface and to the implementation
41     ATM used to delclare implement getPrimitive3DID()
42  */
43 
44 #define DeclPrimitrive3DIDBlock() \
45     virtual sal_uInt32 getPrimitive3DID() const;
46 
47 #define ImplPrimitrive3DIDBlock(TheClass, TheID) \
48     sal_uInt32 TheClass::getPrimitive3DID() const { return TheID; }
49 
50 //////////////////////////////////////////////////////////////////////////////
51 // predefines
52 
53 namespace drawinglayer { namespace geometry {
54     class ViewInformation3D;
55 }}
56 
57 namespace drawinglayer { namespace primitive3d {
58     /// typedefs for basePrimitive3DImplBase, Primitive3DSequence and Primitive3DReference
59     typedef cppu::WeakComponentImplHelper1< ::com::sun::star::graphic::XPrimitive3D > BasePrimitive3DImplBase;
60     typedef ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XPrimitive3D > Primitive3DReference;
61     typedef ::com::sun::star::uno::Sequence< Primitive3DReference > Primitive3DSequence;
62 }}
63 
64 //////////////////////////////////////////////////////////////////////////////
65 // basePrimitive3D class
66 
67 namespace drawinglayer
68 {
69     namespace primitive3d
70     {
71         /** BasePrimitive3D class
72 
73             Baseclass for all C++ implementations of com::sun::star::graphic::XPrimitive2D
74 
75             The description/functionality is identical with the 2D case in baseprimitive2d.hxx,
76             please see there for detailed information.
77 
78             Current Basic 3D Primitives are:
79 
80             - PolygonHairlinePrimitive3D (for 3D hairlines)
81             - PolyPolygonMaterialPrimitive3D (for 3D filled plane polygons)
82 
83             That's all for 3D!
84          */
85         class BasePrimitive3D
86         :   private boost::noncopyable,
87             protected comphelper::OBaseMutex,
88             public BasePrimitive3DImplBase
89         {
90         private:
91         protected:
92         public:
93             // constructor/destructor
94             BasePrimitive3D();
95             virtual ~BasePrimitive3D();
96 
97             /** the ==operator is mainly needed to allow testing newly-created high level primitives against their last
98                 incarnation which buffers/holds the decompositionsThe default implementation
99                 uses getPrimitive3DID()-calls to test if it's the same ID at last. Overloaded implementation are then
100                 based on this implementation.
101              */
102             virtual bool operator==( const BasePrimitive3D& rPrimitive ) const;
103             bool operator!=( const BasePrimitive3D& rPrimitive ) const { return !operator==(rPrimitive); }
104 
105             /** This method is for places where using the C++ implementation directly is possible. The subprocessing
106                 and range merging is more efficient when working directly on basegfx::B3DRange. The default implementation
107                 will use getDecomposition results to create the range
108              */
109             virtual basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D& rViewInformation) const;
110 
111             /** provide unique ID for fast identifying of known primitive implementations in renderers. These use
112                 the the defines from primitivetypes3d.hxx to define unique IDs.
113              */
114             virtual sal_uInt32 getPrimitive3DID() const = 0;
115 
116             /// The default implementation returns an empty sequence
117             virtual Primitive3DSequence get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const;
118 
119             //
120             // Methods from XPrimitive3D
121             //
122 
123             /** The getDecomposition implementation for UNO API will use getDecomposition from this implementation. It
124                 will get the ViewInformation from the ViewParameters for that purpose
125              */
126             virtual Primitive3DSequence SAL_CALL getDecomposition( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rViewParameters ) throw ( ::com::sun::star::uno::RuntimeException );
127 
128             /** the getRange default implemenation will use getDecomposition to create the range information from merging
129                 getRange results from the single local decomposition primitives.
130              */
131             virtual ::com::sun::star::geometry::RealRectangle3D SAL_CALL getRange( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rViewParameters ) throw ( ::com::sun::star::uno::RuntimeException );
132         };
133     } // end of namespace primitive3d
134 } // end of namespace drawinglayer
135 
136 //////////////////////////////////////////////////////////////////////////////
137 // BufferedDecompositionPrimitive3D class
138 
139 namespace drawinglayer
140 {
141     namespace primitive3d
142     {
143         /** BufferedDecompositionPrimitive3D class
144 
145             Baseclass for all C++ implementations of com::sun::star::graphic::XPrimitive2D
146 
147             The description/functionality is identical with the 2D case in baseprimitive2d.hxx,
148             please see there for detailed information
149          */
150         class BufferedDecompositionPrimitive3D
151         :   public BasePrimitive3D
152         {
153         private:
154             /// a sequence used for buffering the last create3DDecomposition() result
155             Primitive3DSequence                             maBuffered3DDecomposition;
156 
157         protected:
158             /** access methods to maBuffered3DDecomposition. The usage of this methods may allow
159                 later thread-safe stuff to be added if needed. Only to be used by getDecomposition()
160                 implementations for buffering the last decomposition.
161              */
162             const Primitive3DSequence& getBuffered3DDecomposition() const { return maBuffered3DDecomposition; }
163             void setBuffered3DDecomposition(const Primitive3DSequence& rNew) { maBuffered3DDecomposition = rNew; }
164 
165             /** method which is to be used to implement the local decomposition of a 2D primitive. The default
166                 implementation will just return an empty decomposition
167              */
168             virtual Primitive3DSequence create3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const;
169 
170         public:
171             // constructor
172             BufferedDecompositionPrimitive3D();
173 
174             /** The getDecomposition default implementation will on demand use create3DDecomposition() if
175                 maBuffered3DDecomposition is empty. It will set maBuffered3DDecomposition to this obtained decomposition
176                 to buffer it. If the decomposition is also ViewInformation-dependent, this method needs to be
177                 overloaded and the ViewInformation for the last decomposition needs to be remembered, too, and
178                 be used in the next call to decide if the buffered decomposition may be reused or not.
179              */
180             virtual Primitive3DSequence get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const;
181         };
182     } // end of namespace primitive3d
183 } // end of namespace drawinglayer
184 
185 //////////////////////////////////////////////////////////////////////////////
186 // tooling
187 
188 namespace drawinglayer
189 {
190     namespace primitive3d
191     {
192         /// get B3DRange from a given Primitive3DReference
193         basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation);
194 
195         /// get range3D from a given Primitive3DSequence
196         basegfx::B3DRange getB3DRangeFromPrimitive3DSequence(const Primitive3DSequence& rCandidate, const geometry::ViewInformation3D& aViewInformation);
197 
198         /** compare two Primitive2DReferences for equality, including trying to get implementations (BasePrimitive2D)
199             and using compare operator
200          */
201         bool arePrimitive3DReferencesEqual(const Primitive3DReference& rA, const Primitive3DReference& rB);
202 
203         /// compare two Primitive3DReferences for equality, uses arePrimitive3DReferencesEqual internally
204         bool arePrimitive3DSequencesEqual(const Primitive3DSequence& rA, const Primitive3DSequence& rB);
205 
206         /// concatenate sequence
207         void appendPrimitive3DSequenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DSequence& rSource);
208 
209         /// concatenate single Primitive3D
210         void appendPrimitive3DReferenceToPrimitive3DSequence(Primitive3DSequence& rDest, const Primitive3DReference& rSource);
211 
212     } // end of namespace primitive3d
213 } // end of namespace drawinglayer
214 
215 //////////////////////////////////////////////////////////////////////////////
216 
217 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
218 
219 //////////////////////////////////////////////////////////////////////////////
220 // eof
221