/
DogboneDressup.py
622 lines (529 loc) · 24.4 KB
/
DogboneDressup.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
# * *
# * 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
from PathScripts import PathUtils
from PySide import QtCore, QtGui
import math
"""Dogbone Dressup object and FreeCAD command"""
# Qt tanslation handling
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig)
movecommands = ['G0', 'G00', 'G1', 'G01', 'G2', 'G02', 'G3', 'G03']
movestraight = ['G1', 'G01']
class Shape:
Dogbone = 'Dogbone'
Tbone_H = 'T-bone horizontal'
Tbone_V = 'T-bone vertical'
Tbone_L = 'T-bone long edge'
Tbone_S = 'T-bone short edge'
All = [Dogbone, Tbone_H, Tbone_V, Tbone_L, Tbone_S]
class Side:
Left = 'Left'
Right = 'Right'
All = [Left, Right]
class Length:
Fixed = 'fixed'
Adaptive = 'adaptive'
Custom = 'custom'
All = [Adaptive, Fixed, Custom]
# Chord
# A class to represent the start and end point of a path command. If the underlying
# Command is a rotate command the receiver does represent a chord in the geometric
# sense of the word. If the underlying command is a straight move then the receiver
# represents the actual move.
# This implementation really only deals with paths in the XY plane. Z is assumed to
# be constant in all calculated results.
# Instances of Chord are generally considered immutable and all movement member
# functions return new instances.
class Chord (object):
def __init__(self, start = None, end = None):
if not start:
start = FreeCAD.Vector()
if not end:
end = FreeCAD.Vector()
self.Start = start
self.End = end
def __str__(self):
return "Chord([%g, %g, %g] -> [%g, %g, %g])" % (self.Start.x, self.Start.y, self.Start.z, self.End.x, self.End.y, self.End.z)
def moveTo(self, newEnd):
#print("Chord(%s -> %s)" % (self.End, newEnd))
return Chord(self.End, newEnd)
def moveToParameters(self, params):
x = params.get('X', self.End.x)
y = params.get('Y', self.End.y)
z = params.get('Z', self.End.z)
return self.moveTo(FreeCAD.Vector(x, y, z))
def moveBy(self, x, y, z):
return self.moveTo(self.End + FreeCAD.Vector(x, y, z))
def asVector(self):
return self.End - self.Start
def getLength(self):
return self.asVector().Length
def getDirectionOfVector(self, B):
A = self.asVector()
# if the 2 vectors are identical, they head in the same direction
if A == B:
return 'Straight'
d = -A.x*B.y + A.y*B.x
if d < 0:
return Side.Left
if d > 0:
return Side.Right
# at this point the only direction left is backwards
return 'Back'
def getDirectionOf(self, chordOrVector):
if type(chordOrVector) is Chord:
return self.getDirectionOfVector(chordOrVector.asVector())
return self.getDirectionOfVector(chordOrVector)
def getAngleOfVector(self, ref):
angle = self.asVector().getAngle(ref)
# unfortunately they never figure out the sign :(
# positive angles go up, so when the reference vector is left
# then the receiver must go down
if self.getDirectionOfVector(ref) == Side.Left:
return -angle
return angle
def getAngle(self, refChordOrVector):
if type(refChordOrVector) is Chord:
return self.getAngleOfVector(refChordOrVector.asVector())
return self.getAngleOfVector(refChordOrVector)
def getAngleXY(self):
return self.getAngle(FreeCAD.Vector(1,0,0))
def offsetBy(self, distance):
angle = self.getAngleXY() - math.pi/2
dx = distance * math.cos(angle)
dy = distance * math.sin(angle)
d = FreeCAD.Vector(dx, dy, 0)
return Chord(self.Start + d, self.End + d)
def g1Command(self):
return Path.Command("G1", {"X": self.End.x, "Y": self.End.y})
def isAPlungeMove(self):
return self.End.z != self.Start.z
def foldsBackOrTurns(self, chord, side):
dir = chord.getDirectionOf(self)
return dir == 'Back' or dir == side
def connectsTo(self, chord):
return self.End == chord.Start
def lineEquation(self):
if self.End.x != self.Start.x:
slope = (self.End.y - self.Start.y) / (self.End.x - self.Start.x)
offset = self.Start.y - self.Start.x * slope
return (offset, slope)
return (None, None)
def intersection(self, chord, emergencyOffset = 0):
itsOffset, itsSlope = chord.lineEquation()
myOffset, mySlope = self.lineEquation()
x = 0
y = 0
if itsSlope is not None and mySlope is not None:
if itsSlope == mySlope:
# Now this is wierd, but it happens when the path folds onto itself
angle = self.getAngleXY()
x = self.End.x + emergencyOffset * math.cos(angle)
y = self.End.y + emergencyOffset * math.sin(angle)
else:
x = (myOffset - itsOffset) / (itsSlope - mySlope)
y = myOffset + mySlope * x
elif itsSlope is not None:
x = self.Start.x
y = itsOffset + x * itsSlope
elif mySlope is not None:
x = chord.Start.x
y = myOffset + x * mySlope
else:
print("Now this really sucks")
return (x, y)
class ObjectDressup:
def __init__(self, obj):
obj.addProperty("App::PropertyLink", "Base","Base", "The base path to modify")
obj.addProperty("App::PropertyEnumeration", "Side", "Dressup", "The side of path to insert bones")
obj.Side = [Side.Left, Side.Right]
obj.Side = Side.Right
obj.addProperty("App::PropertyEnumeration", "Shape", "Dressup", "The shape of boness")
obj.Shape = Shape.All
obj.Shape = Shape.Dogbone
obj.addProperty("App::PropertyIntegerList", "BoneBlacklist", "Dressup", "Bones that aren't dressed up")
obj.BoneBlacklist = []
obj.setEditorMode('BoneBlacklist', 2) # hide this one
obj.addProperty("App::PropertyEnumeration", "Length", "Dressup", "The algorithm to determine the bone length")
obj.Length = Length.All
obj.Length = Length.Fixed
obj.addProperty("App::PropertyFloat", "Custom", "Dressup", "Dressup length if lenght == custom")
obj.Custom = 0.0
obj.Proxy = self
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def theOtherSideOf(self, side):
if side == Side.Left:
return Side.Right
return Side.Left
# Answer true if a dogbone could be on either end of the chord, given its command
def canAttachDogbone(self, cmd, chord):
return cmd.Name in movestraight and not chord.isAPlungeMove()
def shouldInsertDogbone(self, obj, inChord, outChord):
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.Side))
# draw circles where dogbones go, easier to spot during testing
def debugCircleBone(self, obj,inChord, outChord):
di = 0.
dj = 0.5
if inChord.Start.x < outChord.End.x:
dj = -dj
circle = Path.Command("G1", {"I": di, "J": dj}).Parameters
circle.update({"X": inChord.End.x, "Y": inChord.End.y})
return [ Path.Command("G3", circle) ]
def adaptiveBoneLength(self, obj, inChord, outChord, angle):
iChord = inChord.offsetBy(self.toolRadius)
oChord = outChord.offsetBy(self.toolRadius)
x,y = iChord.intersection(oChord, self.toolRadius)
dest = inChord.moveTo(FreeCAD.Vector(x, y, inChord.End.z))
destAngle = dest.getAngleXY()
distance = dest.getLength() - self.toolRadius * math.fabs(math.cos(destAngle - angle))
#print("adapt")
#print(" in = %s -> %s" % (inChord, iChord))
#print(" out = %s -> %s" % (outChord, oChord))
#print(" = (%.2f, %.2f) -> %.2f (%.2f %.2f) -> %.2f" % (x, y, dest.getLength(), destAngle/math.pi, angle/math.pi, distance))
return distance
def inOutBoneCommands(self, obj, inChord, outChord, angle, fixedLength):
length = fixedLength
if obj.Length == Length.Custom:
length = obj.Custom
if obj.Length == Length.Adaptive:
length = self.adaptiveBoneLength(obj, inChord, outChord, angle)
x = length * math.cos(angle);
y = length * math.sin(angle);
boneChordIn = inChord.moveBy(x, y, 0)
boneChordOut = boneChordIn.moveTo(outChord.Start)
return [ boneChordIn.g1Command(), boneChordOut.g1Command() ]
def dogboneAngle(self, obj, inChord, outChord):
baseAngle = inChord.getAngleXY()
turnAngle = outChord.getAngle(inChord)
boneAngle = baseAngle + (turnAngle - math.pi)/2
if obj.Side == Side.Left:
boneAngle = boneAngle + math.pi
while boneAngle < -math.pi:
boneAngle += 2*math.pi
while boneAngle > math.pi:
boneAngle -= 2*math.pi
#print("base=%+3.2f turn=%+3.2f bone=%+3.2f" % (baseAngle/math.pi, turnAngle/math.pi, boneAngle/math.pi))
return boneAngle
def dogbone(self, obj, inChord, outChord):
boneAngle = self.dogboneAngle(obj, inChord, outChord)
length = self.toolRadius * 0.41422 # 0.41422 = 2/sqrt(2) - 1 + (a tiny bit)
return self.inOutBoneCommands(obj, inChord, outChord, boneAngle, length)
def tboneHorizontal(self, obj, inChord, outChord):
angle = self.dogboneAngle(obj, inChord, outChord)
boneAngle = 0
if angle == math.pi or math.fabs(angle) > math.pi/2:
boneAngle = -math.pi
return self.inOutBoneCommands(obj, inChord, outChord, boneAngle, self.toolRadius)
def tboneVertical(self, obj, inChord, outChord):
angle = self.dogboneAngle(obj, inChord, outChord)
boneAngle = math.pi/2
if angle == math.pi or angle < 0:
boneAngle = -boneAngle
return self.inOutBoneCommands(obj, inChord, outChord, boneAngle, self.toolRadius)
def tboneEdgeCommands(self, obj, inChord, outChord, onIn):
boneAngle = outChord.getAngleXY()
if onIn:
boneAngle = inChord.getAngleXY()
boneAngle = boneAngle + math.pi/2
if Side.Right == outChord.getDirectionOf(inChord):
boneAngle = boneAngle - math.pi
return self.inOutBoneCommands(obj, inChord, outChord, boneAngle, self.toolRadius)
def tboneLongEdge(self, obj, inChord, outChord):
inChordIsLonger = inChord.getLength() > outChord.getLength()
return self.tboneEdgeCommands(obj, inChord, outChord, inChordIsLonger)
def tboneShortEdge(self, obj, inChord, outChord):
inChordIsShorter = inChord.getLength() < outChord.getLength()
return self.tboneEdgeCommands(obj, inChord, outChord, inChordIsShorter)
def isBoneBlacklisted(self, obj, boneId, loc):
blacklisted = False
if boneId in obj.BoneBlacklist:
blacklisted = True
elif loc in self.locationBlacklist:
obj.BoneBlacklist.append(boneId)
blacklisted = True
if blacklisted:
self.locationBlacklist.add(loc)
return blacklisted
# Generate commands necessary to execute the dogbone
def boneCommands(self, obj, boneId, inChord, outChord):
loc = (inChord.End.x, inChord.End.y)
enabled = not self.isBoneBlacklisted(obj, boneId, loc)
self.bones.append((boneId, loc, enabled))
if enabled:
if obj.Shape == Shape.Dogbone:
return self.dogbone(obj, inChord, outChord)
if obj.Shape == Shape.Tbone_H:
return self.tboneHorizontal(obj, inChord, outChord)
if obj.Shape == Shape.Tbone_V:
return self.tboneVertical(obj, inChord, outChord)
if obj.Shape == Shape.Tbone_L:
return self.tboneLongEdge(obj, inChord, outChord)
if obj.Shape == Shape.Tbone_S:
return self.tboneShortEdge(obj, inChord, outChord)
return self.debugCircleBone(obj, inChord, outChord)
else:
return []
def execute(self, obj):
if not obj.Base:
return
if not obj.Base.isDerivedFrom("Path::Feature"):
return
if not obj.Base.Path:
return
if not obj.Base.Path.Commands:
return
self.setup(obj)
commands = [] # the dressed commands
lastChord = Chord() # the last chord
lastCommand = None # the command that generated the last chord
oddsAndEnds = [] # track chords that are connected to plunges - in case they form a loop
boneId = 1
self.bones = []
self.locationBlacklist = set()
for thisCmd in obj.Base.Path.Commands:
if thisCmd.Name in movecommands:
thisChord = lastChord.moveToParameters(thisCmd.Parameters)
thisIsACandidate = self.canAttachDogbone(thisCmd, thisChord)
if thisIsACandidate and lastCommand and self.shouldInsertDogbone(obj, lastChord, thisChord):
commands.extend(self.boneCommands(obj, boneId, lastChord, thisChord))
boneId = boneId + 1
if lastCommand and thisChord.isAPlungeMove():
for chord in (chord for chord in oddsAndEnds if lastChord.connectsTo(chord)):
if self.shouldInsertDogbone(obj, lastChord, chord):
commands.extend(self.boneCommands(obj, boneId,lastChord, chord))
boneId = boneId + 1
if lastChord.isAPlungeMove() and thisIsACandidate:
oddsAndEnds.append(thisChord)
if thisIsACandidate:
lastCommand = thisCmd
else:
lastCommand = None
lastChord = thisChord
commands.append(thisCmd)
path = Path.Path(commands)
obj.Path = path
def setup(self, obj):
if not hasattr(self, 'toolRadius'):
print("Here we go ... ")
# By default the side for dogbones is opposite of the base path side
if obj.Base.Side == Side.Left:
obj.Side = Side.Right
elif obj.Base.Side == Side.Right:
obj.Side = Side.Left
else:
# This will cause an error, which is fine for now 'cause I don't know what to do here
obj.Side = 'On'
self.toolRadius = 5
toolLoad = PathUtils.getLastToolLoad(obj)
if toolLoad is None or toolLoad.ToolNumber == 0:
self.toolRadius = 5
else:
tool = PathUtils.getTool(obj, toolLoad.ToolNumber)
if not tool or tool.Diameter == 0:
self.toolRadius = 5
else:
self.toolRadius = tool.Diameter / 2
def boneStateList(self, obj):
state = {}
# If the receiver was loaded from file, then it never generated the bone list.
if not hasattr(self, 'bones'):
self.execute(obj)
for (id, loc, enabled) in self.bones:
item = state.get(loc)
if item:
item[1].append(id)
else:
state[loc] = (enabled, [id])
return state
class ViewProviderDressup:
def __init__(self, vobj):
vobj.Proxy = self
def attach(self, vobj):
self.Object = vobj.Object
return
def claimChildren(self):
for i in self.Object.Base.InList:
if hasattr(i, "Group"):
group = i.Group
for g in group:
if g.Name == self.Object.Base.Name:
group.remove(g)
i.Group = group
print i.Group
#FreeCADGui.ActiveDocument.getObject(obj.Base.Name).Visibility = False
return [self.Object.Base]
def setEdit(self, vobj, mode=0):
FreeCADGui.Control.closeDialog()
panel = TaskPanel(vobj.Object)
FreeCADGui.Control.showDialog(panel)
panel.setupUi()
return True
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def onDelete(self, arg1=None, arg2=None):
'''this makes sure that the base operation is added back to the project and visible'''
FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name).Visibility = True
PathUtils.addToJob(arg1.Object.Base)
return True
class CommandDogboneDressup:
def GetResources(self):
return {'Pixmap': 'Path-Dressup',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "Dogbone Dress-up"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Dogbone_Dressup", "Creates a Dogbone Dress-up object from a selected path")}
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):
# check that the selection contains exactly what we want
selection = FreeCADGui.Selection.getSelection()
if len(selection) != 1:
FreeCAD.Console.PrintError(translate("Dogbone_Dressup", "Please select one path object\n"))
return
if not selection[0].isDerivedFrom("Path::Feature"):
FreeCAD.Console.PrintError(translate("Dogbone_Dressup", "The selected object is not a path\n"))
return
if selection[0].isDerivedFrom("Path::FeatureCompoundPython"):
FreeCAD.Console.PrintError(translate("Dogbone_Dressup", "Please select a Path object"))
return
# everything ok!
FreeCAD.ActiveDocument.openTransaction(translate("Dogbone_Dressup", "Create Dress-up"))
FreeCADGui.addModule("PathScripts.DogboneDressup")
FreeCADGui.addModule("PathScripts.PathUtils")
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "DogboneDressup")')
FreeCADGui.doCommand('dbo = PathScripts.DogboneDressup.ObjectDressup(obj)')
FreeCADGui.doCommand('obj.Base = FreeCAD.ActiveDocument.' + selection[0].Name)
FreeCADGui.doCommand('PathScripts.DogboneDressup.ViewProviderDressup(obj.ViewObject)')
FreeCADGui.doCommand('PathScripts.PathUtils.addToJob(obj)')
FreeCADGui.doCommand('Gui.ActiveDocument.getObject(obj.Base.Name).Visibility = False')
FreeCADGui.doCommand('dbo.setup(obj)')
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
class TaskPanel:
DataIds = QtCore.Qt.ItemDataRole.UserRole
DataKey = QtCore.Qt.ItemDataRole.UserRole + 1
def __init__(self, obj):
self.obj = obj
self.form = FreeCADGui.PySideUic.loadUi(":/panels/DogboneEdit.ui")
self.updating = False
def accept(self):
self.getFields()
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
FreeCADGui.Selection.removeObserver(self.s)
FreeCAD.ActiveDocument.recompute()
def reject(self):
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
FreeCADGui.Selection.removeObserver(self.s)
def getFields(self):
self.obj.Shape = str(self.form.shape.currentText())
self.obj.Side = str(self.form.side.currentText())
self.obj.Length = str(self.form.length.currentText())
self.obj.Custom = self.form.custom.value()
blacklist = []
for i in range(0, self.form.bones.count()):
item = self.form.bones.item(i)
if item.checkState() == QtCore.Qt.CheckState.Unchecked:
blacklist.extend(item.data(self.DataIds))
self.obj.BoneBlacklist = sorted(blacklist)
self.obj.Proxy.execute(self.obj)
def updateModel(self):
self.getFields()
self.form.custom.setEnabled(self.obj.Length == Length.Custom)
FreeCAD.ActiveDocument.recompute()
def setupCombo(self, combo, text, items):
if items and len(items) > 0:
for i in range(combo.count(), -1, -1):
combo.removeItem(i)
combo.addItems(items)
index = combo.findText(text, QtCore.Qt.MatchFixedString)
if index >= 0:
combo.setCurrentIndex(index)
def setFields(self):
self.setupCombo(self.form.shape, self.obj.Shape, Shape.All)
self.setupCombo(self.form.side, self.obj.Side, Side.All)
self.setupCombo(self.form.length, self.obj.Length, Length.All)
self.form.custom.setMinimum(0.0)
self.form.custom.setDecimals(3)
self.form.custom.setValue(self.obj.Custom)
self.form.custom.setEnabled(self.obj.Length == Length.Custom)
self.form.bones.clear()
itemList = []
for loc, state in self.obj.Proxy.boneStateList(self.obj).iteritems():
lbl = '(%.2f, %.2f): %s' % (loc[0], loc[1], ','.join(str(id) for id in state[1]))
item = QtGui.QListWidgetItem(lbl)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsUserCheckable)
if state[0]:
item.setCheckState(QtCore.Qt.CheckState.Checked)
else:
item.setCheckState(QtCore.Qt.CheckState.Unchecked)
item.setData(self.DataIds, state[1])
item.setData(self.DataKey, state[1][0])
itemList.append(item)
for item in sorted(itemList, key=lambda item: item.data(self.DataKey)):
self.form.bones.addItem(item)
def open(self):
self.s = SelObserver()
# install the function mode resident
FreeCADGui.Selection.addObserver(self.s)
def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok)
def setupUi(self):
self.setFields()
# now that the form is filled, setup the signal handlers
self.form.shape.currentIndexChanged.connect(self.updateModel)
self.form.side.currentIndexChanged.connect(self.updateModel)
self.form.length.currentIndexChanged.connect(self.updateModel)
self.form.custom.valueChanged.connect(self.updateModel)
self.form.bones.itemChanged.connect(self.updateModel)
class SelObserver:
def __init__(self):
import PathScripts.PathSelection as PST
PST.eselect()
def __del__(self):
import PathScripts.PathSelection as PST
PST.clear()
def addSelection(self, doc, obj, sub, pnt):
FreeCADGui.doCommand('Gui.Selection.addSelection(FreeCAD.ActiveDocument.' + obj + ')')
FreeCADGui.updateGui()
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Dogbone_Dressup', CommandDogboneDressup())
FreeCAD.Console.PrintLog("Loading DogboneDressup... done\n")