-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel_options.py
More file actions
213 lines (177 loc) · 6.05 KB
/
panel_options.py
File metadata and controls
213 lines (177 loc) · 6.05 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import adsk.core
import adsk.fusion
from ..generalUtils.persist_utils import Persistable
from .. import fusionAddInUtils as futil # noqa: F401
app = adsk.core.Application.get()
# All numeric values are in cm, which is the default for the Fusion API
SLOT_DIMENSIONS = {
"slotDiameter": 0.35,
"slotLength": 0.14,
"slotOffsetY": 0.3,
"slotOffsetX": 0.6,
}
EURORACK_DEFAULTS = {
"hpWidth": 0.508,
"widthUnitMinimum": 2,
"panelHoleMinimum": 6,
"widthUnitName": "HP",
}
FORMAT_DATA = {
"3u_eurorack": {
"name": "3U Eurorack",
**SLOT_DIMENSIONS,
**EURORACK_DEFAULTS,
"panelLength": 12.85,
"maxPcbLength": 11.0,
},
"1u_intellijel": {
"name": "1U (Intellijel)",
**SLOT_DIMENSIONS,
**EURORACK_DEFAULTS,
"panelLength": 3.965,
"maxPcbLength": 2.25,
},
"1u_pulplogic": {
"name": "1U Tile (Pulp Logic)",
**SLOT_DIMENSIONS,
**EURORACK_DEFAULTS,
"panelLength": 4.318,
"maxPcbLength": 2.87,
"slotOffsetX": 0.433,
},
"ae": {
"name": "AE Modular",
**SLOT_DIMENSIONS,
"hpWidth": 2.5,
"widthUnitMinimum": 1,
"widthUnitName": "Unit",
"widthUnitNamePlural": "Units",
"panelHoleMinimum": 2,
"panelLength": 10.1,
"maxPcbLength": 8,
"slotOffsetX": 1.18,
},
}
ANCHOR_POINTS = {
f"{prefix.lower()}-{suffix.lower()}": "Center" if prefix == "Middle" and suffix == "Center" else f"{prefix} {suffix}"
for prefix in ["Top", "Middle", "Bottom"]
for suffix in ["Left", "Center", "Right"]
}
SUPPORT_TYPES = {
"none": "No reinforcements",
"solid": "Solid (good for larger blanks)",
"shell": "Shell (leaves space for components)",
}
class PanelOptions(Persistable):
def __init__(self, persistFile: str):
Persistable.__init__(
self,
persistFile,
{
"formatId": "3u_eurorack",
"widthInHp": 6,
"sketchOnly": False,
"panelHeight": 0.2,
"anchorPoint": "top-left",
"supportType": "none",
"supportSolidHeight": 0.2,
"supportShellHeight": 0.9,
"supportShellWallThickness": 0.1,
},
)
self.formatId: str
self.widthInHp: int
self.sketchOnly: bool
self.panelHeight: float
self.anchorPoint: str
self.supportType: str
self.supportSolidHeight: float
self.supportShellHeight: float
self.supportShellWallThickness: float
def restoreDefaults(self):
super().restoreDefaults()
self.ensureDefaultKeyIsValid("formatId", FORMAT_DATA)
self.ensureDefaultKeyIsValid("anchorPoint", ANCHOR_POINTS)
self.ensureDefaultKeyIsValid("supportType", SUPPORT_TYPES)
# anchorPoint getters and setters by name for the Fusion UI
@property
def anchorPointNames(self):
return ANCHOR_POINTS.values()
@property
def anchorPointName(self):
return ANCHOR_POINTS[self.anchorPoint]
def getIdForAnchorPointName(self, name: str):
return next(key for key, value in ANCHOR_POINTS.items() if value == name)
@anchorPointName.setter
def anchorPointName(self, name: str):
self.anchorPoint = self.getIdForAnchorPointName(name)
# supportType getters and setters by name for the Fusion UI
@property
def supportTypeNames(self):
return SUPPORT_TYPES.values()
@property
def supportTypeName(self):
return SUPPORT_TYPES[self.supportType]
def getIdForSupportTypeName(self, name: str):
return next(key for key, value in SUPPORT_TYPES.items() if value == name)
@supportTypeName.setter
def supportTypeName(self, name: str):
self.supportType = self.getIdForSupportTypeName(name)
# All format names and details
@property
def formatDetails(self):
return {formatId: {**obj} for formatId, obj in FORMAT_DATA.items()}
@property
def formatNames(self):
return [obj["name"] for obj in FORMAT_DATA.values()]
# formatId getters and setters by name for the Fusion UI
@property
def formatName(self):
return FORMAT_DATA[self.formatId]["name"]
def getIdForFormatName(self, name: str):
return next(formatId for formatId, obj in FORMAT_DATA.items() if obj["name"] == name)
@formatName.setter
def formatName(self, name: str):
self.formatId = self.getIdForFormatName(name)
# Format data getters
def __formatValue(self, key: str, defaultValue=False):
return FORMAT_DATA[self.formatId].get(key, defaultValue)
@property
def width(self):
return self.__formatValue("hpWidth") * self.widthInHp
@property
def widthUnitMinimum(self):
return self.__formatValue("widthUnitMinimum")
@property
def widthUnitName(self):
return self.__formatValue("widthUnitName")
@property
def widthUnitNamePlural(self):
return self.__formatValue("widthUnitNamePlural", defaultValue=self.widthUnitName)
@property
def widthAsExpression(self):
# Ensure value is specified as HP * hpWidth in the user's default units for easy adjustments later
design = adsk.fusion.Design.cast(app.activeProduct)
unitsMgr = design.fusionUnitsManager
return "{} * {}".format(self.widthInHp, unitsMgr.formatValue(self.__formatValue("hpWidth")))
@property
def panelLength(self):
return self.__formatValue("panelLength")
@property
def panelHoleMinimum(self):
return self.__formatValue("panelHoleMinimum")
@property
def maxPcbLength(self):
return self.__formatValue("maxPcbLength")
@property
def slotDiameter(self):
return self.__formatValue("slotDiameter")
@property
def slotLength(self):
return self.__formatValue("slotLength")
@property
def slotOffsetY(self):
return self.__formatValue("slotOffsetY")
@property
def slotOffsetX(self):
return self.__formatValue("slotOffsetX")