public override bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (obj.GetType() != this.GetType()) { return(false); } Imagem im = (Imagem)obj; return(this.indice == im.indice); }
private void interpretarDesenhavel(Desenhavel aInterpretar) { //this.width => largura da janela //this.length => altura da janela //** espessura e cor alturaTotal = this.Height; larguraTotal = this.Width; double xC = 0, yC = 0, largura = 0, altura = 0; xC = aInterpretar.XRelCentro * larguraTotal; yC = aInterpretar.YRelCentro * alturaTotal; largura = aInterpretar.LarguraRel * larguraTotal; altura = aInterpretar.AlturaRel * alturaTotal; if (aInterpretar.GetType() == typeof(Imagem)) { Imagem imagemAInterpretar = (Imagem)aInterpretar; Image imagemInterpretada = imagemAInterpretar.imagem(); if (imagemInterpretada != null) { double x1 = 0, y1 = 0; largura *= taxaProporcaoLargura; altura *= taxaProporcaoAltura; x1 = xC - (largura / 2); y1 = yC - (altura / 2); g.DrawImage(imagemInterpretada, Convert.ToInt32(x1), Convert.ToInt32(y1), Convert.ToInt32(largura), Convert.ToInt32(altura)); } } if (aInterpretar.GetType() == typeof(Forma)) { Forma formaAInterpretar = (Forma)aInterpretar; double x1 = 0, y1 = 0, x2 = 0, y2 = 0; switch (formaAInterpretar.Tipo) { case Forma.TipoForma.Reta: try { caneta = new Pen(corReta, espessura); x1 = xC - (largura / 2); y1 = yC - (altura / 2); x2 = x1 + largura; y2 = y1 + altura; g.DrawLine(caneta, (float)x1, (float)y1, (float)x2, (float)y2); } catch { } break; case Forma.TipoForma.Elipse: caneta = new Pen(corElipse, espessura); largura *= taxaProporcaoLargura; altura *= taxaProporcaoAltura; g.DrawEllipse(caneta, (float)xC, (float)yC, (float)largura, (float)altura); break; case Forma.TipoForma.Refratado: try { caneta = new Pen(corTracejado, espessuraRefratado); x1 = xC - (largura / 2); y1 = yC - (altura / 2); x2 = x1 + largura; y2 = y1 + altura; g.DrawLine(caneta, (float)x1, (float)y1, (float)x2, (float)y2); } catch { } break; case Forma.TipoForma.Prolongamento: try { caneta = new Pen(corReta, espessuraProlongamento); float[] padraoTracos = { 1, 2 }; //tem que ser múltiplo de 1,2 caneta.DashPattern = padraoTracos; //double x1=0, y1=0, x2=0, y2=0; x1 = xC - (largura / 2); y1 = yC - (altura / 2); x2 = x1 + largura; y2 = y1 + altura; g.DrawLine(caneta, (float)x1, (float)y1, (float)x2, (float)y2); } catch { } break; } } }
public static void interpretarBuffer(byte[] buf) { ControladorDesenhavel.interpretando = true; // enfileirar dados /* byte[] buffer = new byte[buf.Length]; * for (int i = 0; i < buf.Length; i++) * buffer[i] = buf[i]; *///MessageBox.Show("Tratando dados"); //pegar conjuntos de 41 em 41 bytes //repDes = new DesenhavelRepositorio(); //throw new Exception("a"); //MessageBox.Show("Recebeu TCP"); for (int i = 0; i == 0 || i < buf.Length - 40; i = i + 41) { if (buf[i] == flagFim) { //flag para FIM = 255 Form2.flagFimSimulacao = true; ControladorDesenhavel.interpretando = false; return; } if (buf[i] == flagInicio) { frmPrincipal.flagAbrirSimulacao = true; ControladorDesenhavel.interpretando = false; return; } byte[] convertidoIndice = inverter(buf, i + 1, i + 5); byte[] convertidoQTD = inverter(buf, i + 5, i + 9); byte[] convertidoXRel = inverter(buf, i + 9, i + 17); byte[] convertidoYRel = inverter(buf, i + 17, i + 25); byte[] convertidoLarguraRel = inverter(buf, i + 25, i + 33); byte[] convertidoAlturaRel = inverter(buf, i + 33, i + 41); Desenhavel itemBuffer = null; //byte 0-> indica se é forma, imagem, fim, início, ... int indice = BitConverter.ToInt32(convertidoIndice, 0); //byte 1 até 4 => índice int qtdDesenhaveis = BitConverter.ToInt32(convertidoQTD, 0); //byte 5 até 8 => qtd Desenhaveis desse tipo double xRel = BitConverter.ToDouble(convertidoXRel, 0); //byte 9 até 16 => xRel double yRel = BitConverter.ToDouble(convertidoYRel, 0); //byte 17 até 24 => yRel double larguraRel = BitConverter.ToDouble(convertidoLarguraRel, 0); //byte 25 até 32 => larguraRel double alturaRel = (double)BitConverter.ToDouble(convertidoAlturaRel, 0); //byte 33 até 40 => alturaRel if (buf[i] != flagFim && buf[i] != flagForma) { //flag para imagem itemBuffer = new Imagem(indice, xRel, yRel, larguraRel, alturaRel); } if (buf[i] == flagForma) { //flag para forma = 254 itemBuffer = new Forma(indice, xRel, yRel, larguraRel, alturaRel); } DesenhavelRepositorio.armazenar(itemBuffer, qtdDesenhaveis); DesenhavelRepositorio.armazenar(itemBuffer); } Form2.flagFimInterpretacao = false; Form2.flagFimRecebimento = true; ControladorDesenhavel.interpretando = false; }