-
Notifications
You must be signed in to change notification settings - Fork 4
/
QUIKGRID.CPP
1963 lines (1702 loc) · 66.3 KB
/
QUIKGRID.CPP
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//**************************************************************
// Q U I K G R I D / S U R F A C E
// A program to visualize scattered data points as a
// contour map or gridded surface.
//
// Copyright (c) 1993 - 2005 by John Coulthard
//
// This file is part of QuikGrid.
//
// QuikGrid 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 2 of the License, or
// (at your option) any later version.
//
// QuikGrid 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 QuikGrid (File gpl.txt); if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// or visit their website at http://www.fsf.org/licensing/licenses/gpl.txt .
//
// Jul. 8/96: Renamed from SURFACE to QUIKGRID.
// Oct. 10/96: Reset grid to undefined in Generate Grid.
// (if sticks remove ZapZgrid() from many other modules).
// Oct. 17/96: Don't draw screen if window is an Icon.
// Feb. 24/97: Convert to Borland C++ v4.5
// : Add hooks to output 3D DXF FACE output.
// Call it version 3.4. (DXF upgrade).
// Mar. 4/97: Upgrade to Version 4 loaddata. Implement
// Version 4 read DXF data points. Tear out old
// Blair Allen code. Clean up DXFACE code some more.
// May 18/98: Accelerators not loading - fixed.
// Jun. 27/98: Changed load grid so not restricted.
// Jul. 19/98: Started version 3.5
// Doubled saveline.h memory to 128000 segments.
// Sep. 21/98: Converted over to Win32
// Sep. 23/98: Port over grid resoultion code & USGS DEM input.
// Sep. 25/98: Insert hooks for number of grid lines dialog box.
// Nov. 8/98: Insert code for Statistics dialog box.
// Prevent invocation of grid lines dialog boxes if no data points.
// Jan. 28/99: Implelent saving of the data points.
// Jan. 30/99: Implement Generating a grid on a zoomed view.
// Feb. 1/99: Implement Generate grid on original view.
// Feb. 4/99: Implement 3d scroll bars. Axes on the 3d view.
// Feb. 8/99: Deleted ShowCorners menu item.
// Added PleaseRegister dialog box.
// Remove restrictions from all but writing out grid, points
// and printing.
// Feb. 10/99: Restored ShowCorners (someone missed it!)
// Feb. 13/99: Implement Zoom and Pan options and preferences.
// Implement panning with arrows.
// Mar. 6/99: Implement code changes to display scattered data points
// when there is no grid generated.
// Mar. 7/99: Implementation begins on contour labels.
// Mar. 20/99:Install multitasking using multithreading.
// Mar. 29/99: Reset the new grid before starting grid re-generation.
// (to reset grid max and min's.
// Apr. 20/99: Changes to multithread data input.
// Apr. 21/99: More changes for multi tasked data input.
// May 14/99: Change so Grid Resolution works better for Zooming.
// May 16/99: Changes for USGS DEM input. Delete reading data dialog
// box for grid type input.
// May 29/99: Implement Grid cropping infrastructure.
// June 1-2/99: Code for functions menu and interface to it.
// Oct. 8/99: Implement command line version (handle arguments)
// Oct. 12/99: Default template code installed.
// Oct. 25/99: Hooks for handling display of wind speed & direction.
// Dec. 26/99: Code to load ER Mapper files
// Feb. 9/00: Hooks to implement command file processing.
// Feb. 25/00: Hooks to implement choosing color for features.
// Nov. 8/00: Add PaintContourReset after processing commmand file.
// PaintContourReset after IDM_NOCOLOR (black/white option).
// Dec. 4/00: Add bold outline flag.
// Feb. 6/01: To Windows 2000
// Feb. 13/01: Add EditViewOptions dialog box.
// Mar. 9/01: Inhibit croping and zoom grid gen when grid coord's locked.
// Enable (perhaps) croping etc. after processing command file.
// Apr. 1/01: Implement copy grid to colour grid.
// Sep. /01: Implement support for display of volume difference
// Oct. 26/01: Implement capture metafile and exit.
// Nov. 3-8/01: Implement drawing to a memory DC.
// & restore screen from memory.
// Nov. 9/01: Inhibit screen updating while processing commands.
// Force window to foreground if capturebitmap & exit
// (so window is not obscured).
// Jan 28/03: Move "Please Register Dialog Box" to later in the
// startup sequence (error ignored in Windows caused
// problems in WINE).
// Feb. 22/05: Remove "Register" code - more than this module involved.
//**************************************************************
#include <windows.h>
#include <HtmlHelp.h>
#include <stddef.h>
#include <process.h>
#include <iostream>
#include <commdlg.h>
#include <string.h>
#include <stdlib.h>
//#include <dir.h>
#include <dos.h>
#include "assert.h"
#include "surfgrid.h"
#include "scatdata.h"
#include "xygrid.h"
#include "xpand.h"
#include "quikgrid.h"
#include "paintcon.h"
#include "loaddata.h"
#include "grdwrite.h"
#include "dxfwrite.h"
#include "erwrite.h"
#include "utilitys.h"
#include "rc.h"
#include "dxfface.h"
#include "gridres.h"
#include "grid.h"
#include "rotate.h"
#include "datawrit.h"
#include "gridview.h"
#include "prefer.h"
#include "cmdfile.h"
#include "condraw.h"
#include "vrml.h"
// Function definitions that WinMain needs.
BOOL WINAPI AboutDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI NumberGridLinesDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI NewGridDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI GridgenDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI RotateDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ContoursDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI TechnicalDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI TitleDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ReadingDataDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI GridLocationDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI DataInputOptionsDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI DataOutputOptionsDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ZratioDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ZoomRatioDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI DataPointsDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI StatisticsDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ColorFeaturesDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI ColorMappingDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI RightMouseOptionsDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI GridLocnTerseDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
BOOL WINAPI EditViewDlgProc( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam);
long WINAPI WndProc( HWND, UINT, WPARAM, LPARAM) ;
static long CommandParam;
static char FileName[5000], OutputFileName[1000];
static int ReadingData = FALSE;
static bool ProcessingCommands = false;
extern int LockNormalization;
extern ScatData OutLine;
extern COLORREF BackgroundPen;
extern HPEN hBackgroundPen;
extern int RightMouseDialogTerse;
// global data definitions.
DLGPROC lpfnDataPointsDlgProc;
int RestoreScreenFromMemory = TRUE;
int AlwaysDrawDirectlyToScreen = FALSE;
int GridResAuto = FALSE ;
int CaptureBitmapAndExit = FALSE;
int CaptureMetaFileAndExit = FALSE;
int QuikGridChangedImage = TRUE;
bool CreatingAMetaFile = false;
bool UseThreads = TRUE;
float Turn = 35.,
Tilt = 35.,
Aspect = 0.,
Projection = 5.;
int Zooming = 0,
// PenHighLite = 5,
DoGenerateGrid = 0,
LatLonData = 0,
GridGeneratedOK = FALSE,
PictureDrawnOK = FALSE,
GridLock = FALSE,
ColouredGrid = FALSE,
BoldOutline = FALSE;
char szTitle[256];
ContourOptionsType
DrawingOptions = { 0, 0, 0, 0, 0, 0, 1, 0, 0 ,1 ,0, 0, 1, 0 },
OldOptions;
ScatData ScatterData;
SurfaceGrid Zgrid(2,2); // these are initial dimensions only.
//HINSTANCE hInst;
HACCEL hAccel;
HWND hGridgenDlgBox,
hReadingDataDlgBox,
hGridLocationDlgBox = NULL;
HWND WindProcHwnd;
UINT PaintState = IDM_2DSURFACE;
HDC hdc;
//************************************************************
// W i n M a i n
//************************************************************
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "QuikGrid";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
if( !hPrevInstance )
{
wndclass.cbSize = sizeof( wndclass );
wndclass.style = CS_VREDRAW | CS_HREDRAW ; // | CS_SAVEBITS
wndclass.lpfnWndProc = (WNDPROC)WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, "Surface" );
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = NULL;
RegisterClassEx (&wndclass) ;
}
hInst = hInstance;
void EnableHtmlHelp();
hwnd = CreateWindow(szAppName,
"QuikGrid", // Window Caption
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, // Window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow( hwnd, nCmdShow );
UpdateWindow(hwnd);
HtmlHelp((HWND)hwnd, "QUIKGRID.CHM::contents.htm", HH_DISPLAY_TOPIC, 0L);
HtmlHelp(
NULL,
NULL,
HH_CLOSE_ALL,
0);
hAccel = LoadAccelerators( hInstance, "QuikGrid" );
while( GetMessage( &msg, NULL, 0, 0 ) )
{
if( !TranslateAccelerator( hwnd, hAccel, &msg) )
{
TranslateMessage( &msg);
DispatchMessage( &msg);
}
}
return msg.wParam;
}
//****************************************************************
// T h r e a d G r i d G e n e r a t e
//****************************************************************
static void ThreadGridGenerate( PVOID pvoid )
{
while( DoGenerateGrid )
{
if( !XpandPoint( Zgrid, ScatterData ) ) break;
}
SendMessage( hGridgenDlgBox, WM_CLOSE, NULL, NULL);
}
//****************************************************************
// T h r e a d L o a d D a t a
//****************************************************************
static void ThreadLoadData( PVOID pvoid )
{
static int i, FileOK;
static HMENU hMenu;
// ReadingData = TRUE; // Probably redundant.
hMenu = GetMenu( WindProcHwnd );
for( i=0; i < 6; i++)
EnableMenuItem( hMenu, i, MF_GRAYED|MF_DISABLED|MF_BYPOSITION);
DrawMenuBar( WindProcHwnd );
switch( CommandParam )
{
case IDM_OPENMETRIC :
FileOK = LoadFileMetricData( WindProcHwnd, FileName );
break;
case IDM_OPENNOS :
FileOK = LoadFileNOSData( WindProcHwnd , FileName );
break;
case IDM_OPENNOAA :
FileOK = LoadFileNOAALatLonData( WindProcHwnd , FileName );
break;
case IDM_OPENLATLON :
FileOK = LoadFileLatLonData( WindProcHwnd , FileName );
break ;
case IDM_OPENDCA :
FileOK = LoadFileDCAData( WindProcHwnd , FileName );
break ;
case IDM_OPENDXF:
FileOK = LoadFileDXFData( WindProcHwnd , FileName );
break ;
case IDM_OPENSUBMETRIXSXP:
FileOK = LoadSubmetrixSXPData( WindProcHwnd , FileName );
break;
case IDM_OPENOUTLINE:
FileOK = LoadFileOutlineData( WindProcHwnd , FileName );
SendMessage( hReadingDataDlgBox, WM_CLOSE, NULL, NULL);
ReadingData = FALSE;
PictureChanged( WindProcHwnd );
return;
case IDM_OPENGRID:
FileOK = LoadGridData(WindProcHwnd, FileName );
SendMessage( hReadingDataDlgBox, WM_CLOSE, NULL, NULL);
ReadingData = FALSE;
if( !FileOK ) return;
if( PaintState == IDM_2DSURFACE)
{
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
}
Zooming = 0;
GridGeneratedOK = TRUE;
if( GridResAuto ) GridResOptimum( WindProcHwnd, hMenu );
else GridResMenus( WindProcHwnd, hMenu );
PictureChanged( WindProcHwnd );
return ;
case IDM_USGSDEM:
FileOK = LoadUSGSDEMData(WindProcHwnd, FileName );
SendMessage( hReadingDataDlgBox, WM_CLOSE, NULL, NULL);
ReadingData = FALSE;
Zooming = 0;
GridResOptimum( WindProcHwnd, hMenu );
CheckMenuItem( hMenu, IDM_GRIDRESAUTO, MF_CHECKED);
if( !FileOK ) return;
if( PaintState == IDM_2DSURFACE)
{
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
}
GridGeneratedOK = TRUE;
PictureChanged( WindProcHwnd );
return ;
case IDM_LOADERMAPPER:
FileOK = LoadERMapperGrid( WindProcHwnd, FileName );
SendMessage( hReadingDataDlgBox, WM_CLOSE, NULL, NULL);
ReadingData = FALSE;
Zooming = 0;
GridResOptimum( WindProcHwnd, hMenu );
CheckMenuItem( hMenu, IDM_GRIDRESAUTO, MF_CHECKED);
if( !FileOK ) return;
if( PaintState == IDM_2DSURFACE)
{
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
}
GridGeneratedOK = TRUE;
PictureChanged( WindProcHwnd );
return;
}
SendMessage( hReadingDataDlgBox, WM_CLOSE, NULL, NULL);
ReadingData = FALSE;
if( FileOK )
{
if( !GridLock ) GridGeneratedOK = FALSE;
PostMessage( WindProcHwnd, WM_COMMAND, IDM_REGENGRID, NULL );
PictureChanged( WindProcHwnd );
}
}
//******************************************************************
// L o a d D a t a
//******************************************************************
static void LoadData()
{
if( UseThreads) _beginthread( ThreadLoadData, 0, NULL );
else ThreadLoadData( NULL );
return;
}
//******************************************************************
// S e t M e m o r y D i s p l a y
//******************************************************************
static HBITMAP hbmScreen = 0;
static HDC hdcDisplay = 0;
static HDC hdcMemory = 0;
static HDC SetMemoryDisplay( HWND &hwnd )
//
// Select a memory mapped display compatible with the current
// display window. Only get new memory when window size changes.
//
{
static RECT rect;
static long OldRight = 0;
static long OldBottom = 0;
GetClientRect( hwnd, &rect); // Get size of screen.
if( (rect.right != OldRight) || (rect.bottom != OldBottom) )
{
if( hdcDisplay != 0 ) ReleaseDC( hwnd, hdcDisplay );
hdcDisplay = GetDC( hwnd ); // Selects display excluding title, etc.
if( hdcMemory != 0 ) DeleteDC( hdcMemory );
hdcMemory = CreateCompatibleDC(hdcDisplay);
DeleteObject( hbmScreen );
hbmScreen = CreateCompatibleBitmap(hdcDisplay, rect.right, rect.bottom);
if (hbmScreen == 0) NotifyUser( "QuikGrid failure: Unable to obtain display memory.");
if (!SelectObject(hdcMemory, hbmScreen)) NotifyUser( "QuikGrid failure: Unable to select display memory.");
OldRight = rect.right;
OldBottom = rect.bottom;
}
return hdcMemory;
}
//*****************************************************************
// C o p y M e m o r y T o D i s p l a y
//*****************************************************************
extern RECT ClientRect, ClipRect; // Setup up in logical units in PAINTCON
static void CopyMemoryToDisplay()
{
// Note: BitBlt works in "logical" units.
SetMapMode( hdcDisplay, MM_ISOTROPIC ); // Set up the display
SetCurrentWinView( hdcDisplay );
SetMapMode( hdcMemory, MM_ISOTROPIC ); // Set up memory map.
SetCurrentWinView( hdcMemory );
if (!BitBlt(hdcDisplay,
ClientRect.left, ClientRect.bottom, // Destination lower left corner.
ClientRect.right-ClientRect.left, ClientRect.top-ClientRect.bottom, // Width, Height
hdcMemory,
ClientRect.left, ClientRect.bottom, // Source lower left corner.
SRCCOPY)) NotifyUser("QuikGrid failure: Copy memory to screen failed");
ValidateRect(WindProcHwnd, NULL);
}
//*****************************************************************
// C o p y D i s p l a y T o M e m o r y
//*****************************************************************
static void CopyDisplayToMemory()
{
// Note: BitBlt works in "logical" units.
SetMapMode( hdcDisplay, MM_ISOTROPIC ); // Set up the display
SetCurrentWinView( hdcDisplay );
SetMapMode( hdcMemory, MM_ISOTROPIC ); // Set up memory map.
SetCurrentWinView( hdcMemory );
if (!BitBlt(hdcMemory,
ClientRect.left, ClientRect.bottom, // Destination lower left corner.
ClientRect.right-ClientRect.left, ClientRect.top-ClientRect.bottom, // Width, Height
hdcDisplay,
ClientRect.left, ClientRect.bottom, // Source lower left corner.
SRCCOPY)) NotifyUser("QuikGrid failure: Copy display to memory failed");
}
//******************************************************************
// W N D P R O C
//******************************************************************
long FAR PASCAL WndProc( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
static PAINTSTRUCT ps;
static RECT rect, cliprect;
static long OldRight = 0;
static long OldBottom = 0;
static HANDLE hInstance;
static HMENU hMenu ;
static DLGPROC
lpfnAboutDlgProc,
lpfnGridgenDlgProc,
lpfnNumberGridLinesDlgProc,
lpfnNewGridDlgProc,
lpfnRotateDlgProc,
lpfnContoursDlgProc,
lpfnTechnicalDlgProc,
lpfnTitleDlgProc,
lpfnReadingDataDlgProc,
lpfnGridLocationDlgProc,
lpfnDataInputOptionsDlgProc,
lpfnDataOutputOptionsDlgProc,
lpfnZratioDlgProc,
lpfnZoomRatioDlgProc,
lpfnStatisticsDlgProc,
lpfnColorFeaturesDlgProc,
lpfnColorMappingDlgProc,
lpfnRightMouseOptionsDlgProc,
lpfnGridLocnTerseDlgProc,
lpfnEditViewDlgProc;
static int i,
ZoomFactor = 2,
ZoomLevel = 1,
AutoGridGen = 1,
MouseResolution = 20; // Throw away first 20 mouse moves.
static POINT ZoomCentre, MouseLocation;
static long Oldix = -1, Oldiy = -1;
WindProcHwnd = hwnd;
// ****** MAIN SWITCH ****************
switch (message)
{
case WM_CREATE :
hInstance = (( LPCREATESTRUCT) lParam) -> hInstance ;
lpfnAboutDlgProc = (DLGPROC) AboutDlgProc;
lpfnGridgenDlgProc = (DLGPROC) GridgenDlgProc;
lpfnNumberGridLinesDlgProc = (DLGPROC) NumberGridLinesDlgProc;
lpfnNewGridDlgProc = (DLGPROC) NewGridDlgProc;
lpfnRotateDlgProc = (DLGPROC) RotateDlgProc;
lpfnContoursDlgProc = (DLGPROC) ContoursDlgProc;
lpfnTechnicalDlgProc = (DLGPROC) TechnicalDlgProc;
lpfnTitleDlgProc = (DLGPROC) TitleDlgProc;
lpfnReadingDataDlgProc = (DLGPROC) ReadingDataDlgProc;
lpfnGridLocationDlgProc = (DLGPROC) GridLocationDlgProc;
lpfnDataInputOptionsDlgProc = (DLGPROC) DataInputOptionsDlgProc;
lpfnDataOutputOptionsDlgProc = (DLGPROC) DataOutputOptionsDlgProc;
lpfnZratioDlgProc = (DLGPROC) ZratioDlgProc;
lpfnZoomRatioDlgProc = (DLGPROC) ZoomRatioDlgProc;
lpfnDataPointsDlgProc = (DLGPROC) DataPointsDlgProc,
lpfnStatisticsDlgProc = (DLGPROC) StatisticsDlgProc;
lpfnColorFeaturesDlgProc = (DLGPROC) ColorFeaturesDlgProc;
lpfnColorMappingDlgProc = (DLGPROC) ColorMappingDlgProc;
lpfnRightMouseOptionsDlgProc = (DLGPROC) RightMouseOptionsDlgProc;
lpfnGridLocnTerseDlgProc = (DLGPROC) GridLocnTerseDlgProc;
lpfnEditViewDlgProc = (DLGPROC) EditViewDlgProc;
ShowScrollBar( hwnd, SB_BOTH, FALSE);
SetStartupState( hwnd );
// set menu defaults correctly (undone in 5.2?)
hMenu = GetMenu( hwnd );
GridResMenus( hwnd, hMenu );
LoadPreferences( hMenu);
CreatePens( );
RotateInitialize( Turn, Tilt, Aspect );
if( PaintState == IDM_3DSURFACE )
{
ShowScrollBar( hwnd, SB_BOTH, TRUE);
SetScrollRange( hwnd, SB_VERT, 0, 90, TRUE);
SetScrollRange( hwnd, SB_HORZ, 0, 360, TRUE);
SetScrollPos( hwnd, SB_VERT, 90-Tilt, TRUE );
SetScrollPos( hwnd, SB_HORZ, Turn+180, TRUE );
}
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_GRAYED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_GRAYED);
DrawMenuBar( hwnd );
PostMessage( hwnd, WM_COMMAND, IDM_STARTUP, NULL);
return 0;
//*********** COMMAND SWITCH ************************
case WM_COMMAND:
hMenu = GetMenu( hwnd );
switch ( LOWORD(wParam) )
{
case IDM_STARTUP:
{
if( __argc < 2 ) return 0; // there are no command line arguments.
strcpy( FileName, __argv[1] );
int LengthName = strlen(FileName);
FileName[LengthName+1] = NULL; // Place second null on file name.
for( i = LengthName-1; i > 0; i--)
if( FileName[i] == '.' ) break;
// Test for command file first.
if( strnicmp( &FileName[i], ".CMD", 4 ) == 0 ||
strnicmp( &FileName[i], ".QCF", 4 ) == 0 )
{
ProcessingCommands = true;
InputCommandFile( hwnd , FileName, hMenu );
if( PaintState == IDM_2DSURFACE)
{
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
}
Zooming = 0;
PictureChanged( hwnd );
PaintContourReset();
ProcessingCommands = false;
return 0;
}
// Iff not a command file we do data input.
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
( (HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = IDM_OPENMETRIC;
if( strnicmp( &FileName[i], ".NOS",4 ) == 0 ) CommandParam = IDM_OPENNOS;
if( strnicmp( &FileName[i], ".LST",4 ) == 0 ||
strnicmp( &FileName[i], ".NGS",4 ) == 0 ||
strnicmp( &FileName[i], ".NOA",4 ) == 0 ) CommandParam = IDM_OPENNOAA;
if( strnicmp( &FileName[i], ".LL", 3 ) == 0 ) CommandParam = IDM_OPENLATLON;
if( strnicmp( &FileName[i], ".SXP", 3 ) == 0 ) CommandParam = IDM_OPENSUBMETRIXSXP;
if( strnicmp( &FileName[i], ".DXF",4 ) == 0 ||
strnicmp( &FileName[i], ".3DF",4 ) == 0 ) CommandParam = IDM_OPENDXF;
if( strnicmp( &FileName[i], ".DCA",4 ) == 0 ) CommandParam = IDM_OPENDCA;
if( strnicmp( &FileName[i], ".DEM",4 ) == 0 )
{ CommandParam = IDM_USGSDEM;
GridGeneratedOK = FALSE;
GridResAuto = TRUE; }
if( strnicmp( &FileName[i], ".QG", 3 ) == 0 )
{ CommandParam = IDM_OPENGRID;
GridGeneratedOK = FALSE; }
if( strnicmp( &FileName[i], ".ERS", 4 ) == 0 )
{ CommandParam = IDM_LOADERMAPPER;
GridGeneratedOK = FALSE; }
if( strnicmp( &FileName[i], ".OUT",4 ) == 0 ) CommandParam = IDM_OPENOUTLINE;
_beginthread( ThreadLoadData, 0, NULL );
return 0;
}
case IDM_WRITEFILEQUIT:
// DIALOGBX sets this up after a grid has been generated *and*
// if there are two arguments on the command line
if( !GridGeneratedOK)
NotifyUser( "QuikGrid failure: No grid available to write out");
strcpy( OutputFileName, __argv[2] );
for( i = strlen(OutputFileName)-1; i > 0; i--)
if( OutputFileName[i] == '.' ) break ;
if( strnicmp( &OutputFileName[i], ".QG", 3 ) == 0 )
SaveGridData( OutputFileName ) ;
else if( strnicmp( &OutputFileName[i], ".ERS", 4 ) == 0 )
OutputERMapperFile( hwnd, OutputFileName ) ;
else if( strnicmp( &OutputFileName[i], ".3DF", 4 ) == 0 )
OutputDXF3DFaceFile( hwnd, OutputFileName ) ;
else if( strnicmp( &OutputFileName[i], ".WRL", 4 ) == 0 )
OutputVRMLFile( OutputFileName ) ;
else if( strnicmp( &OutputFileName[i], ".GRD", 4 ) == 0 )
OutputGRDfile( OutputFileName ) ;
else if( strnicmp( &OutputFileName[i], ".DXF", 4 ) == 0 )
OutputDXFfile( DrawingOptions, PaintState, OutputFileName ) ;
else OutputXYZfile( OutputFileName );
PostMessage( hwnd, WM_DESTROY, NULL, NULL );
return 0;
//****************** FILE MENU COMMANDS **********************
case IDM_INPUTCOMMANDFILE:
if( !GetReadFile( FileName, hwnd, "Open command file" ) ) return 0;
ProcessingCommands = true;
InputCommandFile( hwnd , FileName, hMenu );
if( PaintState == IDM_2DSURFACE)
{
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
}
Zooming = 0;
PictureChanged( hwnd );
PaintContourReset();
ProcessingCommands = false;
return 0;
case IDM_LOADTESTDATA:
Zooming = 0;
LoadTestData( hwnd );
strcpy( FileName, "Internal test data" );
if( !GridLock ) GridGeneratedOK = FALSE;
CheckMenuItem( hMenu, IDM_LATLON, MF_UNCHECKED);
PictureChanged( hwnd );
PostMessage( hwnd, WM_COMMAND, IDM_REGENGRID, NULL );
return 0;
case IDM_OPENMETRIC :
if( !GetReadFileMultiple( FileName, hwnd, "Open metric XYZ data file",
"All files\0*.*\0\0" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE) hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
LoadData();
//_beginthread( ThreadLoadData, 0, NULL );
return 0;
case IDM_OPENNOS :
// if( !GetReadFile( FileName, hwnd, "Open NOS Lat/Lon data file" ) ) return 0;
if( !GetReadFileMultiple( FileName, hwnd, "Open NOS data file",
"All files\0*.*\0\0" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENNOAA :
if( !GetReadFileMultiple( FileName, hwnd, "Open NOAA Lat/Lon data file",
"All files\0*.*\0\0" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENLATLON :
//if( !GetReadFile( FileName, hwnd, "Open Lat/Lon data file" ) ) return 0;
if( !GetReadFileMultiple( FileName, hwnd, "Open Lat/Lon data file",
"All files\0*.*\0\0" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENOUTLINE:
if( !GetReadFileMultiple( FileName, hwnd, "Open outline data file",
"All files\0*.*\0\0" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_CLEAROUTLINE:
OutLine.Reset();
LockNormalization = FALSE;
PictureChanged( WindProcHwnd );
return 0;
case IDM_OPENDCA :
if( !GetReadFile( FileName, hwnd, "Open DCA data file") ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENDXF:
if( !GetReadFile( FileName, hwnd, "Open DXF data file") ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENSUBMETRIXSXP:
if( !GetReadFileMultiple( FileName, hwnd, "Open Submetrix .sxp data file",
"SXP files\0*.sxp\0All files\0*.*\0\0") ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_USGSDEM:
if( GridLock )
{ //NotifyUser( "Current grid is locked as template - request ignored.");
NotifyUser( IDS_GRIDLOCKEDTEMPLATE );
return 0; }
if( !GetReadFile( FileName, hwnd, "Open USGS DEM data file" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
GridGeneratedOK = FALSE;
GridResAuto = TRUE;
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_OPENGRID:
if( !GetReadFile( FileName, hwnd, "Open QuikGrid grid data file" ) ) return 0;
ReadingData = TRUE;
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
GridGeneratedOK = FALSE;
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
case IDM_LOADERMAPPER:
{
if( GridLock )
{ //NotifyUser( "Current grid is locked as template - request ignored.");
NotifyUser( IDS_GRIDLOCKEDTEMPLATE );
return 0; }
if( !GetReadFile( FileName, hwnd, "Open ER Mapper raster file .ers" ) ) return 0;
ReadingData = TRUE;
hMenu = GetMenu( WindProcHwnd );
for( i=0; i < 6; i++)
EnableMenuItem( hMenu, i, MF_GRAYED|MF_DISABLED|MF_BYPOSITION);
DrawMenuBar( WindProcHwnd );
hReadingDataDlgBox = CreateDialog
((HINSTANCE)hInstance, "ReadingData", hwnd, lpfnReadingDataDlgProc);
GridGeneratedOK = FALSE;
CommandParam = LOWORD( wParam );
//_beginthread( ThreadLoadData, 0, NULL );
LoadData();
return 0;
}
case IDM_SAVE: // Save in QuikGrid format.
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetSaveFile( OutputFileName, hwnd, "Save grid data in QuikGrid format to file" ) )
return 0;
SaveGridData( OutputFileName );
return 0;
case IDM_DXF3DFACE:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetDXF3DFaceFileName( hwnd, OutputFileName ) ) return 0;
OutputDXF3DFaceFile( hwnd, OutputFileName ) ;
return 0;
case IDM_OUTPUTDXF:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetDXFfilename( hwnd, OutputFileName ) ) return 0;
OutputDXFfile( DrawingOptions, PaintState, OutputFileName ) ;
return 0;
case IDM_OUTPUTWRL:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetVRMLFileName( hwnd, OutputFileName ) ) return 0;
OutputVRMLFile( OutputFileName ) ;
return 0;
case IDM_SAVEXYZ:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetSaveFile( OutputFileName, hwnd, "Save grid in XYZ format to file" ) )
return 0;
OutputXYZfile( OutputFileName ) ;
return 0;
case IDM_SAVEGRD:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetSaveFile( OutputFileName, hwnd, "Save grid in GRD format to file",
"GRD files\0*.grd\0All files\0*.*\0\0", "grd" ) )
return 0;
OutputGRDfile( OutputFileName ) ;
return 0;
// case IDM_SAVEMAPINFO:
// if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
// if( !GetSaveFile( OutputFileName, hwnd, "Save grid in Mapinfo Vertical Mapper format to file",
// "txt files\0*.txt\0All files\0*.*\0\0", "txt" ) )
// return 0;
// OutputMapinfoFile( OutputFileName ) ;
// return 0;
case IDM_SAVEDATAPOINTS:
if( ScatterData.Size() > 2 )OutputDataPointFile( hwnd ) ;
else NotifyUser( " Cannot write out file. There are no data points. ");
return 0;
case IDM_ERMAPPER:
if( !GridGeneratedOK ) {NotifyUser( IDS_GRIDNOTGENERATED ); return 0; }
if( !GetERMapperFileName( hwnd, OutputFileName ) ) return 0;
OutputERMapperFile( hwnd, OutputFileName );
return 0;
case IDM_PRINT:
{
if( DoGenerateGrid || !PictureDrawnOK || (Zgrid.xsize()<3) )
{NotifyUser(" There is no display to print???"); return 0; }
CreatingAMetaFile = false;
static PRINTDLG pd;
static DOCINFO di = { sizeof(DOCINFO), "QuikGrid: Printing", NULL };
memset( &pd, 0, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd;
pd.Flags = PD_RETURNDC|PD_HIDEPRINTTOFILE|PD_NOSELECTION;
if( !PrintDlg(&pd) ) return 0;
StartDoc( pd.hDC, &di );
StartPage( pd.hDC );
SetWaitCursor();
rect.right = GetDeviceCaps( pd.hDC, HORZRES );
rect.bottom = GetDeviceCaps( pd.hDC, VERTRES );
rect.top = 0;
rect.left = 0;
HRGN hRgn = CreateRectRgnIndirect( &rect );
cliprect = rect;
SelectClipRgn( pd.hDC, hRgn );
hdc = pd.hDC;
switch ( PaintState )
{
case IDM_2DSURFACE:
Scale2dRectangle();
CentreDisplay( pd.hDC, rect, cliprect, Zooming);
Paint2dSurface( pd.hDC, DrawingOptions);
break;
case IDM_3DSURFACE:
Scale3dCube();
CentreDisplay( pd.hDC, rect, cliprect, Zooming);
Paint3dSurface( pd.hDC, DrawingOptions );
break;
} // end switch ( PaintState...
DeleteObject( hRgn );
RestoreCursor();
EndPage( pd.hDC );
EndDoc( pd.hDC);
DeleteDC( pd.hDC );
if( pd.hDevMode != NULL ) GlobalFree(pd.hDevMode);
if( pd.hDevNames!= NULL ) GlobalFree(pd.hDevNames);
return 0;
}
case IDM_EXIT:
PostMessage( hwnd, WM_DESTROY, NULL, NULL );
return 0;
//***************** VIEW COMMANDS ****************************
case IDM_2DSURFACE :
if( PaintState == IDM_2DSURFACE) return 0;
Zooming = 0;
CheckMenuItem( hMenu, PaintState, MF_UNCHECKED);
PaintState = IDM_2DSURFACE;
CheckMenuItem( hMenu, PaintState, MF_CHECKED);
EnableMenuItem( hMenu, IDM_GENGRIDZOOM, MF_ENABLED);
EnableMenuItem( hMenu, IDM_CROP2DVIEW, MF_ENABLED);
DrawMenuBar( hwnd );
PictureChanged( hwnd);
ShowScrollBar( hwnd, SB_BOTH, FALSE);