139 lines
5.8 KiB
Python
139 lines
5.8 KiB
Python
# -*- 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 Path
|
|
import PathScripts.PathAreaOpGui as PathAreaOpGui
|
|
import PathScripts.PathContour as PathContour
|
|
import PathScripts.PathLog as PathLog
|
|
import PathScripts.PathSelection as PathSelection
|
|
|
|
from PathScripts import PathUtils
|
|
from PySide import QtCore, QtGui
|
|
|
|
def translate(context, text, disambig=None):
|
|
return QtCore.QCoreApplication.translate(context, text, disambig)
|
|
|
|
class TaskPanelOpPage(PathAreaOpGui.TaskPanelPage):
|
|
|
|
def opSelectionFactory(self):
|
|
return PathSelection.contourselect
|
|
|
|
def getForm(self):
|
|
return FreeCADGui.PySideUic.loadUi(":/panels/PageOpContourEdit.ui")
|
|
|
|
def getFields(self, obj):
|
|
PathLog.track()
|
|
self.obj.OffsetExtra = FreeCAD.Units.Quantity(self.form.extraOffset.text()).Value
|
|
self.obj.UseComp = self.form.useCompensation.isChecked()
|
|
self.obj.Direction = str(self.form.direction.currentText())
|
|
tc = PathUtils.findToolController(self.obj, self.form.toolController.currentText())
|
|
self.obj.ToolController = tc
|
|
|
|
def setFields(self, obj):
|
|
PathLog.track()
|
|
self.form.extraOffset.setText(FreeCAD.Units.Quantity(self.obj.OffsetExtra.Value, FreeCAD.Units.Length).UserString)
|
|
self.form.useCompensation.setChecked(self.obj.UseComp)
|
|
# self.form.useStartPoint.setChecked(self.obj.UseStartPoint)
|
|
|
|
index = self.form.direction.findText(
|
|
self.obj.Direction, QtCore.Qt.MatchFixedString)
|
|
if index >= 0:
|
|
self.form.direction.blockSignals(True)
|
|
self.form.direction.setCurrentIndex(index)
|
|
self.form.direction.blockSignals(False)
|
|
|
|
controllers = PathUtils.getToolControllers(self.obj)
|
|
labels = [c.Label for c in controllers]
|
|
self.form.toolController.blockSignals(True)
|
|
self.form.toolController.addItems(labels)
|
|
self.form.toolController.blockSignals(False)
|
|
|
|
if self.obj.ToolController is None:
|
|
self.obj.ToolController = PathUtils.findToolController(self.obj)
|
|
|
|
if self.obj.ToolController is not None:
|
|
index = self.form.toolController.findText(
|
|
self.obj.ToolController.Label, QtCore.Qt.MatchFixedString)
|
|
if index >= 0:
|
|
self.form.toolController.blockSignals(True)
|
|
self.form.toolController.setCurrentIndex(index)
|
|
self.form.toolController.blockSignals(False)
|
|
else:
|
|
self.obj.ToolController = PathUtils.findToolController(self.obj)
|
|
|
|
def getSignalsForUpdate(self, obj):
|
|
PathLog.track()
|
|
signals = []
|
|
signals.append(self.form.direction.currentIndexChanged)
|
|
signals.append(self.form.toolController.currentIndexChanged)
|
|
signals.append(self.form.useCompensation.clicked)
|
|
signals.append(self.form.useStartPoint.clicked)
|
|
signals.append(self.form.extraOffset.editingFinished)
|
|
return signals
|
|
|
|
class _ViewProviderContour(PathAreaOpGui.ViewProvider):
|
|
|
|
def getTaskPanelOpPage(self, obj):
|
|
return TaskPanelOpPage(obj)
|
|
|
|
def getIcon(self):
|
|
return ":/icons/Path-Contour.svg"
|
|
|
|
def getSelectionFactory(self):
|
|
return PathSelection.contourselect
|
|
|
|
def Create(name):
|
|
FreeCAD.ActiveDocument.openTransaction(translate("Path", "Create a Contour"))
|
|
obj = PathContour.Create(name)
|
|
vobj = _ViewProviderContour(obj.ViewObject)
|
|
|
|
obj.ViewObject.Proxy.deleteOnReject = True
|
|
|
|
FreeCAD.ActiveDocument.commitTransaction()
|
|
obj.ViewObject.startEditing()
|
|
|
|
class CommandPathContour:
|
|
def GetResources(self):
|
|
return {'Pixmap': 'Path-Contour',
|
|
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathContour", "Contour"),
|
|
'Accel': "P, C",
|
|
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathContour", "Creates a Contour Path for the Base Object ")}
|
|
|
|
def IsActive(self):
|
|
if FreeCAD.ActiveDocument is not None:
|
|
for o in FreeCAD.ActiveDocument.Objects:
|
|
if o.Name[:3] == "Job":
|
|
return True
|
|
return False
|
|
|
|
def Activated(self):
|
|
return Create("Contour")
|
|
|
|
# register the FreeCAD command
|
|
FreeCADGui.addCommand('Path_Contour', CommandPathContour())
|
|
|
|
FreeCAD.Console.PrintLog("Loading PathContourGui... done\n")
|