From 84bba2a186c4ce755ae75746d4341db1b64c4bd1 Mon Sep 17 00:00:00 2001 From: easyw Date: Mon, 17 Feb 2020 15:39:00 +0100 Subject: [PATCH] improving Dialogs --- MoveToLayer/Move2LayerDlg.py | 9 +- MoveToLayer/Move2LayerDlg.py.bak | 75 +++ MoveToLayer/move_to_layer.py | 7 +- MoveToLayer/move_to_layer.py.bak | 153 ++++++ MoveToLayer/move_to_layer_dlg.fbp | 13 +- MoveToLayer/move_to_layer_dlg.fbp.bak | 536 ++++++++++++++++++++ PcbToDxf/__init__.py | 2 + Snap2Grid/Snap2GridDlg.fbp | 682 ++++++++++++++++++++++++++ Snap2Grid/Snap2GridDlg.py | 88 ++++ Snap2Grid/snap2grid.py | 292 ++++++----- Snap2Grid/snap2grid.py.bak | 200 ++++++++ 11 files changed, 1917 insertions(+), 140 deletions(-) create mode 100644 MoveToLayer/Move2LayerDlg.py.bak create mode 100644 MoveToLayer/move_to_layer.py.bak create mode 100644 MoveToLayer/move_to_layer_dlg.fbp.bak create mode 100644 PcbToDxf/__init__.py create mode 100644 Snap2Grid/Snap2GridDlg.fbp create mode 100644 Snap2Grid/Snap2GridDlg.py create mode 100644 Snap2Grid/snap2grid.py.bak diff --git a/MoveToLayer/Move2LayerDlg.py b/MoveToLayer/Move2LayerDlg.py index 3f5f403..66ed329 100644 --- a/MoveToLayer/Move2LayerDlg.py +++ b/MoveToLayer/Move2LayerDlg.py @@ -17,13 +17,13 @@ import wx.xrc class Move2LayerDlg ( wx.Dialog ): def __init__( self, parent ): - wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Move to Layer", pos = wx.DefaultPosition, size = wx.Size( 325,190 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER ) + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Move to Layer", pos = wx.DefaultPosition, size = wx.Size( 568,263 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER ) self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) bSizer3 = wx.BoxSizer( wx.VERTICAL ) - self.m_comment = wx.StaticText( self, wx.ID_ANY, u"Selected Objects to Move to chosen Layer", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_comment = wx.StaticText( self, wx.ID_ANY, u"Selected Objects will Move to chosen Layer", wx.DefaultPosition, wx.DefaultSize, 0 ) self.m_comment.Wrap( -1 ) bSizer3.Add( self.m_comment, 0, wx.ALL|wx.EXPAND, 5 ) @@ -63,6 +63,11 @@ class Move2LayerDlg ( wx.Dialog ): bSizer3.Add( bSizer1, 0, wx.ALIGN_RIGHT|wx.EXPAND, 5 ) + bSizer4 = wx.BoxSizer( wx.VERTICAL ) + + + bSizer3.Add( bSizer4, 1, wx.EXPAND, 5 ) + self.SetSizer( bSizer3 ) self.Layout() diff --git a/MoveToLayer/Move2LayerDlg.py.bak b/MoveToLayer/Move2LayerDlg.py.bak new file mode 100644 index 0000000..3f5f403 --- /dev/null +++ b/MoveToLayer/Move2LayerDlg.py.bak @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +########################################################################### +## Python code generated with wxFormBuilder (version Oct 26 2018) +## http://www.wxformbuilder.org/ +## +## PLEASE DO *NOT* EDIT THIS FILE! +########################################################################### + +import wx +import wx.xrc + +########################################################################### +## Class Move2LayerDlg +########################################################################### + +class Move2LayerDlg ( wx.Dialog ): + + def __init__( self, parent ): + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Move to Layer", pos = wx.DefaultPosition, size = wx.Size( 325,190 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER ) + + self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) + + bSizer3 = wx.BoxSizer( wx.VERTICAL ) + + self.m_comment = wx.StaticText( self, wx.ID_ANY, u"Selected Objects to Move to chosen Layer", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_comment.Wrap( -1 ) + + bSizer3.Add( self.m_comment, 0, wx.ALL|wx.EXPAND, 5 ) + + bSizer31 = wx.BoxSizer( wx.HORIZONTAL ) + + self.m_staticTextLayer = wx.StaticText( self, wx.ID_ANY, u"Layer", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticTextLayer.Wrap( -1 ) + + bSizer31.Add( self.m_staticTextLayer, 1, wx.ALL|wx.EXPAND, 5 ) + + m_comboBoxLayerChoices = [] + self.m_comboBoxLayer = wx.ComboBox( self, wx.ID_ANY, u"Combo!", wx.DefaultPosition, wx.Size( 250,-1 ), m_comboBoxLayerChoices, 0 ) + bSizer31.Add( self.m_comboBoxLayer, 0, wx.ALL|wx.EXPAND, 5 ) + + + bSizer3.Add( bSizer31, 0, 0, 5 ) + + self.m_staticline1 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + bSizer3.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 ) + + bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) + + self.m_staticText101 = wx.StaticText( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticText101.Wrap( -1 ) + + bSizer1.Add( self.m_staticText101, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 5 ) + + self.m_buttonOK = wx.Button( self, wx.ID_OK, u"Apply", wx.DefaultPosition, wx.DefaultSize, 0 ) + + self.m_buttonOK.SetDefault() + bSizer1.Add( self.m_buttonOK, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + + self.m_buttonCancel = wx.Button( self, wx.ID_CANCEL, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 ) + bSizer1.Add( self.m_buttonCancel, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + + + bSizer3.Add( bSizer1, 0, wx.ALIGN_RIGHT|wx.EXPAND, 5 ) + + + self.SetSizer( bSizer3 ) + self.Layout() + + self.Centre( wx.BOTH ) + + def __del__( self ): + pass + + diff --git a/MoveToLayer/move_to_layer.py b/MoveToLayer/move_to_layer.py index bc6b7b1..6a1a950 100644 --- a/MoveToLayer/move_to_layer.py +++ b/MoveToLayer/move_to_layer.py @@ -25,19 +25,20 @@ from pcbnew import * import base64 from wx.lib.embeddedimage import PyEmbeddedImage import os -___version___="1.2.2" +___version___="1.2.3" from . import Move2LayerDlg def MoveToLayer(pcb,layerId): + found_selected=False for drw in pcb.GetDrawings(): if drw.IsSelected(): drw.SetLayer(layerId) found_selected=True if found_selected!=True: - LogMsg="select lines to be moved to new layer\n" + LogMsg="select drawings to be moved to new layer\n" LogMsg+="use GAL for selecting lines" wx.LogMessage(LogMsg) else: @@ -101,7 +102,7 @@ class move_to_draw_layer( pcbnew.ActionPlugin ): of the plugin """ import os - self.name = "Move Selected Drawings to chosen Layer\nversion "+___version___ + self.name = "Move Selected Drawings to chosen Layer \nversion "+___version___ self.category = "Modify PCB" self.description = "Move Selected Drawings to chosen Layer on an existing PCB" self.icon_file_name = os.path.join(os.path.dirname(__file__), "./move2layer.png") diff --git a/MoveToLayer/move_to_layer.py.bak b/MoveToLayer/move_to_layer.py.bak new file mode 100644 index 0000000..bc6b7b1 --- /dev/null +++ b/MoveToLayer/move_to_layer.py.bak @@ -0,0 +1,153 @@ +# move_to_edge_cuts.py +# +# Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# + +import wx +import pcbnew +from pcbnew import * +import base64 +from wx.lib.embeddedimage import PyEmbeddedImage +import os +___version___="1.2.2" + +from . import Move2LayerDlg + + +def MoveToLayer(pcb,layerId): + for drw in pcb.GetDrawings(): + if drw.IsSelected(): + drw.SetLayer(layerId) + found_selected=True + + if found_selected!=True: + LogMsg="select lines to be moved to new layer\n" + LogMsg+="use GAL for selecting lines" + wx.LogMessage(LogMsg) + else: + pcbnew.Refresh() + layerName = pcbnew.GetBoard().GetLayerName(layerId) + LogMsg="selected drawings moved to "+layerName+" layer" + wx.LogMessage(LogMsg) +# + + + +# Python plugin stuff + +class Move2Layer_Dlg(Move2LayerDlg.Move2LayerDlg): + # 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): + if wx.__version__ < '4.0': + self.SetSizeHintsSz(sz1, sz2) + else: + super(Move2Layer_Dlg, self).SetSizeHints(sz1, sz2) + + #def onApplyClick(self, event): + # return self.EndModal(wx.ID_OK) + # + #def onCancelClick(self, event): + # return self.EndModal(wx.ID_CANCEL) + + def __init__(self, parent): + import wx + Move2LayerDlg.Move2LayerDlg.__init__(self, parent) + #self.GetSizer().Fit(self) + self.SetMinSize(self.GetSize()) + # self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick) + # self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick) + # if wx.__version__ < '4.0': + # 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" ) + # else: + # 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_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) +# +class move_to_draw_layer( pcbnew.ActionPlugin ): + """ + A script to Move Selected Drawing(s) to chosen new Layer (available only in GAL) + How to use: + - move to GAL + - select some draw objects + - call the plugin + - select the new layer + - selected draw objects will be moved to new layer + """ + + def defaults( self ): + """ + Method defaults must be redefined + self.name should be the menu label to use + self.category should be the category (not yet used) + self.description should be a comprehensive description + of the plugin + """ + import os + self.name = "Move Selected Drawings to chosen Layer\nversion "+___version___ + self.category = "Modify PCB" + self.description = "Move Selected Drawings to chosen Layer on an existing PCB" + self.icon_file_name = os.path.join(os.path.dirname(__file__), "./move2layer.png") + self.show_toolbar_button = True + + def Run( self ): + found_selected=False + + board = pcbnew.GetBoard() + fileName = GetBoard().GetFileName() + # # dicts for converting layer name to id, used by _get_layer + # _std_layer_dict = {pcbnew.BOARD_GetStandardLayerName(n): n + # 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()} + # _brd_layer_dict = {pcbnew.GetBoard().GetLayerName(n): n + # for n in range(pcbnew.PCB_LAYER_ID_COUNT)} + # #_std_layer_names = {s: n for n, s in _std_layer_dict.iteritems()} + # _brd_layer_names = {s: n for n, s in _brd_layer_dict.items()} + + + if 0: #len(fileName) == 0: + wx.LogMessage("A board needs to be saved/loaded\nto run the plugin!") + else: + #from https://github.com/MitjaNemec/Kicad_action_plugins + #hack wxFormBuilder py2/py3 + _pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0] + aParameters = Move2Layer_Dlg(_pcbnew_frame) + aParameters.Show() + for l in range(pcbnew.PCB_LAYER_ID_COUNT): + aParameters.m_comboBoxLayer.Append(pcbnew.GetBoard().GetLayerName(l)) + aParameters.m_comboBoxLayer.Select(44) + modal_result = aParameters.ShowModal() + if modal_result == wx.ID_OK: + LayerName = aParameters.m_comboBoxLayer.GetStringSelection() + LayerIndex = aParameters.m_comboBoxLayer.FindString(LayerName) + LayerStdName = pcbnew.BOARD_GetStandardLayerName(LayerIndex) + #wx.LogMessage(LayerName+';'+str(LayerIndex)+';'+LayerStdName) + MoveToLayer(board, LayerIndex) + else: + None # Cancel + + LogMsg='' + msg="'move to layer tool'\n" + msg+="version = "+___version___ + + +#move_to_draw_layer().register() + diff --git a/MoveToLayer/move_to_layer_dlg.fbp b/MoveToLayer/move_to_layer_dlg.fbp index 43a4da8..66f4aa8 100644 --- a/MoveToLayer/move_to_layer_dlg.fbp +++ b/MoveToLayer/move_to_layer_dlg.fbp @@ -45,7 +45,7 @@ Move2LayerDlg - 325,190 + 568,263 wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER Move to Layer @@ -530,6 +530,17 @@ + + 5 + wxEXPAND + 1 + + + bSizer4 + wxVERTICAL + none + + diff --git a/MoveToLayer/move_to_layer_dlg.fbp.bak b/MoveToLayer/move_to_layer_dlg.fbp.bak new file mode 100644 index 0000000..43a4da8 --- /dev/null +++ b/MoveToLayer/move_to_layer_dlg.fbp.bak @@ -0,0 +1,536 @@ + + + + + + Python + 1 + source_name + 0 + 0 + res + UTF-8 + connect + Move2LayerDlg + 1000 + none + + 0 + Move2LayerDlg + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + Move2LayerDlg + + 325,190 + wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + + Move to Layer + + + + + + + bSizer3 + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Selected Objects will Move to chosen Layer + 0 + + 0 + + + 0 + + 1 + m_comment + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + + 0 + + + bSizer31 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Layer + 0 + + 0 + + + 0 + + 1 + m_staticTextLayer + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + -1,-1 + 0 + -1,-1 + 1 + m_comboBoxLayer + 1 + + + protected + 1 + + Resizable + -1 + 1 + 250,-1 + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + Combo! + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxALIGN_RIGHT|wxEXPAND + 0 + + + bSizer1 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + + 0 + + 1 + m_staticText101 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 0 + + 1 + + 1 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_OK + Apply + + 0 + + 0 + + + 0 + + 1 + m_buttonOK + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_CANCEL + Cancel + + 0 + + 0 + + + 0 + + 1 + m_buttonCancel + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + diff --git a/PcbToDxf/__init__.py b/PcbToDxf/__init__.py new file mode 100644 index 0000000..68def39 --- /dev/null +++ b/PcbToDxf/__init__.py @@ -0,0 +1,2 @@ +from .action_menu_pcb2dxf import pcb2dxf +pcb2dxf().register() diff --git a/Snap2Grid/Snap2GridDlg.fbp b/Snap2Grid/Snap2GridDlg.fbp new file mode 100644 index 0000000..6becf11 --- /dev/null +++ b/Snap2Grid/Snap2GridDlg.fbp @@ -0,0 +1,682 @@ + + + + + + Python + 1 + source_name + 0 + 0 + res + UTF-8 + connect + Snap2GridDlg + 1000 + none + + 0 + Snap2GridDlg + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + Snap2GridDlg + + 499,394 + wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + + Snap to Grid + + + + + + + bSizer3 + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Selected Model(s) to Snap to the Grid + 0 + + 0 + + + 0 + + 1 + m_comment + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + + 0 + + + bSizer31 + wxHORIZONTAL + none + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Grid + 0 + + 0 + + + 0 + + 1 + m_staticTextGrid + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + "1.0mm (39.37mils)" "0.5mm (19.69mils)" "0.25mm (9.84mils)" "0.1mm (3.94mils)" "2.54mm (100mils)" "1.27mm (50mils)" "0.635mm (25mils)" "0.508mm (20mils)" "0.254mm (10mils)" "0.127mm (5mils)" + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + -1,-1 + 0 + -1,-1 + 1 + m_comboBoxGrid + 1 + + + protected + 1 + + Resizable + 0 + 1 + -1,-1 + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 1.0mm (39.37mils) + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline1 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + GridOrigin reference + + 0 + + + 0 + + 1 + m_radioBtnGO + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + AuxOrigin reference + + 0 + + + 0 + + 1 + m_radioBtnAO + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline2 + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + ; ; forward_declare + 0 + + + + + + + + 5 + wxALIGN_RIGHT|wxEXPAND + 0 + + + bSizer1 + wxHORIZONTAL + none + + 5 + wxEXPAND + 1 + + 0 + protected + 0 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 0 + + 1 + + 1 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_OK + Apply + + 0 + + 0 + + + 0 + + 1 + m_buttonOK + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 0 + wxID_CANCEL + Cancel + + 0 + + 0 + + + 0 + + 1 + m_buttonCancel + 1 + + + protected + 1 + + + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + 5 + wxEXPAND + 1 + + + bSizer4 + wxVERTICAL + none + + + + + + diff --git a/Snap2Grid/Snap2GridDlg.py b/Snap2Grid/Snap2GridDlg.py new file mode 100644 index 0000000..55c4f1d --- /dev/null +++ b/Snap2Grid/Snap2GridDlg.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- + +########################################################################### +## Python code generated with wxFormBuilder (version Oct 26 2018) +## http://www.wxformbuilder.org/ +## +## PLEASE DO *NOT* EDIT THIS FILE! +########################################################################### + +import wx +import wx.xrc + +########################################################################### +## Class Snap2GridDlg +########################################################################### + +class Snap2GridDlg ( wx.Dialog ): + + def __init__( self, parent ): + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Snap to Grid", pos = wx.DefaultPosition, size = wx.Size( 499,394 ), style = wx.CAPTION|wx.CLOSE_BOX|wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER ) + + self.SetSizeHints( wx.DefaultSize, wx.DefaultSize ) + + bSizer3 = wx.BoxSizer( wx.VERTICAL ) + + self.m_comment = wx.StaticText( self, wx.ID_ANY, u"Selected Model(s) to Snap\nto the Grid", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_comment.Wrap( -1 ) + + bSizer3.Add( self.m_comment, 0, wx.ALL|wx.EXPAND, 5 ) + + bSizer31 = wx.BoxSizer( wx.HORIZONTAL ) + + self.m_staticTextGrid = wx.StaticText( self, wx.ID_ANY, u"Grid", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_staticTextGrid.Wrap( -1 ) + + bSizer31.Add( self.m_staticTextGrid, 1, wx.ALL|wx.EXPAND, 5 ) + + m_comboBoxGridChoices = [ u"1.0mm (39.37mils)", u"0.5mm (19.69mils)", u"0.25mm (9.84mils)", u"0.1mm (3.94mils)", u"2.54mm (100mils)", u"1.27mm (50mils)", u"0.635mm (25mils)", u"0.508mm (20mils)", u"0.254mm (10mils)", u"0.127mm (5mils)" ] + self.m_comboBoxGrid = wx.ComboBox( self, wx.ID_ANY, u"1.0mm (39.37mils)", wx.DefaultPosition, wx.Size( -1,-1 ), m_comboBoxGridChoices, 0 ) + self.m_comboBoxGrid.SetSelection( 0 ) + bSizer31.Add( self.m_comboBoxGrid, 0, wx.ALL|wx.EXPAND, 5 ) + + + bSizer3.Add( bSizer31, 0, 0, 5 ) + + self.m_staticline1 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + bSizer3.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 ) + + self.m_radioBtnGO = wx.RadioButton( self, wx.ID_ANY, u"GridOrigin reference", wx.DefaultPosition, wx.DefaultSize, 0 ) + bSizer3.Add( self.m_radioBtnGO, 0, wx.ALL, 5 ) + + self.m_radioBtnAO = wx.RadioButton( self, wx.ID_ANY, u"AuxOrigin reference", wx.DefaultPosition, wx.DefaultSize, 0 ) + bSizer3.Add( self.m_radioBtnAO, 0, wx.ALL, 5 ) + + self.m_staticline2 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) + bSizer3.Add( self.m_staticline2, 0, wx.EXPAND |wx.ALL, 5 ) + + bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) + + + bSizer1.Add( ( 0, 0), 1, wx.EXPAND, 5 ) + + self.m_buttonOK = wx.Button( self, wx.ID_OK, u"Apply", wx.DefaultPosition, wx.DefaultSize, 0 ) + + self.m_buttonOK.SetDefault() + bSizer1.Add( self.m_buttonOK, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, 5 ) + + self.m_buttonCancel = wx.Button( self, wx.ID_CANCEL, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 ) + bSizer1.Add( self.m_buttonCancel, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, 5 ) + + + bSizer3.Add( bSizer1, 0, wx.ALIGN_RIGHT|wx.EXPAND, 5 ) + + bSizer4 = wx.BoxSizer( wx.VERTICAL ) + + + bSizer3.Add( bSizer4, 1, wx.EXPAND, 5 ) + + + self.SetSizer( bSizer3 ) + self.Layout() + + self.Centre( wx.BOTH ) + + def __del__( self ): + pass + + diff --git a/Snap2Grid/snap2grid.py b/Snap2Grid/snap2grid.py index 97edcbf..a8f98f4 100644 --- a/Snap2Grid/snap2grid.py +++ b/Snap2Grid/snap2grid.py @@ -8,6 +8,10 @@ #import snaptogrid; import importlib; importlib.reload(snaptogrid) +### plugins errors +#import pcbnew +#pcbnew.GetWizardsBackTrace() + __version__ = '1.0.1' import sys, os import pcbnew @@ -17,11 +21,11 @@ from pcbnew import * use_grid_origin = True -gridReference = 2.54 #1.27 #mm pcbnew.FromMM(1.0) #0.1mm +gridReference = 0.1 #1.27 #mm pcbnew.FromMM(1.0) #0.1mm gridSizeMM = gridReference -#from . import Send2GridDlg +from . import Snap2GridDlg sys.path.append(os.path.dirname(__file__)) @@ -32,36 +36,36 @@ def wxLogDebug(msg,dbg): wx.LogMessage(msg) # -#class Snap2Grid_Dlg(Snap2GridDlg.Snap2GridDlg): -# # 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): -# if wx.__version__ < '4.0': -# self.SetSizeHintsSz(sz1, sz2) -# else: -# super(RoundTrack_Dlg, self).SetSizeHints(sz1, sz2) -# -# # def onDeleteClick(self, event): -# # return self.EndModal(wx.ID_DELETE) -# # -# # def onConnectClick(self, event): -# # return self.EndModal(wx.ID_REVERT) -# -# def __init__(self, parent): -# import wx -# Send2GridDlg.Send2GridDlg.__init__(self, parent) -# #self.GetSizer().Fit(self) -# self.SetMinSize(self.GetSize()) -# #self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick) -# #self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick) -# #if wx.__version__ < '4.0': -# # 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" ) -# #else: -# # 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_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) -# +class Snap2Grid_Dlg(Snap2GridDlg.Snap2GridDlg): + # 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): + if wx.__version__ < '4.0': + self.SetSizeHintsSz(sz1, sz2) + else: + super(Snap2Grid_Dlg, self).SetSizeHints(sz1, sz2) + + # def onDeleteClick(self, event): + # return self.EndModal(wx.ID_DELETE) + # + # def onConnectClick(self, event): + # return self.EndModal(wx.ID_REVERT) + + def __init__(self, parent): + import wx + Snap2GridDlg.Snap2GridDlg.__init__(self, parent) + #self.GetSizer().Fit(self) + self.SetMinSize(self.GetSize()) + #self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick) + #self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick) + #if wx.__version__ < '4.0': + # 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" ) + #else: + # 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_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) + # Python plugin stuff class snap_to_grid( pcbnew.ActionPlugin ): """ @@ -77,7 +81,7 @@ class snap_to_grid( pcbnew.ActionPlugin ): self.description should be a comprehensive description of the plugin """ - self.name = "Snap Selected Module(s) to Grid\nversion "+__version__ + self.name = "Snap Selected Modules to Grid \nversion "+__version__ self.category = "Modify PCB" self.description = "Automaticaly Snap Selected Module(s) to Grid on an existing PCB" #self.pcbnew_icon_support = hasattr(self, "show_toolbar_button") @@ -89,111 +93,131 @@ class snap_to_grid( pcbnew.ActionPlugin ): #self.pcb = GetBoard() import sys,os #mm_ius = 1000000.0 + _pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0] + #aParameters = RoundTrackDlg(None) + aParameters = Snap2Grid_Dlg(_pcbnew_frame) + gridIndex = aParameters.m_comboBoxGrid.FindString('0.1mm (3.94mils)') + aParameters.m_comboBoxGrid.SetSelection(gridIndex) + #aParameters.m_comboBoxGrid.Append('0.1mm (3.94mils)') + aParameters.m_radioBtnGO.SetValue(True) + aParameters.Show() - pcb = pcbnew.GetBoard() - gridOrigin = pcb.GetGridOrigin() - auxOrigin = pcb.GetAuxOrigin() - content='' - locked_fp='' - #wxPoint(77470000, 135890000) - for module in pcb.GetModules(): - if module.IsSelected(): - if use_grid_origin: - mpx = module.GetPosition().x - gridOrigin.x - mpy = module.GetPosition().y - gridOrigin.y - print(mpx,mpy) - mpxOnG = int(mpx/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.x - mpyOnG = int(mpy/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.y - print(mpxOnG,mpyOnG) - locked='' - if not module.IsLocked(): - module.SetPosition(wxPoint(mpxOnG,mpyOnG)) - else: - locked='LOCKED' - X_POS=str(module.GetPosition().x) # - gridOrigin.x) - #X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - gridOrigin.x )) - X_POS="{0:<11}".format(X_POS) - Y_POS=str(module.GetPosition().y) # - gridOrigin.y) - Y_POS="{0:<11}".format(Y_POS) - ## mpOnGx = PutOnGridMM(module.GetPosition().x, gridSizeMM) - ## mpOnGy = PutOnGridMM(module.GetPosition().y, gridSizeMM) - ## module.SetPosition(wxPoint(mpOnGx,mpOnGy)) - #module.SetPosition(wxPoint(mpOnGx+FromMM(100.0),mpOnGy+FromMM(2.0))) - #module.SetOrientation(10) - #Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - gridOrigin.y)) - # else: - # mpx = module.GetPosition().x - auxOrigin().x - # mpy = module.GetPosition().y - auxOrigin().y - # X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - auxOrigin().x )) - # X_POS="{0:<11}".format(X_POS) - # Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - auxOrigin().y)) - # Y_POS="{0:<11}".format(Y_POS) - Reference="{0:<10}".format(str(module.GetReference())) - Value = str(module.GetValue()) - Value=(Value[:17] + '..') if len(Value) > 19 else Value - Value="{0:<20}".format(Value) - Rotation='{0:.1f}'.format((module.GetOrientation()/10)) - Rotation="{0:>6}".format(Rotation)+' ' - if module.GetLayer() == 0: - Layer=" top" - else: - Layer=" bottom" - #Side="## Side :"+Layer+lsep - Layer="{0:<10}".format(Layer) - content+=Reference - if 'LOCKED' in locked: - locked_fp+=Reference + ' LOCKED'+'\n' #os.linesep - #content+=Value - content+=X_POS - content+=Y_POS - #content+=str(mpOnGx) - #content+=str(mpOnGy) - content+=str(mpxOnG) - content+=str(mpyOnG) - content+=Layer+'\n' #os.linesep - if len(content)>0: - content+=str(pcbnew.FromMM(gridReference)) - wxLogDebug(content,debug) - if len (locked_fp)>0: - locked_fp+='\n'+'NOT Moved' - wxLogDebug(locked_fp,True) + modal_result = aParameters.ShowModal() + if modal_result == wx.ID_OK: + grid = aParameters.m_comboBoxGrid.GetStringSelection() + gridSizeMM = float(grid.split('mm')[0]) + if aParameters.m_radioBtnGO.GetValue(): + use_grid_origin = True + else: + use_grid_origin = False + snap2grid(gridSizeMM,use_grid_origin) else: - wxLogDebug('No Modules Selected',True) - Refresh() - #return content + None # Cancel +## - #if 0: - # #from https://github.com/MitjaNemec/Kicad_action_plugins - # #hack wxFormBuilder py2/py3 - # _pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0] - # #aParameters = RoundTrackDlg(None) - # aParameters = RoundTrack_Dlg(_pcbnew_frame) - # #aParameters = RoundTrack_DlgEx(_pcbnew_frame) - # aParameters.Show() - # #end hack - # aParameters.m_distanceMM.SetValue("5") - # aParameters.m_segments.SetValue("16") - # aParameters.m_bitmap1.SetBitmap(wx.Bitmap( os.path.join(os.path.dirname(os.path.realpath(__file__)), "round_track_help.png") ) ) - # modal_result = aParameters.ShowModal() - # segments = self.CheckSegmentsInput( - # aParameters.m_segments.GetValue(), "number of segments") - # distI = FromMM(self.CheckDistanceInput(aParameters.m_distanceMM.GetValue(), "distance from intersection")) - # if segments is not None and distI is not None: - # if modal_result == wx.ID_OK: - # Round_Selection(pcb, distI, segments) - # elif modal_result == wx.ID_DELETE: - # Delete_Segments(pcb) - # #wx.LogMessage('Round Segments on Track Net Deleted') - # elif modal_result == wx.ID_REVERT: - # wxLogDebug('Connecting Tracks',debug) - # Connect_Segments(pcb) - # else: - # None # Cancel - # else: - # None # Invalid input - # aParameters.Destroy() - +def snap2grid(gridSizeMM,use_grid_origin): + pcb = pcbnew.GetBoard() + gridOrigin = pcb.GetGridOrigin() + auxOrigin = pcb.GetAuxOrigin() + content='' + locked_fp='' + #wxPoint(77470000, 135890000) + for module in pcb.GetModules(): + if module.IsSelected(): + if use_grid_origin: + mpx = module.GetPosition().x - gridOrigin.x + mpy = module.GetPosition().y - gridOrigin.y + #print(mpx,mpy) + mpxOnG = int(mpx/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.x + mpyOnG = int(mpy/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.y + #print(mpxOnG,mpyOnG) + locked='' + if not module.IsLocked(): + module.SetPosition(wxPoint(mpxOnG,mpyOnG)) + else: + locked='LOCKED' + X_POS=str(module.GetPosition().x) # - gridOrigin.x) + #X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - gridOrigin.x )) + X_POS="{0:<11}".format(X_POS) + Y_POS=str(module.GetPosition().y) # - gridOrigin.y) + Y_POS="{0:<11}".format(Y_POS) + ## mpOnGx = PutOnGridMM(module.GetPosition().x, gridSizeMM) + ## mpOnGy = PutOnGridMM(module.GetPosition().y, gridSizeMM) + ## module.SetPosition(wxPoint(mpOnGx,mpOnGy)) + #module.SetPosition(wxPoint(mpOnGx+FromMM(100.0),mpOnGy+FromMM(2.0))) + #module.SetOrientation(10) + #Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - gridOrigin.y)) + else: # AuxOrigin + mpx = module.GetPosition().x - auxOrigin.x + mpy = module.GetPosition().y - auxOrigin.y + #print(mpx,mpy) + mpxOnG = int(mpx/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ auxOrigin.x + mpyOnG = int(mpy/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ auxOrigin.y + #print(mpxOnG,mpyOnG) + locked='' + if not module.IsLocked(): + module.SetPosition(wxPoint(mpxOnG,mpyOnG)) + else: + locked='LOCKED' + X_POS=str(module.GetPosition().x) # - gridOrigin.x) + #X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - gridOrigin.x )) + X_POS="{0:<11}".format(X_POS) + Y_POS=str(module.GetPosition().y) # - gridOrigin.y) + Y_POS="{0:<11}".format(Y_POS) + ## mpOnGx = PutOnGridMM(module.GetPosition().x, gridSizeMM) + ## mpOnGy = PutOnGridMM(module.GetPosition().y, gridSizeMM) + ## module.SetPosition(wxPoint(mpOnGx,mpOnGy)) + #module.SetPosition(wxPoint(mpOnGx+FromMM(100.0),mpOnGy+FromMM(2.0))) + #module.SetOrientation(10) + #Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - gridOrigin.y)) + Reference="{0:<10}".format(str(module.GetReference())) + Value = str(module.GetValue()) + Value=(Value[:17] + '..') if len(Value) > 19 else Value + Value="{0:<20}".format(Value) + Rotation='{0:.1f}'.format((module.GetOrientation()/10)) + Rotation="{0:>6}".format(Rotation)+' ' + if module.GetLayer() == 0: + Layer=" top" + else: + Layer=" bottom" + #Side="## Side :"+Layer+lsep + Layer="{0:<10}".format(Layer) + content+=Reference + if 'LOCKED' in locked: + locked_fp+=Reference + ' LOCKED'+'\n' #os.linesep + #content+=Value + content+=X_POS + content+=Y_POS + #content+=str(mpOnGx) + #content+=str(mpOnGy) + content+=str(mpxOnG) + content+=str(mpyOnG) + content+=Layer+'\n' #os.linesep + if len(content)>0: + content+=str(pcbnew.FromMM(gridSizeMM))+'\n' + info='Snapped to grid: '+str(gridSizeMM)+'mm\n' + if use_grid_origin: + content+="Using GridOrigin as Ref"+'\n' + info+="Using GridOrigin as Ref"+'\n' + else: + content+="Using AuxOrigin as Ref"+'\n' + info+="Using AuxOrigin as Ref"+'\n' + if debug: + wxLogDebug(content,debug) + #else: + wxLogDebug(info,True) + if len (locked_fp)>0: + locked_fp+='\n'+'NOT Moved (Locked fp)' + locked_fp+='\n'+info + wxLogDebug(locked_fp,True) + else: + wxLogDebug(info,True) + else: + wxLogDebug('No Modules Selected',True) + Refresh() + #return content + # wxLogDebug('showing Selected Tracks',debug) # wx.LogMessage('Select Tracks to calculate the Length\nor One Pad to select connected Tracks') # diff --git a/Snap2Grid/snap2grid.py.bak b/Snap2Grid/snap2grid.py.bak new file mode 100644 index 0000000..15ecdfc --- /dev/null +++ b/Snap2Grid/snap2grid.py.bak @@ -0,0 +1,200 @@ +# -*- coding: utf-8 -*- +# +# A script to Snap modules to selected Grid for kicad_pcb +# requirements: KiCAD pcbnew >= 4.0 +# copyright Maurice easyw +# +# + +#import snaptogrid; import importlib; importlib.reload(snaptogrid) + +__version__ = '1.0.1' +import sys, os +import pcbnew +import datetime +import wx +from pcbnew import * + +use_grid_origin = True + +gridReference = 2.54 #1.27 #mm pcbnew.FromMM(1.0) #0.1mm + +gridSizeMM = gridReference + +#from . import Send2GridDlg + +sys.path.append(os.path.dirname(__file__)) + +debug = False +def wxLogDebug(msg,dbg): + """printing messages only if show is omitted or True""" + if dbg == True: + wx.LogMessage(msg) +# + +#class Snap2Grid_Dlg(Snap2GridDlg.Snap2GridDlg): +# # 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): +# if wx.__version__ < '4.0': +# self.SetSizeHintsSz(sz1, sz2) +# else: +# super(RoundTrack_Dlg, self).SetSizeHints(sz1, sz2) +# +# # def onDeleteClick(self, event): +# # return self.EndModal(wx.ID_DELETE) +# # +# # def onConnectClick(self, event): +# # return self.EndModal(wx.ID_REVERT) +# +# def __init__(self, parent): +# import wx +# Send2GridDlg.Send2GridDlg.__init__(self, parent) +# #self.GetSizer().Fit(self) +# self.SetMinSize(self.GetSize()) +# #self.m_buttonDelete.Bind(wx.EVT_BUTTON, self.onDeleteClick) +# #self.m_buttonReconnect.Bind(wx.EVT_BUTTON, self.onConnectClick) +# #if wx.__version__ < '4.0': +# # 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" ) +# #else: +# # 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_buttonRound.SetToolTip( u"Select two connected Tracks to round the corner\nThen choose distance from intersection and the number of segments" ) +# +# Python plugin stuff +class snap_to_grid( pcbnew.ActionPlugin ): + """ + A plugin to Snap modules to selected Grid for kicad_pcb + requirements: KiCAD pcbnew >= 4.0 + + """ + def defaults( self ): + """ + Method defaults must be redefined + self.name should be the menu label to use + self.category should be the category (not yet used) + self.description should be a comprehensive description + of the plugin + """ + self.name = "Snap Selected Module(s) to Grid\nversion "+__version__ + self.category = "Modify PCB" + self.description = "Automaticaly Snap Selected Module(s) to Grid on an existing PCB" + #self.pcbnew_icon_support = hasattr(self, "show_toolbar_button") + self.show_toolbar_button = True + self.icon_file_name = os.path.join(os.path.dirname(__file__), './snap2grid.png') + # + + def Run(self): + #self.pcb = GetBoard() + import sys,os + #mm_ius = 1000000.0 + + pcb = pcbnew.GetBoard() + gridOrigin = pcb.GetGridOrigin() + auxOrigin = pcb.GetAuxOrigin() + content='' + locked_fp='' + #wxPoint(77470000, 135890000) + for module in pcb.GetModules(): + if module.IsSelected(): + if use_grid_origin: + mpx = module.GetPosition().x - gridOrigin.x + mpy = module.GetPosition().y - gridOrigin.y + print(mpx,mpy) + mpxOnG = int(mpx/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.x + mpyOnG = int(mpy/FromMM(gridSizeMM))*FromMM(gridSizeMM)+ gridOrigin.y + print(mpxOnG,mpyOnG) + locked='' + if not module.IsLocked(): + module.SetPosition(wxPoint(mpxOnG,mpyOnG)) + else: + locked='LOCKED' + X_POS=str(module.GetPosition().x) # - gridOrigin.x) + #X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - gridOrigin.x )) + X_POS="{0:<11}".format(X_POS) + Y_POS=str(module.GetPosition().y) # - gridOrigin.y) + Y_POS="{0:<11}".format(Y_POS) + ## mpOnGx = PutOnGridMM(module.GetPosition().x, gridSizeMM) + ## mpOnGy = PutOnGridMM(module.GetPosition().y, gridSizeMM) + ## module.SetPosition(wxPoint(mpOnGx,mpOnGy)) + #module.SetPosition(wxPoint(mpOnGx+FromMM(100.0),mpOnGy+FromMM(2.0))) + #module.SetOrientation(10) + #Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - gridOrigin.y)) + # else: + # mpx = module.GetPosition().x - auxOrigin().x + # mpy = module.GetPosition().y - auxOrigin().y + # X_POS='{0:.4f}'.format(pcbnew.ToMM(module.GetPosition().x - auxOrigin().x )) + # X_POS="{0:<11}".format(X_POS) + # Y_POS='{0:.4f}'.format(-1*pcbnew.ToMM(module.GetPosition().y - auxOrigin().y)) + # Y_POS="{0:<11}".format(Y_POS) + Reference="{0:<10}".format(str(module.GetReference())) + Value = str(module.GetValue()) + Value=(Value[:17] + '..') if len(Value) > 19 else Value + Value="{0:<20}".format(Value) + Rotation='{0:.1f}'.format((module.GetOrientation()/10)) + Rotation="{0:>6}".format(Rotation)+' ' + if module.GetLayer() == 0: + Layer=" top" + else: + Layer=" bottom" + #Side="## Side :"+Layer+lsep + Layer="{0:<10}".format(Layer) + content+=Reference + if 'LOCKED' in locked: + locked_fp+=Reference + ' LOCKED'+'\n' #os.linesep + #content+=Value + content+=X_POS + content+=Y_POS + #content+=str(mpOnGx) + #content+=str(mpOnGy) + content+=str(mpxOnG) + content+=str(mpyOnG) + content+=Layer+'\n' #os.linesep + if len(content)>0: + content+=str(pcbnew.FromMM(gridReference)) + wxLogDebug(content,debug) + if len (locked_fp)>0: + locked_fp+='\n'+'NOT Moved' + wxLogDebug(locked_fp,True) + else: + wxLogDebug('No Modules Selected',True) + Refresh() + #return content + + #if 0: + # #from https://github.com/MitjaNemec/Kicad_action_plugins + # #hack wxFormBuilder py2/py3 + # _pcbnew_frame = [x for x in wx.GetTopLevelWindows() if x.GetTitle().lower().startswith('pcbnew')][0] + # #aParameters = RoundTrackDlg(None) + # aParameters = RoundTrack_Dlg(_pcbnew_frame) + # #aParameters = RoundTrack_DlgEx(_pcbnew_frame) + # aParameters.Show() + # #end hack + # aParameters.m_distanceMM.SetValue("5") + # aParameters.m_segments.SetValue("16") + # aParameters.m_bitmap1.SetBitmap(wx.Bitmap( os.path.join(os.path.dirname(os.path.realpath(__file__)), "round_track_help.png") ) ) + # modal_result = aParameters.ShowModal() + # segments = self.CheckSegmentsInput( + # aParameters.m_segments.GetValue(), "number of segments") + # distI = FromMM(self.CheckDistanceInput(aParameters.m_distanceMM.GetValue(), "distance from intersection")) + # if segments is not None and distI is not None: + # if modal_result == wx.ID_OK: + # Round_Selection(pcb, distI, segments) + # elif modal_result == wx.ID_DELETE: + # Delete_Segments(pcb) + # #wx.LogMessage('Round Segments on Track Net Deleted') + # elif modal_result == wx.ID_REVERT: + # wxLogDebug('Connecting Tracks',debug) + # Connect_Segments(pcb) + # else: + # None # Cancel + # else: + # None # Invalid input + # aParameters.Destroy() + + + # wxLogDebug('showing Selected Tracks',debug) + # wx.LogMessage('Select Tracks to calculate the Length\nor One Pad to select connected Tracks') +# +