Files
libreoffice/xmloff/source/chart/SchXMLSeriesHelper.cxx
Jens-Heiner Rechtien 0b762ccfc4 INTEGRATION: CWS obo11 (1.2.34); FILE MERGED
2007/06/18 14:39:59 obo 1.2.34.1: #i76441# parse problem VS2005 fixed by IHA
2007-06-27 12:57:15 +00:00

327 lines
12 KiB
C++

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: SchXMLSeriesHelper.cxx,v $
*
* $Revision: 1.3 $
*
* last change: $Author: hr $ $Date: 2007-06-27 13:57:15 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"
#include "SchXMLSeriesHelper.hxx"
#ifndef _COM_SUN_STAR_CHART2_XCHARTDOCUMENT_HPP_
#include <com/sun/star/chart2/XChartDocument.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_XCHARTTYPECONTAINER_HPP_
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_XCOORDINATESYSTEMCONTAINER_HPP_
#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_XDATASERIESCONTAINER_HPP_
#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
#include <com/sun/star/lang/XInitialization.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
// header for define RTL_CONSTASCII_USTRINGPARAM
#ifndef _RTL_USTRING_H_
#include <rtl/ustring.h>
#endif
// header for define DBG_ERROR1
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#include <typeinfo>
using namespace ::com::sun::star;
using namespace rtl;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::rtl::OUString;
// ----------------------------------------
::std::vector< Reference< chart2::XDataSeries > >
SchXMLSeriesHelper::getDataSeriesFromDiagram(
const Reference< chart2::XDiagram > & xDiagram )
{
::std::vector< Reference< chart2::XDataSeries > > aResult;
try
{
Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
xDiagram, uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
xCooSysCnt->getCoordinateSystems());
for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
{
Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
{
Reference< chart2::XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
::std::copy( aSeriesSeq.getConstArray(), aSeriesSeq.getConstArray() + aSeriesSeq.getLength(),
::std::back_inserter( aResult ));
}
}
}
catch( uno::Exception & ex )
{
(void)ex; // avoid warning for pro build
OSL_ENSURE( false, OUStringToOString( OUString(
OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
OUString::createFromAscii( typeid( ex ).name()) +
OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
ex.Message), RTL_TEXTENCODING_ASCII_US ).getStr());
}
return aResult;
}
::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
const Reference< chart2::XDiagram > & xDiagram )
{
::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
sal_Int32 nIndex=0;
::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
; aSeriesIt != aSeriesVector.end()
; aSeriesIt++, nIndex++ )
{
Reference< chart2::XDataSeries > xSeries( *aSeriesIt );
if( xSeries.is() )
{
if( aRet.end() == aRet.find(xSeries) )
aRet[xSeries]=nIndex;
}
}
return aRet;
}
uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
const uno::Reference< chart2::XDiagram >& xDiagram
, const Reference< chart2::XDataSeries >& xSeries )
{
if(!xDiagram.is())
return 0;
//iterate through the model to find the given xSeries
//the found parent indicates the charttype
//iterate through all coordinate systems
uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
if( !xCooSysContainer.is())
return 0;
uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
{
uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysList[nCS] );
//iterate through all chart types in the current coordinate system
uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
OSL_ASSERT( xChartTypeContainer.is());
if( !xChartTypeContainer.is() )
continue;
uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
{
uno::Reference< chart2::XChartType > xChartType( aChartTypeList[nT] );
//iterate through all series in this chart type
uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
OSL_ASSERT( xDataSeriesContainer.is());
if( !xDataSeriesContainer.is() )
continue;
uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
{
Reference< chart2::XDataSeries > xCurrentSeries( aSeriesList[nS] );
if( xSeries == xCurrentSeries )
return xChartType;
}
}
}
return 0;
}
bool SchXMLSeriesHelper::isCandleStickSeries(
const Reference< chart2::XDataSeries >& xSeries
, const Reference< frame::XModel >& xChartModel )
{
bool bRet = false;
uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
if( xNewDoc.is() )
{
uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
if( xNewDiagram.is() )
{
uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
xNewDiagram, xSeries ) );
if( xChartType.is() )
{
rtl::OUString aServiceName( xChartType->getChartType() );
if( aServiceName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.CandleStickChartType" ) ) ) )
bRet = true;
}
}
}
return bRet;
}
// static
Reference< chart2::XDataSeries > SchXMLSeriesHelper::getFirstCandleStickSeries(
const Reference< chart2::XDiagram > & xDiagram )
{
Reference< chart2::XDataSeries > xResult;
try
{
Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
for( sal_Int32 nCooSysIdx=0; !xResult.is() && nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
{
Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XChartType > > aCTSeq( xCTCnt->getChartTypes());
for( sal_Int32 nCTIdx=0; !xResult.is() && nCTIdx<aCTSeq.getLength(); ++nCTIdx )
{
if( aCTSeq[nCTIdx]->getChartType().equals(
::rtl::OUString::createFromAscii("com.sun.star.chart2.CandleStickChartType")))
{
Reference< chart2::XDataSeriesContainer > xSeriesCnt( aCTSeq[nCTIdx], uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries() );
if( aSeriesSeq.getLength())
xResult.set( aSeriesSeq[0] );
break;
}
}
}
}
catch( const uno::Exception & )
{
OSL_ENSURE( false, "Exception caught" );
}
return xResult;
}
//static
uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
const uno::Reference< chart2::XDataSeries >& xSeries
, const uno::Reference< frame::XModel >& xChartModel )
{
uno::Reference< beans::XPropertySet > xRet;
if( xSeries.is() )
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
if( xFactory.is() )
{
xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
OUString::createFromAscii( "com.sun.star.comp.chart2.DataSeriesWrapper" ) ), uno::UNO_QUERY );
Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
if(xInit.is())
{
Sequence< uno::Any > aArguments(1);
aArguments[0]=uno::makeAny(xSeries);
xInit->initialize(aArguments);
}
}
}
catch( uno::Exception & rEx )
{
(void)rEx; // avoid warning for pro build
DBG_ERROR1( "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: %s",
OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
}
}
return xRet;
}
//static
uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
const uno::Reference< chart2::XDataSeries >& xSeries
, sal_Int32 nPointIndex
, const uno::Reference< frame::XModel >& xChartModel )
{
uno::Reference< beans::XPropertySet > xRet;
if( xSeries.is() )
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
if( xFactory.is() )
{
xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
OUString::createFromAscii( "com.sun.star.comp.chart2.DataSeriesWrapper" ) ), uno::UNO_QUERY );
Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
if(xInit.is())
{
Sequence< uno::Any > aArguments(2);
aArguments[0]=uno::makeAny(xSeries);
aArguments[1]=uno::makeAny(nPointIndex);
xInit->initialize(aArguments);
}
}
}
catch( uno::Exception & rEx )
{
(void)rEx; // avoid warning for pro build
DBG_ERROR1( "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: %s",
OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
}
}
return xRet;
}