Skip to content

Commit b94a067

Browse files
authored
Fix additional spaces in Python code blocks in tests (#1861)
The correct alignment is the 3 column, aligned to the `code-block` directive, not the 4 column. The extra space is not removed by the docutils parser, so the docs all had an extra space in them, which is very annoying for copy-pasting, especially into limited editors like the CQ-editor where you have to clean up every code sample before it works (otherwise you get IndentationError).
1 parent f07e7e0 commit b94a067

File tree

9 files changed

+446
-445
lines changed

9 files changed

+446
-445
lines changed

cadquery/occ_impl/exporters/dxf.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,28 @@ class DxfDocument:
5454
.. rubric:: Example usage
5555
5656
.. code-block:: python
57-
:caption: Single layer DXF document
57+
:caption: Single layer DXF document
5858
59-
rectangle = cq.Workplane().rect(10, 20)
59+
rectangle = cq.Workplane().rect(10, 20)
6060
61-
dxf = DxfDocument()
62-
dxf.add_shape(rectangle)
63-
dxf.document.saveas("rectangle.dxf")
61+
dxf = DxfDocument()
62+
dxf.add_shape(rectangle)
63+
dxf.document.saveas("rectangle.dxf")
6464
6565
.. code-block:: python
66-
:caption: Multilayer DXF document
67-
68-
rectangle = cq.Workplane().rect(10, 20)
69-
circle = cq.Workplane().circle(3)
70-
71-
dxf = DxfDocument()
72-
dxf = (
73-
dxf.add_layer("layer_1", color=2)
74-
.add_layer("layer_2", color=3)
75-
.add_shape(rectangle, "layer_1")
76-
.add_shape(circle, "layer_2")
77-
)
78-
dxf.document.saveas("rectangle-with-hole.dxf")
66+
:caption: Multilayer DXF document
67+
68+
rectangle = cq.Workplane().rect(10, 20)
69+
circle = cq.Workplane().circle(3)
70+
71+
dxf = DxfDocument()
72+
dxf = (
73+
dxf.add_layer("layer_1", color=2)
74+
.add_layer("layer_2", color=3)
75+
.add_shape(rectangle, "layer_1")
76+
.add_shape(circle, "layer_2")
77+
)
78+
dxf.document.saveas("rectangle-with-hole.dxf")
7979
"""
8080

8181
CURVE_TOLERANCE = 1e-9

doc/assy.rst

Lines changed: 99 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ We want to start with defining the model parameters to allow for easy dimension
1818

1919
.. code-block:: python
2020
21-
import cadquery as cq
21+
import cadquery as cq
2222
23-
# Parameters
24-
H = 400
25-
W = 200
26-
D = 350
23+
# Parameters
24+
H = 400
25+
W = 200
26+
D = 350
2727
28-
PROFILE = cq.importers.importDXF("vslot-2020_1.dxf").wires()
28+
PROFILE = cq.importers.importDXF("vslot-2020_1.dxf").wires()
2929
30-
SLOT_D = 5
31-
PANEL_T = 3
30+
SLOT_D = 5
31+
PANEL_T = 3
3232
33-
HANDLE_D = 20
34-
HANDLE_L = 50
35-
HANDLE_W = 4
33+
HANDLE_D = 20
34+
HANDLE_L = 50
35+
HANDLE_W = 4
3636
3737
It is interesting to note that the v-slot profile is imported from a DXF file.
3838
This way it is very easy to change to other aluminum extrusion type, e.g. Item or Bosch.
@@ -45,72 +45,72 @@ Next we want to define functions generating the assembly components based on the
4545

4646
.. code-block:: python
4747
48-
def make_vslot(l):
49-
return PROFILE.toPending().extrude(l)
48+
def make_vslot(l):
49+
return PROFILE.toPending().extrude(l)
5050
5151
52-
def make_connector():
53-
rv = (
54-
cq.Workplane()
55-
.box(20, 20, 20)
56-
.faces("<X")
57-
.workplane()
58-
.cboreHole(6, 15, 18)
59-
.faces("<Z")
60-
.workplane(centerOption="CenterOfMass")
61-
.cboreHole(6, 15, 18)
62-
)
63-
64-
# tag mating faces
65-
rv.faces(">X").tag("X").end()
66-
rv.faces(">Z").tag("Z").end()
52+
def make_connector():
53+
rv = (
54+
cq.Workplane()
55+
.box(20, 20, 20)
56+
.faces("<X")
57+
.workplane()
58+
.cboreHole(6, 15, 18)
59+
.faces("<Z")
60+
.workplane(centerOption="CenterOfMass")
61+
.cboreHole(6, 15, 18)
62+
)
6763
68-
return rv
64+
# tag mating faces
65+
rv.faces(">X").tag("X").end()
66+
rv.faces(">Z").tag("Z").end()
67+
68+
return rv
69+
70+
71+
def make_panel(w, h, t, cutout):
72+
rv = (
73+
cq.Workplane("XZ")
74+
.rect(w, h)
75+
.extrude(t)
76+
.faces(">Y")
77+
.vertices()
78+
.rect(2 * cutout, 2 * cutout)
79+
.cutThruAll()
80+
.faces("<Y")
81+
.workplane()
82+
.pushPoints([(-w / 3, HANDLE_L / 2), (-w / 3, -HANDLE_L / 2)])
83+
.hole(3)
84+
)
6985
86+
# tag mating edges
87+
rv.faces(">Y").edges("%CIRCLE").edges(">Z").tag("hole1")
88+
rv.faces(">Y").edges("%CIRCLE").edges("<Z").tag("hole2")
7089
71-
def make_panel(w, h, t, cutout):
72-
rv = (
73-
cq.Workplane("XZ")
74-
.rect(w, h)
75-
.extrude(t)
76-
.faces(">Y")
77-
.vertices()
78-
.rect(2 * cutout, 2 * cutout)
79-
.cutThruAll()
80-
.faces("<Y")
81-
.workplane()
82-
.pushPoints([(-w / 3, HANDLE_L / 2), (-w / 3, -HANDLE_L / 2)])
83-
.hole(3)
84-
)
90+
return rv
8591
86-
# tag mating edges
87-
rv.faces(">Y").edges("%CIRCLE").edges(">Z").tag("hole1")
88-
rv.faces(">Y").edges("%CIRCLE").edges("<Z").tag("hole2")
8992
90-
return rv
93+
def make_handle(w, h, r):
94+
pts = ((0, 0), (w, 0), (w, h), (0, h))
9195
96+
path = cq.Workplane().polyline(pts)
9297
93-
def make_handle(w, h, r):
94-
pts = ((0, 0), (w, 0), (w, h), (0, h))
95-
96-
path = cq.Workplane().polyline(pts)
97-
98-
rv = (
99-
cq.Workplane("YZ")
100-
.rect(r, r)
101-
.sweep(path, transition="round")
102-
.tag("solid")
103-
.faces("<X")
104-
.workplane()
105-
.faces("<X", tag="solid")
106-
.hole(r / 1.5)
107-
)
98+
rv = (
99+
cq.Workplane("YZ")
100+
.rect(r, r)
101+
.sweep(path, transition="round")
102+
.tag("solid")
103+
.faces("<X")
104+
.workplane()
105+
.faces("<X", tag="solid")
106+
.hole(r / 1.5)
107+
)
108108
109-
# tag mating faces
110-
rv.faces("<X").faces(">Y").tag("mate1")
111-
rv.faces("<X").faces("<Y").tag("mate2")
109+
# tag mating faces
110+
rv.faces("<X").faces(">Y").tag("mate1")
111+
rv.faces("<X").faces("<Y").tag("mate2")
112112
113-
return rv
113+
return rv
114114
115115
Initial assembly
116116
================
@@ -149,35 +149,35 @@ Then we want to define all the constraints
149149

150150
.. code-block:: python
151151
152-
# define the constraints
153-
(
154-
door
155-
# left profile
156-
.constrain("left@faces@<Z", "con_bl?Z", "Plane")
157-
.constrain("left@faces@<X", "con_bl?X", "Axis")
158-
.constrain("left@faces@>Z", "con_tl?Z", "Plane")
159-
.constrain("left@faces@<X", "con_tl?X", "Axis")
160-
# top
161-
.constrain("top@faces@<Z", "con_tl?X", "Plane")
162-
.constrain("top@faces@<Y", "con_tl@faces@>Y", "Axis")
163-
# bottom
164-
.constrain("bottom@faces@<Y", "con_bl@faces@>Y", "Axis")
165-
.constrain("bottom@faces@>Z", "con_bl?X", "Plane")
166-
# right connectors
167-
.constrain("top@faces@>Z", "con_tr@faces@>X", "Plane")
168-
.constrain("bottom@faces@<Z", "con_br@faces@>X", "Plane")
169-
.constrain("left@faces@>Z", "con_tr?Z", "Axis")
170-
.constrain("left@faces@<Z", "con_br?Z", "Axis")
171-
# right profile
172-
.constrain("right@faces@>Z", "con_tr@faces@>Z", "Plane")
173-
.constrain("right@faces@<X", "left@faces@<X", "Axis")
174-
# panel
175-
.constrain("left@faces@>X[-4]", "panel@faces@<X", "Plane")
176-
.constrain("left@faces@>Z", "panel@faces@>Z", "Axis")
177-
# handle
178-
.constrain("panel?hole1", "handle?mate1", "Plane")
179-
.constrain("panel?hole2", "handle?mate2", "Point")
180-
)
152+
# define the constraints
153+
(
154+
door
155+
# left profile
156+
.constrain("left@faces@<Z", "con_bl?Z", "Plane")
157+
.constrain("left@faces@<X", "con_bl?X", "Axis")
158+
.constrain("left@faces@>Z", "con_tl?Z", "Plane")
159+
.constrain("left@faces@<X", "con_tl?X", "Axis")
160+
# top
161+
.constrain("top@faces@<Z", "con_tl?X", "Plane")
162+
.constrain("top@faces@<Y", "con_tl@faces@>Y", "Axis")
163+
# bottom
164+
.constrain("bottom@faces@<Y", "con_bl@faces@>Y", "Axis")
165+
.constrain("bottom@faces@>Z", "con_bl?X", "Plane")
166+
# right connectors
167+
.constrain("top@faces@>Z", "con_tr@faces@>X", "Plane")
168+
.constrain("bottom@faces@<Z", "con_br@faces@>X", "Plane")
169+
.constrain("left@faces@>Z", "con_tr?Z", "Axis")
170+
.constrain("left@faces@<Z", "con_br?Z", "Axis")
171+
# right profile
172+
.constrain("right@faces@>Z", "con_tr@faces@>Z", "Plane")
173+
.constrain("right@faces@<X", "left@faces@<X", "Axis")
174+
# panel
175+
.constrain("left@faces@>X[-4]", "panel@faces@<X", "Plane")
176+
.constrain("left@faces@>Z", "panel@faces@>Z", "Axis")
177+
# handle
178+
.constrain("panel?hole1", "handle?mate1", "Plane")
179+
.constrain("panel?hole2", "handle?mate2", "Point")
180+
)
181181
182182
Should you need to do something unusual that is not possible with the string
183183
based selectors (e.g. use :py:class:`cadquery.selectors.BoxSelector` or a user-defined selector class),
@@ -359,9 +359,10 @@ STEP can be loaded in all CAD tool, e.g. in FreeCAD and the XML be used in other
359359
.. code-block:: python
360360
:linenos:
361361
362-
door.export("door.step")
363-
door.export("door.xml")
364-
.. image:: _static/door_assy_freecad.png
362+
door.export("door.step")
363+
door.export("door.xml")
364+
365+
.. image:: _static/door_assy_freecad.png
365366

366367

367368
Object locations

doc/designprinciples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CadQuery strives to allow scripts to read roughly as a human would describe an o
1414

1515
For example, consider this object:
1616

17-
.. image:: _static/quickstart.png
17+
.. image:: _static/quickstart.png
1818

1919
A human would describe this as:
2020

doc/free-func.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,39 @@ It begins with defining few edges.
5353

5454
.. code-block:: python
5555
56-
edge1 = circle(r)
57-
edge2 = circle(2*r).moved(z=dh)
58-
edge3 = circle(r).moved(z=1.5*dh)
56+
edge1 = circle(r)
57+
edge2 = circle(2*r).moved(z=dh)
58+
edge3 = circle(r).moved(z=1.5*dh)
5959
6060
6161
Those edges are used to create the side faces of the final solid using :meth:`~cadquery.occ_impl.shapes.loft`.
6262

6363
.. code-block:: python
6464
65-
side = loft(edge1, edge2, edge3)
65+
side = loft(edge1, edge2, edge3)
6666
6767
Once the side is there, :meth:`~cadquery.occ_impl.shapes.cap` and :meth:`~cadquery.occ_impl.shapes.fill` are used to define the top and bottom faces.
6868
Note that :meth:`~cadquery.occ_impl.shapes.cap` tries to maintain curvature continuity with respect to the context shape. This is not the case for :meth:`~cadquery.occ_impl.shapes.fill`.
6969

7070
.. code-block:: python
7171
72-
# bottom face
73-
bottom = fill(side.edges('<Z'))
72+
# bottom face
73+
bottom = fill(side.edges('<Z'))
7474
75-
# top face with continuous curvature
76-
top = cap(side.edges('>Z'), side, [(0,0,1.75*dh)])
75+
# top face with continuous curvature
76+
top = cap(side.edges('>Z'), side, [(0,0,1.75*dh)])
7777
7878
Next, all the faces are assembled into a solid.
7979

8080
.. code-block:: python
8181
82-
s = solid(side, bottom, top)
82+
s = solid(side, bottom, top)
8383
8484
Finally, the solid is duplicated and placed in the desired locations creating the final compound object. Note various usages of :meth:`~cadquery.Shape.moved`.
8585

8686
.. code-block:: python
8787
88-
result = s.moved((-3*r, 0, 0), (3*r, 0, 0))
88+
result = s.moved((-3*r, 0, 0), (3*r, 0, 0))
8989
9090
In general all the operations are implemented as free functions, with the exception of placement and selection which are strictly related to a specific shape.
9191

0 commit comments

Comments
 (0)