forked from yorikvanhavre/FreeCAD-NativeIFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathifc_commands.py
140 lines (113 loc) · 5.2 KB
/
ifc_commands.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
# ***************************************************************************
# * *
# * Copyright (c) 2023 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU General Public License (GPL) *
# * as published by the Free Software Foundation; either version 3 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 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 IFC-related FreeCAD commands"""
import os
import FreeCAD
import FreeCADGui
translate = FreeCAD.Qt.translate
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP
def get_project():
"""Gets the current project"""
import ifc_tools
if FreeCADGui.Selection.getSelection():
return ifc_tools.get_project(FreeCADGui.Selection.getSelection()[0])
else:
return ifc_tools.get_project(FreeCAD.ActiveDocument)
class IFC_Diff:
"""Shows a diff of the changes in the current IFC document"""
def GetResources(self):
tt = QT_TRANSLATE_NOOP(
"IFC_Diff", "Shows the current unsaved changes in the IFC file"
)
return {
"Pixmap": os.path.join(os.path.dirname(__file__), "icons", "IFC.svg"),
"MenuText": QT_TRANSLATE_NOOP("IFC_Diff", "IFC Diff..."),
"ToolTip": tt,
"Accel": "I, D",
}
def Activated(self):
import ifc_diff
proj = get_project()
if proj:
diff = ifc_diff.get_diff(proj)
ifc_diff.show_diff(diff)
class IFC_Expand:
"""Expands the children of the selected objects or document"""
def GetResources(self):
tt = QT_TRANSLATE_NOOP(
"IFC_Expand", "Expands the children of the selected objects or document"
)
return {
"Pixmap": os.path.join(os.path.dirname(__file__), "icons", "IFC.svg"),
"MenuText": QT_TRANSLATE_NOOP("IFC_Expand", "IFC Expand"),
"ToolTip": tt,
"Accel": "I, E",
}
def Activated(self):
ns = []
for obj in FreeCADGui.Selection.getSelection():
if hasattr(obj.ViewObject, "Proxy"):
if hasattr(obj.ViewObject.Proxy, "hasChildren"):
if obj.ViewObject.Proxy.hasChildren(obj):
no = obj.ViewObject.Proxy.expandChildren(obj)
ns.extend(no)
else:
import ifc_generator
import ifc_tools
document = FreeCAD.ActiveDocument
ifc_generator.delete_ghost(document)
ifcfile = ifc_tools.get_ifcfile(document)
if ifcfile:
ns = ifc_tools.create_children(
document, ifcfile, recursive=True, only_structure=True
)
if ns:
document.recompute()
FreeCADGui.Selection.clearSelection()
for o in ns:
FreeCADGui.Selection.addSelection(o)
class IFC_ConvertDocument:
"""Converts the active document to an IFC document"""
def GetResources(self):
tt = QT_TRANSLATE_NOOP(
"IFC_ConvertDocument", "Converts the active document to an IFC document"
)
return {
"Pixmap": os.path.join(os.path.dirname(__file__), "icons", "IFC.svg"),
"MenuText": QT_TRANSLATE_NOOP("IFC_ConvertDocument", "Convert document"),
"ToolTip": tt,
# "Accel": "I, C",
}
def Activated(self):
doc = FreeCAD.ActiveDocument
if hasattr(doc, "Proxy") and hasattr(doc.Proxy, "ifcfile") and doc.Proxy.ifcfile:
FreeCAD.Console.PrintError(translate("BIM","The active document is already an IFC document"))
else:
import ifc_tools
ifc_tools.convert_document(doc)
def get_commands():
"""Returns a list of IFC commands"""
return ["IFC_Diff", "IFC_Expand", "IFC_ConvertDocument"]
# initialize commands
FreeCADGui.addCommand("IFC_Diff", IFC_Diff())
FreeCADGui.addCommand("IFC_Expand", IFC_Expand())
FreeCADGui.addCommand("IFC_ConvertDocument", IFC_ConvertDocument())