marcus7070 / cadquery

A parametric CAD scripting framework based on PythonOCC
https://cadquery.readthedocs.io
Other
0 stars 0 forks source link

Implement feature tree #1

Open marcus7070 opened 4 years ago

marcus7070 commented 4 years ago

References

Taken from here:

RoadMap: Planned Features

Selectors

tagged entities

support tagging entities when they are created, so they can be selected later on using that tag. ideally, tags are propagated to features that are created from these features ( ie, an edge tagged with ‘foo’ that is later extruded into a face means that face would be tagged with ‘foo’ as well )


Taken from cadquery/cadquery issue number 50 (not linking properly because I don't want to ping that issue with a link to this shitty draft):

Implement Feature Tree

CQ 2.0 should have a feature tree, which stores operations and their results in a way that can be searched and referenced by later steps.

Each branch in the tree should have an id, and an associated operation.

The tree will be stored in the modelling context.


Taken from cadquery/cadquery issue number 49:

Implement Selection by Operation ID

We need to be able to select geometry by the operationID that created it. This could require fingerprinting or other fancy tricks, since OCC does not provide an out-of-the-box way to identify which faces, edges, etc, were created by a given operation.

marcus7070 commented 4 years ago

^ GitHub is being silly, that's not this issue.

marcus7070 commented 4 years ago

An idea: Store a "feature" in an attribute of the CQ object every time a solid is created. Selectors can operate on a "feature" instead of the context solid.

part = (
    cq.Workplane("XY")
    .box(5, 5, 5)
    .box(1, 1, 10).tag("foo")
    .sphere(5)
    .faces(">X", tag="foo", feature=True)
)

^ will return the face of the tall thin box. feature=False would return the face of the first cube. Omitting the tag would select nothing, because it's looking for faces on the sphere.

feature=True could also be used without the tag argument, which would search the parent chain for the nearest .feature attribute, like how CQ already searches for the first solid to use and the context solid.

Rewrite all Boolean operators to include a call to CQ.create_feature(). .create_feature() takes a solid. For example, if the operation is a subtract then .create_feature() should be called with the solid to subtract.

CQ-editor could use feature tree display, where highlighting an item in the feature tree shows CQ.feature rather than CQ.objects.

marcus7070 commented 4 years ago

log_feature might be a better name than create_feature, since no solids are created during this call.

marcus7070 commented 4 years ago

Could do some fancy CQ.__getattribute__ stuff to log each method called on a CQ object, so that calls could be associated with CQ objects in the parent chain, or collected for features.

This would allow pretty icons next to each feature in the feature tree. Not too sure what else I could do with it.

marcus7070 commented 4 years ago

At the occ_impl layer, write a decorator that appends the returned object to occ_impl.feature stack. At the fluent API level, CQ.newObject pops the whole occ.impl.feature stack and saves it.

marcus7070 commented 4 years ago

I like storing the feature tree in CQ objects as part of the parent chain, because that enables garbage collection tied to the CQ object.