FreeCAD 0.19 support

This commit is contained in:
Igor Brylyov 2021-12-17 16:57:58 +03:00
parent 23905b1000
commit c410442b98

View file

@ -49,7 +49,7 @@ def boundingBox2list(bb, scale=1e-3):
def principalProperties2dict(pp, scale=1e-3): def principalProperties2dict(pp, scale=1e-3):
npp = {} npp = {}
for key, value in pp.iteritems(): for key, value in pp.items():
if type(value) is FreeCAD.Vector: if type(value) is FreeCAD.Vector:
npp[key.lower()] = vector2list(value, scale=1e-3) npp[key.lower()] = vector2list(value, scale=1e-3)
else: else:
@ -179,7 +179,7 @@ def exportPartInfo(obj, ofile):
ofile = ofile + ".json" ofile = ofile + ".json"
partprops = getLocalPartProps(obj) partprops = getLocalPartProps(obj)
with open(ofile, "wb") as propfile: with open(ofile, "w", encoding="utf8") as propfile:
json.dump(partprops, propfile, indent=1, separators=(',', ': ')) json.dump(partprops, propfile, indent=1, separators=(',', ': '))
return True return True
@ -192,11 +192,11 @@ def appendPartInfo(obj, ofile):
For more information on principal properties, see TopoShape in OCCT For more information on principal properties, see TopoShape in OCCT
documentation. documentation.
""" """
with open(ofile, "rb") as propfile: with open(ofile, "r", encoding="utf8") as propfile:
partprops = json.load(propfile) partprops = json.load(propfile)
new_props = getLocalPartProps(obj) new_props = getLocalPartProps(obj)
partprops.update(new_props) partprops.update(new_props)
with open(ofile, "wb") as propfile: with open(ofile, "w", encoding="utf8") as propfile:
json.dump(partprops, propfile, indent=1, separators=(',', ': ')) json.dump(partprops, propfile, indent=1, separators=(',', ': '))
return True return True
@ -205,7 +205,7 @@ def exportFeatureFrames(obj, ofile):
"""Exports feature frames attached to a part.""" """Exports feature frames attached to a part."""
# Get the feature frames # Get the feature frames
import ARFrames import ARFrames
ff_check = lambda x: isinstance(x.Proxy, ARFrames.FeatureFrame) ff_check = lambda x: isinstance(x.Proxy, ARFrames.FeatureFrame) if hasattr(x, 'Proxy') else False
ff_list = filter(ff_check, obj.InList) ff_list = filter(ff_check, obj.InList)
ff_named = {ff.Label: ff.Proxy.getDict() for ff in ff_list} ff_named = {ff.Label: ff.Proxy.getDict() for ff in ff_list}
feature_dict = {"features": ff_named} feature_dict = {"features": ff_named}
@ -216,7 +216,7 @@ def exportFeatureFrames(obj, ofile):
os.makedirs(odir) os.makedirs(odir)
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, "w", encoding="utf8") as propfile:
json.dump(feature_dict, propfile, indent=1, separators=(',', ': ')) json.dump(feature_dict, propfile, indent=1, separators=(',', ': '))
return True return True
@ -226,9 +226,9 @@ def appendFeatureFrames(obj, ofile):
file.""" file."""
# Get the feature frames # Get the feature frames
import ARFrames import ARFrames
with open(ofile, "rb") as propfile: with open(ofile, "r", encoding="utf8") as propfile:
partprops = json.load(propfile) partprops = json.load(propfile)
ff_check = lambda x: isinstance(x.Proxy, ARFrames.FeatureFrame) ff_check = lambda x: isinstance(x.Proxy, ARFrames.FeatureFrame) if hasattr(x, 'Proxy') else False
ff_list = filter(ff_check, obj.InList) ff_list = filter(ff_check, obj.InList)
ff_named = {ff.Label: ff.Proxy.getDict() for ff in ff_list} ff_named = {ff.Label: ff.Proxy.getDict() for ff in ff_list}
feature_dict = {"features": ff_named} feature_dict = {"features": ff_named}
@ -236,7 +236,7 @@ def appendFeatureFrames(obj, ofile):
partprops.update(feature_dict) partprops.update(feature_dict)
else: else:
partprops["features"].update(feature_dict["features"]) partprops["features"].update(feature_dict["features"])
with open(ofile, "wb") as propfile: with open(ofile, "w", encoding="utf8") as propfile:
json.dump(partprops, propfile, indent=1, separators=(',', ': ')) json.dump(partprops, propfile, indent=1, separators=(',', ': '))
return True return True
@ -270,10 +270,8 @@ def exportPartInfoDialogue():
if os.path.exists(ofile): if os.path.exists(ofile):
msgbox = QtGui.QMessageBox() msgbox = QtGui.QMessageBox()
msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.") msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.")
append_button = msgbox.addButton(unicode("Append"), append_button = msgbox.addButton("Append", QtGui.QMessageBox.YesRole)
QtGui.QMessageBox.YesRole) overwrite_button = msgbox.addButton("Overwrite", QtGui.QMessageBox.NoRole)
overwrite_button = msgbox.addButton(unicode("Overwrite"),
QtGui.QMessageBox.NoRole)
msgbox.exec_() msgbox.exec_()
if msgbox.clickedButton() == append_button: if msgbox.clickedButton() == append_button:
NEWFILE = False NEWFILE = False
@ -296,6 +294,7 @@ def exportPartInfoDialogue():
def exportFeatureFramesDialogue(): def exportFeatureFramesDialogue():
"""Spawns a dialogue window for a part's feature frames to be exported.""" """Spawns a dialogue window for a part's feature frames to be exported."""
# Select only true parts # Select only true parts
import ARFrames
s = FreeCADGui.Selection.getSelection() s = FreeCADGui.Selection.getSelection()
FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.clearSelection()
if len(s) == 0: if len(s) == 0:
@ -303,7 +302,7 @@ def exportFeatureFramesDialogue():
return False return False
unique_selected = [] unique_selected = []
for item in s: for item in s:
if item not in unique_selected and isinstance(item, Part.Feature): if item not in unique_selected and isinstance(item.Proxy, ARFrames.FeatureFrame):
# Ensuring that we are parts # Ensuring that we are parts
unique_selected.append(item) unique_selected.append(item)
FreeCADGui.Selection.addSelection(item) FreeCADGui.Selection.addSelection(item)
@ -322,10 +321,8 @@ def exportFeatureFramesDialogue():
if os.path.exists(ofile): if os.path.exists(ofile):
msgbox = QtGui.QMessageBox() msgbox = QtGui.QMessageBox()
msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.") msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.")
append_button = msgbox.addButton(unicode("Append"), append_button = msgbox.addButton("Append", QtGui.QMessageBox.YesRole)
QtGui.QMessageBox.YesRole) overwrite_button = msgbox.addButton("Overwrite", QtGui.QMessageBox.NoRole)
overwrite_button = msgbox.addButton(unicode("Overwrite"),
QtGui.QMessageBox.NoRole)
msgbox.exec_() msgbox.exec_()
if msgbox.clickedButton() == append_button: if msgbox.clickedButton() == append_button:
NEWFILE = False NEWFILE = False
@ -346,17 +343,19 @@ def exportFeatureFramesDialogue():
def exportPartInfoAndFeaturesDialogue(): def exportPartInfoAndFeaturesDialogue():
"""Spawns a dialogue window for exporting both.""" """Spawns a dialogue window for exporting both."""
import ARFrames
s = FreeCADGui.Selection.getSelection() s = FreeCADGui.Selection.getSelection()
FreeCADGui.Selection.clearSelection() FreeCADGui.Selection.clearSelection()
if len(s) == 0: if len(s) == 0:
FreeCAD.Console.PrintError("No part selected.") FreeCAD.Console.PrintError("No part selected")
return False return False
unique_selected = [] unique_selected = []
for item in s: for item in s:
if item not in unique_selected and isinstance(item, Part.Feature): if item not in unique_selected:
# Ensuring that we are parts # Ensuring that we are parts
unique_selected.append(item) unique_selected.append(item)
FreeCADGui.Selection.addSelection(item) FreeCADGui.Selection.addSelection(item)
FreeCAD.Console.PrintMessage("Added for export "+str(item.FullName)+"\n")
# Fix wording # Fix wording
textprompt = "Save the part info and feature frames attached to the part" textprompt = "Save the part info and feature frames attached to the part"
if len(unique_selected) > 1: if len(unique_selected) > 1:
@ -372,10 +371,8 @@ def exportPartInfoAndFeaturesDialogue():
if os.path.exists(ofile): if os.path.exists(ofile):
msgbox = QtGui.QMessageBox() msgbox = QtGui.QMessageBox()
msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.") msgbox.setText("File already exists. We can overwrite the file, or add the information/rewrite only relevant sections.")
append_button = msgbox.addButton(unicode("Append"), append_button = msgbox.addButton("Append", QtGui.QMessageBox.YesRole)
QtGui.QMessageBox.YesRole) overwrite_button = msgbox.addButton("Overwrite", QtGui.QMessageBox.NoRole)
overwrite_button = msgbox.addButton(unicode("Overwrite"),
QtGui.QMessageBox.NoRole)
msgbox.exec_() msgbox.exec_()
if msgbox.clickedButton() == append_button: if msgbox.clickedButton() == append_button:
NEWFILE = False NEWFILE = False