LibreOffice Module svx (master)  1
e3dsceneupdater.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <svx/e3dsceneupdater.hxx>
22 #include <svx/obj3d.hxx>
23 #include <svx/scene3d.hxx>
25 
26 
28 : mpScene(nullptr)
29 {
30  // Secure old 3D transformation stack before modification
31  const E3dObject* pE3dObject = dynamic_cast< const E3dObject* >(pObject);
32  if(!pE3dObject)
33  return;
34 
35  mpScene = pE3dObject->getRootE3dSceneFromE3dObject();
36 
37  if(nullptr == mpScene || mpScene->getRootE3dSceneFromE3dObject() != mpScene)
38  return;
39 
40  // if there is a scene and it's the outmost scene, get current 3D range
42  const basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());
43 
44  if(aAllContentRange.isEmpty())
45  {
46  // no content, nothing to do
47  mpScene = nullptr;
48  }
49  else
50  {
51  // secure current 3D transformation stack
52  mpViewInformation3D.reset(
54  rVCScene.getViewInformation3D(aAllContentRange)));
55  }
56 }
57 
59 {
61  return;
62 
63  // after changing parts of the scene, use the secured last 3d transformation stack and the new content
64  // range to calculate a new, eventually expanded or shrunk, 2D geometry for the scene and apply it.
65  // Get new content range
67  basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());
68 
69  // only change when there is still content; else let scene stay at old SnapRect
70  if(aAllContentRange.isEmpty())
71  return;
72 
73  // check if object transform of scene has changed
74  if(mpViewInformation3D->getObjectTransformation() != mpScene->GetTransform())
75  {
76  // If Yes, it needs to be updated since it's - for historical reasons -
77  // part of the basic 3d transformation stack of the scene
79  mpScene->GetTransform(), // replace object transformation with new local transform
80  mpViewInformation3D->getOrientation(),
81  mpViewInformation3D->getProjection(),
82  mpViewInformation3D->getDeviceToView(),
83  mpViewInformation3D->getViewTime(),
84  mpViewInformation3D->getExtendedInformationSequence());
85  mpViewInformation3D.reset(pNew);
86  }
87 
88  // transform content range to scene-relative coordinates using old 3d transformation stack
89  aAllContentRange.transform(mpViewInformation3D->getObjectToView());
90 
91  // build 2d relative content range
92  basegfx::B2DRange aSnapRange(
93  aAllContentRange.getMinX(), aAllContentRange.getMinY(),
94  aAllContentRange.getMaxX(), aAllContentRange.getMaxY());
95 
96  // transform to 2D world coordinates using scene's 2D transformation
97  aSnapRange.transform(rVCScene.getObjectTransformation());
98 
99  // snap to (old) integer
100  const tools::Rectangle aNewSnapRect(
101  sal_Int32(floor(aSnapRange.getMinX())), sal_Int32(floor(aSnapRange.getMinY())),
102  sal_Int32(ceil(aSnapRange.getMaxX())), sal_Int32(ceil(aSnapRange.getMaxY())));
103 
104  // set as new SnapRect and invalidate bound volume
105  if(mpScene->GetSnapRect() != aNewSnapRect)
106  {
107  mpScene->SetSnapRect(aNewSnapRect);
109  }
110 }
111 
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D(const ::basegfx::B3DRange &rContentRange) const
const basegfx::B3DHomMatrix & GetTransform() const
Definition: obj3d.hxx:111
virtual const tools::Rectangle & GetSnapRect() const override
Definition: svdoattr.cxx:48
sdr::contact::ViewContact & GetViewContact() const
Definition: svdobj.cxx:245
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
Abstract DrawObject.
Definition: svdobj.hxx:313
E3DModifySceneSnapRectUpdater(const SdrObject *mpObject)
const basegfx::B2DHomMatrix & getObjectTransformation() const
virtual void SetSnapRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1623
virtual E3dScene * getRootE3dSceneFromE3dObject() const
Definition: obj3d.cxx:254
std::unique_ptr< drawinglayer::geometry::ViewInformation3D > mpViewInformation3D
virtual E3dScene * getRootE3dSceneFromE3dObject() const override
Definition: scene3d.cxx:357
void InvalidateBoundVolume()
Definition: obj3d.cxx:300
basegfx::B3DRange getAllContentRange3D() const