cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofe3dcube.cxx
blob2687aab32ff01ae82ca7236c3bdab6e851599c5d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/viewcontactofe3dcube.hxx>
22 #include <svx/cube3d.hxx>
23 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
24 #include <sdr/primitive2d/sdrattributecreator.hxx>
25 #include <sdr/primitive3d/sdrattributecreator3d.hxx>
26 #include <basegfx/range/b3drange.hxx>
29 namespace sdr::contact
31 ViewContactOfE3dCube::ViewContactOfE3dCube(E3dCubeObj& rCubeObj)
32 : ViewContactOfE3d(rCubeObj)
36 ViewContactOfE3dCube::~ViewContactOfE3dCube()
40 drawinglayer::primitive3d::Primitive3DContainer ViewContactOfE3dCube::createViewIndependentPrimitive3DContainer() const
42 drawinglayer::primitive3d::Primitive3DContainer xRetval;
43 const SfxItemSet& rItemSet = GetE3dCubeObj().GetMergedItemSet();
44 const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
45 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
47 // get cube geometry and use as translation and scaling for unit cube
48 basegfx::B3DRange aCubeRange;
49 const basegfx::B3DVector aCubeSize(GetE3dCubeObj().GetCubeSize());
50 const basegfx::B3DPoint aCubePosition(GetE3dCubeObj().GetCubePos());
51 basegfx::B3DHomMatrix aWorldTransform;
53 if(GetE3dCubeObj().GetPosIsCenter())
55 const basegfx::B3DVector aHalfCubeSize(aCubeSize / 2.0);
56 aCubeRange.expand(aCubePosition - aHalfCubeSize);
57 aCubeRange.expand(aCubePosition + aHalfCubeSize);
59 else
61 aCubeRange.expand(aCubePosition);
62 aCubeRange.expand(aCubePosition + aCubeSize);
65 // add scale and translate to world transformation
66 const basegfx::B3DVector abjectRange(aCubeRange.getRange());
67 aWorldTransform.scale(abjectRange.getX(), abjectRange.getY(), abjectRange.getZ());
68 aWorldTransform.translate(aCubeRange.getMinX(), aCubeRange.getMinY(), aCubeRange.getMinZ());
70 // get 3D Object Attributes
71 drawinglayer::attribute::Sdr3DObjectAttribute aSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
73 // calculate texture size to get a perfect mapping for
74 // the front/back sides
75 const basegfx::B2DVector aTextureSize(aCubeSize.getX(), aCubeSize.getY());
77 // create primitive and add
78 const drawinglayer::primitive3d::Primitive3DReference xReference(
79 new drawinglayer::primitive3d::SdrCubePrimitive3D(
80 aWorldTransform, aTextureSize, aAttribute, aSdr3DObjectAttribute));
81 xRetval = { xReference };
83 return xRetval;
86 } // end of namespace
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */