1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <svx/e3dsceneupdater.hxx>
21 #include <drawinglayer/geometry/viewinformation3d.hxx>
22 #include <svx/obj3d.hxx>
23 #include <svx/scene3d.hxx>
24 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
27 E3DModifySceneSnapRectUpdater::E3DModifySceneSnapRectUpdater(const SdrObject
* pObject
)
30 // Secure old 3D transformation stack before modification
31 if(const E3dObject
* pE3dObject
= dynamic_cast< const E3dObject
* >(pObject
))
33 mpScene
= pE3dObject
->getRootE3dSceneFromE3dObject();
35 if(nullptr != mpScene
&& mpScene
->getRootE3dSceneFromE3dObject() == mpScene
)
37 // if there is a scene and it's the outmost scene, get current 3D range
38 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(mpScene
->GetViewContact());
39 const basegfx::B3DRange
aAllContentRange(rVCScene
.getAllContentRange3D());
41 if(aAllContentRange
.isEmpty())
43 // no content, nothing to do
48 // secure current 3D transformation stack
49 mpViewInformation3D
.reset(
50 new drawinglayer::geometry::ViewInformation3D(
51 rVCScene
.getViewInformation3D(aAllContentRange
)));
57 E3DModifySceneSnapRectUpdater::~E3DModifySceneSnapRectUpdater()
59 if(mpScene
&& mpViewInformation3D
)
61 // after changing parts of the scene, use the secured last 3d transformation stack and the new content
62 // range to calculate a new, eventually expanded or shrunk, 2D geometry for the scene and apply it.
63 // Get new content range
64 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(mpScene
->GetViewContact());
65 basegfx::B3DRange
aAllContentRange(rVCScene
.getAllContentRange3D());
67 // only change when there is still content; else let scene stay at old SnapRect
68 if(!aAllContentRange
.isEmpty())
70 // check if object transform of scene has changed
71 if(mpViewInformation3D
->getObjectTransformation() != mpScene
->GetTransform())
73 // If Yes, it needs to be updated since it's - for historical reasons -
74 // part of the basic 3d transformation stack of the scene
75 drawinglayer::geometry::ViewInformation3D
* pNew
= new drawinglayer::geometry::ViewInformation3D(
76 mpScene
->GetTransform(), // replace object transformation with new local transform
77 mpViewInformation3D
->getOrientation(),
78 mpViewInformation3D
->getProjection(),
79 mpViewInformation3D
->getDeviceToView(),
80 mpViewInformation3D
->getViewTime(),
81 mpViewInformation3D
->getExtendedInformationSequence());
82 mpViewInformation3D
.reset(pNew
);
85 // transform content range to scene-relative coordinates using old 3d transformation stack
86 aAllContentRange
.transform(mpViewInformation3D
->getObjectToView());
88 // build 2d relative content range
89 basegfx::B2DRange
aSnapRange(
90 aAllContentRange
.getMinX(), aAllContentRange
.getMinY(),
91 aAllContentRange
.getMaxX(), aAllContentRange
.getMaxY());
93 // transform to 2D world coordinates using scene's 2D transformation
94 aSnapRange
.transform(rVCScene
.getObjectTransformation());
96 // snap to (old) integer
97 const tools::Rectangle
aNewSnapRect(
98 sal_Int32(floor(aSnapRange
.getMinX())), sal_Int32(floor(aSnapRange
.getMinY())),
99 sal_Int32(ceil(aSnapRange
.getMaxX())), sal_Int32(ceil(aSnapRange
.getMaxY())));
101 // set as new SnapRect and invalidate bound volume
102 if(mpScene
->GetSnapRect() != aNewSnapRect
)
104 mpScene
->SetSnapRect(aNewSnapRect
);
105 mpScene
->InvalidateBoundVolume();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */