Arch: Enhanced Space tool - fixes #1610

This commit is contained in:
Yorik van Havre 2014-08-04 18:24:20 -03:00
parent a7d1b80fc3
commit f5f6cb1adf
2 changed files with 112 additions and 82 deletions

View File

@ -658,18 +658,22 @@ class ViewProviderComponent:
def claimChildren(self): def claimChildren(self):
if hasattr(self,"Object"): if hasattr(self,"Object"):
if Draft.getType(self.Object) != "Wall": c = []
c = [self.Object.Base] if hasattr(self.Object,"Base"):
elif Draft.getType(self.Object.Base) == "Space": if Draft.getType(self.Object) != "Wall":
c = [] c = [self.Object.Base]
else: elif Draft.getType(self.Object.Base) == "Space":
c = [self.Object.Base] c = []
c = c + self.Object.Additions else:
for s in self.Object.Subtractions: c = [self.Object.Base]
if Draft.getType(self.Object) == "Wall": if hasattr(self.Object,"Additions"):
if Draft.getType(s) == "Roof": c.extend(self.Object.Additions)
continue if hasattr(self.Object,"Subtractions"):
c.append(s) for s in self.Object.Subtractions:
if Draft.getType(self.Object) == "Wall":
if Draft.getType(s) == "Roof":
continue
c.append(s)
if hasattr(self.Object,"Armatures"): if hasattr(self.Object,"Armatures"):
c.extend(self.Object.Armatures) c.extend(self.Object.Armatures)
if hasattr(self.Object,"Tool"): if hasattr(self.Object,"Tool"):

View File

@ -1,3 +1,5 @@
# -*- coding: utf8 -*-
#*************************************************************************** #***************************************************************************
#* * #* *
#* Copyright (c) 2013 * #* Copyright (c) 2013 *
@ -105,9 +107,9 @@ class _CommandSpace:
class _Space(ArchComponent.Component): class _Space(ArchComponent.Component):
"A space object" "A space object"
def __init__(self,obj): def __init__(self,obj):
obj.Proxy = self ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyLink","Base","Arch",translate("Arch","A base shape defining this space"))
obj.addProperty("App::PropertyLinkSubList","Boundaries","Arch",translate("Arch","The objects that make the boundaries of this space object")) obj.addProperty("App::PropertyLinkSubList","Boundaries","Arch",translate("Arch","The objects that make the boundaries of this space object"))
obj.addProperty("App::PropertyFloat","Area","Arch",translate("Arch","The computed floor area of this space"))
self.Type = "Space" self.Type = "Space"
def execute(self,obj): def execute(self,obj):
@ -116,6 +118,8 @@ class _Space(ArchComponent.Component):
def onChanged(self,obj,prop): def onChanged(self,obj,prop):
if prop in ["Boundaries","Base"]: if prop in ["Boundaries","Base"]:
self.getShape(obj) self.getShape(obj)
obj.Area = self.getArea(obj)
obj.setEditorMode('Area',1)
def addSubobjects(self,obj,subobjects): def addSubobjects(self,obj,subobjects):
"adds subobjects to this space" "adds subobjects to this space"
@ -203,13 +207,14 @@ class _Space(ArchComponent.Component):
import Part,DraftGeomUtils import Part,DraftGeomUtils
try: try:
pl = Part.makePlane(1,1) pl = Part.makePlane(1,1)
pl.translate(obj.Shape.CenterOfMass)
sh = obj.Shape.copy() sh = obj.Shape.copy()
cutplane,v1,v2 = ArchCommands.getCutVolume(pl,sh) cutplane,v1,v2 = ArchCommands.getCutVolume(pl,sh)
e = sh.section(cutplane) e = sh.section(cutplane)
e = DraftGeomUtils.sortEdges(e.Edges) e = DraftGeomUtils.sortEdges(e.Edges)
w = Part.Wire(e) w = Part.Wire(e)
f = Part.Face(w) f = Part.Face(w)
return round(f.Area,Draft.getParam("dimPrecision",6)) return f.Area
except: except:
return 0 return 0
@ -217,85 +222,106 @@ class _Space(ArchComponent.Component):
class _ViewProviderSpace(ArchComponent.ViewProviderComponent): class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
"A View Provider for Section Planes" "A View Provider for Section Planes"
def __init__(self,vobj): def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
vobj.Transparency = 85 vobj.Transparency = 85
vobj.LineWidth = 1 vobj.LineWidth = 1
vobj.LineColor = (1.0,0.0,0.0,1.0) vobj.LineColor = (1.0,0.0,0.0,1.0)
vobj.DrawStyle = "Dotted" vobj.DrawStyle = "Dotted"
vobj.addProperty("App::PropertyString","Override","Base","Text override. Use $area to insert the area") vobj.addProperty("App::PropertyStringList","Text", "Arch","Text to show. Use $area, $label or $tag to insert the area, label or tag")
vobj.addProperty("App::PropertyColor","TextColor","Base","The color of the area text") vobj.addProperty("App::PropertyString", "FontName", "Arch","Font name")
vobj.TextColor = (1.0,0.0,0.0,1.0) vobj.addProperty("App::PropertyColor", "TextColor", "Arch","The color of the area text")
vobj.Override = "$area m2" vobj.addProperty("App::PropertyLength", "FontSize", "Arch","Font size")
ArchComponent.ViewProviderComponent.__init__(self,vobj) vobj.addProperty("App::PropertyFloat", "LineSpacing", "Arch","The space between the lines of text")
vobj.addProperty("App::PropertyVector", "TextPosition","Arch","The position of the text. Leave (0,0,0) for automatic position")
vobj.TextColor = (0.0,0.0,0.0,1.0)
vobj.Text = ["$label","$area"]
vobj.FontSize = Draft.getParam("textheight",10)
vobj.FontName = Draft.getParam("textfont","")
vobj.LineSpacing = 1.0
def getIcon(self): def getIcon(self):
import Arch_rc import Arch_rc
return ":/icons/Arch_Space_Tree.svg" return ":/icons/Arch_Space_Tree.svg"
def claimChildren(self): def attach(self,vobj):
if self.Object.Base: ArchComponent.ViewProviderComponent.attach(self,vobj)
return [self.Object.Base] from pivy import coin
else: self.color = coin.SoBaseColor()
return [] self.font = coin.SoFont()
self.text = coin.SoAsciiText()
def setDisplayMode(self,mode): self.text.string = "d"
if mode == "Detailed": self.coords = coin.SoTransform()
self.setAnnotation(True) self.text.justification = coin.SoAsciiText.LEFT
return "Flat Lines" label = coin.SoSeparator()
else: label.addChild(self.coords)
self.setAnnotation(False) label.addChild(self.color)
return mode label.addChild(self.font)
label.addChild(self.text)
def getArea(self,obj): vobj.Annotation.addChild(label)
"returns a formatted area text" self.onChanged(vobj,"TextColor")
area = str(obj.Proxy.getArea(obj)) self.onChanged(vobj,"FontSize")
if obj.ViewObject.Override: self.onChanged(vobj,"LineSpacing")
text = obj.ViewObject.Override self.onChanged(vobj,"FontName")
area = text.replace("$area",str(area))
return str(area)
def setAnnotation(self,recreate=True):
if hasattr(self,"Object"):
if hasattr(self,"area"):
if self.area:
self.Object.ViewObject.Annotation.removeChild(self.area)
self.area = None
self.coords = None
self.anno = None
if recreate:
area = self.getArea(self.Object)
if area:
from pivy import coin
import SketcherGui
self.area = coin.SoSeparator()
self.coords = coin.SoTransform()
if self.Object.Shape:
if not self.Object.Shape.isNull():
c = self.Object.Shape.CenterOfMass
self.coords.translation.setValue([c.x,c.y,c.z])
self.anno = coin.SoType.fromName("SoDatumLabel").createInstance()
self.anno.string.setValue(area)
self.anno.datumtype.setValue(6)
color = coin.SbVec3f(self.Object.ViewObject.TextColor[:3])
self.anno.textColor.setValue(color)
self.area.addChild(self.coords)
self.area.addChild(self.anno)
self.Object.ViewObject.Annotation.addChild(self.area)
def updateData(self,obj,prop): def updateData(self,obj,prop):
if prop == "Shape": if prop in ["Shape","Label","Tag"]:
if hasattr(self,"area"): self.onChanged(obj.ViewObject,"Text")
if self.area: self.onChanged(obj.ViewObject,"TextPosition")
area = self.getArea(obj)
self.anno.string.setValue(area)
if not obj.Shape.isNull():
c = obj.Shape.CenterOfMass
self.coords.translation.setValue([c.x,c.y,c.z])
def onChanged(self,vobj,prop): def onChanged(self,vobj,prop):
if prop in ["Override","TextColor"]: if prop == "Text":
if vobj.DisplayMode == "Detailed": if hasattr(self,"text") and hasattr(vobj,"Text"):
self.setAnnotation(True) self.text.string.deleteValues(0)
return texts = []
for t in vobj.Text:
if t:
if hasattr(vobj.Object,"Area"):
from FreeCAD import Units
q = Units.Quantity(vobj.Object.Area,Units.Area)
q = q.getUserPreferred()[0].replace("^2","²")
t = t.replace("$area",q.decode("utf8"))
t = t.replace("$label",vobj.Object.Label.decode("utf8"))
if hasattr(vobj.Object,"Tag"):
t = t.replace("$tag",vobj.Object.Tag.decode("utf8"))
texts.append(t.encode("utf8"))
if texts:
self.text.string.setValues(texts)
elif prop == "FontName":
if hasattr(self,"font") and hasattr(vobj,"FontName"):
self.font.name = str(vobj.FontName)
elif (prop == "FontSize"):
if hasattr(self,"font") and hasattr(vobj,"FontSize"):
self.font.size = vobj.FontSize.Value
elif prop == "TextColor":
if hasattr(self,"color") and hasattr(vobj,"TextColor"):
c = vobj.TextColor
self.color.rgb.setValue(c[0],c[1],c[2])
elif prop == "TextPosition":
if hasattr(self,"coords") and hasattr(vobj,"TextPosition"):
import DraftVecUtils
if DraftVecUtils.isNull(vobj.TextPosition):
try:
pos = vobj.Object.Shape.CenterOfMass
z = vobj.Object.Shape.BoundBox.ZMin
pos = FreeCAD.Vector(pos.x,pos.y,z)
except:
pos = FreeCAD.Vector()
else:
pos = vobj.TextPosition
self.coords.translation.setValue([pos.x,pos.y,pos.z])
elif prop == "LineSpacing":
if hasattr(self,"text") and hasattr(vobj,"LineSpacing"):
self.text.spacing = vobj.LineSpacing
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
FreeCADGui.addCommand('Arch_Space',_CommandSpace()) FreeCADGui.addCommand('Arch_Space',_CommandSpace())