Simple job initialisation from template xml file.
This commit is contained in:
@@ -86,6 +86,11 @@ HighCarbonToolSteel CastAlloy, Ceramics, Diamond, Sialon or Undefined</UserDocu>
|
||||
<UserDocu>returns a copy of this tool</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="fromTemplate">
|
||||
<Documentation>
|
||||
<UserDocu>fills receiver with values from the template string</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<!--<ClassDeclarations>
|
||||
bool touched;
|
||||
</ClassDeclarations>-->
|
||||
|
||||
@@ -133,14 +133,15 @@ void Tool::Restore(XMLReader &reader)
|
||||
{
|
||||
reader.readElement("Tool");
|
||||
Name = reader.getAttribute("name");
|
||||
Diameter = (double) reader.getAttributeAsFloat("diameter");
|
||||
LengthOffset = (double) reader.getAttributeAsFloat("length");
|
||||
FlatRadius = (double) reader.getAttributeAsFloat("flat");
|
||||
CornerRadius = (double) reader.getAttributeAsFloat("corner");
|
||||
CuttingEdgeAngle = (double) reader.getAttributeAsFloat("angle");
|
||||
CuttingEdgeHeight = (double) reader.getAttributeAsFloat("height");
|
||||
|
||||
std::string type = reader.getAttribute("type");
|
||||
Diameter = reader.hasAttribute("diameter") ? (double) reader.getAttributeAsFloat("diameter") : 0.0;
|
||||
LengthOffset = reader.hasAttribute("length") ? (double) reader.getAttributeAsFloat("length") : 0.0;
|
||||
FlatRadius = reader.hasAttribute("flat") ? (double) reader.getAttributeAsFloat("flat") : 0.0;
|
||||
CornerRadius = reader.hasAttribute("corner") ? (double) reader.getAttributeAsFloat("corner") : 0.0;
|
||||
CuttingEdgeAngle = reader.hasAttribute("angle") ? (double) reader.getAttributeAsFloat("angle") : 0.0;
|
||||
CuttingEdgeHeight = reader.hasAttribute("height") ? (double) reader.getAttributeAsFloat("height") : 0.0;
|
||||
std::string type = reader.hasAttribute("type") ? reader.getAttribute("type") : "";
|
||||
std::string mat = reader.hasAttribute("mat") ? reader.getAttribute("mat") : "";
|
||||
|
||||
if(type=="EndMill")
|
||||
Type = Tool::ENDMILL;
|
||||
else if(type=="Drill")
|
||||
@@ -168,7 +169,6 @@ void Tool::Restore(XMLReader &reader)
|
||||
else
|
||||
Type = Tool::UNDEFINED;
|
||||
|
||||
std::string mat = reader.getAttribute("mat");
|
||||
if(mat=="Carbide")
|
||||
Material = Tool::CARBIDE;
|
||||
else if(mat=="HighSpeedSteel")
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Base/Reader.h"
|
||||
#include "Mod/Path/App/Tooltable.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ToolPy.xml and TooltablePy.xml)
|
||||
@@ -328,6 +328,22 @@ PyObject* ToolPy::copy(PyObject * args)
|
||||
}
|
||||
|
||||
|
||||
PyObject* ToolPy::fromTemplate(PyObject * args)
|
||||
{
|
||||
PyObject *pcObj;
|
||||
if (PyArg_ParseTuple(args, "S", &pcObj)) {
|
||||
if (PyString_Check(pcObj)) {
|
||||
// embed actual string in dummy tag so XMLReader can consume that on construction
|
||||
std::ostringstream os;
|
||||
os << "<snippet>" << PyString_AsString(pcObj) << "</snippet>";
|
||||
std::istringstream is(os.str());
|
||||
Base::XMLReader reader("", is);
|
||||
getToolPtr()->Restore(reader);
|
||||
Py_Return ;
|
||||
}
|
||||
}
|
||||
throw Py::Exception("only string argument accepted.");
|
||||
}
|
||||
|
||||
|
||||
// TooltablePy
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<file>icons/preferences-path.svg</file>
|
||||
<file>panels/ContourEdit.ui</file>
|
||||
<file>panels/DlgJobChooser.ui</file>
|
||||
<file>panels/DlgJobCreate.ui</file>
|
||||
<file>panels/DlgSelectPostProcessor.ui</file>
|
||||
<file>panels/DlgToolCopy.ui</file>
|
||||
<file>panels/DlgTCChooser.ui</file>
|
||||
|
||||
120
src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui
Normal file
120
src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>208</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Base Model </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cbModel"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Template</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="cbTemplate">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Job.xml</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Stock</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="cbStock">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>coming soon</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -26,8 +26,9 @@ import Draft
|
||||
import FreeCAD
|
||||
import Path
|
||||
import PathScripts.PathLog as PathLog
|
||||
import sys
|
||||
import PathScripts.PathToolController as PathToolController
|
||||
import lxml.etree as xml
|
||||
import sys
|
||||
|
||||
from PySide import QtCore, QtGui
|
||||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
@@ -52,7 +53,8 @@ def translate(context, text, disambig=None):
|
||||
|
||||
class ObjectPathJob:
|
||||
|
||||
def __init__(self, obj):
|
||||
def __init__(self, obj, base):
|
||||
self.obj = obj
|
||||
obj.addProperty("App::PropertyFile", "PostProcessorOutputFile", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project"))
|
||||
obj.PostProcessorOutputFile = PathPreferences.defaultOutputFile()
|
||||
obj.setEditorMode("PostProcessorOutputFile", 0) # set to default mode
|
||||
@@ -74,12 +76,20 @@ class ObjectPathJob:
|
||||
obj.GeometryTolerance = PathPreferences.defaultGeometryTolerance()
|
||||
|
||||
obj.addProperty("App::PropertyLink", "Base", "Base", "The base object for all operations")
|
||||
obj.Base = base
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
ViewProviderJob(obj.ViewObject)
|
||||
|
||||
def assignTemplate(self, template):
|
||||
if template:
|
||||
tree = xml.parse(template)
|
||||
for tc in tree.getroot().iter('ToolController'):
|
||||
PathToolController.CommandPathToolController.FromTemplate(self.obj, tc)
|
||||
else:
|
||||
PathToolController.CommandPathToolController.Create(self.obj.Name)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -96,16 +106,6 @@ class ObjectPathJob:
|
||||
self.tooltip = processor.tooltip
|
||||
self.tooltipArgs = processor.tooltipArgs
|
||||
|
||||
# def getToolControllers(self, obj):
|
||||
# '''returns a list of ToolControllers for the current job'''
|
||||
# controllers = []
|
||||
# for o in obj.Group:
|
||||
# if "Proxy" in o.PropertiesList:
|
||||
# if isinstance(o.Proxy, PathToolController.ToolController):
|
||||
# controllers.append (o.Name)
|
||||
# return controllers
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
cmds = []
|
||||
for child in obj.Group:
|
||||
@@ -162,6 +162,7 @@ class ViewProviderJob:
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self, obj, deleteOnReject):
|
||||
PathLog.error("Edit Job")
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Edit Job"))
|
||||
self.obj = obj
|
||||
self.deleteOnReject = deleteOnReject
|
||||
@@ -196,6 +197,7 @@ class TaskPanel:
|
||||
FreeCADGui.Control.closeDialog()
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
if self.deleteOnReject:
|
||||
PathLog.error("Uncreate Job")
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Uncreate Job"))
|
||||
for child in self.obj.Group:
|
||||
FreeCAD.ActiveDocument.removeObject(child.Name)
|
||||
@@ -295,6 +297,32 @@ class TaskPanel:
|
||||
|
||||
self.setFields()
|
||||
|
||||
class DlgJobCreate:
|
||||
|
||||
def __init__(self, parent=None):
|
||||
self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobCreate.ui")
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
if sel:
|
||||
selected = sel[0].Label
|
||||
else:
|
||||
selected = None
|
||||
index = 0
|
||||
for solid in sorted(filter(lambda obj: hasattr(obj, 'Shape') and obj.Shape.isClosed(), FreeCAD.ActiveDocument.Objects), key=lambda o: o.Label):
|
||||
if solid.Label == selected:
|
||||
index = self.dialog.cbModel.count()
|
||||
self.dialog.cbModel.addItem(solid.Label)
|
||||
self.dialog.cbModel.setCurrentIndex(index)
|
||||
|
||||
def getModel(self):
|
||||
label = self.dialog.cbModel.currentText()
|
||||
return filter(lambda obj: obj.Label == label, FreeCAD.ActiveDocument.Objects)[0]
|
||||
|
||||
def getTemplate(self):
|
||||
return self.dialog.cbTemplate.currentText()
|
||||
|
||||
def exec_(self):
|
||||
return self.dialog.exec_()
|
||||
|
||||
class CommandJobCreate:
|
||||
|
||||
def GetResources(self):
|
||||
@@ -307,22 +335,17 @@ class CommandJobCreate:
|
||||
return FreeCAD.ActiveDocument is not None
|
||||
|
||||
def Activated(self):
|
||||
self.Create()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
dialog = DlgJobCreate()
|
||||
if dialog.exec_() == 1:
|
||||
self.Create(dialog.getModel(), dialog.getTemplate())
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
@classmethod
|
||||
def Execute(cls):
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Create Job"))
|
||||
def Create(cls, base, template):
|
||||
FreeCADGui.addModule('PathScripts.PathUtils')
|
||||
FreeCADGui.addModule('PathScripts.PathToolController')
|
||||
snippet = '''
|
||||
import PathScripts.PathToolController as PathToolController
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Job")
|
||||
PathScripts.PathJob.ObjectPathJob(obj)
|
||||
PathToolController.CommandPathToolController.Create(obj.Name)
|
||||
obj.ViewObject.Proxy.deleteOnReject = True
|
||||
obj.ViewObject.startEditing()
|
||||
'''
|
||||
FreeCADGui.addModule('PathScripts.PathJob')
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Create Job"))
|
||||
snippet = 'PathScripts.PathJob.ObjectPathJob(FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython", "Job"), FreeCAD.ActiveDocument.%s).assignTemplate("%s")' % (base.Name, template)
|
||||
FreeCADGui.doCommand(snippet)
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
@@ -344,12 +367,13 @@ class CommandJobExportTemplate:
|
||||
|
||||
@classmethod
|
||||
def Execute(cls, job):
|
||||
PathLog.error("Export Job template")
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_Job", "Export Job template"))
|
||||
root = xml.Element('PathJobConfiguration')
|
||||
for obj in job.Group:
|
||||
if hasattr(obj, 'Tool') and hasattr(obj, 'SpindleDir'):
|
||||
tc = xml.SubElement(root, 'ToolController', {'Label': obj.Label})
|
||||
attrs = {}
|
||||
attrs['label'] = ("%s" % (obj.Label))
|
||||
attrs['nr'] = ("%d" % (obj.ToolNumber))
|
||||
attrs['vfeed'] = ("%s" % (obj.VertFeed))
|
||||
attrs['hfeed'] = ("%s" % (obj.HorizFeed))
|
||||
@@ -358,15 +382,12 @@ class CommandJobExportTemplate:
|
||||
attrs['speed'] = ("%f" % (obj.SpindleSpeed))
|
||||
attrs['dir'] = ("%s" % (obj.SpindleDir))
|
||||
|
||||
xml.SubElement(tc, 'Controller', attrs)
|
||||
tc = xml.SubElement(root, 'ToolController', attrs)
|
||||
tc.append(xml.fromstring(obj.Tool.Content))
|
||||
xml.ElementTree(root).write("./%s.xml" % job.Label, pretty_print=True)
|
||||
|
||||
xml.ElementTree(root).write("./%s.xml" % job.Label, pretty_print=True)
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
# register the FreeCAD command
|
||||
FreeCADGui.addCommand('Path_Job', CommandJobCreate())
|
||||
|
||||
@@ -30,6 +30,7 @@ import Path
|
||||
import PathScripts
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathUtils
|
||||
import lxml.etree as xml
|
||||
|
||||
from FreeCAD import Units
|
||||
from PySide import QtCore, QtGui
|
||||
@@ -203,6 +204,37 @@ class CommandPathToolController:
|
||||
obj.ToolNumber = toolNumber
|
||||
PathUtils.addToJob(obj, jobname)
|
||||
|
||||
@staticmethod
|
||||
def FromTemplate(job, template, assignViewProvider=True):
|
||||
PathLog.track()
|
||||
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", template.get('label'))
|
||||
PathScripts.PathToolController.ToolController(obj)
|
||||
if assignViewProvider:
|
||||
PathScripts.PathToolController._ViewProviderToolController(obj.ViewObject)
|
||||
|
||||
if template.get('vfeed'):
|
||||
obj.HorizFeed = template.get('vfeed')
|
||||
if template.get('hfeed'):
|
||||
obj.HorizFeed = template.get('hfeed')
|
||||
if template.get('vrapid'):
|
||||
obj.HorizRapid = template.get('vrapid')
|
||||
if template.get('hrapid'):
|
||||
obj.HorizRapid = template.get('hrapid')
|
||||
if template.get('speed'):
|
||||
obj.SpindleSpeed = float(template.get('speed'))
|
||||
if template.get('dir'):
|
||||
obj.SpindleDir = template.get('dir')
|
||||
if template.get('nr'):
|
||||
obj.ToolNumber = int(template.get('nr'))
|
||||
|
||||
for t in template.iter('Tool'):
|
||||
tool = Path.Tool()
|
||||
tool.fromTemplate(xml.tostring(t))
|
||||
obj.Tool = tool
|
||||
|
||||
PathUtils.addToJob(obj, job.Name)
|
||||
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
|
||||
Reference in New Issue
Block a user