forked from hamish2014/FreeCAD_assembly2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitGui.py
82 lines (77 loc) · 3.56 KB
/
InitGui.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
import assembly2 #QtCore.QResource.registerResource happens here
import FreeCAD
class Assembly2Workbench (Workbench):
MenuText = 'Assembly 2'
def Initialize(self):
commandslist = [
'assembly2_importPart',
'assembly2_updateImportedPartsCommand',
'assembly2_movePart',
'assembly2_addCircularEdgeConstraint',
'assembly2_addPlaneConstraint',
'assembly2_addAxialConstraint',
'assembly2_addAngleConstraint',
'assembly2_addSphericalSurfaceConstraint',
#'assembly2_undoConstraint', not ready yet
'assembly2_degreesOfFreedomAnimation',
'assembly2_solveConstraints',
'assembly2_muxAssembly',
'assembly2_muxAssemblyRefresh',
'assembly2_addPartsList',
'assembly2_checkAssembly'
]
self.appendToolbar('Assembly 2', commandslist)
shortcut_commandslist = [
'assembly2_flipLastConstraintsDirection',
'assembly2_lockLastConstraintsRotation',
'assembly2_boltMultipleCircularEdges',
]
self.appendToolbar('Assembly 2 shortcuts', shortcut_commandslist )
self.treecmdList = [
'assembly2_importPart',
'assembly2_updateImportedPartsCommand'
]
FreeCADGui.addIconPath( ':/assembly2/icons' )
FreeCADGui.addPreferencePage( ':/assembly2/ui/assembly2_prefs.ui','Assembly2' )
self.appendMenu('Assembly 2', commandslist)
def Activated(self):
from assembly2.constraints import updateOldStyleConstraintProperties
import os
doc = FreeCAD.activeDocument()
if hasattr(doc, 'Objects'):
updateOldStyleConstraintProperties(doc)
GuiPath = os.path.expanduser ("~")
constraintFile = os.path.join( GuiPath , 'constraintFile.txt')
if os.path.exists(constraintFile):
os.remove(constraintFile)
def ContextMenu(self, recipient):
selection = [s for s in FreeCADGui.Selection.getSelection() if s.Document == FreeCAD.ActiveDocument ]
if len(selection) == 1:
obj = selection[0]
if hasattr(obj,'Content'):
if 'ConstraintInfo' in obj.Content or 'ConstraintNfo' in obj.Content:
redefineCmd = {
'plane':'assembly2_redefinePlaneConstraint',
'angle_between_planes':'assembly2_redefineAngleConstraint',
'axial': 'assembly2_redefineAxialConstraint',
'circularEdge' : 'assembly2_redefineCircularEdgeConstraint',
'sphericalSurface' : 'assembly2_redefineSphericalSurfaceConstraint'
}[ obj.Type ]
self.appendContextMenu( "Assembly2", [
'assembly2_animate_constraint',
redefineCmd,
'assembly2_selectConstraintObjects',
'assembly2_selectConstraintElements'
])
if 'sourceFile' in obj.Content:
self.appendContextMenu(
"Assembly2",
[ 'assembly2_movePart',
'assembly2_duplicatePart',
'assembly2_editImportedPart',
'assembly2_forkImportedPart',
'assembly2_deletePartsConstraints',
'assembly2_randomColorAll']
)
Icon = ':/assembly2/icons/workBenchIcon.svg'
Gui.addWorkbench( Assembly2Workbench() )