forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaceLinkCmd.py
125 lines (111 loc) · 5.34 KB
/
placeLinkCmd.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
#!/usr/bin/env python3
# coding: utf-8
#
# placeLinkCmd.py
#
# LGPL
# Copyright HUBERT Zoltán
import os, time
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
from FreeCAD import Console as FCC
import Asm4_libs as Asm4
from placeLinkUI import placeLinkUI
from placePartUI import placePartUI
import selectionFilter
"""
+-----------------------------------------------+
| The command |
+-----------------------------------------------+
"""
class placeLinkCmd():
def __init__(self):
super(placeLinkCmd,self).__init__()
def GetResources(self):
return {"MenuText": "Edit Placement of a Part",
"ToolTip": "Move/Attach a Part in the assembly",
"Pixmap" : os.path.join( Asm4.iconPath , 'Place_Link.svg')
}
def IsActive(self):
# We only insert a link into an Asm4 Model
if App.ActiveDocument:
( obj, tree ) = Asm4.getSelectionTree()
if tree and len(tree)>=2:
# the root container is the first element and must be an App::Part
root = App.ActiveDocument.getObject(tree[0])
if root and root.TypeId=='App::Part':
# check that the object has a Placement property
if hasattr(obj,'Placement') and obj.getTypeIdOfProperty('Placement')=='App::PropertyPlacement':
return True
return False
def Activated(self):
# try with a regular App::Link
selection = Asm4.getSelectedLink()
# may-be an Asm4::VariantLink ?
if selection is None:
selection = Asm4.getSelectedVarLink()
# if we found a valid link
if selection is not None:
# check that it's in the root assembly
parent = selection.getParentGeoFeatureGroup()
if parent and parent == Asm4.getAssembly():
# if it's a valid assembly and part
if Asm4.isAsm4EE(selection):
# BUGFIX: if the part was corrupted by Assembly4 v0.11.5:
if hasattr(selection,'MapMode'):
Asm4.warningBox("This Part has the Attachment extension, it can only be placed manually")
else:
# launch the UI in the task panel
ui = placeLinkUI()
Gui.Control.showDialog(ui)
# else try to convert it
else:
convert = Asm4.confirmBox("This Part wasn't assembled with this Assembly4 WorkBench, but I can convert it.")
if convert:
Asm4.makeAsmProperties( selection, reset=True )
# launch the UI in the task panel
ui = placeLinkUI()
Gui.Control.showDialog(ui)
else:
Asm4.warningBox('Please select a link in the assembly Model.')
else:
# or any part that has a Placement ?
if len(Gui.Selection.getSelection())==1:
selection = Gui.Selection.getSelection()[0]
# object has a Placement property
if hasattr(selection,'Placement') and selection.getTypeIdOfProperty('Placement')=='App::PropertyPlacement':
# we don't want to mess with obects that are attached with the Attacher (MapMode)
if hasattr(selection,'MapMode') and not Asm4.isAsm4EE(selection):
# FCC.PrintMessage('Object has MapMode property, you should use that\n')
Gui.runCommand('Part_EditAttachment')
else:
# check that it's in the root assembly
parent = selection.getParentGeoFeatureGroup()
if parent and parent == Asm4.getAssembly():
# is it's a virgin object, give it Asm4 properties
if not hasattr(selection,'SolverId'):
Asm4.makeAsmProperties(selection)
# if it's a valid assembly and part
if Asm4.isAsm4EE(selection):
# launch the UI in the task panel
ui = placePartUI()
Gui.Control.showDialog(ui)
# else try to convert it
else:
convert = Asm4.confirmBox("This Part wasn't assembled with this Assembly4 WorkBench, but I can convert it.")
if convert:
Asm4.makeAsmProperties( selection, reset=True )
# launch the UI in the task panel
ui = placePartUI()
Gui.Control.showDialog(ui)
# the selected object doesn't belong to the root assembly
else:
Asm4.warningBox('Please select an object in the assembly Model.')
return
"""
+-----------------------------------------------+
| add the command to the workbench |
+-----------------------------------------------+
"""
Gui.addCommand( 'Asm4_placeLink', placeLinkCmd() )