-
Notifications
You must be signed in to change notification settings - Fork 2
/
fg_edit_line.m
1502 lines (1156 loc) · 61.2 KB
/
fg_edit_line.m
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
function varargout = fg_edit_line(varargin)
% FG_EDIT_LINE MATLAB code for fg_edit_line.fig
% FG_EDIT_LINE, by itself, creates a new FG_EDIT_LINE or raises the existing
% singleton*.
%
% H = FG_EDIT_LINE returns the handle to a new FG_EDIT_LINE or the handle to
% the existing singleton*.
%
% FG_EDIT_LINE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FG_EDIT_LINE.M with the given input arguments.
%
% FG_EDIT_LINE('Property','Value',...) creates a new FG_EDIT_LINE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fg_edit_line_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fg_edit_line_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help fg_edit_line
% Last Modified by GUIDE v2.5 14-Sep-2024 13:36:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fg_edit_line_OpeningFcn, ...
'gui_OutputFcn', @fg_edit_line_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before fg_edit_line is made visible.
function fg_edit_line_OpeningFcn(hObject, eventdata, handles, varargin)
% Center the figure on the screen
movegui(hObject, 'center');
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to fg_edit_line (see VARARGIN)
% Choose default command line output for fg_edit_line
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes fg_edit_line wait for user response (see UIRESUME)
% uiwait(handles.fg_edit_line);
% load the project
h = findobj('Tag','fg_main');
vars = guidata(h);
project = CssProject(vars.working_folder);
database = project.LoadDatabase();
lines = project.LoadLines();
instruments = project.LoadInstruments();
if ~isempty(instruments)
set(handles.dropInstruments,'string',sort({instruments.name}));
end
% save the database to the local handle
hObj = guidata(hObject);
hObj.database = database;
hObj.working_folder = vars.working_folder;
hObj.project = project;
hObj.lines = lines;
hObj.instruments = instruments;
hObj.selected_line = 0;
hObj.selected_instrument = 0;
hObj.selected_direction = 0;
hObj.selected_row = 0;
% create an empty gravity line and have it ready to start
% editing/adding observations
hObj.new_line = CssGravityLine();
hObj = Update_hObj_Sync(hObj, hObj.new_line, handles);
guidata(hObject, hObj);
set(handles.dropDirections,'String', str([CssDirections.forward; CssDirections.reverse]))
set(handles.tblObs,'Data', [])
% --- Outputs from this function are returned to the command line.
function varargout = fg_edit_line_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on selection change in dropInstruments.
function dropInstruments_Callback(hObject, eventdata, handles)
% hObject handle to dropInstruments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns dropInstruments contents as cell array
% contents{get(hObject,'Value')} returns selected item from dropInstruments
% when click, show the information for the current line and gravimeter
hObj = guidata(hObject);
selection = get(handles.dropInstruments,{'string','value'});
hObj.selected_instrument = selection{2};
% reset the selection
set(handles.dropDirections,'value', [])
set(handles.tblObs,'Data', [])
hObj.selected_direction = 0;
hObj.selected_row = 0;
line = GetLine(hObj);
hObj = Update_hObj_Sync(hObj, line, handles);
guidata(hObject, hObj);
function plot_line_info(hObj, handles)
if hObj.selected_instrument ~=0
instrument = hObj.instruments(hObj.selected_instrument);
line = GetLine(hObj);
if get(handles.optDeltas, 'Value') ~= 0
if ~isnan(line.GetDeltasResiduals(instrument.name))
axes(handles.axPlot)
cla('reset')
if line.GetDeltasResiduals(instrument.name)
% there are deltas and residuals, plot
plot(line, instrument.name)
set(handles.lblError,'Visible','off')
else
axes(handles.axPlot)
set(handles.lblError,'Visible','on')
end
else
axes(handles.axPlot)
cla('reset')
set(handles.lblError,'Visible','on')
end
else
axes(handles.axPlot)
set(handles.lblError,'Visible','off')
if get(handles.optRaw, 'Value') ~= 0
plotRaw(line, instrument.name)
else
if handles.chkBothDirs.Value
plotLineTime(line, instrument.name)
else
if hObj.selected_direction ~= 0
plotLineTime(line, instrument.name, CssDirections.ToDirection(hObj.selected_direction - 1))
else
plotLineTime(line, instrument.name)
end
end
end
end
else
axes(handles.axPlot)
cla('reset')
set(handles.lblError,'Visible','on')
end
% --- Executes during object creation, after setting all properties.
function dropInstruments_CreateFcn(hObject, eventdata, handles)
% hObject handle to dropInstruments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in dropDirections.
function dropDirections_Callback(hObject, eventdata, handles)
% hObject handle to dropDirections (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns dropDirections contents as cell array
% contents{get(hObject,'Value')} returns selected item from dropDirections
hObj = guidata(hObject);
if hObj.selected_instrument ~= 0
selection = get(handles.dropDirections,{'String','Value'});
hObj.selected_direction = selection{2};
line = GetLine(hObj);
hObj = Update_hObj_Sync(hObj, line, handles);
guidata(hObject, hObj);
end
% --- Executes during object creation, after setting all properties.
function dropDirections_CreateFcn(hObject, eventdata, handles)
% hObject handle to dropDirections (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in cmdSave.
function cmdSave_Callback(hObject, eventdata, handles)
% hObject handle to cmdSave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
line = GetLine(hObj);
% save the line, and then create a new one
if hObj.selected_line ~= 0
% allow overwrite if editing a line
line.SaveGravityLine(fullfile(hObj.working_folder,'lines'), true);
else
% disallow overwrite if editing a line
line.SaveGravityLine(fullfile(hObj.working_folder,'lines'), false);
end
guidata(hObject, hObj);
function [hObj, line, cancel] = SaveLine(hObj, line, handles)
cancel = false;
if hObj.selected_line == 0
if ~isempty(line.line_name)
% requesting a new line, ask if user wants to save the current working
% line
response = questdlg('Do you want to save the current new line? If you answer No, all changes to the current new line will be lost!','Save changes?','Yes','No','Cancel','Cancel');
if strcmp(response,'No')
% create a new line, don't save changes
line = CssGravityLine();
elseif strcmp(response,'Yes')
% save the line, and then create a new one
if hObj.selected_line ~= 0
% allow overwrite if editing a line
line.SaveGravityLine(fullfile(hObj.working_folder,'lines'), true);
else
% disallow overwrite if editing a line
line.SaveGravityLine(fullfile(hObj.working_folder,'lines'), false);
end
line = CssGravityLine();
elseif strcmp(response,'Cancel')
cancel = true;
end
end
else
h = msgbox('The changes performed to the current line were not saved to disk. These changes are stored in memory until you save them or discard them (by closing the edit line window).');
waitfor(h)
line = CssGravityLine();
end
if cancel == false
hObj.selected_line = 0;
hObj.selected_instrument = 0;
hObj.selected_direction = 0;
hObj.selected_row = 0;
UpdateCombos(hObj, line, handles);
set(handles.txtLat, 'string', '')
set(handles.txtLon, 'string', '')
set(handles.txtHeight, 'string', '')
set(handles.txtX, 'string', '')
set(handles.txtY, 'string', '')
set(handles.txtZ, 'string', '')
set(handles.txtComments, 'string', '')
end
% if user cancels, then nothing happens...
hObj = Update_hObj_Sync(hObj, line, handles);
% --- Executes on button press in cmdNew.
function cmdNew_Callback(hObject, eventdata, handles)
% hObject handle to cmdNew (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
line = GetLine(hObj);
[hObj, ~] = SaveLine(hObj, line, handles);
guidata(hObject,hObj);
% --- Executes on button press in cmdOpenLine.
function cmdOpenLine_Callback(hObject, eventdata, handles)
% hObject handle to cmdOpenLine (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% list the lines available:
hObj = guidata(hObject);
line = GetLine(hObj);
[hObj, ~, cancel] = SaveLine(hObj, line, handles);
if ~cancel
[line, sel] = listdlg('PromptString', 'Select a line', 'SelectionMode','single','ListString',{hObj.lines.line_filename});
if sel
hObj.selected_line = line;
handles.lblTitle.String = ['Gravity Line - modifying: ' hObj.lines(line).line_name];
hObj.selected_instrument = 0;
hObj.selected_direction = 0;
hObj.selected_row = 0;
line = GetLine(hObj);
hObj = Update_hObj_Sync(hObj, line, handles);
set(handles.txtComments,'string', line.comments)
set(handles.txtLat, 'string', '')
set(handles.txtLon, 'string', '')
set(handles.txtHeight, 'string', '')
set(handles.txtX, 'string', '')
set(handles.txtY, 'string', '')
set(handles.txtZ, 'string', '')
set(handles.BenchmarkPanel, 'title', 'Benchmark Metadata')
guidata(hObject, hObj);
end
end
function UpdateCombos(hObj, line, handles)
for i = 1:length(hObj.instruments)
if ismember(hObj.instruments(i).name, line.instruments)
instruments(i) = {sprintf('<HTML><strong><FONT color="%s">%s', 'blue', hObj.instruments(i).name)};
else
instruments(i) = {hObj.instruments(i).name};
end
end
if ismember(CssDirections.forward, line.directions)
directions(1) = {sprintf('<HTML><strong><FONT color="%s">%s', 'blue', char(str(CssDirections.forward)))};
else
directions(1) = str(CssDirections.forward);
end
if ismember(CssDirections.reverse, line.directions)
directions(2) = {sprintf('<HTML><strong><FONT color="%s">%s', 'blue', char(str(CssDirections.reverse)))};
else
directions(2) = str(CssDirections.reverse);
end
% show deltas
if ~hObj.selected_instrument == 0
deltas = line.GetDeltaName(hObj.instruments(hObj.selected_instrument).name, 0);
set(handles.lstDeltas, 'String', deltas)
set(handles.lstDeltas, 'Value', [])
else
set(handles.lstDeltas, 'String', {})
set(handles.lstDeltas, 'Value', [])
end
% reset controls section
set(handles.dropInstruments,'String', instruments)
set(handles.dropDirections, 'String', directions)
if ~hObj.selected_instrument == 0
set(handles.dropInstruments,'Value', hObj.selected_instrument)
else
set(handles.dropInstruments,'Value', [])
end
if ~hObj.selected_direction == 0
set(handles.dropDirections,'Value', hObj.selected_direction)
else
set(handles.dropDirections,'Value', [])
end
function txtLat_Callback(hObject, eventdata, handles)
% hObject handle to txtLat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txtLat as text
% str2double(get(hObject,'String')) returns contents of txtLat as a double
% --- Executes during object creation, after setting all properties.
function txtLat_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtLat (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtLon_Callback(hObject, eventdata, handles)
% hObject handle to txtLon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txtLon as text
% str2double(get(hObject,'String')) returns contents of txtLon as a double
% --- Executes during object creation, after setting all properties.
function txtLon_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtLon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtHeight_Callback(hObject, eventdata, handles)
% hObject handle to lblHeight (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblHeight as text
% str2double(get(hObject,'String')) returns contents of lblHeight as a double
% --- Executes during object creation, after setting all properties.
function txtHeight_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtHeight (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function lblHeight_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblHeight (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtRINEXPath_Callback(hObject, eventdata, handles)
% hObject handle to txtRINEXPath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txtRINEXPath as text
% str2double(get(hObject,'String')) returns contents of txtRINEXPath as a double
% --- Executes during object creation, after setting all properties.
function txtRINEXPath_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtRINEXPath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtX_Callback(hObject, eventdata, handles)
% hObject handle to lblX (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblX as text
% str2double(get(hObject,'String')) returns contents of lblX as a double
% --- Executes during object creation, after setting all properties.
function txtX_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtX (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function lblX_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblX (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtY_Callback(hObject, eventdata, handles)
% hObject handle to lblY (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblY as text
% str2double(get(hObject,'String')) returns contents of lblY as a double
% --- Executes during object creation, after setting all properties.
function txtY_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtY (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function lblY_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblY (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtZ_Callback(hObject, eventdata, handles)
% hObject handle to lblZ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of lblZ as text
% str2double(get(hObject,'String')) returns contents of lblZ as a double
% --- Executes during object creation, after setting all properties.
function txtZ_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtZ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function lblZ_CreateFcn(hObject, eventdata, handles)
% hObject handle to lblZ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in cmdLLA2XYZ.
function cmdLLA2XYZ_Callback(hObject, eventdata, handles)
% hObject handle to cmdLLA2XYZ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in cmdXYZ2LLA.
function cmdXYZ2LLA_Callback(hObject, eventdata, handles)
% hObject handle to cmdXYZ2LLA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in cmdOpenRINEX.
function cmdOpenRINEX_Callback(hObject, eventdata, handles)
% hObject handle to cmdOpenRINEX (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in cmdComputeCoord.
function cmdComputeCoord_Callback(hObject, eventdata, handles)
% hObject handle to cmdComputeCoord (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function txtComments_Callback(hObject, eventdata, handles)
% hObject handle to txtComments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of txtComments as text
% str2double(get(hObject,'String')) returns contents of txtComments as a double
% save the comments to the structure
hObj = guidata(hObject);
line = GetLine(hObj);
line.comments = handles.txtComments.String;
hObj = Update_hObj_Sync(hObj, line, handles);
guidata(hObject,hObj);
% --- Executes during object creation, after setting all properties.
function txtComments_CreateFcn(hObject, eventdata, handles)
% hObject handle to txtComments (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in cmdDelete.
function cmdDelete_Callback(hObject, eventdata, handles)
% hObject handle to cmdDelete (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
if hObj.selected_row ~= 0
if strcmp(questdlg('Are you sure you want to delete this observation?'),'Yes')
line = GetLine(hObj);
line = line.DeleteObservation(hObj.observations(hObj.selected_row));
hObj = Update_hObj_Sync(hObj, line, handles);
guidata(hObject, hObj);
end
end
% --- Executes when selected cell(s) is changed in tblObs.
function tblObs_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to tblObs (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
index = eventdata.Indices;
if ~isempty(index)
row = index(1);
col = index(2);
hObj.selected_row = row;
else
row = [];
col = [];
hObj.selected_row = 0;
end
modifier = handles.fg_edit_line.CurrentModifier;
if isempty(modifier)
modifier = '';
end
if strcmp(modifier,'control')
if and(hObj.selected_instrument ~= 0, hObj.selected_direction ~= 0)
instrument = hObj.instruments(hObj.selected_instrument);
line = GetLine(hObj);
if ~isempty(row)
% perform other operations
switch col
case 1
% benchmark
if strcmp(questdlg('You are about to modify the benchmark. This operation will replace this benchmark from ALL observations (and all instruments). Do you want to continue?'),'Yes')
% bring up the find_benchmark dialog
if row > 1
lat = hObj.observations(row-1).benchmark.lat;
lon = hObj.observations(row-1).benchmark.lon;
elseif and(length(hObj.observations) == 1, row == 1)
lat = hObj.observations(row).benchmark.lat;
lon = hObj.observations(row).benchmark.lon;
elseif and(length(hObj.observations) > 1, row == 1)
lat = hObj.observations(row+1).benchmark.lat;
lon = hObj.observations(row+1).benchmark.lon;
else
lat = 0;
lon = 0;
end
[~,benchmark] = fg_find_benchmark(lat, lon);
if ~isempty(benchmark)
if and(CssBenchmark.exists(line.benchmarks, benchmark.name), length(line.directions) > 1)
h = warndlg('You are trying to replace a benchmark with a benchmark that is already a member of this line. This could lead to inconsistencies during delta estimation in lines with forward and reverse directions. The change will not be performed. If you want to edit the coordinate of an existing benchmark go to Lines -> Benchmarks -> Add/Edit/Remove benchmarks.');
waitfor(h);
else
if ~isempty(benchmark)
line = line.UpdateBenchmark(hObj.observations(row).benchmark, benchmark, hObj.instruments);
end
end
end
end
case 2
% time stamp
d = datenum(handles.tblObs.Data{row,col},'yyyy-mm-dd HH:MM');
newdate = uigetdate(d);
if newdate
% find the observation and replace the timestamp
% this will trigger an update of all the affected
% variables
newdate = datetime(newdate,'ConvertFrom','datenum');
% in this section of the code it seems weird to
% manipulate hObj.observations(), since it looks
% like a different variable. However, this is a
% pointer to the observations in
% hObj.lines(selected_line) or hObj.new_line
line = line.UpdateObservation(hObj.observations(row), 'timestamp', newdate, instrument.calibration);
end
end
% save the line back to the corresponding variable
hObj = Update_hObj_Sync(hObj, line, handles);
end
end
else
if ~isempty(row)
% when click in an existing cell, get the information of the benchmark
set(handles.txtLat, 'string', sprintf('%.8f',hObj.observations(row).benchmark.lat))
set(handles.txtLon, 'string', sprintf('%.8f',hObj.observations(row).benchmark.lon))
set(handles.txtHeight, 'string', sprintf('%.3f',hObj.observations(row).benchmark.height))
set(handles.txtX, 'string', sprintf('%.3f',hObj.observations(row).benchmark.x))
set(handles.txtY, 'string', sprintf('%.3f',hObj.observations(row).benchmark.y))
set(handles.txtZ, 'string', sprintf('%.3f',hObj.observations(row).benchmark.z))
set(handles.BenchmarkPanel, 'title', ['Benchmark Metadata: ' hObj.observations(row).benchmark.name])
end
end
if or(col == 1, col == 2)
% clear selection that prevents from re-calling
% edit on this cell
jUIScrollPane = findjobj(handles.tblObs);
jUITable = jUIScrollPane.getViewport.getView;
jUITable.changeSelection(row-1,col-1, true, false);
end
% leave outside if to save the selected_row
guidata(hObject, hObj);
% --- Executes on button press in optDeltas.
function optDeltas_Callback(hObject, eventdata, handles)
% hObject handle to optDeltas (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of optDeltas
hObj = guidata(hObject);
if hObj.selected_instrument ~= 0
plot_line_info(hObj, handles)
end
% --- Executes on button press in optRaw.
function optRaw_Callback(hObject, eventdata, handles)
% hObject handle to optRaw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of optRaw
hObj = guidata(hObject);
if hObj.selected_instrument ~= 0
plot_line_info(hObj, handles)
end
% --- Executes on button press in optLineTimes.
function optLineTimes_Callback(hObject, eventdata, handles)
% hObject handle to optLineTimes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of optLineTimes
hObj = guidata(hObject);
if hObj.selected_instrument ~= 0
plot_line_info(hObj, handles)
end
% --- Executes on button press in cmdInsert.
function cmdInsert_Callback(hObject, eventdata, handles)
% hObject handle to cmdInsert (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% insert a blank line in the tblObs
hObj = guidata(hObject);
% call find benchmark
if and(hObj.selected_instrument ~= 0, hObj.selected_direction ~=0)
% pass a search location
if ~isempty(hObj.observations)
lat = hObj.observations(end).benchmark.lat;
lon = hObj.observations(end).benchmark.lon;
else
lat = 0;
lon = 0;
end
% open the dialog box
[~, benchmark] = fg_find_benchmark(lat,lon);
if isempty(benchmark)
return
end
instrument = hObj.instruments(hObj.selected_instrument);
direction = CssDirections.ToDirection(hObj.selected_direction - 1);
line = GetLine(hObj);
% use the max timestamp to compute
% the next possible datetime for the observation (to reduce user
% errors)
observations = line.GetObservationsByInstrumentDirection(instrument.name, direction);
if ~isempty(observations)
max_time = observations(end).timestamp;
% estimate the average velocity in this line
bench = [observations.benchmark];
lat = [bench.lat]';
lon = [bench.lon]';
if length(observations) >= 2
% estimate speed
d = cumsum([0; m_idist(lon(1:end-1),lat(1:end-1),lon(2:end),lat(2:end))])/1000;
speed = mean(diff(d)./hours(diff([observations.timestamp]'))); % km/h
else
% use a default speed
speed = 25; % km/h
end
% distance between last observation and new benchmark
ts = max_time + hours(m_idist(lon(end),lat(end),benchmark.lon,benchmark.lat)./1000./speed);
else
ts = datetime() + hours(1);
end
% if the benchmark exists in the line, get the reference to it
% rather than a copy from fg_find_benchmark
if CssBenchmark.exists(line.benchmarks, benchmark.name)
benchmark = CssBenchmark.ReturnBenchmark(line.benchmarks, benchmark.name);
end
% create a new observation object. Will be deep copied by AddObservation
new_obs = CssObservation(benchmark, direction, year(ts), month(ts), day(ts), hour(ts), minute(ts), instrument, [0,0,0]);
line = line.AddObservation(new_obs);
% save the line back to the corresponding variable
hObj = Update_hObj_Sync(hObj, line, handles);
guidata(hObject, hObj);
else
h = warndlg('Please select an instrument and a direction');
waitfor(h);
end
function hObj = Update_hObj_Sync(hObj, line, handles)
% this function updates the hObj variables and syncs the display with
% the contents of the line object
if hObj.selected_line ~=0
hObj.lines(hObj.selected_line) = line;
else
hObj.new_line = line;
handles.lblTitle.String = ['Gravity Line - New Line: ' line.line_name];
end
if and(hObj.selected_instrument ~= 0, hObj.selected_direction ~= 0)
instrument = hObj.instruments(hObj.selected_instrument);
direction = CssDirections.ToDirection(hObj.selected_direction - 1);
% now filter all observations for this instrument and direction
% using the built-in functions. This creates a shallow copy in
% hObj.observations that points to the actual object in new_line
observations = line.GetObservationsByInstrumentDirection(instrument.name, direction, true);
else
observations = [];
end
% sync the display
list = ToList(line, observations);
% make the combo items blue or gray, depending the contents of the
% observations list
UpdateCombos(hObj, line, handles)
% copy handle to observations
hObj.observations = observations;
% update the table
handles.tblObs.Data = list;
% try to plot, if possible
plot_line_info(hObj, handles)
% --- Executes when entered data in editable cell(s) in tblObs.
function tblObs_CellEditCallback(hObject, eventdata, handles)
% hObject handle to tblObs (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
hObj = guidata(hObject);
if and(hObj.selected_instrument ~= 0, hObj.selected_direction ~= 0)