Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Path] Add selection gate and set default turning diameter #4006

Merged
merged 5 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Mod/Path/PathScripts/PathOp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
# * *
# ***************************************************************************

import FreeCAD
import time

from PySide import QtCore

import Path
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils

from PathScripts.PathUtils import waiting_effects
from PySide import QtCore
import time

# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
Expand Down Expand Up @@ -92,7 +92,7 @@ class ObjectOp(object):
FeatureBasePanels ... Base geometry support for Arch.Panels
FeatureLocations ... Base location support
FeatureCoolant ... Support for operation coolant
FeatureDiameters ... Support for turning operation diameters
FeatureDiameters ... Support for turning operation diameters

The base class handles all base API and forwards calls to subclasses with
an op prefix. For instance, an op is not expected to overwrite onChanged(),
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(self, obj, name):
if FeatureDiameters & features:
obj.addProperty("App::PropertyDistance", "MinDiameter", "Diameter", QtCore.QT_TRANSLATE_NOOP("PathOp", "Lower limit of the turning diameter"))
obj.addProperty("App::PropertyDistance", "MaxDiameter", "Diameter", QtCore.QT_TRANSLATE_NOOP("PathOp", "Upper limit of the turning diameter."))

# members being set later
self.commandlist = None
self.horizFeed = None
Expand Down Expand Up @@ -361,6 +361,8 @@ def setDefaultValues(self, obj):
if FeatureDiameters & features:
obj.MinDiameter = '0 mm'
obj.MaxDiameter = '0 mm'
if job.Stock:
obj.MaxDiameter = job.Stock.Shape.BoundBox.XLength

if FeatureStartPoint & features:
obj.UseStartPoint = False
Expand Down
65 changes: 35 additions & 30 deletions src/Mod/Path/PathScripts/PathSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ class PathBaseGate(object):


class EGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
return sub and sub[0:4] == 'Edge'


class MESHGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
return obj.TypeId[0:4] == 'Mesh'


class VCARVEGate:
def allow(self, doc, obj, sub):
try:
shape = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if math.fabs(shape.Volume) < 1e-9 and len(shape.Wires) > 0:
Expand All @@ -77,10 +78,10 @@ def allow(self, doc, obj, sub):


class ENGRAVEGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
try:
shape = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if math.fabs(shape.Volume) < 1e-9 and len(shape.Wires) > 0:
Expand All @@ -98,10 +99,10 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument


class CHAMFERGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
try:
shape = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if math.fabs(shape.Volume) < 1e-9 and len(shape.Wires) > 0:
Expand All @@ -110,23 +111,21 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument
if shape.ShapeType == 'Edge':
return True

if (shape.ShapeType == 'Face'
and shape.normalAt(0,0) == FreeCAD.Vector(0,0,1)):
return True
if (shape.ShapeType == 'Face' and shape.normalAt(0, 0) == FreeCAD.Vector(0, 0, 1)):
return True

if sub:
subShape = shape.getElement(sub)
if subShape.ShapeType == 'Edge':
return True
elif (subShape.ShapeType == 'Face'
and subShape.normalAt(0,0) == FreeCAD.Vector(0,0,1)):
elif (subShape.ShapeType == 'Face' and subShape.normalAt(0, 0) == FreeCAD.Vector(0, 0, 1)):
return True

return False


class DRILLGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
PathLog.debug('obj: {} sub: {}'.format(obj, sub))
if hasattr(obj, "Shape") and sub:
shape = obj.Shape
Expand All @@ -136,34 +135,34 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument
return False


class FACEGate(PathBaseGate): # formerly PROFILEGate class using allow_ORIG method as allow()
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
class FACEGate(PathBaseGate): # formerly PROFILEGate class using allow_ORIG method as allow()
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
profileable = False

try:
obj = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if obj.ShapeType == 'Compound':
if sub and sub[0:4] == 'Face':
profileable = True

elif obj.ShapeType == 'Face': # 3D Face, not flat, planar?
profileable = True # Was False
elif obj.ShapeType == 'Face': # 3D Face, not flat, planar?
profileable = True # Was False

elif obj.ShapeType == 'Solid':
if sub and sub[0:4] == 'Face':
profileable = True

return profileable

def allow_ORIG(self, doc, obj, sub): # pylint: disable=unused-argument
def allow_ORIG(self, doc, obj, sub): # pylint: disable=unused-argument

profileable = False
try:
obj = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if obj.ShapeType == 'Edge':
Expand Down Expand Up @@ -193,13 +192,13 @@ def allow_ORIG(self, doc, obj, sub): # pylint: disable=unused-argument


class PROFILEGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
if sub and sub[0:4] == 'Edge':
return True

try:
obj = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if obj.ShapeType == 'Compound':
Expand All @@ -220,12 +219,12 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument


class POCKETGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument

pocketable = False
try:
obj = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

if obj.ShapeType == 'Edge':
Expand All @@ -246,28 +245,29 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument


class ADAPTIVEGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument

adaptive = True
try:
obj = obj.Shape
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except
return False

return adaptive


class CONTOURGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
pass


class PROBEGate:
def allow(self, doc, obj, sub):
pass


class TURNGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
PathLog.debug('obj: {} sub: {}'.format(obj, sub))
if hasattr(obj, "Shape") and sub:
shape = obj.Shape
Expand All @@ -276,8 +276,9 @@ def allow(self, doc, obj, sub): # pylint: disable=unused-argument
else:
return False


class ALLGate(PathBaseGate):
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
def allow(self, doc, obj, sub): # pylint: disable=unused-argument
if sub and sub[0:6] == 'Vertex':
return True
if sub and sub[0:4] == 'Edge':
Expand Down Expand Up @@ -336,13 +337,15 @@ def slotselect():
FreeCADGui.Selection.addSelectionGate(ALLGate())
FreeCAD.Console.PrintWarning("Slot Cutter Select Mode\n")


def surfaceselect():
gate = False
if(MESHGate() or FACEGate()):
gate = True
FreeCADGui.Selection.addSelectionGate(gate)
FreeCAD.Console.PrintWarning("Surfacing Select Mode\n")


def vcarveselect():
FreeCADGui.Selection.addSelectionGate(VCARVEGate())
FreeCAD.Console.PrintWarning("Vcarve Select Mode\n")
Expand All @@ -352,15 +355,16 @@ def probeselect():
FreeCADGui.Selection.addSelectionGate(PROBEGate())
FreeCAD.Console.PrintWarning("Probe Select Mode\n")


def customselect():
FreeCAD.Console.PrintWarning("Custom Select Mode\n")


def turnselect():
FreeCADGui.Selection.addSelectionGate(TURNGate())
FreeCAD.Console.PrintWarning("Turning Select Mode\n")



def select(op):
opsel = {}
opsel['Contour'] = contourselect # (depreciated)
Expand All @@ -384,6 +388,7 @@ def select(op):
opsel['Custom'] = customselect
opsel['TurnFace'] = turnselect
opsel['TurnProfile'] = turnselect
opsel['TurnPart'] = turnselect
return opsel[op]


Expand Down