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