CQ-editor
CQ-editor copied to clipboard
Add a random color function to CQ-editor
This PR adds a new function called rand_color to CQ-editor. This function gives a new random color each time it is called e.g. for a new object in show_object. Because of the way I have configured it (using random.seed) the colors are PRESERVED run-to-run. This function is nice when you need to highlight specific features and assign them a new color automatically, or as in the example below, when displaying objects in a loop.
f1 = cq.Workplane('XY').box(8, 3, 4)
ytr = 0
for i in range(0,10):
show_object(f1.translate((0,ytr,0)),options=rand_color(alpha=0))
ytr += 5

I also registered this function for use in the CQ-editor console. The color "palette" can also be changed by prepending the above code with this:
from random import seed
seed(123456)
f1 = cq.Workplane('XY').box(8, 3, 4)
ytr = 0
for i in range(0,10):
show_object(f1.translate((0,ytr,0)),options=rand_color(alpha=0))
ytr += 5

The optional parameter cfloat outputs a different data format for use with changing the color of assembly objects.
_rand_color(alpha = 0., cfloat=False)
Nice, I'd like to merge this. Could you check though why the diff indicated that the whole file was modified? I'd rather work with localized diffs...
Yeah no problem, I will fix the PR. I must have committed the change to debugger.py incorrectly.
This should be ready for review now. I fixed the diff for debugger.py, as discussed.
@adam-urbanczyk just making sure you are aware that I have updated the PR as requested (as far as I can tell)
Yes, thanks @jdegenstein ! I'll take a look next week.
@jdegenstein There is an AppVeyor error across all platforms that may be related to your changes.
I haven't looked into it recently, but I thought appveyor was failing on all PRs due to an issue with qtawesome, here: https://github.com/spyder-ide/qtawesome/issues/214
On second thought, it looks like you may be right:
=========================== short test summary info ===========================
FAILED tests/test_app.py::test_debug - assert 1 == 2
+ where 1 = <bound method LocalsModel.rowCount of <cq_editor.widgets.debugger.LocalsModel object at 0x000000EE643FA7A0>>()
+ where <bound method LocalsModel.rowCount of <cq_editor.widgets.debugger.LocalsModel object at 0x000000EE643FA7A0>> = <cq_editor.widgets.debugger.LocalsModel object at 0x000000EE643FA7A0>.rowCount
+ where <cq_editor.widgets.debugger.LocalsModel object at 0x000000EE643FA7A0> = <built-in method model of LocalsView object at 0x000000EE661D5900>()
+ where <built-in method model of LocalsView object at 0x000000EE661D5900> = <cq_editor.widgets.debugger.LocalsView object at 0x000000EE661D5900>.model
=========== 1 failed, 32 passed, 456 warnings in 150.19s (0:02:30) ============
TKOpenGl.WinSystem | Type: Error | ID: 6 | Severity: High | Message:
wglMakeCurrent() has failed. The handle is invalid.
Command exited with code 1
I think I might need to update test_app.py ??
What did you change that could affect this test? Why would you need to update this value?
I don't have a great understanding of what is happening in test_debug in tests/test_app.py. Any suggestions on what needs to be updated would be greatly appreciated. I attempted one change, but it seems multiple items need to be changed.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 89.07%. Comparing base (
98711d8) to head (65e61f4).
Additional details and impacted files
@@ Coverage Diff @@
## master #379 +/- ##
==========================================
+ Coverage 89.00% 89.07% +0.06%
==========================================
Files 19 19
Lines 1565 1575 +10
Branches 189 190 +1
==========================================
+ Hits 1393 1403 +10
Misses 139 139
Partials 33 33
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
That was complicated...@jdegenstein would you be able to add some tests, or should I do it?
Thanks @jdegenstein
Thank you and also thanks for your help on the tests @adam-urbanczyk