1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofe3dlathe.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/viewcontactofe3dlathe.hxx>
36 #include <svx/lathe3d.hxx>
37 #include <drawinglayer/primitive3d/sdrlatheprimitive3d.hxx>
38 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
39 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
42 //////////////////////////////////////////////////////////////////////////////
48 ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj
& rLathe
)
49 : ViewContactOfE3d(rLathe
)
53 ViewContactOfE3dLathe::~ViewContactOfE3dLathe()
57 drawinglayer::primitive3d::Primitive3DSequence
ViewContactOfE3dLathe::createViewIndependentPrimitive3DSequence() const
59 drawinglayer::primitive3d::Primitive3DSequence xRetval
;
60 const SfxItemSet
& rItemSet
= GetE3dLatheObj().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
67 pAttribute
= new drawinglayer::attribute::SdrLineFillShadowAttribute(
68 impCreateFallbackLineAttribute(basegfx::BColor(0.0, 1.0, 0.0)),
72 // get extrude geometry
73 const basegfx::B2DPolyPolygon
aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
75 // get 3D Object Attributes
76 drawinglayer::attribute::Sdr3DObjectAttribute
* pSdr3DObjectAttribute
= drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet
);
78 // calculate texture size. Use the polygon length of the longest polygon for
79 // height and the rotated radius for width (using polygon center) to get a good
81 const sal_uInt32
nPolygonCount(aPolyPolygon
.count());
82 double fPolygonMaxLength(0.0);
84 for(sal_uInt32
a(0); a
< nPolygonCount
; a
++)
86 const basegfx::B2DPolygon
aCandidate(aPolyPolygon
.getB2DPolygon(a
));
87 const double fPolygonLength(basegfx::tools::getLength(aCandidate
));
88 fPolygonMaxLength
= std::max(fPolygonMaxLength
, fPolygonLength
);
91 const basegfx::B2DRange
aPolyPolygonRange(basegfx::tools::getRange(aPolyPolygon
));
92 const basegfx::B2DVector
aTextureSize(
93 F_PI
* fabs(aPolyPolygonRange
.getCenter().getX()), // PI * d
97 const sal_uInt32
nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
98 const sal_uInt32
nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
99 const double fDiagonal((double)GetE3dLatheObj().GetPercentDiagonal() / 100.0);
100 const double fBackScale((double)GetE3dLatheObj().GetBackScale() / 100.0);
101 const double fRotation(((double)GetE3dLatheObj().GetEndAngle() / 1800.0) * F_PI
);
102 const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
103 const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
104 const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
105 const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
106 const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
108 // create primitive and add
109 const basegfx::B3DHomMatrix aWorldTransform
;
110 const drawinglayer::primitive3d::Primitive3DReference
xReference(new drawinglayer::primitive3d::SdrLathePrimitive3D(
111 aWorldTransform
, aTextureSize
, *pAttribute
, *pSdr3DObjectAttribute
,
112 aPolyPolygon
, nHorizontalSegments
, nVerticalSegments
,
113 fDiagonal
, fBackScale
, fRotation
,
114 bSmoothNormals
, true, bSmoothLids
, bCharacterMode
, bCloseFront
, bCloseBack
));
115 xRetval
= drawinglayer::primitive3d::Primitive3DSequence(&xReference
, 1);
117 // delete 3D Object Attributes
118 delete pSdr3DObjectAttribute
;
123 } // end of namespace contact
124 } // end of namespace sdr
126 //////////////////////////////////////////////////////////////////////////////