/src/libreoffice/svx/source/sdr/contact/viewcontactofe3dlathe.cxx
Line | Count | Source |
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 | | |
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> |
27 | | |
28 | | |
29 | | namespace sdr::contact |
30 | | { |
31 | | ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj& rLathe) |
32 | 0 | : ViewContactOfE3d(rLathe) |
33 | 0 | { |
34 | 0 | } |
35 | | |
36 | | ViewContactOfE3dLathe::~ViewContactOfE3dLathe() |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | drawinglayer::primitive3d::Primitive3DContainer ViewContactOfE3dLathe::createViewIndependentPrimitive3DContainer() const |
41 | 0 | { |
42 | 0 | drawinglayer::primitive3d::Primitive3DContainer xRetval; |
43 | 0 | const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet(); |
44 | 0 | const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute( |
45 | 0 | drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false)); |
46 | | |
47 | | // get extrude geometry |
48 | 0 | basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D()); |
49 | | |
50 | | // get 3D Object Attributes |
51 | 0 | drawinglayer::attribute::Sdr3DObjectAttribute aSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet)); |
52 | | |
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 |
55 | | // texture mapping |
56 | 0 | double fPolygonMaxLength(0.0); |
57 | |
|
58 | 0 | for(auto const& rCandidate : aPolyPolygon) |
59 | 0 | { |
60 | 0 | const double fPolygonLength(basegfx::utils::getLength(rCandidate)); |
61 | 0 | fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength); |
62 | 0 | } |
63 | |
|
64 | 0 | const basegfx::B2DRange aPolyPolygonRange(aPolyPolygon.getB2DRange()); |
65 | 0 | const basegfx::B2DVector aTextureSize( |
66 | 0 | M_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d |
67 | 0 | fPolygonMaxLength); |
68 | | |
69 | | // get more data |
70 | 0 | const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments()); |
71 | 0 | const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments()); |
72 | 0 | const double fDiagonal(static_cast<double>(GetE3dLatheObj().GetPercentDiagonal()) / 100.0); |
73 | 0 | const double fBackScale(static_cast<double>(GetE3dLatheObj().GetBackScale()) / 100.0); |
74 | 0 | const double fRotation(basegfx::deg2rad<10>(GetE3dLatheObj().GetEndAngle())); |
75 | 0 | const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself |
76 | 0 | const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back |
77 | 0 | const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode()); |
78 | 0 | const bool bCloseFront(GetE3dLatheObj().GetCloseFront()); |
79 | 0 | const bool bCloseBack(GetE3dLatheObj().GetCloseBack()); |
80 | | |
81 | | // create primitive and add |
82 | 0 | const basegfx::B3DHomMatrix aWorldTransform; |
83 | 0 | const drawinglayer::primitive3d::Primitive3DReference xReference( |
84 | 0 | new drawinglayer::primitive3d::SdrLathePrimitive3D( |
85 | 0 | aWorldTransform, aTextureSize, aAttribute, aSdr3DObjectAttribute, |
86 | 0 | std::move(aPolyPolygon), nHorizontalSegments, nVerticalSegments, |
87 | 0 | fDiagonal, fBackScale, fRotation, |
88 | 0 | bSmoothNormals, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack)); |
89 | 0 | xRetval = { xReference }; |
90 | |
|
91 | 0 | return xRetval; |
92 | 0 | } |
93 | | |
94 | | } // end of namespace |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |