Arch: Survey tool
This commit is contained in:
@@ -698,6 +698,106 @@ def pruneIncluded(objectslist):
|
||||
if toplevel:
|
||||
newlist.append(obj)
|
||||
return newlist
|
||||
|
||||
class SurveyObserver:
|
||||
"an observer for the survey() function"
|
||||
def __init__(self,callback):
|
||||
self.callback = callback
|
||||
self.cancellable = False
|
||||
self.selection = []
|
||||
self.labels = []
|
||||
|
||||
def addSelection(self,document, object, element, position):
|
||||
self.cancellable = False
|
||||
self.callback(True)
|
||||
|
||||
def clearSelection(self,document):
|
||||
if self.cancellable:
|
||||
self.callback(True)
|
||||
else:
|
||||
self.cancellable = True
|
||||
|
||||
def survey(callback=False):
|
||||
"""survey(): starts survey mode, where you can click edges and faces to get their lengths or area.
|
||||
Clicking on no object (on an empty area) stops survey mode."""
|
||||
if not callback:
|
||||
if hasattr(FreeCAD,"SurveyObserver"):
|
||||
for label in FreeCAD.SurveyObserver.labels:
|
||||
FreeCAD.ActiveDocument.removeObject(label)
|
||||
FreeCADGui.Selection.removeObserver(FreeCAD.SurveyObserver)
|
||||
del FreeCAD.SurveyObserver
|
||||
else:
|
||||
FreeCAD.SurveyObserver = SurveyObserver(callback=survey)
|
||||
FreeCADGui.Selection.addObserver(FreeCAD.SurveyObserver)
|
||||
else:
|
||||
sel = FreeCADGui.Selection.getSelectionEx()
|
||||
if not sel:
|
||||
if hasattr(FreeCAD,"SurveyObserver"):
|
||||
for label in FreeCAD.SurveyObserver.labels:
|
||||
FreeCAD.ActiveDocument.removeObject(label)
|
||||
FreeCADGui.Selection.removeObserver(FreeCAD.SurveyObserver)
|
||||
del FreeCAD.SurveyObserver
|
||||
else:
|
||||
if hasattr(FreeCAD,"SurveyObserver"):
|
||||
basesel = FreeCAD.SurveyObserver.selection
|
||||
newsels = []
|
||||
for o in sel:
|
||||
found = False
|
||||
for eo in basesel:
|
||||
if o.ObjectName == eo.ObjectName:
|
||||
if o.SubElementNames == eo.SubElementNames:
|
||||
found = True
|
||||
if not found:
|
||||
newsels.append(o)
|
||||
if newsels:
|
||||
from pivy import coin
|
||||
pr = Draft.getParam("dimPrecision",2)
|
||||
for o in newsels:
|
||||
if o.Object.isDerivedFrom("Part::Feature"):
|
||||
n = o.Object.Label
|
||||
if not o.HasSubObjects:
|
||||
# entire object
|
||||
anno = FreeCAD.ActiveDocument.addObject("App::AnnotationLabel","surveyLabel")
|
||||
anno.BasePosition = o.Object.Shape.CenterOfMass
|
||||
FreeCAD.SurveyObserver.labels.append(anno.Name)
|
||||
t = ""
|
||||
if o.Object.Shape.Solids:
|
||||
t = str(round(o.Object.Shape.Volume,pr))
|
||||
anno.LabelText = "v " + t
|
||||
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Volume: " + t + "\n")
|
||||
elif o.Object.Shape.Faces:
|
||||
t = str(round(o.Object.Shape.Area,pr))
|
||||
anno.LabelText = "a " + t
|
||||
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Area: " + t + "\n")
|
||||
else:
|
||||
t = str(round(o.Object.Shape.Length,pr))
|
||||
anno.LabelText = "l " + t
|
||||
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: Whole, Length: " + t + "\n")
|
||||
if FreeCAD.GuiUp and t:
|
||||
QtGui.qApp.clipboard().setText(t)
|
||||
else:
|
||||
# single element(s)
|
||||
for el in o.SubElementNames:
|
||||
e = getattr(o.Object.Shape,el)
|
||||
anno = FreeCAD.ActiveDocument.addObject("App::AnnotationLabel","surveyLabel")
|
||||
anno.BasePosition = e.CenterOfMass
|
||||
FreeCAD.SurveyObserver.labels.append(anno.Name)
|
||||
t = ""
|
||||
if "Face" in el:
|
||||
t = str(round(e.Area,pr))
|
||||
anno.LabelText = "a " + t
|
||||
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Area: "+ t + "\n")
|
||||
elif "Edge" in el:
|
||||
t = str(round(e.Length,pr))
|
||||
anno.LabelText = "l " + t
|
||||
FreeCAD.Console.PrintMessage("Object: " + n + ", Element: " + el + ", Length: " + t + "\n")
|
||||
if FreeCAD.GuiUp and t:
|
||||
QtGui.qApp.clipboard().setText(t)
|
||||
|
||||
FreeCAD.SurveyObserver.selection.extend(newsels)
|
||||
|
||||
|
||||
|
||||
|
||||
# command definitions ###############################################
|
||||
|
||||
@@ -939,6 +1039,18 @@ class _CommandIfcExplorer:
|
||||
self.dialog = importIFC.explore()
|
||||
|
||||
|
||||
class _CommandSurvey:
|
||||
"the Arch Survey command definition"
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Arch_Survey',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Survey","Survey"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Survey","Starts survey")}
|
||||
|
||||
def Activated(self):
|
||||
FreeCADGui.doCommand("import Arch")
|
||||
FreeCADGui.doCommand("Arch.survey()")
|
||||
|
||||
|
||||
class _CommandFixture:
|
||||
# OBSOLETE - To be removed
|
||||
"the Arch Fixture command definition"
|
||||
@@ -963,6 +1075,7 @@ class _CommandFixture:
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('Arch_Add',_CommandAdd())
|
||||
FreeCADGui.addCommand('Arch_Remove',_CommandRemove())
|
||||
@@ -973,4 +1086,5 @@ if FreeCAD.GuiUp:
|
||||
FreeCADGui.addCommand('Arch_CloseHoles',_CommandCloseHoles())
|
||||
FreeCADGui.addCommand('Arch_Check',_CommandCheck())
|
||||
FreeCADGui.addCommand('Arch_IfcExplorer',_CommandIfcExplorer())
|
||||
FreeCADGui.addCommand('Arch_Survey',_CommandSurvey())
|
||||
#FreeCADGui.addCommand('Arch_Fixture',_CommandFixture())
|
||||
|
||||
Reference in New Issue
Block a user