Update ooo320-m1
[ooovba.git] / chart2 / source / view / axes / TickmarkHelper.hxx
blobf8b2ef6a8c402792fdced2b29fe16ff19efbf3c0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TickmarkHelper.hxx,v $
10 * $Revision: 1.7.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _CHART2_TICKMARKHELPER_HXX
31 #define _CHART2_TICKMARKHELPER_HXX
33 #include "TickmarkProperties.hxx"
34 #include "VAxisProperties.hxx"
35 #include <com/sun/star/chart2/ExplicitIncrementData.hpp>
36 #include <com/sun/star/chart2/ExplicitScaleData.hpp>
37 #include <basegfx/vector/b2dvector.hxx>
38 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
39 #include <com/sun/star/drawing/XShape.hpp>
40 #include <com/sun/star/uno/Sequence.h>
42 #include <vector>
44 //.............................................................................
45 namespace chart
47 //.............................................................................
49 using ::basegfx::B2DVector;
50 //-----------------------------------------------------------------------------
51 /**
54 struct TickInfo
56 double fScaledTickValue;
57 double fUnscaledTickValue;
59 ::basegfx::B2DVector aTickScreenPosition;
60 bool bPaintIt;
62 ::com::sun::star::uno::Reference<
63 ::com::sun::star::drawing::XShape > xTextShape;
65 //methods:
66 TickInfo();
67 void updateUnscaledValue( const ::com::sun::star::uno::Reference<
68 ::com::sun::star::chart2::XScaling >& xInverseScaling );
71 class TickIter
73 public:
74 TickIter( const ::com::sun::star::uno::Sequence<
75 ::com::sun::star::uno::Sequence< double > >& rTicks
76 , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement
77 , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 );
78 TickIter( ::std::vector< ::std::vector< TickInfo > >& rTickInfos
79 , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement
80 , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 );
81 virtual ~TickIter();
83 virtual double* firstValue();
84 virtual double* nextValue();
86 virtual TickInfo* firstInfo();
87 virtual TickInfo* nextInfo();
89 sal_Int32 getCurrentDepth() const { return m_nCurrentDepth; }
91 protected:
92 bool gotoIndex( sal_Int32 nTickIndex );
93 sal_Int32 getCurrentIndex() const;
94 sal_Int32 getMaxIndex() const;
96 private: //methods
97 sal_Int32 getIntervalCount( sal_Int32 nDepth );
98 bool isAtLastPartTick();
100 void initIter( sal_Int32 nMinDepth, sal_Int32 nMaxDepth );
101 sal_Int32 getStartDepth() const;
103 bool gotoFirst();
104 bool gotoNext();
107 double getTickValue(sal_Int32 nDepth, sal_Int32 nIndex) const
109 if(m_pSimpleTicks)
110 return (*m_pSimpleTicks)[nDepth][nIndex];
111 else
112 return (((*m_pInfoTicks)[nDepth])[nIndex]).fScaledTickValue;
114 sal_Int32 getTickCount( sal_Int32 nDepth ) const
116 if(m_pSimpleTicks)
117 return (*m_pSimpleTicks)[nDepth].getLength();
118 else
119 return (*m_pInfoTicks)[nDepth].size();
121 sal_Int32 getMaxDepth() const
123 if(m_pSimpleTicks)
124 return (*m_pSimpleTicks).getLength()-1;
125 else
126 return (*m_pInfoTicks).size()-1;
129 private: //member
130 const ::com::sun::star::uno::Sequence<
131 ::com::sun::star::uno::Sequence< double > >* m_pSimpleTicks;
132 ::std::vector< ::std::vector< TickInfo > >* m_pInfoTicks;
133 const ::com::sun::star::chart2::ExplicitIncrementData& m_rIncrement;
134 //iteration from m_nMinDepth to m_nMaxDepth
135 sal_Int32 m_nMinDepth;
136 sal_Int32 m_nMaxDepth;
137 sal_Int32 m_nTickCount;
138 sal_Int32* m_pnPositions; //current positions in the different sequences
139 sal_Int32* m_pnPreParentCount; //the tickmarks do not start with a major tick always,
140 //the PreParentCount states for each depth how many subtickmarks are available in front of the first parent tickmark
141 bool* m_pbIntervalFinished;
142 sal_Int32 m_nCurrentDepth;
143 sal_Int32 m_nCurrentPos;
144 double m_fCurrentValue;
147 class TickmarkHelper
149 public:
150 TickmarkHelper(
151 const ::com::sun::star::chart2::ExplicitScaleData& rScale
152 , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement );
153 virtual ~TickmarkHelper();
155 virtual TickmarkHelper* createShiftedTickmarkHelper() const;
157 void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
158 void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
161 static double getMinimumAtIncrement( double fMin, const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement );
162 static double getMaximumAtIncrement( double fMax, const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement );
164 protected: //methods
165 void addSubTicks( sal_Int32 nDepth,
166 ::com::sun::star::uno::Sequence<
167 ::com::sun::star::uno::Sequence< double > >& rParentTicks ) const;
168 double* getMajorTick( sal_Int32 nTick ) const;
169 double* getMinorTick( sal_Int32 nTick, sal_Int32 nDepth
170 , double fStartParentTick, double fNextParentTick ) const;
171 sal_Int32 getMaxTickCount( sal_Int32 nDepth = 0 ) const;
172 sal_Int32 getTickDepth() const;
173 bool isVisible( double fValue ) const;
174 bool isWithinOuterBorder( double fScaledValue ) const; //all within the outer major tick marks
176 virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& /*rAllTickInfos*/ ) const {}
177 virtual void hideIdenticalScreenValues( ::std::vector< ::std::vector< TickInfo > >& /*rAllTickInfos*/ ) const {}
179 protected: //member
180 ::com::sun::star::chart2::ExplicitScaleData m_rScale;
181 ::com::sun::star::chart2::ExplicitIncrementData m_rIncrement;
183 ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling >
184 m_xInverseScaling;
185 double* m_pfCurrentValues;
186 //major-tick positions that may lay outside the visible range but complete partly visible intervals at the borders
187 double m_fOuterMajorTickBorderMin;
188 double m_fOuterMajorTickBorderMax;
189 double m_fOuterMajorTickBorderMin_Scaled;
190 double m_fOuterMajorTickBorderMax_Scaled;
192 //minimum and maximum of the visible range after scaling
193 double m_fScaledVisibleMin;
194 double m_fScaledVisibleMax;
197 class TickmarkHelper_2D : public TickmarkHelper
199 public:
200 TickmarkHelper_2D(
201 const ::com::sun::star::chart2::ExplicitScaleData& rScale
202 , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement
203 , const ::basegfx::B2DVector& rStartScreenPos, const ::basegfx::B2DVector& rEndScreenPos
204 , const ::basegfx::B2DVector& rAxisLineToLabelLineShift );
205 //, double fStrech_SceneToScreen, double fOffset_SceneToScreen );
206 virtual ~TickmarkHelper_2D();
208 virtual TickmarkHelper* createShiftedTickmarkHelper() const;
210 static sal_Int32 getTickScreenDistance( TickIter& rIter );
212 void createPointSequenceForAxisMainLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints ) const;
213 void addPointSequenceForTickLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints
214 , sal_Int32 nSequenceIndex
215 , double fScaledLogicTickValue, double fInnerDirectionSign
216 , const TickmarkProperties& rTickmarkProperties, bool bPlaceAtLabels ) const;
217 ::basegfx::B2DVector getDistanceAxisTickToText( const AxisProperties& rAxisProperties ) const;
219 virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
220 virtual void hideIdenticalScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
222 bool isHorizontalAxis() const;
223 bool isVerticalAxis() const;
225 protected: //methods
226 ::basegfx::B2DVector getTickScreenPosition2D( double fScaledLogicTickValue ) const;
228 private: //member
229 ::basegfx::B2DVector m_aAxisStartScreenPosition2D;
230 ::basegfx::B2DVector m_aAxisEndScreenPosition2D;
232 //labels might be posioned high or low on the border of the diagram far away from the axis
233 //add this vector to go from the axis line to the label line (border of the diagram)
234 ::basegfx::B2DVector m_aAxisLineToLabelLineShift;
236 double m_fStrech_LogicToScreen;
237 double m_fOffset_LogicToScreen;
240 class TickmarkHelper_3D : public TickmarkHelper
242 public:
243 TickmarkHelper_3D(
244 const ::com::sun::star::chart2::ExplicitScaleData& rScale
245 , const ::com::sun::star::chart2::ExplicitIncrementData& rIncrement );
246 virtual ~TickmarkHelper_3D();
248 virtual TickmarkHelper* createShiftedTickmarkHelper() const;
251 //.............................................................................
252 } //namespace chart
253 //.............................................................................
254 #endif