1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "VCartesianCoordinateSystem.hxx"
31 #include "VCartesianGrid.hxx"
32 #include "VCartesianAxis.hxx"
33 #include "macros.hxx"
34 #include "AxisIndexDefines.hxx"
35 #include "AxisHelper.hxx"
36 #include "ChartTypeHelper.hxx"
37 
38 //for auto_ptr
39 #include <memory>
40 
41 //.............................................................................
42 namespace chart
43 {
44 //.............................................................................
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::chart2;
47 using ::com::sun::star::uno::Reference;
48 
49 //.............................................................................
50 
51 class TextualDataProvider : public ::cppu::WeakImplHelper1<
52         ::com::sun::star::chart2::data::XTextualDataSequence
53 		>
54 {
55 public:
56     TextualDataProvider( const uno::Sequence< ::rtl::OUString >& rTextSequence )
57         : m_aTextSequence( rTextSequence )
58     {
59     }
60 	virtual ~TextualDataProvider()
61     {
62     }
63 
64     //XTextualDataSequence
65     virtual uno::Sequence< ::rtl::OUString > SAL_CALL getTextualData()
66         throw ( uno::RuntimeException)
67     {
68         return m_aTextSequence;
69     }
70 
71 private: //member
72     uno::Sequence< ::rtl::OUString > m_aTextSequence;
73 };
74 
75 //.............................................................................
76 
77 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
78     : VCoordinateSystem(xCooSys)
79 {
80 }
81 
82 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
83 {
84 }
85 
86 void VCartesianCoordinateSystem::createGridShapes()
87 {
88     if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
89         return;
90 
91     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
92     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
93 
94     for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
95     {
96         sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
97         Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
98         if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
99             continue;
100 
101         VCartesianGrid aGrid(nDimensionIndex,nDimensionCount,this->getGridListFromAxis( xAxis ));
102         aGrid.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex,nAxisIndex)
103                             , this->getExplicitIncrement(nDimensionIndex,nAxisIndex) );
104         aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
105 
106         aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
107             , this->createCIDForGrid( xAxis,nDimensionIndex,nAxisIndex ) );
108         if(2==nDimensionCount)
109             aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
110         aGrid.setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
111         aGrid.createShapes();
112     }
113 }
114 
115 void VCartesianCoordinateSystem::createVAxisList(
116               const uno::Reference< util::XNumberFormatsSupplier > & xNumberFormatsSupplier
117             , const awt::Size& rFontReferenceSize
118             , const awt::Rectangle& rMaximumSpaceForLabels
119             )
120 {
121     m_aAxisMap.clear();
122 
123     //if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
124     //    return;
125 
126     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
127     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
128 
129     if(nDimensionCount<=0)
130         return;
131 
132     sal_Int32 nDimensionIndex = 0;
133 
134     for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
135     {
136         sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
137         for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
138         {
139             Reference< XAxis > xAxis = this->getAxisByDimension(nDimensionIndex,nAxisIndex);
140             if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
141                 continue;
142 
143             AxisProperties aAxisProperties(xAxis,this->getExplicitCategoriesProvider());
144             aAxisProperties.m_nDimensionIndex = nDimensionIndex;
145             aAxisProperties.m_bSwapXAndY = bSwapXAndY;
146             aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
147             Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
148             if( xCrossingMainAxis.is() )
149             {
150                 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
151                 aAxisProperties.m_bCrossingAxisHasReverseDirection = (AxisOrientation_REVERSE==aCrossingScale.Orientation);
152 
153                 if( aCrossingScale.AxisType == AxisType::CATEGORY )
154                     aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
155             }
156 
157             if( nDimensionIndex == 2 )
158             {
159                 aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
160 
161                 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
162                 Reference< XAxis > xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel ) );
163                 aAxisProperties.initAxisPositioning( Reference< beans::XPropertySet >( xSisterAxis, uno::UNO_QUERY) );
164             }
165             aAxisProperties.init(true);
166             if(aAxisProperties.m_bDisplayLabels)
167                 aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis( xAxis, xNumberFormatsSupplier );
168             //-------------------
169             ::boost::shared_ptr< VAxisBase > apVAxis( new VCartesianAxis(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
170             tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
171             m_aAxisMap[aFullAxisIndex] = apVAxis;
172             apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
173 
174             apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
175         }
176     }
177 }
178 
179 void VCartesianCoordinateSystem::initVAxisInList()
180 {
181     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
182         return;
183 
184     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
185     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
186 
187     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
188     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
189     for( ; aIt != aEnd; ++aIt )
190     {
191         VAxisBase* pVAxis = aIt->second.get();
192         if( pVAxis )
193         {
194             sal_Int32 nDimensionIndex = aIt->first.first;
195             sal_Int32 nAxisIndex = aIt->first.second;
196             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
197             pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
198                 , this->createCIDForAxis( getAxisByDimension( nDimensionIndex, nAxisIndex ), nDimensionIndex, nAxisIndex ) );
199             if(2==nDimensionCount)
200                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
201             pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
202         }
203     }
204 }
205 
206 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
207 {
208     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
209         return;
210 
211     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
212     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
213 
214     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
215     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
216     for( ; aIt != aEnd; ++aIt )
217     {
218         VAxisBase* pVAxis = aIt->second.get();
219         if( pVAxis )
220         {
221             sal_Int32 nDimensionIndex = aIt->first.first;
222             sal_Int32 nAxisIndex = aIt->first.second;
223             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
224             if(2==nDimensionCount)
225                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
226             pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
227         }
228     }
229 }
230 
231 //.............................................................................
232 } //namespace chart
233 //.............................................................................
234