public ControleLivre InsereSimboloDireto(List <ControleLivre> _lstCL, ControleLivre _AposCL, List <SimboloBasico> _lstSB)
        {
            int _indiceSimbolo = _lstCL.IndexOf(_AposCL);

            if (_indiceSimbolo < 0)
            {
                _indiceSimbolo = 0;
            }
            else
            {
                _indiceSimbolo++;
            }

            if (_lstSB.Count > 0)
            {
                foreach (SimboloBasico _sb in _lstSB)
                {
                    InsereSimboloUnicoVisual(_indiceSimbolo, _lstCL, _sb);
                    _indiceSimbolo++;
                }

                return(_lstCL[_indiceSimbolo - 1]);
            }
            return(null);
        }
Example #2
0
        private void InsereSimbolo(LinhaCompletaVisual.LocalInsereSimbolo _lIS, params CodigosInterpretaveis[] _cI)
        {
            if (!IsDiagramaAberto())
            {
                return;
            }

            if (frmProj.frmDiagLadder.ControleSelecionado.IsDisposed)
            {
                return;
            }

            /// aborta a simulação quando for executar uma alteração
            if (btnSimular.Checked)
            {
                btnSimular.Checked = false;
                Thread.Sleep(100);
            }

            ControleLivre       _controle = frmProj.frmDiagLadder.ControleSelecionado;
            LinhaCompletaVisual _linha    = frmProj.frmDiagLadder.LinhaSelecionada;

            _controle = _linha.InsereSimbolo(_lIS, _controle, _cI);

            /// Redesenha linhas e fundo
            frmProj.frmDiagLadder.ReorganizandoLinhas();
            //_linha.simboloDesenhoFundo.Invalidate();

            _controle.Select();
        }
        void simboloInicioLinha_Click(object sender, MouseEventArgs e)
        {
            ControleLivre         _cL = (ControleLivre)sender;
            CodigosInterpretaveis _cI = _cL.getCI();
            DiagramaLadder        _frmDL;

            _frmDL = (DiagramaLadder)_cL.Parent;

            if (e.Button == MouseButtons.Right)
            {
                if (_cI == CodigosInterpretaveis.INICIO_DA_LINHA)
                {
                    _frmDL.menuEnderecamento.Enabled = false;
                    _frmDL.menuInsereLinha.Enabled   = true;

                    /// Extensao de paralelo - acima/abaixo
                    ///    somente sobre simbolos de paralelo
                    _frmDL.menuEstenderParaleloAcima.Enabled  = false;
                    _frmDL.menuEstenderParaleloAcima.Visible  = false;
                    _frmDL.menuEstenderParaleloAbaixo.Enabled = false;
                    _frmDL.menuEstenderParaleloAbaixo.Visible = false;

                    _frmDL.menuControle.Show(_cL.PointToScreen(e.Location));
                }
            }
        }
Example #4
0
        public List <SimboloBasico> VariosSelecionados(ControleLivre _cL, LinhaCompletaVisual _lCL)
        {
            CodigosInterpretaveis _cI    = _cL.getCI();
            List <SimboloBasico>  _lstSB = new List <SimboloBasico>();
            List <ControleLivre>  _lstCL = null;

            switch (_cI)
            {
            case CodigosInterpretaveis.PARALELO_INICIAL:
            case CodigosInterpretaveis.PARALELO_PROXIMO:
            case CodigosInterpretaveis.PARALELO_FINAL:
                int _indicePosInicial = 0;
                int _indicePosFinal   = 0;

                /// verifica em qual lista o controle esta presente (simbolos/saida)
                if (LinhaSelecionada.simbolos.Contains(_cL))
                {
                    _lstCL = LinhaSelecionada.simbolos;
                }
                else if (LinhaSelecionada.saida.Contains(_cL))
                {
                    _lstCL = LinhaSelecionada.saida;
                }
                else
                {
                    return(_lstSB);
                }

                /// define a posicao inicial a partir da posicao
                /// do controle na lista
                _indicePosInicial = _lstCL.IndexOf(_cL);

                if (_cI == CodigosInterpretaveis.PARALELO_FINAL)
                {
                    /// se for paralelo final, inverte a posicial inicial/final
                    _indicePosFinal = _indicePosInicial;
                    /// se for paralelo final, a posicao inicial e
                    /// o paralelo inical
                    _indicePosInicial = _lstCL.IndexOf(_cL.Aponta2PI);
                }
                else
                {
                    /// senao for final aponta para o proximo item de paralelo
                    _indicePosFinal = _lstCL.IndexOf(_cL.Aponta2proxPP);
                }

                /// pega todos os controles dentro da faixa inicial / final
                for (int i = _indicePosInicial; i <= _indicePosFinal; i++)
                {
                    _lstSB.Add(_lstCL[i].SimboloBasico);
                }
                break;

            default:
                _lstSB.Add(_cL.SimboloBasico);
                break;
            }
            return(_lstSB);
        }
Example #5
0
 public void InsereEnderecoNoSimbolo(ControleLivre _cL, EnderecamentoLadder _end)
 {
     if (!_cL.IsDisposed)
     {
         _cL.setOperando(0, _end);
         _cL.Refresh();
     }
 }
        private ControleLivre Insere2Simbolo(bool _bApos, ControleLivre _controle, ListaSimbolo _lstSB)
        {
            int _indiceSimbolo = 0;

            _indiceSimbolo = VerificaPosicaoDeInserirSimbolo(_bApos, _controle, this.simbolos);

            foreach (SimboloBasico _sb in _lstSB)
            {
                linhaBase.simbolos.Insert(_indiceSimbolo, _sb);
                InsereSimboloUnicoVisual(_indiceSimbolo, this.simbolos, _sb);
                _indiceSimbolo++;
            }

            return(this.simbolos[_indiceSimbolo - 1]);
        }
Example #7
0
        public void Simbolo_KeyDown(object sender, KeyEventArgs e)
        {
            ControleLivre _cL = (ControleLivre)sender;

            switch (_cL.getCI())
            {
            case CodigosInterpretaveis.NENHUM:
                /// Tive que colocar aqui esta opcao de NENHUM para evitar que
                /// a execucao passasse duas vezes em apagar
                break;

            case CodigosInterpretaveis.INICIO_DA_LINHA:
                break;

            default:
                if (e.KeyCode == Keys.Delete)
                {
                    if (_cL != null && linhaSelecionada != null)
                    {
                        if (!_cL.IsDisposed)
                        {
                            switch (_cL.getCI())
                            {
                            case CodigosInterpretaveis.PARALELO_INICIAL:
                                break;

                            case CodigosInterpretaveis.PARALELO_PROXIMO:
                                break;

                            case CodigosInterpretaveis.PARALELO_FINAL:
                                break;

                            default:
                                break;
                            }

                            this.SuspendLayout();
                            this.SelectNextControl(_cL, false, true, false, false);
                            linhaSelecionada.ApagaSimbolos(_cL);
                            this.ReorganizandoLinhas();
                            this.ResumeLayout();
                            linhaSelecionada.simboloDesenhoFundo.Invalidate();
                        }
                    }
                }
                break;
            }
        }
        public ControleLivre InsereSimboloIndefinido(bool _bApos, ControleLivre _controle, ListaSimbolo _lstSB)
        {
            _lstSB.ValidaOperandos(this.frmDiag.linkProjeto.programa.endereco);

            /// Verifica se a insercao sera no lista simbolos ou saida
            if (!_lstSB.Contains(CodigosInterpretaveis.BOBINA_SAIDA) &&
                !_lstSB.Contains(CodigosInterpretaveis.TEMPORIZADOR) &&
                !_lstSB.Contains(CodigosInterpretaveis.CONTADOR))
            {
                return(Insere2Simbolo(_bApos, _controle, _lstSB));
            }
            else
            {
                return(Insere2Saida(_bApos, _controle, _lstSB));
            }
        }
        private static int VerificaPosicaoDeInserirSimbolo(bool _bApos, ControleLivre _controle, List <ControleLivre> _lstFinal)
        {
            int _indiceSimbolo = _lstFinal.IndexOf(_controle);

            if (_indiceSimbolo < 0)
            {
                _indiceSimbolo = 0;
            }
            else
            if (_bApos)
            {
                _indiceSimbolo++;
            }

            return(_indiceSimbolo);
        }
Example #10
0
 public void Simbolo_ControleSelecionado(ControleLivre sender, LinhaCompletaVisual lCL)
 {
     if (controleSelecionado != null)
     {
         if (!controleSelecionado.IsDisposed)
         {
             if (!controleSelecionado.Equals(sender))
             {
                 controleSelecionado.selecionado = false;
                 controleSelecionado.Refresh();
             }
         }
     }
     //cmbOpcoes.Visible = false;
     controleSelecionado = sender;
     linhaSelecionada    = lCL;
 }
Example #11
0
 public void simboloInicioLinha_MudaLinha(ControleLivre sender, Keys e)
 {
     if (e == Keys.Up)
     {
         if ((int)sender.linhaAtual.simboloInicioLinha.getOperandos(0) != 0)
         {
             sender.linhaAtual.linhaAnterior.simboloInicioLinha.Select();
         }
     }
     else if (e == Keys.Down)
     {
         if ((int)sender.linhaAtual.linhaProxima.simboloInicioLinha.getOperandos(0) != 0)
         {
             sender.linhaAtual.linhaProxima.simboloInicioLinha.Select();
         }
     }
 }
Example #12
0
        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO: Use System.Windows.Forms.Clipboard.GetText() or System.Windows.Forms.GetData to retrieve information from the clipboard.
            if (IsDiagramaAberto())
            {
                if (frmProj.frmDiagLadder.ControleSelecionado != null)
                {
                    if (!frmProj.frmDiagLadder.ControleSelecionado.IsDisposed)
                    {
                        DataFormats.Format   myFormat     = DataFormats.GetFormat("List<SimboloBasico>");
                        Object               returnObject = null;
                        List <SimboloBasico> _lstSB       = new List <SimboloBasico>();
                        ListaSimbolo         _lstSB2      = new ListaSimbolo();

                        IDataObject iData = Clipboard.GetDataObject();

                        // Determines whether the data is in a format you can use.
                        if (iData.GetDataPresent(myFormat.Name))
                        {
                            try
                            {
                                returnObject = iData.GetData(myFormat.Name);
                            }
                            catch
                            {
                                MessageBox.Show("Erro");
                            }
                        }

                        _lstSB = (List <SimboloBasico>)returnObject;

                        _lstSB2.InsertAllWithClearBefore(_lstSB);

                        ControleLivre _controle = frmProj.frmDiagLadder.LinhaSelecionada.InsereSimboloIndefinido(true, frmProj.frmDiagLadder.ControleSelecionado, _lstSB2);
                        frmProj.frmDiagLadder.ReorganizandoLinhas();
                        _controle.Select();
                    }
                }
            }
        }
        public ControleLivre InsereSimbolo(bool _bApos, LocalInsereSimbolo _lIS, ControleLivre _controle, params CodigosInterpretaveis[] _arrayCI)
        {
            ListaSimbolo _lstSB = new ListaSimbolo();

            /// Insere o array de CodigosInterpretaveis em uma lista de simbolos para facilitar a manipulacao
            _lstSB.InsertAllWithClearBefore(_arrayCI);

            switch (_lIS)
            {
            case LocalInsereSimbolo.INDEFINIDO:
                _controle = InsereSimboloIndefinido(_bApos, _controle, _lstSB);
                break;

            case LocalInsereSimbolo.SIMBOLOS:
                _controle = Insere2Simbolo(_bApos, _controle, _lstSB);
                break;

            case LocalInsereSimbolo.SAIDA:
                _controle = Insere2Saida(_bApos, _controle, _lstSB);
                break;
            }
            return(_controle);
        }
        public bool ApagaSimbolos(ControleLivre _aSerApagado)
        {
            int _indicePosInicial = 0;
            int _indicePosFinal   = 0;
            int _auxSaida         = 0;
            List <ControleLivre> _lstCLDeletar = new List <ControleLivre>();
            List <ControleLivre> _lstCL        = null;
            List <SimboloBasico> _lstSB        = null;
            ControleLivre        _cLAMudarCI   = null;

            if (!simbolos.Contains(_aSerApagado))
            {
                if (!saida.Contains(_aSerApagado))
                {
                    return(false);
                }
                else
                {
                    _lstCL = this.saida;
                    _lstSB = linhaBase.saida;

                    /// caso haja um paralelo na saida
                    /// deleta a linha do paralelo
                    switch (_aSerApagado.getCI())
                    {
                    case CodigosInterpretaveis.PARALELO_INICIAL:
                    case CodigosInterpretaveis.PARALELO_FINAL:
                    case CodigosInterpretaveis.PARALELO_PROXIMO:
                        break;

                    default:
                        if (this.saida.Count > 1)
                        {
                            _auxSaida    = this.saida.IndexOf(_aSerApagado);
                            _aSerApagado = this.saida[_auxSaida - 1];
                        }
                        break;
                    }
                }
            }
            else
            {
                _lstCL = this.simbolos;
                _lstSB = linhaBase.simbolos;
            }

            switch (_aSerApagado.getCI())
            {
            case CodigosInterpretaveis.PARALELO_INICIAL:
            case CodigosInterpretaveis.PARALELO_PROXIMO:
                _indicePosInicial = _lstCL.IndexOf(_aSerApagado);
                _indicePosFinal   = _lstCL.IndexOf(_aSerApagado.Aponta2proxPP);

                _indicePosFinal--;

                switch (_aSerApagado.getCI())
                {
                case CodigosInterpretaveis.PARALELO_INICIAL:
                    if (_aSerApagado.Aponta2proxPP.Aponta2proxPP.Aponta2PI != null)
                    {
                        _lstCLDeletar.Add(_aSerApagado.Aponta2proxPP.Aponta2proxPP);
                        _indicePosFinal++;
                    }
                    else
                    {
                        _cLAMudarCI = _aSerApagado.Aponta2proxPP;
                    }
                    break;

                case CodigosInterpretaveis.PARALELO_PROXIMO:
                    if (_aSerApagado.Aponta2proxPP.Aponta2PI != null)
                    {
                        if (_aSerApagado.Aponta2proxPP.Aponta2PI.Aponta2proxPP.Equals(_aSerApagado))
                        {
                            _lstCLDeletar.Add(_aSerApagado.Aponta2proxPP.Aponta2PI);
                            _indicePosFinal++;
                        }
                        //else
                        //_aSerApagado.Aponta2proxPP.setCI(CodigosInterpretaveis.PARALELO_FINAL);
                    }
                    break;
                }
                break;

            case CodigosInterpretaveis.PARALELO_FINAL:
                _indicePosFinal   = _lstCL.IndexOf(_aSerApagado);
                _indicePosInicial = _lstCL.IndexOf(_aSerApagado.Aponta2PI);
                break;

            default:
                _indicePosInicial = _lstCL.IndexOf(_aSerApagado);
                _indicePosFinal   = _indicePosInicial;
                break;
            }

            /// levanta os controles a serem deletados
            for (int i = _indicePosInicial; i <= _indicePosFinal; i++)
            {
                _lstCLDeletar.Add(_lstCL[i]);
            }

            /// deleta um a um
            foreach (ControleLivre _cLADeletar in _lstCLDeletar)
            {
                ApagaSimbolo(_lstCL, _lstSB, _cLADeletar);
            }

            if (_cLAMudarCI != null)
            {
                _cLAMudarCI.setCI(CodigosInterpretaveis.PARALELO_INICIAL);
            }

            return(true);
        }
        public bool ApagaSimbolo(List <ControleLivre> _lstCL, List <SimboloBasico> _lstSB, ControleLivre _aSerApagado)
        {
            int _indice = 0;

            _indice = _lstCL.IndexOf(_aSerApagado);
            _lstCL.RemoveAt(_indice);

            _lstSB.RemoveAt(_indice);

            _aSerApagado.ControleSelecionado -= new ControleSelecionadoEventHandler(frmDiag.Simbolo_ControleSelecionado);
            _aSerApagado.MouseClick          -= new MouseEventHandler(Simbolo_Click);
            _aSerApagado.KeyDown             += new KeyEventHandler(frmDiag.Simbolo_KeyDown);
            _aSerApagado.SimboloBasico.Dispose();
            _aSerApagado.Dispose();

            return(true);
        }
 public ControleLivre InsereSimbolo(LocalInsereSimbolo _lIS, ControleLivre _controle, params CodigosInterpretaveis[] _arrayCI)
 {
     return(InsereSimbolo(true, _lIS, _controle, _arrayCI));
 }
Example #17
0
        public void ControleSelecionado_SolicitaMudarEndereco(ControleLivre sender, Rectangle rect, Type tipo, int valorMax, int valorMin, params object[] faixa)
        {
            AlteraTemporizadorContador Altera = new AlteraTemporizadorContador(sender.getCI());

            if (sender.getOperandos(0) == null)
            {
                MessageBox.Show("Favor selecionar um endereço primeiro", "Alterar configuração", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            switch (sender.getCI())
            {
            case CodigosInterpretaveis.TEMPORIZADOR:
                Altera.Tipo      = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Tipo;
                Altera.Preset    = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Preset;
                Altera.Acumulado = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Acumulado;
                Altera.BaseTempo = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.BaseTempo;
                break;

            case CodigosInterpretaveis.CONTADOR:
                Altera.Tipo      = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Contador.Tipo;
                Altera.Preset    = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Contador.Preset;
                Altera.Acumulado = (Int32)((EnderecamentoLadder)sender.getOperandos(0)).Contador.Acumulado;
                break;

            default:
                break;
            }

            DialogResult _result = Altera.ShowDialog();

            if (_result == DialogResult.OK)
            {
                /// mantem os parametros do ci atualizados
                sender.setOperando(1, Altera.Tipo);
                sender.setOperando(2, Altera.Preset);
                sender.setOperando(3, Altera.Acumulado);
                switch (sender.getCI())
                {
                case CodigosInterpretaveis.TEMPORIZADOR:
                    /// mantem os parametros do ci atualizados
                    sender.setOperando(4, Altera.BaseTempo);

                    ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Tipo      = Altera.Tipo;
                    ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Preset    = Altera.Preset;
                    ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Acumulado = Altera.Acumulado;
                    ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.BaseTempo = Altera.BaseTempo;

                    sender.setOperando(1, ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Tipo);
                    sender.setOperando(2, ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Preset);
                    sender.setOperando(3, ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.Acumulado);
                    sender.setOperando(4, ((EnderecamentoLadder)sender.getOperandos(0)).Temporizador.BaseTempo);

                    break;

                case CodigosInterpretaveis.CONTADOR:
                    ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Tipo      = Altera.Tipo;
                    ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Preset    = Altera.Preset;
                    ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Acumulado = Altera.Acumulado;

                    sender.setOperando(1, ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Tipo);
                    sender.setOperando(2, ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Preset);
                    sender.setOperando(3, ((EnderecamentoLadder)sender.getOperandos(0)).Contador.Acumulado);
                    break;

                default:
                    break;
                }

                sender.Invalidate();
            }
        }
        void Simbolo_Click(object sender, MouseEventArgs e)
        {
            ControleLivre         _cL = (ControleLivre)sender;
            CodigosInterpretaveis _cI = _cL.getCI();

            ProjetoLadder _frmPL;

            _frmPL = frmDiag.linkProjeto;

            if (e.Button == MouseButtons.Right)
            {
                if (_cI != CodigosInterpretaveis.INICIO_DA_LINHA)
                {
                    frmDiag.menuInsereLinha.Enabled = false;

                    frmDiag.menuToggleBit.Enabled = false;
                    if (_cI == CodigosInterpretaveis.PARALELO_INICIAL ||
                        _cI == CodigosInterpretaveis.PARALELO_FINAL ||
                        _cI == CodigosInterpretaveis.PARALELO_PROXIMO)
                    {
                        frmDiag.menuEnderecamento.Enabled = false;
                        frmDiag.menuEnderecamento.Visible = false;

                        /// Extensao de paralelo - acima/abaixo
                        ///    somente sobre simbolos de paralelo
                        frmDiag.menuEstenderParaleloAcima.Enabled  = true;
                        frmDiag.menuEstenderParaleloAcima.Visible  = true;
                        frmDiag.menuEstenderParaleloAbaixo.Enabled = true;
                        frmDiag.menuEstenderParaleloAbaixo.Visible = true;
                    }
                    else
                    {
                        frmDiag.menuEnderecamento.Enabled = true;
                        frmDiag.menuEnderecamento.Visible = true;

                        if (_cL.getOperandos(0) != null)
                        {
                            frmDiag.menuToggleBit.Enabled = true;
                        }
                        else
                        {
                            frmDiag.menuToggleBit.Enabled = false;
                        }

                        TreeNode _NoEnderecamento = _frmPL.ArvoreProjeto.Nodes["NoProjeto"].Nodes["NoEnderecamento"];

                        ToolStripMenuItem _mnu = null;
                        //ToolStripMenuItem _mnuSub = null;

                        foreach (TreeNode _NoEnd in _NoEnderecamento.Nodes)
                        {
                            //_mnu = new ToolStripMenuItem(_end.Nome);
                            switch (_NoEnd.Text)
                            {
                            case "Memoria":
                                _mnu = frmDiag.menuMemoria;
                                break;

                            case "Temporizadores":
                                _mnu = frmDiag.menuTemporizador;
                                break;

                            case "Contadores":
                                _mnu = frmDiag.menuContador;
                                break;

                            case "Entradas":
                                _mnu = frmDiag.menuEntrada;
                                break;

                            case "Saidas":
                                _mnu = frmDiag.menuSaida;
                                break;
                            }

                            EnderecamentoLadder _end = null;
                            if (_cL.getOperandos(0) != null)
                            {
                                Object obj = _cL.getOperandos(0);
                                if (obj.GetType().ToString() == "LadderApp1.EnderecamentoLadder")
                                {
                                    _end = (LadderApp.EnderecamentoLadder)obj;
                                }
                            }

                            _mnu.DropDownItems.Clear();
                            foreach (TreeNode _NoEndSub in _NoEnd.Nodes)
                            {
                                _mnu.DropDownItems.Add(_NoEndSub.Text);

                                if (_end != null)
                                {
                                    if (_end.Nome == _NoEndSub.Text)
                                    {
                                        _mnu.DropDownItems[_mnu.DropDownItems.Count - 1].Select();
                                    }
                                }

                                _mnu.DropDownItems[_mnu.DropDownItems.Count - 1].Name   = _NoEndSub.Text;
                                _mnu.DropDownItems[_mnu.DropDownItems.Count - 1].Tag    = _NoEndSub.Tag;
                                _mnu.DropDownItems[_mnu.DropDownItems.Count - 1].Click += new EventHandler(LinhaCompletaLivre_Click);
                            }
                        }
                    }
                }
                frmDiag.menuControle.Show(_cL.PointToScreen(e.Location));
            }
        }
        private ControleLivre Insere2Saida(bool _bApos, ControleLivre _controle, ListaSimbolo _lstSB)
        {
            int _indiceSimbolo = 0;
            int _subt2posicionaSimboloInserido = 0;

            switch (saida.Count)
            {
            case 0:
                /// case 0: Primeiro simbolo na saida, adiciona apenas um
                /// simbolo na saida
                _indiceSimbolo = 0;

                if (_lstSB.Count > 1)
                {
                    _lstSB.InsereParalelo(ListaSimbolo.TipoInsercaoParalelo.PARALELO_COMPLETO);
                    _subt2posicionaSimboloInserido = -1;
                }

                break;

            case 1:
                /// case 1: Caso ja exista 1 (um) simbolo de saida, insere um
                /// paralelo de forma automatica

                _indiceSimbolo = VerificaPosicaoDeInserirSimbolo(_bApos, _controle, this.saida);

                // aqui 0=antes, 1=depois
                if (_indiceSimbolo == 0)
                {
                    /// prepara para inserir antes do objeto atual
                    _lstSB.InsereParalelo(ListaSimbolo.TipoInsercaoParalelo.PARALELO_INICIADO);

                    /// insere PP antes do objeto atual na linha
                    linhaBase.saida.Insert(0, new SimboloBasico(CodigosInterpretaveis.PARALELO_PROXIMO));
                    InsereSimboloUnicoVisual(0, this.saida, new SimboloBasico(CodigosInterpretaveis.PARALELO_PROXIMO));
                    /// insere PF depois do objeto atual da linha
                    linhaBase.saida.Insert(this.saida.Count, new SimboloBasico(CodigosInterpretaveis.PARALELO_FINAL));
                    InsereSimboloUnicoVisual(this.saida.Count, this.saida, new SimboloBasico(CodigosInterpretaveis.PARALELO_FINAL));
                }
                else
                {
                    _lstSB.InsereParalelo(ListaSimbolo.TipoInsercaoParalelo.PARALELO_FINALIZADO);
                    _subt2posicionaSimboloInserido = -1;

                    linhaBase.saida.Insert(0, new SimboloBasico(CodigosInterpretaveis.PARALELO_INICIAL));
                    InsereSimboloUnicoVisual(0, this.saida, new SimboloBasico(CodigosInterpretaveis.PARALELO_INICIAL));
                    _indiceSimbolo++;
                }

                break;

            default:
                /// Caso ja haja paralelo, insere apenas PP + simbolo
                _indiceSimbolo = VerificaPosicaoDeInserirSimbolo(false, _controle, this.saida);

                switch (this.saida[_indiceSimbolo].getCI())
                {
                case CodigosInterpretaveis.PARALELO_INICIAL:
                    _lstSB.InsereParalelo(ListaSimbolo.TipoInsercaoParalelo.PARALELO_INICIADO);

                    linhaBase.saida[0].setCI(CodigosInterpretaveis.PARALELO_PROXIMO);
                    this.saida[0].setCI(CodigosInterpretaveis.PARALELO_PROXIMO);
                    break;

                case CodigosInterpretaveis.PARALELO_PROXIMO:
                    _lstSB.InsereParaleloProximo();
                    break;

                case CodigosInterpretaveis.PARALELO_FINAL:
                    _lstSB.InsereParaleloProximo();
                    break;

                default:
                    _lstSB.InsereParaleloProximo();
                    _indiceSimbolo++;
                    break;
                }
                break;
            }

            foreach (SimboloBasico _sb in _lstSB)
            {
                linhaBase.saida.Insert(_indiceSimbolo, _sb);
                InsereSimboloUnicoVisual(_indiceSimbolo, this.saida, _sb);
                _indiceSimbolo++;
            }

            /// retorna o ultimo objeto inserido
            return(this.saida[_indiceSimbolo - 1 + _subt2posicionaSimboloInserido]);
        }
Example #20
0
        public static void AjustaPosicionamento(LinhaCompletaVisual lc)
        {
            ControleLivre _ctrlLivreAux = null;

            int _maiorX = 0;

            SuporteParalelo        _par     = null;
            List <SuporteParalelo> _lst_par = new List <SuporteParalelo>();

            int _ultTamY2ParaleloFinal = 0; // acumula o tamanho Y (pos+tam) do ultimo
            // VPI tratado dentro de um mesmo paralelo
            // seu valor e usado para informar
            // ao PF qual o seu tamanho Y

            int _tamY2DesenhoFundo = 0;

            // Variaveis auxiliares para posicionamento
            //  dos controles
            int _posX     = lc.posX; // auxiliar para posX
            int _posY     = lc.posY; // auxiliar para posY
            int _tamX     = lc.tamX; // auxiliar para tamX
            int _tamY     = lc.tamY; // auxiliar para tamY
            int _acumTamX = 0;       // usado para acumular o valor de X na sequencia
            // em que os simbolos sao montados
            int _acumTamY = lc.tamY; // auxiliar para tamY

            List <ControleLivre> _simbProxLinha = new List <ControleLivre>();

            _acumTamX += lc.tamX;

            foreach (ControleLivre simbAux in lc.simbolos)
            {
                // caso todos os paralelos abertos tenham sido
                // tratados forca paralelos tratados = 0
                if (_lst_par.Count == 0)
                {
                    if (_maiorX > 0)
                    {
                        _posX = _maiorX;
                    }

                    _maiorX = 0;
                }
                else
                {
                    if (_maiorX < (_posX + _tamX))
                    {
                        _maiorX = _posX + _tamX;
                    }
                }

                switch (simbAux.getCI())
                {
                case CodigosInterpretaveis.PARALELO_INICIAL:
                    _tamY = lc.tamY;     // restaura tamanho Y base
                    _posX = _acumTamX;
                    _tamX = lc.tamX / 3;

                    _par = new SuporteParalelo();
                    _lst_par.Add(_par);

                    _par._yAcum = _posY;
                    _par.maiorY = _posY;
                    _par.maiorX = _maiorX;
                    _par.par    = simbAux;

                    _acumTamX = _posX + _tamX;
                    break;

                case CodigosInterpretaveis.PARALELO_FINAL:
                    _tamX = lc.tamX / 3;
                    //                        _tamY = _par.ultimoVPI.Location.Y - _par.par.Location.Y + _par.ultimoVPI.Size.Height; // _ultTamY2ParaleloFinal;
                    _tamY = _par.ultimoVPI.posicaoXY.Y - _par.par.posicaoXY.Y + _par.ultimoVPI.tamanhoXY.Height;     // _ultTamY2ParaleloFinal;
                    _posY = _par.par.posicaoXY.Y;

                    if (_maiorX > _par.maiorX)
                    {
                        _par.maiorX = _maiorX;
                    }

                    _posX = _par.maiorX;

                    // Salva (por paralelo) o maior tamanho Y para os simbolos
                    // linha inicial / final e desenho de fundo
                    if (_ultTamY2ParaleloFinal > _tamY2DesenhoFundo)
                    {
                        _tamY2DesenhoFundo = _ultTamY2ParaleloFinal;
                    }

                    simbAux.SalvaVPI2PF(_par.lstVPI);

                    _par = null;
                    _lst_par.RemoveAt(_lst_par.Count - 1);

                    if (_lst_par.Count > 0)
                    {
                        _par = _lst_par[_lst_par.Count - 1];
                    }


                    // se tiver paralelo aberto
                    // salva nele o maior y processado dentro dele
                    if (_lst_par.Count > 0)
                    {
                        if (_ultTamY2ParaleloFinal > _par.maiorY)
                        {
                            _par.maiorY = _ultTamY2ParaleloFinal;
                        }
                    }

                    _acumTamX = _posX + _tamX;
                    break;

                case CodigosInterpretaveis.PARALELO_PROXIMO:
                    _tamY = lc.tamY;     // restaura tamanho Y base
                    _tamX = lc.tamX / 3; // tamanho X reduzido

                    if (_maiorX > _par.maiorX)
                    {
                        _par.maiorX = _maiorX;
                    }
                    _maiorX = 0;

                    _posX = _par.par.posicaoXY.X;

                    _par._yAcum = _par.maiorY;
                    _posY       = _par.maiorY + (lc.tamY * (_par.numVPITratados + 1));

                    // caso seja o primeiro VPI(NXB) atualiza o SIZE do PI(BST)
                    // caso seja o segundo VPI em diante, atualiza SIZE do VPI anterior
                    if (_par.numVPITratados > 0)
                    {
                        _ctrlLivreAux           = _par.ultimoVPI;
                        _ctrlLivreAux.UltimoVPI = false;
                    }
                    else
                    {
                        _ctrlLivreAux = _par.par;
                    }

                    _ctrlLivreAux.tamanhoXY = new Size(_ctrlLivreAux.tamanhoXY.Width, _posY - _ctrlLivreAux.posicaoXY.Y);

                    _par.numVPITratados   += 1;
                    _par.ultimoVPI         = simbAux;
                    _ultTamY2ParaleloFinal = _posY;

                    _par.lstVPI.Add(simbAux);

                    _acumTamX = _posX + _tamX;
                    break;

                default:
                    _tamY      = lc.tamY;
                    _tamX      = lc.tamX;
                    _posX      = _acumTamX;
                    _acumTamX += _tamX;
                    break;
                }

                // posiciona e dimensiona simbolo
                simbAux.posicaoXY = new Point(_posX, _posY);
                simbAux.tamanhoXY = new Size(_tamX, _tamY);

                simbAux.Location = new Point(_posX, _posY);
                simbAux.Size     = new Size(_tamX, _tamY);
            }

            _tamY2DesenhoFundo += lc.tamY;

            //--Inicio da linha
            lc.simboloInicioLinha.posicaoXY = new Point(lc.posX, lc.posY);
            lc.simboloInicioLinha.tamanhoXY = new Size(lc.tamX, _tamY2DesenhoFundo);

            //--Fim da linha
            DiagramaLadder dlFormAux = null;

            dlFormAux = (DiagramaLadder)lc.frmDiag;
            if (_acumTamX < (dlFormAux.Width - lc.tamX))
            {
                _acumTamX = (dlFormAux.Width - lc.tamX);
            }

            lc.simboloFimLinha.posicaoXY = new Point(_acumTamX, lc.posY);
            lc.simboloFimLinha.tamanhoXY = new Size(lc.tamX, _tamY2DesenhoFundo);

            //--Desenho de fundo
            lc.simboloFimLinha.posicaoXY = new Point(lc.posX, lc.posY);
            lc.simboloFimLinha.tamanhoXY = new Size(_acumTamX, _tamY2DesenhoFundo);

            RedimensionaSimbolos(lc);
        }
        public void AjustaPosicionamento()
        {
            ControleLivre _ctrlLivreAux = null;

            int _maiorX = 0;

            /// Variaveis para desenhar os simbolos de saida
            /// sempre no final da linha
            int _contaNumSimbolos = 0;
            int _guardaAcumXnoPrimeiroSimbSaida = 0;
            int _guardaAcumXnoMaiorSimbSaida    = 0;
            int _guardaTamSaida = 0;

            SuporteParalelo        _par     = null;
            List <SuporteParalelo> _lst_par = new List <SuporteParalelo>();

            /// acumula o tamanho Y (pos+tam) do ultimo
            /// VPI tratado dentro de um mesmo paralelo
            /// seu valor e usado para informar
            /// ao PF qual o seu tamanho Y
            int _ultTamY2ParaleloFinal = 0;

            int _tamY2DesenhoFundo = 0;

            /// Variaveis auxiliares para posicionamento
            ///  dos controles
            int _posX     = posX;      // auxiliar para posX
            int _posY     = posY;      // auxiliar para posY
            int _tamX     = this.tamX; // auxiliar para tamX
            int _tamY     = tamY;      // auxiliar para tamY
            int _acumTamX = 0;         // usado para acumular o valor de X na sequencia
            // em que os simbolos sao montados
            int _acumTamY = tamY;      // auxiliar para tamY

            _acumTamX += this.tamX;

            simbolos.AddRange(saida);

            foreach (ControleLivre simbAux in simbolos)
            {
                _contaNumSimbolos++;

                // caso todos os paralelos abertos tenham sido
                // tratados forca paralelos tratados = 0
                if (_lst_par.Count == 0)
                {
                    if (_maiorX > 0)
                    {
                        _posX = _maiorX;
                    }

                    _maiorX = 0;
                }
                else
                {
                    if (_maiorX < (_posX + _tamX))
                    {
                        _maiorX = _posX + _tamX;
                    }
                }

                switch (simbAux.getCI())
                {
                case CodigosInterpretaveis.PARALELO_INICIAL:
                    _tamY = tamY;     // restaura tamanho Y base
                    _posX = _acumTamX;
                    _tamX = this.tamX / 3;

                    _par = new SuporteParalelo();
                    _lst_par.Add(_par);

                    _par._yAcum = _posY;
                    _par.maiorY = _posY;
                    _par.maiorX = _maiorX;
                    _par.par    = simbAux;

                    _acumTamX = _posX + _tamX;
                    break;

                case CodigosInterpretaveis.PARALELO_FINAL:
                    _tamX = this.tamX / 3;
                    //                        _tamY = _par.ultimoVPI.Location.Y - _par.par.Location.Y + _par.ultimoVPI.Size.Height; // _ultTamY2ParaleloFinal;
                    _tamY = _par.ultimoVPI.posicaoXY.Y - _par.par.posicaoXY.Y + _par.ultimoVPI.tamanhoXY.Height;     // _ultTamY2ParaleloFinal;
                    _posY = _par.par.posicaoXY.Y;

                    if (_maiorX > _par.maiorX)
                    {
                        _par.maiorX = _maiorX;
                    }

                    _posX = _par.maiorX;

                    // Salva (por paralelo) o maior tamanho Y para os simbolos
                    // linha inicial / final e desenho de fundo
                    if (_ultTamY2ParaleloFinal > _tamY2DesenhoFundo)
                    {
                        _tamY2DesenhoFundo = _ultTamY2ParaleloFinal;
                    }

                    simbAux.SalvaVPI2PF(_par.lstVPI);

                    /// Faz os apontamentos de paralelo
                    ///  para facilitar futuras buscas de paralelos
                    simbAux.Aponta2PI            = _par.par;
                    _par.par.Aponta2PF           = simbAux;
                    _par.ultimoVPI.Aponta2proxPP = simbAux;

                    _par.ultimoVPI.UltimoVPI = true;

                    _par = null;
                    _lst_par.RemoveAt(_lst_par.Count - 1);

                    if (_lst_par.Count > 0)
                    {
                        _par = _lst_par[_lst_par.Count - 1];
                    }


                    // se tiver paralelo aberto
                    // salva nele o maior y processado dentro dele
                    if (_lst_par.Count > 0)
                    {
                        if (_ultTamY2ParaleloFinal > _par.maiorY)
                        {
                            _par.maiorY = _ultTamY2ParaleloFinal;
                        }
                    }

                    _acumTamX = _posX + _tamX;
                    break;

                case CodigosInterpretaveis.PARALELO_PROXIMO:
                    _tamY = tamY;          // restaura tamanho Y base
                    _tamX = this.tamX / 3; // tamanho X reduzido

                    if (_maiorX > _par.maiorX)
                    {
                        _par.maiorX = _maiorX;
                    }
                    _maiorX = 0;

                    _posX = _par.par.posicaoXY.X;

                    _par._yAcum = _par.maiorY;
                    _posY       = _par.maiorY + (tamY * (_par.numVPITratados + 1));

                    // caso seja o primeiro VPI(NXB) atualiza o SIZE do PI(BST)
                    // caso seja o segundo VPI em diante, atualiza SIZE do VPI anterior
                    if (_par.numVPITratados > 0)
                    {
                        _ctrlLivreAux           = _par.ultimoVPI;
                        _ctrlLivreAux.UltimoVPI = false;
                    }
                    else
                    {
                        _ctrlLivreAux = _par.par;
                    }

                    _ctrlLivreAux.tamanhoXY = new Size(_ctrlLivreAux.tamanhoXY.Width, _posY - _ctrlLivreAux.posicaoXY.Y);

                    /// PARA FACILITAR A BUSCA DO PROXIMO PONTO DE PARALELO
                    _ctrlLivreAux.Aponta2proxPP = simbAux;

                    _par.numVPITratados   += 1;
                    _par.ultimoVPI         = simbAux;
                    _ultTamY2ParaleloFinal = _posY;

                    _par.lstVPI.Add(simbAux);

                    _acumTamX = _posX + _tamX;
                    break;

                default:
                    _tamY      = tamY;
                    _tamX      = this.tamX;
                    _posX      = _acumTamX;
                    _acumTamX += _tamX;
                    break;
                }

                // posiciona e dimensiona simbolo
                simbAux.posicaoXY = new Point(_posX, _posY);
                simbAux.tamanhoXY = new Size(_tamX, _tamY);

                //simbAux.Location = new Point(_posX, _posY);
                //simbAux.Size = new Size(_tamX, _tamY);

                if ((saida.Count > 0) && (_contaNumSimbolos >= (simbolos.Count - saida.Count)))
                {
                    if (_contaNumSimbolos == (simbolos.Count - saida.Count))
                    {
                        _guardaAcumXnoPrimeiroSimbSaida = _acumTamX;
                    }

                    if (_guardaAcumXnoMaiorSimbSaida < _acumTamX)
                    {
                        _guardaAcumXnoMaiorSimbSaida = _acumTamX;
                    }
                }
            }

            //_guardaTamSaida = _guardaAcumXnoPrimeiroSimbSaida;
            _guardaTamSaida = (_guardaAcumXnoMaiorSimbSaida - _guardaAcumXnoPrimeiroSimbSaida);// -this.tamX;
            if (_guardaTamSaida == 0)
            {
                _guardaTamSaida = tamX;
            }

            /// Caso tenha ao menos 1 objeto de saida cria um espaco de meio simbolo
            /// entre o ultimo simbolo e o primeiro de saida
            simbolos.RemoveRange((simbolos.Count - saida.Count), saida.Count);

            _tamY2DesenhoFundo += tamY;

            if ((posY > tamY) && (_tamY2DesenhoFundo > posY))
            {
                _tamY2DesenhoFundo -= posY;
            }

            //--Inicio da linha
            simboloInicioLinha.posicaoXY = new Point(posX, posY);
            simboloInicioLinha.tamanhoXY = new Size(this.tamX, _tamY2DesenhoFundo);
            simboloInicioLinha.Location  = new Point(posX, posY);
            simboloInicioLinha.Size      = new Size(this.tamX, _tamY2DesenhoFundo);

            //--Fim da linha
            if (_acumTamX < (frmDiag.Width - this.tamX))
            {
                _acumTamX = (frmDiag.Width - this.tamX);
            }

            if (linhaAnterior != null)
            {
                if (_acumTamX < linhaAnterior.simboloFimLinha.posicaoXY.X)
                {
                    _acumTamX = linhaAnterior.simboloFimLinha.posicaoXY.X;
                }
            }

            posX2primeiroSimbSaida = _acumTamX - _guardaAcumXnoPrimeiroSimbSaida - (_guardaTamSaida);

            simboloFimLinha.posicaoXY = new Point(_acumTamX, posY);
            simboloFimLinha.tamanhoXY = new Size(this.tamX, _tamY2DesenhoFundo);
            simboloFimLinha.Location  = new Point(_acumTamX, posY);
            simboloFimLinha.Size      = new Size(this.tamX, _tamY2DesenhoFundo);

            //--Desenho de fundo
            simboloDesenhoFundo.posicaoXY = new Point(posX, posY);
            simboloDesenhoFundo.tamanhoXY = new Size(_acumTamX, _tamY2DesenhoFundo);
            simboloDesenhoFundo.Location  = new Point(posX, posY);
            simboloDesenhoFundo.Size      = new Size(_acumTamX, _tamY2DesenhoFundo);

            RedimensionaSimbolos();
        }