# HG changeset patch # User lbessard # Date 1218551118 -7200 # Node ID 520d2416ff4dce5b0cf7b8846d42c9216255b8a1 # Parent 009fc5850157d2aef47480a51dbef293fb1b87c5 Adding support for highlighing compiling errors into PLCOpenEditor diff -r 009fc5850157 -r 520d2416ff4d Beremiz.py --- a/Beremiz.py Wed Jul 30 17:16:57 2008 +0200 +++ b/Beremiz.py Tue Aug 12 16:25:18 2008 +0200 @@ -89,6 +89,7 @@ 'size' : 18, } +MATIEC_ERROR_MODEL = re.compile(".*\.st:([0-9]*)-([0-9]*)..([0-9]*)-([0-9]*): error : (.*)$") # Some helpers to tweak GenBitmapTextButtons # TODO: declare customized classes instead. @@ -330,6 +331,7 @@ self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='', name='LogConsole', parent=parent, pos=wx.Point(0, 0), size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2) + self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick) if wx.VERSION < (2, 8, 0): self.MainSplitter.SplitHorizontally(self.PLCConfig, self.LogConsole, -250) @@ -380,6 +382,20 @@ wnd = self InspectionTool().Show(wnd, True) + def OnLogConsoleDClick(self, event): + wx.CallAfter(self.SearchLineForError) + event.Skip() + + def SearchLineForError(self): + text = self.LogConsole.GetRange(0, self.LogConsole.GetInsertionPoint()) + line = self.LogConsole.GetLineText(len(text.splitlines()) - 1) + result = MATIEC_ERROR_MODEL.match(line) + if result is not None: + first_line, first_column, last_line, last_column, error = result.groups() + infos = self.PluginRoot.ShowError(self.Log, + (int(first_line), int(first_column)), + (int(last_line), int(last_column))) + def OnCloseFrame(self, event): if self.PluginRoot.HasProjectOpened(): if self.PluginRoot.runningPLC is not None: diff -r 009fc5850157 -r 520d2416ff4d plugins/svgui/svgui.py --- a/plugins/svgui/svgui.py Wed Jul 30 17:16:57 2008 +0200 +++ b/plugins/svgui/svgui.py Tue Aug 12 16:25:18 2008 +0200 @@ -191,7 +191,7 @@ shutil.copy(svgfilepath, buildpath) shutil.copy(xmlfilepath, buildpath) - generator = _SVGUICGenerator(self.GetElementsByType(), + generator = _SVGUICGenerator(self, self.GetElementsByType(), os.path.split(self.GetSVGFilePath())[1], os.path.split(self.GetFilePath())[1], self.GetCurrentLocation()) @@ -215,28 +215,44 @@ return [(Gen_C_file, cxx_flags)],libs,True def BlockTypesFactory(self): + + SVGUIBlock_Types = [] + + def GetSVGUIBlockType(type): + for category in SVGUIBlock_Types: + for blocktype in category["list"]: + if blocktype["name"] == type: + return blocktype + setattr(self, "GetSVGUIBlockType", GetSVGUIBlockType) + def generate_svgui_block(generator, block, body, link, order=False): name = block.getinstanceName() block_id = self.GetElementIdFromName(name) if block_id == None: raise ValueError, "No corresponding block found" type = block.gettypeName() - block_infos = GetBlockType(type) + block_infos = GetSVGUIBlockType(type) current_location = ".".join(map(str, self.GetCurrentLocation())) if not generator.ComputedBlocks.get(block, False) and not order: generator.ComputedBlocks[block] = True for num, variable in enumerate(block.inputVariables.getvariable()): connections = variable.connectionPointIn.getconnections() + input_info = (generator.TagName, "block", block.getlocalId(), "input", num) if connections and len(connections) == 1: parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num+1) value = generator.ComputeFBDExpression(body, connections[0]) - generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) + generator.Program += [(generator.CurrentIndent, ()), + (parameter, input_info), + (" := ", ())] + generator.Program += generator.ExtractModifier(variable, value, input_info) + generator.Program += [(";\n", ())] if link: connectionPoint = link.getposition()[-1] for num, variable in enumerate(block.outputVariables.getvariable()): blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY() + output_info = (generator.TagName, "block", block.getlocalId(), "output", num) if block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety(): - return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1) + return [("%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1), output_info)] raise ValueError, "No output variable found" else: return None @@ -245,7 +261,7 @@ block_id = self.GetElementIdFromName(name) if block_id == None: raise ValueError, "No corresponding block found" - block_infos = GetBlockType(type) + block_infos = GetSVGUIBlockType(type) current_location = ".".join(map(str, self.GetCurrentLocation())) variables = [] if block is not None: @@ -263,7 +279,7 @@ variables.append((output_type, None, "%sI%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None)) return variables - return [{"name" : "SVGUI function blocks", "list" : + SVGUIBlock_Types.extend([{"name" : "SVGUI function blocks", "list" : [{"name" : "Container", "type" : "functionBlock", "extensible" : False, "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none")], "outputs" : [], @@ -300,16 +316,18 @@ "comment" : "SVGUI Transform", "generate" : generate_svgui_block, "initialise" : initialise_block}, ]} - ] - + ]) + + return SVGUIBlock_Types class _SVGUICGenerator(SVGUICGenerator): - def __init__(self, elements, svgfile, xmlfile, current_location): + def __init__(self, controler, elements, svgfile, xmlfile, current_location): SVGUICGenerator.__init__(self, elements, svgfile, xmlfile) self.CurrentLocation = current_location + self.Controler = controler def GenerateProgramHeadersPublicVars(self): text = """ void OnPlcOutEvent(wxEvent& event); @@ -330,7 +348,7 @@ current_location = "_".join(map(str, self.CurrentLocation)) #Declaration des variables for element in self.Elements: - block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)]) + block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)]) block_id = element.getid() for i, input in enumerate(block_infos["inputs"]): element_c_type = CTYPECONVERSION[input[1]] @@ -658,7 +676,7 @@ for element in self.Elements: element_type = GetElementType(element) texts = {"location" : current_location, "id" : element.getid()} - block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)]) + block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)]) if len(block_infos["outputs"]) > 0: text += """ if (COMPARE_AND_SWAP_VAL(&in_state_%(id)d, CHANGED, PLC_BUSY) == CHANGED) { """%texts @@ -678,7 +696,7 @@ for element in self.Elements: element_type = GetElementType(element) texts = {"location" : current_location, "id" : element.getid()} - block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)]) + block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)]) text += """ if ((new_state = COMPARE_AND_SWAP_VAL(&out_state_%(id)d, UNCHANGED, PLC_BUSY)) == UNCHANGED || (new_state = COMPARE_AND_SWAP_VAL(&out_state_%(id)d, CHANGED, PLC_BUSY)) == CHANGED) {