1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir #include "Tickmarks_Dates.hxx" 31*cdf0e10cSrcweir #include "DateScaling.hxx" 32*cdf0e10cSrcweir #include <rtl/math.hxx> 33*cdf0e10cSrcweir #include <tools/debug.hxx> 34*cdf0e10cSrcweir #include "DateHelper.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir //............................................................................. 37*cdf0e10cSrcweir namespace chart 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir //............................................................................. 40*cdf0e10cSrcweir using namespace ::com::sun::star; 41*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 42*cdf0e10cSrcweir using namespace ::rtl::math; 43*cdf0e10cSrcweir using ::basegfx::B2DVector; 44*cdf0e10cSrcweir using ::com::sun::star::chart::TimeUnit::DAY; 45*cdf0e10cSrcweir using ::com::sun::star::chart::TimeUnit::MONTH; 46*cdf0e10cSrcweir using ::com::sun::star::chart::TimeUnit::YEAR; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir DateTickFactory::DateTickFactory( 49*cdf0e10cSrcweir const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement ) 50*cdf0e10cSrcweir : m_aScale( rScale ) 51*cdf0e10cSrcweir , m_aIncrement( rIncrement ) 52*cdf0e10cSrcweir , m_xInverseScaling(NULL) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir //@todo: make sure that the scale is valid for the scaling 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir if( m_aScale.Scaling.is() ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir m_xInverseScaling = m_aScale.Scaling->getInverseScaling(); 59*cdf0e10cSrcweir DBG_ASSERT( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" ); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir m_fScaledVisibleMin = m_aScale.Minimum; 63*cdf0e10cSrcweir if( m_xInverseScaling.is() ) 64*cdf0e10cSrcweir m_fScaledVisibleMin = m_aScale.Scaling->doScaling(m_fScaledVisibleMin); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir m_fScaledVisibleMax = m_aScale.Maximum; 67*cdf0e10cSrcweir if( m_xInverseScaling.is() ) 68*cdf0e10cSrcweir m_fScaledVisibleMax = m_aScale.Scaling->doScaling(m_fScaledVisibleMax); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir DateTickFactory::~DateTickFactory() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos, bool bShifted ) const 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir rAllTickInfos.resize(2); 78*cdf0e10cSrcweir ::std::vector< TickInfo >& rMajorTicks = rAllTickInfos[0]; 79*cdf0e10cSrcweir ::std::vector< TickInfo >& rMinorTicks = rAllTickInfos[1]; 80*cdf0e10cSrcweir rMajorTicks.clear(); 81*cdf0e10cSrcweir rMinorTicks.clear(); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir Date aNull(m_aScale.NullDate); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir Date aDate = aNull + static_cast<long>(::rtl::math::approxFloor(m_aScale.Minimum)); 86*cdf0e10cSrcweir Date aMaxDate = aNull + static_cast<long>(::rtl::math::approxFloor(m_aScale.Maximum)); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir uno::Reference< chart2::XScaling > xScaling(m_aScale.Scaling); 89*cdf0e10cSrcweir uno::Reference< chart2::XScaling > xInverseScaling(m_xInverseScaling); 90*cdf0e10cSrcweir if( bShifted ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/); 93*cdf0e10cSrcweir xInverseScaling = xScaling->getInverseScaling(); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir //create major date tickinfos 97*cdf0e10cSrcweir while( aDate<= aMaxDate ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir if( bShifted && aDate==aMaxDate ) 100*cdf0e10cSrcweir break; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if( xInverseScaling.is() ) 105*cdf0e10cSrcweir aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); 106*cdf0e10cSrcweir rMajorTicks.push_back( aNewTick ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if(m_aIncrement.MajorTimeInterval.Number<=0) 109*cdf0e10cSrcweir break; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir //find next major date 112*cdf0e10cSrcweir switch( m_aIncrement.MajorTimeInterval.TimeUnit ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir case DAY: 115*cdf0e10cSrcweir aDate += m_aIncrement.MajorTimeInterval.Number; 116*cdf0e10cSrcweir break; 117*cdf0e10cSrcweir case YEAR: 118*cdf0e10cSrcweir aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); 119*cdf0e10cSrcweir break; 120*cdf0e10cSrcweir case MONTH: 121*cdf0e10cSrcweir default: 122*cdf0e10cSrcweir aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number ); 123*cdf0e10cSrcweir break; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir //create minor date tickinfos 128*cdf0e10cSrcweir aDate = aNull + static_cast<long>(::rtl::math::approxFloor(m_aScale.Minimum)); 129*cdf0e10cSrcweir while( aDate<= aMaxDate ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if( bShifted && aDate==aMaxDate ) 132*cdf0e10cSrcweir break; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull; 135*cdf0e10cSrcweir if( xInverseScaling.is() ) 136*cdf0e10cSrcweir aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue); 137*cdf0e10cSrcweir rMinorTicks.push_back( aNewTick ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir if(m_aIncrement.MinorTimeInterval.Number<=0) 140*cdf0e10cSrcweir break; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir //find next minor date 143*cdf0e10cSrcweir switch( m_aIncrement.MinorTimeInterval.TimeUnit ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir case DAY: 146*cdf0e10cSrcweir aDate += m_aIncrement.MinorTimeInterval.Number; 147*cdf0e10cSrcweir break; 148*cdf0e10cSrcweir case YEAR: 149*cdf0e10cSrcweir aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); 150*cdf0e10cSrcweir break; 151*cdf0e10cSrcweir case MONTH: 152*cdf0e10cSrcweir default: 153*cdf0e10cSrcweir aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number ); 154*cdf0e10cSrcweir break; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir getAllTicks( rAllTickInfos, false ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void DateTickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir getAllTicks( rAllTickInfos, true ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir //............................................................................. 170*cdf0e10cSrcweir } //namespace chart 171*cdf0e10cSrcweir //............................................................................. 172