Basic editor and shape update.

This commit is contained in:
Markus Lampert
2019-09-04 22:56:28 -07:00
parent 9a7db28819
commit cf8c0fadd1
15 changed files with 744 additions and 69 deletions

View File

@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2019 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 FreeCAD
import FreeCADGui
import Path
import PathScripts.PathGui as PathGui
import PathScripts.PathLog as PathLog
import PathScripts.PathToolBit as PathToolBit
import copy
import math
import re
from PySide import QtGui
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
ParameterTypeConstraint = {
'Angle': 'Angle',
'Distance': 'Length',
'DistanceX': 'Length',
'DistanceY': 'Length',
'Radius': 'Length'
}
ParameterTypeProperty = {
'Length': 'App::PropertyLength',
'Angle': 'App::PropertyAngle'
}
class ToolBitEditor:
'''UI and controller for editing a ToolBit.
The controller embeds the UI to the parentWidget which has to have a layout attached to it.
'''
def __init__(self, tool, parentWidget=None):
self.form = FreeCADGui.PySideUic.loadUi(":/panels/ToolBitEditor.ui")
if parentWidget:
self.form.setParent(parentWidget)
parentWidget.layout().addWidget(self.form)
self.tool = tool
if not tool.BitTemplate:
self.tool.BitTemplate = 'src/Mod/Path/Tools/Template/endmill-straight.fcstd'
self.setupTool(self.tool)
def setupTool(self, tool):
layout = self.form.bitParams.layout()
for i in range(layout.rowCount() - 1, -1, -1):
layout.removeRow(i)
editor = {}
ui = FreeCADGui.UiLoader()
for name in tool.PropertiesList:
if tool.getGroupOfProperty(name) == PathToolBit.PropertyGroupBit:
qsb = ui.createWidget('Gui::QuantitySpinBox')
editor[name] = PathGui.QuantitySpinBox(qsb, tool, name)
label = QtGui.QLabel(re.sub('([A-Z][a-z]+)', r' \1', re.sub('([A-Z]+)', r' \1', name)))
#if parameter.get('Desc'):
# qsb.setToolTip(parameter['Desc'])
layout.addRow(label, qsb)
self.bitEditor = editor
def accept(self):
self.refresh()
def reject(self):
pass
def updateUI(self):
PathLog.track()
self.form.toolName.setText(self.tool.Label)
self.form.templatePath.setText(self.tool.BitTemplate)
for editor in self.bitEditor:
self.bitEditor[editor].updateSpinBox()
def updateTemplate(self):
self.tool.BitTemplate = str(self.form.templatePath.text())
self.setupTool(self.tool)
def updateTool(self):
PathLog.track()
self.tool.Label = str(self.form.toolName.text())
self.tool.BitTemplate = str(self.form.templatePath.text())
for editor in self.bitEditor:
self.bitEditor[editor].updateProperty()
self.tool.Proxy._updateBitShape(self.tool)
def refresh(self):
PathLog.track()
self.form.blockSignals(True)
self.updateTool()
self.updateUI()
self.form.blockSignals(False)
def setupUI(self):
PathLog.track()
self.updateUI()
self.form.toolName.editingFinished.connect(self.refresh)
self.form.templatePath.editingFinished.connect(self.updateTemplate)