Skip to content

Commit

Permalink
Arch: fixed encoding problem in Survey tool - fixes #1821
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Nov 9, 2014
1 parent d30eb39 commit 039cacb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Mod/Arch/ArchCommands.py
Expand Up @@ -712,18 +712,19 @@ def survey(callback=False):
if o.Object.Shape.Solids:
t = FreeCAD.Units.Quantity(o.Object.Shape.Volume,FreeCAD.Units.Volume)
t = t.getUserPreferred()[0]
t = t.replace("^3","³")
t = t.encode("utf8").replace("^3","³")
anno.LabelText = "v " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Volume: " + t.decode("utf8") + "\n")
elif o.Object.Shape.Faces:
t = FreeCAD.Units.Quantity(o.Object.Shape.Area,FreeCAD.Units.Area)
t = t.getUserPreferred()[0]
t = t.replace("^2","²")
t = t.encode("utf8").replace("^2","²")
anno.LabelText = "a " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Area: " + t.decode("utf8") + "\n")
else:
t = FreeCAD.Units.Quantity(o.Object.Shape.Length,FreeCAD.Units.Length)
t = t.getUserPreferred()[0]
t = t.encode("utf8")
anno.LabelText = "l " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Length: " + t + "\n")
if FreeCAD.GuiUp and t:
Expand All @@ -745,17 +746,18 @@ def survey(callback=False):
if "Face" in el:
t = FreeCAD.Units.Quantity(e.Area,FreeCAD.Units.Area)
t = t.getUserPreferred()[0]
t = t.replace("^2","²")
t = t.encode("utf8").replace("^2","²")
anno.LabelText = "a " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Area: "+ t.decode("utf8") + "\n")
elif "Edge" in el:
t = FreeCAD.Units.Quantity(e.Length,FreeCAD.Units.Length)
t = t.getUserPreferred()[0]
t = t.encode("utf8").getUserPreferred()[0]
anno.LabelText = "l " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Length: " + t + "\n")
elif "Vertex" in el:
t = FreeCAD.Units.Quantity(e.Z,FreeCAD.Units.Length)
t = t.getUserPreferred()[0]
t = t.encode("utf8")
anno.LabelText = "z " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Zcoord: " + t + "\n")
if FreeCAD.GuiUp and t:
Expand Down

1 comment on commit 039cacb

@blazewicz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It causes TypeError in Python 3

>>> 'a'.encode('utf-8') + 'b'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't concat str to bytes

Survey tool does not work because of that.

Please sign in to comment.