summaryrefslogtreecommitdiffstats
path: root/applications/rview/rviewDisplay.hh
blob: 7587d0687f748c79a48acca5f35ab1667d241049 (plain)
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
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community 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 rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/

/**
 *  Purpose:
 *
 *  Base class for all object viewers (rviewImage, rviewChart, rviewTable
 *  and rviewSound). Provides a frame with standard control widgets and
 *  menus, functions for parsing/advancing the projection string and
 *  initializing protected variables according to the MDD object that will
 *  be displayed.
 *
 *  COMMENTS:
 *		None
 */


#ifndef _RVIEW_DISPLAY_H_
#define _RVIEW_DISPLAY_H_




#include "rasodmg/ref.hh"
#include "rasodmg/marray.hh"
#include "rasodmg/gmarray.hh"

#include "labelManager.hh"
#include "rviewUtils.hh"




/*
 *  A window containing an display mode + controls
 */
class rviewDisplay: public rviewFrame
{
  public:

  rviewDisplay(mdd_frame *mf, int es, unsigned int flags=0);
  virtual ~rviewDisplay(void);

  // must use separate call because no virtual functions beyond level i can
  // be called in a constructor of level i. This became necessary when the
  // rviewImage class was split up. Returns 0 for OK, -1 for error.
  virtual int openViewer(void);
  // Same reason for virtual calls (getViewerType()) in the destructor; this
  // functions is called from a viewer's destructor to notify its parent of the
  // close event.
  void closeViewer(void);

  virtual void label();
  virtual int process(wxObject &obj, wxEvent &evt);

  virtual void OnSize(int w, int h);
  virtual void OnMenuCommand(int id);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const = 0;

  // Needs to process user events
  virtual int userEvent(const user_event &ue);
  // Notify derived classes that they should get ready to die. This is needed
  // for stuff like images with movie-playback running.
  virtual void prepareToDie(void);
  // Notify derived classes that the projection has changed
  virtual int newProjection(void);
  // get the minterval to use with the projection string
  virtual const r_Minterval &getVirtualDomain(void) const;

  // Called when an update object has been replaced with a new one
  void noLongerUpdate(void);
  // Returns the display ID (used in for update displays)
  int getIdentifier(void) const;
  int getDisplayCounter(void) const;
  // sets the ID of the query window in case it's an update object
  void setQueryWindow(int qwindowID);

  // viewer-related constants
  // Default width and height of display window
  static const int display_width;
  static const int display_height;
  // Space reserved around the canvas
  static const int display_cnvborder;
  // Borders used in display window
  static const int display_border;
  // Scrollbar steps
  static const int display_scrstep;
  // Page stepping
  static const int display_pgstep;
  // Height of control area
  static const int display_cheight;
  // Height of projection widget
  static const int display_pjheight;
  // Maximum width of projection widget
  static const int display_pjwidth;
  // Projection OK-button dimensions
  static const int display_pbwidth;
  static const int display_pbheight;
  // Minimum display window size (to avoid X errors)
  static const int display_minwidth;

  // Display flags
  static const int display_flag_standalone;
  static const int display_flag_update;

  // modes for advanceProjection()
  enum display_advmode_e {
    display_advmode_relative,
    display_advmode_absolute,
    display_advmode_reset
  };


  protected:

  // to allow derived functions to add stuff to the file menu before the quit item
  virtual int fileMenuInitHook(wxMenu *menu);
  // to allow derived functions to add stuff to the view menu
  virtual int viewMenuInitHook(wxMenu *menu);
  // for appending menus to the menu bar
  virtual int menuBarInitHook(void);

  // Called by the derived classes to (un)grey certain widgets
  void setModeDimension(int dim);
  // Called by derived classes to set minimum size of viewer window
  void setMinimumViewerSize(int w, int h);
  // Advances projection (+/- buttons)
  const char *skipIndexMapping(const char *s);
  int advanceProjection(int direction, int advmode=display_advmode_relative);
  void newDBState(bool dbstate);
  void setDisplayTitle(const char *title=NULL);
  // view management
  int doSaveView(void);
  int doLoadView(void);
  int parseViewFile(FILE *fp);
  static void writeViewKey(FILE *fp, const char *key);
  static void writeViewParam(FILE *fp, const char *key, const char *value);
  static void writeViewParam(FILE *fp, const char *key, long value);
  static void writeViewParam(FILE *fp, const char *key, double value);
  static void writeViewParam(FILE *fp, const char *key, unsigned int num, const long *values);
  static void writeViewParam(FILE *fp, const char *key, unsigned int num, const double *values);
  static int readVector(const char *value, unsigned int num, long *values);
  static int readVector(const char *value, unsigned int num, double *values);

  // save the current view to a file descriptor
  virtual int saveView(FILE *fp);
  // read a parameter from a view file line; returns 0 if unknown key, 1 otherwise
  virtual int readView(const char *key, const char *value);
  // loading a new view is finished, allow updating of displays before the redraw
  virtual void loadViewFinished(void);

  unsigned int displayFlags;
  r_Ref<r_GMarray> mddObj;
  r_Minterval interv;
  r_Point pt1, pt2, mapIndex;
  int dimMDD, dimMode, baseSize;
  rviewBaseType baseType;
  wxMenuBar *mBar;
  wxPanel *ctrlPanel;
  rviewText *project, *advance;
  wxMessage *typeMsg;
  rviewButton *projBut, *projPlus, *projMinus;
  char projString[STRINGSIZE];
  char rootTitle[STRINGSIZE];
  int extraSpace;
  int totalCtrlHeight;
  int displayID;
  int qwindowID;
  int minViewX, minViewY, mbarHeight;
  bool displayOperation;
  bool objectInitializedOK;
  // number of menus that are always on the menu bar
  static const int fixedNumberOfMenus;


  private:

  // This variable avoids closeViewer() being called more than once
  // in case there are viewer classes derived from a common, non-
  // abstract base class.
  bool closeViewerCalled;

  // This global variable is incremented every time a display window is
  // opened. It is used to init the displayID member to identify display
  // windows by a number.
  static int displayCounter;

  // file extension of view file
  static const char *viewFileExtension;

  // size of buffer for view loading
  static const unsigned int viewBuffSize;

  // view parameter keywords
  static const char *view_HeaderLine;
  static const char *view_ViewerType;
  static const char *view_ProjString;
  static const char *view_WindowSize;
};

#endif