etisserant@12: import os
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@12:
etisserant@12:
etisserant@12:
etisserant@12: """
etisserant@12:
lbessard@17: def __init__(self):
lbessard@11: manager = NodeManager()
lbessard@11: NodeList.__init__(self, manager)
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@13: self.View = None
etisserant@13: self._View = _NetworkEdit()
etisserant@13: self._View._onclose = _onclose
etisserant@13: return self.View
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):
lbessard@11: self.SaveProject()
etisserant@12: return True
etisserant@12:
etisserant@18: def PlugGenerate_C(self, buildpath, current_location, 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@15: [(IEC_loc, IEC_Direction IEC_Type, Name)]\
etisserant@15: ex: [((0,0,4,5),'I','X','__IX_0_0_4_5'),...]
etisserant@12: """
etisserant@15: prefix = "_".join(map(lambda x:str(x), current_location))
etisserant@15: Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" )
etisserant@15: master = config_utils.GenerateConciseDCF(locations, current_location, self)
etisserant@15: res = gen_cfile.GenerateFile(Gen_OD_path, master)
etisserant@15: if res :
etisserant@15: raise Exception, res
etisserant@15:
etisserant@15: return [(Gen_OD_path,CanFestival_OD_CFLAGS)],""
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@15: def PlugGenerate_C(self, buildpath, current_location, locations):
lbessard@11: """
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@15: [(IEC_loc, IEC_Direction IEC_Type, Name)]\
etisserant@15: ex: [((0,0,4,5),'I','X','__IX_0_0_4_5'),...]
lbessard@11: """
etisserant@15: prefix = "_".join(map(lambda x:str(x), current_location))
etisserant@15: Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" )
lbessard@11: master = config_utils.GenerateConciseDCF(locations, self)
etisserant@15: res = gen_cfile.GenerateFile(Gen_OD_path, master)
lbessard@11: if not res:
etisserant@12: s = str(self.BaseParams.BusId)+"_IN(){}\n"
etisserant@13: s += "CanOpen(str(\""+self.CanFestivalNode.CAN_Device+"\")"
lbessard@11: f = file(filepath, 'a')
lbessard@11: f.write(s)
lbessard@11: else:
lbessard@11: pass # error
etisserant@15:
etisserant@15: return [],""
lbessard@11:
etisserant@15: