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/viewcontactofe3dcube.hxx>
28 #include <svx/cube3d.hxx>
29 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
30 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
31 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
32 #include <basegfx/range/b3drange.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace sdr
37 {
38 	namespace contact
39 	{
ViewContactOfE3dCube(E3dCubeObj & rCubeObj)40 		ViewContactOfE3dCube::ViewContactOfE3dCube(E3dCubeObj& rCubeObj)
41 		:	ViewContactOfE3d(rCubeObj)
42 		{
43 		}
44 
~ViewContactOfE3dCube()45 		ViewContactOfE3dCube::~ViewContactOfE3dCube()
46 		{
47 		}
48 
createViewIndependentPrimitive3DSequence() const49 		drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dCube::createViewIndependentPrimitive3DSequence() const
50 		{
51 			drawinglayer::primitive3d::Primitive3DSequence xRetval;
52 			const SfxItemSet& rItemSet = GetE3dCubeObj().GetMergedItemSet();
53 			const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
54 				drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
55 
56 			// get cube geometry and use as translation and scaling for unit cube
57 			basegfx::B3DRange aCubeRange;
58 			const basegfx::B3DVector aCubeSize(GetE3dCubeObj().GetCubeSize());
59 			const basegfx::B3DPoint aCubePosition(GetE3dCubeObj().GetCubePos());
60 			basegfx::B3DHomMatrix aWorldTransform;
61 
62 			if(GetE3dCubeObj().GetPosIsCenter())
63 			{
64 				const basegfx::B3DVector aHalfCubeSize(aCubeSize / 2.0);
65 				aCubeRange.expand(aCubePosition - aHalfCubeSize);
66 				aCubeRange.expand(aCubePosition + aHalfCubeSize);
67 			}
68 			else
69 			{
70 				aCubeRange.expand(aCubePosition);
71 				aCubeRange.expand(aCubePosition + aCubeSize);
72 			}
73 
74 			// add scale and translate to world transformation
75 			const basegfx::B3DVector abjectRange(aCubeRange.getRange());
76 			aWorldTransform.scale(abjectRange.getX(), abjectRange.getY(), abjectRange.getZ());
77 			aWorldTransform.translate(aCubeRange.getMinX(), aCubeRange.getMinY(), aCubeRange.getMinZ());
78 
79 			// get 3D Object Attributes
80 			drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
81 
82 			// calculate texture size to get a perfect mapping for
83 			// the front/back sides
84 			const basegfx::B2DVector aTextureSize(aCubeSize.getX(), aCubeSize.getY());
85 
86 			// create primitive and add
87 			const drawinglayer::primitive3d::Primitive3DReference xReference(
88 				new drawinglayer::primitive3d::SdrCubePrimitive3D(
89 					aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute));
90 			xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
91 
92 			// delete 3D Object Attributes
93 			delete pSdr3DObjectAttribute;
94 
95 			return xRetval;
96 		}
97 	} // end of namespace contact
98 } // end of namespace sdr
99 
100 //////////////////////////////////////////////////////////////////////////////
101 // eof
102