dprojects / getDimensions

FreeCAD macro to get chipboards dimensions to cut
MIT License
22 stars 4 forks source link

Support for Cuts and Links #12

Closed johndoe2323 closed 1 year ago

johndoe2323 commented 1 year ago

Cuts (Part::Cut) and Links are not supported (App::Link), so they don't show in the final report.

The following lines fix this issue at the beginning of the routine selectFurniturePart, at line 1945:

    #support for nested cuts
    while iObj.TypeId == "Part::Cut":
        iObj = iObj.Base

    #support for nested linked objects
    while iObj.TypeId == "App::Link":
        iObj = iObj.getLinkedObject()
johndoe2323 commented 1 year ago

Addition: Cuts and Links only don't work, when the Visibility setting for the report is "on".

See example files, run the report with Visibility = "on".

Cut-Examples.zip

johndoe2323 commented 1 year ago

As I cut my panels for system 32 holes with cylinders, this would be extremely useful to incorportate in the code.

dprojects commented 1 year ago

Addition: Cuts and Links only don't work, when the Visibility setting for the report is "on". See example files, run the report with Visibility = "on".

This is ok, because the logic is little different. Visibility on means you can turn off objects at the report with FreeCAD visibility feature. So if the Visibility is on you can play with visibility. The default has been set to off because many PartDesign objects are hidden by default.

Here is described: Docs - visibility

As I cut my panels for system 32 holes with cylinders, this would be extremely useful to incorportate in the code. The following lines fix this issue at the beginning of the routine selectFurniturePart, at line 1945:

I know this is not good to mix Cut and PartDesign objects. Also Cut not works with Mirror on LinkGroup. Did you tested magicDriller? there is 32 mm system embedded. The idea behind this tool is that base furniture parts are only Cube and Pad, it is easy to end up with infinite loop. So you need to be careful adding anything directly.

Currently, I want to improve a little bit rotation but I will look into that later. Keep it open. However, I don't want to just fix it... but I want to look closer at the "Cut way of designing" without PartDesign. I know I went maybe little too much to PartDesign side but... maybe there would be needed extension to the drilling tool with "Cut via dowels" option. I added special property to objects at magicCut: Skip copies in cut-list so this tool is working well with BOM, cut-list report.

johndoe2323 commented 1 year ago

It's actually pretty simple, my panels are basic cubes, my drill holes are cylinders that I group into arrays. All drillings go into one body as the cut operation only allows for one cutting tool object. I then reuse the panels in my projects via links ("Make Link").

See example file.

The benefit really is that you have only native FreeCAD objects and don't need custom macros if you want to change number of holes or the position of the holes. Custom macros need to be maintained and who knows how future API changes could affect custom code.

Std_cabinet_panel.zip

johndoe2323 commented 1 year ago

If you run getDimensions with my proposed fix the report will include both panels just fine.

dprojects commented 1 year ago

If you run getDimensions with my proposed fix the report will include both panels just fine.

The problem was related to Part :: Cut support. This is similar problem to LinkGroup. I added support for Part :: Cut so now should be fine.

The benefit really is that you have only native FreeCAD objects and don't need custom macros if you want to change number of holes or the position of the holes. Custom macros need to be maintained and who knows how future API changes could affect custom code.

The Woodworking workbench and all macros are maintained, developed by the same person, by me. So, if you use getDimensions, all tools at Woodworking workbench have the same level of reliability. Also all objects created via Woodworking workbench are FreeCAD objects, and they can be managed directly at FreeCAD.

However, I understand you may not want to mix "Boolean Cut", "Part objects" with PartDesign objects.

It's actually pretty simple, my panels are basic cubes, my drill holes are cylinders that I group into arrays. All drillings go into one body as the cut operation only allows for one cutting tool object. I then reuse the panels in my projects via links ("Make Link").

Maybe this week I will submit finally the rotation improvement for workbench, so I will look at the "Boolean" approach to the modeling. I see you want to have parametrized Cut. This is nice idea. I will look closer to it later.

Feel free to reopen this issue or create new one. Thanks.

johndoe2323 commented 1 year ago

Darek, unfortunately the test did not work, neither from my test file nor from the new test file you uploaded in the repository. In order to reproduce, please run the macro with visibility = on. (I cannot reopen the issue due to missing rights.)

dprojects commented 1 year ago

In order to reproduce, please run the macro with visibility = on.

I reopened this issue for you but this is wrong understanding of this feature. The "visibility = on" is related to the feature not to the objects. If the set is "on" it means all hidden objects will not be listed at the report, this is how the feature works. The content of Cut is always hidden so it is obvious, the content will not be listed. This is why I set the default to "off" to support normal Cut by default. This might be little confusing, but you need to set the feature to "off" if you work with Cut and hidden elements.

johndoe2323 commented 1 year ago

Ok thanks for clarification - it seems logical from programming perspective but not for practical use. After a cut all objects become invisible but the actual new cut object is visible and should therefore be included when visibility is set to "on". In my panel example I still want to see the panel after I cut the row of system-32-holes. Another example would be to cut a rabbet or groove into a panel - I still want to see the cut panel but not the original one nor the rabbet/groove-cutting-object. If I set the feature to off I would include all those unnecessary cutting objects...

dprojects commented 1 year ago

If I set the feature to off I would include all those unnecessary cutting objects...

Indeed, this is why I added special feature at magicCut and magicKnife. The feature add special property for unnecessary objects, so they are not listed at report. You can also add the property manually at FreeCAD or with your own script and this will be working.

This is problem to choose what object is right and should be listed and which one should not be listed. Maybe you could analyze the Cut structure, but I am not sure if you always would be able to create the correct report.

johndoe2323 commented 1 year ago

It's actually very simple - every cut consists of a Base object and a Tool object. Both become invisible after the cutting operation. The view actually displays the boolean operation of the cut. What we want in the getDimension-report is the Base object as it contains the source object you applied the cut on. Cuts can be nested so there can be cut objects as a base for another cut operation. Or a base object could be a linked object which is very common when you want to re-use panels. Thus my proposed code change within the furniture subroutine that loops through any nested cut- or link-objects.

See screenshot for further information of the structure of a cut:

Screenshot 2023-01-02 213237

dprojects commented 1 year ago

It's actually very simple - every cut consists of a Base object

In your simple sample, yes, the Base is used and the Tool is not needed. So you can replace the .OutList with .Base and will be working as well.

But the Boolean Cut operation also can be used with copies. Mostly to remove the common part. Look at the gif macro: Macro_MultiCuts

The macro hasn't got the magic property to turn off the tool copy from report but it shows the problem, you may see if you go with .Base solution.

johndoe2323 commented 1 year ago

I have not tested it but this example should work with my changes:

  1. In the gif you see that the clone-object is used as the Tool object in the cut. We don't want the Tool object to show anywhere.
  2. The macro generates a nested cut. The deepest Base object is the original panel we want on the report.

Edit: restored, sorry

johndoe2323 commented 1 year ago

(clone objects should not be used anyway as we now have linked objects, see https://wiki.freecadweb.org/Std_LinkMake)

dprojects commented 1 year ago

We don't want the Tool object to show anywhere.

The Tool is part of the Box so it need to be listed and calculated at the gif sample.

(clone objects should not be used anyway as we now have linked objects, see https://wiki.freecadweb.org/Std_LinkMake)

I like Links too but sometimes they not allow for some operations. They are not real objects so you can't do this with Links, you can't drill in Link: pilot holes for angles hinges

Also there are several problems with colors, because the Links store the colors in a different place.

sorry I edited your comment by mistake ;-)

johndoe2323 commented 1 year ago

We don't want the Tool object to show anywhere.

The Tool is part of the Box so it need to be listed and calculated at the gif sample.

It will be because there is still the original panelXZ object!

dprojects commented 1 year ago

It will be because there is still the original panelXZ object!

But it is only at FreeCAD XML content, it is not visible at 3D model if you not make copy of it. Visible is only the result of Cut. The container. Not its parts.

dprojects commented 1 year ago

Maybe there is needed another tool or option to fulfill all needs.

johndoe2323 commented 1 year ago

Do you have that multicut file at hand so I could test it? I don't have the multicut macro. Thank you!

dprojects commented 1 year ago

I will look into that after rotation feature. Probably I will add new option to Visibility drop-down menu, for example "CutTool" and this option will go thru .Base path, leaving the tools behind the report. I think this will be the best choice. This approach will allow to create any report with respect of all points of view.

dprojects commented 1 year ago

I extended the visibility feature with containers support. Now there are 3 new options:

This is more described here: docs - visibility

Let me know if you found it useful. You can also provide more sample files with your way of linking. Maybe I will be able to figure out the common way to support it all.

johndoe2323 commented 1 year ago

You are awesome! I will have a look at it at lunch time!

johndoe2323 commented 1 year ago

Tested it, my findings, when run with setting Visibility = "Cut Base":

  1. cut objects are reported properly, even if the cuts are nested => OK
  2. links to cut objects, even if the cuts are nested, are reported properly => OK
  3. cut objects based on linked objects are reported properly => OK

Unfortunately the "Cut Base" and "Cut Tool" settings are now under visibility, so objects are always included in the report, even if the Cut objects is invisible. I usually make stuff I don't need invisible. This is because I have template files for cabinet types and I only make visible from a template object what I need.

Is there any other option to exclude objects from the report? You were mentioning a dedicated property?

Thank you for your efforts!

johndoe2323 commented 1 year ago

From the code it looks as if it could be the "BOM" property which I tried to add to the Base property group without having an effect on the report. Like so: Screenshot 2023-01-04 122834

johndoe2323 commented 1 year ago

OK found it in the MagicKnife script, proper code to set it:

info = QT_TRANSLATE_NOOP("App::Property", "Allows to skip this duplicated copy in BOM, cut-list report.")
obj.addProperty("App::PropertyBool", "BOM", "Woodworking", info)

That could work for me - but would a dedicated setting option for Cut-objects be possible instead of being included in the visibility option?

johndoe2323 commented 1 year ago

Ok after a little testing with the BOM attribute: unfortunately the attribute is only checked after a lot of other checks are done in routine scanObjects. If I set the BOM attribute to false of a cut object it will be included nevertheless.

Is it possible to move lines 2489 - 2492 to line 2464 so that the attribute will be checked in any case?

dprojects commented 1 year ago

Is it possible to move lines 2489 - 2492 to line 2464 so that the attribute will be checked in any case?

I guess, yes. But I need to test it and re-think if I will not break something.

Unfortunately the "Cut Base" and "Cut Tool" settings are now under visibility, so objects are always included Is there any other option to exclude objects from the report?

I plan to improve the visibility "on" option in our desired way, to verify also the container visibility. This is why the gCurrentOB has been introduced. Now I have more control over the loop and caller object so I can check its visibility. Also the Cut Base and Cut Tool will be working with visibility always on. But I want to do it without impacting current functionality. So I need to go thru all tests and verify and calculate everything manually.

I will do it because I knew the visibility feature is not working with very complex structures and also the script is little far behind this what is offered by the Woodworking workbench. But also I need more real-life scenarios and figure out if your scenarios are only theoretical scenarios or real-life practice. FreeCAD have many complicated structures and also I would even say the visibility FreeCAD feature not works correctly, the object isn't grey but the object has Visibility inherited from parent.

dprojects commented 1 year ago

I decided to leave the "on" option as simple mode. The inherit mode will be the nesting mode, and developed as advanced. It will be easier to develop without impacting basic functionality. Now the Cut Base and Cut Tool are running with inherit mode, so you don't need the BOM special property. However the if is moved upper, as you proposed. I don't remember why I added this below the visibility check.

There is also test case updated with magicCut Dado joints. So you can see why I wanted Tools to be visible. Let me know if there is other scenario you are interested in?

johndoe2323 commented 1 year ago

I have a tricky one here - see example file. Base cube has the BOM attribute set to false. Is then linked in a cut. Cut does not show although itself it has no BOM attribute.

Cut-with-Link-Example and BOM Attribute.zip

dprojects commented 1 year ago

Yes, I know the linked element of the Cut content is not working. Both element are hidden, Base and Link, so the only way to show it, would be to get Visibility for Link path from Cut.

Currently, You can link whole Cut structure to make it parametric. You can create Base structure, make it even parametric with Spreadsheet and Link whole structure and this will be working, and will be parametric.

I am not sure if linking objects directly is better? Do you use this way in practice? BOM attribute not help here, I guess. There need to be additional check for Cut parent, for Links. But this should also working with many nesting Cuts and by turning on and off some of them, to be compliant with this what you see at 3D view. I would rather go to other type of option instead of trying to adjust inherit mode. But you need to know that Visibility, Grey at Tree and 3D view not match at FreeCAD.

dprojects commented 1 year ago

OK. I improved the whole feature. And now the Cut content visibility is in separate section so it is independent of Visibility feature option. The Visibility feature has new option parent that allows to inherit visibility only from nearest container. For your way of linking the option will be: parent + base, all is described at: Docs - visibility. So, now the tool should be more up-to-date ;-)

Also I clean the code little bit so it is more clear. And also I added section for debug loop so it will be more easier to understand how the loop is working.