# HG changeset patch
# User lbessard
# Date 1186675664 -7200
# Node ID 3a1b0afdaf841e4bfd24b0acb50d640e03bc87ee
# Parent fd138fc7751023b5f0c3a768ce5cbb4d12d9b19c
Adding support for automatically generate function blocks in interface when a block is added
diff -r fd138fc77510 -r 3a1b0afdaf84 LDViewer.py
--- a/LDViewer.py Thu Aug 09 18:06:54 2007 +0200
+++ b/LDViewer.py Thu Aug 09 18:07:44 2007 +0200
@@ -179,9 +179,10 @@
for i, rung in enumerate(self.Rungs):
bbox = rung.GetBoundingBox()
if i < len(self.RungComments):
- pos = self.RungComments[i].GetPosition()
- if pos[1] > bbox.y:
- self.RungComments.insert(i, None)
+ if self.RungComments[i]:
+ pos = self.RungComments[i].GetPosition()
+ if pos[1] > bbox.y:
+ self.RungComments.insert(i, None)
else:
self.RungComments.insert(i, None)
@@ -207,7 +208,8 @@
for connector in element.GetConnectors():
for wire, num in connector.GetWires():
self.Rungs[rungs[0]].SelectElement(wire)
- self.RefreshPosition(element)
+ if self.GetDrawingMode() != FREEDRAWING_MODE:
+ self.RefreshPosition(element)
elif instance["type"] in ["contact", "coil"]:
rungs = []
for link in instance["connectors"]["input"]["links"]:
@@ -221,7 +223,8 @@
self.Rungs[rungs[0]].SelectElement(element)
for wire, num in element.GetConnectors()["input"].GetWires():
self.Rungs[rungs[0]].SelectElement(wire)
- self.RefreshPosition(element)
+ if self.GetDrawingMode() != FREEDRAWING_MODE:
+ self.RefreshPosition(element)
elif instance["type"] == "comment":
element = self.FindElementById(instance["id"])
pos = element.GetPosition()
diff -r fd138fc77510 -r 3a1b0afdaf84 PLCControler.py
--- a/PLCControler.py Thu Aug 09 18:06:54 2007 +0200
+++ b/PLCControler.py Thu Aug 09 18:07:44 2007 +0200
@@ -24,6 +24,7 @@
from minixsv import pyxsval
from xml.dom import minidom
+from types import StringType, UnicodeType
import cPickle
import os,sys,re
from datetime import *
@@ -382,15 +383,15 @@
def GenerateProgram(self, filepath):
if self.Project:
- try:
- program = GenerateCurrentProgram(self.Project)
- programfile = open(filepath, "w")
- programfile.write(program)
- programfile.close()
- self.ProgramFilePath = filepath
- return True
- except:
- pass
+ #try:
+ program = GenerateCurrentProgram(self.Project)
+ programfile = open(filepath, "w")
+ programfile.write(program)
+ programfile.close()
+ self.ProgramFilePath = filepath
+ return True
+ #except:
+ # pass
return False
#-------------------------------------------------------------------------------
@@ -626,7 +627,12 @@
tempvar = plcopen.varListPlain_variable()
tempvar.setName(var["Name"])
var_type = plcopen.dataType()
- var_type.setValue(var["Type"])
+ if GetBlockType(var["Type"]) != None:
+ derived_type = plcopen.derived()
+ derived_type.setName(var["Type"])
+ var_type.setValue(derived_type)
+ else:
+ var_type.setValue(var["Type"])
tempvar.setType(var_type)
if var["Initial Value"] != "":
value = plcopen.value()
@@ -660,7 +666,12 @@
# Extract variables from every varLists
for varlist in configuration.getGlobalVars():
for var in varlist.getVariable():
- tempvar = {"Name":var.getName(),"Class":"Global","Type":var.getType().getValue()}
+ tempvar = {"Name":var.getName(),"Class":"Global"}
+ var_type = var.getType().getValue()
+ if isinstance(var_type, (StringType, UnicodeType)):
+ tempvar["Type"] = var_type
+ else:
+ tempvar["Type"] = var_type.getName()
initial = var.getInitialValue()
if initial:
tempvar["Initial Value"] = initial.getValue()
@@ -702,7 +713,12 @@
# Extract variables from every varLists
for varlist in resource.getGlobalVars():
for var in varlist.getVariable():
- tempvar = {"Name":var.getName(),"Class":"Global","Type":var.getType().getValue()}
+ tempvar = {"Name":var.getName(),"Class":"Global"}
+ var_type = var.getType().getValue()
+ if isinstance(var_type, (StringType, UnicodeType)):
+ tempvar["Type"] = var_type
+ else:
+ tempvar["Type"] = var_type.getName()
initial = var.getInitialValue()
if initial:
tempvar["Initial Value"] = initial.getValue()
@@ -737,7 +753,12 @@
# Extract variables from every varLists
for type, varlist in pou.getVars():
for var in varlist.getVariable():
- tempvar = {"Name":var.getName(),"Class":type,"Type":var.getType().getValue()}
+ tempvar = {"Name":var.getName(),"Class":type}
+ var_type = var.getType().getValue()
+ if isinstance(var_type, (StringType, UnicodeType)):
+ tempvar["Type"] = var_type
+ else:
+ tempvar["Type"] = var_type.getName()
initial = var.getInitialValue()
if initial:
tempvar["Initial Value"] = initial.getValue()
@@ -1418,10 +1439,24 @@
connection.setConnectionParameter(idx, None)
idx += 1
- def AddCurrentElementEditingBlock(self, id):
+ def AddCurrentElementEditingBlock(self, id, blocktype, blockname = None):
block = plcopen.block()
block.setLocalId(id)
- self.GetCurrentElementEditing().addInstance("block", block)
+ block.setTypeName(blocktype)
+ if blockname:
+ block.setInstanceName(blockname)
+ element = self.GetCurrentElementEditing()
+ blocktype_infos = GetBlockType(blocktype)
+ if blocktype_infos["type"] != "function":
+ if self.CurrentElementEditing != None:
+ name = self.ElementsOpened[self.CurrentElementEditing]
+ words = name.split("::")
+ if len(words) == 1:
+ element.addPouVar(blocktype, blockname)
+ elif words[0] in ['T', 'A']:
+ pou = self.Project.getPou(words[1])
+ pou.addPouVar(blocktype, blockname)
+ element.addInstance("block", block)
self.RefreshPouUsingTree()
def SetCurrentElementEditingBlockInfos(self, id, infos):
@@ -1888,7 +1923,21 @@
self.SetConnectionWires(actionBlock.connectionPointIn, value)
def RemoveCurrentElementEditingInstance(self, id):
- self.GetCurrentElementEditing().removeInstance(id)
+ element = self.GetCurrentElementEditing()
+ instance = element.getInstance(id)
+ if isinstance(instance, plcopen.block):
+ blocktype = instance.getTypeName()
+ blocktype_infos = GetBlockType(blocktype)
+ if blocktype_infos["type"] != "function":
+ if self.CurrentElementEditing != None:
+ name = self.ElementsOpened[self.CurrentElementEditing]
+ words = name.split("::")
+ if len(words) == 1:
+ element.removePouVar(blocktype, instance.getInstanceName())
+ elif words[0] in ['T', 'A']:
+ pou = self.Project.getPou(words[1])
+ pou.removePouVar(blocktype, instance.getInstanceName())
+ element.removeInstance(id)
self.RefreshPouUsingTree()
def GetCurrentResourceEditingVariables(self):
diff -r fd138fc77510 -r 3a1b0afdaf84 PLCOpenEditor.py
--- a/PLCOpenEditor.py Thu Aug 09 18:06:54 2007 +0200
+++ b/PLCOpenEditor.py Thu Aug 09 18:07:44 2007 +0200
@@ -412,7 +412,7 @@
else:
self.Controler = controler
- if fileOpen:
+ if self.ModeSolo and fileOpen:
self.Controler.OpenXMLFile(fileOpen)
self.RefreshProjectTree()
@@ -485,6 +485,11 @@
self.EditMenu.FindItemByPosition(5).Enable(False)
self.EditMenu.FindItemByPosition(6).Enable(False)
+ def RefreshEditor(self):
+ selected = self.TabsOpened.GetSelection()
+ if selected != -1:
+ self.TabsOpened.GetPage(selected).RefreshView()
+
def ShowProperties(self):
old_values = self.Controler.GetProjectProperties()
dialog = ProjectDialog(self)
@@ -585,6 +590,10 @@
message = wx.MessageDialog(self, "Can't generate program to file %s!"%filepath, "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
message.Destroy()
+ else:
+ message = wx.MessageDialog(self, "Program was successfully generated!", "Done", wx.OK|wx.ICON_INFORMATION)
+ message.ShowModal()
+ message.Destroy()
else:
message = wx.MessageDialog(self, "%s is not a valid folder!"%os.path.dirname(filepath), "Error", wx.OK|wx.ICON_ERROR)
message.ShowModal()
@@ -2434,7 +2443,7 @@
self.RefreshValues()
self.RefreshButtons()
self.Viewer.RefreshView()
-
+
def OnClassFilter(self, event):
self.Filter = self.FilterChoiceTransfer[self.ClassFilter.GetStringSelection()]
self.RefreshTypeList()
diff -r fd138fc77510 -r 3a1b0afdaf84 SFCViewer.py
--- a/SFCViewer.py Thu Aug 09 18:06:54 2007 +0200
+++ b/SFCViewer.py Thu Aug 09 18:07:44 2007 +0200
@@ -325,6 +325,7 @@
self.Scroll(max(0, xpos - 1), ypos)
elif self.SelectedElement:
self.SelectedElement.Move(-scaling[0], 0)
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -335,6 +336,7 @@
self.Scroll(min(xpos + 1, xmax), ypos)
elif self.SelectedElement:
self.SelectedElement.Move(scaling[0], 0)
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -345,6 +347,7 @@
self.Scroll(xpos, max(0, ypos - 1))
elif self.SelectedElement:
self.SelectedElement.Move(0, -scaling[1])
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -355,6 +358,7 @@
self.Scroll(xpos, min(ypos + 1, ymax))
elif self.SelectedElement:
self.SelectedElement.Move(0, scaling[1])
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
diff -r fd138fc77510 -r 3a1b0afdaf84 Viewer.py
--- a/Viewer.py Thu Aug 09 18:06:54 2007 +0200
+++ b/Viewer.py Thu Aug 09 18:07:44 2007 +0200
@@ -832,7 +832,7 @@
elif self.Mode == MODE_CONTACT:
wx.CallAfter(self.AddNewContact, bbox)
elif self.Mode == MODE_COIL:
- wx.CallAfter(self.AddNewContact, bbox)
+ wx.CallAfter(self.AddNewCoil, bbox)
elif self.Mode == MODE_POWERRAIL:
wx.CallAfter(self.AddNewPowerRail, bbox)
elif self.Mode == MODE_INITIALSTEP:
@@ -948,6 +948,7 @@
self.Scroll(max(0, xpos - 1), ypos)
elif self.SelectedElement:
self.SelectedElement.Move(-scaling[0], 0)
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -958,6 +959,7 @@
self.Scroll(min(xpos + 1, xmax), ypos)
elif self.SelectedElement:
self.SelectedElement.Move(scaling[0], 0)
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -968,6 +970,7 @@
self.Scroll(xpos, max(0, ypos - 1))
elif self.SelectedElement:
self.SelectedElement.Move(0, -scaling[1])
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -978,6 +981,7 @@
self.Scroll(xpos, min(ypos + 1, ymax))
elif self.SelectedElement:
self.SelectedElement.Move(0, scaling[1])
+ self.SelectedElement.RefreshModel()
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -1000,10 +1004,11 @@
block.SetPosition(bbox.x, bbox.y)
block.SetSize(values["width"], values["height"])
self.AddBlock(block)
- self.Controler.AddCurrentElementEditingBlock(id)
+ self.Controler.AddCurrentElementEditingBlock(id, values["type"], values.get("name", None))
self.RefreshBlockModel(block)
self.RefreshBuffer()
self.RefreshScrollBars()
+ self.Parent.RefreshEditor()
self.Refresh()
dialog.Destroy()
@@ -1114,7 +1119,7 @@
coil.SetSize(values["width"], values["height"])
self.AddBlock(coil)
self.Controler.AddCurrentElementEditingCoil(id)
- self.RefreshCoilModel(contact)
+ self.RefreshCoilModel(coil)
self.RefreshBuffer()
self.RefreshScrollBars()
self.Refresh()
@@ -1492,6 +1497,7 @@
self.Controler.RemoveCurrentElementEditingInstance(block.GetId())
for element in elements:
element.RefreshModel()
+ wx.CallAfter(self.Parent.RefreshEditor)
def DeleteVariable(self, variable):
connectors = variable.GetConnectors()
diff -r fd138fc77510 -r 3a1b0afdaf84 examples/example.xml
--- a/examples/example.xml Thu Aug 09 18:06:54 2007 +0200
+++ b/examples/example.xml Thu Aug 09 18:07:44 2007 +0200
@@ -55,6 +55,13 @@
+