etisserant@20: import os, sys
etisserant@20: base_folder = os.path.split(sys.path[0])[0]
etisserant@20: sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
etisserant@20:
lbessard@11: from nodelist import NodeList
lbessard@11: from nodemanager import NodeManager
lbessard@11: import config_utils, gen_cfile
etisserant@12: from networkedit import networkedit
lbessard@11:
etisserant@13: class _NetworkEdit(networkedit):
etisserant@13: " Overload some of CanFestival Network Editor methods "
etisserant@12: def OnCloseFrame(self, event):
etisserant@13: " Do reset _NodeListPlug.View when closed"
etisserant@13: self._onclose()
etisserant@12: event.Skip()
etisserant@12:
etisserant@13: class _NodeListPlug(NodeList):
etisserant@12: XSD = """
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@26:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12: """
etisserant@12:
lbessard@17: def __init__(self):
lbessard@11: manager = NodeManager()
etisserant@23: # TODO change netname when name change
etisserant@23: NodeList.__init__(self, manager, self.BaseParams.getName())
lbessard@17: self.LoadProject(self.PlugPath())
lbessard@11:
etisserant@13: _View = None
etisserant@18: def _OpenView(self, logger):
etisserant@13: if not self._View:
etisserant@13: def _onclose():
etisserant@30: self._View = None
lbessard@25: def _onsave():
lbessard@25: self.GetPlugRoot().SaveProject()
etisserant@23: self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self)
etisserant@23: # TODO redefine BusId when IEC channel change
etisserant@23: self._View.SetBusId(self.GetCurrentLocation())
etisserant@13: self._View._onclose = _onclose
lbessard@25: self._View._onsave = _onsave
etisserant@23: self._View.Show()
etisserant@23:
etisserant@13: PluginMethods = [("NetworkEdit",_OpenView)]
etisserant@13:
etisserant@13: def OnPlugClose(self):
etisserant@13: if self._View:
etisserant@13: self._View.Close()
etisserant@13:
etisserant@13: def PlugTestModified(self):
etisserant@12: return self.HasChanged()
etisserant@12:
lbessard@17: def OnPlugSave(self):
etisserant@32: self.SetRoot(self.PlugPath())
lbessard@11: self.SaveProject()
etisserant@12: return True
etisserant@12:
etisserant@24: def PlugGenerate_C(self, buildpath, locations, logger):
etisserant@12: """
etisserant@15: Generate C code
etisserant@15: @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
etisserant@15: @param locations: List of complete variables locations \
etisserant@22: [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
etisserant@22: "NAME" : name of the variable (generally "__IW0_1_2" style)
etisserant@22: "DIR" : direction "Q","I" or "M"
etisserant@22: "SIZE" : size "X", "B", "W", "D", "L"
etisserant@22: "LOC" : tuple of interger for IEC location (0,1,2,...)
etisserant@22: }, ...]
etisserant@22: @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
etisserant@12: """
etisserant@24: current_location = self.GetCurrentLocation()
etisserant@22: # define a unique name for the generated C file
etisserant@15: prefix = "_".join(map(lambda x:str(x), current_location))
etisserant@15: Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" )
etisserant@22: # Create a new copy of the model with DCF loaded with PDO mappings for desired location
etisserant@26: master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs())
etisserant@15: res = gen_cfile.GenerateFile(Gen_OD_path, master)
etisserant@15: if res :
etisserant@15: raise Exception, res
etisserant@15:
etisserant@24: return [(Gen_OD_path,"")],""
etisserant@12:
etisserant@13: class RootClass:
etisserant@12: XSD = """
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12:
etisserant@12: """
lbessard@11:
etisserant@13: PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
lbessard@17:
etisserant@24: def PlugGenerate_C(self, buildpath, locations, logger):
etisserant@15: return [],""
lbessard@11:
etisserant@15: