Basic UI/editor for the SetupSheet.

This commit is contained in:
Markus Lampert
2018-08-15 21:08:20 -07:00
parent baac7569d7
commit 6a48072357
9 changed files with 463 additions and 4 deletions

View File

@@ -89,6 +89,7 @@ SET(PathScripts_SRCS
PathScripts/PathSanity.py
PathScripts/PathSelection.py
PathScripts/PathSetupSheet.py
PathScripts/PathSetupSheetGui.py
PathScripts/PathSimpleCopy.py
PathScripts/PathStock.py
PathScripts/PathStop.py

View File

@@ -90,6 +90,7 @@
<file>panels/PageOpSurfaceEdit.ui</file>
<file>panels/PathEdit.ui</file>
<file>panels/PointEdit.ui</file>
<file>panels/SetupGlobal.ui</file>
<file>panels/ToolEditor.ui</file>
<file>panels/ToolLibraryEditor.ui</file>
<file>panels/TaskPathSimulator.ui</file>

View File

@@ -0,0 +1,246 @@
<?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>642</width>
<height>721</height>
</rect>
</property>
<property name="windowTitle">
<string>Setup Global</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabWidgetPage1" native="true">
<attribute name="title">
<string>Operation</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Depths</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Start Depth</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="startDepthExpr">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expression set as the StartDepth of a newly created operation.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: OpStartDepth&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Final Depth</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="finalDepthExpr">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expression set as the FinalDepth for a newly created operation.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: OpFinalDepth&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Step Down</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="stepDownExpr">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expression set as the StepDown of a newly created operation.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: OpToolDiameter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Heights</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Safe</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Clearance</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="safeHeightExpr">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expression set as SafeHeight for new operations.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: &amp;quot;OpStockZMax+SetupSheet.SafeHeightOffset&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="clearanceHeightExpr">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expression set as ClearanceHeight for new operations.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: &amp;quot;OpStockZMax+SetupSheet.ClearanceHeightOffset&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="Gui::QuantitySpinBox" name="clearanceHeightOffs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;ClearanceHeightOffset - can be used by expressions to set the default ClearanceHeight for new operations.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: &amp;quot;3 mm&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Offset</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Expression</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="Gui::QuantitySpinBox" name="safeHeightOffs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;SafeHeightOffset can be for expressions to set the SafeHeight for new operations.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Default: &amp;quot;5 mm&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</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>
<widget class="QWidget" name="tabWidgetPage2" native="true">
<attribute name="title">
<string>Tool Controller</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Rapid Speeds</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Horizontal</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::QuantitySpinBox" name="rapidHorizontal">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Rapid horizontal speed assigned as HorizRapid to new ToolController.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Vertical</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="rapidVertical">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Rapid vertical speed assigne to VertRapid of new ToolController.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>gui_quantityspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -95,6 +95,7 @@ class PathWorkbench (Workbench):
from PathScripts import PathProfileEdgesGui
from PathScripts import PathProfileFacesGui
from PathScripts import PathSanity
from PathScripts import PathSetupSheetGui
from PathScripts import PathSimpleCopy
from PathScripts import PathStop
from PathScripts import PathSurfaceGui

View File

@@ -22,6 +22,8 @@
# * *
# ***************************************************************************
import PathScripts.PathLog as PathLog
import PathScripts.PathUtil as PathUtil
import importlib
__title__ = "Path Icon ViewProvider"
@@ -29,6 +31,12 @@ __author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "ViewProvider who's main and only task is to assign an icon."
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
class ViewProvider(object):
'''Generic view provider to assign an icon.'''
@@ -72,3 +80,25 @@ class ViewProvider(object):
def unsetEdit(self, arg1, arg2):
self._onEditCallback(False)
_factory = {}
def Attach(vobj, name):
'''Attach(vobj, name) ... attach the appropriate view provider to the view object.
If no view provider was registered for the given name a default IconViewProvider is created.'''
PathLog.track(name)
global _factory
for key,value in PathUtil.keyValueIter(_factory):
if key == name:
return value(vobj, name)
PathLog.track(name, 'PathIconViewProvider')
return ViewProvider(vobj, name)
def RegisterViewProvider(name, provider):
'''RegisterViewProvider(name, provider) ... if an IconViewProvider is created for an object with the given name
an instance of provider is used instead.'''
PathLog.track(name)
global _factory
_factory[name] = provider

View File

@@ -83,7 +83,7 @@ def createResourceClone(obj, orig, name, icon):
clone.addProperty('App::PropertyString', 'PathResource')
clone.PathResource = name
if clone.ViewObject:
PathIconViewProvider.ViewProvider(clone.ViewObject, icon)
PathIconViewProvider.Attach(clone.ViewObject, icon)
clone.ViewObject.Visibility = False
obj.Document.recompute() # necessary to create the clone shape
return clone
@@ -144,7 +144,7 @@ class ObjectJob:
obj.addProperty('App::PropertyLink', 'SetupSheet', 'Base', QtCore.QT_TRANSLATE_NOOP('PathJob', 'SetupSheet holding the settings for this job'))
obj.SetupSheet = PathSetupSheet.Create()
if obj.SetupSheet.ViewObject:
PathIconViewProvider.ViewProvider(obj.SetupSheet.ViewObject, 'SetupSheet')
PathIconViewProvider.Attach(obj.SetupSheet.ViewObject, 'SetupSheet')
self.setupSheet = obj.SetupSheet.Proxy
def onDelete(self, obj, arg2=None):

View File

@@ -38,6 +38,7 @@ import PathScripts.PathUtil as PathUtil
import PathScripts.PathUtils as PathUtils
import math
import sys
import traceback
from PySide import QtCore, QtGui
from pivy import coin
@@ -1032,7 +1033,8 @@ def Create(base, template=None):
obj.Document.recompute()
obj.ViewObject.Proxy.editObject(obj.Stock)
return obj
except:
except Exception as exc:
PathLog.error(sys.exc_info())
#traceback.print_exc(exc)
FreeCAD.ActiveDocument.abortTransaction()

View File

@@ -207,7 +207,7 @@ class SetupSheet:
return _traverseTemplateAttributes(attrs, self.decodeAttributeString)
def Create(name='SetupSheet'):
def Create(name = 'SetupSheet'):
obj = FreeCAD.ActiveDocument.addObject('App::FeaturePython', name)
proxy = SetupSheet(obj)
return obj

View File

@@ -0,0 +1,178 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2018 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import Draft
import DraftVecUtils
import FreeCAD
import FreeCADGui
import PathScripts.PathGui as PathGui
import PathScripts.PathLog as PathLog
import PathScripts.PathIconViewProvider as PathIconViewProvider
from PySide import QtCore, QtGui
# Qt tanslation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
if True:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
class ViewProvider:
def __init__(self, vobj, name):
PathLog.track(name)
vobj.Proxy = self
self.icon = name
mode = 2
#vobj.setEditorMode('BoundingBox', mode)
#vobj.setEditorMode('DisplayMode', mode)
#vobj.setEditorMode('Selectable', mode)
#vobj.setEditorMode('ShapeColor', mode)
#vobj.setEditorMode('Transparency', mode)
def attach(self, vobj):
PathLog.track()
self.vobj = vobj
self.obj = vobj.Object
def getIcon(self):
PathLog.track()
return ":/icons/Path-SetupSheet.svg"
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def getDisplayMode(self, mode):
return 'Default'
def setEdit(self, vobj, mode=0):
PathLog.track()
taskPanel = TaskPanel(vobj)
FreeCADGui.Control.closeDialog()
FreeCADGui.Control.showDialog(taskPanel)
taskPanel.setupUi()
return True
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def claimChildren(self):
return []
def doubleClicked(self, vobj):
self.setEdit(vobj)
class TaskPanel:
DataIds = QtCore.Qt.ItemDataRole.UserRole
DataKey = QtCore.Qt.ItemDataRole.UserRole + 1
def __init__(self, vobj):
self.vobj = vobj
self.obj = vobj.Object
PathLog.track(self.obj.Label)
self.form = FreeCADGui.PySideUic.loadUi(":/panels/SetupGlobal.ui")
FreeCAD.ActiveDocument.openTransaction(translate("Path_SetupSheet", "Edit SetupSheet"))
def reject(self):
FreeCAD.ActiveDocument.abortTransaction()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
def accept(self):
self.getFields()
FreeCAD.ActiveDocument.commitTransaction()
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
#FreeCADGui.Selection.removeObserver(self.s)
#FreeCAD.ActiveDocument.recompute()
def getFields(self):
def updateExpression(name, widget):
value = str(widget.text())
val = PathGui.getProperty(self.obj, name)
if val != value:
PathGui.setProperty(self.obj, name, value)
updateExpression('StartDepthExpression', self.form.startDepthExpr)
updateExpression('FinalDepthExpression', self.form.finalDepthExpr)
updateExpression('StepDownExpression', self.form.stepDownExpr)
updateExpression('ClearanceHeightExpression', self.form.clearanceHeightExpr)
updateExpression('SafeHeightExpression', self.form.safeHeightExpr)
self.clearanceHeightOffs.updateProperty()
self.safeHeightOffs.updateProperty()
self.rapidVertical.updateProperty()
self.rapidHorizontal.updateProperty()
def updateUI(self):
self.form.startDepthExpr.setText( self.obj.StartDepthExpression)
self.form.finalDepthExpr.setText( self.obj.FinalDepthExpression)
self.form.stepDownExpr.setText( self.obj.StepDownExpression)
self.form.clearanceHeightExpr.setText( self.obj.ClearanceHeightExpression)
self.form.safeHeightExpr.setText( self.obj.SafeHeightExpression)
self.clearanceHeightOffs.updateSpinBox()
self.safeHeightOffs.updateSpinBox()
self.rapidVertical.updateSpinBox()
self.rapidHorizontal.updateSpinBox()
def updateModel(self):
self.getFields()
self.updateUI()
FreeCAD.ActiveDocument.recompute()
def setupCombo(self, combo, text, items):
if items and len(items) > 0:
for i in range(combo.count(), -1, -1):
combo.removeItem(i)
combo.addItems(items)
index = combo.findText(text, QtCore.Qt.MatchFixedString)
if index >= 0:
combo.setCurrentIndex(index)
def setFields(self):
self.updateUI()
def setupUi(self):
self.clearanceHeightOffs = PathGui.QuantitySpinBox(self.form.clearanceHeightOffs, self.obj, 'ClearanceHeightOffset')
self.safeHeightOffs = PathGui.QuantitySpinBox(self.form.safeHeightOffs, self.obj, 'SafeHeightOffset')
self.rapidHorizontal = PathGui.QuantitySpinBox(self.form.rapidHorizontal, self.obj, 'HorizRapid')
self.rapidVertical = PathGui.QuantitySpinBox(self.form.rapidVertical, self.obj, 'VertRapid')
self.setFields()
def Create(name = 'SetupSheet'):
'''Create(name = 'SetupSheet') ... creates a new setup sheet'''
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Create Job"))
ssheet = SetupSheet.Create(name)
PathIconViewProvider.Attach(ssheet)
return ssheet
PathIconViewProvider.RegisterViewProvider('SetupSheet', ViewProvider)