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 #include <drawinglayer/primitive3d/baseprimitive3d.hxx> 21 #include <drawinglayer/geometry/viewinformation3d.hxx> 22 #include <basegfx/utils/canvastools.hxx> 23 #include <comphelper/sequence.hxx> 24 25 26 using namespace com::sun::star; 27 28 29 namespace drawinglayer 30 { 31 namespace primitive3d 32 { BasePrimitive3D()33 BasePrimitive3D::BasePrimitive3D() 34 : BasePrimitive3DImplBase(m_aMutex) 35 { 36 } 37 ~BasePrimitive3D()38 BasePrimitive3D::~BasePrimitive3D() 39 { 40 } 41 operator ==(const BasePrimitive3D & rPrimitive) const42 bool BasePrimitive3D::operator==( const BasePrimitive3D& rPrimitive ) const 43 { 44 return (getPrimitive3DID() == rPrimitive.getPrimitive3DID()); 45 } 46 getB3DRange(const geometry::ViewInformation3D & rViewInformation) const47 basegfx::B3DRange BasePrimitive3D::getB3DRange(const geometry::ViewInformation3D& rViewInformation) const 48 { 49 return get3DDecomposition(rViewInformation).getB3DRange(rViewInformation); 50 } 51 get3DDecomposition(const geometry::ViewInformation3D &) const52 Primitive3DContainer BasePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const 53 { 54 return Primitive3DContainer(); 55 } 56 getDecomposition(const uno::Sequence<beans::PropertyValue> & rViewParameters)57 css::uno::Sequence< ::css::uno::Reference< ::css::graphic::XPrimitive3D > > SAL_CALL BasePrimitive3D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) 58 { 59 const geometry::ViewInformation3D aViewInformation(rViewParameters); 60 return comphelper::containerToSequence(get3DDecomposition(aViewInformation)); 61 } 62 getRange(const uno::Sequence<beans::PropertyValue> & rViewParameters)63 css::geometry::RealRectangle3D SAL_CALL BasePrimitive3D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) 64 { 65 const geometry::ViewInformation3D aViewInformation(rViewParameters); 66 return basegfx::unotools::rectangle3DFromB3DRectangle(getB3DRange(aViewInformation)); 67 } 68 } // end of namespace primitive3d 69 } // end of namespace drawinglayer 70 71 72 namespace drawinglayer 73 { 74 namespace primitive3d 75 { create3DDecomposition(const geometry::ViewInformation3D &) const76 Primitive3DContainer BufferedDecompositionPrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const 77 { 78 return Primitive3DContainer(); 79 } 80 BufferedDecompositionPrimitive3D()81 BufferedDecompositionPrimitive3D::BufferedDecompositionPrimitive3D() 82 : BasePrimitive3D(), 83 maBuffered3DDecomposition() 84 { 85 } 86 get3DDecomposition(const geometry::ViewInformation3D & rViewInformation) const87 Primitive3DContainer BufferedDecompositionPrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const 88 { 89 ::osl::MutexGuard aGuard( m_aMutex ); 90 91 if(getBuffered3DDecomposition().empty()) 92 { 93 const Primitive3DContainer aNewSequence(create3DDecomposition(rViewInformation)); 94 const_cast< BufferedDecompositionPrimitive3D* >(this)->setBuffered3DDecomposition(aNewSequence); 95 } 96 97 return getBuffered3DDecomposition(); 98 } 99 } // end of namespace primitive3d 100 } // end of namespace drawinglayer 101 102 103 // tooling 104 105 namespace drawinglayer 106 { 107 namespace primitive3d 108 { 109 // get range3D from a given Primitive3DReference getB3DRangeFromPrimitive3DReference(const Primitive3DReference & rCandidate,const geometry::ViewInformation3D & aViewInformation)110 basegfx::B3DRange getB3DRangeFromPrimitive3DReference(const Primitive3DReference& rCandidate, const geometry::ViewInformation3D& aViewInformation) 111 { 112 basegfx::B3DRange aRetval; 113 114 if(rCandidate.is()) 115 { 116 // try to get C++ implementation base 117 const BasePrimitive3D* pCandidate(dynamic_cast< BasePrimitive3D* >(rCandidate.get())); 118 119 if(pCandidate) 120 { 121 // use it if possible 122 aRetval.expand(pCandidate->getB3DRange(aViewInformation)); 123 } 124 else 125 { 126 // use UNO API call instead 127 const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence()); 128 aRetval.expand(basegfx::unotools::b3DRectangleFromRealRectangle3D(rCandidate->getRange(rViewParameters))); 129 } 130 } 131 132 return aRetval; 133 } 134 135 // get range3D from a given Primitive3DContainer getB3DRange(const geometry::ViewInformation3D & aViewInformation) const136 basegfx::B3DRange Primitive3DContainer::getB3DRange(const geometry::ViewInformation3D& aViewInformation) const 137 { 138 basegfx::B3DRange aRetval; 139 140 if(!empty()) 141 { 142 const size_t nCount(size()); 143 144 for(size_t a(0); a < nCount; a++) 145 { 146 aRetval.expand(getB3DRangeFromPrimitive3DReference((*this)[a], aViewInformation)); 147 } 148 } 149 150 return aRetval; 151 } 152 arePrimitive3DReferencesEqual(const Primitive3DReference & rxA,const Primitive3DReference & rxB)153 bool arePrimitive3DReferencesEqual(const Primitive3DReference& rxA, const Primitive3DReference& rxB) 154 { 155 const bool bAIs(rxA.is()); 156 157 if(bAIs != rxB.is()) 158 { 159 return false; 160 } 161 162 if(!bAIs) 163 { 164 return true; 165 } 166 167 const BasePrimitive3D* pA(dynamic_cast< const BasePrimitive3D* >(rxA.get())); 168 const BasePrimitive3D* pB(dynamic_cast< const BasePrimitive3D* >(rxB.get())); 169 170 if(!pA || !pB) 171 { 172 return false; 173 } 174 175 return pA->operator==(*pB); 176 } 177 operator ==(const Primitive3DContainer & rB) const178 bool Primitive3DContainer::operator==(const Primitive3DContainer& rB) const 179 { 180 const bool bAHasElements(!empty()); 181 182 if(bAHasElements != !rB.empty()) 183 { 184 return false; 185 } 186 187 if(!bAHasElements) 188 { 189 return true; 190 } 191 192 const size_t nCount(size()); 193 194 if(nCount != rB.size()) 195 { 196 return false; 197 } 198 199 for(size_t a(0); a < nCount; a++) 200 { 201 if(!arePrimitive3DReferencesEqual((*this)[a], rB[a])) 202 { 203 return false; 204 } 205 } 206 207 return true; 208 } 209 append(const Primitive3DContainer & rSource)210 void Primitive3DContainer::append(const Primitive3DContainer& rSource) 211 { 212 insert(end(), rSource.begin(), rSource.end()); 213 } 214 215 } // end of namespace primitive3d 216 } // end of namespace drawinglayer 217 218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 219