1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sdr/contact/viewcontactofe3dlathe.hxx>
22 #include <svx/lathe3d.hxx>
23 #include <drawinglayer/primitive3d/sdrlatheprimitive3d.hxx>
24 #include <sdr/primitive2d/sdrattributecreator.hxx>
25 #include <sdr/primitive3d/sdrattributecreator3d.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
29 namespace sdr::contact
31 ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj
& rLathe
)
32 : ViewContactOfE3d(rLathe
)
36 ViewContactOfE3dLathe::~ViewContactOfE3dLathe()
40 drawinglayer::primitive3d::Primitive3DContainer
ViewContactOfE3dLathe::createViewIndependentPrimitive3DContainer() const
42 drawinglayer::primitive3d::Primitive3DContainer xRetval
;
43 const SfxItemSet
& rItemSet
= GetE3dLatheObj().GetMergedItemSet();
44 const drawinglayer::attribute::SdrLineFillShadowAttribute3D
aAttribute(
45 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet
, false));
47 // get extrude geometry
48 basegfx::B2DPolyPolygon
aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
50 // get 3D Object Attributes
51 drawinglayer::attribute::Sdr3DObjectAttribute
aSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet
));
53 // calculate texture size. Use the polygon length of the longest polygon for
54 // height and the rotated radius for width (using polygon center) to get a good
56 double fPolygonMaxLength(0.0);
58 for(auto const& rCandidate
: aPolyPolygon
)
60 const double fPolygonLength(basegfx::utils::getLength(rCandidate
));
61 fPolygonMaxLength
= std::max(fPolygonMaxLength
, fPolygonLength
);
64 const basegfx::B2DRange
aPolyPolygonRange(basegfx::utils::getRange(aPolyPolygon
));
65 const basegfx::B2DVector
aTextureSize(
66 M_PI
* fabs(aPolyPolygonRange
.getCenter().getX()), // PI * d
70 const sal_uInt32
nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
71 const sal_uInt32
nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
72 const double fDiagonal(static_cast<double>(GetE3dLatheObj().GetPercentDiagonal()) / 100.0);
73 const double fBackScale(static_cast<double>(GetE3dLatheObj().GetBackScale()) / 100.0);
74 const double fRotation(basegfx::deg2rad
<10>(GetE3dLatheObj().GetEndAngle()));
75 const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
76 const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
77 const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
78 const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
79 const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
81 // create primitive and add
82 const basegfx::B3DHomMatrix aWorldTransform
;
83 const drawinglayer::primitive3d::Primitive3DReference
xReference(
84 new drawinglayer::primitive3d::SdrLathePrimitive3D(
85 aWorldTransform
, aTextureSize
, aAttribute
, aSdr3DObjectAttribute
,
86 std::move(aPolyPolygon
), nHorizontalSegments
, nVerticalSegments
,
87 fDiagonal
, fBackScale
, fRotation
,
88 bSmoothNormals
, bSmoothLids
, bCharacterMode
, bCloseFront
, bCloseBack
));
89 xRetval
= { xReference
};
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */