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 #ifndef _BGFX_TOOLS_DEBUGPLOTTER_HXX
25 #define _BGFX_TOOLS_DEBUGPLOTTER_HXX
26 
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/vector/b2dvector.hxx>
29 #include <basegfx/range/b2drange.hxx>
30 #include <basegfx/polygon/b2dpolygon.hxx>
31 #include <basegfx/polygon/b2dpolypolygon.hxx>
32 #include <rtl/string.hxx>
33 #include <boost/utility.hpp> // for noncopyable
34 #include <vector>
35 #include <utility>
36 #include <iostream>
37 #include <basegfx/basegfxdllapi.h>
38 
39 
40 namespace basegfx
41 {
42     class B2DCubicBezier;
43 
44     /** Generates debug output for various basegfx data types.
45 
46     	Use this class to produce debug (trace) output for various
47     	basegfx geometry data types. By default, this class outputs
48     	via OSL_TRACE (i.e. to stderr), and uses the gnuplot output
49     	format.
50 
51         To be able to generate one coherent block of output, this
52         class delays actual writing to its destructor
53      */
54     class BASEGFX_DLLPUBLIC DebugPlotter : private ::boost::noncopyable
55     {
56     public:
57         /** Create new debug output object
58 
59         	@param pTitle
60             Title of the debug output, will appear in trace output
61          */
62         explicit DebugPlotter( const sal_Char* pTitle );
63 
64         /** Create new debug output object
65 
66         	@param pTitle
67             Title of the debug output, will appear in trace output
68 
69             @param rOutputStream
70             Stream to write output to. Must stay valid over the
71             lifetime of this object!
72          */
73         DebugPlotter( const sal_Char* pTitle,
74                       ::std::ostream& rOutputStream );
75 
76         ~DebugPlotter();
77 
78         void plot( const B2DPoint&  		rPoint,
79                    const sal_Char* 			pTitle );
80         void plot( const B2DVector& 		rVec,
81                    const sal_Char* 			pTitle );
82         void plot( const B2DCubicBezier&	rBezier,
83                    const sal_Char* 			pTitle );
84         void plot( const B2DRange&  		rRange,
85                    const sal_Char* 			pTitle );
86         void plot( const B2DPolygon& 		rPoly,
87                    const sal_Char* 			pTitle );
88         void plot( const B2DPolyPolygon&	rPoly,
89                    const sal_Char* 			pTitle );
90 
91     private:
92         void print( const sal_Char* );
93 
94         ::rtl::OString												maTitle;
95         ::std::vector< ::std::pair< B2DPoint, ::rtl::OString > >	maPoints;
96         ::std::vector< ::std::pair< B2DVector, ::rtl::OString > >	maVectors;
97         ::std::vector< ::std::pair< B2DRange, ::rtl::OString > >	maRanges;
98         ::std::vector< ::std::pair< B2DPolygon, ::rtl::OString > >	maPolygons;
99 
100         ::std::ostream*												mpOutputStream;
101     };
102 }
103 
104 #endif /* _BGFX_TOOLS_DEBUGPLOTTER_HXX */
105