LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/main - DragMethod_RotateDiagram.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 90 0.0 %
Date: 2012-12-27 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "DragMethod_RotateDiagram.hxx"
      21             : 
      22             : #include "SelectionHelper.hxx"
      23             : #include "CommonConverters.hxx"
      24             : #include "ChartModelHelper.hxx"
      25             : #include "macros.hxx"
      26             : #include "DiagramHelper.hxx"
      27             : #include "ChartTypeHelper.hxx"
      28             : #include "ThreeDHelper.hxx"
      29             : #include "defines.hxx"
      30             : #include <svx/sdr/overlay/overlaypolypolygon.hxx>
      31             : #include <svx/sdr/overlay/overlaymanager.hxx>
      32             : 
      33             : // header for class E3dScene
      34             : #include <svx/scene3d.hxx>
      35             : #include <basegfx/matrix/b3dhommatrix.hxx>
      36             : #include <com/sun/star/beans/XPropertySet.hpp>
      37             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      38             : #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
      39             : #include <drawinglayer/geometry/viewinformation3d.hxx>
      40             : 
      41             : //.............................................................................
      42             : namespace chart
      43             : {
      44             : //.............................................................................
      45             : 
      46             : using namespace ::com::sun::star;
      47             : using ::com::sun::star::uno::Reference;
      48             : 
      49           0 : DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper& rDrawViewWrapper
      50             :         , const rtl::OUString& rObjectCID
      51             :         , const Reference< frame::XModel >& xChartModel
      52             :         , RotationDirection eRotationDirection )
      53             :     : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel, ActionDescriptionProvider::ROTATE )
      54             :     , m_pScene(0)
      55             :     , m_aReferenceRect(100,100,100,100)
      56             :     , m_aStartPos(0,0)
      57             :     , m_aWireframePolyPolygon()
      58             :     , m_fInitialXAngleRad(0.0)
      59             :     , m_fInitialYAngleRad(0.0)
      60             :     , m_fInitialZAngleRad(0.0)
      61             :     , m_fAdditionalXAngleRad(0.0)
      62             :     , m_fAdditionalYAngleRad(0.0)
      63             :     , m_fAdditionalZAngleRad(0.0)
      64             :     , m_nInitialHorizontalAngleDegree(0)
      65             :     , m_nInitialVerticalAngleDegree(0)
      66             :     , m_nAdditionalHorizontalAngleDegree(0)
      67             :     , m_nAdditionalVerticalAngleDegree(0)
      68             :     , m_eRotationDirection(eRotationDirection)
      69           0 :     , m_bRightAngledAxes(sal_False)
      70             : {
      71           0 :     m_pScene = SelectionHelper::getSceneToRotate( rDrawViewWrapper.getNamedSdrObject( rObjectCID ) );
      72           0 :     SdrObject* pObj = rDrawViewWrapper.getSelectedObject();
      73           0 :     if(pObj && m_pScene)
      74             :     {
      75           0 :         m_aReferenceRect = pObj->GetLogicRect();
      76             : 
      77           0 :         m_aWireframePolyPolygon = m_pScene->CreateWireframe();
      78             : 
      79           0 :         uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram(this->getChartModel()) );
      80           0 :         uno::Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
      81           0 :         if( xDiagramProperties.is() )
      82             :         {
      83             :             ThreeDHelper::getRotationFromDiagram( xDiagramProperties
      84           0 :                 , m_nInitialHorizontalAngleDegree, m_nInitialVerticalAngleDegree );
      85             : 
      86             :             ThreeDHelper::getRotationAngleFromDiagram( xDiagramProperties
      87           0 :                 , m_fInitialXAngleRad, m_fInitialYAngleRad, m_fInitialZAngleRad );
      88             : 
      89           0 :             if( ChartTypeHelper::isSupportingRightAngledAxes(
      90           0 :                 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
      91           0 :                 xDiagramProperties->getPropertyValue(C2U( "RightAngledAxes" )) >>= m_bRightAngledAxes;
      92           0 :             if(m_bRightAngledAxes)
      93             :             {
      94           0 :                 if( m_eRotationDirection==ROTATIONDIRECTION_Z )
      95           0 :                     m_eRotationDirection=ROTATIONDIRECTION_FREE;
      96           0 :                 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad, m_fInitialYAngleRad );
      97             :             }
      98           0 :         }
      99             :     }
     100           0 : }
     101           0 : DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
     102             : {
     103           0 : }
     104           0 : void DragMethod_RotateDiagram::TakeSdrDragComment(String& /*rStr*/) const
     105             : {
     106           0 : }
     107           0 : bool DragMethod_RotateDiagram::BeginSdrDrag()
     108             : {
     109           0 :     m_aStartPos = DragStat().GetStart();
     110           0 :     Show();
     111           0 :     return true;
     112             : }
     113           0 : void DragMethod_RotateDiagram::MoveSdrDrag(const Point& rPnt)
     114             : {
     115           0 :     if( DragStat().CheckMinMoved(rPnt) )
     116             :     {
     117           0 :         Hide();
     118             : 
     119             :         //calculate new angle
     120           0 :         double fX = F_PI / 2.0 * (double)(rPnt.Y() - m_aStartPos.Y())
     121           0 :                 / (double)m_aReferenceRect.GetHeight();
     122           0 :         double fY = F_PI * (double)(rPnt.X() - m_aStartPos.X())
     123           0 :                 / (double)m_aReferenceRect.GetWidth();
     124             : 
     125           0 :         if( m_eRotationDirection != ROTATIONDIRECTION_Y )
     126           0 :             m_fAdditionalYAngleRad = fY;
     127             :         else
     128           0 :             m_fAdditionalYAngleRad = 0.0;
     129           0 :         if( m_eRotationDirection != ROTATIONDIRECTION_X )
     130           0 :             m_fAdditionalXAngleRad = fX;
     131             :         else
     132           0 :             m_fAdditionalXAngleRad = 0.0;
     133           0 :         m_fAdditionalZAngleRad = 0.0;
     134             : 
     135           0 :         if( m_eRotationDirection == ROTATIONDIRECTION_Z )
     136             :         {
     137           0 :             m_fAdditionalXAngleRad = 0.0;
     138           0 :             m_fAdditionalYAngleRad = 0.0;
     139             : 
     140           0 :             double fCx = m_aReferenceRect.Center().X();
     141           0 :             double fCy = m_aReferenceRect.Center().Y();
     142             : 
     143           0 :             m_fAdditionalZAngleRad = atan((double)(fCx - m_aStartPos.X())/(m_aStartPos.Y()-fCy))
     144           0 :                 + atan((double)(fCx - rPnt.X())/(fCy-rPnt.Y()));
     145             :         }
     146             : 
     147           0 :         m_nAdditionalHorizontalAngleDegree = static_cast<sal_Int32>(m_fAdditionalXAngleRad*180.0/F_PI);
     148           0 :         m_nAdditionalVerticalAngleDegree = -static_cast<sal_Int32>(m_fAdditionalYAngleRad*180.0/F_PI);
     149             : 
     150           0 :         DragStat().NextMove(rPnt);
     151           0 :         Show();
     152             :     }
     153           0 : }
     154           0 : bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
     155             : {
     156           0 :     Hide();
     157             : 
     158           0 :     if( m_bRightAngledAxes || m_eRotationDirection==ROTATIONDIRECTION_Z )
     159             :     {
     160           0 :         double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
     161           0 :         double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
     162           0 :         double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
     163             : 
     164           0 :         if(m_bRightAngledAxes)
     165           0 :             ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
     166             : 
     167             :         ThreeDHelper::setRotationAngleToDiagram( uno::Reference< beans::XPropertySet >( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY )
     168           0 :             , fResultX, fResultY, fResultZ );
     169             :     }
     170             :     else
     171             :     {
     172             :         ThreeDHelper::setRotationToDiagram( ( uno::Reference< beans::XPropertySet >( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY ) )
     173           0 :             , m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree );
     174             :     }
     175             : 
     176           0 :     return true;
     177             : }
     178           0 : void DragMethod_RotateDiagram::CreateOverlayGeometry(sdr::overlay::OverlayManager& rOverlayManager)
     179             : {
     180           0 :     ::basegfx::B3DHomMatrix aCurrentTransform;
     181             :     aCurrentTransform.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
     182             :                                  -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
     183           0 :                                  -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
     184             : 
     185           0 :     double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
     186           0 :     double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
     187           0 :     double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
     188             : 
     189           0 :     if(!m_bRightAngledAxes)
     190             :     {
     191           0 :         if( m_eRotationDirection!=ROTATIONDIRECTION_Z )
     192             :         {
     193             :             ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
     194             :                 m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, -(m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree)
     195           0 :                 , fResultX, fResultY, fResultZ );
     196             :         }
     197           0 :         aCurrentTransform.rotate( fResultX, fResultY, fResultZ );
     198             :     }
     199             :     else
     200             :     {
     201           0 :         ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
     202           0 :         aCurrentTransform.shearXY(fResultY,-(fResultX));
     203             :     }
     204             : 
     205           0 :     if(m_aWireframePolyPolygon.count() && m_pScene)
     206             :     {
     207           0 :         const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(m_pScene->GetViewContact());
     208           0 :         const drawinglayer::geometry::ViewInformation3D aViewInfo3D(rVCScene.getViewInformation3D());
     209           0 :         const basegfx::B3DHomMatrix aWorldToView(aViewInfo3D.getDeviceToView() * aViewInfo3D.getProjection() * aViewInfo3D.getOrientation());
     210           0 :         const basegfx::B3DHomMatrix aTransform(aWorldToView * aCurrentTransform);
     211             : 
     212             :         // transform to relative scene coordinates
     213           0 :         basegfx::B2DPolyPolygon aPolyPolygon(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon, aTransform));
     214             : 
     215             :         // transform to 2D view coordinates
     216           0 :         aPolyPolygon.transform(rVCScene.getObjectTransformation());
     217             : 
     218           0 :         sdr::overlay::OverlayPolyPolygonStriped* pNew = new ::sdr::overlay::OverlayPolyPolygonStriped(aPolyPolygon);
     219           0 :         rOverlayManager.add(*pNew);
     220           0 :         addToOverlayObjectList(*pNew);
     221           0 :     }
     222           0 : }
     223             : //.............................................................................
     224             : } //namespace chart
     225             : //.............................................................................
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10