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::contact
31 {
33  : ViewContactOfE3d(rLathe)
34  {
35  }
36 
38  {
39  }
40 
42  {
44  const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet();
47 
48  // get extrude geometry
49  const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
50 
51  // get 3D Object Attributes
52  std::unique_ptr<drawinglayer::attribute::Sdr3DObjectAttribute> pSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
53 
54  // calculate texture size. Use the polygon length of the longest polygon for
55  // height and the rotated radius for width (using polygon center) to get a good
56  // texture mapping
57  double fPolygonMaxLength(0.0);
58 
59  for(auto const& rCandidate : aPolyPolygon)
60  {
61  const double fPolygonLength(basegfx::utils::getLength(rCandidate));
62  fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength);
63  }
64 
65  const basegfx::B2DRange aPolyPolygonRange(basegfx::utils::getRange(aPolyPolygon));
66  const basegfx::B2DVector aTextureSize(
67  F_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d
68  fPolygonMaxLength);
69 
70  // get more data
71  const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
72  const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
73  const double fDiagonal(static_cast<double>(GetE3dLatheObj().GetPercentDiagonal()) / 100.0);
74  const double fBackScale(static_cast<double>(GetE3dLatheObj().GetBackScale()) / 100.0);
75  const double fRotation((static_cast<double>(GetE3dLatheObj().GetEndAngle()) / 1800.0) * F_PI);
76  const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
77  const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
78  const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
79  const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
80  const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
81 
82  // create primitive and add
83  const basegfx::B3DHomMatrix aWorldTransform;
86  aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
87  aPolyPolygon, nHorizontalSegments, nVerticalSegments,
88  fDiagonal, fBackScale, fRotation,
89  bSmoothNormals, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack));
90  xRetval = { xReference };
91 
92  return xRetval;
93  }
94 
95 } // end of namespace
96 
97 /* 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:1889
double getLength(const B2DPolygon &rCandidate)
const E3dLatheObj & GetE3dLatheObj() const
virtual drawinglayer::primitive3d::Primitive3DContainer createViewIndependentPrimitive3DContainer() const override