1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/primitive2d/baseprimitive2d.hxx> 28cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation2d.hxx> 29cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace com::sun::star; 34cdf0e10cSrcweir 35cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace drawinglayer 38cdf0e10cSrcweir { 39cdf0e10cSrcweir namespace primitive2d 40cdf0e10cSrcweir { BasePrimitive2D()41cdf0e10cSrcweir BasePrimitive2D::BasePrimitive2D() 42cdf0e10cSrcweir : BasePrimitive2DImplBase(m_aMutex) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir } 45cdf0e10cSrcweir ~BasePrimitive2D()46cdf0e10cSrcweir BasePrimitive2D::~BasePrimitive2D() 47cdf0e10cSrcweir { 48cdf0e10cSrcweir } 49cdf0e10cSrcweir operator ==(const BasePrimitive2D & rPrimitive) const50cdf0e10cSrcweir bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const 51cdf0e10cSrcweir { 52cdf0e10cSrcweir return (getPrimitive2DID() == rPrimitive.getPrimitive2DID()); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir getB2DRange(const geometry::ViewInformation2D & rViewInformation) const55cdf0e10cSrcweir basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 56cdf0e10cSrcweir { 57cdf0e10cSrcweir return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir get2DDecomposition(const geometry::ViewInformation2D &) const60cdf0e10cSrcweir Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 61cdf0e10cSrcweir { 62cdf0e10cSrcweir return Primitive2DSequence(); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir getDecomposition(const uno::Sequence<beans::PropertyValue> & rViewParameters)65cdf0e10cSrcweir Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir const geometry::ViewInformation2D aViewInformation(rViewParameters); 68cdf0e10cSrcweir return get2DDecomposition(aViewInformation); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir getRange(const uno::Sequence<beans::PropertyValue> & rViewParameters)71cdf0e10cSrcweir com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const geometry::ViewInformation2D aViewInformation(rViewParameters); 74cdf0e10cSrcweir return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation)); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir } // end of namespace primitive2d 77cdf0e10cSrcweir } // end of namespace drawinglayer 78cdf0e10cSrcweir 79cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 80cdf0e10cSrcweir 81cdf0e10cSrcweir namespace drawinglayer 82cdf0e10cSrcweir { 83cdf0e10cSrcweir namespace primitive2d 84cdf0e10cSrcweir { create2DDecomposition(const geometry::ViewInformation2D &) const85cdf0e10cSrcweir Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return Primitive2DSequence(); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir BufferedDecompositionPrimitive2D()90cdf0e10cSrcweir BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D() 91cdf0e10cSrcweir : BasePrimitive2D(), 92cdf0e10cSrcweir maBuffered2DDecomposition() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir } 95cdf0e10cSrcweir get2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const96cdf0e10cSrcweir Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 97cdf0e10cSrcweir { 98cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if(!getBuffered2DDecomposition().hasElements()) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation)); 103cdf0e10cSrcweir const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir return getBuffered2DDecomposition(); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir } // end of namespace primitive2d 109cdf0e10cSrcweir } // end of namespace drawinglayer 110cdf0e10cSrcweir 111cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 112cdf0e10cSrcweir // tooling 113cdf0e10cSrcweir 114cdf0e10cSrcweir namespace drawinglayer 115cdf0e10cSrcweir { 116cdf0e10cSrcweir namespace primitive2d 117cdf0e10cSrcweir { 118*ddde725dSArmin Le Grand // convert helper stl vector of primitives to Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector & rSource,bool bInvert)119*ddde725dSArmin Le Grand Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector& rSource, bool bInvert) 120*ddde725dSArmin Le Grand { 121*ddde725dSArmin Le Grand const sal_uInt32 nSize(rSource.size()); 122*ddde725dSArmin Le Grand Primitive2DSequence aRetval; 123*ddde725dSArmin Le Grand 124*ddde725dSArmin Le Grand aRetval.realloc(nSize); 125*ddde725dSArmin Le Grand 126*ddde725dSArmin Le Grand for(sal_uInt32 a(0); a < nSize; a++) 127*ddde725dSArmin Le Grand { 128*ddde725dSArmin Le Grand aRetval[bInvert ? nSize - 1 - a : a] = rSource[a]; 129*ddde725dSArmin Le Grand } 130*ddde725dSArmin Le Grand 131*ddde725dSArmin Le Grand // all entries taken over to Uno References as owners. To avoid 132*ddde725dSArmin Le Grand // errors with users of this mechanism to delete pointers to BasePrimitive2D 133*ddde725dSArmin Le Grand // itself, clear given vector 134*ddde725dSArmin Le Grand const_cast< Primitive2DVector& >(rSource).clear(); 135*ddde725dSArmin Le Grand 136*ddde725dSArmin Le Grand return aRetval; 137*ddde725dSArmin Le Grand } 138*ddde725dSArmin Le Grand 139cdf0e10cSrcweir // get B2DRange from a given Primitive2DReference getB2DRangeFromPrimitive2DReference(const Primitive2DReference & rCandidate,const geometry::ViewInformation2D & aViewInformation)140cdf0e10cSrcweir basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir basegfx::B2DRange aRetval; 143cdf0e10cSrcweir 144cdf0e10cSrcweir if(rCandidate.is()) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir // try to get C++ implementation base 147cdf0e10cSrcweir const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get())); 148cdf0e10cSrcweir 149cdf0e10cSrcweir if(pCandidate) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir // use it if possible 152cdf0e10cSrcweir aRetval.expand(pCandidate->getB2DRange(aViewInformation)); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir else 155cdf0e10cSrcweir { 156cdf0e10cSrcweir // use UNO API call instead 157cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence()); 158cdf0e10cSrcweir aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters))); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir return aRetval; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // get B2DRange from a given Primitive2DSequence getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence & rCandidate,const geometry::ViewInformation2D & aViewInformation)166cdf0e10cSrcweir basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir basegfx::B2DRange aRetval; 169cdf0e10cSrcweir 170cdf0e10cSrcweir if(rCandidate.hasElements()) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir const sal_Int32 nCount(rCandidate.getLength()); 173cdf0e10cSrcweir 174cdf0e10cSrcweir for(sal_Int32 a(0L); a < nCount; a++) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation)); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir return aRetval; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir arePrimitive2DReferencesEqual(const Primitive2DReference & rxA,const Primitive2DReference & rxB)183cdf0e10cSrcweir bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir const sal_Bool bAIs(rxA.is()); 186cdf0e10cSrcweir 187cdf0e10cSrcweir if(bAIs != rxB.is()) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir return false; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir if(!bAIs) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir return true; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get())); 198cdf0e10cSrcweir const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get())); 199cdf0e10cSrcweir const bool bAEqualZero(pA == 0L); 200cdf0e10cSrcweir 201cdf0e10cSrcweir if(bAEqualZero != (pB == 0L)) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir return false; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir if(bAEqualZero) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir return false; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir return (pA->operator==(*pB)); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir arePrimitive2DSequencesEqual(const Primitive2DSequence & rA,const Primitive2DSequence & rB)214cdf0e10cSrcweir bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir const sal_Bool bAHasElements(rA.hasElements()); 217cdf0e10cSrcweir 218cdf0e10cSrcweir if(bAHasElements != rB.hasElements()) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir return false; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir if(!bAHasElements) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir return true; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir const sal_Int32 nCount(rA.getLength()); 229cdf0e10cSrcweir 230cdf0e10cSrcweir if(nCount != rB.getLength()) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir return false; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir for(sal_Int32 a(0L); a < nCount; a++) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir if(!arePrimitive2DReferencesEqual(rA[a], rB[a])) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir return false; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir return true; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir // concatenate sequence appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence & rDest,const Primitive2DSequence & rSource)247cdf0e10cSrcweir void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if(rSource.hasElements()) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir if(rDest.hasElements()) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir const sal_Int32 nSourceCount(rSource.getLength()); 254cdf0e10cSrcweir const sal_Int32 nDestCount(rDest.getLength()); 255cdf0e10cSrcweir const sal_Int32 nTargetCount(nSourceCount + nDestCount); 256cdf0e10cSrcweir sal_Int32 nInsertPos(nDestCount); 257cdf0e10cSrcweir 258cdf0e10cSrcweir rDest.realloc(nTargetCount); 259cdf0e10cSrcweir 260cdf0e10cSrcweir for(sal_Int32 a(0L); a < nSourceCount; a++) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir if(rSource[a].is()) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir rDest[nInsertPos++] = rSource[a]; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir if(nInsertPos != nTargetCount) 269cdf0e10cSrcweir { 270cdf0e10cSrcweir rDest.realloc(nInsertPos); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir } 273cdf0e10cSrcweir else 274cdf0e10cSrcweir { 275cdf0e10cSrcweir rDest = rSource; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir // concatenate single Primitive2D appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence & rDest,const Primitive2DReference & rSource)281cdf0e10cSrcweir void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if(rSource.is()) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir const sal_Int32 nDestCount(rDest.getLength()); 286cdf0e10cSrcweir rDest.realloc(nDestCount + 1L); 287cdf0e10cSrcweir rDest[nDestCount] = rSource; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir } // end of namespace primitive2d 292cdf0e10cSrcweir } // end of namespace drawinglayer 293cdf0e10cSrcweir 294cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 295cdf0e10cSrcweir // eof 296