From 92b07d059d58b3278f110403d838d026728ba9ea Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Fri, 4 May 2018 22:59:29 -0400 Subject: [PATCH] Revert "Updating CadQuery library to include sagittaArc changes." This reverts commit 19994ffd488224d0eb9540e083a7cbeab99d4db7. --- Libs/cadquery/.travis.yml | 4 +- Libs/cadquery/appveyor.yml | 2 +- Libs/cadquery/cadquery/cq.py | 81 ++----------------- .../FreeCAD/Ex005_Extruded_Lines_and_Arcs.py | 19 +---- Libs/cadquery/tests/TestCadQuery.py | 47 ----------- 5 files changed, 13 insertions(+), 140 deletions(-) diff --git a/Libs/cadquery/.travis.yml b/Libs/cadquery/.travis.yml index 7e00eba..d61778e 100644 --- a/Libs/cadquery/.travis.yml +++ b/Libs/cadquery/.travis.yml @@ -14,12 +14,12 @@ before_install: conda config --set always_yes yes --set changeps1 no; conda update -q conda; conda info -a; - conda create -y -q -n freecad_cq3 -c cadquery -c conda-forge freecad=0.17 python=3.6 pyparsing conda mock coverage codecov; + conda create -y -q -n freecad_cq3 -c freecad -c freecad/label/broken -c conda-forge freecad=0.17=py36_11 occt=7.2.0=occt7.2.0_0 python=3.6 pyparsing conda mock coverage codecov; source ~/miniconda/bin/activate freecad_cq3; else sudo add-apt-repository -y ppa:freecad-maintainers/freecad-stable; sudo apt-get update -qq; - sudo apt-get install -y freecad; + sudo apt-get install -y freecad freecad-doc; pip install -r requirements-dev.txt; pip install travis-sphinx; pip install sphinx_rtd_theme; diff --git a/Libs/cadquery/appveyor.yml b/Libs/cadquery/appveyor.yml index 427f287..892835b 100644 --- a/Libs/cadquery/appveyor.yml +++ b/Libs/cadquery/appveyor.yml @@ -12,7 +12,7 @@ install: - set "PATH=%MINICONDA_DIRNAME%;%MINICONDA_DIRNAME%\\Scripts;%PATH%" - conda config --set always_yes yes - conda update -q conda - - conda create --quiet --name cqtest -c cadquery -c conda-forge python=%PYTHON_VERSION% freecad=0.17 python=3.6 pyparsing mock coverage codecov + - conda create --quiet --name cqtest -c freecad -c freecad/label/broken -c conda-forge python=%PYTHON_VERSION% freecad=0.17=py36_vc14_13 occt=7.2.0 python=3.6 pyparsing mock coverage codecov - activate cqtest - python setup.py install diff --git a/Libs/cadquery/cadquery/cq.py b/Libs/cadquery/cadquery/cq.py index 9ed9d16..943f1fc 100644 --- a/Libs/cadquery/cadquery/cq.py +++ b/Libs/cadquery/cadquery/cq.py @@ -1320,77 +1320,17 @@ class Workplane(CQ): provide tangent arcs """ - startPoint = self._findFromPoint(False) - point1 = self.plane.toWorldCoords(point1) - point2 = self.plane.toWorldCoords(point2) + gstartPoint = self._findFromPoint(False) + gpoint1 = self.plane.toWorldCoords(point1) + gpoint2 = self.plane.toWorldCoords(point2) - arc = Edge.makeThreePointArc(startPoint, point1, point2) + arc = Edge.makeThreePointArc(gstartPoint, gpoint1, gpoint2) if not forConstruction: self._addPendingEdge(arc) return self.newObject([arc]) - def sagittaArc(self, endPoint, sag, forConstruction=False): - """ - Draw an arc from the current point to endPoint with an arc defined by the sag (sagitta). - - :param endPoint: end point for the arc - :type endPoint: 2-tuple, in workplane coordinates - :param sag: the sagitta of the arc - :type sag: float, perpendicular distance from arc center to arc baseline. - :return: a workplane with the current point at the end of the arc - - The sagitta is the distance from the center of the arc to the arc base. - Given that a closed contour is drawn clockwise; - A positive sagitta means convex arc and negative sagitta means concave arc. - See "https://en.wikipedia.org/wiki/Sagitta_(geometry)" for more information. - """ - - startPoint = self._findFromPoint(useLocalCoords=True) - endPoint = Vector(endPoint) - midPoint = endPoint.add(startPoint).multiply(0.5) - - sagVector = endPoint.sub(startPoint).normalized().multiply(abs(sag)) - if(sag > 0): - sagVector.x, sagVector.y = -sagVector.y, sagVector.x # Rotate sagVector +90 deg - else: - sagVector.x, sagVector.y = sagVector.y, -sagVector.x # Rotate sagVector -90 deg - - sagPoint = midPoint.add(sagVector) - - return self.threePointArc(sagPoint, endPoint, forConstruction) - - def radiusArc(self, endPoint, radius, forConstruction=False): - """ - Draw an arc from the current point to endPoint with an arc defined by the sag (sagitta). - - :param endPoint: end point for the arc - :type endPoint: 2-tuple, in workplane coordinates - :param radius: the radius of the arc - :type radius: float, the radius of the arc between start point and end point. - :return: a workplane with the current point at the end of the arc - - Given that a closed contour is drawn clockwise; - A positive radius means convex arc and negative radius means concave arc. - """ - - startPoint = self._findFromPoint(useLocalCoords=True) - endPoint = Vector(endPoint) - - # Calculate the sagitta from the radius - length = endPoint.sub(startPoint).Length / 2.0 - try: - sag = abs(radius) - math.sqrt(radius**2 - length**2) - except ValueError: - raise ValueError("Arc radius is not large enough to reach the end point.") - - # Return a sagittaArc - if radius > 0: - return self.sagittaArc(endPoint, sag, forConstruction) - else: - return self.sagittaArc(endPoint, -sag, forConstruction) - def rotateAndCopy(self, matrix): """ Makes a copy of all edges on the stack, rotates them according to the @@ -1798,14 +1738,7 @@ class Workplane(CQ): s = Workplane().lineTo(1,0).lineTo(1,1).close().extrude(0.2) """ - endPoint = self._findFromPoint(True) - startPoint = self.ctx.firstPoint - - # Check if there is a distance between startPoint and endPoint - # that is larger than what is considered a numerical error. - # If so; add a line segment between endPoint and startPoint - if endPoint.sub(startPoint).Length > 1e-6: - self.lineTo(self.ctx.firstPoint.x, self.ctx.firstPoint.y) + self.lineTo(self.ctx.firstPoint.x, self.ctx.firstPoint.y) # Need to reset the first point after closing a wire self.ctx.firstPoint=None @@ -2147,7 +2080,7 @@ class Workplane(CQ): :param path: A wire along which the pending wires will be swept :param boolean sweepAlongWires: False to create mutliple swept from wires on the chain along path - True to create only one solid swept along path with shape following the list of wires on the chain + True to create only one solid swept along path with shape following the list of wires on the chain :param boolean combine: True to combine the resulting solid with parent solids if found. :param boolean clean: call :py:meth:`clean` afterwards to have a clean shape :return: a CQ object with the resulting solid selected. @@ -2474,7 +2407,7 @@ class Workplane(CQ): :param path: A wire along which the pending wires will be swept :param boolean sweepAlongWires: False to create mutliple swept from wires on the chain along path - True to create only one solid swept along path with shape following the list of wires on the chain + True to create only one solid swept along path with shape following the list of wires on the chain :return:a FreeCAD solid, suitable for boolean operations """ diff --git a/Libs/cadquery/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py b/Libs/cadquery/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py index fa93a89..62b51a4 100644 --- a/Libs/cadquery/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py +++ b/Libs/cadquery/examples/FreeCAD/Ex005_Extruded_Lines_and_Arcs.py @@ -18,27 +18,14 @@ thickness = 0.25 # Thickness of the plate # half-way back to the origin in the X direction and 0.5 mm above where # the last line ended at. The arc then ends at (0.0, 1.0), which is 1.0 mm # above (in the Y direction) where our first line started from. -# 5. An arc is drawn from the last point that ends on (-0.5, 1.0), the sag of -# the curve 0.2 determines that the curve is concave with the midpoint 0.1 mm -# from the arc baseline. If the sag was -0.2 the arc would be convex. -# This convention is valid when the profile is drawn counterclockwise. -# The reverse is true if the profile is drawn clockwise. -# Clockwise: +sag => convex, -sag => concave -# Counterclockwise: +sag => concave, -sag => convex -# 6. An arc is drawn from the last point that ends on (-0.7, -0.2), the arc is -# determined by the radius of -1.5 mm. -# Clockwise: +radius => convex, -radius => concave -# Counterclockwise: +radius => concave, -radius => convex -# 7. close() is called to automatically draw the last line for us and close +# 5. close() is called to automatically draw the last line for us and close # the sketch so that it can be extruded. -# 7a. Without the close(), the 2D sketch will be left open and the extrude +# 5a. Without the close(), the 2D sketch will be left open and the extrude # operation will provide unpredictable results. -# 8. The 2D sketch is extruded into a solid object of the specified thickness. +# 6. The 2D sketch is extruded into a solid object of the specified thickness. result = cq.Workplane("front").lineTo(width, 0) \ .lineTo(width, 1.0) \ .threePointArc((1.0, 1.5), (0.0, 1.0)) \ - .sagittaArc((-0.5, 1.0), 0.2) \ - .radiusArc((-0.7, -0.2), -1.5) \ .close().extrude(thickness) # Displays the result of this script diff --git a/Libs/cadquery/tests/TestCadQuery.py b/Libs/cadquery/tests/TestCadQuery.py index 64cadd0..db329dc 100644 --- a/Libs/cadquery/tests/TestCadQuery.py +++ b/Libs/cadquery/tests/TestCadQuery.py @@ -867,20 +867,6 @@ class TestCadQuery(BaseTest): r.vertices(selectors.NearestToPointSelector((0.0, 0.0, 0.0)))\ .first().val().Y)) - # Test the sagittaArc and radiusArc functions - a1 = Workplane(Plane.YZ()).threePointArc((5, 1), (10, 0)) - a2 = Workplane(Plane.YZ()).sagittaArc((10, 0), -1) - a3 = Workplane(Plane.YZ()).threePointArc((6, 2), (12, 0)) - a4 = Workplane(Plane.YZ()).radiusArc((12, 0), -10) - - assert(a1.edges().first().val().geomType() == "CIRCLE") - assert(a2.edges().first().val().geomType() == "CIRCLE") - assert(a3.edges().first().val().geomType() == "CIRCLE") - assert(a4.edges().first().val().geomType() == "CIRCLE") - - assert(a1.edges().first().val().Length() == a2.edges().first().val().Length()) - assert(a3.edges().first().val().Length() == a4.edges().first().val().Length()) - def testLargestDimension(self): """ Tests the largestDimension function when no solids are on the stack and when there are @@ -1605,36 +1591,3 @@ class TestCadQuery(BaseTest): self.assertTupleAlmostEquals(delta.toTuple(), (0.,0.,2.*h), decimal_places) - - def testClose(self): - # Close without endPoint and startPoint coincide. - # Create a half-circle - a = Workplane(Plane.XY()).sagittaArc((10, 0), 2).close().extrude(2) - - # Close when endPoint and startPoint coincide. - # Create a double half-circle - b = Workplane(Plane.XY()).sagittaArc((10, 0), 2).sagittaArc((0, 0), 2).close().extrude(2) - - # The b shape shall have twice the volume of the a shape. - self.assertAlmostEqual(a.val().wrapped.Volume * 2.0, b.val().wrapped.Volume) - - # Testcase 3 from issue #238 - thickness = 3.0 - length = 10.0 - width = 5.0 - - obj1 = Workplane('XY', origin=(0, 0, -thickness / 2)) \ - .moveTo(length / 2, 0).threePointArc((0, width / 2), (-length / 2, 0)) \ - .threePointArc((0, -width / 2), (length / 2, 0)) \ - .close().extrude(thickness) - - os_x = 8.0 # Offset in X - os_y = -19.5 # Offset in Y - - obj2 = Workplane('YZ', origin=(os_x, os_y, -thickness / 2)) \ - .moveTo(os_x + length / 2, os_y).sagittaArc((os_x -length / 2, os_y), width / 2) \ - .sagittaArc((os_x + length / 2, os_y), width / 2) \ - .close().extrude(thickness) - - # The obj1 shape shall have the same volume as the obj2 shape. - self.assertAlmostEqual(obj1.val().wrapped.Volume, obj2.val().wrapped.Volume)