Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for dark mode and a couple other things. #335

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/main
178 changes: 28 additions & 150 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,162 +1,40 @@
# CadQuery editor
A fork of cq-editor with support for selectable dark+light colour theme added. Also, an optional switch to delete the saved preferences from disk was added due to reasons. I started the fork out of simple need, as cq-editor + cadquery look very promising for some ideas I have - e.g. programmatically generated, parametrically comprehensive 3D models of inductor coils for use with KiCAD - at the same time that light backgrounds are unusable for me together with the dark ones I'm used to (actually they feel like a bright brick wall slamming into the visual cortex).

[![Build status](https://ci.appveyor.com/api/projects/status/g98rs7la393mgy91/branch/master?svg=true)](https://ci.appveyor.com/project/adam-urbanczyk/cq-editor/branch/master)
[![codecov](https://codecov.io/gh/CadQuery/CQ-editor/branch/master/graph/badge.svg)](https://codecov.io/gh/CadQuery/CQ-editor)
[![Build Status](https://dev.azure.com/cadquery/CQ-editor/_apis/build/status/CadQuery.CQ-editor?branchName=master)](https://dev.azure.com/cadquery/CQ-editor/_build/latest?definitionId=3&branchName=master)
[![DOI](https://zenodo.org/badge/136604983.svg)](https://zenodo.org/badge/latestdoi/136604983)
Some of the ways my changes accomplish things may be inelegant, break the OO paradigm or in other ways be abominable, due to (but probably not exclusively):

CadQuery GUI editor based on PyQT supports Linux, Windows and Mac.
1. This is the first time I use conda (I settled for micromamba).
2. This is the first time I make changes in any Python code I didn't write myself the same week.
3. This is the third time I do anything in Python except for a page-long text processing hack two years ago and a similar one five years ago.
4. This is the first time I do anything using the qt framework aside from a 'hello world' window sometime around the previous millenium.
5. This is the first time I use git for anything more esoteric than 'git clone'.

<img src="https://github.com/CadQuery/CQ-editor/raw/master/screenshots/screenshot2.png" alt="Screenshot" width="70%" >
<img src="https://github.com/CadQuery/CQ-editor/raw/master/screenshots/screenshot3.png" alt="Screenshot" width="70%" >
<img src="https://github.com/CadQuery/CQ-editor/raw/master/screenshots/screenshot4.png" alt="Screenshot" width="70%" >
It wasn't until I was done with the goal I had set that I was struck with the realization that there's a non-negligible probability that my dark mode implementation may be of use to someone, and that the socially responsible thing to do would be to publizise my work on github. Hence (5) above, in addition to, as a result of me from the outset only planning to risk myself being exposed to my code:

## Notable features
6. Any documentation in the commit is what I remember after everything was done, which is probably half if that.

* OCCT based
* Graphical debugger for CadQuery scripts
* Step through script and watch how your model changes
* CadQuery object stack inspector
* Visual inspection of current workplane and selected items
* Insight into evolution of the model
* Export to various formats
* STL
* STEP
The largest (only...?) difference between the conda environment dependencies in my fork w.r.t. the origin is a Python version bump to 3.10.? and the resulting versions upgrades of everything dependant on it. I probably didn't have good reasons, although I do remember something about a non-ancient qdarkstyle version and its requirements, although I may be confusing it with something else that may or may not be reality-related. Additionally, there may well remain unnecessary and forgotten packages I installed but ultimately didn't need.

## Installation - Pre-Built Packages (Recommended)
The steps to get my code running are something at least similar to the ones below:

### Release Packages
$ cd ~/
$ wget -qO- https://micromamba.snakepit.net/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
$ bin/micromamba shell init -s bash -p ~/micromamba

Stable release builds which do not require Anaconda are attached to the [latest release](https://github.com/CadQuery/CQ-editor/releases). Download the zip file for your operating system, extract it, and run the CQ-editor script for your OS (CQ-editor.cmd for Windows, CQ-editor.sh for Linux and MacOS). On Windows you should be able to simply double-click on CQ-editor.cmd. On Linux and MacOS you may need to make the script executable with `chmod +x CQ-editor.sh` and run the script from the command line. The script contains an environment variable export that may be required to get CQ-editor to launch correctly on MacOS Big Sur, so it is better to use the script than to launch CQ-editor directly.
$ git clone https://github.com/axhan/CQ-editor_themed.git
$ micromamba env create -f CQ-editor/cqgui_env.yml -n cqgui
$ micromamba activate cqgui
(cqgui) $ cd ~/micromamba/envs/cqgui

### Development Packages
(cqgui) $ micromamba install python=3.10.4 -c conda-forge
(cqgui) $ micromamba install cadquery=master -c CadQuery
(cqgui) $ micromamba install spyder -c conda-forge

Development builds are also available, but can be unstable and should be used at your own risk. Click on the newest build with a green checkmark [here](https://github.com/jmwright/CQ-editor/actions?query=workflow%3Abuild), wait for the _Artifacts_ section at the bottom of the page to load, and then click on the appropriate download for your operating system. Extract the archive file and run the shell (Linux/MacOS) or cmd (Windows) script in the root CQ-editor directory. The CQ-editor window should launch.
(cqgui) $ mkdir src
(cqgui) $ mv ~/CQ-editor src/
(cqgui) $ cd src/CQ-editor

## Installation (Anaconda)
# Test run:
(cqgui) $ python run.py

Use conda to install:
```
conda install -c cadquery -c conda-forge cq-editor=master
```
and then simply type `cq-editor` to run it. This installs the latest version built directly from the HEAD of this repository.

Alternatively clone this git repository and set up the following conda environment:
```
conda env create -f cqgui_env.yml -n cqgui
conda activate cqgui
python run.py
```

On some linux distributions (e.g. `Ubuntu 18.04`) it might be necessary to install additonal packages:
```
sudo apt install libglu1-mesa libgl1-mesa-dri mesa-common-dev libglu1-mesa-dev
```
On Fedora 29 the packages can be installed as follows:
```
dnf install -y mesa-libGLU mesa-libGL mesa-libGLU-devel
```

## Usage

### Showing Objects

By default, CQ-editor will display a 3D representation of all `Workplane` objects in a script with a default color and alpha (transparency). To have more control over what is shown, and what the color and alpha settings are, the `show_object` method can be used. `show_object` tells CQ-editor to explicity display an object, and accepts the `options` parameter. The `options` parameter is a dictionary of rendering options named `alpha` and `color`. `alpha` is scaled between 0.0 and 1.0, with 0.0 being completely opaque and 1.0 being completely transparent. The color is set using R (red), G (green) and B (blue) values, and each one is scaled from 0 to 255. Either option or both can be omitted.

```python
show_object(result, options={"alpha":0.5, "color": (64, 164, 223)})
```

Note that `show_object` works for `Shape` and `TopoDS_Shape` objects too. In order to display objects from the embedded Python console use `show`.

### Rotate, Pan and Zoom the 3D View

The following mouse controls can be used to alter the view of the 3D object, and should be familiar to CAD users, even if the mouse buttons used may differ.

* _Left Mouse Button_ + _Drag_ = Rotate
* _Middle Mouse Button_ + _Drag_ = Pan
* _Right Mouse Button_ + _Drag_ = Zoom
* _Mouse Wheel_ = Zoom

### Debugging Objects

There are multiple menu options to help in debugging a CadQuery script. They are included in the `Run` menu, with corresponding buttons in the toolbar. Below is a listing of what each menu item does.

* `Debug` (Ctrl + F5) - Instead of running the script completely through as with the `Render` item, it begins executing the script but stops at the first non-empty line, waiting for the user to continue execution manually.
* `Step` (Ctrl + F10) - Will move execution of the script to the next non-empty line.
* `Step in` (Ctrl + F11) - Will follow the flow of execution to the inside of a user-created function defined within the script.
* `Continue` (Ctrl + F12) - Completes execution of the script, starting from the current line that is being debugged.

It is also possible to do visual debugging of objects. This is possible by using the `debug()` function to display an object instead of `show_object()`. An alternative method for the following code snippet is shown below for highlighting a specific face, but it demonstrates one use of `debug()`.
```python
import cadquery as cq

result = cq.Workplane().box(10, 10, 10)

highlight = result.faces('>Z')

show_object(result, name='box')
debug(highlight)
```
Objects displayed with `debug()` are colored in red and have their alpha set so they are semi-transparent. This can be useful for checking for interference, clearance, or whether the expected face is being selected, as in the code above.

### Console Logging

Python's standard `print()` function will not output to the CQ-editor GUI, and `log()` should be used instead. `log()` will output the provided text to the _Log viewer_ panel, providing another way to debug CadQuery scripts. If you started CQ-editor from the command line, the `print()` function will output text back to it.

### Using an External Code Editor

Some users prefer to use an external code editor instead of the built-in Spyder-based editor that comes stock with CQ-editor. The steps below should allow CQ-editor to work alongside most text editors.

1. Open the Preferences dialog by clicking `Edit->Preferences`.
2. Make sure that `Code Editor` is selected in the left pane.
3. Check `Autoreload` in the right pane.
4. If CQ-editor is not catching the saves from your external editor, increasing `Autoreload delay` in the right pane may help. This issue has been reported when using vim or emacs.

### Exporting an Object

Any object can be exported to either STEP or STL format. The steps for doing so are listed below.

1. Highlight the object to be exported in the _Objects_ panel.
2. Click either `Export as STL` or `Export as STEP` from the `Tools` menu, depending on which file format you want to export. Both of these options will be disabled if an object is not selected in the _Objects_ panel.

Clicking either _Export_ item will present a file dialog that allows the file name and location of the export file to be set.

### Displaying All Wires for Debugging

**NOTE:** This is intended for debugging purposes, and if not removed, could interfere with the execution of your model in some cases.

Using `consolidateWires()` is a quick way to combine all wires so that they will display together in CQ-editor's viewer. In the following code, it is used to make sure that both rects are displayed. This technique can make it easier to debug in-progress 2D sketches.

```python
import cadquery as cq
res = cq.Workplane().rect(1,1).rect(3,3).consolidateWires()
show_object(res)
```

### Highlighting a Specific Face

Highlighting a specific face in a different color can be useful when debugging, or when trying to learn CadQuery selectors. The following code creates a separate, highlighted object to show the selected face in red. This is an alternative to using a `debug()` object, and in most cases `debug()` will provide the same result with less code. However, this method will allow the color and alpha of the highlight object to be customized.

```python
import cadquery as cq

result = cq.Workplane().box(10, 10, 10)

highlight = result.faces('>Z')

show_object(result)
show_object(highlight,'highlight',options=dict(alpha=0.1,color=(1.,0,0)))
```

### Naming an Object

By default, objects have a randomly generated ID in the object inspector. However, it can be useful to name objects so that it is easier to identify them. The `name` parameter of `show_object()` can be used to do this.

```python
import cadquery as cq

result = cq.Workplane().box(10, 10, 10)

show_object(result, name='box')
```
![Screenshot from 2022-04-08 16-18-39](https://user-images.githubusercontent.com/41844315/162455097-620813fb-4279-4013-a9d1-e7f3aaed12ab.png)
![Screenshot from 2022-04-08 16-18-55](https://user-images.githubusercontent.com/41844315/162455138-97051129-ad2f-48ca-94c7-b9316d37456a.png)
Loading