PLCControler.py
changeset 1649 3291024e00da
parent 1619 163d3a883575
child 1680 6db967480b7d
equal deleted inserted replaced
1648:6431f26aa501 1649:3291024e00da
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #based on the plcopen standard.
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 from xml.dom import minidom
    25 from xml.dom import minidom
    26 from types import StringType, UnicodeType, TupleType
    26 from types import StringType, UnicodeType, TupleType
    27 from lxml import etree
    27 from lxml import etree
    28 from copy import deepcopy
    28 from copy import deepcopy
   965             # prevent violations of POU content restrictions:
   965             # prevent violations of POU content restrictions:
   966             # function blocks cannot be pasted as functions,
   966             # function blocks cannot be pasted as functions,
   967             # programs cannot be pasted as functions or function blocks
   967             # programs cannot be pasted as functions or function blocks
   968             if orig_type == 'functionBlock' and pou_type == 'function' or \
   968             if orig_type == 'functionBlock' and pou_type == 'function' or \
   969                orig_type == 'program' and pou_type in ['function', 'functionBlock']:
   969                orig_type == 'program' and pou_type in ['function', 'functionBlock']:
   970                 return _('''%s "%s" can't be pasted as a %s.''') % (orig_type, name, pou_type)
   970                 msg = _('''{a1} "{a2}" can't be pasted as a {a3}.''').format(a1 = orig_type, a2 = name, a3 = pou_type)
       
   971                 return msg
   971 
   972 
   972             new_pou.setpouType(pou_type)
   973             new_pou.setpouType(pou_type)
   973 
   974 
   974         self.Project.insertpou(0, new_pou)
   975         self.Project.insertpou(0, new_pou)
   975         self.BufferProject()
   976         self.BufferProject()
  2181             if project is not None:
  2182             if project is not None:
  2182                 pou = self.Project.getpou(words[1])
  2183                 pou = self.Project.getpou(words[1])
  2183                 if pou is not None:
  2184                 if pou is not None:
  2184                     return self.GetPouInterfaceReturnType(pou, tree, debug)
  2185                     return self.GetPouInterfaceReturnType(pou, tree, debug)
  2185         elif words[0] == 'T':
  2186         elif words[0] == 'T':
  2186             return "BOOL"
  2187             return ["BOOL", ([], [])]
  2187         return None
  2188         return None
  2188 
  2189 
  2189     # Change the edited element text
  2190     # Change the edited element text
  2190     def SetEditedElementText(self, tagname, text):
  2191     def SetEditedElementText(self, tagname, text):
  2191         if self.Project is not None:
  2192         if self.Project is not None:
  3190         return self.Project.Search(criteria)
  3191         return self.Project.Search(criteria)
  3191 
  3192 
  3192     def SearchInPou(self, tagname, criteria, debug=False):
  3193     def SearchInPou(self, tagname, criteria, debug=False):
  3193         pou = self.GetEditedElement(tagname, debug)
  3194         pou = self.GetEditedElement(tagname, debug)
  3194         if pou is not None:
  3195         if pou is not None:
  3195             return pou.Search(criteria)
  3196             search_results = pou.Search(criteria, [tagname])
       
  3197             if tagname.split("::")[0] in ['A', 'T']:
       
  3198                 parent_pou_tagname = "P::%s" % (tagname.split("::")[-2])
       
  3199                 parent_pou = self.GetEditedElement(parent_pou_tagname, debug)
       
  3200                 for infos, start, end, text in parent_pou.Search(criteria):
       
  3201                     if infos[1] in ["var_local", "var_input", "var_output", "var_inout"]:
       
  3202                         search_results.append((infos, start, end, text))
       
  3203             return search_results
  3196         return []
  3204         return []
  3197 
  3205 
  3198 #-------------------------------------------------------------------------------
  3206 #-------------------------------------------------------------------------------
  3199 #                      Current Buffering Management Functions
  3207 #                      Current Buffering Management Functions
  3200 #-------------------------------------------------------------------------------
  3208 #-------------------------------------------------------------------------------