Skip to content

Commit

Permalink
Arch: Added pref option to not copy units to clipboard in survey mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Apr 30, 2016
1 parent eca3ce2 commit a07ad8d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
39 changes: 23 additions & 16 deletions src/Mod/Arch/ArchCommands.py
Expand Up @@ -730,6 +730,9 @@ def survey(callback=False):
for o in newsels:
if o.Object.isDerivedFrom("Part::Feature"):
n = o.Object.Label
showUnit = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("surveyUnits",True)
t = ""
u = FreeCAD.Units.Quantity()
if not o.HasSubObjects:
# entire object
anno = FreeCAD.ActiveDocument.addObject("App::AnnotationLabel","surveyLabel")
Expand All @@ -738,27 +741,29 @@ def survey(callback=False):
else:
anno.BasePosition = o.Object.Shape.BoundBox.Center
FreeCAD.SurveyObserver.labels.append(anno.Name)
t = ""
if o.Object.Shape.Solids:
t = FreeCAD.Units.Quantity(o.Object.Shape.Volume,FreeCAD.Units.Volume)
t = t.getUserPreferred()[0]
u = FreeCAD.Units.Quantity(o.Object.Shape.Volume,FreeCAD.Units.Volume)
t = u.getUserPreferred()[0]
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]
u = FreeCAD.Units.Quantity(o.Object.Shape.Area,FreeCAD.Units.Area)
t = u.getUserPreferred()[0]
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]
u = FreeCAD.Units.Quantity(o.Object.Shape.Length,FreeCAD.Units.Length)
t = u.getUserPreferred()[0]
t = t.encode("utf8")
anno.LabelText = "l " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Length: " + t.decode("utf8") + "\n")
if FreeCAD.GuiUp and t:
QtGui.qApp.clipboard().setText(t)
if showUnit:
QtGui.qApp.clipboard().setText(t)
else:
QtGui.qApp.clipboard().setText(str(u.Value))
else:
# single element(s)
for el in o.SubElementNames:
Expand All @@ -772,27 +777,29 @@ def survey(callback=False):
else:
anno.BasePosition = e.BoundBox.Center
FreeCAD.SurveyObserver.labels.append(anno.Name)
t = ""
if "Face" in el:
t = FreeCAD.Units.Quantity(e.Area,FreeCAD.Units.Area)
t = t.getUserPreferred()[0]
u = FreeCAD.Units.Quantity(e.Area,FreeCAD.Units.Area)
t = u.getUserPreferred()[0]
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]
u= FreeCAD.Units.Quantity(e.Length,FreeCAD.Units.Length)
t = u.getUserPreferred()[0]
t = t.encode("utf8")
anno.LabelText = "l " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Length: " + t.decode("utf8") + "\n")
elif "Vertex" in el:
t = FreeCAD.Units.Quantity(e.Z,FreeCAD.Units.Length)
t = t.getUserPreferred()[0]
u = FreeCAD.Units.Quantity(e.Z,FreeCAD.Units.Length)
t = u.getUserPreferred()[0]
t = t.encode("utf8")
anno.LabelText = "z " + t
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Zcoord: " + t.decode("utf8") + "\n")
if FreeCAD.GuiUp and t:
QtGui.qApp.clipboard().setText(t)
if showUnit:
QtGui.qApp.clipboard().setText(t)
else:
QtGui.qApp.clipboard().setText(str(u.Value))

FreeCAD.SurveyObserver.selection.extend(newsels)

Expand Down
34 changes: 33 additions & 1 deletion src/Mod/Arch/Resources/ui/preferences-arch.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>460</width>
<height>500</height>
<height>537</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -402,6 +402,38 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Survey</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_2">
<property name="toolTip">
<string>If this is checked, the text that gets placed in the clipboard will include the unit. Otherwise, it will be a simple number expressed in internal units (millimeters)</string>
</property>
<property name="text">
<string>Include unit when sending measurements to clipboard</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>surveyUnits</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down

0 comments on commit a07ad8d

Please sign in to comment.