1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
21 #include <DrawViewWrapper.hxx>
23 #include <SelectionHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <Diagram.hxx>
26 #include <ChartType.hxx>
27 #include <ChartTypeHelper.hxx>
28 #include <ThreeDHelper.hxx>
29 #include <defines.hxx>
30 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
32 #include <svx/scene3d.hxx>
33 #include <basegfx/matrix/b3dhommatrix.hxx>
34 #include <basegfx/polygon/b2dpolypolygontools.hxx>
35 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
36 #include <drawinglayer/geometry/viewinformation3d.hxx>
41 using namespace ::com::sun::star
;
43 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper
& rDrawViewWrapper
44 , const OUString
& rObjectCID
45 , const rtl::Reference
<::chart::ChartModel
>& xChartModel
46 , RotationDirection eRotationDirection
)
47 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
, ActionDescriptionProvider::ActionType::Rotate
)
49 , m_aReferenceRect(100,100,100,100)
51 , m_fInitialXAngleRad(0.0)
52 , m_fInitialYAngleRad(0.0)
53 , m_fInitialZAngleRad(0.0)
54 , m_fAdditionalXAngleRad(0.0)
55 , m_fAdditionalYAngleRad(0.0)
56 , m_fAdditionalZAngleRad(0.0)
57 , m_nInitialHorizontalAngleDegree(0)
58 , m_nInitialVerticalAngleDegree(0)
59 , m_nAdditionalHorizontalAngleDegree(0)
60 , m_nAdditionalVerticalAngleDegree(0)
61 , m_eRotationDirection(eRotationDirection
)
62 , m_bRightAngledAxes(false)
64 m_pScene
= SelectionHelper::getSceneToRotate( rDrawViewWrapper
.getNamedSdrObject( rObjectCID
) );
65 SdrObject
* pObj
= rDrawViewWrapper
.getSelectedObject();
66 if(!(pObj
&& m_pScene
))
69 m_aReferenceRect
= pObj
->GetLogicRect();
71 m_aWireframePolyPolygon
= m_pScene
->CreateWireframe();
73 rtl::Reference
< Diagram
> xDiagram
= getChartModel()->getFirstChartDiagram();
77 xDiagram
->getRotation(
78 m_nInitialHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
);
80 xDiagram
->getRotationAngle(
81 m_fInitialXAngleRad
, m_fInitialYAngleRad
, m_fInitialZAngleRad
);
83 if( ChartTypeHelper::isSupportingRightAngledAxes(
84 xDiagram
->getChartTypeByIndex( 0 ) ) )
85 xDiagram
->getPropertyValue(u
"RightAngledAxes"_ustr
) >>= m_bRightAngledAxes
;
86 if(m_bRightAngledAxes
)
88 if( m_eRotationDirection
==ROTATIONDIRECTION_Z
)
89 m_eRotationDirection
=ROTATIONDIRECTION_FREE
;
90 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad
, m_fInitialYAngleRad
);
93 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
96 OUString
DragMethod_RotateDiagram::GetSdrDragComment() const
100 bool DragMethod_RotateDiagram::BeginSdrDrag()
102 m_aStartPos
= DragStat().GetStart();
106 void DragMethod_RotateDiagram::MoveSdrDrag(const Point
& rPnt
)
108 if( !DragStat().CheckMinMoved(rPnt
) )
113 //calculate new angle
114 double fX
= M_PI_2
* static_cast<double>(rPnt
.Y() - m_aStartPos
.Y())
115 / (m_aReferenceRect
.GetHeight() > 0 ? static_cast<double>(m_aReferenceRect
.GetHeight()) : 1.0);
116 double fY
= M_PI
* static_cast<double>(rPnt
.X() - m_aStartPos
.X())
117 / (m_aReferenceRect
.GetWidth() > 0 ? static_cast<double>(m_aReferenceRect
.GetWidth()) : 1.0);
119 if( m_eRotationDirection
!= ROTATIONDIRECTION_Y
)
120 m_fAdditionalYAngleRad
= fY
;
122 m_fAdditionalYAngleRad
= 0.0;
123 if( m_eRotationDirection
!= ROTATIONDIRECTION_X
)
124 m_fAdditionalXAngleRad
= fX
;
126 m_fAdditionalXAngleRad
= 0.0;
127 m_fAdditionalZAngleRad
= 0.0;
129 if( m_eRotationDirection
== ROTATIONDIRECTION_Z
)
131 m_fAdditionalXAngleRad
= 0.0;
132 m_fAdditionalYAngleRad
= 0.0;
134 double fCx
= m_aReferenceRect
.Center().X();
135 double fCy
= m_aReferenceRect
.Center().Y();
137 m_fAdditionalZAngleRad
= atan((fCx
- m_aStartPos
.X())/(m_aStartPos
.Y()-fCy
))
138 + atan((fCx
- rPnt
.X())/(fCy
-rPnt
.Y()));
141 m_nAdditionalHorizontalAngleDegree
= static_cast<sal_Int32
>(basegfx::rad2deg(m_fAdditionalXAngleRad
));
142 m_nAdditionalVerticalAngleDegree
= -static_cast<sal_Int32
>(basegfx::rad2deg(m_fAdditionalYAngleRad
));
144 DragStat().NextMove(rPnt
);
147 bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
151 if( m_bRightAngledAxes
|| m_eRotationDirection
==ROTATIONDIRECTION_Z
)
153 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
154 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
155 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
157 if(m_bRightAngledAxes
)
158 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
160 rtl::Reference
<Diagram
> xDiagram
= getChartModel()->getFirstChartDiagram();
162 xDiagram
->setRotationAngle( fResultX
, fResultY
, fResultZ
);
166 rtl::Reference
<Diagram
> xDiagram
= getChartModel()->getFirstChartDiagram();
168 xDiagram
->setRotation(
169 m_nInitialHorizontalAngleDegree
+m_nAdditionalHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
+m_nAdditionalVerticalAngleDegree
);
174 void DragMethod_RotateDiagram::CreateOverlayGeometry(
175 sdr::overlay::OverlayManager
& rOverlayManager
,
176 const sdr::contact::ObjectContact
& rObjectContact
, bool /* bIsGeometrySizeValid */)
178 ::basegfx::B3DHomMatrix aCurrentTransform
;
179 aCurrentTransform
.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
180 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
181 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0 );
183 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
184 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
185 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
187 if(!m_bRightAngledAxes
)
189 if( m_eRotationDirection
!=ROTATIONDIRECTION_Z
)
191 ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
192 m_nInitialHorizontalAngleDegree
+m_nAdditionalHorizontalAngleDegree
, -(m_nInitialVerticalAngleDegree
+m_nAdditionalVerticalAngleDegree
)
193 , fResultX
, fResultY
, fResultZ
);
195 aCurrentTransform
.rotate( fResultX
, fResultY
, fResultZ
);
199 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
200 aCurrentTransform
.shearXY(fResultY
,-fResultX
);
203 if(!(m_aWireframePolyPolygon
.count() && m_pScene
))
206 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(m_pScene
->GetViewContact());
207 const drawinglayer::geometry::ViewInformation3D
& aViewInfo3D(rVCScene
.getViewInformation3D());
208 const basegfx::B3DHomMatrix
aWorldToView(aViewInfo3D
.getDeviceToView() * aViewInfo3D
.getProjection() * aViewInfo3D
.getOrientation());
209 const basegfx::B3DHomMatrix
aTransform(aWorldToView
* aCurrentTransform
);
211 // transform to relative scene coordinates
212 basegfx::B2DPolyPolygon
aPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon
, aTransform
));
214 // transform to 2D view coordinates
215 aPolyPolygon
.transform(rVCScene
.getObjectTransformation());
217 std::unique_ptr
<sdr::overlay::OverlayPolyPolygonStripedAndFilled
> pNew(
218 new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
219 std::move(aPolyPolygon
)));
221 insertNewlyCreatedOverlayObjectForSdrDragMethod(
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */