fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / DragMethod_RotateDiagram.cxx
blobd929342ad43daf30879a4267f2cc9c4b6f446e39
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DragMethod_RotateDiagram.hxx"
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>
33 #include <svx/scene3d.hxx>
34 #include <basegfx/matrix/b3dhommatrix.hxx>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <basegfx/polygon/b2dpolypolygontools.hxx>
37 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
38 #include <drawinglayer/geometry/viewinformation3d.hxx>
40 namespace chart
43 using namespace ::com::sun::star;
44 using ::com::sun::star::uno::Reference;
46 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper& rDrawViewWrapper
47 , const OUString& rObjectCID
48 , const Reference< frame::XModel >& xChartModel
49 , RotationDirection eRotationDirection )
50 : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel, ActionDescriptionProvider::ROTATE )
51 , m_pScene(0)
52 , m_aReferenceRect(100,100,100,100)
53 , m_aStartPos(0,0)
54 , m_aWireframePolyPolygon()
55 , m_fInitialXAngleRad(0.0)
56 , m_fInitialYAngleRad(0.0)
57 , m_fInitialZAngleRad(0.0)
58 , m_fAdditionalXAngleRad(0.0)
59 , m_fAdditionalYAngleRad(0.0)
60 , m_fAdditionalZAngleRad(0.0)
61 , m_nInitialHorizontalAngleDegree(0)
62 , m_nInitialVerticalAngleDegree(0)
63 , m_nAdditionalHorizontalAngleDegree(0)
64 , m_nAdditionalVerticalAngleDegree(0)
65 , m_eRotationDirection(eRotationDirection)
66 , m_bRightAngledAxes(false)
68 m_pScene = SelectionHelper::getSceneToRotate( rDrawViewWrapper.getNamedSdrObject( rObjectCID ) );
69 SdrObject* pObj = rDrawViewWrapper.getSelectedObject();
70 if(pObj && m_pScene)
72 m_aReferenceRect = pObj->GetLogicRect();
74 m_aWireframePolyPolygon = m_pScene->CreateWireframe();
76 uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram(this->getChartModel()) );
77 uno::Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY );
78 if( xDiagramProperties.is() )
80 ThreeDHelper::getRotationFromDiagram( xDiagramProperties
81 , m_nInitialHorizontalAngleDegree, m_nInitialVerticalAngleDegree );
83 ThreeDHelper::getRotationAngleFromDiagram( xDiagramProperties
84 , m_fInitialXAngleRad, m_fInitialYAngleRad, m_fInitialZAngleRad );
86 if( ChartTypeHelper::isSupportingRightAngledAxes(
87 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
88 xDiagramProperties->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes;
89 if(m_bRightAngledAxes)
91 if( m_eRotationDirection==ROTATIONDIRECTION_Z )
92 m_eRotationDirection=ROTATIONDIRECTION_FREE;
93 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad, m_fInitialYAngleRad );
98 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
101 void DragMethod_RotateDiagram::TakeSdrDragComment(OUString& /*rStr*/) const
104 bool DragMethod_RotateDiagram::BeginSdrDrag()
106 m_aStartPos = DragStat().GetStart();
107 Show();
108 return true;
110 void DragMethod_RotateDiagram::MoveSdrDrag(const Point& rPnt)
112 if( DragStat().CheckMinMoved(rPnt) )
114 Hide();
116 //calculate new angle
117 double fX = F_PI / 2.0 * (double)(rPnt.Y() - m_aStartPos.Y())
118 / (m_aReferenceRect.GetHeight() > 0 ? (double)m_aReferenceRect.GetHeight() : 1.0);
119 double fY = F_PI * (double)(rPnt.X() - m_aStartPos.X())
120 / (m_aReferenceRect.GetWidth() > 0 ? (double)m_aReferenceRect.GetWidth() : 1.0);
122 if( m_eRotationDirection != ROTATIONDIRECTION_Y )
123 m_fAdditionalYAngleRad = fY;
124 else
125 m_fAdditionalYAngleRad = 0.0;
126 if( m_eRotationDirection != ROTATIONDIRECTION_X )
127 m_fAdditionalXAngleRad = fX;
128 else
129 m_fAdditionalXAngleRad = 0.0;
130 m_fAdditionalZAngleRad = 0.0;
132 if( m_eRotationDirection == ROTATIONDIRECTION_Z )
134 m_fAdditionalXAngleRad = 0.0;
135 m_fAdditionalYAngleRad = 0.0;
137 double fCx = m_aReferenceRect.Center().X();
138 double fCy = m_aReferenceRect.Center().Y();
140 m_fAdditionalZAngleRad = atan((double)(fCx - m_aStartPos.X())/(m_aStartPos.Y()-fCy))
141 + atan((double)(fCx - rPnt.X())/(fCy-rPnt.Y()));
144 m_nAdditionalHorizontalAngleDegree = static_cast<sal_Int32>(m_fAdditionalXAngleRad*180.0/F_PI);
145 m_nAdditionalVerticalAngleDegree = -static_cast<sal_Int32>(m_fAdditionalYAngleRad*180.0/F_PI);
147 DragStat().NextMove(rPnt);
148 Show();
151 bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
153 Hide();
155 if( m_bRightAngledAxes || m_eRotationDirection==ROTATIONDIRECTION_Z )
157 double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
158 double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
159 double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
161 if(m_bRightAngledAxes)
162 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
164 ThreeDHelper::setRotationAngleToDiagram( uno::Reference< beans::XPropertySet >( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY )
165 , fResultX, fResultY, fResultZ );
167 else
169 ThreeDHelper::setRotationToDiagram( ( uno::Reference< beans::XPropertySet >( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY ) )
170 , m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree );
173 return true;
175 void DragMethod_RotateDiagram::CreateOverlayGeometry(sdr::overlay::OverlayManager& rOverlayManager)
177 ::basegfx::B3DHomMatrix aCurrentTransform;
178 aCurrentTransform.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
179 -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
180 -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0 );
182 double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
183 double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
184 double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
186 if(!m_bRightAngledAxes)
188 if( m_eRotationDirection!=ROTATIONDIRECTION_Z )
190 ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
191 m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, -(m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree)
192 , fResultX, fResultY, fResultZ );
194 aCurrentTransform.rotate( fResultX, fResultY, fResultZ );
196 else
198 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
199 aCurrentTransform.shearXY(fResultY,-(fResultX));
202 if(m_aWireframePolyPolygon.count() && m_pScene)
204 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(m_pScene->GetViewContact());
205 const drawinglayer::geometry::ViewInformation3D aViewInfo3D(rVCScene.getViewInformation3D());
206 const basegfx::B3DHomMatrix aWorldToView(aViewInfo3D.getDeviceToView() * aViewInfo3D.getProjection() * aViewInfo3D.getOrientation());
207 const basegfx::B3DHomMatrix aTransform(aWorldToView * aCurrentTransform);
209 // transform to relative scene coordinates
210 basegfx::B2DPolyPolygon aPolyPolygon(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon, aTransform));
212 // transform to 2D view coordinates
213 aPolyPolygon.transform(rVCScene.getObjectTransformation());
215 sdr::overlay::OverlayPolyPolygonStripedAndFilled* pNew = new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
216 aPolyPolygon);
217 rOverlayManager.add(*pNew);
218 addToOverlayObjectList(*pNew);
221 } //namespace chart
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */