forked from shaise/FreeCAD_SheetMetal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SheetMetalUnfoldCmd.py
145 lines (125 loc) · 5.23 KB
/
SheetMetalUnfoldCmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
###############################################################################
#
# SheetMetalUnfoldCmd.py
#
# Copyright 2014, 2018 Ulrich Brammer <ulrich@Pauline>
# Copyright 2023 Ondsel Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###############################################################################
import Part, FreeCAD, FreeCADGui, os
from PySide import QtGui, QtCore
from FreeCAD import Gui
from UnfoldGUI import SMUnfoldTaskPanel
try:
from TechDraw import projectEx
except:
from Drawing import projectEx
from engineering_mode import engineering_mode_enabled
from SheetMetalLogger import SMLogger, UnfoldException, BendException, TreeException
class SMUnfoldUnattendedCommandClass:
"""Unfold object"""
def GetResources(self):
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join(__dir__, "Resources", "icons")
return {
"Pixmap": os.path.join(
iconPath, "SheetMetal_UnfoldUnattended.svg"
), # the name of a svg file available in the resources
"MenuText": FreeCAD.Qt.translate("SheetMetal", "Unattended Unfold"),
"Accel": "U",
"ToolTip": FreeCAD.Qt.translate(
"SheetMetal",
"Flatten folded sheet metal object with default options\n"
"1. Select flat face on sheetmetal shape.\n"
"2. Change parameters from task Panel to create unfold Shape & Flatten drawing.",
),
}
def Activated(self):
SMLogger.message(FreeCAD.Qt.translate("Logger", "Running unattended unfold..."))
try:
taskd = SMUnfoldTaskPanel()
except ValueError as e:
SMLogger.error(e.args[0])
return
pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/SheetMetal")
if pg.GetBool("separateSketches"):
taskd.form.chkSeparate.setCheckState(QtCore.Qt.CheckState.Checked)
else:
taskd.form.chkSeparate.setCheckState(QtCore.Qt.CheckState.Unchecked)
if pg.GetBool("genSketch"):
taskd.form.chkSketch.setCheckState(QtCore.Qt.CheckState.Checked)
else:
taskd.form.chkSketch.setCheckState(QtCore.Qt.CheckState.Unchecked)
taskd.form.bendColor.setProperty("color", pg.GetString("bendColor"))
taskd.form.genColor.setProperty("color", pg.GetString("genColor"))
taskd.form.internalColor.setProperty("color", pg.GetString("intColor"))
# taskd.new_mds_name = taskd.material_sheet_name
taskd.accept()
return
def IsActive(self):
if (
len(Gui.Selection.getSelection()) != 1
or len(Gui.Selection.getSelectionEx()[0].SubElementNames) != 1
):
return False
selFace = Gui.Selection.getSelectionEx()[0].SubObjects[0]
return isinstance(selFace.Surface, Part.Plane)
Gui.addCommand("SheetMetal_UnattendedUnfold", SMUnfoldUnattendedCommandClass())
class SMUnfoldCommandClass:
"""Unfold object"""
def GetResources(self):
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join(__dir__, "Resources", "icons")
# add translations path
LanguagePath = os.path.join(__dir__, "translations")
Gui.addLanguagePath(LanguagePath)
Gui.updateLocale()
return {
"Pixmap": os.path.join(
iconPath, "SheetMetal_Unfold.svg"
), # the name of a svg file available in the resources
"MenuText": FreeCAD.Qt.translate("SheetMetal", "Unfold"),
"Accel": "U",
"ToolTip": FreeCAD.Qt.translate(
"SheetMetal",
"Flatten folded sheet metal object.\n"
"1. Select flat face on sheetmetal shape.\n"
"2. Change parameters from task Panel to create unfold Shape & Flatten drawing.",
),
}
def Activated(self):
dialog = SMUnfoldTaskPanel()
FreeCADGui.Control.showDialog(dialog)
# try:
# taskd = SMUnfoldTaskPanel()
# except ValueError as e:
# SMErrorBox(e.args[0])
# return
# FreeCADGui.Control.showDialog(taskd)
# return
def IsActive(self):
if (
len(Gui.Selection.getSelection()) != 1
or len(Gui.Selection.getSelectionEx()[0].SubElementNames) != 1
):
return False
selFace = Gui.Selection.getSelectionEx()[0].SubObjects[0]
return isinstance(selFace.Surface, Part.Plane)
Gui.addCommand("SheetMetal_Unfold", SMUnfoldCommandClass())