-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_QUERY.CPP
13226 lines (11161 loc) · 524 KB
/
GS_QUERY.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_QUERY.CPP
Module description: File funzioni di base per l'inserimento,
l'aggiornamento e l'interrogazione, filtro
per le entità GEOSIM.
Author: Roberto Poltini
(c) Copyright 1995-2015 by IREN ACQUA GAS S.p.A.
**********************************************************/
/**********************************************************/
/* INCLUDE */
/**********************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
#include <ctype.h>
#include "rxdefs.h"
#include "adslib.h"
#include <adeads.h>
#include <dbmain.h>
#include <dbpl.h>
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h"
#include "gs_opcod.h"
#include "gs_utily.h"
#include "gs_resbf.h"
#include "gs_list.h"
#include "gs_ase.h"
#include "gs_dbref.h"
#include "gs_init.h"
#include "gs_user.h"
#include "gs_class.h"
#include "gs_prjct.h"
#include "gs_area.h"
#include "gs_graph.h"
#include "gs_attbl.h" // gestione blocchi attributi visibili
#include "gs_lisp.h"
#include "gs_cmd.h"
#include "gs_sec.h" // gestione tabelle secondarie
#include "gs_query.h"
#include "gs_lock.h"
#include "gs_setv.h"
#include "gs_ade.h"
#include "gs_dwg.h" // gestione disegni
#include "gs_topo.h"
#include "gs_evid.h"
#if defined(GSDEBUG) // se versione per debugging
#include <sys/timeb.h> // Solo per debug
#include <time.h> // Solo per debug
double tempo=0, tempo1=0, tempo2=0, tempo3=0, tempo4=0, tempo5=0, tempo6=0, tempo7=0;
double tempo8=0, tempo9=0, tempo10=0, tempo11=0, tempo12=0, tempo13=0, tempo14=0;
#endif
/*************************************************************************/
/* GLOBAL VARIABLES */
/*************************************************************************/
int GS_CURRENT_OPERATION = NONE; // codice operazione corrente di GEOsim
/*************************************************************************/
/* PRIVATE FUNCTIONS */
/*************************************************************************/
int gsc_is_group_existing(C_CLASS *pCls, C_CLS_PUNT_LIST *p_cls_punt_list);
int gsc_is_group_existing(C_CLASS *pCls, C_2INT_LONG_LIST &memberList);
static int gsc_areActionsOnErase(TCHAR *usr_cmds);
static int gsc_doActionOnInsert(const TCHAR *UsrFunction, ads_name ent, presbuf info,
C_RB_LIST *pColValues, short visib_block, int Reason = UNKNOWN_MOD);
static int gsc_doActionOnInsert(const TCHAR *UsrFunction, ads_name SelSet, C_RB_LIST *pColValues,
int Reason = UNKNOWN_MOD);
static int gsc_doActionOnUpdate(const TCHAR *UsrFunction, ads_name ent,
int Reason = UNKNOWN_MOD);
static int gsc_doActionOnUpdate(const TCHAR *UsrFunction, int cls, int sub, long gs_id,
C_RB_LIST *pColValues, int Reason = UNKNOWN_MOD);
static int gsc_doActionOnErase(const TCHAR *UsrFunction, ads_name Entity,
int Reason = UNKNOWN_MOD);
static int gsc_doActionOnErase(const TCHAR *UsrFunction, int cls, int sub, long gs_id,
int Reason = UNKNOWN_MOD);
int gsc_verify_topo_on_align_for_link(C_SUB *pLinkSub, ads_name LinkEnt,
C_SUB *pNewNode,
C_RB_LIST &NewNodeDefaultValues,
int NewNodeIsDefCalc,
_RecordsetPtr &pNewNodeInsRs,
C_CLS_PUNT **pInitNode, int *NewInitNode,
C_CLS_PUNT **pFinalNode, int *NewFinalNode);
int gsc_insBlockAttrib(C_CLASS *pClass, C_SELSET &ssPR, C_SELSET &ssDA,
long BitForChangeToNewFAS, C_FAS *pNewFas,
C_RB_LIST &ColValues);
int gsc_getDefAttrFromGSblock(ads_name BlockGs, TCHAR *NameAttr, C_RB_LIST &DefAttr);
/////////////// FUNZIONI PER AMBIENTE LISP ////////////////////////
/*********************************************************/
/*.doc gs_ins_data <external> */
/*+
Inserisce una scheda nella tabella temporanea della classe e
visualizza gli attributi visibili attivando il collegamento
tra grafica e tabelle.
Parametri:
Per classi NON gruppo:
Lista RESBUF (<cls><sub><ename>[((<nome colonna><valore>) ...)[<visib. blocco attr>]])
Per classi gruppo:
Lista RESBUF (<cls><SelSet>[((<nome colonna><valore>) ...)])
Restituisce codice nuova entità in caso di successo, GS_CAN in caso di annullamento
altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gs_ins_data(void)
{
presbuf arg = acedGetArgs();
C_RB_LIST ColValues;
int cls, sub, rc, visib_block = VISIBLE;
ads_name newent;
long new_code;
C_CLASS *pCls;
acedRetNil();
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return RTERROR; }
// codice classe
if (!arg || arg->restype != RTSHORT)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
cls = (int) arg->resval.rint;
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(cls)) == NULL) return RTERROR;
if (pCls->get_category() == CAT_GROUP) // classe gruppo
{
C_CLS_PUNT_LIST lista_cls;
if ((arg = arg->rbnext) == NULL || arg->restype != RTPICKS)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
// lista oggetti grafici che compongono il gruppo
if (lista_cls.from_ss(arg->resval.rlname) == GS_BAD) return RTERROR;
// lista <nome colonna><valore> (opzionale)
if ((arg = arg->rbnext) == NULL)
{ // leggo scheda di default
if (pCls->get_default_values(ColValues, (C_SELSET *) NULL) == GS_BAD) return RTERROR;
}
else
{
if (arg->restype != RTLB)
{ // leggo scheda di default
if (pCls->get_default_values(ColValues, (C_SELSET *) NULL) == GS_BAD) return RTERROR;
}
else
// lista <nome colonna><valore>
if ((ColValues << gsc_listcopy(arg, &arg)) == NULL)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
}
// inserimento gruppo
if ((rc = pCls->ins_data(&lista_cls, ColValues, &new_code)) == GS_BAD)
return RTERROR;
else if (rc == GS_CAN) return RTCAN;
}
else // non si tratta di classe gruppo
{
// codice sotto-classe
if ((arg = arg->rbnext) == NULL || arg->restype != RTSHORT)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
sub = (int) arg->resval.rint;
// nome oggetto grafico
if ((arg = arg->rbnext) == NULL)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype != RTENAME) { GS_ERR_COD=eGSInvRBType; return RTERROR; }
ads_name_set(arg->resval.rlname, newent);
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(cls, sub)) == NULL) return RTERROR;
// lista <nome colonna><valore> (opzionale)
if ((arg = arg->rbnext) == NULL)
{ // leggo scheda di default
if (pCls->get_default_values(ColValues, newent) == GS_BAD) return RTERROR;
}
else
{
if (arg->restype != RTLB)
{ // leggo scheda di default
if (pCls->get_default_values(ColValues, newent) == GS_BAD) return RTERROR;
}
else
// lista <nome colonna><valore>
if ((ColValues << gsc_listcopy(arg, &arg)) == NULL)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
// blocco attributi visibile (opzionale)
if ((arg = arg->rbnext) != NULL)
{
if (arg->restype != RTSHORT) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
visib_block = (int) arg->resval.rint;
}
}
if ((rc = pCls->ins_data(newent, ColValues, &new_code, visib_block)) == GS_BAD)
return RTERROR;
else if (rc == GS_CAN) return RTCAN;
}
acedRetReal((double) new_code);
return RTNORM;
}
/*********************************************************/
/*.doc gs_aggr_data <external> */
/*+
Aggrega un gruppo di selezione ad una entità già esistente
Parametri:
Lista RESBUF (<newSS><oldent>)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gs_aggr_data(void)
{
presbuf arg = acedGetArgs();
ads_name newSS, oldent;
long code;
C_CLASS *pCls;
acedRetNil();
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return RTERROR; }
// gruppo di selezione oggetti grafici nuovi
if (!arg) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype != RTPICKS) { GS_ERR_COD = eGSInvRBType; return RTERROR; }
ads_name_set(arg->resval.rlname, newSS);
// nome oggetto grafico a cui aggregarsi
if ((arg = arg->rbnext) == NULL)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype != RTENAME) { GS_ERR_COD=eGSInvRBType; return RTERROR; }
ads_name_set(arg->resval.rlname, oldent);
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(oldent)) == NULL) return RTERROR;
if (gsc_startTransaction() == GS_BAD) return GS_BAD;
if (pCls->aggr_data(newSS, oldent, &code) == GS_BAD)
{ gsc_abortTransaction(); return RTERROR; }
if (gsc_endTransaction() == GS_BAD) return RTERROR;
acedRetReal((double) code);
return RTNORM;
}
/*********************************************************/
/*.doc gs_disaggr_data <external> */
/*+
Disgrega una entità. Se l'entità da disgregare
è un blocco DA, questo verrà cancellato.
Parametri:
Lista RESBUF (<ent>|<selection set> [<CounterToVideo>])
Restituisce il numero di oggetti disaggregati in caso di successo altrimenti nil.
-*/
/*********************************************************/
int gs_disaggr_data(void)
{
presbuf arg = acedGetArgs();
ads_name ent;
int CounterToVideo;
long Refused, i, dummy;
C_CLASS *pCls;
C_SELSET ss;
C_STATUSBAR_PROGRESSMETER StatusBarProgressMeter(gsc_msg(1080)); // "Disgregazione entità"
acedRetNil();
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return RTERROR; }
// gruppo di selezione oggetti grafici nuovi
if (!arg) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype == RTENAME) ss.add(arg->resval.rlname);
else if (arg->restype == RTPICKS) ss.add_selset(arg->resval.rlname);
else { GS_ERR_COD = eGSInvRBType; return RTERROR; }
if ((arg = arg->rbnext) && arg->restype == RTNIL) CounterToVideo = GS_BAD;
else CounterToVideo = GS_GOOD;
Refused = i = 0;
if (CounterToVideo == GS_GOOD)
StatusBarProgressMeter.Init(ss.length());
while (ss.entname(i++, ent) == GS_GOOD)
{
if (CounterToVideo == GS_GOOD)
StatusBarProgressMeter.Set(i);
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(ent)) != NULL)
// se si tratta di un blocco DA lo cancello
if (gsc_is_DABlock(ent) == GS_GOOD)
{
if (pCls->erase_data(ent) != GS_GOOD) Refused++;
}
else
if (pCls->disaggr_data(ent, &dummy) != GS_GOOD) Refused++;
}
i--;
if (CounterToVideo == GS_GOOD)
{
StatusBarProgressMeter.End(gsc_msg(1090)); // "Terminato."
if (i >= 0)
acutPrintf(gsc_msg(308), i, Refused); // "\n%ld entità GEOsim elaborate, %ld scartate."
}
acedRetReal(i - Refused);
return RTNORM;
}
/*********************************************************/
/*.doc gs_query_data <external> */
/*+
Interroga la scheda dell'entita' della classe.
Parametri:
Lista RESBUF (ename oggetto grafico)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gs_query_data(void)
{
presbuf arg = acedGetArgs();
C_RB_LIST ColValues;
ads_name entity;
C_CLASS *pCls;
int cls;
acedRetNil();
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return GS_BAD; }
// nome oggetto grafico (per aggiornare da video)
if (!arg || arg->restype == RTENAME)
{
ads_name_set(arg->resval.rlname, entity);
pCls = GS_CURRENT_WRK_SESSION->find_class(arg->resval.rlname);
if (pCls->query_data(arg->resval.rlname, ColValues) == GS_BAD) return RTERROR;
}
else if (gsc_rb2Int(arg, &cls) == GS_GOOD) // codice classe
{
long gs_id;
int sub;
// codice sottoclasse
if (!(arg = arg->rbnext) || gsc_rb2Int(arg, &sub) == GS_BAD)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(cls, sub)) == NULL) return RTERROR;
// gs_id
if (!(arg = arg->rbnext) || gsc_rb2Lng(arg, &gs_id) == GS_BAD)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
if (pCls->query_data(gs_id, ColValues) != GS_GOOD)
return RTERROR;
}
else
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
ColValues.remove_head(); ColValues.remove_tail();
ColValues.LspRetList();
return RTNORM;
}
/*********************************************************/
/*.doc gs_upd_data <external> */
/*+
Aggiorna la scheda dell'entita' della classe.
Parametri:
Lista RESBUF:
(ename oggetto grafico) (<lista valori>))
oppure
(gs_id (<lista valori>))
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gs_upd_data(void)
{
presbuf arg;
int cls, sub = 0;
C_RB_LIST ColValues;
acedRetNil();
if (!(arg = acedGetArgs())) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype == RTENAME)
{
if (!arg->rbnext || arg->rbnext->restype != RTLB)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
// lista valori
ColValues << gsc_rblistcopy(arg->rbnext);
if (gsc_upd_data(arg->resval.rlname, ColValues) == GS_BAD) return RTERROR;
}
else if (gsc_rb2Int(arg, &cls) == GS_GOOD) // codice classe
{
C_CLASS *pCls;
long gs_id;
// codice sottoclasse
if (!(arg = arg->rbnext) || gsc_rb2Int(arg, &sub) == GS_BAD)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(cls, sub)) == NULL) return RTERROR;
// gs_id
if (!(arg = arg->rbnext) || gsc_rb2Lng(arg, &gs_id) == GS_BAD)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
// lista valori
if (!(arg = arg->rbnext) || arg->restype != RTLB)
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
ColValues << gsc_rblistcopy(arg);
if (pCls->upd_data(gs_id, ColValues, NULL, RECORD_MOD) != GS_GOOD)
return RTERROR;
}
else
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
acedRetT();
return RTNORM;
}
/*********************************************************/
/*.doc gs_erase_data <external> */
/*+
Cancella gli oggetti grafici delle entita' della/e classe/i
se ultima entità cancella anche la scheda associata.
Parametri:
Lista RESBUF <ent>
Per classi gruppo:
Lista RESBUF <cls><ent>
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gs_erase_data(void)
{
presbuf arg = acedGetArgs();
C_EED eed;
C_CLASS *pCls;
acedRetNil();
// nome oggetto grafico (per aggiornare da video)
if (!arg) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (arg->restype != RTENAME)
{
int cls;
long KeyVal;
C_PREPARED_CMD pTempLnkCmd, pOldLnkCmd;
C_LONG_LIST KeyGroupList;
C_LONG *pKeyComp;
// codice classe gruppo
if (arg->restype != RTSHORT) { GS_ERR_COD = eGSInvalidArg; return RTERROR; }
cls = arg->resval.rint;
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(cls)) == NULL) return RTERROR;
if (pCls->get_category() != CAT_GROUP) // deve essere gruppo
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
if (!(arg = arg->rbnext) || arg->restype != RTENAME)
{ GS_ERR_COD = eGSInvalidArg; return RTERROR; }
/////////////////////////////////////////////////////////////////////////
// Compilo le istruzioni di lettura dei codici dei gruppi legati ad un membro
if (pCls->prepare_reldata_where_member(pTempLnkCmd, TEMP) == GS_BAD) return RTERROR;
if (pCls->prepare_reldata_where_member(pOldLnkCmd, OLD) == GS_BAD) return RTERROR;
if (eed.load(arg->resval.rlname) == GS_BAD)
{ GS_ERR_COD = eGSGEOsimObjNotFound; return RTERROR; }
if (gsc_getKeyValue(arg->resval.rlname, &KeyVal) == GS_BAD) return RTERROR;
// leggo i codici dei gruppi legati a questa entità
if (pCls->get_group_list(pTempLnkCmd, pOldLnkCmd, eed.cls, KeyVal, KeyGroupList) == GS_BAD)
return RTERROR;
// ciclo per ogni gruppo
pKeyComp = (C_LONG *) KeyGroupList.get_head();
while (pKeyComp)
{
pCls->erase_data(pKeyComp->get_id());
pKeyComp = (C_LONG *) KeyGroupList.get_next();
}
}
else
{
if (eed.load(arg->resval.rlname) == GS_BAD)
{ GS_ERR_COD = eGSGEOsimObjNotFound; return RTERROR; }
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(eed.cls, eed.sub)) == NULL) return RTERROR;
if (pCls->erase_data(arg->resval.rlname) == GS_BAD) return RTERROR;
}
acedRetT();
return RTNORM;
}
/////////////// FUNZIONI PER AMBIENTE C ////////////////////////
int set_GS_CURRENT_OPERATION(int Value)
{
int OldValue = GS_CURRENT_OPERATION;
GS_CURRENT_OPERATION = Value;
return OldValue;
}
/*********************************************************/
/*.doc gsc_upd_data <external> */
/*+
Aggiorna una entità.
Parametri:
ads_name entity; nome oggetto grafico
C_RB_LIST &ColValues; Lista ((<nome colonna><valore>) ...)
oppure:
int cls; Classe
int sub; Sottoclasse
long gs_id; Codice scheda
C_RB_LIST &ColValues; Lista ((<nome colonna><valore>) ...)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gsc_upd_data(ads_name entity, C_RB_LIST &ColValues)
{
C_CLASS *pCls;
C_EED eed;
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return NULL; }
if (eed.load(entity) == GS_BAD)
{ GS_ERR_COD = eGSGEOsimObjNotFound; return GS_BAD; }
// Ritorna il puntatore alla classe cercata
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(eed.cls, eed.sub)) == NULL) return GS_BAD;
return pCls->upd_data(entity, ColValues);
}
/*********************************************************/
/*.doc gsc_UpdDataForSave <external> */
/*+
Funzione speciale di aggiornamento da lanciare durante il salvataggio qualora
esistano degli attributi calcolati da GS_ID per le sole entità appartenenti
a classi C_SIMPLEX.
Parametri:
C_CLASS *pCls; Puntatore alla classe
C_RB_LIST &ColValues; Lista ((<nome colonna><valore>) ...)
C_SELSET &EntSS; Gruppo di selezione dell'entità
C_STRING &SubstUpdUsrFun; Eventuale funzione di virtualizzazione
C_STRING &BeforeUpdUsrFun; Eventuale funzione di virtualizzazione
C_STRING &AfterUpdFun; Eventuale funzione di virtualizzazione
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gsc_UpdDataForSave(C_CLASS *pCls, C_RB_LIST &ColValues, C_SELSET &EntSS,
C_STRING &SubstUpdUsrFun, C_STRING &BeforeUpdUsrFun, C_STRING &AfterUpdFun)
{
int result = GS_BAD, OldOp;
int Cls = pCls->ptr_id()->code, Sub = pCls->ptr_id()->sub_code;
presbuf p;
TCHAR *KeyAttrib = pCls->ptr_info()->key_attrib.get_name();
long Key;
// Setto l'operazione corrente
OldOp = set_GS_CURRENT_OPERATION(MODIFY);
// estraggo il codice entità
if ((p = ColValues.CdrAssoc(KeyAttrib)) == NULL || gsc_rb2Lng(p, &Key) == GS_BAD)
return GS_BAD;
// validazione e ricalcolo dati
if (pCls->CalcValidData(ColValues, MODIFY, &EntSS) == GS_BAD) return GS_BAD;
// eventuale chiamata ad una funzione utente esterna (prima della modifica o in
// completa sostituzione della funzione di GEOsim)
if (SubstUpdUsrFun.len() > 0)
return gsc_doActionOnUpdate(SubstUpdUsrFun.get_name(), Cls, Sub, Key,
&ColValues, RECORD_MOD);
if (BeforeUpdUsrFun.len() > 0)
{
if (gsc_doActionOnUpdate(BeforeUpdUsrFun.get_name(), Cls, Sub, Key,
&ColValues, RECORD_MOD) == GS_BAD) return GS_BAD;
// validazione e ricalcolo dati ("gsc_doActionOnUpdate" potrebbe cambiare qualcosa)
if (pCls->CalcValidData(ColValues, MODIFY, &EntSS) == GS_BAD) return GS_BAD;
}
if (pCls->updtoDA(EntSS, ColValues) == GS_BAD) return GS_BAD;
// se esistono funzioni di calcolo grafico vengono applicate ora
if (pCls->graph_calc(ColValues, &EntSS) == GS_BAD) return GS_BAD;
// eventuale chiamata ad una funzione utente esterna (dopo la modifica)
if (AfterUpdFun.len() > 0)
if (gsc_doActionOnUpdate(AfterUpdFun.get_name(), Cls, Sub, Key,
&ColValues, RECORD_MOD) == GS_BAD)
return GS_BAD;
// Notifico in file log
TCHAR Msg[MAX_LEN_MSG];
swprintf(Msg, MAX_LEN_MSG, _T("Updated entity (on saving): key %ld, prj %d, class %d, subclass %d."),
Key, pCls->ptr_id()->pPrj->get_key(), Cls, Sub);
gsc_write_log(Msg);
// Setto l'operazione corrente
set_GS_CURRENT_OPERATION(OldOp);
return GS_GOOD;
}
/*********************************************************/
/* INIZIO FUNZIONI DELLA CATEGORIA C_SIMPLEX */
/*********************************************************/
/*****************************************************************************/
/*.doc C_SIMPLEX::ins_data <external> */
/*+
Inserisce una scheda nella tabella temporanea della classe e
visualizza gli attributi visibili attivando il collegamento
tra grafica e tabelle.
Parametri:
C_CLS_PUNT_LIST *lista_cls; Nuovo oggetto grafico; se si tratta di superfici
il secondo oggetto rappresenta il riempimento
C_RB_LIST &ColValues; Lista ((<nome colonna><valore>) ...)
long *gs_id; Nuovo codice entità (default = NULL)
int visib_block; Visibilità blocco se = INVISIBLE invisibile altrimenti
visibile (default = VISIBLE)
int Reason; Origine della modifica sugli oggetti: GEOMETRY_MOD, FAS_MOD,
RECORD_MOD, UNKNOWN_MOD, NO_EXTERN_ACTION (flag a bit)
(default = UNKNOWN_MOD)
_RecordsetPtr *pRsIns; RecordSet per inserimento dati (in caso
di inserimenti multipli); default = NULL.
C_BTREE *pPtObjsBTree = NULL; non usato, solo per compatibilità con C_SUB::ins_data
Restituisce GS_GOOD in caso di successo, GS_CAN in caso di annullamento
altrimenti restituisce GS_BAD.
N.B. : il primo oggetto grafico della lista <lista_cls> viene sostituito con
un altro oggetto grafico uguale ma con differente handle e con le entità estese
di GEOsim. L'inserimento dell'oggetto grafico nel database di autocad
dovrebbe avvenire con le entità estese di GEOsim per gestire l'UNDO
-*/
/*****************************************************************************/
int C_SIMPLEX::ins_data(ads_name lista_ent, C_RB_LIST &ColValues, long *gs_id,
int visib_block, int Reason, _RecordsetPtr pRsIns, C_BTREE *pPtObjsBTree)
{
C_CLS_PUNT_LIST lista_cls;
C_CLS_PUNT *p;
long len;
// Converto una lista di ename in una lista C_CLS_PUNT_LIST
if (ads_sslength(lista_ent, &len) != RTNORM)
{
len = 0;
// è una sola entità
if ((p = new C_CLS_PUNT(this, lista_ent)) == NULL) { GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
lista_cls.add_tail(p);
}
else
{ // è un gruppo di selezione
ads_name ent;
for (long i = 0; i < len; i++)
{
if (acedSSName(lista_ent, i, ent) != RTNORM) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if ((p = new C_CLS_PUNT(this, ent)) == NULL) { GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
lista_cls.add_tail(p);
}
}
int ret = ins_data(&lista_cls, ColValues, gs_id, visib_block, Reason, pRsIns);
if (len == 0)
ads_name_set(((C_CLS_PUNT *) lista_cls.get_head())->ent, lista_ent);
else
{
ads_ssfree(lista_ent);
lista_cls.to_ssgroup(lista_ent);
}
return ret;
}
int C_SIMPLEX::ins_data(C_CLS_PUNT_LIST *lista_cls, C_RB_LIST &ColValues, long *gs_id,
int visib_block, int Reason, _RecordsetPtr pRsIns, C_BTREE *pPtObjsBTree)
{
C_ATTRIB_LIST *p_attrib_list = ptr_attrib_list();
C_EED eed;
int result = GS_BAD, InsRecord = FALSE, InsLink = FALSE, OldOp;
C_LINK Link, OrigLink;
ads_name NewEnt, newDABlock;
long new_key;
presbuf pKey;
C_CLS_PUNT *pEntCls;
C_STRING UsrFunction;
C_RB_LIST InfoList;
#if defined(GSDEBUG) // se versione per debugging
struct _timeb t1, t2;
#endif
// verifico l'abilitazione dell' utente;
if (gsc_check_op(opInsEntity) == GS_BAD) return GS_BAD;
#if defined(GSDEBUG) // se versione per debugging
_ftime(&t1);
#endif
if (!lista_cls || lista_cls->get_count() == 0)
{ GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (!GS_CURRENT_WRK_SESSION) { GS_ERR_COD = eGSNotCurrentSession; return GS_BAD; }
if (GS_CURRENT_WRK_SESSION->isReadyToUpd(&GS_ERR_COD) != GS_GOOD) return GS_BAD;
if (id.abilit != GSUpdateableData)
{
GS_ERR_COD = (id.abilit == GSReadOnlyData) ? eGSClassIsReadOnly : eGSClassLocked;
return GS_BAD;
}
ads_name_set(((C_CLS_PUNT *) lista_cls->get_head())->ent, NewEnt);
ads_name_clear(newDABlock);
if (!(pKey = ColValues.CdrAssoc(ptr_info()->key_attrib.get_name()))) return GS_BAD;
// verifico che gli oggetti grafici non siano già di "GEOsim"
pEntCls = (C_CLS_PUNT *) lista_cls->get_head();
while (pEntCls)
{
// controllo che la tipologia sia giusta.
if (check_graph_compatib(pEntCls->ent) == GS_BAD)
{ GS_ERR_COD = eGSOpNotAble; return GS_BAD; }
// verifico che l'oggetto grafico non sia già legato ad un record di questa classe
if (eed.load(pEntCls->ent) == GS_GOOD || getKeyValue(pEntCls->ent, &new_key) == GS_GOOD)
{ GS_ERR_COD = eGSGEOsimObjFound; return GS_BAD; }
pEntCls = (C_CLS_PUNT*) lista_cls->get_next();
}
// Setto l'operazione corrente
OldOp = set_GS_CURRENT_OPERATION(INSERT);
do
{
// ricavo codice per prossimo inserimento
if ((new_key = GetNewEntCode()) >= 0) break;
// modifico <key_attrib>
gsc_RbSubst(pKey, new_key);
// eventuale chiamata ad una funzione utente esterna (prima dell'inserimento o in
// completa sostituzione della funzione di GEOsim)
if (gsc_getAction(id.usr_cmds, STR_SUBST, STR_INSERT, UsrFunction) == GS_GOOD &&
UsrFunction.len() > 0)
{
if (!InfoList.get_head())
if ((InfoList << acutBuildList(RTLB, RTSHORT, id.code, RTSHORT, id.sub_code, RTLE, 0)) == NULL)
break;
if (gsc_doActionOnInsert(UsrFunction.get_name(), NewEnt, InfoList.get_head(),
&ColValues, visib_block, Reason) == GS_BAD) break;
result = GS_GOOD;
break;
}
else
if (gsc_getAction(id.usr_cmds, STR_BEFORE, STR_INSERT, UsrFunction) == GS_GOOD &&
UsrFunction.len() > 0)
{
if (!InfoList.get_head())
if ((InfoList << acutBuildList(RTLB, RTSHORT, id.code, RTSHORT, id.sub_code, RTLE, 0)) == NULL)
break;
if (gsc_doActionOnInsert(UsrFunction.get_name(), NewEnt, InfoList.get_head(),
&ColValues, visib_block, Reason) == GS_BAD) break;
}
eed.cls = id.code;
eed.sub = id.sub_code;
eed.num_el = lista_cls->get_count(); // fattore di aggregazione
eed.gs_id = new_key;
// Collego il primo oggetto grafico alla tabella senza inserirlo nel gruppo
// di selezione del salvataggio
if (OrigLink.Set(NewEnt, id.code, id.sub_code, new_key, INSERT) == GS_BAD) break;
InsLink = TRUE; // inserimento link avvenuto
// inserisco etichette "entità di GEOsim" senza inserirlo nel gruppo
// di selezione del salvataggio
if (eed.save(NewEnt, GS_BAD) == GS_BAD) break;
C_SELSET SelSet;
SelSet.add(NewEnt);
// Collego gli oggetti grafici successivi alla tabella temp
result = GS_GOOD;
pEntCls = (C_CLS_PUNT*) lista_cls->getptr_at(2);
while (pEntCls)
{
if (OrigLink.Set(pEntCls->ent, id.code, id.sub_code, new_key, INSERT) == GS_BAD)
{ result = GS_BAD; break; }
// inserisco etichette "entità di GEOsim" agli oggetti grafici
// che vengono aggiunti in GEOsimAppl::SAVE_SS per salvataggio
if (eed.save(pEntCls->ent) == GS_BAD) { result = GS_BAD; break; }
SelSet.add(pEntCls->ent);
pEntCls = (C_CLS_PUNT*) pEntCls->get_next();
}
if (result == GS_BAD) break;
result = GS_BAD;
// Se esiste qualche azione sull'evento cancellazione
if (gsc_areActionsOnErase(id.usr_cmds) == GS_GOOD)
{
// Faccio la copia di una sola entità e cancello la vecchia (è sufficiente una sola)
// perchè l'inserimento dell'oggetto grafico nel database di autocad
// dovrebbe avvenire con le entità estese di GEOsim per gestire l'UNDO.
if (gsc_DeepClone2ModSpace(NewEnt) != GS_GOOD || gsc_EraseEnt(NewEnt) != GS_GOOD)
{ GS_ERR_COD = eGSErrorExecutingCommand; break; }
if (acdbEntLast(NewEnt) != RTNORM) { GS_ERR_COD = eGSInvEntityOp; break; }
// sostituisco entità nella lista degli oggetti grafici (parametro della funzione)
ads_name_set(NewEnt, ((C_CLS_PUNT*) lista_cls->get_head())->ent);
// Collego il nuovo oggetto grafico alla tabella
if (Link.Set(NewEnt, id.code, id.sub_code, new_key, INSERT) == GS_BAD)
{ result = GS_BAD; break; }
// inserisco etichetta "entità di GEOsim" al nuovo oggetto grafico
// che viene aggiunto in GEOsimAppl::SAVE_SS per salvataggio
if (eed.save(NewEnt) == GS_BAD) { result = GS_BAD; break; }
}
// inserisco record in tabella (fa anche il ricalcolo e la validazione)
if (ins_row(ColValues, NULL, NULL, pRsIns, &SelSet) == GS_BAD) break;
InsRecord = TRUE; // inserimento record avvenuto
if (gs_id) *gs_id = new_key;
if (id.type != TYPE_TEXT &&
visib_block == VISIBLE && p_attrib_list->is_visible() == GS_GOOD)
{
C_RB_LIST VisValues;
C_ATTRIB_BLOCK attrib_block;
C_SET_VISIB *pActiveSet = NULL;
eed.num_el++; // + 1 scheda attributi
// ricavo gli attributi visibili
if ((VisValues << p_attrib_list->get_vis_values(ColValues)) == GS_BAD)
break;
if (attrib_block.set_layer(ptr_fas()->layer) == GS_BAD) break;
// altezza testo degli attributi del blocco
if (attrib_block.set_h_text(ptr_fas()->h_text) == GS_BAD) break;
// stile testo degli attributi del blocco
if (attrib_block.set_text_style(ptr_fas()->style) == GS_BAD) break;
// colore
if (attrib_block.set_color(ptr_fas()->color) == GS_BAD) break;
if (GEOsimAppl::GLOBALVARS.get_InsPos() == AUTO)
{
ads_point point;
double rot;
if (id.type == TYPE_POLYLINE) // punto medio tratto + lungo
{
if (gsc_getPntRtzOnObj(NewEnt, point, &rot, _T("MML"), 0, 0, GS_GOOD) == GS_BAD) break;
}
else if (id.type == TYPE_NODE) // punto di inserimento
{
if (gsc_getPntRtzOnObj(NewEnt, point, &rot, _T("S"), 0, 0, GS_GOOD) == GS_BAD) break;
}
else if (id.type == TYPE_SURFACE) // centroide
{
if (gsc_getPntRtzOnObj(NewEnt, point, &rot, _T("C"), 0, 0, GS_GOOD) == GS_BAD) break;
}
else break;
attrib_block.set_insert_point(point);
attrib_block.set_rotation(gsc_rad2grd(rot));
}
if ((result = attrib_block.insert(VisValues, id.code, id.sub_code, new_key,
ptr_fas()->file_ref_block, ptr_fas()->ref_block,
GEOsimAppl::GLOBALVARS.get_InsPos(),
eed.num_el)) != GS_GOOD)
break;
result = GS_BAD;
// inserimento blocco attributi avvenuto
if (acdbEntLast(newDABlock) != RTNORM) { GS_ERR_COD = eGSInvEntityOp; break; }
// aggiorno il n. di aggregazioni "entità di GEOsim" a oggetti grafici
result = GS_GOOD;
pEntCls = (C_CLS_PUNT *) lista_cls->get_head();
while (pEntCls)
{
if (eed.save(pEntCls->ent) == GS_BAD) { result = GS_BAD; break; }
pEntCls = (C_CLS_PUNT*) lista_cls->get_next();
}
if (result == GS_BAD) break;
result = GS_BAD;
}
else
if (id.type == TYPE_TEXT)
// aggiorno il testo
if (updtoDA(NewEnt, ColValues, GS_GOOD) == GS_BAD) break;
// se esistono funzioni di calcolo grafico vengono applicate ora
if (graph_calc(ColValues) == GS_BAD) break;
// eventuale chiamata ad una funzione utente esterna (dopo l'inserimento)
if (gsc_getAction(id.usr_cmds, STR_AFTER, STR_INSERT, UsrFunction) == GS_GOOD &&
UsrFunction.len() > 0)
{
if (!InfoList.get_head())
if ((InfoList << acutBuildList(RTLB, RTSHORT, id.code, RTSHORT, id.sub_code, RTLE, 0)) == NULL)
break;
if (gsc_doActionOnInsert(UsrFunction.get_name(), NewEnt, InfoList.get_head(),
&ColValues, visib_block, Reason) == GS_BAD) break;
}
gsc_addEnt2savess(NewEnt);
setModified(GS_GOOD); // classe modificata
// Notifico in file log
TCHAR Msg[MAX_LEN_MSG];
swprintf(Msg, MAX_LEN_MSG, _T("Inserted entity: key %ld, prj %d, class %d, subclass %d."),
new_key, GS_CURRENT_WRK_SESSION->get_PrjId(), id.code, id.sub_code);
gsc_write_log(Msg);
result = GS_GOOD;
}
while (0);
if (result != GS_GOOD)
{
if (InsLink) // se erano stati inseriti i link
{
ads_name OrigEnt;
pEntCls = (C_CLS_PUNT *) lista_cls->get_head(); // cancellazione dei link
// se la prima entità è diversa da quella di OrigLink
// significa che era stata cancellata
OrigLink.GetEnt(OrigEnt);