-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy patha2p_lcs_support.py
116 lines (97 loc) · 4.75 KB
/
a2p_lcs_support.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
#***************************************************************************
#* *
#* Copyright (c) 2019 kbwbe *
#* *
#* 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
from a2p_translateUtils import *
#==============================================================================
def LCS_Group_deleteContent(_self,doc):
"""
LCS_Group featurepython extending function deleteContent
"""
if len(_self.Group) > 0:
deleteList = []
deleteList.extend(_self.Group)
_self.Group = []
for ob in deleteList:
doc.removeObject(ob.Name) # delete the imported LCS'
#==============================================================================
class LCS_Group(object):
def __init__(self, obInstance):
obInstance.addExtension('App::GeoFeatureGroupExtensionPython', self)
obInstance.addProperty("App::PropertyString", "Owner").Owner = ''
obInstance.setEditorMode('Owner', 1)
obInstance.setEditorMode('Placement', 1) # read-only # KBWBE: does not work...
obInstance.deleteContent = LCS_Group_deleteContent # add a function to this featurepython class
def execute(self, obj):
pass
def onChanged(self, obj, prop):
pass
#==============================================================================
class VP_LCS_Group(object):
def __init__(self,vobj):
vobj.addExtension('Gui::ViewProviderGeoFeatureGroupExtensionPython', self)
vobj.Proxy = self
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
# restore lost functions to featurePython object during reload
if not hasattr(self.Object,'deleteContent'):
self.Object.deleteContent = LCS_Group_deleteContent
def onDelete(self, viewObject, subelements): # subelements is a tuple of strings
if FreeCAD.activeDocument() != viewObject.Object.Document:
return False # only delete objects in the active Document anytime !!
obj = viewObject.Object
doc = obj.Document
try:
if obj.Owner != '':
owner = doc.getObject(obj.Owner)
owner.lcsLink = [] # delete link entry within owning A2p part.
except:
pass
obj.deleteContent(doc) # Clean up this group complete with all content
return True
def getIcon(self):
return ":/icons/a2p_LCS_group.svg"
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def dumps(self):
return None
def loads(self, state):
return None
#==============================================================================
def getListOfLCS(targetDoc,sourceDoc):
lcsOut = []
for sourceOb in sourceDoc.Objects:
if (
sourceOb.Name.startswith("Local_CS") or
sourceOb.Name.startswith("App__Placement") or
sourceOb.Name.startswith("a2pLCS") or
sourceOb.Name.startswith("PartDesign__CoordinateSystem")
):
newLCS = targetDoc.addObject("PartDesign::CoordinateSystem","a2pLCS")
pl = sourceOb.getGlobalPlacement()
newLCS.Placement = pl
newLCS.setEditorMode('Placement', 1) #read-only # KBWBE: does not work...
lcsOut.append(newLCS)
return lcsOut