-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_IMPOR.CPP
2484 lines (2087 loc) · 95.9 KB
/
GS_IMPOR.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_IMPORT
Module description: File contenente le funzioni per
l'importazione e l'esportazione dati GEOsim.
Author: Paolo De Sole, Poltini Roberto.
(c) Copyright 1995-2015 by IREN ACQUA GAS S.p.A.
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 <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <fcntl.h> /* per _open() */
#include <sys\stat.h> /* per _open() */
#include "adslib.h"
#include "adsdlg.h"
#include "..\gs_def.h" // definizioni globali
#include "gs_utily.h" // (gsc_strcat, gsc_tostring)
#include "gs_resbf.h" // (gsc_nth)
#include "gs_error.h" // codici errori
#include "gs_list.h"
#include "gs_ase.h" // gestione database
#include "gs_init.h" // direttori globali
#include "gs_opcod.h"
#include "gs_user.h"
#include "gs_dbref.h"
#include "gs_cmd.h"
#include "gs_class.h"
#include "gs_prjct.h"
#include "gs_area.h"
#include "gs_graph.h"
#include "gs_query.h"
#include "gs_attbl.h"
#include "gs_lisp.h"
#include "gs_sql.h"
#include "gs_evid.h"
#include "gs_impor.h"
#include "gs_sec.h"
#if defined(GSDEBUG) // se versione per debugging
#include <sys/timeb.h> // Solo per debug
#include <time.h> // Solo per debug
#endif
// Definizioni
#define SKIPHANDLETOONE // Se definito utilizzo il tapullo dell' handle - 1
// per ricavare i DA (Mtext) dagli oggetti di AutoCAD.
// V A R I A B I L I G L O B A L I
// La seguente mi serve per memorizzare lo stato dei LPN coinvolti nelle operazioni di IMPORT
// C_2STR_INT_LIST LPNACTIVATED;
C_2STR_INT_LIST LPN_USER_STATUS;
// D E F I N I Z I O N E F U N Z I O N I
int gsc_isAcMapAnnotation(ads_name obj);
int gsc_queryAcadObject(ads_name ent, C_STRING &nameLPN, C_RB_LIST &ColValues,
int RemoveLPN, CAseLinkSel *pLS = NULL);
int analyzingLPN(C_STR_LIST *pLPNList);
int objectIsLinked(ads_name ent, C_STR_LIST *pLPNList, C_STRING &nameValidLPN);
int gsc_objectIsODLinked(ads_name ent, C_STR_LIST *pValidODList, C_STRING &ValidODTable);
int gsc_isValidExternalLPN(const TCHAR *NameLPN, CAseLinkPath &InternalLPN);
int is_enableLPN(C_STRING &lpName);
int gsc_ImportBlocksFromFile(FILE *pFile, bool Unicode, C_CLASS *pClass,
C_DBCONNECTION *pConn = NULL, C_STRING *pTable = NULL,
C_STRING *pKeyAttr = NULL);
int gsc_ImportTextsFromFile(FILE *pFile, bool Unicode, C_CLASS *pClass,
C_DBCONNECTION *pConn = NULL, C_STRING *pTable = NULL,
C_STRING *pKeyAttr = NULL);
int gsc_ImportPlinesFromFile(FILE *pFile, bool Unicode, C_CLASS *pClass,
C_DBCONNECTION *pConn = NULL, C_STRING *pTable = NULL,
C_STRING *pKeyAttr = NULL);
//////////////////////////////////////////////////////////////////////////////////////
/*********************************************************/
/*.doc objectIsLinked() <internal> */
/*+
Questa funzione determina se l' oggetto passato in input
ha dei Lpn, e in casi positivo restituisce il LPN
valido. In caso di più Lpn restituisce il primo valido.
Param:
ads_name ent Oggetto da controllare (input)
C_STR_LIST *pValidLPNList; Puntatore alla lista dei LPN validi (input)
C_STRING &ValidLPN; Nome del LPN per la lettura (out)
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int objectIsLinked(ads_name ent, C_STR_LIST *pValidLPNList, C_STRING &ValidLPN)
{
int is_linked = GS_BAD;
C_STR_LIST LPNames;
ValidLPN.clear();
// Leggo i LPT usati da questa entità
if (!pValidLPNList || gsc_getLinkNames(ent, LPNames) == GS_BAD) return GS_BAD;
if (LPNames.get_count() > 0)
{
C_STR *pLPName = (C_STR *) LPNames.get_head();
while (pLPName)
{
if (pValidLPNList->search_name(pLPName->get_name(), FALSE) != NULL)
{ is_linked = GS_GOOD; ValidLPN = pLPName->get_name(); break; }
pLPName = (C_STR *) pLPName->get_next();
}
}
return is_linked;
}
/*********************************************************/
/*.doc gsc_objectIsODLinked <internal> */
/*+
Questa funzione determina se l' oggetto passato in input
ha delle tabelle OD, e in caso positivo restituisce il nome della
tabella valida. In caso di più tabelle restituisce la prima.
Param:
ads_name ent Oggetto da controllare (input)
C_STR_LIST *pValidODList; Puntatore alla lista delle tabelle OD valide (input)
C_STRING &ValidODTable; Nome della tabella OD per la lettura (out)
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_objectIsODLinked(ads_name ent, C_STR_LIST *pValidODList, C_STRING &ValidODTable)
{
int is_linked = GS_BAD;
C_STR_LIST ODTables;
ValidODTable.clear();
// Leggo i LPT usati da questa entità
if (!pValidODList || gsc_getODTables(ent, ODTables) == GS_BAD) return GS_BAD;
if (ODTables.get_count() > 0)
{
C_STR *pODTable = (C_STR *) ODTables.get_head();
while (pODTable)
{ // No sensitive
if (pValidODList->search_name(pODTable->get_name(), GS_BAD) != NULL)
{ is_linked = GS_GOOD; ValidODTable = pODTable->get_name(); break; }
pODTable = (C_STR *) pODTable->get_next();
}
}
return is_linked;
}
/*******************************************************/
/*.doc int gsc_importFromFile(void) */
/*+
Funzione base che importa degli oggetti leggendo le
caratteristiche da un file specificato (compresa la path)
nel parametro fileName.
Parametri:
C_CLASS *pCls Puntatore alla classe di destinazione;
C_STRING &fileName Path completa del file delle specifiche;
C_DBCONNECTION *pConn; Opzionale, se presente indica il riferimento
ad un database da cui leggere gli attributi
(Default = NULL)
C_STRING *pTable; Se pConn è valido, indica la tabella da cui
leggere gli attributi (Default = NULL)
C_STRING *pKeyAttr; Se pConn è valido, indica l'attributo chiave
per leggere i valori degli attributi che trovano
corrispondenza con quelli della classe (Default = NULL)
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_importFromFile(C_CLASS *pCls, C_STRING &fileName,
C_DBCONNECTION *pConn, C_STRING *pTable, C_STRING *pKeyAttr)
{
FILE *pFile;
long posiz;
int result = GS_BAD;
bool Unicode;
// Verifico l'abilitazione dell'utente;
if (gsc_check_op(opImportEntity) == GS_BAD) return GS_BAD;
// Apro il file in lettura
if ((pFile = gsc_open_profile(fileName, READONLY, MORETESTS, &Unicode)) == NULL) return GS_BAD;
// Cerco il profilo BLOCK, se non lo trovo cerco LINE, se non lo
// trovo cerco TEXT, se non trovo neanche quest' ultimo il file non va bene.
if (gsc_find_sez(pFile, _T("BLOCK"), 5, &posiz, Unicode) == GS_GOOD)
{
if (pCls->get_category() == CAT_SPAGHETTI ||
pCls->get_type() == TYPE_NODE)
result = gsc_ImportBlocksFromFile(pFile, Unicode, pCls, pConn, pTable, pKeyAttr);
else
GS_ERR_COD = eGSInvClassType;
}
else if (gsc_find_sez(pFile, _T("LINE"), 4, &posiz) == GS_GOOD)
{
if (pCls->get_category() == CAT_SPAGHETTI ||
pCls->get_type() == TYPE_POLYLINE)
result = gsc_ImportPlinesFromFile(pFile, Unicode, pCls, pConn, pTable, pKeyAttr);
else
GS_ERR_COD = eGSInvClassType;
}
else if (gsc_find_sez(pFile, _T("TEXT"), 4, &posiz) == GS_GOOD)
{
if (pCls->get_category() == CAT_SPAGHETTI ||
pCls->get_type() == TYPE_TEXT)
result = gsc_ImportTextsFromFile(pFile, Unicode, pCls, pConn, pTable, pKeyAttr);
else
GS_ERR_COD = eGSInvClassType;
}
else
GS_ERR_COD = eGSSezNotFound;
if (gsc_fclose(pFile) == GS_BAD) return GS_BAD;
return result;
}
/*******************************************************/
/*.doc int gsc_importFromGraph */
/*+
Funzione base che importa degli oggetti in GEOsim.
Parametri:
ads_name SelSet Gruppo di selezione degli oggetti da importare;
C_CLASS *pCls Puntatore alla classe di destinazione;
int ObjGEOsimLoad Flag per importare oggetti di GEOsim;
long BitForChangeToNewFAS; Opzionale, Flag a bit per indicare quali caratteristiche
grafiche cambiare
C_FAS *pNewFas; Opzionale, i valori delle caratteristiche grafiche da cambiare
C_STR_LIST *pLPNList Lista nomi LPT esterni a GEOsim che possono essere
utilizzati per la lettura dei dati da DB esterno
int RemoveLPN Flag per cancellare il LPN dall' oggetto;
C_STR_LIST *pODTableList;
int RemoveODData;
bool ReadAttrBlk; Flag di importazione; se = true e se non è stato scelto
di leggere i valori degli attributi da link a db esterno
vengono letti eventuali valori degli attributi dei blocchi
che si stanno importando (default = false).
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_importFromGraph(ads_name SelSet, C_CLASS *pCls, int ObjGEOsimLoad,
long BitForChangeToNewFAS, C_FAS *pNewFas,
C_STR_LIST *pLPNList, int RemoveLPN,
C_STR_LIST *pODTableList, int RemoveODData, bool ReadAttrBlk)
{
_RecordsetPtr pInsRs;
C_SELSET SelectionSet, Considered, ssGraph, ssDA;
C_CLASS *pObjClass = NULL;
C_STRING nameLPN, ODTable, BlockName;
C_RB_LIST RbToIns, RbDefault, RbReaded;
C_EED eed;
ads_name ent;
long index = 0, numObj = 0, notLoaded = 0, Loaded = 0, tmp = 0;
long OBJloaded = 0, OBJnotloaded = 0, a = 0, b = 0, OBJlocked = 0;
int result, flagLocked;
CAseLinkSel ls(GEOsimAppl::ASE);
C_FAS *pFas = (pNewFas) ? pNewFas : pCls->ptr_fas();
// Verifico l'abilitazione dell'utente;
if (gsc_check_op(opImportEntity) == GS_BAD) return GS_BAD;
// Per comodità mi metto il gruppo di selezione passato come parametro
// in un oggetto della classe C_SELSET.
SelectionSet.add_selset(SelSet);
// se non esistono i layer della classe li creo prima di gsc_startTransaction sennò autocad dà problemi
if (BitForChangeToNewFAS & GSLayerSetting)
if (gsc_crea_layer(pFas->layer) == GS_BAD) return GS_BAD;
if (pCls->get_type() == TYPE_SURFACE &&
BitForChangeToNewFAS & GSHatchLayerSetting)
if (gsc_crea_layer(pFas->hatch_layer) == GS_BAD) return GS_BAD;
// creo coumunque il layer perchè il blocco degli attributi potrebbe essere inserito nuovo
if (BitForChangeToNewFAS & GSDABlockLayerSetting)
{
if (gsc_crea_layer(pFas->layer) == GS_BAD) return GS_BAD;
}
else
if (gsc_crea_layer(pCls->ptr_fas()->layer) == GS_BAD) return GS_BAD;
// Start Undo
if (gsc_startTransaction() == GS_BAD) return GS_BAD;
// Eseguo una prima scrematura degli oggetti che posso eliminare subito.
if (gsc_RemoveInvalidObject(SelectionSet, pCls, ObjGEOsimLoad) == GS_BAD) return GS_BAD;
// Per prima cosa, se la classe di destinazione ha una attrib_list
// mi memorizzo la scheda di default, per passarla alla funzione di import,
// e mi ricavo già il record set per l'inserimento nella classe di destinazione
if (pCls->ptr_attrib_list() != NULL)
{
if (pCls->ptr_attrib_list()->get_StaticDefValues(RbDefault) == GS_BAD) return GS_BAD;
if (pCls->prepareInsRs(pInsRs, TEMP) == GS_BAD) return GS_BAD;
}
// Poi, se la lista dei LPN contiene almeno un LPN richiamo la funzione
// di verifica ed eventuale attivazione recordset.
if (pLPNList && pLPNList->get_count() > 0)
if (analyzingLPN(pLPNList) == GS_BAD) return GS_BAD;
Considered.clear();
C_STATUSBAR_PROGRESSMETER StatusBarProgressMeter(gsc_msg(344)); // "Importazione entità"
StatusBarProgressMeter.Init(SelectionSet.length());
index = 0;
result = GS_GOOD;
while (SelectionSet.entname(index++, ent) == GS_GOOD)
{
StatusBarProgressMeter.Set(index);
// Se è un oggetto che ho già preso in considerazione lo salto
if (Considered.is_member(ent) == GS_GOOD) continue;
// Se è un blocco DA lo salto
if (gsc_isAcMapAnnotation(ent) == GS_GOOD) continue;
// Svuoto i due gruppi (Principali e Schede)
ssGraph.clear();
ssDA.clear();
nameLPN.clear();
ODTable.clear();
pObjClass = NULL;
// Devo verificare se l' oggetto preso in considerazione è linkato con
// un record di un DB esterno
if (eed.load(ent) == GS_BAD)
{
if (pCls->ptr_attrib_list() != NULL)
{
if (pLPNList && pLPNList->get_count() > 0)
{
if (objectIsLinked(ent, pLPNList, nameLPN) == GS_BAD)
// Verifico se si devono leggere dati OD
if (pODTableList && pODTableList->get_count() > 0)
gsc_objectIsODLinked(ent, pODTableList, ODTable);
}
else // Verifico se si devono leggere dati OD
if (pODTableList && pODTableList->get_count() > 0)
gsc_objectIsODLinked(ent, pODTableList, ODTable);
}
}
else
if ((pObjClass = gsc_find_class(GS_CURRENT_WRK_SESSION->get_PrjId(), eed.cls, eed.sub)) == NULL)
{ result = GS_BAD; break; }
// Se pObjClass è NULL allora ent non è di GEOsim.
// Se pObjClass è diverso da NULL allora vado a vedere se ha la
// p_attrib_list che vuol dire che è da interrogare.
// Devo tenere conto che in Colvalues ho già memorizzato la scheda di Default
// Della classe di destinazione, se l' oggetto è interrogabile allora
// per l' importazione devo utilizzare l' RB_list che ricvavo dall' interrogazione.
RbToIns.remove_all();
if (pCls->ptr_attrib_list() != NULL) // Se classe con collegamento a DB
{
// Ricavo da ent le entità legate (Principali e Schede)
if (gsc_load_Princ_and_DABlk(SelectionSet, ent, nameLPN, ssGraph, ssDA,
&pObjClass, &ls) == GS_BAD)
{ result = GS_BAD; break; }
Considered.add_selset(ssDA);
if (pObjClass) // entità di GEOsim
{
if (pObjClass->ptr_attrib_list())
{
if (pObjClass->query_data(ent, RbReaded) == GS_BAD ||
RbToRbOnlyFieldCompatible(pCls, RbReaded, RbToIns) == GS_BAD)
RbDefault.copy(RbToIns);
}
else // Sono nel caso degli spaghetti
RbDefault.copy(RbToIns);
}
else // entità non appartenente a GEOsim
{
if ((nameLPN.len() > 0) && (is_enableLPN(nameLPN) == GS_GOOD))
{
// Interrogo l' oggetto di Acad, se va male l' interrogazione,
// oppure va bene ma fallisce la funzione che ricava i valori
// del resbuf compatibili mi ripristino la scheda di default
if (gsc_queryAcadObject(ent, nameLPN, RbReaded, RemoveLPN, &ls) == GS_BAD ||
RbToRbOnlyFieldCompatible(pCls, RbReaded, RbToIns) == GS_BAD)
RbDefault.copy(RbToIns);
}
else
{
C_RB_LIST ColValues;
RbDefault.copy(RbToIns);
// Verifico se l'oggetto è colegato a tabelle OD
if (ODTable.len() > 0)
{
// Leggo i valori OD
if (gsc_getValuesFromODTable(ent, ODTable, ColValues) == GS_GOOD)
if (RemoveODData == GS_GOOD) // se richiesto cancello il dato OD apppena letto
gsc_delID2ODTable(ent, ODTable);
}
else
{
// Se si vogliono leggere gli attributi dei blocchi e
// si stanno importando dei blocchi verifico se
// questi hanno degli attributi
if (ReadAttrBlk && gsc_isblock(ent) == GS_GOOD &&
pCls->get_category() == CAT_SIMPLEX && pCls->get_type() == TYPE_NODE)
{
C_ATTRIB_BLOCK AttrBlk(ent);
AttrBlk.get_values_attrib(ColValues);
}
}
// Se sono stati letti dei valori li sostituisco a quelli di default
if (ColValues.GetCount() > 0)
{
int i = 0;
presbuf pRbAttr, pRbAttrName, pRbAttrValue;
C_ATTRIB *pAttrib;
while ((pRbAttr = ColValues.nth(i++)))
{
pRbAttrName = gsc_nth(0, pRbAttr);
pRbAttrValue = gsc_nth(1, pRbAttr);
pAttrib = (C_ATTRIB *) pCls->ptr_attrib_list()->search_name(pRbAttrName->resval.rstring, FALSE);
if (pAttrib && pAttrib->CheckValue(pRbAttrValue) == GS_GOOD)
RbToIns.CdrAssocSubst(pAttrib->name.get_name(), // nome attributo
pRbAttrValue); // valore attributo
}
}
}
}
}
else
ssGraph.add(ent);
Considered.add_selset(ssGraph);
flagLocked = GS_BAD;
numObj = a + b;
tmp = notLoaded = Loaded = 0;
// Richiamo la funzione di importazione
if ((tmp = pCls->import_data(ssGraph, ssDA, ObjGEOsimLoad,
BitForChangeToNewFAS, pFas,
RbToIns, pObjClass, pInsRs, &flagLocked)) == GS_BAD)
{
notLoaded = numObj - tmp;
if (flagLocked == GS_GOOD)
OBJlocked++;
}
else
{
C_SINTH_SEC_TAB_LIST SrcSinthSecList, DstSinthSecList;
long EntKey;
if (pObjClass)
// leggo la lista delle tabelle secondarie
pObjClass->get_pPrj()->getSinthClsSecondaryTabList(pObjClass->ptr_id()->code, pObjClass->ptr_id()->sub_code,
SrcSinthSecList);
pCls->get_pPrj()->getSinthClsSecondaryTabList(pCls->ptr_id()->code, pCls->ptr_id()->sub_code,
DstSinthSecList);
DstSinthSecList.FilterOnType(GSInternalSecondaryTable);
// Se la classe sorgente ha delle tabelle secondarie e
// la classe destinazione ha delle tabelle secondarie interne
if (SrcSinthSecList.get_count() > 0 && DstSinthSecList.get_count() > 0)
{
C_SINTH_SEC_TAB *pSrcSinthSec, *pDstSinthSec;
// Per ogni secondaria interna di destinazione
pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_head();
while (pDstSinthSec)
{
// Se esiste una secondaria sorgente con lo stesso nome
if ((pSrcSinthSec = (C_SINTH_SEC_TAB *) SrcSinthSecList.search_name(pDstSinthSec->get_name(), FALSE)))
{
C_SECONDARY *pSrcSec, *pDstSec;
presbuf pSrckeyPri, pSrcColValues;
C_RB_LIST SrcSecColValues, SrcSecColValuesList, DstSecColValues;
if (!(pSrcSec = (C_SECONDARY *) pObjClass->find_sec(pSrcSinthSec->get_key())) ||
!(pDstSec = (C_SECONDARY *) pCls->find_sec(pSrcSinthSec->get_key())))
{ pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_next(); continue; }
// Cerco il valore della chiave dell'entità sorgente
if (!(pSrckeyPri = RbReaded.CdrAssoc(pSrcSec->ptr_info()->key_pri.get_name())))
{ pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_next(); continue; }
// leggo tutte le schede secondarie dell'entità sorgente
if (pSrcSec->query_AllData(pSrckeyPri, SrcSecColValuesList) == GS_BAD)
{ pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_next(); continue; }
// Cerco il valore della chiave dell'entità destinazione
if (gsc_rb2Lng(RbToIns.CdrAssoc(pCls->ptr_info()->key_attrib.get_name()), &EntKey) == GS_BAD)
{ pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_next(); continue; }
SrcSecColValuesList.remove_head(); // cancello la prima tonda
SrcSecColValuesList.remove_tail(); // cancello l'ultima tonda
pSrcColValues = SrcSecColValuesList.get_head();
while (pSrcColValues)
{
SrcSecColValues << gsc_listcopy(pSrcColValues);
if (RbToRbOnlyFieldCompatible(pDstSec, SrcSecColValues, DstSecColValues) == GS_GOOD)
pDstSec->ins_data(EntKey, DstSecColValues, NULL, FALSE);
if ((pSrcColValues = gsc_scorri(pSrcColValues))) // vado alla chiusa tonda successiva
pSrcColValues = pSrcColValues->rbnext;
}
}
pDstSinthSec = (C_SINTH_SEC_TAB *) DstSinthSecList.get_next();
}
}
Loaded = tmp;
}
OBJloaded = OBJloaded + Loaded;
OBJnotloaded = OBJnotloaded + notLoaded;
}
StatusBarProgressMeter.End(gsc_msg(70), --index); // "%ld oggetti grafici elaborati."
// Stampo se ho trovato oggetti bloccati da un' altro utente.
if (OBJlocked > 0)
// "\nIl comando non è stato eseguito su %d oggetto(i) perchè bloccato(i) da un'altro utente."
acutPrintf(gsc_msg(76), OBJlocked);
// "\nIl comando è stato eseguito correttamente su %ld oggetti grafici."
acutPrintf(gsc_msg(562), OBJloaded);
if (result == GS_GOOD)
{
gsc_endTransaction();
ade_errclear();
}
else gsc_abortTransaction();
return result;
}
/*******************************************************/
/*.doc int gsc_isValidExternalLPN() */
/*+
Funzione base per verificare ed inizializzare un LPN.
Parametri:
const TCHAR *NameLPN Nome del LPN da inizializzare;
CAseLinkPath &InternalLPN
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_isValidExternalLPN(const TCHAR *NameLPN, CAseLinkPath &InternalLPN)
{
int Status;
if (InternalLPN.initName(NameLPN) != kAsiGood) // non è utilizzabile
return GS_BAD;
Status = InternalLPN.getStatus();
if (!(Status & ASE_DO_REG) || // The DO is registered (has at least one Link Path).
!(Status & ASE_DO_EXIST) || // The DO exists in the SQL database (can be
// assigned if the Environment is connected in ASE).
!(Status & ASE_DO_CON)) // The DO belongs to the connected environment
{
// provo a collegare il LPN con l'ambiente ASE se necessario
if (gsc_LPNConnectAse(InternalLPN, (TCHAR *) GEOsimAppl::GS_USER.log,
(TCHAR *) GEOsimAppl::GS_USER.pwd) == GS_BAD)
return GS_BAD;
// Check whether the table already exists
if (!(InternalLPN.getStatus() & ASE_DO_EXIST))
{ GS_ERR_COD = eGSTableNotExisting; return GS_BAD; }
}
return GS_GOOD;
}
/*******************************************************/
/*.doc int gsc_queryAcadObject() */
/*+
Funzione base interroga un oggetto di AutoCAD.
Parametri:
ads_name ent Oggetto da interrogare;
CAseLinkPath &nameLPN LinkPathName;
C_RB_LIST &ColValues Rb_list risultato della query;
int RemoveLPN
CAseLinkSel *pLS; (default = NULL)
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_queryAcadObject(ads_name ent, C_STRING &nameLPN, C_RB_LIST &ColValues,
int RemoveLPN, CAseLinkSel *pLS)
{
CAsiRow *pKeyCols = NULL, *pRowBuffer = NULL;
CAsiUcStr AsiUcrStr;
TCHAR FldName[MAX_LEN_FIELDNAME];
C_STRING CorrectedFldName;
CAseLinkPath InternalLPN(GEOsimAppl::ASE);
CAseLink Link(GEOsimAppl::ASE);
LinkID ID;
CAsiSession *pTempSession = NULL;
CAsiCsr *pCsr = NULL;
CAseLinkSel *pInternalLS;
if (InternalLPN.initName(nameLPN.get_name()) != kAsiGood)
{ GS_ERR_COD = eGSInvalidLPN; return GS_BAD; }
if (InternalLPN.getKeyDsc(&pKeyCols) != kAsiGood)
{ GS_ERR_COD = eGSInvalidLPN; return GS_BAD; }
if (InternalLPN.getTableDsc(&pRowBuffer) != kAsiGood)
{ GS_ERR_COD = eGSInvalidLPN; return GS_BAD; }
if (pLS)
pInternalLS = pLS;
else
if ((pInternalLS = new CAseLinkSel(GEOsimAppl::ASE)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
if (pInternalLS->initLpEnt(nameLPN.get_name(), ent) != kAsiGood)
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
if ((ID = pInternalLS->getId(0)) == LINKID_NULL) // primo link del link set
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
// Inizializzo il Link Descriptor attraverso ent
if (Link.initId(ID) != kAsiGood)
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
if (Link.getKey(pKeyCols) != kAsiGood)
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
// commentato perchè dopo circa 480 volte si inchioda (baco MAP)
// if (InternalLPN.getRow(pKeyCols, pRowBuffer) != kAsiGood)
{
// #if defined(GSDEBUG) // se versione per debugging
// gsc_printASEErr(&InternalLPN);
// #endif
// se fallisce questa funzione (se i tipi tra LPN e DB non corrispondono
// la funzione fa casino) provo a fare la select SQL (valido solo per campo
// chiave numerico o carattere)
C_STRING statement;
statement = _T("SELECT * FROM ");
TCHAR Table[256];
InternalLPN.getName(Table, 255, kAseSQLCode);
statement += Table;
statement += _T(" WHERE ");
AsiUcrStr = GS_EMPTYSTR;
(*pKeyCols)[0].Name().ToString(&AsiUcrStr); // fa strcat
AsiUcrStr.getToChar(FldName, MAX_LEN_FIELDNAME - 1);
statement += FldName;
if ((*pKeyCols)[0].getData()->Type() == kAsiCharVar ||
(*pKeyCols)[0].getData()->Type() == kAsiChar)
{
TCHAR Value[256];
C_STRING dummy;
statement += _T("='");
if ((*pKeyCols)[0].getData()->getValue(Value, 255) == kAsiBad)
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
dummy = Value;
dummy.strtran(_T("'"), _T("''"));
statement += dummy.get_name();
statement += _T("'");
}
else
{
real Value;
statement += _T("=");
if ((*pKeyCols)[0].getData()->getValue(&Value) == kAsiBad)
{ if (!pLS) delete pInternalLS; GS_ERR_COD = eGSInvalidLink; return GS_BAD; }
statement += Value;
}
TCHAR UDL[256];
CAsiExecStm *pTempStm;
InternalLPN.getName(UDL, 255, kAseEnvCode);
if ((pTempSession = gsc_ASICreateSession(UDL)) == NULL)
{ if (!pLS) delete pInternalLS; return GS_BAD; }
if (gsc_ASIPrepareSql(pTempSession, statement.get_name(), UDL,
&pTempStm, &pCsr) == GS_BAD)
{ if (!pLS) delete pInternalLS; return GS_BAD; }
if (pCsr->Open() != kAsiGood)
{
if (!pLS) delete pInternalLS;
delete pCsr;
gsc_ASITermStm(&pTempStm);
gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
if (pCsr->Fetch() != kAsiGood ||
(pRowBuffer = pCsr->getCurrentRow()) == NULL)
{
if (!pLS) delete pInternalLS;
pCsr->Close();
delete pCsr;
gsc_ASITermStm(&pTempStm);
gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
gsc_ASITermStm(&pTempStm);
}
ColValues << acutBuildList(RTLB, 0);
for (int i = 0; i < pRowBuffer->ColNum(); i++)
{
AsiUcrStr = GS_EMPTYSTR;
(*pRowBuffer)[i].Name().ToString(&AsiUcrStr); // fa strcat
AsiUcrStr.getToChar(FldName, MAX_LEN_FIELDNAME - 1);
CorrectedFldName = FldName;
if (CorrectedFldName.get_chr(0) == _T('"')) // tolgo il primo e l'ultimo "
CorrectedFldName.removePrefixSuffix(_T("\""), _T("\""));
ColValues += acutBuildList(RTLB, RTSTR, CorrectedFldName.get_name(), 0);
if ((*pRowBuffer)[i].getData()->isNull() == kAsiGood)
ColValues += acutBuildList(RTNIL, RTLE, 0);
else
switch ((*pRowBuffer)[i].getData()->Type())
{
case kAsiDateTime:
case kAsiInterval:
{
DBTIMESTAMP Value;
CString dummyStr;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
DBDATE Value;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
DBTIME Value;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
if (!pLS) delete pInternalLS;
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
COleDateTime dummyOleDateTime(0, 0, 0, Value.hour, Value.minute, Value.second);
// "%c" = Date and time representation for current locale
dummyStr = dummyOleDateTime.Format(_T("%c"));
}
else
{
COleDateTime dummyOleDateTime(Value.year, Value.month, Value.day, 0, 0, 0);
// "%c" = Date and time representation for current locale
dummyStr = dummyOleDateTime.Format(_T("%c"));
}
}
else
{
COleDateTime dummyOleDateTime(Value.year, Value.month, Value.day,
Value.hour, Value.minute, Value.second);
// "%c" = Date and time representation for current locale
dummyStr = dummyOleDateTime.Format(_T("%c"));
}
ColValues += acutBuildList(RTSTR, dummyStr, RTLE, 0);
break;
}
case kAsiChar:
case kAsiCharVar:
case kAsiBit:
case kAsiBitVar:
{
CAsiUcStr Buffer;
if ((*pRowBuffer)[i].getData()->getValue(&Buffer) == kAsiBad)
{
if (!pLS) delete pInternalLS;
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
ColValues += acutBuildList(RTSTR, Buffer.UcStr(), RTLE, 0);
break;
}
case kAsiNumeric:
case kAsiDecimal:
case kAsiFloat:
case kAsiReal:
case kAsiDouble:
{
real Value;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
if (!pLS) delete pInternalLS;
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
ColValues += acutBuildList(RTREAL, Value, RTLE, 0);
break;
}
case kAsiInteger:
{
integer Value;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
if (!pLS) delete pInternalLS;
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
ColValues += acutBuildList(RTLONG, Value, RTLE, 0);
break;
}
case kAsiSmallInt:
{
smallint Value;
if ((*pRowBuffer)[i].getData()->getValue(&Value) == kAsiBad)
{
if (!pLS) delete pInternalLS;
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
GS_ERR_COD = eGSInvalidLink;
return GS_BAD;
}
ColValues += acutBuildList(RTSHORT, Value, RTLE, 0);
break;
}
default:
ColValues += acutBuildList(RTNIL, RTLE, 0);
}
}
ColValues += acutBuildList(RTLE, 0);
if (pCsr) { pCsr->Close(); delete pCsr; }
if (pTempSession) gsc_ASITermSession(&pTempSession);
if (RemoveLPN == GS_GOOD)
{
// La seguente istruzione serve a cancellare il LPN esterno dall'oggetto.
pInternalLS->erase();
}
if (!pLS) delete pInternalLS;
return GS_GOOD;
}
/*****************************************************/
/*.doc int gsc_load_Princ_and_DABlk() */
/*+
Funzione che, dato un oggetto e il nome di un LPN
ricava due gruppi di selezione, uno che rappresenta
le principali eventualmente legate allo stesso record
ed un' altro gruppo che rappresenta gli eventuali
blocchi DA.
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*****************************************************/
int gsc_load_Princ_and_DABlk(C_SELSET &ssAll, ads_name ent, C_STRING &lpnName,
C_SELSET &ssGraph, C_SELSET &ssDA, C_CLASS **pCObj,
CAseLinkSel *pLS)
{
C_EED eed;
C_SELSET tmp, ssLeader;
int result;
long key;
//long index, a, b;
//ads_name obj;
C_RB_LIST Descr;
// Devo stare attento ai seguenti casi:
// 1. caso di entità di GEOsim con DB
// 2. caso di entità di GEOsim senza DB
// 3. caso di entità non di GEOsim con DB
// 4. caso di entità non di GEOsim senza DB
if (eed.load(ent) == GS_GOOD)
{
do
{
result = GS_BAD;
// Se è un' entità di GEOsim allora per prima cosa ricavo il
// il puntatore alla classe originale
if (((*pCObj) = gsc_find_class(GS_CURRENT_WRK_SESSION->get_PrjId(), eed.cls, eed.sub)) == NULL) break;
// Se poi non è un' entità spaghetti vado a ricavare gli oggetti linkati
if ((*pCObj)->get_category() != CAT_SPAGHETTI)
{
// Ricavo il codice chiave
if ((*pCObj)->getKeyValue(ent, &key) == GS_BAD) break;
// Ricavo il gruppo di selezione degli oggetti principali
if ((*pCObj)->get_SelSet(key, ssGraph, GRAPHICAL) == GS_BAD) break;
// Ricavo il gruppo di selezione dei blocchi degli attributi visibili
if ((*pCObj)->get_SelSet(key, ssDA, DA_BLOCK) == GS_BAD) break;
}
else
ssGraph.add(ent);
result = GS_GOOD;
}
while (0);
}
else // entità non di GEOsim
if (lpnName.get_name() == NULL)
{
ssGraph.add(ent);
result = GS_GOOD;
}
else
{
CAseLinkSel *pInternalLS;
result = GS_BAD;
do
{
if (pLS)
pInternalLS = pLS;
else
if ((pInternalLS = new CAseLinkSel(GEOsimAppl::ASE)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; break; }
if (lpnName.get_name() &&
pInternalLS->initLpEnt(lpnName.get_name(), ent) == kAsiGood)
{
LinkID ID;
if ((ID = pInternalLS->getId(0)) != LINKID_NULL) // primo link del link set
{
CAseLink Link(GEOsimAppl::ASE);
CAseLinkPath LPN(GEOsimAppl::ASE);
CAsiRow *pKeyCols;
ads_name dummy_ssDA, dummy_ssGraph;
// Inizializzo il Link Descriptor attraverso ent
if (Link.initId(ID) != kAsiGood) break;
// Leggo il valore chiave
if (LPN.initName(lpnName.get_name()) != kAsiGood) break;
if (LPN.getKeyDsc(&pKeyCols) != kAsiGood) break;
if (Link.getKey(pKeyCols) != kAsiGood) break;
if (pInternalLS->initLpKey(lpnName.get_name(), pKeyCols, kAseEntityLink) != kAsiGood)
break;
if (pInternalLS->getEntSel(dummy_ssGraph) != kAsiGood) break;
ssGraph << dummy_ssGraph;
ssDA.clear();
if (pInternalLS->initLpKey(lpnName.get_name(), pKeyCols, kAseLeaderLink) == kAsiGood)
if (pInternalLS->getEntSel(dummy_ssDA) == kAsiGood) ssDA.add_selset(dummy_ssDA);
if (pInternalLS->initLpKey(lpnName.get_name(), pKeyCols, kAseDALink) == kAsiGood)
if (pInternalLS->getEntSel(dummy_ssDA) == kAsiGood) ssDA.add_selset(dummy_ssDA);