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_TICKMARKS_EQUIDISTANT_HXX
28 #define _CHART2_TICKMARKS_EQUIDISTANT_HXX
29 
30 #include "Tickmarks.hxx"
31 
32 //.............................................................................
33 namespace chart
34 {
35 //.............................................................................
36 
37 using ::basegfx::B2DVector;
38 //-----------------------------------------------------------------------------
39 /**
40 */
41 
42 class EquidistantTickIter : public TickIter
43 {
44 public:
45     EquidistantTickIter( const ::com::sun::star::uno::Sequence<
46                 ::com::sun::star::uno::Sequence< double > >& rTicks
47                 , const ExplicitIncrementData& rIncrement
48             , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 );
49     EquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTickInfos
50             , const ExplicitIncrementData& rIncrement
51             , sal_Int32 nMinDepth=0, sal_Int32 nMaxDepth=-1 );
52     virtual ~EquidistantTickIter();
53 
54     virtual double*     firstValue();
55     virtual double*     nextValue();
56 
57     virtual TickInfo*   firstInfo();
58     virtual TickInfo*   nextInfo();
59 
60     sal_Int32   getCurrentDepth() const { return m_nCurrentDepth; }
61 
62 protected:
63     bool        gotoIndex( sal_Int32 nTickIndex );
64     sal_Int32   getCurrentIndex() const;
65     sal_Int32   getMaxIndex() const;
66 
67 private: //methods
68     sal_Int32   getIntervalCount( sal_Int32 nDepth );
69     bool        isAtLastPartTick();
70 
71     void        initIter( sal_Int32 nMinDepth, sal_Int32 nMaxDepth );
72     sal_Int32   getStartDepth() const;
73 
74     bool        gotoFirst();
75     bool        gotoNext();
76 
77 
78     double      getTickValue(sal_Int32 nDepth, sal_Int32 nIndex) const
79                 {
80                     if(m_pSimpleTicks)
81                         return (*m_pSimpleTicks)[nDepth][nIndex];
82                     else
83                         return (((*m_pInfoTicks)[nDepth])[nIndex]).fScaledTickValue;
84                 }
85     sal_Int32   getTickCount( sal_Int32 nDepth ) const
86                 {
87                     if(m_pSimpleTicks)
88                         return (*m_pSimpleTicks)[nDepth].getLength();
89                     else
90                         return (*m_pInfoTicks)[nDepth].size();
91                 }
92     sal_Int32   getMaxDepth() const
93                 {
94                     if(m_pSimpleTicks)
95                         return (*m_pSimpleTicks).getLength()-1;
96                     else
97                         return (*m_pInfoTicks).size()-1;
98                 }
99 
100 private: //member
101     const ::com::sun::star::uno::Sequence<
102         ::com::sun::star::uno::Sequence< double > >*  m_pSimpleTicks;
103     ::std::vector< ::std::vector< TickInfo > >*       m_pInfoTicks;
104     const ExplicitIncrementData& m_rIncrement;
105     //iteration from m_nMinDepth to m_nMaxDepth
106     sal_Int32   m_nMinDepth;
107     sal_Int32   m_nMaxDepth;
108     sal_Int32   m_nTickCount;
109     sal_Int32*  m_pnPositions; //current positions in the different sequences
110     sal_Int32*  m_pnPreParentCount; //the tickmarks do not start with a major tick always,
111                                     //the PreParentCount states for each depth how many subtickmarks are available in front of the first parent tickmark
112     bool*       m_pbIntervalFinished;
113     sal_Int32   m_nCurrentDepth;
114     sal_Int32   m_nCurrentPos;
115     double      m_fCurrentValue;
116 };
117 
118 class EquidistantTickFactory
119 {
120 public:
121     EquidistantTickFactory(
122          const ExplicitScaleData& rScale
123         , const ExplicitIncrementData& rIncrement );
124     ~EquidistantTickFactory();
125 
126     void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
127     void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
128 
129     static double getMinimumAtIncrement( double fMin, const ExplicitIncrementData& rIncrement );
130     static double getMaximumAtIncrement( double fMax, const ExplicitIncrementData& rIncrement );
131 
132 private: //methods
133     void        addSubTicks( sal_Int32 nDepth,
134                         ::com::sun::star::uno::Sequence<
135                             ::com::sun::star::uno::Sequence< double > >& rParentTicks ) const;
136     double*     getMajorTick( sal_Int32 nTick ) const;
137     double*     getMinorTick( sal_Int32 nTick, sal_Int32 nDepth
138                     , double fStartParentTick, double fNextParentTick ) const;
139     sal_Int32   getMaxTickCount( sal_Int32 nDepth = 0 ) const;
140     sal_Int32   getTickDepth() const;
141 
142     bool        isVisible( double fValue ) const;
143     bool        isWithinOuterBorder( double fScaledValue ) const; //all within the outer major tick marks
144 
145 private: //member
146     ExplicitScaleData     m_rScale;
147     ExplicitIncrementData m_rIncrement;
148     ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling >
149                                                 m_xInverseScaling;
150 
151     //minimum and maximum of the visible range after scaling
152     double    m_fScaledVisibleMin;
153     double    m_fScaledVisibleMax;
154 
155     double*   m_pfCurrentValues;
156     //major-tick positions that may lay outside the visible range but complete partly visible intervals at the borders
157     double    m_fOuterMajorTickBorderMin;
158     double    m_fOuterMajorTickBorderMax;
159     double    m_fOuterMajorTickBorderMin_Scaled;
160     double    m_fOuterMajorTickBorderMax_Scaled;
161 };
162 
163 //.............................................................................
164 } //namespace chart
165 //.............................................................................
166 #endif
167