Merge pull request #9555 from Ondsel-Development/SanityFix

Path: Sanity fix
This commit is contained in:
sliptonic
2023-05-13 07:40:51 -05:00
committed by GitHub
2 changed files with 50 additions and 26 deletions

View File

@@ -29,7 +29,8 @@ macro(CheckInterModuleDependencies)
REQUIRES_MODS(BUILD_FLAT_MESH BUILD_MESH_PART)
REQUIRES_MODS(BUILD_OPENSCAD BUILD_MESH_PART BUILD_DRAFT)
REQUIRES_MODS(BUILD_PART_DESIGN BUILD_SKETCHER)
REQUIRES_MODS(BUILD_PATH BUILD_PART BUILD_MESH BUILD_ROBOT)
# REQUIRES_MODS(BUILD_PATH BUILD_PART BUILD_MESH BUILD_ROBOT)
REQUIRES_MODS(BUILD_PATH BUILD_PART BUILD_MESH)
REQUIRES_MODS(BUILD_RAYTRACING BUILD_PART)
REQUIRES_MODS(BUILD_REVERSEENGINEERING BUILD_PART BUILD_MESH)
REQUIRES_MODS(BUILD_ROBOT BUILD_PART)

View File

@@ -32,6 +32,7 @@ from PySide import QtCore, QtGui
import FreeCAD
import FreeCADGui
import Path
import Path.Log
import PathScripts
from collections import Counter
from datetime import datetime
@@ -42,10 +43,11 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
translate = FreeCAD.Qt.translate
LOG_MODULE = "PathSanity"
# Path.Log.setLevel(Path.Log.Level.INFO, LOG_MODULE)
# Path.Log.trackModule('PathSanity')
if True:
Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
Path.Log.trackModule(Path.Log.thisModule())
else:
Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule())
class CommandPathSanity:
@@ -57,32 +59,49 @@ class CommandPathSanity:
else:
filepath = Path.Preferences.macroFilePath()
if "%D" in filepath:
D = FreeCAD.ActiveDocument.FileName
if D:
D = os.path.dirname(D)
# in case the document is in the current working directory
if not D:
D = "."
else:
FreeCAD.Console.PrintError(
"Please save document in order to resolve output path!\n"
)
return None
filepath = filepath.replace("%D", D)
Path.Log.debug(filepath)
if "%d" in filepath:
d = FreeCAD.ActiveDocument.Label
filepath = filepath.replace("%d", d)
D = FreeCAD.ActiveDocument.FileName
if D:
D = os.path.dirname(D)
# in case the document is in the current working directory
if not D:
D = "."
else:
FreeCAD.Console.PrintError(
"Please save document in order to resolve output path!\n"
)
return None
filepath = filepath.replace("%D", D + os.path.sep)
if "%j" in filepath:
j = job.Label
filepath = filepath.replace("%j", j)
filepath = filepath.replace("%d", FreeCAD.ActiveDocument.Label)
filepath = filepath.replace("%j", job.Label)
if "%M" in filepath:
pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")
M = pref.GetString("MacroPath", FreeCAD.getUserAppDataDir())
filepath = filepath.replace("%M", M)
filepath = filepath.replace("%M", M+ os.path.sep)
# strip out all substitutions related to output splitting
for elem in ["%O", "%W", "%T", "%t", "%S"]:
filepath = filepath.replace(elem, "")
Path.Log.debug("filepath: {}".format(filepath))
# if there's no basename left, use the activedocument basename
fname = os.path.splitext(os.path.basename(filepath))
if fname[0] == "":
final = os.path.splitext(os.path.basename(FreeCAD.ActiveDocument.FileName))[
0
]
filepath = os.path.dirname(filepath) + os.path.sep + final + fname[1]
Path.Log.debug("filepath: {}".format(filepath))
# Make sure the filepath is fully qualified
if os.path.basename(filepath) == filepath:
filepath = f"{os.path.dirname(FreeCAD.ActiveDocument.FileName)}/{filepath}"
Path.Log.debug("filepath: {}".format(filepath))
@@ -116,6 +135,7 @@ class CommandPathSanity:
obj = FreeCADGui.Selection.getSelectionEx()[0].Object
self.outputpath = self.resolveOutputPath(obj)
Path.Log.debug(f"outputstring: {self.outputpath}")
data = self.__summarize(obj)
html = self.__report(data)
if html is not None:
@@ -507,7 +527,9 @@ class CommandPathSanity:
data = {"baseimage": "", "bases": ""}
try:
bases = {}
for name, count in Counter([obj.Proxy.baseObject(obj, o).Label for o in obj.Model.Group]).items():
for name, count in Counter(
[obj.Proxy.baseObject(obj, o).Label for o in obj.Model.Group]
).items():
bases[name] = str(count)
data["baseimage"] = self.__makePicture(obj.Model, "baseimage")
@@ -772,6 +794,7 @@ class CommandPathSanity:
FreeCADGui.SendMsgToActiveView("ViewSelection")
FreeCADGui.Selection.clearSelection()
obj.ViewObject.Proxy.editObject(obj)
Path.Log.debug(imagepath)
aview.saveImage("{}.png".format(imagepath), 320, 320, "Current")
aview.saveImage("{}_t.png".format(imagepath), 320, 320, "Transparent")
obj.ViewObject.Proxy.uneditObject(obj)