Skip to content

Commit

Permalink
Basic editor and shape update.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert committed Nov 29, 2019
1 parent 9a7db28 commit cf8c0fa
Show file tree
Hide file tree
Showing 15 changed files with 746 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/Mod/Path/CMakeLists.txt
Expand Up @@ -101,6 +101,7 @@ SET(PathScripts_SRCS
PathScripts/PathStop.py
PathScripts/PathSurface.py
PathScripts/PathSurfaceGui.py
PathScripts/PathToolBitEdit.py
PathScripts/PathToolController.py
PathScripts/PathToolControllerGui.py
PathScripts/PathToolEdit.py
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Path/Gui/Resources/Path.qrc
Expand Up @@ -107,6 +107,7 @@
<file>panels/PointEdit.ui</file>
<file>panels/SetupGlobal.ui</file>
<file>panels/SetupOp.ui</file>
<file>panels/ToolBitEditor.ui</file>
<file>panels/ToolEditor.ui</file>
<file>panels/ToolLibraryEditor.ui</file>
<file>panels/TaskPathSimulator.ui</file>
Expand Down
170 changes: 170 additions & 0 deletions src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>411</width>
<height>886</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Tool Bit</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="toolName">
<property name="maxLength">
<number>50</number>
</property>
<property name="placeholderText">
<string>Display Name</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="templatePath"/>
</item>
<item>
<widget class="QToolButton" name="templateSet">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="bitParams">
<property name="title">
<string>Bit Parameter</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Point/Tip Angle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="toolCuttingEdgeAngle">
<property name="text">
<string>180°</string>
</property>
<property name="unit" stdset="0">
<string>°</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Cutting Edge Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::InputField" name="toolCuttingEdgeHeight">
<property name="text">
<string>0.00</string>
</property>
<property name="unit" stdset="0">
<string>mm</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="image">
<property name="maximumSize">
<size>
<width>210</width>
<height>297</height>
</size>
</property>
<property name="text">
<string>Image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
37 changes: 5 additions & 32 deletions src/Mod/Path/PathScripts/PathGui.py
Expand Up @@ -25,6 +25,7 @@
import FreeCAD
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import PySide


Expand All @@ -44,34 +45,6 @@ def translate(context, text, disambig=None):
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())

def _getProperty(obj, prop):
o = obj
attr = obj
name = None
for name in prop.split('.'):
o = attr
if not hasattr(o, name):
break
attr = getattr(o, name)

if o == attr:
PathLog.warning(translate('PathGui', "%s has no property %s (%s))") % (obj.Label, prop, name))
return (None, None, None)

#PathLog.debug("found property %s of %s (%s: %s)" % (prop, obj.Label, name, attr))
return(o, attr, name)

def getProperty(obj, prop):
'''getProperty(obj, prop) ... answer obj's property defined by its canonical name.'''
o, attr, name = _getProperty(obj, prop) # pylint: disable=unused-variable
return attr

def setProperty(obj, prop, value):
'''setProperty(obj, prop, value) ... set the property value of obj's property defined by its canonical name.'''
o, attr, name = _getProperty(obj, prop) # pylint: disable=unused-variable
if o and name:
setattr(o, name, value)

def updateInputField(obj, prop, widget, onBeforeChange=None):
'''updateInputField(obj, prop, widget) ... update obj's property prop with the value of widget.
The property's value is only assigned if the new value differs from the current value.
Expand All @@ -82,13 +55,13 @@ def updateInputField(obj, prop, widget, onBeforeChange=None):
Returns True if a new value was assigned, False otherwise (new value is the same as the current).
'''
value = FreeCAD.Units.Quantity(widget.text()).Value
attr = getProperty(obj, prop)
attr = PathUtil.getProperty(obj, prop)
attrValue = attr.Value if hasattr(attr, 'Value') else attr
if not PathGeom.isRoughly(attrValue, value):
PathLog.debug("updateInputField(%s, %s): %.2f -> %.2f" % (obj.Label, prop, attr, value))
if onBeforeChange:
onBeforeChange(obj)
setProperty(obj, prop, value)
PathUtil.setProperty(obj, prop, value)
return True
return False

Expand All @@ -107,7 +80,7 @@ def __init__(self, widget, obj, prop, onBeforeChange=None):
self.widget = widget
self.prop = prop
self.onBeforeChange = onBeforeChange
attr = getProperty(self.obj, self.prop)
attr = PathUtil.getProperty(self.obj, self.prop)
if attr is not None:
if hasattr(attr, 'Value'):
widget.setProperty('unit', attr.getUserPreferred()[2])
Expand All @@ -134,7 +107,7 @@ def updateSpinBox(self, quantity=None):
quantity can be of type Quantity or Float.'''
if self.valid:
if quantity is None:
quantity = getProperty(self.obj, self.prop)
quantity = PathUtil.getProperty(self.obj, self.prop)
value = quantity.Value if hasattr(quantity, 'Value') else quantity
self.widget.setProperty('rawValue', value)

Expand Down
5 changes: 3 additions & 2 deletions src/Mod/Path/PathScripts/PathMillFace.py
Expand Up @@ -80,7 +80,8 @@ def areaOpOnChanged(self, obj, prop):
# default depths calculation not correct for facing
if prop == "Base":
job = PathUtils.findParentJob(obj)
obj.OpStartDepth = job.Stock.Shape.BoundBox.ZMax
if job:
obj.OpStartDepth = job.Stock.Shape.BoundBox.ZMax

if len(obj.Base) >= 1:
print('processing')
Expand All @@ -95,7 +96,7 @@ def areaOpOnChanged(self, obj, prop):
# Otherwise, top of part.

obj.OpFinalDepth = Part.makeCompound(sublist).BoundBox.ZMax
else:
elif job:
obj.OpFinalDepth = job.Proxy.modelBoundBox(job).ZMax

def areaOpShapes(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Path/PathScripts/PathSetupSheetGui.py
Expand Up @@ -306,9 +306,9 @@ def accept(self):
def getFields(self):
def updateExpression(name, widget):
value = str(widget.text())
val = PathGui.getProperty(self.obj, name)
val = PathUtil.getProperty(self.obj, name)
if val != value:
PathGui.setProperty(self.obj, name, value)
PathUtil.setProperty(self.obj, name, value)

updateExpression('StartDepthExpression', self.form.setupStartDepthExpr)
updateExpression('FinalDepthExpression', self.form.setupFinalDepthExpr)
Expand Down
41 changes: 23 additions & 18 deletions src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py
Expand Up @@ -106,6 +106,10 @@ def displayString(self):
return Property.displayString(self)
return self.value.getUserPreferred()[0]

class PropertyAngle(PropertyQuantity):
def typeString(self):
return "Angle"

class PropertyDistance(PropertyQuantity):
def typeString(self):
return "Distance"
Expand Down Expand Up @@ -137,24 +141,25 @@ def typeString(self):
class OpPrototype(object):

PropertyType = {
'App::PropertyBool': PropertyBool,
'App::PropertyDistance': PropertyDistance,
'App::PropertyEnumeration': PropertyEnumeration,
'App::PropertyFloat': PropertyFloat,
'App::PropertyFloatConstraint': Property,
'App::PropertyFloatList': Property,
'App::PropertyInteger': PropertyInteger,
'App::PropertyIntegerList': PropertyInteger,
'App::PropertyLength': PropertyLength,
'App::PropertyLink': Property,
'App::PropertyLinkList': Property,
'App::PropertyLinkSubListGlobal': Property,
'App::PropertyPercent': PropertyPercent,
'App::PropertyString': PropertyString,
'App::PropertyStringList': Property,
'App::PropertyVectorDistance': Property,
'App::PropertyVectorList': Property,
'Part::PropertyPartShape': Property,
'App::PropertyAngle': PropertyAngle,
'App::PropertyBool': PropertyBool,
'App::PropertyDistance': PropertyDistance,
'App::PropertyEnumeration': PropertyEnumeration,
'App::PropertyFloat': PropertyFloat,
'App::PropertyFloatConstraint': Property,
'App::PropertyFloatList': Property,
'App::PropertyInteger': PropertyInteger,
'App::PropertyIntegerList': PropertyInteger,
'App::PropertyLength': PropertyLength,
'App::PropertyLink': Property,
'App::PropertyLinkList': Property,
'App::PropertyLinkSubListGlobal': Property,
'App::PropertyPercent': PropertyPercent,
'App::PropertyString': PropertyString,
'App::PropertyStringList': Property,
'App::PropertyVectorDistance': Property,
'App::PropertyVectorList': Property,
'Part::PropertyPartShape': Property,
}

def __init__(self, name):
Expand Down
34 changes: 25 additions & 9 deletions src/Mod/Path/PathScripts/PathSetupSheetOpPrototypeGui.py
Expand Up @@ -112,6 +112,21 @@ def setEditorData(self, widget):
def setModelData(self, widget):
self.prop.setValue(widget.text())

class _PropertyAngleEditor(_PropertyEditor):
'''Editor for angle values - uses a line edit'''

def widget(self, parent):
return QtGui.QLineEdit(parent)

def setEditorData(self, widget):
quantity = self.prop.getValue()
if quantity is None:
quantity = FreeCAD.Units.Quantity(0, FreeCAD.Units.Angle)
widget.setText(quantity.getUserPreferred()[0])

def setModelData(self, widget):
self.prop.setValue(FreeCAD.Units.Quantity(widget.text()))

class _PropertyLengthEditor(_PropertyEditor):
'''Editor for length values - uses a line edit.'''

Expand Down Expand Up @@ -174,15 +189,16 @@ def setModelData(self, widget):
self.prop.setValue(widget.value())

_EditorFactory = {
PathSetupSheetOpPrototype.Property: None,
PathSetupSheetOpPrototype.PropertyBool: _PropertyBoolEditor,
PathSetupSheetOpPrototype.PropertyDistance: _PropertyLengthEditor,
PathSetupSheetOpPrototype.PropertyEnumeration: _PropertyEnumEditor,
PathSetupSheetOpPrototype.PropertyFloat: _PropertyFloatEditor,
PathSetupSheetOpPrototype.PropertyInteger: _PropertyIntegerEditor,
PathSetupSheetOpPrototype.PropertyLength: _PropertyLengthEditor,
PathSetupSheetOpPrototype.PropertyPercent: _PropertyPercentEditor,
PathSetupSheetOpPrototype.PropertyString: _PropertyStringEditor,
PathSetupSheetOpPrototype.Property: None,
PathSetupSheetOpPrototype.PropertyAngle: _PropertyAngleEditor,
PathSetupSheetOpPrototype.PropertyBool: _PropertyBoolEditor,
PathSetupSheetOpPrototype.PropertyDistance: _PropertyLengthEditor,
PathSetupSheetOpPrototype.PropertyEnumeration: _PropertyEnumEditor,
PathSetupSheetOpPrototype.PropertyFloat: _PropertyFloatEditor,
PathSetupSheetOpPrototype.PropertyInteger: _PropertyIntegerEditor,
PathSetupSheetOpPrototype.PropertyLength: _PropertyLengthEditor,
PathSetupSheetOpPrototype.PropertyPercent: _PropertyPercentEditor,
PathSetupSheetOpPrototype.PropertyString: _PropertyStringEditor,
}

def Editor(prop):
Expand Down

0 comments on commit cf8c0fa

Please sign in to comment.