PLCOpenEditor.py
changeset 58 39cd981ff242
parent 56 7187e1c00975
child 64 dd6f693e46a1
equal deleted inserted replaced
57:9bf197698af0 58:39cd981ff242
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     5 #based on the plcopen standard. 
     5 #based on the plcopen standard. 
     6 #
     6 #
     7 #Copyright (C): Edouard TISSERANT and Laurent BESSARD
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 #See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 #This library is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 #modify it under the terms of the GNU General Public
    14 #version 2.1 of the License, or (at your option) any later version.
    14 #version 2.1 of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 #This library is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    19 #Lesser General Public License for more details.
    19 #General Public License for more details.
    20 #
    20 #
    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 
  1949     """
  1949     """
  1950     def __init__(self, parent, data, colnames):
  1950     def __init__(self, parent, data, colnames):
  1951         # The base class must be initialized *first*
  1951         # The base class must be initialized *first*
  1952         wxPyGridTableBase.__init__(self)
  1952         wxPyGridTableBase.__init__(self)
  1953         self.data = data
  1953         self.data = data
       
  1954         self.old_value = None
  1954         self.colnames = colnames
  1955         self.colnames = colnames
  1955         self.Parent = parent
  1956         self.Parent = parent
  1956         # XXX
  1957         # XXX
  1957         # we need to store the row length and collength to
  1958         # we need to store the row length and collength to
  1958         # see if the table has changed size
  1959         # see if the table has changed size
  1982     def GetValueByName(self, row, colname):
  1983     def GetValueByName(self, row, colname):
  1983         return self.data[row].get(colname)
  1984         return self.data[row].get(colname)
  1984 
  1985 
  1985     def SetValue(self, row, col, value):
  1986     def SetValue(self, row, col, value):
  1986         if col < len(self.colnames):
  1987         if col < len(self.colnames):
  1987             self.data[row][self.GetColLabelValue(col)] = value
  1988             colname = self.GetColLabelValue(col)
  1988         
  1989             if colname == "Name":
       
  1990                 self.old_value = self.data[row][colname]
       
  1991             self.data[row][colname] = value
       
  1992     
       
  1993     def GetOldValue(self):
       
  1994         return self.old_value
       
  1995     
  1989     def ResetView(self, grid):
  1996     def ResetView(self, grid):
  1990         """
  1997         """
  1991         (wxGrid) -> Reset the grid view.   Call this to
  1998         (wxGrid) -> Reset the grid view.   Call this to
  1992         update the grid if rows and columns have been added or deleted
  1999         update the grid if rows and columns have been added or deleted
  1993         """
  2000         """
  2513                 message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR)
  2520                 message = wxMessageDialog(self, "A variable with \"%s\" as name exists in this pou!"%value, "Error", wxOK|wxICON_ERROR)
  2514                 message.ShowModal()
  2521                 message.ShowModal()
  2515                 message.Destroy()
  2522                 message.Destroy()
  2516                 event.Veto()
  2523                 event.Veto()
  2517             else:
  2524             else:
  2518                 self.SaveValues()
  2525                 self.SaveValues(False)
       
  2526                 old_value = self.Table.GetOldValue()
       
  2527                 if old_value != "":
       
  2528                     self.Controler.UpdateCurrentPouEditingUsedVariable(old_value, value)
       
  2529                 self.Controler.BufferProject()
       
  2530                 self.Parent.RefreshTitle()
       
  2531                 self.Parent.RefreshEditMenu()
       
  2532                 self.Viewer.RefreshView()
  2519                 event.Skip()
  2533                 event.Skip()
  2520         else:
  2534         else:
  2521             self.SaveValues()
  2535             self.SaveValues()
  2522             event.Skip()
  2536             event.Skip()
  2523 
  2537 
  2555             if variable["Class"] in self.ClassList:
  2569             if variable["Class"] in self.ClassList:
  2556                 data.append(variable)
  2570                 data.append(variable)
  2557         self.Table.SetData(data)
  2571         self.Table.SetData(data)
  2558         self.Table.ResetView(self.VariablesGrid)
  2572         self.Table.ResetView(self.VariablesGrid)
  2559 
  2573 
  2560     def SaveValues(self):
  2574     def SaveValues(self, buffer = True):
  2561         if self.ElementType == "config":
  2575         if self.ElementType == "config":
  2562             self.Controler.SetConfigurationGlobalVars(self.ConfigName, self.Values)
  2576             self.Controler.SetConfigurationGlobalVars(self.ConfigName, self.Values)
  2563         elif self.ElementType == "resource":
  2577         elif self.ElementType == "resource":
  2564             self.Controler.SetConfigurationResourceGlobalVars(self.ConfigName, self.ResourceName, self.Values)
  2578             self.Controler.SetConfigurationResourceGlobalVars(self.ConfigName, self.ResourceName, self.Values)
  2565         else:
  2579         else:
  2566             if self.ReturnType.IsEnabled():
  2580             if self.ReturnType.IsEnabled():
  2567                 self.Controler.SetPouInterfaceReturnType(self.PouName, self.ReturnType.GetStringSelection())
  2581                 self.Controler.SetPouInterfaceReturnType(self.PouName, self.ReturnType.GetStringSelection())
  2568             self.Controler.SetPouInterfaceVars(self.PouName, self.Values)
  2582             self.Controler.SetPouInterfaceVars(self.PouName, self.Values)
       
  2583         if buffer:
       
  2584             self.Controler.BufferProject()
       
  2585             self.Parent.RefreshTitle()
       
  2586             self.Parent.RefreshEditMenu()
  2569 
  2587 
  2570 ##[wxID_EDITVARIABLEDIALOG, wxID_EDITVARIABLEDIALOGMAINPANEL, 
  2588 ##[wxID_EDITVARIABLEDIALOG, wxID_EDITVARIABLEDIALOGMAINPANEL, 
  2571 ## wxID_EDITVARIABLEDIALOGVARIABLESGRID, wxID_EDITVARIABLEDIALOGRETURNTYPE, 
  2589 ## wxID_EDITVARIABLEDIALOGVARIABLESGRID, wxID_EDITVARIABLEDIALOGRETURNTYPE, 
  2572 ## wxID_EDITVARIABLEDIALOGCLASSFILTER, wxID_EDITVARIABLEDIALOGADDBUTTON,
  2590 ## wxID_EDITVARIABLEDIALOGCLASSFILTER, wxID_EDITVARIABLEDIALOGADDBUTTON,
  2573 ## wxID_EDITVARIABLEDIALOGDELETEBUTTON, wxID_EDITVARIABLEDIALOGUPBUTTON, 
  2591 ## wxID_EDITVARIABLEDIALOGDELETEBUTTON, wxID_EDITVARIABLEDIALOGUPBUTTON,