Skip to content

Commit

Permalink
BIM: fix BIM_Setup unit system issue
Browse files Browse the repository at this point in the history
Fixes FreeCAD#14675.

Note that I would prefer to use the FEM unit system (always mm). BIM_Setup does not support that, and this PR does not change that.
  • Loading branch information
Roy-043 authored and yorikvanhavre committed Jun 24, 2024
1 parent 727ff9a commit 13296cc
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/Mod/BIM/bimcommands/BimSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ def Activated(self):
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt(
"UserSchema", unit
)
if FreeCAD.ActiveDocument is not None:
docs_dict = FreeCAD.listDocuments()
for doc in docs_dict.values():
doc.UnitSystem = unit
if len(docs_dict) == 1:
FreeCAD.Console.PrintWarning(
translate("BIM", "Unit system updated for active document") + "\n"
)
else:
FreeCAD.Console.PrintWarning(
translate("BIM", "Unit system updated for all opened documents") + "\n"
)
if hasattr(FreeCAD.Units, "setSchema"):
FreeCAD.Units.setSchema(unit)
decimals = self.form.settingDecimals.value()
Expand Down Expand Up @@ -474,7 +486,7 @@ def setPreset(self, preset=None):
unit = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt(
"UserSchema", 0
)
unit = [0, 2, 3, 3, 1, 5, 0, 4][
unit = [0, 2, 3, 3, 1, 5, 0, 4, 0, 2][
unit
] # less choices in our simplified dialog
decimals = FreeCAD.ParamGet(
Expand Down Expand Up @@ -620,16 +632,16 @@ def getPrefColor(self,color):
g = ((color >> 16) & 0xFF) / 255.0
b = ((color >> 8) & 0xFF) / 255.0
from PySide import QtGui

return QtGui.QColor.fromRgbF(r, g, b)


def getIfcOpenShell(self,force=False):
"""downloads and installs IfcOpenShell"""

# TODO WARNING the IfcOpenBot repo below is not actively kept updated.

Check warning on line 642 in src/Mod/BIM/bimcommands/BimSetup.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

TODO WARNING the IfcOpenBot repo below is not actively kept updated. (fixme)
# We need to use PIP

ifcok = False
if not force:
try:
Expand All @@ -649,7 +661,7 @@ def getIfcOpenShell(self,force=False):
from PySide import QtGui
import zipfile
from urllib import request

if not FreeCAD.GuiUp:
reply = QtGui.QMessageBox.Yes
else:
Expand Down Expand Up @@ -706,11 +718,11 @@ def getIfcOpenShell(self,force=False):
if u:
if sys.version_info.major < 3:
import StringIO as io

_stringio = io.StringIO
else:
import io

_stringio = io.BytesIO
zfile = _stringio()
zfile.write(u.read())
Expand Down

0 comments on commit 13296cc

Please sign in to comment.