1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir #include <svx/e3dsceneupdater.hxx> 27cdf0e10cSrcweir #include <drawinglayer/geometry/viewinformation3d.hxx> 28cdf0e10cSrcweir #include <svx/obj3d.hxx> 29cdf0e10cSrcweir #include <svx/scene3d.hxx> 30cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofe3dscene.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 33cdf0e10cSrcweir 34cdf0e10cSrcweir E3DModifySceneSnapRectUpdater::E3DModifySceneSnapRectUpdater(const SdrObject* pObject) 35cdf0e10cSrcweir : mpScene(0), 36cdf0e10cSrcweir mpViewInformation3D(0) 37cdf0e10cSrcweir { 38cdf0e10cSrcweir // Secure old 3D transformation stack before modification 39cdf0e10cSrcweir if(pObject) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir const E3dObject* pE3dObject = dynamic_cast< const E3dObject* >(pObject); 42cdf0e10cSrcweir 43cdf0e10cSrcweir if(pE3dObject) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir mpScene = pE3dObject->GetScene(); 46cdf0e10cSrcweir 47cdf0e10cSrcweir if(mpScene && mpScene->GetScene() == mpScene) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // if there is a scene and it's the outmost scene, get current 3D range 50cdf0e10cSrcweir const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact()); 51cdf0e10cSrcweir const basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D()); 52cdf0e10cSrcweir 53cdf0e10cSrcweir if(aAllContentRange.isEmpty()) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir // no content, nothing to do 56cdf0e10cSrcweir mpScene = 0; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir else 59cdf0e10cSrcweir { 60cdf0e10cSrcweir // secure current 3D transformation stack 61cdf0e10cSrcweir mpViewInformation3D = new drawinglayer::geometry::ViewInformation3D(rVCScene.getViewInformation3D(aAllContentRange)); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir E3DModifySceneSnapRectUpdater::~E3DModifySceneSnapRectUpdater() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir if(mpScene && mpViewInformation3D) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir // after changing parts of the scene, use the secured last 3d transformation stack and the new content 73cdf0e10cSrcweir // range to calculate a new, eventually expanded or shrunk, 2D geometry for the scene and apply it. 74cdf0e10cSrcweir // Get new content range 75cdf0e10cSrcweir const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact()); 76cdf0e10cSrcweir basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D()); 77cdf0e10cSrcweir 78cdf0e10cSrcweir // only change when there is still content; else let scene stay at old SnapRect 79cdf0e10cSrcweir if(!aAllContentRange.isEmpty()) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir // check if object transform of scene has changed 82cdf0e10cSrcweir if(mpViewInformation3D->getObjectTransformation() != mpScene->GetTransform()) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir // If Yes, it needs to be updated since it's - for historical reasons - 85cdf0e10cSrcweir // part of the basic 3d transformation stack of the scene 86cdf0e10cSrcweir drawinglayer::geometry::ViewInformation3D* pNew = new drawinglayer::geometry::ViewInformation3D( 87cdf0e10cSrcweir mpScene->GetTransform(), // replace object transformation with new local transform 88cdf0e10cSrcweir mpViewInformation3D->getOrientation(), 89cdf0e10cSrcweir mpViewInformation3D->getProjection(), 90cdf0e10cSrcweir mpViewInformation3D->getDeviceToView(), 91cdf0e10cSrcweir mpViewInformation3D->getViewTime(), 92cdf0e10cSrcweir mpViewInformation3D->getExtendedInformationSequence()); 93cdf0e10cSrcweir delete mpViewInformation3D; 94cdf0e10cSrcweir mpViewInformation3D = pNew; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // transform content range to scene-relative coordinates using old 3d transformation stack 98cdf0e10cSrcweir aAllContentRange.transform(mpViewInformation3D->getObjectToView()); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // build 2d relative content range 101cdf0e10cSrcweir basegfx::B2DRange aSnapRange( 102cdf0e10cSrcweir aAllContentRange.getMinX(), aAllContentRange.getMinY(), 103cdf0e10cSrcweir aAllContentRange.getMaxX(), aAllContentRange.getMaxY()); 104cdf0e10cSrcweir 105cdf0e10cSrcweir // transform to 2D world coordiantes using scene's 2D transformation 106cdf0e10cSrcweir aSnapRange.transform(rVCScene.getObjectTransformation()); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // snap to (old) integer 109cdf0e10cSrcweir const Rectangle aNewSnapRect( 110cdf0e10cSrcweir sal_Int32(floor(aSnapRange.getMinX())), sal_Int32(floor(aSnapRange.getMinY())), 111cdf0e10cSrcweir sal_Int32(ceil(aSnapRange.getMaxX())), sal_Int32(ceil(aSnapRange.getMaxY()))); 112cdf0e10cSrcweir 113cdf0e10cSrcweir // set as new SnapRect and invalidate bound volume 114cdf0e10cSrcweir if(mpScene->GetSnapRect() != aNewSnapRect) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir mpScene->SetSnapRect(aNewSnapRect); 117cdf0e10cSrcweir mpScene->InvalidateBoundVolume(); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir delete mpViewInformation3D; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 126cdf0e10cSrcweir // eof 127