| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | """This module contains FreeCAD commands for the Draft workbench""" |
| |
|
| | import os |
| | import FreeCAD |
| | from draftguitools import gui_base |
| | from draftutils import params |
| | from draftutils.todo import todo |
| | from draftutils.translate import QT_TRANSLATE_NOOP, translate |
| |
|
| |
|
| | class Draft_Hatch(gui_base.GuiCommandNeedsSelection): |
| |
|
| | def GetResources(self): |
| |
|
| | return { |
| | "Pixmap": "Draft_Hatch", |
| | "MenuText": QT_TRANSLATE_NOOP("Draft_Hatch", "Hatch"), |
| | "Accel": "H, A", |
| | "ToolTip": QT_TRANSLATE_NOOP( |
| | "Draft_Hatch", "Creates hatches on the faces of a selected object" |
| | ), |
| | } |
| |
|
| | def Activated(self): |
| |
|
| | import FreeCADGui |
| |
|
| | if FreeCADGui.Selection.getSelection(): |
| | task = FreeCADGui.Control.showDialog( |
| | Draft_Hatch_TaskPanel(FreeCADGui.Selection.getSelection()[0]) |
| | ) |
| | task.setDocumentName(FreeCADGui.ActiveDocument.Document.Name) |
| | task.setAutoCloseOnDeletedDocument(True) |
| | else: |
| | FreeCAD.Console.PrintError( |
| | translate("Draft", "Choose a base object before using this command") + "\n" |
| | ) |
| |
|
| |
|
| | class Draft_Hatch_TaskPanel: |
| |
|
| | def __init__(self, baseobj): |
| |
|
| | import FreeCADGui |
| | from PySide import QtCore, QtGui |
| | import Draft_rc |
| |
|
| | self.baseobj = baseobj |
| | self.form = FreeCADGui.PySideUic.loadUi(":/ui/dialogHatch.ui") |
| | self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Hatch.svg")) |
| | self.form.File.fileNameChanged.connect(self.onFileChanged) |
| | self.form.File.setFileName(params.get_param("HatchPatternFile")) |
| | pat = params.get_param("HatchPatternName") |
| | if pat in [self.form.Pattern.itemText(i) for i in range(self.form.Pattern.count())]: |
| | self.form.Pattern.setCurrentText(pat) |
| | self.form.Scale.setValue(params.get_param("HatchPatternScale")) |
| | self.form.Rotation.setValue(params.get_param("HatchPatternRotation")) |
| | self.form.Translate.setChecked(params.get_param("HatchPatternTranslate")) |
| | todo.delay(self.form.setFocus, None) |
| |
|
| | def accept(self): |
| |
|
| | import FreeCADGui |
| |
|
| | params.set_param("HatchPatternFile", self.form.File.property("fileName")) |
| | params.set_param("HatchPatternName", self.form.Pattern.currentText()) |
| | params.set_param("HatchPatternScale", self.form.Scale.value()) |
| | params.set_param("HatchPatternRotation", self.form.Rotation.value()) |
| | params.set_param("HatchPatternTranslate", self.form.Translate.isChecked()) |
| | if hasattr(self.baseobj, "File") and hasattr(self.baseobj, "Pattern"): |
| | |
| | o = 'FreeCAD.ActiveDocument.getObject("' + self.baseobj.Name + '")' |
| | FreeCADGui.doCommand(o + '.File="' + self.form.File.property("fileName") + '"') |
| | FreeCADGui.doCommand(o + '.Pattern="' + self.form.Pattern.currentText() + '"') |
| | FreeCADGui.doCommand(o + ".Scale=" + str(self.form.Scale.value())) |
| | FreeCADGui.doCommand(o + ".Rotation=" + str(self.form.Rotation.value())) |
| | FreeCADGui.doCommand(o + ".Translate=" + str(self.form.Translate.isChecked())) |
| | else: |
| | |
| | FreeCAD.ActiveDocument.openTransaction("Create Hatch") |
| | FreeCADGui.addModule("Draft") |
| | cmd = "Draft.make_hatch(" |
| | cmd += 'baseobject=FreeCAD.ActiveDocument.getObject("' + self.baseobj.Name |
| | cmd += '"),filename="' + self.form.File.property("fileName") |
| | cmd += '",pattern="' + self.form.Pattern.currentText() |
| | cmd += '",scale=' + str(self.form.Scale.value()) |
| | cmd += ",rotation=" + str(self.form.Rotation.value()) |
| | cmd += ",translate=" + str(self.form.Translate.isChecked()) + ")" |
| | FreeCADGui.doCommand(cmd) |
| | FreeCAD.ActiveDocument.commitTransaction() |
| | FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()") |
| | self.reject() |
| |
|
| | def reject(self): |
| |
|
| | import FreeCADGui |
| |
|
| | FreeCADGui.Control.closeDialog() |
| | FreeCADGui.ActiveDocument.resetEdit() |
| | FreeCAD.ActiveDocument.recompute() |
| |
|
| | def onFileChanged(self, filename): |
| |
|
| | if filename[0] == "." and self.baseobj: |
| | |
| | filename = os.path.join(os.path.dirname(self.baseobj.Document.FileName), filename) |
| | filename = os.path.abspath(filename) |
| |
|
| | pat = self.form.Pattern.currentText() |
| | self.form.Pattern.clear() |
| | patterns = self.getPatterns(filename) |
| | self.form.Pattern.addItems(patterns) |
| | if pat in patterns: |
| | self.form.Pattern.setCurrentText(pat) |
| |
|
| | def getPatterns(self, filename): |
| | """returns a list of pattern names found in a PAT file""" |
| | patterns = [] |
| | if os.path.exists(filename): |
| | with open(filename) as patfile: |
| | for line in patfile: |
| | if line.startswith("*"): |
| | patterns.append(line.split(",")[0][1:]) |
| | return patterns |
| |
|
| |
|
| | if FreeCAD.GuiUp: |
| | import FreeCADGui |
| |
|
| | FreeCADGui.addCommand("Draft_Hatch", Draft_Hatch()) |
| |
|