LCOV - code coverage report
Current view: top level - libreoffice/svx/source/sdr/properties - e3dsceneproperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-12-27 Functions: 0 15 0.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/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             : 
      27             : //////////////////////////////////////////////////////////////////////////////
      28             : 
      29             : namespace sdr
      30             : {
      31             :     namespace properties
      32             :     {
      33           0 :         E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
      34           0 :         :   E3dProperties(rObj)
      35             :         {
      36           0 :         }
      37             : 
      38           0 :         E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
      39           0 :         :   E3dProperties(rProps, rObj)
      40             :         {
      41           0 :         }
      42             : 
      43           0 :         E3dSceneProperties::~E3dSceneProperties()
      44             :         {
      45           0 :         }
      46             : 
      47           0 :         BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
      48             :         {
      49           0 :             return *(new E3dSceneProperties(*this, rObj));
      50             :         }
      51             : 
      52           0 :         const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
      53             :         {
      54             :             //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
      55           0 :             return E3dProperties::GetObjectItemSet();
      56             :         }
      57             : 
      58           0 :         const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
      59             :         {
      60             :             // prepare ItemSet
      61           0 :             if(mpItemSet)
      62             :             {
      63             :                 // filter for SDRATTR_3DSCENE_ items, only keep those items
      64           0 :                 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
      65           0 :                 aNew.Put(*mpItemSet);
      66           0 :                 mpItemSet->ClearItem();
      67           0 :                 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           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
      77           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
      78             : 
      79           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
      80             :             {
      81           0 :                 SdrObject* pObj = pSub->GetObj(a);
      82             : 
      83           0 :                 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(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False))
      96             :                             {
      97           0 :                                 mpItemSet->InvalidateItem(nWhich);
      98             :                             }
      99             :                             else
     100             :                             {
     101           0 :                                 mpItemSet->MergeValue(rSet.Get(nWhich), sal_True);
     102             :                             }
     103             :                         }
     104             : 
     105           0 :                         nWhich = aIter.NextWhich();
     106           0 :                     }
     107             :                 }
     108             :             }
     109             : 
     110             :             // call parent
     111           0 :             return E3dProperties::GetMergedItemSet();
     112             :         }
     113             : 
     114           0 :         void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
     115             :         {
     116             :             // Set SDRATTR_3DOBJ_ range at contained objects.
     117           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     118           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
     119             : 
     120           0 :             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           0 :                 SfxItemSet* pNewSet = rSet.Clone(sal_True);
     125             :                 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
     126             : 
     127           0 :                 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
     128             :                 {
     129           0 :                     pNewSet->ClearItem(b);
     130             :                 }
     131             : 
     132           0 :                 if(pNewSet->Count())
     133             :                 {
     134           0 :                     for(sal_uInt32 a(0L); 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             :                 }
     145             : 
     146           0 :                 delete pNewSet;
     147             :             }
     148             : 
     149             :             // call parent. This will set items on local object, too.
     150           0 :             E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
     151           0 :         }
     152             : 
     153           0 :         void E3dSceneProperties::SetMergedItem(const SfxPoolItem& rItem)
     154             :         {
     155           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     156           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
     157             : 
     158           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
     159             :             {
     160           0 :                 pSub->GetObj(a)->SetMergedItem(rItem);
     161             :             }
     162             : 
     163             :             // #i43809# call parent. This will set items on local object, too.
     164           0 :             E3dProperties::SetMergedItem(rItem);
     165           0 :         }
     166             : 
     167           0 :         void E3dSceneProperties::ClearMergedItem(const sal_uInt16 nWhich)
     168             :         {
     169           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     170           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
     171             : 
     172           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
     173             :             {
     174           0 :                 pSub->GetObj(a)->ClearMergedItem(nWhich);
     175             :             }
     176             : 
     177             :             // #i43809# call parent. This will clear items on local object, too.
     178           0 :             E3dProperties::ClearMergedItem(nWhich);
     179           0 :         }
     180             : 
     181           0 :         void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
     182             :         {
     183             :             // call parent
     184           0 :             E3dProperties::PostItemChange(nWhich);
     185             : 
     186             :             // local changes
     187           0 :             E3dScene& rObj = (E3dScene&)GetSdrObject();
     188           0 :             rObj.StructureChanged();
     189             : 
     190           0 :             switch(nWhich)
     191             :             {
     192             :                 case SDRATTR_3DSCENE_PERSPECTIVE            :
     193             :                 case SDRATTR_3DSCENE_DISTANCE               :
     194             :                 case SDRATTR_3DSCENE_FOCAL_LENGTH           :
     195             :                 {
     196             :                     // #83387#, #83391#
     197             :                     // one common function for the camera attributes
     198             :                     // since SetCamera() sets all three back to the ItemSet
     199           0 :                     Camera3D aSceneCam(rObj.GetCamera());
     200           0 :                     sal_Bool bChange(sal_False);
     201             : 
     202             :                     // for SDRATTR_3DSCENE_PERSPECTIVE:
     203           0 :                     if(aSceneCam.GetProjection() != rObj.GetPerspective())
     204             :                     {
     205           0 :                         aSceneCam.SetProjection(rObj.GetPerspective());
     206           0 :                         bChange = sal_True;
     207             :                     }
     208             : 
     209             :                     // for SDRATTR_3DSCENE_DISTANCE:
     210           0 :                     basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
     211           0 :                     double fNew = rObj.GetDistance();
     212             : 
     213           0 :                     if(fNew != aActualPosition.getZ())
     214             :                     {
     215           0 :                         aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
     216           0 :                         bChange = sal_True;
     217             :                     }
     218             : 
     219             :                     // for SDRATTR_3DSCENE_FOCAL_LENGTH:
     220           0 :                     fNew = rObj.GetFocalLength() / 100.0;
     221             : 
     222           0 :                     if(aSceneCam.GetFocalLength() != fNew)
     223             :                     {
     224           0 :                         aSceneCam.SetFocalLength(fNew);
     225           0 :                         bChange = sal_True;
     226             :                     }
     227             : 
     228             :                     // for all
     229           0 :                     if(bChange)
     230             :                     {
     231           0 :                         rObj.SetCamera(aSceneCam);
     232             :                     }
     233             : 
     234           0 :                     break;
     235             :                 }
     236             :             }
     237           0 :         }
     238             : 
     239           0 :         void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
     240             :         {
     241           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     242           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
     243             : 
     244           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
     245             :             {
     246           0 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     247             :             }
     248           0 :         }
     249             : 
     250           0 :         SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
     251             :         {
     252           0 :             SfxStyleSheet* pRetval = 0L;
     253             : 
     254           0 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     255           0 :             const sal_uInt32 nCount(pSub->GetObjCount());
     256             : 
     257           0 :             for(sal_uInt32 a(0L); a < nCount; a++)
     258             :             {
     259           0 :                 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet();
     260             : 
     261           0 :                 if(pRetval)
     262             :                 {
     263           0 :                     if(pCandidate != pRetval)
     264             :                     {
     265             :                         // different StyleSheelts, return none
     266           0 :                         return 0L;
     267             :                     }
     268             :                 }
     269             :                 else
     270             :                 {
     271           0 :                     pRetval = pCandidate;
     272             :                 }
     273             :             }
     274             : 
     275           0 :             return pRetval;
     276             :         }
     277             : 
     278           0 :         void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     279             :         {
     280           0 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
     281             :             {
     282             :                 // call parent
     283           0 :                 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     284             : 
     285             :                 // own reaction, but only with outmost scene
     286           0 :                 E3dScene& rObj = (E3dScene&)GetSdrObject();
     287           0 :                 const SdrObjList* pSubList = rObj.GetSubList();
     288             : 
     289           0 :                 if(pSubList && rObj.GetScene() == &rObj)
     290             :                 {
     291           0 :                     SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
     292             : 
     293           0 :                     while(a3DIterator.IsMore())
     294             :                     {
     295           0 :                         E3dObject* pObj = (E3dObject*)a3DIterator.Next();
     296             :                         DBG_ASSERT(pObj->ISA(E3dObject), "In scenes there are only 3D objects allowed (!)");
     297           0 :                         pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     298           0 :                     }
     299             :                 }
     300             :             }
     301           0 :         }
     302             : 
     303           0 :         void E3dSceneProperties::SetSceneItemsFromCamera()
     304             :         {
     305             :             // force ItemSet
     306           0 :             GetObjectItemSet();
     307             : 
     308           0 :             E3dScene& rObj = (E3dScene&)GetSdrObject();
     309           0 :             Camera3D aSceneCam(rObj.GetCamera());
     310             : 
     311             :             // ProjectionType
     312           0 :             mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
     313             : 
     314             :             // CamPos
     315           0 :             mpItemSet->Put(Svx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
     316             : 
     317             :             // FocalLength
     318           0 :             mpItemSet->Put(Svx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
     319           0 :         }
     320             :     } // end of namespace properties
     321             : } // end of namespace sdr
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10