forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowHideLcsCmd.py
More file actions
136 lines (111 loc) · 4.41 KB
/
showHideLcsCmd.py
File metadata and controls
136 lines (111 loc) · 4.41 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
#!/usr/bin/env python3
# coding: utf-8
#
# showHideLcsCmd.py
import math, re, os
import FreeCADGui as Gui
import FreeCAD as App
import libAsm4 as Asm4
# Already processed links cache, no need to process the same part if its linked multiple times
#processedLinks = []
"""
+-----------------------------------------------+
| Show |
+-----------------------------------------------+
"""
class showLcsCmd:
def __init__(self):
super(showLcsCmd,self).__init__()
def GetResources(self):
return {"MenuText": "Show LCS",
"ToolTip": "Show LCS and Datums of selected part and its children",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_showLCS.svg')
}
def IsActive(self):
# treats all container types : Body and Part
if Asm4.getSelectedContainer() or Asm4.checkModel() or Asm4.getSelectedLink():
return True
return False
def Activated(self):
#global processedLinks
# reset processed links cache
processedLinks = []
#model = Asm4.getModelSelected()
container = Asm4.getSelectedContainer()
if not container:
container = Asm4.checkModel()
link = Asm4.getSelectedLink()
if link:
showChildLCSs(link, True, processedLinks)
elif container:
for objName in container.getSubObjects(1):
showChildLCSs(container.getSubObject(objName, 1), True, processedLinks)
"""
+-----------------------------------------------+
| Hide |
+-----------------------------------------------+
"""
class hideLcsCmd:
def __init__(self):
super(hideLcsCmd,self).__init__()
def GetResources(self):
return {"MenuText": "Hide LCS",
"ToolTip": "Hide LCS and Datums of selected part and its children",
"Pixmap" : os.path.join( Asm4.iconPath , 'Asm4_hideLCS.svg')
}
def IsActive(self):
# Will handle LCSs only for the Assembly4 model
if Asm4.getSelectedContainer() or Asm4.checkModel() or Asm4.getSelectedLink():
return True
return False
def Activated(self):
#global processedLinks
# reset processed links cache
processedLinks = []
container = Asm4.getSelectedContainer()
if not container:
container = Asm4.checkModel()
link = Asm4.getSelectedLink()
if link:
showChildLCSs(link, False, processedLinks)
elif container:
for objName in container.getSubObjects(1):
showChildLCSs(container.getSubObject(objName, 1), False, processedLinks)
"""
+-----------------------------------------------+
| Show/Hide the LCSs in |
| the provided object and all its children |
+-----------------------------------------------+
"""
def showChildLCSs(obj, show, processedLinks):
#global processedLinks
# if its a datum apply the visibility
if obj.TypeId in Asm4.datumTypes:
obj.Visibility = show
# if it's a link, look for subObjects
elif obj.TypeId == 'App::Link' and obj.Name not in processedLinks:
processedLinks.append(obj.Name)
for objName in obj.LinkedObject.getSubObjects(1):
linkedObj = obj.LinkedObject.Document.getObject(objName[0:-1])
showChildLCSs(linkedObj, show, processedLinks)
# if it's a container
else:
if obj.TypeId in Asm4.containerTypes:
for subObjName in obj.getSubObjects(1):
subObj = obj.getSubObject(subObjName, 1) # 1 for returning the real object
if subObj != None:
if subObj.TypeId in Asm4.datumTypes:
#subObj.Visibility = show
# Aparently obj.Visibility API is very slow
# Using the ViewObject.show() and ViewObject.hide() API runs at least twice faster
if show:
subObj.ViewObject.show()
else:
subObj.ViewObject.hide()
"""
+-----------------------------------------------+
| add the command to the workbench |
+-----------------------------------------------+
"""
Gui.addCommand( 'Asm4_showLcs', showLcsCmd() )
Gui.addCommand( 'Asm4_hideLcs', hideLcsCmd() )