move to layer kv6 compatibility

This commit is contained in:
U-CAD\userC
2021-07-22 16:33:50 +02:00
parent 8b61aa907a
commit f42374814b

View File

@ -1,162 +1,169 @@
# move_to_edge_cuts.py # move_to_edge_cuts.py
# #
# Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. # Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. # MA 02110-1301, USA.
# #
# #
### plugins errors ### plugins errors
#import pcbnew #import pcbnew
#pcbnew.GetWizardsBackTrace() #pcbnew.GetWizardsBackTrace()
import wx import wx
import pcbnew import pcbnew
from pcbnew import * from pcbnew import *
import base64 import base64
from wx.lib.embeddedimage import PyEmbeddedImage from wx.lib.embeddedimage import PyEmbeddedImage
import os import os
___version___="1.2.3" ___version___="1.2.4"
from . import Move2LayerDlg from . import Move2LayerDlg
def MoveToLayer(pcb,layerId): def MoveToLayer(pcb,layerId):
found_selected=False found_selected=False
for drw in pcb.GetDrawings(): for drw in pcb.GetDrawings():
if drw.IsSelected(): if drw.IsSelected():
drw.SetLayer(layerId) drw.SetLayer(layerId)
found_selected=True found_selected=True
if found_selected!=True: if found_selected!=True:
LogMsg="select drawings to be moved to new layer\n" LogMsg="select drawings to be moved to new layer\n"
LogMsg+="use GAL for selecting lines" LogMsg+="use GAL for selecting lines"
wx.LogMessage(LogMsg) wx.LogMessage(LogMsg)
else: else:
pcbnew.Refresh() pcbnew.Refresh()
layerName = pcbnew.GetBoard().GetLayerName(layerId) layerName = pcbnew.GetBoard().GetLayerName(layerId)
LogMsg="selected drawings moved to "+layerName+" layer" LogMsg="selected drawings moved to "+layerName+" layer"
wx.LogMessage(LogMsg) wx.LogMessage(LogMsg)
# #
def find_pcbnew_w():
windows = wx.GetTopLevelWindows()
pcbneww = [w for w in windows if "pcbnew" in w.GetTitle().lower()]
# Python plugin stuff if len(pcbneww) != 1:
return None
class Move2Layer_Dlg(Move2LayerDlg.Move2LayerDlg): return pcbneww[0]
# from https://github.com/MitjaNemec/Kicad_action_plugins #
# hack for new wxFormBuilder generating code incompatible with old wxPython
# noinspection PyMethodOverriding
def SetSizeHints(self, sz1, sz2): # Python plugin stuff
if wx.__version__ < '4.0':
self.SetSizeHintsSz(sz1, sz2) class Move2Layer_Dlg(Move2LayerDlg.Move2LayerDlg):
else: # from https://github.com/MitjaNemec/Kicad_action_plugins
super(Move2Layer_Dlg, self).SetSizeHints(sz1, sz2) # hack for new wxFormBuilder generating code incompatible with old wxPython
# noinspection PyMethodOverriding
#def onApplyClick(self, event): def SetSizeHints(self, sz1, sz2):
# return self.EndModal(wx.ID_OK) if wx.__version__ < '4.0':
# self.SetSizeHintsSz(sz1, sz2)
#def onCancelClick(self, event): else:
# return self.EndModal(wx.ID_CANCEL) super(Move2Layer_Dlg, self).SetSizeHints(sz1, sz2)
def __init__(self, parent): #def onApplyClick(self, event):
import wx # return self.EndModal(wx.ID_OK)
Move2LayerDlg.Move2LayerDlg.__init__(self, parent) #
#self.GetSizer().Fit(self) #def onCancelClick(self, event):
self.SetMinSize(self.GetSize()) # return self.EndModal(wx.ID_CANCEL)
self.m_bitmapLayers.SetBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), "./add_polygon.png"))) def __init__(self, parent):
self.m_bitmapDwgs.SetBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), "./move2layer.png"))) import wx
# self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick) Move2LayerDlg.Move2LayerDlg.__init__(self, parent)
# self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick) #self.GetSizer().Fit(self)
# if wx.__version__ < '4.0': self.SetMinSize(self.GetSize())
# self.m_buttonReconnect.SetToolTipString( u"Select two converging Tracks to re-connect them\nor Select tracks including one round corner to be straighten" )
# self.m_buttonRound.SetToolTipString( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) self.m_bitmapLayers.SetBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), "./add_polygon.png")))
# else: self.m_bitmapDwgs.SetBitmap(wx.Bitmap(os.path.join(os.path.dirname(__file__), "./move2layer.png")))
# self.m_buttonReconnect.SetToolTip( u"Select two converging Tracks to re-connect them\nor Select tracks including one round corner to be straighten" ) # self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick)
# self.m_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) # self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick)
# # if wx.__version__ < '4.0':
class move_to_draw_layer( pcbnew.ActionPlugin ): # self.m_buttonReconnect.SetToolTipString( u"Select two converging Tracks to re-connect them\nor Select tracks including one round corner to be straighten" )
""" # self.m_buttonRound.SetToolTipString( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" )
A script to Move Selected Drawing(s) to chosen new Layer (available only in GAL) # else:
How to use: # self.m_buttonReconnect.SetToolTip( u"Select two converging Tracks to re-connect them\nor Select tracks including one round corner to be straighten" )
- move to GAL # self.m_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" )
- select some draw objects #
- call the plugin class move_to_draw_layer( pcbnew.ActionPlugin ):
- select the new layer """
- selected draw objects will be moved to new layer A script to Move Selected Drawing(s) to chosen new Layer (available only in GAL)
""" How to use:
- move to GAL
def defaults( self ): - select some draw objects
""" - call the plugin
Method defaults must be redefined - select the new layer
self.name should be the menu label to use - selected draw objects will be moved to new layer
self.category should be the category (not yet used) """
self.description should be a comprehensive description
of the plugin def defaults( self ):
""" """
import os Method defaults must be redefined
self.name = "Move Selected Drawings to chosen Layer \nversion "+___version___ self.name should be the menu label to use
self.category = "Modify PCB" self.category should be the category (not yet used)
self.description = "Move Selected Drawings to chosen Layer on an existing PCB" self.description should be a comprehensive description
self.icon_file_name = os.path.join(os.path.dirname(__file__), "./move2layer.png") of the plugin
self.show_toolbar_button = True """
import os
def Run( self ): self.name = "Move Selected Drawings to chosen Layer \nversion "+___version___
found_selected=False self.category = "Modify PCB"
self.description = "Move Selected Drawings to chosen Layer on an existing PCB"
board = pcbnew.GetBoard() self.icon_file_name = os.path.join(os.path.dirname(__file__), "./move2layer.png")
fileName = GetBoard().GetFileName() self.show_toolbar_button = True
# # dicts for converting layer name to id, used by _get_layer
# _std_layer_dict = {pcbnew.BOARD_GetStandardLayerName(n): n def Run( self ):
# for n in range(pcbnew.PCB_LAYER_ID_COUNT)} found_selected=False
# #_std_layer_names = {s: n for n, s in _std_layer_dict.iteritems()}
# _std_layer_names = {s: n for n, s in _std_layer_dict.items()} board = pcbnew.GetBoard()
# _brd_layer_dict = {pcbnew.GetBoard().GetLayerName(n): n fileName = GetBoard().GetFileName()
# for n in range(pcbnew.PCB_LAYER_ID_COUNT)} # # dicts for converting layer name to id, used by _get_layer
# #_std_layer_names = {s: n for n, s in _std_layer_dict.iteritems()} # _std_layer_dict = {pcbnew.BOARD_GetStandardLayerName(n): n
# _brd_layer_names = {s: n for n, s in _brd_layer_dict.items()} # for n in range(pcbnew.PCB_LAYER_ID_COUNT)}
# #_std_layer_names = {s: n for n, s in _std_layer_dict.iteritems()}
# _std_layer_names = {s: n for n, s in _std_layer_dict.items()}
if 0: #len(fileName) == 0: # _brd_layer_dict = {pcbnew.GetBoard().GetLayerName(n): n
wx.LogMessage("A board needs to be saved/loaded\nto run the plugin!") # for n in range(pcbnew.PCB_LAYER_ID_COUNT)}
else: # #_std_layer_names = {s: n for n, s in _std_layer_dict.iteritems()}
#from https://github.com/MitjaNemec/Kicad_action_plugins # _brd_layer_names = {s: n for n, s in _brd_layer_dict.items()}
#hack wxFormBuilder py2/py3
_pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0]
aParameters = Move2Layer_Dlg(_pcbnew_frame) if 0: #len(fileName) == 0:
aParameters.Show() wx.LogMessage("A board needs to be saved/loaded\nto run the plugin!")
for l in range(pcbnew.PCB_LAYER_ID_COUNT): else:
aParameters.m_comboBoxLayer.Append(pcbnew.GetBoard().GetLayerName(l)) #from https://github.com/MitjaNemec/Kicad_action_plugins
aParameters.m_comboBoxLayer.Select(44) #hack wxFormBuilder py2/py3
modal_result = aParameters.ShowModal() #_pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0]
if modal_result == wx.ID_OK: pcbnew_window = find_pcbnew_w()
LayerName = aParameters.m_comboBoxLayer.GetStringSelection() aParameters = Move2Layer_Dlg(pcbnew_window)
LayerIndex = aParameters.m_comboBoxLayer.FindString(LayerName) aParameters.Show()
LayerStdName = pcbnew.BOARD_GetStandardLayerName(LayerIndex) for l in range(pcbnew.PCB_LAYER_ID_COUNT):
#wx.LogMessage(LayerName+';'+str(LayerIndex)+';'+LayerStdName) aParameters.m_comboBoxLayer.Append(pcbnew.GetBoard().GetLayerName(l))
MoveToLayer(board, LayerIndex) aParameters.m_comboBoxLayer.Select(44)
else: modal_result = aParameters.ShowModal()
None # Cancel if modal_result == wx.ID_OK:
LayerName = aParameters.m_comboBoxLayer.GetStringSelection()
LogMsg='' LayerIndex = aParameters.m_comboBoxLayer.FindString(LayerName)
msg="'move to layer tool'\n" LayerStdName = pcbnew.BOARD_GetStandardLayerName(LayerIndex)
msg+="version = "+___version___ #wx.LogMessage(LayerName+';'+str(LayerIndex)+';'+LayerStdName)
MoveToLayer(board, LayerIndex)
else:
#move_to_draw_layer().register() None # Cancel
LogMsg=''
msg="'move to layer tool'\n"
msg+="version = "+___version___
#move_to_draw_layer().register()