-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHiView.cc
429 lines (369 loc) · 11.6 KB
/
HiView.cc
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/* HiView
HiROC CVS ID: $Id: HiView.cc,v 1.37 2014/05/27 17:13:51 guym Exp $
Copyright (C) 2009-2011 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#include "HiView_Application.hh"
#include "HiView_Window.hh"
#include "HiView_Utilities.hh"
using namespace UA::HiRISE;
#include <QSizeF>
#include <QString>
#include <QStringRef>
#include <QStyleFactory>
#include <QImageReader>
#include <QDesktopWidget>
#include <string>
using std::string;
#include <iostream>
using std::cout;
#include <iomanip>
using std::endl;
#include <fstream>
using std::ifstream;
#include <vector>
using std::vector;
#include <cstring>
using std::strlen;
using std::memmove;
using std::strcpy;
#if defined (DEBUG_SECTION)
// DEBUG_SECTION controls.
#define DEBUG_OFF 0
#define DEBUG_ALL -1
#define DEBUG_COMMAND_LINE (1 << 0)
#define DEBUG_DEFAULT DEBUG_ALL
#if (DEBUG_SECTION+0) == 0
#undef DEBUG_SECTION
#define DEBUG_SECTION DEBUG_OFF
#else
using std::clog;
#endif
#endif // DEBUG_SECTION
/*==============================================================================
Constants
*/
#ifndef AS_STRING
/* Provides stringification of #defined names.
Note: The extra double quotes are for MSVC which fails to stringify
__VA_ARGS__ if its value is empty (STRINGIFIED has no argument).
In this case the double quotes coalesce into the intended empty
string constant; otherwise they have no effect on the string generated.
*/
#define STRINGIFIED(...) "" #__VA_ARGS__ ""
#define AS_STRING(...) STRINGIFIED(__VA_ARGS__)
#endif
#ifndef APP_NAME
#define APP_NAME HiView
#endif
#define APP_NAME_STRING AS_STRING(APP_NAME)
//! Application name.
extern const char* const
APPLICATION_NAME = APP_NAME_STRING;
#ifndef ORG_NAME
#define ORG_NAME UA_HiRISE
#endif
#define ORG_NAME_STRING AS_STRING(ORG_NAME)
//! Organization name.
extern const char* const
ORGANIZATION_NAME = ORG_NAME_STRING;
#ifndef MODULE_VERSION
#define MODULE_VERSION_STRING ""
#define _VERSION_ " "
#else
#define MODULE_VERSION_STRING AS_STRING(MODULE_VERSION)
#define _VERSION_ " v" MODULE_VERSION_STRING ", "
#endif
//! Application version identification.
extern const char* const
APPLICATION_VERSION = MODULE_VERSION_STRING;
//! Application identification with source code version and date.
extern const char* const
APPLICATION_ID =
APP_NAME_STRING
_VERSION_ __DATE__
" ($Revision: 1.37 $ $Date: 2014/05/27 17:13:51 $)";
#ifndef MACHINE
#define MACHINE_STRING ""
#else
#define MACHINE_STRING AS_STRING(MACHINE)
#endif
//! Host machine identification (typically an architecture name).
extern const char* const
HOST_MACHINE = MACHINE_STRING;
#ifndef OS
#define HOST_OS_STRING ""
#else
#define HOST_OS_STRING AS_STRING(OS)
#endif
//! Host operating system identification.
extern const char* const
HOST_OS = HOST_OS_STRING;
//! The runtime command name.
char
*Command_Name;
//! Exit status values.
const int
SUCCESS = 0,
// Command line syntax.
BAD_SYNTAX = 1;
/*==============================================================================
Usage
*/
/** Print the application usage description and exit.
The usage description is printed to the standard output stream.
@param exit_status The exit status value,
@param list_descriptions If true usage details will be included in
the output. If false a brief usage description will be provided.
*/
void
usage
(
int exit_status = BAD_SYNTAX,
bool list_descriptions = false
)
{
cout
<< "Usage: " << Command_Name << " [options] [[-Image] <source name>]" << endl;
if (list_descriptions)
cout
<< endl
<< "Viewer for images obtained from local file or remote server sources." << endl
<< endl;
cout << "[-Image] <source name>" << endl;
if (list_descriptions)
cout
<< " The image source name may be the pathname to a local image file" << endl
<< " or a URL to a remote image file. The image source data may be in" << endl
<< " various common formats - such as JPEG, PNG, etc. - as well as a" << endl
<< " JP2 encapsulated JPEG2000 codestream. If a URL is specified for a" << endl
<< " JP2 file the protocol is expected to be \"jpip\"." << endl
<< endl
<< " Default: An internal application image is displayed, or the" << endl
<< " last viewed image is displayed if session restoration is enabled." << endl
<< endl;
cout << "-SCale <horizontal>[,<vertical>]" << endl;
if (list_descriptions)
cout
<< " The initial scaling factor(s) will be applied when the specified" << endl
<< " image source is displayed. If no image source name is specified" << endl
<< " any scaling factors are ignored. If only one scaling factor is" << endl
<< " specified it will apply to both horizontal and vertical scaling." << endl
<< " The scaling factors are decimal values relative to 1.0 for full" << endl
<< " resolution display; 0.5 will display the image at half size, 2.5" << endl
<< " will display the image at two and half times normal size, etc." << endl
<< endl
<< " Default: 1.0" << endl
<< endl;
cout << "-[No_]Restore" << endl;
if (list_descriptions)
cout
<< " Do (not) restore the GUI layout geometry that was saved from the" << endl
<< " last time HiView was used. This option overrides the corresponding" << endl
<< " General Preferences settings." << endl
<< endl
<< " If No_Restore is specified neither the GUI layout geometry nor the" << endl
<< " last source viewed are restored; i.e. the preferences settings are" << endl
<< " ignored in this case. If Restore is specified the Restore Geometry" << endl
<< " preferences setting is ignored but the Restore Last Source setting" << endl
<< " is used." << endl
<< endl
<< " Default: The GUI layout geometry is restored if available and as" << endl
<< " the General Preferences settings specify." << endl
<< endl;
cout << "-STYLE <style> | -STYLES" << endl;
if (list_descriptions)
cout
<< " Sets the application GUI style. Possible values are \"platinum\"," << endl
<< " \"motif\" and \"windows\". Some platforms may support additional" << endl
<< " styles; use the -styles option to get a list of available styles." << endl
<< endl
<< " Default: The default style for the platform being used." << endl
<< endl;
cout << "-Version" << endl;
if (list_descriptions)
cout
<< " List the application version identification and exit." << endl
<< endl
<< " Default: No version identification." << endl
<< endl;
cout << "-Help" << endl;
if (list_descriptions)
cout
<< " Print this help description and exit." << endl
<< endl;
exit (exit_status);
}
/*==============================================================================
Main
*/
int
main
(
int arg_count,
char** arg_list
)
{
Command_Name = *arg_list;
#if defined (DEBUG_SECTION) && DEBUG_SECTION != 0
clog << Command_Name << ": " << APPLICATION_ID << endl
<< HOST_OS << ' ' << HOST_MACHINE << endl;
#endif
// Initialize application resources and Qt run-time environment.
Q_INIT_RESOURCE (HiView); // Can't use APP_NAME in this macro.
// Application object.
HiView_Application
application (arg_count, arg_list);
//QDesktopWidget* widget = application.desktop();
//widget->installEventFilter(new NullEventFilter());
// Application identification.
application.setApplicationName (APPLICATION_NAME);
application.setOrganizationName (ORGANIZATION_NAME);
application.setApplicationVersion (APPLICATION_VERSION);
application.setWindowIcon (QIcon (":/Images/HiView_Icon.png"));
QString
Source_Name;
QSizeF
Scaling;
HiView_Window::Layout_Restoration
Restore_Layout = HiView_Window::PREFERENCES_RESTORE_LAYOUT;
for (int
count = 1;
count < arg_count;
count++)
{
#if ((DEBUG_SECTION) & DEBUG_COMMAND_LINE)
clog << " " << count << ": " << arg_list[count] << endl;
#endif
if (arg_list[count][0] == '-')
{
switch (toupper (arg_list[count][1]))
{
case 'I': // -Image
if (++count == arg_count ||
arg_list[count][0] == '-')
{
cout << "Missing image source name." << endl
<< endl;
usage ();
}
Image_Input:
if (! Source_Name.isEmpty ())
{
cout << "More than one image source specified:" << endl
<< Source_Name << endl
<< "and" << endl
<< arg_list[count] << endl;
usage ();
}
Source_Name = arg_list[count];
break;
case 'S':
if (toupper (arg_list[count][2]) == 'C')
{
// -SCale
if (++count == arg_count)
{
cout << "Missing scaling factor(s)." << endl;
usage ();
}
char
*last_character;
double
scale = strtod (arg_list[count], &last_character);
if (*last_character &&
*last_character != ',')
{
Bad_Scale:
cout << "A scale factor was expected for the "
<< arg_list[count - 1] << " option but \""
<< arg_list[count] << "\" found." << endl;
usage ();
}
Scaling.rwidth () = scale;
if (*last_character &&
*(++last_character))
{
scale = strtod (last_character, &last_character);
if (*last_character)
goto Bad_Scale;
}
Scaling.rheight () = scale;
}
else
if (QString (arg_list[count])
.compare ("-STYLES", Qt::CaseInsensitive) == 0)
{
// -STYLES
cout << "Supported styles -" << endl;
QStringList
styles (QStyleFactory::keys ());
for (int
index = 0;
index < styles.size ();
index++)
cout << " " << styles.at (index) << endl;
exit (SUCCESS);
}
else
goto Unknown_Option;
break;
case 'F': // -Formats
foreach (const QByteArray& entry, QImageReader::supportedImageFormats ())
{
cout << QString (entry) << ' ';
}
cout << endl;
if (! QImageReader::supportedImageFormats ().contains ("PDS"))
{
cout << "The PDS plugin was not found." << endl;
}
exit (SUCCESS);
case 'N': // -No_Restore
Restore_Layout = HiView_Window::DO_NOT_RESTORE_LAYOUT;
break;
case 'R': // -Restore
Restore_Layout = HiView_Window::RESTORE_LAYOUT;
break;
case 'H': // -Help
usage (SUCCESS, true);
case 'V': // -Version
cout << APPLICATION_ID << endl
<< "Build system: "
<< HOST_OS << ' ' << HOST_MACHINE << endl;
exit (SUCCESS);
default:
Unknown_Option:
cout << "Unrecognized command line argument: "
<< arg_list[count] << endl;
usage ();
}
}
else
goto Image_Input;
}
if (Source_Name.isEmpty ())
// Use any Requested_Pathname from a HiView_Application FileOpen event.
Source_Name = application.Requested_Pathname;
if (HiView_Application::is_jpip_passthru_link(Source_Name))
{
QString Requested_Link = HiView_Application::parse_jpip_passthru_link(Source_Name);
if (! Requested_Link.isEmpty() ) Source_Name = Requested_Link;
}
// Construct the main application window and display it.
HiView_Window
main_window (Source_Name, Scaling, Restore_Layout);
// Run the application event loop.
return application.exec ();
}