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