Arch: Axis can now be referenced in sketches

This commit is contained in:
Yorik van Havre
2019-01-18 17:40:50 -02:00
parent ae95f77f5a
commit a60b6957db

View File

@@ -57,7 +57,7 @@ def makeAxis(num=5,size=1000,name="Axes"):
if not FreeCAD.ActiveDocument:
FreeCAD.Console.PrintError("No active document. Aborting\n")
return
obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","Axis")
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Axis")
obj.Label = translate("Arch",name)
_Axis(obj)
if FreeCAD.GuiUp:
@@ -225,6 +225,7 @@ class _Axis:
def execute(self,obj):
pl = obj.Placement
import Part
geoms = []
dist = 0
@@ -242,13 +243,13 @@ class _Axis:
geoms.append(Part.LineSegment(p1,p2).toShape())
if geoms:
sh = Part.Compound(geoms)
sh.Placement = obj.Placement
obj.Shape = sh
obj.Placement = pl
def onChanged(self,obj,prop):
#def onChanged(self,obj,prop):
if prop in ["Angles","Distances","Placement"]:
self.execute(obj)
# if prop in ["Angles","Distances","Placement"]:
# self.execute(obj)
def __getstate__(self):
@@ -306,7 +307,7 @@ class _ViewProviderAxis:
if not "DrawStyle" in pl:
vobj.addProperty("App::PropertyEnumeration","DrawStyle","Axis",QT_TRANSLATE_NOOP("App::Property","The type of line to draw this axis"))
vobj.DrawStyle = ["Solid","Dashed","Dotted","Dashdot"]
vobj.DrawStyle = "Dashdot"
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"]
@@ -315,7 +316,7 @@ class _ViewProviderAxis:
vobj.LineWidth = 1
if not "LineColor" in pl:
vobj.addProperty("App::PropertyColor","LineColor","Axis",QT_TRANSLATE_NOOP("App::Property","The color of this axis"))
vobj.LineColor = ArchCommands.getDefaultColor("Helpers")
vobj.LineColor = ArchCommands.getDefaultColor("Helpers")
if not "StartNumber" in pl:
vobj.addProperty("App::PropertyInteger","StartNumber","Axis",QT_TRANSLATE_NOOP("App::Property","The number of the first axis"))
vobj.StartNumber = 1
@@ -389,7 +390,7 @@ class _ViewProviderAxis:
i = 0
for e in obj.Shape.Edges:
for v in e.Vertexes:
verts.append([v.X,v.Y,v.Z])
verts.append(tuple(obj.Placement.inverse().multVec(v.Point)))
vset.append(i)
i += 1
vset.append(-1)
@@ -441,13 +442,13 @@ class _ViewProviderAxis:
pos = [vobj.BubblePosition]
for i in range(len(vobj.Object.Shape.Edges)):
for p in pos:
verts = vobj.Object.Shape.Edges[i].Vertexes
verts = [vobj.Object.Placement.inverse().multVec(v.Point) for v in vobj.Object.Shape.Edges[i].Vertexes]
if p == "Start":
p1 = verts[0].Point
p2 = verts[1].Point
p1 = verts[0]
p2 = verts[1]
else:
p1 = verts[1].Point
p2 = verts[0].Point
p1 = verts[1]
p2 = verts[0]
dv = p2.sub(p1)
dv.normalize()
if hasattr(vobj.BubbleSize,"Value"):