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/viewcontactofe3dextrude.hxx>
22 #include <extrud3d.hxx>
23 #include <drawinglayer/primitive3d/sdrextrudeprimitive3d.hxx>
24 #include <sdr/primitive2d/sdrattributecreator.hxx>
25 #include <sdr/primitive3d/sdrattributecreator3d.hxx>
26 #include <basegfx/polygon/b2dpolypolygontools.hxx>
27 #include <memory>
28 
29 
30 namespace sdr::contact
31 {
ViewContactOfE3dExtrude(E3dExtrudeObj & rExtrude)32         ViewContactOfE3dExtrude::ViewContactOfE3dExtrude(E3dExtrudeObj& rExtrude)
33         :   ViewContactOfE3d(rExtrude)
34         {
35         }
36 
~ViewContactOfE3dExtrude()37         ViewContactOfE3dExtrude::~ViewContactOfE3dExtrude()
38         {
39         }
40 
createViewIndependentPrimitive3DContainer() const41         drawinglayer::primitive3d::Primitive3DContainer ViewContactOfE3dExtrude::createViewIndependentPrimitive3DContainer() const
42         {
43             drawinglayer::primitive3d::Primitive3DContainer xRetval;
44             const SfxItemSet& rItemSet = GetE3dExtrudeObj().GetMergedItemSet();
45             const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
46                 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
47 
48             // get extrude geometry
49             const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dExtrudeObj().GetExtrudePolygon());
50 
51             // get 3D Object Attributes
52             std::unique_ptr<drawinglayer::attribute::Sdr3DObjectAttribute> pSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
53 
54             // calculate texture size; use size of top/bottom cap to get a perfect mapping
55             // for the caps. The in-between geometry will get a stretched size with a
56             // relative factor size of caps to extrude depth
57             const basegfx::B2DRange aRange(basegfx::utils::getRange(aPolyPolygon));
58             const basegfx::B2DVector aTextureSize(aRange.getWidth(), aRange.getHeight());
59 
60             // get more data
61             const double fDepth(static_cast<double>(GetE3dExtrudeObj().GetExtrudeDepth()));
62             const double fDiagonal(static_cast<double>(GetE3dExtrudeObj().GetPercentDiagonal()) / 100.0);
63             const double fBackScale(static_cast<double>(GetE3dExtrudeObj().GetPercentBackScale()) / 100.0);
64             const bool bSmoothNormals(GetE3dExtrudeObj().GetSmoothNormals()); // Plane itself
65             const bool bSmoothLids(GetE3dExtrudeObj().GetSmoothLids()); // Front/back
66             const bool bCharacterMode(GetE3dExtrudeObj().GetCharacterMode());
67             const bool bCloseFront(GetE3dExtrudeObj().GetCloseFront());
68             const bool bCloseBack(GetE3dExtrudeObj().GetCloseBack());
69 
70             // create primitive and add
71             const basegfx::B3DHomMatrix aWorldTransform;
72             const drawinglayer::primitive3d::Primitive3DReference xReference(
73                 new drawinglayer::primitive3d::SdrExtrudePrimitive3D(
74                     aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
75                     aPolyPolygon, fDepth, fDiagonal, fBackScale, bSmoothNormals, bSmoothLids,
76                     bCharacterMode, bCloseFront, bCloseBack));
77             xRetval = { xReference };
78 
79             return xRetval;
80         }
81 
82 } // end of namespace
83 
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
85