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 #include <svx/e3dsceneupdater.hxx>
27 #include <drawinglayer/geometry/viewinformation3d.hxx>
28 #include <svx/obj3d.hxx>
29 #include <svx/scene3d.hxx>
30 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
31
32 //////////////////////////////////////////////////////////////////////////////
33
E3DModifySceneSnapRectUpdater(const SdrObject * pObject)34 E3DModifySceneSnapRectUpdater::E3DModifySceneSnapRectUpdater(const SdrObject* pObject)
35 : mpScene(0),
36 mpViewInformation3D(0)
37 {
38 // Secure old 3D transformation stack before modification
39 if(pObject)
40 {
41 const E3dObject* pE3dObject = dynamic_cast< const E3dObject* >(pObject);
42
43 if(pE3dObject)
44 {
45 mpScene = pE3dObject->GetScene();
46
47 if(mpScene && mpScene->GetScene() == mpScene)
48 {
49 // if there is a scene and it's the outmost scene, get current 3D range
50 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact());
51 const basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());
52
53 if(aAllContentRange.isEmpty())
54 {
55 // no content, nothing to do
56 mpScene = 0;
57 }
58 else
59 {
60 // secure current 3D transformation stack
61 mpViewInformation3D = new drawinglayer::geometry::ViewInformation3D(rVCScene.getViewInformation3D(aAllContentRange));
62 }
63 }
64 }
65 }
66 }
67
~E3DModifySceneSnapRectUpdater()68 E3DModifySceneSnapRectUpdater::~E3DModifySceneSnapRectUpdater()
69 {
70 if(mpScene && mpViewInformation3D)
71 {
72 // after changing parts of the scene, use the secured last 3d transformation stack and the new content
73 // range to calculate a new, eventually expanded or shrunk, 2D geometry for the scene and apply it.
74 // Get new content range
75 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact());
76 basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());
77
78 // only change when there is still content; else let scene stay at old SnapRect
79 if(!aAllContentRange.isEmpty())
80 {
81 // check if object transform of scene has changed
82 if(mpViewInformation3D->getObjectTransformation() != mpScene->GetTransform())
83 {
84 // If Yes, it needs to be updated since it's - for historical reasons -
85 // part of the basic 3d transformation stack of the scene
86 drawinglayer::geometry::ViewInformation3D* pNew = new drawinglayer::geometry::ViewInformation3D(
87 mpScene->GetTransform(), // replace object transformation with new local transform
88 mpViewInformation3D->getOrientation(),
89 mpViewInformation3D->getProjection(),
90 mpViewInformation3D->getDeviceToView(),
91 mpViewInformation3D->getViewTime(),
92 mpViewInformation3D->getExtendedInformationSequence());
93 delete mpViewInformation3D;
94 mpViewInformation3D = pNew;
95 }
96
97 // transform content range to scene-relative coordinates using old 3d transformation stack
98 aAllContentRange.transform(mpViewInformation3D->getObjectToView());
99
100 // build 2d relative content range
101 basegfx::B2DRange aSnapRange(
102 aAllContentRange.getMinX(), aAllContentRange.getMinY(),
103 aAllContentRange.getMaxX(), aAllContentRange.getMaxY());
104
105 // transform to 2D world coordiantes using scene's 2D transformation
106 aSnapRange.transform(rVCScene.getObjectTransformation());
107
108 // snap to (old) integer
109 const Rectangle aNewSnapRect(
110 sal_Int32(floor(aSnapRange.getMinX())), sal_Int32(floor(aSnapRange.getMinY())),
111 sal_Int32(ceil(aSnapRange.getMaxX())), sal_Int32(ceil(aSnapRange.getMaxY())));
112
113 // set as new SnapRect and invalidate bound volume
114 if(mpScene->GetSnapRect() != aNewSnapRect)
115 {
116 mpScene->SetSnapRect(aNewSnapRect);
117 mpScene->InvalidateBoundVolume();
118 }
119 }
120 }
121
122 delete mpViewInformation3D;
123 }
124
125 //////////////////////////////////////////////////////////////////////////////
126 // eof
127