コード例 #1
0
        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]);
        }
コード例 #2
0
ファイル: EditorLadder.cs プロジェクト: q306023680/LadderApp
        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();
                    }
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public SimboloBasico Insere2Saida(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


                // 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
                    this.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
                    this.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;

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

                break;

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

                    this.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)
            {
                this.saida.Insert(_indiceSimbolo, _sb);
                //InsereSimboloUnicoVisual(_indiceSimbolo, this.saida, _sb);
                _indiceSimbolo++;
            }

            /// retorna o ultimo objeto inserido
            return(this.saida[_indiceSimbolo - 1 + _subt2posicionaSimboloInserido]);
        }
コード例 #5
0
ファイル: EditorLadder.cs プロジェクト: q306023680/LadderApp
        private void LerExecutavel(String DadosConvertidosChar, String strNomeProjeto)
        {
            List <int>            lstCodigosLidos = new List <int>();
            CodigosInterpretaveis guarda          = CodigosInterpretaveis.NENHUM;

            if (DadosConvertidosChar.IndexOf("@laddermic.com") != -1)
            {
                Int32 intContaFim    = 0;
                Int32 intIndiceLinha = 0;
                Int32 iNumOperandos  = 0;
                EnderecamentoLadder          _endLido;
                TipoEnderecamentoDispositivo _tpEndLido;
                Int32 _iIndiceEndLido = 0;


                /// Cria um programa novo vazio
                ProgramaBasico programa = new ProgramaBasico();
                programa.StsPrograma = ProgramaBasico.StatusPrograma.NOVO;
                programa.Nome        = strNomeProjeto;
                programa.dispositivo = new DispositivoLadder(1);
                programa.endereco.AlocaEnderecamentoIO(programa.dispositivo);
                programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstMemoria, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA, 10);
                programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstTemporizador, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_TEMPORIZADOR, 10);
                programa.endereco.AlocaEnderecamentoMemoria(programa.dispositivo, programa.endereco.lstContador, TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_CONTADOR, 10);
                intIndiceLinha = programa.InsereLinhaNoFinal(new LinhaCompleta());

                for (int i = DadosConvertidosChar.IndexOf("@laddermic.com") + 15; i < DadosConvertidosChar.Length; i++)
                {
                    guarda = (CodigosInterpretaveis)Convert.ToChar(DadosConvertidosChar.Substring(i, 1));

                    switch (guarda)
                    {
                    case CodigosInterpretaveis.NENHUM:
                        intContaFim++;
                        iNumOperandos = 0;
                        break;

                    case CodigosInterpretaveis.FIM_DA_LINHA:
                        intContaFim++;
                        iNumOperandos = 0;
                        if ((CodigosInterpretaveis)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)) != CodigosInterpretaveis.NENHUM)
                        {
                            intIndiceLinha = programa.InsereLinhaNoFinal(new LinhaCompleta());
                        }
                        break;

                    //case CodigosInterpretaveis.INICIO_DA_LINHA:
                    case CodigosInterpretaveis.CONTATO_NA:
                    case CodigosInterpretaveis.CONTATO_NF:
                        intContaFim   = 0;
                        iNumOperandos = 2;
                        {
                            SimboloBasico _sb = new SimboloBasico((CodigosInterpretaveis)guarda);
                            //_sb.setOperando(0, programa.endereco.Find((TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1)), (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1))));

                            _tpEndLido      = (TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1));
                            _iIndiceEndLido = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1));
                            _endLido        = programa.endereco.Find(_tpEndLido, _iIndiceEndLido);
                            if (_endLido == null)
                            {
                                programa.dispositivo.lstBitPorta[_iIndiceEndLido - 1].TipoDefinido = _tpEndLido;
                                programa.dispositivo.RealocaEnderecoDispositivo();
                                programa.endereco.AlocaEnderecamentoIO(programa.dispositivo);
                                _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido);
                            }
                            _sb.setOperando(0, _endLido);

                            i += 2;
                            programa.linhas[intIndiceLinha].simbolos.Add(_sb);
                        }
                        break;

                    case CodigosInterpretaveis.BOBINA_SAIDA:
                    case CodigosInterpretaveis.RESET:
                        intContaFim   = 0;
                        iNumOperandos = 2;
                        {
                            ListaSimbolo _lstSB = new ListaSimbolo();
                            _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda));
                            _tpEndLido      = (TipoEnderecamentoDispositivo)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1));
                            _iIndiceEndLido = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1));
                            _endLido        = programa.endereco.Find(_tpEndLido, _iIndiceEndLido);
                            if (_endLido == null)
                            {
                                programa.dispositivo.lstBitPorta[_iIndiceEndLido - 1].TipoDefinido = _tpEndLido;
                                programa.dispositivo.RealocaEnderecoDispositivo();
                                programa.endereco.AlocaEnderecamentoIO(programa.dispositivo);
                                _endLido = programa.endereco.Find(_tpEndLido, _iIndiceEndLido);
                            }
                            _lstSB[_lstSB.Count - 1].setOperando(0, _endLido);
                            i += 2;
                            programa.linhas[intIndiceLinha].Insere2Saida(_lstSB);
                            _lstSB.Clear();
                        }
                        break;

                    case CodigosInterpretaveis.PARALELO_INICIAL:
                    case CodigosInterpretaveis.PARALELO_FINAL:
                    case CodigosInterpretaveis.PARALELO_PROXIMO:
                        intContaFim   = 0;
                        iNumOperandos = 0;
                        programa.linhas[intIndiceLinha].simbolos.Add(new SimboloBasico((CodigosInterpretaveis)guarda));
                        break;

                    case CodigosInterpretaveis.CONTADOR:
                        intContaFim   = 0;
                        iNumOperandos = 3;
                        {
                            ListaSimbolo _lstSB = new ListaSimbolo();
                            _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda));
                            _lstSB[_lstSB.Count - 1].setOperando(0, programa.endereco.Find(TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_CONTADOR, (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1))));
                            ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Tipo   = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1));
                            ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Preset = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 3, 1));

                            _lstSB[_lstSB.Count - 1].setOperando(1, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Tipo);
                            _lstSB[_lstSB.Count - 1].setOperando(2, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Contador.Preset);
                            i += 3;
                            programa.linhas[intIndiceLinha].Insere2Saida(_lstSB);
                            _lstSB.Clear();
                        }
                        break;

                    case CodigosInterpretaveis.TEMPORIZADOR:
                        intContaFim   = 0;
                        iNumOperandos = 4;
                        {
                            ListaSimbolo _lstSB = new ListaSimbolo();
                            _lstSB.Add(new SimboloBasico((CodigosInterpretaveis)guarda));
                            _lstSB[_lstSB.Count - 1].setOperando(0, programa.endereco.Find(TipoEnderecamentoDispositivo.DIGITAL_MEMORIA_TEMPORIZADOR, (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 1, 1))));
                            ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Tipo      = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 2, 1));
                            ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.BaseTempo = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 3, 1));
                            ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Preset    = (Int32)Convert.ToChar(DadosConvertidosChar.Substring(i + 4, 1));

                            _lstSB[_lstSB.Count - 1].setOperando(1, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Tipo);
                            _lstSB[_lstSB.Count - 1].setOperando(2, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.Preset);
                            _lstSB[_lstSB.Count - 1].setOperando(4, ((EnderecamentoLadder)_lstSB[_lstSB.Count - 1].getOperandos(0)).Temporizador.BaseTempo);

                            i += 4;
                            programa.linhas[intIndiceLinha].Insere2Saida(_lstSB);
                            _lstSB.Clear();
                        }
                        break;
                    }

                    /// fim dos códigos
                    if (intContaFim >= 2)
                    {
                        /// grava os dados lidos do codigo intepretavel
                        ModuloIntegracaoMSP430 p = new ModuloIntegracaoMSP430();
                        p.CriaArquivo("codigosinterpretaveis.txt", DadosConvertidosChar.Substring(DadosConvertidosChar.IndexOf("@laddermic.com"), i - DadosConvertidosChar.IndexOf("@laddermic.com") + 1));

                        /// força saída do loop
                        i = DadosConvertidosChar.Length;
                    }
                }
                frmProj           = new ProjetoLadder(programa);
                frmProj.MdiParent = this;
                frmProj.Show();
                frmProj.SetText();
            }
            else
            {
                MessageBox.Show("O arquivo não foi reconhecido pelo sistema!", "Abrir Arquivos ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #6
0
        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));
            }
        }