Skip to content

Commit

Permalink
πŸ‘½οΈ FreeCAD 0.21.2 (#2864)
Browse files Browse the repository at this point in the history
* πŸ‘½οΈ FreeCAD 0.21.2

* πŸ§ͺ Test

* πŸ› Freecad show cad fixes

* πŸ› Fix deepcopy
  • Loading branch information
je-cook committed Dec 15, 2023
1 parent 13496bb commit 5a0f88c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
activate-environment: bluemira
environment-file: conda/environment.yml
miniforge-version: "latest"
use-only-tar-bz2: true
use-only-tar-bz2: false
miniforge-variant: Mambaforge
use-mamba: true

Expand Down
18 changes: 10 additions & 8 deletions bluemira/codes/_freecadapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import math
import os
import sys
from copy import deepcopy
from dataclasses import dataclass
from dataclasses import asdict, dataclass
from functools import wraps
from pathlib import Path
from types import DynamicClassAttribute
Expand Down Expand Up @@ -546,7 +545,7 @@ def offset_wire(
Offset wire
"""
if thickness == 0.0: # noqa: PLR2004
return deepcopy(wire)
return wire.copy()

if _wire_is_straight(wire):
raise InvalidCADInputsError("Cannot offset a straight line.")
Expand Down Expand Up @@ -1228,7 +1227,7 @@ class CADFileType(enum.Enum):
# SVG = ("svg", "DrawingGui")
# SVG_FLAT = ("$svg", "importSVG")
# TETGEN_FEM = ("poly", "feminout.convert2TetGen")
THREED_MANUFACTURING = ("3mf", "Mesh")
# THREED_MANUFACTURING = ("3mf", "Mesh") # segfault?
# UNV = ("unv", "Fem")
# VRML = ("vrml", "FreeCADGui")
# VRML_2 = ("wrl", "FreeCADGui")
Expand Down Expand Up @@ -2363,8 +2362,8 @@ def color(self, value: Union[str, Tuple[float, float, float], ColorPalette]):

def show_cad(
parts: Union[apiShape, List[apiShape]],
options: Union[Dict, List[Optional[Dict]]],
labels: List[str],
options: Optional[Union[Dict, List[Optional[Dict]]]] = None,
labels: Optional[List[str]] = None,
**kwargs, # noqa: ARG001
):
"""
Expand All @@ -2379,11 +2378,14 @@ def show_cad(
labels:
labels to use for each part object
"""
if isinstance(parts, apiShape):
parts = [parts]

if options is None:
options = [None]
options = [None] * len(parts)

if None in options:
options = [DefaultDisplayOptions() if o is None else o for o in options]
options = [asdict(DefaultDisplayOptions()) if o is None else o for o in options]

if len(options) != len(parts):
raise FreeCADError(
Expand Down
21 changes: 21 additions & 0 deletions bluemira/geometry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,27 @@ def __repr__(self) -> str: # noqa: D105
f"volume: {self.volume})"
)

def __deepcopy__(self, memo):
"""Deepcopy for BluemiraGeo.
FreeCAD shapes cannot be deepcopied on versions >=0.21
"""
cls = self.__class__
result = cls.__new__(cls)
memo[id(self)] = result
for k, v in self.__dict__.items():
if k not in {"_shape", "_boundary"}:
setattr(
result,
k,
copy.deepcopy(v, memo),
)

result._shape = self._shape.copy()
result._boundary = [n.copy() for n in self._boundary]

return result

def copy(self, label: Optional[str] = None):
"""
Make a copy of the BluemiraGeo.
Expand Down
3 changes: 1 addition & 2 deletions bluemira/geometry/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import functools
import inspect
import json
from copy import deepcopy
from pathlib import Path
from typing import (
Any,
Expand Down Expand Up @@ -770,7 +769,7 @@ def revolve_shape(
flag_shell = False

shape_1 = cadapi.revolve_shape(shape, base, direction, degree=180)
shape_2 = deepcopy(shape_1)
shape_2 = shape_1.copy()
shape_2 = cadapi.rotate_shape(shape_2, base, direction, degree=-180)
result = cadapi.boolean_fuse([shape_1, shape_2], remove_splitter=False)

Expand Down
11 changes: 1 addition & 10 deletions conda/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ variables:

dependencies:
- python=3.8
- freecad=0.20.1
- pivy=0.6.8
- libpng=1.6.37 # malloc crash on 1.6.38
- hdf5=1.12.1
- netcdf4=1.6.0
- numpy=1.23
- freecad=0.21.2
- fenics=2019.1.0
- MeshPy=2020.1
- meshio=5.3.4
- mshr=2019.1.0
- scipy=1.9
- graphviz
- pip
- pip:
Expand Down
8 changes: 4 additions & 4 deletions requirements-conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ appdirs==1.4.4
cached-property==1.5.2
cftime==1.6.3
gmsh-interop==2021.1.1
h5py==3.7.0
h5py==3.10.0
importlib-metadata==6.8.0
pybind11==2.11.1
pybind11-global==2.11.1
PySide2==5.15.5
PySide2==5.15.8
pytools==2023.1.1
PyYAML==6.0.1
shiboken2==5.15.5
shiboken2==5.15.8
sympy==1.12
typing_extensions==4.8.0
vtk==9.1.0
vtk==9.2.6
zipp==3.17.0
2 changes: 1 addition & 1 deletion requirements-develop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ docutils==0.18.1
filelock==3.13.1
greenlet==3.0.1
identify==2.5.31
idna==3.4
idna==3.6
imagesize==1.4.1
importlib-metadata==6.8.0
iniconfig==2.0.0
Expand Down
1 change: 1 addition & 0 deletions tests/builders/test_coil_supports.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def test_curved_profile(self, n_TF):
join_2 = make_polygon([p3, p1])

ois_profile = BluemiraWire([result, join_1, r_copy, join_2])
assert ois_profile.is_closed()
params = OISBuilderParams(
Parameter("n_TF", n_TF),
Parameter("tf_wp_depth", 1.4),
Expand Down
2 changes: 1 addition & 1 deletion tests/codes/test_freecadapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def test_init(self, name, ftype):
"STEP_2",
"STEP_ZIP", # Case sensitive extension
"STL",
"THREED_MANUFACTURING",
# "THREED_MANUFACTURING", #segfault
pytest.param("IFC_BIM", marks=[skipif_import_error("ifcopenshell")]),
pytest.param(
"IFC_BIM_JSON", # github.com/buildingSMART/ifcJSON
Expand Down

0 comments on commit 5a0f88c

Please sign in to comment.