LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - e3dsceneproperties.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 80 124 64.5 %
Date: 2015-06-13 12:38:46 Functions: 11 15 73.3 %
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        1273 :         E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
      34        1273 :         :   E3dProperties(rObj)
      35             :         {
      36        1273 :         }
      37             : 
      38           0 :         E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
      39           0 :         :   E3dProperties(rProps, rObj)
      40             :         {
      41           0 :         }
      42             : 
      43        2546 :         E3dSceneProperties::~E3dSceneProperties()
      44             :         {
      45        2546 :         }
      46             : 
      47           0 :         BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
      48             :         {
      49           0 :             return *(new E3dSceneProperties(*this, rObj));
      50             :         }
      51             : 
      52       84488 :         const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
      53             :         {
      54             :             //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
      55       84488 :             return E3dProperties::GetObjectItemSet();
      56             :         }
      57             : 
      58        2241 :         const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
      59             :         {
      60             :             // prepare ItemSet
      61        2241 :             if(mpItemSet)
      62             :             {
      63             :                 // filter for SDRATTR_3DSCENE_ items, only keep those items
      64        2241 :                 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
      65        2241 :                 aNew.Put(*mpItemSet);
      66        2241 :                 mpItemSet->ClearItem();
      67        2241 :                 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        2241 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
      77        2241 :             const size_t nCount(pSub->GetObjCount());
      78             : 
      79        4482 :             for(size_t a = 0; a < nCount; ++a)
      80             :             {
      81        2241 :                 SdrObject* pObj = pSub->GetObj(a);
      82             : 
      83        2241 :                 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        2241 :             return E3dProperties::GetMergedItemSet();
     112             :         }
     113             : 
     114        1595 :         void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, bool bClearAllItems)
     115             :         {
     116             :             // Set SDRATTR_3DOBJ_ range at contained objects.
     117        1595 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     118        1595 :             const size_t nCount(pSub->GetObjCount());
     119             : 
     120        1595 :             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        1595 :                 boost::scoped_ptr<SfxItemSet> pNewSet(rSet.Clone(true));
     125             :                 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
     126             : 
     127       51040 :                 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
     128             :                 {
     129       49445 :                     pNewSet->ClearItem(b);
     130             :                 }
     131             : 
     132        1595 :                 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        1595 :                 }
     145             :             }
     146             : 
     147             :             // call parent. This will set items on local object, too.
     148        1595 :             E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
     149        1595 :         }
     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       28715 :         void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
     180             :         {
     181             :             // call parent
     182       28715 :             E3dProperties::PostItemChange(nWhich);
     183             : 
     184             :             // local changes
     185       28715 :             E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     186       28715 :             rObj.StructureChanged();
     187             : 
     188       28715 :             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        3119 :                     Camera3D aSceneCam(rObj.GetCamera());
     198        3119 :                     bool bChange(false);
     199             : 
     200             :                     // for SDRATTR_3DSCENE_PERSPECTIVE:
     201        3119 :                     if(aSceneCam.GetProjection() != rObj.GetPerspective())
     202             :                     {
     203          38 :                         aSceneCam.SetProjection(rObj.GetPerspective());
     204          38 :                         bChange = true;
     205             :                     }
     206             : 
     207             :                     // for SDRATTR_3DSCENE_DISTANCE:
     208        6238 :                     basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
     209        3119 :                     double fNew = rObj.GetDistance();
     210             : 
     211        3119 :                     if(fNew != aActualPosition.getZ())
     212             :                     {
     213          55 :                         aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
     214          55 :                         bChange = true;
     215             :                     }
     216             : 
     217             :                     // for SDRATTR_3DSCENE_FOCAL_LENGTH:
     218        3119 :                     fNew = rObj.GetFocalLength() / 100.0;
     219             : 
     220        3119 :                     if(aSceneCam.GetFocalLength() != fNew)
     221             :                     {
     222           0 :                         aSceneCam.SetFocalLength(fNew);
     223           0 :                         bChange = true;
     224             :                     }
     225             : 
     226             :                     // for all
     227        3119 :                     if(bChange)
     228             :                     {
     229          93 :                         rObj.SetCamera(aSceneCam);
     230             :                     }
     231             : 
     232        6238 :                     break;
     233             :                 }
     234             :             }
     235       28715 :         }
     236             : 
     237        1273 :         void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
     238             :         {
     239        1273 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     240        1273 :             const sal_uInt32 nCount(pSub->GetObjCount());
     241             : 
     242        1273 :             for(size_t a = 0; a < nCount; ++a)
     243             :             {
     244           0 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     245             :             }
     246        1273 :         }
     247             : 
     248        2546 :         SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
     249             :         {
     250        2546 :             SfxStyleSheet* pRetval = 0L;
     251             : 
     252        2546 :             const SdrObjList* pSub = static_cast<const E3dScene&>(GetSdrObject()).GetSubList();
     253        2546 :             const size_t nCount(pSub->GetObjCount());
     254             : 
     255        2546 :             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        2546 :             return pRetval;
     274             :         }
     275             : 
     276        1273 :         void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     277             :         {
     278        1273 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
     279             :             {
     280             :                 // call parent
     281        1273 :                 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     282             : 
     283             :                 // own reaction, but only with outmost scene
     284        1273 :                 E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     285        1273 :                 const SdrObjList* pSubList = rObj.GetSubList();
     286             : 
     287        1273 :                 if(pSubList && rObj.GetScene() == &rObj)
     288             :                 {
     289        1273 :                     SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
     290             : 
     291        2546 :                     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        1273 :                     }
     297             :                 }
     298             :             }
     299        1273 :         }
     300             : 
     301        1366 :         void E3dSceneProperties::SetSceneItemsFromCamera()
     302             :         {
     303             :             // force ItemSet
     304        1366 :             GetObjectItemSet();
     305             : 
     306        1366 :             E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
     307        1366 :             Camera3D aSceneCam(rObj.GetCamera());
     308             : 
     309             :             // ProjectionType
     310        1366 :             mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
     311             : 
     312             :             // CamPos
     313        1366 :             mpItemSet->Put(makeSvx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
     314             : 
     315             :             // FocalLength
     316        1366 :             mpItemSet->Put(makeSvx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
     317        1366 :         }
     318             :     } // end of namespace properties
     319             : } // end of namespace sdr
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11