LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - e3dsceneproperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 81 125 64.8 %
Date: 2014-11-03 Functions: 13 17 76.5 %
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 <sdr/properties/e3dsceneproperties.hxx>
      21             : #include <svl/itemset.hxx>
      22             : #include <svl/whiter.hxx>
      23             : #include <svx/svddef.hxx>
      24             : #include <svx/scene3d.hxx>
      25             : #include <svx/svditer.hxx>
      26             : #include <boost/scoped_ptr.hpp>
      27             : 
      28             : 
      29             : namespace sdr
      30             : {
      31             :     namespace properties
      32             :     {
      33        1406 :         E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
      34        1406 :         :   E3dProperties(rObj)
      35             :         {
      36        1406 :         }
      37             : 
      38           0 :         E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
      39           0 :         :   E3dProperties(rProps, rObj)
      40             :         {
      41           0 :         }
      42             : 
      43        2812 :         E3dSceneProperties::~E3dSceneProperties()
      44             :         {
      45        2812 :         }
      46             : 
      47           0 :         BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
      48             :         {
      49           0 :             return *(new E3dSceneProperties(*this, rObj));
      50             :         }
      51             : 
      52       75471 :         const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
      53             :         {
      54             :             //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
      55       75471 :             return E3dProperties::GetObjectItemSet();
      56             :         }
      57             : 
      58        1500 :         const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
      59             :         {
      60             :             // prepare ItemSet
      61        1500 :             if(mpItemSet)
      62             :             {
      63             :                 // filter for SDRATTR_3DSCENE_ items, only keep those items
      64        1500 :                 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
      65        1500 :                 aNew.Put(*mpItemSet);
      66        1500 :                 mpItemSet->ClearItem();
      67        1500 :                 mpItemSet->Put(aNew);
      68             :             }
      69             :             else
      70             :             {
      71             :                 // No ItemSet yet, force local ItemSet
      72           0 :                 GetObjectItemSet();
      73             :             }
      74             : 
      75             :             // collect all ItemSets of contained 3d objects
      76        1500 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
      77        1500 :             const size_t nCount(pSub->GetObjCount());
      78             : 
      79        3000 :             for(size_t a = 0; a < nCount; ++a)
      80             :             {
      81        1500 :                 SdrObject* pObj = pSub->GetObj(a);
      82             : 
      83        1500 :                 if(pObj && pObj->ISA(E3dCompoundObject))
      84             :                 {
      85           0 :                     const SfxItemSet& rSet = pObj->GetMergedItemSet();
      86           0 :                     SfxWhichIter aIter(rSet);
      87           0 :                     sal_uInt16 nWhich(aIter.FirstWhich());
      88             : 
      89           0 :                     while(nWhich)
      90             :                     {
      91             :                         // Leave out the SDRATTR_3DSCENE_ range, this would only be double
      92             :                         // and always equal.
      93           0 :                         if(nWhich <= SDRATTR_3DSCENE_FIRST || nWhich >= SDRATTR_3DSCENE_LAST)
      94             :                         {
      95           0 :                             if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
      96             :                             {
      97           0 :                                 mpItemSet->InvalidateItem(nWhich);
      98             :                             }
      99             :                             else
     100             :                             {
     101           0 :                                 mpItemSet->MergeValue(rSet.Get(nWhich), true);
     102             :                             }
     103             :                         }
     104             : 
     105           0 :                         nWhich = aIter.NextWhich();
     106           0 :                     }
     107             :                 }
     108             :             }
     109             : 
     110             :             // call parent
     111        1500 :             return E3dProperties::GetMergedItemSet();
     112             :         }
     113             : 
     114        1073 :         void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
     115             :         {
     116             :             // Set SDRATTR_3DOBJ_ range at contained objects.
     117        1073 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     118        1073 :             const size_t nCount(pSub->GetObjCount());
     119             : 
     120        1073 :             if(nCount)
     121             :             {
     122             :                 // Generate filtered ItemSet which contains all but the SDRATTR_3DSCENE items.
     123             :                 // #i50808# Leak fix, Clone produces a new instance and we get ownership here
     124        1073 :                 boost::scoped_ptr<SfxItemSet> pNewSet(rSet.Clone(true));
     125             :                 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
     126             : 
     127       34336 :                 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
     128             :                 {
     129       33263 :                     pNewSet->ClearItem(b);
     130             :                 }
     131             : 
     132        1073 :                 if(pNewSet->Count())
     133             :                 {
     134           0 :                     for(size_t a = 0; a < nCount; ++a)
     135             :                     {
     136           0 :                         SdrObject* pObj = pSub->GetObj(a);
     137             : 
     138           0 :                         if(pObj && pObj->ISA(E3dCompoundObject))
     139             :                         {
     140             :                             // set merged ItemSet at contained 3d object.
     141           0 :                             pObj->SetMergedItemSet(*pNewSet, bClearAllItems);
     142             :                         }
     143             :                     }
     144        1073 :                 }
     145             :             }
     146             : 
     147             :             // call parent. This will set items on local object, too.
     148        1073 :             E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
     149        1073 :         }
     150             : 
     151           0 :         void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
     152             :         {
     153           0 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     154           0 :             const size_t nCount(pSub->GetObjCount());
     155             : 
     156           0 :             for(size_t a = 0; a < nCount; ++a)
     157             :             {
     158           0 :                 pSub->GetObj(a)->SetMergedItem(rItem);
     159             :             }
     160             : 
     161             :             // #i43809# call parent. This will set items on local object, too.
     162           0 :             E3dProperties::SetMergedItem(rItem);
     163           0 :         }
     164             : 
     165           0 :         void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
     166             :         {
     167           0 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     168           0 :             const size_t nCount(pSub->GetObjCount());
     169             : 
     170           0 :             for(size_t a = 0; a < nCount; ++a)
     171             :             {
     172           0 :                 pSub->GetObj(a)->ClearMergedItem(nWhich);
     173             :             }
     174             : 
     175             :             // #i43809# call parent. This will clear items on local object, too.
     176           0 :             E3dProperties::ClearMergedItem(nWhich);
     177           0 :         }
     178             : 
     179       26645 :         void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
     180             :         {
     181             :             // call parent
     182       26645 :             E3dProperties::PostItemChange(nWhich);
     183             : 
     184             :             // local changes
     185       26645 :             E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     186       26645 :             rObj.StructureChanged();
     187             : 
     188       26645 :             switch(nWhich)
     189             :             {
     190             :                 case SDRATTR_3DSCENE_PERSPECTIVE            :
     191             :                 case SDRATTR_3DSCENE_DISTANCE               :
     192             :                 case SDRATTR_3DSCENE_FOCAL_LENGTH           :
     193             :                 {
     194             :                     // #83387#, #83391#
     195             :                     // one common function for the camera attributes
     196             :                     // since SetCamera() sets all three back to the ItemSet
     197        2831 :                     Camera3D aSceneCam(rObj.GetCamera());
     198        2831 :                     bool bChange(false);
     199             : 
     200             :                     // for SDRATTR_3DSCENE_PERSPECTIVE:
     201        2831 :                     if(aSceneCam.GetProjection() != rObj.GetPerspective())
     202             :                     {
     203          16 :                         aSceneCam.SetProjection(rObj.GetPerspective());
     204          16 :                         bChange = true;
     205             :                     }
     206             : 
     207             :                     // for SDRATTR_3DSCENE_DISTANCE:
     208        5662 :                     basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
     209        2831 :                     double fNew = rObj.GetDistance();
     210             : 
     211        2831 :                     if(fNew != aActualPosition.getZ())
     212             :                     {
     213          37 :                         aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
     214          37 :                         bChange = true;
     215             :                     }
     216             : 
     217             :                     // for SDRATTR_3DSCENE_FOCAL_LENGTH:
     218        2831 :                     fNew = rObj.GetFocalLength() / 100.0;
     219             : 
     220        2831 :                     if(aSceneCam.GetFocalLength() != fNew)
     221             :                     {
     222           0 :                         aSceneCam.SetFocalLength(fNew);
     223           0 :                         bChange = true;
     224             :                     }
     225             : 
     226             :                     // for all
     227        2831 :                     if(bChange)
     228             :                     {
     229          53 :                         rObj.SetCamera(aSceneCam);
     230             :                     }
     231             : 
     232        5662 :                     break;
     233             :                 }
     234             :             }
     235       26645 :         }
     236             : 
     237        1406 :         void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     238             :         {
     239        1406 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     240        1406 :             const sal_uInt32 nCount(pSub->GetObjCount());
     241             : 
     242        1406 :             for(size_t a = 0; a < nCount; ++a)
     243             :             {
     244           0 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     245             :             }
     246        1406 :         }
     247             : 
     248        2812 :         SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
     249             :         {
     250        2812 :             SfxStyleSheet* pRetval = 0L;
     251             : 
     252        2812 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     253        2812 :             const size_t nCount(pSub->GetObjCount());
     254             : 
     255        2812 :             for(size_t a = 0; a < nCount; ++a)
     256             :             {
     257           0 :                 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
     258             : 
     259           0 :                 if(pRetval)
     260             :                 {
     261           0 :                     if(pCandidate != pRetval)
     262             :                     {
     263             :                         // different StyleSheelts, return none
     264           0 :                         return 0L;
     265             :                     }
     266             :                 }
     267             :                 else
     268             :                 {
     269           0 :                     pRetval = pCandidate;
     270             :                 }
     271             :             }
     272             : 
     273        2812 :             return pRetval;
     274             :         }
     275             : 
     276        1406 :         void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     277             :         {
     278        1406 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
     279             :             {
     280             :                 // call parent
     281        1406 :                 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     282             : 
     283             :                 // own reaction, but only with outmost scene
     284        1406 :                 E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     285        1406 :                 const SdrObjList* pSubList = rObj.GetSubList();
     286             : 
     287        1406 :                 if(pSubList && rObj.GetScene() == &rObj)
     288             :                 {
     289        1406 :                     SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
     290             : 
     291        2812 :                     while(a3DIterator.IsMore())
     292             :                     {
     293           0 :                         E3dObject* pObj = static_cast<E3dObject*>(a3DIterator.Next());
     294             :                         DBG_ASSERT(pObj->ISA(E3dObject), "In scenes there are only 3D objects allowed (!)");
     295           0 :                         pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     296        1406 :                     }
     297             :                 }
     298             :             }
     299        1406 :         }
     300             : 
     301        1459 :         void E3dSceneProperties::SetSceneItemsFromCamera()
     302             :         {
     303             :             // force ItemSet
     304        1459 :             GetObjectItemSet();
     305             : 
     306        1459 :             E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     307        1459 :             Camera3D aSceneCam(rObj.GetCamera());
     308             : 
     309             :             // ProjectionType
     310        1459 :             mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
     311             : 
     312             :             // CamPos
     313        1459 :             mpItemSet->Put(makeSvx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
     314             : 
     315             :             // FocalLength
     316        1459 :             mpItemSet->Put(makeSvx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
     317        1459 :         }
     318             :     } // end of namespace properties
     319         651 : } // end of namespace sdr
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10