Menu

[487b0c]: / src / gtkplotter.cpp  Maximize  Restore  History

Download this file

263 lines (194 with data), 6.1 kB

  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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*! \file gtkplotter.cpp
* \brief GTK based plotters.
*/
/* Copyright (c) 2005-2012 Taneli Kalvas. All rights reserved.
*
* You can redistribute this software and/or modify it under the terms
* of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This library 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library (file "COPYING" included in the package);
* if not, write to the Free Software Foundation, Inc., 51 Franklin
* Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* If you have questions about your rights to use or distribute this
* software, please contact Berkeley Lab's Technology Transfer
* Department at TTD@lbl.gov. Other questions, comments and bug
* reports should be sent directly to the author via email at
* taneli.kalvas@jyu.fi.
*
* NOTICE. This software was developed under partial funding from the
* U.S. Department of Energy. As such, the U.S. Government has been
* granted for itself and others acting on its behalf a paid-up,
* nonexclusive, irrevocable, worldwide license in the Software to
* reproduce, prepare derivative works, and perform publicly and
* display publicly. Beginning five (5) years after the date
* permission to assert copyright is obtained from the U.S. Department
* of Energy, and subject to any subsequent five (5) year renewals,
* the U.S. Government is granted for itself and others acting on its
* behalf a paid-up, nonexclusive, irrevocable, worldwide license in
* the Software to reproduce, prepare derivative works, distribute
* copies to the public, perform publicly and display publicly, and to
* permit others to do so.
*/
#include "config.h"
#ifdef OPENGL
#include <gtk/gtkgl.h>
#endif
#include "gtkplotter.hpp"
#include "gtkgeomwindow.hpp"
#include "gtkgeom3dwindow.hpp"
#include "gtkparticlediagwindow.hpp"
#include "gtkfielddiagwindow.hpp"
#include "ibsimu.hpp"
#include "error.hpp"
bool GTKPlotter::_gtk_initialized = false;
bool GTKPlotter::_opengl = false;
GTKPlotter::GTKPlotter( int *argc, char ***argv )
: _geom(NULL), _epot(NULL), _efield(NULL), _scharge(NULL), _tdens(NULL),
_bfield(NULL), _pdb(NULL)
{
if( !_gtk_initialized ) {
// Initialize gtk
if( gtk_init_check( argc, argv ) == FALSE )
throw( Error( ERROR_LOCATION, "Couldn't initialize GTK" ) );
_gtk_initialized = true;
#ifdef OPENGL
_opengl = true;
// Initialize OpenGL
if( gtk_gl_init_check( argc, argv ) == FALSE ||
gdk_gl_query_extension() == FALSE )
_opengl = false;
#endif
}
}
GTKPlotter::~GTKPlotter()
{
}
void GTKPlotter::force_software_renderer( void ) const
{
_opengl = false;
}
bool GTKPlotter::opengl( void ) const
{
return( _opengl );
}
void GTKPlotter::run()
{
ibsimu.message( 1 ) << "Running GTKPlotter\n";
ibsimu.inc_indent();
gtk_main();
ibsimu.message( 1 ) << "Done\n";
ibsimu.dec_indent();
}
GTKWindow *GTKPlotter::new_geometry_plot_window( void )
{
GTKWindow *window = new GTKGeomWindow( *this, *_geom, _epot, _efield, _scharge, _tdens, _bfield, _pdb );
_windows.push_back( window );
return( window );
}
GTKWindow *GTKPlotter::new_geometry_3d_plot_window( void )
{
GTKWindow *window = new GTKGeom3DWindow( *this, *_geom, _pdb );
_windows.push_back( window );
return( window );
}
GTKWindow *GTKPlotter::new_particle_plot_window( coordinate_axis_e axis, double level,
particle_diag_plot_type_e type,
trajectory_diagnostic_e diagx,
trajectory_diagnostic_e diagy )
{
if( !_pdb )
throw( Error( ERROR_LOCATION, "Particle database not defined" ) );
if( !_geom )
throw( Error( ERROR_LOCATION, "Geometry not defined" ) );
GTKWindow *window = new GTKParticleDiagWindow( *this, *_pdb, *_geom, axis, level, type, diagx, diagy );
_windows.push_back( window );
return( window );
}
GTKWindow *GTKPlotter::new_field_plot_window( size_t N, const Vec3D &x1, const Vec3D &x2,
const field_diag_type_e diag[2],
const field_loc_type_e loc[2] )
{
if( !_geom )
throw( Error( ERROR_LOCATION, "Geometry not defined" ) );
GTKWindow *window = new GTKFieldDiagWindow( *this, *_geom, N, x1, x2, diag, loc );
_windows.push_back( window );
return( window );
}
void GTKPlotter::delete_window( GTKWindow *window )
{
for( size_t a = 0; a < _windows.size(); a++ ) {
if( _windows[a] == window ) {
delete( window );
_windows.erase( _windows.begin()+a );
break;
}
}
if( _windows.size() == 0 ) {
gtk_main_quit();
}
}
const Geometry *GTKPlotter::get_geometry( void ) const
{
return( _geom );
}
const EpotField *GTKPlotter::get_epot( void ) const
{
return( _epot );
}
const EpotEfield *GTKPlotter::get_efield( void ) const
{
return( _efield );
}
const MeshScalarField *GTKPlotter::get_scharge( void ) const
{
return( _scharge );
}
const MeshScalarField *GTKPlotter::get_trajdens( void ) const
{
return( _tdens );
}
const VectorField *GTKPlotter::get_bfield( void ) const
{
return( _bfield );
}
const ParticleDataBase *GTKPlotter::get_particledatabase( void ) const
{
return( _pdb );
}
void GTKPlotter::set_geometry( const Geometry *geom )
{
_geom = geom;
}
void GTKPlotter::set_epot( const EpotField *epot )
{
_epot = epot;
}
void GTKPlotter::set_efield( const EpotEfield *efield )
{
_efield = efield;
}
void GTKPlotter::set_scharge( const MeshScalarField *scharge )
{
_scharge = scharge;
}
void GTKPlotter::set_trajdens( const MeshScalarField *tdens )
{
_tdens = tdens;
}
void GTKPlotter::set_bfield( const VectorField *bfield )
{
_bfield = bfield;
}
void GTKPlotter::set_particledatabase( const ParticleDataBase *pdb )
{
_pdb = pdb;
}