Next small step in the CQ.py code cleanup.

This commit is contained in:
Jeremy Wright 2015-06-15 15:59:28 -04:00
parent 0c060925de
commit 7f0ef93868
4 changed files with 53 additions and 12 deletions

BIN
.coverage

Binary file not shown.

View File

@ -20,6 +20,7 @@
import time, math
from cadquery import *
from cadquery import selectors
from cadquery import exporters
class CQContext(object):
@ -389,7 +390,6 @@ class CQ(object):
will return the same as::
CQ(obj).faces("+Z")
"""
if self.parent:
return self.parent
@ -643,7 +643,7 @@ class CQ(object):
:type opts: dictionary, width and height
:return: a string that contains SVG that represents this item.
"""
return SVGexporter.getSVG(self.val().wrapped, opts)
return exporters.getSVG(self.val().wrapped, opts)
def exportSvg(self, fileName):
"""
@ -1093,6 +1093,15 @@ class Workplane(CQ):
"""
return self.line(0, distance, forConstruction)
def hLine(self, distance, forConstruction=False):
"""
Make a horizontal line from the current point the provided distance
:param float distance: (x) distance from current point
:return: the Workplane object with the current point at the end of the new line
"""
return self.line(distance, 0, forConstruction)
def vLineTo(self, yCoord, forConstruction=False):
"""
Make a vertical line from the current point to the provided y coordinate.
@ -1119,15 +1128,6 @@ class Workplane(CQ):
p = self._findFromPoint(True)
return self.lineTo(xCoord, p.y, forConstruction)
def hLine(self, distance, forConstruction=False):
"""
Make a horizontal line from the current point the provided distance
:param float distance: (x) distance from current point
:return: the Workplane object with the current point at the end of the new line
"""
return self.line(distance, 0, forConstruction)
#absolute move in current plane, not drawing
def moveTo(self, x=0, y=0):
"""

View File

@ -249,6 +249,7 @@ def getPaths(freeCadSVG):
else:
return ([],[])
def getSVG(shape,opts=None):
"""
Export a shape to SVG

View File

@ -88,6 +88,18 @@ class TestCadQuery(BaseTest):
self.assertEqual(12, len(r.Edges))
def testToSVG(self):
"""
Tests to make sure that a CadQuery object is converted correctly to SVG
"""
r = Workplane('XY').rect(5, 5).extrude(5)
r_str = r.toSvg()
# Make sure that a couple of sections from the SVG output make sense
self.assertTrue(r_str.index('path d=" M 2.35965 -2.27987 L 4.0114 -3.23936 "') > 0)
self.assertTrue(r_str.index('line x1="30" y1="-30" x2="58" y2="-15" stroke-width="3"') > 0)
def testCubePlugin(self):
"""
Tests a plugin that combines cubes together with a base
@ -556,7 +568,9 @@ class TestCadQuery(BaseTest):
self.saveModel(r)
def test2DDrawing(self):
"""Draw things like 2D lines and arcs, should be expanded later to include all 2D constructs"""
"""
Draw things like 2D lines and arcs, should be expanded later to include all 2D constructs
"""
s = Workplane(Plane.XY())
r = s.lineTo(1.0, 0.0) \
.lineTo(1.0, 1.0) \
@ -572,6 +586,32 @@ class TestCadQuery(BaseTest):
self.assertEqual(1, r.wires().size())
# Test the *LineTo functions
s = Workplane(Plane.XY())
r = s.hLineTo(1.0).vLineTo(1.0).hLineTo(0.0).close()
self.assertEqual(1, r.wire().size())
self.assertEqual(4, r.edges().size())
# Test the *Line functions
s = Workplane(Plane.XY())
r = s.hLine(1.0).vLine(1.0).hLine(-1.0).close()
self.assertEqual(1, r.wire().size())
self.assertEqual(4, r.edges().size())
# Test the move function
s = Workplane(Plane.XY())
r = s.move(1.0, 1.0).hLine(1.0).vLine(1.0).hLine(-1.0).close()
self.assertEqual(1, r.wire().size())
self.assertEqual(4, r.edges().size())
self.assertEqual((1.0, 1.0),
(r.vertices(selectors.NearestToPointSelector((0.0, 0.0, 0.0)))\
.first().val().X,
r.vertices(selectors.NearestToPointSelector((0.0, 0.0, 0.0)))\
.first().val().Y))
def testOccBottle(self):
"""
Make the OCC bottle example.