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