[finished] project: Making Part Extrude taking care of inner structure

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: project: Making Part Extrude taking care of inner structure

Post by adrianinsaval »

davidosterberg wrote: Tue Jan 11, 2022 6:50 am I don't think you are right here. PartDesign_Draft is TNP sensitive because it relies on FreeCAD's face numbering. The OCC function does not use face numbers, as long as we can identify what faces should be drafted inside the feature code, everything will be fine with respect to TNP.
agreed, as long as the faces are determined when recomputing and not by user selection there shouldn't be any issue
Addendum:
I will try to make a proposal for how we can use BRepOffsetAPI_DraftAngle to add the draft to the pad before it is fused/cut from the baseshape. It will not rely on topological naming. Any face that is perpendicular to the pad direction will be drafted, inner and outer wires does not matter. And I expect FreeCAD face numbering will remain constant with taper angle 0 or other.
keep in mind that we now have custom directions for pads an pockets so it's not sufficient to check if they are perpendicular, or are tapered pads only allowed for the normal direction?
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: project: Making Part Extrude taking care of inner structure

Post by chrisb »

uwestoehr wrote: Mon Jan 10, 2022 5:38 pm Most of my real-life sketches contains B-Splines (I even wrote this Wiki page: https://wiki.freecadweb.org/B-Splines ;) ). B-Splines are a basic feature of CAD in my opinion.
There is no doubt that B-splines are helpful or even needed. But that doesn't mean that they should be used whenever possible. The argument here is rather, that it is preferable to use the simplemost geometry. And I think we can at least agree on this one: planes are simpler than B-spline surfaces.
If things can be done with a Plane, they can from a mathematical point of view be done with a B-spline surface as well. But they shouldn't. There is more computing power needed for calculations, and, as my example above shows, in using them on a computer with finite precision there are practical differences too.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: project: Making Part Extrude taking care of inner structure

Post by TheMarkster »

uwestoehr wrote: Tue Jan 11, 2022 4:09 am
I could identify the problem to this:
- on making the offset wire, the resulting wire ends up at an arbitrary location. This only occurs for inner wires, outer wires keep their positions.
- when all offset wires would keep the position, the sewer succeeds. I could manage to make this work in the PD workbench, and there the trick is to make the offset of a wire and then move it to the desired direction. First moving, the offsetting fails.
- for the Part WB, no matter what I try, just making an offset of an inner wires moves the result to a strange location. Also other face this issue: https://dev.opencascade.org/content/bre ... d-occt-740
With this change (setting solid to false on line 533) it works well for me on OCCT 7.5.2:
Snip macro screenshot-41575d.png
Snip macro screenshot-41575d.png (103.4 KiB) Viewed 1728 times
Negative taper angles also work as long as the taper is not too much to cause an inner wire to intersect the outer wire.

I am not seeing the issue with inner wires moving to a new location when offsetting. Is there a way to reproduce the issue in python? I have 7.5.3 in Windows, but 7.5.2 in the Ubuntu VM where I compile. How about using Part 2d offset in the Gui on the same profile? Does the 2d offset there also produce the same issue? If not, then in that code there might be a solution.

The tapered faces are bspline surfaces, but the untapered faces are plane faces. An easy way to check for this is select the face, press Ctrl+Shift+P, and enter in the python console:

Code: Select all

elt.Surface.TypeId
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: project: Making Part Extrude taking care of inner structure

Post by davidosterberg »

I will try to make a proposal for how we can use BRepOffsetAPI_DraftAngle to add the draft to the pad before it is fused/cut from the baseshape
Now I tried it. It was straight-forward to implement a proof of concept.

I simply inserted this code at the end of the pad execute, just before the fuse or the cut.

Code: Select all

double angle = 10.0*3.14/180.0;    // hardcoded 10 degrees just for proof of concept
gp_Pln neutralPlane;  // TODO: we need to define the plane from the support face. For now we hardcode XY plane

BRepOffsetAPI_DraftAngle mkDraft;

mkDraft.Init(prism);          // prism is the shape that normal pad has made.

TopExp_Explorer xp;

for (xp.Init(prism, TopAbs_FACE); xp.More(); xp.Next())
{
    TopoDS_Face face = TopoDS::Face(xp.Current());

    // get the face normal
    double umin, umax, vmin, vmax;
    BRepTools::UVBounds(face,umin, umax, vmin, vmax);
    Handle(Geom_Surface) aSurface = BRep_Tool::Surface(face);
    GeomLProp_SLProps props(aSurface, umin, vmin, 1, 0.01);
    gp_Dir normal = props.Normal();


    if (std::fabs(normal*dir) > 1e-10)
        continue;

    mkDraft.Add(face, dir, angle, neutralPlane);
}

mkDraft.Build();
prism = mkDraft.Shape();
Screenshot_20220111_224511.png
Screenshot_20220111_224511.png (65.13 KiB) Viewed 1666 times

It works as expected. Inner and outer wires are supported automatically. The straight faces are planar and the circle genrated a cone shape. No BSpline.

keep in mind that we now have custom directions for pads an pockets so it's not sufficient to check if they are perpendicular, or are tapered pads only allowed for the normal direction?

Yes, indeed. It does not seem to work for arbitrary direction.

Appendix:
Something else that does not work is to extrude splines. How ironic :D
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: project: Making Part Extrude taking care of inner structure

Post by chrisb »

davidosterberg wrote: Tue Jan 11, 2022 10:01 pm The straight faces are planar and the circle genrated a cone shape. No BSpline.
:D :D :D
It does not seem to work for arbitrary direction.
From my point of view that is well acceptable.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: project: Making Part Extrude taking care of inner structure

Post by davidosterberg »

From my point of view we could conclude that the Draft based method is best when it works since it generates simpler geometries that can be used for sketching on and so on. But there are limitations: sketches with spline wires cannot be padded. And arbitrary direction only works if there are only straight lines in the sketch (no arcs).

One approach could be to try the Draft method first and then fall back on the Loft method. I think that would give the best of both worlds.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: project: Making Part Extrude taking care of inner structure

Post by chrisb »

davidosterberg wrote: Tue Jan 11, 2022 10:40 pm I think that would give the best of both worlds.
Indeed. And it it is quite natural that B-spline curves create B-spline surfaces.
B-splines currently don't work with taper in Part workbench nor do they work with PartDesign Draft; and I guess it would be very hard to calculate them.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: project: Making Part Extrude taking care of inner structure

Post by adrianinsaval »

davidosterberg wrote: Tue Jan 11, 2022 10:40 pm And arbitrary direction only works if there are only straight lines in the sketch (no arcs).
Is this because the faces are not identified as needing to be drafted or is there another issue at play?
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: project: Making Part Extrude taking care of inner structure

Post by davidosterberg »

adrianinsaval wrote: Wed Jan 12, 2022 1:17 pm
davidosterberg wrote: Tue Jan 11, 2022 10:40 pm And arbitrary direction only works if there are only straight lines in the sketch (no arcs).
Is this because the faces are not identified as needing to be drafted or is there another issue at play?
No the code understands that the face should be drafted. But the OCC class (BRepOffsetAPI_DraftAngle) does not know how to work on the surface type that you get when you extrude a circle at an angle. Again, a reason to prefer the simple surface types: Plane, Cylinder, Cone. Advantage is that it is clear if the operation worked or not. So we can implement a fallback method based on the more general loft.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: project: Making Part Extrude taking care of inner structure

Post by TheMarkster »

davidosterberg wrote: Tue Jan 11, 2022 10:40 pm From my point of view we could conclude that the Draft based method is best when it works since it generates simpler geometries that can be used for sketching on and so on. But there are limitations: sketches with spline wires cannot be padded. And arbitrary direction only works if there are only straight lines in the sketch (no arcs).

One approach could be to try the Draft method first and then fall back on the Loft method. I think that would give the best of both worlds.
Works for me. Another advantage of having cones and cylinders as faces is there is a macro that can flatten such faces.

If it is known which types of edges do not work, then it might be possible to check for them before attempting one of the methods rather than trying one and seeing if it fails.
Post Reply