Skip to content

Commit

Permalink
Arch: Fixed display of axis bubbles and texts on DXF export and Techd…
Browse files Browse the repository at this point in the history
…raw pages
  • Loading branch information
yorikvanhavre committed Dec 16, 2021
1 parent b1beadd commit 568dbce
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 94 deletions.
30 changes: 26 additions & 4 deletions src/Mod/Arch/ArchAxis.py
Expand Up @@ -361,6 +361,7 @@ def attach(self, vobj):

self.bubbles = None
self.bubbletexts = []
self.bubbledata = []
sep = coin.SoSeparator()
self.mat = coin.SoMaterial()
self.linestyle = coin.SoDrawStyle()
Expand Down Expand Up @@ -445,6 +446,7 @@ def onChanged(self, vobj, prop):
self.bubbles.addChild(self.bubblestyle)
import Part,Draft
self.bubbletexts = []
self.bubbledata = []
pos = ["Start"]
if hasattr(vobj,"BubblePosition"):
if vobj.BubblePosition in ["Both","Arrow left","Arrow right","Bar left","Bar right"]:
Expand Down Expand Up @@ -501,6 +503,9 @@ def onChanged(self, vobj, prop):
coords.point.setValues(0,len(pts),pts)
line = coin.SoFaceSet()
line.numVertices.setValue(-1)
cir = Part.makePolygon(pts)
cir.Placement = vobj.Object.Placement
self.bubbledata.append(cir)
elif arrow == False:
p3 = p2.add(Vector(chord).multiply(rad/2))
if vobj.BubblePosition.startswith("Arrow"):
Expand All @@ -518,8 +523,12 @@ def onChanged(self, vobj, prop):
coords.point.setValues(0,len(pts),pts)
line = coin.SoFaceSet()
line.numVertices.setValue(-1)
cir = Part.makePolygon(pts)
cir.Placement = vobj.Object.Placement
self.bubbledata.append(cir)
else:
buf = Part.makeCircle(rad,center).writeInventor()
cir = Part.makeCircle(rad,center)
buf = cir.writeInventor()
try:
cin = coin.SoInput()
cin.setBuffer(buf)
Expand All @@ -541,14 +550,17 @@ def onChanged(self, vobj, prop):
else:
coords = cob.getChild(1).getChild(0).getChild(2)
line = cob.getChild(1).getChild(0).getChild(3)
cir.Placement = vobj.Object.Placement
self.bubbledata.append(cir)
self.bubbles.addChild(coords)
self.bubbles.addChild(line)
st = coin.SoSeparator()
tr = coin.SoTransform()
fs = rad*1.5
if hasattr(vobj,"FontSize"):
fs = vobj.FontSize.Value
tr.translation.setValue((center.x,center.y-fs/2.5,center.z))
txpos = FreeCAD.Vector(center.x,center.y-fs/2.5,center.z)
tr.translation.setValue(tuple(txpos))
fo = coin.SoFont()
fn = Draft.getParam("textfont","Arial,Sans")
if hasattr(vobj,"FontName"):
Expand All @@ -561,7 +573,7 @@ def onChanged(self, vobj, prop):
fo.size = fs
tx = coin.SoAsciiText()
tx.justification = coin.SoText2.CENTER
self.bubbletexts.append(tx)
self.bubbletexts.append((tx,vobj.Object.Placement.multVec(center)))
st.addChild(tr)
st.addChild(fo)
st.addChild(tx)
Expand All @@ -578,7 +590,7 @@ def onChanged(self, vobj, prop):
num = vobj.StartNumber-1
alt = False
for t in self.bubbletexts:
t.string = self.getNumber(vobj,num)
t[0].string = self.getNumber(vobj,num)
num += 1
if hasattr(vobj,"BubblePosition"):
if vobj.BubblePosition in ["Both","Arrow left","Arrow right","Bar left","Bar right"]:
Expand Down Expand Up @@ -685,6 +697,14 @@ def getNumber(self,vobj,num):
else:
return str(num+1)

def getTextData(self):

return [(t[0].string.getValues()[0],t[1]) for t in self.bubbletexts]

def getShapeData(self):

return self.bubbledata

def setEdit(self,vobj,mode=0):

taskd = _AxisTaskPanel()
Expand All @@ -711,6 +731,8 @@ def __setstate__(self,state):
return None




class _AxisTaskPanel:

'''The editmode TaskPanel for Axis objects'''
Expand Down
57 changes: 17 additions & 40 deletions src/Mod/Draft/draftfunctions/svg.py
Expand Up @@ -684,55 +684,32 @@ def get_svg(obj,

if App.GuiUp:
vobj = obj.ViewObject
lorig = lstyle
fn = obj.ViewObject.FontName
fill = 'none'
rad = vobj.BubbleSize.Value/2
n = 0
for e in obj.Shape.Edges:
lstyle = lorig
svg += get_path(obj, plane,
fill, pathdata, stroke, linewidth, lstyle,
fill_opacity=None,
edges=[e])
lstyle = "none"
pos = ["Start"]
if hasattr(vobj, "BubblePosition"):
if vobj.BubblePosition == "Both":
pos = ["Start", "End"]
else:
pos = [vobj.BubblePosition]
for p in pos:
if p == "Start":
p1 = e.Vertexes[0].Point
p2 = e.Vertexes[1].Point
else:
p1 = e.Vertexes[1].Point
p2 = e.Vertexes[0].Point
dv = p2.sub(p1)
dv.normalize()
center = p2.add(dv.scale(rad, rad, rad))
for t in obj.ViewObject.Proxy.getTextData():
pos = t[1].add(App.Vector(0,-fontsize/2,0))
svg += svgtext.get_text(plane, techdraw,
tstroke, fontsize, fn,
0.0, pos, t[0],
1.0, "center")
for b in obj.ViewObject.Proxy.getShapeData():
if hasattr(b,"Curve") and isinstance(b.Curve,Part.Circle):
svg += get_circle(plane,
fill, stroke, linewidth, lstyle,
Part.makeCircle(rad, center))
if (hasattr(vobj.Proxy, "bubbletexts")
and len(vobj.Proxy.bubbletexts) >= n):
bubb = vobj.Proxy.bubbletexts
svg += '<text '
svg += 'fill="{}" '.format(stroke)
svg += 'font-size="{}" '.format(rad)
svg += 'style="text-anchor:middle;'
svg += 'text-align:center;'
svg += 'font-family: sans;" '
svg += 'transform="'
svg += 'translate({},{}) '.format(center.x + rad/4.0,
center.y - rad/3.0)
svg += 'scale(1,-1)"> '
svg += '<tspan>'
svg += bubb[n].string.getValues()[0]
svg += '</tspan>\n'
svg += '</text>\n'
n += 1
lstyle = lorig
fill, stroke, linewidth, "none",
b)
else:
sfill = stroke
svg += get_path(obj, plane,
sfill, pathdata, stroke, linewidth, "none",
fill_opacity=None,
edges=b.Edges)

elif utils.get_type(obj) == "Pipe":
fill = stroke
Expand Down
87 changes: 37 additions & 50 deletions src/Mod/Draft/importDXF.py
Expand Up @@ -806,7 +806,7 @@ def placementFromDXFOCS(ent):
# http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-7941.htm
# Arbitrary Axis Algorithm
# http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-793d.htm#WSc30cd3d5faa8f6d81cb25f1ffb755717d-7ff5
# Riferimenti dell'algoritmo dell'asse arbitrario in italiano
# Riferimenti dell'algoritmo dell'asse arbitrario in italiano
# http://docs.autodesk.com/ACD/2011/ITA/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-7941.htm
# http://docs.autodesk.com/ACD/2011/ITA/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-793d.htm#WSc30cd3d5faa8f6d81cb25f1ffb755717d-7ff5
if (draftWPlane.axis == FreeCAD.Vector(1.0, 0.0, 0.0)):
Expand All @@ -825,7 +825,7 @@ def placementFromDXFOCS(ent):
draftWPlane.v.normalize()
draftWPlane.position = Vector(0.0, 0.0, 0.0)
draftWPlane.weak = False

pl = FreeCAD.Placement()
pl = draftWPlane.getPlacement()
if ((ent.type == "lwpolyline") or (ent.type == "polyline")):
Expand Down Expand Up @@ -3666,7 +3666,7 @@ def export(objectslist, filename, nospline=False, lwPoly=False):
# other cases, treat objects one by one
dxf = dxfLibrary.Drawing()
# add global variables
if hasattr(dxf,"header"):
if hasattr(dxf,"header"):
dxf.header.append(" 9\n$DIMTXT\n 40\n"+str(Draft.getParam("textheight", 20))+"\n")
for ob in exportLayers:
if ob.Label != "0": # dxflibrary already creates it
Expand Down Expand Up @@ -3732,7 +3732,7 @@ def export(objectslist, filename, nospline=False, lwPoly=False):
p2 = obj.Placement.multVec(App.Vector(_v))
_h = vobj.Proxy.header.translation.getValue().getValue()
lspc = FreeCAD.Vector(_h)
p1 = p2 + lspc
p1 = p2 + lspc
dxf.append(dxfLibrary.Text(t1, p1, height=f1,
color=getACI(ob, text=True),
style='STANDARD',
Expand All @@ -3752,56 +3752,43 @@ def export(objectslist, filename, nospline=False, lwPoly=False):
if not axes:
continue
for ax in axes:
dxf.append(dxfLibrary.Line([tuple(ax[0]),
tuple(ax[1])],
color=getACI(ob),
layer=getStrGroup(ob)))
p = ax[1]
h = 1
if FreeCAD.GuiUp:
vobj = ob.ViewObject
rad = vobj.BubbleSize.Value/2
n = 0
pos = ["Start"]
if hasattr(vobj, "BubblePosition"):
if vobj.BubblePosition == "Both":
pos = ["Start", "End"]
else:
pos = [vobj.BubblePosition]
for p in pos:
if p == "Start":
p1 = ax[0]
p2 = ax[1]
else:
p1 = ax[1]
p2 = ax[0]
dv = p2.sub(p1)
dv.normalize()
center = p2.add(dv.scale(rad, rad, rad))
h = float(ob.ViewObject.FontSize)
dxf.append(dxfLibrary.Circle(center,
rad,
color=getACI(ob),
layer=getStrGroup(ob)))
dxf.append(dxfLibrary.Text(ax[2],
center,
alignment=center,
height=h,
justifyhor=1,
justifyver=2,
color=getACI(ob),
style='STANDARD',
layer=getStrGroup(ob)))
else:
dxf.append(dxfLibrary.Text(ax[2],
p,
alignment=p,
dxf.append(dxfLibrary.Line([ax[0],
ax[1]],
color=getACI(ob),
layer=getStrGroup(ob)))
h = 1
if FreeCAD.GuiUp:
vobj = ob.ViewObject
h = float(ob.ViewObject.FontSize)
for text in vobj.Proxy.getTextData():
pos = text[1].add(FreeCAD.Vector(-h/2,-h/2,0))
dxf.append(dxfLibrary.Text(text[0],
pos,
height=h,
justifyhor=1,
justifyver=2,
color=getACI(ob),
style='STANDARD',
layer=getStrGroup(ob)))
for shape in vobj.Proxy.getShapeData():
if hasattr(shape,"Curve") and isinstance(shape.Curve,Part.Circle):
dxf.append(dxfLibrary.Circle(shape.Curve.Center,
shape.Curve.Radius,
color=getACI(ob),
layer=getStrGroup(ob)))
else:
if lwPoly:
points = [(v.Point.x, v.Point.y, v.Point.z, None, None, 0.0) for v in shape.Vertexes]
dxf.append(dxfLibrary.LwPolyLine(points,
[0.0, 0.0],
1,
color=getACI(ob),
layer=getGroup(ob)))
else:
points = [((v.Point.x, v.Point.y, v.Point.z), None, [None, None], 0.0) for v in shape.Vertexes]
dxf.append(dxfLibrary.PolyLine(points,
[0.0, 0.0, 0.0],
1,
color=getACI(ob),
layer=getGroup(ob)))

elif ob.isDerivedFrom("Part::Feature"):
tess = None
Expand Down

0 comments on commit 568dbce

Please sign in to comment.