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
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ SET(PathTests_SRCS
|
||||
PathTests/TestPathLog.py
|
||||
PathTests/TestPathPost.py
|
||||
PathTests/TestPathStock.py
|
||||
PathTests/TestPathTool.py
|
||||
PathTests/TestPathUtil.py
|
||||
)
|
||||
|
||||
|
||||
85
src/Mod/Path/PathTests/TestPathTool.py
Normal file
85
src/Mod/Path/PathTests/TestPathTool.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import Path
|
||||
|
||||
from PathTests.PathTestUtils import PathTestBase
|
||||
|
||||
class TestPathTool(PathTestBase):
|
||||
|
||||
def test00(self):
|
||||
'''Verify templateAttrs'''
|
||||
|
||||
name = 'tool 1'
|
||||
mat = 'Carbide'
|
||||
typ = 'EndMill'
|
||||
dia = 1.7
|
||||
flat = 7.2
|
||||
offset = 3.2
|
||||
corner = 4
|
||||
height = 45.3
|
||||
angle = 118
|
||||
|
||||
tool = Path.Tool()
|
||||
tool.Name = name
|
||||
tool.ToolType = typ
|
||||
tool.Material = mat
|
||||
tool.Diameter = dia
|
||||
tool.LengthOffset = offset
|
||||
tool.FlatRadius = flat
|
||||
tool.CornerRadius = corner
|
||||
tool.CuttingEdgeAngle = angle
|
||||
tool.CuttingEdgeHeight = height
|
||||
|
||||
attrs = tool.templateAttrs()
|
||||
self.assertEqual(attrs['name'], name)
|
||||
self.assertEqual(attrs['diameter'], dia)
|
||||
self.assertEqual(attrs['material'], mat)
|
||||
self.assertEqual(attrs['tooltype'], typ)
|
||||
self.assertEqual(attrs['lengthOffset'], offset)
|
||||
self.assertEqual(attrs['flatRadius'], flat)
|
||||
self.assertEqual(attrs['cornerRadius'], corner)
|
||||
self.assertEqual(attrs['cuttingEdgeAngle'], angle)
|
||||
self.assertEqual(attrs['cuttingEdgeHeight'], height)
|
||||
return tool
|
||||
|
||||
|
||||
def test01(self):
|
||||
'''Verify template roundtrip'''
|
||||
|
||||
t0 = self.test00()
|
||||
t1 = Path.Tool()
|
||||
t1.fromTemplate(t0.templateAttrs())
|
||||
|
||||
self.assertEqual(t0.Name, t1.Name)
|
||||
self.assertEqual(t0.ToolType, t1.ToolType)
|
||||
self.assertEqual(t0.Material, t1.Material)
|
||||
self.assertEqual(t0.Diameter, t1.Diameter)
|
||||
self.assertEqual(t0.LengthOffset, t1.LengthOffset)
|
||||
self.assertEqual(t0.FlatRadius, t1.FlatRadius)
|
||||
self.assertEqual(t0.CornerRadius, t1.CornerRadius)
|
||||
self.assertEqual(t0.CuttingEdgeAngle, t1.CuttingEdgeAngle)
|
||||
self.assertEqual(t0.CuttingEdgeHeight, t1.CuttingEdgeHeight)
|
||||
|
||||
@@ -33,3 +33,4 @@ from PathTests.TestPathDepthParams import depthTestCases
|
||||
from PathTests.TestPathDressupHoldingTags import TestHoldingTags
|
||||
from PathTests.TestPathDressupDogbone import TestDressupDogbone
|
||||
from PathTests.TestPathStock import TestPathStock
|
||||
from PathTests.TestPathTool import TestPathTool
|
||||
|
||||
Reference in New Issue
Block a user