8000 Sketch support (#297) · ag-python-qt/CQ-editor-pyqt@bba0aed · GitHub
[go: up one dir, main page]

Skip to content

Commit bba0aed

Browse files
Sketch support (CadQuery#297)
* Sketch support * Update cqgui_env.yml * Try using mamba * Update the curl call * Update appveyor.yml
1 parent dc95018 commit bba0aed

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

appveyor.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
shallow_clone: false
22

33
image:
4-
# - macOS-mojave
5-
# - macOS
6-
# - Ubuntu
74
- Ubuntu2004
85
- Ubuntu1804
96
- Visual Studio 2015
@@ -17,21 +14,20 @@ environment:
1714

1815
install:
1916
- sh: if [[ $APPVEYOR_BUILD_WORKER_IMAGE != "macOS"* ]]; then sudo apt update; sudo apt -y --force-yes install libglu1-mesa xvfb libgl1-mesa-dri mesa-common-dev libglu1-mesa-dev; fi
20-
- sh: if [[ $APPVEYOR_BUILD_WORKER_IMAGE != "macOS"* ]]; then curl -o miniconda.sh curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh; fi
21-
- sh: if [[ $APPVEYOR_BUILD_WORKER_IMAGE == "macOS"* ]]; then curl -o miniconda.sh curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-4.7.10-MacOSX-x86_64.sh; fi
17+
- sh: if [[ $APPVEYOR_BUILD_WORKER_IMAGE != "macOS"* ]]; then curl -fsSL -o miniconda.sh https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh; fi
18+
- sh: if [[ $APPVEYOR_BUILD_WORKER_IMAGE == "macOS"* ]]; then curl -fsSL -o miniconda.sh https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-MacOSX-x86_64.sh; fi
2219
- sh: bash miniconda.sh -b -p $HOME/miniconda
2320
- sh: source $HOME/miniconda/bin/activate
24-
- cmd: appveyor DownloadFile https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
25-
- cmd: Miniconda3-latest-Windows-x86_64.exe /S /InstallationType=JustMe /D=%MINICONDA_DIRNAME%
21+
- cmd: curl -fsSL -o miniconda.exe https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Windows-x86_64.exe
22+
- cmd: miniconda.exe /S /InstallationType=JustMe /D=%MINICONDA_DIRNAME%
2623
- cmd: set "PATH=%MINICONDA_DIRNAME%;%MINICONDA_DIRNAME%\\Scripts;%PATH%"
2724
- cmd: activate
28-
- conda config --set always_yes yes
29-
- conda install -c conda-forge python=3.7
30-
- conda info
31-
- conda env create --name cqgui -f cqgui_env.yml
25+
- mamba config --set always_yes yes
26+
- mamba info
27+
- mamba env create --name cqgui -f cqgui_env.yml
3228
- sh: source activate cqgui
3329
- cmd: activate cqgui
34-
- conda list
30+
- mamba list
3531
- pip install pytest pluggy pytest-qt
3632
- pip install pytest-mock pytest-cov pytest-repeat codecov pyvirtualdisplay
3733

cq_editor/cq_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cadquery as cq
22
from cadquery.occ_impl.assembly import toCAF
33

4-
from typing import List, Union, Tuple
4+
from typing import List, Union
55
from imp import reload
66
from types import SimpleNamespace
77

@@ -17,7 +17,7 @@ def find_cq_objects(results : dict):
1717

1818
return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if isinstance(v,cq.Workplane)}
1919

20-
def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape]]):
20+
def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Sketch]):
2121

2222
vals = []
2323

@@ -33,6 +33,11 @@ def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.
3333
vals.append(cq.Shape.cast(obj))
3434
elif isinstance(obj,list) and isinstance(obj[0],TopoDS_Shape):
3535
vals.extend(cq.Shape.cast(o) for o in obj)
36+
elif isinstance(obj, cq.Sketch):
37+
if obj._faces:
38+
vals.append(obj._faces)
39+
else:
40+
vals.extend(obj._edges)
3641
else:
3742
raise ValueError(f'Invalid type {type(obj)}')
3843

@@ -110,12 +115,17 @@ def get_occ_color(ais : AIS_ColoredShape) -> QColor:
110115
def reload_cq():
111116

112117
# NB: order of reloads is important
118+
reload(cq.types)
113119
reload(cq.occ_impl.geom)
114120
reload(cq.occ_impl.shapes)
121+
reload(cq.occ_impl.importers.dxf)
115122
reload(cq.occ_impl.importers)
116123
reload(cq.occ_impl.solver)
117124
reload(cq.occ_impl.assembly)
125+
reload(cq.occ_impl.sketch_solver)
126+
reload(cq.hull)
118127
reload(cq.selectors)
128+
reload(cq.sketch)
119129
reload(cq.occ_impl.exporters.svg)
120130
reload(cq.cq)
121131
reload(cq.occ_impl.exporters.utils)

cqgui_env.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ dependencies:
99
- pyqtgraph
1010
- python=3.8
1111
- spyder=4
12-
- ocp=7.5
1312
- path.py
1413
- logbook
1514
- requests
16-
- ezdxf
17-
- typing_extensions
18-
- scipy
19-
- nptyping
20-
- nlopt
21-
- pip
22-
- pip:
23-
- "https://github.com/CadQuery/cadquery/archive/master.zip"
15+
- cadquery=master

tests/test_app.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,40 @@ def test_render_ais(main):
12621262
qtbot.wait(500)
12631263
assert(obj_tree_comp.CQ.childCount() == 2)
12641264

1265+
code_show_sketch = \
1266+
'''import cadquery as cq
1267+
1268+
s1 = cq.Sketch().rect(1,1)
1269+
s2 = cq.Sketch().segment((0,0), (0,3.),"s1")
1270+
1271+
show_object(s1)
1272+
show_object(s2)
1273+
'''
1274+
1275+
def test_render_sketch(main):
1276+
1277+
qtbot, win = main
1278+
1279+
obj_tree_comp = win.components['object_tree']
1280+
editor = win.components['editor']
1281+
debugger = win.components['debugger']
1282+
console = win.components['console']
1283+
1284+
# check that object was removed
1285+
obj_tree_comp._toolbar_actions[0].triggered.emit()
1286+
assert(obj_tree_comp.CQ.childCount() == 0)
1287+
1288+
# check that object was rendered usin explicit show_object call
1289+
editor.set_text(code_show_sketch)
1290+
debugger._actions['Run'][0].triggered.emit()
1291+
qtbot.wait(500)
1292+
assert(obj_tree_comp.CQ.childCount() == 2)
1293+
1294+
# test rendering via console
1295+
console.execute('show(s1); show(s2)')
1296+
qtbot.wait(500)
1297+
assert(obj_tree_comp.CQ.childCount() == 4)
1298+
12651299
def test_window_title(monkeypatch, main):
12661300

12671301
fname = 'test_window_title.py'

0 commit comments

Comments
 (0)
0