/*
* Ncview by David W. Pierce. A visual netCDF file viewer.
* Copyright (C) 1993-2010 David W. Pierce
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program 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, version 3, for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* David W. Pierce
* 6259 Caminito Carrena
* San Diego, CA 92122
* pierce@cirrus.ucsd.edu
*/
/*****************************************************************************
*
* Elements which implement the X Windows user interface to ncview
*
*****************************************************************************/
#include "../ncview.includes.h"
#include "../ncview.defines.h"
#include "../ncview.protos.h"
#include "../ncview.bitmaps.h"
#include "fallback_resources.h"
#include <X11/CoreP.h>
#include <X11/CoreP.h>
#ifdef INC_PPM
#include "ppm.h"
#endif
#define DEFAULT_BUTTON_WIDTH 55
#define DEFAULT_LABEL_WIDTH 400
#define DEFAULT_DIMLABEL_WIDTH 95
#define DEFAULT_VARLABEL_WIDTH 95
#define DEFAULT_N_VARS_PER_ROW 4
#define DEFAULT_BLOWUP_SIZE 300
#define DEFAULT_VAR_COLORS 1
#define DEFAULT_AUTO_OVERLAY 1
#define N_EXTRA_COLORS 10
#define CBAR_HEIGHT 24
#define XtNlabelWidth "labelWidth"
#define XtCLabelWidth "LabelWidth"
#define XtNblowupDefaultSize "blowupDefaultSize"
#define XtCBlowupDefaultSize "BlowupDefaultSize"
#define XtNdimLabelWidth "dimLabelWidth"
#define XtCDimLabelWidth "DimLabelWidth"
#define XtNvarLabelWidth "varLabelWidth"
#define XtCVarLabelWidth "VarLabelWidth"
#define XtNbuttonWidth "buttonWidth"
#define XtCButtonWidth "ButtonWidth"
#define XtNnVarsPerRow "nVarsPerRow"
#define XtCNVarsPerRow "NVarsPerRow"
#define XtNdeltaStep "deltaStep"
#define XtCDeltaStep "DeltaStep"
#define XtNversion "version"
#define XtCVersion "Version"
#define XtNvarcolors "varColors"
#define XtCvarcolors "VarColors"
#define XtNautooverlay "autoOverlay"
#define XtCautooverlay "AutoOverlay"
#define XtNforeground1d "foreground1d"
#define XtCforeground1d "Foreground1d"
#define XtNforeground2d "foreground2d"
#define XtCforeground2d "Foreground2d"
#define XtNforeground3d "foreground3d"
#define XtCforeground3d "Foreground3d"
#define XtNforeground4d "foreground4d"
#define XtCforeground4d "Foreground4d"
#define XtNforeground5d "foreground5d"
#define XtCforeground5d "Foreground5d"
#define ORDER_RGB 1 /* R mask > B mask */
#define ORDER_BGR 2 /* B mask > R mask */
/* This is used to hold key info about the X server
* that we use when we try to create an image.
*/
typedef struct {
int bits_per_pixel,
byte_order,
bytes_per_pixel,
bitmap_unit,
bitmap_pad,
rgb_order,
shift_red,
shift_green_upper, shift_green_lower,
shift_blue,
depth,
width,
height;
unsigned long mask_red,
mask_green_upper, mask_green_lower,
mask_blue;
} Server_Info;
/**************************/
extern NCVar *variables;
extern Options options;
extern ncv_pixel *pixel_transform;
/**************************/
typedef struct {
int label_width; /* width of the informational labels */
int dimlabel_width; /* as above, but for dimension labls */
int varlabel_width; /* as above, but for variable labls */
int blowup_default_size; /* default size, in pixels, of newly opened windows */
int button_width; /* width of the control buttons */
int n_vars_per_row; /* how many vars in one row before
* we start another.
*/
int delta_step; /* Becomes options.delta_step */
float version; /* Must match compiled in version */
int var_colors; /* 1 to use var colors, 0 not to */
int auto_overlay; /* 1 to automatically put on overlays, 0 not to */
Pixel foreground1d;
Pixel foreground2d;
Pixel foreground3d;
Pixel foreground4d;
Pixel foreground5d;
} AppData, *AppDataPtr;
typedef struct {
XColor *color_list;
void *next, *prev;
char *name;
ncv_pixel *pixel_transform;
} Cmaplist;
/* These are "global" to this directory, in the sense that other files
* in this directory use them.
*/
Widget topLevel;
XtAppContext x_app_context;
static Cmaplist *colormap_list = NULL, *current_colormap_list = NULL;
static Colormap current_colormap = (Colormap)NULL;
static AppData app_data;
static Server_Info server;
static XtIntervalId timer;
static int timer_enabled = FALSE,
ccontour_popped_up = FALSE,
valid_display;
static float default_version_number = 0.0;
static Pixmap reverse_pixmap,
backwards_pixmap,
pause_pixmap,
forward_pixmap,
fastforward_pixmap;
/* Not static cuz used by set_options.c */
Pixmap open_circle_pixmap,
closed_circle_pixmap;
static XEvent event;
static Widget
error_popup_widget = NULL,
error_popupcanvas_widget,
error_popupdialog_widget,
dimsel_popup_widget,
dimsel_popupcanvas_widget,
dimsel_ok_button_widget,
dimsel_cancel_button_widget,
ccontourpanel_widget,
ccontour_form_widget,
ccontour_info1_widget,
ccontour_viewport_widget,
horiz_scroll_widget,
vert_scroll_widget,
ccontour_widget,
ccontour_info2_widget,
commandcanvas_widget,
buttonbox_widget,
label1_widget,
label2_widget,
label3_widget,
label4_widget,
label5_widget,
quit_button_widget,
restart_button_widget,
reverse_button_widget,
backwards_button_widget,
pause_button_widget,
forward_button_widget,
fastforward_button_widget,
edit_button_widget,
info_button_widget,
scrollspeed_label_widget,
scrollspeed_widget,
options_button_widget,
optionbox_widget,
cmap_button_widget,
invert_button_widget,
invert_color_button_widget,
blowup_widget,
transform_widget,
dimset_widget,
range_widget,
blowup_type_widget,
print_button_widget,
colorbar_form_widget,
colorbar_widget,
varsel_form_widget,
*var_selection_widget, /* the boxes with N vars per box */
varlist_label_widget,
*varlist_widget, /* The buttons that select a var */
varsel_menu_widget, /* Only if using menu-style var selection */
var_menu_1d, /* ditto */
var_menu_2d, /* ditto */
var_menu_3d, /* ditto */
var_menu_4d, /* ditto */
var_menu_other, /* ditto */
labels_row_widget,
lr_dim_widget,
lr_name_widget,
lr_min_widget,
lr_cur_widget,
lr_max_widget,
lr_units_widget,
*diminfo_row_widget = NULL,
*diminfo_dim_widget = NULL,
*diminfo_name_widget = NULL,
*diminfo_min_widget = NULL,
*diminfo_cur_widget = NULL,
*diminfo_max_widget = NULL,
*diminfo_units_widget = NULL,
xdim_selection_widget,
xdimlist_label_widget,
*xdimlist_widget = NULL,
ydim_selection_widget,
ydimlist_label_widget,
*ydimlist_widget = NULL;
static XtResource resources[] = {
{
XtNlabelWidth,
XtCLabelWidth,
XtRInt,
sizeof( int ),
XtOffset( AppDataPtr, label_width ),
XtRImmediate,
(XtPointer)DEFAULT_LABEL_WIDTH,
},
{
XtNblowupDefaultSize,
XtCBlowupDefaultSize,
XtRInt,
sizeof( int ),
XtOffset( AppDataPtr, blowup_default_size ),
XtRImmediate,
(XtPointer)DEFAULT_BLOWUP_SIZE,
},
{
XtNdimLabelWidth,
XtCDimLabelWidth,
XtRInt,
sizeof( int ),
XtOffset( AppDataPtr, dimlabel_width ),
XtRImmediate,
(XtPointer)DEFAULT_DIMLABEL_WIDTH,
},
{
XtNvarLabelWidth,
XtCVarLabelWidth,
XtRInt,
sizeof( int ),
XtOffset( AppDataPtr, varlabel_width ),
XtRImmediate,
(XtP