Debian Codegraph @

chart2/source/controller/main/DragMethod_RotateDiagram.cxx

raw
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 #include <DrawViewWrapper.hxx>
22
23 #include <SelectionHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <Diagram.hxx>
26 #include <ChartType.hxx>
27 #include <ThreeDHelper.hxx>
28 #include <defines.hxx>
29 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
30
31 #include <svx/scene3d.hxx>
32 #include <basegfx/matrix/b3dhommatrix.hxx>
33 #include <basegfx/polygon/b2dpolypolygontools.hxx>
34 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
35 #include <drawinglayer/geometry/viewinformation3d.hxx>
36
37 namespace chart
38 {
39
40 using namespace ::com::sun::star;
41
42 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper& rDrawViewWrapper
43 , const OUString& rObjectCID
44 , const rtl::Reference<::chart::ChartModel>& xChartModel
45 , RotationDirection eRotationDirection )
46 : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel, ActionDescriptionProvider::ActionType::Rotate )
47 , m_pScene(nullptr)
48 , m_aReferenceRect(100,100,100,100)
49 , m_aStartPos(0,0)
50 , m_fInitialXAngleRad(0.0)
51 , m_fInitialYAngleRad(0.0)
52 , m_fInitialZAngleRad(0.0)
53 , m_fAdditionalXAngleRad(0.0)
54 , m_fAdditionalYAngleRad(0.0)
55 , m_fAdditionalZAngleRad(0.0)
56 , m_nInitialHorizontalAngleDegree(0)
57 , m_nInitialVerticalAngleDegree(0)
58 , m_nAdditionalHorizontalAngleDegree(0)
59 , m_nAdditionalVerticalAngleDegree(0)
60 , m_eRotationDirection(eRotationDirection)
61 , m_bRightAngledAxes(false)
62 {
63 m_pScene = SelectionHelper::getSceneToRotate( rDrawViewWrapper.getNamedSdrObject( rObjectCID ) );
64 SdrObject* pObj = rDrawViewWrapper.getSelectedObject();
65 if(!(pObj && m_pScene))
66 return;
67
68 m_aReferenceRect = pObj->GetLogicRect();
69
70 m_aWireframePolyPolygon = m_pScene->CreateWireframe();
71
72 rtl::Reference< Diagram > xDiagram = getChartModel()->getFirstChartDiagram();
73 if( !xDiagram.is() )
74 return;
75
76 xDiagram->getRotation(
77 m_nInitialHorizontalAngleDegree, m_nInitialVerticalAngleDegree );
78
79 xDiagram->getRotationAngle(
80 m_fInitialXAngleRad, m_fInitialYAngleRad, m_fInitialZAngleRad );
81
82 auto xChartType = xDiagram->getChartTypeByIndex(0);
83 if (xChartType.is() ? xChartType->isSupportingRightAngledAxes() : true)
84 xDiagram->getPropertyValue(u"RightAngledAxes"_ustr) >>= m_bRightAngledAxes;
85 if(m_bRightAngledAxes)
86 {
87 if( m_eRotationDirection==ROTATIONDIRECTION_Z )
88 m_eRotationDirection=ROTATIONDIRECTION_FREE;
89 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad, m_fInitialYAngleRad );
90 }
91 }
92 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
93 {
94 }
95 OUString DragMethod_RotateDiagram::GetSdrDragComment() const
96 {
97 return OUString();
98 }
99 bool DragMethod_RotateDiagram::BeginSdrDrag()
100 {
101 m_aStartPos = DragStat().GetStart();
102 Show();
103 return true;
104 }
105 void DragMethod_RotateDiagram::MoveSdrDrag(const Point& rPnt)
106 {
107 if( !DragStat().CheckMinMoved(rPnt) )
108 return;
109
110 Hide();
111
112 //calculate new angle
113 double fX = M_PI_2 * static_cast<double>(rPnt.Y() - m_aStartPos.Y())
114 / (m_aReferenceRect.GetHeight() > 0 ? static_cast<double>(m_aReferenceRect.GetHeight()) : 1.0);
115 double fY = M_PI * static_cast<double>(rPnt.X() - m_aStartPos.X())
116 / (m_aReferenceRect.GetWidth() > 0 ? static_cast<double>(m_aReferenceRect.GetWidth()) : 1.0);
117
118 if( m_eRotationDirection != ROTATIONDIRECTION_Y )
119 m_fAdditionalYAngleRad = fY;
120 else
121 m_fAdditionalYAngleRad = 0.0;
122 if( m_eRotationDirection != ROTATIONDIRECTION_X )
123 m_fAdditionalXAngleRad = fX;
124 else
125 m_fAdditionalXAngleRad = 0.0;
126 m_fAdditionalZAngleRad = 0.0;
127
128 if( m_eRotationDirection == ROTATIONDIRECTION_Z )
129 {
130 m_fAdditionalXAngleRad = 0.0;
131 m_fAdditionalYAngleRad = 0.0;
132
133 double fCx = m_aReferenceRect.Center().X();
134 double fCy = m_aReferenceRect.Center().Y();
135
136 m_fAdditionalZAngleRad = atan((fCx - m_aStartPos.X())/(m_aStartPos.Y()-fCy))
137 + atan((fCx - rPnt.X())/(fCy-rPnt.Y()));
138 }
139
140 m_nAdditionalHorizontalAngleDegree = static_cast<sal_Int32>(basegfx::rad2deg(m_fAdditionalXAngleRad));
141 m_nAdditionalVerticalAngleDegree = -static_cast<sal_Int32>(basegfx::rad2deg(m_fAdditionalYAngleRad));
142
143 DragStat().NextMove(rPnt);
144 Show();
145 }
146 bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
147 {
148 Hide();
149
150 if( m_bRightAngledAxes || m_eRotationDirection==ROTATIONDIRECTION_Z )
151 {
152 double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
153 double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
154 double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
155
156 if(m_bRightAngledAxes)
157 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
158
159 rtl::Reference<Diagram> xDiagram = getChartModel()->getFirstChartDiagram();
160 if (xDiagram)
161 xDiagram->setRotationAngle( fResultX, fResultY, fResultZ );
162 }
163 else
164 {
165 rtl::Reference<Diagram> xDiagram = getChartModel()->getFirstChartDiagram();
166 if (xDiagram)
167 xDiagram->setRotation(
168 m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree );
169 }
170
171 return true;
172 }
173 void DragMethod_RotateDiagram::CreateOverlayGeometry(
174 sdr::overlay::OverlayManager& rOverlayManager,
175 const sdr::contact::ObjectContact& rObjectContact, bool /* bIsGeometrySizeValid */)
176 {
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 );
181
182 double fResultX = m_fInitialXAngleRad + m_fAdditionalXAngleRad;
183 double fResultY = m_fInitialYAngleRad + m_fAdditionalYAngleRad;
184 double fResultZ = m_fInitialZAngleRad + m_fAdditionalZAngleRad;
185
186 if(!m_bRightAngledAxes)
187 {
188 if( m_eRotationDirection!=ROTATIONDIRECTION_Z )
189 {
190 ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
191 m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, -(m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree)
192 , fResultX, fResultY, fResultZ );
193 }
194 aCurrentTransform.rotate( fResultX, fResultY, fResultZ );
195 }
196 else
197 {
198 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY );
199 aCurrentTransform.shearXY(fResultY,-fResultX);
200 }
201
202 if(!(m_aWireframePolyPolygon.count() && m_pScene))
203 return;
204
205 const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(m_pScene->GetViewContact());
206 const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D());
207 const basegfx::B3DHomMatrix aWorldToView(aViewInfo3D.getDeviceToView() * aViewInfo3D.getProjection() * aViewInfo3D.getOrientation());
208 const basegfx::B3DHomMatrix aTransform(aWorldToView * aCurrentTransform);
209
210 // transform to relative scene coordinates
211 basegfx::B2DPolyPolygon aPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon, aTransform));
212
213 // transform to 2D view coordinates
214 aPolyPolygon.transform(rVCScene.getObjectTransformation());
215
216 std::unique_ptr<sdr::overlay::OverlayPolyPolygonStripedAndFilled> pNew(
217 new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
218 std::move(aPolyPolygon)));
219
220 insertNewlyCreatedOverlayObjectForSdrDragMethod(
221 std::move(pNew),
222 rObjectContact,
223 rOverlayManager);
224 }
225 } //namespace chart
226
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */