1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
32 #include <svx/lathe3d.hxx>
33 #include <drawinglayer/primitive3d/sdrlatheprimitive3d.hxx>
34 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
35 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace sdr
41 {
42 	namespace contact
43 	{
44 		ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj& rLathe)
45 		:	ViewContactOfE3d(rLathe)
46 		{
47 		}
48 
49 		ViewContactOfE3dLathe::~ViewContactOfE3dLathe()
50 		{
51 		}
52 
53 		drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dLathe::createViewIndependentPrimitive3DSequence() const
54 		{
55 			drawinglayer::primitive3d::Primitive3DSequence xRetval;
56 			const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet();
57 			const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
58 				drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
59 
60 			// get extrude geometry
61 			const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
62 
63 			// get 3D Object Attributes
64 			drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
65 
66 			// calculate texture size. Use the polygon length of the longest polygon for
67 			// height and the rotated radius for width (using polygon center) to get a good
68 			// texture mapping
69 			const sal_uInt32 nPolygonCount(aPolyPolygon.count());
70 			double fPolygonMaxLength(0.0);
71 
72 			for(sal_uInt32 a(0); a < nPolygonCount; a++)
73 			{
74 				const basegfx::B2DPolygon aCandidate(aPolyPolygon.getB2DPolygon(a));
75 				const double fPolygonLength(basegfx::tools::getLength(aCandidate));
76 				fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength);
77 			}
78 
79 			const basegfx::B2DRange aPolyPolygonRange(basegfx::tools::getRange(aPolyPolygon));
80 			const basegfx::B2DVector aTextureSize(
81 				F_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d
82 				fPolygonMaxLength);
83 
84 			// get more data
85 			const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
86 			const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
87 			const double fDiagonal((double)GetE3dLatheObj().GetPercentDiagonal() / 100.0);
88 			const double fBackScale((double)GetE3dLatheObj().GetBackScale() / 100.0);
89 			const double fRotation(((double)GetE3dLatheObj().GetEndAngle() / 1800.0) * F_PI);
90 			const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
91 			const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
92 			const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
93 			const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
94 			const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
95 
96 			// create primitive and add
97 			const basegfx::B3DHomMatrix aWorldTransform;
98 			const drawinglayer::primitive3d::Primitive3DReference xReference(
99 				new drawinglayer::primitive3d::SdrLathePrimitive3D(
100 					aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
101 					aPolyPolygon, nHorizontalSegments, nVerticalSegments,
102 					fDiagonal, fBackScale, fRotation,
103 					bSmoothNormals, true, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack));
104             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
105 
106 			// delete 3D Object Attributes
107 			delete pSdr3DObjectAttribute;
108 
109 			return xRetval;
110 		}
111 	} // end of namespace contact
112 } // end of namespace sdr
113 
114 //////////////////////////////////////////////////////////////////////////////
115 // eof
116