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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "NetChartTypeTemplate.hxx"
27 #include "macros.hxx"
28 #include "PolarCoordinateSystem.hxx"
29 #include "DiagramHelper.hxx"
30 #include "servicenames_charttypes.hxx"
31 #include "DataSeriesHelper.hxx"
32 #include <com/sun/star/chart2/SymbolStyle.hpp>
33 #include <com/sun/star/chart2/Symbol.hpp>
34 #include <com/sun/star/drawing/LineStyle.hpp>
35 
36 using namespace ::com::sun::star;
37 
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::rtl::OUString;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Any;
43 using ::osl::MutexGuard;
44 
45 
46 namespace
47 {
48 static const ::rtl::OUString lcl_aServiceName(
49     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.NetChartTypeTemplate" ));
50 } // anonymous namespace
51 
52 namespace chart
53 {
54 
NetChartTypeTemplate(Reference<uno::XComponentContext> const & xContext,const::rtl::OUString & rServiceName,StackMode eStackMode,bool bSymbols,bool bHasLines,bool bHasFilledArea)55 NetChartTypeTemplate::NetChartTypeTemplate(
56     Reference< uno::XComponentContext > const & xContext,
57     const ::rtl::OUString & rServiceName,
58     StackMode eStackMode,
59     bool bSymbols,
60     bool bHasLines ,
61     bool bHasFilledArea ) :
62         ChartTypeTemplate( xContext, rServiceName ),
63         m_eStackMode( eStackMode ),
64         m_bHasSymbols( bSymbols ),
65         m_bHasLines( bHasLines ),
66         m_bHasFilledArea( bHasFilledArea )
67 {}
68 
~NetChartTypeTemplate()69 NetChartTypeTemplate::~NetChartTypeTemplate()
70 {}
71 
getStackMode(sal_Int32) const72 StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
73 {
74     return m_eStackMode;
75 }
76 
applyStyle(const Reference<chart2::XDataSeries> & xSeries,::sal_Int32 nChartTypeIndex,::sal_Int32 nSeriesIndex,::sal_Int32 nSeriesCount)77 void SAL_CALL NetChartTypeTemplate::applyStyle(
78     const Reference< chart2::XDataSeries >& xSeries,
79     ::sal_Int32 nChartTypeIndex,
80     ::sal_Int32 nSeriesIndex,
81     ::sal_Int32 nSeriesCount )
82     throw (uno::RuntimeException)
83 {
84     ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
85 
86     try
87     {
88         Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
89 
90         DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
91         DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
92         DataSeriesHelper::makeLinesThickOrThin( xProp, true );
93     }
94     catch( uno::Exception & ex )
95     {
96         ASSERT_EXCEPTION( ex );
97     }
98 }
99 
100 // ____ XChartTypeTemplate ____
matchesTemplate(const Reference<chart2::XDiagram> & xDiagram,sal_Bool bAdaptProperties)101 sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate(
102     const Reference< chart2::XDiagram >& xDiagram,
103     sal_Bool bAdaptProperties )
104     throw (uno::RuntimeException)
105 {
106     sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
107 
108     uno::Reference< beans::XPropertySet > xChartTypeProp(
109         DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
110 
111     if( bResult )
112     {
113         //filled net chart?:
114         if( m_bHasFilledArea )
115             return sal_True;
116 
117         // check symbol-style
118         // for a template with symbols it is ok, if there is at least one series
119         // with symbols, otherwise an unknown template is too easy to achieve
120         bool bSymbolFound = false;
121         bool bLineFound = false;
122 
123         ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
124             DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
125 
126         for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
127                  aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
128         {
129             try
130             {
131                 chart2::Symbol aSymbProp;
132                 drawing::LineStyle eLineStyle;
133                 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
134 
135                 bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) &&
136                     (aSymbProp.Style != chart2::SymbolStyle_NONE);
137 
138                 if( bCurrentHasSymbol )
139                     bSymbolFound = true;
140 
141                 if( bCurrentHasSymbol && (!m_bHasSymbols) )
142                 {
143                     bResult = false;
144                     break;
145                 }
146 
147                 bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) &&
148                     ( eLineStyle != drawing::LineStyle_NONE );
149 
150                 if( bCurrentHasLine )
151                     bLineFound = true;
152 
153                 if( bCurrentHasLine && (!m_bHasLines) )
154                 {
155                     bResult = false;
156                     break;
157                 }
158             }
159             catch( uno::Exception & ex )
160             {
161                 ASSERT_EXCEPTION( ex );
162             }
163         }
164 
165         if(bResult)
166         {
167             if( !bLineFound && m_bHasLines && bSymbolFound )
168                 bResult = false;
169             else if( !bSymbolFound && m_bHasSymbols && bLineFound )
170                 bResult = false;
171             else if( !bLineFound && !bSymbolFound )
172                 return m_bHasLines && m_bHasSymbols;
173         }
174     }
175 
176     return bResult;
177 }
178 
getChartTypeForIndex(sal_Int32)179 Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
180 {
181     Reference< chart2::XChartType > xResult;
182 
183     try
184     {
185         Reference< lang::XMultiServiceFactory > xFact(
186             GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
187 
188         if( m_bHasFilledArea )
189             xResult.set( xFact->createInstance(
190                              CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW );
191         else
192             xResult.set( xFact->createInstance(
193                              CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW );
194     }
195     catch( uno::Exception & ex )
196     {
197         ASSERT_EXCEPTION( ex );
198     }
199 
200     return xResult;
201 }
202 
getChartTypeForNewSeries(const uno::Sequence<Reference<chart2::XChartType>> & aFormerlyUsedChartTypes)203 Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries(
204         const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
205     throw (uno::RuntimeException)
206 {
207     Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
208     ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
209     return xResult;
210 }
211 
212 // ----------------------------------------
213 
getSupportedServiceNames_Static()214 Sequence< OUString > NetChartTypeTemplate::getSupportedServiceNames_Static()
215 {
216     Sequence< OUString > aServices( 2 );
217     aServices[ 0 ] = lcl_aServiceName;
218     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
219     return aServices;
220 }
221 
222 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
223 APPHELPER_XSERVICEINFO_IMPL( NetChartTypeTemplate, lcl_aServiceName );
224 
225 } //  namespace chart
226