Path: Make operations use tool from adapted TCs
This commit is contained in:
committed by
Yorik van Havre
parent
c633e59805
commit
aaee72cba8
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>352</width>
|
||||
<height>455</height>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@@ -31,7 +31,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>334</width>
|
||||
<height>347</height>
|
||||
<height>292</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
@@ -98,7 +98,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>334</width>
|
||||
<height>347</height>
|
||||
<height>292</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
@@ -148,7 +148,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>334</width>
|
||||
<height>347</height>
|
||||
<height>292</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
@@ -162,7 +162,7 @@
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QWidget" name="widget_3" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
@@ -189,7 +189,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
@@ -216,7 +216,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QWidget" name="widget_4" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<item row="0" column="0">
|
||||
@@ -256,6 +256,28 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>ToolController</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="uiToolController"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -23,12 +23,17 @@
|
||||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import Path
|
||||
from FreeCAD import Vector
|
||||
import TechDraw
|
||||
import Path
|
||||
import PathScripts.PathLog as PathLog
|
||||
from PathScripts import PathUtils
|
||||
from PathScripts.PathUtils import depth_params
|
||||
from PySide import QtCore
|
||||
import TechDraw
|
||||
|
||||
LOG_MODULE = 'PathContour'
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
|
||||
PathLog.trackModule('PathContour')
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
@@ -60,11 +65,13 @@ class ObjectContour:
|
||||
obj.addProperty("App::PropertyString", "Comment", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "An optional comment for this Contour"))
|
||||
obj.addProperty("App::PropertyString", "UserLabel", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "User Assigned Label"))
|
||||
|
||||
obj.addProperty("App::PropertyIntegerConstraint", "ToolNumber", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool number in use"))
|
||||
obj.ToolNumber = (0, 0, 1000, 1)
|
||||
obj.setEditorMode('ToolNumber', 1) # make this read only
|
||||
obj.addProperty("App::PropertyString", "ToolDescription", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The description of the tool "))
|
||||
obj.setEditorMode('ToolDescription', 1) # make this read only
|
||||
obj.addProperty("App::PropertyLink", "ToolController", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool controller that will be used to calculate the path"))
|
||||
|
||||
# obj.addProperty("App::PropertyIntegerConstraint", "ToolNumber", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool number in use"))
|
||||
# obj.ToolNumber = (0, 0, 1000, 1)
|
||||
# obj.setEditorMode('ToolNumber', 1) # make this read only
|
||||
# obj.addProperty("App::PropertyString", "ToolDescription", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The description of the tool "))
|
||||
# obj.setEditorMode('ToolDescription', 1) # make this read only
|
||||
|
||||
# Depth Properties
|
||||
obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth", QtCore.QT_TRANSLATE_NOOP("App::Property", "The height needed to clear clamps and obstructions"))
|
||||
@@ -104,17 +111,18 @@ class ObjectContour:
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
def setLabel(self, obj):
|
||||
if not obj.UserLabel:
|
||||
obj.Label = obj.Name + " :" + obj.ToolDescription
|
||||
else:
|
||||
obj.Label = obj.UserLabel + " :" + obj.ToolDescription
|
||||
# def setLabel(self, obj):
|
||||
# if not obj.UserLabel:
|
||||
# obj.Label = obj.Name + " :" + obj.ToolDescription
|
||||
# else:
|
||||
# obj.Label = obj.UserLabel + " :" + obj.ToolDescription
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
if prop == "UserLabel":
|
||||
self.setLabel(obj)
|
||||
|
||||
def setDepths(proxy, obj):
|
||||
PathLog.track()
|
||||
parentJob = PathUtils.findParentJob(obj)
|
||||
if parentJob is None:
|
||||
return
|
||||
@@ -136,6 +144,7 @@ class ObjectContour:
|
||||
|
||||
def _buildPathLibarea(self, obj, edgelist):
|
||||
import PathScripts.PathKurveUtils as PathKurveUtils
|
||||
PathLog.track()
|
||||
# import math
|
||||
# import area
|
||||
output = ""
|
||||
@@ -188,33 +197,37 @@ class ObjectContour:
|
||||
return output
|
||||
|
||||
def execute(self, obj):
|
||||
PathLog.track()
|
||||
import Part # math #DraftGeomUtils
|
||||
output = ""
|
||||
|
||||
toolLoad = PathUtils.getLastToolLoad(obj)
|
||||
toolLoad = obj.ToolController
|
||||
|
||||
if toolLoad is None or toolLoad.ToolNumber == 0:
|
||||
self.vertFeed = 100
|
||||
self.horizFeed = 100
|
||||
self.vertRapid = 100
|
||||
self.horizRapid = 100
|
||||
self.radius = 0.25
|
||||
obj.ToolNumber = 0
|
||||
obj.ToolDescription = "UNDEFINED"
|
||||
FreeCAD.Console.PrintError("No Tool Controller is selected. We need a tool to build a Path.")
|
||||
return
|
||||
|
||||
# self.vertFeed = 100
|
||||
# self.horizFeed = 100
|
||||
# self.vertRapid = 100
|
||||
# self.horizRapid = 100
|
||||
# self.radius = 0.25
|
||||
# obj.ToolNumber = 0
|
||||
# obj.ToolDescription = "UNDEFINED"
|
||||
else:
|
||||
self.vertFeed = toolLoad.VertFeed.Value
|
||||
self.horizFeed = toolLoad.HorizFeed.Value
|
||||
self.vertRapid = toolLoad.VertRapid.Value
|
||||
self.horizRapid = toolLoad.HorizRapid.Value
|
||||
tool = PathUtils.getTool(obj, toolLoad.ToolNumber)
|
||||
tool = toolLoad.Proxy.getTool(toolLoad) #PathUtils.getTool(obj, toolLoad.ToolNumber)
|
||||
if not tool or tool.Diameter == 0:
|
||||
self.radius = 0.25
|
||||
else:
|
||||
self.radius = tool.Diameter/2
|
||||
obj.ToolNumber = toolLoad.ToolNumber
|
||||
obj.ToolDescription = toolLoad.Name
|
||||
# obj.ToolNumber = toolLoad.ToolNumber
|
||||
# obj.ToolDescription = toolLoad.Name
|
||||
|
||||
self.setLabel(obj)
|
||||
#self.setLabel(obj)
|
||||
|
||||
output += "(" + obj.Label + ")"
|
||||
if not obj.UseComp:
|
||||
@@ -377,6 +390,7 @@ class TaskPanel:
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def getFields(self):
|
||||
PathLog.track()
|
||||
if self.obj:
|
||||
if hasattr(self.obj, "StartDepth"):
|
||||
self.obj.StartDepth = FreeCAD.Units.Quantity(self.form.startDepth.text()).Value
|
||||
@@ -400,9 +414,13 @@ class TaskPanel:
|
||||
self.obj.UseEndPoint = self.form.useEndPoint.isChecked()
|
||||
if hasattr(self.obj, "Direction"):
|
||||
self.obj.Direction = str(self.form.direction.currentText())
|
||||
if hasattr(self.obj, "ToolController"):
|
||||
tc = PathUtils.findToolController(self.obj, self.form.uiToolController.currentText())
|
||||
self.obj.ToolController = tc
|
||||
self.obj.Proxy.execute(self.obj)
|
||||
|
||||
def setFields(self):
|
||||
PathLog.track()
|
||||
self.form.startDepth.setText(FreeCAD.Units.Quantity(self.obj.StartDepth.Value, FreeCAD.Units.Length).UserString)
|
||||
self.form.finalDepth.setText(FreeCAD.Units.Quantity(self.obj.FinalDepth.Value, FreeCAD.Units.Length).UserString)
|
||||
self.form.safeHeight.setText(FreeCAD.Units.Quantity(self.obj.SafeHeight.Value, FreeCAD.Units.Length).UserString)
|
||||
@@ -419,6 +437,15 @@ class TaskPanel:
|
||||
if index >= 0:
|
||||
self.form.direction.setCurrentIndex(index)
|
||||
|
||||
controllers = PathUtils.getToolControllers(self.obj)
|
||||
labels = [c.Label for c in controllers]
|
||||
self.form.uiToolController.addItems(labels)
|
||||
if self.obj.ToolController is not None:
|
||||
index = self.form.direction.findText(
|
||||
self.obj.ToolController.Label, QtCore.Qt.MatchFixedString)
|
||||
if index >= 0:
|
||||
self.form.uiToolController.setCurrentIndex(index)
|
||||
|
||||
def open(self):
|
||||
self.s = SelObserver()
|
||||
# install the function mode resident
|
||||
@@ -428,7 +455,7 @@ class TaskPanel:
|
||||
return int(QtGui.QDialogButtonBox.Ok)
|
||||
|
||||
def setupUi(self):
|
||||
|
||||
PathLog.track()
|
||||
# Connect Signals and Slots
|
||||
# Depths
|
||||
self.form.startDepth.editingFinished.connect(self.getFields)
|
||||
@@ -441,6 +468,7 @@ class TaskPanel:
|
||||
|
||||
# operation
|
||||
self.form.direction.currentIndexChanged.connect(self.getFields)
|
||||
self.form.uiToolController.currentIndexChanged.connect(self.getFields)
|
||||
self.form.useCompensation.clicked.connect(self.getFields)
|
||||
self.form.useStartPoint.clicked.connect(self.getFields)
|
||||
self.form.useEndPoint.clicked.connect(self.getFields)
|
||||
|
||||
@@ -548,21 +548,33 @@ def getLastToolLoad(obj):
|
||||
continue
|
||||
return tc
|
||||
|
||||
# def getToolControllers(obj):
|
||||
# controllers = []
|
||||
# try:
|
||||
# parent = obj.InList[0]
|
||||
# except:
|
||||
# parent = None
|
||||
def getToolControllers(obj):
|
||||
controllers = []
|
||||
try:
|
||||
parent = obj.InList[0]
|
||||
except:
|
||||
parent = None
|
||||
|
||||
# if parent is not None and hasattr(parent, 'Group'):
|
||||
# sibs = parent.Group
|
||||
# for g in sibs:
|
||||
# if isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool):
|
||||
# controllers.append(g.Name)
|
||||
# return controllers
|
||||
if parent is not None and hasattr(parent, 'Group'):
|
||||
sibs = parent.Group
|
||||
for g in sibs:
|
||||
if isinstance(g.Proxy, PathScripts.PathLoadTool.LoadTool):
|
||||
controllers.append(g)
|
||||
return controllers
|
||||
|
||||
def findToolController(obj, name=""):
|
||||
'''returns a tool controller with a given name.
|
||||
If no name is specified, returns the first controller.
|
||||
if no controller is found, returns None'''
|
||||
|
||||
controllers = getToolControllers(obj)
|
||||
for c in controllers:
|
||||
if c.Label == name:
|
||||
return c
|
||||
if len(controllers) > 0:
|
||||
return controllers[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def findParentJob(obj):
|
||||
'''retrieves a parent job object for an operation or other Path object'''
|
||||
|
||||
Reference in New Issue
Block a user