Cleaned out the tests folder. Added simple test gerber. Added simple unit test using the GUI.
This commit is contained in:
34
tests/other/destructor_test.py
Normal file
34
tests/other/destructor_test.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
|
||||
class MyObj():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
print "##### Destroyed ######"
|
||||
|
||||
|
||||
def parse():
|
||||
o = MyObj()
|
||||
raise Exception("Intentional Exception")
|
||||
|
||||
|
||||
class Example(QtGui.QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super(Example, self).__init__()
|
||||
|
||||
qbtn = QtGui.QPushButton('Raise', self)
|
||||
qbtn.clicked.connect(parse)
|
||||
|
||||
self.setWindowTitle('Quit button')
|
||||
self.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
ex = Example()
|
||||
sys.exit(app.exec_())
|
||||
8
tests/other/profile_gerber_parser.py
Normal file
8
tests/other/profile_gerber_parser.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
os.chdir('../')
|
||||
|
||||
from camlib import *
|
||||
|
||||
g = Gerber()
|
||||
g.parse_file(r'C:\Users\jpcaram\Dropbox\CNC\pcbcam\test_files\PlacaReles-F_Cu.gtl')
|
||||
|
||||
48
tests/other/test_excellon_1.py
Normal file
48
tests/other/test_excellon_1.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun Jan 05 13:30:47 2014
|
||||
|
||||
@author: jpcaram
|
||||
"""
|
||||
|
||||
import os
|
||||
os.chdir('../')
|
||||
|
||||
from camlib import *
|
||||
#from matplotlib.figure import Figure
|
||||
from matplotlib import pyplot
|
||||
|
||||
# Gerber. To see if the Excellon is correct
|
||||
project_dir = "tests/"
|
||||
gerber_filename = project_dir + "KiCad_Squarer-F_Cu.gtl"
|
||||
g = Gerber()
|
||||
g.parse_file(gerber_filename)
|
||||
g.create_geometry()
|
||||
|
||||
excellon_filename = project_dir + "KiCad_Squarer.drl"
|
||||
ex = Excellon()
|
||||
ex.parse_file(excellon_filename)
|
||||
ex.create_geometry()
|
||||
|
||||
#fig = Figure()
|
||||
fig = pyplot.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
ax.set_aspect(1)
|
||||
|
||||
# Plot gerber
|
||||
for geo in g.solid_geometry:
|
||||
x, y = geo.exterior.coords.xy
|
||||
plot(x, y, 'k-')
|
||||
for ints in geo.interiors:
|
||||
x, y = ints.coords.xy
|
||||
ax.plot(x, y, 'k-')
|
||||
|
||||
# Plot excellon
|
||||
for geo in ex.solid_geometry:
|
||||
x, y = geo.exterior.coords.xy
|
||||
plot(x, y, 'r-')
|
||||
for ints in geo.interiors:
|
||||
x, y = ints.coords.xy
|
||||
ax.plot(x, y, 'g-')
|
||||
|
||||
fig.show()
|
||||
37
tests/other/test_fcrts.py
Normal file
37
tests/other/test_fcrts.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from camlib import *
|
||||
from shapely.geometry import LineString, LinearRing
|
||||
|
||||
s = FlatCAMRTreeStorage()
|
||||
|
||||
geoms = [
|
||||
LinearRing(((0.5699056603773586, 0.7216037735849057),
|
||||
(0.9885849056603774, 0.7216037735849057),
|
||||
(0.9885849056603774, 0.6689622641509434),
|
||||
(0.5699056603773586, 0.6689622641509434),
|
||||
(0.5699056603773586, 0.7216037735849057))),
|
||||
LineString(((0.8684952830188680, 0.6952830188679245),
|
||||
(0.8680655198743615, 0.6865349890935113),
|
||||
(0.8667803692948564, 0.6778712076279851),
|
||||
(0.8646522079829676, 0.6693751114229638),
|
||||
(0.8645044888670096, 0.6689622641509434))),
|
||||
LineString(((0.9874952830188680, 0.6952830188679245),
|
||||
(0.9864925023483531, 0.6748709493942936),
|
||||
(0.9856160316877274, 0.6689622641509434))),
|
||||
|
||||
]
|
||||
|
||||
for geo in geoms:
|
||||
s.insert(geo)
|
||||
|
||||
current_pt = (0, 0)
|
||||
pt, geo = s.nearest(current_pt)
|
||||
while geo is not None:
|
||||
print pt, geo
|
||||
print "OBJECTS BEFORE:", s.objects
|
||||
|
||||
#geo.coords = list(geo.coords[::-1])
|
||||
s.remove(geo)
|
||||
|
||||
print "OBJECTS AFTER:", s.objects
|
||||
current_pt = geo.coords[-1]
|
||||
pt, geo = s.nearest(current_pt)
|
||||
47
tests/other/test_plotg.py
Normal file
47
tests/other/test_plotg.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from shapely.geometry import LineString, Polygon
|
||||
from shapely.ops import cascaded_union, unary_union
|
||||
from matplotlib.pyplot import plot, subplot, show
|
||||
from camlib import *
|
||||
|
||||
|
||||
def plotg2(geo, solid_poly=False, color="black", linestyle='solid'):
|
||||
|
||||
try:
|
||||
for sub_geo in geo:
|
||||
plotg2(sub_geo, solid_poly=solid_poly, color=color, linestyle=linestyle)
|
||||
except TypeError:
|
||||
if type(geo) == Polygon:
|
||||
if solid_poly:
|
||||
patch = PolygonPatch(geo,
|
||||
#facecolor="#BBF268",
|
||||
facecolor=color,
|
||||
edgecolor="#006E20",
|
||||
alpha=0.5,
|
||||
zorder=2)
|
||||
ax = subplot(111)
|
||||
ax.add_patch(patch)
|
||||
else:
|
||||
x, y = geo.exterior.coords.xy
|
||||
plot(x, y, color=color, linestyle=linestyle)
|
||||
for ints in geo.interiors:
|
||||
x, y = ints.coords.xy
|
||||
plot(x, y, color=color, linestyle=linestyle)
|
||||
|
||||
if type(geo) == LineString or type(geo) == LinearRing:
|
||||
x, y = geo.coords.xy
|
||||
plot(x, y, color=color, linestyle=linestyle)
|
||||
|
||||
if type(geo) == Point:
|
||||
x, y = geo.coords.xy
|
||||
plot(x, y, 'o')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
p = Polygon([[0, 0], [0, 5], [5, 5], [5, 0]])
|
||||
paths = [
|
||||
LineString([[0.5, 2], [2, 4.5]]),
|
||||
LineString([[2, 0.5], [4.5, 2]])
|
||||
]
|
||||
plotg2(p, solid_poly=True)
|
||||
plotg2(paths, linestyle="dashed")
|
||||
show()
|
||||
24
tests/other/test_rt.py
Normal file
24
tests/other/test_rt.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from rtree import index as rtindex
|
||||
|
||||
def pt2rect(pt):
|
||||
return pt[0], pt[1], pt[0], pt[1]
|
||||
|
||||
pts = [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
|
||||
|
||||
p = rtindex.Property()
|
||||
p.buffering_capacity = 1
|
||||
p.dimension = 2
|
||||
rt = rtindex.Index(properties=p)
|
||||
#rt = rtindex.Index()
|
||||
|
||||
# If interleaved is True, the coordinates must be in
|
||||
# the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax].
|
||||
print rt.interleaved
|
||||
|
||||
[rt.add(0, pt2rect(pt)) for pt in pts]
|
||||
print [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
|
||||
|
||||
for pt in pts:
|
||||
rt.delete(0, pt2rect(pt))
|
||||
print pt2rect(pt), [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
|
||||
|
||||
Reference in New Issue
Block a user