canfestival/canfestival.py
changeset 1003 de812e258213
parent 976 0ba3d9cd61e8
child 1061 02f371f3e063
equal deleted inserted replaced
1002:15c05ba95df4 1003:de812e258213
     7 import wx
     7 import wx
     8 
     8 
     9 from nodelist import NodeList
     9 from nodelist import NodeList
    10 from nodemanager import NodeManager
    10 from nodemanager import NodeManager
    11 import config_utils, gen_cfile, eds_utils
    11 import config_utils, gen_cfile, eds_utils
    12 from networkedit import networkedit
       
    13 from objdictedit import objdictedit
       
    14 import canfestival_config as local_canfestival_config
    12 import canfestival_config as local_canfestival_config
    15 from ConfigTreeNode import ConfigTreeNode
    13 from ConfigTreeNode import ConfigTreeNode
    16 from commondialogs import CreateNodeDialog
    14 from commondialogs import CreateNodeDialog
    17 
    15 from subindextable import IECTypeConversion, SizeConversion
       
    16 
       
    17 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    18 from SlaveEditor import SlaveEditor, MasterViewer
    18 from SlaveEditor import SlaveEditor, MasterViewer
    19 from NetworkEditor import NetworkEditor
    19 from NetworkEditor import NetworkEditor
    20 
    20 
    21 from gnosis.xml.pickle import *
    21 from gnosis.xml.pickle import *
    22 from gnosis.xml.pickle.util import setParanoia
    22 from gnosis.xml.pickle.util import setParanoia
    23 setParanoia(0)
    23 setParanoia(0)
    24 
    24 
    25 from util.TranslationCatalogs import AddCatalog
    25 from util.TranslationCatalogs import AddCatalog
    26 AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale"))
    26 AddCatalog(os.path.join(CanFestivalPath, "objdictgen", "locale"))
       
    27 
       
    28 #--------------------------------------------------
       
    29 #              Location Tree Helper
       
    30 #--------------------------------------------------
       
    31 
       
    32 def GetSlaveLocationTree(slave_node, current_location, name):
       
    33     entries = []
       
    34     for index, subindex, size, entry_name in slave_node.GetMapVariableList():
       
    35         subentry_infos = slave_node.GetSubentryInfos(index, subindex)
       
    36         typeinfos = slave_node.GetEntryInfos(subentry_infos["type"])
       
    37         if typeinfos:
       
    38             entries.append({
       
    39                 "name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry_name),
       
    40                 "type": LOCATION_VAR_MEMORY,
       
    41                 "size": size,
       
    42                 "IEC_type": IECTypeConversion.get(typeinfos["name"]),
       
    43                 "var_name": "%s_%4.4x_%2.2x" % ("_".join(name.split()), index, subindex),
       
    44                 "location": "%s%s"%(SizeConversion[size], ".".join(map(str, current_location + 
       
    45                                                                                 (index, subindex)))),
       
    46                 "description": "",
       
    47                 "children": []})
       
    48     return  {"name": name,
       
    49              "type": LOCATION_CONFNODE,
       
    50              "location": ".".join([str(i) for i in current_location]) + ".x",
       
    51              "children": entries
       
    52     }
    27 
    53 
    28 #--------------------------------------------------
    54 #--------------------------------------------------
    29 #                    SLAVE
    55 #                    SLAVE
    30 #--------------------------------------------------
    56 #--------------------------------------------------
    31 
    57 
   137         # Filter IEC_Channel and Name, that have specific behavior
   163         # Filter IEC_Channel and Name, that have specific behavior
   138         if path == "BaseParams.IEC_Channel" and self._View is not None:
   164         if path == "BaseParams.IEC_Channel" and self._View is not None:
   139             self._View.SetBusId(self.GetCurrentLocation())
   165             self._View.SetBusId(self.GetCurrentLocation())
   140         
   166         
   141         return result
   167         return result
   142         
   168     
       
   169     def GetVariableLocationTree(self):
       
   170         current_location = self.GetCurrentLocation()
       
   171         return GetSlaveLocationTree(self.CurrentNode, 
       
   172                                     self.GetCurrentLocation(), 
       
   173                                     self.BaseParams.getName())
       
   174     
   143     def CTNGenerate_C(self, buildpath, locations):
   175     def CTNGenerate_C(self, buildpath, locations):
   144         """
   176         """
   145         Generate C code
   177         Generate C code
   146         @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
   178         @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
   147         @param locations: List of complete variables locations \
   179         @param locations: List of complete variables locations \
   275             refresh_network = True
   307             refresh_network = True
   276             
   308             
   277         if refresh_network and self._View is not None:
   309         if refresh_network and self._View is not None:
   278             wx.CallAfter(self._View.RefreshBufferState)
   310             wx.CallAfter(self._View.RefreshBufferState)
   279         return value, refresh
   311         return value, refresh
   280         
   312     
       
   313     def GetVariableLocationTree(self):
       
   314         current_location = self.GetCurrentLocation()
       
   315         nodeindexes = self.SlaveNodes.keys()
       
   316         nodeindexes.sort()
       
   317         return {"name": self.BaseParams.getName(),
       
   318                  "type": LOCATION_CONFNODE,
       
   319                  "location": self.GetFullIEC_Channel(),
       
   320                  "children": [GetSlaveLocationTree(self.Manager.GetCurrentNodeCopy(),
       
   321                                                    current_location,
       
   322                                                    _("Local entries"))] + 
       
   323                              [GetSlaveLocationTree(self.SlaveNodes[nodeid]["Node"], 
       
   324                                                    current_location + (nodeid,), 
       
   325                                                    self.SlaveNodes[nodeid]["Name"])
       
   326                               for nodeid in nodeindexes]
       
   327         }
       
   328     
   281     _GeneratedMasterView = None
   329     _GeneratedMasterView = None
   282     def _ShowGeneratedMaster(self):
   330     def _ShowGeneratedMaster(self):
   283         self._OpenView("Generated master")
   331         self._OpenView("Generated master")
   284         
   332         
   285     def _OpenView(self, name=None, onlyopened=False):
   333     def _OpenView(self, name=None, onlyopened=False):