LCOV - code coverage report
Current view: top level - svx/source/engine3d - e3dsceneupdater.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 37 97.3 %
Date: 2015-06-13 12:38:46 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11