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/viewcontactofe3dextrude.hxx>
32 #include <svx/extrud3d.hxx>
33 #include <drawinglayer/primitive3d/sdrextrudeprimitive3d.hxx>
34 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
35 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 namespace sdr
41 {
42 	namespace contact
43 	{
44 		ViewContactOfE3dExtrude::ViewContactOfE3dExtrude(E3dExtrudeObj& rExtrude)
45 		:	ViewContactOfE3d(rExtrude)
46 		{
47 		}
48 
49 		ViewContactOfE3dExtrude::~ViewContactOfE3dExtrude()
50 		{
51 		}
52 
53 		drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dExtrude::createViewIndependentPrimitive3DSequence() const
54 		{
55 			drawinglayer::primitive3d::Primitive3DSequence xRetval;
56 			const SfxItemSet& rItemSet = GetE3dExtrudeObj().GetMergedItemSet();
57 			const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
58 				drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
59 
60 			// get extrude geometry
61 			const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dExtrudeObj().GetExtrudePolygon());
62 
63 			// get 3D Object Attributes
64 			drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
65 
66 			// calculate texture size; use size of top/bottom cap to get a perfect mapping
67 			// for the caps. The in-between geometry will get a stretched size with a
68 			// relative factor size of caps to extrude depth
69 			const basegfx::B2DRange aRange(basegfx::tools::getRange(aPolyPolygon));
70 			const basegfx::B2DVector aTextureSize(aRange.getWidth(), aRange.getHeight());
71 
72 			// get more data
73 			const double fDepth((double)GetE3dExtrudeObj().GetExtrudeDepth());
74 			const double fDiagonal((double)GetE3dExtrudeObj().GetPercentDiagonal() / 100.0);
75 			const double fBackScale((double)GetE3dExtrudeObj().GetPercentBackScale() / 100.0);
76 			const bool bSmoothNormals(GetE3dExtrudeObj().GetSmoothNormals()); // Plane itself
77 			const bool bSmoothLids(GetE3dExtrudeObj().GetSmoothLids()); // Front/back
78 			const bool bCharacterMode(GetE3dExtrudeObj().GetCharacterMode());
79 			const bool bCloseFront(GetE3dExtrudeObj().GetCloseFront());
80 			const bool bCloseBack(GetE3dExtrudeObj().GetCloseBack());
81 
82 			// create primitive and add
83 			const basegfx::B3DHomMatrix aWorldTransform;
84 			const drawinglayer::primitive3d::Primitive3DReference xReference(
85 				new drawinglayer::primitive3d::SdrExtrudePrimitive3D(
86 					aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
87 					aPolyPolygon, fDepth, fDiagonal, fBackScale, bSmoothNormals, true, bSmoothLids,
88 					bCharacterMode, bCloseFront, bCloseBack));
89             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
90 
91 			// delete 3D Object Attributes
92 			delete pSdr3DObjectAttribute;
93 
94 			return xRetval;
95 		}
96 	} // end of namespace contact
97 } // end of namespace sdr
98 
99 //////////////////////////////////////////////////////////////////////////////
100 // eof
101