1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef CHART2_REGRESSIONCURVEHELPER_HXX 28 #define CHART2_REGRESSIONCURVEHELPER_HXX 29 30 #include <com/sun/star/chart2/XRegressionCurve.hpp> 31 #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp> 32 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> 33 #include <com/sun/star/chart2/data/XDataSource.hpp> 34 #include <com/sun/star/chart2/XDataSeries.hpp> 35 #include <com/sun/star/chart2/XDiagram.hpp> 36 #include <com/sun/star/uno/XComponentContext.hpp> 37 #include <com/sun/star/frame/XModel.hpp> 38 #include "charttoolsdllapi.hxx" 39 40 #include <vector> 41 42 namespace chart 43 { 44 45 class OOO_DLLPUBLIC_CHARTTOOLS RegressionCurveHelper 46 { 47 public: 48 /// returns a model mean-value line 49 SAL_DLLPRIVATE static ::com::sun::star::uno::Reference< 50 ::com::sun::star::chart2::XRegressionCurve > 51 createMeanValueLine( 52 const ::com::sun::star::uno::Reference< 53 ::com::sun::star::uno::XComponentContext > & xContext ); 54 55 /// returns a model regression curve 56 SAL_DLLPRIVATE static ::com::sun::star::uno::Reference< 57 ::com::sun::star::chart2::XRegressionCurve > 58 createRegressionCurveByServiceName( 59 const ::com::sun::star::uno::Reference< 60 ::com::sun::star::uno::XComponentContext > & xContext, 61 ::rtl::OUString aServiceName ); 62 63 // ------------------------------------------------------------ 64 65 static bool hasMeanValueLine( 66 const ::com::sun::star::uno::Reference< 67 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 68 69 static bool isMeanValueLine( 70 const ::com::sun::star::uno::Reference< 71 ::com::sun::star::chart2::XRegressionCurve > & xRegCurve ); 72 73 static ::com::sun::star::uno::Reference< 74 ::com::sun::star::chart2::XRegressionCurve > 75 getMeanValueLine( 76 const ::com::sun::star::uno::Reference< 77 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 78 79 /** creates a mean-value line and adds it to the container. 80 81 @param xSeriesProp 82 If set, this property-set will be used to apply a line color 83 */ 84 static void addMeanValueLine( 85 ::com::sun::star::uno::Reference< 86 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 87 const ::com::sun::star::uno::Reference< 88 ::com::sun::star::uno::XComponentContext > & xContext, 89 const ::com::sun::star::uno::Reference< 90 ::com::sun::star::beans::XPropertySet > & xSeriesProp ); 91 92 static void removeMeanValueLine( 93 ::com::sun::star::uno::Reference< 94 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 95 96 enum tRegressionType 97 { 98 REGRESSION_TYPE_NONE, 99 REGRESSION_TYPE_LINEAR, 100 REGRESSION_TYPE_LOG, 101 REGRESSION_TYPE_EXP, 102 REGRESSION_TYPE_POWER, 103 REGRESSION_TYPE_MEAN_VALUE, 104 REGRESSION_TYPE_UNKNOWN 105 }; 106 107 /** Returns the first regression curve found that is not of type 108 mean-value line 109 */ 110 static ::com::sun::star::uno::Reference< 111 ::com::sun::star::chart2::XRegressionCurve > 112 getFirstCurveNotMeanValueLine( 113 const ::com::sun::star::uno::Reference< 114 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 115 116 /** Returns the type of the first regression curve found that is not of type 117 mean-value line 118 */ 119 static tRegressionType getFirstRegressTypeNotMeanValueLine( 120 const ::com::sun::star::uno::Reference< 121 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 122 123 static tRegressionType getRegressionType( 124 const ::com::sun::star::uno::Reference< 125 ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 126 127 /** @param xPropertySource is taken as source to copy all properties from if 128 not null 129 @param xEquationProperties is set at the new regression curve as 130 equation properties if not null 131 */ 132 static void addRegressionCurve( tRegressionType eType, 133 ::com::sun::star::uno::Reference< 134 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 135 const ::com::sun::star::uno::Reference< 136 ::com::sun::star::uno::XComponentContext > & xContext, 137 const ::com::sun::star::uno::Reference< 138 ::com::sun::star::beans::XPropertySet >& xPropertySource = 139 ::com::sun::star::uno::Reference< 140 ::com::sun::star::beans::XPropertySet >(), 141 const ::com::sun::star::uno::Reference< 142 ::com::sun::star::beans::XPropertySet >& xEquationProperties = 143 ::com::sun::star::uno::Reference< 144 ::com::sun::star::beans::XPropertySet >() 145 ); 146 147 static bool removeAllExceptMeanValueLine( 148 ::com::sun::star::uno::Reference< 149 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 150 151 static void removeEquations( 152 ::com::sun::star::uno::Reference< 153 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 154 155 /** adds the given regression curve if there was none before. If there are 156 regression curves, the first one is replaced by the one given by the 157 type. All remaining curves are remnoved. 158 159 <p>This fuction ignores mean-value lines.</p> 160 */ 161 static void replaceOrAddCurveAndReduceToOne( 162 tRegressionType eType, 163 ::com::sun::star::uno::Reference< 164 ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 165 const ::com::sun::star::uno::Reference< 166 ::com::sun::star::uno::XComponentContext > & xContext ); 167 168 // ------------------------------------------------------------ 169 170 /// returns a calculator object for regression curves (used by the view) 171 static ::com::sun::star::uno::Reference< 172 ::com::sun::star::chart2::XRegressionCurveCalculator > 173 createRegressionCurveCalculatorByServiceName( 174 ::rtl::OUString aServiceName ); 175 176 /** recalculates the regression parameters according to the data given in 177 the data source. 178 179 A sequence having the role "values-x" will be used as x-values for the 180 calculation if found. Otherwise a sequence (1, 2, 3, ...) of category 181 indexes will be used for the recalculateRegression() method of the 182 regression curve. 183 184 The first sequence having the role "values-y" will be used as y-values 185 for the recalculateRegression() method of the regression curve. 186 187 @param bUseXValuesIfAvailable 188 If false, the sequence (1, 2, 3, ...) will always be used, even if 189 there is a data-sequence with role "values-x" 190 */ 191 SAL_DLLPRIVATE static void initializeCurveCalculator( 192 const ::com::sun::star::uno::Reference< 193 ::com::sun::star::chart2::XRegressionCurveCalculator > & xOutCurveCalculator, 194 const ::com::sun::star::uno::Reference< 195 ::com::sun::star::chart2::data::XDataSource > & xSource, 196 bool bUseXValuesIfAvailable = true ); 197 198 /** Same method as above, but uses the given XModel to determine the 199 parameter bUseXValuesIfAvailable in the above function. It is also 200 necessary that the data::XDataSource is an XDataSeries, thus this parameter 201 also changed. 202 */ 203 static void initializeCurveCalculator( 204 const ::com::sun::star::uno::Reference< 205 ::com::sun::star::chart2::XRegressionCurveCalculator > & xOutCurveCalculator, 206 const ::com::sun::star::uno::Reference< 207 ::com::sun::star::chart2::XDataSeries > & xSeries, 208 const ::com::sun::star::uno::Reference< 209 ::com::sun::star::frame::XModel > & xModel ); 210 211 static ::rtl::OUString getUINameForRegressionCurve( const ::com::sun::star::uno::Reference< 212 ::com::sun::star::chart2::XRegressionCurve >& xCurve ); 213 214 static ::std::vector< ::com::sun::star::uno::Reference< 215 ::com::sun::star::chart2::XRegressionCurve > > getAllRegressionCurvesNotMeanValueLine( 216 const ::com::sun::star::uno::Reference< 217 ::com::sun::star::chart2::XDiagram > & xDiagram ); 218 219 static void resetEquationPosition( const ::com::sun::star::uno::Reference< 220 ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 221 222 /// @return the index of the given curve in the given container. -1 if not contained 223 static sal_Int32 getRegressionCurveIndex( 224 const ::com::sun::star::uno::Reference< 225 ::com::sun::star::chart2::XRegressionCurveContainer > & xContainer, 226 const ::com::sun::star::uno::Reference< 227 ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 228 229 static bool hasEquation( 230 const ::com::sun::star::uno::Reference< 231 ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 232 233 private: 234 // not implemented 235 RegressionCurveHelper(); 236 }; 237 238 } // namespace chart 239 240 // CHART2_REGRESSIONCURVEHELPER_HXX 241 #endif 242