Skip to content

Commit fe53ca0

Browse files
authored
Remove deprecated functions (#1972)
* Use tmpdir for all test_exporters.py tests * Remove deprecated export functions * Remove Workplane combineSolids * Remove Workplane findFace * Remove Workplane text() deprecated 'cut' parameter * Remove deprecated Solid.interpPlate * Fix typo Workplane __truediv__ docstring
1 parent 5fa5956 commit fe53ca0

File tree

9 files changed

+343
-154911
lines changed

9 files changed

+343
-154911
lines changed

cadquery/cq.py

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -342,46 +342,6 @@ def split(self: T, *args, **kwargs) -> T:
342342

343343
return self.newObject(rv)
344344

345-
@deprecate()
346-
def combineSolids(
347-
self, otherCQToCombine: Optional["Workplane"] = None
348-
) -> "Workplane":
349-
"""
350-
!!!DEPRECATED!!! use union()
351-
Combines all solids on the current stack, and any context object, together
352-
into a single object.
353-
354-
After the operation, the returned solid is also the context solid.
355-
356-
:param otherCQToCombine: another CadQuery to combine.
357-
:return: a CQ object with the resulting combined solid on the stack.
358-
359-
Most of the time, both objects will contain a single solid, which is
360-
combined and returned on the stack of the new object.
361-
"""
362-
# loop through current stack objects, and combine them
363-
toCombine = cast(List[Solid], self.solids().vals())
364-
365-
if otherCQToCombine:
366-
otherSolids = cast(List[Solid], otherCQToCombine.solids().vals())
367-
for obj in otherSolids:
368-
toCombine.append(obj)
369-
370-
if len(toCombine) < 1:
371-
raise ValueError("Cannot Combine: at least one solid required!")
372-
373-
# get context solid and we don't want to find our own objects
374-
ctxSolid = self._findType((Solid,), searchStack=False, searchParents=True)
375-
if ctxSolid is None:
376-
ctxSolid = toCombine.pop(0)
377-
378-
# now combine them all. make sure to save a reference to the ctxSolid pointer!
379-
s: Shape = ctxSolid
380-
if toCombine:
381-
s = s.fuse(*_selectShapes(toCombine))
382-
383-
return self.newObject([s])
384-
385345
def all(self: T) -> List[T]:
386346
"""
387347
Return a list of all CQ objects on the stack.
@@ -789,25 +749,6 @@ def findSolid(
789749

790750
return found
791751

792-
@deprecate()
793-
def findFace(self, searchStack: bool = True, searchParents: bool = True) -> Face:
794-
"""
795-
Finds the first face object in the chain, searching from the current node
796-
backwards through parents until one is found.
797-
798-
:param searchStack: should objects on the stack be searched first.
799-
:param searchParents: should parents be searched?
800-
:returns: A face or None if no face is found.
801-
"""
802-
803-
found = self._findType((Face,), searchStack, searchParents)
804-
805-
if found is None:
806-
message = "on the stack or " if searchStack else ""
807-
raise ValueError("Cannot find a face {}in the parent chain".format(message))
808-
809-
return found
810-
811752
def _selectObjects(
812753
self: T,
813754
objType: Any,
@@ -3553,7 +3494,7 @@ def __mul__(self: T, other: Union["Workplane", Solid, Compound]) -> T:
35533494

35543495
def __truediv__(self: T, other: Union["Workplane", Solid, Compound]) -> T:
35553496
"""
3556-
Syntactic sugar for intersect.
3497+
Syntactic sugar for split.
35573498
35583499
Notice that :code:`r = a / b` is equivalent to :code:`r = a.split(b)`.
35593500
@@ -4294,14 +4235,12 @@ def clean(self: T) -> T:
42944235

42954236
return self.newObject(cleanObjects)
42964237

4297-
@deprecate_kwarg_name("cut", "combine='cut'")
42984238
def text(
42994239
self: T,
43004240
txt: str,
43014241
fontsize: float,
43024242
distance: float,
4303-
cut: bool = True,
4304-
combine: CombineMode = False,
4243+
combine: CombineMode = "cut",
43054244
clean: bool = True,
43064245
font: str = "Arial",
43074246
fontPath: Optional[str] = None,
@@ -4316,7 +4255,6 @@ def text(
43164255
:param fontsize: size of the font in model units
43174256
:param distance: the distance to extrude or cut, normal to the workplane plane
43184257
:type distance: float, negative means opposite the normal direction
4319-
:param cut: True to cut the resulting solid from the parent solids if found
43204258
:param combine: True or "a" to combine the resulting solid with parent solids if found,
43214259
"cut" or "s" to remove the resulting solid from the parent solids if found.
43224260
False to keep the resulting solid separated from the parent solids.
@@ -4332,11 +4270,13 @@ def text(
43324270
whether a context solid is already defined:
43334271
43344272
* if combine is False, the new value is pushed onto the stack.
4335-
* if combine is true, the value is combined with the context solid if it exists,
4273+
* if combine is True, "a", "cut" or "s", the value is combined with the context solid if it exists,
43364274
and the resulting solid becomes the new context solid.
43374275
43384276
Examples::
43394277
4278+
Create text::
4279+
43404280
cq.Workplane().text("CadQuery", 5, 1)
43414281
43424282
Specify the font (name), and kind to use an installed system font::
@@ -4347,10 +4287,15 @@ def text(
43474287
43484288
cq.Workplane().text("CadQuery", 5, 1, fontPath="/opt/fonts/texgyrecursor-bold.otf")
43494289
4350-
Cutting text into a solid::
4290+
Cut text from a solid (default behavior when context solid exists and combine is not overridden)::
43514291
43524292
cq.Workplane().box(8, 8, 8).faces(">Z").workplane().text("Z", 5, -1.0)
43534293
4294+
Add text to a solid::
4295+
4296+
cq.Workplane().box(8, 8, 8).faces(">Z").workplane().text("Z", 5, 1.0, combine="a")
4297+
4298+
43544299
"""
43554300
r = Compound.makeText(
43564301
txt,
@@ -4364,9 +4309,6 @@ def text(
43644309
position=self.plane,
43654310
)
43664311

4367-
if cut:
4368-
combine = "cut"
4369-
43704312
return self._combineWithBase(r, combine, clean)
43714313

43724314
def section(self: T, height: float = 0.0) -> T:

cadquery/occ_impl/exporters/__init__.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -134,96 +134,3 @@ def export(
134134

135135
else:
136136
raise ValueError("Unknown export type")
137-
138-
139-
@deprecate()
140-
def toString(shape, exportType, tolerance=0.1, angularTolerance=0.05):
141-
s = StringIO.StringIO()
142-
exportShape(shape, exportType, s, tolerance, angularTolerance)
143-
return s.getvalue()
144-
145-
146-
@deprecate()
147-
def exportShape(
148-
w: Union[Shape, Iterable[Shape]],
149-
exportType: ExportLiterals,
150-
fileLike: IO,
151-
tolerance: float = 0.1,
152-
angularTolerance: float = 0.1,
153-
):
154-
"""
155-
:param shape: the shape to export. it can be a shape object, or a cadquery object. If a cadquery
156-
object, the first value is exported
157-
:param exportType: the exportFormat to use
158-
:param fileLike: a file like object to which the content will be written.
159-
The object should be already open and ready to write. The caller is responsible
160-
for closing the object
161-
:param tolerance: the linear tolerance, in model units. Default 0.1.
162-
:param angularTolerance: the angular tolerance, in radians. Default 0.1.
163-
"""
164-
165-
def tessellate(shape, angularTolerance):
166-
167-
return shape.tessellate(tolerance, angularTolerance)
168-
169-
shape: Shape
170-
if isinstance(w, Shape):
171-
shape = w
172-
else:
173-
shape = compound(*w)
174-
175-
if exportType == ExportTypes.TJS:
176-
tess = tessellate(shape, angularTolerance)
177-
mesher = JsonMesh()
178-
179-
# add vertices
180-
for v in tess[0]:
181-
mesher.addVertex(v.x, v.y, v.z)
182-
183-
# add triangles
184-
for t in tess[1]:
185-
mesher.addTriangleFace(*t)
186-
187-
fileLike.write(mesher.toJson())
188-
189-
elif exportType == ExportTypes.SVG:
190-
fileLike.write(getSVG(shape))
191-
elif exportType == ExportTypes.AMF:
192-
tess = tessellate(shape, angularTolerance)
193-
aw = AmfWriter(tess)
194-
aw.writeAmf(fileLike)
195-
elif exportType == ExportTypes.THREEMF:
196-
tmfw = ThreeMFWriter(shape, tolerance, angularTolerance)
197-
tmfw.write3mf(fileLike)
198-
else:
199-
200-
# all these types required writing to a file and then
201-
# re-reading. this is due to the fact that FreeCAD writes these
202-
(h, outFileName) = tempfile.mkstemp()
203-
# weird, but we need to close this file. the next step is going to write to
204-
# it from c code, so it needs to be closed.
205-
os.close(h)
206-
207-
if exportType == ExportTypes.STEP:
208-
shape.exportStep(outFileName)
209-
elif exportType == ExportTypes.STL:
210-
shape.exportStl(outFileName, tolerance, angularTolerance, True)
211-
else:
212-
raise ValueError("No idea how i got here")
213-
214-
res = readAndDeleteFile(outFileName)
215-
fileLike.write(res)
216-
217-
218-
@deprecate()
219-
def readAndDeleteFile(fileName):
220-
"""
221-
Read data from file provided, and delete it when done
222-
return the contents as a string
223-
"""
224-
res = ""
225-
with open(fileName, "r") as f:
226-
res = "{}".format(f.read())
227-
228-
os.remove(fileName)
229-
return res

cadquery/occ_impl/shapes.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,92 +3910,6 @@ class Solid(Shape, Mixin3D):
39103910

39113911
wrapped: TopoDS_Solid
39123912

3913-
@classmethod
3914-
@deprecate()
3915-
def interpPlate(
3916-
cls,
3917-
surf_edges,
3918-
surf_pts,
3919-
thickness,
3920-
degree=3,
3921-
nbPtsOnCur=15,
3922-
nbIter=2,
3923-
anisotropy=False,
3924-
tol2d=0.00001,
3925-
tol3d=0.0001,
3926-
tolAng=0.01,
3927-
tolCurv=0.1,
3928-
maxDeg=8,
3929-
maxSegments=9,
3930-
) -> Union["Solid", Face]:
3931-
"""
3932-
Returns a plate surface that is 'thickness' thick, enclosed by 'surf_edge_pts' points, and going through 'surf_pts' points.
3933-
3934-
:param surf_edges:
3935-
list of [x,y,z] float ordered coordinates
3936-
or list of ordered or unordered wires
3937-
:param surf_pts: list of [x,y,z] float coordinates (uses only edges if [])
3938-
:param thickness: thickness may be negative or positive depending on direction, (returns 2D surface if 0)
3939-
:param degree: >=2
3940-
:param nbPtsOnCur: number of points on curve >= 15
3941-
:param nbIter: number of iterations >= 2
3942-
:param anisotropy: bool Anisotropy
3943-
:param tol2d: 2D tolerance >0
3944-
:param tol3d: 3D tolerance >0
3945-
:param tolAng: angular tolerance
3946-
:param tolCurv: tolerance for curvature >0
3947-
:param maxDeg: highest polynomial degree >= 2
3948-
:param maxSegments: greatest number of segments >= 2
3949-
"""
3950-
3951-
# POINTS CONSTRAINTS: list of (x,y,z) points, optional.
3952-
pts_array = [gp_Pnt(*pt) for pt in surf_pts]
3953-
3954-
# EDGE CONSTRAINTS
3955-
# If a list of wires is provided, make a closed wire
3956-
if not isinstance(surf_edges, list):
3957-
surf_edges = [o.vals()[0] for o in surf_edges.all()]
3958-
surf_edges = Wire.assembleEdges(surf_edges)
3959-
w = surf_edges.wrapped
3960-
3961-
# If a list of (x,y,z) points provided, build closed polygon
3962-
if isinstance(surf_edges, list):
3963-
e_array = [Vector(*e) for e in surf_edges]
3964-
wire_builder = BRepBuilderAPI_MakePolygon()
3965-
for e in e_array: # Create polygon from edges
3966-
wire_builder.Add(e.toPnt())
3967-
wire_builder.Close()
3968-
w = wire_builder.Wire()
3969-
3970-
edges = [i for i in Shape(w).Edges()]
3971-
3972-
# MAKE SURFACE
3973-
continuity = GeomAbs_C0 # Fixed, changing to anything else crashes.
3974-
face = Face.makeNSidedSurface(
3975-
edges,
3976-
pts_array,
3977-
continuity,
3978-
degree,
3979-
nbPtsOnCur,
3980-
nbIter,
3981-
anisotropy,
3982-
tol2d,
3983-
tol3d,
3984-
tolAng,
3985-
tolCurv,
3986-
maxDeg,
3987-
maxSegments,
3988-
)
3989-
3990-
# THICKEN SURFACE
3991-
if (
3992-
abs(thickness) > 0
3993-
): # abs() because negative values are allowed to set direction of thickening
3994-
return face.thicken(thickness)
3995-
3996-
else: # Return 2D surface only
3997-
return face
3998-
39993913
@staticmethod
40003914
def isSolid(obj: Shape) -> bool:
40013915
"""

doc/extending.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,13 @@ Plugin Example
161161

162162
This ultra simple plugin makes cubes of the specified size for each stack point.
163163

164-
(The cubes are off-center because the boxes have their lower left corner at the reference points.)
165-
166164
.. cadquery::
167165

168-
from cadquery.occ_impl.shapes import box
166+
import cadquery as cq
167+
from cadquery.func import box
169168

170169
def makeCubes(self, length):
171-
# self refers to the CQ or Workplane object
170+
# self refers to the Workplane object
172171

173172
# inner method that creates a cube
174173
def _singleCube(loc):
@@ -192,7 +191,7 @@ This ultra simple plugin makes cubes of the specified size for each stack point.
192191
.rect(4.0, 4.0, forConstruction=True)
193192
.vertices()
194193
.makeCubes(1.0)
195-
.combineSolids()
194+
.combine()
196195
)
197196

198197

@@ -214,7 +213,8 @@ Here is the same plugin rewritten using one of those methods.
214213

215214
.. cadquery::
216215

217-
from cadquery.occ_impl.shapes import box
216+
import cadquery as cq
217+
from cadquery.func import box
218218

219219
def makeCubes(length):
220220

@@ -233,7 +233,7 @@ Here is the same plugin rewritten using one of those methods.
233233
.rect(4.0, 4.0, forConstruction=True)
234234
.vertices()
235235
.invoke(makeCubes(1.0))
236-
.combineSolids()
236+
.combine()
237237
)
238238

239239
Such an approach is more friendly for auto-completion and static analysis tools.

0 commit comments

Comments
 (0)