-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_GPHDATA.cpp
16198 lines (13658 loc) · 613 KB
/
GS_GPHDATA.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
/**********************************************************
Name: GS_GPHDATA
Module description: File contenente le funzioni per
la gestione dei dati grafici in formato DB
Author: Roberto Poltini
(c) Copyright 1996-2015 by IREN ACQUA GAS S.p.a. Genova
Modification history:
Notes and restrictions on use:
**********************************************************/
/*********************************************************/
/* INCLUDES */
/*********************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include "MapODRecord.h"
#include "gs_opcod.h"
#include "gs_error.h"
#include "gs_utily.h"
#include "gs_resbf.h"
#include "gs_netw.h" // funzioni di rete
#include "gs_init.h"
#include "gs_dbref.h"
#include "gs_ade.h"
#include "gs_thm.h" // gestione tematismi e sistemi di coordinate
#include "gs_attbl.h"
#include "gs_query.h"
#include "gs_topo.h" // per topologia simulazioni
#include "gs_gphdata.h" // gestione dati grafici
#if defined(GSDEBUG) // se versione per debugging
#include <sys/timeb.h> // Solo per debug
#include <time.h> // Solo per debug
double gph_tempo=0, gph_tempo1=0, gph_tempo2=0, gph_tempo3=0, gph_tempo4=0, gph_tempo5=0, gph_tempo6=0, gph_tempo7=0;
double gph_tempo8=0, gph_tempo9=0, gph_tempo10=0, gph_tempo11=0, gph_tempo12=0, gph_tempo13=0, gph_tempo14=0;
#endif
///////////////////////////////////////////////////////////////////////////
// INIZIO FUNZIONI PRIVATE
///////////////////////////////////////////////////////////////////////////
void gsc_geom_print_save_report(long deleted, long updated, long inserted);
void gsc_label_print_save_report(long deleted, long updated, long inserted);
/*************************************************************/
/*.doc cls_print_save_report <internal> */
/*+
Funzione che stampa a video il risultato del salvataggio di classi
Parametri:
long deleted; n. entità cancellate
long updated; n. entità aggiornate
long inserted; n. entità inserite
-*/
/*************************************************************/
void gsc_geom_print_save_report(long deleted, long updated, long inserted)
{
TCHAR Msg[MAX_LEN_MSG];
acutPrintf(gsc_msg(495), deleted); // "\n%ld oggetti grafici GEOsim cancellati."
swprintf(Msg, MAX_LEN_MSG, _T("%ld erased graphical objects."), deleted);
gsc_write_log(Msg);
acutPrintf(gsc_msg(496), updated); // "\n%ld oggetti grafici GEOsim aggiornati."
swprintf(Msg, MAX_LEN_MSG, _T("%ld updated graphical objects."), updated);
gsc_write_log(Msg);
acutPrintf(gsc_msg(497), inserted); // "\n%ld oggetti grafici GEOsim inseriti."
swprintf(Msg, MAX_LEN_MSG, _T("%ld inserted graphical objects."), inserted);
gsc_write_log(Msg);
}
void gsc_label_print_save_report(long deleted, long updated, long inserted)
{
TCHAR Msg[MAX_LEN_MSG];
acutPrintf(gsc_msg(498), deleted); // "\n%ld blocchi etichette GEOsim cancellati."
swprintf(Msg, MAX_LEN_MSG, _T("%ld erased label blocks."), deleted);
gsc_write_log(Msg);
acutPrintf(gsc_msg(499), updated); // "\n%ld blocchi etichette GEOsim aggiornati."
swprintf(Msg, MAX_LEN_MSG, _T("%ld updated label blocks."), updated);
gsc_write_log(Msg);
acutPrintf(gsc_msg(500), inserted); // "\n%ld blocchi etichette GEOsim inseriti."
swprintf(Msg, MAX_LEN_MSG, _T("%ld inserted label blocks."), inserted);
gsc_write_log(Msg);
}
/*********************************************************/
/*.doc gsc_PrintBackUpMsg <internal> */
/*+
Questa funzione stampa messaggi relativi al backup dei dati.
Parametri:
BackUpModeEnum Mode;
-*/
/*********************************************************/
void gsc_PrintBackUpMsg(BackUpModeEnum Mode)
{
switch (Mode)
{
case GSCreateBackUp: // crea backup
acutPrintf(gsc_msg(478)); // "\nCreazione backup dati geometrici..."
break;
case GSRemoveBackUp: // cancella backup
acutPrintf(gsc_msg(479)); // "\nCancellazione backup dati geometrici..."
break;
case GSRestoreBackUp: // ripristina backup
acutPrintf(gsc_msg(480)); // "\nRipristino backup dati geometrici..."
break;
}
}
///////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI PRIVATE
// INIZIO FUNZIONI C_GPH_OBJ_ARRAY
///////////////////////////////////////////////////////////////////////////
// costruttore
C_GPH_OBJ_ARRAY::C_GPH_OBJ_ARRAY()
{
mReleaseAllAtDistruction = true;
}
// distruttore
C_GPH_OBJ_ARRAY::~C_GPH_OBJ_ARRAY()
{
if (mReleaseAllAtDistruction)
removeAll();
}
int C_GPH_OBJ_ARRAY::length(void)
{
if (ObjType == AcDbObjectIdType)
{
int Tot = 0;
C_DWG *pDwg = (C_DWG *) DwgList.get_head();
while (pDwg)
{
Tot += pDwg->ptr_ObjectIdArray()->length();
pDwg = (C_DWG *) DwgList.get_next();
}
return Tot;
}
else
return Ents.length();
}
void C_GPH_OBJ_ARRAY::removeAll(void)
{
int i;
AcDbEntity *pEnt;
C_INT_LONG *p;
C_DWG *pDwg = (C_DWG *) DwgList.get_head();
while (pDwg)
{
pDwg->clear_ObjectIdArray();
pDwg = (C_DWG *) DwgList.get_next();
}
p = (C_INT_LONG *) KeyEnts.get_head();
for (i = 0; i < Ents.length(); i++)
{
if ((pEnt = Ents.at(i)))
if (p)
{
// Se l'entità è da rilasciare (== 0)
if (p->get_key() == 0) delete pEnt;
p = (C_INT_LONG *) KeyEnts.get_next();
}
else
delete pEnt;
}
Ents.removeAll();
KeyEnts.remove_all();
}
///////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI C_GPH_OBJ_ARRAY
// INIZIO FUNZIONI C_GPH_INFO
///////////////////////////////////////////////////////////////////////////
// costruttore
C_GPH_INFO::C_GPH_INFO()
{
prj = 0;
cls = 0;
sub = 0;
}
// distruttore
C_GPH_INFO::~C_GPH_INFO() {}
GraphDataSourceEnum C_GPH_INFO::getDataSourceType(void) { return GSNoneGphDataSource; }
int C_GPH_INFO::copy(C_GPH_INFO* out)
{
if (!out) { GS_ERR_COD = eGSNotAllocVar; return GS_BAD; }
out->prj = prj;
out->cls = cls;
out->sub = sub;
out->coordinate_system = coordinate_system;
return GS_GOOD;
}
int C_GPH_INFO::ToFile(C_STRING &filename, const TCHAR *sez)
{
C_PROFILE_SECTION_BTREE ProfileSections;
bool Unicode = false;
if (gsc_path_exist(filename) == GS_GOOD)
if (gsc_read_profile(filename, ProfileSections, &Unicode) == GS_BAD) return GS_BAD;
if (ToFile(ProfileSections, sez) == GS_BAD) return GS_BAD;
return gsc_write_profile(filename, ProfileSections, Unicode);
}
int C_GPH_INFO::ToFile(C_PROFILE_SECTION_BTREE &ProfileSections, const TCHAR *sez)
{
C_BPROFILE_SECTION *ProfileSection;
C_STRING Buffer;
if (!(ProfileSection = (C_BPROFILE_SECTION *) ProfileSections.search(sez)))
{
if (ProfileSections.add(sez) == GS_BAD) return GS_BAD;
ProfileSection = (C_BPROFILE_SECTION *) ProfileSections.get_cursor();
}
ProfileSection->set_entry(_T("GPH_INFO.PRJ"), prj);
ProfileSection->set_entry(_T("GPH_INFO.CLS"), cls);
ProfileSection->set_entry(_T("GPH_INFO.SUB"), sub);
Buffer = (coordinate_system.get_name()) ? coordinate_system.get_name() : GS_EMPTYSTR;
ProfileSection->set_entry(_T("GPH_INFO.COORDINATE_SYSTEM"), Buffer.get_name());
return GS_GOOD;
}
int C_GPH_INFO::load(C_STRING &filename, const TCHAR *sez)
{
C_PROFILE_SECTION_BTREE ProfileSections;
if (gsc_read_profile(filename, ProfileSections) == GS_BAD) return GS_BAD;
return load(ProfileSections, sez);
}
int C_GPH_INFO::load(C_PROFILE_SECTION_BTREE &ProfileSections, const TCHAR *sez)
{
C_BPROFILE_SECTION *ProfileSection;
C_2STR_BTREE *pProfileEntries;
C_B2STR *pProfileEntry;
if (!(ProfileSection = (C_BPROFILE_SECTION *) ProfileSections.search(sez))) return GS_CAN;
pProfileEntries = (C_2STR_BTREE *) ProfileSection->get_ptr_EntryList();
// codice progetto (obbligatorio)
if (!(pProfileEntry = (C_B2STR *) pProfileEntries->search(_T("GPH_INFO.PRJ")))) return GS_CAN;
prj = _wtoi(pProfileEntry->get_name2());
// codice classe (obbligatorio)
if (!(pProfileEntry = (C_B2STR *) pProfileEntries->search(_T("GPH_INFO.CLS")))) return GS_CAN;
cls = _wtoi(pProfileEntry->get_name2());
// codice sotto-classe (obbligatorio)
if (!(pProfileEntry = (C_B2STR *) pProfileEntries->search(_T("GPH_INFO.SUB")))) return GS_CAN;
sub = _wtoi(pProfileEntry->get_name2());
// sistema di coordinate
if ((pProfileEntry = (C_B2STR *) pProfileEntries->search(_T("GPH_INFO.COORDINATE_SYSTEM"))))
coordinate_system = pProfileEntry->get_name2();
return GS_GOOD;
}
resbuf *C_GPH_INFO::to_rb(bool ConvertDrive2nethost, bool ToDB)
{
C_RB_LIST List;
if (ToDB)
if ((List << acutBuildList(RTLB, // non scrivo volutamente prj
RTSTR, _T("CLASS_ID"),
RTSHORT, cls,
RTLE,
RTLB,
RTSTR, _T("SUB_CL_ID"),
RTSHORT, sub,
RTLE, 0)) == NULL) return NULL;
if ((List += acutBuildList(RTLB,
RTSTR, _T("COORDINATE"),
0)) == NULL) return NULL;
if ((List += gsc_str2rb(coordinate_system)) == NULL) return NULL;
if ((List += acutBuildList(RTLE, 0)) == NULL) return NULL;
List.ReleaseAllAtDistruction(GS_BAD);
return List.get_head();
}
int C_GPH_INFO::from_rb(C_RB_LIST &ColValues)
{
return from_rb(ColValues.get_head());
}
int C_GPH_INFO::from_rb(resbuf *rb)
{
presbuf p;
if ((p = gsc_CdrAssoc(_T("PRJ"), rb, FALSE)))
if (gsc_rb2Int(p, &prj) == GS_BAD) return GS_BAD;
if ((p = gsc_CdrAssoc(_T("CLASS_ID"), rb, FALSE)))
if (gsc_rb2Int(p, &cls) == GS_BAD) return GS_BAD;
if ((p = gsc_CdrAssoc(_T("SUB_CL_ID"), rb, FALSE)))
if (gsc_rb2Int(p, &sub) == GS_BAD) return GS_BAD;
if ((p = gsc_CdrAssoc(_T("COORDINATE"), rb, FALSE)))
if (p->restype == RTSTR)
{
coordinate_system = p->resval.rstring;
coordinate_system.alltrim();
}
else coordinate_system.clear();
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GPH_INFO::to_db <internal> */
/*+
Questa funzione scrive i dati di una C_GPH_INFO nella
tabella CLASS_GPH_DATA_SRC_TABLE_NAME.
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::to_db(void)
{
C_PROJECT *pPrj;
C_DBCONNECTION *pConn;
C_STRING MetaTableRef, statement;
_RecordsetPtr pRs;
C_RB_LIST ColValues;
if ((ColValues << acutBuildList(RTLB, 0)) == NULL) return GS_BAD;
if ((ColValues += to_rb(true, true)) == NULL) return GS_BAD;
if ((ColValues += acutBuildList(RTLE, 0)) == NULL) return GS_BAD;
// cerco elemento in lista progetti
if ((pPrj = (C_PROJECT *) GEOsimAppl::PROJECTS.search_key(prj)) == NULL) return GS_BAD;
// setto il riferimento di CLASS_GPH_DATA_SRC_TABLE_NAME (<catalogo>.<schema>.<tabella>)
if (pPrj->getClassGphDataSrcTabInfo(&pConn, &MetaTableRef) == GS_BAD) return GS_BAD;
statement = _T("SELECT * FROM ");
statement += MetaTableRef;
statement += _T(" WHERE CLASS_ID=");
statement += cls;
statement += _T(" AND SUB_CL_ID=");
statement += sub;
// leggo la riga della tabella bloccandola in modifica
if (pConn->ExeCmd(statement, pRs, adOpenDynamic, adLockPessimistic) == GS_BAD) return GS_BAD;
if (gsc_isEOF(pRs) == GS_GOOD)
{
gsc_DBCloseRs(pRs);
// inserisco nuova riga
if (pConn->InsRow(MetaTableRef.get_name(), ColValues) == GS_BAD) return GS_BAD;
}
else
{
// modifico la riga del cursore
if (gsc_DBUpdRow(pRs, ColValues) == GS_BAD) return GS_BAD;
if (gsc_DBCloseRs(pRs) == GS_BAD) return GS_BAD;
}
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GPH_INFO::del_db <internal> */
/*+
Questa funzione cancella i dati di una C_GPH_INFO dalla
tabella CLASS_GPH_DATA_SRC_TABLE_NAME.
Parametri:
bool DelResource; Opzionale; flag di rimozione delle risorse (cartelle disegni...)
(default = false)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::del_db(bool DelResource)
{
C_PROJECT *pPrj;
C_DBCONNECTION *pConn;
C_STRING MetaTableRef;
_RecordsetPtr pRs;
// cerco elemento in lista progetti
if ((pPrj = (C_PROJECT *) GEOsimAppl::PROJECTS.search_key(prj)) == NULL) return GS_BAD;
// setto il riferimento di GS_CLASS_GRAPH_INFO (<catalogo>.<schema>.<tabella>)
if (pPrj->getClassGphDataSrcTabInfo(&pConn, &MetaTableRef) == GS_BAD) return GS_BAD;
// blocco riga in GS_CLASS_GRAPH_INFO
if (gsc_lock_on_gs_class_graph_info(pConn, MetaTableRef, cls, sub, pRs) == GS_BAD)
return GS_BAD;
if (DelResource)
{
C_RB_LIST ColValues;
if (gsc_DBReadRow(pRs, ColValues) == GS_BAD)
{ gsc_unlock_on_gs_class_graph_info(pConn, pRs, READONLY); return GS_BAD; }
if (from_rb(ColValues) == GS_BAD)
{ gsc_unlock_on_gs_class_graph_info(pConn, pRs, READONLY); return GS_BAD; }
if (RemoveResource() == GS_BAD)
{ gsc_unlock_on_gs_class_graph_info(pConn, pRs, READONLY); return GS_BAD; }
}
// cancello la riga in CLASS_GPH_DATA_SRC_TABLE_NAME
gsc_DBDelRow(pRs);
// sblocco CLASS_GPH_DATA_SRC_TABLE_NAME
return gsc_unlock_on_gs_class_graph_info(pConn, pRs);
}
/*********************************************************/
/*.doc C_GPH_INFO::isValid <external> */
/*+
Questa funzione verifica la correttezza della C_GPH_INFO.
Parametri:
int GeomType; Usato per compatibilità
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::isValid(int GeomType)
{
// verifico validità coord
return gsc_validcoord(coordinate_system.get_name());
}
int C_GPH_INFO::CreateResource(int GeomType)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::RemoveResource(void)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
bool C_GPH_INFO::IsTheSameResource(C_GPH_INFO *p)
{ GS_ERR_COD = eGSInvClassType; return false; }
bool C_GPH_INFO::ResourceExist(bool *pGeomExist, bool *pLblGroupingExist, bool *pLblExist)
{
if (pGeomExist) *pGeomExist = false;
if (pLblGroupingExist) *pLblGroupingExist = false;
if (pLblExist) *pLblExist = false;
GS_ERR_COD = eGSInvClassType;
return false;
}
/*********************************************************/
/*.doc C_GPH_INFO::QueryClear <internal> */
/*+
Questa funzione pulisce la condizione di query da applicare
alla fonte dati grafica (si usa la query ADE corrente).
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::QueryClear(void)
{
return (ade_qryclear() != RTNORM) ? GS_BAD : GS_GOOD;
}
/*********************************************************/
/*.doc C_GPH_INFO::LoadQueryFromCls <internal> */
/*+
Questa funzione carica la condizione di query impostata per la classe
di GEOsim da applicare alla fonte dati grafica.
Viene cancellata, se esistente, la query precedente dopodichè viene impostata
la condizione spaziale e, se viene passata una lista di codici di entità
da ricercare (lista non vuota), viene impostata una condizione partendo
dalla posizione del cursore corrente nella lista considerando un certo numero di
codici (vedi MAX_GRAPH_CONDITIONS). Se invece la lista dei codici di entità è
vuota allora viene impostata la query SQL e determinata la lista dei codici di
entità che soddisfano la query impostando la condizione partendo
dall'inizio della lista considerando un certo numero di codici (vedi MAX_GRAPH_CONDITIONS).
Parametri:
TCHAR *qryName; Nome della query spaziale
C_STR_LIST &IdList; Lista dei codici di entità da estrarre
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::LoadQueryFromCls(TCHAR *qryName, C_STR_LIST &IdList)
{
C_STRING SQL;
// Se la lista dei codici delle entità da cercare è vuota
if (IdList.get_count() == 0)
{
// carico la query SQL
if (gsc_ClsSQLQryLoad(cls, sub, SQL) == GS_GOOD)
{
// leggo i codici delle entità che soddisfano la query SQL sulla tabella OLD
if (gsc_getKeyListFromASISQLonOld(cls, sub, SQL.get_name(), IdList) == GS_BAD)
return GS_BAD;
if (IdList.get_count() == 0) return GS_GOOD;
}
IdList.get_head(); // mi posiziono all'inizio della lista
}
// carico e attivo la query spaziale cancellando la query precedente
if (LoadSpatialQueryFromADEQry(qryName) == GS_BAD) return GS_BAD;
// definisco la query per OD
if (AddQueryFromEntityIds(IdList) == GS_BAD) return GS_BAD;
return GS_GOOD;
}
int C_GPH_INFO::LoadSpatialQueryFromADEQry(TCHAR *qryName)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
/*********************************************************/
/*.doc C_GPH_INFO::AddQueryFromEntityIds <internal> */
/*+
Questa funzione aggiunge in "and" alla query corrente la condizione necessaria
per cercare gli oggetti appartenenti ad una lista di ID sotto forma di una
C_STR_LIST passata come parametro (utilizza il codice dell'entità).
Parametri:
C_STR_LIST &IdList; Lista dei codici chiave degli oggetti da estrarre
bool FromBeginnig; Flag opzionale; se true parto dall'inizio della lista
KeyList altrimenti parto dalla posizione del cursore
(default = true)
int MaxConditions; Opzionale; numero massimo di condizioni impostabili.
Se = -1 non c'è limite (default = MAX_GRAPH_CONDITIONS)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::AddQueryFromEntityId(long Id)
{
C_STR_LIST IdList;
C_STR *pId;
if ((pId = new C_STR()) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
(*pId) = Id;
IdList.add_tail(pId);
return AddQueryFromEntityIds(IdList);
}
int C_GPH_INFO::AddQueryFromEntityIds(C_STR_LIST &IdList, bool FromBeginnig,
int MaxConditions)
{
C_STR *pKey;
C_STRING ODTblFldName, JOp, endGroups;
bool First = TRUE;
C_RB_LIST QryCond;
int i = 1;
if (FromBeginnig)
pKey = (C_STR *) IdList.get_head();
else
pKey = (C_STR *) IdList.get_cursor();
if (!pKey) return GS_GOOD;
gsc_getODTableName(prj, cls, sub, ODTblFldName);
ODTblFldName += _T(".ID");
// Costruisco la condition query da passare a QueryDefine
QryCond << acutBuildList(RTLB,
RTSTR, _T("objdata"),
RTSTR, ODTblFldName.get_name(),
RTSTR, _T("="), RTSTR, pKey->get_name(),
RTLE, 0);
pKey = (C_STR *) IdList.get_next();
endGroups = (!pKey) ? _T(")"): GS_EMPTYSTR; // ultima condizione
// Imposto la prima condizione di estrazione DATA
if (QueryDefine(_T("and"), // joinop
_T("("), // bgGroups
GS_EMPTYSTR, // not_op
_T("Data"), QryCond.get_head(),
endGroups.get_name()) == GS_BAD) // endGroups
return GS_BAD;
// scorro la lista delle classi e degli oggetti che voglio estrarre
while (pKey && i++ < MaxConditions)
{
// Costruisco la condition query da passare ad ade_qrydefine()
QryCond << acutBuildList(RTLB,
RTSTR, _T("objdata"),
RTSTR, ODTblFldName.get_name(),
RTSTR, _T("="), RTSTR, pKey->get_name(),
RTLE, 0);
pKey = (C_STR *) IdList.get_next();
endGroups = (!pKey || i >= MaxConditions) ? _T(")"): GS_EMPTYSTR; // ultima condizione
// Imposto la condizione di estrazione DATA
if (QueryDefine(_T("or"), // joinop
GS_EMPTYSTR, // bgGroups
GS_EMPTYSTR, // not_op
_T("Data"), QryCond.get_head(),
endGroups.get_name()) == GS_BAD) // endGroups
return GS_BAD;
}
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GPH_INFO::AddQueryOnlyLabels <internal> */
/*+
Questa funzione aggiunge in "and" alla query ADE corrente la condizione
necessaria per cercare solo le etichette.
Parametri:
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::AddQueryOnlyLabels(void)
{
C_RB_LIST DollarTCond;
if ((DollarTCond << acutBuildList(RTLB,
RTSTR, _T("blockname"),
RTSTR, _T("="),
RTSTR, _T("$T"),
RTLE, 0)) == NULL)
return GS_BAD;
return QueryDefine(_T("AND"), _T("(") , _T(""), _T("Property"),
DollarTCond.get_head(), _T(")"));
}
/*********************************************************/
/*.doc C_GPH_INFO::AddQueryOnlyGraphObjs <internal> */
/*+
Questa funzione aggiunge in "and" alla query ADE corrente la condizione
necessaria per cercare solo oggetti grafici senza etichette.
Parametri:
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::AddQueryOnlyGraphObjs(void)
{
C_RB_LIST DollarTCond;
if ((DollarTCond << acutBuildList(RTLB,
RTSTR, _T("blockname"),
RTSTR, _T("="),
RTSTR, _T("$T"),
RTLE, 0)) == NULL)
return GS_BAD;
return QueryDefine(_T("AND"), _T("(") , _T("NOT"), _T("Property"),
DollarTCond.get_head(), _T(")"));
}
/*********************************************************/
/*.doc C_GPH_INFO::QueryDefine <internal> */
/*+
Questa funzione definisce la query ADE corrente da applicare
alla fonte dati grafica.
Parametri:
TCHAR* joinop; A joining operator: "and" or "or" or "" (none).
If "" (none) is specified, the default joining operator
is used (see ade_prefgetval).
TCHAR* bggroups; For grouping this condition with others in the query
definition you are building. Use one or more open parentheses
as needed, or "" (none). For example, "((".
TCHAR* not_op; The NOT operator, if needed: "not" or "" (none).
TCHAR* condtype; A condition type: "Location", "Property", "Data", or "SQL".
presbuf qrycond; A condition expression. Depends on the condition type.
TCHAR* endgroups; For grouping this condition with others in the query
definition you are building. Use one or more close p
arentheses as needed, or "" (none). For example, "))".
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GPH_INFO::QueryDefine(TCHAR* joinOp, TCHAR* bgGroups, TCHAR* notOp,
TCHAR* condType, presbuf qryCond, TCHAR* endGroups)
{
if (ade_qrydefine(joinOp, bgGroups, notOp, condType, qryCond, endGroups) == ADE_NULLID)
{ GS_ERR_COD = eGSQryCondNotDef; return GS_BAD; }
return GS_GOOD;
}
long C_GPH_INFO::Query(int WhatToDo,
C_SELSET *pSelSet, long BitForFAS, C_FAS *pFAS ,
C_STRING *pRptTemplate, C_STRING *pRptFile, const TCHAR *pRptMode,
int CounterToVideo)
{ GS_ERR_COD = eGSInvClassType; return -1; }
int C_GPH_INFO::ApplyQuery(C_GPH_OBJ_ARRAY &Objs, int CounterToVideo)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::QueryIn(C_GPH_OBJ_ARRAY &Objs, C_SELSET *pSelSet,
long BitForFAS, C_FAS *pFAS, int CounterToVideo)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::Report(C_GPH_OBJ_ARRAY &Objs, C_STRING &Template,
C_STRING &Path, const TCHAR *Mode)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::Preview(C_GPH_OBJ_ARRAY &Objs, long BitForFAS, C_FAS *pFAS)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::Save(void)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::editnew(ads_name sel_set)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
bool C_GPH_INFO::HasCompatibleGeom(AcDbObject *pObj, bool TryToExplode, AcDbVoidPtrArray *pExplodedSet)
{ GS_ERR_COD = eGSInvClassType; return false; }
bool C_GPH_INFO::HasValidGeom(AcDbEntity *pObj, C_STRING &WhyNotValid)
{ return false; }
bool C_GPH_INFO::HasValidGeom(AcDbEntityPtrArray &EntArray, C_STRING &WhyNotValid)
{ return false; }
/*********************************************************/
/*.doc bool C_GPH_INFO::HasCompatibleGeom <external> /*
/*+
Questa funzione verifica che la geometria di un oggetto grafico
sia compatibile al tipo di risorsa grafica usata.
Parametri:
ads_name ent; oggetto grafico
bool TryToExplode; Opzionale; flag di esplosione. Nel caso l'oggetto
grafico non sia compatibile vine esploso per ridurlo
ad oggetti semplici (default = false)
C_SELSET *pExplodedSS; Opzionale; Puntatore a risultato
dell'esplosione (default = NULL)
Restituisce true se l'oggetto ha una geometria compatibile altrimenti false.
-*/
/*********************************************************/
bool C_GPH_INFO::HasCompatibleGeom(ads_name ent, bool TryToExplode, C_SELSET *pExplodedSS)
{
AcDbObjectId objId;
AcDbObject *pObj;
bool Result;
AcDbVoidPtrArray ExplodedSet;
ads_name ExplodedEnt;
if (pExplodedSS) pExplodedSS->clear();
if (acdbGetObjectId(objId, ent) != Acad::eOk) return false;
if (acdbOpenObject(pObj, objId, AcDb::kForRead, true) != Acad::eOk) return false;
Result = HasCompatibleGeom(pObj, TryToExplode, &ExplodedSet);
pObj->close();
if (Result && TryToExplode && pExplodedSS && ExplodedSet.length() > 0)
for (int i = 0; i < ExplodedSet.length(); i++)
{
if (acdbGetAdsName(ExplodedEnt, ((AcDbObject *) ExplodedSet[i])->objectId()) == Acad::eOk)
pExplodedSS->add(ExplodedEnt);
}
return Result;
}
/*********************************************************/
/*.doc bool C_GPH_INFO::HasValidGeom <external> /*
/*+
Questa funzione verifica che la validità della geometria di un oggetto grafico.
Parametri:
ads_name ent; oggetto grafico
Restituisce true se l'oggetto ha una geometria troppo complessa altrimenti false.
-*/
/*********************************************************/
bool C_GPH_INFO::HasValidGeom(ads_name ent, C_STRING &WhyNotValid)
{
AcDbObjectId objId;
AcDbObject *pObj;
bool Result;
if (acdbGetObjectId(objId, ent) != Acad::eOk) return false;
if (acdbOpenObject(pObj, objId, AcDb::kForRead, true) != Acad::eOk) return false;
Result = HasValidGeom((AcDbEntity *) pObj, WhyNotValid);
pObj->close();
return Result;
}
bool C_GPH_INFO::HasValidGeom(C_SELSET &entSS, C_STRING &WhyNotValid)
{
C_SELSET GraphSS;
AcDbEntityPtrArray EntArray;
bool Result;
entSS.copyIntersectType(GraphSS, GRAPHICAL); // scarto le etichette
if (GraphSS.get_AcDbEntityPtrArray(EntArray) == GS_BAD) return false;
Result = HasValidGeom(EntArray, WhyNotValid);
if (gsc_close_AcDbEntities(EntArray) == GS_BAD) return GS_BAD;
return Result;
}
int C_GPH_INFO::Check(int WhatOperation)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_GPH_INFO::Detach(void)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
/****************************************************************************/
/*.doc C_GPH_INFO::reportHTML <external> */
/*+
Questa funzione stampa su un file html i dati della C_GPH_INFO.
Parametri:
FILE *file; Puntatore a file
bool SynthMode; Opzionale. Flag di modalità di report.
Se = true attiva il report sintetico (default = false)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/****************************************************************************/
int C_GPH_INFO::reportHTML(FILE *file, bool SynthMode)
{
C_STRING TitleBorderColor("#808080"), TitleBgColor("#c0c0c0");
C_STRING BorderColor("#00CCCC"), BgColor("#99FFFF");
if (SynthMode) return GS_GOOD;
if (fwprintf(file, _T("\n<table bordercolor=\"%s\" bgcolor=\"%s\" width=\"100%%\" border=\"1\">"),
TitleBorderColor.get_name(), TitleBgColor.get_name()) < 0)
{ GS_ERR_COD = eGSWriteFile; return GS_BAD; }
// "Caratteristiche Grafiche"
if (fwprintf(file, _T("\n<tr><td align=\"center\"><b><font size=\"3\">%s</font></b></td></tr></table><br>"),
gsc_msg(752)) < 0)
{ GS_ERR_COD = eGSWriteFile; return GS_BAD; }
// intestazione tabella
if (fwprintf(file, _T("\n<table bordercolor=\"%s\" cellspacing=\"2\" cellpadding=\"2\" border=\"1\">"),
BorderColor.get_name()) < 0)
{ GS_ERR_COD = eGSWriteFile; return GS_BAD; }
// "Sistema coordinate"
if (fwprintf(file, _T("\n<tr><td align=\"right\" bgcolor=\"%s\"><b>%s:</b></td><td>%s</td></tr>"),
BgColor.get_name(), gsc_msg(722),
(coordinate_system.len() == 0) ? _T(" ") : coordinate_system.get_name()) < 0)
{ GS_ERR_COD = eGSWriteFile; return GS_BAD; }
// fine tabella
if (fwprintf(file, _T("\n</table><br><br>")) < 0)
{ GS_ERR_COD = eGSWriteFile; return GS_BAD; }
return GS_GOOD;
}
int C_GPH_INFO::Backup(BackUpModeEnum Mode, int MsgToVideo)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
/****************************************************************************/
/*.doc C_GPH_INFO::getLocatorReportTemplate <external> */
/*+
Questa funzione resrituisce il template di default per individuare la
posizione degli oggetti grafici.
Parametri:
C_STRING &Template; Stringa contenente il template
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/****************************************************************************/
int C_GPH_INFO::getLocatorReportTemplate(C_STRING &Template)
{
C_CLASS *pCls;
C_ID *pId;
// Ritorna il puntatore alla classe cercata
if ((pCls = gsc_find_class(prj, cls, sub)) == NULL) return GS_BAD;
pId = pCls->ptr_id();
switch (pId->category)
{
case CAT_SIMPLEX:
switch (pId->type)
{
case TYPE_POLYLINE:
Template = _T(".X1,.Y1,.Z1,.X2,.Y2,.Z2");
break;
case TYPE_TEXT:
Template = _T(".LABELPT");
break;
case TYPE_NODE:
Template = _T(".CENTER");
break;
case TYPE_SURFACE:
Template = _T(".CENTROID");
break;
default:
GS_ERR_COD = eGSInvClassType;
return GS_BAD;
}
break;
default:
GS_ERR_COD = eGSInvClassType;
return GS_BAD;
}
return GS_GOOD;
}
int C_GPH_INFO::get_isCoordToConvert(void)
{ return GS_BAD; }
/*****************************************************************************/
/*.doc C_GPH_INFO::gsc_get_UnitCoordConvertionFactor <internal> */
/*+
Questa funzione restituisce il fattore moltiplicativo per convertire le unità delle coordinate
degli oggetti dal sistema nel DB a quello della sessione di lavoro.
Ritorna 1 = nessuna correzione, 0 = non inizializzato
-*/
/*****************************************************************************/
double C_GPH_INFO::get_UnitCoordConvertionFactorFromClsToWrkSession(void)
{
if (UnitCoordConvertionFactorFromClsToWrkSession != 0) // se il valore è già stato inizializzato
return UnitCoordConvertionFactorFromClsToWrkSession;
if (!GS_CURRENT_WRK_SESSION)
UnitCoordConvertionFactorFromClsToWrkSession = 0;
else
UnitCoordConvertionFactorFromClsToWrkSession = gsc_get_UnitCoordConvertionFactor(get_ClsSRID_unit(),
GS_CURRENT_WRK_SESSION->get_SRID_unit());
return UnitCoordConvertionFactorFromClsToWrkSession;
}
/*****************************************************************************/
/*.doc C_GPH_INFO::get_ClsSRID_converted_to_AutocadSRID <internal> */
/*+
Questa funzione carica lo SRID in formato Autocad e le unità del
sistema di coordinate della classe.
Restituisce il puntatore allo SRID della classe convertito (se possibile)
nello SRID gestito da Autocad.
-*/
/*****************************************************************************/
C_STRING *C_GPH_INFO::get_ClsSRID_converted_to_AutocadSRID(void)
{ GS_ERR_COD = eGSInvClassType; return NULL; }
/*****************************************************************************/
/*.doc C_GPH_INFO::get_ClsSRID_unit <internal> */
/*+
Questa funzione restituisce l'unita del sistema di coordinate dello SRID della classe.
-*/
/*****************************************************************************/
GSSRIDUnitEnum C_GPH_INFO::get_ClsSRID_unit(void)
{
get_ClsSRID_converted_to_AutocadSRID();
return ClsSRID_unit;
}
///////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI C_GPH_INFO