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_HXX
24 #define _CHART2_TICKMARKS_HXX
25 
26 #include "TickmarkProperties.hxx"
27 #include "VAxisProperties.hxx"
28 #include "chartview/ExplicitScaleValues.hxx"
29 #include <basegfx/vector/b2dvector.hxx>
30 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
31 #include <com/sun/star/drawing/XShape.hpp>
32 #include <com/sun/star/uno/Sequence.h>
33 
34 #include <vector>
35 
36 //.............................................................................
37 namespace chart
38 {
39 //.............................................................................
40 
41 using ::basegfx::B2DVector;
42 //-----------------------------------------------------------------------------
43 /**
44 */
45 
46 struct TickInfo
47 {
48     double      fScaledTickValue;
49     ::com::sun::star::uno::Reference<
50                     ::com::sun::star::chart2::XScaling > xInverseScaling;
51 
52     ::basegfx::B2DVector  aTickScreenPosition;
53     bool        bPaintIt;
54 
55     ::com::sun::star::uno::Reference<
56         ::com::sun::star::drawing::XShape > xTextShape;
57 
58     rtl::OUString aText;//used only for complex categories so far
59     sal_Int32 nFactorForLimitedTextWidth;//categories in higher levels of complex categories can have more place than a single simple category
60 
61 //methods:
62     TickInfo( const ::com::sun::star::uno::Reference<
63                     ::com::sun::star::chart2::XScaling >& xInverseScaling );
64 
65     double getUnscaledTickValue() const;
66     sal_Int32 getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const;
67 private:
68     TickInfo();
69 };
70 class TickIter
71 {
72 public:
~TickIter()73     virtual ~TickIter(){};
74     virtual TickInfo* firstInfo()=0;
75     virtual TickInfo* nextInfo()=0;
76 };
77 
78 class PureTickIter : public TickIter
79 {
80 public:
81     PureTickIter( ::std::vector< TickInfo >& rTickInfoVector );
82     virtual ~PureTickIter();
83     virtual TickInfo* firstInfo();
84     virtual TickInfo* nextInfo();
85 
86 private:
87     ::std::vector< TickInfo >& m_rTickVector;
88     ::std::vector< TickInfo >::iterator m_aTickIter;
89 };
90 
91 class TickFactory
92 {
93 public:
94     TickFactory(
95          const ExplicitScaleData& rScale
96         , const ExplicitIncrementData& rIncrement );
97     virtual ~TickFactory();
98 
99     void getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
100     void getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
updateScreenValues(::std::vector<::std::vector<TickInfo>> &) const101     virtual void updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& /*rAllTickInfos*/ ) const {}
102 
103 private: //methods
104     bool        isDateAxis() const;
105 
106 protected: //member
107     ExplicitScaleData     m_rScale;
108     ExplicitIncrementData m_rIncrement;
109     ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling >
110                                                 m_xInverseScaling;
111 
112     //minimum and maximum of the visible range after scaling
113     double    m_fScaledVisibleMin;
114     double    m_fScaledVisibleMax;
115 };
116 
117 class TickFactory_2D : public TickFactory
118 {
119 public:
120     TickFactory_2D(
121         const ExplicitScaleData& rScale
122         , const ExplicitIncrementData& rIncrement
123         , const ::basegfx::B2DVector& rStartScreenPos, const ::basegfx::B2DVector& rEndScreenPos
124         , const ::basegfx::B2DVector& rAxisLineToLabelLineShift );
125         //, double fStrech_SceneToScreen, double fOffset_SceneToScreen );
126     virtual ~TickFactory_2D();
127 
128     static sal_Int32    getTickScreenDistance( TickIter& rIter );
129 
130     void createPointSequenceForAxisMainLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints ) const;
131     void addPointSequenceForTickLine( ::com::sun::star::drawing::PointSequenceSequence& rPoints
132                             , sal_Int32 nSequenceIndex
133                             , double fScaledLogicTickValue, double fInnerDirectionSign
134                             , const TickmarkProperties& rTickmarkProperties, bool bPlaceAtLabels ) const;
135     ::basegfx::B2DVector  getDistanceAxisTickToText( const AxisProperties& rAxisProperties
136         , bool bIncludeFarAwayDistanceIfSo = false
137         , bool bIncludeSpaceBetweenTickAndText = true ) const;
138 
139     virtual void        updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const;
140 
141     bool  isHorizontalAxis() const;
142     bool  isVerticalAxis() const;
143 
144 protected: //methods
145     ::basegfx::B2DVector     getTickScreenPosition2D( double fScaledLogicTickValue ) const;
146 
147 private: //member
148     ::basegfx::B2DVector    m_aAxisStartScreenPosition2D;
149     ::basegfx::B2DVector    m_aAxisEndScreenPosition2D;
150 
151     //labels might be posioned high or low on the border of the diagram far away from the axis
152     //add this vector to go from the axis line to the label line (border of the diagram)
153     ::basegfx::B2DVector    m_aAxisLineToLabelLineShift;
154 
155     double      m_fStrech_LogicToScreen;
156     double      m_fOffset_LogicToScreen;
157 };
158 
159 //.............................................................................
160 } //namespace chart
161 //.............................................................................
162 #endif
163