first Snap2Grid release
This commit is contained in:
2
Snap2Grid/__init__.py
Normal file
2
Snap2Grid/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from .snap2grid import snap_to_grid
|
||||||
|
snap_to_grid().register()
|
BIN
Snap2Grid/snap2grid.png
Normal file
BIN
Snap2Grid/snap2grid.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
200
Snap2Grid/snap2grid.py
Normal file
200
Snap2Grid/snap2grid.py
Normal file
@ -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')
|
||||||
|
#
|
||||||
|
|
242
Snap2Grid/snap2grid.svg
Normal file
242
Snap2Grid/snap2grid.svg
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
height="26"
|
||||||
|
width="26"
|
||||||
|
version="1.1"
|
||||||
|
id="svg2"
|
||||||
|
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||||
|
sodipodi:docname="snap2grid.svg"
|
||||||
|
inkscape:export-filename="/home/mau/.kicad_plugins/kicad-action-tools/Snap2Grid/snap2grid.png"
|
||||||
|
inkscape:export-xdpi="118.15385"
|
||||||
|
inkscape:export-ydpi="118.15385">
|
||||||
|
<metadata
|
||||||
|
id="metadata72">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<defs
|
||||||
|
id="defs70" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1009"
|
||||||
|
id="namedview68"
|
||||||
|
showgrid="true"
|
||||||
|
inkscape:snap-grids="true"
|
||||||
|
inkscape:snap-to-guides="true"
|
||||||
|
inkscape:zoom="8.1181296"
|
||||||
|
inkscape:cx="-15.991654"
|
||||||
|
inkscape:cy="14.972949"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg2">
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid3049"
|
||||||
|
empspacing="1"
|
||||||
|
visible="true"
|
||||||
|
enabled="true"
|
||||||
|
snapvisiblegridlinesonly="true"
|
||||||
|
spacingx="0.5"
|
||||||
|
spacingy="0.5"
|
||||||
|
originx="0"
|
||||||
|
originy="0" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10"
|
||||||
|
d="m 5.5,4 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-9"
|
||||||
|
d="m 11.5,4 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-4"
|
||||||
|
d="m 17.5,4 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-7"
|
||||||
|
d="m 23.5,4 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-8"
|
||||||
|
d="m 5.5,10 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-9-3"
|
||||||
|
d="m 11.5,10 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-4-8"
|
||||||
|
d="m 17.5,10 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-7-5"
|
||||||
|
d="m 23.5,10 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-71"
|
||||||
|
d="m 5.5,16 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#c80000;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-9-33"
|
||||||
|
d="m 12,16 a 2,2.0030045 0 0 1 -4,0 2,2.0030045 0 1 1 4,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-4-3"
|
||||||
|
d="m 17.5,16 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-7-8"
|
||||||
|
d="m 23.5,16 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-3"
|
||||||
|
d="m 5.5,22 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-9-5"
|
||||||
|
d="m 11.5,22 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-4-6"
|
||||||
|
d="m 17.5,22 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path10-7-59"
|
||||||
|
d="m 23.5,22 a 1.5,1.5022534 0 0 1 -3,0 1.5,1.5022534 0 1 1 3,0 z" />
|
||||||
|
<path
|
||||||
|
d="M 11,7 A 1,1.0015023 0 0 1 9,7 1,1.0015023 0 1 1 11,7 z"
|
||||||
|
id="path3811"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1" />
|
||||||
|
<path
|
||||||
|
style="fill:#c80000;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path3813"
|
||||||
|
d="m 11,13 a 1,1.0015023 0 0 1 -2,0 1,1.0015023 0 1 1 2,0 z" />
|
||||||
|
<path
|
||||||
|
d="m 11,19 a 1,1.0015023 0 0 1 -2,0 1,1.0015023 0 1 1 2,0 z"
|
||||||
|
id="path3815"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#c80000;fill-rule:evenodd;fill-opacity:1" />
|
||||||
|
<path
|
||||||
|
style="fill:#c80000;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path3817"
|
||||||
|
d="m 8,16 a 1,1.0015023 0 0 1 -2,0 1,1.0015023 0 1 1 2,0 z" />
|
||||||
|
<path
|
||||||
|
d="m 14,16 a 1,1.0015023 0 0 1 -2,0 1,1.0015023 0 1 1 2,0 z"
|
||||||
|
id="path3819"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:#c80000;fill-rule:evenodd;fill-opacity:1" />
|
||||||
|
<path
|
||||||
|
style="fill:#333333;fill-rule:evenodd;fill-opacity:1"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path3821"
|
||||||
|
d="m 20,16 a 1,1.0015023 0 0 1 -2,0 1,1.0015023 0 1 1 2,0 z" />
|
||||||
|
<g
|
||||||
|
transform="matrix(0.67334578,0,0,0.67334578,6.072015,-0.80029514)"
|
||||||
|
id="g4164">
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="rect51"
|
||||||
|
d="m 1.5380859,6.5039062 v 4.6249998 a 2.2240581,1.9589449 0 0 1 0,3.822266 V 20.59375 H 24.461914 V 6.5039062 Z"
|
||||||
|
style="fill:#e6e6e6;stroke:#545454;stroke-width:0.97711289;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<g
|
||||||
|
transform="translate(-0.53360319)"
|
||||||
|
id="g3983">
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="4.5123401"
|
||||||
|
x="-8.5317764"
|
||||||
|
id="rect73" />
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="11.451617"
|
||||||
|
x="-8.5076618"
|
||||||
|
id="rect73-5" />
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="18.488895"
|
||||||
|
x="-8.5498009"
|
||||||
|
id="rect73-56" />
|
||||||
|
</g>
|
||||||
|
<g
|
||||||
|
id="g3983-1"
|
||||||
|
transform="translate(-0.53360319,16.090848)">
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="4.5123401"
|
||||||
|
x="-8.5317764"
|
||||||
|
id="rect73-0" />
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="11.451617"
|
||||||
|
x="-8.5076618"
|
||||||
|
id="rect73-5-4" />
|
||||||
|
<rect
|
||||||
|
style="fill:#00c921;fill-opacity:1;stroke:#545454;stroke-width:0.93241322;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
transform="rotate(-90)"
|
||||||
|
height="4.0659709"
|
||||||
|
width="6.0590835"
|
||||||
|
y="18.488895"
|
||||||
|
x="-8.5498009"
|
||||||
|
id="rect73-56-9" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 8.6 KiB |
96
Snap2Grid/snaptogrid_script.py
Normal file
96
Snap2Grid/snaptogrid_script.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# -*- 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)
|
||||||
|
import sys, os
|
||||||
|
import pcbnew
|
||||||
|
import datetime
|
||||||
|
import wx
|
||||||
|
from pcbnew import *
|
||||||
|
|
||||||
|
use_grid_origin = True
|
||||||
|
gridReference = 0.127 #1.27 #mm pcbnew.FromMM(1.0) #0.1mm
|
||||||
|
|
||||||
|
|
||||||
|
# def PutOnGridMM(value, gridSizeMM):
|
||||||
|
# thresh = FromMM(gridSizeMM)
|
||||||
|
# return round(value/thresh)*thresh
|
||||||
|
#
|
||||||
|
# def PutOnGridMils(value, gridSizeMils):
|
||||||
|
# thresh = FromMils(gridSizeMils)
|
||||||
|
# return round(value/thresh)*thresh
|
||||||
|
#def SetPosition(self, p):
|
||||||
|
# """SetPosition(wxRect self, wxPoint p)"""
|
||||||
|
# return _pcbnew.wxRect_SetPosition(self, p)
|
||||||
|
|
||||||
|
|
||||||
|
def Snap2Grid(gridSizeMM,use_grid_origin):
|
||||||
|
import sys,os
|
||||||
|
#mm_ius = 1000000.0
|
||||||
|
|
||||||
|
pcb = pcbnew.GetBoard()
|
||||||
|
gridOrigin = pcb.GetGridOrigin()
|
||||||
|
auxOrigin = pcb.GetAuxOrigin()
|
||||||
|
content=''
|
||||||
|
#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)
|
||||||
|
module.SetPosition(wxPoint(mpxOnG,mpyOnG))
|
||||||
|
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
|
||||||
|
#content+=Value
|
||||||
|
content+=X_POS
|
||||||
|
content+=Y_POS
|
||||||
|
#content+=str(mpOnGx)
|
||||||
|
#content+=str(mpOnGy)
|
||||||
|
content+=str(mpxOnG)
|
||||||
|
content+=str(mpyOnG)
|
||||||
|
content+=Layer+os.linesep
|
||||||
|
content+=str(pcbnew.FromMM(gridReference))
|
||||||
|
Refresh()
|
||||||
|
return content
|
||||||
|
|
||||||
|
reply=Snap2Grid(gridReference,use_grid_origin)
|
||||||
|
#LogMsg=reply
|
||||||
|
wx.LogMessage(reply)
|
@ -9,3 +9,6 @@ from . import FabricationPositions
|
|||||||
from . import MoveToLayer
|
from . import MoveToLayer
|
||||||
|
|
||||||
from . import PcbToDxf
|
from . import PcbToDxf
|
||||||
|
|
||||||
|
from . import Snap2Grid
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user