~freecad-community/freecad-extras/lattice2

« back to all changes in this revision

Viewing changes to lattice2SubstituteObject.py

  • Committer: DeepSOIC
  • Date: 2015-11-26 20:53:58 UTC
  • Revision ID: git-v1:ab0e6012c908301cbacc4945b82c40a4bb484bda
V2: renames inside files

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import FreeCAD as App
28
28
 
29
29
from replaceobj import replaceobj #from OpenSCAD wb, the code that drives replaceChild
30
 
from latticeCommon import *
 
30
from lattice2Common import *
31
31
 
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"),
43
43
                'Accel': "",
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")}
45
45
        
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))
65
65
                    mb.exec_()
66
66
                    
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))
73
73
                mb.exec_()
74
74
                App.ActiveDocument.abortTransaction()
75
75
                return
85
85
        else:
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))
90
90
            mb.exec_()
91
91
            
92
92
    def IsActive(self):
95
95
        else:
96
96
            return False
97
97
            
98
 
FreeCADGui.addCommand('Lattice_SubstituteObject', CommandSubstituteObject())
 
98
FreeCADGui.addCommand('Lattice2_SubstituteObject', CommandSubstituteObject())
99
99
 
100
 
exportedCommands = ['Lattice_SubstituteObject']
 
100
exportedCommands = ['Lattice2_SubstituteObject']