Arch: improvements in Space object

* Better text control
* Text position editable with Draft Edit
* Additional properties such as finish types
This commit is contained in:
Yorik van Havre 2014-08-05 16:19:39 -03:00
parent be3299a46d
commit 234af5b27f
6 changed files with 139 additions and 46 deletions

View File

@ -91,6 +91,9 @@ class _CommandPanel:
'Accel': "P, A", 'Accel': "P, A",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Panel","Creates a panel object from scratch or from a selected object (sketch, wire, face or solid)")} 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Panel","Creates a panel object from scratch or from a selected object (sketch, wire, face or solid)")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self): def Activated(self):
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
self.Length = p.GetFloat("PanelLength",1000) self.Length = p.GetFloat("PanelLength",1000)

View File

@ -108,8 +108,11 @@ class _Space(ArchComponent.Component):
"A space object" "A space object"
def __init__(self,obj): def __init__(self,obj):
ArchComponent.Component.__init__(self,obj) ArchComponent.Component.__init__(self,obj)
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")) obj.addProperty("App::PropertyFloat", "Area", "Arch",translate("Arch","The computed floor area of this space"))
obj.addProperty("App::PropertyString", "FinishFloor", "Arch",translate("Arch","The finishing of the floor of this space"))
obj.addProperty("App::PropertyString", "FinishWalls", "Arch",translate("Arch","The finishing of the walls of this space"))
obj.addProperty("App::PropertyString", "FinishCeiling","Arch",translate("Arch","The finishing of the ceiling of this space"))
self.Type = "Space" self.Type = "Space"
def execute(self,obj): def execute(self,obj):
@ -119,7 +122,8 @@ class _Space(ArchComponent.Component):
if prop in ["Boundaries","Base"]: if prop in ["Boundaries","Base"]:
self.getShape(obj) self.getShape(obj)
obj.Area = self.getArea(obj) obj.Area = self.getArea(obj)
obj.setEditorMode('Area',1) if hasattr(obj,"Area"):
obj.setEditorMode('Area',1)
def addSubobjects(self,obj,subobjects): def addSubobjects(self,obj,subobjects):
"adds subobjects to this space" "adds subobjects to this space"
@ -227,18 +231,29 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
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::PropertyStringList","Text", "Arch","Text to show. Use $area, $label or $tag to insert the area, label or tag") vobj.addProperty("App::PropertyStringList", "Text", "Arch",translate("Arch","The text to show. Use $area, $label, $tag, $floor, $walls, $ceiling to insert the respective data"))
vobj.addProperty("App::PropertyString", "FontName", "Arch","Font name") vobj.addProperty("App::PropertyString", "FontName", "Arch",translate("Arch","The name of the font"))
vobj.addProperty("App::PropertyColor", "TextColor", "Arch","The color of the area text") vobj.addProperty("App::PropertyColor", "TextColor", "Arch",translate("Arch","The color of the area text"))
vobj.addProperty("App::PropertyLength", "FontSize", "Arch","Font size") vobj.addProperty("App::PropertyLength", "FontSize", "Arch",translate("Arch","The size of the text font"))
vobj.addProperty("App::PropertyFloat", "LineSpacing", "Arch","The space between the lines of text") vobj.addProperty("App::PropertyLength", "FirstLine", "Arch",translate("Arch","The size of the first line of text"))
vobj.addProperty("App::PropertyVector", "TextPosition","Arch","The position of the text. Leave (0,0,0) for automatic position") vobj.addProperty("App::PropertyFloat", "LineSpacing", "Arch",translate("Arch","The space between the lines of text"))
vobj.addProperty("App::PropertyVector", "TextPosition","Arch",translate("Arch","The position of the text. Leave (0,0,0) for automatic position"))
vobj.addProperty("App::PropertyEnumeration","TextAlign", "Arch",translate("Arch","The justification of the text"))
vobj.addProperty("App::PropertyInteger", "Decimals", "Arch",translate("Arch","The number of decimals to use for calculated texts"))
vobj.addProperty("App::PropertyBool", "ShowUnit", "Arch",translate("Arch","Show the unit suffix"))
vobj.TextColor = (0.0,0.0,0.0,1.0) vobj.TextColor = (0.0,0.0,0.0,1.0)
vobj.Text = ["$label","$area"] vobj.Text = ["$label","$area"]
vobj.TextAlign = ["Left","Center","Right"]
vobj.FontSize = Draft.getParam("textheight",10) vobj.FontSize = Draft.getParam("textheight",10)
vobj.FirstLine = Draft.getParam("textheight",10)
vobj.FontName = Draft.getParam("textfont","") vobj.FontName = Draft.getParam("textfont","")
vobj.Decimals = Draft.getParam("dimPrecision",2)
vobj.ShowUnit = Draft.getParam("showUnit",True)
vobj.LineSpacing = 1.0 vobj.LineSpacing = 1.0
def getDefaultDisplayMode(self):
return "Wireframe"
def getIcon(self): def getIcon(self):
import Arch_rc import Arch_rc
return ":/icons/Arch_Space_Tree.svg" return ":/icons/Arch_Space_Tree.svg"
@ -248,18 +263,25 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
from pivy import coin from pivy import coin
self.color = coin.SoBaseColor() self.color = coin.SoBaseColor()
self.font = coin.SoFont() self.font = coin.SoFont()
self.text = coin.SoAsciiText() self.text1 = coin.SoAsciiText()
self.text.string = "d" self.text1.string = " "
self.text1.justification = coin.SoAsciiText.LEFT
self.text2 = coin.SoAsciiText()
self.text2.string = " "
self.text2.justification = coin.SoAsciiText.LEFT
self.coords = coin.SoTransform() self.coords = coin.SoTransform()
self.text.justification = coin.SoAsciiText.LEFT self.header = coin.SoTransform()
label = coin.SoSeparator() label = coin.SoSeparator()
label.addChild(self.coords) label.addChild(self.coords)
label.addChild(self.color) label.addChild(self.color)
label.addChild(self.font) label.addChild(self.font)
label.addChild(self.text) label.addChild(self.text2)
label.addChild(self.header)
label.addChild(self.text1)
vobj.Annotation.addChild(label) vobj.Annotation.addChild(label)
self.onChanged(vobj,"TextColor") self.onChanged(vobj,"TextColor")
self.onChanged(vobj,"FontSize") self.onChanged(vobj,"FontSize")
self.onChanged(vobj,"FirstLine")
self.onChanged(vobj,"LineSpacing") self.onChanged(vobj,"LineSpacing")
self.onChanged(vobj,"FontName") self.onChanged(vobj,"FontName")
@ -268,24 +290,65 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
self.onChanged(obj.ViewObject,"Text") self.onChanged(obj.ViewObject,"Text")
self.onChanged(obj.ViewObject,"TextPosition") self.onChanged(obj.ViewObject,"TextPosition")
def getTextPosition(self,vobj):
pos = FreeCAD.Vector()
if 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
return pos
def onChanged(self,vobj,prop): def onChanged(self,vobj,prop):
if prop == "Text": if prop in ["Text","Decimals","ShowUnit"]:
if hasattr(self,"text") and hasattr(vobj,"Text"): if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"Text"):
self.text.string.deleteValues(0) self.text1.string.deleteValues(0)
texts = [] self.text2.string.deleteValues(0)
text1 = []
text2 = []
first = True
for t in vobj.Text: for t in vobj.Text:
if t: if t:
if hasattr(vobj.Object,"Area"): if hasattr(vobj.Object,"Area"):
from FreeCAD import Units from FreeCAD import Units
q = Units.Quantity(vobj.Object.Area,Units.Area) q = Units.Quantity(vobj.Object.Area,Units.Area).getUserPreferred()
q = q.getUserPreferred()[0].replace("^2","²") qt = vobj.Object.Area/q[1]
t = t.replace("$area",q.decode("utf8")) if hasattr(vobj,"Decimals"):
if vobj.Decimals == 0:
qt = str(int(qt))
else:
f = "%."+str(abs(vobj.Decimals))+"f"
qt = f % qt
else:
qt = str(qt)
if hasattr(vobj,"ShowUnit"):
if vobj.ShowUnit:
qt = qt + q[2].replace("^2","²")
t = t.replace("$area",qt.decode("utf8"))
t = t.replace("$label",vobj.Object.Label.decode("utf8")) t = t.replace("$label",vobj.Object.Label.decode("utf8"))
if hasattr(vobj.Object,"Tag"): if hasattr(vobj.Object,"Tag"):
t = t.replace("$tag",vobj.Object.Tag.decode("utf8")) t = t.replace("$tag",vobj.Object.Tag.decode("utf8"))
texts.append(t.encode("utf8")) if hasattr(vobj.Object,"FinishFloor"):
if texts: t = t.replace("$floor",vobj.Object.FinishFloor.decode("utf8"))
self.text.string.setValues(texts) if hasattr(vobj.Object,"FinishWalls"):
t = t.replace("$walls",vobj.Object.FinishWalls.decode("utf8"))
if hasattr(vobj.Object,"FinishCeiling"):
t = t.replace("$ceiling",vobj.Object.FinishCeiling.decode("utf8"))
if first:
text1.append(t.encode("utf8"))
else:
text2.append(t.encode("utf8"))
first = False
if text1:
self.text1.string.setValues(text1)
if text2:
self.text2.string.setValues(text2)
elif prop == "FontName": elif prop == "FontName":
if hasattr(self,"font") and hasattr(vobj,"FontName"): if hasattr(self,"font") and hasattr(vobj,"FontName"):
@ -295,28 +358,41 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
if hasattr(self,"font") and hasattr(vobj,"FontSize"): if hasattr(self,"font") and hasattr(vobj,"FontSize"):
self.font.size = vobj.FontSize.Value self.font.size = vobj.FontSize.Value
elif (prop == "FirstLine"):
if hasattr(self,"header") and hasattr(vobj,"FontSize") and hasattr(vobj,"FirstLine"):
scale = vobj.FirstLine.Value/vobj.FontSize.Value
self.header.scaleFactor.setValue([scale,scale,scale])
elif prop == "TextColor": elif prop == "TextColor":
if hasattr(self,"color") and hasattr(vobj,"TextColor"): if hasattr(self,"color") and hasattr(vobj,"TextColor"):
c = vobj.TextColor c = vobj.TextColor
self.color.rgb.setValue(c[0],c[1],c[2]) self.color.rgb.setValue(c[0],c[1],c[2])
elif prop == "TextPosition": elif prop == "TextPosition":
if hasattr(self,"coords") and hasattr(vobj,"TextPosition"): if hasattr(self,"coords") and hasattr(self,"header") and hasattr(vobj,"TextPosition") and hasattr(vobj,"FirstLine"):
import DraftVecUtils pos = self.getTextPosition(vobj)
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]) self.coords.translation.setValue([pos.x,pos.y,pos.z])
up = vobj.FirstLine.Value * vobj.LineSpacing
self.header.translation.setValue([0,up,0])
elif prop == "LineSpacing": elif prop == "LineSpacing":
if hasattr(self,"text") and hasattr(vobj,"LineSpacing"): if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"LineSpacing"):
self.text.spacing = vobj.LineSpacing self.text1.spacing = vobj.LineSpacing
self.text2.spacing = vobj.LineSpacing
self.onChanged(vobj,"TextPosition")
elif prop == "TextAlign":
if hasattr(self,"text1") and hasattr(self,"text2") and hasattr(vobj,"TextAlign"):
from pivy import coin
if vobj.TextAlign == "Center":
self.text1.justification = coin.SoAsciiText.CENTER
self.text2.justification = coin.SoAsciiText.CENTER
elif vobj.TextAlign == "Right":
self.text1.justification = coin.SoAsciiText.RIGHT
self.text2.justification = coin.SoAsciiText.RIGHT
else:
self.text1.justification = coin.SoAsciiText.LEFT
self.text2.justification = coin.SoAsciiText.LEFT

View File

@ -95,7 +95,7 @@ class ArchWorkbench(Workbench):
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine", "Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine",
"Draft_FinishLine","Draft_CloseLine"] "Draft_FinishLine","Draft_CloseLine"]
self.draftutils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension", self.draftutils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension",
"Draft_ToggleConstructionMode","Draft_ToggleContinueMode"] "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit"]
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular', self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel', 'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',
'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center', 'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center',

View File

@ -2998,9 +2998,12 @@ class _Dimension(_DraftObject):
obj.Dimline = FreeCAD.Vector(0,1,0) obj.Dimline = FreeCAD.Vector(0,1,0)
def onChanged(self,obj,prop): def onChanged(self,obj,prop):
obj.setEditorMode('Distance',1) if hasattr(obj,"Distance"):
obj.setEditorMode('Normal',2) obj.setEditorMode('Distance',1)
obj.setEditorMode('Support',2) if hasattr(obj,"Normal"):
obj.setEditorMode('Normal',2)
if hasattr(obj,"Support"):
obj.setEditorMode('Support',2)
def execute(self, obj): def execute(self, obj):
if obj.LinkedGeometry: if obj.LinkedGeometry:
@ -3392,9 +3395,12 @@ class _AngularDimension(_DraftObject):
obj.Center = FreeCAD.Vector(0,0,0) obj.Center = FreeCAD.Vector(0,0,0)
def onChanged(self,obj,prop): def onChanged(self,obj,prop):
obj.setEditorMode('Angle',1) if hasattr(obj,"Angle"):
obj.setEditorMode('Normal',2) obj.setEditorMode('Angle',1)
obj.setEditorMode('Support',2) if hasattr(obj,"Normal"):
obj.setEditorMode('Normal',2)
if hasattr(obj,"Support"):
obj.setEditorMode('Support',2)
def execute(self, fp): def execute(self, fp):
if fp.ViewObject: if fp.ViewObject:

View File

@ -3271,6 +3271,11 @@ class Edit(Modifier):
self.editpoints.append(self.obj.End) self.editpoints.append(self.obj.End)
self.editpoints.append(self.obj.Dimline) self.editpoints.append(self.obj.Dimline)
self.editpoints.append(Vector(p[0],p[1],p[2])) self.editpoints.append(Vector(p[0],p[1],p[2]))
elif Draft.getType(self.obj) == "Space":
try:
self.editpoints.append(self.obj.ViewObject.Proxy.getTextPosition(self.obj.ViewObject))
except:
pass
if Draft.getType(self.obj) != "BezCurve": if Draft.getType(self.obj) != "BezCurve":
self.trackers = [] self.trackers = []
if self.editpoints: if self.editpoints:
@ -3481,6 +3486,9 @@ class Edit(Modifier):
self.obj.Dimline = v self.obj.Dimline = v
elif self.editing == 3: elif self.editing == 3:
self.obj.ViewObject.TextPosition = v self.obj.ViewObject.TextPosition = v
elif Draft.getType(self.obj) == "Space":
if self.editing == 0:
self.obj.ViewObject.TextPosition = v
def numericInput(self,v,numy=None,numz=None): def numericInput(self,v,numy=None,numz=None):
'''this function gets called by the toolbar '''this function gets called by the toolbar

View File

@ -119,7 +119,7 @@ class DraftWorkbench (Workbench):
"Draft_ShowSnapBar","Draft_ToggleGrid"] "Draft_ShowSnapBar","Draft_ToggleGrid"]
self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"] self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"]
self.utils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension", self.utils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension",
"Draft_ToggleConstructionMode","Draft_ToggleContinueMode"] "Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit"]
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular', self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel', 'Draft_Snap_Grid','Draft_Snap_Intersection','Draft_Snap_Parallel',
'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center', 'Draft_Snap_Endpoint','Draft_Snap_Angle','Draft_Snap_Center',