1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DragMethod_RotateDiagram.cxx,v $
10 * $Revision: 1.6.60.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "DragMethod_RotateDiagram.hxx"
35 #include "SelectionHelper.hxx"
36 #include "CommonConverters.hxx"
37 #include "ChartModelHelper.hxx"
39 #include "DiagramHelper.hxx"
40 #include "ChartTypeHelper.hxx"
41 #include "ThreeDHelper.hxx"
42 #include <svx/sdr/overlay/overlaypolypolygon.hxx>
43 #include <svx/sdr/overlay/overlaymanager.hxx>
45 // header for class E3dScene
46 #include <svx/scene3d.hxx>
47 #include <basegfx/matrix/b3dhommatrix.hxx>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <basegfx/polygon/b2dpolypolygontools.hxx>
50 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
51 #include <drawinglayer/geometry/viewinformation3d.hxx>
53 #define FIXED_SIZE_FOR_3D_CHART_VOLUME (10000.0)
55 //.............................................................................
58 //.............................................................................
60 using namespace ::com::sun::star
;
61 using ::com::sun::star::uno::Reference
;
63 DragMethod_RotateDiagram::DragMethod_RotateDiagram( DrawViewWrapper
& rDrawViewWrapper
64 , const rtl::OUString
& rObjectCID
65 , const Reference
< frame::XModel
>& xChartModel
66 , RotationDirection eRotationDirection
)
67 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
, ActionDescriptionProvider::ROTATE
)
69 , m_aReferenceRect(100,100,100,100)
71 , m_aWireframePolyPolygon()
72 , m_fInitialXAngleRad(0.0)
73 , m_fInitialYAngleRad(0.0)
74 , m_fInitialZAngleRad(0.0)
75 , m_fAdditionalXAngleRad(0.0)
76 , m_fAdditionalYAngleRad(0.0)
77 , m_fAdditionalZAngleRad(0.0)
78 , m_nInitialHorizontalAngleDegree(0)
79 , m_nInitialVerticalAngleDegree(0)
80 , m_nAdditionalHorizontalAngleDegree(0)
81 , m_nAdditionalVerticalAngleDegree(0)
82 , m_eRotationDirection(eRotationDirection
)
83 , m_bRightAngledAxes(sal_False
)
85 m_pScene
= SelectionHelper::getSceneToRotate( rDrawViewWrapper
.getNamedSdrObject( rObjectCID
) );
86 SdrObject
* pObj
= rDrawViewWrapper
.getSelectedObject();
89 m_aReferenceRect
= pObj
->GetLogicRect();
90 Rectangle aTemp
= m_pScene
->GetLogicRect();
92 m_aWireframePolyPolygon
= m_pScene
->CreateWireframe();
94 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram(this->getChartModel()) );
95 uno::Reference
< beans::XPropertySet
> xDiagramProperties( xDiagram
, uno::UNO_QUERY
);
96 if( xDiagramProperties
.is() )
98 ThreeDHelper::getRotationFromDiagram( xDiagramProperties
99 , m_nInitialHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
);
101 ThreeDHelper::getRotationAngleFromDiagram( xDiagramProperties
102 , m_fInitialXAngleRad
, m_fInitialYAngleRad
, m_fInitialZAngleRad
);
104 if( ChartTypeHelper::isSupportingRightAngledAxes(
105 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ) ) )
106 xDiagramProperties
->getPropertyValue(C2U( "RightAngledAxes" )) >>= m_bRightAngledAxes
;
107 if(m_bRightAngledAxes
)
109 if( m_eRotationDirection
==ROTATIONDIRECTION_Z
)
110 m_eRotationDirection
=ROTATIONDIRECTION_FREE
;
111 ThreeDHelper::adaptRadAnglesForRightAngledAxes( m_fInitialXAngleRad
, m_fInitialYAngleRad
);
116 DragMethod_RotateDiagram::~DragMethod_RotateDiagram()
119 void DragMethod_RotateDiagram::TakeSdrDragComment(String
& /*rStr*/) const
122 bool DragMethod_RotateDiagram::BeginSdrDrag()
124 m_aStartPos
= DragStat().GetStart();
128 void DragMethod_RotateDiagram::MoveSdrDrag(const Point
& rPnt
)
130 if( DragStat().CheckMinMoved(rPnt
) )
134 //calculate new angle
135 double fX
= F_PI
/ 2.0 * (double)(rPnt
.Y() - m_aStartPos
.Y())
136 / (double)m_aReferenceRect
.GetHeight();
137 double fY
= F_PI
* (double)(rPnt
.X() - m_aStartPos
.X())
138 / (double)m_aReferenceRect
.GetWidth();
140 if( m_eRotationDirection
!= ROTATIONDIRECTION_Y
)
141 m_fAdditionalYAngleRad
= fY
;
143 m_fAdditionalYAngleRad
= 0.0;
144 if( m_eRotationDirection
!= ROTATIONDIRECTION_X
)
145 m_fAdditionalXAngleRad
= fX
;
147 m_fAdditionalXAngleRad
= 0.0;
148 m_fAdditionalZAngleRad
= 0.0;
150 if( m_eRotationDirection
== ROTATIONDIRECTION_Z
)
152 m_fAdditionalXAngleRad
= 0.0;
153 m_fAdditionalYAngleRad
= 0.0;
155 double fCx
= m_aReferenceRect
.Center().X();
156 double fCy
= m_aReferenceRect
.Center().Y();
158 m_fAdditionalZAngleRad
= atan((double)(fCx
- m_aStartPos
.X())/(m_aStartPos
.Y()-fCy
))
159 + atan((double)(fCx
- rPnt
.X())/(fCy
-rPnt
.Y()));
162 m_nAdditionalHorizontalAngleDegree
= static_cast<sal_Int32
>(m_fAdditionalXAngleRad
*180.0/F_PI
);
163 m_nAdditionalVerticalAngleDegree
= -static_cast<sal_Int32
>(m_fAdditionalYAngleRad
*180.0/F_PI
);
165 DragStat().NextMove(rPnt
);
169 bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
173 if( m_bRightAngledAxes
|| m_eRotationDirection
==ROTATIONDIRECTION_Z
)
175 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
176 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
177 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
179 if(m_bRightAngledAxes
)
180 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
182 ThreeDHelper::setRotationAngleToDiagram( uno::Reference
< beans::XPropertySet
>( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY
)
183 , fResultX
, fResultY
, fResultZ
);
187 ThreeDHelper::setRotationToDiagram( ( uno::Reference
< beans::XPropertySet
>( ChartModelHelper::findDiagram( this->getChartModel() ), uno::UNO_QUERY
) )
188 , m_nInitialHorizontalAngleDegree
+m_nAdditionalHorizontalAngleDegree
, m_nInitialVerticalAngleDegree
+m_nAdditionalVerticalAngleDegree
);
193 void DragMethod_RotateDiagram::CreateOverlayGeometry(sdr::overlay::OverlayManager
& rOverlayManager
)
195 ::basegfx::B3DHomMatrix aCurrentTransform
;
196 aCurrentTransform
.translate( -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
197 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0,
198 -FIXED_SIZE_FOR_3D_CHART_VOLUME
/2.0 );
200 double fResultX
= m_fInitialXAngleRad
+ m_fAdditionalXAngleRad
;
201 double fResultY
= m_fInitialYAngleRad
+ m_fAdditionalYAngleRad
;
202 double fResultZ
= m_fInitialZAngleRad
+ m_fAdditionalZAngleRad
;
204 if(!m_bRightAngledAxes
)
206 if( m_eRotationDirection
!=ROTATIONDIRECTION_Z
)
208 ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
209 m_nInitialHorizontalAngleDegree
+m_nAdditionalHorizontalAngleDegree
, -(m_nInitialVerticalAngleDegree
+m_nAdditionalVerticalAngleDegree
)
210 , fResultX
, fResultY
, fResultZ
);
212 aCurrentTransform
.rotate( fResultX
, fResultY
, fResultZ
);
216 ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX
, fResultY
);
217 aCurrentTransform
.shearXY(fResultY
,-(fResultX
));
220 if(m_aWireframePolyPolygon
.count() && m_pScene
)
222 const sdr::contact::ViewContactOfE3dScene
& rVCScene
= static_cast< sdr::contact::ViewContactOfE3dScene
& >(m_pScene
->GetViewContact());
223 const drawinglayer::geometry::ViewInformation3D
aViewInfo3D(rVCScene
.getViewInformation3D());
224 const basegfx::B3DHomMatrix
aWorldToView(aViewInfo3D
.getDeviceToView() * aViewInfo3D
.getProjection() * aViewInfo3D
.getOrientation());
225 const basegfx::B3DHomMatrix
aTransform(aWorldToView
* aCurrentTransform
);
227 // transform to relative scene coordinates
228 basegfx::B2DPolyPolygon
aPolyPolygon(basegfx::tools::createB2DPolyPolygonFromB3DPolyPolygon(m_aWireframePolyPolygon
, aTransform
));
230 // transform to 2D view coordinates
231 aPolyPolygon
.transform(rVCScene
.getObjectTransformation());
233 sdr::overlay::OverlayPolyPolygonStriped
* pNew
= new ::sdr::overlay::OverlayPolyPolygonStriped(aPolyPolygon
);
234 rOverlayManager
.add(*pNew
);
235 addToOverlayObjectList(*pNew
);
238 //.............................................................................
240 //.............................................................................