-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
BimTrash.py
107 lines (94 loc) · 4.69 KB
/
BimTrash.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
# -*- coding: utf8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2017 Yorik van Havre <[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 *
# * *
# ***************************************************************************
"""This module contains FreeCAD commands for the BIM workbench"""
import os
import FreeCAD
from BimTranslateUtils import *
class BIM_Trash:
def GetResources(self):
return {
"Pixmap": os.path.join(os.path.dirname(__file__), "icons", "BIM_Trash.svg"),
"MenuText": QT_TRANSLATE_NOOP("BIM_Trash", "Move to Trash"),
"ToolTip": QT_TRANSLATE_NOOP(
"BIM_Trash", "Moves the selected objects to the Trash folder"
),
"Accel": "Shift+Del",
}
def Activated(self):
import FreeCADGui
if FreeCADGui.Selection.getSelection():
trash = FreeCAD.ActiveDocument.getObject("Trash")
if not trash or not trash.isDerivedFrom("App::DocumentObjectGroup"):
trash = FreeCAD.ActiveDocument.addObject(
"App::DocumentObjectGroup", "Trash"
)
trash.Label = translate("BIM", "Trash")
for obj in FreeCADGui.Selection.getSelection():
trash.addObject(obj)
# check for parents still there
for par in obj.InList:
if (par != trash) and hasattr(par, "Group"):
if obj in par.Group:
if hasattr(par, "removeObject"):
par.removeObject(obj)
else:
g = par.Group
g.remove(obj)
par.Group = g
obj.ViewObject.hide()
def IsActive(self):
import FreeCADGui
if FreeCADGui.Selection.getSelection():
return True
else:
return False
class BIM_EmptyTrash:
def GetResources(self):
return {
"Pixmap": os.path.join(os.path.dirname(__file__), "icons", "BIM_Trash.svg"),
"MenuText": QT_TRANSLATE_NOOP("BIM_EmptyTrash", "Clean Trash"),
"ToolTip": QT_TRANSLATE_NOOP(
"BIM_EmptyTrash",
"Deletes from the trash bin all objects that are not used by any other",
),
}
def Activated(self):
trash = FreeCAD.ActiveDocument.getObject("Trash")
if trash and trash.isDerivedFrom("App::DocumentObjectGroup"):
deletelist = []
for obj in trash.Group:
if (len(obj.InList) == 1) and (obj.InList[0] == trash):
deletelist.append(obj.Name)
deletelist.extend(self.getDeletableChildren(obj))
if deletelist:
FreeCAD.ActiveDocument.openTransaction("Empty Trash")
for name in deletelist:
FreeCAD.ActiveDocument.removeObject(name)
FreeCAD.ActiveDocument.commitTransaction()
def getDeletableChildren(self, obj):
deletelist = []
for child in obj.OutList:
if (len(child.InList) == 1) and (child.InList[0] == obj):
deletelist.append(child.Name)
deletelist.extend(self.getDeletableChildren(child))
return deletelist