Added preferences for holding tags.
This commit is contained in:
parent
70c3fc8686
commit
891add9bd3
|
@ -45,6 +45,7 @@ SET(PathScripts_SRCS
|
|||
PathScripts/PathPost.py
|
||||
PathScripts/PathPostProcessor.py
|
||||
PathScripts/PathPreferences.py
|
||||
PathScripts/PathPreferencesPathDressup.py
|
||||
PathScripts/PathPreferencesPathJob.py
|
||||
PathScripts/PathProfile.py
|
||||
PathScripts/PathProfileEdges.py
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
<file>panels/ToolControl.ui</file>
|
||||
<file>panels/ToolEdit.ui</file>
|
||||
<file>panels/ToolLibraryEditor.ui</file>
|
||||
<file>preferences/PathDressupHoldingTags.ui</file>
|
||||
<file>preferences/PathJob.ui</file>
|
||||
<file>translations/Path_af.qm</file>
|
||||
<file>translations/Path_cs.qm</file>
|
||||
|
|
133
src/Mod/Path/Gui/Resources/preferences/PathDressupHoldingTags.ui
Normal file
133
src/Mod/Path/Gui/Resources/preferences/PathDressupHoldingTags.ui
Normal 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><html><head/><body><p>Set the default width of holding tags.</p><p>If the width is set to 0 the dressup will try to guess a reasonable value based on the path itself.</p></body></html></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><html><head/><body><p>Default height of holding tags.</p><p>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.</p></body></html></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><html><head/><body><p>Plunge angle for the holding tags ascent and descent.</p></body></html></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><html><head/><body><p>Specify the number of tags generated when a new dressup is created.</p></body></html></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>
|
|
@ -31,8 +31,9 @@ class PathWorkbench (Workbench):
|
|||
|
||||
def Initialize(self):
|
||||
# Add preferences pages - before loading PathGui to properly order pages of Path group
|
||||
from PathScripts import PathPreferencesPathJob
|
||||
FreeCADGui.addPreferencePage(PathPreferencesPathJob.Page, "Path")
|
||||
from PathScripts import PathPreferencesPathJob, PathPreferencesPathDressup
|
||||
FreeCADGui.addPreferencePage(PathPreferencesPathJob.JobPreferencesPage, "Path")
|
||||
FreeCADGui.addPreferencePage(PathPreferencesPathDressup.DressupPreferencesPage, "Path")
|
||||
|
||||
# load the builtin modules
|
||||
import Path
|
||||
|
|
|
@ -27,6 +27,7 @@ import Draft
|
|||
import DraftGeomUtils
|
||||
import DraftGui
|
||||
import Path
|
||||
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
|
||||
import Part
|
||||
import copy
|
||||
import math
|
||||
|
@ -103,19 +104,65 @@ def debugCone(vector, r1, r2, height, label, color = None):
|
|||
if color:
|
||||
obj.ViewObject.ShapeColor = color
|
||||
|
||||
class Tag:
|
||||
|
||||
class HoldingTagsPreferences:
|
||||
DefaultHoldingTagWidth = 'DefaultHoldingTagWidth'
|
||||
DefaultHoldingTagHeight = 'DefaultHoldingTagHeight'
|
||||
DefaultHoldingTagAngle = 'DefaultHoldingTagAngle'
|
||||
DefaultHoldingTagCount = 'DefaultHoldingTagCount'
|
||||
|
||||
@classmethod
|
||||
def FromString(cls, string):
|
||||
try:
|
||||
t = eval(string)
|
||||
return Tag(t[0], t[1], t[2], t[3], t[4], t[5])
|
||||
except:
|
||||
return None
|
||||
def defaultWidth(cls, ifNotSet):
|
||||
value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagWidth, ifNotSet)
|
||||
if value == 0.0:
|
||||
return ifNotSet
|
||||
return value
|
||||
|
||||
def toString(self):
|
||||
return str((self.x, self.y, self.width, self.height, self.angle, self.enabled))
|
||||
@classmethod
|
||||
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):
|
||||
debugPrint("Tag(%.2f, %.2f, %.2f, %.2f, %.2f, %d)" % (x, y, width, height, angle/math.pi, enabled))
|
||||
self.x = x
|
||||
|
@ -456,7 +503,7 @@ class PathData:
|
|||
edges = sorted(self.base.Edges, key=lambda e: e.Length)
|
||||
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))
|
||||
#for e in self.base.Edges:
|
||||
# debugMarker(e.Vertexes[0].Point, 'base', (0.0, 1.0, 1.0), 0.2)
|
||||
|
@ -544,14 +591,20 @@ class PathData:
|
|||
|
||||
def defaultTagHeight(self):
|
||||
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
|
||||
return (self.maxZ - self.minZ) / 2
|
||||
pathHeight = (self.obj.Base.StartDepth - self.obj.Base.FinalDepth).Value
|
||||
else:
|
||||
pathHeight = self.maxZ - self.minZ
|
||||
height = HoldingTagsPreferences.defaultHeight(pathHeight / 2)
|
||||
if height > pathHeight:
|
||||
return pathHeight
|
||||
return height
|
||||
|
||||
def defaultTagWidth(self):
|
||||
return self.shortestAndLongestPathEdge()[1].Length / 10
|
||||
width = self.shortestAndLongestPathEdge()[1].Length / 10
|
||||
return HoldingTagsPreferences.defaultWidth(width)
|
||||
|
||||
def defaultTagAngle(self):
|
||||
return 45
|
||||
return HoldingTagsPreferences.defaultAngle()
|
||||
|
||||
def sortedTags(self, tags):
|
||||
ordered = []
|
||||
|
@ -762,7 +815,7 @@ class ObjectDressup:
|
|||
obj.Path = self.createPath(self.pathData.edges, self.tags, self.pathData.rapid)
|
||||
print("execute - done")
|
||||
|
||||
def setup(self, obj, generate=None):
|
||||
def setup(self, obj, generate=False):
|
||||
print("setup")
|
||||
self.obj = obj
|
||||
try:
|
||||
|
@ -786,7 +839,8 @@ class ObjectDressup:
|
|||
obj.Height = self.pathData.defaultTagHeight()
|
||||
obj.Width = self.pathData.defaultTagWidth()
|
||||
obj.Angle = self.pathData.defaultTagAngle()
|
||||
self.generateTags(obj, min(2, generate))
|
||||
count = HoldingTagsPreferences.defaultCount()
|
||||
self.generateTags(obj, count)
|
||||
return self.pathData
|
||||
|
||||
def setXyEnabled(self, triples):
|
||||
|
@ -807,6 +861,12 @@ class ObjectDressup:
|
|||
self.setup(obj)
|
||||
return self.pathData.pointIsOnPath(point)
|
||||
|
||||
@classmethod
|
||||
def preferencesPage(cls):
|
||||
return HoldingTagsPreferences()
|
||||
|
||||
PathPreferencesPathDressup.RegisterDressup(ObjectDressup)
|
||||
|
||||
class TaskPanel:
|
||||
DataX = QtCore.Qt.ItemDataRole.UserRole
|
||||
DataY = QtCore.Qt.ItemDataRole.UserRole + 1
|
||||
|
@ -1292,10 +1352,11 @@ class CommandPathDressupHoldingTags:
|
|||
FreeCADGui.doCommand('PathScripts.PathDressupHoldingTags.ViewProviderDressup(obj.ViewObject)')
|
||||
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
|
||||
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.recompute()
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
# register the FreeCAD command
|
||||
FreeCADGui.addCommand('PathDressup_HoldingTags', CommandPathDressupHoldingTags())
|
||||
|
|
59
src/Mod/Path/PathScripts/PathPreferencesPathDressup.py
Normal file
59
src/Mod/Path/PathScripts/PathPreferencesPathDressup.py
Normal 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()
|
||||
|
|
@ -29,7 +29,7 @@ from PathScripts.PathPreferences import PathPreferences
|
|||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
|
||||
|
||||
class Page:
|
||||
class JobPreferencesPage:
|
||||
def __init__(self, parent=None):
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":preferences/PathJob.ui")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user