-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFuseCompound2.py
145 lines (117 loc) · 5.96 KB
/
FuseCompound2.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
#***************************************************************************
#* *
#* Copyright (c) 2015 - Victor Titov (DeepSOIC) *
#* <[email protected]> *
#* *
#* 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 *
#* *
#***************************************************************************
from lattice2Common import *
__title__="FuseCompound module for FreeCAD"
__author__ = "DeepSOIC"
__url__ = ""
# -------------------------- document object --------------------------------------------------
def makeFuseCompound(name):
'''makeFuseCompound(name): makes a FuseCompound object.'''
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
_FuseCompound(obj)
obj.Refine = getParamRefine()
if FreeCAD.GuiUp:
_ViewProviderFuseCompound(obj.ViewObject)
return obj
class _FuseCompound:
"The FuseCompound object"
def __init__(self,obj):
self.Type = "FuseCompound"
obj.addProperty("App::PropertyLink","Base","FuseCompound","Compound with self-intersections to be fused")
obj.addProperty("App::PropertyBool","Refine","FuseCompound","True = refine resulting shape. False = output as is.")
obj.addProperty("App::PropertyInteger","recomputeQuota","FuseCompound","recompute limiter. Will decrease by one each time it recomputes. Setting to zero disables recomputes. Setting negative makes recomputes unlimited.")
obj.recomputeQuota = -1
obj.Proxy = self
def execute(self,obj):
rst = None
shps = screen(obj.Base).Shape.childShapes()
if len(shps) > 1:
rst = shps[0].multiFuse(shps[1:])
if obj.Refine:
rst = rst.removeSplitter()
obj.Shape = rst
else:
obj.Shape = shps[0]
return
class _ViewProviderFuseCompound:
"A View Provider for the FuseCompound object"
def __init__(self,vobj):
vobj.Proxy = self
def getIcon(self):
return getIconPath("Lattice2_FuseCompound.svg")
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def dumps(self):
return None
def loads(self,state):
return None
def claimChildren(self):
return [screen(self.Object.Base)]
def onDelete(self, feature, subelements): # subelements is a tuple of strings
try:
screen(self.Object.Base).ViewObject.show()
except Exception as err:
FreeCAD.Console.PrintError("Error in onDelete: " + str(err))
return True
# -------------------------- /document object --------------------------------------------------
# -------------------------- Gui command --------------------------------------------------
def CreateFuseCompound(name):
FreeCAD.ActiveDocument.openTransaction("Create FuseCompound")
FreeCADGui.addModule("FuseCompound2")
FreeCADGui.addModule("lattice2Executer")
FreeCADGui.doCommand("f = FuseCompound2.makeFuseCompound(name = '"+name+"')")
FreeCADGui.doCommand("f.Base = FreeCADGui.Selection.getSelection()[0]")
FreeCADGui.doCommand("lattice2Executer.executeFeature(f)")
FreeCADGui.doCommand("f.Base.ViewObject.hide()")
FreeCADGui.doCommand("f = None")
FreeCAD.ActiveDocument.commitTransaction()
class _CommandFuseCompound:
"Command to create FuseCompound feature"
def GetResources(self):
return {'Pixmap' : getIconPath("Lattice2_FuseCompound.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice2_FuseCompound","Fuse compound"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_FuseCompound","Fuse objects contained in a compound")}
def Activated(self):
if len(FreeCADGui.Selection.getSelection()) == 1 :
CreateFuseCompound(name = "FuseCompound")
else:
mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning)
mb.setText(translate("Lattice2_FuseCompound", "Select a shape that is a compound whose children intersect, first!", None))
mb.setWindowTitle(translate("Lattice2_FuseCompound","Bad selection", None))
mb.exec_()
def IsActive(self):
if FreeCAD.ActiveDocument:
return activeBody() is None
else:
return False
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Lattice2_FuseCompound', _CommandFuseCompound())
exportedCommands = ['Lattice2_FuseCompound']
# -------------------------- /Gui command --------------------------------------------------