CQ-editor icon indicating copy to clipboard operation
CQ-editor copied to clipboard

Add a random color function to CQ-editor

Open jdegenstein opened this issue 3 years ago • 12 comments

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

image

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

image

The optional parameter cfloat outputs a different data format for use with changing the color of assembly objects.

_rand_color(alpha = 0., cfloat=False)

jdegenstein avatar Nov 03 '22 17:11 jdegenstein

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...

adam-urbanczyk avatar Nov 04 '22 17:11 adam-urbanczyk

Yeah no problem, I will fix the PR. I must have committed the change to debugger.py incorrectly.

jdegenstein avatar Nov 04 '22 17:11 jdegenstein

This should be ready for review now. I fixed the diff for debugger.py, as discussed.

jdegenstein avatar Nov 07 '22 19:11 jdegenstein

@adam-urbanczyk just making sure you are aware that I have updated the PR as requested (as far as I can tell)

jdegenstein avatar Nov 10 '22 17:11 jdegenstein

Yes, thanks @jdegenstein ! I'll take a look next week.

adam-urbanczyk avatar Nov 10 '22 17:11 adam-urbanczyk

@jdegenstein There is an AppVeyor error across all platforms that may be related to your changes.

jmwright avatar Nov 11 '22 00:11 jmwright

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

jdegenstein avatar Nov 11 '22 00:11 jdegenstein

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 ??

jdegenstein avatar Nov 11 '22 00:11 jdegenstein

What did you change that could affect this test? Why would you need to update this value?

adam-urbanczyk avatar Nov 16 '22 20:11 adam-urbanczyk

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.

jdegenstein avatar Nov 16 '22 20:11 jdegenstein

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.

codecov[bot] avatar Nov 22 '22 07:11 codecov[bot]

That was complicated...@jdegenstein would you be able to add some tests, or should I do it?

adam-urbanczyk avatar Nov 22 '22 20:11 adam-urbanczyk

Thanks @jdegenstein

adam-urbanczyk avatar Jun 07 '24 20:06 adam-urbanczyk

Thank you and also thanks for your help on the tests @adam-urbanczyk

jdegenstein avatar Jun 10 '24 19:06 jdegenstein