1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
21 #define INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
23 #include <drawinglayer/drawinglayerdllapi.h>
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <com/sun/star/graphic/XPrimitive3D.hpp>
28 #include <basegfx/range/b3drange.hxx>
32 /** defines for DeclPrimitive3DIDBlock and ImplPrimitive3DIDBlock
33 Added to be able to simply change identification stuff later, e.g. add
34 an identification string and/or ID to the interface and to the implementation
35 ATM used to delclare implement getPrimitive3DID()
38 #define DeclPrimitive3DIDBlock() \
39 virtual sal_uInt32 getPrimitive3DID() const override;
41 #define ImplPrimitive3DIDBlock(TheClass, TheID) \
42 sal_uInt32 TheClass::getPrimitive3DID() const { return TheID; }
47 namespace drawinglayer::geometry
{
48 class ViewInformation3D
;
51 namespace drawinglayer::primitive3d
{
52 /// typedefs for basePrimitive3DImplBase, Primitive3DContainer and Primitive3DReference
53 typedef cppu::WeakComponentImplHelper
< css::graphic::XPrimitive3D
> BasePrimitive3DImplBase
;
54 typedef css::uno::Reference
< css::graphic::XPrimitive3D
> Primitive3DReference
;
56 class SAL_WARN_UNUSED DRAWINGLAYER_DLLPUBLIC Primitive3DContainer
: public std::deque
< Primitive3DReference
>
59 explicit Primitive3DContainer() {}
60 explicit Primitive3DContainer( size_type count
) : deque(count
) {}
61 Primitive3DContainer( const Primitive3DContainer
& other
) : deque(other
) {}
62 Primitive3DContainer( Primitive3DContainer
&& other
) noexcept
: deque(std::move(other
)) {}
63 Primitive3DContainer( std::initializer_list
<Primitive3DReference
> init
) : deque(init
) {}
65 Primitive3DContainer(Iter first
, Iter last
) : deque(first
, last
) {}
67 void append(const Primitive3DContainer
& rSource
);
68 Primitive3DContainer
& operator=(const Primitive3DContainer
& r
) { deque::operator=(r
); return *this; }
69 Primitive3DContainer
& operator=(Primitive3DContainer
&& r
) noexcept
{ deque::operator=(std::move(r
)); return *this; }
70 bool operator==(const Primitive3DContainer
& rB
) const;
71 bool operator!=(const Primitive3DContainer
& rB
) const { return !operator==(rB
); }
72 basegfx::B3DRange
getB3DRange(const geometry::ViewInformation3D
& aViewInformation
) const;
77 // basePrimitive3D class
79 namespace drawinglayer::primitive3d
81 /** BasePrimitive3D class
83 Baseclass for all C++ implementations of css::graphic::XPrimitive2D
85 The description/functionality is identical with the 2D case in baseprimitive2d.hxx,
86 please see there for detailed information.
88 Current Basic 3D Primitives are:
90 - PolygonHairlinePrimitive3D (for 3D hairlines)
91 - PolyPolygonMaterialPrimitive3D (for 3D filled plane polygons)
95 class DRAWINGLAYER_DLLPUBLIC BasePrimitive3D
96 : protected cppu::BaseMutex
,
97 public BasePrimitive3DImplBase
99 BasePrimitive3D(const BasePrimitive3D
&) = delete;
100 BasePrimitive3D
& operator=( const BasePrimitive3D
& ) = delete;
102 // constructor/destructor
104 virtual ~BasePrimitive3D() override
;
106 /** the ==operator is mainly needed to allow testing newly-created high level primitives against their last
107 incarnation which buffers/holds the decompositions. The default implementation
108 uses getPrimitive3DID()-calls to test if it's the same ID at last.
109 Overridden implementation are then based on this implementation.
111 virtual bool operator==( const BasePrimitive3D
& rPrimitive
) const;
112 bool operator!=( const BasePrimitive3D
& rPrimitive
) const { return !operator==(rPrimitive
); }
114 /** This method is for places where using the C++ implementation directly is possible. The subprocessing
115 and range merging is more efficient when working directly on basegfx::B3DRange. The default implementation
116 will use getDecomposition results to create the range
118 virtual basegfx::B3DRange
getB3DRange(const geometry::ViewInformation3D
& rViewInformation
) const;
120 /** provide unique ID for fast identifying of known primitive implementations in renderers. These use
121 the defines from primitivetypes3d.hxx to define unique IDs.
123 virtual sal_uInt32
getPrimitive3DID() const = 0;
125 /// The default implementation returns an empty sequence
126 virtual Primitive3DContainer
get3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const;
129 // Methods from XPrimitive3D
132 /** The getDecomposition implementation for UNO API will use getDecomposition from this implementation. It
133 will get the ViewInformation from the ViewParameters for that purpose
135 virtual css::uno::Sequence
< ::css::uno::Reference
< ::css::graphic::XPrimitive3D
> > SAL_CALL
getDecomposition( const css::uno::Sequence
< css::beans::PropertyValue
>& rViewParameters
) override
;
137 /** the getRange default implementation will use getDecomposition to create the range information from merging
138 getRange results from the single local decomposition primitives.
140 virtual css::geometry::RealRectangle3D SAL_CALL
getRange( const css::uno::Sequence
< css::beans::PropertyValue
>& rViewParameters
) override
;
143 } // end of namespace drawinglayer::primitive2d
146 // BufferedDecompositionPrimitive3D class
148 namespace drawinglayer::primitive3d
150 /** BufferedDecompositionPrimitive3D class
152 Baseclass for all C++ implementations of css::graphic::XPrimitive2D
154 The description/functionality is identical with the 2D case in baseprimitive2d.hxx,
155 please see there for detailed information
157 class DRAWINGLAYER_DLLPUBLIC BufferedDecompositionPrimitive3D
158 : public BasePrimitive3D
161 /// a sequence used for buffering the last create3DDecomposition() result
162 Primitive3DContainer maBuffered3DDecomposition
;
165 /** access methods to maBuffered3DDecomposition. The usage of this methods may allow
166 later thread-safe stuff to be added if needed. Only to be used by getDecomposition()
167 implementations for buffering the last decomposition.
169 const Primitive3DContainer
& getBuffered3DDecomposition() const { return maBuffered3DDecomposition
; }
170 void setBuffered3DDecomposition(const Primitive3DContainer
& rNew
) { maBuffered3DDecomposition
= rNew
; }
172 /** method which is to be used to implement the local decomposition of a 2D primitive. The default
173 implementation will just return an empty decomposition
175 virtual Primitive3DContainer
create3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const;
179 BufferedDecompositionPrimitive3D();
181 /** The getDecomposition default implementation will on demand use create3DDecomposition() if
182 maBuffered3DDecomposition is empty. It will set maBuffered3DDecomposition to this obtained decomposition
183 to buffer it. If the decomposition is also ViewInformation-dependent, this method needs to be
184 overridden and the ViewInformation for the last decomposition needs to be remembered, too, and
185 be used in the next call to decide if the buffered decomposition may be reused or not.
187 virtual Primitive3DContainer
get3DDecomposition(const geometry::ViewInformation3D
& rViewInformation
) const override
;
190 } // end of namespace drawinglayer::primitive3d
195 namespace drawinglayer::primitive3d
197 /// get B3DRange from a given Primitive3DReference
198 basegfx::B3DRange DRAWINGLAYER_DLLPUBLIC
getB3DRangeFromPrimitive3DReference(const Primitive3DReference
& rCandidate
, const geometry::ViewInformation3D
& aViewInformation
);
200 /** compare two Primitive2DReferences for equality, including trying to get implementations (BasePrimitive2D)
201 and using compare operator
203 bool DRAWINGLAYER_DLLPUBLIC
arePrimitive3DReferencesEqual(const Primitive3DReference
& rA
, const Primitive3DReference
& rB
);
205 } // end of namespace drawinglayer::primitive3d
208 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */