LCOV - code coverage report
Current view: top level - svx/source/sdr/properties - e3dsceneproperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 124 64.5 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 57 152 37.5 %

           Branch data     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                 :        736 :         E3dSceneProperties::E3dSceneProperties(SdrObject& rObj)
      34                 :        736 :         :   E3dProperties(rObj)
      35                 :            :         {
      36                 :        736 :         }
      37                 :            : 
      38                 :          0 :         E3dSceneProperties::E3dSceneProperties(const E3dSceneProperties& rProps, SdrObject& rObj)
      39                 :          0 :         :   E3dProperties(rProps, rObj)
      40                 :            :         {
      41                 :          0 :         }
      42                 :            : 
      43                 :        736 :         E3dSceneProperties::~E3dSceneProperties()
      44                 :            :         {
      45         [ -  + ]:       1472 :         }
      46                 :            : 
      47                 :          0 :         BaseProperties& E3dSceneProperties::Clone(SdrObject& rObj) const
      48                 :            :         {
      49         [ #  # ]:          0 :             return *(new E3dSceneProperties(*this, rObj));
      50                 :            :         }
      51                 :            : 
      52                 :      48289 :         const SfxItemSet& E3dSceneProperties::GetObjectItemSet() const
      53                 :            :         {
      54                 :            :             //DBG_ASSERT(sal_False, "E3dSceneProperties::GetObjectItemSet() maybe the wrong call (!)");
      55                 :      48289 :             return E3dProperties::GetObjectItemSet();
      56                 :            :         }
      57                 :            : 
      58                 :        970 :         const SfxItemSet& E3dSceneProperties::GetMergedItemSet() const
      59                 :            :         {
      60                 :            :             // prepare ItemSet
      61         [ +  - ]:        970 :             if(mpItemSet)
      62                 :            :             {
      63                 :            :                 // filter for SDRATTR_3DSCENE_ items, only keep those items
      64         [ +  - ]:        970 :                 SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
      65         [ +  - ]:        970 :                 aNew.Put(*mpItemSet);
      66         [ +  - ]:        970 :                 mpItemSet->ClearItem();
      67 [ +  - ][ +  - ]:        970 :                 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                 :        970 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
      77                 :        970 :             const sal_uInt32 nCount(pSub->GetObjCount());
      78                 :            : 
      79         [ +  + ]:       1940 :             for(sal_uInt32 a(0L); a < nCount; a++)
      80                 :            :             {
      81                 :        970 :                 SdrObject* pObj = pSub->GetObj(a);
      82                 :            : 
      83 [ -  + ][ -  + ]:        970 :                 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                 :        970 :             return E3dProperties::GetMergedItemSet();
     112                 :            :         }
     113                 :            : 
     114                 :        420 :         void E3dSceneProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems)
     115                 :            :         {
     116                 :            :             // Set SDRATTR_3DOBJ_ range at contained objects.
     117                 :        420 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     118                 :        420 :             const sal_uInt32 nCount(pSub->GetObjCount());
     119                 :            : 
     120         [ +  + ]:        420 :             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                 :        406 :                 SfxItemSet* pNewSet = rSet.Clone(sal_True);
     125                 :            :                 DBG_ASSERT(pNewSet, "E3dSceneProperties::SetMergedItemSet(): Could not clone ItemSet (!)");
     126                 :            : 
     127         [ +  + ]:      12992 :                 for(sal_uInt16 b(SDRATTR_3DSCENE_FIRST); b <= SDRATTR_3DSCENE_LAST; b++)
     128                 :            :                 {
     129                 :      12586 :                     pNewSet->ClearItem(b);
     130                 :            :                 }
     131                 :            : 
     132         [ -  + ]:        406 :                 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         [ +  - ]:        406 :                 delete pNewSet;
     147                 :            :             }
     148                 :            : 
     149                 :            :             // call parent. This will set items on local object, too.
     150                 :        420 :             E3dProperties::SetMergedItemSet(rSet, bClearAllItems);
     151                 :        420 :         }
     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                 :      13884 :         void E3dSceneProperties::PostItemChange(const sal_uInt16 nWhich)
     182                 :            :         {
     183                 :            :             // call parent
     184                 :      13884 :             E3dProperties::PostItemChange(nWhich);
     185                 :            : 
     186                 :            :             // local changes
     187                 :      13884 :             E3dScene& rObj = (E3dScene&)GetSdrObject();
     188                 :      13884 :             rObj.StructureChanged();
     189                 :            : 
     190         [ +  + ]:      13884 :             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         [ +  - ]:       1450 :                     Camera3D aSceneCam(rObj.GetCamera());
     200                 :       1450 :                     sal_Bool bChange(sal_False);
     201                 :            : 
     202                 :            :                     // for SDRATTR_3DSCENE_PERSPECTIVE:
     203 [ +  - ][ +  + ]:       1450 :                     if(aSceneCam.GetProjection() != rObj.GetPerspective())
     204                 :            :                     {
     205         [ +  - ]:         11 :                         aSceneCam.SetProjection(rObj.GetPerspective());
     206                 :         11 :                         bChange = sal_True;
     207                 :            :                     }
     208                 :            : 
     209                 :            :                     // for SDRATTR_3DSCENE_DISTANCE:
     210                 :       1450 :                     basegfx::B3DPoint aActualPosition(aSceneCam.GetPosition());
     211         [ +  - ]:       1450 :                     double fNew = rObj.GetDistance();
     212                 :            : 
     213         [ +  + ]:       1450 :                     if(fNew != aActualPosition.getZ())
     214                 :            :                     {
     215         [ +  - ]:         14 :                         aSceneCam.SetPosition(basegfx::B3DPoint(aActualPosition.getX(), aActualPosition.getY(), fNew));
     216                 :         14 :                         bChange = sal_True;
     217                 :            :                     }
     218                 :            : 
     219                 :            :                     // for SDRATTR_3DSCENE_FOCAL_LENGTH:
     220         [ +  - ]:       1450 :                     fNew = rObj.GetFocalLength() / 100.0;
     221                 :            : 
     222         [ -  + ]:       1450 :                     if(aSceneCam.GetFocalLength() != fNew)
     223                 :            :                     {
     224         [ #  # ]:          0 :                         aSceneCam.SetFocalLength(fNew);
     225                 :          0 :                         bChange = sal_True;
     226                 :            :                     }
     227                 :            : 
     228                 :            :                     // for all
     229         [ +  + ]:       1450 :                     if(bChange)
     230                 :            :                     {
     231         [ +  - ]:         25 :                         rObj.SetCamera(aSceneCam);
     232                 :            :                     }
     233                 :            : 
     234         [ +  - ]:       1450 :                     break;
     235                 :            :                 }
     236                 :            :             }
     237                 :      13884 :         }
     238                 :            : 
     239                 :        736 :         void E3dSceneProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
     240                 :            :         {
     241                 :        736 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     242                 :        736 :             const sal_uInt32 nCount(pSub->GetObjCount());
     243                 :            : 
     244         [ -  + ]:        736 :             for(sal_uInt32 a(0L); a < nCount; a++)
     245                 :            :             {
     246                 :          0 :                 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
     247                 :            :             }
     248                 :        736 :         }
     249                 :            : 
     250                 :       1472 :         SfxStyleSheet* E3dSceneProperties::GetStyleSheet() const
     251                 :            :         {
     252                 :       1472 :             SfxStyleSheet* pRetval = 0L;
     253                 :            : 
     254                 :       1472 :             const SdrObjList* pSub = ((const E3dScene&)GetSdrObject()).GetSubList();
     255                 :       1472 :             const sal_uInt32 nCount(pSub->GetObjCount());
     256                 :            : 
     257         [ -  + ]:       1472 :             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                 :       1472 :             return pRetval;
     276                 :            :         }
     277                 :            : 
     278                 :        736 :         void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
     279                 :            :         {
     280 [ +  - ][ +  - ]:        736 :             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
                 [ +  - ]
     281                 :            :             {
     282                 :            :                 // call parent
     283                 :        736 :                 E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);
     284                 :            : 
     285                 :            :                 // own reaction, but only with outmost scene
     286                 :        736 :                 E3dScene& rObj = (E3dScene&)GetSdrObject();
     287                 :        736 :                 const SdrObjList* pSubList = rObj.GetSubList();
     288                 :            : 
     289 [ +  - ][ +  - ]:        736 :                 if(pSubList && rObj.GetScene() == &rObj)
                 [ +  - ]
     290                 :            :                 {
     291         [ +  - ]:        736 :                     SdrObjListIter a3DIterator(*pSubList, IM_DEEPWITHGROUPS);
     292                 :            : 
     293         [ -  + ]:        736 :                     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                 :        736 :                     }
     299                 :            :                 }
     300                 :            :             }
     301                 :        736 :         }
     302                 :            : 
     303                 :        761 :         void E3dSceneProperties::SetSceneItemsFromCamera()
     304                 :            :         {
     305                 :            :             // force ItemSet
     306         [ +  - ]:        761 :             GetObjectItemSet();
     307                 :            : 
     308                 :        761 :             E3dScene& rObj = (E3dScene&)GetSdrObject();
     309         [ +  - ]:        761 :             Camera3D aSceneCam(rObj.GetCamera());
     310                 :            : 
     311                 :            :             // ProjectionType
     312 [ +  - ][ +  - ]:        761 :             mpItemSet->Put(Svx3DPerspectiveItem((sal_uInt16)aSceneCam.GetProjection()));
                 [ +  - ]
     313                 :            : 
     314                 :            :             // CamPos
     315 [ +  - ][ +  - ]:        761 :             mpItemSet->Put(Svx3DDistanceItem((sal_uInt32)(aSceneCam.GetPosition().getZ() + 0.5)));
                 [ +  - ]
     316                 :            : 
     317                 :            :             // FocalLength
     318 [ +  - ][ +  - ]:        761 :             mpItemSet->Put(Svx3DFocalLengthItem((sal_uInt32)((aSceneCam.GetFocalLength() * 100.0) + 0.5)));
         [ +  - ][ +  - ]
     319                 :        761 :         }
     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