1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "VCartesianCoordinateSystem.hxx"
27 #include "VCartesianGrid.hxx"
28 #include "VCartesianAxis.hxx"
29 #include "macros.hxx"
30 #include "AxisIndexDefines.hxx"
31 #include "AxisHelper.hxx"
32 #include "ChartTypeHelper.hxx"
33 
34 //for auto_ptr
35 #include <memory>
36 
37 //.............................................................................
38 namespace chart
39 {
40 //.............................................................................
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::chart2;
43 using ::com::sun::star::uno::Reference;
44 
45 //.............................................................................
46 
47 class TextualDataProvider : public ::cppu::WeakImplHelper1<
48         ::com::sun::star::chart2::data::XTextualDataSequence
49 		>
50 {
51 public:
TextualDataProvider(const uno::Sequence<::rtl::OUString> & rTextSequence)52     TextualDataProvider( const uno::Sequence< ::rtl::OUString >& rTextSequence )
53         : m_aTextSequence( rTextSequence )
54     {
55     }
~TextualDataProvider()56 	virtual ~TextualDataProvider()
57     {
58     }
59 
60     //XTextualDataSequence
getTextualData()61     virtual uno::Sequence< ::rtl::OUString > SAL_CALL getTextualData()
62         throw ( uno::RuntimeException)
63     {
64         return m_aTextSequence;
65     }
66 
67 private: //member
68     uno::Sequence< ::rtl::OUString > m_aTextSequence;
69 };
70 
71 //.............................................................................
72 
VCartesianCoordinateSystem(const Reference<XCoordinateSystem> & xCooSys)73 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
74     : VCoordinateSystem(xCooSys)
75 {
76 }
77 
~VCartesianCoordinateSystem()78 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
79 {
80 }
81 
createGridShapes()82 void VCartesianCoordinateSystem::createGridShapes()
83 {
84     if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
85         return;
86 
87     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
88     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
89 
90     for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
91     {
92         sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
93         Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
94         if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
95             continue;
96 
97         VCartesianGrid aGrid(nDimensionIndex,nDimensionCount,this->getGridListFromAxis( xAxis ));
98         aGrid.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex,nAxisIndex)
99                             , this->getExplicitIncrement(nDimensionIndex,nAxisIndex) );
100         aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
101 
102         aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
103             , this->createCIDForGrid( xAxis,nDimensionIndex,nAxisIndex ) );
104         if(2==nDimensionCount)
105             aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
106         aGrid.setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
107         aGrid.createShapes();
108     }
109 }
110 
createVAxisList(const uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier,const awt::Size & rFontReferenceSize,const awt::Rectangle & rMaximumSpaceForLabels)111 void VCartesianCoordinateSystem::createVAxisList(
112               const uno::Reference< util::XNumberFormatsSupplier > & xNumberFormatsSupplier
113             , const awt::Size& rFontReferenceSize
114             , const awt::Rectangle& rMaximumSpaceForLabels
115             )
116 {
117     m_aAxisMap.clear();
118 
119     //if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
120     //    return;
121 
122     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
123     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
124 
125     if(nDimensionCount<=0)
126         return;
127 
128     sal_Int32 nDimensionIndex = 0;
129 
130     for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
131     {
132         sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
133         for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
134         {
135             Reference< XAxis > xAxis = this->getAxisByDimension(nDimensionIndex,nAxisIndex);
136             if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
137                 continue;
138 
139             AxisProperties aAxisProperties(xAxis,this->getExplicitCategoriesProvider());
140             aAxisProperties.m_nDimensionIndex = nDimensionIndex;
141             aAxisProperties.m_bSwapXAndY = bSwapXAndY;
142             aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
143             Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
144             if( xCrossingMainAxis.is() )
145             {
146                 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
147                 aAxisProperties.m_bCrossingAxisHasReverseDirection = (AxisOrientation_REVERSE==aCrossingScale.Orientation);
148 
149                 if( aCrossingScale.AxisType == AxisType::CATEGORY )
150                     aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
151             }
152 
153             if( nDimensionIndex == 2 )
154             {
155                 aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
156 
157                 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
158                 Reference< XAxis > xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel ) );
159                 aAxisProperties.initAxisPositioning( Reference< beans::XPropertySet >( xSisterAxis, uno::UNO_QUERY) );
160             }
161             aAxisProperties.init(true);
162             if(aAxisProperties.m_bDisplayLabels)
163                 aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis( xAxis, xNumberFormatsSupplier );
164             //-------------------
165             ::boost::shared_ptr< VAxisBase > apVAxis( new VCartesianAxis(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
166             tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
167             m_aAxisMap[aFullAxisIndex] = apVAxis;
168             apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
169 
170             apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
171         }
172     }
173 }
174 
initVAxisInList()175 void VCartesianCoordinateSystem::initVAxisInList()
176 {
177     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
178         return;
179 
180     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
181     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
182 
183     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
184     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
185     for( ; aIt != aEnd; ++aIt )
186     {
187         VAxisBase* pVAxis = aIt->second.get();
188         if( pVAxis )
189         {
190             sal_Int32 nDimensionIndex = aIt->first.first;
191             sal_Int32 nAxisIndex = aIt->first.second;
192             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
193             pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
194                 , this->createCIDForAxis( getAxisByDimension( nDimensionIndex, nAxisIndex ), nDimensionIndex, nAxisIndex ) );
195             if(2==nDimensionCount)
196                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
197             pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
198         }
199     }
200 }
201 
updateScalesAndIncrementsOnAxes()202 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
203 {
204     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
205         return;
206 
207     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
208     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
209 
210     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
211     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
212     for( ; aIt != aEnd; ++aIt )
213     {
214         VAxisBase* pVAxis = aIt->second.get();
215         if( pVAxis )
216         {
217             sal_Int32 nDimensionIndex = aIt->first.first;
218             sal_Int32 nAxisIndex = aIt->first.second;
219             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
220             if(2==nDimensionCount)
221                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
222             pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
223         }
224     }
225 }
226 
227 //.............................................................................
228 } //namespace chart
229 //.............................................................................
230