-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
BimStatusBar.py
329 lines (294 loc) · 13.1 KB
/
BimStatusBar.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# -*- 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 *
# Language path for InitGui.py
def getLanguagePath():
return os.path.join(os.path.dirname(__file__), "translations")
# Status bar buttons
def setStatusIcons(show=True):
"shows or hides the BIM icons in the status bar"
import FreeCADGui
from PySide import QtCore, QtGui
nudgeLabelsM = [
translate("BIM", "Custom..."),
'1/16"',
'1/8"',
'1/4"',
'1"',
'6"',
"1'",
translate("BIM", "Auto"),
]
nudgeLabelsI = [
translate("BIM", "Custom..."),
"1 mm",
"5 mm",
"1 cm",
"5 cm",
"10 cm",
"50 cm",
translate("BIM", "Auto"),
]
def toggle(state):
FreeCADGui.runCommand("BIM_TogglePanels")
def toggleBimViews(state):
FreeCADGui.runCommand("BIM_Views")
def toggleBackground(state):
FreeCADGui.runCommand("BIM_Background")
def addonMgr():
mw = FreeCADGui.getMainWindow()
if mw:
st = mw.statusBar()
statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
if statuswidget:
updatebutton = statuswidget.findChild(QtGui.QPushButton, "UpdateButton")
if updatebutton:
statuswidget.actions()[-1].setVisible(False)
FreeCADGui.runCommand("Std_AddonMgr")
def setNudge(action):
utext = action.text().replace("&", "")
if utext == nudgeLabelsM[0]:
# load dialog
form = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "dialogNudgeValue.ui")
)
# center the dialog over FreeCAD window
mw = FreeCADGui.getMainWindow()
form.move(
mw.frameGeometry().topLeft() + mw.rect().center() - form.rect().center()
)
result = form.exec_()
if not result:
return
utext = form.inputField.text()
action.parent().parent().parent().setText(utext)
class CheckWorker(QtCore.QThread):
updateAvailable = QtCore.Signal(bool)
def __init__(self):
QtCore.QThread.__init__(self)
def run(self):
try:
import git
except ImportError:
return
FreeCAD.Console.PrintLog(
"Checking for available updates of the BIM workbench\n"
)
bimdir = os.path.join(FreeCAD.getUserAppDataDir(), "Mod", "BIM")
if os.path.exists(bimdir):
if os.path.exists(bimdir + os.sep + ".git"):
gitrepo = git.Git(bimdir)
try:
gitrepo.fetch()
if "git pull" in gitrepo.status():
self.updateAvailable.emit(True)
return
except:
# can fail for any number of reasons, ex. not being online
pass
self.updateAvailable.emit(False)
def checkUpdates():
FreeCAD.bim_update_checker = CheckWorker()
FreeCAD.bim_update_checker.updateAvailable.connect(showUpdateButton)
FreeCAD.bim_update_checker.start()
def showUpdateButton(avail):
if avail:
FreeCAD.Console.PrintLog("A BIM update is available\n")
mw = FreeCADGui.getMainWindow()
if mw:
st = mw.statusBar()
statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
if statuswidget:
updatebutton = statuswidget.findChild(
QtGui.QAction, "UpdateButton"
)
if updatebutton:
# updatebutton.show() # doesn't work for some reason
statuswidget.actions()[-1].setVisible(True)
else:
FreeCAD.Console.PrintLog("No BIM update available\n")
if hasattr(FreeCAD, "bim_update_checker"):
del FreeCAD.bim_update_checker
def toggleContextMenu(point):
# DISABLED - TODO need to find a way to add a context menu to a QAction...
FreeCADGui.BimToggleMenu = QtGui.QMenu()
for t in ["Report view", "Python console", "Selection view", "Combo View"]:
a = QtGui.QAction(t)
# a.setCheckable(True)
# a.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("toggle"+t.replace(" ",""),True))
FreeCADGui.BimToggleMenu.addAction(a)
pos = FreeCADGui.getMainWindow().cursor().pos()
FreeCADGui.BimToggleMenu.triggered.connect(toggleSaveSettings)
# QtCore.QObject.connect(FreeCADGui.BimToggleMenu,QtCore.SIGNAL("triggered(QAction *)"),toggleSaveSettings)
FreeCADGui.BimToggleMenu.popup(pos)
def toggleSaveSettings(action):
t = action.text()
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetBool(
"toggle" + t.replace(" ", ""), action.isChecked()
)
if hasattr(FreeCADGui, "BimToggleMenu"):
del FreeCADGui.BimToggleMenu
# main code
mw = FreeCADGui.getMainWindow()
if mw:
st = mw.statusBar()
statuswidget = st.findChild(QtGui.QToolBar, "BIMStatusWidget")
if show:
if statuswidget:
statuswidget.show()
else:
statuswidget = QtGui.QToolBar()
statuswidget.setObjectName("BIMStatusWidget")
s = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetInt("ToolbarIconSize", 24)
statuswidget.setIconSize(QtCore.QSize(s,s))
st.insertPermanentWidget(2, statuswidget)
# report panels toggle button
togglebutton = QtGui.QAction()
togglemenu = QtGui.QMenu()
for t in ["Toggle", "Report view", "Python console", "Selection view", "Combo View"]:
a = QtGui.QAction(t)
togglemenu.addAction(a)
togglemenu.triggered.connect(toggleSaveSettings)
togglebutton.setIcon(
QtGui.QIcon(
os.path.join(
os.path.dirname(__file__), "icons", "BIM_TogglePanels.svg"
)
)
)
togglebutton.setText("")
togglebutton.setToolTip(
translate("BIM", "Toggle report panels on/off (Ctrl+0)")
)
togglebutton.setCheckable(True)
rv = mw.findChild(QtGui.QWidget, "Python console")
if rv and rv.isVisible():
togglebutton.setChecked(True)
statuswidget.togglebutton = togglebutton
#togglebutton.setMenu(togglemenu)
togglebutton.triggered.connect(toggle)
statuswidget.addAction(togglebutton)
# bim views widget toggle button
import BimViews
bimviewsbutton = QtGui.QAction()
bimviewsbutton.setIcon(
QtGui.QIcon(
os.path.join(
os.path.dirname(__file__), "icons", "BIM_Views.svg"
)
)
)
bimviewsbutton.setText("")
bimviewsbutton.setToolTip(
translate("BIM", "Toggle BIM views panel on/off (Ctrl+9)")
)
bimviewsbutton.setCheckable(True)
if BimViews.findWidget():
bimviewsbutton.setChecked(True)
statuswidget.bimviewsbutton = bimviewsbutton
bimviewsbutton.triggered.connect(toggleBimViews)
statuswidget.addAction(bimviewsbutton)
# background toggle button
bgbutton = QtGui.QAction()
#bwidth = bgbutton.fontMetrics().boundingRect("AAAA").width()
#bgbutton.setMaximumWidth(bwidth)
bgbutton.setIcon(
QtGui.QIcon(
os.path.join(
os.path.dirname(__file__), "icons", "BIM_Background.svg"
)
)
)
bgbutton.setText("")
bgbutton.setToolTip(
translate(
"BIM", "Toggle 3D view background between simple and gradient"
)
)
statuswidget.bgbutton = bgbutton
bgbutton.triggered.connect(toggleBackground)
statuswidget.addAction(bgbutton)
# ifc widgets
try:
import ifc_status
except:
pass
else:
ifc_status.set_status_widget(statuswidget)
# update notifier button (starts hidden)
updatebutton = QtGui.QAction()
updatebutton.setObjectName("UpdateButton")
#updatebutton.setMaximumWidth(bwidth)
updatebutton.setIcon(QtGui.QIcon(":/icons/view-refresh.svg"))
updatebutton.setText("")
updatebutton.setToolTip(
translate(
"BIM",
"An update to the BIM workbench is available. Click here to open the addons manager.",
)
)
updatebutton.triggered.connect(addonMgr)
updatebutton.setVisible(False)
statuswidget.addAction(updatebutton)
QtCore.QTimer.singleShot(
2500, checkUpdates
) # delay a bit the check for BIM WB update...
# nudge button
nudge = QtGui.QPushButton(nudgeLabelsM[-1])
nudge.setIcon(
QtGui.QIcon(
os.path.join(
os.path.dirname(__file__), "icons", "BIM_Nudge.svg"
)
)
)
nudge.setFlat(True)
nudge.setToolTip(
translate(
"BIM",
"The value of the nudge movement (rotation is always 45°).\n\nCTRL+arrows to move\nCTRL+, to rotate left\nCTRL+. to rotate right\nCTRL+PgUp to extend extrusion\nCTRL+PgDown to shrink extrusion\nCTRL+/ to switch between auto and manual mode",
)
)
statuswidget.addWidget(nudge)
statuswidget.nudge = nudge
menu = QtGui.QMenu(nudge)
gnudge = QtGui.QActionGroup(menu)
for u in nudgeLabelsM:
a = QtGui.QAction(gnudge)
a.setText(u)
menu.addAction(a)
nudge.setMenu(menu)
gnudge.triggered.connect(setNudge)
statuswidget.nudgeLabelsI = nudgeLabelsI
statuswidget.nudgeLabelsM = nudgeLabelsM
else:
if statuswidget is None:
# when switching workbenches, the toolbar sometimes "jumps"
# out of the status bar to any other dock area...
statuswidget = mw.findChild(QtGui.QToolBar, "BIMStatusWidget")
if statuswidget:
statuswidget.hide()
statuswidget.toggleViewAction().setVisible(False)