-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_GRAPH.CPP
19090 lines (16234 loc) · 663 KB
/
GS_GRAPH.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_GRAPH.CPP
Module description: File per interfaccia alle operazioni con la grafica
Author: Roberto Poltini
(c) Copyright 1995-2015 by IREN ACQUA GAS S.p.A.
Modification history:
Notes and restrictions on use:
**********************************************************/
/*********************************************************/
/* INCLUDES */
/*********************************************************/
#include "stdafx.h"
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <math.h>
#include <ctype.h> /* per isdigit() */
#include <fcntl.h>
#include <string.h> /* per strcat() strcmp() */
#include <limits>
#include "rxdefs.h"
#include "adslib.h"
#include <adeads.h>
#include "adsdlg.h"
#include "acutmem.h"
#include <actrans.h>
#include <aced.h>
#include <acdb.h>
#include <dbents.h>
#include <dbelipse.h>
#include <dblead.h>
#include <dbpl.h>
#include <dbray.h>
#include <dbsol3d.h>
#include <dbspline.h>
#include <dbxline.h>
#include <dbhatch.h>
#include <dbsymtb.h>
#include <dbidmap.h>
#include <dbapserv.h>
#include <dbMPolygon.h> // per centroidi
#include <AcMapUtilities.h> // per centroidi
#include "topoads.h" // per funzionalità topologiche
#include "acedCmdNF.h" // per acedCommandS
#include "gs_opcod.h" // codici delle operazioni
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h" // codici errori
#include "gs_resbf.h" // gestione resbuf
#include "gs_list.h" // gestione liste C++
#include "gs_dbref.h" // prototipi funzioni gestione riferimenti a db
#include "gs_init.h"
#include "gs_graph.h"
#include "gs_query.h"
#include "gs_attbl.h" // gestione blocchi attributi visibili
#include "gs_lisp.h" // per validita' e calcolo attributi
#include "gs_utily.h"
#include "gs_topo.h" // per "gsc_OverlapValidation"
#include "d2hMap.h" // doc to help
#if defined(GSDEBUG) // se versione per debugging
#include <sys/timeb.h> // Solo per debug
#include <time.h> // Solo per debug
#endif
/*************************************************************************/
/* GLOBAL VARIABLES */
/*************************************************************************/
double _SCALE, XSCALE, YSCALE, ROTA;
ads_point BASE, GS_POINT_CURSOR;
int GS_LAST_NODE_CLS=0; // CLASSE ULTIMO NODO INSERITO PER CLASSI simulazioni
int GS_LAST_NODE_SUB=0; // SOTTOCLASSE ULTIMO NODO INSERITO PER CLASSI simulazioni
C_CLASS *SEL_CLS; // PUNT. CLASSE O SOTTOCLASSE SCELTA //
C_CLASS *SEL_EXT; // PUNT. CLASSE-SIMULAZIONE SCELTA //
// struttura usata per scambiare dati nelle dcl "per inserimento dati"
struct Common_Dcl_DataIns_Struct
{
int mode;
C_CLS_PUNT_LIST SelClsList; // LISTA PUNT. CLASSI SELEZ.
C_CLS_PUNT_LIST SelSubList; // LISTA PUNT. SOTTOCLASSI SELEZ.
};
// INSERIMENTO ATTRIBUTI ENTITA'
///////////////////////////////////////
static ads_matrix ads_identmat = {
{1.0, 0.0, 0.0, 0.0},
{0.0, 1.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0},
{0.0, 0.0, 0.0, 1.0}
};
// VECCHIO VALORE VARIBILI GLOBALI EXPERT E CMDECHO
static int GS_LAST_ECHO, GS_LAST_EXPERT; // gsc_set_env_cmd() gsc_rest_env_cmd()
///////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS
const TCHAR *gsc_get_graphical_data_type(TCHAR *what);
double gsc_get_graphical_area(C_SELSET &SelSet);
int SelectGrid(ads_point pt, long *gs_id, C_CLS_PUNT_LIST &SelClsList);
int gsc_getSplitMode(ads_point pt, ads_name ent, C_INT_INT *punt);
int gsc_getPtList_BetweenPts(AcGePoint3d &ptStart, AcGePoint3d &ptEnd, double Bulge,
double DistanceFromStart, double Length,
C_POINT_LIST &PtList, double *MyLength = NULL);
/*********************************************************/
/*.doc gsc_zoom <extern> */
/*+
Effettua la funzione di ZOOM WINDOW.
Parametri:
AcGePoint2d min_2d; coordinate in basso a sx
AcGePoint2d max_2d; coordinate in alto a dx
ads_real min_dim_x; dimensione minima della finestra sull'asse x (default = 0)
ads_real min_dim_y; dimensione minima della finestra sull'asse y (default = 0)
-*/
/*********************************************************/
void gsc_zoom(ads_point min_2d, ads_point max_2d,
ads_real min_dim_x, ads_real min_dim_y)
{
AcGePoint2d _min_2d(min_2d[X], min_2d[Y]);
AcGePoint2d _max_2d(max_2d[X], max_2d[Y]);
gsc_zoom(_min_2d, _max_2d, min_dim_x, min_dim_y);
}
void gsc_zoom(AcGePoint2d min_2d, AcGePoint2d max_2d,
ads_real min_dim_x, ads_real min_dim_y)
{
AcDbViewTableRecord view;
if (min_dim_x > 0 && min_dim_y > 0)
{
double offset;
// correggo l'estensione della finestra se è troppo piccola
if ((max_2d.x - min_2d.x) < min_dim_x)
{
offset = (min_dim_x - (max_2d.x - min_2d.x)) / 2;
min_2d.x -= offset;
max_2d.x += offset;
}
if ((max_2d.y - min_2d.y) < min_dim_y)
{
offset = (min_dim_y - (max_2d.y - min_2d.y)) / 2;
min_2d.y -= offset;
max_2d.y += offset;
}
}
// now set the view centre point
view.setCenterPoint (min_2d + (max_2d - min_2d) / 2.0);
// now height and width of view
view.setHeight(max_2d[Y] - min_2d[Y]);
view.setWidth (max_2d[X] - min_2d[X]);
// set the view
acedSetCurrentView (&view, NULL);
// updates the extents
acdbHostApplicationServices()->workingDatabase()->updateExt(TRUE);
}
/*********************************************************/
/*.doc gsc_zoom_extents <extern> */
/*+
Effettua la funzione di ZOOM EXTENTS.
Parametri:
ads_real min_dim_x; dimensione minima della finestra sull'asse x (default = 0)
ads_real min_dim_y; dimensione minima della finestra sull'asse y (default = 0)
-*/
/*********************************************************/
void gsc_zoom_extents(ads_real min_dim_x, ads_real min_dim_y)
{
// get the extents of the drawing
AcGePoint3d max = acdbHostApplicationServices()->workingDatabase()->extmax();
AcGePoint3d min = acdbHostApplicationServices()->workingDatabase()->extmin();
AcGePoint2d max_2d(max[X], max[Y]);
AcGePoint2d min_2d(min[X], min[Y]);
return gsc_zoom(min_2d, max_2d);
}
/****************************************************************************/
/*.doc gsc_GrDrawCross */
/*+
Questa funzione disegna in modalità grdraw una croce nel punto indicato.
Parametri:
ads_point pt;
La funzione restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/****************************************************************************/
int gs_GrDrawCross(void)
{
presbuf arg = acedGetArgs();
acedRetNil();
if (!arg || (arg->restype != RTPOINT && arg->restype != RT3DPOINT))
{ GS_ERR_COD = eGSInvRBType; return RTERROR; }
if (gsc_GrDrawCross(arg->resval.rpoint) == GS_BAD)
return RTERROR;
acedRetT();
return RTNORM;
}
int gsc_GrDrawCross(ads_point pt)
{
double factor = 50, offset;
resbuf res;
ads_point p1, p2;
// leggo il valore di VIEWSIZE (altezza della finestra)
// e parametrizzo il valore della croce
if (acedGetVar(_T("VIEWSIZE"), &res) != RTNORM) return GS_BAD;
offset = res.resval.rreal / factor;
p1[Z] = p2[Z] = 0.0;
p1[X] = pt[X] - offset;
p1[Y] = pt[Y] + offset;
p2[X] = pt[X] + offset;
p2[Y] = pt[Y] - offset;
// disegno un ramo della croce
if (acedGrDraw(p1, p2, -1, 0) != RTNORM) return GS_BAD;
p1[X] = pt[X] - offset;
p1[Y] = pt[Y] - offset;
p2[X] = pt[X] + offset;
p2[Y] = pt[Y] + offset;
// disegno l'altro ramo della croce
if (acedGrDraw(p1, p2, -1, 0) != RTNORM) return GS_BAD;
return GS_GOOD;
}
/*********************************************************/
/*.doc gsc_IsErasedEnt <extern> */
/*+
Verifica se l'oggetto è stato cancellato o ancora esistente.
Parametri:
ads_name ent; oggetto grafico
Ritorna GS_GOOD se l'oggetto è stato cancellato altrimenti GS_BAD
-*/
/*********************************************************/
int gsc_IsErasedEnt(ads_name ent)
{
AcDbObjectId objId;
if (acdbGetObjectId(objId, ent) != Acad::eOk) return GS_BAD;
return (objId.isEffectivelyErased()) ? GS_GOOD : GS_BAD;
}
/*********************************************************/
/*.doc gsc_UnEraseEnt <extern> */
/*+
Se l'oggetto è stato cancellato lo ripristina.
Parametri:
ads_name ent; oggetto grafico
Ritorna GS_GOOD se l'oggetto è stato cancellato altrimenti GS_BAD
-*/
/*********************************************************/
int gsc_UnEraseEnt(ads_name ent)
{
AcDbObjectId objId;
if (acdbGetObjectId(objId, ent) != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
return gsc_UnEraseEnt(objId);
}
int gsc_UnEraseEnt(AcDbObjectId objId)
{
if (objId.isErased())
{
AcDbObject *pObj;
if (acdbOpenObject(pObj, objId, AcDb::kForWrite, true) != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
// ripristino l'oggetto grafico
if (pObj->erase(Adesk::kFalse) != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
if (pObj->close() != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
}
return GS_GOOD;
}
/*********************************************************/
/*.doc gsc_EraseEnt <external>*/
/*+
Cancella l'oggetto grafico solo se non è già stato cancellato.
(a differenza di acdbEntDel che in questo caso ripristina l'oggetto)
Parametri:
ads_name ent; oggetto grafico
Ritorna GS_GOOD se l'oggetto è stato cancellato altrimenti GS_BAD.
-*/
/*********************************************************/
int gsc_EraseEnt(ads_name ent)
{
AcDbObjectId objId;
if (acdbGetObjectId(objId, ent) != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
return gsc_EraseEnt(objId);
}
int gsc_EraseEnt(AcDbObjectId &objId)
{
AcDbObject *pObj;
if (!objId.isErased())
{
if (acdbOpenObject(pObj, objId, AcDb::kForWrite, false) != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
// cancello l'oggetto grafico
if (pObj->erase(Adesk::kTrue) != Acad::eOk )
{ pObj->close(); GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
if (pObj->close() != Acad::eOk)
{ GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
}
return GS_GOOD;
}
int gsc_EraseEnt(AcDbObjectIdArray &objIds)
{
int i, len = objIds.length();
for (i = 0; i < len; i++)
if (gsc_EraseEnt(objIds.at(i)) == GS_BAD) return GS_BAD;
return GS_GOOD;
}
//////////////////////////////////////////////////////////////////////////
// INIZIO FUNZIONI DI C_CLASS
//////////////////////////////////////////////////////////////////////////
/*******************************************************/
/*.doc int gs_insert_ent() */
/*+
Funzione lisp per disegnare in modo guidato degli oggetti in GEOsim.
Parametri:
(<cls><check_con>)
Restituisce GS_GOOD in caso di successo altrimenti GS_BAD.
-*/
/*********************************************************/
int gs_insert_ent(void)
{
presbuf arg = acedGetArgs();
int cls, check_con = 0;
C_CLASS *pCls;
C_SELSET SSOut;
ads_name ss;
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 ((arg = arg->rbnext) != NULL)
if (arg->restype == RTT)
check_con = 1;
if (pCls->InsertEnt(NULL, check_con, NULL, &SSOut) != GS_GOOD) return RTERROR;
SSOut.get_selection(ss);
acedRetName(ss, RTPICKS);
SSOut.ReleaseAllAtDistruction(GS_BAD);
return RTNORM;
}
int C_CLASS::InsertEnt(ads_point start, int check_con, ads_name ent,
C_SELSET *pSSOut, long *gs_id)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
int C_CLASS::InsertEnt(C_SUB *cls, C_SELSET *pSSOut, bool Undo)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
//////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI DI C_CLASS
// INIZIO FUNZIONI DI C_SIMPLEX
//////////////////////////////////////////////////////////////////////////
/*********************************************************/
/*.doc C_SIMPLEX::InsertEnt <external> */
/*+
Funzioni per inserimento di un'entita di GEOsim.
L'utente viene guidato per l'inserimento della sola parte grafica
a cui viene successivamente associata la scheda di default.
Parametri:
ads_point start; Se <> NULL viene usato come punto iniziale di riferimento
(es. per oggetti lineari)
int check_con; Flag di controllo, se = FALSE non effettua alcun
controllo sulle connessioni.
ads_name con_ent; Usato se check_con = TRUE. La funzione cerca
(se possibile) la connessione con questa entità
C_SELSET *pSSOut; Se <> NULL gruppo di selezione con l'oggetto grafico
principale dell'entità inserita
long *gs_id; Codice nuova entità (default = NULL)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_SIMPLEX::InsertEnt(ads_point start, int check_con, ads_name con_ent,
C_SELSET *pSSOut, long *gs_id)
{
C_FAS OldGraphEnv;
int ret = GS_GOOD, SplitMode;
ads_point ins;
ads_pointp point = NULL;
ads_name ent;
C_SELSET entSS;
C_RB_LIST ColValues;
C_CLS_PUNT *pEntCls;
C_CLS_PUNT_LIST EntClsList;
C_STRING TextValue;
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;
// verifico l'abilitazione dell' utente;
if (gsc_check_op(opInsEntity) == GS_BAD) return GS_BAD;
if (id.abilit != GSUpdateableData)
{
GS_ERR_COD = (id.abilit == GSReadOnlyData) ? eGSClassIsReadOnly : eGSClassLocked;
return GS_BAD;
}
if (pSSOut) pSSOut->clear();
// Start Undo
if (gsc_startTransaction() == GS_BAD) return GS_BAD;
// Controlla l'esistenza di eventuali connessioni
if (check_con && ptr_connect_list()->is_to_be_connected() == GS_GOOD)
{
ads_name EntToConnectTo;
if (con_ent) ads_name_set(con_ent, EntToConnectTo);
else ads_name_clear(EntToConnectTo);
if ((ret = gsc_get_connect_point(this, start, EntToConnectTo,
&point, &SplitMode)) == GS_CAN)
{ gsc_abortTransaction(); return GS_CAN; }
if (ret == GS_BAD) { gsc_abortTransaction(); return GS_BAD; }
if (point)
{ // Elimina allocazioni dinamiche
ads_point_set(point, ins); free(point); point = ins;
// Se si deve dividere l'entità di connessione
if (SplitMode == SOFT_SPLIT || SplitMode == HARD_SPLIT)
{ // La spezzo
ads_name EntLast;
// Memorizzo ultima entita.
if (acdbEntLast(EntLast) != RTNORM)
{ gsc_abortTransaction(); GS_ERR_COD = eGSInvGraphObjct; return GS_BAD; }
if (gsc_break(EntToConnectTo, ins) == GS_GOOD && SplitMode == SOFT_SPLIT)
{
C_SELSET NewSS;
ads_name sel;
// Aggrego i due pezzi
// creo gruppo di selezione delle entità nuove generate da "break"
while (gsc_mainentnext(EntLast, EntLast) == GS_GOOD)
NewSS.add(EntLast);
// Scarto eventuali blocchi DA
NewSS.intersectType(GRAPHICAL);
// Se il "break" ha generato 2 nuovi oggetti grafici
// prendo il primo come oggetto a cui aggregare il secondo
if (NewSS.length() > 1)
{
NewSS.entname(0, EntToConnectTo);
NewSS.subtract_ent(EntToConnectTo);
}
NewSS.get_selection(sel);
aggr_data(sel, EntToConnectTo);
}
}
}
}
else
{
point = start;
if (point && check_con) // se esiste il punto e si devono controllare le connessioni
// controllo che in quel punto non ci sia un oggetto GEOsim non sovrapponibile
if (gsc_OverlapValidation(start, this) == GS_BAD)
{ gsc_abortTransaction(); GS_ERR_COD = eGSOverlapValidation; return GS_BAD; }
}
if (gsc_setenv_graph(id.category, id.type, fas, &OldGraphEnv) == GS_BAD)
{ gsc_abortTransaction(); return GS_BAD; }
do
{
// A seconda del tipo inserisce l'entita' grafica corrispondente
switch (id.type)
{
case TYPE_SURFACE :
case TYPE_POLYLINE :
if ((ret = gsc_insert_pline(point, (check_con) ? this : NULL)) != GS_GOOD)
break;
acdbEntLast(ent);
if ((pEntCls = new C_CLS_PUNT(this, ent)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; ret = GS_BAD; break; }
EntClsList.add_tail(pEntCls);
// Setto la scala del tipo linea
if (gsc_set_lineTypeScale(ent, fas.line_scale) == GS_BAD) { ret = GS_BAD; break; }
// Se SURFACE chiude polilinea
if (id.type == TYPE_SURFACE)
{
if (gsc_close_pline(ent) == GS_BAD) { ret = GS_BAD; break; }
// se impostato un riempimento lo applica
if (fas.hatch && wcslen(fas.hatch) > 0)
{
// se ritorna GS_CAN la superficie era troppo piccola per
// contenere il riempimento
if ((ret = gsc_setHatchEnt(ent, fas.hatch, fas.hatch_scale,
fas.hatch_rotation, &fas.hatch_color,
fas.hatch_layer)) == GS_BAD)
break;
if (ret == GS_GOOD)
{
acdbEntLast(ent); // aggiungo anche il riempimento
if ((pEntCls = new C_CLS_PUNT(this, ent)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; ret = GS_BAD; break; }
EntClsList.add_tail(pEntCls);
}
ret = GS_GOOD;
}
}
break;
case TYPE_TEXT :
{
C_ATTRIB *pTextAttr;
// cerco il valore di default dell'attributo visibile
pTextAttr = ptr_attrib_list()->getFirstVisibleAttrib();
if ((ret = gsc_insert_text(fas.style, point, fas.h_text, fas.rotation,
NULL,
(pTextAttr->def && pTextAttr->def->restype == RTSTR) ? pTextAttr->def->resval.rstring : _T("?"),
(check_con) ? this : NULL)) != GS_GOOD)
break;
acdbEntLast(ent);
gsc_getInfoText(ent, &TextValue);
if ((pEntCls = new C_CLS_PUNT(this, ent)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; ret = GS_BAD; break; }
EntClsList.add_tail(pEntCls);
break;
}
case TYPE_NODE :
if ((ret = gsc_insert_block(fas.block, point, fas.block_scale, fas.rotation,
(check_con) ? this : NULL)) != GS_GOOD)
break;
acdbEntLast(ent);
if ((pEntCls = new C_CLS_PUNT(this, ent)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; ret = GS_BAD; break; }
EntClsList.add_tail(pEntCls);
break;
default :
acutPrintf(gsc_msg(217)); // "\nNON DISPONIBILE IN QUESTA VERSIONE...\n"
ret = GS_BAD;
break;
}
if (ret == GS_BAD || ret == GS_CAN) break;
// Inserimento di entità GEOsim usando i valori attributi di default
if ((ret = get_default_values(ColValues)) == GS_BAD) break;
// Se si tratta di testo devo modificare il valore del testo
if (id.type == TYPE_TEXT)
if (ColValues.CdrAssocSubst(ptr_attrib_list()->getFirstVisibleAttrib()->get_name(),
TextValue.get_name()) == GS_BAD)
break;
if ((ret = ins_data(&EntClsList, ColValues, gs_id)) != GS_GOOD)
break;
// la funzione ins_data potrebbe variare la prima entità di EntClsList
pEntCls = (C_CLS_PUNT *) EntClsList.get_head();
ads_name_set(pEntCls->ent, ent);
if (pSSOut) pSSOut->add(ent);
GEOsimAppl::LAST_CLS = id.code;
GEOsimAppl::LAST_SUB = id.sub_code;
}
while (0);
// Ripristina situazione FAS precedente
gsc_setenv_graph(id.category, id.type, OldGraphEnv);
if (ret != GS_GOOD) { gsc_abortTransaction(); return ret; }
// End Undo
gsc_endTransaction();
return ret;
}
//////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI DI C_SIMPLEX
// INIZIO FUNZIONI DI C_GROUP
//////////////////////////////////////////////////////////////////////////
presbuf C_GROUP::get_graphical_data(long code, TCHAR *what, TCHAR *type)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
/*********************************************************/
/*.doc C_GROUP::InsertEnt <external> */
/*+
Funzioni per inserimento di un'entita di GEOsim.
L'utente viene guidato per la selezione della sola parte grafica
a cui viene successivamente associata la scheda di default.
Parametri:
ads_point start; Usato solo per compatibilità
int check_con; Usato solo per compatibilità
ads_name con_ent; Usato solo per compatibilità
C_SELSET *pSSOut; Se <> NULL gruppo di selezione con gli oggetti grafici
membri dell'entità inserita
long *gs_id; Codice nuova entità (default = NULL)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GROUP::InsertEnt(ads_point start, int check_con, ads_name con_ent,
C_SELSET *pSSOut, long *gs_id)
{
C_SELSET ss;
long i;
ads_name ent;
C_CLASS *pCls;
C_EED eed;
C_GROUP_LIST group_list;
C_INT_INT *pMember;
C_CLS_PUNT_LIST ent_list;
C_CLS_PUNT *punt;
int ret;
long Key, NotMemberObjs;
C_RB_LIST ColValues;
bool InvalidGroup;
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;
// verifico l'abilitazione dell' utente;
if (gsc_check_op(opInsEntity) == GS_BAD) return GS_BAD;
if (id.abilit != GSUpdateableData)
{
GS_ERR_COD = (id.abilit == GSReadOnlyData) ? eGSClassIsReadOnly : eGSClassLocked;
return GS_BAD;
}
if (pSSOut) pSSOut->clear();
do
{
NotMemberObjs = 0;
InvalidGroup = false;
ent_list.remove_all();
// Copio la lista che descrive la composizione del gruppo
ptr_group_list()->copy(&group_list);
do
{
if (gsc_ssget(NULL, NULL, NULL, NULL, ss) != RTNORM) return GS_CAN;
if (ss.length() > 0) break;
}
while (1);
// Controllo che il gruppo di selezione sia compatibie con il gruppo
// Scarto gli oggetti che non sono delle classi componenti il gruppo
i = 0;
while (ss.entname(i++, ent) == GS_GOOD)
{
if (eed.load(ent) != GS_GOOD) // solo entità di GEOsim
{ NotMemberObjs++; continue; }
// solo entità membri del gruppo
if ((pMember = (C_INT_INT *) ptr_group_list()->search_key(eed.cls)) == NULL)
{ NotMemberObjs++; continue; }
// Cerco caratteristiche classe
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(eed.cls, eed.sub)) == NULL)
{ NotMemberObjs++; continue; }
if (pCls->getKeyValue(ent, &Key) == GS_BAD)
{ NotMemberObjs++; continue; }
// Se l'entità non era ancora stata selezionata
if (ent_list.search_ClsKey(pCls, Key) == NULL)
{
// Verifico la sua modificabilità ed eventualmente la estraggo totalmente
if (pCls->is_updateable(Key, NULL, GS_GOOD, GS_GOOD) != GS_GOOD)
{
acutPrintf(gsc_msg(770), 1); // "\n%ld entità GEOsim bloccata/e da un' altro utente."
InvalidGroup = true;
break;
}
// Se si è definito un numero di entità per la classe
if (pMember->get_type() > 0)
{
pMember = (C_INT_INT *) group_list.search_key(eed.cls);
if (pMember->get_type() == 0) // se non si devono aggiungere altre entità
{
pMember = (C_INT_INT *) ptr_group_list()->search_key(eed.cls);
// "\nSono state selezionate troppe entità della classe %s (il gruppo ne deve contenere %d)."
acutPrintf(gsc_msg(211), pCls->get_name(), pMember->get_type());
InvalidGroup = true;
break;
}
pMember->set_type(pMember->get_type() - 1); // decremento il n. di entità
}
// La aggiungo alla lista
if ((punt = new C_CLS_PUNT(pCls, ent, Key)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
ent_list.add_tail(punt);
if (pSSOut) pSSOut->add(ent);
}
else // se l'entità era già stata selezionata
if (pSSOut) pSSOut->add(ent);
}
if (InvalidGroup) continue;
acutPrintf(gsc_msg(227), ss.length(), NotMemberObjs); // "\nOggetti grafici elaborati %ld, scartati %ld."
// Valuto se il gruppo è completo o se deve essere selezionata qualche altra entità
pMember = (C_INT_INT *) group_list.get_head();
while (pMember)
{
if (pMember->get_type() > 0) // Se è rimasta ancora qualche entità da aggiungere
{
int Tot = ptr_group_list()->search_key(pMember->get_key())->get_type();
pCls = GS_CURRENT_WRK_SESSION->find_class(pMember->get_key());
// "\nSono state selezionate solo %d entità della classe %s (il gruppo ne deve contenere %d)."
acutPrintf(gsc_msg(212), Tot - pMember->get_type(), pCls->get_name(), Tot);
InvalidGroup = true;
}
pMember = (C_INT_INT *) pMember->get_next();
}
if (InvalidGroup) continue;
break;
}
while (1);
// Inserimento di entità GEOsim usando i valori attributi di default
if (get_default_values(ColValues) == GS_BAD) return GS_BAD;
if ((ret = ins_data(&ent_list, ColValues, gs_id)) == GS_GOOD)
{
GEOsimAppl::LAST_CLS = id.code;
GEOsimAppl::LAST_SUB = id.sub_code;
}
return ret;
}
//////////////////////////////////////////////////////////////////////////
// FINE FUNZIONI DI C_GROUP
// INIZIO FUNZIONI DI C_EXTERN
//////////////////////////////////////////////////////////////////////////
presbuf C_EXTERN::get_graphical_data(long code, TCHAR *what, TCHAR *type)
{ GS_ERR_COD = eGSInvClassType; return GS_BAD; }
/*********************************************************/
/*.doc C_EXTERN::InsertEnt <external> */
/*+
Funzioni per inserimento di una o più entita di GEOsim.
L'utente viene guidato per l'inserimento della sola parte grafica
a cui viene successivamente associata la/e scheda/e di default.
Parametri:
C_SUB *pSub; Puntatore alla sottoclasse che si vuole inserire
C_SELSET *pSSOut; Se <> NULL puntatore a gruppo di selezione degli
oggetti grafici principali delle entità inserite
bool Undo; Se = TRUE la procedura gestisce gli undo (default = TRUE)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_EXTERN::InsertEnt(C_SUB *pSub, C_SELSET *pSSOut, bool Undo)
{
C_EED ent_EED;
C_CONNECT_LIST *con_list, *con_tmp;
TCHAR str[60];
int direct; // flag usato per inserimento di polilinee:
// 1 = Unisce i due nodi con un solo tratto
// 2 = Unisce i due nodi con più tratti
int rc, ret = GS_GOOD, flag = 1, type = 0;
int inserted_initial_node = FALSE, inserted_final_node = FALSE, inserted_pline = FALSE;
ads_point point,drag;
ads_name last, ent, nodo1, middle, nodo2;
C_SELSET entSS;
C_INT_INT *punt;
C_CLASS *pCls, *cls_initial_nodo, *cls_final_nodo;
long gs_id_initial_node = 0, gs_id_final_node = 0, gs_id_pline = 0;
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;
// verifico l'abilitazione dell' utente;
if (gsc_check_op(opInsEntity) == GS_BAD) return GS_BAD;
if (id.abilit != GSUpdateableData)
{
GS_ERR_COD = (id.abilit == GSReadOnlyData) ? eGSClassIsReadOnly : eGSClassLocked;
return GS_BAD;
}
if (!pSub || (con_list = pSub->ptr_connect_list()) == NULL && con_list->get_count() > 0)
{ GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
ads_name_clear(nodo1);
ads_name_clear(nodo2);
SEL_EXT = this;
if (pSSOut) pSSOut->clear();
// Start Undo
if (Undo)
if (gsc_startTransaction() == GS_BAD) return GS_BAD;
// INSERIMENTO NODO INIZIALE
if ((type = pSub->get_type()) == TYPE_POLYLINE)
{
wcscpy(str, gsc_msg(100)); // "Esistente"
acedInitGet(0, gsc_msg(101)); // "Nuova Esistente"
if ((rc = acedGetKword(gsc_msg(102), str)) == RTERROR) // "\nEntita' iniziale [Nuova/<Esistente>]: "
{ GS_ERR_COD = eGSAdsCommandErr; if (Undo) gsc_abortTransaction(); return GS_CAN; }
if (rc == RTCAN) { gsc_abortTransaction(); return GS_CAN; }
if (gsc_strcmp(str, gsc_msg(103)) == 0) // "Nuova"
{
gsc_ddselect_subnode(con_list, _T("StartNode"));
if ((cls_initial_nodo = SEL_CLS) == NULL)
{ if (Undo) gsc_abortTransaction(); return GS_CAN; }
// inserimento senza controllo di connessione ma solo di sovrapposizione
ret = cls_initial_nodo->InsertEnt(NULL, NO_OVERLAP, NULL, &entSS,
&gs_id_initial_node);
if (ret == GS_CAN || ret == GS_BAD)
{ if (Undo) gsc_abortTransaction(); return ret; }
entSS.entname(0, nodo1);
if (pSSOut) pSSOut->add(nodo1); // aggiungo l'entità inserita
GS_LAST_NODE_CLS = cls_initial_nodo->ptr_id()->code;
GS_LAST_NODE_SUB = cls_initial_nodo->ptr_id()->sub_code;
inserted_initial_node = TRUE;
}
else // NODO ESISTENTE
{
int Flag = 1;
LinkID ID = LINKID_NULL;
ret = GS_BAD;
do
{
if (Flag == 0) acutPrintf(gsc_msg(28)); // "\nSelezione entita' non valida."
Flag = 0;
acutPrintf(gsc_msg(29)); // "\nSeleziona entita' a cui connettersi :"
acedInitGet(RSG_NONULL, GS_EMPTYSTR);
while ((ret = acedEntSel(GS_EMPTYSTR, nodo1, point)) == RTERROR);
if (ret == RTREJ) { GS_ERR_COD = eGSAdsCommandErr; break; }
if (ret == RTCAN) { ret = GS_CAN; break; }
// verifico che l'oggetto grafico sia già etichettato "GEOsim"
if (ent_EED.load(nodo1) == GS_BAD) { GS_ERR_COD = eGSGEOsimObjNotFound; continue; }
// Verifico che si tratti di un elemento della simulazione corrente
if (ent_EED.cls != id.code) continue;
// Deve essere nella connect_list
if ((punt=(C_INT_INT*)con_list->search_key(ent_EED.sub))==NULL) continue;
// Cerco caratteristiche classe
if ((pCls = GS_CURRENT_WRK_SESSION->find_class(ent_EED.cls, ent_EED.sub)) == NULL)
continue;
// Deve avere la connect_list non vuota
if ((con_tmp = pCls->ptr_connect_list()) == NULL || con_tmp->is_empty()) continue;
// leggo valore chiave e il gruppo di selezione
if (pCls->get_Key_SelSet(nodo1, &gs_id_initial_node, entSS) == GS_BAD)
continue;
if (gsc_is_DABlock(nodo1) == GS_GOOD) // Selezione su scheda degli attributi
{
// Ricavo elemento grafico del nodo di partenza
if (entSS.intersectType(GRAPHICAL) == GS_BAD) continue;
// get entity name
if (entSS.entname(0, nodo1) != GS_GOOD) continue;
}
// se si è abilitati a inserire in GEOsimAppl::SAVE_SS
if (GEOsimAppl::GLOBALVARS.get_AddEntityToSaveSet() == GS_GOOD)
// se l'entità è nuova e non è ancora stata inserita in GEOsimAppl::SAVE_SS
// NON può essere selezionata a meno che non abbia regole di connessione
// con altri oggetti.
// Questo controlla la seguente casistica:
// Con "AddEntityToSaveSet" = OFF si inserisce un lato di una simulazione
// acqua, successivamente con "AddEntityToSaveSet" = ON si inserisce un
// altro lato utilizzando un nodo del lato precedente e si salva.
if (pCls->is_NewEntity(gs_id_initial_node) == GS_GOOD) // entità nuova
{
if (GEOsimAppl::SAVE_SS.is_member(nodo1) == GS_BAD)
if (is_IndipendentSub(pCls->ptr_id()->sub_code) == GS_BAD)
// ha regole di connessione con altri oggetti
continue;
}
ret = GS_GOOD;
break;
}
while (1);
if (ret != GS_GOOD)
{ if (Undo) gsc_abortTransaction(); return ret; }
cls_initial_nodo = pCls;
}
}
// INSERIMENTO ENTITA' SELEZIONATA
if (acdbEntLast(last) != RTNORM) ads_name_clear(last);
do
{
// se è polilinea non inserisce la scheda
// inserimento con controllo di connessione
ret = pSub->InsertEnt(NULL, TRUE, nodo1, &entSS);
entSS.entname(0, ent);
if (ret == GS_CAN)
{
// per le polilinee la funzione restituisce GS_CAN se non si
// è scelto di inserire la polilinea ma si vuole unire due nodi
// con un unico tratto
if (type != TYPE_POLYLINE) break;
}
else if (ret == GS_BAD)
break;
// INSERIMENTO NODO FINALE
if (type == TYPE_POLYLINE)
{