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 #ifndef _CHART2_VCOORDINATESYSTEM_HXX
28 #define _CHART2_VCOORDINATESYSTEM_HXX
29 
30 #include "MinimumAndMaximumSupplier.hxx"
31 #include "ScaleAutomatism.hxx"
32 #include "ThreeDHelper.hxx"
33 #include "ExplicitCategoriesProvider.hxx"
34 #include "chartview/ExplicitScaleValues.hxx"
35 
36 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
37 #include "comphelper/implementationreference.hxx"
38 #include <com/sun/star/awt/Rectangle.hpp>
39 #include <com/sun/star/drawing/HomogenMatrix.hpp>
40 #include <com/sun/star/drawing/XShapes.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
43 
44 #include<map>
45 #include <vector>
46 #include <boost/shared_ptr.hpp>
47 
48 //.............................................................................
49 namespace chart
50 {
51 //.............................................................................
52 
53 //-----------------------------------------------------------------------------
54 /**
55 */
56 class VAxisBase;
57 class VCoordinateSystem
58 {
59 public:
60     virtual ~VCoordinateSystem();
61 
62     static VCoordinateSystem* createCoordinateSystem( const ::com::sun::star::uno::Reference<
63                                 ::com::sun::star::chart2::XCoordinateSystem >& xCooSysModel );
64 
65     virtual void initPlottingTargets(
66                   const ::com::sun::star::uno::Reference<
67                         ::com::sun::star::drawing::XShapes >& xLogicTarget
68 		        , const ::com::sun::star::uno::Reference<
69                         ::com::sun::star::drawing::XShapes >& xFinalTarget
70 		        , const ::com::sun::star::uno::Reference<
71                         ::com::sun::star::lang::XMultiServiceFactory >& xFactory
72                 , ::com::sun::star::uno::Reference<
73                         ::com::sun::star::drawing::XShapes >& xLogicTargetForSeriesBehindAxis )
74 				        throw (::com::sun::star::uno::RuntimeException);
75 
76     void setParticle( const rtl::OUString& rCooSysParticle );
77 
78     virtual void setTransformationSceneToScreen( const ::com::sun::star::drawing::HomogenMatrix& rMatrix );
79     ::com::sun::star::drawing::HomogenMatrix getTransformationSceneToScreen();
80 
81     //better performance for big data
82     virtual ::com::sun::star::uno::Sequence< sal_Int32 > getCoordinateSystemResolution( const ::com::sun::star::awt::Size& rPageSize
83                                     , const ::com::sun::star::awt::Size& rPageResolution );
84 
85     ExplicitScaleData getExplicitScale( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const;
86     ExplicitIncrementData getExplicitIncrement( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const;
87 
88     void setExplicitCategoriesProvider( ExplicitCategoriesProvider* /*takes ownership*/ );
89     ExplicitCategoriesProvider* getExplicitCategoriesProvider();
90 
91     // returns a coplete scale set for a given dimension and index; for example if nDimensionIndex==1 and nAxisIndex==2 you get returned the secondary x axis, main y axis and main z axis
92     ::std::vector< ExplicitScaleData > getExplicitScales( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const;
93     // returns a coplete increment set for a given dimension and index; for example if nDimensionIndex==1 and nAxisIndex==2 you get returned the secondary x axis, main y axis and main z axis
94     ::std::vector< ExplicitIncrementData > getExplicitIncrements( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) const;
95 
96     void addMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier );
97     bool hasMinimumAndMaximumSupplier( MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier );
98     void clearMinimumAndMaximumSupplierList();
99 
100     void prepareScaleAutomatismForDimensionAndIndex( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex );
101 
102     void setExplicitScaleAndIncrement( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex
103         , const ExplicitScaleData& rExplicitScale
104         , const ExplicitIncrementData& rExplicitIncrement );
105 
106     void set3DWallPositions( CuboidPlanePosition eLeftWallPos, CuboidPlanePosition eBackWallPos, CuboidPlanePosition eBottomPos );
107 
108     ::com::sun::star::uno::Reference<
109         ::com::sun::star::chart2::XCoordinateSystem >
110         getModel() const;
111 
112     virtual void createVAxisList(
113             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > & xNumberFormatsSupplier
114             , const ::com::sun::star::awt::Size& rFontReferenceSize
115             , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels );
116 
117     virtual void initVAxisInList();
118     virtual void updateScalesAndIncrementsOnAxes();
119 
120     virtual void createMaximumAxesLabels();
121     virtual void createAxesLabels();
122     virtual void updatePositions();
123     virtual void createAxesShapes();
124 
125     virtual void createGridShapes();
126 
127     virtual bool getPropertySwapXAndYAxis() const;
128 
129     sal_Int32 getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex ) const;
130 
131     virtual bool needSeriesNamesForAxis() const;
132     void setSeriesNamesForAxis( const ::com::sun::star::uno::Sequence< rtl::OUString >& rSeriesNames );
133 
134 protected: //methods
135     VCoordinateSystem( const ::com::sun::star::uno::Reference<
136         ::com::sun::star::chart2::XCoordinateSystem >& xCooSys );
137 
138     ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >
139         getAxisByDimension( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex  ) const;
140     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > >
141         getGridListFromAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >& xAxis );
142 
143     VAxisBase* getVAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
144 
145     rtl::OUString createCIDForAxis( const ::com::sun::star::uno::Reference<
146                     ::com::sun::star::chart2::XAxis >& xAxis
147                     , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
148     rtl::OUString createCIDForGrid( const ::com::sun::star::uno::Reference<
149                     ::com::sun::star::chart2::XAxis >& xAxis
150                     , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
151 
152     sal_Int32 getNumberFormatKeyForAxis( const ::com::sun::star::uno::Reference<
153                      ::com::sun::star::chart2::XAxis >& xAxis
154                      , const ::com::sun::star::uno::Reference<
155                      ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
156 
157 private: //methods
158     void impl_adjustDimension( sal_Int32& rDimensionIndex ) const;
159     void impl_adjustDimensionAndIndex( sal_Int32& rDimensionIndex, sal_Int32& rAxisIndex ) const;
160 
161 protected: //member
162     ::com::sun::star::uno::Reference<
163         ::com::sun::star::chart2::XCoordinateSystem > m_xCooSysModel;
164 
165     rtl::OUString m_aCooSysParticle;
166 
167     typedef std::pair< sal_Int32, sal_Int32 > tFullAxisIndex; //first index is the dimension, second index is the axis index that indicates wether this is a main or secondary axis
168 
169     //
170     ::com::sun::star::uno::Reference<
171                     ::com::sun::star::drawing::XShapes >                m_xLogicTargetForGrids;
172     ::com::sun::star::uno::Reference<
173                     ::com::sun::star::drawing::XShapes >                m_xLogicTargetForAxes;
174     ::com::sun::star::uno::Reference<
175                     ::com::sun::star::drawing::XShapes >                m_xFinalTarget;
176     ::com::sun::star::uno::Reference<
177                     ::com::sun::star::lang::XMultiServiceFactory>	    m_xShapeFactory;
178     ::com::sun::star::drawing::HomogenMatrix                            m_aMatrixSceneToScreen;
179 
180     CuboidPlanePosition m_eLeftWallPos;
181     CuboidPlanePosition m_eBackWallPos;
182     CuboidPlanePosition m_eBottomPos;
183 
184     //
185     MergedMinimumAndMaximumSupplier m_aMergedMinimumAndMaximumSupplier; //this is used only for autoscaling purpose
186 
187     ::com::sun::star::uno::Sequence< rtl::OUString > m_aSeriesNamesForZAxis;
188 
189     typedef std::map< tFullAxisIndex, ::boost::shared_ptr< VAxisBase > > tVAxisMap;
190 
191     tVAxisMap m_aAxisMap;
192 
193 private:
194     std::vector< ExplicitScaleData >     m_aExplicitScales;
195     std::vector< ExplicitIncrementData > m_aExplicitIncrements;
196 
197     typedef std::map< tFullAxisIndex, ExplicitScaleData > tFullExplicitScaleMap;
198     typedef std::map< tFullAxisIndex, ExplicitIncrementData > tFullExplicitIncrementMap;
199 
200     tFullExplicitScaleMap       m_aSecondaryExplicitScales;
201     tFullExplicitIncrementMap   m_aSecondaryExplicitIncrements;
202 
203     ::std::auto_ptr< ExplicitCategoriesProvider > m_apExplicitCategoriesProvider;
204 };
205 
206 //.............................................................................
207 } //namespace chart
208 //.............................................................................
209 #endif
210