1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX 21 #define INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX 22 23 #include <drawinglayer/drawinglayerdllapi.h> 24 25 #include <cppuhelper/compbase.hxx> 26 #include <cppuhelper/basemutex.hxx> 27 #include <com/sun/star/graphic/XPrimitive3D.hpp> 28 #include <basegfx/range/b3drange.hxx> 29 #include <deque> 30 31 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() 36 */ 37 38 #define DeclPrimitive3DIDBlock() \ 39 virtual sal_uInt32 getPrimitive3DID() const override; 40 41 #define ImplPrimitive3DIDBlock(TheClass, TheID) \ 42 sal_uInt32 TheClass::getPrimitive3DID() const { return TheID; } 43 44 45 // predefines 46 47 namespace drawinglayer::geometry { 48 class ViewInformation3D; 49 } 50 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; 55 56 class SAL_WARN_UNUSED DRAWINGLAYER_DLLPUBLIC Primitive3DContainer : public std::deque< Primitive3DReference > 57 { 58 public: Primitive3DContainer()59 explicit Primitive3DContainer() {} Primitive3DContainer(size_type count)60 explicit Primitive3DContainer( size_type count ) : deque(count) {} Primitive3DContainer(const Primitive3DContainer & other)61 Primitive3DContainer( const Primitive3DContainer& other ) : deque(other) {} Primitive3DContainer(Primitive3DContainer && other)62 Primitive3DContainer( Primitive3DContainer&& other ) noexcept : deque(std::move(other)) {} Primitive3DContainer(std::initializer_list<Primitive3DReference> init)63 Primitive3DContainer( std::initializer_list<Primitive3DReference> init ) : deque(init) {} 64 template <class Iter> Primitive3DContainer(Iter first,Iter last)65 Primitive3DContainer(Iter first, Iter last) : deque(first, last) {} 66 67 void append(const Primitive3DContainer& rSource); operator =(const Primitive3DContainer & r)68 Primitive3DContainer& operator=(const Primitive3DContainer& r) { deque::operator=(r); return *this; } operator =(Primitive3DContainer && r)69 Primitive3DContainer& operator=(Primitive3DContainer&& r) noexcept { deque::operator=(std::move(r)); return *this; } 70 bool operator==(const Primitive3DContainer& rB) const; operator !=(const Primitive3DContainer & rB) const71 bool operator!=(const Primitive3DContainer& rB) const { return !operator==(rB); } 72 basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D& aViewInformation) const; 73 }; 74 } 75 76 77 // basePrimitive3D class 78 79 namespace drawinglayer::primitive3d 80 { 81 /** BasePrimitive3D class 82 83 Baseclass for all C++ implementations of css::graphic::XPrimitive2D 84 85 The description/functionality is identical with the 2D case in baseprimitive2d.hxx, 86 please see there for detailed information. 87 88 Current Basic 3D Primitives are: 89 90 - PolygonHairlinePrimitive3D (for 3D hairlines) 91 - PolyPolygonMaterialPrimitive3D (for 3D filled plane polygons) 92 93 That's all for 3D! 94 */ 95 class DRAWINGLAYER_DLLPUBLIC BasePrimitive3D 96 : protected cppu::BaseMutex, 97 public BasePrimitive3DImplBase 98 { 99 BasePrimitive3D(const BasePrimitive3D&) = delete; 100 BasePrimitive3D& operator=( const BasePrimitive3D& ) = delete; 101 public: 102 // constructor/destructor 103 BasePrimitive3D(); 104 virtual ~BasePrimitive3D() override; 105 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. 110 */ 111 virtual bool operator==( const BasePrimitive3D& rPrimitive ) const; operator !=(const BasePrimitive3D & rPrimitive) const112 bool operator!=( const BasePrimitive3D& rPrimitive ) const { return !operator==(rPrimitive); } 113 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 117 */ 118 virtual basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D& rViewInformation) const; 119 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. 122 */ 123 virtual sal_uInt32 getPrimitive3DID() const = 0; 124 125 /// The default implementation returns an empty sequence 126 virtual Primitive3DContainer get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const; 127 128 129 // Methods from XPrimitive3D 130 131 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 134 */ 135 virtual css::uno::Sequence< ::css::uno::Reference< ::css::graphic::XPrimitive3D > > SAL_CALL getDecomposition( const css::uno::Sequence< css::beans::PropertyValue >& rViewParameters ) override; 136 137 /** the getRange default implementation will use getDecomposition to create the range information from merging 138 getRange results from the single local decomposition primitives. 139 */ 140 virtual css::geometry::RealRectangle3D SAL_CALL getRange( const css::uno::Sequence< css::beans::PropertyValue >& rViewParameters ) override; 141 }; 142 143 } // end of namespace drawinglayer::primitive2d 144 145 146 // BufferedDecompositionPrimitive3D class 147 148 namespace drawinglayer::primitive3d 149 { 150 /** BufferedDecompositionPrimitive3D class 151 152 Baseclass for all C++ implementations of css::graphic::XPrimitive2D 153 154 The description/functionality is identical with the 2D case in baseprimitive2d.hxx, 155 please see there for detailed information 156 */ 157 class DRAWINGLAYER_DLLPUBLIC BufferedDecompositionPrimitive3D 158 : public BasePrimitive3D 159 { 160 private: 161 /// a sequence used for buffering the last create3DDecomposition() result 162 Primitive3DContainer maBuffered3DDecomposition; 163 164 protected: 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. 168 */ getBuffered3DDecomposition() const169 const Primitive3DContainer& getBuffered3DDecomposition() const { return maBuffered3DDecomposition; } setBuffered3DDecomposition(const Primitive3DContainer & rNew)170 void setBuffered3DDecomposition(const Primitive3DContainer& rNew) { maBuffered3DDecomposition = rNew; } 171 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 174 */ 175 virtual Primitive3DContainer create3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const; 176 177 public: 178 // constructor 179 BufferedDecompositionPrimitive3D(); 180 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. 186 */ 187 virtual Primitive3DContainer get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const override; 188 }; 189 190 } // end of namespace drawinglayer::primitive3d 191 192 193 // tooling 194 195 namespace drawinglayer::primitive3d 196 { 197 /// get B3DRange from a given Primitive3DReference 198 basegfx::B3DRange DRAWINGLAYER_DLLPUBLIC getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation); 199 200 /** compare two Primitive2DReferences for equality, including trying to get implementations (BasePrimitive2D) 201 and using compare operator 202 */ 203 bool DRAWINGLAYER_DLLPUBLIC arePrimitive3DReferencesEqual(const Primitive3DReference& rA, const Primitive3DReference& rB); 204 205 } // end of namespace drawinglayer::primitive3d 206 207 208 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE3D_BASEPRIMITIVE3D_HXX 209 210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 211