LPCBeremiz.py
author ed
Sun, 06 Dec 2009 15:58:33 +0100
changeset 457 e01434cfcb9d
parent 445 1b1dc8ad2498
child 472 80eb3bde98e3
permissions -rwxr-xr-x
Fixes
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 -*-
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     3
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     4
__version__ = "$Revision$"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     5
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     6
import os, sys, getopt, wx, tempfile
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     7
from types import TupleType, StringType, UnicodeType
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     8
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     9
CWD = os.path.split(os.path.realpath(__file__))[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    10
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    11
def Bpath(*args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    12
    return os.path.join(CWD,*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    13
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    14
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    15
    def usage():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    16
        print "\nUsage of LPCBeremiz.py :"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    17
        print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    18
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    19
    try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    20
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    21
    except getopt.GetoptError:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    22
        # print help information and exit:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    23
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    24
        sys.exit(2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    25
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    26
    for o, a in opts:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    27
        if o in ("-h", "--help"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    28
            usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    29
            sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    30
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    31
    if len(args) > 2:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    32
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    33
        sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    34
    elif len(args) == 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    35
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    36
        buildpath = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    37
    elif len(args) == 2:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    38
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    39
        buildpath = args[1]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    40
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    41
        projectOpen = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    42
        buildpath = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    43
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    44
class PseudoLocale:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    45
    LocaleDirs = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    46
    Domains = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    47
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    48
    def AddCatalogLookupPathPrefix(self, localedir):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    49
        self.LocaleDirs.append(localedir)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    50
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    51
    def AddCatalog(self, domain):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    52
        self.Domains.append(domain)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    53
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    54
# Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    55
import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    56
import __builtin__
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    57
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    58
# Define locale for wx
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    59
__builtin__.__dict__['loc'] = PseudoLocale()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    60
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    61
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    62
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    63
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    64
from Beremiz import *
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    65
from plugger import PluginsRoot, PlugTemplate, opjimg
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    66
from plcopen.structures import LOCATIONDATATYPES
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    67
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    68
                         LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    69
from PLCOpenEditor import IDEFrame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    70
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    71
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    72
#                              LPCModule Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    73
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    74
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    75
def _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    76
    children = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    77
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    78
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    79
            children.extend(child["children"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    80
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    81
            children.append(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    82
    return children
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    83
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    84
def _GetLastModuleGroup(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    85
    group = module
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    86
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    87
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    88
            group = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    89
    return group["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    90
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    91
def _GetModuleBySomething(module, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    92
    for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    93
        if child.get(something) == toks[0]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    94
            if len(toks) > 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    95
                return _GetModuleBySomething(child, something, toks[1:])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    96
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    97
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    98
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    99
def _GetModuleVariable(module, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   100
    for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   101
        if child["location"] == location:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   102
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   103
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   104
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   105
def _RemoveModuleChild(module, child):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   106
    if child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   107
        module["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   108
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   109
        for group in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   110
            if group["type"] == LOCATION_GROUP and child in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   111
                group["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   112
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   113
LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   114
                  "Q": LOCATION_VAR_OUTPUT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   115
                  "M": LOCATION_VAR_MEMORY}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   116
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   117
LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   118
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   119
LOCATION_SIZES = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   120
for size, types in LOCATIONDATATYPES.iteritems():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   121
    for type in types:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   122
        LOCATION_SIZES[type] = size
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   123
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   124
BUS_TEXT = """/* Code generated by LPCBus plugin */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   125
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   126
/* LPCBus plugin includes */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   127
#include "app_glue.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   128
#ifdef _WINDOWS_H
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   129
  #include "iec_types.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   130
#else
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   131
  #include "iec_std_lib.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   132
#endif
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   133
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   134
%(declare_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   135
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   136
/* LPCBus plugin user variables definition */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   137
%(var_decl)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   138
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   139
/* LPCBus plugin functions */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   140
int __init_%(location_str)s(int argc,char **argv)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   141
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   142
  return 0;
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   143
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   144
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   145
void __cleanup_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   146
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   147
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   148
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   149
void __retrieve_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   150
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   151
  %(retrieve_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   152
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   153
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   154
void __publish_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   155
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   156
  %(publish_code)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   157
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   158
"""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   159
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   160
class LPCBus(object):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   161
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   162
    def __init__(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   163
        self.VariableLocationTree = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   164
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   165
        self.Icon = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   166
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   167
    def __getitem__(self, key):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   168
        if key == "children":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   169
            return self.VariableLocationTree
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   170
        raise KeyError, "Only 'children' key is available"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   171
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   172
    def SetIcon(self, icon):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   173
        self.Icon = icon
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   174
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   175
    def _GetChildBySomething(self, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   176
        return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   177
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   178
    def GetBaseTypes(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   179
        return self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   180
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   181
    def GetSizeOfType(self, type):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   182
        return LOCATION_SIZES[self.GetPlugRoot().GetBaseType(type)]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   183
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   184
    def _GetVariableLocationTree(self, current_location, infos):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   185
        if infos["type"] == LOCATION_MODULE:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   186
            location = current_location + (infos["IEC_Channel"],)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   187
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   188
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   189
                    "location": ".".join(map(str, location + ("x",))), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   190
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   191
                    "children": [self._GetVariableLocationTree(location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   192
        elif infos["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   193
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   194
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   195
                    "location": "", 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   196
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   197
                    "children": [self._GetVariableLocationTree(current_location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   198
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   199
            size = self.GetSizeOfType(infos["IEC_type"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   200
            location = "%" + LOCATION_DIRS[infos["type"]] + size + ".".join(map(str, current_location + infos["location"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   201
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   202
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   203
                    "size": size,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   204
                    "IEC_type": infos["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   205
                    "location": location,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   206
                    "description": infos["description"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   207
                    "children": []}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   208
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   209
    def GetVariableLocationTree(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   210
        return {"name": self.BaseParams.getName(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   211
                "type": LOCATION_PLUGIN,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   212
                "location": self.GetFullIEC_Channel(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   213
                "icon": self.Icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   214
                "children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   215
                             for child in self.VariableLocationTree]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   216
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   217
    def PlugTestModified(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   218
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   219
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   220
    def PlugMakeDir(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   221
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   222
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   223
    def PlugRequestSave(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   224
        return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   225
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   226
    def ResetUsedLocations(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   227
        self.UsedLocations = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   228
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   229
    def _AddUsedLocation(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   230
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   231
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   232
            parent[num] = {"used": False, "children": {}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   233
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   234
            self._AddUsedLocation(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   235
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   236
            parent[num]["used"] = True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   237
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   238
    def AddUsedLocation(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   239
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   240
            self._AddUsedLocation(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   241
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   242
    def _CheckLocationConflicts(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
            return False
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
            if parent[num]["used"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   248
                return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   249
            return self._CheckLocationConflicts(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   250
        elif len(parent[num]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   251
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   252
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   253
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   254
    def CheckLocationConflicts(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   255
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   256
            return self._CheckLocationConflicts(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   257
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   258
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   259
    def PlugGenerate_C(self, buildpath, locations):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   260
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   261
        Generate C code
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   262
        @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
   263
        @param locations: List of complete variables locations \
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   264
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   265
            "NAME" : name of the variable (generally "__IW0_1_2" style)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   266
            "DIR" : direction "Q","I" or "M"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   267
            "SIZE" : size "X", "B", "W", "D", "L"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   268
            "LOC" : tuple of interger for IEC location (0,1,2,...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   269
            }, ...]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   270
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   271
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   272
        current_location = self.GetCurrentLocation()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   273
        # define a unique name for the generated C file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   274
        location_str = "_".join(map(str, current_location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   275
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   276
        code_str = {"location_str": location_str,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   277
                    "var_decl": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   278
                    "declare_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   279
                    "retrieve_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   280
                    "publish_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   281
                   }
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   282
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   283
        # Adding variables
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   284
        vars = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   285
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   286
        for location in locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   287
            loc = location["LOC"][len(current_location):]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   288
            group = next = self
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   289
            i = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   290
            while next is not None and i < len(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   291
                next = self._GetChildBySomething("IEC_Channel", loc[:i + 1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   292
                if next is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   293
                    i += 1
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   294
                    group = next
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   295
            var_loc = loc[i:]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   296
            for variable in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   297
                if variable["location"] == var_loc:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   298
                    if location["DIR"] != LOCATION_DIRS[variable["type"]]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   299
                        raise Exception, "Direction conflict in variable definition"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   300
                    if location["IEC_TYPE"] != variable["IEC_type"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   301
                        raise Exception, "Type conflict in variable definition"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   302
                    if location["DIR"] == "Q":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   303
                        if self.CheckLocationConflicts(location["LOC"]):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   304
                            raise Exception, "BYTE and BIT from the same BYTE can't be used together"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   305
                        self.AddUsedLocation(location["LOC"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   306
                    vars.append({"location": location["NAME"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   307
                                 "Type": variable["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   308
                                 "Declare": variable["declare"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   309
                                 "Retrieve": variable["retrieve"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   310
                                 "Publish": variable["publish"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   311
                                })
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   312
                    break
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   313
        base_types = self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   314
        for var in vars:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   315
            prefix = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   316
            if var["Type"] in base_types:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   317
                prefix = "IEC_"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   318
            code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   319
            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
   320
            if var["Declare"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   321
                code_str["declare_code"] += var["Declare"] + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   322
            if var["Retrieve"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   323
                code_str["retrieve_code"] += var["Retrieve"] % ("*" + var["location"]) + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   324
            if var["Publish"] != "":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   325
                code_str["publish_code"] += var["Publish"] % ("*" + var["location"]) + "\n"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   326
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   327
        Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   328
        module = open(Gen_Module_path,'w')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   329
        module.write(BUS_TEXT % code_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   330
        module.close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   331
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   332
        matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   333
        return [(Gen_Module_path, matiec_flags)],"",True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   334
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   335
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   336
#                              LPCPluginsRoot Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   337
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   338
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   339
def mycopytree(src, dst):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   340
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   341
    Copy content of a directory to an other, omit hidden files
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   342
    @param src: source directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   343
    @param dst: destination directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   344
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   345
    for i in os.listdir(src):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   346
        if not i.startswith('.'):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   347
            srcpath = os.path.join(src,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   348
            dstpath = os.path.join(dst,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   349
            if os.path.isdir(srcpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   350
                os.makedirs(dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   351
                mycopytree(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   352
            elif os.path.isfile(srcpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   353
                shutil.copy2(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   354
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   355
class LPCPluginsRoot(PluginsRoot):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   356
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   357
    PlugChildsTypes = [("LPCBus", LPCBus, "LPC bus")]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   358
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   359
    PluginMethods = [
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   360
        {"bitmap" : opjimg("Build"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   361
         "name" : _("Build"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   362
         "tooltip" : _("Build project into build folder"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   363
         "method" : "_build"},
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   364
        {"bitmap" : opjimg("Clean"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   365
         "name" : _("Clean"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   366
         "enabled" : False,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   367
         "tooltip" : _("Clean project build folder"),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   368
         "method" : "_Clean"},
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   369
    ]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   370
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   371
    def GetProjectName(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   372
        return self.Project.getname()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   373
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   374
    def GetDefaultTarget(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   375
        target = self.Classes["BeremizRoot_TargetType"]()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   376
        target_value = self.Classes["TargetType_Makefile"]()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   377
        target_value.setBuildPath(self.BuildPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   378
        target.setcontent({"name": "Makefile", "value": target_value})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   379
        return target
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   380
     
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   381
    def SetProjectName(self, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   382
        return self.Project.setname(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   383
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
   384
    # 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
   385
    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
   386
        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
   387
        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
   388
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
   389
    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
   390
        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
   391
        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
   392
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
   393
    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
   394
        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
   395
        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
   396
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   397
    def LoadProject(self, ProjectPath, BuildPath=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   398
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   399
        Load a project XML file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   400
        @param ProjectPath: path of the project xml file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   401
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   402
        # Load PLCOpen file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   403
        result = self.OpenXMLFile(ProjectPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   404
        if result:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   405
            return result
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   406
        # Change XSD into class members
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   407
        self._AddParamsMembers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   408
        self.PluggedChilds = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   409
        # Keep track of the root plugin (i.e. project path)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   410
        self.ProjectPath = ProjectPath
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   411
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   412
        self.BuildPath = tempfile.mkdtemp()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   413
        if BuildPath is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   414
            mycopytree(BuildPath, self.BuildPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   415
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   416
        self.RefreshPluginsBlockLists()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   417
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   418
        if os.path.exists(self._getBuildPath()):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   419
            self.EnableMethod("_Clean", True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   420
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   421
    def SaveProject(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   422
        self.SaveXMLFile(self.ProjectPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   423
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   424
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   425
#                              LPCBeremiz Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   426
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   427
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   428
class LPCBeremiz(Beremiz):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   429
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   430
    def _init_coll_FileMenu_Items(self, parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   431
        AppendMenu(parent, help='', id=wx.ID_SAVE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   432
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   433
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   434
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   435
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   436
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   437
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   438
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   439
              kind=wx.ITEM_NORMAL, text=_(u'Preview'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   440
        AppendMenu(parent, help='', id=wx.ID_PRINT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   441
              kind=wx.ITEM_NORMAL, text=_(u'Print'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   442
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   443
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   444
              kind=wx.ITEM_NORMAL, text=_(u'Properties'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   445
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   446
        AppendMenu(parent, help='', id=wx.ID_EXIT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   447
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   448
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   449
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   450
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   451
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   452
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   453
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   454
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   455
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   456
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   457
    def _init_ctrls(self, prnt):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   458
        IDEFrame._init_ctrls(self, prnt)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   459
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   460
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   461
        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
   462
        self.SetAcceleratorTable(accel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   463
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   464
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   465
              name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   466
              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
   467
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   468
        self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   469
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   470
        self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   471
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   472
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   473
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   474
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   475
        self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   476
        self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   477
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   478
        self._init_beremiz_sizers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   479
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   480
    def OnCloseFrame(self, event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   481
        global frame, lpcberemiz_cmd
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   482
        frame = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   483
        self.PluginRoot.ResetAppFrame(lpcberemiz_cmd.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   484
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   485
        self.KillLocalRuntime()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   486
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   487
        event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   488
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   489
    def RefreshFileMenu(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   490
        if self.PluginRoot is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   491
            selected = self.TabsOpened.GetSelection()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   492
            if selected >= 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   493
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   494
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   495
                graphic_viewer = False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   496
            if self.TabsOpened.GetPageCount() > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   497
                self.FileMenu.Enable(wx.ID_CLOSE, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   498
                if graphic_viewer:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   499
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   500
                    self.FileMenu.Enable(wx.ID_PRINT, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   501
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   502
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   503
                    self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   504
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   505
                self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   506
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   507
                self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   508
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   509
            self.FileMenu.Enable(wx.ID_SAVE, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   510
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   511
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   512
            self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   513
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   514
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   515
            self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   516
            self.FileMenu.Enable(wx.ID_SAVE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   517
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   518
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   519
    def RefreshPLCParams(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   520
        self.Freeze()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   521
        self.ClearSizer(self.PLCParamsSizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   522
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   523
        if self.PluginRoot is not None:    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   524
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   525
            if self.PluginRoot.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   526
                bkgdclr = CHANGED_TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   527
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   528
                bkgdclr = TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   529
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   530
            if self.PluginRoot not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   531
                self.PluginInfos[self.PluginRoot] = {"right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   532
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   533
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   534
            plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   535
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   536
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   537
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   538
            plcwindow.SetSizer(plcwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   539
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   540
            st = wx.StaticText(plcwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   541
            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
   542
            st.SetLabel(self.PluginRoot.GetProjectName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   543
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   544
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   545
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   546
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   547
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   548
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   549
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   550
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   551
            msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   552
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   553
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   554
        self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   555
        self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   556
        self.Thaw()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   557
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   558
    def GenerateTreeBranch(self, plugin):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   559
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   560
        if plugin.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   561
            bkgdclr=CHANGED_WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   562
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   563
            bkgdclr=WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   564
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   565
        leftwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   566
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   567
        if plugin not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   568
            self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   569
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   570
        self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   571
        plugin_infos = plugin.GetVariableLocationTree()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   572
        plugin_locations = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   573
        if len(self.PluginInfos[plugin]["children"]) == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   574
            plugin_locations = plugin_infos["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   575
            if not self.PluginInfos[plugin].has_key("locations_infos"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   576
                self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   577
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   578
            self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   579
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   580
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   581
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   582
        leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   583
        leftwindow.SetSizer(leftwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   584
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   585
        st = wx.StaticText(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   586
        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
   587
        st.SetLabel(plugin.GetFullIEC_Channel())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   588
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   589
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   590
        expandbutton_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   591
        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
   592
              name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   593
              size=wx.Size(13, 13), style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   594
        expandbutton.labelDelta = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   595
        expandbutton.SetBezelWidth(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   596
        expandbutton.SetUseFocusIndicator(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   597
        expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   598
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   599
        if len(self.PluginInfos[plugin]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   600
            expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   601
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   602
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   603
                    self.ExpandPlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   604
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   605
                    self.CollapsePlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   606
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   607
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   608
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   609
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   610
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   611
        elif len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   612
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   613
            expandbutton.SetToggle(locations_infos["root"]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   614
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   615
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   616
                    self.ExpandLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   617
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   618
                    self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   619
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   620
                locations_infos["root"]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   621
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   622
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   623
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   624
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   625
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   626
            expandbutton.Enable(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   627
        leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   628
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   629
        sb = wx.StaticBitmap(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   630
        icon = plugin_infos.get("icon", None)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   631
        if icon is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   632
            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
   633
        sb.SetBitmap(wx.Bitmap(icon))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   634
        leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   635
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   636
        st_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   637
        st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   638
        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
   639
        st.SetLabel(plugin.MandatoryParams[1].getName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   640
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   641
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   642
        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   643
        rightwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   644
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   645
        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   646
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   647
        self.PluginInfos[plugin]["left"] = leftwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   648
        self.PluginInfos[plugin]["right"] = rightwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   649
        for child in self.PluginInfos[plugin]["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   650
            self.GenerateTreeBranch(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   651
            if not self.PluginInfos[child]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   652
                self.CollapsePlugin(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   653
        if len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   654
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   655
            for location in plugin_locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   656
                locations_infos["root"]["children"].append("root.%s" % location["name"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   657
                self.GenerateLocationTreeBranch(locations_infos, "root", location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   658
            if not locations_infos["root"]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   659
                self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   660
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   661
frame = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   662
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   663
def BeremizStartProc(plugin_root):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   664
    global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   665
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   666
    app = wx.PySimpleApp()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   667
    app.SetAppName('beremiz')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   668
    wx.InitAllImageHandlers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   669
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   670
    # Get the english language
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   671
    langid = wx.LANGUAGE_ENGLISH
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   672
    # Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   673
    import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   674
    import __builtin__
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   675
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   676
    # Define locale for wx
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   677
    loc = wx.Locale(langid)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   678
    for localedir in PseudoLocale.LocaleDirs:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   679
        loc.AddCatalogLookupPathPrefix(localedir)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   680
    for domain in PseudoLocale.Domains:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   681
        loc.AddCatalog(domain)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   682
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   683
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   684
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   685
    # Install a exception handle for bug reports
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   686
    AddExceptHook(os.getcwd(),__version__)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   687
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   688
    frame = LPCBeremiz(None, plugin_root=plugin_root, debug=False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   689
    plugin_root.SetAppFrame(frame, frame.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   690
    frame.Show()
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   691
    frame.Raise()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   692
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   693
    app.MainLoop()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   694
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   695
    frame = None
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   696
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   697
class StdoutPseudoFile:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   698
    """ Base class for file like objects to facilitate StdOut for the Shell."""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   699
    def write(self, s, style = None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   700
        if s != '':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   701
            print s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   702
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   703
    def write_warning(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   704
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   705
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   706
    def write_error(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   707
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   708
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   709
    def flush(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   710
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   711
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   712
    def isatty(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   713
        return false
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   714
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   715
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   716
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   717
    from threading import Thread, Timer
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   718
    import cmd
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   719
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   720
    class LPCBeremiz_Cmd(cmd.Cmd):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   721
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   722
        prompt = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   723
        Log = StdoutPseudoFile()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   724
        RefreshTimer = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   725
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   726
        def __init__(self, projectOpen, buildpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   727
            cmd.Cmd.__init__(self)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   728
            self.PluginRoot = LPCPluginsRoot(None, self.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   729
            if projectOpen is not None and os.path.isfile(projectOpen):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   730
                result = self.PluginRoot.LoadProject(projectOpen, buildpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   731
                if result:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   732
                    print "Error: Invalid project directory", result
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   733
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   734
                print "Error: No such file or directory"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   735
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   736
        def RestartTimer(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   737
            if self.RefreshTimer is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   738
                self.RefreshTimer.cancel()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   739
            self.RefreshTimer = Timer(0.1, self.Refresh)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   740
            self.RefreshTimer.start()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   741
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   742
        def Exit(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   743
            self.Close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   744
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   745
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   746
        def do_EOF(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   747
            return self.Exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   748
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   749
        def Show(self):
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   750
            global frame
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   751
            if frame is None:
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   752
                beremiz_thread=Thread(target=BeremizStartProc, args=[self.PluginRoot])
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
   753
                beremiz_thread.start()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   754
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   755
        def Refresh(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   756
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   757
            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
   758
                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
   759
                wx.CallAfter(frame.RefreshEditor)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   760
                wx.CallAfter(frame.RefreshAll)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   761
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   762
        def Close(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   763
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   764
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   765
            self.PluginRoot.ResetAppFrame(self.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   766
            if frame is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   767
                wx.CallAfter(frame.Close)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   768
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   769
        def Compile(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   770
            if wx.GetApp() is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   771
                self.PluginRoot._build()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   772
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   773
                wx.CallAfter(self.PluginRoot._build)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   774
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   775
        def SetProjectName(self, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   776
            self.PluginRoot.SetProjectName(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   777
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   778
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   779
        def AddBus(self, iec_channel, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   780
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   781
                if child.BaseParams.getName() == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   782
                    return "Error: A bus named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   783
                elif child.BaseParams.getIEC_Channel() == iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   784
                    return "Error: A bus with IEC_channel %d already exists" % iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   785
            bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   786
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   787
                return "Error: Unable to create bus"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   788
            bus.SetIcon(icon)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   789
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   790
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   791
        def RenameBus(self, iec_channel, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   792
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   793
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   794
                return "Error: No bus found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   795
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   796
                if child != bus and child.BaseParams.getName() == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   797
                    return "Error: A bus named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   798
            bus.BaseParams.setName(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   799
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   800
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   801
        def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   802
            bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   803
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   804
                return "Error: No bus found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   805
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   806
                if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   807
                    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
   808
            self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), str(new_iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   809
            bus.BaseParams.setIEC_Channel(new_iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   810
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   811
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   812
        def RemoveBus(self, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   813
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   814
            if bus is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   815
                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
   816
            self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   817
            self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   818
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   819
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   820
        def AddModule(self, parent, iec_channel, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   821
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   822
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   823
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   824
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   825
                if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   826
                    return "Error: A module named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   827
                elif child["IEC_Channel"] == iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   828
                    return "Error: A module with IEC_channel %d already exists" % iec_channel 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   829
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   830
                                                "type": LOCATION_MODULE, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   831
                                                "IEC_Channel": iec_channel, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   832
                                                "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   833
                                                "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   834
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   835
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   836
        def RenameModule(self, iec_location, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   837
            module = self.PluginRoot.GetChildByIECLocation(iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   838
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   839
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   840
            parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   841
            if parent is self.PluginRoot:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   842
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   843
            if module["name"] != name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   844
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   845
                    if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   846
                        return "Error: A module named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   847
                module["name"] = name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   848
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   849
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   850
        def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   851
            module = self.PluginRoot.GetChildByIECLocation(old_iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   852
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   853
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   854
            parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   855
            if parent is self.PluginRoot:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   856
                return "Error: No module found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   857
            if module["IEC_Channel"] != new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   858
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   859
                    if child["IEC_Channel"] == new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   860
                        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
   861
            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
   862
            module["IEC_Channel"] = new_iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   863
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   864
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   865
        def RemoveModule(self, parent, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   866
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   867
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   868
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   869
            child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   870
            if child is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   871
                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
   872
            self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   873
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   874
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   875
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   876
        def StartGroup(self, parent, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   877
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   878
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   879
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   880
            for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   881
                if child["type"] == LOCATION_GROUP and child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   882
                    return "Error: A group named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   883
            module["children"].append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   884
                                      "type": LOCATION_GROUP, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   885
                                      "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   886
                                      "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   887
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   888
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   889
        def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   890
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   891
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   892
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   893
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   894
                if child["name"] == name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   895
                    return "Error: A variable named %s already exists" % name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   896
                if child["location"] == location:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   897
                    return "Error: A variable with location %s already exists" % ".".join(map(str, location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   898
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   899
                                                "location": location, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   900
                                                "type": LOCATION_TYPES[direction], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   901
                                                "IEC_type": type, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   902
                                                "description": description, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   903
                                                "declare": dcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   904
                                                "retrieve": rcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   905
                                                "publish": pcode})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   906
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   907
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   908
        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
   909
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   910
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   911
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   912
            variable = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   913
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   914
                if child["location"] == location:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   915
                    variable = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   916
                elif child["name"] == new_name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   917
                    return "Error: A variable named %s already exists" % new_name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   918
            if variable is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   919
                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
   920
            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
   921
                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
   922
                variable["name"] = new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   923
            variable["type"] = LOCATION_TYPES[new_direction]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   924
            variable["IEC_type"] = new_type
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   925
            variable["declare"] = new_dcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   926
            variable["retrieve"] = new_rcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   927
            variable["publish"] = new_pcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   928
            if new_description is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   929
                variable["description"] = new_description
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   930
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   931
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   932
        def RemoveVariable(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   933
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   934
            if module is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   935
                return "Error: No parent found"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   936
            child = _GetModuleVariable(module, location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   937
            if child is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   938
                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
   939
            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
   940
            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
   941
            self.PluginRoot.RemoveProjectVariableByAddress(address)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   942
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   943
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   944
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   945
    def location(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   946
        return tuple(map(int, loc.split(".")))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   947
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   948
    def GetCmdFunction(function, arg_types, opt=0):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   949
        arg_number = len(arg_types)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   950
        def CmdFunction(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   951
            args_toks = line.split('"')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   952
            if len(args_toks) % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   953
                print "Error: Invalid command"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   954
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   955
            args = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   956
            for num, arg in enumerate(args_toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   957
                if num % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   958
                    stripped = arg.strip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   959
                    if stripped:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   960
                        args.extend(stripped.split(" "))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   961
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   962
                    args.append(arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   963
            number = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   964
            extra = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   965
            if opt == 0 and len(args) != arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   966
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   967
            elif len(args) > arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   968
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   969
                extra = " at most"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   970
            elif len(args) < arg_number - opt:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   971
                number = arg_number - opt
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   972
                extra = " at least"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   973
            if number is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   974
                if number == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   975
                    print "Error: No argument%s expected" % extra
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   976
                elif number == 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   977
                    print "Error: 1 argument%s expected" % extra
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   978
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   979
                    print "Error: %d arguments%s expected" % (number, extra)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   980
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   981
            for num, arg in enumerate(args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   982
                try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   983
                    args[num] = arg_types[num](arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   984
                except:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   985
                    print "Error: Invalid value for argument %d" % (num + 1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   986
                    return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   987
            res = getattr(self, function)(*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   988
            if isinstance(res, (StringType, UnicodeType)):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   989
                print res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   990
                return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   991
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   992
                return res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   993
        return CmdFunction
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   994
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   995
    for function, (arg_types, opt) in {"Exit": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   996
                                       "Show": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   997
                                       "Refresh": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   998
                                       "Close": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   999
                                       "Compile": ([], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1000
                                       "SetProjectName": ([str], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1001
                                       "AddBus": ([int, str, str], 1),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1002
                                       "RenameBus": ([int, str], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1003
                                       "ChangeBusIECChannel": ([int, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1004
                                       "RemoveBus": ([int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1005
                                       "AddModule": ([location, int, str, str], 1), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1006
                                       "RenameModule": ([location, str], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1007
                                       "ChangeModuleIECChannel": ([location, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1008
                                       "RemoveModule": ([location, int], 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1009
                                       "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
  1010
                                       "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
  1011
                                       "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1012
                                       "RemoveVariable": ([location, location], 0)}.iteritems():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1013
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1014
        setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1015
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1016
    lpcberemiz_cmd = LPCBeremiz_Cmd(projectOpen, buildpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1017
    lpcberemiz_cmd.cmdloop()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1018