File: wxPLplotstream.cpp

package info (click to toggle)
plplot 5.15.0%2Bdfsg2-15
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 31,396 kB
  • sloc: ansic: 79,703; xml: 28,583; cpp: 20,033; ada: 19,456; tcl: 12,081; f90: 11,431; ml: 7,276; java: 6,863; python: 6,792; sh: 3,274; perl: 828; lisp: 75; makefile: 74; sed: 34; fortran: 6
file content (150 lines) | stat: -rw-r--r-- 3,942 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (C) 2015  Phil Rosenberg
// Copyright (C) 2005  Werner Smekal
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//

// wxwidgets headers
#include "wx/wx.h"

// plplot headers
#include "plplotP.h"

#include "wxPLplotstream.h"

//! Constructor of wxPLplotstream class which is inherited from plstream.
//  Here we set the driver (wxwidgets :), and tell plplot in which dc to
//  plot to and the size of the canvas. We also check and set several
//  device style options.
//
wxPLplotstream::wxPLplotstream( wxDC *dc, int width, int height, int style ) : plstream()
{
    m_created = false;
    Create( dc, width, height, style );
}


wxPLplotstream::wxPLplotstream() : plstream()
{
    m_created = false;
}

//! Called from the constructor or can be called by the user if the default constructor is used
//  We set the driver to be wxwidgets, set the page size, set the driver options and initialize
//  the plot.
void wxPLplotstream::Create( wxDC *dc, int width, int height, int style )
{
    if ( m_created )
    {
        plabort( "wxPLplotstream::Create - Stream already created" );
        return;
    }
    const size_t bufferSize = 256;

    m_width  = width;
    m_height = height;
    m_style  = style;

    sdev( "wxwidgets" );
    spage( 90.0, 90.0, m_width, m_height, 0, 0 );

    char drvopt[bufferSize], buffer[bufferSize];
    drvopt[0] = '\0';

    sprintf( buffer, "hrshsym=%d,text=%d",
        m_style & wxPLPLOT_USE_HERSHEY_SYMBOLS ? 1 : 0,
        m_style & wxPLPLOT_DRAW_TEXT ? 1 : 0 );
    strncat( drvopt, buffer, bufferSize - strlen( drvopt ) );

    setopt( "-drvopt", drvopt );

    sdevdata( (void *) dc );

    init();
}

//! Set the DC to be used by the stream. This will initiate a replot, unless
//  the device is NULL
void wxPLplotstream::SetDC( wxDC *dc )
{
    set_stream();
    cmd( PLESC_DEVINIT, (void *) dc );
}

//! Destructor, although we have no resources to free
wxPLplotstream::~wxPLplotstream()
{
}


//! This is the overloaded set_stream() function, where we could have some
//  code processed before every call of a plplot functions, since set_stream()
//  is called before every plplot function. Not used in the moment.
//
void wxPLplotstream::set_stream()
{
    plstream::set_stream();
}


//! Call this method if the size of the dc changed (because of resizing)
//  to set the new size. You need to call RenewPlot afterwards.
//
void wxPLplotstream::SetSize( int width, int height )
{
    wxSize size( width, height );
    cmd( PLESC_RESIZE, (void *) &size );
    m_width  = width;
    m_height = height;
}


//! Replot everything.
//
void wxPLplotstream::RenewPlot()
{
    replot();
}

void wxPLplotstream::ImportBuffer( void *buffer, size_t size )
{
    plbuffer buf;
    buf.buffer = buffer;
    buf.size   = size;
    cmd( PLESC_IMPORT_BUFFER, &buf );
    RenewPlot();
}

void wxPLplotstream::AppendBuffer( void *buffer, size_t size )
{
    plbuffer buf;
    buf.buffer = buffer;
    buf.size   = size;
    cmd( PLESC_APPEND_BUFFER, &buf );
    cmd( PLESC_FLUSH_REMAINING_BUFFER, NULL );
}

void wxPLplotstream::SetFixedAspectRatio( bool fixed )
{
    PLBOOL f = fixed ? 1 : 0;
    cmd( PLESC_FIXASPECT, &f );
}

bool wxPLplotstream::IsValid()
{
    return m_created;
}