Skip to content

Commit

Permalink
Path: Auto-load the user-selected job for the simulator
Browse files Browse the repository at this point in the history
Add code to auto-load the user-selected job in the simulator so manual selection is not necessary with multi-job documents.
  • Loading branch information
Russ4262 committed Aug 14, 2021
1 parent be1e394 commit ff3adac
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions src/Mod/Path/PathScripts/PathSimulatorGui.py
Expand Up @@ -27,6 +27,7 @@
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PathScripts.PathJob as PathJob
import PathSimulator
import math
import os
Expand Down Expand Up @@ -75,6 +76,7 @@ def __init__(self):
self.simperiod = 20
self.accuracy = 0.1
self.resetSimulation = False
self.jobs = []

def Connect(self, but, sig):
QtCore.QObject.connect(but, QtCore.SIGNAL("clicked()"), sig)
Expand All @@ -96,13 +98,9 @@ def Activate(self):
self.onSpeedBarChange()
form.sliderAccuracy.valueChanged.connect(self.onAccuracyBarChange)
self.onAccuracyBarChange()
self._populateJobSelection(form)
form.comboJobs.currentIndexChanged.connect(self.onJobChange)
jobList = FreeCAD.ActiveDocument.findObjects("Path::FeaturePython", "Job.*")
form.comboJobs.clear()
self.jobs = []
for j in jobList:
self.jobs.append(j)
form.comboJobs.addItem(j.ViewObject.Icon, j.Label)
self.onJobChange()
FreeCADGui.Control.showDialog(self.taskForm)
self.disableAnim = False
self.isVoxel = True
Expand All @@ -111,6 +109,40 @@ def Activate(self):
self.SimulateMill()
self.initdone = True

def _populateJobSelection(self, form):
# Make Job selection combobox
setJobIdx = 0
jobName = ''
jIdx = 0
# Get list of Job objects in active document
jobList = FreeCAD.ActiveDocument.findObjects("Path::FeaturePython", "Job.*")
jCnt = len(jobList)

# Check if user has selected a specific job for simulation
guiSelection = FreeCADGui.Selection.getSelectionEx()
if guiSelection: # Identify job selected by user
sel = guiSelection[0]
if hasattr(sel.Object, "Proxy") and isinstance(sel.Object.Proxy, PathJob.ObjectJob):
jobName = sel.Object.Name
FreeCADGui.Selection.clearSelection()

# populate the job selection combobox
form.comboJobs.blockSignals(True)
form.comboJobs.clear()
form.comboJobs.blockSignals(False)
for j in jobList:
form.comboJobs.addItem(j.ViewObject.Icon, j.Label)
self.jobs.append(j)
if j.Name == jobName or jCnt == 1:
setJobIdx = jIdx
jIdx += 1

# Pre-select GUI-selected job in the combobox
if jobName or jCnt == 1:
form.comboJobs.setCurrentIndex(setJobIdx)
else:
form.comboJobs.setCurrentIndex(0)

def SetupSimulation(self):
form = self.taskForm.form
self.activeOps = []
Expand Down

0 comments on commit ff3adac

Please sign in to comment.