forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thdb2d.cxx
3779 lines (3418 loc) · 113 KB
/
thdb2d.cxx
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
/**
* @file thdb2d.cxx
*/
/* Copyright (C) 2000 Stacho Mudrak
*
* $Date: $
* $RCSfile: $
* $Revision: $
*
* --------------------------------------------------------------------
* This program 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
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------
*/
#include "thdb2d.h"
#include "thexception.h"
#include "thdatabase.h"
#include "thtfangle.h"
#include "tharea.h"
#include "thmap.h"
#include "thjoin.h"
#include "thpoint.h"
#include "thline.h"
#include "thscrap.h"
#include "thsurvey.h"
#include "thlogfile.h"
#include <math.h>
#include "thlayout.h"
#include "thexpmap.h"
#include "thtrans.h"
#include "thtmpdir.h"
#include "thinit.h"
#include "thfilehandle.h"
#include "therion.h"
#include <list>
#include <set>
#include <iterator>
#include <cstdio>
#include <algorithm>
class thprjx_link {
public:
thdb2dcp * from_cp, * to_cp;
class thprjx_scrap * from_scrap, * to_scrap;
thprjx_link * next_link, * prev_link, * oposite_link;
thprjx_link() : from_cp(NULL), to_cp(NULL), from_scrap(NULL),
to_scrap(NULL), next_link(NULL), prev_link(NULL), oposite_link(NULL) {}
};
class thprjx_scrap {
public:
bool is_attached;
thscrap * scrap;
thprjx_scrap * prev_scrap;
thprjx_link * via_link;
double viacpx = 0.0, viacpy = 0.0, viacpz = 0.0;
thprjx_link * first_link, * last_link;
thprjx_scrap() : is_attached(false), scrap(NULL), prev_scrap(NULL),
via_link(NULL), first_link(NULL), last_link(NULL) {}
};
class thprjx_station {
public:
unsigned long nstations;
class thprjx_station_link * first_link, * last_link;
thprjx_station() : nstations(0), first_link(NULL), last_link(NULL) {}
};
class thprjx_station_link {
public:
thdb2dcp * scrapcp;
thprjx_scrap * scrap;
thprjx_station_link * next_link;
thprjx_station_link() : scrapcp(NULL), scrap(NULL), next_link(NULL) {}
};
bool operator < (const struct thdb2d_udef & u1, const struct thdb2d_udef & u2)
{
if (u1.m_command < u2.m_command) return true;
if (u1.m_command > u2.m_command) return false;
return (strcmp(u1.m_type, u2.m_type) < 0);
}
bool operator == (const struct thdb2d_udef & u1, const struct thdb2d_udef & u2)
{
if ((u1.m_command == u2.m_command) && (strcmp(u1.m_type, u2.m_type) == 0))
return true;
else
return false;
}
thdb2d::thdb2d()
{
this->db = NULL;
this->processed_area_outlines = false;
this->prj_lid = 0;
thdb2dprjpr dpr = this->parse_projection("plan");
this->prj_default = dpr.prj;
this->m_udef_map.clear();
}
thdb2d::~thdb2d()
{
}
void thdb2d::assigndb(thdatabase * dbptr)
{
this->db = dbptr;
}
void thdb2d_rot_align(int & align, double rot) {
double o;
switch (align) {
case TT_POINT_ALIGN_T:
o = 0.0;
break;
case TT_POINT_ALIGN_B:
o = 180.0;
break;
case TT_POINT_ALIGN_L:
o = 270.0;
break;
case TT_POINT_ALIGN_R:
o = 90.0;
break;
case TT_POINT_ALIGN_TL:
o = 315.0;
break;
case TT_POINT_ALIGN_BL:
o = 225.0;
break;
case TT_POINT_ALIGN_TR:
o = 45.0;
break;
case TT_POINT_ALIGN_BR:
o = 135.0;
break;
default:
return;
}
o += rot;
if (o < 0.0) {
o += 360.0;
} else if (o >= 360.0) {
o -= 360.0;
}
if ((o >= 337.5) || (o <= 22.5))
align = TT_POINT_ALIGN_T;
else if ((o >= 67.5) && (o <= 112.5))
align = TT_POINT_ALIGN_R;
else if ((o >= 157.5) && (o <= 202.5))
align = TT_POINT_ALIGN_B;
else if ((o >= 247.5) && (o <= 292.5))
align = TT_POINT_ALIGN_L;
else if ((o > 22.5) && (o < 67.5))
align = TT_POINT_ALIGN_TR;
else if ((o > 112.5) && (o < 157.5))
align = TT_POINT_ALIGN_BR;
else if ((o > 202.5) && (o < 247.5))
align = TT_POINT_ALIGN_BL;
else if ((o > 292.5) && (o < 337.5))
align = TT_POINT_ALIGN_TL;
}
void thdb2d_flip_align(int & align, bool horiz) {
bool vert = ! horiz;
switch (align) {
case TT_POINT_ALIGN_T:
if (vert) align = TT_POINT_ALIGN_B;
break;
case TT_POINT_ALIGN_B:
if (vert) align = TT_POINT_ALIGN_T;
break;
case TT_POINT_ALIGN_L:
if (horiz) align = TT_POINT_ALIGN_R;
break;
case TT_POINT_ALIGN_R:
if (horiz) align = TT_POINT_ALIGN_L;
break;
case TT_POINT_ALIGN_TL:
if (vert) align = TT_POINT_ALIGN_BL;
if (horiz) align = TT_POINT_ALIGN_TR;
break;
case TT_POINT_ALIGN_BL:
if (vert) align = TT_POINT_ALIGN_TL;
if (horiz) align = TT_POINT_ALIGN_BR;
break;
case TT_POINT_ALIGN_TR:
if (vert) align = TT_POINT_ALIGN_BR;
if (horiz) align = TT_POINT_ALIGN_TL;
break;
case TT_POINT_ALIGN_BR:
if (vert) align = TT_POINT_ALIGN_TR;
if (horiz) align = TT_POINT_ALIGN_BL;
break;
}
}
int thdb2d_rotate_align(int align, double rot) {
thdb2d_rot_align(align, rot);
return(align);
}
thdb2dprjpr thdb2d::parse_projection(const char * prjstr,bool insnew)
{
// let's split string into type - index - param - units
thsplit_words(& this->mbf, prjstr);
thdb2dprjpr ret_val;
std::string index_str_str(":");
thdb2dprj tp;
char ** pars = this->mbf.get_buffer(), ** pars2;
const char * type_str, * index_str = "";
double par = tp.pp1;
int npar = this->mbf.get_size(), prj_type;
if (npar < 1)
ththrow("missing projection type");
thsplit_strings(& this->mbf2, pars[0], ':');
switch (this->mbf2.get_size()) {
case 1:
type_str = pars[0];
break;
case 2:
pars2 = this->mbf2.get_buffer();
type_str = pars2[0];
index_str_str += pars2[1];
if (!th_is_keyword(pars2[1]))
ththrow("projection index not a keyword -- {}", pars2[1]);
break;
default:
ththrow("only one projection index allowed -- {}", pars[0]);
}
prj_type = thmatch_token(type_str,thtt_2dproj);
if (prj_type == TT_2DPROJ_UNKNOWN)
ththrow("unknown projection type -- {}", pars[0]);
if ((prj_type == TT_2DPROJ_NONE) && (index_str_str.length() > 1))
ththrow("no projection index allowed -- {}",prjstr);
//parse rest arguments
thtfangle angtf;
int asv;
switch (prj_type) {
case TT_2DPROJ_ELEV:
// parse units if necessary
if (npar > 3)
ththrow("too many projection arguments");
if (npar > 1) {
thparse_double(asv,par,pars[1]);
index_str_str += ":";
index_str_str += pars[1];
if (asv != TT_SV_NUMBER)
ththrow("invalid projection parameter -- {}",pars[1]);
if (npar > 2) {
angtf.parse_units(pars[2]);
par = angtf.transform(par);
}
if ((par < 0.0) || (par >= 360.0))
ththrow("elevation orientation out of range -- {}", pars[1]);
} else {
par = 0.0;
}
break;
default:
if (npar > 1)
ththrow("too many projection arguments");
break;
}
// let's find projection in a set or create a new one
if (index_str_str.length() > 1)
index_str = this->db->strstore(index_str_str.c_str(), true);
thdb2dprjid_map::iterator pi;
thdb2dprjid tpid(prj_type, index_str);
bool prj_found = false;
pi = this->prjid_map.find(tpid);
if (pi != this->prjid_map.end())
prj_found = true;
ret_val.newprj = !prj_found;
ret_val.parok = true;
thdb2dprj_list::iterator prjli;
if (prj_found) {
ret_val.prj = pi->second;
} else {
if (insnew) {
this->prj_lid++;
tp.type = prj_type;
tp.id = this->prj_lid;
tp.pp1 = par;
prjli = this->prj_list.insert(this->prj_list.end(),tp);
ret_val.prj = &(*prjli);
this->prjid_map[tpid] = ret_val.prj;
} else {
ret_val.prj = NULL;
}
}
return ret_val;
}
void thdb2d::self_print(FILE * /*outf*/)
{
}
thdb2dpt * thdb2d::insert_point()
{
thdb2dpt dumm;
return &(* this->pt_list.insert(this->pt_list.end(), dumm));
}
thdb2dlp * thdb2d::insert_line_point()
{
thdb2dlp dumm;
return &(* this->lp_list.insert(this->lp_list.end(),dumm));
}
thdb2dab * thdb2d::insert_border_line()
{
thdb2dab dumm;
return &(* this->ab_list.insert(this->ab_list.end(),dumm));
}
thdb2dji * thdb2d::insert_join_item()
{
thdb2dji dumm;
return &(* this->ji_list.insert(this->ji_list.end(),dumm));
}
thdb2dmi * thdb2d::insert_map_item()
{
thdb2dmi dumm;
return &(* this->mi_list.insert(this->mi_list.end(),dumm));
}
thdb2dcp * thdb2d::insert_control_point()
{
thdb2dcp dumm;
return &(* this->cp_list.insert(this->cp_list.end(),dumm));
}
thdb2dxm * thdb2d::insert_xm()
{
thdb2dxm dumm;
return &(* this->xm_list.insert(this->xm_list.end(),dumm));
}
thdb2dxs * thdb2d::insert_xs()
{
thdb2dxs dumm;
return &(* this->xs_list.insert(this->xs_list.end(),dumm));
}
thscraplo * thdb2d::insert_scraplo()
{
thscraplo dumm;
return &(* this->scraplo_list.insert(this->scraplo_list.end(),dumm));
}
thscrapen * thdb2d::insert_scrapen()
{
thscrapen dumm;
return &(* this->scrapen_list.insert(this->scrapen_list.end(),dumm));
}
thscraplp * thdb2d::insert_scraplp()
{
thscraplp dumm;
return &(* this->scraplp_list.insert(this->scraplp_list.end(),dumm));
}
void thdb2d::process_references()
{
#ifdef THDEBUG
thprintf("\n\nprocessing references\n");
#else
thprintf("processing references ... ");
thtext_inline = true;
#endif
thdb_object_list_type::iterator obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
switch ((*obi)->get_class_id()) {
case TT_LINE_CMD:
dynamic_cast<thline*>(obi->get())->preprocess();
break;
case TT_LAYOUT_CMD:
dynamic_cast<thlayout*>(obi->get())->process_copy();
break;
}
obi++;
}
obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
if ((*obi)->fsptr != NULL) {
switch ((*obi)->get_class_id()) {
case TT_AREA_CMD:
this->process_area_references(dynamic_cast<tharea*>(obi->get()));
break;
case TT_POINT_CMD:
this->process_point_references(dynamic_cast<thpoint*>(obi->get()));
break;
case TT_MAP_CMD:
this->process_map_references(dynamic_cast<thmap*>(obi->get()));
break;
case TT_JOIN_CMD:
this->process_join_references(dynamic_cast<thjoin*>(obi->get()));
break;
case TT_SCRAP_CMD:
this->process_scrap_references(dynamic_cast<thscrap*>(obi->get()));
}
}
obi++;
}
obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
if ((*obi)->fsptr != NULL) {
switch ((*obi)->get_class_id()) {
case TT_MAP_CMD:
this->postprocess_map_references(dynamic_cast<thmap*>(obi->get()));
break;
}
}
obi++;
}
#ifdef THDEBUG
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
void thdb2d::process_area_references(tharea * aptr)
{
thdb2dab* cbl = aptr->first_line;
thdataobject * optr;
while (cbl != NULL) {
optr = this->db->get_object(cbl->name, aptr->fsptr);
if (optr == NULL) {
if (cbl->name.survey != NULL)
ththrow("{} [{}] -- object does not exist -- {}@{}",
cbl->source.name, cbl->source.line,
cbl->name.name,cbl->name.survey);
else
ththrow("{} [{}] -- object does not exist -- {}",
cbl->source.name, cbl->source.line,
cbl->name.name);
}
if (optr->get_class_id() != TT_LINE_CMD) {
if (cbl->name.survey != NULL)
ththrow("{} [{}] -- object is not a line -- {}@{}",
cbl->source.name, cbl->source.line, cbl->name.name,cbl->name.survey);
else
ththrow("{} [{}] -- object is not a line -- {}",
cbl->source.name, cbl->source.line, cbl->name.name);
}
cbl->line = dynamic_cast<thline*>(optr);
if (cbl->line->fscrapptr->id != aptr->fscrapptr->id) {
if (cbl->name.survey != NULL)
ththrow("{} [{}] -- line outside of current scrap -- {}@{}",
cbl->source.name, cbl->source.line, cbl->name.name,cbl->name.survey);
else
ththrow("{} [{}] -- line outside of current scrap -- {}",
cbl->source.name, cbl->source.line, cbl->name.name);
}
cbl = cbl->next_line;
}
}
void thdb2d::process_map_references(thmap * mptr)
{
if (!mptr->asoc_survey.is_empty()) {
thdataobject * obj = this->db->get_object(mptr->asoc_survey, mptr->asoc_survey.psurvey);
if ((obj == NULL) || (obj->get_class_id() != TT_SURVEY_CMD)) {
if (mptr->asoc_survey.survey != NULL)
ththrow("{} [{}] -- invalid survey reference -- {}@{}",
mptr->source.name, mptr->source.line, mptr->asoc_survey.name, mptr->asoc_survey.survey);
else
ththrow("{} [{}] -- invalid survey reference -- {}",
mptr->source.name, mptr->source.line, mptr->asoc_survey.name);
}
mptr->asoc_survey.psurvey = dynamic_cast<thsurvey*>(obj);
}
if (mptr->projection_id > 0)
return;
if (mptr->first_item == NULL) {
ththrow("{} -- empty map not allowed", mptr->throw_source());
}
if (mptr->projection_id == -1)
ththrow("recursive map reference");
// let's lock the current map
mptr->projection_id = -1;
thdb2dmi * citem = mptr->first_item, * xcitem;
thdataobject * optr;
int proj_id = -1;
while (citem != NULL) {
if (citem->type != TT_MAPITEM_NORMAL) {
citem = citem->next_item;
continue;
}
optr = this->db->get_object(citem->name, citem->psurvey);
if (optr == NULL) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- object does not exist -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- object does not exist -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
thmap * mapp;
thscrap * scrapp;
thsurvey * survp;
switch (optr->get_class_id()) {
case TT_SURVEY_CMD:
if (proj_id == -1) {
if (mptr->expl_projection == NULL)
ththrow("{} [{}] -- no projection for survey", citem->source.name, citem->source.line);
proj_id = mptr->expl_projection->id;
mptr->is_basic = false;
} else {
if (mptr->is_basic) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- not a scrap reference -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- not a scrap reference -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
}
// skontroluje ci nie sme v inej projekcii
switch (this->get_projection(proj_id)->type) {
case TT_2DPROJ_EXTEND:
case TT_2DPROJ_PLAN:
case TT_2DPROJ_ELEV:
break;
default:
ththrow("{} [{}] -- unsupported projection for survey", citem->source.name, citem->source.line);
break;
}
survp = dynamic_cast<thsurvey*>(optr);
// vytvorime specialnu mapu s jednym scrapom,
// ktoremu nastavime centerline io a survey
{
auto unique_scrapp = std::make_unique<thscrap>();
scrapp = unique_scrapp.get();
scrapp->centerline_io = true;
scrapp->centerline_survey = survp;
scrapp->z = thnan;
if ((survp->stat.station_top != NULL) && (survp->stat.station_bottom != NULL)) {
scrapp->z = (survp->stat.station_top->z + survp->stat.station_bottom->z) / 2.0;
}
scrapp->fsptr = NULL;
scrapp->db = this->db;
scrapp->proj = this->get_projection(proj_id);
thdb.object_list.push_back(std::move(unique_scrapp));
}
{
auto unique_mapp = std::make_unique<thmap>();
mapp = unique_mapp.get();
mapp->projection_id = proj_id;
mapp->id = ++this->db->objid;
mapp->db = this->db;
mapp->z = scrapp->z;
mapp->fsptr = NULL;
thdb.object_list.push_back(std::move(unique_mapp));
}
xcitem = this->db->db2d.insert_map_item();
xcitem->itm_level = mapp->last_level;
xcitem->source = thdb.csrc;
xcitem->psurvey = NULL;
xcitem->type = TT_MAPITEM_NORMAL;
xcitem->object = scrapp;
mapp->first_item = xcitem;
mapp->last_item = xcitem;
citem->object = mapp;
break;
case TT_MAP_CMD:
mapp = dynamic_cast<thmap*>(optr);
// if not defined - process recursively
if (mapp->projection_id == 0) {
try {
this->process_map_references(mapp);
}
catch (...) {
if (citem->name.survey != NULL)
threthrow("{} [{}] -- error processing map reference -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
threthrow("{} [{}] -- error processing map reference -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
}
if (proj_id == -1) {
proj_id = mapp->projection_id;
mptr->is_basic = false;
} else {
// check projection
if (mapp->projection_id != proj_id) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- incompatible map projection -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- incompatible map projection -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
// check basic
if (mptr->is_basic) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- not a scrap reference -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- not a scrap reference -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
}
if ((mptr->expl_projection != NULL) && (mptr->expl_projection->id != proj_id)) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- incompatible map projection -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- incompatible map projection -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
citem->object = mapp;
break;
case TT_SCRAP_CMD:
scrapp = dynamic_cast<thscrap*>(optr);
if (proj_id == -1) {
proj_id = scrapp->proj->id;
mptr->is_basic = true;
} else {
// check projection
if (scrapp->proj->id != proj_id) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- incompatible scrap projection -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- incompatible scrap projection -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
// check basic
if (!mptr->is_basic) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- not a map reference -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- not a map reference -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
if (citem->m_shift.is_active()) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- shift is not allowed for scrap -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- shift is not allowed for scrap -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
}
if ((mptr->expl_projection != NULL) && (mptr->expl_projection->id != proj_id)) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- incompatible scrap projection -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- incompatible scrap projection -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
citem->object = scrapp;
break;
default:
mptr->throw_source();
if (citem->name.survey != NULL)
ththrow("{} [{}] -- invalid map object -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- invalid map object -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
citem = citem->next_item;
}
#ifdef THDEBUG
thprintf("\nmap projection %s -> %d\n",mptr->name,proj_id);
#endif
mptr->projection_id = proj_id;
}
void thdb2d::postprocess_map_references(thmap * mptr)
{
thdb2dmi * citem = mptr->first_item;
thdataobject * optr;
if (mptr->projection_id == -1) {
ththrow("{} [{}] -- map cannot contain only previews",
citem->source.name, citem->source.line);
}
while (citem != NULL) {
if (citem->type == TT_MAPITEM_NORMAL) {
citem = citem->next_item;
continue;
}
optr = this->db->get_object(citem->name, citem->psurvey);
if (optr == NULL) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- object does not exist -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- object does not exist -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
thmap * mapp;
switch (optr->get_class_id()) {
case TT_MAP_CMD:
mapp = dynamic_cast<thmap*>(optr);
if (mapp->projection_id != mptr->projection_id) {
if (citem->name.survey != NULL)
ththrow("{} [{}] -- incompatible map projection -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- incompatible map projection -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
citem->object = optr;
break;
case TT_SCRAP_CMD:
if (citem->name.survey != NULL)
ththrow("{} [{}] -- not a map reference -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- not a map reference -- {}",
citem->source.name, citem->source.line,
citem->name.name);
break;
default:
mptr->throw_source();
if (citem->name.survey != NULL)
ththrow("{} [{}] -- invalid map object -- {}@{}",
citem->source.name, citem->source.line,
citem->name.name,citem->name.survey);
else
ththrow("{} [{}] -- invalid map object -- {}",
citem->source.name, citem->source.line,
citem->name.name);
}
citem = citem->next_item;
}
}
void thdb2d::process_join_references(thjoin * jptr)
{
thdataobject * optr;
thdb2dji * citem = jptr->first_item, * prev_item;
thpoint * pointp;
thline * linep;
thdb2dprj * cprj;
int otype;
while (citem != NULL) {
optr = this->db->get_object(citem->name, jptr->fsptr);
if (optr == NULL) {
if (citem->name.survey != NULL)
ththrow("{} -- object does not exist -- {}@{}", jptr->throw_source(),
citem->name.name,citem->name.survey);
else
ththrow("{} -- object does not exist -- {}", jptr->throw_source(),
citem->name.name);
}
otype = optr->get_class_id();
if (optr->is(TT_2DDATAOBJECT_CMD) || optr->is(TT_SCRAP_CMD)) {
if (jptr->proj != NULL) {
if (optr->is(TT_SCRAP_CMD))
cprj = dynamic_cast<thscrap*>(optr)->proj;
else
cprj = dynamic_cast<th2ddataobject*>(optr)->fscrapptr->proj;
if (cprj->id != jptr->proj->id) {
if (citem->name.survey != NULL)
ththrow("{} -- projection mishmash -- {}@{}", jptr->throw_source(),
citem->name.name,citem->name.survey);
else
ththrow("{} -- projection mishmash -- {}", jptr->throw_source(),
citem->name.name);
}
} else {
if (optr->is(TT_SCRAP_CMD))
jptr->proj = dynamic_cast<thscrap*>(optr)->proj;
else
jptr->proj = dynamic_cast<th2ddataobject*>(optr)->fscrapptr->proj;
}
}
switch (otype) {
case TT_SCRAP_CMD:
prev_item = citem->prev_item;
if (prev_item != NULL) {
if (!(prev_item->object->is(TT_SCRAP_CMD))) {
if (citem->name.survey != NULL)
ththrow("{} -- scrap can not follow not scrap -- {}@{}:{}", jptr->throw_source(),
citem->name.name,citem->name.survey,citem->mark);
else
ththrow("{} -- scrap can not follow not scrap -- {}:{}", jptr->throw_source(),
citem->name.name,citem->mark);
}
prev_item = prev_item->prev_item;
if (prev_item != NULL) {
if (citem->name.survey != NULL)
ththrow("{} -- join of more than 2 scraps not supported -- {}@{}:{}", jptr->throw_source(),
citem->name.name,citem->name.survey,citem->mark);
else
ththrow("{} -- join of more than 2 scraps not supported -- {}:{}", jptr->throw_source(),
citem->name.name,citem->mark);
}
}
citem->object = optr;
break;
case TT_POINT_CMD:
pointp = dynamic_cast<thpoint*>(optr);
if (citem->mark != NULL) {
if (citem->name.survey != NULL)
ththrow("{} -- mark reference with point -- {}@{}:{}", jptr->throw_source(),
citem->name.name,citem->name.survey,citem->mark);
else
ththrow("{} -- mark reference with point -- {}:{}", jptr->throw_source(),
citem->name.name,citem->mark);
}
citem->point = pointp->point;
citem->line_point = NULL;
citem->object = optr;
break;
case TT_LINE_CMD:
linep = dynamic_cast<thline*>(optr);
if (citem->mark != NULL) {
citem->line_point = linep->get_marked_station(citem->mark);
if (citem->line_point == NULL) {
if (citem->name.survey != NULL)
ththrow("{} -- marked station not found -- {}@{}:{}", jptr->throw_source(),
citem->name.name,citem->name.survey,citem->mark);
else
ththrow("{} -- marked station not found -- {}:{}", jptr->throw_source(),
citem->name.name,citem->mark);
}
citem->point = citem->line_point->point;
}
citem->object = optr;
break;
default:
if (citem->name.survey != NULL)
ththrow("{} -- invalid join object -- {}@{}", jptr->throw_source(),
citem->name.name,citem->name.survey);
else
ththrow("{} -- invalid join object -- {}", jptr->throw_source(),
citem->name.name);
}
citem = citem->next_item;
}
}
void thdb2d::process_point_references(thpoint * pp)
{
thdataobject * optr;
bool extend_error = false;
const char * err_code = "invalid station or point reference";
switch (pp->type) {
case TT_POINT_TYPE_STATION:
case TT_POINT_TYPE_CONTINUATION:
if (! pp->station_name.is_empty()) {
try {
pp->station_name.id = this->db->db1d.get_station_id(pp->station_name,pp->fsptr);
} catch (...) {
pp->station_name.id = 0;
}
if (pp->station_name.id == 0) {
if (pp->station_name.survey != NULL)
ththrow("{} -- station does not exist -- {}@{}", pp->throw_source(),
pp->station_name.name,pp->station_name.survey);
else
ththrow("{} -- station does not exist -- {}", pp->throw_source(),
pp->station_name.name);
}
if (pp->type == TT_POINT_TYPE_STATION)