Skip to content

Commit

Permalink
refactor Sanity
Browse files Browse the repository at this point in the history
Logic is more modular with many more unit tests.
Reduced dependence on GUI
Cleaner template structure
  • Loading branch information
Brad Collette authored and sliptonic committed Apr 26, 2024
1 parent d92f74e commit 8ca50d0
Show file tree
Hide file tree
Showing 16 changed files with 2,021 additions and 1,642 deletions.
25 changes: 20 additions & 5 deletions src/Mod/CAM/CMakeLists.txt
Expand Up @@ -94,14 +94,21 @@ SET(PathPythonMainGui_SRCS
Path/Main/Gui/JobCmd.py
Path/Main/Gui/JobDlg.py
Path/Main/Gui/PreferencesJob.py
Path/Main/Gui/Sanity.py
Path/Main/Gui/Sanity_Bulb.svg
Path/Main/Gui/Sanity_Caution.svg
Path/Main/Gui/Sanity_Note.svg
Path/Main/Gui/Sanity_Warning.svg
Path/Main/Gui/SanityCmd.py
Path/Main/Gui/Simulator.py
)

SET(PathPythonMainSanity_SRCS
Path/Main/Sanity/Sanity.py
Path/Main/Sanity/ImageBuilder.py
Path/Main/Sanity/ReportGenerator.py
Path/Main/Sanity/HTMLTemplate.py
Path/Main/Sanity/Sanity_Bulb.svg
Path/Main/Sanity/Sanity_Caution.svg
Path/Main/Sanity/Sanity_Note.svg
Path/Main/Sanity/Sanity_Warning.svg
)

SET(PathPythonTools_SRCS
Path/Tool/__init__.py
Path/Tool/Bit.py
Expand Down Expand Up @@ -289,6 +296,7 @@ SET(Tests_SRCS
Tests/test_filenaming.fcstd
Tests/test_geomop.fcstd
Tests/test_holes00.fcstd
Tests/TestCAMSanity.py
Tests/TestCentroidPost.py
Tests/TestGrblPost.py
Tests/TestLinuxCNCPost.py
Expand Down Expand Up @@ -376,6 +384,7 @@ SET(all_files
${PathPythonDressupGui_SRCS}
${PathPythonMain_SRCS}
${PathPythonMainGui_SRCS}
${PathPythonMainSanity_SRCS}
${PathPythonOp_SRCS}
${PathPythonOpGui_SRCS}
${PathPythonPost_SRCS}
Expand Down Expand Up @@ -468,6 +477,12 @@ INSTALL(
DESTINATION
Mod/CAM/Path/Main/Gui
)
INSTALL(
FILES
${PathPythonMainSanity_SRCS}
DESTINATION
Mod/CAM/Path/Main/Sanity
)

INSTALL(
FILES
Expand Down
1 change: 1 addition & 0 deletions src/Mod/CAM/InitGui.py
Expand Up @@ -75,6 +75,7 @@ def Initialize(self):
import Path.GuiInit

from Path.Main.Gui import JobCmd as PathJobCmd
from Path.Main.Gui import SanityCmd as SanityCmd
from Path.Tool.Gui import BitCmd as PathToolBitCmd
from Path.Tool.Gui import BitLibraryCmd as PathToolBitLibraryCmd

Expand Down
3 changes: 2 additions & 1 deletion src/Mod/CAM/Path/GuiInit.py
Expand Up @@ -52,9 +52,10 @@ def Startup():

from Path.Main.Gui import Fixture
from Path.Main.Gui import Inspect
from Path.Main.Gui import Sanity
from Path.Main.Gui import Simulator

from Path.Main.Sanity import Sanity

from Path.Op.Gui import Adaptive
from Path.Op.Gui import Array
from Path.Op.Gui import Comment
Expand Down
90 changes: 76 additions & 14 deletions src/Mod/CAM/Path/Main/Gui/Job.py
Expand Up @@ -121,29 +121,91 @@ def attach(self, vobj):
if not hasattr(self, "stockVisibility"):
self.stockVisibility = False

# setup the axis display at the origin
# Setup the axis display at the origin
self.switch = coin.SoSwitch()
self.sep = coin.SoSeparator()
self.axs = coin.SoType.fromName("SoAxisCrossKit").createInstance()
self.axs.set("xHead.transform", "scaleFactor 2 3 2")
self.axs.set("yHead.transform", "scaleFactor 2 3 2")
self.axs.set("zHead.transform", "scaleFactor 2 3 2")

#Adjust the axis heads if needed, the scale here is just for the head
self.axs.set("xHead.transform", "scaleFactor 1.5 1.5 1")
self.axs.set("yHead.transform", "scaleFactor 1.5 1.5 1")
self.axs.set("zHead.transform", "scaleFactor 1.5 1.5 1")

# Adjust the axis heads if needed, the scale here is just for the head
self.axs.set("xHead.transform", "translation 50 0 0")
self.axs.set("yHead.transform", "translation 0 50 0")
self.axs.set("zHead.transform", "translation 0 0 50")

# Adjust the axis line width if needed
self.axs.set("xAxis.transform", "scaleFactor 0.5 0.5 1")
self.axs.set("xAxis.appearance.drawStyle", "lineWidth 9")
self.axs.set("yAxis.transform", "scaleFactor 0.5 0.5 1")
self.axs.set("yAxis.appearance.drawStyle", "lineWidth 9")
self.axs.set("zAxis.transform", "scaleFactor 0.5 0.5 1")
self.axs.set("zAxis.appearance.drawStyle", "lineWidth 9")

self.sca = coin.SoType.fromName("SoShapeScale").createInstance()
self.sca.setPart("shape", self.axs)
self.sca.scaleFactor.setValue(0.5)
self.sca.scaleFactor.setValue(1) # Keep or adjust if needed

self.mat = coin.SoMaterial()
self.mat.diffuseColor = coin.SbColor(0.9, 0, 0.9)
self.mat.transparency = 0.85
# Set sphere color to bright yellow
self.mat.diffuseColor = coin.SbColor(1, 1, 0)
self.mat.transparency = 0.35 # Keep or adjust if needed

self.sph = coin.SoSphere()
self.scs = coin.SoType.fromName("SoShapeScale").createInstance()
self.scs.setPart("shape", self.sph)
self.scs.scaleFactor.setValue(10)
# Increase the scaleFactor to make the sphere larger
self.scs.scaleFactor.setValue(10) # Adjust this value as needed

self.sep.addChild(self.sca)
self.sep.addChild(self.mat)
self.sep.addChild(self.scs)
self.switch.addChild(self.sep)

self.switch.addChild(self.sep)
vobj.RootNode.addChild(self.switch)
self.showOriginAxis(False)
self.showOriginAxis(True)

for base in self.obj.Model.Group:
Path.Log.debug(f"{base.Name}: {base.ViewObject.Visibility}")


def onChanged(self, vobj, prop):
if prop == "Visibility":
self.showOriginAxis(vobj.Visibility)
if vobj.Visibility:
self.rememberStockVisibility()
self.obj.Stock.ViewObject.Visibility = True

self.KeepBaseVisibility()
for base in self.obj.Model.Group:
base.ViewObject.Visibility = True
else:
self.restoreStockVisibility()
self.RestoreBaseVisibility()

def rememberStockVisibility(self):
self.stockVisibility = self.obj.Stock.ViewObject.Visibility

def restoreStockVisibility(self):
self.obj.Stock.ViewObject.Visibility = self.stockVisibility

def KeepBaseVisibility(self):
Path.Log.debug("KeepBaseVisibility")
self.visibilitystate = {}
for base in self.obj.Model.Group:
Path.Log.debug(f"{base.Name}: {base.ViewObject.Visibility}")
self.visibilitystate[base.Name] = base.ViewObject.Visibility
Path.Log.debug(self.visibilitystate)

def RestoreBaseVisibility(self):
Path.Log.debug("RestoreBaseVisibility")
for base in self.obj.Model.Group:
base.ViewObject.Visibility = self.visibilitystate[base.Name]
Path.Log.debug(self.visibilitystate)


def showOriginAxis(self, yes):
sw = coin.SO_SWITCH_ALL if yes else coin.SO_SWITCH_NONE
Expand Down Expand Up @@ -252,11 +314,11 @@ def rememberBaseVisibility(self, obj, base):

def forgetBaseVisibility(self, obj, base):
Path.Log.track()
if self.baseVisibility.get(base.Name):
visibility = self.baseVisibility[base.Name]
visibility[0].ViewObject.Visibility = visibility[1]
visibility[2].ViewObject.Visibility = visibility[3]
del self.baseVisibility[base.Name]
# if self.baseVisibility.get(base.Name):
# visibility = self.baseVisibility[base.Name]
# visibility[0].ViewObject.Visibility = visibility[1]
# visibility[2].ViewObject.Visibility = visibility[3]
# del self.baseVisibility[base.Name]

def setupEditVisibility(self, obj):
Path.Log.track()
Expand Down

0 comments on commit 8ca50d0

Please sign in to comment.