Added restore from dictionary to Tool and templateAttrs for their retreival.
This commit is contained in:
@@ -88,7 +88,12 @@ HighCarbonToolSteel CastAlloy, Ceramics, Diamond, Sialon or Undefined</UserDocu>
|
||||
</Methode>
|
||||
<Methode Name="fromTemplate">
|
||||
<Documentation>
|
||||
<UserDocu>fromTemplate(xmlString) ... fills receiver with values from the template string</UserDocu>
|
||||
<UserDocu>fromTemplate(xmlString|dictionary) ... fills receiver with values from the template string or dictionary</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="templateAttrs">
|
||||
<Documentation>
|
||||
<UserDocu>templateAttrs() ... returns a dictionary with all attributes</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<!--<ClassDeclarations>
|
||||
|
||||
@@ -89,52 +89,10 @@ void Tool::Save (Writer &writer) const
|
||||
<< "flat=\"" << FlatRadius << "\" "
|
||||
<< "corner=\"" << CornerRadius << "\" "
|
||||
<< "angle=\"" << CuttingEdgeAngle << "\" "
|
||||
<< "height=\"" << CuttingEdgeHeight << "\" ";
|
||||
|
||||
if(Type == Tool::ENDMILL)
|
||||
writer.Stream() << " type=\"EndMill\" ";
|
||||
else if(Type == Tool::DRILL)
|
||||
writer.Stream() << " type=\"Drill\" ";
|
||||
else if(Type == Tool::CENTERDRILL)
|
||||
writer.Stream() << " type=\"CenterDrill\" ";
|
||||
else if(Type == Tool::COUNTERSINK)
|
||||
writer.Stream() << " type=\"CounterSink\" ";
|
||||
else if(Type == Tool::COUNTERBORE)
|
||||
writer.Stream() << " type=\"CounterBore\" ";
|
||||
else if(Type == Tool::REAMER)
|
||||
writer.Stream() << " type=\"Reamer\" ";
|
||||
else if(Type == Tool::TAP)
|
||||
writer.Stream() << " type=\"Tap\" ";
|
||||
else if(Type == Tool::SLOTCUTTER)
|
||||
writer.Stream() << " type=\"SlotCutter\" ";
|
||||
else if(Type == Tool::BALLENDMILL)
|
||||
writer.Stream() << " type=\"BallEndMill\" ";
|
||||
else if(Type == Tool::CHAMFERMILL)
|
||||
writer.Stream() << " type=\"ChamferMill\" ";
|
||||
else if(Type == Tool::CORNERROUND)
|
||||
writer.Stream() << " type=\"CornerRound\" ";
|
||||
else if(Type == Tool::ENGRAVER)
|
||||
writer.Stream() << " type=\"Engraver\" ";
|
||||
else
|
||||
writer.Stream() << " type=\"Undefined\" ";
|
||||
|
||||
if(Material == Tool::CARBIDE)
|
||||
writer.Stream() << " mat=\"Carbide\" /> ";
|
||||
else if(Material == Tool::HIGHSPEEDSTEEL)
|
||||
writer.Stream() << " mat=\"HighSpeedSteel\" /> ";
|
||||
else if(Material == Tool::HIGHCARBONTOOLSTEEL)
|
||||
writer.Stream() << " mat=\"HighCarbonToolSteel\" /> ";
|
||||
else if(Material == Tool::CASTALLOY)
|
||||
writer.Stream() << " mat=\"CastAlloy\" /> ";
|
||||
else if(Material == Tool::CERAMICS)
|
||||
writer.Stream() << " mat=\"Ceramics\" /> ";
|
||||
else if(Material == Tool::DIAMOND)
|
||||
writer.Stream() << " mat=\"Diamond\" /> ";
|
||||
else if(Material == Tool::SIALON)
|
||||
writer.Stream() << " mat=\"Sialon\" /> ";
|
||||
else
|
||||
writer.Stream() << " mat=\"Undefined\" /> ";
|
||||
writer.Stream()<< std::endl;
|
||||
<< "height=\"" << CuttingEdgeHeight << "\" "
|
||||
<< "type=\"" << TypeName(Type) << "\" "
|
||||
<< "mat=\"" << MaterialName(Material) << "\" "
|
||||
<< "/>" << std::endl;
|
||||
}
|
||||
|
||||
void Tool::Restore(XMLReader &reader)
|
||||
@@ -195,7 +153,60 @@ void Tool::Restore(XMLReader &reader)
|
||||
Material = Tool::MATUNDEFINED;
|
||||
}
|
||||
|
||||
const char* Tool::TypeName(Tool::ToolType typ) {
|
||||
switch (typ) {
|
||||
case Tool::DRILL:
|
||||
return "Drill";
|
||||
case Tool::CENTERDRILL:
|
||||
return "CenterDrill";
|
||||
case Tool::COUNTERSINK:
|
||||
return "CounterSink";
|
||||
case Tool::COUNTERBORE:
|
||||
return "CounterBore";
|
||||
case Tool::REAMER:
|
||||
return "Reamer";
|
||||
case Tool::TAP:
|
||||
return "Tap";
|
||||
case Tool::ENDMILL:
|
||||
return "EndMill";
|
||||
case Tool::SLOTCUTTER:
|
||||
return "SlotCutter";
|
||||
case Tool::BALLENDMILL:
|
||||
return "BallEndMill";
|
||||
case Tool::CHAMFERMILL:
|
||||
return "ChamferMill";
|
||||
case Tool::CORNERROUND:
|
||||
return "CornerRound";
|
||||
case Tool::ENGRAVER:
|
||||
return "Engraver";
|
||||
case Tool::UNDEFINED:
|
||||
return "Undefined";
|
||||
}
|
||||
return "Undefined";
|
||||
}
|
||||
|
||||
const char* Tool::MaterialName(Tool::ToolMaterial mat)
|
||||
{
|
||||
switch (mat) {
|
||||
case Tool::HIGHSPEEDSTEEL:
|
||||
return "HighSpeedSteel";
|
||||
case Tool::CARBIDE:
|
||||
return "Carbide";
|
||||
case Tool::HIGHCARBONTOOLSTEEL:
|
||||
return "HighCarbonToolSteel";
|
||||
case Tool::CASTALLOY:
|
||||
return "CastAlloy";
|
||||
case Tool::CERAMICS:
|
||||
return "Ceramics";
|
||||
case Tool::DIAMOND:
|
||||
return "Diamond";
|
||||
case Tool::SIALON:
|
||||
return "Sialon";
|
||||
case Tool::MATUNDEFINED:
|
||||
return "Undefined";
|
||||
}
|
||||
return "Undefined";
|
||||
}
|
||||
|
||||
// TOOLTABLE
|
||||
|
||||
|
||||
@@ -92,6 +92,8 @@ namespace Path
|
||||
double CuttingEdgeAngle;
|
||||
double CuttingEdgeHeight;
|
||||
|
||||
static const char* TypeName(ToolType typ);
|
||||
static const char* MaterialName(ToolMaterial mat);
|
||||
};
|
||||
|
||||
/** The representation of a table of tools */
|
||||
|
||||
@@ -146,32 +146,7 @@ void ToolPy::setName(Py::String arg)
|
||||
|
||||
Py::String ToolPy::getToolType(void) const
|
||||
{
|
||||
if(getToolPtr()->Type == Tool::DRILL)
|
||||
return Py::String("Drill");
|
||||
else if(getToolPtr()->Type == Tool::CENTERDRILL)
|
||||
return Py::String("CenterDrill");
|
||||
else if(getToolPtr()->Type == Tool::COUNTERSINK)
|
||||
return Py::String("CounterSink");
|
||||
else if(getToolPtr()->Type == Tool::COUNTERBORE)
|
||||
return Py::String("CounterBore");
|
||||
else if(getToolPtr()->Type == Tool::REAMER)
|
||||
return Py::String("Reamer");
|
||||
else if(getToolPtr()->Type == Tool::TAP)
|
||||
return Py::String("Tap");
|
||||
else if(getToolPtr()->Type == Tool::ENDMILL)
|
||||
return Py::String("EndMill");
|
||||
else if(getToolPtr()->Type == Tool::SLOTCUTTER)
|
||||
return Py::String("SlotCutter");
|
||||
else if(getToolPtr()->Type == Tool::BALLENDMILL)
|
||||
return Py::String("BallEndMill");
|
||||
else if(getToolPtr()->Type == Tool::CHAMFERMILL)
|
||||
return Py::String("ChamferMill");
|
||||
else if(getToolPtr()->Type == Tool::CORNERROUND)
|
||||
return Py::String("CornerRound");
|
||||
else if(getToolPtr()->Type == Tool::ENGRAVER)
|
||||
return Py::String("Engraver");
|
||||
else
|
||||
return Py::String("Undefined");
|
||||
return Py::String(Tool::TypeName(getToolPtr()->Type));
|
||||
}
|
||||
|
||||
void ToolPy::setToolType(Py::String arg)
|
||||
@@ -208,22 +183,7 @@ void ToolPy::setToolType(Py::String arg)
|
||||
|
||||
Py::String ToolPy::getMaterial(void) const
|
||||
{
|
||||
if(getToolPtr()->Material == Tool::HIGHSPEEDSTEEL)
|
||||
return Py::String("HighSpeedSteel");
|
||||
else if(getToolPtr()->Material == Tool::CARBIDE)
|
||||
return Py::String("Carbide");
|
||||
else if(getToolPtr()->Material == Tool::HIGHCARBONTOOLSTEEL)
|
||||
return Py::String("HighCarbonToolSteel");
|
||||
else if(getToolPtr()->Material == Tool::CASTALLOY)
|
||||
return Py::String("CastAlloy");
|
||||
else if(getToolPtr()->Material == Tool::CERAMICS)
|
||||
return Py::String("Ceramics");
|
||||
else if(getToolPtr()->Material == Tool::DIAMOND)
|
||||
return Py::String("Diamond");
|
||||
else if(getToolPtr()->Material == Tool::SIALON)
|
||||
return Py::String("Sialon");
|
||||
else
|
||||
return Py::String("Undefined");
|
||||
return Py::String(Tool::MaterialName(getToolPtr()->Material));
|
||||
}
|
||||
|
||||
void ToolPy::setMaterial(Py::String arg)
|
||||
@@ -331,6 +291,7 @@ PyObject* ToolPy::copy(PyObject * args)
|
||||
PyObject* ToolPy::fromTemplate(PyObject * args)
|
||||
{
|
||||
char *pstr = 0;
|
||||
PyObject *dict = 0;
|
||||
if (PyArg_ParseTuple(args, "s", &pstr)) {
|
||||
// embed actual string in dummy tag so XMLReader can consume that on construction
|
||||
std::ostringstream os;
|
||||
@@ -340,10 +301,42 @@ PyObject* ToolPy::fromTemplate(PyObject * args)
|
||||
getToolPtr()->Restore(reader);
|
||||
Py_Return ;
|
||||
}
|
||||
PyErr_SetString(PyExc_TypeError, "argument must be a string");
|
||||
|
||||
if (PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) {
|
||||
PyErr_Clear(); // it's not a string, need to clear that exception
|
||||
PyObject *arg = PyTuple_New(0);
|
||||
if (!PyInit(arg, dict)) {
|
||||
Py_Return ;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "argument must be a string or dictionary");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str)
|
||||
#else
|
||||
# define PYSTRING_FROMSTRING(str) PyString_FromString(str)
|
||||
#endif
|
||||
|
||||
PyObject* ToolPy::templateAttrs(PyObject * args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
PyObject *dict = PyDict_New();
|
||||
PyDict_SetItemString(dict, "name", PYSTRING_FROMSTRING(getToolPtr()->Name.c_str()));
|
||||
PyDict_SetItemString(dict, "tooltype",PYSTRING_FROMSTRING(Tool::TypeName(getToolPtr()->Type)));
|
||||
PyDict_SetItemString(dict, "material", PYSTRING_FROMSTRING(Tool::MaterialName(getToolPtr()->Material)));
|
||||
PyDict_SetItemString(dict, "diameter", PyFloat_FromDouble(getToolPtr()->Diameter));
|
||||
PyDict_SetItemString(dict, "lengthOffset", PyFloat_FromDouble(getToolPtr()->LengthOffset));
|
||||
PyDict_SetItemString(dict, "flatRadius", PyFloat_FromDouble(getToolPtr()->FlatRadius));
|
||||
PyDict_SetItemString(dict, "cornerRadius", PyFloat_FromDouble(getToolPtr()->CornerRadius));
|
||||
PyDict_SetItemString(dict, "cuttingEdgeAngle", PyFloat_FromDouble(getToolPtr()->CuttingEdgeAngle));
|
||||
PyDict_SetItemString(dict, "cuttingEdgeHeight", PyFloat_FromDouble(getToolPtr()->CuttingEdgeHeight));
|
||||
return dict;
|
||||
}
|
||||
throw Py::Exception("This method accepts no argument");
|
||||
}
|
||||
|
||||
// TooltablePy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user