Update ooo320-m1
[ooovba.git] / svx / source / sdr / contact / viewcontactofe3dcube.cxx
blob8bde7b3c450d70ccbb1e3ed72d68fb7e8efae76a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofe3dcube.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewcontactofe3dcube.hxx>
36 #include <svx/cube3d.hxx>
37 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
38 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
39 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
40 #include <basegfx/range/b3drange.hxx>
42 //////////////////////////////////////////////////////////////////////////////
44 namespace sdr
46 namespace contact
48 ViewContactOfE3dCube::ViewContactOfE3dCube(E3dCubeObj& rCubeObj)
49 : ViewContactOfE3d(rCubeObj)
53 ViewContactOfE3dCube::~ViewContactOfE3dCube()
57 drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dCube::createViewIndependentPrimitive3DSequence() const
59 drawinglayer::primitive3d::Primitive3DSequence xRetval;
60 const SfxItemSet& rItemSet = GetE3dCubeObj().GetMergedItemSet();
61 drawinglayer::attribute::SdrLineFillShadowAttribute* pAttribute = drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false);
63 // for 3D Objects, always create a primitive even when not visible. This is necessary ATM
64 // since e.g. chart geometries rely on the occupied space of non-visible objects
65 if(!pAttribute)
67 pAttribute = new drawinglayer::attribute::SdrLineFillShadowAttribute(
68 impCreateFallbackLineAttribute(basegfx::BColor(0.0, 1.0, 0.0)),
69 0, 0, 0, 0);
72 // get cube geometry and use as traslation and scaling for unit cube
73 basegfx::B3DRange aCubeRange;
74 const basegfx::B3DVector aCubeSize(GetE3dCubeObj().GetCubeSize());
75 const basegfx::B3DPoint aCubePosition(GetE3dCubeObj().GetCubePos());
76 basegfx::B3DHomMatrix aWorldTransform;
78 if(GetE3dCubeObj().GetPosIsCenter())
80 const basegfx::B3DVector aHalfCubeSize(aCubeSize / 2.0);
81 aCubeRange.expand(aCubePosition - aHalfCubeSize);
82 aCubeRange.expand(aCubePosition + aHalfCubeSize);
84 else
86 aCubeRange.expand(aCubePosition);
87 aCubeRange.expand(aCubePosition + aCubeSize);
90 // add scale and translate to world transformation
91 const basegfx::B3DVector abjectRange(aCubeRange.getRange());
92 aWorldTransform.scale(abjectRange.getX(), abjectRange.getY(), abjectRange.getZ());
93 aWorldTransform.translate(aCubeRange.getMinX(), aCubeRange.getMinY(), aCubeRange.getMinZ());
95 // get 3D Object Attributes
96 drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
98 // calculate texture size to get a perfect mapping for
99 // the front/back sides
100 const basegfx::B2DVector aTextureSize(aCubeSize.getX(), aCubeSize.getY());
102 // create primitive and add
103 const drawinglayer::primitive3d::Primitive3DReference xReference(new drawinglayer::primitive3d::SdrCubePrimitive3D(aWorldTransform, aTextureSize, *pAttribute, *pSdr3DObjectAttribute));
104 xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
106 // delete 3D Object Attributes
107 delete pSdr3DObjectAttribute;
108 delete pAttribute;
110 return xRetval;
112 } // end of namespace contact
113 } // end of namespace sdr
115 //////////////////////////////////////////////////////////////////////////////
116 // eof