merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / contact / viewcontactofe3dextrude.cxx
blob954b54396a783977d6f1e45e3187c5e47e2fdd41
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofe3dextrude.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
36 #include <svx/extrud3d.hxx>
37 #include <drawinglayer/primitive3d/sdrextrudeprimitive3d.hxx>
38 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
39 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
40 #include <basegfx/polygon/b2dpolypolygontools.hxx>
42 //////////////////////////////////////////////////////////////////////////////
44 namespace sdr
46 namespace contact
48 ViewContactOfE3dExtrude::ViewContactOfE3dExtrude(E3dExtrudeObj& rExtrude)
49 : ViewContactOfE3d(rExtrude)
53 ViewContactOfE3dExtrude::~ViewContactOfE3dExtrude()
57 drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dExtrude::createViewIndependentPrimitive3DSequence() const
59 drawinglayer::primitive3d::Primitive3DSequence xRetval;
60 const SfxItemSet& rItemSet = GetE3dExtrudeObj().GetMergedItemSet();
61 drawinglayer::attribute::SdrLineFillShadowAttribute* pAttribute = drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false);
63 // for 3D Objects, always create a primitive even when not visible. This is necessary ATM
64 // since e.g. chart geometries rely on the occupied space of non-visible objects
65 if(!pAttribute)
67 pAttribute = new drawinglayer::attribute::SdrLineFillShadowAttribute(
68 impCreateFallbackLineAttribute(basegfx::BColor(0.0, 1.0, 0.0)),
69 0, 0, 0, 0);
72 // get extrude geometry
73 const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dExtrudeObj().GetExtrudePolygon());
75 // get 3D Object Attributes
76 drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
78 // calculate texture size; use size of top/bottom cap to get a perfect mapping
79 // for the caps. The in-between geometry will get a stretched size with a
80 // relative factor size of caps to extrude depth
81 const basegfx::B2DRange aRange(basegfx::tools::getRange(aPolyPolygon));
82 const basegfx::B2DVector aTextureSize(aRange.getWidth(), aRange.getHeight());
84 // get more data
85 const double fDepth((double)GetE3dExtrudeObj().GetExtrudeDepth());
86 const double fDiagonal((double)GetE3dExtrudeObj().GetPercentDiagonal() / 100.0);
87 const double fBackScale((double)GetE3dExtrudeObj().GetPercentBackScale() / 100.0);
88 const bool bSmoothNormals(GetE3dExtrudeObj().GetSmoothNormals()); // Plane itself
89 const bool bSmoothLids(GetE3dExtrudeObj().GetSmoothLids()); // Front/back
90 const bool bCharacterMode(GetE3dExtrudeObj().GetCharacterMode());
91 const bool bCloseFront(GetE3dExtrudeObj().GetCloseFront());
92 const bool bCloseBack(GetE3dExtrudeObj().GetCloseBack());
94 // create primitive and add
95 const basegfx::B3DHomMatrix aWorldTransform;
96 const drawinglayer::primitive3d::Primitive3DReference xReference(new drawinglayer::primitive3d::SdrExtrudePrimitive3D(
97 aWorldTransform, aTextureSize, *pAttribute, *pSdr3DObjectAttribute,
98 aPolyPolygon, fDepth, fDiagonal, fBackScale, bSmoothNormals, true, bSmoothLids,
99 bCharacterMode, bCloseFront, bCloseBack));
100 xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
102 // delete 3D Object Attributes
103 delete pSdr3DObjectAttribute;
104 delete pAttribute;
106 return xRetval;
108 } // end of namespace contact
109 } // end of namespace sdr
111 //////////////////////////////////////////////////////////////////////////////
112 // eof