-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_GRID.CPP
8451 lines (7093 loc) · 313 KB
/
GS_GRID.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_GRID.CPP
Module description: File per gestione delle griglia
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 <actrans.h>
#include <aced.h>
#include <acdb.h>
#include <dbelipse.h>
#include <dblead.h>
#include <dbray.h>
#include <dbxline.h>
#include <dbhatch.h>
#include "GSresource.h"
#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_thm.h" // gestione tematismi e sistemi di coordinate
#include "gs_class.h"
#include "gs_prjct.h"
#include "gs_graph.h"
#include "gs_query.h"
#include "gs_attbl.h" // gestione blocchi attributi visibili
#include "gs_utily.h"
#include "gs_init.h"
#include "gs_grid.h"
#if defined(GSDEBUG) // se versione per debugging
#include <sys/timeb.h> // Solo per debug
#include <time.h> // Solo per debug
double GrdTempo1 = 0.0, GrdTempo2 = 0.0, GrdTempo3 = 0.0, GrdTempo4 = 0.0, GrdTempo5 = 0.0;
double GrdTempo6 = 0.0, GrdTempo7 = 0.0, GrdTempo8 = 0.0, GrdTempo9 = 0.0, GrdTempo10 = 0.0;
double GrdTempo11 = 0.0, GrdTempo12 = 0.0, GrdTempo13 = 0.0, GrdTempo14 = 0.0, GrdTempo15 = 0.0;
#endif
///////////////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS
int gsc_setFAS4Grid(C_FAS *pFAS, int Mode, C_COLOR *Color = NULL, TCHAR **Layer = NULL,
TCHAR **Hatch = NULL, C_COLOR *HatchColor = NULL,
double *HatchScale = NULL, double *HatchRotation = NULL);
int gsc_CloneTo3dPolyline(AcDb2dPolyline *pEnt);
int gsc_CloneTo3dPolyline(AcDbPolyline *pEnt);
int gsc_CloneTo3dPolyline(AcDbLine *pEnt);
int gsc_InitGridToMemory(C_GRID *pGrid, double **Vector, long *VectorLen);
void gsc_MatrixKey2VettPos(C_GRID *pInfoGrid, long LeftBottomKey, C_DBL_MATRIX &Matrix);
void gsc_MatrixVettPos2Key(C_DBL_MATRIX &Matrix, C_GRID *pInfoGrid, long LeftBottomKey);
/*********************************************************/
/*.doc gsc_setFAS4Grid <internal> */
/*+
Funzione interna di ausilio per le funzioni di visualizzazione
della griglia.
C_FAS *pFAS; Caratteristiche grafiche della visualizzazione
int Mode; Se = PREVIEW non crea oggetti ACAD (più veloce) altrimenti
(= EXTRACTION) crea oggetti grafici
C_COLOR *Color; Se = NULL non viene usato
TCHAR **Layer;
TCHAR **Hatch;
C_COLOR *HatchColor; Se = NULL non viene usato
double *HatchScale;
double *HatchRotation;
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*************************************************************/
int gsc_setFAS4Grid(C_FAS *pFAS, int Mode, C_COLOR *Color, TCHAR **Layer,
TCHAR **Hatch, C_COLOR *HatchColor, double *HatchScale,
double *HatchRotation)
{
if (pFAS)
{
if (Color)
if (Mode == PREVIEW)
{
if (pFAS->color.getColorMethod() == C_COLOR::None)
Color->setAutoCADColorIndex(7);
else
*Color = pFAS->color;
}
else
*Color = pFAS->color;
if (Layer)
{
*Layer = pFAS->hatch_layer;
// Se non esiste il layer lo crea
if (gsc_crea_layer(*Layer) == GS_BAD) return GS_BAD;
}
if (Hatch) *Hatch = pFAS->hatch;
if (HatchColor)
if (Mode == PREVIEW)
{
if (pFAS->color.getColorMethod() == C_COLOR::None)
HatchColor->setForeground();
else
*HatchColor = pFAS->hatch_color;
}
else
*HatchColor = pFAS->hatch_color;
if (HatchScale) *HatchScale = pFAS->hatch_scale;
if (HatchRotation) *HatchRotation = pFAS->hatch_rotation;
}
else
{
if (Color)
if (Mode == PREVIEW) Color->setAutoCADColorIndex(7);
else Color->setByLayer();
if (Layer) *Layer = NULL;
if (Hatch) *Hatch = NULL;
if (HatchColor)
if (Mode == PREVIEW) HatchColor->setForeground();
else HatchColor->setByLayer();
if (HatchScale) *HatchScale = 1.0;
if (HatchRotation) *HatchRotation = 0.0;
}
return GS_GOOD;
}
/*********************************************************/
/*.doc gsc_CloneTo3dPolyline <extern> */
/*+
Duplica l'oggetto grafico in AcDb3dPolyline.
Parametri:
AcDb2dPolyline *pEnt;
oppure
AcDbPolyline *pEnt;
Ritorna un GS_GOOD se l'oggetto è stato duplicato altrimenti NULL.
-*/
/*********************************************************/
int gsc_CloneTo3dPolyline(AcDb2dPolyline *pEnt)
{
AcGePoint3dArray Vertices;
AcDbObjectIterator *pVertIter = pEnt->vertexIterator();
AcDbObjectId vertexObjId;
AcDb2dVertex *pVertex;
AcDb::Poly3dType Type;
C_STRING layerName, lineTypeName;
// Leggo vertici
for (; !pVertIter->done(); pVertIter->step())
{
vertexObjId = pVertIter->objectId();
if (acdbOpenObject(pVertex, vertexObjId, AcDb::kForRead) == Acad::eOk)
{ // se NON è un punto di controllo della cornice di spline
if (pVertex->vertexType() != AcDb::k2dSplineCtlVertex)
Vertices.append(pVertex->position());
pVertex->close();
}
}
delete pVertIter;
// Open the block table for read.
AcDbBlockTable *pBlockTable;
if (acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,
AcDb::kForRead) != Acad::eOk)
return GS_BAD;
AcDbBlockTableRecord *pBlockTableRecord;
if (pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite) != Acad::eOk)
{ pBlockTable->close(); GS_ERR_COD = eGSAdsCommandErr; return GS_BAD; }
pBlockTable->close();
switch (pEnt->polyType())
{
case AcDb::k2dSimplePoly:
case AcDb::k2dFitCurvePoly:
Type = AcDb::k3dSimplePoly;
break;
case AcDb::k2dQuadSplinePoly:
Type = AcDb::k3dQuadSplinePoly;
break;
case AcDb::k2dCubicSplinePoly:
Type = AcDb::k3dCubicSplinePoly;
break;
}
AcDb3dPolyline *p3dPolyline = new AcDb3dPolyline(Type, Vertices, pEnt->isClosed());
p3dPolyline->setColor(pEnt->color());
gsc_getLayer(pEnt, layerName);
if (gsc_setLayer(p3dPolyline, layerName.get_name()) != GS_GOOD)
{ delete p3dPolyline; return GS_BAD; }
gsc_get_lineType(pEnt, lineTypeName);
p3dPolyline->setLinetype(lineTypeName.get_name());
p3dPolyline->setLinetypeScale(pEnt->linetypeScale());
p3dPolyline->setLineWeight(pEnt->lineWeight());
pBlockTableRecord->appendAcDbEntity(p3dPolyline);
pBlockTableRecord->close();
p3dPolyline->close();
return GS_GOOD;
}
int gsc_CloneTo3dPolyline(AcDbPolyline *pEnt)
{
AcGePoint3dArray Vertices;
AcGePoint3d location;
int i = 0;
C_STRING layerName, lineTypeName;
// Leggo vertici
while (pEnt->getPointAt(i++, location) == Acad::eOk)
Vertices.append(location);
// Open the block table for read.
AcDbBlockTable *pBlockTable;
if (acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,
AcDb::kForRead) != Acad::eOk)
return GS_BAD;
AcDbBlockTableRecord *pBlockTableRecord;
if (pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite) != Acad::eOk)
{ pBlockTable->close(); GS_ERR_COD = eGSAdsCommandErr; return GS_BAD; }
pBlockTable->close();
AcDb3dPolyline *p3dPolyline = new AcDb3dPolyline(AcDb::k3dSimplePoly, Vertices, pEnt->isClosed());
p3dPolyline->setColor(pEnt->color());
gsc_getLayer(pEnt, layerName);
if (gsc_setLayer(p3dPolyline, layerName.get_name()) != GS_GOOD)
{ delete p3dPolyline; return GS_BAD; }
gsc_get_lineType(pEnt, lineTypeName);
p3dPolyline->setLinetype(lineTypeName.get_name());
p3dPolyline->setLinetypeScale(pEnt->linetypeScale());
p3dPolyline->setLineWeight(pEnt->lineWeight());
pBlockTableRecord->appendAcDbEntity(p3dPolyline);
pBlockTableRecord->close();
p3dPolyline->close();
return GS_GOOD;
}
int gsc_CloneTo3dPolyline(AcDbLine *pEnt)
{
AcGePoint3dArray Vertices;
AcGePoint3d location;
int i = 0;
C_STRING layerName, lineTypeName;
// Leggo vertici
Vertices.append(pEnt->startPoint());
Vertices.append(pEnt->endPoint());
// Open the block table for read.
AcDbBlockTable *pBlockTable;
if (acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,
AcDb::kForRead) != Acad::eOk)
return GS_BAD;
AcDbBlockTableRecord *pBlockTableRecord;
if (pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite) != Acad::eOk)
{ pBlockTable->close(); GS_ERR_COD = eGSAdsCommandErr; return GS_BAD; }
pBlockTable->close();
AcDb3dPolyline *p3dPolyline = new AcDb3dPolyline(AcDb::k3dSimplePoly, Vertices, pEnt->isClosed());
p3dPolyline->setColor(pEnt->color());
gsc_getLayer(pEnt, layerName);
if (gsc_setLayer(p3dPolyline, layerName.get_name()) != GS_GOOD)
{ delete p3dPolyline; return GS_BAD; }
gsc_get_lineType(pEnt, lineTypeName);
p3dPolyline->setLinetype(lineTypeName.get_name());
p3dPolyline->setLinetypeScale(pEnt->linetypeScale());
p3dPolyline->setLineWeight(pEnt->lineWeight());
pBlockTableRecord->appendAcDbEntity(p3dPolyline);
pBlockTableRecord->close();
p3dPolyline->close();
return GS_GOOD;
}
/*********************************************************/
/*.doc gsc_GridPrepare_data_on_row_map_fmt <internal> */
/*+
Prepara un comando per la restituzione dei record in un intervallo.
E' composta in 2 parti:
gsc_GridPrepare_data_on_row_map_fmt_1
Parametri:
C_CGRID *pCls; Classe griglia
const TCHAR *what; Eventuale espressione da ritornare (default = NULL)
const TCHAR *SQLWhere; Eventuale condizione di filtro (default = NULL)
C_STRING &StmPrefix; out; Da usare in "gsc_GridPrepare_data_on_row_map_fmt_2"
CAsiSession **pSession; out; Da usare in "gsc_GridPrepare_data_on_row_map_fmt_2"
gsc_GridPrepare_data_on_row_map_fmt_2
Parametri:
C_CGRID *pCls; Classe griglia
C_STRING &StmPrefix;
long MinValue; Valore minimo intervallo
long MaxValue; Valore massimo intervallo
CAsiSession *pSession; out
CAsiExecStm **pStm; out
CAsiCsr **pCsr; out
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int gsc_GridPrepare_data_on_row_map_fmt_1(C_CGRID *pCls, TCHAR *what, TCHAR *SQLWhere,
C_STRING &StmPrefix, CAsiSession **pSession)
{
C_STRING UDL, TableRef, KeyAttribCorrected;
C_DBCONNECTION *pConn;
// ricavo connessione OLE-DB per tabella TEMP
if ((pConn = pCls->ptr_info()->getDBConnection(TEMP)) == NULL) return GS_BAD;
if (pCls->getTempTableRef(TableRef, GS_BAD) == GS_BAD) return GS_BAD; // senza creare la tabella
// Correggo la sintassi del nome del campo per SQL MAP
KeyAttribCorrected = pCls->ptr_info()->key_attrib;
gsc_AdjSyntaxMAPFormat(KeyAttribCorrected);
// preparo istruzione per lettura da TEMP
StmPrefix = _T("SELECT ");
StmPrefix += KeyAttribCorrected;
if (what != NULL && wcslen(what) > 0)
{
StmPrefix += _T(',');
StmPrefix += what;
}
StmPrefix += _T(" FROM ");
if (gsc_Table2MAPFormat(pConn, TableRef, UDL) == GS_BAD) return GS_BAD;
StmPrefix += UDL;
StmPrefix += _T(" WHERE ");
if (SQLWhere != NULL && wcslen(SQLWhere) > 0)
{
StmPrefix += _T("(");
StmPrefix += SQLWhere;
StmPrefix += _T(") AND ");
}
// se ha db e grafica
if (pCls->getLPNameTemp(UDL) == GS_BAD) return GS_BAD;
if (gsc_SetACADUDLFile(UDL.get_name(), pCls->ptr_info()->getDBConnection(TEMP),
TableRef.get_name()) == GS_BAD)
return GS_BAD;
if ((*pSession = gsc_ASICreateSession(UDL.get_name())) == NULL)
return GS_BAD;
return GS_GOOD;
}
int gsc_GridPrepare_data_on_row_map_fmt_2(C_CGRID *pCls, C_STRING &StmPrefix,
long MinValue, long MaxValue,
CAsiSession *pSession, CAsiExecStm **pStm,
CAsiCsr **pCsr)
{
C_STRING UDL, statement, KeyAttribCorrected;
// Correggo la sintassi del nome del campo per SQL MAP
KeyAttribCorrected = pCls->ptr_info()->key_attrib;
gsc_AdjSyntaxMAPFormat(KeyAttribCorrected);
// preparo istruzione per lettura da TEMP
statement = StmPrefix;
statement += _T("");
statement += KeyAttribCorrected;
statement += _T(">=");
statement += MinValue;
statement += _T(" AND ");
statement += KeyAttribCorrected;
statement += _T("<=");
statement += MaxValue;
// se ha db e grafica
if (pCls->getLPNameTemp(UDL) == GS_BAD) return GS_BAD;
if (gsc_ASIPrepareSql(pSession, statement.get_name(), UDL.get_name(),
pStm, pCsr) == GS_BAD)
return GS_BAD;
return GS_GOOD;
}
///////////////////////////////////////////////////////////////////////////////
// INIZIO FUNZIONE C_GRID
///////////////////////////////////////////////////////////////////////////////
/*********************************************************/
/*.doc C_GRID::pt2key <external> */
/*+
Dato un punto restituisce il codice della cella che lo contiene.
N.B.: I punti noti della griglia sono considerati centroidi delle celle.
Parametri:
ads_point pt; Punto selezionato
long *key; Codice chiave della cella
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GRID::pt2key(ads_point pt, long *key)
{
ads_real CoordX, CoordY;
long OffsetX, OffsetY;
CoordX = pt[X] - x;
CoordY = pt[Y] - y;
if (CoordX < 0 || CoordX >= (dx * nx))
{ GS_ERR_COD = eGSInvalidKey; return GS_BAD; }
if (CoordY < 0 || CoordY >= (dy * ny))
{ GS_ERR_COD = eGSInvalidKey; return GS_BAD; }
OffsetX = long(CoordX / dx) + 1;
OffsetY = long(CoordY / dy);
*key = OffsetY * nx + OffsetX;
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GRID::key2pt <external> */
/*+
Dato il codice della cella restituisce il punto corrispondente (solo X e Y).
Parametri:
long key; Codice chiave della cella
ads_point pt; Punto selezionato
bool Centroid; Se = TRUE, il punto sarà il centroide della cella altrimenti
sarà il punto in basso a sinistra (default = TRUE)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GRID::key2pt(long key, ads_point pt, bool Centroid)
{
long _internalKey = key - 1; // lo modifico per i calcoli
pt[X] = x;
pt[Y] = y;
if (_internalKey)
{
pt[X] += ((_internalKey % nx) * dx);
pt[Y] += ((long (_internalKey / nx)) * dy);
}
if (Centroid)
{
pt[X] += (dx / 2);
pt[Y] += (dy / 2);
}
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GRID::key2Rect <external> */
/*+
Dato il codice della cella restituisce i punti del rettangolo
corrispondente.
Parametri:
long key; Codice chiave della cella
ads_point pt1; Punto in basso-sinistra
ads_point pt2; Punto alto-destra
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GRID::key2Rect(long key, ads_point pt1, ads_point pt2)
{
if (key2pt(key, pt1, false) == GS_BAD) return GS_BAD;
pt2[X] = pt1[X] + dx;
pt2[Y] = pt1[Y] + dy;
return GS_GOOD;
}
AcDbPolyline *C_GRID::key2Rect(long key)
{
AcDbPolyline *pRect;
AcGePoint2d Vertice;
ads_point p1, p2;
if (key2Rect(key, p1, p2) == GS_BAD) return NULL;
if ((pRect = new AcDbPolyline(4)) == NULL) // 4 vertici
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
Vertice.set(p1[X], p1[Y]);
pRect->addVertexAt(0, Vertice);
Vertice.set(p1[X], p2[Y]);
pRect->addVertexAt(1, Vertice);
Vertice.set(p2[X], p2[Y]);
pRect->addVertexAt(2, Vertice);
Vertice.set(p2[X], p1[Y]);
pRect->addVertexAt(3, Vertice);
pRect->setClosed(Adesk::kTrue); // polilinea chiusa
return pRect;
}
/*********************************************************/
/*.doc C_GRID::RowColumn2pt <external> */
/*+
Dato il numero della riga e della colonna restituisce il punto corrispondente (solo X e Y).
Parametri:
long Column; Colonna (inizia da 0)
long Row; Riga (inizia da 0)
ads_point pt; Punto selezionato
bool Centroid; Se = TRUE, il punto sarà il centroide della cella altrimenti
sarà il punto in basso a sinistra (default = TRUE)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
int C_GRID::RowColumn2pt(long Column, long Row, ads_point pt, bool Centroid)
{
pt[X] = x + dx * Column;
pt[Y] = y + dy * Row;
if (Centroid)
{
pt[X] += (dx / 2);
pt[Y] += (dy / 2);
}
return GS_GOOD;
}
/*********************************************************/
/*.doc C_GRID::getRow <external> */
/*+
Dato il codice della cella restituisce la riga di appartenenza (0-based).
Parametri:
long Key; Codice chiave della cella
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
long C_GRID::getRow(long Key)
{
long _internalKey = Key - 1; // lo modifico per i calcoli
return (long) floor((double) (_internalKey / nx));
}
/*********************************************************/
/*.doc C_GRID::getRow <external> */
/*+
Dato un punto della cella restituisce la riga di appartenenza (0-based).
Parametri:
ads_point pt; Punto interno ad una cella
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
long C_GRID::getRow(ads_point pt)
{
return (long) floor((double) ((pt[Y] - y) / dy));
}
/*********************************************************/
/*.doc C_GRID::getColumn <external> */
/*+
Dato il codice della cella restituisce la colonna di appartenenza (0-based).
Parametri:
long Key; Codice chiave della cella
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
long C_GRID::getColumn(long Key)
{
long _internalKey = Key - 1; // lo modifico per i calcoli
return (_internalKey % nx);
}
/*********************************************************/
/*.doc C_GRID::getColumn <external> */
/*+
Dato un punto della cella restituisce la colonna di appartenenza (0-based).
Parametri:
ads_point pt; Punto interno ad una cella
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
long C_GRID::getColumn(ads_point pt)
{
return (long) floor((double) ((pt[X] - x) / dx));
}
/*********************************************************/
/*.doc C_GRID::getKey <external> */
/*+
Dato la colonna e la riga ricava il codice della cella.
Parametri:
long Column; Colonna (0-based)
long Row; Riga (0-based)
Restituisce il codice della cella in caso di successo altrimenti restituisce -1.
-*/
/*********************************************************/
long C_GRID::getKey(long Column, long Row)
{
return (nx * Row) + Column + 1;
}
/*********************************************************/
/*.doc C_GRID::getXLimit <external> */
/*+
Restituisce il limite massimo delle X della griglia.
-*/
/*********************************************************/
double C_GRID::getXLimit() { return x + (dx * nx); }
/*********************************************************/
/*.doc C_GRID::getYLimit <external> */
/*+
Restituisce il limite massimo delle X della griglia.
-*/
/*********************************************************/
double C_GRID::getYLimit() { return y + (dy * ny); }
/*****************************************************************************/
/*.doc C_GRID::getExtension <external> */
/*+
Restituisce le estensioni della griglia.
Parametri:
C_RECT &Rect; Rettangolo di estensione della griglia
bool SubtractOffSetForTopRight; opzionale; siccome la cella considera il punto in
basso a sinistra compreso e il punto in alto a destra
escluso, in certi caso è utile considerare l'angolo
in alto a destra meno un piccolo offset (x e y),
default = false.
-*/
/*****************************************************************************/
void C_GRID::getExtension(C_RECT &Rect, bool SubtractOffSetForTopRight)
{
Rect.BottomLeft.point[X] = x;
Rect.BottomLeft.point[Y] = y;
Rect.TopRight.point[X] = getXLimit();
Rect.TopRight.point[Y] = getYLimit();
if (SubtractOffSetForTopRight)
{
Rect.TopRight.point[X] -= (dx / 10);
Rect.TopRight.point[Y] -= (dy / 10);
}
}
/*****************************************************************************/
/*.doc C_GRID::getKeyListInEntity <external> */
/*+
Restituisce la lista dei codici delle celle che intersecano l'entità grafica.
Parametri:
AcDbEntity *pEnt; puntatore a entità grafica
int Mode; Flag: INSIDE oppure CROSSING
C_LONG_BTREE &KeyList; Lista dei codici delle celle (output)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_GRID::getKeyListInEntity(AcDbEntity *pEnt, int Mode, C_LONG_BTREE &KeyList)
{
ads_point pt1, pt2;
C_RECT Rect;
AcDbPolyline *pEntRect;
C_BLONG *pKey;
// calcolo il rettangolo di occupazione dell'entità
if (gsc_get_ent_window(pEnt, pt1, pt2) == GS_BAD) return GS_BAD;
Rect.Set(pt1, pt2);
if (getKeyListInWindow(Rect, Mode, KeyList) == GS_BAD) return GS_BAD;
// per ogni cella
pKey = (C_BLONG *) KeyList.go_top();
while (pKey)
{
// ricavo il rettangolo che descrive la cella
if ((pEntRect = key2Rect(pKey->get_key())) == NULL)
return GS_BAD;
// verifico se l'occupazione del rettangolo della cella si interseca o è interna all'entità
if (gsc_IsInternalEnt(pEnt, pEntRect, Mode) == GS_GOOD)
pKey = (C_BLONG *) KeyList.go_next();
else
{
KeyList.remove_at();
pKey = (C_BLONG *) KeyList.get_cursor();
}
delete pEntRect;
}
return GS_GOOD;
}
/*****************************************************************************/
/*.doc C_GRID::getKeyListInWindow <external> */
/*+
Restituisce la lista dei codici delle celle che intersecano la finestra.
Parametri:
C_RB_LIST &CoordList; Lista delle coordinate
int type; Flag: INSIDE oppure CROSSING
C_LONG_BTREE &KeyList; Lista dei cofici delle celle (output)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_GRID::getKeyListInWindow(C_RECT &Rect, int Mode, C_LONG_BTREE &KeyList)
{
C_RECT Extension;
ads_point pt;
long KeyMin, KeyMax;
KeyList.remove_all();
// Estensioni della griglia sottraendo un piccolo offset all'angolo alto-destro
getExtension(Extension, true);
// Ricavo l'area di intersezione tra i 2 rettangoli
if (Extension.Intersect(Rect) == GS_BAD) return GS_GOOD; // Non c'è intersezione
if (Mode == INSIDE) // solo le celle completamente interne al rettangolo
{
if (pt2key(Extension.BottomLeft.point, &KeyMin) == GS_BAD) return GS_BAD;
if (key2pt(KeyMin, pt, false) == GS_BAD) return GS_BAD;
if (pt[X] < Extension.BottomLeft.point[X]) Extension.BottomLeft.point[X] += dx;
if (pt[Y] < Extension.BottomLeft.point[Y]) Extension.BottomLeft.point[Y] += dy;
if (pt2key(Extension.TopRight.point, &KeyMin) == GS_BAD) return GS_BAD;
if (key2pt(KeyMin, Extension.TopRight.point, false) == GS_BAD) return GS_BAD;
Extension.TopRight.point[X] -= (dx / 10);
Extension.TopRight.point[Y] -= (dy / 10);
}
else
{
if (pt2key(Extension.BottomLeft.point, &KeyMin) == GS_BAD) return GS_BAD;
if (key2pt(KeyMin, Extension.BottomLeft.point, false) == GS_BAD) return GS_BAD;
}
pt[Y] = Extension.BottomLeft.point[Y]; // riga inferiore
while (pt[Y] <= Extension.TopRight.point[Y])
{
// cella a sinistra
pt[X] = Extension.BottomLeft.point[X];
if (pt2key(pt, &KeyMin) == GS_BAD) return GS_BAD;
// cella a destra
pt[X] = Extension.TopRight.point[X];
if (pt2key(pt, &KeyMax) == GS_BAD) return GS_BAD;
for (long i = KeyMin; i <= KeyMax; i++)
KeyList.add(&i);
pt[Y] += dy; // riga superiore
}
return GS_GOOD;
}
int C_GRID::getKeyListInWindow(C_RB_LIST &CoordList, int Mode, C_LONG_BTREE &KeyList)
{
C_RECT Rect;
gsc_rb2Pt(CoordList.getptr_at(1), Rect.BottomLeft.point);
gsc_rb2Pt(CoordList.getptr_at(2), Rect.TopRight.point);
return getKeyListInWindow(Rect, Mode, KeyList);
}
int C_GRID::getKeyListInCircle(C_RB_LIST &CoordList, int Mode, C_LONG_BTREE &KeyList)
{
ads_point center;
double radius;
presbuf p;
if ((p = CoordList.get_head()) == NULL ||
(p->restype != RTPOINT && p->restype != RT3DPOINT))
{ GS_ERR_COD = eGSBadLocationQry; return GS_BAD; }
ads_point_set(p->resval.rpoint, center);
if ((p = CoordList.get_next()) == NULL || p->restype != RTREAL)
{ GS_ERR_COD = eGSBadLocationQry; return GS_BAD; }
radius = p->resval.rreal;
AcGePoint3d dummyCenter(center[X], center[Y], center[Z]);
AcDbCircle ContainerEnt(dummyCenter, AcGeVector3d(0.0, 0.0, 1.0), radius);
return getKeyListInEntity(&ContainerEnt, Mode, KeyList);
}
int C_GRID::getKeyListInPolygon(C_RB_LIST &CoordList, int Mode, C_LONG_BTREE &KeyList)
{
AcGePoint3dArray Vertices;
presbuf p;
int i = 0;
Vertices.setLogicalLength(CoordList.GetCount());
p = CoordList.get_head();
while (p)
{
Vertices[i++].set(p->resval.rpoint[X], p->resval.rpoint[Y], 0.0) ; // X, Y, Z
p = CoordList.get_next();
}
AcDb3dPolyline ContainerEnt(AcDb::k3dSimplePoly, Vertices, Adesk::kTrue); // closed
return getKeyListInEntity(&ContainerEnt, Mode, KeyList);
}
/*****************************************************************************/
/*.doc C_GRID::getKeyListFence */
/*+
Questa funzione effettua la selezione dei codici delle celle intersecanti ad
una fence esistente (celle intersecanti una polyline).
Parametri:
C_RB_LIST &CoordList; Lista delle coordinate
(<flag aperta o chiusa> <piano> <bulge1> <punto1> <bulge2> <punto2> ...)
<flag aperta o chiusa> = 0 se polilinea aperta altrimenti 1
<piano> vettore normale che identifica l'asse Z (0 0 1)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_GRID::getKeyListFence(C_RB_LIST &CoordList, C_LONG_BTREE &KeyList)
{
presbuf p;
int Closed, i = 0;
double Bulge;
AcGePoint2d Vertex;
AcDbPolyline ContainerEnt;
if (!(p = CoordList.get_head())) return GS_BAD;
if (gsc_rb2Int(p, &Closed) == GS_BAD) return GS_BAD; // leggo flag aperta/chiusa
if (!(p = p->rbnext)) return GS_BAD;
if (!(p = p->rbnext)) return GS_BAD; // salto il vettore normale dell'asse Z
while (p)
{
if (gsc_rb2Dbl(p, &Bulge) == GS_BAD) Bulge = 0.0; // potrebbe non esserci
else if (!(p = p->rbnext)) return GS_BAD;
AcGePoint2d_set_from_ads_point(p->resval.rpoint, Vertex);
ContainerEnt.addVertexAt(i++, Vertex, Bulge);
p = p->rbnext;
}
if (Closed == 1) ContainerEnt.setClosed(Adesk::kTrue);
return getKeyListInEntity(&ContainerEnt, CROSSING, KeyList);
}
int C_GRID::getKeyListBufferFence(C_RB_LIST &CoordList, int Mode, C_LONG_BTREE &KeyList)
{
presbuf p;
int Closed;
double Bulge1, Bulge2, OffSet;
AcGePoint3d Vertex, NextVertex, StartVertex;
C_LONG_BTREE PartialKeyList;
if (!(p = CoordList.get_head())) return GS_BAD;
if (gsc_rb2Dbl(p, &OffSet) == GS_BAD) return GS_BAD; // leggo offset
if (!(p = p->rbnext)) return GS_BAD;
if (gsc_rb2Int(p, &Closed) == GS_BAD) return GS_BAD; // leggo flag aperta/chiusa
if (!(p = p->rbnext)) return GS_BAD;
if (!(p = p->rbnext)) return GS_BAD; // salto il vettore normale dell'asse Z
// Per ogni tratto della polilinea verifico gli oggetti
if (gsc_rb2Dbl(p, &Bulge1) == GS_BAD) Bulge1 = 0.0; // potrebbe non esserci
else if (!(p = p->rbnext)) return GS_BAD;
if (p->restype != RTPOINT && p->restype != RT3DPOINT) return GS_BAD;
Vertex.set(p->resval.rpoint[X], p->resval.rpoint[Y], p->resval.rpoint[Z]);
if (Closed == 1) StartVertex.set(p->resval.rpoint[X], p->resval.rpoint[Y], p->resval.rpoint[Z]);
while ((p = p->rbnext))
{
if (gsc_rb2Dbl(p, &Bulge2) == GS_BAD) Bulge2 = 0.0; // potrebbe non esserci
else if (!(p = p->rbnext)) return GS_BAD;
if (p->restype != RTPOINT && p->restype != RT3DPOINT) return GS_BAD;
NextVertex.set(p->resval.rpoint[X], p->resval.rpoint[Y], p->resval.rpoint[Z]);
if (getKeyListBufferFence(Vertex, NextVertex, Bulge1, OffSet, Mode, PartialKeyList) == GS_BAD)
return GS_BAD;
if (KeyList.add_list(PartialKeyList) == GS_BAD) return GS_BAD;
Vertex.set(NextVertex.x, NextVertex.y, NextVertex.z);
Bulge1 = Bulge2;
}
if (Closed == 1) // Se polilinea chiusa
{
if (getKeyListBufferFence(Vertex, StartVertex, Bulge1, OffSet, Mode, PartialKeyList) == GS_BAD)
return GS_BAD;
if (KeyList.add_list(PartialKeyList) == GS_BAD) return GS_BAD;
}
return GS_GOOD;
}
/*****************************************************************************/
/*.doc C_GRID::getKeyListBufferFence <internal> */
/*+
Questa funzione è di ausilio alla C_GRID::getKeyListBufferFence e ottiene
gli oggetti che sono entro un buffer di un segmento rettilineo o un arco.
Parametri:
AcGePoint3d &Vertex; Primo punto del segmento
AcGePoint3d &NextVertex; Secondo punto del segmento
double Bulge; Tangente di 1/4 angolo interno
double OffSet; Distanza
int Mode; Flag: se INSIDE -> "inside", se CROSSING -> "crossing"
C_LONG_BTREE &KeyList; Risultato
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*****************************************************************************/
int C_GRID::getKeyListBufferFence(AcGePoint3d &Vertex, AcGePoint3d &NextVertex,
double Bulge, double OffSet, int Mode,
C_LONG_BTREE &KeyList)
{
AcDbPolyline *pExtBuffer, *pIntBuffer;
int res;
if (Bulge == 0) // segmento rettilineo
{
if (gsc_getBufferOnLine(Vertex, NextVertex, OffSet, &pExtBuffer) == GS_BAD) return GS_BAD;
pIntBuffer = NULL;
}
else // arco
if (Bulge < 0) // senso orario
{
if (gsc_getBufferOnArc(NextVertex, Vertex, -1 * Bulge, OffSet, &pExtBuffer, &pIntBuffer) == GS_BAD)
return GS_BAD;