PLCControler.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 21 Aug 2017 21:55:18 +0300
changeset 1782 5b6ad7a7fd9d
parent 1780 c52d1460cea8
child 1785 0ff2a45dcefa
permissions -rw-r--r--
clean-up: fix PEP8 E265 block comment should start with '# '
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1619
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    10
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    15
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    20
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1508
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
from xml.dom import minidom
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    27
from types import StringType, UnicodeType, TupleType
1308
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
    28
from lxml import etree
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
    29
from copy import deepcopy
1732
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1686
diff changeset
    30
import os
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1686
diff changeset
    31
import sys
94ffe74e6895 clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1686
diff changeset
    32
import re
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
import datetime
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1619
diff changeset
    34
import util.paths as paths
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
from time import localtime
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
    36
from collections import OrderedDict, namedtuple
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
    37
from util.TranslationCatalogs import NoTranslate
1313
85c167bfff93 Replaced standard function blocks library definition from dictionary to plcopen xml files
Laurent Bessard
parents: 1311
diff changeset
    38
from plcopen import *
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
from graphics.GraphicCommons import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
from PLCGenerator import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    44
ITEMS_EDITABLE = [
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    45
    ITEM_PROJECT,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    46
    ITEM_POU,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    47
    ITEM_VARIABLE,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    48
    ITEM_TRANSITION,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    49
    ITEM_ACTION,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    50
    ITEM_CONFIGURATION,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    51
    ITEM_RESOURCE,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    52
    ITEM_DATATYPE
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    53
] = range(8)
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    54
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    55
ITEMS_UNEDITABLE = [
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    56
    ITEM_DATATYPES,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    57
    ITEM_FUNCTION,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    58
    ITEM_FUNCTIONBLOCK,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    59
    ITEM_PROGRAM,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    60
    ITEM_TRANSITIONS,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    61
    ITEM_ACTIONS,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    62
    ITEM_CONFIGURATIONS,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    63
    ITEM_RESOURCES,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    64
    ITEM_PROPERTIES
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    65
] = range(8, 17)
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    66
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    67
ITEMS_VARIABLE = [
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    68
    ITEM_VAR_LOCAL,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    69
    ITEM_VAR_GLOBAL,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    70
    ITEM_VAR_EXTERNAL,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    71
    ITEM_VAR_TEMP,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    72
    ITEM_VAR_INPUT,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    73
    ITEM_VAR_OUTPUT,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    74
    ITEM_VAR_INOUT
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    75
] = range(17, 24)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    77
VAR_CLASS_INFOS = {
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    78
    "Local":    ("localVars",    ITEM_VAR_LOCAL),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    79
    "Global":   ("globalVars",   ITEM_VAR_GLOBAL),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    80
    "External": ("externalVars", ITEM_VAR_EXTERNAL),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    81
    "Temp":     ("tempVars",     ITEM_VAR_TEMP),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    82
    "Input":    ("inputVars",    ITEM_VAR_INPUT),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    83
    "Output":   ("outputVars",   ITEM_VAR_OUTPUT),
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
    84
    "InOut":    ("inOutVars",    ITEM_VAR_INOUT)}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    86
POU_TYPES = {
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    87
    "program": ITEM_PROGRAM,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    88
    "functionBlock": ITEM_FUNCTIONBLOCK,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    89
    "function": ITEM_FUNCTION,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    90
}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
LOCATIONS_ITEMS = [LOCATION_CONFNODE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
                   LOCATION_MODULE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
                   LOCATION_GROUP,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    95
                   LOCATION_VAR_INPUT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    96
                   LOCATION_VAR_OUTPUT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
                   LOCATION_VAR_MEMORY] = range(6)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
1680
6db967480b7d make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1619
diff changeset
    99
ScriptDirectory = paths.AbsDir(__file__)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   100
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   101
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
def GetUneditableNames():
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   103
    _ = NoTranslate
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   104
    return [_("User-defined POUs"), _("Functions"), _("Function Blocks"),
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   105
            _("Programs"), _("Data Types"), _("Transitions"), _("Actions"),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
            _("Configurations"), _("Resources"), _("Properties")]
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   107
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   108
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
UNEDITABLE_NAMES = GetUneditableNames()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   110
[USER_DEFINED_POUS, FUNCTIONS, FUNCTION_BLOCKS, PROGRAMS,
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   111
 DATA_TYPES, TRANSITIONS, ACTIONS, CONFIGURATIONS,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
 RESOURCES, PROPERTIES] = UNEDITABLE_NAMES
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   114
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   115
class LibraryResolver(etree.Resolver):
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   116
    """Helper object for loading library in xslt stylesheets"""
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   117
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   118
    def __init__(self, controller, debug=False):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   119
        self.Controller = controller
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   120
        self.Debug = debug
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   121
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   122
    def resolve(self, url, pubid, context):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   123
        lib_name = os.path.basename(url)
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   124
        if lib_name in ["project", "stdlib", "extensions"]:
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   125
            lib_el = etree.Element(lib_name)
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   126
            if lib_name == "project":
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   127
                lib_el.append(deepcopy(self.Controller.GetProject(self.Debug)))
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   128
            elif lib_name == "stdlib":
1390
0f4d32a033e0 Tidy PLCopen definitions
Edouard Tisserant
parents: 1379
diff changeset
   129
                for lib in StdBlckLibs.values():
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   130
                    lib_el.append(deepcopy(lib))
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   131
            else:
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   132
                for ctn in self.Controller.ConfNodeTypes:
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   133
                    lib_el.append(deepcopy(ctn["types"]))
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   134
            return self.resolve_string(etree.tostring(lib_el), context)
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   135
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   136
# -------------------------------------------------------------------------------
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   137
#           Helpers functions for translating list of arguments
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   138
#                       from xslt to valid arguments
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   139
# -------------------------------------------------------------------------------
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   140
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   141
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   142
def _StringValue(x):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   143
    return x
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   144
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   145
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   146
def _BoolValue(x):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1753
diff changeset
   147
    return x in ["true", "0"]
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   148
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   149
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   150
def _translate_args(translations, args):
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   151
    return [translate(arg[0]) if len(arg) > 0 else None
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   152
            for translate, arg in
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   153
            zip(translations, args)]
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   154
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   155
# -------------------------------------------------------------------------------
1308
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
   156
#                 Helpers object for generating pou var list
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   157
# -------------------------------------------------------------------------------
1308
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
   158
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   159
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   160
class _VariableInfos(object):
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   161
    __slots__ = ["Name", "Class", "Option", "Location", "InitialValue",
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   162
                 "Edit", "Documentation", "Type", "Tree", "Number"]
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   163
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   164
    def __init__(self, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   165
        for attr, value in zip(self.__slots__, args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   166
            setattr(self, attr, value if value is not None else "")
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   167
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   168
    def copy(self):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   169
        return _VariableInfos(*[getattr(self, attr) for attr in self.__slots__])
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   170
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   171
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   172
class VariablesInfosFactory:
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   173
1308
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
   174
    def __init__(self, variables):
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
   175
        self.Variables = variables
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   176
        self.TreeStack = []
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   177
        self.Type = None
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   178
        self.Dimensions = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   179
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   180
    def SetType(self, context, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   181
        self.Type = args[0][0]
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   182
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   183
    def GetType(self):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   184
        if len(self.Dimensions) > 0:
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   185
            return ("array", self.Type, self.Dimensions)
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   186
        return self.Type
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   187
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   188
    def GetTree(self):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   189
        return (self.TreeStack.pop(-1), self.Dimensions)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   190
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   191
    def AddDimension(self, context, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   192
        self.Dimensions.append(tuple(
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   193
            _translate_args([_StringValue] * 2, args)))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   194
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   195
    def AddTree(self, context, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   196
        self.TreeStack.append([])
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   197
        self.Dimensions = []
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   198
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   199
    def AddVarToTree(self, context, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   200
        var = (args[0][0], self.Type, self.GetTree())
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   201
        self.TreeStack[-1].append(var)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   202
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   203
    def AddVariable(self, context, *args):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   204
        self.Variables.append(_VariableInfos(*(_translate_args(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   205
            [_StringValue] * 5 + [_BoolValue] + [_StringValue], args) +
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   206
            [self.GetType(), self.GetTree()])))
1308
ad61268dbdb6 Replaced old pou variable list and variable tree generating by xslt stylesheet
Laurent Bessard
parents: 1306
diff changeset
   207
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   208
# -------------------------------------------------------------------------------
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   209
#            Helpers object for generating pou variable instance list
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   210
# -------------------------------------------------------------------------------
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   211
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   212
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   213
def class_extraction(value):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   214
    class_type = {
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   215
        "configuration": ITEM_CONFIGURATION,
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   216
        "resource": ITEM_RESOURCE,
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   217
        "action": ITEM_ACTION,
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   218
        "transition": ITEM_TRANSITION,
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   219
        "program": ITEM_PROGRAM}.get(value)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   220
    if class_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   221
        return class_type
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   222
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   223
    pou_type = POU_TYPES.get(value)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   224
    if pou_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   225
        return pou_type
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   226
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   227
    var_type = VAR_CLASS_INFOS.get(value)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   228
    if var_type is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   229
        return var_type[1]
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   230
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   231
    return None
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   232
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   233
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   234
class _VariablesTreeItemInfos(object):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   235
    __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"]
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   236
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   237
    def __init__(self, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   238
        for attr, value in zip(self.__slots__, args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   239
            setattr(self, attr, value if value is not None else "")
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   240
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   241
    def copy(self):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   242
        return _VariableTreeItem(*[getattr(self, attr) for attr in self.__slots__])
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   243
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   244
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   245
class VariablesTreeInfosFactory:
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   246
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   247
    def __init__(self):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   248
        self.Root = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   249
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   250
    def GetRoot(self):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   251
        return self.Root
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   252
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   253
    def SetRoot(self, context, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   254
        self.Root = _VariablesTreeItemInfos(
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   255
            *([''] + _translate_args(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   256
                [class_extraction, _StringValue] + [_BoolValue] * 2,
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   257
                args) + [[]]))
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   258
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   259
    def AddVariable(self, context, *args):
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   260
        if self.Root is not None:
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   261
            self.Root.variables.append(_VariablesTreeItemInfos(
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   262
                *(_translate_args(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   263
                    [_StringValue, class_extraction, _StringValue] +
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   264
                    [_BoolValue] * 2, args) + [[]])))
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   265
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   266
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   267
class InstancesPathFactory:
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   268
    """Helpers object for generating instances path list"""
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   269
    def __init__(self, instances):
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   270
        self.Instances = instances
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   271
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   272
    def AddInstance(self, context, *args):
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   273
        self.Instances.append(args[0][0])
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   274
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   275
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   276
class InstanceTagName:
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   277
    """Helpers object for generating instance tagname"""
1321
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   278
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   279
    def __init__(self, controller):
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   280
        self.Controller = controller
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   281
        self.TagName = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   282
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   283
    def GetTagName(self):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   284
        return self.TagName
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   285
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   286
    def ConfigTagName(self, context, *args):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   287
        self.TagName = self.Controller.ComputeConfigurationName(args[0][0])
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   288
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   289
    def ResourceTagName(self, context, *args):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   290
        self.TagName = self.Controller.ComputeConfigurationResourceName(args[0][0], args[1][0])
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   291
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   292
    def PouTagName(self, context, *args):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   293
        self.TagName = self.Controller.ComputePouName(args[0][0])
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   294
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   295
    def ActionTagName(self, context, *args):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   296
        self.TagName = self.Controller.ComputePouActionName(args[0][0], args[0][1])
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   297
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   298
    def TransitionTagName(self, context, *args):
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   299
        self.TagName = self.Controller.ComputePouTransitionName(args[0][0], args[0][1])
1321
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   300
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   301
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   302
# -------------------------------------------------------------------------------
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   303
#           Helpers object for generating pou block instances list
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   304
# -------------------------------------------------------------------------------
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   305
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   306
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   307
_Point = namedtuple("Point", ["x", "y"])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   308
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   309
_BlockInstanceInfos = namedtuple(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   310
    "BlockInstanceInfos",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   311
    ["type", "id", "x", "y", "width", "height", "specific_values", "inputs", "outputs"])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   312
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   313
_BlockSpecificValues = (
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   314
    namedtuple("BlockSpecificValues",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   315
               ["name", "execution_order"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   316
    [_StringValue, int])
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   317
_VariableSpecificValues = (
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   318
    namedtuple("VariableSpecificValues",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   319
               ["name", "value_type", "execution_order"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   320
    [_StringValue, _StringValue, int])
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   321
_ConnectionSpecificValues = (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   322
    namedtuple("ConnectionSpecificValues", ["name"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   323
    [_StringValue])
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   324
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   325
_PowerRailSpecificValues = (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   326
    namedtuple("PowerRailSpecificValues", ["connectors"]),
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   327
    [int])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   328
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   329
_LDElementSpecificValues = (
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   330
    namedtuple("LDElementSpecificValues",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   331
               ["name", "negated", "edge", "storage", "execution_order"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   332
    [_StringValue, _BoolValue, _StringValue, _StringValue, int])
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   333
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   334
_DivergenceSpecificValues = (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   335
    namedtuple("DivergenceSpecificValues", ["connectors"]),
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   336
    [int])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   337
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   338
_SpecificValuesTuples = {
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   339
    "comment": (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   340
        namedtuple("CommentSpecificValues", ["content"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   341
        [_StringValue]),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   342
    "input": _VariableSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   343
    "output": _VariableSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   344
    "inout": _VariableSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   345
    "connector": _ConnectionSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   346
    "continuation": _ConnectionSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   347
    "leftPowerRail": _PowerRailSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   348
    "rightPowerRail": _PowerRailSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   349
    "contact": _LDElementSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   350
    "coil": _LDElementSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   351
    "step": (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   352
        namedtuple("StepSpecificValues", ["name", "initial", "action"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   353
        [_StringValue, _BoolValue, lambda x: x]),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   354
    "transition": (
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   355
        namedtuple("TransitionSpecificValues",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   356
                   ["priority", "condition_type", "condition", "connection"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   357
        [int, _StringValue, _StringValue, lambda x: x]),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   358
    "selectionDivergence": _DivergenceSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   359
    "selectionConvergence": _DivergenceSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   360
    "simultaneousDivergence": _DivergenceSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   361
    "simultaneousConvergence": _DivergenceSpecificValues,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   362
    "jump": (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   363
        namedtuple("JumpSpecificValues", ["target"]),
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   364
        [_StringValue]),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   365
    "actionBlock": (
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   366
        namedtuple("ActionBlockSpecificValues", ["actions"]),
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   367
        [lambda x: x]),
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   368
}
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   369
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   370
_InstanceConnectionInfos = namedtuple(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   371
    "InstanceConnectionInfos",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   372
    ["name", "negated", "edge", "position", "links"])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   373
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   374
_ConnectionLinkInfos = namedtuple(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   375
    "ConnectionLinkInfos",
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   376
    ["refLocalId", "formalParameter", "points"])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   377
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   378
1341
0923e602c603 Fixed ActionInfos class with slots
Laurent Bessard
parents: 1339
diff changeset
   379
class _ActionInfos(object):
1339
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   380
    __slots__ = ["qualifier", "type", "value", "duration", "indicator"]
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   381
1339
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   382
    def __init__(self, *args):
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   383
        for attr, value in zip(self.__slots__, args):
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   384
            setattr(self, attr, value if value is not None else "")
1751
c28db6f7616b clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1749
diff changeset
   385
1339
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   386
    def copy(self):
6adf05c4508d Fixed bug in actionBlock actions editing
Laurent Bessard
parents: 1338
diff changeset
   387
        return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__])
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   388
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   389
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   390
class BlockInstanceFactory:
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   391
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   392
    def __init__(self, block_instances):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   393
        self.BlockInstances = block_instances
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   394
        self.CurrentInstance = None
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   395
        self.SpecificValues = None
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   396
        self.CurrentConnection = None
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   397
        self.CurrentLink = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   398
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   399
    def SetSpecificValues(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   400
        self.SpecificValues = list(args)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   401
        self.CurrentInstance = None
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   402
        self.CurrentConnection = None
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   403
        self.CurrentLink = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   404
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   405
    def AddBlockInstance(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   406
        specific_values_tuple, specific_values_translation = \
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   407
            _SpecificValuesTuples.get(args[0][0], _BlockSpecificValues)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   408
1774
ac0fe8aabb5e clean-up: fix PEP8 E272 multiple spaces before keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   409
        if args[0][0] == "step" and len(self.SpecificValues) < 3 or \
1766
c1e5b9f19483 clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1763
diff changeset
   410
           args[0][0] == "transition" and len(self.SpecificValues) < 4:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   411
            self.SpecificValues.append([None])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   412
        elif args[0][0] == "actionBlock" and len(self.SpecificValues) < 1:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   413
            self.SpecificValues.append([[]])
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   414
        specific_values = specific_values_tuple(*_translate_args(
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   415
            specific_values_translation, self.SpecificValues))
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   416
        self.SpecificValues = None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   417
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   418
        self.CurrentInstance = _BlockInstanceInfos(
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   419
            *(_translate_args([_StringValue, int] + [float] * 4, args) +
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   420
              [specific_values, [], []]))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   421
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   422
        self.BlockInstances[self.CurrentInstance.id] = self.CurrentInstance
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   423
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   424
    def AddInstanceConnection(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   425
        connection_args = _translate_args(
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   426
            [_StringValue] * 2 + [_BoolValue, _StringValue] + [float] * 2, args)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   427
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   428
        self.CurrentConnection = _InstanceConnectionInfos(
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   429
            *(connection_args[1:4] + [
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   430
                _Point(*connection_args[4:6]), []]))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   431
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   432
        if self.CurrentInstance is not None:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   433
            if connection_args[0] == "input":
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   434
                self.CurrentInstance.inputs.append(self.CurrentConnection)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   435
            else:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   436
                self.CurrentInstance.outputs.append(self.CurrentConnection)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   437
        else:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   438
            self.SpecificValues.append([self.CurrentConnection])
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   439
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   440
    def AddConnectionLink(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   441
        self.CurrentLink = _ConnectionLinkInfos(
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   442
            *(_translate_args([int, _StringValue], args) + [[]]))
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   443
        self.CurrentConnection.links.append(self.CurrentLink)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   444
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   445
    def AddLinkPoint(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   446
        self.CurrentLink.points.append(_Point(
1373
4278d5c1e414 Fixed bug when graphic element position and size and connection points are decimal
Laurent Bessard
parents: 1372
diff changeset
   447
            *_translate_args([float] * 2, args)))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   448
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   449
    def AddAction(self, context, *args):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   450
        if len(self.SpecificValues) == 0:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   451
            self.SpecificValues.append([[]])
1378
cbc0f64a25eb Fixed bug with non-ascii characters in program comments
Laurent Bessard
parents: 1373
diff changeset
   452
        translated_args = _translate_args([_StringValue] * 5, args)
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   453
        self.SpecificValues[0][0].append(_ActionInfos(*translated_args))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   454
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1744
diff changeset
   455
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   456
pou_block_instances_xslt = etree.parse(
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   457
    os.path.join(ScriptDirectory, "plcopen", "pou_block_instances.xslt"))
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1337
diff changeset
   458
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   459
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
# Length of the buffer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
UNDO_BUFFER_LENGTH = 20
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   463
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
class UndoBuffer:
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   465
    """
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   466
    Undo Buffer for PLCOpenEditor
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   467
    Class implementing a buffer of changes made on the current editing model
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   468
    """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   469
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   470
    def __init__(self, currentstate, issaved=False):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   471
        """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   472
        Constructor initialising buffer
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   473
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
        self.Buffer = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
        self.CurrentIndex = -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
        self.MinIndex = -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
        self.MaxIndex = -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   478
        # if current state is defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
        if currentstate:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
            self.CurrentIndex = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
            self.MinIndex = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   482
            self.MaxIndex = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
        # Initialising buffer with currentstate at the first place
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
        for i in xrange(UNDO_BUFFER_LENGTH):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   485
            if i == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
                self.Buffer.append(currentstate)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   488
                self.Buffer.append(None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
        # Initialising index of state saved
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   490
        if issaved:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   491
            self.LastSave = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   492
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   493
            self.LastSave = -1
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   494
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
    def Buffering(self, currentstate):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   496
        """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   497
        Add a new state in buffer
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   498
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   499
        self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
        self.Buffer[self.CurrentIndex] = currentstate
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   501
        # Actualising buffer limits
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   502
        self.MaxIndex = self.CurrentIndex
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
        if self.MinIndex == self.CurrentIndex:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
            # If the removed state was the state saved, there is no state saved in the buffer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
            if self.LastSave == self.MinIndex:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   506
                self.LastSave = -1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
            self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
        self.MinIndex = max(self.MinIndex, 0)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   509
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
    def Current(self):
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   511
        """
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   512
        Return current state of buffer
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   513
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
        return self.Buffer[self.CurrentIndex]
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   515
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
    # Change current state to previous in buffer and return new current state
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
    def Previous(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   518
        if self.CurrentIndex != self.MinIndex:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
            self.CurrentIndex = (self.CurrentIndex - 1) % UNDO_BUFFER_LENGTH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
            return self.Buffer[self.CurrentIndex]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   522
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
    # Change current state to next in buffer and return new current state
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
    def Next(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   525
        if self.CurrentIndex != self.MaxIndex:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
            self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
            return self.Buffer[self.CurrentIndex]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   529
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
    # Return True if current state is the first in buffer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
    def IsFirst(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
        return self.CurrentIndex == self.MinIndex
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   533
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   534
    # Return True if current state is the last in buffer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
    def IsLast(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
        return self.CurrentIndex == self.MaxIndex
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   538
    # Note that current state is saved
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
    def CurrentSaved(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   540
        self.LastSave = self.CurrentIndex
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   541
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   542
    # Return True if current state is saved
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
    def IsCurrentSaved(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
        return self.LastSave == self.CurrentIndex
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   545
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
class PLCControler:
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   548
    """
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   549
    Controler for PLCOpenEditor
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   550
    Class which controls the operations made on the plcopen model and answers to view requests
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1735
diff changeset
   551
    """
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   552
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
    # Create a new PLCControler
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
    def __init__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   555
        self.LastNewIndex = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
        self.Reset()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   557
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   558
    # Reset PLCControler internal variables
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
    def Reset(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
        self.Project = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        self.ProjectBufferEnabled = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   562
        self.ProjectBuffer = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   563
        self.ProjectSaved = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
        self.Buffering = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
        self.FilePath = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
        self.FileName = ""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   567
        self.ProgramChunks = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
        self.ProgramOffset = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   569
        self.NextCompiledProject = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
        self.CurrentCompiledProject = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   571
        self.ConfNodeTypes = []
1283
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1265
diff changeset
   572
        self.TotalTypesDict = StdBlckDct.copy()
f3cfe1ff917e More optimization attemps in type handling
Edouard Tisserant
parents: 1265
diff changeset
   573
        self.TotalTypes = StdBlckLst[:]
1284
abf63a310532 Fixed GetBlockTypes method
Laurent Bessard
parents: 1283
diff changeset
   574
        self.ProgramFilePath = ""
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   575
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
    def GetQualifierTypes(self):
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
   577
        return QualifierList
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   579
    def GetProject(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
        if debug and self.CurrentCompiledProject is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   581
            return self.CurrentCompiledProject
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
            return self.Project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   585
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   586
    #                         Project management functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   587
    # -------------------------------------------------------------------------------
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   589
    # Return if a project is opened
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
    def HasOpenedProject(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
        return self.Project is not None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
    # Create a new project by replacing the current one
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
    def CreateNewProject(self, properties):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   595
        # Create the project
1290
13ee5f4ab612 First stage of xmlclass refactoring using lxml
Laurent Bessard
parents: 1284
diff changeset
   596
        self.Project = PLCOpenParser.CreateRoot()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
        properties["creationDateTime"] = datetime.datetime(*localtime()[:6])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
        self.Project.setfileHeader(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   599
        self.Project.setcontentHeader(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
        self.SetFilePath("")
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   601
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   602
        # Initialize the project buffer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   603
        self.CreateProjectBuffer(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
        self.ProgramChunks = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   605
        self.ProgramOffset = 0
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
   606
        self.NextCompiledProject = self.Copy(self.Project)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
        self.CurrentCompiledProject = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
        self.Buffering = False
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   609
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
    # Return project data type names
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   611
    def GetProjectDataTypeNames(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   612
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
            return [datatype.getname() for datatype in project.getdataTypes()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
        return []
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   616
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
    # Return project pou names
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   618
    def GetProjectPouNames(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
            return [pou.getname() for pou in project.getpous()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
        return []
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   623
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
    # Return project pou names
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   625
    def GetProjectConfigNames(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
            return [config.getname() for config in project.getconfigurations()]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
        return []
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   630
1171
a506e4de8f84 Add support for Drag'n dropping located variables to function block creating global located variable in configuration and external variable in function block
Laurent Bessard
parents: 1127
diff changeset
   631
    # Return project pou variable names
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   632
    def GetProjectPouVariableNames(self, pou_name=None, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
        variables = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   634
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   635
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   636
            for pou in project.getpous():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   637
                if pou_name is None or pou_name == pou.getname():
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
   638
                    variables.extend([var.Name for var in self.GetPouInterfaceVars(pou, debug=debug)])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   639
                    for transition in pou.gettransitionList():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
                        variables.append(transition.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   641
                    for action in pou.getactionList():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
                        variables.append(action.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
        return variables
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   644
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   645
    # Return file path if project is an open file
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
    def GetFilePath(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
        return self.FilePath
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   648
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
    # Return file path if project is an open file
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
    def GetProgramFilePath(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
        return self.ProgramFilePath
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   652
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   653
    # Return file name and point out if file is up to date
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
    def GetFilename(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   656
            if self.ProjectIsSaved():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
                return self.FileName
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
            else:
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   659
                return "~%s~" % self.FileName
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
        return ""
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   661
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
    # Change file path and save file name or create a default one if file path not defined
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
    def SetFilePath(self, filepath):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
        self.FilePath = filepath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
        if filepath == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
            self.LastNewIndex += 1
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1732
diff changeset
   667
            self.FileName = _("Unnamed%d") % self.LastNewIndex
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
            self.FileName = os.path.splitext(os.path.basename(filepath))[0]
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   670
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
    # Change project properties
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   672
    def SetProjectProperties(self, name=None, properties=None, buffer=True):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   674
            if name is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   675
                self.Project.setname(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
            if properties is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
                self.Project.setfileHeader(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   678
                self.Project.setcontentHeader(properties)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
            if buffer and (name is not None or properties is not None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   680
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   681
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
    # Return project name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
    def GetProjectName(self, debug=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
            return project.getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   688
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
    # Return project properties
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   690
    def GetProjectProperties(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
            properties = project.getfileHeader()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
            properties.update(project.getcontentHeader())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
            return properties
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   697
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   698
    # Return project informations
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   699
    def GetProjectInfos(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
            infos = {"name": project.getname(), "type": ITEM_PROJECT}
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   703
            datatypes = {"name": DATA_TYPES, "type": ITEM_DATATYPES, "values": []}
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
            for datatype in project.getdataTypes():
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   705
                datatypes["values"].append({
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   706
                    "name": datatype.getname(),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   707
                    "type": ITEM_DATATYPE,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   708
                    "tagname": self.ComputeDataTypeName(datatype.getname()),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   709
                    "values": []})
1740
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   710
            pou_types = {
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   711
                "function": {
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   712
                    "name":   FUNCTIONS,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   713
                    "type":   ITEM_FUNCTION,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   714
                    "values": []
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   715
                },
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   716
                "functionBlock": {
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   717
                    "name":   FUNCTION_BLOCKS,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   718
                    "type":   ITEM_FUNCTIONBLOCK,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   719
                    "values": []
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   720
                },
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   721
                "program": {
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   722
                    "name":   PROGRAMS,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   723
                    "type":   ITEM_PROGRAM,
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   724
                    "values": []
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   725
                }
b789b695b5c6 clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1739
diff changeset
   726
            }
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
            for pou in project.getpous():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
                pou_type = pou.getpouType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   729
                pou_infos = {"name": pou.getname(), "type": ITEM_POU,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   730
                             "tagname": self.ComputePouName(pou.getname())}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   731
                pou_values = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   732
                if pou.getbodyType() == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   733
                    transitions = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   734
                    for transition in pou.gettransitionList():
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   735
                        transitions.append({
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   736
                            "name": transition.getname(),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   737
                            "type": ITEM_TRANSITION,
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   738
                            "tagname": self.ComputePouTransitionName(pou.getname(), transition.getname()),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
                            "values": []})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
                    pou_values.append({"name": TRANSITIONS, "type": ITEM_TRANSITIONS, "values": transitions})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   741
                    actions = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
                    for action in pou.getactionList():
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   743
                        actions.append({
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   744
                            "name": action.getname(),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   745
                            "type": ITEM_ACTION,
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   746
                            "tagname": self.ComputePouActionName(pou.getname(), action.getname()),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
                            "values": []})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
                    pou_values.append({"name": ACTIONS, "type": ITEM_ACTIONS, "values": actions})
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
                if pou_type in pou_types:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
                    pou_infos["values"] = pou_values
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
                    pou_types[pou_type]["values"].append(pou_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
            configurations = {"name": CONFIGURATIONS, "type": ITEM_CONFIGURATIONS, "values": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
            for config in project.getconfigurations():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
                config_name = config.getname()
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   755
                config_infos = {
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   756
                    "name": config_name,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   757
                    "type": ITEM_CONFIGURATION,
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   758
                    "tagname": self.ComputeConfigurationName(config.getname()),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                    "values": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   760
                resources = {"name": RESOURCES, "type": ITEM_RESOURCES, "values": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   761
                for resource in config.getresource():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                    resource_name = resource.getname()
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   763
                    resource_infos = {
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   764
                        "name": resource_name,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   765
                        "type": ITEM_RESOURCE,
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   766
                        "tagname": self.ComputeConfigurationResourceName(config.getname(), resource.getname()),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
                        "values": []}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                    resources["values"].append(resource_infos)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                config_infos["values"] = [resources]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
                configurations["values"].append(config_infos)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   771
            infos["values"] = [datatypes, pou_types["function"], pou_types["functionBlock"],
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
                               pou_types["program"], configurations]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
            return infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   776
    def GetPouVariables(self, tagname, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   777
        pou_type = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
        if project is not None:
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   780
            factory = VariablesTreeInfosFactory()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   781
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   782
            parser = etree.XMLParser()
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   783
            parser.resolvers.add(LibraryResolver(self, debug))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   784
1316
df9d02bd3eb7 Replaced old pou instance variable list generating process by xslt stylesheet
Laurent Bessard
parents: 1315
diff changeset
   785
            pou_variable_xslt_tree = etree.XSLT(
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   786
                etree.parse(
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   787
                    os.path.join(ScriptDirectory, "plcopen", "pou_variables.xslt"),
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   788
                    parser),
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   789
                extensions={("pou_vars_ns", name): getattr(factory, name)
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   790
                            for name in ["SetRoot", "AddVariable"]})
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   791
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   792
            obj = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
            words = tagname.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
            if words[0] == "P":
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   795
                obj = self.GetPou(words[1], debug)
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   796
            elif words[0] != "D":
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   797
                obj = self.GetEditedElement(tagname, debug)
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   798
            if obj is not None:
1348
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   799
                pou_variable_xslt_tree(obj)
aee0a7eb833a Fixed pou variables instance information loading stylesheet
Laurent Bessard
parents: 1347
diff changeset
   800
                return factory.GetRoot()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   801
1321
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   802
        return None
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   803
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   804
    def GetInstanceList(self, root, name, debug=False):
1354
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   805
        instances = []
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   806
        project = self.GetProject(debug)
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   807
        if project is not None:
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   808
            factory = InstancesPathFactory(instances)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   809
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   810
            parser = etree.XMLParser()
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   811
            parser.resolvers.add(LibraryResolver(self, debug))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   812
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   813
            instances_path_xslt_tree = etree.XSLT(
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   814
                etree.parse(
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   815
                    os.path.join(ScriptDirectory, "plcopen", "instances_path.xslt"),
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   816
                    parser),
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   817
                extensions={
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   818
                    ("instances_ns", "AddInstance"): factory.AddInstance})
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   819
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   820
            instances_path_xslt_tree(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   821
                root, instance_type=etree.XSLT.strparam(name))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   822
1354
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   823
        return instances
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   824
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   825
    def SearchPouInstances(self, tagname, debug=False):
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   826
        project = self.GetProject(debug)
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   827
        if project is not None:
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   828
            words = tagname.split("::")
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   829
            if words[0] == "P":
1350
7280349a3375 Fixed pou instance path list computing stylesheet
Laurent Bessard
parents: 1348
diff changeset
   830
                return self.GetInstanceList(project, words[1])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   831
            elif words[0] == 'C':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
                return [words[1]]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
            elif words[0] == 'R':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   834
                return ["%s.%s" % (words[1], words[2])]
826
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 823
diff changeset
   835
            elif words[0] in ['T', 'A']:
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 823
diff changeset
   836
                return ["%s.%s" % (instance, words[2])
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 823
diff changeset
   837
                        for instance in self.SearchPouInstances(
098f822ef308 Adding transition and action in list of instances of SFC POU in PouInstanceVariablesPanel
laurent
parents: 823
diff changeset
   838
                            self.ComputePouName(words[1]), debug)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
        return []
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   840
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   841
    def GetPouInstanceTagName(self, instance_path, debug=False):
1254
ebc765355536 Fixed bug when trying to add a global function block instance variable to debug variable panel and not connected
Laurent Bessard
parents: 1223
diff changeset
   842
        project = self.GetProject(debug)
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   843
        factory = InstanceTagName(self)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   844
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   845
        parser = etree.XMLParser()
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   846
        parser.resolvers.add(LibraryResolver(self, debug))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   847
1321
83f41ea00b97 Replaced old pou instance type tagname computing by xslt stylesheet
Laurent Bessard
parents: 1319
diff changeset
   848
        instance_tagname_xslt_tree = etree.XSLT(
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   849
            etree.parse(
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   850
                os.path.join(ScriptDirectory, "plcopen", "instance_tagname.xslt"),
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   851
                parser),
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   852
            extensions={("instance_tagname_ns", name): getattr(factory, name)
1767
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   853
                        for name in ["ConfigTagName",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   854
                                     "ResourceTagName",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   855
                                     "PouTagName",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   856
                                     "ActionTagName",
c74815729afd clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1766
diff changeset
   857
                                     "TransitionTagName"]})
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   858
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   859
        instance_tagname_xslt_tree(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1767
diff changeset
   860
            project, instance_path=etree.XSLT.strparam(instance_path))
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   861
1351
a546a63ce1bf Fixed pou tagname of instance path computing stylesheet
Laurent Bessard
parents: 1350
diff changeset
   862
        return factory.GetTagName()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   863
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   864
    def GetInstanceInfos(self, instance_path, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
        tagname = self.GetPouInstanceTagName(instance_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
        if tagname is not None:
827
a2ce084fb598 Fix restore project tab layout with transition and action debug tabs
laurent
parents: 826
diff changeset
   867
            infos = self.GetPouVariables(tagname, debug)
1360
ebfe9c22af2a Fixed bug when debugging PLC with Graphic Viewer in debug open and re-transfer PLC
Laurent Bessard
parents: 1354
diff changeset
   868
            infos.type = tagname
827
a2ce084fb598 Fix restore project tab layout with transition and action debug tabs
laurent
parents: 826
diff changeset
   869
            return infos
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   870
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
            pou_path, var_name = instance_path.rsplit(".", 1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
            tagname = self.GetPouInstanceTagName(pou_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
            if tagname is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
                pou_infos = self.GetPouVariables(tagname, debug)
1360
ebfe9c22af2a Fixed bug when debugging PLC with Graphic Viewer in debug open and re-transfer PLC
Laurent Bessard
parents: 1354
diff changeset
   875
                for var_infos in pou_infos.variables:
ebfe9c22af2a Fixed bug when debugging PLC with Graphic Viewer in debug open and re-transfer PLC
Laurent Bessard
parents: 1354
diff changeset
   876
                    if var_infos.name == var_name:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
                        return var_infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   878
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   879
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
    # Return if data type given by name is used by another data type or pou
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   881
    def DataTypeIsUsed(self, name, debug=False):
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   882
        project = self.GetProject(debug)
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   883
        if project is not None:
1354
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   884
            return len(self.GetInstanceList(project, name, debug)) > 0
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
    # Return if pou given by name is used by another pou
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   888
    def PouIsUsed(self, name, debug=False):
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   889
        project = self.GetProject(debug)
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   890
        if project is not None:
1354
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   891
            return len(self.GetInstanceList(project, name, debug)) > 0
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   893
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
    # Return if pou given by name is directly or undirectly used by the reference pou
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
   895
    def PouIsUsedBy(self, name, reference, debug=False):
1319
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   896
        pou_infos = self.GetPou(reference, debug)
748347102c97 Replaced old list of pou instance in project generating process by xslt stylesheet
Laurent Bessard
parents: 1316
diff changeset
   897
        if pou_infos is not None:
1354
241c19ea80da Fixed bug when selecting pou that is not used in project
Laurent Bessard
parents: 1351
diff changeset
   898
            return len(self.GetInstanceList(pou_infos, name, debug)) > 0
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
        return False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
    def GenerateProgram(self, filepath=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
        errors = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
        warnings = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
            try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
                self.ProgramChunks = GenerateCurrentProgram(self, self.Project, errors, warnings)
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
   907
                self.NextCompiledProject = self.Copy(self.Project)
901
ab43f3e40b9d Fix bug when compiling project containing non-ascii characters
Laurent Bessard
parents: 887
diff changeset
   908
                program_text = "".join([item[0] for item in self.ProgramChunks])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   909
                if filepath is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   910
                    programfile = open(filepath, "w")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
                    programfile.write(program_text.encode("utf-8"))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   912
                    programfile.close()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   913
                    self.ProgramFilePath = filepath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   914
                return program_text, errors, warnings
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   915
            except PLCGenException, e:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   916
                errors.append(e.message)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   917
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   918
            errors.append("No project opened")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   919
        return "", errors, warnings
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   921
    def DebugAvailable(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
        return self.CurrentCompiledProject is not None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   923
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   924
    def ProgramTransferred(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   925
        if self.NextCompiledProject is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   926
            self.CurrentCompiledProject = self.NextCompiledProject
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   927
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   928
            self.CurrentCompiledProject = self.Copy(self.Project)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   930
    def GetChunkInfos(self, from_location, to_location):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   931
        row = self.ProgramOffset + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
        col = 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
        infos = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
        for chunk, chunk_infos in self.ProgramChunks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
            lines = chunk.split("\n")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   936
            if len(lines) > 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
                next_row = row + len(lines) - 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   938
                next_col = len(lines[-1]) + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   939
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   940
                next_row = row
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
                next_col = col + len(chunk)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
            if (next_row > from_location[0] or next_row == from_location[0] and next_col >= from_location[1]) and len(chunk_infos) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   943
                infos.append((chunk_infos, (row, col)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
            if next_row == to_location[0] and next_col > to_location[1] or next_row > to_location[0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   945
                return infos
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   946
            row, col = next_row, next_col
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   947
        return infos
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   948
1782
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   949
    # -------------------------------------------------------------------------------
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   950
    #                        Project Pous management functions
5b6ad7a7fd9d clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1780
diff changeset
   951
    # -------------------------------------------------------------------------------
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   952
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   953
    # Add a Data Type to Project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   954
    def ProjectAddDataType(self, datatype_name=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   955
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   956
            if datatype_name is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   957
                datatype_name = self.GenerateNewName(None, None, "datatype%d")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   958
            # Add the datatype to project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   959
            self.Project.appenddataType(datatype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   960
            self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   961
            return self.ComputeDataTypeName(datatype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   963
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
    # Remove a Data Type from project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
    def ProjectRemoveDataType(self, datatype_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
            self.Project.removedataType(datatype_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
            self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   969
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
    # Add a Pou to Project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
    def ProjectAddPou(self, pou_name, pou_type, body_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
            # Add the pou to project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
            self.Project.appendpou(pou_name, pou_type, body_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   975
            if pou_type == "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
                self.SetPouInterfaceReturnType(pou_name, "BOOL")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   977
            self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
            return self.ComputePouName(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   980
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   981
    def ProjectChangePouType(self, name, pou_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
            pou = self.Project.getpou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   984
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   985
                pou.setpouType(pou_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   986
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   987
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   988
    def GetPouXml(self, pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   989
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   990
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   991
            if pou is not None:
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
   992
                return pou.tostring()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   993
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
   994
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   995
    def PastePou(self, pou_type, pou_xml):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   996
        '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   997
        Adds the POU defined by 'pou_xml' to the current project with type 'pou_type'
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   998
        '''
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   999
        try:
1330
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1328
diff changeset
  1000
            new_pou, error = LoadPou(pou_xml)
1780
c52d1460cea8 clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1779
diff changeset
  1001
        except Exception:
1330
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1328
diff changeset
  1002
            error = ""
96b242e4c59d Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents: 1328
diff changeset
  1003
        if error is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1004
            return _("Couldn't paste non-POU object.")
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1005
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1006
        name = new_pou.getname()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1007
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1008
        idx = 0
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1009
        new_name = name
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1010
        while self.Project.getpou(new_name) is not None:
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1011
            # a POU with that name already exists.
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1012
            # make a new name and test if a POU with that name exists.
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1013
            # append an incrementing numeric suffix to the POU name.
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1014
            idx += 1
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1015
            new_name = "%s%d" % (name, idx)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1016
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1017
        # we've found a name that does not already exist, use it
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1018
        new_pou.setname(new_name)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1019
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1020
        if pou_type is not None:
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1021
            orig_type = new_pou.getpouType()
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1022
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1023
            # prevent violations of POU content restrictions:
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1024
            # function blocks cannot be pasted as functions,
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1025
            # programs cannot be pasted as functions or function blocks
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1026
            if orig_type == 'functionBlock' and pou_type == 'function' or \
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1027
               orig_type == 'program' and pou_type in ['function', 'functionBlock']:
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1028
                msg = _('''{a1} "{a2}" can't be pasted as a {a3}.''').format(a1=orig_type, a2=name, a3=pou_type)
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
  1029
                return msg
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1030
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1031
            new_pou.setpouType(pou_type)
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1032
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1033
        self.Project.insertpou(0, new_pou)
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1034
        self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1035
1299
9ffc49bfdf9d Fixed copy/paste with xmlclass refactoring
Laurent Bessard
parents: 1298
diff changeset
  1036
        return self.ComputePouName(new_name),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1037
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1038
    # Remove a Pou from project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1039
    def ProjectRemovePou(self, pou_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1040
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1041
            self.Project.removepou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1042
            self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1043
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1044
    # Return the name of the configuration if only one exist
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1045
    def GetProjectMainConfigurationName(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1046
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1047
            # Found the configuration corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1048
            configurations = self.Project.getconfigurations()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1049
            if len(configurations) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1050
                return configurations[0].getname()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1051
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1052
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1053
    # Add a configuration to Project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1054
    def ProjectAddConfiguration(self, config_name=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1055
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1056
            if config_name is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1057
                config_name = self.GenerateNewName(None, None, "configuration%d")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1058
            self.Project.addconfiguration(config_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1059
            self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1060
            return self.ComputeConfigurationName(config_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1061
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1062
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1063
    # Remove a configuration from project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1064
    def ProjectRemoveConfiguration(self, config_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1065
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1066
            self.Project.removeconfiguration(config_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1067
            self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1068
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1069
    # Add a resource to a configuration of the Project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1070
    def ProjectAddConfigurationResource(self, config_name, resource_name=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1071
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1072
            if resource_name is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1073
                resource_name = self.GenerateNewName(None, None, "resource%d")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1074
            self.Project.addconfigurationResource(config_name, resource_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1075
            self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1076
            return self.ComputeConfigurationResourceName(config_name, resource_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1077
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1078
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1079
    # Remove a resource from a configuration of the project
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1080
    def ProjectRemoveConfigurationResource(self, config_name, resource_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1081
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1082
            self.Project.removeconfigurationResource(config_name, resource_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1083
            self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1084
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1085
    # Add a Transition to a Project Pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1086
    def ProjectAddPouTransition(self, pou_name, transition_name, transition_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1087
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1088
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1089
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1090
                pou.addtransition(transition_name, transition_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1091
                self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1092
                return self.ComputePouTransitionName(pou_name, transition_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1093
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1094
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1095
    # Remove a Transition from a Project Pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1096
    def ProjectRemovePouTransition(self, pou_name, transition_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1097
        # Search if the pou removed is currently opened
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1098
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1099
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1100
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1101
                pou.removetransition(transition_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1102
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1103
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1104
    # Add an Action to a Project Pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1105
    def ProjectAddPouAction(self, pou_name, action_name, action_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1106
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1107
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1108
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1109
                pou.addaction(action_name, action_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1110
                self.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1111
                return self.ComputePouActionName(pou_name, action_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1112
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1113
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1114
    # Remove an Action from a Project Pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1115
    def ProjectRemovePouAction(self, pou_name, action_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1116
        # Search if the pou removed is currently opened
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1117
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1118
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1119
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1120
                pou.removeaction(action_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1121
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1122
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1123
    # Change the name of a pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1124
    def ChangeDataTypeName(self, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1125
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1126
            # Found the pou corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1127
            datatype = self.Project.getdataType(old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1128
            if datatype is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1129
                datatype.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1130
                self.Project.updateElementName(old_name, new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1131
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1132
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1133
    # Change the name of a pou
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1134
    def ChangePouName(self, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1135
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1136
            # Found the pou corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1137
            pou = self.Project.getpou(old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1138
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1139
                pou.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1140
                self.Project.updateElementName(old_name, new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1141
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1142
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1143
    # Change the name of a pou transition
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1144
    def ChangePouTransitionName(self, pou_name, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1145
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1146
            # Found the pou transition corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1147
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1148
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1149
                transition = pou.gettransition(old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1150
                if transition is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1151
                    transition.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1152
                    pou.updateElementName(old_name, new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1153
                    self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1154
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1155
    # Change the name of a pou action
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1156
    def ChangePouActionName(self, pou_name, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1157
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1158
            # Found the pou action corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1159
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1160
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1161
                action = pou.getaction(old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1162
                if action is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1163
                    action.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1164
                    pou.updateElementName(old_name, new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1165
                    self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1166
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1167
    # Change the name of a pou variable
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1168
    def ChangePouVariableName(self, pou_name, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1169
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1170
            # Found the pou action corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1171
            pou = self.Project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1172
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1173
                for type, varlist in pou.getvars():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1174
                    for var in varlist.getvariable():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1175
                        if var.getname() == old_name:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1176
                            var.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1177
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1178
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1179
    # Change the name of a configuration
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1180
    def ChangeConfigurationName(self, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1181
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1182
            # Found the configuration corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1183
            configuration = self.Project.getconfiguration(old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1184
            if configuration is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1185
                configuration.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1186
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1187
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1188
    # Change the name of a configuration resource
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1189
    def ChangeConfigurationResourceName(self, config_name, old_name, new_name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1190
        if self.Project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1191
            # Found the resource corresponding to old name and change its name to new name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1192
            resource = self.Project.getconfigurationResource(config_name, old_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1193
            if resource is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1194
                resource.setname(new_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1195
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1196
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1197
    # Return the description of the pou given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1198
    def GetPouDescription(self, name, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1199
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1200
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1201
            # Found the pou correponding to name and return its type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1202
            pou = project.getpou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1203
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1204
                return pou.getdescription()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1205
        return ""
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1206
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1207
    # Return the description of the pou given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1208
    def SetPouDescription(self, name, description, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1209
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1210
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1211
            # Found the pou correponding to name and return its type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1212
            pou = project.getpou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1213
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1214
                pou.setdescription(description)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1215
                self.BufferProject()
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1216
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1217
    # Return the type of the pou given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1218
    def GetPouType(self, name, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1219
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1220
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1221
            # Found the pou correponding to name and return its type
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1222
            pou = project.getpou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1223
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1224
                return pou.getpouType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1225
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1226
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1227
    # Return pous with SFC language
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1228
    def GetSFCPous(self, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1229
        list = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1230
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1231
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1232
            for pou in project.getpous():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1233
                if pou.getBodyType() == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1234
                    list.append(pou.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1235
        return list
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1236
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1237
    # Return the body language of the pou given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1238
    def GetPouBodyType(self, name, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1239
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1240
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1241
            # Found the pou correponding to name and return its body language
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1242
            pou = project.getpou(name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1243
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1244
                return pou.getbodyType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1245
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1246
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1247
    # Return the actions of a pou
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1248
    def GetPouTransitions(self, pou_name, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1249
        transitions = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1250
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1251
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1252
            # Found the pou correponding to name and return its transitions if SFC
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1253
            pou = project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1254
            if pou is not None and pou.getbodyType() == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1255
                for transition in pou.gettransitionList():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1256
                    transitions.append(transition.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1257
        return transitions
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1258
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1259
    # Return the body language of the transition given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1260
    def GetTransitionBodyType(self, pou_name, pou_transition, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1261
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1262
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1263
            # Found the pou correponding to name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1264
            pou = project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1265
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1266
                # Found the pou transition correponding to name and return its body language
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1267
                transition = pou.gettransition(pou_transition)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1268
                if transition is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1269
                    return transition.getbodyType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1270
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1271
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1272
    # Return the actions of a pou
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1273
    def GetPouActions(self, pou_name, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1274
        actions = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1275
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1276
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1277
            # Found the pou correponding to name and return its actions if SFC
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1278
            pou = project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1279
            if pou.getbodyType() == "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1280
                for action in pou.getactionList():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1281
                    actions.append(action.getname())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1282
        return actions
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1283
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1284
    # Return the body language of the pou given by its name
1744
69dfdb26f600 clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1743
diff changeset
  1285
    def GetActionBodyType(self, pou_name, pou_action, debug=False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1286
        project = self.GetProject(debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1287
        if project is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1288
            # Found the pou correponding to name and return its body language
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1289
            pou = project.getpou(pou_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1290
            if pou is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1291
                action = pou.getaction(pou_action)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1292
                if action is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1293
                    return action.getbodyType()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1294
        return None
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1295
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1296
    # Extract varlists from a list of vars
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1297
    def ExtractVarLists(self, vars):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1298
        varlist_list = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1299
        current_varlist = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1300
        current_type = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1301
        for var in vars:
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1302
            next_type = (var.Class,
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1303
                         var.Option,
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1304
                         var.Location in ["", None] or
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1305
                         # When declaring globals, located
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1306
                         # and not located variables are
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1307
                         # in the same declaration block
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1308
                         var.Class == "Global")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1309
            if current_type != next_type:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1310
                current_type = next_type
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1311
                infos = VAR_CLASS_INFOS.get(var.Class, None)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1312
                if infos is not None:
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1313
                    current_varlist = PLCOpenParser.CreateElement(infos[0], "interface")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1314
                else:
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1315
                    current_varlist = PLCOpenParser.CreateElement("varList")
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1316
                varlist_list.append((var.Class, current_varlist))
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1317
                if var.Option == "Constant":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1318
                    current_varlist.setconstant(True)
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1319
                elif var.Option == "Retain":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1320
                    current_varlist.setretain(True)
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1321
                elif var.Option == "Non-Retain":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1322
                    current_varlist.setnonretain(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1323
            # Create variable and change its properties
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1324
            tempvar = PLCOpenParser.CreateElement("variable", "varListPlain")
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1325
            tempvar.setname(var.Name)
1411
805d13d216c0 Fixed POU paste exception
Edouard Tisserant
parents: 1406
diff changeset
  1326
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1327
            var_type = PLCOpenParser.CreateElement("type", "variable")
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1328
            if isinstance(var.Type, TupleType):
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1329
                if var.Type[0] == "array":
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1341
diff changeset
  1330
                    array_type, base_type_name, dimensions = var.Type
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1331
                    array = PLCOpenParser.CreateElement("array", "dataType")
1306
1ff1cdf6c318 Fixed bug with direct array variable type definition
Laurent Bessard
parents: 1304
diff changeset
  1332
                    baseType = PLCOpenParser.CreateElement("baseType", "array")
1ff1cdf6c318 Fixed bug with direct array variable type definition
Laurent Bessard
parents: 1304
diff changeset
  1333
                    array.setbaseType(baseType)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1334
                    for i, dimension in enumerate(dimensions):
1306
1ff1cdf6c318 Fixed bug with direct array variable type definition
Laurent Bessard
parents: 1304
diff changeset
  1335
                        dimension_range = PLCOpenParser.CreateElement("dimension", "array")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1336
                        if i == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1337
                            array.setdimension([dimension_range])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1338
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1339
                            array.appenddimension(dimension_range)
1298
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1340
                        dimension_range.setlower(dimension[0])
f034fb2b1aab Fixed SFC block edition and SFC to SFC_textual code generating
Laurent Bessard
parents: 1297
diff changeset
  1341
                        dimension_range.setupper(dimension[1])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1342
                    if base_type_name in self.GetBaseTypes():
1306
1ff1cdf6c318 Fixed bug with direct array variable type definition
Laurent Bessard
parents: 1304
diff changeset
  1343
                        baseType.setcontent(PLCOpenParser.CreateElement(
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1344
                            base_type_name.lower()
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1345
                            if base_type_name in ["STRING", "WSTRING"]
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1346
                            else base_type_name, "dataType"))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1347
                    else:
1291
42ea51d083ce Second stage of xmlclass refactoring using lxml , project are loaded and displayed successfully
Laurent Bessard
parents: 1290
diff changeset
  1348
                        derived_datatype = PLCOpenParser.CreateElement("derived", "dataType")
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1349
                        derived_datatype.setname(base_type_name)
1306
1ff1cdf6c318 Fixed bug with direct array variable type definition
Laurent Bessard
parents: 1304