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"
22 #include <SelectionHelper.hxx>
23 #include <CommonConverters.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>
30 #include <svx/sdr/overlay/overlaymanager.hxx>
32 #include <svx/scene3d.hxx>
33 #include <basegfx/matrix/b3dhommatrix.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <basegfx/polygon/b2dpolypolygontools.hxx>
36 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
37 #include <drawinglayer/geometry/viewinformation3d.hxx>
42 using namespace ::com::sun::star
;
43 using ::com::sun::star::uno::Reference
;
45 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper
& rDrawViewWrapper
46 , const OUString
& rObjectCID
47 , const Reference
< frame::XModel
>& xChartModel
48 , RotationDirection eRotationDirection
)
49 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
, ActionDescriptionProvider::ActionType::Rotate
)
51 , m_aReferenceRect(100,100,100,100)
53 , m_aWireframePolyPolygon()
54 , m_fInitialXAngleRad(0.0)
55 , m_fInitialYAngleRad(0.0)
56 , m_fInitialZAngleRad(0.0)
57 , m_fAdditionalXAngleRad(0.0)
58 , m_fAdditionalYAngleRad(0.0)
59 , m_fAdditionalZAngleRad(0.0)
60 , m_nInitialHorizontalAngleDegree(0)
61 , m_nInitialVerticalAngleDegree(0)
62 , m_nAdditionalHorizontalAngleDegree(0)
63 , m_nAdditionalVerticalAngleDegree(0)
64 , m_eRotationDirection(eRotationDirection
)
65 , m_bRightAngledAxes(false)
67 m_pScene
= SelectionHelper::getSceneToRotate( rDrawViewWrapper
.getNamedSdrObject( rObjectCID
) );
68 SdrObject
* pObj
= rDrawViewWrapper
.getSelectedObject();
71 m_aReferenceRect
= pObj
->GetLogicRect();
73 m_aWireframePolyPolygon
= m_pScene
->CreateWireframe();
75 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram(getChartModel()) );
76 uno::Reference
< beans::XPropertySet
> xDiagramProperties( xDiagram
, uno::UNO_QUERY
);
77 if( xDiagramProperties
.is() )
79 ThreeDHelper::getRotationFromDiagram( xDiagramProperties
80 , m_nInitialHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
);
82 ThreeDHelper::getRotationAngleFromDiagram( xDiagramProperties
83 , m_fInitialXAngleRad
, m_fInitialYAngleRad
, m_fInitialZAngleRad
);
85 if( ChartTypeHelper::isSupportingRightAngledAxes(
86 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ) ) )
87 xDiagramProperties
->getPropertyValue("RightAngledAxes") >>= m_bRightAngledAxes
;
88 if(m_bRightAngledAxes
)
90 if( m_eRotationDirection
==ROTATIONDIRECTION_Z
)
91 m_eRotationDirection
=ROTATIONDIRECTION_FREE
;
92 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad
, m_fInitialYAngleRad
);
97 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
100 void DragMethod_RotateDiagram::TakeSdrDragComment(OUString
& /*rStr*/) 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_PI
/ 2.0 * 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
>(m_fAdditionalXAngleRad
*180.0/F_PI
);
144 m_nAdditionalVerticalAngleDegree
= -static_cast<sal_Int32
>(m_fAdditionalYAngleRad
*180.0/F_PI
);
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(sdr::overlay::OverlayManager
& rOverlayManager
)
176 ::basegfx::B3DHomMatrix aCurrentTransform
;
177 aCurrentTransform
.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
178 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
179 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0 );
181 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
182 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
183 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
185 if(!m_bRightAngledAxes
)
187 if( m_eRotationDirection
!=ROTATIONDIRECTION_Z
)
189 ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
190 m_nInitialHorizontalAngleDegree
+m_nAdditionalHorizontalAngleDegree
, -(m_nInitialVerticalAngleDegree
+m_nAdditionalVerticalAngleDegree
)
191 , fResultX
, fResultY
, fResultZ
);
193 aCurrentTransform
.rotate( fResultX
, fResultY
, fResultZ
);
197 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
198 aCurrentTransform
.shearXY(fResultY
,-fResultX
);
201 if(m_aWireframePolyPolygon
.count() && m_pScene
)
203 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(m_pScene
->GetViewContact());
204 const drawinglayer::geometry::ViewInformation3D
& aViewInfo3D(rVCScene
.getViewInformation3D());
205 const basegfx::B3DHomMatrix
aWorldToView(aViewInfo3D
.getDeviceToView() * aViewInfo3D
.getProjection() * aViewInfo3D
.getOrientation());
206 const basegfx::B3DHomMatrix
aTransform(aWorldToView
* aCurrentTransform
);
208 // transform to relative scene coordinates
209 basegfx::B2DPolyPolygon
aPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon
, aTransform
));
211 // transform to 2D view coordinates
212 aPolyPolygon
.transform(rVCScene
.getObjectTransformation());
214 sdr::overlay::OverlayPolyPolygonStripedAndFilled
* pNew
= new sdr::overlay::OverlayPolyPolygonStripedAndFilled(
216 rOverlayManager
.add(*pNew
);
217 addToOverlayObjectList(pNew
);
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */