Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "NetChartTypeTemplate.hxx"
21 : #include "macros.hxx"
22 : #include "PolarCoordinateSystem.hxx"
23 : #include "DiagramHelper.hxx"
24 : #include "servicenames_charttypes.hxx"
25 : #include "DataSeriesHelper.hxx"
26 : #include <com/sun/star/chart2/SymbolStyle.hpp>
27 : #include <com/sun/star/chart2/Symbol.hpp>
28 : #include <com/sun/star/drawing/LineStyle.hpp>
29 :
30 : using namespace ::com::sun::star;
31 :
32 : using ::com::sun::star::uno::Reference;
33 : using ::com::sun::star::uno::Sequence;
34 : using ::com::sun::star::uno::Any;
35 : using ::osl::MutexGuard;
36 :
37 : namespace chart
38 : {
39 :
40 13113 : NetChartTypeTemplate::NetChartTypeTemplate(
41 : Reference< uno::XComponentContext > const & xContext,
42 : const OUString & rServiceName,
43 : StackMode eStackMode,
44 : bool bSymbols,
45 : bool bHasLines ,
46 : bool bHasFilledArea ) :
47 : ChartTypeTemplate( xContext, rServiceName ),
48 : m_eStackMode( eStackMode ),
49 : m_bHasSymbols( bSymbols ),
50 : m_bHasLines( bHasLines ),
51 13113 : m_bHasFilledArea( bHasFilledArea )
52 13113 : {}
53 :
54 26226 : NetChartTypeTemplate::~NetChartTypeTemplate()
55 26226 : {}
56 :
57 0 : StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
58 : {
59 0 : return m_eStackMode;
60 : }
61 :
62 0 : void SAL_CALL NetChartTypeTemplate::applyStyle(
63 : const Reference< chart2::XDataSeries >& xSeries,
64 : ::sal_Int32 nChartTypeIndex,
65 : ::sal_Int32 nSeriesIndex,
66 : ::sal_Int32 nSeriesCount )
67 : throw (uno::RuntimeException, std::exception)
68 : {
69 0 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
70 :
71 : try
72 : {
73 0 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
74 :
75 0 : DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
76 0 : DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
77 0 : DataSeriesHelper::makeLinesThickOrThin( xProp, true );
78 : }
79 0 : catch( const uno::Exception & ex )
80 : {
81 : ASSERT_EXCEPTION( ex );
82 : }
83 0 : }
84 :
85 : // ____ XChartTypeTemplate ____
86 13113 : sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate(
87 : const Reference< chart2::XDiagram >& xDiagram,
88 : sal_Bool bAdaptProperties )
89 : throw (uno::RuntimeException, std::exception)
90 : {
91 13113 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
92 :
93 : uno::Reference< beans::XPropertySet > xChartTypeProp(
94 13113 : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
95 :
96 13113 : if( bResult )
97 : {
98 : //filled net chart?:
99 0 : if( m_bHasFilledArea )
100 0 : return sal_True;
101 :
102 : // check symbol-style
103 : // for a template with symbols it is ok, if there is at least one series
104 : // with symbols, otherwise an unknown template is too easy to achieve
105 0 : bool bSymbolFound = false;
106 0 : bool bLineFound = false;
107 :
108 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
109 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
110 :
111 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
112 0 : aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
113 : {
114 : try
115 : {
116 0 : chart2::Symbol aSymbProp;
117 : drawing::LineStyle eLineStyle;
118 0 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
119 :
120 0 : bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) &&
121 0 : (aSymbProp.Style != chart2::SymbolStyle_NONE);
122 :
123 0 : if( bCurrentHasSymbol )
124 0 : bSymbolFound = true;
125 :
126 0 : if( bCurrentHasSymbol && (!m_bHasSymbols) )
127 : {
128 0 : bResult = false;
129 0 : break;
130 : }
131 :
132 0 : bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) &&
133 0 : ( eLineStyle != drawing::LineStyle_NONE );
134 :
135 0 : if( bCurrentHasLine )
136 0 : bLineFound = true;
137 :
138 0 : if( bCurrentHasLine && (!m_bHasLines) )
139 : {
140 0 : bResult = false;
141 0 : break;
142 0 : }
143 : }
144 0 : catch( const uno::Exception & ex )
145 : {
146 : ASSERT_EXCEPTION( ex );
147 : }
148 : }
149 :
150 0 : if(bResult)
151 : {
152 0 : if( !bLineFound && m_bHasLines && bSymbolFound )
153 0 : bResult = false;
154 0 : else if( !bSymbolFound && m_bHasSymbols && bLineFound )
155 0 : bResult = false;
156 0 : else if( !bLineFound && !bSymbolFound )
157 0 : return m_bHasLines && m_bHasSymbols;
158 0 : }
159 : }
160 :
161 13113 : return bResult;
162 : }
163 :
164 13113 : Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
165 : {
166 13113 : Reference< chart2::XChartType > xResult;
167 :
168 : try
169 : {
170 : Reference< lang::XMultiServiceFactory > xFact(
171 13113 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
172 :
173 13113 : if( m_bHasFilledArea )
174 3333 : xResult.set( xFact->createInstance(
175 3333 : CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW );
176 : else
177 9780 : xResult.set( xFact->createInstance(
178 9780 : CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW );
179 : }
180 0 : catch( const uno::Exception & ex )
181 : {
182 : ASSERT_EXCEPTION( ex );
183 : }
184 :
185 13113 : return xResult;
186 : }
187 :
188 13113 : Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries(
189 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
190 : throw (uno::RuntimeException, std::exception)
191 : {
192 13113 : Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
193 13113 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
194 13113 : return xResult;
195 : }
196 :
197 : } // namespace chart
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|