From 8dad6cf84d24508dd09477f0593de6be92d13221 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sun, 19 Jun 2022 13:35:59 -0500 Subject: [PATCH] Resolving bugs and rebasing for 0.21 merge --- src/Mod/Path/InitGui.py | 13 +- src/Mod/Path/PathScripts/PathCamoticsGui.py | 166 +++----------------- src/Mod/Path/PathScripts/PathPost.py | 2 +- src/Mod/Path/PathTests/TestPathPost.py | 1 - 4 files changed, 31 insertions(+), 151 deletions(-) diff --git a/src/Mod/Path/InitGui.py b/src/Mod/Path/InitGui.py index f023397743..85a6be3433 100644 --- a/src/Mod/Path/InitGui.py +++ b/src/Mod/Path/InitGui.py @@ -159,8 +159,13 @@ class PathWorkbench(Workbench): if PathPreferences.advancedOCLFeaturesEnabled(): try: - subprocess.call(["camsim", "-v"]) - toolcmdlist.append("Path_Camotics") + r = subprocess.run( + ["camotics", "--version"], capture_output=True, text=True + ).stderr.strip() + major, minor, patch = r.split(".") + if int(major) >= 1 and int(minor) >= 2 and int(patch) >= 2: + # subprocess.call(["camsim", "-v"]) + toolcmdlist.append("Path_Camotics") except FileNotFoundError: pass @@ -276,8 +281,8 @@ class PathWorkbench(Workbench): msg = translate( "Path", - "The currently selected unit schema: \n '{}'\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct gcode: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'" - ).format(current_schema) + "The currently selected unit schema: \n '{}'\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct gcode: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'", + ).format(current_schema) header = translate("Path", "Warning") msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg) diff --git a/src/Mod/Path/PathScripts/PathCamoticsGui.py b/src/Mod/Path/PathScripts/PathCamoticsGui.py index 4d5f4a8b34..c75f6e6a0d 100644 --- a/src/Mod/Path/PathScripts/PathCamoticsGui.py +++ b/src/Mod/Path/PathScripts/PathCamoticsGui.py @@ -20,30 +20,20 @@ # * * # *************************************************************************** + +from PySide.QtCore import QT_TRANSLATE_NOOP +from threading import Thread, Lock import FreeCAD import FreeCADGui -import PathScripts.PathLog as PathLog -from PySide.QtCore import QT_TRANSLATE_NOOP - -# from pivy import coin -# from itertools import cycle -# import FreeCADGui as Gui -import json - -# import tempfile -import os import Mesh - -# import string -# import random -import camotics -import PathScripts.PathPost as PathPost -import io - -# import time import PathScripts +import PathScripts.PathLog as PathLog +import PathScripts.PathPost as PathPost +import camotics +import io +import json +import os import queue -from threading import Thread, Lock import subprocess from PySide import QtCore, QtGui @@ -216,42 +206,24 @@ class CamoticsSimulation(QtCore.QObject): success = True finalgcode = "" - if self.job.SplitOutput: - PathLog.track(postlist) - for idx, section in enumerate(postlist): - # split = os.path.splitext(self.filename) - # partname = split[0] + "_{}".format(index) + split[1] - partname = section[0] - sublist = section[1] + for idx, section in enumerate(postlist): + partname = section[0] + sublist = section[1] - result, gcode, name = PathPost.CommandPathPost().exportObjectsWith( - sublist, - partname, - self.job, - idx, - extraargs="--no-show-editor", - ) - self.filenames.append(name) - PathLog.track(result, gcode, name) - - if result is None: - success = False - else: - finalgcode += gcode - - else: - finalpostlist = [item for slist in postlist for item in slist] - PathLog.track(postlist) result, gcode, name = PathPost.CommandPathPost().exportObjectsWith( - finalpostlist, - "allitems", + sublist, + partname, self.job, - 0, + idx, extraargs="--no-show-editor", ) self.filenames.append(name) - success = result is not None - finalgcode = gcode + PathLog.track(result, gcode, name) + + if result is None: + success = False + else: + finalgcode += gcode if not success: return @@ -273,102 +245,6 @@ class CamoticsSimulation(QtCore.QObject): def cancel(self): pass - # def makeCoinMesh(self, surface): - # # this doesn't work yet - # sg = Gui.ActiveDocument.ActiveView.getSceneGraph(); - # color = coin.SoBaseColor() - # color.rgb = (1, 0, 1) - # coords = coin.SoTransform() - # node = coin.SoSeparator() - # node.addChild(color) - # node.addChild(coords) - - # end = [-1] - # vertices = list(zip(*[iter(surface['vertices'])] * 3)) - # #polygons = list(zip(*[iter(vertices)] * 3, cycle(end))) - # polygons = list(zip(*[iter(range(len(vertices)))] * 3, cycle(end))) - - # print(vertices) - # print(polygons) - - # data=coin.SoCoordinate3() - # face=coin.SoIndexedFaceSet() - # node.addChild(data) - # node.addChild(face) - - # i = 0 - # for v in vertices: - # data.point.set1Value(i, v[0], v[1], v[2]) - # i += 1 - # i = 0 - # for p in polygons: - # try: - # face.coordIndex.set1Value(i, p) - # i += 1 - # except Exception as e: - # print(e) - # print(i) - # print(p) - - # sg.addChild(node) - - # def Activated(self): - - # s = self.SIM - # print('activated') - # print (s.is_running()) - - # if s.is_running(): - # print('interrupted') - # s.interrupt() - # s.wait() - # else: - # try: - # surface = s.get_surface('python') - # except Exception as e: - # print(e) - # pp = CommandPathPost() - # job = FreeCADGui.Selection.getSelectionEx()[0].Object - - # s = camotics.Simulation() - # s.set_metric() - # s.set_resolution('high') - - # bb = job.Stock.Shape.BoundBox - # s.set_workpiece(min = (bb.XMin, bb.YMin, bb.ZMin), max = (bb.XMax, bb.YMax, bb.ZMax)) - - # shapemap = {'ballend': 'Ballnose', - # 'endmill': 'Cylindrical', - # 'v-bit' : 'Conical', - # 'chamfer': 'Snubnose'} - - # for t in job.Tools.Group: - # s.set_tool(t.ToolNumber, - # metric = True, - # shape = shapemap.get(t.Tool.ShapeName, 'Cylindrical'), - # length = t.Tool.Length.Value, - # diameter = t.Tool.Diameter.Value) - - # gcode = job.Path.toGCode() #temporary solution!!!!! - # s.compute_path(gcode) - # s.wait() - - # print(s.get_path()) - - # tot = sum([step['time'] for step in s.get_path()]) - - # print(tot) - - # for t in range(1, int(tot), int(tot/10)): - # print(t) - # s.start(callback, time=t) - # while s.is_running(): - # time.sleep(0.1) - - # s.wait() - - # surface = s.get_surface('binary') - # self.addMesh(surface) def buildproject(self): # , files=[]): PathLog.track() diff --git a/src/Mod/Path/PathScripts/PathPost.py b/src/Mod/Path/PathScripts/PathPost.py index bc4f73d0f8..9062f31ebb 100644 --- a/src/Mod/Path/PathScripts/PathPost.py +++ b/src/Mod/Path/PathScripts/PathPost.py @@ -42,7 +42,7 @@ from PySide.QtCore import QT_TRANSLATE_NOOP LOG_MODULE = PathLog.thisModule() -if False: +if True: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: diff --git a/src/Mod/Path/PathTests/TestPathPost.py b/src/Mod/Path/PathTests/TestPathPost.py index 67f4323164..c6bb4ebad6 100644 --- a/src/Mod/Path/PathTests/TestPathPost.py +++ b/src/Mod/Path/PathTests/TestPathPost.py @@ -206,7 +206,6 @@ class TestBuildPostList(unittest.TestCase): self.job.OrderOutputBy = "Operation" def test010(self): - # check that function returns correct hash postlist = PathPost.buildPostList(self.job) self.assertTrue(type(postlist) is list)