27
27
import FreeCAD as App
29
29
from replaceobj import replaceobj #from OpenSCAD wb, the code that drives replaceChild
30
from latticeCommon import *
30
from lattice2Common import *
32
32
def substituteobj(oldobj, newobj):
33
33
'Replaces all links to oldobj in the document with links to newobj'
38
38
class CommandSubstituteObject:
39
39
"Command to substitute object"
40
40
def GetResources(self):
41
return {'Pixmap' : getIconPath("Lattice_SubstituteObject.svg"),
42
'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice_SubstituteObject","Substitute object"),
41
return {'Pixmap' : getIconPath("Lattice2_SubstituteObject.svg"),
42
'MenuText': QtCore.QT_TRANSLATE_NOOP("Lattice2_SubstituteObject","Substitute object"),
44
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice_SubstituteObject","Substitute Object: find all links to one of the selected objects, and rediret them all to another object")}
44
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Lattice2_SubstituteObject","Substitute Object: find all links to one of the selected objects, and rediret them all to another object")}
46
46
def Activated(self):
47
47
sel = FreeCADGui.Selection.getSelectionEx()
58
58
if len(sel[0].Object.InList) != 0:
59
59
mb = QtGui.QMessageBox()
60
60
mb.setIcon(mb.Icon.Warning)
61
msg = translate("Lattice_SubstituteObject", "Some of the links coudn't be redirected, because they are not supported by the tool. Objects still linking to the object that was replaced are: \n%1\nTo redirect these links, the objects have to be edited manually. Sorry!", None)
61
msg = translate("Lattice2_SubstituteObject", "Some of the links coudn't be redirected, because they are not supported by the tool. Objects still linking to the object that was replaced are: \n%1\nTo redirect these links, the objects have to be edited manually. Sorry!", None)
62
62
rem_links = [lnk.Label for lnk in sel[0].Object.InList]
63
63
mb.setText(msg.replace(u"%1", u"\n".join(rem_links)))
64
mb.setWindowTitle(translate("Lattice_SubstituteObject","Error", None))
64
mb.setWindowTitle(translate("Lattice2_SubstituteObject","Error", None))
67
67
except Exception as err:
68
68
mb = QtGui.QMessageBox()
69
69
mb.setIcon(mb.Icon.Warning)
70
mb.setText(translate("Lattice_SubstituteObject", "An error occured while substituting object:", None)+ u"\n"
70
mb.setText(translate("Lattice2_SubstituteObject", "An error occured while substituting object:", None)+ u"\n"
71
71
+ unicode(err.message))
72
mb.setWindowTitle(translate("Lattice_SubstituteObject","Error", None))
72
mb.setWindowTitle(translate("Lattice2_SubstituteObject","Error", None))
74
74
App.ActiveDocument.abortTransaction()
86
86
mb = QtGui.QMessageBox()
87
87
mb.setIcon(mb.Icon.Warning)
88
mb.setText(translate("Lattice_SubstituteObject", "Select two objects, first! The first one is the one to be substituted, and the second one is the object to redirect all links to.", None))
89
mb.setWindowTitle(translate("Lattice_SubstituteObject","Bad selection", None))
88
mb.setText(translate("Lattice2_SubstituteObject", "Select two objects, first! The first one is the one to be substituted, and the second one is the object to redirect all links to.", None))
89
mb.setWindowTitle(translate("Lattice2_SubstituteObject","Bad selection", None))
92
92
def IsActive(self):
98
FreeCADGui.addCommand('Lattice_SubstituteObject', CommandSubstituteObject())
98
FreeCADGui.addCommand('Lattice2_SubstituteObject', CommandSubstituteObject())
100
exportedCommands = ['Lattice_SubstituteObject']
100
exportedCommands = ['Lattice2_SubstituteObject']