Milling an area with open edges

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Milling an area with open edges

Post by Russ4262 »

MRx wrote: Sun Jul 11, 2021 3:28 pm Hi,

I think I figured out what the problem is, I selected wire instead of extend face

Wire:
R2u0pE.png
Face:
...
Afternoon sir.
More detail is necessary to troubleshoot the issue(s) presented. I am interested in the first image, where the path cuts back into the model. What settings did you use? Do you have a file with two Adaptive operations, one using the "wire" version and one using the "extend face" version?

MRx wrote: Sun Jul 11, 2021 3:28 pm ... a serious issue got introduced with FC 0.20
https://forum.freecadweb.org/viewtopic.php?f=15&t=60037
This is simply not true, ... apart from eliminating edge processing. :?
These bugs are within the Adaptive path-generation algorithm. The only changes to Adaptive in 0.20_pre are related to the Extensions upgrade. These upgrades did not touch the path-generation portion of Adaptive, only the shapes fed to its algorithm.

For example, take your last image that only has the profile path with a stray cutting through the model. Edit that operation in the file provided, and change the step over to 22% instead of the default 20% and the Adaptive op generates correct paths. The Adaptive op has pre-existing internal path-generation bugs. The recent Extensions upgrade to Adaptive is providing that op more complex shapes in greater quantities. Consequently, the existing bugs will be manifest more frequently - which can be a positive for Adaptive so we can get a better idea of what might trigger the bugs.

Yes, please feel free to file a bug report in the bug tracker for this Adaptive issue. Please refer to Bug #4658 and related thread, Re: Pocket clearing struggle to see if the error is a duplicate of the current registered bug. There are other historical threads that report Adaptive flaws, such as Why is the Adaptive Path eating my part? and Adaptive Clearing Fault.


Thanks for posting issues here in the forum and helping improve FreeCAD. Much appreciated!

Russell

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.25220 +3 (Git)
Build type: Release
Branch: refactor/path_array
Hash: d7582cb84b8ddb1dcb20fb8df265c6995785d190
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

Russ4262 wrote: Sun Jul 11, 2021 7:21 pm
... a serious issue got introduced with FC 0.20
This is simply not true, ... apart from eliminating edge processing. :?
This is what I meant, because it eliminated the paths generated with FC 0.19 for my existing object (anyway it's fixed :-)
These bugs are within the Adaptive path-generation algorithm. The only changes to Adaptive in 0.20_pre are related to the Extensions upgrade. These upgrades did not touch the path-generation portion of Adaptive, only the shapes fed to its algorithm.

For example, take your last image that only has the profile path with a stray cutting through the model. Edit that operation in the file provided, and change the step over to 22% instead of the default 20% and the Adaptive op generates correct paths. The Adaptive op has pre-existing internal path-generation bugs. The recent Extensions upgrade to Adaptive is providing that op more complex shapes in greater quantities. Consequently, the existing bugs will be manifest more frequently - which can be a positive for Adaptive so we can get a better idea of what might trigger the bugs.
Those are minor issues, as long as some other parameters are able to fix it it should be fine (and can be documented accordingly).
I also need to get used to those features for some time now. Those features are just available at the right time for me.
Tomorrow I'll test the generated path.

Thank you for your support!
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

I tested the extensions feature with my actual object and mostly it works well, however I have a few situations where it has some issues.

I simplified the issue and created a new object:
TEomKM.png
TEomKM.png (36.97 KiB) Viewed 1554 times
Selecting the object by outline (this is necessary for objects with planes on a different Z height).

----

Extend face extends to a round corner, while extending wires does not do that yet.
Iwts8n.png
Iwts8n.png (4.98 KiB) Viewed 1552 times
Extending wires:
MsCYEy.png
MsCYEy.png (6.66 KiB) Viewed 1551 times

----

The part of my original object:
QwAxpE.png
QwAxpE.png (20.7 KiB) Viewed 1547 times
----

How about converting the lines to a simple face and treat it as a face - eg when outline is selected and the X/Y wires are closed?
Z needs to be ignored (or at least the highest Z coordinate of all wires should be used)
Attachments
extensions.FCStd
(434.51 KiB) Downloaded 23 times
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

Seems like I'm not able to attach more files to the previous post, another screenshot with a fillet:
uYpRcj.png
uYpRcj.png (57.5 KiB) Viewed 1511 times
the circle issue seems to be in PathFeatureExtensions.py edge.xxParameter (I added -90 to correct it so far but not sure if that's correct, possibly there's some operation done on the source data which is wrong?)

Code: Select all

                    print("EDGE FirstParameter: %f %f" % (edge.FirstParameter, edge.LastParameter))
                    e3 = Part.makeCircle(r, circle.Center, circle.Axis, edge.FirstParameter * 180 / math.pi-90, edge.LastParameter * 180 / math.pi-90)
                 
                    if endPoints(edge):
                        # need to construct the arc slice
                        e0 = Part.makeLine(edge.valueAt(edge.FirstParameter), e3.valueAt(e3.FirstParameter))
                        e2 = Part.makeLine(edge.valueAt(edge.LastParameter), e3.valueAt(e3.LastParameter))
                        return Part.Wire([e0, edge, e2, e3])

                    extWire = Part.Wire([e3])
                    self.extFaces = [self._makeCircularExtFace(edge, extWire)]
                    return extWire

"PathFeatureExtensions.py" 616L, 24090C written
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

Code: Select all

-            e2 = PathGeom.flipEdge(e2)
-            e1 = Part.Edge(Part.LineSegment(e0.valueAt(e0.LastParameter), e2.valueAt(e2.FirstParameter)))
-            e3 = Part.Edge(Part.LineSegment(e2.valueAt(e2.LastParameter), e0.valueAt(e0.FirstParameter)))
+            #e2 = PathGeom.flipEdge(e2)
+            #e1 = Part.Edge(Part.LineSegment(e0.valueAt(e0.LastParameter), e2.valueAt(e2.FirstParameter)))
+            #e3 = Part.Edge(Part.LineSegment(e2.valueAt(e2.LastParameter), e0.valueAt(e0.FirstParameter)))
+            e1 = Part.Edge(Part.LineSegment(e0.valueAt(e0.FirstParameter), e2.valueAt(e2.FirstParameter)))
+            e3 = Part.Edge(Part.LineSegment(e2.valueAt(e2.LastParameter), e0.valueAt(e0.LastParameter)))
            wire = Part.Wire([e0, e1, e2, e3])
            self.wire = wire
            return wire
"PathFeatureExtensions.py" 630L, 25119C written
why is there a flipedge performed in PathFeatureExtensions? the commented part is the original code

the preview seems to be something now, but the path itself is still not okay (so something's still wrong with the coordinates)
jxKeCz.png
jxKeCz.png (54.69 KiB) Viewed 1468 times
the highlighted parts are at Z0 due to modifications at another place.
Attachments
extensions.FCStd
(516.17 KiB) Downloaded 23 times
Last edited by MRx on Thu Jul 15, 2021 6:28 pm, edited 1 time in total.
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

the areas and edges are just dumped together in a list and that's wrong

combineHorizontalFaces works well with different areas that's why extending areas has no problem, but the output is concatenated with selected edges which blows up the entire thing.

Ok I got it work for a single surface, it still has to be modified to support Edges on multiple heights

1. sort the edges flip them if needed
2. create a face
3. append the face to the list for combineHorizontal Faces
WSNkhi.png
WSNkhi.png (68.47 KiB) Viewed 1402 times

Code: Select all

def cmpEdge(a, b):
    if (abs(a[0]-b[0])<1e-05 and
        abs(a[1]-b[1])<1e-05):
        return True
    return False
    
    ...
    
    
    # Get faces selected by user
    for base, subs in obj.Base:
        for sub in subs:
            if sub.startswith("Face"):
                if sub not in avoidFeatures:
                    if obj.UseOutline:
                        face = base.Shape.getElement(sub)
                        # get outline with wire_A method used in PocketShape, but it does not play nicely later
                        # wire_A = TechDraw.findShapeOutline(face, 1, FreeCAD.Vector(0.0, 0.0, 1.0))
                        wire_B = face.Wires[0]
                        shape = Part.Face(wire_B)
                    else:
                        shape = base.Shape.getElement(sub)
                    regions.append(shape)
            elif sub.startswith("Edge"):
                # Discretize selected edges directly
                shape = base.Shape.getElement(sub)
                f.append(shape)

    if (len(f) != 0):
      EdgeList=list()
      endlen=len(f)
      EdgeList.append(f[0])
      f.remove(f[0])
      while len(EdgeList) != endlen:
       print("LENGTH EDGELIST: %d %d" % (len(EdgeList), endlen))
       lastEdge=EdgeList[len(EdgeList)-1]
       for i in f:
           if cmpEdge(lastEdge.valueAt(lastEdge.LastParameter), i.valueAt(i.FirstParameter)):
             print("regular edge check okay")
             EdgeList.append(i)
             f.remove(i)
             break
           elif cmpEdge(lastEdge.valueAt(lastEdge.LastParameter), i.valueAt(i.LastParameter)):
             b=PathGeom.flipEdge(i)
             print("flipping edge....")
             EdgeList.append(b)
             f.remove(i)
             break

    wire=Part.Wire(EdgeList)
    pf=Part.Face(wire) 
    regions.append(pf)
 
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

Attached the patch for getting edges work with Extensions.

by the way this forum does not allow to upload .diff or .patch files?

This patch creates a Face from the selected edges.
There are a few occasions where Edge selecting is needed. Eg. inside of the object if there's a triangle cutout on a lower Z level within a rectangular surface. Without Edge selecting it's not possible to clear such an area.

Still missing:
- extending corners (when selecting edges), what is the idea behind that, there's some user interface code included but obviously does something totally else?
ePKQD2.png
ePKQD2.png (50.04 KiB) Viewed 1381 times
tn4C6p.png
tn4C6p.png (44.27 KiB) Viewed 1381 times
yMkNAm.png
yMkNAm.png (66.05 KiB) Viewed 1381 times
The test file seems to be too big for the forum:
https://sundtek.de/support/extensions.FCStd
https://sundtek.de/support/pathscripts.diff
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

Regarding the -90° fix, basically the problem only applies to fillets, does anyone know what the core difference between a fillet circle and a draft circle is?
if a rectangle with rounded corners is created via draft wb the path tool is fine, but fillet based circles need -90° ?

Curves generated by the Fillet tool have a value set in Curve.Rotation, does anyone know how to apply this properly?
fillets.png
fillets.png (5.28 KiB) Viewed 1299 times
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Re: Milling an area with open edges

Post by MRx »

A fix for the fillet edges:

PathFeatureExtensions.py

Code: Select all

--- /Users/markus/devel/freecad/FreeCAD-git/src/Mod/Path/PathScripts/PathFeatureExtensions.py	2021-07-15 01:08:17.000000000 +0800
+++ PathFeatureExtensions.py	2021-07-15 22:26:02.000000000 +0800
@@ -328,7 +328,13 @@
 
                 # assuming the offset produces a valid circle - go for it
                 if r > 0:
-                    e3 = Part.makeCircle(r, circle.Center, circle.Axis, edge.FirstParameter * 180 / math.pi-90, edge.LastParameter * 180 / math.pi-90)
+                    if (abs(circle.Rotation.toEuler()[2]-180)<1e-5): # we really only support horizontal milling...
+                       negative=-1
+                    else:
+                       negative=1
+                    offdeg1=edge.FirstParameter * 180 / math.pi+circle.Rotation.toEuler()[0]*negative
+                    offdeg2=edge.LastParameter * 180 / math.pi+circle.Rotation.toEuler()[0]*negative
+                    e3 = Part.makeCircle(r, circle.Center, circle.Axis, offdeg1, offdeg2)
                     if endPoints(edge):
                         # need to construct the arc slice
                         e0 = Part.makeLine(edge.valueAt(edge.FirstParameter), e3.valueAt(e3.FirstParameter))
toEuler()[2] is turning the axis around so [0] will be the angle, while [2] is responsible for the direction.
9sQVe6.png
9sQVe6.png (4.67 KiB) Viewed 1262 times
Diff:
http://sundtek.de/support/pathfeature.diff
Post Reply