forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfoPartCmd.py
166 lines (122 loc) · 4.42 KB
/
infoPartCmd.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
# coding: utf-8
#
# LGPL
# Copyright HUBERT Zoltán
#
# infoPartCmd.py
import os
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
#from FreeCAD import Console as FCC
import libAsm4 as Asm4
"""
+-----------------------------------------------+
| Helper functions |
+-----------------------------------------------+
"""
# allowed types to edit info
partTypes = [ 'App::Part', 'PartDesign::Body']
def checkPart():
selectedPart = None
# if an App::Part is selected
if len(Gui.Selection.getSelection())==1:
selectedObj = Gui.Selection.getSelection()[0]
if selectedObj.TypeId in partTypes:
selectedPart = selectedObj
return selectedPart
"""
+-----------------------------------------------+
| The command |
+-----------------------------------------------+
"""
class infoPartCmd():
def __init__(self):
super(infoPartCmd,self).__init__()
def GetResources(self):
return {"MenuText": "Edit Part Information",
"ToolTip": "Edit Part Information",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_PartInfo.svg')
}
def IsActive(self):
# We only insert a link into an Asm4 Model
if App.ActiveDocument and checkPart():
return True
return False
def Activated(self):
Gui.Control.showDialog( infoPartUI() )
"""
+-----------------------------------------------+
| The UI and functions in the Task panel |
+-----------------------------------------------+
"""
class infoPartUI():
def __init__(self):
self.base = QtGui.QWidget()
self.form = self.base
iconFile = os.path.join( Asm4.iconPath , 'Asm4_PartInfo.svg')
self.form.setWindowIcon(QtGui.QIcon( iconFile ))
self.form.setWindowTitle('Edit Part Information')
# hey-ho, let's go
self.part = checkPart()
self.makePartInfo()
self.infoTable = []
self.getPartInfo()
# the GUI objects are defined later down
self.drawUI()
def getPartInfo(self):
for prop in self.part.PropertiesList:
if self.part.getGroupOfProperty(prop)=='PartInfo' :
if self.part.getTypeIdOfProperty(prop)=='App::PropertyString' :
value = self.part.getPropertyByName(prop)
self.infoTable.append([prop,value])
def makePartInfo( self, reset=False ):
# add the default part information
for info in Asm4.partInfo:
if not hasattr(self.part,info):
self.part.addProperty( 'App::PropertyString', info, 'PartInfo' )
return
# close
def finish(self):
Gui.Control.closeDialog()
# standard panel UI buttons
def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
# Cancel
def reject(self):
self.finish()
# OK: we insert the selected part
def accept(self):
self.finish()
# Define the iUI, only static elements
def drawUI(self):
# Place the widgets with layouts
self.mainLayout = QtGui.QVBoxLayout(self.form)
self.formLayout = QtGui.QFormLayout()
for prop in self.infoTable:
checkLayout = QtGui.QHBoxLayout()
propValue = QtGui.QLineEdit()
propValue.setText( prop[1] )
checked = QtGui.QCheckBox()
checkLayout.addWidget(propValue)
checkLayout.addWidget(checked)
self.formLayout.addRow(QtGui.QLabel(prop[0]),checkLayout)
self.mainLayout.addLayout(self.formLayout)
self.mainLayout.addWidget(QtGui.QLabel())
# Buttons
self.buttonsLayout = QtGui.QHBoxLayout()
self.AddNew = QtGui.QPushButton('Add New Info')
self.Delete = QtGui.QPushButton('Delete Selected')
self.buttonsLayout.addWidget(self.AddNew)
self.buttonsLayout.addStretch()
self.buttonsLayout.addWidget(self.Delete)
self.mainLayout.addLayout(self.buttonsLayout)
self.form.setLayout(self.mainLayout)
# Actions
"""
+-----------------------------------------------+
| add the command to the workbench |
+-----------------------------------------------+
"""
Gui.addCommand( 'Asm4_infoPart', infoPartCmd() )