xref: /trunk/main/chart2/source/inc/DiagramHelper.hxx (revision 07a3d7f1)
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 #ifndef CHART2_DIAGRAMHELPER_HXX
24 #define CHART2_DIAGRAMHELPER_HXX
25 
26 #include "StackMode.hxx"
27 #include "charttoolsdllapi.hxx"
28 #include <com/sun/star/chart2/XAxis.hpp>
29 #include <com/sun/star/chart2/XDiagram.hpp>
30 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
31 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
32 #include <com/sun/star/chart2/InterpretedData.hpp>
33 #include <com/sun/star/chart2/StackingDirection.hpp>
34 #include <com/sun/star/chart2/XChartDocument.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/util/XNumberFormats.hpp>
38 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
39 
40 #include <utility>
41 #include <vector>
42 
43 
44 namespace chart
45 {
46 
47 enum DiagramPositioningMode
48 {
49     DiagramPositioningMode_AUTO,
50     DiagramPositioningMode_EXCLUDING,
51     DiagramPositioningMode_INCLUDING
52 };
53 
54 class OOO_DLLPUBLIC_CHARTTOOLS DiagramHelper
55 {
56 public:
57     typedef ::std::pair<
58             ::com::sun::star::uno::Reference<
59                 ::com::sun::star::chart2::XChartTypeTemplate >,
60             ::rtl::OUString >
61         tTemplateWithServiceName;
62 
63     /** tries to find a template in the chart-type manager that matches the
64         given diagram.
65 
66         @param rPreferredTemplateName
67             Check this template first.  This may speed up searching, if the
68             caller assumes a certain template as most likely to be the one that
69             matches.
70 
71         @return
72             A pair containing a template with the correct properties set as
73             first entry and the service name of the templateas second entry.  If
74             no template was found both elements are empty.
75      */
76     static tTemplateWithServiceName
77         getTemplateForDiagram(
78             const ::com::sun::star::uno::Reference<
79                 ::com::sun::star::chart2::XDiagram > & xDiagram,
80             const ::com::sun::star::uno::Reference<
81                 ::com::sun::star::lang::XMultiServiceFactory > & xChartTypeManager,
82             const ::rtl::OUString & rPreferredTemplateName = ::rtl::OUString());
83 
84     /** Sets the "SwapXAndYAxis" property at all coordinate systems found in the
85         given diagram.
86 
87         "vertical==true" for bar charts, "vertical==false" for column charts
88      */
89     static void setVertical( const ::com::sun::star::uno::Reference<
90                                  ::com::sun::star::chart2::XDiagram > & xDiagram,
91                              bool bVertical = true );
92 
93     /** Gets the "SwapXAndYAxis" property at all coordinate systems found in the
94         given diagram.
95 
96         "vertical==true" for bar charts, "vertical==false" for column charts
97     */
98     static bool getVertical( const ::com::sun::star::uno::Reference<
99                                  ::com::sun::star::chart2::XDiagram > & xDiagram,
100                              bool& rbOutFoundResult, bool& rbOutAmbiguousResult );
101 
102     static StackMode getStackMode(
103         const ::com::sun::star::uno::Reference<
104             ::com::sun::star::chart2::XDiagram > & xDiagram,
105         bool& rbFound, bool& rbAmbiguous
106         );
107 
108     /** @param bOnlyAtFirstChartType
109             If </sal_True>, the stacking mode is only set at the series found inside
110             the first chart type.  This is the standard for all current
111             templates (the only template that has more than one chart-type and
112             allows stacking is bar/line combi, and for this the stacking only
113             applies to the first chart type/the bars)
114      */
115     static void setStackMode(
116         const ::com::sun::star::uno::Reference<
117             ::com::sun::star::chart2::XDiagram > & xDiagram,
118         StackMode eStackMode,
119         bool bOnlyAtFirstChartType = true
120         );
121 
122     /** Retrieves the stackmode of the first DataSeries or none. If the series have differing stack
123         modes, rbAmbiguous is set to true. If no series is there rbFound is set to false.
124 
125         @param xCorrespondingCoordinateSystem
126             The coordinate system in which the given chart type xChartType is
127             located.  (This is needed for determining percent stacking.  If
128             omitted, the result will just indicate "not stacked", "stacked" or
129             "ambiguous")
130      */
131     static StackMode getStackModeFromChartType(
132         const ::com::sun::star::uno::Reference<
133             ::com::sun::star::chart2::XChartType > & xChartType,
134         bool& rbFound, bool& rbAmbiguous,
135         const ::com::sun::star::uno::Reference<
136             ::com::sun::star::chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem =
137                 ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem >()
138         );
139 
140     /** Returns the dimension found for all chart types in the tree.  If the
141         dimension is not unique, 0 is returned.
142      */
143     static sal_Int32 getDimension(
144         const ::com::sun::star::uno::Reference<
145             ::com::sun::star::chart2::XDiagram > & xDiagram );
146 
147     /** Sets the dimension of the diagram given.
148 
149         1. Sets the dimension of all used ChartTypes
150         2. Adapts the DataSeriesTree to reflect the new dimension
151         3. If new coordinate-systems have to be created, adapts the
152            XCoordinateSystemContainer of the diagram.
153      */
154     static void setDimension(
155         const ::com::sun::star::uno::Reference<
156             ::com::sun::star::chart2::XDiagram > & xDiagram,
157         sal_Int32 nNewDimensionCount );
158 
159     /** Replaces all occurrences of xCooSysToReplace in the tree with
160         xReplacement in the diagram's tree
161      */
162     SAL_DLLPRIVATE static void replaceCoordinateSystem(
163         const ::com::sun::star::uno::Reference<
164             ::com::sun::star::chart2::XDiagram > & xDiagram,
165         const ::com::sun::star::uno::Reference<
166             ::com::sun::star::chart2::XCoordinateSystem > & xCooSysToReplace,
167         const ::com::sun::star::uno::Reference<
168             ::com::sun::star::chart2::XCoordinateSystem > & xReplacement );
169 
170     static bool isSeriesAttachedToMainAxis(
171 		const ::com::sun::star::uno::Reference<
172             ::com::sun::star::chart2::XDataSeries >& xDataSeries );
173 
174     static bool attachSeriesToAxis( bool bMainAxis,
175         const ::com::sun::star::uno::Reference<
176 	        ::com::sun::star::chart2::XDataSeries >& xSeries,
177         const ::com::sun::star::uno::Reference<
178             ::com::sun::star::chart2::XDiagram >& xDiagram,
179         const ::com::sun::star::uno::Reference<
180             ::com::sun::star::uno::XComponentContext > & xContext,
181         bool bAdaptAxes=true );
182 
183     static ::com::sun::star::uno::Reference<
184 	        ::com::sun::star::chart2::XAxis > getAttachedAxis(
185         const ::com::sun::star::uno::Reference<
186 	        ::com::sun::star::chart2::XDataSeries >& xSeries,
187         const ::com::sun::star::uno::Reference<
188             ::com::sun::star::chart2::XDiagram >& xDiagram );
189 
190     static ::com::sun::star::uno::Reference<
191 	        ::com::sun::star::chart2::XChartType >
192 		getChartTypeOfSeries(
193 			const ::com::sun::star::uno::Reference<
194                 ::com::sun::star::chart2::XDiagram >& xDiagram,
195 			const ::com::sun::star::uno::Reference<
196 	            ::com::sun::star::chart2::XDataSeries >& xSeries );
197 
198     static ::std::vector<
199             ::com::sun::star::uno::Reference<
200             ::com::sun::star::chart2::XDataSeries > >
201         getDataSeriesFromDiagram(
202             const ::com::sun::star::uno::Reference<
203             ::com::sun::star::chart2::XDiagram > & xDiagram );
204 
205     /** return all data series in this diagram grouped by chart-types
206      */
207     static ::com::sun::star::uno::Sequence<
208                ::com::sun::star::uno::Sequence<
209                    ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > >
210         getDataSeriesGroups(
211             const ::com::sun::star::uno::Reference<
212             ::com::sun::star::chart2::XDiagram > & xDiagram );
213 
214     static bool isCategoryDiagram(
215             const ::com::sun::star::uno::Reference<
216                 ::com::sun::star::chart2::XDiagram >& xDiagram );
217 
218     static void setCategoriesToDiagram(
219             const ::com::sun::star::uno::Reference<
220                 ::com::sun::star::chart2::data::XLabeledDataSequence >& xCategories,
221             const ::com::sun::star::uno::Reference<
222                 ::com::sun::star::chart2::XDiagram >& xDiagram,
223             bool bSetAxisType = false, // when this flag is true ...
224             bool bCategoryAxis = true);// set the AxisType to CATEGORY or back to REALNUMBER
225 
226     static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >
227         getCategoriesFromDiagram(
228             const ::com::sun::star::uno::Reference<
229                 ::com::sun::star::chart2::XDiagram > & xDiagram );
230 
231     static ::com::sun::star::uno::Sequence< rtl::OUString >
232         getExplicitSimpleCategories(
233             const ::com::sun::star::uno::Reference<
234                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
235 
236     SAL_DLLPRIVATE static ::com::sun::star::uno::Sequence< rtl::OUString >
237         generateAutomaticCategoriesFromCooSys(
238             const ::com::sun::star::uno::Reference<
239                 ::com::sun::star::chart2::XCoordinateSystem > & xCooSys );
240 
241     static void switchToDateCategories(
242         const ::com::sun::star::uno::Reference<
243                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
244 
245     static void switchToTextCategories(
246         const ::com::sun::star::uno::Reference<
247                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
248 
249     static bool isSupportingDateAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram );
250     static bool isDateNumberFormat( sal_Int32 nNumberFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& xNumberFormats );
251     static sal_Int32 getDateNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
252 
253     static sal_Int32 getPercentNumberFormat( const ::com::sun::star::uno::Reference<
254                 ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
255 
256     static ::com::sun::star::uno::Reference<
257             ::com::sun::star::chart2::XChartType >
258         getChartTypeByIndex( const ::com::sun::star::uno::Reference<
259             ::com::sun::star::chart2::XDiagram >& xDiagram, sal_Int32 nIndex );
260 
261     static ::com::sun::star::uno::Sequence<
262             ::com::sun::star::uno::Reference<
263                 ::com::sun::star::chart2::XChartType > >
264         getChartTypesFromDiagram(
265             const ::com::sun::star::uno::Reference<
266                 ::com::sun::star::chart2::XDiagram > & xDiagram );
267 
268     SAL_DLLPRIVATE static bool areChartTypesCompatible( const ::com::sun::star::uno::Reference<
269                 ::com::sun::star::chart2::XChartType >& xFirstType,
270                 const ::com::sun::star::uno::Reference<
271                 ::com::sun::star::chart2::XChartType >& xSecondType );
272 
273 
274     /**
275         * Test if a series can be moved.
276         *
277         * @param xDiagram
278         *  Reference to the diagram that contains the series.
279         *
280         * @param xGivenDataSeries
281         *  Reference to the series that should be tested for moving.
282         *
283         * @param bForward
284         *  Direction of the move to be checked.
285         *
286         * @returns </sal_True> if the series can be moved.
287         *
288         */
289     static bool isSeriesMoveable(
290             const ::com::sun::star::uno::Reference<
291                 ::com::sun::star::chart2::XDiagram >& xDiagram,
292             const ::com::sun::star::uno::Reference<
293         ::com::sun::star::chart2::XDataSeries >& xGivenDataSeries,
294             bool bForward );
295 
296     /**
297         * Move a series forward or backward.
298         *
299         * @param xDiagram
300         *  Reference to the diagram that contains the series.
301         *
302         * @param xGivenDataSeries
303         *  Reference to the series that should be moved.
304         *
305         * @param bForward
306         *  Direction in which the series should be moved.
307         *
308         * @returns </sal_True> if the series was moved successfully.
309         *
310         */
311     static bool moveSeries(
312                 const ::com::sun::star::uno::Reference<
313                   ::com::sun::star::chart2::XDiagram >& xDiagram,
314                 const ::com::sun::star::uno::Reference<
315           ::com::sun::star::chart2::XDataSeries >& xGivenDataSeries,
316                 bool bForward );
317 
318     static bool isSupportingFloorAndWall( const ::com::sun::star::uno::Reference<
319                 ::com::sun::star::chart2::XDiagram > & xDiagram );
320 
321     static bool isPieOrDonutChart( const ::com::sun::star::uno::Reference<
322                 ::com::sun::star::chart2::XDiagram >& xDiagram );
323 
324     static sal_Int32 getGeometry3D(
325         const ::com::sun::star::uno::Reference<
326             ::com::sun::star::chart2::XDiagram > & xDiagram,
327         bool& rbFound, bool& rbAmbiguous );
328 
329     static void setGeometry3D(
330         const ::com::sun::star::uno::Reference<
331             ::com::sun::star::chart2::XDiagram > & xDiagram,
332         sal_Int32 nNewGeometry );
333 
334     //returns integer from constant group ::com::sun::star::chart::MissingValueTreatment
335     static sal_Int32 getCorrectedMissingValueTreatment(
336             const ::com::sun::star::uno::Reference<
337                 ::com::sun::star::chart2::XDiagram > & xDiagram,
338             const ::com::sun::star::uno::Reference<
339                 ::com::sun::star::chart2::XChartType >& xChartType );
340 
341     static DiagramPositioningMode getDiagramPositioningMode( const ::com::sun::star::uno::Reference<
342                 ::com::sun::star::chart2::XDiagram > & xDiagram );
343 
344     static bool setDiagramPositioning( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel,
345         const ::com::sun::star::awt::Rectangle& rPosRect /*100th mm*/ );
346 
347     static ::com::sun::star::awt::Rectangle getDiagramRectangleFromModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel );
348 
349     static bool switchDiagramPositioningToExcludingPositioning( const ::com::sun::star::uno::Reference<
350         ::com::sun::star::frame::XModel >& xChartModel
351         , bool bResetModifiedState //set model back to unchanged if it was unchanged before
352         , bool bConvertAlsoFromAutoPositioning );
353 
354 private:
355     // not implemented
356     DiagramHelper();
357 
358 };
359 
360 } //  namespace chart
361 
362 // CHART2_DIAGRAMHELPER_HXX
363 #endif
364