LPCBeremiz.py
author laurent
Tue, 15 Dec 2009 15:39:39 +0100
changeset 519 3a5faff52e5c
parent 517 6da1617a7645
child 521 02cb9e5fb6f6
permissions -rwxr-xr-x
Adding message to standard output to signal when LPCBeremiz is closed
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
     3
import shutil
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     4
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     5
__version__ = "$Revision$"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     6
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     7
import os, sys, getopt, wx, tempfile
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     8
from types import TupleType, StringType, UnicodeType
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     9
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    10
CWD = os.path.split(os.path.realpath(__file__))[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    11
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    12
def Bpath(*args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    13
    return os.path.join(CWD,*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    14
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    15
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    16
    def usage():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    17
        print "\nUsage of LPCBeremiz.py :"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    18
        print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    19
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    20
    try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    21
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    22
    except getopt.GetoptError:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    23
        # print help information and exit:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    24
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    25
        sys.exit(2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    26
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    27
    for o, a in opts:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    28
        if o in ("-h", "--help"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    29
            usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    30
            sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    31
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    32
    if len(args) > 2:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    33
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    34
        sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    35
    elif len(args) == 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    36
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    37
        buildpath = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    38
    elif len(args) == 2:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    39
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    40
        buildpath = args[1]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    41
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    42
        projectOpen = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    43
        buildpath = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    44
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    45
class PseudoLocale:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    46
    LocaleDirs = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    47
    Domains = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    48
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    49
    def AddCatalogLookupPathPrefix(self, localedir):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    50
        self.LocaleDirs.append(localedir)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    51
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    52
    def AddCatalog(self, domain):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    53
        self.Domains.append(domain)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    54
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    55
# Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    56
import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    57
import __builtin__
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    58
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    59
# Define locale for wx
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    60
__builtin__.__dict__['loc'] = PseudoLocale()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    61
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    62
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    63
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    64
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    65
from Beremiz import *
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
    66
from plugger import PluginsRoot, PlugTemplate, opjimg, connectors
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    67
from plcopen.structures import LOCATIONDATATYPES
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    68
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    69
                         LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
    70
from PLCOpenEditor import IDEFrame, ProjectDialog
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    71
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    72
#-------------------------------------------------------------------------------
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    73
#                          CANFESTIVAL PLUGIN HACK
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    74
#-------------------------------------------------------------------------------
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    75
from plugins.canfestival import canfestival
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    76
class LPC_canfestival_config:
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    77
    def getCFLAGS(self, *args):
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    78
        return ""
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    79
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    80
    def getLDFLAGS(self, *args):
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    81
        return ""
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    82
        
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    83
canfestival.local_canfestival_config = LPC_canfestival_config() 
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    84
#-------------------------------------------------------------------------------
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    85
#                              LPCModule Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    86
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    87
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    88
LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    89
                  "Q": LOCATION_VAR_OUTPUT,
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    90
                  "M": LOCATION_VAR_MEMORY}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    91
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    92
LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    93
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    94
LOCATION_SIZES = {}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    95
for size, types in LOCATIONDATATYPES.iteritems():
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    96
    for type in types:
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    97
        LOCATION_SIZES[type] = size
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    98
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    99
def _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   100
    children = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   101
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   102
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   103
            children.extend(child["children"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   104
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   105
            children.append(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   106
    return children
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   107
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   108
def _GetLastModuleGroup(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   109
    group = module
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   110
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   111
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   112
            group = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   113
    return group["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   114
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   115
def _GetModuleBySomething(module, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   116
    for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   117
        if child.get(something) == toks[0]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   118
            if len(toks) > 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   119
                return _GetModuleBySomething(child, something, toks[1:])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   120
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   121
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   122
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   123
def _GetModuleVariable(module, location, direction):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   124
    for child in _GetModuleChildren(module):
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   125
        if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   126
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   127
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   128
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   129
def _RemoveModuleChild(module, child):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   130
    if child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   131
        module["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   132
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   133
        for group in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   134
            if group["type"] == LOCATION_GROUP and child in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   135
                group["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   136
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   137
BUS_TEXT = """/* Code generated by LPCBus plugin */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   138
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   139
/* LPCBus plugin includes */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   140
#include "app_glue.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   141
#ifdef _WINDOWS_H
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   142
  #include "iec_types.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   143
#else
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   144
  #include "iec_std_lib.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   145
#endif
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   146
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   147
%(declare_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   148
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   149
/* LPCBus plugin user variables definition */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   150
%(var_decl)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   151
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   152
/* LPCBus plugin functions */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   153
int __init_%(location_str)s(int argc,char **argv)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   154
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   155
  return 0;
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   156
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   157
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   158
void __cleanup_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   159
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   160
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   161
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   162
void __retrieve_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   163
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   164
  %(retrieve_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   165
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   166
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   167
void __publish_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   168
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   169
  %(publish_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   170
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   171
"""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   172
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   173
class LPCBus(object):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   174
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   175
    def __init__(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   176
        self.VariableLocationTree = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   177
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   178
        self.Icon = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   179
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   180
    def __getitem__(self, key):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   181
        if key == "children":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   182
            return self.VariableLocationTree
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   183
        raise KeyError, "Only 'children' key is available"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   184
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   185
    def SetIcon(self, icon):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   186
        self.Icon = icon
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   187
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   188
    def _GetChildBySomething(self, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   189
        return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   190
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   191
    def GetBaseTypes(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   192
        return self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   193
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   194
    def GetSizeOfType(self, type):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   195
        return LOCATION_SIZES[self.GetPlugRoot().GetBaseType(type)]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   196
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   197
    def _GetVariableLocationTree(self, current_location, infos):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   198
        if infos["type"] == LOCATION_MODULE:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   199
            location = current_location + (infos["IEC_Channel"],)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   200
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   201
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   202
                    "location": ".".join(map(str, location + ("x",))), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   203
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   204
                    "children": [self._GetVariableLocationTree(location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   205
        elif infos["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   206
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   207
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   208
                    "location": "", 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   209
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   210
                    "children": [self._GetVariableLocationTree(current_location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   211
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   212
            size = self.GetSizeOfType(infos["IEC_type"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   213
            location = "%" + LOCATION_DIRS[infos["type"]] + size + ".".join(map(str, current_location + infos["location"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   214
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   215
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   216
                    "size": size,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   217
                    "IEC_type": infos["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   218
                    "location": location,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   219
                    "description": infos["description"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   220
                    "children": []}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   221
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   222
    def GetVariableLocationTree(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   223
        return {"name": self.BaseParams.getName(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   224
                "type": LOCATION_PLUGIN,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   225
                "location": self.GetFullIEC_Channel(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   226
                "icon": self.Icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   227
                "children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   228
                             for child in self.VariableLocationTree]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   229
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   230
    def PlugTestModified(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   231
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   232
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   233
    def PlugMakeDir(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   234
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   235
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   236
    def PlugRequestSave(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   237
        return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   238
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   239
    def ResetUsedLocations(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   240
        self.UsedLocations = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   241
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   242
    def _AddUsedLocation(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   243
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   244
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   245
            parent[num] = {"used": False, "children": {}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   246
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   247
            self._AddUsedLocation(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   248
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   249
            parent[num]["used"] = True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   250
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   251
    def AddUsedLocation(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   252
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   253
            self._AddUsedLocation(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   254
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   255
    def _CheckLocationConflicts(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   256
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   257
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   258
            return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   259
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   260
            if parent[num]["used"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   261
                return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   262
            return self._CheckLocationConflicts(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   263
        elif len(parent[num]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   264
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   265
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   266
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   267
    def CheckLocationConflicts(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   268
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   269
            return self._CheckLocationConflicts(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   270
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   271
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   272
    def PlugGenerate_C(self, buildpath, locations):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   273
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   274
        Generate C code
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   275
        @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   276
        @param locations: List of complete variables locations \
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   277
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   278
            "NAME" : name of the variable (generally "__IW0_1_2" style)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   279
            "DIR" : direction "Q","I" or "M"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   280
            "SIZE" : size "X", "B", "W", "D", "L"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   281
            "LOC" : tuple of interger for IEC location (0,1,2,...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   282
            }, ...]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   283
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   284
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   285
        current_location = self.GetCurrentLocation()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   286
        # define a unique name for the generated C file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   287
        location_str = "_".join(map(str, current_location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   288
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   289
        code_str = {"location_str": location_str,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   290
                    "var_decl": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   291
                    "declare_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   292
                    "retrieve_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   293
                    "publish_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   294
                   }
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   295
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   296
        # Adding variables
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   297
        vars = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   298
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   299
        for location in locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   300
            loc = location["LOC"][len(current_location):]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   301
            group = next = self
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   302
            i = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   303
            while next is not None and i < len(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   304
                next = self._GetChildBySomething("IEC_Channel", loc[:i + 1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   305
                if next is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   306
                    i += 1
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   307
                    group = next
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   308
            var_loc = loc[i:]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   309
            for variable in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   310
                if variable["location"] == var_loc:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   311
                    if location["DIR"] != LOCATION_DIRS[variable["type"]]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   312
                        raise Exception, "Direction conflict in variable definition"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   313
                    if location["IEC_TYPE"] != variable["IEC_type"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   314
                        raise Exception, "Type conflict in variable definition"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   315
                    if location["DIR"] == "Q":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   316
                        if self.CheckLocationConflicts(location["LOC"]):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   317
                            raise Exception, "BYTE and BIT from the same BYTE can't be used together"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   318
                        self.AddUsedLocation(location["LOC"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   319
                    vars.append({"location": location["NAME"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   320
                                 "Type": variable["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   321
                                 "Declare": variable["declare"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   322
                                 "Retrieve": variable["retrieve"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   323
                                 "Publish": variable["publish"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   324
                                })
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   325
                    break
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   326
        base_types = self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   327
        for var in vars:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   328
            prefix = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   329
            if var["Type"] in base_types:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   330
                prefix = "IEC_"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   331
            code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   332
            code_str["var_decl"] += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   333
            if var["Declare"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   334
                code_str["declare_code"] += var["Declare"] + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   335
            if var["Retrieve"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   336
                code_str["retrieve_code"] += var["Retrieve"] % ("*" + var["location"]) + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   337
            if var["Publish"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   338
                code_str["publish_code"] += var["Publish"] % ("*" + var["location"]) + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   339
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   340
        Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   341
        module = open(Gen_Module_path,'w')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   342
        module.write(BUS_TEXT % code_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   343
        module.close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   344
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   345
        matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   346
        return [(Gen_Module_path, matiec_flags)],"",True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   347
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   348
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   349
#                              LPCPluginsRoot Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   350
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   351
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   352
def mycopytree(src, dst):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   353
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   354
    Copy content of a directory to an other, omit hidden files
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   355
    @param src: source directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   356
    @param dst: destination directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   357
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   358
    for i in os.listdir(src):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   359
        if not i.startswith('.'):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   360
            srcpath = os.path.join(src,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   361
            dstpath = os.path.join(dst,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   362
            if os.path.isdir(srcpath):
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   363
                if os.path.exists(dstpath):
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   364
                    shutil.rmtree(dstpath)
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   365
                os.makedirs(dstpath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   366
                mycopytree(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   367
            elif os.path.isfile(srcpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   368
                shutil.copy2(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   369
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   370
class LPCPluginsRoot(PluginsRoot):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   371
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   372
    PluginMethods = [
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   373
        {"bitmap" : opjimg("Debug"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   374
         "name" : _("Simulate"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   375
         "tooltip" : _("Simulate PLC"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   376
         "method" : "_Simulate"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   377
        {"bitmap" : opjimg("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   378
         "name" : _("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   379
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   380
         "tooltip" : _("Start PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   381
         "method" : "_Run"},
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   382
        {"bitmap" : opjimg("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   383
         "name" : _("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   384
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   385
         "tooltip" : _("Stop Running PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   386
         "method" : "_Stop"},
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   387
        {"bitmap" : opjimg("Build"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   388
         "name" : _("Build"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   389
         "tooltip" : _("Build project into build folder"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   390
         "method" : "_build"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   391
        {"bitmap" : opjimg("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   392
         "name" : _("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   393
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   394
         "tooltip" : _("Transfer PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   395
         "method" : "_Transfer"},
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   396
    ]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   397
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   398
    def __init__(self, frame, logger):
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   399
        PluginsRoot.__init__(self, frame, logger)
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   400
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   401
        self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   402
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   403
        self.OnlineMode = 0
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   404
        self.OnlinePath = None
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   405
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   406
        self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   407
        self.SimulationBuildPath = None
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   408
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   409
        self.previous_simulating = False
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   410
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   411
    def GetProjectName(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   412
        return self.Project.getname()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   413
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   414
    def GetDefaultTargetName(self):
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   415
        if self.BuildSimulation:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   416
            return PluginsRoot.GetDefaultTargetName(self)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   417
        else:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   418
            return "LPC"
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   419
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   420
    def GetTarget(self):
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   421
        target = PluginsRoot.GetTarget(self)
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   422
        if not self.BuildSimulation:
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   423
            target.getcontent()["value"].setBuildPath(self.BuildPath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   424
        return target
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   425
    
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   426
    def _getBuildPath(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   427
        if self.BuildSimulation:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   428
            if self.SimulationBuildPath is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   429
                self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build")
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   430
            return self.SimulationBuildPath
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   431
        else:
494
9e4263099427 Bug when opening with not empty buildpath parameter fixed
laurent
parents: 492
diff changeset
   432
            return PluginsRoot._getBuildPath(self)
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   433
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   434
    def _build(self):
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   435
        if self.BuildPath is not None:
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   436
            mycopytree(self.OrigBuildPath, self.BuildPath)
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   437
        PluginsRoot._build(self)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   438
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   439
    def SetProjectName(self, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   440
        return self.Project.setname(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   441
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   442
    def SetOnlineMode(self, mode, path=None):
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   443
        if self.OnlineMode != mode:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   444
            self.OnlineMode = mode
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   445
            self.KillDebugThread()
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   446
            
517
6da1617a7645 Bug when changing LPCBeremiz OnlineMode fixed
laurent
parents: 515
diff changeset
   447
            if self.OnlineMode != 0:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   448
                if self._connector is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   449
                    uri = "LPC://%s" % path
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   450
                    try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   451
                        self._connector = connectors.ConnectorFactory(uri, self)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   452
                    except Exception, msg:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   453
                        self.logger.write_error(_("Exception while connecting %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   454
                        self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   455
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   456
                    # Did connection success ?
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   457
                    if self._connector is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   458
                        # Oups.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   459
                        self.logger.write_error(_("Connection failed to %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   460
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   461
                if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   462
                
517
6da1617a7645 Bug when changing LPCBeremiz OnlineMode fixed
laurent
parents: 515
diff changeset
   463
                    if self.OnlineMode == 1:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   464
                        self.CompareLocalAndRemotePLC()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   465
                    
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   466
                        # Init with actual PLC status and print it
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   467
                        self.UpdateMethodsFromPLCStatus()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   468
                        if self.previous_plcstate is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   469
                            status = _(self.previous_plcstate)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   470
                        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   471
                            status = ""
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   472
                        self.logger.write(_("PLC is %s\n")%status)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   473
                        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   474
                        # Start the status Timer
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   475
                        self.StatusTimer.Start(milliseconds=500, oneShot=False)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   476
                        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   477
                        if self.previous_plcstate=="Started":
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   478
                            if self.DebugAvailable() and self.GetIECProgramsAndVariables():
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   479
                                self.logger.write(_("Debug connect matching running PLC\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   480
                                self._connect_debug()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   481
                            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   482
                                self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   483
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   484
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   485
                self._connector = None
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   486
                self.StatusTimer.Stop()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   487
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   488
            self.OnlinePath = path
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   489
            self.UpdateMethodsFromPLCStatus()
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   490
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   491
    # Update a PLCOpenEditor Pou variable name
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   492
    def UpdateProjectVariableName(self, old_name, new_name):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   493
        self.Project.updateElementName(old_name, new_name)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   494
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   495
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   496
    def RemoveProjectVariableByAddress(self, address):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   497
        self.Project.removeVariableByAddress(address)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   498
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   499
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   500
    def RemoveProjectVariableByFilter(self, leading):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   501
        self.Project.removeVariableByFilter(leading)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   502
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   503
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   504
    def LoadProject(self, ProjectPath, BuildPath=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   505
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   506
        Load a project contained in a folder
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   507
        @param ProjectPath: path of the project folder
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   508
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   509
        if os.path.basename(ProjectPath) == "":
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   510
            ProjectPath = os.path.dirname(ProjectPath)
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   511
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   512
        # Verify that project contains a PLCOpen program
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   513
        plc_file = os.path.join(ProjectPath, "plc.xml")
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   514
        if os.path.isfile(plc_file):
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   515
            # Load PLCOpen file
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   516
            result = self.OpenXMLFile(plc_file)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   517
            if result:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   518
                return result
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   519
        else:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   520
            self.CreateNewProject({"companyName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   521
                                   "productName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   522
                                   "productVersion": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   523
                                   "projectName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   524
                                   "pageSize": (0, 0),
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   525
                                   "scaling": {}})
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   526
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   527
        # Change XSD into class members
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   528
        self._AddParamsMembers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   529
        self.PluggedChilds = {}
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   530
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   531
        # Keep track of the root plugin (i.e. project path)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   532
        self.ProjectPath = ProjectPath
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   533
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   534
        self.BuildPath = self._getBuildPath()
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   535
        self.OrigBuildPath = BuildPath
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   536
        if BuildPath is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   537
            mycopytree(BuildPath, self.BuildPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   538
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   539
        # If dir have already be made, and file exist
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   540
        if os.path.isdir(self.PlugPath()) and os.path.isfile(self.PluginXmlFilePath()):
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   541
            #Load the plugin.xml file into parameters members
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   542
            result = self.LoadXMLParams()
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   543
            if result:
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   544
                return result
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   545
            #Load and init all the childs
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   546
            self.LoadChilds()
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   547
        
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   548
        if self.PlugTestModified():
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   549
            self.SaveProject()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   550
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   551
        self.RefreshPluginsBlockLists()
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   552
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   553
        return None
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   554
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   555
    ############# Real PLC object access #############
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   556
    def UpdateMethodsFromPLCStatus(self):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   557
        # Get PLC state : Running or Stopped
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   558
        # TODO : use explicit status instead of boolean
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   559
        simulating = False
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   560
        if self.OnlineMode == 0:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   561
            if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   562
                simulating = self._connector.GetPLCstatus() == "Started"
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   563
            status = "Disconnected"
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   564
        elif self.OnlineMode == 1:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   565
            if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   566
                simulating = self._connector.GetPLCstatus() == "Started"
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   567
            status = "Connected"
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   568
        else:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   569
            if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   570
                status = self._connector.GetPLCstatus()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   571
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   572
                status = "Disconnected"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   573
        if self.previous_plcstate != status or self.previous_simulating != simulating:
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   574
            for args in {
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   575
                     "Started" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   576
                                      ("_Run", False),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   577
                                      ("_Stop", True),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   578
                                      ("_build", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   579
                                      ("_Transfer", False)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   580
                     "Stopped" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   581
                                      ("_Run", True),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   582
                                      ("_Stop", False),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   583
                                      ("_build", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   584
                                      ("_Transfer", False)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   585
                     "Connected" :   [("_Simulate", not simulating),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   586
                                      ("_Run", False),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   587
                                      ("_Stop", simulating),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   588
                                      ("_build", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   589
                                      ("_Transfer", True)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   590
                     "Disconnected" :[("_Simulate", not simulating),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   591
                                      ("_Run", False),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   592
                                      ("_Stop", simulating),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   593
                                      ("_build", True),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   594
                                      ("_Transfer", False)],
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   595
                   }.get(status,[]):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   596
                self.ShowMethod(*args)
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   597
            self.previous_plcstate = status
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   598
            self.previous_simulating = simulating
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   599
            return True
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   600
        return False
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   601
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   602
    def Generate_plc_declare_locations(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   603
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   604
        Declare used locations in order to simulatePLC in a black box
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   605
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   606
        return """#include "iec_types_all.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   607
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   608
#define __LOCATED_VAR(type, name, ...) \
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   609
type beremiz_##name;\
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   610
type *name = &beremiz_##name;
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   611
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   612
#include "LOCATED_VARIABLES.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   613
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   614
#undef __LOCATED_VAR
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   615
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   616
"""
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   617
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   618
    def _Simulate(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   619
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   620
        Method called by user to Simulate PLC
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   621
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   622
        uri = "LOCAL://"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   623
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   624
            self._connector = connectors.ConnectorFactory(uri, self)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   625
        except Exception, msg:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   626
            self.logger.write_error(_("Exception while connecting %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   627
            self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   628
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   629
        # Did connection success ?
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   630
        if self._connector is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   631
            # Oups.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   632
            self.logger.write_error(_("Connection failed to %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   633
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   634
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   635
        self.BuildSimulation = True
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   636
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   637
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   638
        buildpath = self._getBuildPath()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   639
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   640
        # Eventually create build dir
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   641
        if not os.path.exists(buildpath):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   642
            os.makedirs(buildpath)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   643
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   644
        # Generate SoftPLC IEC code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   645
        IECGenRes = self._Generate_SoftPLC()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   646
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   647
         # If IEC code gen fail, bail out.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   648
        if not IECGenRes:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   649
            self.logger.write_error(_("IEC-61131-3 code generation failed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   650
            self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   651
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   652
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   653
        # Reset variable and program list that are parsed from
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   654
        # CSV file generated by IEC2C compiler.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   655
        self.ResetIECProgramsAndVariables()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   656
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   657
        gen_result = self.PlugGenerate_C(buildpath, self.PLCGeneratedLocatedVars)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   658
        PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   659
        # if some files have been generated put them in the list with their location
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   660
        if PlugCFilesAndCFLAGS:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   661
            self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   662
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   663
            self.LocationCFilesAndCFLAGS = []
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   664
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   665
        # plugin asks for some LDFLAGS
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   666
        if PlugLDFLAGS:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   667
            # LDFLAGS can be either string
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   668
            if type(PlugLDFLAGS)==type(str()):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   669
                self.LDFLAGS=[PlugLDFLAGS]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   670
            #or list of strings
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   671
            elif type(PlugLDFLAGS)==type(list()):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   672
                self.LDFLAGS=PlugLDFLAGS[:]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   673
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   674
            self.LDFLAGS=[]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   675
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   676
        # Template based part of C code generation
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   677
        # files are stacked at the beginning, as files of plugin tree root
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   678
        for generator, filename, name in [
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   679
           # debugger code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   680
           (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   681
           # init/cleanup/retrieve/publish, run and align code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   682
           (self.Generate_plc_common_main,"plc_common_main.c","Common runtime"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   683
           # declare located variables for simulate in a black box
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   684
           (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations")]:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   685
            try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   686
                # Do generate
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   687
                code = generator()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   688
                if code is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   689
                     raise
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   690
                code_path = os.path.join(buildpath,filename)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   691
                open(code_path, "w").write(code)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   692
                # Insert this file as first file to be compiled at root plugin
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   693
                self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   694
            except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   695
                self.logger.write_error(name+_(" generation failed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   696
                self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   697
                self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   698
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   699
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   700
        # Get simulation builder
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   701
        builder = self.GetBuilder()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   702
        if builder is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   703
            self.logger.write_error(_("Fatal : cannot get builder.\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   704
            self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   705
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   706
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   707
        # Build
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   708
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   709
            if not builder.build() :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   710
                self.logger.write_error(_("C Build failed.\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   711
                self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   712
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   713
        except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   714
            self.logger.write_error(_("C Build crashed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   715
            self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   716
            self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   717
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   718
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   719
        data = builder.GetBinaryCode()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   720
        if data is not None :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   721
            if self._connector.NewPLC(builder.GetBinaryCodeMD5(), data, []):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   722
                if self.AppFrame is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   723
                    self.AppFrame.CloseDebugTabs()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   724
                    self.AppFrame.RefreshInstancesTree()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   725
                self.UnsubscribeAllDebugIECVariable()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   726
                self.ProgramTransferred()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   727
                self.logger.write(_("Transfer completed successfully.\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   728
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   729
                self.logger.write_error(_("Transfer failed\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   730
                self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   731
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   732
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   733
        self._Run()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   734
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   735
        self.BuildSimulation = False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   736
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   737
        # Start the status Timer
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   738
        self.StatusTimer.Start(milliseconds=500, oneShot=False)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   739
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   740
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   741
#                              LPCBeremiz Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   742
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   743
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   744
class LPCBeremiz(Beremiz):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   745
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   746
    def _init_coll_FileMenu_Items(self, parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   747
        AppendMenu(parent, help='', id=wx.ID_SAVE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   748
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   749
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   750
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   751
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   752
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   753
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   754
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   755
              kind=wx.ITEM_NORMAL, text=_(u'Preview'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   756
        AppendMenu(parent, help='', id=wx.ID_PRINT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   757
              kind=wx.ITEM_NORMAL, text=_(u'Print'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   758
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   759
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   760
              kind=wx.ITEM_NORMAL, text=_(u'Properties'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   761
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   762
        AppendMenu(parent, help='', id=wx.ID_EXIT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   763
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   764
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   765
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   766
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   767
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   768
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   769
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   770
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   771
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   772
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   773
    def _init_ctrls(self, prnt):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   774
        IDEFrame._init_ctrls(self, prnt)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   775
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   776
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   777
        accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   778
        self.SetAcceleratorTable(accel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   779
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   780
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   781
              name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   782
              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   783
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   784
        self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   785
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   786
        self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   787
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   788
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   789
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   790
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   791
        self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   792
        self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   793
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   794
        self._init_beremiz_sizers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   795
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   796
    def OnCloseFrame(self, event):
519
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
   797
        global frame
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   798
        frame = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   799
        self.PluginRoot.ResetAppFrame(lpcberemiz_cmd.Log)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   800
        if self.PluginRoot.OnlineMode == 0:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   801
            self.PluginRoot._connector = None
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   802
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   803
        self.PluginRoot.KillDebugThread()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   804
        self.KillLocalRuntime()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   805
        
519
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
   806
        print "Closed"
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
   807
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   808
        event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   809
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   810
    def ShowProperties(self):
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   811
        old_values = self.Controler.GetProjectProperties()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   812
        dialog = ProjectDialog(self ,False)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   813
        dialog.SetValues(old_values)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   814
        if dialog.ShowModal() == wx.ID_OK:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   815
            new_values = dialog.GetValues()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   816
            new_values["creationDateTime"] = old_values["creationDateTime"]
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   817
            if new_values != old_values:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   818
                self.Controler.SetProjectProperties(None, new_values)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   819
                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   820
                              TYPESTREE, INSTANCESTREE, SCALING)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   821
        dialog.Destroy()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   822
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   823
    def RefreshFileMenu(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   824
        if self.PluginRoot is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   825
            selected = self.TabsOpened.GetSelection()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   826
            if selected >= 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   827
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   828
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   829
                graphic_viewer = False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   830
            if self.TabsOpened.GetPageCount() > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   831
                self.FileMenu.Enable(wx.ID_CLOSE, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   832
                if graphic_viewer:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   833
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   834
                    self.FileMenu.Enable(wx.ID_PRINT, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   835
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   836
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   837
                    self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   838
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   839
                self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   840
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   841
                self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   842
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   843
            self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   844
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   845
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   846
            self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   847
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   848
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   849
            self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   850
            self.FileMenu.Enable(wx.ID_SAVE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   851
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   852
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   853
    def RefreshPLCParams(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   854
        self.Freeze()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   855
        self.ClearSizer(self.PLCParamsSizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   856
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   857
        if self.PluginRoot is not None:    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   858
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   859
            if self.PluginRoot.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   860
                bkgdclr = CHANGED_TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   861
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   862
                bkgdclr = TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   863
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   864
            if self.PluginRoot not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   865
                self.PluginInfos[self.PluginRoot] = {"right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   866
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   867
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   868
            plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   869
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   870
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   871
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   872
            plcwindow.SetSizer(plcwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   873
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   874
            st = wx.StaticText(plcwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   875
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   876
            st.SetLabel(self.PluginRoot.GetProjectName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   877
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   878
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   879
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   880
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   881
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   882
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   883
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   884
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   885
            msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   886
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   887
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   888
        self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   889
        self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   890
        self.Thaw()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   891
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   892
    def GenerateTreeBranch(self, plugin):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   893
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   894
        if plugin.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   895
            bkgdclr=CHANGED_WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   896
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   897
            bkgdclr=WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   898
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   899
        leftwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   900
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   901
        if plugin not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   902
            self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   903
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   904
        self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   905
        plugin_infos = plugin.GetVariableLocationTree()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   906
        plugin_locations = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   907
        if len(self.PluginInfos[plugin]["children"]) == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   908
            plugin_locations = plugin_infos["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   909
            if not self.PluginInfos[plugin].has_key("locations_infos"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   910
                self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   911
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   912
            self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   913
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   914
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   915
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   916
        leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   917
        leftwindow.SetSizer(leftwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   918
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   919
        st = wx.StaticText(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   920
        st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   921
        st.SetLabel(plugin.GetFullIEC_Channel())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   922
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   923
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   924
        expandbutton_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   925
        expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   926
              name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   927
              size=wx.Size(13, 13), style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   928
        expandbutton.labelDelta = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   929
        expandbutton.SetBezelWidth(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   930
        expandbutton.SetUseFocusIndicator(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   931
        expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   932
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   933
        if len(self.PluginInfos[plugin]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   934
            expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   935
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   936
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   937
                    self.ExpandPlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   938
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   939
                    self.CollapsePlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   940
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   941
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   942
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   943
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   944
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   945
        elif len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   946
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   947
            expandbutton.SetToggle(locations_infos["root"]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   948
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   949
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   950
                    self.ExpandLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   951
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   952
                    self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   953
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   954
                locations_infos["root"]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   955
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   956
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   957
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   958
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   959
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   960
            expandbutton.Enable(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   961
        leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   962
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   963
        sb = wx.StaticBitmap(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   964
        icon = plugin_infos.get("icon", None)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   965
        if icon is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   966
            icon = os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[plugin_infos["type"]])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   967
        sb.SetBitmap(wx.Bitmap(icon))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   968
        leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   969
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   970
        st_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   971
        st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   972
        st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   973
        st.SetLabel(plugin.MandatoryParams[1].getName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   974
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   975
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   976
        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   977
        rightwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   978
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   979
        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   980
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   981
        self.PluginInfos[plugin]["left"] = leftwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   982
        self.PluginInfos[plugin]["right"] = rightwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   983
        for child in self.PluginInfos[plugin]["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   984
            self.GenerateTreeBranch(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   985
            if not self.PluginInfos[child]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   986
                self.CollapsePlugin(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   987
        if len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   988
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   989
            for location in plugin_locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   990
                locations_infos["root"]["children"].append("root.%s" % location["name"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   991
                self.GenerateLocationTreeBranch(locations_infos, "root", location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   992
            if not locations_infos["root"]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   993
                self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   994
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   995
frame = None
514
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
   996
app = None
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
   997
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
   998
def GetApp():
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
   999
    global app
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
  1000
    return app
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
  1001
wx.GetApp = GetApp
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1002
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1003
def BeremizStartProc(plugin_root):
514
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
  1004
    global frame, app
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1005
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1006
    app = wx.PySimpleApp()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1007
    app.SetAppName('beremiz')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1008
    wx.InitAllImageHandlers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1009
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1010
    # Get the english language
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1011
    langid = wx.LANGUAGE_ENGLISH
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1012
    # Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1013
    import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1014
    import __builtin__
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1015
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1016
    # Define locale for wx
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1017
    loc = wx.Locale(langid)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1018
    for localedir in PseudoLocale.LocaleDirs:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1019
        loc.AddCatalogLookupPathPrefix(localedir)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1020
    for domain in PseudoLocale.Domains:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1021
        loc.AddCatalog(domain)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1022
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1023
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1024
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1025
    # Install a exception handle for bug reports
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1026
    AddExceptHook(os.getcwd(),__version__)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1027
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
  1028
    frame = LPCBeremiz(None, plugin_root=plugin_root, debug=True)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1029
    plugin_root.SetAppFrame(frame, frame.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1030
    frame.Show()
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1031
    frame.Raise()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1032
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1033
    app.MainLoop()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1034
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1035
    frame = None
514
d36a89dcd21c Bug on LPCBeremiz when wxPopen asking for Yield after reopening of a Beremiz window fixed
laurent
parents: 510
diff changeset
  1036
    app = None
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1037
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1038
class StdoutPseudoFile:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1039
    """ Base class for file like objects to facilitate StdOut for the Shell."""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1040
    def write(self, s, style = None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1041
        if s != '':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1042
            print s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1043
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1044
    def write_warning(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1045
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1046
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1047
    def write_error(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1048
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1049
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1050
    def flush(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1051
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1052
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1053
    def isatty(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1054
        return false
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1055
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1056
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1057
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1058
    from threading import Thread, Timer
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1059
    import cmd
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1060
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1061
    class LPCBeremiz_Cmd(cmd.Cmd):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1062
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1063
        prompt = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1064
        Log = StdoutPseudoFile()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1065
        RefreshTimer = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1066
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1067
        def __init__(self, projectOpen, buildpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1068
            cmd.Cmd.__init__(self)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1069
            self.PluginRoot = LPCPluginsRoot(None, self.Log)
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
  1070
            if projectOpen is not None and os.path.isdir(projectOpen):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1071
                result = self.PluginRoot.LoadProject(projectOpen, buildpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1072
                if result:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1073
                    print "Error: Invalid project directory", result
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1074
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1075
                print "Error: No such file or directory"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1076
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1077
        def RestartTimer(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1078
            if self.RefreshTimer is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1079
                self.RefreshTimer.cancel()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1080
            self.RefreshTimer = Timer(0.1, self.Refresh)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1081
            self.RefreshTimer.start()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1082
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1083
        def Exit(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1084
            self.Close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1085
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1086
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1087
        def do_EOF(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1088
            return self.Exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1089
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1090
        def Show(self):
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1091
            global frame
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1092
            if frame is None:
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1093
                beremiz_thread=Thread(target=BeremizStartProc, args=[self.PluginRoot])
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1094
                beremiz_thread.start()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1095
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1096
        def Refresh(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1097
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1098
            if frame is not None:
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1099
                wx.CallAfter(frame._Refresh, TITLE, INSTANCESTREE, FILEMENU, EDITMENU)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1100
                wx.CallAfter(frame.RefreshEditor)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1101
                wx.CallAfter(frame.RefreshAll)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1102
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1103
        def Close(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1104
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1105
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1106
            self.PluginRoot.ResetAppFrame(self.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1107
            if frame is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1108
                wx.CallAfter(frame.Close)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1109
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1110
        def Compile(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1111
            if wx.GetApp() is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1112
                self.PluginRoot._build()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1113
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1114
                wx.CallAfter(self.PluginRoot._build)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1115
        
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1116
        def SetProjectProperties(self, projectname, productname, productversion, companyname):
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1117
            properties = self.PluginRoot.GetProjectProperties()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1118
            properties["projectName"] = projectname
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1119
            properties["productName"] = productname
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1120
            properties["productVersion"] = productversion
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1121
            properties["companyName"] = companyname
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1122
            self.PluginRoot.SetProjectProperties(properties=properties)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1123
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1124
        
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1125
        def SetOnlineMode(self, mode, path=None):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1126
            self.PluginRoot.SetOnlineMode(mode, path)
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1127
            self.RestartTimer()
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1128
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1129
        def AddBus(self, iec_channel, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1130
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1131
                if child.BaseParams.getName() == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1132
                    return "Error: A bus named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1133
                elif child.BaseParams.getIEC_Channel() == iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1134
                    return "Error: A bus with IEC_channel %d already exists" % iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1135
            bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1136
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1137
                return "Error: Unable to create bus"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1138
            bus.SetIcon(icon)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1139
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1140
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1141
        def RenameBus(self, iec_channel, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1142
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1143
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1144
                return "Error: No bus found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1145
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1146
                if child != bus and child.BaseParams.getName() == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1147
                    return "Error: A bus named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1148
            bus.BaseParams.setName(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1149
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1150
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1151
        def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1152
            bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1153
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1154
                return "Error: No bus found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1155
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1156
                if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1157
                    return "Error: A bus with IEC_channel %d already exists" % new_iec_channel
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1158
            self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), str(new_iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1159
            bus.BaseParams.setIEC_Channel(new_iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1160
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1161
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1162
        def RemoveBus(self, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1163
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1164
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1165
                return "Error: No bus found"
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1166
            self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1167
            self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1168
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1169
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1170
        def AddModule(self, parent, iec_channel, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1171
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1172
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1173
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1174
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1175
                if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1176
                    return "Error: A module named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1177
                elif child["IEC_Channel"] == iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1178
                    return "Error: A module with IEC_channel %d already exists" % iec_channel 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1179
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1180
                                                "type": LOCATION_MODULE, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1181
                                                "IEC_Channel": iec_channel, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1182
                                                "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1183
                                                "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1184
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1185
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1186
        def RenameModule(self, iec_location, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1187
            module = self.PluginRoot.GetChildByIECLocation(iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1188
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1189
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1190
            parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1191
            if parent is self.PluginRoot:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1192
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1193
            if module["name"] != name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1194
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1195
                    if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1196
                        return "Error: A module named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1197
                module["name"] = name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1198
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1199
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1200
        def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1201
            module = self.PluginRoot.GetChildByIECLocation(old_iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1202
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1203
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1204
            parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1205
            if parent is self.PluginRoot:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1206
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1207
            if module["IEC_Channel"] != new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1208
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1209
                    if child["IEC_Channel"] == new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1210
                        return "Error: A module with IEC_channel %d already exists" % new_iec_channel
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1211
            self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1212
            module["IEC_Channel"] = new_iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1213
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1214
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1215
        def RemoveModule(self, parent, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1216
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1217
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1218
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1219
            child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1220
            if child is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1221
                return "Error: No module found"
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1222
            self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1223
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1224
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1225
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1226
        def StartGroup(self, parent, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1227
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1228
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1229
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1230
            for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1231
                if child["type"] == LOCATION_GROUP and child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1232
                    return "Error: A group named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1233
            module["children"].append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1234
                                      "type": LOCATION_GROUP, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1235
                                      "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1236
                                      "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1237
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1238
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1239
        def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1240
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1241
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1242
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1243
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1244
                if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1245
                    return "Error: A variable named %s already exists" % name
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1246
                if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1247
                    return "Error: A variable with location %s already exists" % ".".join(map(str, location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1248
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1249
                                                "location": location, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1250
                                                "type": LOCATION_TYPES[direction], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1251
                                                "IEC_type": type, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1252
                                                "description": description, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1253
                                                "declare": dcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1254
                                                "retrieve": rcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1255
                                                "publish": pcode})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1256
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1257
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1258
        def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1259
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1260
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1261
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1262
            variable = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1263
            for child in _GetModuleChildren(module):
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1264
                if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1265
                    variable = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1266
                elif child["name"] == new_name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1267
                    return "Error: A variable named %s already exists" % new_name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1268
            if variable is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1269
                return "Error: No variable found"
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1270
            if variable["name"] != new_name:
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1271
                self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1272
                variable["name"] = new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1273
            variable["type"] = LOCATION_TYPES[new_direction]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1274
            variable["IEC_type"] = new_type
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1275
            variable["declare"] = new_dcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1276
            variable["retrieve"] = new_rcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1277
            variable["publish"] = new_pcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1278
            if new_description is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1279
                variable["description"] = new_description
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1280
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1281
    
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1282
        def RemoveVariable(self, parent, location, direction):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1283
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1284
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1285
                return "Error: No parent found"
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1286
            child = _GetModuleVariable(module, location, direction)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1287
            if child is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1288
                return "Error: No variable found"
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1289
            size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1290
            address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1291
            self.PluginRoot.RemoveProjectVariableByAddress(address)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1292
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1293
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1294
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1295
    def location(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1296
        return tuple(map(int, loc.split(".")))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1297
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1298
    def GetCmdFunction(function, arg_types, opt=0):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1299
        arg_number = len(arg_types)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1300
        def CmdFunction(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1301
            args_toks = line.split('"')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1302
            if len(args_toks) % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1303
                print "Error: Invalid command"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1304
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1305
            args = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1306
            for num, arg in enumerate(args_toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1307
                if num % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1308
                    stripped = arg.strip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1309
                    if stripped:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1310
                        args.extend(stripped.split(" "))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1311
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1312
                    args.append(arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1313
            number = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1314
            extra = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1315
            if opt == 0 and len(args) != arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1316
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1317
            elif len(args) > arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1318
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1319
                extra = " at most"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1320
            elif len(args) < arg_number - opt:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1321
                number = arg_number - opt
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1322
                extra = " at least"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1323
            if number is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1324
                if number == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1325
                    print "Error: No argument%s expected" % extra
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1326
                elif number == 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1327
                    print "Error: 1 argument%s expected" % extra
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1328
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1329
                    print "Error: %d arguments%s expected" % (number, extra)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1330
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1331
            for num, arg in enumerate(args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1332
                try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1333
                    args[num] = arg_types[num](arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1334
                except:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1335
                    print "Error: Invalid value for argument %d" % (num + 1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1336
                    return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1337
            res = getattr(self, function)(*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1338
            if isinstance(res, (StringType, UnicodeType)):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1339
                print res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1340
                return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1341
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1342
                return res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1343
        return CmdFunction
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1344
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1345
    for function, (arg_types, opt) in {"Exit": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1346
                                       "Show": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1347
                                       "Refresh": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1348
                                       "Close": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1349
                                       "Compile": ([], 0),
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1350
                                       "SetProjectProperties": ([str, str, str, str], 0),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1351
                                       "SetOnlineMode": ([int, str], 1),
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1352
                                       "AddBus": ([int, str, str], 1),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1353
                                       "RenameBus": ([int, str], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1354
                                       "ChangeBusIECChannel": ([int, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1355
                                       "RemoveBus": ([int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1356
                                       "AddModule": ([location, int, str, str], 1), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1357
                                       "RenameModule": ([location, str], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1358
                                       "ChangeModuleIECChannel": ([location, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1359
                                       "RemoveModule": ([location, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1360
                                       "StartGroup": ([location, str, str], 1),
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1361
                                       "AddVariable": ([location, location, str, str, str, str, str, str, str], 1),
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1362
                                       "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1363
                                       "RemoveVariable": ([location, location], 0)}.iteritems():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1364
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1365
        setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1366
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1367
    lpcberemiz_cmd = LPCBeremiz_Cmd(projectOpen, buildpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1368
    lpcberemiz_cmd.cmdloop()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1369