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/primitive3d/sdrextrudeprimitive3d.hxx> 28cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx> 29cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx> 31cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx> 32cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 33cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx> 34cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx> 35cdf0e10cSrcweir #include <drawinglayer/attribute/sdrfillattribute.hxx> 36cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlineattribute.hxx> 37cdf0e10cSrcweir #include <drawinglayer/attribute/sdrshadowattribute.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace com::sun::star; 42cdf0e10cSrcweir 43cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace drawinglayer 46cdf0e10cSrcweir { 47cdf0e10cSrcweir namespace primitive3d 48cdf0e10cSrcweir { create3DDecomposition(const geometry::ViewInformation3D & rViewInformation) const49cdf0e10cSrcweir Primitive3DSequence SdrExtrudePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const 50cdf0e10cSrcweir { 51cdf0e10cSrcweir Primitive3DSequence aRetval; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // get slices 54cdf0e10cSrcweir const Slice3DVector& rSliceVector = getSlices(); 55cdf0e10cSrcweir 56cdf0e10cSrcweir if(rSliceVector.size()) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir sal_uInt32 a; 59cdf0e10cSrcweir 60cdf0e10cSrcweir // decide what to create 61cdf0e10cSrcweir const ::com::sun::star::drawing::NormalsKind eNormalsKind(getSdr3DObjectAttribute().getNormalsKind()); 62cdf0e10cSrcweir const bool bCreateNormals(::com::sun::star::drawing::NormalsKind_SPECIFIC == eNormalsKind); 63cdf0e10cSrcweir const bool bCreateTextureCoordiantesX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX()); 64cdf0e10cSrcweir const bool bCreateTextureCoordiantesY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY()); 65cdf0e10cSrcweir double fRelativeTextureWidth(1.0); 66cdf0e10cSrcweir basegfx::B2DHomMatrix aTexTransform; 67cdf0e10cSrcweir 68cdf0e10cSrcweir if(!getSdrLFSAttribute().getFill().isDefault() && (bCreateTextureCoordiantesX || bCreateTextureCoordiantesY)) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir const basegfx::B2DPolygon aFirstPolygon(maCorrectedPolyPolygon.getB2DPolygon(0L)); 71cdf0e10cSrcweir const double fFrontLength(basegfx::tools::getLength(aFirstPolygon)); 72cdf0e10cSrcweir const double fFrontArea(basegfx::tools::getArea(aFirstPolygon)); 73cdf0e10cSrcweir const double fSqrtFrontArea(sqrt(fFrontArea)); 74cdf0e10cSrcweir fRelativeTextureWidth = basegfx::fTools::equalZero(fSqrtFrontArea) ? 1.0 : fFrontLength / fSqrtFrontArea; 75cdf0e10cSrcweir fRelativeTextureWidth = (double)((sal_uInt32)(fRelativeTextureWidth - 0.5)); 76cdf0e10cSrcweir 77cdf0e10cSrcweir if(fRelativeTextureWidth < 1.0) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir fRelativeTextureWidth = 1.0; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir aTexTransform.translate(-0.5, -0.5); 83cdf0e10cSrcweir aTexTransform.scale(-1.0, -1.0); 84cdf0e10cSrcweir aTexTransform.translate(0.5, 0.5); 85cdf0e10cSrcweir aTexTransform.scale(fRelativeTextureWidth, 1.0); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir // create geometry 89cdf0e10cSrcweir ::std::vector< basegfx::B3DPolyPolygon > aFill; 90cdf0e10cSrcweir extractPlanesFromSlice(aFill, rSliceVector, 91cdf0e10cSrcweir bCreateNormals, getSmoothHorizontalNormals(), getSmoothNormals(), getSmoothLids(), false, 92cdf0e10cSrcweir 0.5, 0.6, bCreateTextureCoordiantesX || bCreateTextureCoordiantesY, aTexTransform); 93cdf0e10cSrcweir 94cdf0e10cSrcweir // get full range 95cdf0e10cSrcweir const basegfx::B3DRange aRange(getRangeFrom3DGeometry(aFill)); 96cdf0e10cSrcweir 97cdf0e10cSrcweir // normal creation 98cdf0e10cSrcweir if(!getSdrLFSAttribute().getFill().isDefault()) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if(::com::sun::star::drawing::NormalsKind_SPHERE == eNormalsKind) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir applyNormalsKindSphereTo3DGeometry(aFill, aRange); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir else if(::com::sun::star::drawing::NormalsKind_FLAT == eNormalsKind) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir applyNormalsKindFlatTo3DGeometry(aFill); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir if(getSdr3DObjectAttribute().getNormalsInvert()) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir applyNormalsInvertTo3DGeometry(aFill); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir // texture coordinates 116cdf0e10cSrcweir if(!getSdrLFSAttribute().getFill().isDefault()) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir applyTextureTo3DGeometry( 119cdf0e10cSrcweir getSdr3DObjectAttribute().getTextureProjectionX(), 120cdf0e10cSrcweir getSdr3DObjectAttribute().getTextureProjectionY(), 121cdf0e10cSrcweir aFill, 122cdf0e10cSrcweir aRange, 123cdf0e10cSrcweir getTextureSize()); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir if(!getSdrLFSAttribute().getFill().isDefault()) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir // add fill 129cdf0e10cSrcweir aRetval = create3DPolyPolygonFillPrimitives( 130cdf0e10cSrcweir aFill, 131cdf0e10cSrcweir getTransform(), 132cdf0e10cSrcweir getTextureSize(), 133cdf0e10cSrcweir getSdr3DObjectAttribute(), 134cdf0e10cSrcweir getSdrLFSAttribute().getFill(), 135cdf0e10cSrcweir getSdrLFSAttribute().getFillFloatTransGradient()); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir else 138cdf0e10cSrcweir { 139cdf0e10cSrcweir // create simplified 3d hit test geometry 140cdf0e10cSrcweir aRetval = createHiddenGeometryPrimitives3D( 141cdf0e10cSrcweir aFill, 142cdf0e10cSrcweir getTransform(), 143cdf0e10cSrcweir getTextureSize(), 144cdf0e10cSrcweir getSdr3DObjectAttribute()); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir // add line 148cdf0e10cSrcweir if(!getSdrLFSAttribute().getLine().isDefault()) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir if(getSdr3DObjectAttribute().getReducedLineGeometry()) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir // create geometric outlines with reduced line geometry for chart. 153cdf0e10cSrcweir const basegfx::B3DPolyPolygon aVerLine(extractVerticalLinesFromSlice(rSliceVector)); 154cdf0e10cSrcweir const sal_uInt32 nCount(aVerLine.count()); 155cdf0e10cSrcweir basegfx::B3DPolyPolygon aReducedLoops; 156cdf0e10cSrcweir basegfx::B3DPolyPolygon aNewLineGeometry; 157cdf0e10cSrcweir 158cdf0e10cSrcweir // sort out doubles (front and back planes when no edge rounding is done). Since 159cdf0e10cSrcweir // this is a line geometry merged from PolyPolygons, loop over all Polygons 160cdf0e10cSrcweir for(a = 0; a < nCount; a++) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir const sal_uInt32 nReducedCount(aReducedLoops.count()); 163cdf0e10cSrcweir const basegfx::B3DPolygon aCandidate(aVerLine.getB3DPolygon(a)); 164cdf0e10cSrcweir bool bAdd(true); 165cdf0e10cSrcweir 166cdf0e10cSrcweir if(nReducedCount) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir for(sal_uInt32 b(0); bAdd && b < nReducedCount; b++) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if(aCandidate == aReducedLoops.getB3DPolygon(b)) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir bAdd = false; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir if(bAdd) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir aReducedLoops.append(aCandidate); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // from here work with reduced loops and reduced count without changing them 184cdf0e10cSrcweir const sal_uInt32 nReducedCount(aReducedLoops.count()); 185cdf0e10cSrcweir 186cdf0e10cSrcweir if(nReducedCount > 1) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir for(sal_uInt32 b(1); b < nReducedCount; b++) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir // get loop pair 191cdf0e10cSrcweir const basegfx::B3DPolygon aCandA(aReducedLoops.getB3DPolygon(b - 1)); 192cdf0e10cSrcweir const basegfx::B3DPolygon aCandB(aReducedLoops.getB3DPolygon(b)); 193cdf0e10cSrcweir 194cdf0e10cSrcweir // for each loop pair create the connection edges 195cdf0e10cSrcweir createReducedOutlines( 196cdf0e10cSrcweir rViewInformation, 197cdf0e10cSrcweir getTransform(), 198cdf0e10cSrcweir aCandA, 199cdf0e10cSrcweir aCandB, 200cdf0e10cSrcweir aNewLineGeometry); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir // add reduced loops themselves 205cdf0e10cSrcweir aNewLineGeometry.append(aReducedLoops); 206cdf0e10cSrcweir 207cdf0e10cSrcweir // to create vertical edges at non-C1/C2 steady loops, use maCorrectedPolyPolygon 208cdf0e10cSrcweir // directly since the 3D Polygons do not suport this. 209cdf0e10cSrcweir // 210cdf0e10cSrcweir // Unfortunately there is no bezier polygon provided by the chart module; one reason is 211cdf0e10cSrcweir // that the API for extrude wants a 3D polygon geometry (for historical reasons, i guess) 212cdf0e10cSrcweir // and those have no beziers. Another reason is that he chart module uses self-created 213cdf0e10cSrcweir // stuff to create the 2D geometry (in ShapeFactory::createPieSegment), but this geometry 214cdf0e10cSrcweir // does not contain bezier infos, either. The only way which is possible for now is to 'detect' 215cdf0e10cSrcweir // candidates for vertical edges of pie segments by looking for the angles in the polygon. 216cdf0e10cSrcweir // 217cdf0e10cSrcweir // This is all not very well designed ATM. Ideally, the ReducedLineGeometry is responsible 218cdf0e10cSrcweir // for creating the outer geometry edges (createReducedOutlines), but for special edges 219cdf0e10cSrcweir // like the vertical ones for pie center and both start/end, the incarnation with the 220cdf0e10cSrcweir // knowledge about that it needs to create those and IS a pie segment -> in this case, 221cdf0e10cSrcweir // the chart itself. 222cdf0e10cSrcweir const sal_uInt32 nPolyCount(maCorrectedPolyPolygon.count()); 223cdf0e10cSrcweir 224cdf0e10cSrcweir for(sal_uInt32 c(0); c < nPolyCount; c++) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir const basegfx::B2DPolygon aCandidate(maCorrectedPolyPolygon.getB2DPolygon(c)); 227cdf0e10cSrcweir const sal_uInt32 nPointCount(aCandidate.count()); 228cdf0e10cSrcweir 229cdf0e10cSrcweir if(nPointCount > 2) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir sal_uInt32 nIndexA(nPointCount); 232cdf0e10cSrcweir sal_uInt32 nIndexB(nPointCount); 233cdf0e10cSrcweir sal_uInt32 nIndexC(nPointCount); 234cdf0e10cSrcweir 235cdf0e10cSrcweir for(sal_uInt32 d(0); d < nPointCount; d++) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir const sal_uInt32 nPrevInd((d + nPointCount - 1) % nPointCount); 238cdf0e10cSrcweir const sal_uInt32 nNextInd((d + 1) % nPointCount); 239cdf0e10cSrcweir const basegfx::B2DPoint aPoint(aCandidate.getB2DPoint(d)); 240cdf0e10cSrcweir const basegfx::B2DVector aPrev(aCandidate.getB2DPoint(nPrevInd) - aPoint); 241cdf0e10cSrcweir const basegfx::B2DVector aNext(aCandidate.getB2DPoint(nNextInd) - aPoint); 242cdf0e10cSrcweir const double fAngle(aPrev.angle(aNext)); 243cdf0e10cSrcweir 244cdf0e10cSrcweir // take each angle which deviates more than 10% from going straight as 245cdf0e10cSrcweir // special edge. This will detect the two outer edges of pie segments, 246cdf0e10cSrcweir // but not always the center one (think about a near 180 degree pie) 247cdf0e10cSrcweir if(F_PI - fabs(fAngle) > F_PI * 0.1) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if(nPointCount == nIndexA) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir nIndexA = d; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir else if(nPointCount == nIndexB) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir nIndexB = d; 256cdf0e10cSrcweir } 257cdf0e10cSrcweir else if(nPointCount == nIndexC) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir nIndexC = d; 260cdf0e10cSrcweir d = nPointCount; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir } 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir const bool bIndexAUsed(nIndexA != nPointCount); 266cdf0e10cSrcweir const bool bIndexBUsed(nIndexB != nPointCount); 267cdf0e10cSrcweir bool bIndexCUsed(nIndexC != nPointCount); 268cdf0e10cSrcweir 269cdf0e10cSrcweir if(bIndexCUsed) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir // already three special edges found, so the center one was already detected 272cdf0e10cSrcweir // and does not need to be searched 273cdf0e10cSrcweir } 274cdf0e10cSrcweir else if(bIndexAUsed && bIndexBUsed) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // outer edges detected (they are approx. 90 degrees), but center one not. 277cdf0e10cSrcweir // Look with the knowledge that it's in-between the two found ones 278cdf0e10cSrcweir if(((nIndexA + 2) % nPointCount) == nIndexB) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir nIndexC = (nIndexA + 1) % nPointCount; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir else if(((nIndexA + nPointCount - 2) % nPointCount) == nIndexB) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir nIndexC = (nIndexA + nPointCount - 1) % nPointCount; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir bIndexCUsed = (nIndexC != nPointCount); 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir if(bIndexAUsed) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir const basegfx::B2DPoint aPoint(aCandidate.getB2DPoint(nIndexA)); 293cdf0e10cSrcweir const basegfx::B3DPoint aStart(aPoint.getX(), aPoint.getY(), 0.0); 294cdf0e10cSrcweir const basegfx::B3DPoint aEnd(aPoint.getX(), aPoint.getY(), getDepth()); 295cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 296cdf0e10cSrcweir 297cdf0e10cSrcweir aToBeAdded.append(aStart); 298cdf0e10cSrcweir aToBeAdded.append(aEnd); 299cdf0e10cSrcweir aNewLineGeometry.append(aToBeAdded); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir if(bIndexBUsed) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir const basegfx::B2DPoint aPoint(aCandidate.getB2DPoint(nIndexB)); 305cdf0e10cSrcweir const basegfx::B3DPoint aStart(aPoint.getX(), aPoint.getY(), 0.0); 306cdf0e10cSrcweir const basegfx::B3DPoint aEnd(aPoint.getX(), aPoint.getY(), getDepth()); 307cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 308cdf0e10cSrcweir 309cdf0e10cSrcweir aToBeAdded.append(aStart); 310cdf0e10cSrcweir aToBeAdded.append(aEnd); 311cdf0e10cSrcweir aNewLineGeometry.append(aToBeAdded); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir if(bIndexCUsed) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir const basegfx::B2DPoint aPoint(aCandidate.getB2DPoint(nIndexC)); 317cdf0e10cSrcweir const basegfx::B3DPoint aStart(aPoint.getX(), aPoint.getY(), 0.0); 318cdf0e10cSrcweir const basegfx::B3DPoint aEnd(aPoint.getX(), aPoint.getY(), getDepth()); 319cdf0e10cSrcweir basegfx::B3DPolygon aToBeAdded; 320cdf0e10cSrcweir 321cdf0e10cSrcweir aToBeAdded.append(aStart); 322cdf0e10cSrcweir aToBeAdded.append(aEnd); 323cdf0e10cSrcweir aNewLineGeometry.append(aToBeAdded); 324cdf0e10cSrcweir } 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // append loops themselves 329cdf0e10cSrcweir aNewLineGeometry.append(aReducedLoops); 330cdf0e10cSrcweir 331cdf0e10cSrcweir if(aNewLineGeometry.count()) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir const Primitive3DSequence aLines(create3DPolyPolygonLinePrimitives( 334cdf0e10cSrcweir aNewLineGeometry, getTransform(), getSdrLFSAttribute().getLine())); 335cdf0e10cSrcweir appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aLines); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir } 338cdf0e10cSrcweir else 339cdf0e10cSrcweir { 340cdf0e10cSrcweir // extract line geometry from slices 341cdf0e10cSrcweir const basegfx::B3DPolyPolygon aHorLine(extractHorizontalLinesFromSlice(rSliceVector, false)); 342cdf0e10cSrcweir const basegfx::B3DPolyPolygon aVerLine(extractVerticalLinesFromSlice(rSliceVector)); 343cdf0e10cSrcweir 344cdf0e10cSrcweir // add horizontal lines 345cdf0e10cSrcweir const Primitive3DSequence aHorLines(create3DPolyPolygonLinePrimitives( 346cdf0e10cSrcweir aHorLine, getTransform(), getSdrLFSAttribute().getLine())); 347cdf0e10cSrcweir appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aHorLines); 348cdf0e10cSrcweir 349cdf0e10cSrcweir // add vertical lines 350cdf0e10cSrcweir const Primitive3DSequence aVerLines(create3DPolyPolygonLinePrimitives( 351cdf0e10cSrcweir aVerLine, getTransform(), getSdrLFSAttribute().getLine())); 352cdf0e10cSrcweir appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aVerLines); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir // add shadow 357cdf0e10cSrcweir if(!getSdrLFSAttribute().getShadow().isDefault() && aRetval.hasElements()) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir const Primitive3DSequence aShadow(createShadowPrimitive3D( 360cdf0e10cSrcweir aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D())); 361cdf0e10cSrcweir appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aShadow); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir return aRetval; 366cdf0e10cSrcweir } 367cdf0e10cSrcweir impCreateSlices()368cdf0e10cSrcweir void SdrExtrudePrimitive3D::impCreateSlices() 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // prepare the polygon. No double points, correct orientations and a correct 371cdf0e10cSrcweir // outmost polygon are needed 372*080bd379SArmin Le Grand // Also important: subdivide here to ensure equal point count for all slices (!) 373*080bd379SArmin Le Grand maCorrectedPolyPolygon = basegfx::tools::adaptiveSubdivideByAngle(getPolyPolygon()); 374cdf0e10cSrcweir maCorrectedPolyPolygon.removeDoublePoints(); 375cdf0e10cSrcweir maCorrectedPolyPolygon = basegfx::tools::correctOrientations(maCorrectedPolyPolygon); 376cdf0e10cSrcweir maCorrectedPolyPolygon = basegfx::tools::correctOutmostPolygon(maCorrectedPolyPolygon); 377cdf0e10cSrcweir 378cdf0e10cSrcweir // prepare slices as geometry 379cdf0e10cSrcweir createExtrudeSlices(maSlices, maCorrectedPolyPolygon, getBackScale(), getDiagonal(), getDepth(), getCharacterMode(), getCloseFront(), getCloseBack()); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir getSlices() const382cdf0e10cSrcweir const Slice3DVector& SdrExtrudePrimitive3D::getSlices() const 383cdf0e10cSrcweir { 384cdf0e10cSrcweir // This can be made dependent of getSdrLFSAttribute().getFill() and getSdrLFSAttribute().getLine() 385cdf0e10cSrcweir // again when no longer geometry is needed for non-visible 3D objects as it is now for chart 386cdf0e10cSrcweir if(getPolyPolygon().count() && !maSlices.size()) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir ::osl::Mutex m_mutex; 389cdf0e10cSrcweir const_cast< SdrExtrudePrimitive3D& >(*this).impCreateSlices(); 390cdf0e10cSrcweir } 391cdf0e10cSrcweir 392cdf0e10cSrcweir return maSlices; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir SdrExtrudePrimitive3D(const basegfx::B3DHomMatrix & rTransform,const basegfx::B2DVector & rTextureSize,const attribute::SdrLineFillShadowAttribute3D & rSdrLFSAttribute,const attribute::Sdr3DObjectAttribute & rSdr3DObjectAttribute,const basegfx::B2DPolyPolygon & rPolyPolygon,double fDepth,double fDiagonal,double fBackScale,bool bSmoothNormals,bool bSmoothHorizontalNormals,bool bSmoothLids,bool bCharacterMode,bool bCloseFront,bool bCloseBack)395cdf0e10cSrcweir SdrExtrudePrimitive3D::SdrExtrudePrimitive3D( 396cdf0e10cSrcweir const basegfx::B3DHomMatrix& rTransform, 397cdf0e10cSrcweir const basegfx::B2DVector& rTextureSize, 398cdf0e10cSrcweir const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute, 399cdf0e10cSrcweir const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute, 400cdf0e10cSrcweir const basegfx::B2DPolyPolygon& rPolyPolygon, 401cdf0e10cSrcweir double fDepth, 402cdf0e10cSrcweir double fDiagonal, 403cdf0e10cSrcweir double fBackScale, 404cdf0e10cSrcweir bool bSmoothNormals, 405cdf0e10cSrcweir bool bSmoothHorizontalNormals, 406cdf0e10cSrcweir bool bSmoothLids, 407cdf0e10cSrcweir bool bCharacterMode, 408cdf0e10cSrcweir bool bCloseFront, 409cdf0e10cSrcweir bool bCloseBack) 410cdf0e10cSrcweir : SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute), 411cdf0e10cSrcweir maCorrectedPolyPolygon(), 412cdf0e10cSrcweir maSlices(), 413cdf0e10cSrcweir maPolyPolygon(rPolyPolygon), 414cdf0e10cSrcweir mfDepth(fDepth), 415cdf0e10cSrcweir mfDiagonal(fDiagonal), 416cdf0e10cSrcweir mfBackScale(fBackScale), 417cdf0e10cSrcweir mpLastRLGViewInformation(0), 418cdf0e10cSrcweir mbSmoothNormals(bSmoothNormals), 419cdf0e10cSrcweir mbSmoothHorizontalNormals(bSmoothHorizontalNormals), 420cdf0e10cSrcweir mbSmoothLids(bSmoothLids), 421cdf0e10cSrcweir mbCharacterMode(bCharacterMode), 422cdf0e10cSrcweir mbCloseFront(bCloseFront), 423cdf0e10cSrcweir mbCloseBack(bCloseBack) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir // make sure depth is positive 426cdf0e10cSrcweir if(basegfx::fTools::lessOrEqual(getDepth(), 0.0)) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir mfDepth = 0.0; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir // make sure the percentage value getDiagonal() is between 0.0 and 1.0 432cdf0e10cSrcweir if(basegfx::fTools::lessOrEqual(getDiagonal(), 0.0)) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir mfDiagonal = 0.0; 435cdf0e10cSrcweir } 436cdf0e10cSrcweir else if(basegfx::fTools::moreOrEqual(getDiagonal(), 1.0)) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir mfDiagonal = 1.0; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir // no close front/back when polygon is not closed 442cdf0e10cSrcweir if(getPolyPolygon().count() && !getPolyPolygon().getB2DPolygon(0L).isClosed()) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir mbCloseFront = mbCloseBack = false; 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir // no edge rounding when not closing 448cdf0e10cSrcweir if(!getCloseFront() && !getCloseBack()) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir mfDiagonal = 0.0; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir } 453cdf0e10cSrcweir ~SdrExtrudePrimitive3D()454cdf0e10cSrcweir SdrExtrudePrimitive3D::~SdrExtrudePrimitive3D() 455cdf0e10cSrcweir { 456cdf0e10cSrcweir if(mpLastRLGViewInformation) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir delete mpLastRLGViewInformation; 459cdf0e10cSrcweir } 460cdf0e10cSrcweir } 461cdf0e10cSrcweir operator ==(const BasePrimitive3D & rPrimitive) const462cdf0e10cSrcweir bool SdrExtrudePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const 463cdf0e10cSrcweir { 464cdf0e10cSrcweir if(SdrPrimitive3D::operator==(rPrimitive)) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir const SdrExtrudePrimitive3D& rCompare = static_cast< const SdrExtrudePrimitive3D& >(rPrimitive); 467cdf0e10cSrcweir 468cdf0e10cSrcweir return (getPolyPolygon() == rCompare.getPolyPolygon() 469cdf0e10cSrcweir && getDepth() == rCompare.getDepth() 470cdf0e10cSrcweir && getDiagonal() == rCompare.getDiagonal() 471cdf0e10cSrcweir && getBackScale() == rCompare.getBackScale() 472cdf0e10cSrcweir && getSmoothNormals() == rCompare.getSmoothNormals() 473cdf0e10cSrcweir && getSmoothHorizontalNormals() == rCompare.getSmoothHorizontalNormals() 474cdf0e10cSrcweir && getSmoothLids() == rCompare.getSmoothLids() 475cdf0e10cSrcweir && getCharacterMode() == rCompare.getCharacterMode() 476cdf0e10cSrcweir && getCloseFront() == rCompare.getCloseFront() 477cdf0e10cSrcweir && getCloseBack() == rCompare.getCloseBack()); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir return false; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir getB3DRange(const geometry::ViewInformation3D &) const483cdf0e10cSrcweir basegfx::B3DRange SdrExtrudePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const 484cdf0e10cSrcweir { 485cdf0e10cSrcweir // use defaut from sdrPrimitive3D which uses transformation expanded by line width/2 486cdf0e10cSrcweir // The parent implementation which uses the ranges of the decomposition would be more 487cdf0e10cSrcweir // corrcet, but for historical reasons it is necessary to do the old method: To get 488cdf0e10cSrcweir // the range of the non-transformed geometry and transform it then. This leads to different 489cdf0e10cSrcweir // ranges where the new method is more correct, but the need to keep the old behaviour 490cdf0e10cSrcweir // has priority here. 491cdf0e10cSrcweir return get3DRangeFromSlices(getSlices()); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir get3DDecomposition(const geometry::ViewInformation3D & rViewInformation) const494cdf0e10cSrcweir Primitive3DSequence SdrExtrudePrimitive3D::get3DDecomposition(const geometry::ViewInformation3D& rViewInformation) const 495cdf0e10cSrcweir { 496cdf0e10cSrcweir if(getSdr3DObjectAttribute().getReducedLineGeometry()) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir if(!mpLastRLGViewInformation || 499cdf0e10cSrcweir (getBuffered3DDecomposition().hasElements() 500cdf0e10cSrcweir && *mpLastRLGViewInformation != rViewInformation)) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir // conditions of last local decomposition with reduced lines have changed. Remember 503cdf0e10cSrcweir // new one and clear current decompositiopn 504cdf0e10cSrcweir ::osl::Mutex m_mutex; 505cdf0e10cSrcweir SdrExtrudePrimitive3D* pThat = const_cast< SdrExtrudePrimitive3D* >(this); 506cdf0e10cSrcweir pThat->setBuffered3DDecomposition(Primitive3DSequence()); 507cdf0e10cSrcweir delete pThat->mpLastRLGViewInformation; 508cdf0e10cSrcweir pThat->mpLastRLGViewInformation = new geometry::ViewInformation3D(rViewInformation); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir // no test for buffering needed, call parent 513cdf0e10cSrcweir return SdrPrimitive3D::get3DDecomposition(rViewInformation); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir // provide unique ID 517cdf0e10cSrcweir ImplPrimitrive3DIDBlock(SdrExtrudePrimitive3D, PRIMITIVE3D_ID_SDREXTRUDEPRIMITIVE3D) 518cdf0e10cSrcweir 519cdf0e10cSrcweir } // end of namespace primitive3d 520cdf0e10cSrcweir } // end of namespace drawinglayer 521cdf0e10cSrcweir 522cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 523cdf0e10cSrcweir // eof 524