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

Generated by: LCOV version 1.10