Arch: Added arrow and bar bubble modes to Arch Axis object

This commit is contained in:
Yorik van Havre
2021-05-31 14:14:46 +02:00
parent 9800f22292
commit 74a46e6b95

View File

@@ -217,6 +217,9 @@ class _Axis:
obj.addProperty("App::PropertyPlacement","Placement","Base","")
if not "Shape" in pl:
obj.addProperty("Part::PropertyPartShape","Shape","Base","")
if not "Limit" in pl:
obj.addProperty("App::PropertyLength","Limit","Axis", QT_TRANSLATE_NOOP("App::Property","If not zero, the axes are not represented as one full line but as two lines of the given length"))
obj.Limit=0
self.Type = "Axis"
def onDocumentRestored(self,obj):
@@ -229,7 +232,7 @@ class _Axis:
import Part
geoms = []
dist = 0
if obj.Distances:
if obj.Distances and obj.Length.Value:
if len(obj.Distances) == len(obj.Angles):
for i in range(len(obj.Distances)):
if hasattr(obj.Length,"Value"):
@@ -240,7 +243,17 @@ class _Axis:
ang = math.radians(obj.Angles[i])
p1 = Vector(dist,0,0)
p2 = Vector(dist+(l/math.cos(ang))*math.sin(ang),l,0)
geoms.append(Part.LineSegment(p1,p2).toShape())
if hasattr(obj,"Limit") and obj.Limit.Value:
p3 = p2.sub(p1)
p3.normalize()
p3.multiply(-obj.Limit.Value)
p4 = p1.sub(p2)
p4.normalize()
p4.multiply(-obj.Limit.Value)
geoms.append(Part.LineSegment(p1,p1.add(p4)).toShape())
geoms.append(Part.LineSegment(p2,p2.add(p3)).toShape())
else:
geoms.append(Part.LineSegment(p1,p2).toShape())
if geoms:
sh = Part.Compound(geoms)
obj.Shape = sh
@@ -310,7 +323,7 @@ class _ViewProviderAxis:
vobj.DrawStyle = "Dashdot"
if not "BubblePosition" in pl:
vobj.addProperty("App::PropertyEnumeration","BubblePosition","Axis",QT_TRANSLATE_NOOP("App::Property","Where to add bubbles to this axis: Start, end, both or none"))
vobj.BubblePosition = ["Start","End","Both","None"]
vobj.BubblePosition = ["Start","End","Both","None","Arrow left","Arrow right","Bar left","Bar right"]
if not "LineWidth" in pl:
vobj.addProperty("App::PropertyFloat","LineWidth","Axis",QT_TRANSLATE_NOOP("App::Property","The line width to draw this axis"))
vobj.LineWidth = 1
@@ -434,50 +447,100 @@ class _ViewProviderAxis:
self.bubbletexts = []
pos = ["Start"]
if hasattr(vobj,"BubblePosition"):
if vobj.BubblePosition == "Both":
if vobj.BubblePosition in ["Both","Arrow left","Arrow right","Bar left","Bar right"]:
pos = ["Start","End"]
elif vobj.BubblePosition == "None":
pos = []
else:
pos = [vobj.BubblePosition]
for i in range(len(vobj.Object.Shape.Edges)):
for i in range(len(vobj.Object.Distances)):
for p in pos:
verts = [vobj.Object.Placement.inverse().multVec(v.Point) for v in vobj.Object.Shape.Edges[i].Vertexes]
if hasattr(vobj.Object,"Limit") and vobj.Object.Limit.Value:
verts = [vobj.Object.Placement.inverse().multVec(vobj.Object.Shape.Edges[i].Vertexes[0].Point),
vobj.Object.Placement.inverse().multVec(vobj.Object.Shape.Edges[i+1].Vertexes[0].Point)]
else:
verts = [vobj.Object.Placement.inverse().multVec(v.Point) for v in vobj.Object.Shape.Edges[i].Vertexes]
arrow = None
if p == "Start":
p1 = verts[0]
p2 = verts[1]
if vobj.BubblePosition.endswith("left"):
arrow = True
elif vobj.BubblePosition.endswith("right"):
arrow = False
else:
p1 = verts[1]
p2 = verts[0]
if vobj.BubblePosition.endswith("left"):
arrow = False
elif vobj.BubblePosition.endswith("right"):
arrow = True
dv = p2.sub(p1)
dv.normalize()
if hasattr(vobj.BubbleSize,"Value"):
rad = vobj.BubbleSize.Value/2
else:
rad = vobj.BubbleSize/2
center = p2.add(dv.scale(rad,rad,rad))
buf = Part.makeCircle(rad,center).writeInventor()
try:
cin = coin.SoInput()
cin.setBuffer(buf)
cob = coin.SoDB.readAll(cin)
except Exception:
import re
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n","")
pts = re.findall("point \[(.*?)\]",buf)[0]
pts = pts.split(",")
pc = []
for p in pts:
v = p.strip().split()
pc.append([float(v[0]),float(v[1]),float(v[2])])
center = p2.add(Vector(dv).multiply(rad))
normal = vobj.Object.Placement.Rotation.multVec(Vector(0,0,1))
chord = dv.cross(normal)
if arrow == True:
p3 = p2.add(Vector(chord).multiply(rad/2).negative())
if vobj.BubblePosition.startswith("Arrow"):
p4 = p3.add(Vector(dv).multiply(rad*2).negative())
p5 = p2.add(Vector(dv).multiply(rad).negative()).add(Vector(chord).multiply(rad*1.5).negative())
pts = [tuple(p3),tuple(p5),tuple(p4),tuple(p3)]
center = p5.add(Vector(chord).multiply(rad*2.5))
else:
p4 = p3.add(Vector(dv).multiply(rad/2).negative())
p5 = p4.add(Vector(chord).multiply(rad*1.5).negative())
p6 = p5.add(Vector(dv).multiply(rad/2))
pts = [tuple(p3),tuple(p6),tuple(p5),tuple(p4),tuple(p3)]
center = p5.add(Vector(chord).multiply(rad*3))
coords = coin.SoCoordinate3()
coords.point.setValues(0,len(pc),pc)
line = coin.SoLineSet()
coords.point.setValues(0,len(pts),pts)
line = coin.SoFaceSet()
line.numVertices.setValue(-1)
elif arrow == False:
p3 = p2.add(Vector(chord).multiply(rad/2))
if vobj.BubblePosition.startswith("Arrow"):
p4 = p3.add(Vector(dv).multiply(rad*2).negative())
p5 = p2.add(Vector(dv).multiply(rad).negative()).add(Vector(chord).multiply(rad*1.5))
pts = [tuple(p3),tuple(p4),tuple(p5),tuple(p3)]
center = p5.add(Vector(chord).multiply(rad*2.5).negative())
else:
p4 = p3.add(Vector(dv).multiply(rad/2).negative())
p5 = p4.add(Vector(chord).multiply(rad*1.5))
p6 = p5.add(Vector(dv).multiply(rad/2))
pts = [tuple(p3),tuple(p4),tuple(p5),tuple(p6),tuple(p3)]
center = p5.add(Vector(chord).multiply(rad*3).negative())
coords = coin.SoCoordinate3()
coords.point.setValues(0,len(pts),pts)
line = coin.SoFaceSet()
line.numVertices.setValue(-1)
else:
coords = cob.getChild(1).getChild(0).getChild(2)
line = cob.getChild(1).getChild(0).getChild(3)
buf = Part.makeCircle(rad,center).writeInventor()
try:
cin = coin.SoInput()
cin.setBuffer(buf)
cob = coin.SoDB.readAll(cin)
except Exception:
import re
# workaround for pivy SoInput.setBuffer() bug
buf = buf.replace("\n","")
pts = re.findall("point \[(.*?)\]",buf)[0]
pts = pts.split(",")
pc = []
for p in pts:
v = p.strip().split()
pc.append([float(v[0]),float(v[1]),float(v[2])])
coords = coin.SoCoordinate3()
coords.point.setValues(0,len(pc),pc)
line = coin.SoLineSet()
line.numVertices.setValue(-1)
else:
coords = cob.getChild(1).getChild(0).getChild(2)
line = cob.getChild(1).getChild(0).getChild(3)
self.bubbles.addChild(coords)
self.bubbles.addChild(line)
st = coin.SoSeparator()