public override Geometria RetornarGeometria() { if (Vertices == null && Aneis == null) { throw new ApplicationException("Referência nula de objeto"); } Tecnomapas.TecnoGeo.Geometria.Primitiva.Poligono poligono = new Tecnomapas.TecnoGeo.Geometria.Primitiva.Poligono(2, false); Anel anel = null; SegmentoLinhaReto segm = null; if (Aneis != null) { List <Vertice> lista; for (int i = 0; i < Aneis.Count; i++) { segm = new Tecnomapas.TecnoGeo.Geometria.Primitiva.SegmentoLinhaReto(); lista = Aneis[i] as List <Vertice>; if (lista != null) { for (int k = 0; k < lista.Count; k++) { segm.Posicoes.Adicionar(new Posicao( Convert.ToDecimal(lista[k].X), Convert.ToDecimal(lista[k].Y))); } if (lista.Count > 1 && !(lista[0].X == lista[lista.Count - 1].X && lista[0].Y == lista[lista.Count - 1].Y)) { segm.Posicoes.Adicionar(new Posicao(Convert.ToDecimal(lista[0].X), Convert.ToDecimal(lista[0].Y))); } anel = new Anel(); anel.Segmentos.Adicionar(segm); poligono.Aneis.Adicionar(anel); } } } if (Vertices != null && Vertices.Count > 0) { anel = new Anel(); segm = new SegmentoLinhaReto(); for (int i = 0; i < Vertices.Count; i++) { segm.Posicoes.Adicionar(new Posicao(Convert.ToDecimal(Vertices[i].X), Convert.ToDecimal(Vertices[i].Y))); } if (Vertices.Count > 1 && !(Vertices[0].X == Vertices[Vertices.Count - 1].X && Vertices[0].Y == Vertices[Vertices.Count - 1].Y)) { segm.Posicoes.Adicionar(new Posicao(Convert.ToDecimal(Vertices[0].X), Convert.ToDecimal(Vertices[0].Y))); } anel.Segmentos.Adicionar(segm); poligono.Aneis.Adicionar(anel); } return(poligono); }
private PoligonoCollection GerarPoligonos(Decimal[] elem_info, Decimal[] ordinates, int dimensoes, int eixoLrs, bool multiplo) { PoligonoCollection poligonoCollection = new PoligonoCollection(); int triplet = 0; bool ehLrs = eixoLrs != 0; while (triplet < elem_info.Length) { if (elem_info[triplet + 1] == new Decimal(1005) || elem_info[triplet + 1] == new Decimal(1003)) { try { Anel anel1 = this.GerarAnel(elem_info, ordinates, dimensoes, eixoLrs, ref triplet); Poligono poligono = new Poligono(ehLrs ? dimensoes - 1 : dimensoes, ehLrs); if (anel1 == null) { throw new Exception("Falha ao ler o anel externo"); } poligono.Aneis.Adicionar(anel1); triplet += 3; while (triplet < elem_info.Length && (elem_info[triplet + 1] == new Decimal(2005) || elem_info[triplet + 1] == new Decimal(2003))) { Anel anel2 = this.GerarAnel(elem_info, ordinates, dimensoes, eixoLrs, ref triplet); if (anel2 == null) { throw new Exception("Falha ao ler o anel interno"); } poligono.Aneis.Adicionar(anel2); triplet += 3; } triplet -= 3; poligonoCollection.Adicionar(poligono); } catch { } if (!multiplo) { return(poligonoCollection); } } triplet += 3; } return(poligonoCollection); }
private Anel GerarAnel(Decimal[] elem_info, Decimal[] ordinates, int dimensoes, int eixoLrs, ref int triplet) { Anel anel = (Anel)null; bool flag = eixoLrs != 0; if (elem_info[triplet + 1] == new Decimal(1005) || elem_info[triplet + 1] == new Decimal(2005)) { try { int int32_1 = Convert.ToInt32(elem_info[triplet + 2]); anel = new Anel(); for (int index = 0; index < int32_1; ++index) { triplet += 3; if (elem_info[triplet + 1] != new Decimal(2)) { throw new Exception("Tipo heterogêneo de anel errado"); } int int32_2 = Convert.ToInt32(elem_info[triplet]); int fim = triplet < elem_info.Length - 3 ? Convert.ToInt32(elem_info[triplet + 3]) - (index == int32_1 - 1 ? 1 : -1) : ordinates.Length - 1; SegmentoLinha segmento = this.GerarSegmento(ordinates, int32_2, fim, Convert.ToInt32(elem_info[triplet + 2]), dimensoes, eixoLrs); if (segmento == null) { throw new Exception("Falha ao ler um segmento"); } anel.Segmentos.Adicionar(segmento); } } catch { anel = (Anel)null; } } else if (elem_info[triplet + 1] == new Decimal(1003) || elem_info[triplet + 1] == new Decimal(2003)) { try { int int32 = Convert.ToInt32(elem_info[triplet]); int fim = triplet < elem_info.Length - 3 ? Convert.ToInt32((elem_info[triplet + 3]) - 1) : ordinates.Length - 1; SegmentoLinha segmento = this.GerarSegmento(ordinates, int32, fim, Convert.ToInt32(elem_info[triplet + 2]), dimensoes, eixoLrs); if (segmento == null) { throw new Exception("Falha ao ler um segmento"); } if (elem_info[triplet + 2] == new Decimal(3)) { Posicao[] posicaoArray = new Posicao[4] { segmento.Posicoes[0], null, segmento.Posicoes[1], null }; posicaoArray[1] = new Posicao(posicaoArray[0].Dimensoes, posicaoArray[0].EhLrs); posicaoArray[1].X = posicaoArray[2].X; posicaoArray[1].Y = posicaoArray[0].Y; if (posicaoArray[1].Dimensoes == 3) { posicaoArray[1].Z = posicaoArray[0].Z; } posicaoArray[3] = new Posicao(posicaoArray[2].Dimensoes, posicaoArray[2].EhLrs); posicaoArray[3].X = posicaoArray[0].X; posicaoArray[3].Y = posicaoArray[2].Y; if (posicaoArray[3].Dimensoes == 3) { posicaoArray[3].Z = posicaoArray[2].Z; } segmento = (SegmentoLinha) new SegmentoLinhaReto(); segmento.Posicoes.Adicionar(posicaoArray[0]); if (elem_info[triplet + 1] == new Decimal(1003)) { segmento.Posicoes.Adicionar(posicaoArray[1]); segmento.Posicoes.Adicionar(posicaoArray[2]); segmento.Posicoes.Adicionar(posicaoArray[3]); } else { segmento.Posicoes.Adicionar(posicaoArray[3]); segmento.Posicoes.Adicionar(posicaoArray[2]); segmento.Posicoes.Adicionar(posicaoArray[1]); } segmento.Posicoes.Adicionar(posicaoArray[0]); } anel = new Anel(); anel.Segmentos.Adicionar(segmento); } catch { } } return(anel); }