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