LCOV - code coverage report
Current view: top level - svx/source/engine3d - scene3d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 87 301 28.9 %
Date: 2015-06-13 12:38:46 Functions: 19 57 33.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             : 
      21             : #include "svx/svdstr.hrc"
      22             : #include "svdglob.hxx"
      23             : #include "svx/svditer.hxx"
      24             : 
      25             : #include <stdlib.h>
      26             : #include <svx/globl3d.hxx>
      27             : #include <svx/svdpage.hxx>
      28             : #include <svl/style.hxx>
      29             : #include <svx/scene3d.hxx>
      30             : #include <svx/e3dundo.hxx>
      31             : #include <svx/svdtrans.hxx>
      32             : #include <svx/svxids.hrc>
      33             : #include <editeng/colritem.hxx>
      34             : #include <svx/e3ditem.hxx>
      35             : #include <svx/xlntrit.hxx>
      36             : #include <svx/xfltrit.hxx>
      37             : #include <svx/svx3ditems.hxx>
      38             : #include <svl/whiter.hxx>
      39             : #include <svx/xflftrit.hxx>
      40             : #include <sdr/properties/e3dsceneproperties.hxx>
      41             : #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
      42             : #include <svx/svddrag.hxx>
      43             : #include <helperminimaldepth3d.hxx>
      44             : #include <algorithm>
      45             : #include <drawinglayer/geometry/viewinformation3d.hxx>
      46             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      47             : #include <svx/e3dsceneupdater.hxx>
      48             : #include <svx/svdmodel.hxx>
      49             : 
      50             : 
      51             : 
      52             : class ImpRemap3DDepth
      53             : {
      54             :     sal_uInt32                  mnOrdNum;
      55             :     double                      mfMinimalDepth;
      56             : 
      57             :     // bit field
      58             :     bool                        mbIsScene : 1;
      59             : 
      60             : public:
      61             :     ImpRemap3DDepth(sal_uInt32 nOrdNum, double fMinimalDepth);
      62             :     explicit ImpRemap3DDepth(sal_uInt32 nOrdNum);
      63             :     ~ImpRemap3DDepth();
      64             : 
      65             :     // for ::std::sort
      66             :     bool operator<(const ImpRemap3DDepth& rComp) const;
      67             : 
      68           0 :     sal_uInt32 GetOrdNum() const { return mnOrdNum; }
      69           0 :     bool IsScene() const { return mbIsScene; }
      70             : };
      71             : 
      72           0 : ImpRemap3DDepth::ImpRemap3DDepth(sal_uInt32 nOrdNum, double fMinimalDepth)
      73             : :   mnOrdNum(nOrdNum),
      74             :     mfMinimalDepth(fMinimalDepth),
      75           0 :     mbIsScene(false)
      76             : {
      77           0 : }
      78             : 
      79           0 : ImpRemap3DDepth::ImpRemap3DDepth(sal_uInt32 nOrdNum)
      80             : :   mnOrdNum(nOrdNum),
      81             :     mfMinimalDepth(0.0),
      82           0 :     mbIsScene(true)
      83             : {
      84           0 : }
      85             : 
      86           0 : ImpRemap3DDepth::~ImpRemap3DDepth()
      87             : {
      88           0 : }
      89             : 
      90           0 : bool ImpRemap3DDepth::operator<(const ImpRemap3DDepth& rComp) const
      91             : {
      92           0 :     if(IsScene())
      93             :     {
      94           0 :         return false;
      95             :     }
      96             :     else
      97             :     {
      98           0 :         if(rComp.IsScene())
      99             :         {
     100           0 :             return true;
     101             :         }
     102             :         else
     103             :         {
     104           0 :             return mfMinimalDepth < rComp.mfMinimalDepth;
     105             :         }
     106             :     }
     107             : }
     108             : 
     109             : // typedefs for a vector of ImpRemap3DDepths
     110             : typedef ::std::vector< ImpRemap3DDepth > ImpRemap3DDepthVector;
     111             : 
     112             : 
     113             : 
     114             : class Imp3DDepthRemapper
     115             : {
     116             :     ImpRemap3DDepthVector       maVector;
     117             : 
     118             : public:
     119             :     explicit Imp3DDepthRemapper(E3dScene& rScene);
     120             :     ~Imp3DDepthRemapper();
     121             : 
     122             :     sal_uInt32 RemapOrdNum(sal_uInt32 nOrdNum) const;
     123             : };
     124             : 
     125           0 : Imp3DDepthRemapper::Imp3DDepthRemapper(E3dScene& rScene)
     126             : {
     127             :     // only called when rScene.GetSubList() and nObjCount > 1L
     128           0 :     SdrObjList* pList = rScene.GetSubList();
     129           0 :     const size_t nObjCount(pList->GetObjCount());
     130             : 
     131           0 :     for(size_t a = 0; a < nObjCount; ++a)
     132             :     {
     133           0 :         SdrObject* pCandidate = pList->GetObj(a);
     134             : 
     135           0 :         if(pCandidate)
     136             :         {
     137           0 :             if(pCandidate->ISA(E3dCompoundObject))
     138             :             {
     139             :                 // single 3d object, calc depth
     140           0 :                 const double fMinimalDepth(getMinimalDepthInViewCoordinates(static_cast< const E3dCompoundObject& >(*pCandidate)));
     141           0 :                 ImpRemap3DDepth aEntry(a, fMinimalDepth);
     142           0 :                 maVector.push_back(aEntry);
     143             :             }
     144             :             else
     145             :             {
     146             :                 // scene, use standard entry for scene
     147           0 :                 ImpRemap3DDepth aEntry(a);
     148           0 :                 maVector.push_back(aEntry);
     149             :             }
     150             :         }
     151             :     }
     152             : 
     153             :     // now, we need to sort the maVector by it's members minimal depth. The
     154             :     // smaller, the nearer to the viewer.
     155           0 :     ::std::sort(maVector.begin(), maVector.end());
     156           0 : }
     157             : 
     158           0 : Imp3DDepthRemapper::~Imp3DDepthRemapper()
     159             : {
     160           0 : }
     161             : 
     162           0 : sal_uInt32 Imp3DDepthRemapper::RemapOrdNum(sal_uInt32 nOrdNum) const
     163             : {
     164           0 :     if(nOrdNum < maVector.size())
     165             :     {
     166           0 :         nOrdNum = maVector[(maVector.size() - 1) - nOrdNum].GetOrdNum();
     167             :     }
     168             : 
     169           0 :     return nOrdNum;
     170             : }
     171             : 
     172             : 
     173             : // BaseProperties section
     174             : 
     175        1273 : sdr::properties::BaseProperties* E3dScene::CreateObjectSpecificProperties()
     176             : {
     177        1273 :     return new sdr::properties::E3dSceneProperties(*this);
     178             : }
     179             : 
     180             : 
     181             : // DrawContact section
     182             : 
     183        1273 : sdr::contact::ViewContact* E3dScene::CreateObjectSpecificViewContact()
     184             : {
     185        1273 :     return new sdr::contact::ViewContactOfE3dScene(*this);
     186             : }
     187             : 
     188             : 
     189             : 
     190    16916078 : TYPEINIT1(E3dScene, E3dObject);
     191             : 
     192        1273 : E3dScene::E3dScene()
     193             : :   E3dObject(),
     194             :     aCamera(basegfx::B3DPoint(0.0, 0.0, 4.0), basegfx::B3DPoint()),
     195             :     mp3DDepthRemapper(0L),
     196        1273 :     bDrawOnlySelected(false)
     197             : {
     198             :     // Set defaults
     199        1273 :     E3dDefaultAttributes aDefault;
     200        1273 :     SetDefaultAttributes(aDefault);
     201        1273 : }
     202             : 
     203           0 : E3dScene::E3dScene(E3dDefaultAttributes& rDefault)
     204             : :   E3dObject(),
     205             :     aCamera(basegfx::B3DPoint(0.0, 0.0, 4.0), basegfx::B3DPoint()),
     206             :     mp3DDepthRemapper(0L),
     207           0 :     bDrawOnlySelected(false)
     208             : {
     209             :     // Set defaults
     210           0 :     SetDefaultAttributes(rDefault);
     211           0 : }
     212             : 
     213        1273 : void E3dScene::SetDefaultAttributes(E3dDefaultAttributes& /*rDefault*/)
     214             : {
     215             :     // For WIN95/NT turn off the FP-Exceptions
     216             : #if defined(WNT)
     217             :     _control87( _MCW_EM, _MCW_EM );
     218             : #endif
     219             : 
     220             :     // Set defaults
     221        1273 :     aCamera.SetViewWindow(-2, -2, 4, 4);
     222        1273 :     aCameraSet.SetDeviceRectangle(-2, 2, -2, 2);
     223        1273 :     aCamera.SetDeviceWindow(Rectangle(0, 0, 10, 10));
     224        1273 :     Rectangle aRect(0, 0, 10, 10);
     225        1273 :     aCameraSet.SetViewportRectangle(aRect);
     226             : 
     227             :     // set defaults for Camera from ItemPool
     228        1273 :     aCamera.SetProjection(GetPerspective());
     229        1273 :     basegfx::B3DPoint aActualPosition(aCamera.GetPosition());
     230        1273 :     double fNew = GetDistance();
     231             : 
     232        1273 :     if(fabs(fNew - aActualPosition.getZ()) > 1.0)
     233             :     {
     234        1273 :         aCamera.SetPosition( basegfx::B3DPoint( aActualPosition.getX(), aActualPosition.getY(), fNew) );
     235             :     }
     236             : 
     237        1273 :     fNew = GetFocalLength() / 100.0;
     238        1273 :     aCamera.SetFocalLength(fNew);
     239        1273 : }
     240             : 
     241        2546 : E3dScene::~E3dScene()
     242             : {
     243        1273 :     ImpCleanup3DDepthMapper();
     244        1273 : }
     245             : 
     246           0 : basegfx::B2DPolyPolygon E3dScene::TakeXorPoly() const
     247             : {
     248           0 :     const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(GetViewContact());
     249           0 :     const drawinglayer::geometry::ViewInformation3D aViewInfo3D(rVCScene.getViewInformation3D());
     250           0 :     const basegfx::B3DPolyPolygon aCubePolyPolygon(CreateWireframe());
     251             : 
     252             :     basegfx::B2DPolyPolygon aRetval(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(aCubePolyPolygon,
     253           0 :         aViewInfo3D.getObjectToView()));
     254           0 :     aRetval.transform(rVCScene.getObjectTransformation());
     255             : 
     256           0 :     return aRetval;
     257             : }
     258             : 
     259      120603 : void E3dScene::ImpCleanup3DDepthMapper()
     260             : {
     261      120603 :     if(mp3DDepthRemapper)
     262             :     {
     263           0 :         delete mp3DDepthRemapper;
     264           0 :         mp3DDepthRemapper = 0L;
     265             :     }
     266      120603 : }
     267             : 
     268           0 : sal_uInt32 E3dScene::RemapOrdNum(sal_uInt32 nNewOrdNum) const
     269             : {
     270           0 :     if(!mp3DDepthRemapper)
     271             :     {
     272           0 :         const size_t nObjCount(GetSubList() ? GetSubList()->GetObjCount() : 0);
     273             : 
     274           0 :         if(nObjCount > 1)
     275             :         {
     276           0 :             const_cast<E3dScene*>(this)->mp3DDepthRemapper = new Imp3DDepthRemapper((E3dScene&)(*this));
     277             :         }
     278             :     }
     279             : 
     280           0 :     if(mp3DDepthRemapper)
     281             :     {
     282           0 :         return mp3DDepthRemapper->RemapOrdNum(nNewOrdNum);
     283             :     }
     284             : 
     285           0 :     return nNewOrdNum;
     286             : }
     287             : 
     288           0 : sal_uInt16 E3dScene::GetObjIdentifier() const
     289             : {
     290           0 :     return E3D_SCENE_ID;
     291             : }
     292             : 
     293     1205991 : void E3dScene::SetBoundRectDirty()
     294             : {
     295     1205991 :     E3dScene* pScene = GetScene();
     296             : 
     297     1205991 :     if(pScene == this)
     298             :     {
     299             :         // avoid resetting aOutRect which in case of a 3D scene used as 2d object
     300             :         // is model data,not re-creatable view data
     301             :     }
     302             :     else
     303             :     {
     304             :         // if not the outmost scene it is used as group in 3d, call parent
     305     1148552 :         E3dObject::SetBoundRectDirty();
     306             :     }
     307     1205991 : }
     308             : 
     309        3224 : void E3dScene::NbcSetSnapRect(const Rectangle& rRect)
     310             : {
     311        3224 :     SetRectsDirty();
     312        3224 :     E3dObject::NbcSetSnapRect(rRect);
     313        3224 :     aCamera.SetDeviceWindow(rRect);
     314        3224 :     aCameraSet.SetViewportRectangle((Rectangle&)rRect);
     315             : 
     316        3224 :     ImpCleanup3DDepthMapper();
     317        3224 : }
     318             : 
     319         206 : void E3dScene::NbcMove(const Size& rSize)
     320             : {
     321         206 :     Rectangle aNewSnapRect = GetSnapRect();
     322         206 :     MoveRect(aNewSnapRect, rSize);
     323         206 :     NbcSetSnapRect(aNewSnapRect);
     324         206 : }
     325             : 
     326           0 : void E3dScene::NbcResize(const Point& rRef, const Fraction& rXFact,
     327             :                                             const Fraction& rYFact)
     328             : {
     329           0 :     Rectangle aNewSnapRect = GetSnapRect();
     330           0 :     ResizeRect(aNewSnapRect, rRef, rXFact, rYFact);
     331           0 :     NbcSetSnapRect(aNewSnapRect);
     332           0 : }
     333             : 
     334             : // Set new camera, and thus mark the scene and if possible the bound volume
     335             : // as changed
     336             : 
     337        1366 : void E3dScene::SetCamera(const Camera3D& rNewCamera)
     338             : {
     339             :     // Set old camera
     340        1366 :     aCamera = rNewCamera;
     341        1366 :     static_cast<sdr::properties::E3dSceneProperties&>(GetProperties()).SetSceneItemsFromCamera();
     342             : 
     343        1366 :     SetRectsDirty();
     344             : 
     345             :     // Fill new camera from old
     346        1366 :     Camera3D& rCam = (Camera3D&)GetCamera();
     347             : 
     348             :     // Turn off ratio
     349        1366 :     if(rCam.GetAspectMapping() == AS_NO_MAPPING)
     350        1366 :         GetCameraSet().SetRatio(0.0);
     351             : 
     352             :     // Set Imaging geometry
     353        1366 :     basegfx::B3DPoint aVRP(rCam.GetViewPoint());
     354        2732 :     basegfx::B3DVector aVPN(aVRP - rCam.GetVRP());
     355        2732 :     basegfx::B3DVector aVUV(rCam.GetVUV());
     356             : 
     357             :     // use SetViewportValues() to set VRP, VPN and VUV as vectors, too.
     358             :     // Else these values would not be exported/imported correctly.
     359        1366 :     GetCameraSet().SetViewportValues(aVRP, aVPN, aVUV);
     360             : 
     361             :     // Set perspective
     362        1366 :     GetCameraSet().SetPerspective(rCam.GetProjection() == PR_PERSPECTIVE);
     363        1366 :     GetCameraSet().SetViewportRectangle((Rectangle&)rCam.GetDeviceWindow());
     364             : 
     365        2732 :     ImpCleanup3DDepthMapper();
     366        1366 : }
     367             : 
     368           0 : void E3dScene::NewObjectInserted(const E3dObject* p3DObj)
     369             : {
     370           0 :     E3dObject::NewObjectInserted(p3DObj);
     371             : 
     372           0 :     if ( p3DObj == this )
     373           0 :         return;
     374             : 
     375           0 :     ImpCleanup3DDepthMapper();
     376             : }
     377             : 
     378             : // Inform parent of changes of a child
     379             : 
     380      110609 : void E3dScene::StructureChanged()
     381             : {
     382      110609 :     E3dObject::StructureChanged();
     383      110609 :     SetRectsDirty();
     384             : 
     385      110609 :     ImpCleanup3DDepthMapper();
     386      110609 : }
     387             : 
     388             : // Determine the overall scene object
     389             : 
     390     5305631 : E3dScene* E3dScene::GetScene() const
     391             : {
     392     5305631 :     if(GetParentObj())
     393     4041370 :         return GetParentObj()->GetScene();
     394             :     else
     395     1264261 :         return const_cast<E3dScene*>(this);
     396             : }
     397             : 
     398           0 : void E3dScene::removeAllNonSelectedObjects()
     399             : {
     400           0 :     E3DModifySceneSnapRectUpdater aUpdater(this);
     401             : 
     402           0 :     for(size_t a = 0; a < maSubList.GetObjCount(); ++a)
     403             :     {
     404           0 :         SdrObject* pObj = maSubList.GetObj(a);
     405             : 
     406           0 :         if(pObj)
     407             :         {
     408           0 :             bool bRemoveObject(false);
     409             : 
     410           0 :             if(pObj->ISA(E3dScene))
     411             :             {
     412           0 :                 E3dScene* pScene = static_cast<E3dScene*>(pObj);
     413             : 
     414             :                 // iterate over this sub-scene
     415           0 :                 pScene->removeAllNonSelectedObjects();
     416             : 
     417             :                 // check object count. Empty scenes can be deleted
     418           0 :                 const size_t nObjCount(pScene->GetSubList() ? pScene->GetSubList()->GetObjCount() : 0);
     419             : 
     420           0 :                 if(!nObjCount)
     421             :                 {
     422             :                     // all objects removed, scene can be removed, too
     423           0 :                     bRemoveObject = true;
     424             :                 }
     425             :             }
     426           0 :             else if(pObj->ISA(E3dCompoundObject))
     427             :             {
     428           0 :                 E3dCompoundObject* pCompound = static_cast<E3dCompoundObject*>(pObj);
     429             : 
     430           0 :                 if(!pCompound->GetSelected())
     431             :                 {
     432           0 :                     bRemoveObject = true;
     433             :                 }
     434             :             }
     435             : 
     436           0 :             if(bRemoveObject)
     437             :             {
     438           0 :                 maSubList.NbcRemoveObject(pObj->GetOrdNum());
     439           0 :                 a--;
     440           0 :                 SdrObject::Free(pObj);
     441             :             }
     442             :         }
     443           0 :     }
     444           0 : }
     445             : 
     446           0 : E3dScene* E3dScene::Clone() const
     447             : {
     448           0 :     return CloneHelper< E3dScene >();
     449             : }
     450             : 
     451           0 : E3dScene& E3dScene::operator=(const E3dScene& rObj)
     452             : {
     453           0 :     if( this == &rObj )
     454           0 :         return *this;
     455           0 :     E3dObject::operator=(rObj);
     456             : 
     457           0 :     const E3dScene& r3DObj = (const E3dScene&) rObj;
     458           0 :     aCamera          = r3DObj.aCamera;
     459             : 
     460           0 :     aCameraSet = r3DObj.aCameraSet;
     461           0 :     static_cast<sdr::properties::E3dSceneProperties&>(GetProperties()).SetSceneItemsFromCamera();
     462             : 
     463           0 :     InvalidateBoundVolume();
     464           0 :     RebuildLists();
     465           0 :     SetRectsDirty();
     466             : 
     467           0 :     ImpCleanup3DDepthMapper();
     468             : 
     469             :     // #i101941#
     470             :     // After a Scene as model object is cloned, the used
     471             :     // ViewContactOfE3dScene is created and partially used
     472             :     // to calculate Bound/SnapRects, but - since quite some
     473             :     // values are buffered at the VC - not really well
     474             :     // initialized. It would be possible to always watch for
     475             :     // preconditions of buffered data, but this would be expensive
     476             :     // and would create a lot of short living data structures.
     477             :     // It is currently better to flush that data, e.g. by using
     478             :     // ActionChanged at the VC which will for this class
     479             :     // flush that cached data and initalize it's valid reconstruction
     480           0 :     GetViewContact().ActionChanged();
     481           0 :     return *this;
     482             : }
     483             : 
     484             : // Rebuild Light- and label- object lists rebuild (after loading, allocation)
     485             : 
     486           0 : void E3dScene::RebuildLists()
     487             : {
     488             :     // first delete
     489           0 :     SdrLayerID nCurrLayerID = GetLayer();
     490             : 
     491           0 :     SdrObjListIter a3DIterator(maSubList, IM_FLAT);
     492             : 
     493             :     // then examine all the objects in the scene
     494           0 :     while ( a3DIterator.IsMore() )
     495             :     {
     496           0 :         E3dObject* p3DObj = static_cast<E3dObject*>(a3DIterator.Next());
     497           0 :         p3DObj->NbcSetLayer(nCurrLayerID);
     498           0 :         NewObjectInserted(p3DObj);
     499           0 :     }
     500           0 : }
     501             : 
     502           0 : SdrObjGeoData *E3dScene::NewGeoData() const
     503             : {
     504           0 :     return new E3DSceneGeoData;
     505             : }
     506             : 
     507           0 : void E3dScene::SaveGeoData(SdrObjGeoData& rGeo) const
     508             : {
     509           0 :     E3dObject::SaveGeoData (rGeo);
     510             : 
     511           0 :     static_cast<E3DSceneGeoData &>(rGeo).aCamera = aCamera;
     512           0 : }
     513             : 
     514           0 : void E3dScene::RestGeoData(const SdrObjGeoData& rGeo)
     515             : {
     516             :     // #i94832# removed E3DModifySceneSnapRectUpdater here.
     517             :     // It should not be needed, is already part of E3dObject::RestGeoData
     518           0 :     E3dObject::RestGeoData (rGeo);
     519           0 :     SetCamera (static_cast<const E3DSceneGeoData &>(rGeo).aCamera);
     520           0 : }
     521             : 
     522             : // Something was changed in the style sheet, so change scene
     523             : 
     524           0 : void E3dScene::Notify(SfxBroadcaster &rBC, const SfxHint  &rHint)
     525             : {
     526           0 :     SetRectsDirty();
     527           0 :     E3dObject::Notify(rBC, rHint);
     528           0 : }
     529             : 
     530           0 : void E3dScene::RotateScene (const Point& rRef, long /*nAngle*/, double sn, double cs)
     531             : {
     532           0 :     Point UpperLeft, LowerRight, Center, NewCenter;
     533             : 
     534           0 :     UpperLeft = aOutRect.TopLeft();
     535           0 :     LowerRight = aOutRect.BottomRight();
     536             : 
     537           0 :     long dxOutRectHalf = labs(UpperLeft.X() - LowerRight.X());
     538           0 :     dxOutRectHalf /= 2;
     539           0 :     long dyOutRectHalf = labs(UpperLeft.Y() - LowerRight.Y());
     540           0 :     dyOutRectHalf /= 2;
     541             : 
     542             :         // Only the center is moved. The corners are moved by NbcMove. For the
     543             :         // rotation a cartesian coordinate system is used in which the pivot
     544             :         // point is the origin, and the y-axis increases upward, the X-axis to
     545             :         // the right. This must be especially noted for the Y-values.
     546             :         // (When considering a flat piece of paper the Y-axis pointing downwards
     547           0 :     Center.X() = (UpperLeft.X() + dxOutRectHalf) - rRef.X();
     548           0 :     Center.Y() = -((UpperLeft.Y() + dyOutRectHalf) - rRef.Y());
     549             :                   // A few special cases has to be dealt with first (n * 90 degrees n integer)
     550           0 :     if (sn==1.0 && cs==0.0) { // 90deg
     551           0 :         NewCenter.X() = -Center.Y();
     552           0 :         NewCenter.Y() = -Center.X();
     553           0 :     } else if (sn==0.0 && cs==-1.0) { // 180deg
     554           0 :         NewCenter.X() = -Center.X();
     555           0 :         NewCenter.Y() = -Center.Y();
     556           0 :     } else if (sn==-1.0 && cs==0.0) { // 270deg
     557           0 :         NewCenter.X() =  Center.Y();
     558           0 :         NewCenter.Y() = -Center.X();
     559             :     }
     560             :     else          // Here it is rotated to any angle in the mathematically
     561             :                   // positive direction!
     562             :     {             // xnew = x * cos(alpha) - y * sin(alpha)
     563             :                   // ynew = x * sin(alpha) + y * cos(alpha)
     564             :                   // Bottom Right is not rotated: the pages of aOutRect must
     565             :                   // remain parallel to the coordinate axes.
     566           0 :         NewCenter.X() = (long) (Center.X() * cs - Center.Y() * sn);
     567           0 :         NewCenter.Y() = (long) (Center.X() * sn + Center.Y() * cs);
     568             :     }
     569             : 
     570           0 :     Size Differenz;
     571           0 :     Point DiffPoint = (NewCenter - Center);
     572           0 :     Differenz.Width() = DiffPoint.X();
     573           0 :     Differenz.Height() = -DiffPoint.Y();  // Note that the Y-axis is counted ad positive downward.
     574           0 :     NbcMove (Differenz);  // Actually executes the coordinate transformation.
     575           0 : }
     576             : 
     577           0 : OUString E3dScene::TakeObjNameSingul() const
     578             : {
     579           0 :     OUStringBuffer sName(ImpGetResStr(STR_ObjNameSingulScene3d));
     580             : 
     581           0 :     OUString aName(GetName());
     582           0 :     if (!aName.isEmpty())
     583             :     {
     584           0 :         sName.append(' ');
     585           0 :         sName.append('\'');
     586           0 :         sName.append(aName);
     587           0 :         sName.append('\'');
     588             :     }
     589           0 :     return sName.makeStringAndClear();
     590             : }
     591             : 
     592           0 : OUString E3dScene::TakeObjNamePlural() const
     593             : {
     594           0 :     return ImpGetResStr(STR_ObjNamePluralScene3d);
     595             : }
     596             : 
     597             : // The NbcRotate routine overrides the one of the SdrObject. The idea is
     598             : // to be able to rotate the scene relative to the position of the scene
     599             : // and then the objects in the scene
     600             : 
     601         292 : void E3dScene::NbcSetTransform(const basegfx::B3DHomMatrix& rMatrix)
     602             : {
     603         292 :     if(maTransformation != rMatrix)
     604             :     {
     605             :         // call parent
     606         292 :         E3dObject::NbcSetTransform(rMatrix);
     607             :     }
     608         292 : }
     609             : 
     610        1591 : void E3dScene::SetTransform(const basegfx::B3DHomMatrix& rMatrix)
     611             : {
     612        1591 :     if(rMatrix != maTransformation)
     613             :     {
     614             :         // call parent
     615         292 :         E3dObject::SetTransform(rMatrix);
     616             :     }
     617        1591 : }
     618             : 
     619           0 : void E3dScene::NbcRotate(const Point& rRef, long nAngle, double sn, double cs)
     620             : {
     621             :     // So currently the glue points are defined relative to the scene aOutRect.
     622             :     // Before turning the glue points are defined relative to the page. They
     623             :     // take no part in the rotation of the scene. To ensure this, there is the
     624             :     // SetGlueReallyAbsolute(sal_True);
     625             : 
     626             :     // So that was the scene, now the objects used in the scene
     627             :     // 3D objects, if there is only one it can still have multiple surfaces but
     628             :     // the surfaces do not hve to be connected. This allows you to access child
     629             :     // objects. So going through the entire list and rotate around the Z axis
     630             :     // through the enter of aOutRect's (Steiner's theorem), so RotateZ
     631             : 
     632           0 :     RotateScene (rRef, nAngle, sn, cs);  // Rotates the scene
     633           0 :     double fWinkelInRad = nAngle/100.0 * F_PI180;
     634             : 
     635           0 :     basegfx::B3DHomMatrix aRotation;
     636           0 :     aRotation.rotate(0.0, 0.0, fWinkelInRad);
     637           0 :     NbcSetTransform(aRotation * GetTransform());
     638             : 
     639           0 :     SetRectsDirty();    // This forces a recalculation of all BoundRects
     640           0 :     NbcRotateGluePoints(rRef,nAngle,sn,cs);  // Rotate the glue points (who still
     641             :                                             // have coordinates relative to the
     642             :                                             // original page)
     643           0 :     SetGlueReallyAbsolute(false);  // from now they are again relative to BoundRect (that is defined as aOutRect)
     644           0 :     SetRectsDirty();
     645           0 : }
     646             : 
     647        2554 : void E3dScene::RecalcSnapRect()
     648             : {
     649        2554 :     E3dScene* pScene = GetScene();
     650             : 
     651        2554 :     if(pScene == this)
     652             :     {
     653             :         // The Scene is used as a 2D-Objekt, take the SnapRect from the
     654             :         // 2D Display settings
     655        1336 :         Camera3D& rCam = (Camera3D&)pScene->GetCamera();
     656        1336 :         maSnapRect = rCam.GetDeviceWindow();
     657             :     }
     658             :     else
     659             :     {
     660             :         // The Scene itself is a member of another scene, get the SnapRect
     661             :         // as a composite object
     662        1218 :         E3dObject::RecalcSnapRect();
     663             :     }
     664        2554 : }
     665             : 
     666           0 : bool E3dScene::IsBreakObjPossible()
     667             : {
     668             :     // Break scene, if all members are able to break
     669           0 :     SdrObjListIter a3DIterator(maSubList, IM_DEEPWITHGROUPS);
     670             : 
     671           0 :     while ( a3DIterator.IsMore() )
     672             :     {
     673           0 :         E3dObject* pObj = static_cast<E3dObject*>(a3DIterator.Next());
     674             :         DBG_ASSERT(pObj->ISA(E3dObject), "only 3D objects are allowed in scenes!");
     675           0 :         if(!pObj->IsBreakObjPossible())
     676           0 :             return false;
     677             :     }
     678             : 
     679           0 :     return true;
     680             : }
     681             : 
     682           0 : basegfx::B2DPolyPolygon E3dScene::TakeCreatePoly(const SdrDragStat& /*rDrag*/) const
     683             : {
     684           0 :     return TakeXorPoly();
     685             : }
     686             : 
     687           0 : bool E3dScene::BegCreate(SdrDragStat& rStat)
     688             : {
     689           0 :     rStat.SetOrtho4Possible();
     690           0 :     Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
     691           0 :     aRect1.Justify();
     692           0 :     rStat.SetActionRect(aRect1);
     693           0 :     NbcSetSnapRect(aRect1);
     694           0 :     return true;
     695             : }
     696             : 
     697           0 : bool E3dScene::MovCreate(SdrDragStat& rStat)
     698             : {
     699           0 :     Rectangle aRect1;
     700           0 :     rStat.TakeCreateRect(aRect1);
     701           0 :     aRect1.Justify();
     702           0 :     rStat.SetActionRect(aRect1);
     703           0 :     NbcSetSnapRect(aRect1);
     704           0 :     SetBoundRectDirty();
     705           0 :     bSnapRectDirty=true;
     706           0 :     return true;
     707             : }
     708             : 
     709           0 : bool E3dScene::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
     710             : {
     711           0 :     Rectangle aRect1;
     712           0 :     rStat.TakeCreateRect(aRect1);
     713           0 :     aRect1.Justify();
     714           0 :     NbcSetSnapRect(aRect1);
     715           0 :     SetRectsDirty();
     716           0 :     return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
     717             : }
     718             : 
     719           0 : bool E3dScene::BckCreate(SdrDragStat& /*rStat*/)
     720             : {
     721           0 :     return false;
     722             : }
     723             : 
     724           0 : void E3dScene::BrkCreate(SdrDragStat& /*rStat*/)
     725             : {
     726         435 : }
     727             : 
     728             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11