Extracted preferences for holding tags into their own file.
This commit is contained in:
@@ -29,6 +29,7 @@ SET(PathScripts_SRCS
|
||||
PathScripts/PathDressupDragknife.py
|
||||
PathScripts/PathDressupHoldingTags.py
|
||||
PathScripts/PathDressupRampEntry.py
|
||||
PathScripts/PathDressupTagPreferences.py
|
||||
PathScripts/PathDrilling.py
|
||||
PathScripts/PathEngrave.py
|
||||
PathScripts/PathFacePocket.py
|
||||
|
||||
@@ -27,13 +27,13 @@ import Draft
|
||||
import DraftGeomUtils
|
||||
import Path
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
|
||||
import Part
|
||||
import copy
|
||||
import math
|
||||
|
||||
from PathScripts import PathUtils
|
||||
from PathScripts.PathGeom import PathGeom
|
||||
from PathScripts.PathDressupTagPreferences import HoldingTagPreferences
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
from PathScripts.PathUtils import waiting_effects
|
||||
from PySide import QtCore
|
||||
@@ -95,69 +95,6 @@ def debugCone(vector, r1, r2, height, label, color = None):
|
||||
obj.ViewObject.ShapeColor = color
|
||||
|
||||
|
||||
class HoldingTagsPreferences:
|
||||
DefaultHoldingTagWidth = 'DefaultHoldingTagWidth'
|
||||
DefaultHoldingTagHeight = 'DefaultHoldingTagHeight'
|
||||
DefaultHoldingTagAngle = 'DefaultHoldingTagAngle'
|
||||
DefaultHoldingTagRadius = 'DefaultHoldingTagRadius'
|
||||
DefaultHoldingTagCount = 'DefaultHoldingTagCount'
|
||||
|
||||
@classmethod
|
||||
def defaultWidth(cls, ifNotSet):
|
||||
value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagWidth, ifNotSet)
|
||||
if value == 0.0:
|
||||
return ifNotSet
|
||||
return value
|
||||
|
||||
@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)
|
||||
|
||||
@classmethod
|
||||
def defaultRadius(cls, ifNotSet = 0.0):
|
||||
return PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagRadius, ifNotSet)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/preferences/PathDressupHoldingTags.ui")
|
||||
self.label = translate("PathDressup_HoldingTags", 'Holding Tags')
|
||||
|
||||
def loadSettings(self):
|
||||
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.ifRadius.setText(FreeCAD.Units.Quantity(self.defaultRadius(), FreeCAD.Units.Length).UserString)
|
||||
self.form.sbCount.setValue(self.defaultCount())
|
||||
|
||||
def saveSettings(self):
|
||||
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.SetFloat(self.DefaultHoldingTagRadius, FreeCAD.Units.Quantity(self.form.ifRadius.text()))
|
||||
pref.SetUnsigned(self.DefaultHoldingTagCount, self.form.sbCount.value())
|
||||
|
||||
@classmethod
|
||||
def preferencesPage(cls):
|
||||
return HoldingTagsPreferences()
|
||||
|
||||
class Tag:
|
||||
def __init__(self, id, x, y, width, height, angle, radius, enabled=True):
|
||||
PathLog.track("%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d" % (x, y, width, height, angle, radius, enabled))
|
||||
@@ -685,20 +622,20 @@ class PathData:
|
||||
pathHeight = (self.obj.Base.StartDepth - self.obj.Base.FinalDepth).Value
|
||||
else:
|
||||
pathHeight = self.maxZ - self.minZ
|
||||
height = HoldingTagsPreferences.defaultHeight(pathHeight / 2)
|
||||
height = HoldingTagPreferences.defaultHeight(pathHeight / 2)
|
||||
if height > pathHeight:
|
||||
return pathHeight
|
||||
return height
|
||||
|
||||
def defaultTagWidth(self):
|
||||
width = self.shortestAndLongestPathEdge()[1].Length / 10
|
||||
return HoldingTagsPreferences.defaultWidth(width)
|
||||
return HoldingTagPreferences.defaultWidth(width)
|
||||
|
||||
def defaultTagAngle(self):
|
||||
return HoldingTagsPreferences.defaultAngle()
|
||||
return HoldingTagPreferences.defaultAngle()
|
||||
|
||||
def defaultTagRadius(self):
|
||||
return HoldingTagsPreferences.defaultRadius()
|
||||
return HoldingTagPreferences.defaultRadius()
|
||||
|
||||
def sortedTags(self, tags):
|
||||
ordered = []
|
||||
@@ -988,7 +925,7 @@ class ObjectDressup:
|
||||
obj.Width = self.pathData.defaultTagWidth()
|
||||
obj.Angle = self.pathData.defaultTagAngle()
|
||||
obj.Radius = self.pathData.defaultTagRadius()
|
||||
count = HoldingTagsPreferences.defaultCount()
|
||||
count = HoldingTagPreferences.defaultCount()
|
||||
self.generateTags(obj, count)
|
||||
return self.pathData
|
||||
|
||||
@@ -1011,12 +948,6 @@ 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
|
||||
|
||||
99
src/Mod/Path/PathScripts/PathDressupTagPreferences.py
Normal file
99
src/Mod/Path/PathScripts/PathDressupTagPreferences.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2017 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 PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
|
||||
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
from PySide import QtCore
|
||||
|
||||
# Qt tanslation handling
|
||||
def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
class HoldingTagPreferences:
|
||||
DefaultHoldingTagWidth = 'DefaultHoldingTagWidth'
|
||||
DefaultHoldingTagHeight = 'DefaultHoldingTagHeight'
|
||||
DefaultHoldingTagAngle = 'DefaultHoldingTagAngle'
|
||||
DefaultHoldingTagRadius = 'DefaultHoldingTagRadius'
|
||||
DefaultHoldingTagCount = 'DefaultHoldingTagCount'
|
||||
|
||||
@classmethod
|
||||
def defaultWidth(cls, ifNotSet):
|
||||
value = PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagWidth, ifNotSet)
|
||||
if value == 0.0:
|
||||
return ifNotSet
|
||||
return value
|
||||
|
||||
@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)
|
||||
|
||||
@classmethod
|
||||
def defaultRadius(cls, ifNotSet = 0.0):
|
||||
return PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagRadius, ifNotSet)
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/preferences/PathDressupHoldingTags.ui")
|
||||
self.label = translate("PathDressup_HoldingTag", 'Holding Tag')
|
||||
|
||||
def loadSettings(self):
|
||||
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.ifRadius.setText(FreeCAD.Units.Quantity(self.defaultRadius(), FreeCAD.Units.Length).UserString)
|
||||
self.form.sbCount.setValue(self.defaultCount())
|
||||
|
||||
def saveSettings(self):
|
||||
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.SetFloat(self.DefaultHoldingTagRadius, FreeCAD.Units.Quantity(self.form.ifRadius.text()))
|
||||
pref.SetUnsigned(self.DefaultHoldingTagCount, self.form.sbCount.value())
|
||||
|
||||
@classmethod
|
||||
def preferencesPage(cls):
|
||||
return HoldingTagPreferences()
|
||||
|
||||
PathPreferencesPathDressup.RegisterDressup(HoldingTagPreferences)
|
||||
Reference in New Issue
Block a user