Added preferences for holding tags.

This commit is contained in:
Markus Lampert 2017-01-06 18:39:27 -08:00
parent 70c3fc8686
commit 891add9bd3
7 changed files with 276 additions and 20 deletions

View File

@ -45,6 +45,7 @@ SET(PathScripts_SRCS
PathScripts/PathPost.py PathScripts/PathPost.py
PathScripts/PathPostProcessor.py PathScripts/PathPostProcessor.py
PathScripts/PathPreferences.py PathScripts/PathPreferences.py
PathScripts/PathPreferencesPathDressup.py
PathScripts/PathPreferencesPathJob.py PathScripts/PathPreferencesPathJob.py
PathScripts/PathProfile.py PathScripts/PathProfile.py
PathScripts/PathProfileEdges.py PathScripts/PathProfileEdges.py

View File

@ -66,6 +66,7 @@
<file>panels/ToolControl.ui</file> <file>panels/ToolControl.ui</file>
<file>panels/ToolEdit.ui</file> <file>panels/ToolEdit.ui</file>
<file>panels/ToolLibraryEditor.ui</file> <file>panels/ToolLibraryEditor.ui</file>
<file>preferences/PathDressupHoldingTags.ui</file>
<file>preferences/PathJob.ui</file> <file>preferences/PathJob.ui</file>
<file>translations/Path_af.qm</file> <file>translations/Path_af.qm</file>
<file>translations/Path_cs.qm</file> <file>translations/Path_cs.qm</file>

View File

@ -0,0 +1,133 @@
<?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>477</width>
<height>478</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Tag Parameters</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Default Width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="ifWidth">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Set the default width of holding tags.&lt;/p&gt;&lt;p&gt;If the width is set to 0 the dressup will try to guess a reasonable value based on the path itself.&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>Default Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::InputField" name="ifHeight">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default height of holding tags.&lt;/p&gt;&lt;p&gt;If the specified height is 0 the dressup will use half the height of the part. Should the height be bigger than the height of the part the dressup will reduce the height to the height of the part.&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>Default Angle</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dsbAngle">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Plunge angle for the holding tags ascent and descent.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<double>5.000000000000000</double>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="singleStep">
<double>15.000000000000000</double>
</property>
<property name="value">
<double>45.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Tag Generation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Initial # Tags </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="sbCount">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Specify the number of tags generated when a new dressup is created.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="value">
<number>4</number>
</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>

View File

@ -31,8 +31,9 @@ class PathWorkbench (Workbench):
def Initialize(self): def Initialize(self):
# Add preferences pages - before loading PathGui to properly order pages of Path group # Add preferences pages - before loading PathGui to properly order pages of Path group
from PathScripts import PathPreferencesPathJob from PathScripts import PathPreferencesPathJob, PathPreferencesPathDressup
FreeCADGui.addPreferencePage(PathPreferencesPathJob.Page, "Path") FreeCADGui.addPreferencePage(PathPreferencesPathJob.JobPreferencesPage, "Path")
FreeCADGui.addPreferencePage(PathPreferencesPathDressup.DressupPreferencesPage, "Path")
# load the builtin modules # load the builtin modules
import Path import Path

View File

@ -27,6 +27,7 @@ import Draft
import DraftGeomUtils import DraftGeomUtils
import DraftGui import DraftGui
import Path import Path
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
import Part import Part
import copy import copy
import math import math
@ -103,19 +104,65 @@ def debugCone(vector, r1, r2, height, label, color = None):
if color: if color:
obj.ViewObject.ShapeColor = color obj.ViewObject.ShapeColor = color
class Tag:
class HoldingTagsPreferences:
DefaultHoldingTagWidth = 'DefaultHoldingTagWidth'
DefaultHoldingTagHeight = 'DefaultHoldingTagHeight'
DefaultHoldingTagAngle = 'DefaultHoldingTagAngle'
DefaultHoldingTagCount = 'DefaultHoldingTagCount'
@classmethod @classmethod
def FromString(cls, string): def defaultWidth(cls, ifNotSet):
try: value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagWidth, ifNotSet)
t = eval(string) if value == 0.0:
return Tag(t[0], t[1], t[2], t[3], t[4], t[5]) return ifNotSet
except: return value
return None
def toString(self): @classmethod
return str((self.x, self.y, self.width, self.height, self.angle, self.enabled)) def defaultHeight(cls, ifNotSet):
value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagHeight, ifNotSet)
if value == 0.0:
return ifNotSet
return value
@classmethod
def defaultAngle(cls, ifNotSet = 45.0):
value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagAngle, ifNotSet)
if value < 10.0:
return ifNotSet
return value
@classmethod
def defaultCount(cls, ifNotSet = 4):
value = PathPreferences.preferences().GetUnsigned(cls.DefaultHoldingTagCount, ifNotSet)
if value < 2:
return float(ifNotSet)
return float(value)
def __init__(self):
self.form = FreeCADGui.PySideUic.loadUi(":/preferences/PathDressupHoldingTags.ui")
self.label = 'Holding Tags'
def loadSettings(self):
print("holding tags - load settings")
self.form.ifWidth.setText(FreeCAD.Units.Quantity(self.defaultWidth(0), FreeCAD.Units.Length).UserString)
self.form.ifHeight.setText(FreeCAD.Units.Quantity(self.defaultHeight(0), FreeCAD.Units.Length).UserString)
self.form.dsbAngle.setValue(self.defaultAngle())
self.form.sbCount.setValue(self.defaultCount())
def saveSettings(self):
print("holding tags - save settings")
pref = PathPreferences.preferences()
pref.SetFloat(self.DefaultHoldingTagWidth, FreeCAD.Units.Quantity(self.form.ifWidth.text()).Value)
pref.SetFloat(self.DefaultHoldingTagHeight, FreeCAD.Units.Quantity(self.form.ifHeight.text()).Value)
pref.SetFloat(self.DefaultHoldingTagAngle, self.form.dsbAngle.value())
pref.SetUnsigned(self.DefaultHoldingTagCount, self.form.sbCount.value())
@classmethod
def preferencesPage(cls):
return HoldingTagsPreferences()
class Tag:
def __init__(self, x, y, width, height, angle, enabled=True): def __init__(self, x, y, width, height, angle, enabled=True):
debugPrint("Tag(%.2f, %.2f, %.2f, %.2f, %.2f, %d)" % (x, y, width, height, angle/math.pi, enabled)) debugPrint("Tag(%.2f, %.2f, %.2f, %.2f, %.2f, %d)" % (x, y, width, height, angle/math.pi, enabled))
self.x = x self.x = x
@ -456,7 +503,7 @@ class PathData:
edges = sorted(self.base.Edges, key=lambda e: e.Length) edges = sorted(self.base.Edges, key=lambda e: e.Length)
return (edges[0], edges[-1]) return (edges[0], edges[-1])
def generateTags(self, obj, count=None, width=None, height=None, angle=90, spacing=None): def generateTags(self, obj, count, width=None, height=None, angle=None, spacing=None):
debugPrint("generateTags(%s, %s, %s, %s, %s)" % (count, width, height, angle, spacing)) debugPrint("generateTags(%s, %s, %s, %s, %s)" % (count, width, height, angle, spacing))
#for e in self.base.Edges: #for e in self.base.Edges:
# debugMarker(e.Vertexes[0].Point, 'base', (0.0, 1.0, 1.0), 0.2) # debugMarker(e.Vertexes[0].Point, 'base', (0.0, 1.0, 1.0), 0.2)
@ -544,14 +591,20 @@ class PathData:
def defaultTagHeight(self): def defaultTagHeight(self):
if hasattr(self.obj, 'Base') and hasattr(self.obj.Base, 'StartDepth') and hasattr(self.obj.Base, 'FinalDepth'): if hasattr(self.obj, 'Base') and hasattr(self.obj.Base, 'StartDepth') and hasattr(self.obj.Base, 'FinalDepth'):
return (self.obj.Base.StartDepth - self.obj.Base.FinalDepth).Value / 2 pathHeight = (self.obj.Base.StartDepth - self.obj.Base.FinalDepth).Value
return (self.maxZ - self.minZ) / 2 else:
pathHeight = self.maxZ - self.minZ
height = HoldingTagsPreferences.defaultHeight(pathHeight / 2)
if height > pathHeight:
return pathHeight
return height
def defaultTagWidth(self): def defaultTagWidth(self):
return self.shortestAndLongestPathEdge()[1].Length / 10 width = self.shortestAndLongestPathEdge()[1].Length / 10
return HoldingTagsPreferences.defaultWidth(width)
def defaultTagAngle(self): def defaultTagAngle(self):
return 45 return HoldingTagsPreferences.defaultAngle()
def sortedTags(self, tags): def sortedTags(self, tags):
ordered = [] ordered = []
@ -762,7 +815,7 @@ class ObjectDressup:
obj.Path = self.createPath(self.pathData.edges, self.tags, self.pathData.rapid) obj.Path = self.createPath(self.pathData.edges, self.tags, self.pathData.rapid)
print("execute - done") print("execute - done")
def setup(self, obj, generate=None): def setup(self, obj, generate=False):
print("setup") print("setup")
self.obj = obj self.obj = obj
try: try:
@ -786,7 +839,8 @@ class ObjectDressup:
obj.Height = self.pathData.defaultTagHeight() obj.Height = self.pathData.defaultTagHeight()
obj.Width = self.pathData.defaultTagWidth() obj.Width = self.pathData.defaultTagWidth()
obj.Angle = self.pathData.defaultTagAngle() obj.Angle = self.pathData.defaultTagAngle()
self.generateTags(obj, min(2, generate)) count = HoldingTagsPreferences.defaultCount()
self.generateTags(obj, count)
return self.pathData return self.pathData
def setXyEnabled(self, triples): def setXyEnabled(self, triples):
@ -807,6 +861,12 @@ class ObjectDressup:
self.setup(obj) self.setup(obj)
return self.pathData.pointIsOnPath(point) return self.pathData.pointIsOnPath(point)
@classmethod
def preferencesPage(cls):
return HoldingTagsPreferences()
PathPreferencesPathDressup.RegisterDressup(ObjectDressup)
class TaskPanel: class TaskPanel:
DataX = QtCore.Qt.ItemDataRole.UserRole DataX = QtCore.Qt.ItemDataRole.UserRole
DataY = QtCore.Qt.ItemDataRole.UserRole + 1 DataY = QtCore.Qt.ItemDataRole.UserRole + 1
@ -1292,10 +1352,11 @@ class CommandPathDressupHoldingTags:
FreeCADGui.doCommand('PathScripts.PathDressupHoldingTags.ViewProviderDressup(obj.ViewObject)') FreeCADGui.doCommand('PathScripts.PathDressupHoldingTags.ViewProviderDressup(obj.ViewObject)')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)') FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
FreeCADGui.doCommand('Gui.ActiveDocument.getObject(obj.Base.Name).Visibility = False') FreeCADGui.doCommand('Gui.ActiveDocument.getObject(obj.Base.Name).Visibility = False')
FreeCADGui.doCommand('dbo.setup(obj, 4.)') FreeCADGui.doCommand('dbo.setup(obj, True)')
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
# register the FreeCAD command # register the FreeCAD command
FreeCADGui.addCommand('PathDressup_HoldingTags', CommandPathDressupHoldingTags()) FreeCADGui.addCommand('PathDressup_HoldingTags', CommandPathDressupHoldingTags())

View File

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2016 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
from PySide import QtCore, QtGui
from PathScripts.PathPreferences import PathPreferences
_dressups = []
def RegisterDressup(dressup):
_dressups.append(dressup)
class DressupPreferencesPage:
def __init__(self, parent=None):
print('dressup - __init__')
self.form = QtGui.QToolBox()
self.form.setWindowTitle('Dressups')
pages = []
for dressup in _dressups:
page = dressup.preferencesPage()
if hasattr(page, 'icon') and page.icon:
self.form.addItem(page.form, page.icon, page.label)
else:
self.form.addItem(page.form, page.label)
pages.append(page)
self.pages = pages
def saveSettings(self):
print('dressup - save settings')
for page in self.pages:
page.saveSettings()
def loadSettings(self):
print('dressup - load settings')
for page in self.pages:
page.loadSettings()

View File

@ -29,7 +29,7 @@ from PathScripts.PathPreferences import PathPreferences
from PathScripts.PathPostProcessor import PostProcessor from PathScripts.PathPostProcessor import PostProcessor
class Page: class JobPreferencesPage:
def __init__(self, parent=None): def __init__(self, parent=None):
self.form = FreeCADGui.PySideUic.loadUi(":preferences/PathJob.ui") self.form = FreeCADGui.PySideUic.loadUi(":preferences/PathJob.ui")