-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_KML.cs
More file actions
1499 lines (1431 loc) · 83.8 KB
/
Program_KML.cs
File metadata and controls
1499 lines (1431 loc) · 83.8 KB
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
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.Linq;
using System.Reflection;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
using G = CoordinateSharp;
using OX = Microsoft.Office.Interop.Excel;
namespace Rio
{
public class Basicas
{
private Document _doc;
private Editor _edi;
private Database _db1;
private Database _db2;
private Transaction _tran;
private string _drive;
public string Drive { get { return _drive; } set { _drive = value; } }
public Document doc { get { return Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; } set { _doc = value; } }
public Editor edi { get { return Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor; } set { _edi = value; } }
public Database dba { get { return Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor.Document.Database;} set { _db1 = value; } }
public Database dbw { get { return HostApplicationServices.WorkingDatabase; } set { _db2 = value; } }
public Transaction tran { get { return _tran; } set { _tran = value; } }
public double Str_Doble (string s) { return System.Convert.ToDouble(s);}
public long Str_Int64 (string s) { return System.Convert.ToInt64(s); }
public int Str_Int32 (string s) { return System.Convert.ToInt32(s); }
public void Mensaje (string m)
{
System.Windows.Forms.MessageBox.Show(m);
}
public Point3d PontoMedio (Point3d p1, Point3d p2)
{
double dis = p1.DistanceTo(p2);
return new Point3d((p1.X + p2.X) * 0.5, (p1.Y + p2.Y) * 0.5, (p1.Z + p2.Z) * 0.5);
}
public Point3d PontoMedio (Point3d p1, Point3d p2, double fat)
{
double dis = p1.DistanceTo(p2);
return new Point3d((p1.X + p2.X) * fat, (p1.Y + p2.Y) * fat, (p1.Z + p2.Z) * fat);
}
public double Comprimento(Object curva)
{
Curve elem = curva as Curve;
double comprimento = 0.0;
if (elem != null)
{
comprimento = elem.GetDistanceAtParameter(elem.EndParam)
- elem.GetDistanceAtParameter(elem.StartParam);
}
return comprimento;
}
public ObjectId[] Captura_entidades(string entidade, bool msg )
{
ObjectId[] objid = null;
SelectionSet sset = null;
PromptSelectionResult res = null;
try
{
TypedValue[] filtro = new TypedValue[] {
new TypedValue((int)DxfCode.Start, entidade),
new TypedValue((int)DxfCode.LayerName, "0")
};
SelectionFilter ss = new SelectionFilter(filtro);
res = edi.SelectAll(ss);
sset = res.Value;
objid = sset.GetObjectIds();
if (msg == true) Mensaje("Entidades capturada tipo " + entidade + ". Total = " + objid.Count().ToString());
return objid;
}
catch { return objid; }
}
public ObjectId[] Captura_Zonas (string entidade, bool msg )
{
ObjectId[] objid = null;
SelectionSet sset = null;
PromptSelectionResult res = null;
try
{
TypedValue[] filtro = new TypedValue[] {
new TypedValue((int)DxfCode.Start, entidade),
new TypedValue((int)DxfCode.Operator, "<or"),
new TypedValue((int)DxfCode.LayerName, "Piano"),
new TypedValue((int)DxfCode.LayerName, "Violin"),
new TypedValue((int)DxfCode.LayerName, "Tuba"),
new TypedValue((int)DxfCode.LayerName, "Fundo"),
new TypedValue((int)DxfCode.Operator, "or>")
};
SelectionFilter ss = new SelectionFilter(filtro);
res = edi.SelectAll(ss);
sset = res.Value;
objid = sset.GetObjectIds();
if (msg == true)
Mensaje("Entidades capturada tipo " + entidade + ". Total = " + objid.Count().ToString());
return objid;
}
catch { return objid; }
}
public Entity Captura_Ultima ()
{
Entity ent;
ObjectId objid = Autodesk.AutoCAD.Internal.Utils.EntLast();
if (!objid.IsNull && objid.IsValid)
{
ent = (Entity)objid.GetObject(OpenMode.ForWrite) as Entity;
}
else
{
ent = null;
}
return ent;
}
public List<double> Caixa(Entity ent, out double dx, out double dy, out double dz)
{
List<double> bbox = new List<double> { };
Extents3d bb = ent.GeometricExtents;
Point3d p1 = bb.MinPoint;
Point3d p2 = bb.MaxPoint;
Point3d p0 = PontoMedio(p1, p2);
Vector3d v1 = p1.GetAsVector();
Vector3d v2 = p2.GetAsVector();
double ang = v1.GetAngleTo(v2) * (180 / Math.PI);
double seno = System.Math.Sin(ang);
double cose = System.Math.Cos(ang);
dx = p1.DistanceTo(p2) * cose; bbox.Add(dx);
dy = p1.DistanceTo(p2) * seno; bbox.Add(dy);
dz = 0.0; bbox.Add(dz);
return bbox;
}
// ----------------------------------------------------------------------------------------------------------------
public DBObject Cria_Esfera ( Transaction tr, Point3d centro, double raio, string nomelayer )
{
Matrix3d mat = new Matrix3d();
Solid3d esf = new Solid3d();
mat = Matrix3d.Displacement(centro.GetAsVector());
NovaEntidad(tr, esf);
esf.CreateSphere(raio);
esf.TransformBy(mat);
DBObject obj = tr.GetObject(esf.ObjectId, OpenMode.ForRead);
esf.Layer = nomelayer;
return obj;
}
public DBObject Cria_Circulo ( Transaction tr, Point3d centro, double raio )
{
Circle cir = new Circle();
cir.Center = centro;
cir.Radius = raio;
cir.Normal = Vector3d.ZAxis;
NovaEntidad(tr, cir);
DBObject obj = tr.GetObject(cir.ObjectId, OpenMode.ForRead);
return obj;
}
public DBObject Cria_Circulo ( Transaction tr, Point3d centro, double raio, string nomelayer )
{
Circle cir = new Circle();
cir.Center = centro;
cir.Radius = raio;
cir.Normal = Vector3d.ZAxis;
NovaEntidad(tr, cir);
DBObject obj = tr.GetObject(cir.ObjectId, OpenMode.ForRead);
cir.Layer = nomelayer;
return obj;
}
public DBObject Cria_Texto ( Transaction tr, Point3d pto, string txt )
{
Autodesk.AutoCAD.DatabaseServices.DBText tex = new Autodesk.AutoCAD.DatabaseServices.DBText();
tex.TextStyleId = dba.Textstyle;
tex.TextString = txt;
tex.Position = pto;
tex.Rotation = 0.0;
tex.Height = 0.1;
tex.Normal = Vector3d.ZAxis;
NovaEntidad(tr, tex);
DBObject obj = tr.GetObject(tex.ObjectId, OpenMode.ForRead);
edi.UpdateScreen();
return obj;
}
public DBObject Cria_Hachura ( Transaction tr, DBObject obj, double elev )
{
Hatch Hachura = new Hatch();
NovaEntidad(tr, Hachura);
ObjectIdCollection objcol = new ObjectIdCollection();
objcol.Add(obj.ObjectId);
Hachura.SetDatabaseDefaults();
Hachura.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
Hachura.AppendLoop(HatchLoopTypes.Default, objcol);
Hachura.Color = Autodesk.AutoCAD.Colors.Color.FromRgb((byte)100, (byte)100, (byte)100);
Hachura.Transparency = new Autodesk.AutoCAD.Colors.Transparency((byte)70);
Hachura.Elevation = elev;
Hachura.Associative = true;
edi.UpdateScreen();
return tr.GetObject(Hachura.ObjectId, OpenMode.ForRead);
}
public Entity NovaEntidad ( Transaction tr, Entity ent )
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(dba.CurrentSpaceId, OpenMode.ForWrite);
ObjectId obj = btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
return ent;
}
public void Faz_Offset ( Transaction tr, Polyline pl , BlockTableRecord btr)
{
foreach (Entity ent in pl.GetOffsetCurves(0.025))
{
btr.AppendEntity( ent );
tr.AddNewlyCreatedDBObject( ent , true );
}
}
public ObjectId[] Prepara_Zonas ( )
{
ObjectId[] PoligonaisZonas = Captura_Zonas("LWPOLYLINE", true);
return PoligonaisZonas;
}
public string Ponto_Dentro ( Polyline poli, Point3d p0 )
{
string puntoadentro = "-";
Point3d p1 = poli.GetPoint3dAt(0);
Point3d p2 = poli.GetPoint3dAt(1);
Point3d p3 = poli.GetPoint3dAt(2);
Point3d p4 = poli.GetPoint3dAt(3);
double areapoli = poli.Area;
string layerpol = poli.Layer;
double areatri1 = AreaTriangulo(p0, p1, p2);
double areatri2 = AreaTriangulo(p0, p2, p3);
double areatri3 = AreaTriangulo(p0, p3, p4);
double areatri4 = AreaTriangulo(p0, p4, p1);
double somatori = areatri1 + areatri2 + areatri3 + areatri4;
if (areapoli > (somatori * 0.995) && areapoli < (somatori * 1.005))
puntoadentro = layerpol;
else
puntoadentro = "-";
return puntoadentro;
}
public double AreaTriangulo ( Point3d p1, Point3d p2, Point3d p3 )
{
double a = p1.DistanceTo(p2);
double b = p2.DistanceTo(p3);
double c = p3.DistanceTo(p1);
double S = (a + b + c) / 2.0;
double area = Math.Sqrt(S * (S - a) * (S - b) * (S - c));
return area;
}
public Point3d Seleccion_Ponto ( string msg )
{
PromptPointOptions pop = new PromptPointOptions("\n" + msg);
PromptPointResult pnt = edi.GetPoint(pop);
if (pnt.Status == PromptStatus.OK)
return pnt.Value;
else
return new Point3d();
}
public int Ingressar_Inteiro ( string msg, int defaul)
{
PromptIntegerResult numint;
PromptIntegerOptions inte = new PromptIntegerOptions("\n" + msg);
inte.DefaultValue = defaul;
inte.UseDefaultValue = true;
numint = edi.GetInteger(inte);
return numint.Value;
}
public double Ingressar_Real ( string msg, double defaul )
{
PromptDoubleResult numreal;
PromptDoubleOptions real = new PromptDoubleOptions("\n" + msg);
real.DefaultValue = defaul;
real.UseDefaultValue = true;
numreal = edi.GetDouble(real);
return numreal.Value;
}
public string Ingressar_Text ( string msg, string defaul )
{
PromptResult texto;
PromptStringOptions textoin = new PromptStringOptions("\n" + msg);
textoin.DefaultValue = defaul;
textoin.UseDefaultValue = true;
texto = edi.GetString(textoin);
if (texto.Status != PromptStatus.OK)
return defaul;
else
return texto.StringResult;
}
public bool ParImp(int num) { return num % 2 == 0; } // Verifica se número é par ou impar
public bool Modulo(int num, int mod) { return num % mod == 0; } // Verifica indice modular do número
public int Congru(int num, int mod)
{
int partes = (num / mod);
int modular = (num - (partes * mod));
return modular;
} // Retorna congruente modular do número
public Entity Selecionar_Entidad (string msg )
{
DBObject obj;
Entity ent;
PromptEntityResult per = edi.GetEntity("\n" + msg);
Transaction tra = doc.TransactionManager.StartTransaction();
using (tra)
{
obj = tra.GetObject(per.ObjectId, OpenMode.ForRead);
ent = obj as Entity;
return ent;
}
}
public SelectionSet FiltrarLayer (string layer)
{
TypedValue[] tvs = new TypedValue[] { new TypedValue((int)DxfCode.LayerName, layer), };
SelectionFilter sset = new SelectionFilter(tvs);
PromptSelectionResult psr = edi.SelectAll( sset );
return psr.Value;
}
public ObjectId[] FiltraObjetos(string entidade, string layer1)
{
ObjectId[] objetos = null;
SelectionSet sset = null;
PromptSelectionResult res = null;
try
{
TypedValue[] filtro = new TypedValue[] {
new TypedValue((int)DxfCode.Operator,"<and"),
new TypedValue((int)DxfCode.Start, entidade),
new TypedValue((int)DxfCode.LayerName, layer1),
new TypedValue((int)DxfCode.Operator,"and>")
};
SelectionFilter ssfil = new SelectionFilter(filtro);
res = edi.SelectAll(ssfil);
sset = res.Value;
objetos = sset.GetObjectIds();
return objetos;
}
catch { return objetos; }
}
public ObjectId[] Filtrar_Temas(string[] layer1)
{
ObjectId[] objetos = null;
SelectionSet sset = null;
PromptSelectionResult res = null;
string layers = "";
foreach (string s in layer1)
{
layers = layers + "," + s;
}
try
{
TypedValue[] filtro = new TypedValue[] {
new TypedValue((int)DxfCode.Operator,"<and"),
new TypedValue(8, layers),
new TypedValue((int)DxfCode.Operator,"and>")
};
SelectionFilter ssfil = new SelectionFilter(filtro);
res = edi.SelectAll(ssfil);
sset = res.Value;
objetos = sset.GetObjectIds();
return objetos;
}
catch { return objetos; }
}
public string Extrair_Pontos ( Entity enti, Transaction tr)
{
string t = enti.GetType().ToString();
string p = "-";
string s = " ";
switch (t)
{
case "Autodesk.AutoCAD.DatabaseServices.DBPoint": p = Extrair_xyz_pontos ( enti , s ); break;
case "Autodesk.AutoCAD.DatabaseServices.Line": p = Extrair_xyz_linhas ( enti , s ); break;
case "Autodesk.AutoCAD.DatabaseServices.Circle": p = Extrair_xyz_circle ( enti , s ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline": p = Extrair_xyz_poly2D ( enti , s , 0.1 ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline2d": p = Extrair_xyz_poly2D ( enti , s , 0.1 ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline3d": p = Extrair_xyz_poly3D ( enti , s , 0.1, tr); break;
case "Autodesk.AutoCAD.DatabaseServices.BlockReference": p = Extrair_xyz_bloco ( enti , s ); break;
case "Autodesk.AutoCAD.DatabaseServices.DBText": p = Extrair_xyz_texto ( enti , s ); break;
default: p = "-"; break;
}
return p;
}
public string Extrair_Pontos_KML ( Entity enti, Transaction tr)
{
string t = enti.GetType().ToString();
string p = "-";
switch (t)
{
case "Autodesk.AutoCAD.DatabaseServices.DBPoint": p = Extrair_UTM_pontos (enti ); break;
case "Autodesk.AutoCAD.DatabaseServices.Line": p = Extrair_UTM_linhas (enti ); break;
case "Autodesk.AutoCAD.DatabaseServices.Circle": p = Extrair_UTM_circle (enti ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline": p = Extrair_UTM_poly2D (enti , 0.1 ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline2d": p = Extrair_UTM_poly2D (enti , 0.1 ); break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline3d": p = Extrair_UTM_poly3D (enti , 0.1 , tr); break;
case "Autodesk.AutoCAD.DatabaseServices.BlockReference": p = Extrair_UTM_bloco (enti ); break;
case "Autodesk.AutoCAD.DatabaseServices.DBText": p = Extrair_UTM_texto (enti ); break;
default: p = "-"; break;
}
return p;
}
public string Tipo_de_Objeto ( Entity enti)
{
string tipo = enti.GetType().ToString();
string obje = "Desconocido";
switch (tipo)
{
case "Autodesk.AutoCAD.DatabaseServices.DBPoint": obje = "Ponto"; break;
case "Autodesk.AutoCAD.DatabaseServices.Line": obje = "Linha"; break;
case "Autodesk.AutoCAD.DatabaseServices.Circle": obje = "Circulo"; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline": obje = "Poli_2D"; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline2d": obje = "Poli_2D"; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline3d": obje = "Poli_3D"; break;
case "Autodesk.AutoCAD.DatabaseServices.BlockReference": obje = "Bloco"; break;
case "Autodesk.AutoCAD.DatabaseServices.DBText": obje = "Texto"; break;
default: obje = "Desconocido"; break;
}
return obje;
}
public string Texto_do_Objeto ( Entity enti)
{
string tipo = enti.GetType().ToString();
string texto = "-";
switch (tipo)
{
case "Autodesk.AutoCAD.DatabaseServices.DBText": texto = Extrair_texto(enti); break;
default: texto = "-"; break;
}
return texto;
}
public double Area_objeto ( Entity enti)
{
double area = 0.0;
Curve ob = enti as Curve;
string tipo = enti.GetType().ToString();
switch (tipo)
{
case "Autodesk.AutoCAD.DatabaseServices.DBPoint": break;
case "Autodesk.AutoCAD.DatabaseServices.Line": break;
case "Autodesk.AutoCAD.DatabaseServices.Circle": area = ob.Area; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline": area = ob.Area; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline2d": area = ob.Area; break;
case "Autodesk.AutoCAD.DatabaseServices.Polyline3d": area = ob.Area; break;
default: break;
}
return area;
}
public string Extrair_texto ( Entity enti)
{
string texto = "-";
DBText txt = enti as DBText;
texto = txt.TextString;
return texto;
}
public string Extrair_xyz_texto ( Entity enti, string sep)
{
string coords = "-";
DBText entxt = enti as DBText;
Point3d p1 = entxt.Position;
coords = p1.X.ToString() + sep + p1.Y.ToString() + sep + p1.Z.ToString();
return coords;
}
public string Extrair_xyz_pontos ( Entity enti, string sep)
{
string coords = "";
DBPoint pnt = enti as DBPoint;
Point3d p1 = pnt.Position;
coords = p1.X.ToString() + sep + p1.Y.ToString() + sep + p1.Z.ToString();
return coords;
}
public string Extrair_xyz_linhas ( Entity enti, string sep)
{
string coords = "";
Line linha = enti as Line;
Point3d p1 = linha.StartPoint;
Point3d p2 = linha.EndPoint;
coords = p1.X.ToString() + sep + p1.Y.ToString() + sep + p1.Z.ToString() + " " + p2.X.ToString() + sep + p2.Y.ToString() + sep + p2.Z.ToString();
return coords;
}
public string Extrair_xyz_circle ( Entity enti, string sep)
{
string coords = "";
Circle circulo = enti as Circle;
Point3d p1 = circulo.Center;
coords = p1.X.ToString() + sep + p1.Y.ToString() + sep + p1.Z.ToString();
return coords;
}
public string Extrair_xyz_bloco ( Entity enti, string sep)
{
string coords = "";
BlockReference bloco = enti as BlockReference;
Point3d p1 = bloco.Position;
coords = p1.X.ToString() + sep + p1.Y.ToString() + sep + p1.Z.ToString();
return coords;
}
public string Extrair_xyz_poly2D ( Entity enti, string sep, double preci)
{
string coords = "";
Polyline poly2d = enti as Polyline;
double elevac = poly2d.Elevation;
List<Point2d> Lp = new List<Point2d> { };
for (int i = 0; i < poly2d.NumberOfVertices; i++)
{
Point2d p1 = poly2d.GetPoint2dAt(i);
if (Lp.Count == 0)
Lp.Add(p1);
else
{ if (p1.GetDistanceTo(Lp.Last()) > preci)
Lp.Add(p1);
}
}
for (int i = 0; i < Lp.Count; i++)
{
Point2d p1 = Lp[i];
string vertice = p1.X.ToString() + sep + p1.Y.ToString() + sep + elevac.ToString();
if (!coords.Contains(vertice))
{
coords = coords + " " + vertice;
}
}
return coords;
}
public string Extrair_xyz_poly3D ( Entity enti, string sep, double preci , Transaction tr)
{
string coords = "";
Polyline3d poly3d = enti as Polyline3d;
List<Point3d> Lp = new List<Point3d> { };
List<double> Lalt = new List<double> { };
foreach (ObjectId acObjIdVert in poly3d)
{
PolylineVertex3d p1 = tr.GetObject(acObjIdVert, OpenMode.ForRead) as PolylineVertex3d;
Lalt.Add(p1.Position.Z);
}
string alturamax = Lalt.Max().ToString();
foreach (ObjectId acObjIdVert in poly3d)
{
PolylineVertex3d p1 = tr.GetObject(acObjIdVert, OpenMode.ForRead) as PolylineVertex3d;
string vertice = p1.Position.X.ToString() + sep + p1.Position.Y.ToString() + sep + alturamax;
if (Lp.Count == 0)
{
coords = coords + " " + vertice;
Lp.Add(p1.Position);
}
else {
Point3d px = p1.Position;
if (px.DistanceTo(Lp.Last()) > preci && !coords.Contains(vertice))
{
coords = coords + " " + vertice;
Lp.Add(p1.Position);
}
}
}
return coords;
}
public Vector2d VetorCorrecao2d = new Vector2d(-43.85591336, -45.81013948);
public Vector3d VetorCorrecao3d = new Vector3d(-43.85591336, -45.81013948, 0);
public string ElevacaoPonto = "";
public string ElevacaoTotal = "";
public string Traduz_GeoPonto ( Point3d p1 )
{
double altura = p1.Z;
if (altura == 0)
altura = 6.1234;
Point3d pc = p1.Add( VetorCorrecao3d ); //desloca para corrigir posição
G.UniversalTransverseMercator utm1 = new G.UniversalTransverseMercator("23K", pc.X, pc.Y);
double[] lat1 = G.UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm1);
string coor = lat1[1].ToString() + "," + lat1[0].ToString() + "," + altura.ToString();
return coor;
}
public string Traduz_GeoPonto ( Point2d p1 , double altura)
{
if (altura == 0)
altura = 6.1234;
Point2d pc = p1.Add( VetorCorrecao2d ); //desloca para corrigir posição
G.UniversalTransverseMercator utm1 = new G.UniversalTransverseMercator("23K", pc.X, pc.Y);
double[] lat1 = G.UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm1);
string coor = lat1[1].ToString() + "," + lat1[0].ToString() + "," + altura.ToString();
return coor;
}
public string Traduz_GeoPonto ( PolylineVertex3d p1 , double altura)
{
if (altura == 0)
altura = 6.1234;
Point3d pc = new Point3d(p1.Position.X, p1.Position.Y, p1.Position.Z).Add( VetorCorrecao3d );
G.UniversalTransverseMercator utm1 = new G.UniversalTransverseMercator("23K", pc.X, pc.Y);
double[] lat1 = G.UniversalTransverseMercator.ConvertUTMtoSignedDegree(utm1);
string coor = lat1[1].ToString() + "," + lat1[0].ToString() + "," + altura.ToString();
return coor;
}
public string Extrair_UTM_texto ( Entity enti )
{
DBText entxt = enti as DBText;
Point3d p1 = entxt.Position;
string coords = Traduz_GeoPonto(p1);
return coords;
}
public string Extrair_UTM_pontos ( Entity enti )
{
DBPoint pnt = enti as DBPoint;
Point3d p1 = pnt.Position;
string coords = Traduz_GeoPonto( p1 );
return coords;
}
public string Extrair_UTM_linhas ( Entity enti )
{
Line linha = enti as Line;
Point3d p1 = linha.StartPoint;
Point3d p2 = linha.EndPoint;
string coo1 = Traduz_GeoPonto( p1 );
string coo2 = Traduz_GeoPonto( p2 );
return coo1 + " " + coo2;
}
public string Extrair_UTM_circle ( Entity enti )
{
Circle circulo = enti as Circle;
Point3d p1 = circulo.Center;
string coords = Traduz_GeoPonto( p1 );
return coords;
}
public string Extrair_UTM_bloco ( Entity enti )
{
BlockReference bloco = enti as BlockReference;
Point3d p1 = bloco.Position;
string coords = Traduz_GeoPonto(p1);
return coords;
}
public string Extrair_UTM_poly2D ( Entity enti, double preci)
{
string coords = "";
Polyline poly2d = enti as Polyline;
double elevac = poly2d.Elevation;
List<Point2d> Lp = new List<Point2d> { };
for (int i = 0; i < poly2d.NumberOfVertices; i++)
{
Point2d p1 = poly2d.GetPoint2dAt(i);
if (Lp.Count == 0)
Lp.Add(p1);
else
{
if (p1.GetDistanceTo(Lp.Last()) > preci)
Lp.Add ( p1 );
}
}
Lp.Add(Lp.First());
for (int i = 0; i < Lp.Count; i++)
{
Point2d p1 = Lp[i];
string vrtz = Traduz_GeoPonto( p1 , elevac );
if (!coords.Contains( vrtz ))
{
coords = coords + " " + vrtz;
}
}
return coords;
}
public string Extrair_UTM_poly3D ( Entity enti, double preci, Transaction tr)
{
string coords = "";
Polyline3d poly3d = enti as Polyline3d;
List<PolylineVertex3d> Lvrtcs = new List<PolylineVertex3d> { };
List<string> Lvzgeo = new List<string> { };
List<double> Lalt = new List<double> { };
foreach (ObjectId acObjIdVert in poly3d)
{
PolylineVertex3d vrtc1 = tr.GetObject(acObjIdVert, OpenMode.ForRead) as PolylineVertex3d;
Lalt.Add( vrtc1.Position.Z );
}
double alturamin = Lalt.Min();
double alturamax = Lalt.Max();
foreach (ObjectId acObjIdVert in poly3d)
{
PolylineVertex3d vrtc1 = tr.GetObject(acObjIdVert, OpenMode.ForRead) as PolylineVertex3d;
string vrtz = Traduz_GeoPonto( vrtc1 , alturamax );
Lvzgeo.Add(vrtz);
if (Lvrtcs.Count == 0)
{
coords = coords + " " + vrtz;
Lvrtcs.Add( vrtc1 );
}
else
{
if (vrtc1.Position.DistanceTo (Lvrtcs.Last().Position) > preci && !coords.Contains(vrtz))
{
coords = coords + " " + vrtz;
Lvrtcs.Add( vrtc1 );
}
}
}
coords = coords + " " + Lvzgeo.First(); //adiciona o primeiro para fechar o ring
return coords;
}
}
public class Rio : Basicas
{
private List<string[]> barrial; public List<string[]> Barrial { get { return barrial; } set { barrial = value; } }
private List<string[]> tematic; public List<string[]> Tematic { get { return tematic; } set { tematic = value; } }
public void Cria_Texto ( List<Point3d> Lpontos, string layer, string txt)
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database dbase = acDoc.Database;
using (Transaction tr = dbase.TransactionManager.StartTransaction())
{
BlockTable btl;
BlockTableRecord btr;
btl = tr.GetObject(dbase.BlockTableId, OpenMode.ForRead) as BlockTable;
btr = tr.GetObject(btl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
foreach (Point3d p in Lpontos)
{
using (DBText enttxt = new DBText())
{
btr.AppendEntity(enttxt);
tr.AddNewlyCreatedDBObject(enttxt, true);
enttxt.Layer = layer;
enttxt.TextString = txt;
enttxt.Position = p;
enttxt.Rotation = 0.0;
enttxt.Height = 1.5;
enttxt.Normal = Vector3d.ZAxis;
}
}
tr.Commit();
}
}
public void Cria_Ponto ( List<Point3d> Lpontos, string layer )
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database dbase = acDoc.Database;
using (Transaction tr = dbase.TransactionManager.StartTransaction())
{
BlockTable btl;
BlockTableRecord btr;
btl = tr.GetObject(dbase.BlockTableId, OpenMode.ForRead) as BlockTable;
btr = tr.GetObject(btl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
dbase.Pdmode = 34;
dbase.Pdsize = 1;
foreach (Point3d p in Lpontos)
{
using (DBPoint entponto = new DBPoint(p))
{
btr.AppendEntity(entponto);
tr.AddNewlyCreatedDBObject(entponto, true);
entponto.Layer = layer;
}
}
tr.Commit();
}
}
public void Cria_Linha ( List<Point3d> Lpontos, string layer )
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database dbase = acDoc.Database;
using (Transaction tr = dbase.TransactionManager.StartTransaction())
{
BlockTable btl;
BlockTableRecord btr;
btl = tr.GetObject(dbase.BlockTableId, OpenMode.ForRead) as BlockTable;
btr = tr.GetObject(btl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Line lin = new Line(Lpontos[0], Lpontos[1]);
tr.AddNewlyCreatedDBObject(lin, true);
lin.Layer = layer;
tr.Commit();
}
}
public void Cria_Poli_3D ( List<Point3d> Lpontos, string layer , bool fecha)
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database dbase = acDoc.Database;
using (Transaction tr = dbase.TransactionManager.StartTransaction())
{
BlockTable btl;
BlockTableRecord btr;
btl = tr.GetObject(dbase.BlockTableId, OpenMode.ForRead) as BlockTable;
btr = tr.GetObject(btl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (Polyline3d Poly3d = new Polyline3d())
{
Poly3d.Closed = fecha;
btr.AppendEntity(Poly3d);
tr.AddNewlyCreatedDBObject(Poly3d, true);
Point3dCollection acPts3dPoly = new Point3dCollection();
for (int i = 0; i < Lpontos.Count; i++) { acPts3dPoly.Add(Lpontos[i]); }
foreach (Point3d acPt3d in acPts3dPoly)
{
using (PolylineVertex3d acPolVer3d = new PolylineVertex3d(acPt3d))
{
Poly3d.AppendVertex(acPolVer3d);
tr.AddNewlyCreatedDBObject(acPolVer3d, true);
}
}
Poly3d.Layer = layer;
}
tr.Commit();
}
}
public void Cria_Camada ( string layer, short cor)
{
if (layer != "")
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database dba = doc.Database;
string des = Rio_Dados_Tematica(layer)[4];
using (Transaction tra = dba.TransactionManager.StartTransaction())
{
LayerTable camadas = (LayerTable)tra.GetObject(dba.LayerTableId, OpenMode.ForRead);
if (!camadas.Has(layer))
{
camadas.UpgradeOpen();
using (LayerTableRecord camareg = new LayerTableRecord())
{
camareg.Name = layer;
camareg.LineWeight = LineWeight.LineWeight015;
camareg.Color = Color.FromColorIndex(ColorMethod.ByAci, cor);
camadas.Add(camareg);
tra.AddNewlyCreatedDBObject(camareg, true);
camareg.Description = des;
}
}
tra.Commit();
}
}
}
// ----------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------
[CommandMethod("RIOIN")]
public void Rio_IN()
{
try
{
string Pasta;
List<string> Temario;
List<string> Barrios;
Rio_Selecion_Tema (out Pasta, out Temario, out Barrios);
if (Temario.Count > 0)
{
Rio_Insertar_Temas(Pasta, Temario, Barrios);
}
}
catch { }
finally { }
Mensaje( "Temas inseridos." );
}
public void Rio_Selecion_Tema ( out string Pasta, out List<string> Temario, out List<string> Barrios)
{
string Drive = "C";
Pasta = Drive + ":\\JLMenegotto\\Academia\\04_Pesquisa\\MRJ\\MRJ_ORIG";
Form1 QDia = new Form1();
if (QDia.Temario.Count > 0) { Temario = QDia.Temario; } else { Temario = new List<string> { "_" }; }
if (QDia.Barrios.Count > 0) { Barrios = QDia.Barrios; } else { Barrios = new List<string> { "_" }; }
Barrial = QDia.Rio_Barrial();
Tematic = QDia.Rio_GruTema();
}
public void Rio_Insertar_Temas ( string pasta, List<string> TemasPro, List<string> BarriosPro)
{
for (int t = 0; t < TemasPro.Count; t++)
{
Cria_Camada(TemasPro[t], (short)(t + 10)); //Cria_os layers necessarios
}
for (int t = 0; t < TemasPro.Count; t++)
{
XmlDocument xmlDoc = new XmlDocument();
string Tema = TemasPro[t];
string Arq_XML_Tema = pasta + "\\Rio_" + Tema + ".XML";
xmlDoc.Load(Arq_XML_Tema);
char[] separa = new char[] { ' ' };
foreach (string barrio in BarriosPro)
{
Rio_Procurar_Barrio(xmlDoc, Arq_XML_Tema, Tema, barrio);
}
}
}
public void Rio_Procurar_Barrio ( XmlDocument doc, string nomearq, string tema, string barr)
{
XmlNode nodoraiz = null;
XmlNodeList L_nodos = null;
XmlNodeList L_Elem = null;
doc.Load(nomearq);
nodoraiz = doc.DocumentElement;
L_nodos = nodoraiz.SelectNodes("descendant::Bairro[@Bairro_Zona='" + barr + "']");
for (int i = 0; i < L_nodos.Count; i++)
{
L_Elem = ((XmlElement)(L_nodos[i])).GetElementsByTagName("Elemento");
for (int j = 0; j < L_Elem.Count; j++)
{
XmlElement elemento = (XmlElement)L_Elem[j];
string texto = "-";
string coord = elemento.GetAttributeNode("Local").Value;
string objet = elemento.GetAttributeNode("Objeto").Value;
if (elemento.HasAttribute("Texto"))
{ texto = elemento.GetAttributeNode("Texto").Value; }
string[] coords = Rio_Separar_Coordena(coord.Substring(1));
List<Point3d> Lpontos = new List<Point3d> { };
for (int k = 0; k < (coords.Length / 3); k++)
{
double x = Convert.ToDouble(coords[3 * k + 0]);
double y = Convert.ToDouble(coords[3 * k + 1]);
double z = Convert.ToDouble(coords[3 * k + 2]);
Point3d pt = new Point3d(x, y, z);
Lpontos.Add(pt);
}
Rio_Desenhar_Objetos ( objet, tema, Lpontos, texto );
}
}
}
public void Rio_Desenhar_Objetos ( string objeto , string tema, List<Point3d> Lpnts, string texto)
{
bool fecha = true;
switch (tema)
{
case "338": fecha = false; break;
case "339": fecha = false; break;
case "500": fecha = false; break;
case "502": fecha = false; break;
case "503": fecha = false; break;
case "504": fecha = false; break;
case "505": fecha = false; break;
case "506": fecha = false; break;
case "507": fecha = false; break;
case "508": fecha = false; break;
case "562": fecha = false; break;
case "572": fecha = false; break;
case "650": fecha = false; break;
case "651": fecha = false; break;
case "652": fecha = false; break;
case "653": fecha = false; break;
case "654": fecha = false; break;
case "655": fecha = false; break;
case "656": fecha = false; break;
case "657": fecha = false; break;
case "658": fecha = false; break;
case "671": fecha = false; break;
case "672": fecha = false; break;
case "696": fecha = false; break;
case "714": fecha = false; break;
case "720": fecha = false; break;
case "721": fecha = false; break;
case "722": fecha = false; break;
case "723": fecha = false; break;
case "780": fecha = false; break;
case "781": fecha = false; break;
case "782": fecha = false; break;
case "783": fecha = false; break;
case "784": fecha = false; break;
case "785": fecha = false; break;
case "786": fecha = false; break;
default: break;
}
switch (objeto)
{