xref: /AOO41X/main/svx/source/sdr/contact/viewcontactofe3dextrude.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofe3dextrude.hxx>
28 #include <svx/extrud3d.hxx>
29 #include <drawinglayer/primitive3d/sdrextrudeprimitive3d.hxx>
30 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
31 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
32 #include <basegfx/polygon/b2dpolypolygontools.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace sdr
37 {
38     namespace contact
39     {
ViewContactOfE3dExtrude(E3dExtrudeObj & rExtrude)40         ViewContactOfE3dExtrude::ViewContactOfE3dExtrude(E3dExtrudeObj& rExtrude)
41         :   ViewContactOfE3d(rExtrude)
42         {
43         }
44 
~ViewContactOfE3dExtrude()45         ViewContactOfE3dExtrude::~ViewContactOfE3dExtrude()
46         {
47         }
48 
createViewIndependentPrimitive3DSequence() const49         drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dExtrude::createViewIndependentPrimitive3DSequence() const
50         {
51             drawinglayer::primitive3d::Primitive3DSequence xRetval;
52             const SfxItemSet& rItemSet = GetE3dExtrudeObj().GetMergedItemSet();
53             const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
54                 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
55 
56             // get extrude geometry
57             const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dExtrudeObj().GetExtrudePolygon());
58 
59             // get 3D Object Attributes
60             drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
61 
62             // calculate texture size; use size of top/bottom cap to get a perfect mapping
63             // for the caps. The in-between geometry will get a stretched size with a
64             // relative factor size of caps to extrude depth
65             const basegfx::B2DRange aRange(basegfx::tools::getRange(aPolyPolygon));
66             const basegfx::B2DVector aTextureSize(aRange.getWidth(), aRange.getHeight());
67 
68             // get more data
69             const double fDepth((double)GetE3dExtrudeObj().GetExtrudeDepth());
70             const double fDiagonal((double)GetE3dExtrudeObj().GetPercentDiagonal() / 100.0);
71             const double fBackScale((double)GetE3dExtrudeObj().GetPercentBackScale() / 100.0);
72             const bool bSmoothNormals(GetE3dExtrudeObj().GetSmoothNormals()); // Plane itself
73             const bool bSmoothLids(GetE3dExtrudeObj().GetSmoothLids()); // Front/back
74             const bool bCharacterMode(GetE3dExtrudeObj().GetCharacterMode());
75             const bool bCloseFront(GetE3dExtrudeObj().GetCloseFront());
76             const bool bCloseBack(GetE3dExtrudeObj().GetCloseBack());
77 
78             // create primitive and add
79             const basegfx::B3DHomMatrix aWorldTransform;
80             const drawinglayer::primitive3d::Primitive3DReference xReference(
81                 new drawinglayer::primitive3d::SdrExtrudePrimitive3D(
82                     aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
83                     aPolyPolygon, fDepth, fDiagonal, fBackScale, bSmoothNormals, true, bSmoothLids,
84                     bCharacterMode, bCloseFront, bCloseBack));
85             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
86 
87             // delete 3D Object Attributes
88             delete pSdr3DObjectAttribute;
89 
90             return xRetval;
91         }
92     } // end of namespace contact
93 } // end of namespace sdr
94 
95 //////////////////////////////////////////////////////////////////////////////
96 // eof
97