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