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