Arch: Fixed axis object - fixes #1605
This commit is contained in:
parent
4de77a921a
commit
9671d9658b
|
@ -82,11 +82,11 @@ class _Axis:
|
||||||
def __init__(self,obj):
|
def __init__(self,obj):
|
||||||
obj.addProperty("App::PropertyFloatList","Distances","Arch", translate("Arch","The intervals between axes"))
|
obj.addProperty("App::PropertyFloatList","Distances","Arch", translate("Arch","The intervals between axes"))
|
||||||
obj.addProperty("App::PropertyFloatList","Angles","Arch", translate("Arch","The angles of each axis"))
|
obj.addProperty("App::PropertyFloatList","Angles","Arch", translate("Arch","The angles of each axis"))
|
||||||
obj.addProperty("App::PropertyFloat","Length","Arch", translate("Arch","The length of the axes"))
|
obj.addProperty("App::PropertyLength","Length","Arch", translate("Arch","The length of the axes"))
|
||||||
obj.addProperty("App::PropertyPlacement","Placement","Base","")
|
obj.addProperty("App::PropertyPlacement","Placement","Base","")
|
||||||
obj.addProperty("Part::PropertyPartShape","Shape","Base","")
|
obj.addProperty("Part::PropertyPartShape","Shape","Base","")
|
||||||
self.Type = "Axis"
|
self.Type = "Axis"
|
||||||
obj.Length=1.0
|
obj.Length=3000
|
||||||
obj.Proxy = self
|
obj.Proxy = self
|
||||||
|
|
||||||
def execute(self,obj):
|
def execute(self,obj):
|
||||||
|
@ -96,10 +96,14 @@ class _Axis:
|
||||||
if obj.Distances:
|
if obj.Distances:
|
||||||
if len(obj.Distances) == len(obj.Angles):
|
if len(obj.Distances) == len(obj.Angles):
|
||||||
for i in range(len(obj.Distances)):
|
for i in range(len(obj.Distances)):
|
||||||
|
if hasattr(obj.Length,"Value"):
|
||||||
|
l = obj.Length.Value
|
||||||
|
else:
|
||||||
|
l = obj.Length
|
||||||
dist += obj.Distances[i]
|
dist += obj.Distances[i]
|
||||||
ang = math.radians(obj.Angles[i])
|
ang = math.radians(obj.Angles[i])
|
||||||
p1 = Vector(dist,0,0)
|
p1 = Vector(dist,0,0)
|
||||||
p2 = Vector(dist+(obj.Length/math.cos(ang))*math.sin(ang),obj.Length,0)
|
p2 = Vector(dist+(l/math.cos(ang))*math.sin(ang),l,0)
|
||||||
geoms.append(Part.Line(p1,p2).toShape())
|
geoms.append(Part.Line(p1,p2).toShape())
|
||||||
if geoms:
|
if geoms:
|
||||||
sh = Part.Compound(geoms)
|
sh = Part.Compound(geoms)
|
||||||
|
@ -121,7 +125,7 @@ class _ViewProviderAxis:
|
||||||
"A View Provider for the Axis object"
|
"A View Provider for the Axis object"
|
||||||
|
|
||||||
def __init__(self,vobj):
|
def __init__(self,vobj):
|
||||||
vobj.addProperty("App::PropertyFloat","BubbleSize","Arch", translate("Arch","The size of the axis bubbles"))
|
vobj.addProperty("App::PropertyLength","BubbleSize","Arch", translate("Arch","The size of the axis bubbles"))
|
||||||
vobj.addProperty("App::PropertyEnumeration","NumberingStyle","Arch", translate("Arch","The numbering style"))
|
vobj.addProperty("App::PropertyEnumeration","NumberingStyle","Arch", translate("Arch","The numbering style"))
|
||||||
vobj.addProperty("App::PropertyEnumeration","DrawStyle","Base","")
|
vobj.addProperty("App::PropertyEnumeration","DrawStyle","Base","")
|
||||||
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
|
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
|
||||||
|
@ -129,7 +133,7 @@ class _ViewProviderAxis:
|
||||||
vobj.NumberingStyle = ["1,2,3","01,02,03","001,002,003","A,B,C","a,b,c","I,II,III","L0,L1,L2"]
|
vobj.NumberingStyle = ["1,2,3","01,02,03","001,002,003","A,B,C","a,b,c","I,II,III","L0,L1,L2"]
|
||||||
vobj.DrawStyle = ["Solid","Dashed","Dotted","Dashdot"]
|
vobj.DrawStyle = ["Solid","Dashed","Dotted","Dashdot"]
|
||||||
vobj.Proxy = self
|
vobj.Proxy = self
|
||||||
vobj.BubbleSize = .1
|
vobj.BubbleSize = 500
|
||||||
vobj.LineWidth = 1
|
vobj.LineWidth = 1
|
||||||
vobj.LineColor = (0.13,0.15,0.37)
|
vobj.LineColor = (0.13,0.15,0.37)
|
||||||
vobj.DrawStyle = "Dashdot"
|
vobj.DrawStyle = "Dashdot"
|
||||||
|
@ -220,7 +224,10 @@ class _ViewProviderAxis:
|
||||||
p2 = verts[1].Point
|
p2 = verts[1].Point
|
||||||
dv = p2.sub(p1)
|
dv = p2.sub(p1)
|
||||||
dv.normalize()
|
dv.normalize()
|
||||||
rad = vobj.BubbleSize
|
if hasattr(vobj.BubbleSize,"Value"):
|
||||||
|
rad = vobj.BubbleSize.Value/2
|
||||||
|
else:
|
||||||
|
rad = vobj.BubbleSize/2
|
||||||
center = p2.add(dv.scale(rad,rad,rad))
|
center = p2.add(dv.scale(rad,rad,rad))
|
||||||
buf = Part.makeCircle(rad,center).writeInventor()
|
buf = Part.makeCircle(rad,center).writeInventor()
|
||||||
try:
|
try:
|
||||||
|
@ -248,11 +255,11 @@ class _ViewProviderAxis:
|
||||||
self.bubbles.addChild(line)
|
self.bubbles.addChild(line)
|
||||||
st = coin.SoSeparator()
|
st = coin.SoSeparator()
|
||||||
tr = coin.SoTransform()
|
tr = coin.SoTransform()
|
||||||
tr.translation.setValue((center.x,center.y-rad/4,center.z))
|
tr.translation.setValue((center.x,center.y-rad/2,center.z))
|
||||||
fo = coin.SoFont()
|
fo = coin.SoFont()
|
||||||
fo.name = Draft.getParam("textfont","Arial,Sans")
|
fo.name = Draft.getParam("textfont","Arial,Sans")
|
||||||
fo.size = rad*100
|
fo.size = rad*1.5
|
||||||
tx = coin.SoText2()
|
tx = coin.SoAsciiText()
|
||||||
tx.justification = coin.SoText2.CENTER
|
tx.justification = coin.SoText2.CENTER
|
||||||
self.bubbletexts.append(tx)
|
self.bubbletexts.append(tx)
|
||||||
st.addChild(tr)
|
st.addChild(tr)
|
||||||
|
@ -332,6 +339,8 @@ class _AxisTaskPanel:
|
||||||
# for the subcomponents, such as additions, subtractions.
|
# for the subcomponents, such as additions, subtractions.
|
||||||
# the categories are shown only if they are not empty.
|
# the categories are shown only if they are not empty.
|
||||||
|
|
||||||
|
self.updating = False
|
||||||
|
|
||||||
self.obj = None
|
self.obj = None
|
||||||
self.form = QtGui.QWidget()
|
self.form = QtGui.QWidget()
|
||||||
self.form.setObjectName("TaskPanel")
|
self.form.setObjectName("TaskPanel")
|
||||||
|
@ -363,6 +372,7 @@ class _AxisTaskPanel:
|
||||||
|
|
||||||
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
|
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
|
||||||
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
|
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
|
||||||
|
QtCore.QObject.connect(self.tree, QtCore.SIGNAL("itemChanged(QTreeWidgetItem *, int)"), self.edit)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
|
@ -376,6 +386,7 @@ class _AxisTaskPanel:
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
'fills the treewidget'
|
'fills the treewidget'
|
||||||
|
self.updating = True
|
||||||
self.tree.clear()
|
self.tree.clear()
|
||||||
if self.obj:
|
if self.obj:
|
||||||
for i in range(len(self.obj.Distances)):
|
for i in range(len(self.obj.Distances)):
|
||||||
|
@ -386,6 +397,7 @@ class _AxisTaskPanel:
|
||||||
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
|
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
|
||||||
item.setTextAlignment(0,QtCore.Qt.AlignLeft)
|
item.setTextAlignment(0,QtCore.Qt.AlignLeft)
|
||||||
self.retranslateUi(self.form)
|
self.retranslateUi(self.form)
|
||||||
|
self.updating = False
|
||||||
|
|
||||||
def addElement(self):
|
def addElement(self):
|
||||||
item = QtGui.QTreeWidgetItem(self.tree)
|
item = QtGui.QTreeWidgetItem(self.tree)
|
||||||
|
@ -401,8 +413,13 @@ class _AxisTaskPanel:
|
||||||
nr = int(it.text(0))-1
|
nr = int(it.text(0))-1
|
||||||
self.resetObject(remove=nr)
|
self.resetObject(remove=nr)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def edit(self,item,column):
|
||||||
|
if not self.updating:
|
||||||
|
self.resetObject()
|
||||||
|
|
||||||
def resetObject(self,remove=None):
|
def resetObject(self,remove=None):
|
||||||
|
"transfers the values from the widget to the object"
|
||||||
d = []
|
d = []
|
||||||
a = []
|
a = []
|
||||||
for i in range(self.tree.topLevelItemCount()):
|
for i in range(self.tree.topLevelItemCount()):
|
||||||
|
|
|
@ -321,25 +321,31 @@ def makeStructure(baseobj=None,length=None,width=None,height=None,name=translate
|
||||||
obj.Role = "Column"
|
obj.Role = "Column"
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def makeStructuralSystem(objects,axes,name=translate("Arch","StructuralSystem")):
|
def makeStructuralSystem(objects=[],axes=[],name=translate("Arch","StructuralSystem")):
|
||||||
'''makeStructuralSystem(objects,axes): makes a structural system
|
'''makeStructuralSystem(objects,axes): makes a structural system
|
||||||
based on the given objects and axes'''
|
based on the given objects and axes'''
|
||||||
result = []
|
result = []
|
||||||
if objects and axes:
|
if not axes:
|
||||||
|
print "At least one axis must be given"
|
||||||
|
return
|
||||||
|
if objects:
|
||||||
if not isinstance(objects,list):
|
if not isinstance(objects,list):
|
||||||
objects = [objects]
|
objects = [objects]
|
||||||
for o in objects:
|
else:
|
||||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
objects = [None]
|
||||||
_StructuralSystem(obj)
|
for o in objects:
|
||||||
if FreeCAD.GuiUp:
|
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||||
_ViewProviderStructuralSystem(obj.ViewObject)
|
_StructuralSystem(obj)
|
||||||
|
if FreeCAD.GuiUp:
|
||||||
|
_ViewProviderStructuralSystem(obj.ViewObject)
|
||||||
|
if o:
|
||||||
obj.Base = o
|
obj.Base = o
|
||||||
obj.Axes = axes
|
obj.Axes = axes
|
||||||
result.append(obj)
|
result.append(obj)
|
||||||
if FreeCAD.GuiUp:
|
if FreeCAD.GuiUp and o:
|
||||||
o.ViewObject.hide()
|
o.ViewObject.hide()
|
||||||
Draft.formatObject(obj,o)
|
Draft.formatObject(obj,o)
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
return result[0]
|
return result[0]
|
||||||
else:
|
else:
|
||||||
|
@ -386,10 +392,13 @@ class _CommandStructure:
|
||||||
if sel:
|
if sel:
|
||||||
st = Draft.getObjectsOfType(sel,"Structure")
|
st = Draft.getObjectsOfType(sel,"Structure")
|
||||||
ax = Draft.getObjectsOfType(sel,"Axis")
|
ax = Draft.getObjectsOfType(sel,"Axis")
|
||||||
if st and ax:
|
if ax:
|
||||||
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structural System")))
|
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Structural System")))
|
||||||
FreeCADGui.addModule("Arch")
|
FreeCADGui.addModule("Arch")
|
||||||
FreeCADGui.doCommand("Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + "," + ArchCommands.getStringList(ax) + ")")
|
if st:
|
||||||
|
FreeCADGui.doCommand("Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + "," + ArchCommands.getStringList(ax) + ")")
|
||||||
|
else:
|
||||||
|
FreeCADGui.doCommand("Arch.makeStructuralSystem(axes=" + ArchCommands.getStringList(ax) + ")")
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user