LibreOffice Module svx (master)  1
viewcontactofe3dlathe.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 
22 #include <svx/lathe3d.hxx>
27 #include <memory>
28 
29 
30 namespace sdr
31 {
32  namespace contact
33  {
35  : ViewContactOfE3d(rLathe)
36  {
37  }
38 
40  {
41  }
42 
44  {
46  const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet();
49 
50  // get extrude geometry
51  const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
52 
53  // get 3D Object Attributes
54  std::unique_ptr<drawinglayer::attribute::Sdr3DObjectAttribute> pSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
55 
56  // calculate texture size. Use the polygon length of the longest polygon for
57  // height and the rotated radius for width (using polygon center) to get a good
58  // texture mapping
59  double fPolygonMaxLength(0.0);
60 
61  for(auto const& rCandidate : aPolyPolygon)
62  {
63  const double fPolygonLength(basegfx::utils::getLength(rCandidate));
64  fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength);
65  }
66 
67  const basegfx::B2DRange aPolyPolygonRange(basegfx::utils::getRange(aPolyPolygon));
68  const basegfx::B2DVector aTextureSize(
69  F_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d
70  fPolygonMaxLength);
71 
72  // get more data
73  const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
74  const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
75  const double fDiagonal(static_cast<double>(GetE3dLatheObj().GetPercentDiagonal()) / 100.0);
76  const double fBackScale(static_cast<double>(GetE3dLatheObj().GetBackScale()) / 100.0);
77  const double fRotation((static_cast<double>(GetE3dLatheObj().GetEndAngle()) / 1800.0) * F_PI);
78  const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
79  const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
80  const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
81  const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
82  const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
83 
84  // create primitive and add
85  const basegfx::B3DHomMatrix aWorldTransform;
88  aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
89  aPolyPolygon, nHorizontalSegments, nVerticalSegments,
90  fDiagonal, fBackScale, fRotation,
91  bSmoothNormals, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack));
92  xRetval = { xReference };
93 
94  return xRetval;
95  }
96  } // end of namespace contact
97 } // end of namespace sdr
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
B2DPoint getCenter() const
double getX() const
attribute::Sdr3DObjectAttribute * createNewSdr3DObjectAttribute(const SfxItemSet &rSet)
attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet &rSet, bool bSuppressFill)
#define F_PI
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference
B2DRange getRange(const B2DPolygon &rCandidate)
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1911
double getLength(const B2DPolygon &rCandidate)
const E3dLatheObj & GetE3dLatheObj() const
virtual drawinglayer::primitive3d::Primitive3DContainer createViewIndependentPrimitive3DContainer() const override