1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
28 #include <svx/lathe3d.hxx>
29 #include <drawinglayer/primitive3d/sdrlatheprimitive3d.hxx>
30 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
31 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
32 #include <basegfx/polygon/b2dpolygontools.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace sdr
37 {
38 	namespace contact
39 	{
ViewContactOfE3dLathe(E3dLatheObj & rLathe)40 		ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj& rLathe)
41 		:	ViewContactOfE3d(rLathe)
42 		{
43 		}
44 
~ViewContactOfE3dLathe()45 		ViewContactOfE3dLathe::~ViewContactOfE3dLathe()
46 		{
47 		}
48 
createViewIndependentPrimitive3DSequence() const49 		drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dLathe::createViewIndependentPrimitive3DSequence() const
50 		{
51 			drawinglayer::primitive3d::Primitive3DSequence xRetval;
52 			const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet();
53 			const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
54 				drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
55 
56 			// get extrude geometry
57 			const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
58 
59 			// get 3D Object Attributes
60 			drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
61 
62 			// calculate texture size. Use the polygon length of the longest polygon for
63 			// height and the rotated radius for width (using polygon center) to get a good
64 			// texture mapping
65 			const sal_uInt32 nPolygonCount(aPolyPolygon.count());
66 			double fPolygonMaxLength(0.0);
67 
68 			for(sal_uInt32 a(0); a < nPolygonCount; a++)
69 			{
70 				const basegfx::B2DPolygon aCandidate(aPolyPolygon.getB2DPolygon(a));
71 				const double fPolygonLength(basegfx::tools::getLength(aCandidate));
72 				fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength);
73 			}
74 
75 			const basegfx::B2DRange aPolyPolygonRange(basegfx::tools::getRange(aPolyPolygon));
76 			const basegfx::B2DVector aTextureSize(
77 				F_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d
78 				fPolygonMaxLength);
79 
80 			// get more data
81 			const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
82 			const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
83 			const double fDiagonal((double)GetE3dLatheObj().GetPercentDiagonal() / 100.0);
84 			const double fBackScale((double)GetE3dLatheObj().GetBackScale() / 100.0);
85 			const double fRotation(((double)GetE3dLatheObj().GetEndAngle() / 1800.0) * F_PI);
86 			const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
87 			const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
88 			const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
89 			const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
90 			const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
91 
92 			// create primitive and add
93 			const basegfx::B3DHomMatrix aWorldTransform;
94 			const drawinglayer::primitive3d::Primitive3DReference xReference(
95 				new drawinglayer::primitive3d::SdrLathePrimitive3D(
96 					aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
97 					aPolyPolygon, nHorizontalSegments, nVerticalSegments,
98 					fDiagonal, fBackScale, fRotation,
99 					bSmoothNormals, true, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack));
100             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
101 
102 			// delete 3D Object Attributes
103 			delete pSdr3DObjectAttribute;
104 
105 			return xRetval;
106 		}
107 	} // end of namespace contact
108 } // end of namespace sdr
109 
110 //////////////////////////////////////////////////////////////////////////////
111 // eof
112