CadQuery / CQ-editor

CadQuery GUI editor based on PyQT
Apache License 2.0
775 stars 120 forks source link

CQparts support #17

Open adam-urbanczyk opened 6 years ago

adam-urbanczyk commented 6 years ago

Related to https://github.com/adam-urbanczyk/cadquery/pull/6

justbuchanan commented 5 years ago

I was able to get this working with a helper function that traverses the cqparts Assembly/Part tree and displays each one. I'm not sure what the best way to implement this with cqgi would be, but here's what I used for reference:

import cadquery as cq
import cqparts
import car # cqparts car example

 def show_cqparts_obj(cqobj):
    cqobj.build(recursive=True)
    def _show_recursive(cqobj, prefix=''):
        if isinstance(cqobj, cqparts.Part):
            # cq-editor detects cadquery objects in the global namespace
            globals()[prefix] = cqobj.world_obj
        elif isinstance(cqobj, cqparts.Assembly):
            if prefix: prefix = prefix + "_"
            for name, subobj in cqobj.components.items():
                _show_recursive(subobj, prefix + name)
    _show_recursive(cqobj)

 show_cqparts_obj(car.Car())
jmwright commented 5 years ago

In the FreeCAD workbench, I would just import and use the cqparts.display method. cqparts has the concept of an execution environment, and there's one for FreeCAD, which is why that worked.

https://github.com/cqparts/cqparts/blob/master/src/cqparts/display/freecad.py

So there are probably two ways to go.

  1. Modify show_object to properly support cqparts.
  2. Add a CQ-editor environment to cqparts.

The first one has the advantage that it makes the scripts more portable. However, I seem to remember there being some previous discussion on why that was more complicated than it sounds. @fragmuffin can you shed any light on this?

jmwright commented 5 years ago

Potentially relevant discussions:

https://github.com/dcowden/cadquery/issues/273

https://github.com/dcowden/cadquery/issues/279

adam-urbanczyk commented 5 years ago

@justbuchanan looks good, but let's think how to get rid of globals

fragmuffin commented 5 years ago

@justbuchanan - I'd be happy to do a PR in cqparts for this, I'll see if I can put something together ~tonight after work~ when I get time 🙄 ... alternatively, if you'd like to own it, I'd be equally happy with a PR from you.

@adam-urbanczyk - do you have any suggestions for removing globals()?

adam-urbanczyk commented 5 years ago

@fragmuffin @justbuchanan if you could add a function to cqparts that flattens Part/Assembly to a flat list of:

[(CQ object, properties dict),...]

that would be it I think. Then it would be really easy to display it in CQ-editor.

zignig commented 5 years ago

I have an extractor in cqparts_bucket that flattents a cqparts assembly.

https://github.com/zignig/cqparts_bucket/blob/master/svg_test.py#L17

adam-urbanczyk commented 5 years ago

OK good, I can add it to cq_utils submodule in this project and extend show_object accordingly. Does everyone agree that it is the way to go?

jmwright commented 5 years ago

No objections.

justbuchanan commented 5 years ago

Sounds good to me.

A couple random thoughts:

  1. It would be nice to give each part a human-readable name. I was doing this before by just concatenating a part's "component" name with those of its parent components/assemblies.
  2. For now, a flat list of parts in the "CQ models" pane should be fine. Eventually though, it would be nice to consider a tree view that reflects the structure of the assembly.
jmwright commented 5 years ago

Adding a couple more links to this issue.

https://github.com/CadQuery/cqparts

https://groups.google.com/forum/m/#!topic/cadquery/cgdmkO5oq8E

Where does CQParts support for CadQuery 2.0 stand?

fragmuffin commented 5 years ago

@jmwright

Where does CQParts support for CadQuery 2.0 stand?

The most suitable description would be "long overdue". But perhaps a more useful description is "on its way".

I've started a PR cqparts/cqparts#155, will be working on it this week.

jmwright commented 5 years ago

@fragmuffin Awesome, thanks! There will be plenty of excited users when cqparts is compatible with CQ 2.0 and Python-OCC.

fragmuffin commented 5 years ago

Yes! I agree. It's actually passing all the core tests now, in the feature/freecad-occ branch. I've just got to put the hours in to release it.... but I'll definitely be focusing on that this week.

Andrei-Pozolotin commented 4 years ago

+1