From ea257f8b6a2e35eb501e925f70a4907944778acc Mon Sep 17 00:00:00 2001 From: Jeremy Wright <wrightjmf@gmail.com> Date: Mon, 13 Jul 2015 10:23:39 -0400 Subject: [PATCH] Updated to the latest CadQuery commit. --- CadQuery/Libs/cadquery/CQ.py | 44 +- .../cheatsheet/cadquery_cheatsheet.html | 404 ++++++++++++++++++ CadQuery/Libs/cadquery/freecad_impl/shapes.py | 15 + 3 files changed, 460 insertions(+), 3 deletions(-) create mode 100644 CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html diff --git a/CadQuery/Libs/cadquery/CQ.py b/CadQuery/Libs/cadquery/CQ.py index d666659..708f6de 100644 --- a/CadQuery/Libs/cadquery/CQ.py +++ b/CadQuery/Libs/cadquery/CQ.py @@ -795,6 +795,44 @@ class CQ(object): solid.wrapped = s.wrapped return self.newObject([s]) + def chamfer(self, length, length2 = None): + """ + Chamfers a solid on the selected edges. + + The edges on the stack are chamfered. The solid to which the + edges belong must be in the parent chain of the selected + edges. + + Optional parameter `length2` can be supplied with a different + value than `length` for a chamfer that is shorter on one side + longer on the other side. + + :param length: the length of the fillet, must be greater than zero + :param length2: optional parameter for asymmetrical chamfer + :type length: positive float + :type length2: positive float + :raises: ValueError if at least one edge is not selected + :raises: ValueError if the solid containing the edge is not in the chain + :returns: cq object with the resulting solid selected. + + This example will create a unit cube, with the top edges chamfered:: + + s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.1) + + This example will create chamfers longer on the sides:: + + s = Workplane("XY").box(1,1,1).faces("+Z").chamfer(0.2, 0.1) + """ + solid = self.findSolid() + + edgeList = self.edges().vals() + if len(edgeList) < 1: + raise ValueError("Chamfer requires that edges be selected") + + s = solid.chamfer(length, length2, edgeList) + + solid.wrapped = s.wrapped + return self.newObject([s]) class Workplane(CQ): """ @@ -2299,11 +2337,11 @@ class Workplane(CQ): (xp, yp, zp) = pnt.toTuple() if centered[0]: - xp -= radius + xp -= radius * direct.x if centered[1]: - yp -= radius + yp -= radius * direct.y if centered[2]: - zp -= radius + zp -= radius * direct.z return Solid.makeSphere(radius, Vector(xp, yp, zp), direct, angle1, angle2, angle3) diff --git a/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html b/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html new file mode 100644 index 0000000..bb58252 --- /dev/null +++ b/CadQuery/Libs/cadquery/cheatsheet/cadquery_cheatsheet.html @@ -0,0 +1,404 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html> + <head> + <title>CadQuery Cheatsheet</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + + <style type="text/css"> + .section { + margin: 0.5em; + padding: 0px 0.5em 0.5em; + background-color: #EBEBEB; + } + .column { + float: left; + width: 375px; + } + tr { + background-color: #FFFFFF; + } + td { + text-align: center; + width: 5em; + } + h2 { + display: inline; + } + </style> + </head> + <body> + <div class="column" style="width:475px;"> + <div class="section"> + <h2>Documentation</h2> + <ul style="background-color:#ffffff;margin-bottom:0px;margin-top:0px;"> + <li><a href="http://parametricparts.com/docs/#">ParametricParts Documentation</a></li> + <li><a href="https://github.com/dcowden/cadquery/blob/master/README.md">CadQuery Readme</a></li> + <li><a href="http://parametricparts.com/docs/examples.html#examples">CadQuery Examples</a></li> + <li><a href="http://parametricparts.com/docs/classreference.html">CadQuery Class Reference</a></li> + </ul> + </div> + <div class="section"> + <h2>BREP Terminology</h2><br /> + <table style="width:100%;"> + <tr> + <td style="width:10%;"><strong>vertex</strong></td> + <td style="width:90%;">A single point in space</td> + </tr> + <tr> + <td><strong>edge</strong></td> + <td>A connection between two or more vertices along a particular path (called a curve)</td> + </tr> + <tr> + <td><strong>wire</strong></td> + <td>A collection of edges that are connected together</td> + </tr> + <tr> + <td><strong>face</strong></td> + <td>A set of edges or wires that enclose a surface</td> + </tr> + <tr> + <td><strong>shell</strong></td> + <td>A collection of faces that are connected together along some of their edges</td> + </tr> + <tr> + <td><strong>solid</strong></td> + <td>A shell that has a closed interior</td> + </tr> + <tr> + <td><strong>compound</strong></td> + <td>A collection of solids</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Named Planes</h2><br /> + Available named planes are as follows. Direction references refer to the global directions. + <table style="width:100%;"> + <tr> + <th style="width:25%;">Name</th> + <th style="width:25%;">xDir</th> + <th style="width:25%;">yDir</th> + <th style="width:25%;">zDir</th> + </tr> + <tr> + <td>XY</td> + <td>+x</td> + <td>+y</td> + <td>+z</td> + </tr> + <tr> + <td>YZ</td> + <td>+y</td> + <td>+z</td> + <td>+x</td> + </tr> + <tr> + <td>XZ</td> + <td>+x</td> + <td>+z</td> + <td>-y</td> + </tr> + <tr> + <td>front</td> + <td>+x</td> + <td>+y</td> + <td>+z</td> + </tr> + <tr> + <td>back</td> + <td>-x</td> + <td>+y</td> + <td>-z</td> + </tr> + <tr> + <td>left</td> + <td>+z</td> + <td>+y</td> + <td>-x</td> + </tr> + <tr> + <td>right</td> + <td>-z</td> + <td>+y</td> + <td>+x</td> + </tr> + <tr> + <td>top</td> + <td>+x</td> + <td>-z</td> + <td>+y</td> + </tr> + <tr> + <td>bottom</td> + <td>+x</td> + <td>+z</td> + <td>-y</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Core Classes</h2><br /> + <table style="width:100%;"> + <tr> + <th style="width:40%;">Class</th> + <th style="width:60%;">Description</th> + </tr> + <tr> + <td>CQ(obj)</td> + <td>Provides enhanced functionality for a wrapped CAD primitive.</td> + </tr> + <tr> + <td>Plane(origin, xDir, normal)</td> + <td>A 2d coordinate system in space, with the x-y axes on the a plane, and a particular point as the origin.</td> + </tr> + <tr> + <td>Workplane(inPlane[origin, obj])</td> + <td>Defines a coordinate system in space, in which 2-d coordinates can be used.</td> + </tr> + </table> + </div> + </div> + <div class="column" style="width:600px;"> + <div class="section"> + <h2>Selector Methods</h2><br /> + CadQuery selector strings allow filtering various types of object lists. + Most commonly, Edges, Faces, and Vertices are used, but all objects types can be filtered.<br /> + <table style="width:100%;"> + <tr> + <th style="width:40%;">Selector Method</th> + <th style="width:60%;">Description</th> + </tr> + <tr> + <td><a href="http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.CQ.faces">CQ.faces(selector=None)</a></td> + <td>Select the faces of objects on the stack, optionally filtering the selection.</td> + <tr> + <td><a href="http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.CQ.edges">CQ.edges(selector=None)</a></td> + <td>Select the edges of objects on the stack, optionally filtering the selection.</td> + </tr> + <tr> + <td><a href="http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.CQ.vertices">CQ.vertices(selector=None)</a></td> + <td>Select the vertices of objects on the stack, optionally filtering the selection.</td> + </tr> + <tr> + <td><a href="http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.CQ.solids">CQ.solids(selector=None)</a></td> + <td>Select the solids of objects on the stack, optionally filtering the selection.</td> + </tr> + <tr> + <td><a href="http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.CQ.shells">CQ.shells(selector=None)</a></td> + <td>Select the shells of objects on the stack, optionally filtering the selection.</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Selector Classes</h2><br /> + <table style="width:100%;"> + <tr> + <th style="width:40%;">Class</th> + <th style="width:60%;">Description</th> + </tr> + <tr> + <td>NearestToPointSelector(pnt)</td> + <td>Selects object nearest the provided point.</td> + </tr> + <tr> + <td>ParallelDirSelector(vector[tolerance])</td> + <td>Selects objects parallel with the provided direction.</td> + </tr> + <tr> + <td>DirectionSelector(vector[tolerance])</td> + <td>Selects objects aligned with the provided direction.</td> + </tr> + <tr> + <td>PerpendicularDirSelector(vector[tolerance])</td> + <td>Selects objects perpendicular with the provided direction.</td> + </tr> + <tr> + <td>TypeSelector(typeString)</td> + <td>Selects objects of the prescribed topological type.</td> + </tr> + <tr> + <td>DirectionMinMaxSelector(vector[directionMax])</td> + <td>Selects objects closest or farthest in the specified direction.</td> + </tr> + <tr> + <td>StringSyntaxSelector(selectorString)</td> + <td>Filter lists objects using a simple string syntax.</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Selector String Modifiers</h2><br /> + Selectors are a complex topic: see <a href="http://parametricparts.com/docs/selectors.html">CadQuery String Selectors</a> for more information.<br /> + Axis Strings are: X, Y, Z, XY, YZ, XZ + <table style="width:100%;"> + <tr> + <th style="width:10%;">Modifier</th> + <th style="width:90%;">Description</th> + </tr> + <tr> + <td>|</td> + <td>Parallel to (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=paralleldirselector#cadfile.cadutils.cadquery.ParallelDirSelector">ParallelDirSelector</a>). Can return multiple objects.</td> + </tr> + <tr> + <td>#</td> + <td>Perpendicular to (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=perpendiculardirselector#cadfile.cadutils.cadquery.PerpendicularDirSelector">PerpendicularDirSelector</a>)</td> + </tr> + <tr> + <td>+</td> + <td>Positive direction (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=directionselector#cadfile.cadutils.cadquery.DirectionSelector">DirectionSelector</a>)</td> + </tr> + <tr> + <td>-</td> + <td>Negative direction (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=directionselector#cadfile.cadutils.cadquery.DirectionSelector">DirectionSelector</a>)</td> + </tr> + <tr> + <td>></td> + <td>Maximize (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=directionminmaxselector#cadfile.cadutils.cadquery.DirectionMinMaxSelector">DirectionMinMaxSelector</a> with directionMax=True)</td> + </tr> + <tr> + <td><</td> + <td>Minimize (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=directionminmaxselector#cadfile.cadutils.cadquery.DirectionMinMaxSelector">DirectionMinMaxSelector</a> with directionMax=False)</td> + </tr> + <tr> + <td>%</td> + <td>Curve/surface type (same as <a href="http://parametricparts.com/docs/classreference.html?highlight=typeselector#cadfile.cadutils.cadquery.TypeSelector">TypeSelector</a>)</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Examples of Filtering Faces</h2><br /> + All types of filters work on faces. In most cases, the selector refers to the direction of the normal vector of the face. + If a face is not planar, selectors are evaluated at the center of mass of the face. This can lead to results that are quite unexpected. + <table style="width:100%;"> + <tr> + <th style="width:10%;">Selector</th> + <th style="width:40%;">Selector Class</th> + <th style="width:40%;">Selects</th> + <th style="width:10%;"># Objects Returned</th> + </tr> + <tr> + <td>+Z</td> + <td>DirectionSelector</td> + <td>Faces with normal in +z direction</td> + <td>0 or 1</td> + </tr> + <tr> + <td>|Z</td> + <td>ParallelDirSelector</td> + <td>Faces parallel to xy plane</td> + <td>0..many</td> + </tr> + <tr> + <td>-X</td> + <td>DirectionSelector</td> + <td>Faces with normal in neg x direction</td> + <td>0..many</td> + </tr> + <tr> + <td>#Z</td> + <td>PerpendicularDirSelector</td> + <td>Faces perpendicular to z direction</td> + <td>0..many</td> + </tr> + <tr> + <td>%Plane</td> + <td>TypeSelector</td> + <td>Faces of type plane</td> + <td>0..many</td> + </tr> + <tr> + <td>>Y</td> + <td>DirectionMinMaxSelector</td> + <td>Face farthest in the positive y dir</td> + <td>0 or 1</td> + </tr> + <tr> + <td><Y</td> + <td>DirectionMinMaxSelector</td> + <td>Face farthest in the negative y dir</td> + <td>0 or 1</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Examples of Filtering Edges</h2><br /> + Some filter types are not supported for edges. The selector usually refers to the direction of the edge. + Non-linear edges are not selected for any selectors except type (%). Non-linear edges are never returned when these filters are applied. + <table style="width:100%;"> + <tr> + <th style="width:10%;">Selector</th> + <th style="width:40%;">Selector Class</th> + <th style="width:40%;">Selects</th> + <th style="width:10%;"># Objects Returned</th> + </tr> + <tr> + <td>+Z</td> + <td>DirectionSelector</td> + <td>Edges aligned in the Z direction</td> + <td>0..many</td> + </tr> + <tr> + <td>|Z</td> + <td>ParallelDirSelector</td> + <td>Edges parallel to z direction</td> + <td>0..many</td> + </tr> + <tr> + <td>-X</td> + <td>DirectionSelector</td> + <td>Edges aligned in neg x direction</td> + <td>0..many</td> + </tr> + <tr> + <td>#Z</td> + <td>PerpendicularDirSelector</td> + <td>Edges perpendicular to z direction</td> + <td>0..many</td> + </tr> + <tr> + <td>%Plane</td> + <td>TypeSelector</td> + <td>Edges type line</td> + <td>0..many</td> + </tr> + <tr> + <td>>Y</td> + <td>DirectionMinMaxSelector</td> + <td>Edges farthest in the positive y dir</td> + <td>0 or 1</td> + </tr> + <tr> + <td><Y</td> + <td>DirectionMinMaxSelector</td> + <td>Edges farthest in the negative y dir</td> + <td>0 or 1</td> + </tr> + </table> + </div> + <div class="section"> + <h2>Examples of Filtering Vertices</h2><br /> + Only a few of the filter types apply to vertices. The location of the vertex is the subject of the filter. + <table style="width:100%;"> + <tr> + <th style="width:10%;">Selector</th> + <th style="width:40%;">Selector Class</th> + <th style="width:40%;">Selects</th> + <th style="width:10%;"># Objects Returned</th> + </tr> + <tr> + <td>>Y</td> + <td>DirectionMinMaxSelector</td> + <td>Vertices farthest in the positive y dir</td> + <td>0 or 1</td> + </tr> + <tr> + <td><Y</td> + <td>DirectionMinMaxSelector</td> + <td>Vertices farthest in the negative y dir</td> + <td>0 or 1</td> + </tr> + </table> + </div> + </div> + </body> +</html> diff --git a/CadQuery/Libs/cadquery/freecad_impl/shapes.py b/CadQuery/Libs/cadquery/freecad_impl/shapes.py index 03e34b5..e0f2ecf 100644 --- a/CadQuery/Libs/cadquery/freecad_impl/shapes.py +++ b/CadQuery/Libs/cadquery/freecad_impl/shapes.py @@ -812,6 +812,21 @@ class Solid(Shape): nativeEdges = [e.wrapped for e in edgeList] return Shape.cast(self.wrapped.makeFillet(radius, nativeEdges)) + def chamfer(self, length, length2, edgeList): + """ + Chamfers the specified edges of this solid. + :param length: length > 0, the length (length) of the chamfer + :param length2: length2 > 0, optional parameter for asymmetrical chamfer. Should be `None` if not required. + :param edgeList: a list of Edge objects, which must belong to this solid + :return: Chamfered solid + """ + nativeEdges = [e.wrapped for e in edgeList] + # note: we prefer 'length' word to 'radius' as opposed to FreeCAD's API + if length2: + return Shape.cast(self.wrapped.makeChamfer(length, length2, nativeEdges)) + else: + return Shape.cast(self.wrapped.makeChamfer(length, nativeEdges)) + def shell(self, faceList, thickness, tolerance=0.0001): """ make a shelled solid of given by removing the list of faces