Moved Path ToolBit and Controller into Path.Tools module

This commit is contained in:
Markus Lampert
2022-08-10 20:39:53 -07:00
parent 1d27fb00ec
commit 20d2d4c8d0
27 changed files with 205 additions and 56 deletions

View File

@@ -40,6 +40,22 @@ SET(PathPythonOpGui_SRCS
Path/Op/Gui/Adaptive.py
)
SET(PathPythonTools_SRCS
Path/Tools/__init__.py
Path/Tools/Bit.py
Path/Tools/Controller.py
)
SET(PathPythonToolsGui_SRCS
Path/Tools/Gui/__init__.py
Path/Tools/Gui/Bit.py
Path/Tools/Gui/BitCmd.py
Path/Tools/Gui/BitEdit.py
Path/Tools/Gui/BitLibraryCmd.py
Path/Tools/Gui/BitLibrary.py
Path/Tools/Gui/Controller.py
)
SET(PathPythonPost_SRCS
Path/Post/__init__.py
Path/Post/Command.py
@@ -176,14 +192,6 @@ SET(PathScripts_SRCS
PathScripts/PathSurfaceSupport.py
PathScripts/PathThreadMilling.py
PathScripts/PathThreadMillingGui.py
PathScripts/PathToolBit.py
PathScripts/PathToolBitCmd.py
PathScripts/PathToolBitEdit.py
PathScripts/PathToolBitGui.py
PathScripts/PathToolBitLibraryCmd.py
PathScripts/PathToolBitLibraryGui.py
PathScripts/PathToolController.py
PathScripts/PathToolControllerGui.py
PathScripts/PathToolEdit.py
PathScripts/PathToolLibraryEditor.py
PathScripts/PathToolLibraryManager.py
@@ -334,6 +342,8 @@ SET(all_files
${PathPythonOpGui_SRCS}
${PathPythonPost_SRCS}
${PathPythonPostScripts_SRCS}
${PathPythonTools_SRCS}
${PathPythonToolsGui_SRCS}
${Generator_SRCS}
${PathPythonGui_SRCS}
${Tools_SRCS}
@@ -394,6 +404,20 @@ INSTALL(
Mod/Path/Path/Post
)
INSTALL(
FILES
${PathPythonTools_SRCS}
DESTINATION
Mod/Path/Path/Tools
)
INSTALL(
FILES
${PathPythonToolsGui_SRCS}
DESTINATION
Mod/Path/Path/Tools/Gui
)
INSTALL(
FILES
${PathPythonPostScripts_SRCS}

View File

@@ -82,8 +82,8 @@ class PathWorkbench(Workbench):
from PathScripts import PathGuiInit
from PathScripts import PathJobCmd
from PathScripts import PathToolBitCmd
from PathScripts import PathToolBitLibraryCmd
from Path.Tools.Gui import BitCmd as PathToolBitCmd
from Path.Tools.Gui import BitLibraryCmd as PathToolBitLibraryCmd
from PySide.QtCore import QT_TRANSLATE_NOOP
@@ -341,7 +341,7 @@ class PathWorkbench(Workbench):
for cmd in self.dressupcmds:
self.appendContextMenu("", [cmd])
menuAppended = True
if isinstance(obj.Proxy, PathScripts.PathToolBit.ToolBit):
if isinstance(obj.Proxy, Path.Tools.Bit.ToolBit):
self.appendContextMenu("", ["Path_ToolBitSave", "Path_ToolBitSaveAs"])
menuAppended = True
if menuAppended:

View File

@@ -34,7 +34,7 @@ import FreeCAD
import Path.Post.Utils as PostUtils
import Path.Post.UtilsParse as PostUtilsParse
from PathScripts import PathToolController
import Path.Tools.Controller as PathToolController
# to distinguish python built-in open function from the one declared below

View File

View File

@@ -29,13 +29,13 @@ import FreeCAD
from FreeCAD import Units
import Path.Post.Utils as PostUtils
import datetime
import PathScripts
import Path
TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
take a pseudo-gcode fragment outputted by a Path object, and output
real GCode suitable for a centroid 3 axis mill. This postprocessor, once placed
in the appropriate PathScripts folder, can be used directly from inside
in the appropriate Path/Tools folder, can be used directly from inside
FreeCAD, via the GUI importer or via python scripts with:
import centroid_post
@@ -188,7 +188,7 @@ def export(objectslist, filename, argstring):
if OUTPUT_COMMENTS:
for item in objectslist:
if hasattr(item, "Proxy") and isinstance(
item.Proxy, PathScripts.PathToolController.ToolController
item.Proxy, Path.Tools.Controller.ToolController
):
gcode += ";T{}={}\n".format(item.ToolNumber, item.Name)
gcode += linenumber() + ";begin preamble\n"

View File

@@ -22,6 +22,7 @@
import argparse
import Path.Post.Utils as PostUtils
import Path
import PathScripts
import shlex
import math
@@ -186,7 +187,7 @@ TOOLTIP = """
This is a postprocessor file for the Path workbench. It is used to
take a pseudo-gcode fragment outputted by a Path object, and output
real GCode suitable for a heidenhain 3 axis mill. This postprocessor, once placed
in the appropriate PathScripts folder, can be used directly from inside
in the appropriate Path/Tools folder, can be used directly from inside
FreeCAD, via the GUI importer or via python scripts with:
import heidenhain_post
@@ -343,7 +344,7 @@ def export(objectslist, filename, argstring):
LBLIZE_STAUS = False
# useful to get idea of object kind
if isinstance(obj.Proxy, PathScripts.PathToolController.ToolController):
if isinstance(obj.Proxy, Path.Tools.Controller.ToolController):
Object_Kind = "TOOL"
# like we go to change tool position
MACHINE_LAST_POSITION["X"] = 99999

View File

@@ -46,7 +46,7 @@ TOOLTIP = """ Post processor for UC-CNC.
This is a postprocessor file for the Path workbench. It is used to
take a pseudo-gcode fragment outputted by a Path object, and output
real GCode. This postprocessor, once placed in the appropriate
PathScripts folder, can be used directly from inside FreeCAD,
Path/Tools folder, can be used directly from inside FreeCAD,
via the GUI importer or via python scripts with:
import UCCNC_post
@@ -453,7 +453,7 @@ def export(objectslist, filename, argstring):
if OUTPUT_COMMENTS:
gcode += append("(preamble: begin)\n")
# for obj in objectslist:
# if isinstance(obj.Proxy, PathScripts.PathToolController.ToolController):
# if isinstance(obj.Proxy, Path.Tools.Controller.ToolController):
# gcode += append("(T{}={})\n".format(obj.ToolNumber, item.Name))
# error: global name 'PathScripts' is not defined
for line in PREAMBLE.splitlines(False):

View File

@@ -25,8 +25,8 @@
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import Path
import Path.Tools.Bit as PathToolBit
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
from Generators import toolchange_generator as toolchange_generator
from Generators.toolchange_generator import SpindleDirection
@@ -386,6 +386,6 @@ def FromTemplate(template, assignViewProvider=True):
if FreeCAD.GuiUp:
# need ViewProvider class in this file to support loading of old files
from PathScripts.PathToolControllerGui import ViewProvider
from Path.Tools.Gui.Controller import ViewProvider
FreeCAD.Console.PrintLog("Loading PathToolController... done\n")
FreeCAD.Console.PrintLog("Loading Path.Tools.Gui.Controller... done\n")

View File

@@ -25,10 +25,10 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import FreeCADGui
import Path
import Path.Tools.Bit as PathToolBit
import Path.Tools.Gui.BitEdit as PathToolBitEdit
import PathScripts.PathIconViewProvider as PathIconViewProvider
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathToolBitEdit as PathToolBitEdit
import os
__title__ = "Tool Bit UI"

View File

@@ -23,7 +23,7 @@
import FreeCAD
import FreeCADGui
import Path
import PathScripts
import Path.Tools
import os
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
@@ -56,7 +56,7 @@ class CommandToolBitCreate:
return FreeCAD.ActiveDocument is not None
def Activated(self):
obj = PathScripts.PathToolBit.Factory.Create()
obj = Path.Tools.Bit.Factory.Create()
obj.ViewObject.Proxy.setCreate(obj.ViewObject)
@@ -84,7 +84,7 @@ class CommandToolBitSave:
def selectedTool(self):
sel = FreeCADGui.Selection.getSelectionEx()
if 1 == len(sel) and isinstance(
sel[0].Object.Proxy, PathScripts.PathToolBit.ToolBit
sel[0].Object.Proxy, Path.Tools.Bit.ToolBit
):
return sel[0].Object
return None
@@ -146,7 +146,7 @@ class CommandToolBitLoad:
def selectedTool(self):
sel = FreeCADGui.Selection.getSelectionEx()
if 1 == len(sel) and isinstance(
sel[0].Object.Proxy, PathScripts.PathToolBit.ToolBit
sel[0].Object.Proxy, Path.Tools.Bit.ToolBit
):
return sel[0].Object
return None
@@ -155,7 +155,7 @@ class CommandToolBitLoad:
return FreeCAD.ActiveDocument is not None
def Activated(self):
if PathScripts.PathToolBitGui.LoadTools():
if Path.Tools.Bit.Gui.LoadTools():
FreeCAD.ActiveDocument.recompute()

View File

@@ -25,12 +25,12 @@
import FreeCAD
import FreeCADGui
import Path
import Path.Tools.Bit as PathToolBit
import Path.Tools.Gui.Bit as PathToolBitGui
import Path.Tools.Gui.BitEdit as PathToolBitEdit
import Path.Tools.Gui.Controller as PathToolControllerGui
import PathGui as PGui # ensure Path/Gui/Resources are loaded
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathToolBitEdit as PathToolBitEdit
import PathScripts.PathToolBitGui as PathToolBitGui
import PathScripts.PathToolControllerGui as PathToolControllerGui
import PathScripts.PathUtilsGui as PathUtilsGui
import PySide
import glob

View File

@@ -55,7 +55,7 @@ class CommandToolBitSelectorOpen:
return FreeCAD.ActiveDocument is not None
def Activated(self):
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
import Path.Tools.Gui.BitLibrary as PathToolBitLibraryGui
dock = PathToolBitLibraryGui.ToolBitSelector()
dock.open()
@@ -85,7 +85,7 @@ class CommandToolBitLibraryOpen:
return FreeCAD.ActiveDocument is not None
def Activated(self):
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
import Path.Tools.Gui.BitLibrary as PathToolBitLibraryGui
library = PathToolBitLibraryGui.ToolBitLibrary()

View File

@@ -25,10 +25,10 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import FreeCADGui
import Path
import Path.Tools.Controller as PathToolController
import Path.Tools.Gui.Bit as PathToolBitGui
import PathGui as PGui # ensure Path/Gui/Resources are loaded
import PathScripts
import PathScripts.PathGui as PathGui
import PathScripts.PathToolBitGui as PathToolBitGui
import PathScripts.PathToolEdit as PathToolEdit
import PathScripts.PathUtil as PathUtil
@@ -128,7 +128,7 @@ class ViewProvider:
def Create(name="Default Tool", tool=None, toolNumber=1):
Path.Log.track(tool, toolNumber)
obj = PathScripts.PathToolController.Create(name, tool, toolNumber)
obj = PathToolController.Create(name, tool, toolNumber)
ViewProvider(obj.ViewObject)
if not obj.Proxy.usesLegacyTool(obj):
# ToolBits are visible by default, which is typically not what the user wants
@@ -186,7 +186,7 @@ class ToolControllerEditor(object):
self.obj = obj
comboToPropertyMap = [("spindleDirection", "SpindleDir")]
enumTups = PathScripts.PathToolController.ToolController.propertyEnumerations(
enumTups = PathToolController.ToolController.propertyEnumerations(
dataType="raw"
)

View File

View File

View File

@@ -0,0 +1,123 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * Copyright (c) 2022 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import Path
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLanguage as PathLanguage
import PathScripts.Path.Log as Path.Log
import math
class Kink (object):
'''A Kink represents the angle at which two moves connect.
A positive kink angle represents a move to the left, and a negative angle represents a move to the right.'''
def __init__(self, m0, m1):
if m1 is None:
m1 = m0[1]
m0 = m0[0]
self.m0 = m0
self.m1 = m1
self.t0 = m0.anglesOfTangents()[1]
self.t1 = m1.anglesOfTangents()[0]
def deflection(self):
'''deflection() ... returns the tangential difference of the two edges at their intersection'''
return PathGeom.normalizeAngle(self.t1 - self.t0)
def normAngle(self):
'''normAngle() ... returns the angle opposite between the two tangents'''
# The normal angle is perpendicular to the "average tangent" of the kink. The question
# is into which direction to turn. One lies in the center between the two edges and the
# other is opposite to that. As it turns out, the magnitude of the tangents tell it all.
if self.t0 > self.t1:
return PathGeom.normalizeAngle((self.t0 + self.t1 + math.pi) / 2)
return PathGeom.normalizeAngle((self.t0 + self.t1 - math.pi) / 2)
def position(self):
'''position() ... position of the edge's intersection'''
return self.m0.positionEnd()
def x(self):
return self.position().x
def y(self):
return self.position().y
def __repr__(self):
return f"({self.x():.4f}, {self.y():.4f})[t0={180*self.t0/math.pi:.2f}, t1={180*self.t1/math.pi:.2f}, deflection={180*self.deflection()/math.pi:.2f}, normAngle={180*self.normAngle()/math.pi:.2f}]"
def createKinks(maneuver):
k = []
moves = maneuver.getMoves()
if moves:
move0 = moves[0]
prev = move0
for m in moves[1:]:
k.append(Kink(prev, m))
prev = m
if PathGeom.pointsCoincide(move0.positionBegin(), prev.positionEnd()):
k.append(Kink(prev, move0))
return k
def findDogboneKinks(maneuver, threshold):
'''findDogboneKinks(maneuver, threshold) ... return all kinks fitting the criteria.
A positive threshold angle returns all kinks on the right side, and a negative all kinks on the left side'''
if threshold > 0:
return [k for k in createKinks(maneuver) if k.deflection() > threshold]
if threshold < 0:
return [k for k in createKinks(maneuver) if k.deflection() < threshold]
# you asked for it ...
return createKinks(maneuver)
class Bone (object):
'''A Bone holds all the information of a bone and the kink it is attached to'''
def __init__(self, kink, angle, instr=None):
self.kink = kink
self.angle = angle
self.instr = [] if instr is None else instr
def addInstruction(self, instr):
self.instr.append(instr)
def kink_to_path(kink, g0=False):
return Path.Path([PathLanguage.instruction_to_command(instr) for instr in [kink.m0, kink.m1]])
def bone_to_path(bone, g0=False):
kink = bone.kink
cmds = []
if g0 and not PathGeom.pointsCoincide(kink.m0.positionBegin(), FreeCAD.Vector(0, 0, 0)):
pos = kink.m0.positionBegin()
param = {}
if not PathGeom.isRoughly(pos.x, 0):
param['X'] = pos.x
if not PathGeom.isRoughly(pos.y, 0):
param['Y'] = pos.y
cmds.append(Path.Command('G0', param))
for instr in [kink.m0, bone.instr[0], bone.instr[1], kink.m1]:
cmds.append(PathLanguage.instruction_to_command(instr))
return Path.Path(cmds)

View File

@@ -39,6 +39,9 @@ def Startup():
if not Processed:
Path.Log.debug("Initializing PathGui")
from Path.Op.Gui import Adaptive
from Path.Post import Command
from Path.Tools import Controller
from Path.Tools.Gui import Controller
from PathScripts import PathArray
from PathScripts import PathComment
from PathScripts import PathCustomGui
@@ -60,7 +63,6 @@ def Startup():
from PathScripts import PathMillFaceGui
from PathScripts import PathPocketGui
from PathScripts import PathPocketShapeGui
from Path.Post import Command
from PathScripts import PathProbeGui
from PathScripts import PathProfileGui
from PathScripts import PathPropertyBagGui
@@ -71,8 +73,6 @@ def Startup():
from PathScripts import PathSlotGui
from PathScripts import PathStop
from PathScripts import PathThreadMillingGui
from PathScripts import PathToolController
from PathScripts import PathToolControllerGui
from PathScripts import PathToolLibraryEditor
from PathScripts import PathToolLibraryManager
from PathScripts import PathUtilsGui

View File

@@ -24,11 +24,11 @@ from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import Path
import Path.Post.Processor as PostProcessor
from Path.Post.Processor import PostProcessor
import Path.Tools.Controller as PathToolController
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathSetupSheet as PathSetupSheet
import PathScripts.PathStock as PathStock
import PathScripts.PathToolController as PathToolController
import PathScripts.PathUtil as PathUtil
import json
import time

View File

@@ -28,6 +28,8 @@ from pivy import coin
import FreeCAD
import FreeCADGui
import Path
import Path.Tools.Gui.Bit as PathToolBitGui
import Path.Tools.Gui.Controller as PathToolControllerGui
import PathScripts.PathGeom as PathGeom
import PathScripts.PathGuiInit as PathGuiInit
import PathScripts.PathJob as PathJob
@@ -36,8 +38,6 @@ import PathScripts.PathJobDlg as PathJobDlg
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathSetupSheetGui as PathSetupSheetGui
import PathScripts.PathStock as PathStock
import PathScripts.PathToolBitGui as PathToolBitGui
import PathScripts.PathToolControllerGui as PathToolControllerGui
import PathScripts.PathToolLibraryEditor as PathToolLibraryEditor
import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils

View File

@@ -26,9 +26,10 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import FreeCADGui
import Path
import Path.Tools.Controller as PathToolController
import Path.Tools.Gui.BitLibraryCmd as PathToolBitLibraryCmd
import PathScripts
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBitLibraryCmd as PathToolBitLibraryCmd
import PathScripts.PathToolEdit as PathToolEdit
import PathScripts.PathToolLibraryManager as ToolLibraryManager
import PathScripts.PathUtils as PathUtils
@@ -289,7 +290,7 @@ class EditorPanel:
Path.Log.debug("tool: {}, toolnum: {}".format(tool, toolnum))
if self.job:
label = "T{}: {}".format(toolnum, tool.Name)
tc = PathScripts.PathToolController.Create(
tc = PathToolController.Create(
label, tool=tool, toolNumber=int(toolnum)
)
self.job.Proxy.addToolController(tc)
@@ -300,7 +301,7 @@ class EditorPanel:
and job.Label == targetlist
):
label = "T{}: {}".format(toolnum, tool.Name)
tc = PathScripts.PathToolController.Create(
tc = PathToolController.Create(
label, tool=tool, toolNumber=int(toolnum)
)
job.Proxy.addToolController(tc)

View File

@@ -23,8 +23,8 @@
import FreeCADGui
import FreeCAD
import Path
import Path.Tools.Controller as PathToolsController
import PathGui as PGui # ensure Path/Gui/Resources are loaded
import PathScripts
import PathScripts.PathJobCmd as PathJobCmd
import PathScripts.PathUtils as PathUtils
from PySide import QtGui
@@ -46,7 +46,7 @@ class PathUtilsUserInput(object):
for sel in FreeCADGui.Selection.getSelectionEx():
if hasattr(sel.Object, "Proxy"):
if isinstance(
sel.Object.Proxy, PathScripts.PathToolController.ToolController
sel.Object.Proxy, PathToolController.ToolController
):
if tc is None:
tc = sel.Object

View File

@@ -23,10 +23,10 @@
import FreeCAD
import Part
import Path
import Path.Tools.Controller as PathToolController
import PathFeedRate
import PathMachineState
import PathScripts.PathGeom as PathGeom
import PathScripts.PathToolController as PathToolController
import PathScripts.PathUtils as PathUtils
from PathTests.PathTestUtils import PathTestBase

View File

@@ -20,7 +20,7 @@
# * *
# ***************************************************************************
import PathScripts.PathToolBit as PathToolBit
import Path.Tools.Bit as PathToolBit
import PathTests.PathTestUtils as PathTestUtils
import glob
import os

View File

@@ -22,9 +22,9 @@
import FreeCAD
import Path
import Path.Tools.Bit as PathToolBit
import Path.Tools.Controller as PathToolController
import PathScripts.PathPreferences as PathPreferences
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathToolController as PathToolController
from PathTests.PathTestUtils import PathTestBase

View File

@@ -21,8 +21,8 @@
# ***************************************************************************
import FreeCAD
import Path.Tools.Bit as PathToolBit
import PathScripts.PathGeom as PathGeom
import PathScripts.PathToolBit as PathToolBit
import PathScripts.PathVcarve as PathVcarve
import math