21 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import re |
25 import re |
|
26 from types import TupleType |
26 |
27 |
27 import wx |
28 import wx |
28 import wx.grid |
29 import wx.grid |
29 import wx.lib.buttons |
30 import wx.lib.buttons |
30 |
31 |
31 from plcopen.structures import IEC_KEYWORDS, TestIdentifier |
32 from plcopen.structures import IEC_KEYWORDS, TestIdentifier |
32 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD |
33 from graphics.GraphicCommons import REFRESH_HIGHLIGHT_PERIOD |
33 from controls import CustomEditableListBox, CustomGrid, CustomTable |
34 from controls import CustomEditableListBox, CustomGrid, CustomTable |
|
35 from dialogs import ArrayTypeDialog |
34 from EditorPanel import EditorPanel |
36 from EditorPanel import EditorPanel |
35 from util.BitmapLibrary import GetBitmap |
37 from util.BitmapLibrary import GetBitmap |
36 |
38 |
37 #------------------------------------------------------------------------------- |
39 #------------------------------------------------------------------------------- |
38 # Helpers |
40 # Helpers |
68 |
70 |
69 def GetValue(self, row, col): |
71 def GetValue(self, row, col): |
70 if row < self.GetNumberRows(): |
72 if row < self.GetNumberRows(): |
71 if col == 0: |
73 if col == 0: |
72 return row + 1 |
74 return row + 1 |
73 name = str(self.data[row].get(self.GetColLabelValue(col, False), "")) |
75 colname = self.GetColLabelValue(col, False) |
74 return name |
76 value = self.data[row].get(colname, "") |
|
77 if colname == "Type" and isinstance(value, TupleType): |
|
78 if value[0] == "array": |
|
79 return "ARRAY [%s] OF %s" % (",".join(map(lambda x : "..".join(x), value[2])), value[1]) |
|
80 return str(value) |
75 |
81 |
76 def SetValue(self, row, col, value): |
82 def SetValue(self, row, col, value): |
77 if col < len(self.colnames): |
83 if col < len(self.colnames): |
78 colname = self.GetColLabelValue(col, False) |
84 colname = self.GetColLabelValue(col, False) |
79 if colname == "Name": |
85 if colname == "Name": |
607 |
613 |
608 def OnStructureElementsGridEditorShown(self, event): |
614 def OnStructureElementsGridEditorShown(self, event): |
609 row, col = event.GetRow(), event.GetCol() |
615 row, col = event.GetRow(), event.GetCol() |
610 if self.StructureElementsTable.GetColLabelValue(col) == "Type": |
616 if self.StructureElementsTable.GetColLabelValue(col) == "Type": |
611 type_menu = wx.Menu(title='') |
617 type_menu = wx.Menu(title='') |
|
618 |
612 base_menu = wx.Menu(title='') |
619 base_menu = wx.Menu(title='') |
613 for base_type in self.Controler.GetBaseTypes(): |
620 for base_type in self.Controler.GetBaseTypes(): |
614 new_id = wx.NewId() |
621 new_id = wx.NewId() |
615 AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
622 AppendMenu(base_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=base_type) |
616 self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id) |
623 self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(base_type), id=new_id) |
617 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
624 type_menu.AppendMenu(wx.NewId(), _("Base Types"), base_menu) |
|
625 |
618 datatype_menu = wx.Menu(title='') |
626 datatype_menu = wx.Menu(title='') |
619 for datatype in self.Controler.GetDataTypes(self.TagName, False): |
627 for datatype in self.Controler.GetDataTypes(self.TagName, False): |
620 new_id = wx.NewId() |
628 new_id = wx.NewId() |
621 AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
629 AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype) |
622 self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id) |
630 self.Bind(wx.EVT_MENU, self.GetElementTypeFunction(datatype), id=new_id) |
623 type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
631 type_menu.AppendMenu(wx.NewId(), _("User Data Types"), datatype_menu) |
|
632 |
|
633 new_id = wx.NewId() |
|
634 AppendMenu(type_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Array")) |
|
635 self.Bind(wx.EVT_MENU, self.ElementArrayTypeFunction, id=new_id) |
|
636 |
624 ## functionblock_menu = wx.Menu(title='') |
637 ## functionblock_menu = wx.Menu(title='') |
625 ## bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
638 ## bodytype = self.Controler.GetEditedElementBodyType(self.TagName) |
626 ## pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
639 ## pouname, poutype = self.Controler.GetEditedElementType(self.TagName) |
627 ## if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]: |
640 ## if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]: |
628 ## for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName): |
641 ## for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName): |
629 ## new_id = wx.NewId() |
642 ## new_id = wx.NewId() |
630 ## AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
643 ## AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type) |
631 ## self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
644 ## self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id) |
632 ## type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
645 ## type_menu.AppendMenu(wx.NewId(), _("Function Block Types"), functionblock_menu) |
|
646 |
633 rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col)) |
647 rect = self.StructureElementsGrid.BlockToDeviceRect((row, col), (row, col)) |
634 self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize()) |
648 self.StructureElementsGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.StructureElementsGrid.GetColLabelSize()) |
635 type_menu.Destroy() |
649 type_menu.Destroy() |
636 event.Veto() |
650 event.Veto() |
637 else: |
651 else: |
642 row = self.StructureElementsGrid.GetGridCursorRow() |
656 row = self.StructureElementsGrid.GetGridCursorRow() |
643 self.StructureElementsTable.SetValueByName(row, "Type", base_type) |
657 self.StructureElementsTable.SetValueByName(row, "Type", base_type) |
644 self.RefreshTypeInfos() |
658 self.RefreshTypeInfos() |
645 self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
659 self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
646 return ElementTypeFunction |
660 return ElementTypeFunction |
|
661 |
|
662 def ElementArrayTypeFunction(self, event): |
|
663 row = self.StructureElementsGrid.GetGridCursorRow() |
|
664 dialog = ArrayTypeDialog(self, |
|
665 self.Controler.GetDataTypes(self.TagName), |
|
666 self.StructureElementsTable.GetValueByName(row, "Type")) |
|
667 if dialog.ShowModal() == wx.ID_OK: |
|
668 self.StructureElementsTable.SetValueByName(row, "Type", dialog.GetValue()) |
|
669 self.RefreshTypeInfos() |
|
670 self.StructureElementsTable.ResetView(self.StructureElementsGrid) |
|
671 dialog.Destroy() |
647 |
672 |
648 def RefreshDisplayedInfos(self): |
673 def RefreshDisplayedInfos(self): |
649 selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
674 selected = DATATYPE_TYPES_DICT[self.DerivationType.GetStringSelection()] |
650 if selected != self.CurrentPanel: |
675 if selected != self.CurrentPanel: |
651 if self.CurrentPanel == "Directly": |
676 if self.CurrentPanel == "Directly": |