andrej@1511: #!/usr/bin/env python
andrej@1511: # -*- coding: utf-8 -*-
andrej@1511: 
andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
andrej@1511: #
andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
andrej@1511: #
andrej@1511: # See COPYING file for copyrights details.
andrej@1511: #
andrej@1511: # This program is free software; you can redistribute it and/or
andrej@1511: # modify it under the terms of the GNU General Public License
andrej@1511: # as published by the Free Software Foundation; either version 2
andrej@1511: # of the License, or (at your option) any later version.
andrej@1511: #
andrej@1511: # This program is distributed in the hope that it will be useful,
andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1511: # GNU General Public License for more details.
andrej@1511: #
andrej@1511: # You should have received a copy of the GNU General Public License
andrej@1511: # along with this program; if not, write to the Free Software
andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
smarteh-dev@680: 
andrej@1881: from __future__ import absolute_import
smarteh-dev@680: import wx
smarteh-dev@680: 
smarteh-dev@680: from subindextable import EditingPanel
Laurent@1021: from nodeeditortemplate import NodeEditorTemplate
Laurent@814: from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
smarteh-dev@680: 
andrej@1773: [
andrej@1773:     ID_SLAVEEDITORCONFNODEMENUNODEINFOS, ID_SLAVEEDITORCONFNODEMENUDS301PROFILE,
andrej@1773:     ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE,
andrej@1773:     ID_SLAVEEDITORCONFNODEMENUADD,
Edouard@717: ] = [wx.NewId() for _init_coll_ConfNodeMenu_Items in range(5)]
smarteh-dev@680: 
andrej@1773: [
andrej@1773:     ID_SLAVEEDITORADDMENUSDOSERVER, ID_SLAVEEDITORADDMENUSDOCLIENT,
andrej@1773:     ID_SLAVEEDITORADDMENUPDOTRANSMIT, ID_SLAVEEDITORADDMENUPDORECEIVE,
andrej@1773:     ID_SLAVEEDITORADDMENUMAPVARIABLE, ID_SLAVEEDITORADDMENUUSERTYPE,
smarteh-dev@680: ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
smarteh-dev@680: 
andrej@1736: 
laurent@762: class SlaveEditor(ConfTreeNodeEditor, NodeEditorTemplate):
andrej@1730: 
Laurent@920:     CONFNODEEDITOR_TABS = [
Laurent@920:         (_("CANOpen slave"), "_create_SlaveNodeEditor")]
andrej@1730: 
Laurent@920:     def _create_SlaveNodeEditor(self, prnt):
Laurent@920:         self.SlaveNodeEditor = EditingPanel(prnt, self, self.Controler, self.Editable)
Laurent@920:         return self.SlaveNodeEditor
andrej@1730: 
smarteh-dev@680:     def __init__(self, parent, controler, window, editable=True):
smarteh-dev@680:         self.Editable = editable
laurent@762:         ConfTreeNodeEditor.__init__(self, parent, controler, window)
smarteh-dev@680:         NodeEditorTemplate.__init__(self, controler, window, False)
andrej@1730: 
smarteh-dev@680:     def __del__(self):
smarteh-dev@680:         self.Controler.OnCloseEditor(self)
andrej@1730: 
Edouard@717:     def GetConfNodeMenuItems(self):
smarteh-dev@680:         if self.Editable:
smarteh-dev@680:             add_menu = [(wx.ITEM_NORMAL, (_('SDO Server'), ID_SLAVEEDITORADDMENUSDOSERVER, '', self.OnAddSDOServerMenu)),
smarteh-dev@680:                         (wx.ITEM_NORMAL, (_('SDO Client'), ID_SLAVEEDITORADDMENUSDOCLIENT, '', self.OnAddSDOClientMenu)),
smarteh-dev@680:                         (wx.ITEM_NORMAL, (_('PDO Transmit'), ID_SLAVEEDITORADDMENUPDOTRANSMIT, '', self.OnAddPDOTransmitMenu)),
smarteh-dev@680:                         (wx.ITEM_NORMAL, (_('PDO Receive'), ID_SLAVEEDITORADDMENUPDORECEIVE, '', self.OnAddPDOReceiveMenu)),
smarteh-dev@680:                         (wx.ITEM_NORMAL, (_('Map Variable'), ID_SLAVEEDITORADDMENUMAPVARIABLE, '', self.OnAddMapVariableMenu)),
smarteh-dev@680:                         (wx.ITEM_NORMAL, (_('User Type'), ID_SLAVEEDITORADDMENUUSERTYPE, '', self.OnAddUserTypeMenu))]
andrej@1730: 
smarteh-dev@680:             profile = self.Controler.GetCurrentProfileName()
smarteh-dev@680:             if profile not in ("None", "DS-301"):
smarteh-dev@680:                 other_profile_text = _("%s Profile") % profile
smarteh-dev@680:                 add_menu.append((wx.ITEM_SEPARATOR, None))
andrej@1847:                 for text, _indexes in self.Manager.GetCurrentSpecificMenu():
smarteh-dev@680:                     add_menu.append((wx.ITEM_NORMAL, (text, wx.NewId(), '', self.GetProfileCallBack(text))))
smarteh-dev@680:             else:
smarteh-dev@680:                 other_profile_text = _('Other Profile')
andrej@1730: 
laurent@845:             return [(wx.ITEM_NORMAL, (_('DS-301 Profile'), ID_SLAVEEDITORCONFNODEMENUDS301PROFILE, '', self.OnCommunicationMenu)),
Edouard@717:                     (wx.ITEM_NORMAL, (_('DS-302 Profile'), ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, '', self.OnOtherCommunicationMenu)),
Edouard@717:                     (wx.ITEM_NORMAL, (other_profile_text, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, '', self.OnEditProfileMenu)),
smarteh-dev@680:                     (wx.ITEM_SEPARATOR, None),
Edouard@717:                     (add_menu, (_('Add'), ID_SLAVEEDITORCONFNODEMENUADD))]
smarteh-dev@680:         return []
andrej@1730: 
Edouard@717:     def RefreshConfNodeMenu(self, confnode_menu):
laurent@816:         if self.Editable:
laurent@816:             confnode_menu.Enable(ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, False)
smarteh-dev@680: 
smarteh-dev@680:     def RefreshView(self):
laurent@762:         ConfTreeNodeEditor.RefreshView(self)
Laurent@920:         self.SlaveNodeEditor.RefreshIndexList()
smarteh-dev@680: 
smarteh-dev@680:     def RefreshCurrentIndexList(self):
smarteh-dev@680:         self.RefreshView()
andrej@1730: 
smarteh-dev@680:     def RefreshBufferState(self):
smarteh-dev@680:         self.ParentWindow.RefreshTitle()
smarteh-dev@680:         self.ParentWindow.RefreshFileMenu()
smarteh-dev@680:         self.ParentWindow.RefreshEditMenu()
smarteh-dev@680:         self.ParentWindow.RefreshPageTitles()
laurent@777: 
andrej@1736: 
laurent@777: class MasterViewer(SlaveEditor):
Laurent@1286:     SHOW_BASE_PARAMS = False
laurent@777:     SHOW_PARAMS = False
andrej@1730: 
laurent@847:     def __init__(self, parent, controler, window, tagname):
laurent@777:         SlaveEditor.__init__(self, parent, controler, window, False)
andrej@1730: 
laurent@847:         self.TagName = tagname
andrej@1730: 
laurent@847:     def GetTagName(self):
laurent@847:         return self.TagName
andrej@1730: 
laurent@847:     def GetCurrentNodeId(self):
laurent@847:         return None
andrej@1730: 
laurent@847:     def GetInstancePath(self):
laurent@847:         return self.Controler.CTNFullName() + ".generated_master"
andrej@1730: 
laurent@847:     def GetTitle(self):
laurent@847:         return self.GetInstancePath()
andrej@1730: 
laurent@847:     def IsViewing(self, tagname):
laurent@847:         return self.GetInstancePath() == tagname
Laurent@1286: 
Laurent@1286:     def RefreshView(self):
Laurent@1286:         self.SlaveNodeEditor.RefreshIndexList()