LibreOffice Module chart2 (master) 1
DragMethod_RotateDiagram.cxx
Go to the documentation of this file.
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
21#include <DrawViewWrapper.hxx>
22
23#include <SelectionHelper.hxx>
24#include <ChartModelHelper.hxx>
25#include <ChartModel.hxx>
26#include <DiagramHelper.hxx>
27#include <Diagram.hxx>
28#include <ChartType.hxx>
29#include <ChartTypeHelper.hxx>
30#include <ThreeDHelper.hxx>
31#include <defines.hxx>
33
34#include <svx/scene3d.hxx>
39
40namespace chart
41{
42
43using namespace ::com::sun::star;
44
46 , const OUString& rObjectCID
47 , const rtl::Reference<::chart::ChartModel>& xChartModel
48 , RotationDirection eRotationDirection )
49 : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel, ActionDescriptionProvider::ActionType::Rotate )
50 , m_pScene(nullptr)
51 , m_aReferenceRect(100,100,100,100)
52 , m_aStartPos(0,0)
53 , m_fInitialXAngleRad(0.0)
54 , m_fInitialYAngleRad(0.0)
55 , m_fInitialZAngleRad(0.0)
56 , m_fAdditionalXAngleRad(0.0)
57 , m_fAdditionalYAngleRad(0.0)
58 , m_fAdditionalZAngleRad(0.0)
59 , m_nInitialHorizontalAngleDegree(0)
60 , m_nInitialVerticalAngleDegree(0)
61 , m_nAdditionalHorizontalAngleDegree(0)
62 , m_nAdditionalVerticalAngleDegree(0)
63 , m_eRotationDirection(eRotationDirection)
64 , m_bRightAngledAxes(false)
65{
66 m_pScene = SelectionHelper::getSceneToRotate( rDrawViewWrapper.getNamedSdrObject( rObjectCID ) );
67 SdrObject* pObj = rDrawViewWrapper.getSelectedObject();
68 if(!(pObj && m_pScene))
69 return;
70
72
74
75 rtl::Reference< Diagram > xDiagram = getChartModel()->getFirstChartDiagram();
76 if( !xDiagram.is() )
77 return;
78
79 xDiagram->getRotation(
81
82 xDiagram->getRotationAngle(
84
86 xDiagram->getChartTypeByIndex( 0 ) ) )
87 xDiagram->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes;
89 {
93 }
94}
96{
97}
99{
100 return OUString();
101}
103{
105 Show();
106 return true;
107}
109{
110 if( !DragStat().CheckMinMoved(rPnt) )
111 return;
112
113 Hide();
114
115 //calculate new angle
116 double fX = M_PI_2 * static_cast<double>(rPnt.Y() - m_aStartPos.Y())
117 / (m_aReferenceRect.GetHeight() > 0 ? static_cast<double>(m_aReferenceRect.GetHeight()) : 1.0);
118 double fY = M_PI * static_cast<double>(rPnt.X() - m_aStartPos.X())
119 / (m_aReferenceRect.GetWidth() > 0 ? static_cast<double>(m_aReferenceRect.GetWidth()) : 1.0);
120
123 else
127 else
130
132 {
135
136 double fCx = m_aReferenceRect.Center().X();
137 double fCy = m_aReferenceRect.Center().Y();
138
139 m_fAdditionalZAngleRad = atan((fCx - m_aStartPos.X())/(m_aStartPos.Y()-fCy))
140 + atan((fCx - rPnt.X())/(fCy-rPnt.Y()));
141 }
142
145
146 DragStat().NextMove(rPnt);
147 Show();
148}
150{
151 Hide();
152
154 {
158
161
162 rtl::Reference<Diagram> xDiagram = getChartModel()->getFirstChartDiagram();
163 if (xDiagram)
164 xDiagram->setRotationAngle( fResultX, fResultY, fResultZ );
165 }
166 else
167 {
168 rtl::Reference<Diagram> xDiagram = getChartModel()->getFirstChartDiagram();
169 if (xDiagram)
170 xDiagram->setRotation(
172 }
173
174 return true;
175}
177 sdr::overlay::OverlayManager& rOverlayManager,
178 const sdr::contact::ObjectContact& rObjectContact)
179{
180 ::basegfx::B3DHomMatrix aCurrentTransform;
181 aCurrentTransform.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0,
184
188
190 {
192 {
195 , fResultX, fResultY, fResultZ );
196 }
197 aCurrentTransform.rotate( fResultX, fResultY, fResultZ );
198 }
199 else
200 {
202 aCurrentTransform.shearXY(fResultY,-fResultX);
203 }
204
206 return;
207
210 const basegfx::B3DHomMatrix aWorldToView(aViewInfo3D.getDeviceToView() * aViewInfo3D.getProjection() * aViewInfo3D.getOrientation());
211 const basegfx::B3DHomMatrix aTransform(aWorldToView * aCurrentTransform);
212
213 // transform to relative scene coordinates
215
216 // transform to 2D view coordinates
217 aPolyPolygon.transform(rVCScene.getObjectTransformation());
218
219 std::unique_ptr<sdr::overlay::OverlayPolyPolygonStripedAndFilled> pNew(
221 std::move(aPolyPolygon)));
222
224 std::move(pNew),
225 rObjectContact,
226 rOverlayManager);
227}
228} //namespace chart
229
230/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::B3DPolyPolygon CreateWireframe() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
SdrDragStat & DragStat()
void insertNewlyCreatedOverlayObjectForSdrDragMethod(std::unique_ptr< sdr::overlay::OverlayObject > pOverlayObject, const sdr::contact::ObjectContact &rObjectContact, sdr::overlay::OverlayManager &rOverlayManager)
void NextMove(const Point &rPnt)
const Point & GetStart() const
sdr::contact::ViewContact & GetViewContact() const
virtual const tools::Rectangle & GetLogicRect() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
void shearXY(double fSx, double fSy)
void rotate(double fAngleX, double fAngleY, double fAngleZ)
void translate(double fX, double fY, double fZ)
sal_uInt32 count() const
static bool isSupportingRightAngledAxes(const rtl::Reference< ::chart::ChartType > &xChartType)
rtl::Reference<::chart::ChartModel > getChartModel() const
basegfx::B3DPolyPolygon m_aWireframePolyPolygon
virtual OUString GetSdrDragComment() const override
virtual bool EndSdrDrag(bool bCopy) override
virtual void MoveSdrDrag(const Point &rPnt) override
DragMethod_RotateDiagram(DrawViewWrapper &rDrawViewWrapper, const OUString &rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel, RotationDirection eRotationDirection)
virtual void CreateOverlayGeometry(sdr::overlay::OverlayManager &rOverlayManager, const sdr::contact::ObjectContact &rObjectContact) override
SdrObject * getNamedSdrObject(const OUString &rName) const
SdrObject * getSelectedObject() const
static E3dScene * getSceneToRotate(SdrObject *pObj)
static void adaptRadAnglesForRightAngledAxes(double &rfXAngleRad, double &rfYAngleRad)
static void convertElevationRotationDegToXYZAngleRad(sal_Int32 nElevationDeg, sal_Int32 nRotationDeg, double &rfXAngleRad, double &rfYAngleRad, double &rfZAngleRad)
const basegfx::B3DHomMatrix & getDeviceToView() const
const basegfx::B3DHomMatrix & getProjection() const
const basegfx::B3DHomMatrix & getOrientation() const
const drawinglayer::geometry::ViewInformation3D & getViewInformation3D(const ::basegfx::B3DRange &rContentRange) const
const basegfx::B2DHomMatrix & getObjectTransformation() const
constexpr Point Center() const
constexpr tools::Long GetWidth() const
constexpr tools::Long GetHeight() const
constexpr double FIXED_SIZE_FOR_3D_CHART_VOLUME
Definition: defines.hxx:22
B2DPolyPolygon createB2DPolyPolygonFromB3DPolyPolygon(const B3DPolyPolygon &rCandidate, const B3DHomMatrix &rMat)
constexpr double rad2deg(double v)