fixed issues and turned all json stuff lowercase
This commit is contained in:
parent
ef7790d76a
commit
1d3d46e0f8
2 changed files with 77 additions and 74 deletions
12
ARFrames.py
12
ARFrames.py
|
@ -43,8 +43,8 @@ class Frame(object):
|
||||||
|
|
||||||
def getDict(self):
|
def getDict(self):
|
||||||
d = {}
|
d = {}
|
||||||
d["Label"] = self.obj.Label
|
d["label"] = str(self.obj.Label)
|
||||||
d["Placement"] = self.obj.Placement
|
d["placement"] = ARTools.placement2axisvec(self.obj.Placement)
|
||||||
d.update(self.additional_data)
|
d.update(self.additional_data)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class PartFrame(Frame):
|
||||||
|
|
||||||
def getDict(self):
|
def getDict(self):
|
||||||
d = Frame.getDict(self)
|
d = Frame.getDict(self)
|
||||||
d["Part"] = self.obj.Part
|
d["part"] = str(self.obj.Part.Label)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,9 +95,9 @@ class FeatureFrame(PartFrame):
|
||||||
|
|
||||||
def getDict(self):
|
def getDict(self):
|
||||||
d = PartFrame.getDict(self)
|
d = PartFrame.getDict(self)
|
||||||
d["FeaturePlacement"] = ARTools.placement2axisvec(self.obj.FeaturePlacement)
|
d["featureplacement"] = ARTools.placement2axisvec(self.obj.FeaturePlacement)
|
||||||
d["ShapeType"] = ARTools.placement2axisvec(self.obj.ShapeType)
|
d["shapetype"] = str(self.obj.ShapeType)
|
||||||
d["Positioning"] = str(self.obj.Positioning)
|
d["positioning"] = str(self.obj.Positioning)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|
139
ARTools.py
139
ARTools.py
|
@ -1,7 +1,7 @@
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
import Part
|
import Part
|
||||||
import json # For exporting part infos
|
import json # For exporting part infos
|
||||||
import os # for safer path handling
|
import os # for safer path handling
|
||||||
if FreeCAD.GuiUp:
|
if FreeCAD.GuiUp:
|
||||||
import FreeCADGui
|
import FreeCADGui
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
|
@ -217,7 +217,7 @@ def exportFeatureFrames(obj, ofile):
|
||||||
if not of.lower().endswith(".json"):
|
if not of.lower().endswith(".json"):
|
||||||
ofile = ofile + ".json"
|
ofile = ofile + ".json"
|
||||||
with open(ofile, "wb") as propfile:
|
with open(ofile, "wb") as propfile:
|
||||||
json.dump(feature_dict, indent=1, separators=(',', ': '))
|
json.dump(feature_dict, propfile, indent=1, separators=(',', ': '))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ def appendFeatureFrames(obj, ofile):
|
||||||
else:
|
else:
|
||||||
partprops["features"].update(feature_dict["features"])
|
partprops["features"].update(feature_dict["features"])
|
||||||
with open(ofile, "wb") as propfile:
|
with open(ofile, "wb") as propfile:
|
||||||
json.dump(partprops, indent=1, separators=(',', ': '))
|
json.dump(partprops, propfile, indent=1, separators=(',', ': '))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -262,6 +262,7 @@ def exportPartInfoDialogue():
|
||||||
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
||||||
# Create file dialog
|
# Create file dialog
|
||||||
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
||||||
|
os.getenv("HOME"),
|
||||||
"*.json", options=opts)
|
"*.json", options=opts)
|
||||||
if ofile == "":
|
if ofile == "":
|
||||||
# User cancelled
|
# User cancelled
|
||||||
|
@ -313,6 +314,7 @@ def exportFeatureFramesDialogue():
|
||||||
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
||||||
# Create file dialog
|
# Create file dialog
|
||||||
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
||||||
|
os.getenv("HOME"),
|
||||||
"*.json", options=opts)
|
"*.json", options=opts)
|
||||||
if ofile == "":
|
if ofile == "":
|
||||||
# User cancelled
|
# User cancelled
|
||||||
|
@ -339,7 +341,7 @@ def exportFeatureFramesDialogue():
|
||||||
appendFeatureFrames(unique_selected[0], ofile)
|
appendFeatureFrames(unique_selected[0], ofile)
|
||||||
if len(unique_selected) > 1:
|
if len(unique_selected) > 1:
|
||||||
FreeCAD.Console.PrintWarning("Multi-part export not yet supported\n")
|
FreeCAD.Console.PrintWarning("Multi-part export not yet supported\n")
|
||||||
FreeCAD.Console.PrintMessage("Feature frames of " + str(unique_selected[0]) + "exported to " + str(ofile) + "\n")
|
FreeCAD.Console.PrintMessage("Feature frames of " + str(unique_selected[0].Label) + " exported to " + str(ofile) + "\n")
|
||||||
|
|
||||||
|
|
||||||
def exportPartInfoAndFeaturesDialogue():
|
def exportPartInfoAndFeaturesDialogue():
|
||||||
|
@ -362,6 +364,7 @@ def exportPartInfoAndFeaturesDialogue():
|
||||||
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
opts = QtGui.QFileDialog.DontConfirmOverwrite
|
||||||
# Create file dialog
|
# Create file dialog
|
||||||
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
ofile, filt = QtGui.QFileDialog.getSaveFileName(None, textprompt,
|
||||||
|
os.getenv("HOME"),
|
||||||
"*.json", options=opts)
|
"*.json", options=opts)
|
||||||
if ofile == "":
|
if ofile == "":
|
||||||
# User cancelled
|
# User cancelled
|
||||||
|
@ -390,7 +393,7 @@ def exportPartInfoAndFeaturesDialogue():
|
||||||
appendFeatureFrames(unique_selected[0], ofile)
|
appendFeatureFrames(unique_selected[0], ofile)
|
||||||
if len(unique_selected) > 1:
|
if len(unique_selected) > 1:
|
||||||
FreeCAD.Console.PrintWarning("Multi-part export not yet supported.\n")
|
FreeCAD.Console.PrintWarning("Multi-part export not yet supported.\n")
|
||||||
FreeCAD.Console.PrintMessage("Feature frames of " + str(unique_selected[0]) + "exported to " + str(ofile) + "\n")
|
FreeCAD.Console.PrintMessage("Feature frames of " + str(unique_selected[0].Label) + " exported to " + str(ofile) + "\n")
|
||||||
|
|
||||||
|
|
||||||
###################################################################
|
###################################################################
|
||||||
|
@ -413,92 +416,92 @@ def getPrimitiveInfo(prim_type, subobj, scale=1e-3):
|
||||||
"""returns a dictionary of the primitive's specific information."""
|
"""returns a dictionary of the primitive's specific information."""
|
||||||
d = {}
|
d = {}
|
||||||
if prim_type == "ArcOfCircle":
|
if prim_type == "ArcOfCircle":
|
||||||
d["Radius"] = scale*subobj.Curve.Radius
|
d["radius"] = scale*subobj.Curve.Radius
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["ParamerRange"] = subobj.ParameterRange
|
d["paramerrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "ArcOfEllipse":
|
elif prim_type == "ArcOfEllipse":
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["MajorRadius"] = scale*subobj.Curve.MajorRadius
|
d["majorradius"] = scale*subobj.Curve.MajorRadius
|
||||||
d["MinorRadius"] = scale*subobj.Curve.MinorRadius
|
d["minorradius"] = scale*subobj.Curve.MinorRadius
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "ArcOfHyperBola":
|
elif prim_type == "ArcOfHyperBola":
|
||||||
d["AngleXU"] = subobj.Curve.AngleXU
|
d["anglexu"] = subobj.Curve.AngleXU
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["MajorRadius"] = scale*subobj.Curve.MajorRadius
|
d["majorradius"] = scale*subobj.Curve.MajorRadius
|
||||||
d["MinorRadius"] = scale*subobj.Curve.MinorRadius
|
d["minorradius"] = scale*subobj.Curve.MinorRadius
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "ArcOfParabola":
|
elif prim_type == "ArcOfParabola":
|
||||||
d["AngleXU"] = subobj.Curve.AngleXU
|
d["anglexu"] = subobj.Curve.AngleXU
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Focal"] = scale*subobj.Curve.Focal
|
d["focal"] = scale*subobj.Curve.Focal
|
||||||
elif prim_type == "BSplineCurve":
|
elif prim_type == "BSplineCurve":
|
||||||
FreeCAD.Console.PrintWarning("getPrimitiveInfo of BSpline incomplete.")
|
FreeCAD.Console.PrintWarning("getPrimitiveInfo of BSpline incomplete.")
|
||||||
elif prim_type == "BezierCurve":
|
elif prim_type == "BezierCurve":
|
||||||
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Bezier incomplete.")
|
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Bezier incomplete.")
|
||||||
elif prim_type == "Circle":
|
elif prim_type == "Circle":
|
||||||
d["Radius"] = scale*subobj.Curve.Radius
|
d["radius"] = scale*subobj.Curve.Radius
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["ParamerRange"] = subobj.ParameterRange
|
d["paramerrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "Ellipse":
|
elif prim_type == "Ellipse":
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["MajorRadius"] = scale*subobj.Curve.MajorRadius
|
d["majorradius"] = scale*subobj.Curve.MajorRadius
|
||||||
d["MinorRadius"] = scale*subobj.Curve.MinorRadius
|
d["minorradius"] = scale*subobj.Curve.MinorRadius
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "Hyperbola":
|
elif prim_type == "Hyperbola":
|
||||||
d["AngleXU"] = subobj.Curve.AngleXU
|
d["anglexu"] = subobj.Curve.AngleXU
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["MajorRadius"] = scale*subobj.Curve.MajorRadius
|
d["majorradius"] = scale*subobj.Curve.MajorRadius
|
||||||
d["MinorRadius"] = scale*subobj.Curve.MinorRadius
|
d["minorradius"] = scale*subobj.Curve.MinorRadius
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "Parabola":
|
elif prim_type == "Parabola":
|
||||||
d["AngleXU"] = subobj.Curve.AngleXU
|
d["anglexu"] = subobj.Curve.AngleXU
|
||||||
d["Axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Curve.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Curve.Center, scale)
|
d["center"] = vector2list(subobj.Curve.Center, scale)
|
||||||
d["Focal"] = scale*subobj.Curve.Focal
|
d["focal"] = scale*subobj.Curve.Focal
|
||||||
elif prim_type == "Line":
|
elif prim_type == "Line":
|
||||||
if not subobj.Curve.Infinite:
|
if not subobj.Curve.Infinite:
|
||||||
d["StartPoint"] = vector2list(subobj.Curve.StartPoint)
|
d["startpoint"] = vector2list(subobj.Curve.StartPoint)
|
||||||
d["EndPoint"] = vector2list(subobj.Curve.EndPoint)
|
d["endpoint"] = vector2list(subobj.Curve.EndPoint)
|
||||||
d["Infinite"] = subobj.Curve.Infinite
|
d["infinite"] = subobj.Curve.Infinite
|
||||||
elif prim_type == "BSplineSurface":
|
elif prim_type == "BSplineSurface":
|
||||||
FreeCAD.Console.PrintWarning("getPrimitiveInfo of BSpline incomplete.")
|
FreeCAD.Console.PrintWarning("getPrimitiveInfo of BSpline incomplete.")
|
||||||
elif prim_type == "BezierSurface":
|
elif prim_type == "BezierSurface":
|
||||||
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Bezier incomplete.")
|
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Bezier incomplete.")
|
||||||
elif prim_type == "Cylinder":
|
elif prim_type == "Cylinder":
|
||||||
d["Axis"] = subobj.Surface.Axis
|
d["axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
||||||
d["Radius"] = scale*subobj.Surface.Radius
|
d["radius"] = scale*subobj.Surface.Radius
|
||||||
d["Center"] = vector2list(subobj.Surface.Center)
|
d["center"] = vector2list(subobj.Surface.Center)
|
||||||
PR = list(subobj.ParameterRange)
|
PR = list(subobj.ParameterRange)
|
||||||
PR[2] = PR[2]*scale
|
PR[2] = PR[2]*scale
|
||||||
PR[3] = PR[3]*scale
|
PR[3] = PR[3]*scale
|
||||||
d["ParameterRange"] = PR
|
d["parameterrange"] = PR
|
||||||
elif prim_type == "Plane":
|
elif prim_type == "Plane":
|
||||||
d["Axis"] = subobj.Surface.Axis
|
d["axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
||||||
d["Position"] = vector2list(subobj.Surface.Position, scale)
|
d["position"] = vector2list(subobj.Surface.Position, scale)
|
||||||
d["ParameterRange"] = [scale*i for i in subobj.ParameterRange]
|
d["parameterrange"] = [scale*i for i in subobj.ParameterRange]
|
||||||
elif prim_type == "Sphere":
|
elif prim_type == "Sphere":
|
||||||
d["Axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Surface.Center, scale)
|
d["center"] = vector2list(subobj.Surface.Center, scale)
|
||||||
d["Radius"] = scale*subobj.Surface.Radius
|
d["radius"] = scale*subobj.Surface.Radius
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
elif prim_type == "Toroid":
|
elif prim_type == "Toroid":
|
||||||
d["Axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Surface.Center, scale)
|
d["center"] = vector2list(subobj.Surface.Center, scale)
|
||||||
d["MajorRadius"] = scale*subobj.Surface.MajorRadius
|
d["majorradius"] = scale*subobj.Surface.MajorRadius
|
||||||
d["MinorRadius"] = scale*subobj.Surface.MinorRadius
|
d["minorradius"] = scale*subobj.Surface.MinorRadius
|
||||||
d["ParameterRange"] = subobj.Surface.ParameterRange
|
d["parameterrange"] = subobj.Surface.ParameterRange
|
||||||
elif prim_type == "Cone":
|
elif prim_type == "Cone":
|
||||||
d["Axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
d["axis"] = vector2list(subobj.Surface.Axis, scale=1)
|
||||||
d["Center"] = vector2list(subobj.Surface.Center, scale)
|
d["center"] = vector2list(subobj.Surface.Center, scale)
|
||||||
d["Radius"] = scale*subobj.Surface.Radius
|
d["radius"] = scale*subobj.Surface.Radius
|
||||||
d["SemiAngle"] = subobj.Surface.SemiAngle
|
d["semiangle"] = subobj.Surface.SemiAngle
|
||||||
d["ParameterRange"] = subobj.ParameterRange
|
d["parameterrange"] = subobj.ParameterRange
|
||||||
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Cone may have wrong ParameterRange.")
|
FreeCAD.Console.PrintWarning("getPrimitiveInfo of Cone may have wrong ParameterRange.")
|
||||||
return d
|
return d
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue