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 <ChartModelHelper.hxx>
25 #include <DiagramHelper.hxx>
26 #include <ChartTypeHelper.hxx>
27 #include <ThreeDHelper.hxx>
28 #include <defines.hxx>
29 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
31 #include <svx/scene3d.hxx>
32 #include <basegfx/matrix/b3dhommatrix.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
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
;
42 using ::com::sun::star::uno::Reference
;
44 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper
& rDrawViewWrapper
45 , const OUString
& rObjectCID
46 , const Reference
< frame::XModel
>& xChartModel
47 , RotationDirection eRotationDirection
)
48 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
, ActionDescriptionProvider::ActionType::Rotate
)
50 , m_aReferenceRect(100,100,100,100)
52 , m_aWireframePolyPolygon()
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)
66 m_pScene
= SelectionHelper::getSceneToRotate( rDrawViewWrapper
.getNamedSdrObject( rObjectCID
) );
67 SdrObject
* pObj
= rDrawViewWrapper
.getSelectedObject();
70 m_aReferenceRect
= pObj
->GetLogicRect();
72 m_aWireframePolyPolygon
= m_pScene
->CreateWireframe();
74 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram(getChartModel()) );
75 uno::Reference
< beans::XPropertySet
> xDiagramProperties( xDiagram
, uno::UNO_QUERY
);
76 if( xDiagramProperties
.is() )
78 ThreeDHelper::getRotationFromDiagram( xDiagramProperties
79 , m_nInitialHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
);
81 ThreeDHelper::getRotationAngleFromDiagram( xDiagramProperties
82 , m_fInitialXAngleRad
, m_fInitialYAngleRad
, m_fInitialZAngleRad
);
84 if( ChartTypeHelper::isSupportingRightAngledAxes(
85 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ) ) )
86 xDiagramProperties
->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes
;
87 if(m_bRightAngledAxes
)
89 if( m_eRotationDirection
==ROTATIONDIRECTION_Z
)
90 m_eRotationDirection
=ROTATIONDIRECTION_FREE
;
91 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad
, m_fInitialYAngleRad
);
96 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
99 OUString
DragMethod_RotateDiagram::GetSdrDragComment() const
103 bool DragMethod_RotateDiagram::BeginSdrDrag()
105 m_aStartPos
= DragStat().GetStart();
109 void DragMethod_RotateDiagram::MoveSdrDrag(const Point
& rPnt
)
111 if( DragStat().CheckMinMoved(rPnt
) )
115 //calculate new angle
116 double fX
= F_PI2
* static_cast<double>(rPnt
.Y() - m_aStartPos
.Y())
117 / (m_aReferenceRect
.GetHeight() > 0 ? static_cast<double>(m_aReferenceRect
.GetHeight()) : 1.0);
118 double fY
= F_PI
* static_cast<double>(rPnt
.X() - m_aStartPos
.X())
119 / (m_aReferenceRect
.GetWidth() > 0 ? static_cast<double>(m_aReferenceRect
.GetWidth()) : 1.0);
121 if( m_eRotationDirection
!= ROTATIONDIRECTION_Y
)
122 m_fAdditionalYAngleRad
= fY
;
124 m_fAdditionalYAngleRad
= 0.0;
125 if( m_eRotationDirection
!= ROTATIONDIRECTION_X
)
126 m_fAdditionalXAngleRad
= fX
;
128 m_fAdditionalXAngleRad
= 0.0;
129 m_fAdditionalZAngleRad
= 0.0;
131 if( m_eRotationDirection
== ROTATIONDIRECTION_Z
)
133 m_fAdditionalXAngleRad
= 0.0;
134 m_fAdditionalYAngleRad
= 0.0;
136 double fCx
= m_aReferenceRect
.Center().X();
137 double fCy
= m_aReferenceRect
.Center().Y();
139 m_fAdditionalZAngleRad
= atan((fCx
- m_aStartPos
.X())/(m_aStartPos
.Y()-fCy
))
140 + atan((fCx
- rPnt
.X())/(fCy
-rPnt
.Y()));
143 m_nAdditionalHorizontalAngleDegree
= static_cast<sal_Int32
>(basegfx::rad2deg(m_fAdditionalXAngleRad
));
144 m_nAdditionalVerticalAngleDegree
= -static_cast<sal_Int32
>(basegfx::rad2deg(m_fAdditionalYAngleRad
));
146 DragStat().NextMove(rPnt
);
150 bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
154 if( m_bRightAngledAxes
|| m_eRotationDirection
==ROTATIONDIRECTION_Z
)
156 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
157 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
158 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
160 if(m_bRightAngledAxes
)
161 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
163 ThreeDHelper::setRotationAngleToDiagram( uno::Reference
< beans::XPropertySet
>( ChartModelHelper::findDiagram( getChartModel() ), uno::UNO_QUERY
)
164 , fResultX
, fResultY
, fResultZ
);
168 ThreeDHelper::setRotationToDiagram( ( uno::Reference
< beans::XPropertySet
>( ChartModelHelper::findDiagram( getChartModel() ), uno::UNO_QUERY
) )
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
)
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
)
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
);
210 // transform to relative scene coordinates
211 basegfx::B2DPolyPolygon
aPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon
, aTransform
));
213 // transform to 2D view coordinates
214 aPolyPolygon
.transform(rVCScene
.getObjectTransformation());
216 std::unique_ptr
<sdr::overlay::OverlayPolyPolygonStripedAndFilled
> pNew(
217 new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
220 insertNewlyCreatedOverlayObjectForSdrDragMethod(
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */