From 86cd9f21248c2f4b661e29043b5eead2f6b66f39 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Mon, 25 May 2020 09:06:54 -0700 Subject: [PATCH] Path: Opt into automatic git newline normalization Avoid spurious diffs from inadvertent newline changes by letting git normalize newlines in the path module as well, just as a list of other modules including Draft already do. This effectively standardizes all checked-in code to Unix newlines, but checkouts might use CRLF if that is the user preference. --- src/Mod/.gitattributes | 2 +- src/Mod/Path/App/AppPath.cpp | 198 +- src/Mod/Path/App/AppPathPy.cpp | 882 +- src/Mod/Path/App/AreaPy.xml | 214 +- src/Mod/Path/App/AreaPyImp.cpp | 976 +- src/Mod/Path/App/Command.cpp | 646 +- src/Mod/Path/App/Command.h | 152 +- src/Mod/Path/App/CommandPy.xml | 110 +- src/Mod/Path/App/CommandPyImp.cpp | 634 +- src/Mod/Path/App/FeatureArea.cpp | 512 +- src/Mod/Path/App/FeatureArea.h | 200 +- src/Mod/Path/App/FeatureAreaPyImp.cpp | 218 +- src/Mod/Path/App/FeaturePath.cpp | 156 +- src/Mod/Path/App/FeaturePath.h | 144 +- src/Mod/Path/App/FeaturePathCompound.cpp | 262 +- src/Mod/Path/App/FeaturePathCompound.h | 144 +- src/Mod/Path/App/FeaturePathCompoundPy.xml | 56 +- src/Mod/Path/App/FeaturePathCompoundPyImp.cpp | 278 +- src/Mod/Path/App/FeaturePathShape.cpp | 220 +- src/Mod/Path/App/FeaturePathShape.h | 160 +- src/Mod/Path/App/Path.cpp | 996 +- src/Mod/Path/App/Path.h | 210 +- src/Mod/Path/App/PathPy.xml | 182 +- src/Mod/Path/App/PathPyImp.cpp | 480 +- src/Mod/Path/App/PreCompiled.cpp | 48 +- src/Mod/Path/App/PreCompiled.h | 266 +- src/Mod/Path/App/PropertyPath.cpp | 322 +- src/Mod/Path/App/PropertyPath.h | 154 +- src/Mod/Path/App/PropertyTool.cpp | 232 +- src/Mod/Path/App/PropertyTool.h | 150 +- src/Mod/Path/App/PropertyTooltable.cpp | 232 +- src/Mod/Path/App/PropertyTooltable.h | 150 +- src/Mod/Path/App/Tool.cpp | 514 +- src/Mod/Path/App/Tool.h | 208 +- src/Mod/Path/App/ToolPy.xml | 226 +- src/Mod/Path/App/ToolPyImp.cpp | 602 +- src/Mod/Path/App/Tooltable.cpp | 232 +- src/Mod/Path/App/Tooltable.h | 136 +- src/Mod/Path/App/TooltablePy.xml | 156 +- src/Mod/Path/App/TooltablePyImp.cpp | 576 +- .../container/detail/memory_util.hpp | 166 +- .../has_member_function_callable_with.hpp | 730 +- .../intrusive/detail/memory_util.hpp | 584 +- src/Mod/Path/Gui/AppPathGui.cpp | 186 +- src/Mod/Path/Gui/AppPathGuiPy.cpp | 586 +- src/Mod/Path/Gui/Command.cpp | 696 +- src/Mod/Path/Gui/PreCompiled.cpp | 46 +- src/Mod/Path/Gui/PreCompiled.h | 174 +- src/Mod/Path/Gui/Resources/Path.qrc | 324 +- .../Gui/Resources/icons/PathWorkbench.svg | 870 +- src/Mod/Path/Gui/TaskDlgPathCompound.cpp | 320 +- src/Mod/Path/Gui/TaskDlgPathCompound.h | 182 +- src/Mod/Path/Gui/ViewProviderArea.cpp | 394 +- src/Mod/Path/Gui/ViewProviderArea.h | 166 +- src/Mod/Path/Gui/ViewProviderPath.cpp | 1460 +-- src/Mod/Path/Gui/ViewProviderPath.h | 250 +- src/Mod/Path/Gui/ViewProviderPathCompound.cpp | 194 +- src/Mod/Path/Gui/ViewProviderPathCompound.h | 112 +- src/Mod/Path/Gui/ViewProviderPathShape.cpp | 228 +- src/Mod/Path/Gui/ViewProviderPathShape.h | 114 +- src/Mod/Path/Init.py | 64 +- src/Mod/Path/InitGui.py | 394 +- src/Mod/Path/PathScripts/PathAreaOp.py | 2018 ++-- src/Mod/Path/PathScripts/PathOp.py | 1162 +-- src/Mod/Path/PathScripts/PathSurface.py | 4162 ++++---- src/Mod/Path/PathScripts/PathWaterline.py | 3754 +++---- src/Mod/Path/PathScripts/post/nccad_post.py | 232 +- src/Mod/Path/libarea/Arc.cpp | 242 +- src/Mod/Path/libarea/Arc.h | 48 +- src/Mod/Path/libarea/Area.cpp | 1656 +-- src/Mod/Path/libarea/Area.h | 256 +- src/Mod/Path/libarea/AreaClipper.cpp | 1138 +-- src/Mod/Path/libarea/AreaDxf.cpp | 62 +- src/Mod/Path/libarea/AreaDxf.h | 46 +- src/Mod/Path/libarea/AreaOrderer.cpp | 334 +- src/Mod/Path/libarea/AreaOrderer.h | 134 +- src/Mod/Path/libarea/AreaPocket.cpp | 1072 +- src/Mod/Path/libarea/Box2D.h | 188 +- src/Mod/Path/libarea/Circle.cpp | 204 +- src/Mod/Path/libarea/Circle.h | 86 +- src/Mod/Path/libarea/Curve.cpp | 2644 ++--- src/Mod/Path/libarea/Curve.h | 260 +- src/Mod/Path/libarea/Point.h | 150 +- src/Mod/Path/libarea/PythonStuff.cpp | 1084 +- src/Mod/Path/libarea/PythonStuff.h | 20 +- src/Mod/Path/libarea/clipper.cpp | 8942 ++++++++--------- src/Mod/Path/libarea/clipper.hpp | 790 +- src/Mod/Path/libarea/dxf.cpp | 3270 +++--- src/Mod/Path/libarea/dxf.h | 316 +- src/Mod/Path/libarea/kurve/Construction.cpp | 1698 ++-- src/Mod/Path/libarea/kurve/Finite.cpp | 1308 +-- src/Mod/Path/libarea/kurve/Matrix.cpp | 1248 +-- src/Mod/Path/libarea/kurve/geometry.h | 1996 ++-- src/Mod/Path/libarea/kurve/kurve.cpp | 3040 +++--- src/Mod/Path/libarea/kurve/offset.cpp | 752 +- src/Mod/Path/libarea/kurve/test.py | 18 +- 96 files changed, 32403 insertions(+), 32403 deletions(-) diff --git a/src/Mod/.gitattributes b/src/Mod/.gitattributes index 4b723a0c4d..52d7eefe6d 100644 --- a/src/Mod/.gitattributes +++ b/src/Mod/.gitattributes @@ -77,6 +77,7 @@ JtReader export-ignore # Fem/** -text # Material/** -text # OpenSCAD/** -text +# Path/** -text # Show/** -text # Tux/** -text @@ -97,7 +98,6 @@ Mesh/** -text MeshPart/** -text Part/** -text PartDesign/** -text -Path/** -text Plot/** -text Points/** -text Raytracing/** -text diff --git a/src/Mod/Path/App/AppPath.cpp b/src/Mod/Path/App/AppPath.cpp index 2e93cd169b..3e08c68046 100644 --- a/src/Mod/Path/App/AppPath.cpp +++ b/src/Mod/Path/App/AppPath.cpp @@ -1,99 +1,99 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -#endif - -#include -#include -#include - -#include "Command.h" -#include "CommandPy.h" -#include "Path.h" -#include "PathPy.h" -#include "Tool.h" -#include "Tooltable.h" -#include "ToolPy.h" -#include "TooltablePy.h" -#include "PropertyPath.h" -#include "FeaturePath.h" -#include "PropertyTool.h" -#include "PropertyTooltable.h" -#include "FeaturePathCompound.h" -#include "FeaturePathShape.h" -#include "AreaPy.h" -#include "FeatureArea.h" - -namespace Path { -extern PyObject* initModule(); -} - -/* Python entry */ -PyMOD_INIT_FUNC(Path) -{ - // load dependent module - try { - Base::Interpreter().runString("import Part"); - } - catch(const Base::Exception& e) { - PyErr_SetString(PyExc_ImportError, e.what()); - PyMOD_Return(NULL); - } - - PyObject* pathModule = Path::initModule(); - Base::Console().Log("Loading Path module... done\n"); - - // Add Types to module - Base::Interpreter().addType(&Path::CommandPy ::Type, pathModule, "Command"); - Base::Interpreter().addType(&Path::PathPy ::Type, pathModule, "Path"); - Base::Interpreter().addType(&Path::ToolPy ::Type, pathModule, "Tool"); - Base::Interpreter().addType(&Path::TooltablePy ::Type, pathModule, "Tooltable"); - Base::Interpreter().addType(&Path::AreaPy ::Type, pathModule, "Area"); - - // NOTE: To finish the initialization of our own type objects we must - // call PyType_Ready, otherwise we run into a segmentation fault, later on. - // This function is responsible for adding inherited slots from a type's base class. - Path::Command ::init(); - Path::Toolpath ::init(); - Path::Tool ::init(); - Path::Tooltable ::init(); - Path::PropertyPath ::init(); - Path::Feature ::init(); - Path::FeaturePython ::init(); - Path::PropertyTool ::init(); - Path::PropertyTooltable ::init(); - Path::FeatureCompound ::init(); - Path::FeatureCompoundPython ::init(); - Path::FeatureShape ::init(); - Path::FeatureShapePython ::init(); - Path::Area ::init(); - Path::FeatureArea ::init(); - Path::FeatureAreaPython ::init(); - Path::FeatureAreaView ::init(); - Path::FeatureAreaViewPython ::init(); - - PyMOD_Return(pathModule); -} +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include + +#include "Command.h" +#include "CommandPy.h" +#include "Path.h" +#include "PathPy.h" +#include "Tool.h" +#include "Tooltable.h" +#include "ToolPy.h" +#include "TooltablePy.h" +#include "PropertyPath.h" +#include "FeaturePath.h" +#include "PropertyTool.h" +#include "PropertyTooltable.h" +#include "FeaturePathCompound.h" +#include "FeaturePathShape.h" +#include "AreaPy.h" +#include "FeatureArea.h" + +namespace Path { +extern PyObject* initModule(); +} + +/* Python entry */ +PyMOD_INIT_FUNC(Path) +{ + // load dependent module + try { + Base::Interpreter().runString("import Part"); + } + catch(const Base::Exception& e) { + PyErr_SetString(PyExc_ImportError, e.what()); + PyMOD_Return(NULL); + } + + PyObject* pathModule = Path::initModule(); + Base::Console().Log("Loading Path module... done\n"); + + // Add Types to module + Base::Interpreter().addType(&Path::CommandPy ::Type, pathModule, "Command"); + Base::Interpreter().addType(&Path::PathPy ::Type, pathModule, "Path"); + Base::Interpreter().addType(&Path::ToolPy ::Type, pathModule, "Tool"); + Base::Interpreter().addType(&Path::TooltablePy ::Type, pathModule, "Tooltable"); + Base::Interpreter().addType(&Path::AreaPy ::Type, pathModule, "Area"); + + // NOTE: To finish the initialization of our own type objects we must + // call PyType_Ready, otherwise we run into a segmentation fault, later on. + // This function is responsible for adding inherited slots from a type's base class. + Path::Command ::init(); + Path::Toolpath ::init(); + Path::Tool ::init(); + Path::Tooltable ::init(); + Path::PropertyPath ::init(); + Path::Feature ::init(); + Path::FeaturePython ::init(); + Path::PropertyTool ::init(); + Path::PropertyTooltable ::init(); + Path::FeatureCompound ::init(); + Path::FeatureCompoundPython ::init(); + Path::FeatureShape ::init(); + Path::FeatureShapePython ::init(); + Path::Area ::init(); + Path::FeatureArea ::init(); + Path::FeatureAreaPython ::init(); + Path::FeatureAreaView ::init(); + Path::FeatureAreaViewPython ::init(); + + PyMOD_Return(pathModule); +} diff --git a/src/Mod/Path/App/AppPathPy.cpp b/src/Mod/Path/App/AppPathPy.cpp index 381ef87ef6..72a496df8d 100644 --- a/src/Mod/Path/App/AppPathPy.cpp +++ b/src/Mod/Path/App/AppPathPy.cpp @@ -1,441 +1,441 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "CommandPy.h" -#include "PathPy.h" -#include "Path.h" -#include "FeaturePath.h" -#include "FeaturePathCompound.h" -#include "Area.h" - -#define PATH_CATCH catch (Standard_Failure &e) \ - { \ - std::string str; \ - Standard_CString msg = e.GetMessageString(); \ - str += typeid(e).name(); \ - str += " "; \ - if (msg) {str += msg;} \ - else {str += "No OCCT Exception Message";} \ - Base::Console().Error(str.c_str()); \ - PyErr_SetString(Part::PartExceptionOCCError,str.c_str()); \ - } \ - catch(Base::Exception &e) \ - { \ - std::string str; \ - str += "FreeCAD exception thrown ("; \ - str += e.what(); \ - str += ")"; \ - e.ReportException(); \ - PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());\ - } \ - catch(std::exception &e) \ - { \ - std::string str; \ - str += "STL exception thrown ("; \ - str += e.what(); \ - str += ")"; \ - Base::Console().Error(str.c_str()); \ - PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());\ - } \ - catch(const char *e) \ - { \ - PyErr_SetString(Base::BaseExceptionFreeCADError,e); \ - } throw Py::Exception(); - -namespace Path { -class Module : public Py::ExtensionModule -{ - -public: - - Module() : Py::ExtensionModule("Path") - { - add_varargs_method("write",&Module::write, - "write(object,filename): Exports a given path object to a GCode file" - ); - add_varargs_method("read",&Module::read, - "read(filename,[document]): Imports a GCode file into the given document" - ); - add_varargs_method("show",&Module::show, - "show(path,[string]): Add the path to the active document or create one if no document exists" - ); - add_varargs_method("fromShape",&Module::fromShape, - "fromShape(Shape): Returns a Path object from a Part Shape (deprecated - use fromShapes() instead)" - ); - add_keyword_method("fromShapes",&Module::fromShapes, - "fromShapes(shapes, start=Vector(), return_end=False" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_PATH) ")\n" - "\nReturns a Path object from a list of shapes\n" - "\n* shapes: input list of shapes.\n" - "\n* start (Vector()): feed start position, and also serves as a hint of path entry.\n" - "\n* return_end (False): if True, returns tuple (path, endPosition).\n" - PARAM_PY_DOC(ARG, AREA_PARAMS_PATH) - ); - add_keyword_method("sortWires",&Module::sortWires, - "sortWires(shapes, start=Vector(), " - PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_ARC_PLANE) - PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_SORT) ")\n" - "\nReturns (wires,end), where 'wires' is sorted across Z value and with optimized travel distance,\n" - "and 'end' is the ending position of the whole wires. If arc_plane==1, it returns (wires,end,arc_plane),\n" - "where arc_plane is the found plane if any, or unchanged.\n" - "\n* shapes: input shape list\n" - "\n* start (Vector()): optional start position.\n" - PARAM_PY_DOC(ARG, AREA_PARAMS_ARC_PLANE) - PARAM_PY_DOC(ARG, AREA_PARAMS_SORT) - ); - initialize("This module is the Path module."); // register with Python - } - - virtual ~Module() {} - -private: - - Py::Object write(const Py::Tuple& args) - { - char* Name; - PyObject* pObj; - if (!PyArg_ParseTuple(args.ptr(), "Oet",&pObj,"utf-8",&Name)) - throw Py::Exception(); - std::string EncodedName = std::string(Name); - PyMem_Free(Name); - Base::FileInfo file(EncodedName.c_str()); - - if (PyObject_TypeCheck(pObj, &(App::DocumentObjectPy::Type))) { - App::DocumentObject* obj = static_cast(pObj)->getDocumentObjectPtr(); - if (obj->getTypeId().isDerivedFrom(Base::Type::fromName("Path::Feature"))) { - const Toolpath& path = static_cast(obj)->Path.getValue(); - std::string gcode = path.toGCode(); - std::ofstream ofile(EncodedName.c_str()); - ofile << gcode; - ofile.close(); - } - else { - throw Py::RuntimeError("The given file is not a path"); - } - } - - return Py::None(); - } - - - Py::Object read(const Py::Tuple& args) - { - char* Name; - const char* DocName=0; - if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) - throw Py::Exception(); - std::string EncodedName = std::string(Name); - PyMem_Free(Name); - - Base::FileInfo file(EncodedName.c_str()); - if (!file.exists()) - throw Py::RuntimeError("File doesn't exist"); - - App::Document *pcDoc; - if (DocName) - pcDoc = App::GetApplication().getDocument(DocName); - else - pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) - pcDoc = App::GetApplication().newDocument(DocName); - - try { - // read the gcode file - std::ifstream filestr(file.filePath().c_str()); - std::stringstream buffer; - buffer << filestr.rdbuf(); - std::string gcode = buffer.str(); - Toolpath path; - path.setFromGCode(gcode); - Path::Feature *object = static_cast(pcDoc->addObject("Path::Feature",file.fileNamePure().c_str())); - object->Path.setValue(path); - pcDoc->recompute(); - } - catch (const Base::Exception& e) { - throw Py::RuntimeError(e.what()); - } - - return Py::None(); - } - - - Py::Object show(const Py::Tuple& args) - { - PyObject *pcObj; - char *name = "Path"; - if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(PathPy::Type), &pcObj, &name)) - throw Py::Exception(); - - try { - App::Document *pcDoc = App::GetApplication().getActiveDocument(); - if (!pcDoc) - pcDoc = App::GetApplication().newDocument(); - PathPy* pPath = static_cast(pcObj); - Path::Feature *pcFeature = static_cast(pcDoc->addObject("Path::Feature", name)); - Path::Toolpath* pa = pPath->getToolpathPtr(); - if (!pa) { - throw Py::Exception(PyExc_ReferenceError, "object doesn't reference a valid path"); - } - - // copy the data - pcFeature->Path.setValue(*pa); - } - catch (const Base::Exception& e) { - throw Py::RuntimeError(e.what()); - } - - return Py::None(); - } - - - Py::Object fromShape(const Py::Tuple& args) - { - PyObject *pcObj; - if (!PyArg_ParseTuple(args.ptr(), "O", &pcObj)) - throw Py::Exception(); - TopoDS_Shape shape; - try { - if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) { - shape = static_cast(pcObj)->getTopoShapePtr()->getShape(); - } else { - throw Py::TypeError("the given object is not a shape"); - } - if (!shape.IsNull()) { - if (shape.ShapeType() == TopAbs_WIRE) { - Path::Toolpath result; - bool first = true; - Base::Placement last; - - TopExp_Explorer ExpEdges (shape,TopAbs_EDGE); - while (ExpEdges.More()) { - const TopoDS_Edge& edge = TopoDS::Edge(ExpEdges.Current()); - TopExp_Explorer ExpVerts(edge,TopAbs_VERTEX); - bool vfirst = true; - while (ExpVerts.More()) { - const TopoDS_Vertex& vert = TopoDS::Vertex(ExpVerts.Current()); - gp_Pnt pnt = BRep_Tool::Pnt(vert); - Base::Placement tpl; - tpl.setPosition(Base::Vector3d(pnt.X(),pnt.Y(),pnt.Z())); - if (first) { - // add first point as a G0 move - Path::Command cmd; - std::ostringstream ctxt; - ctxt << "G0 X" << tpl.getPosition().x << " Y" << tpl.getPosition().y << " Z" << tpl.getPosition().z; - cmd.setFromGCode(ctxt.str()); - result.addCommand(cmd); - first = false; - vfirst = false; - } else { - if (vfirst) - vfirst = false; - else { - Path::Command cmd; - cmd.setFromPlacement(tpl); - - // write arc data if needed - BRepAdaptor_Curve adapt(edge); - if (adapt.GetType() == GeomAbs_Circle) { - gp_Circ circ = adapt.Circle(); - gp_Pnt c = circ.Location(); - bool clockwise = false; - gp_Dir n = circ.Axis().Direction(); - if (n.Z() < 0) - clockwise = true; - Base::Vector3d center = Base::Vector3d(c.X(),c.Y(),c.Z()); - // center coords must be relative to last point - center -= last.getPosition(); - cmd.setCenter(center,clockwise); - } - result.addCommand(cmd); - } - } - ExpVerts.Next(); - last = tpl; - } - ExpEdges.Next(); - } - return Py::asObject(new PathPy(new Path::Toolpath(result))); - } else { - throw Py::TypeError("the given shape must be a wire"); - } - } else { - throw Py::TypeError("the given shape is empty"); - } - } - catch (const Base::Exception& e) { - throw Py::RuntimeError(e.what()); - } - } - - Py::Object fromShapes(const Py::Tuple& args, const Py::Dict &kwds) - { - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_PATH) - PyObject *pShapes=NULL; - PyObject *start=NULL; - PyObject *return_end=Py_False; - static char* kwd_list[] = {"shapes", "start", "return_end", - PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_PATH), NULL}; - if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), - "O|O!O" PARAM_PY_KWDS(AREA_PARAMS_PATH), - kwd_list, &pShapes, &(Base::VectorPy::Type), &start, &return_end, - PARAM_REF(PARAM_FARG,AREA_PARAMS_PATH))) - throw Py::Exception(); - - std::list shapes; - if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type))) - shapes.push_back(static_cast(pShapes)->getTopoShapePtr()->getShape()); - else if (PyObject_TypeCheck(pShapes, &(PyList_Type)) || - PyObject_TypeCheck(pShapes, &(PyTuple_Type))) - { - Py::Sequence shapeSeq(pShapes); - for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { - PyObject* item = (*it).ptr(); - if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { - PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); - throw Py::Exception(); - } - shapes.push_back(static_cast(item)->getTopoShapePtr()->getShape()); - } - } - - gp_Pnt pstart; - if(start) { - Base::Vector3d vec = static_cast(start)->value(); - pstart.SetCoord(vec.x, vec.y, vec.z); - } - - try { - gp_Pnt pend; - std::unique_ptr path(new Toolpath); - Area::toPath(*path,shapes,start?&pstart:0, &pend, - PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_PATH)); - if(!PyObject_IsTrue(return_end)) - return Py::asObject(new PathPy(path.release())); - Py::Tuple tuple(2); - tuple.setItem(0, Py::asObject(new PathPy(path.release()))); - tuple.setItem(1, Py::asObject(new Base::VectorPy(Base::Vector3d(pend.X(),pend.Y(),pend.Z())))); - return tuple; - } PATH_CATCH - } - - Py::Object sortWires(const Py::Tuple& args, const Py::Dict &kwds) - { - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_ARC_PLANE) - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_SORT) - PyObject *pShapes=NULL; - PyObject *start=NULL; - static char* kwd_list[] = {"shapes", "start", - PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_ARC_PLANE), - PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_SORT), NULL}; - if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), - "O|O!" - PARAM_PY_KWDS(AREA_PARAMS_ARC_PLANE) - PARAM_PY_KWDS(AREA_PARAMS_SORT), - kwd_list, &pShapes, &(Base::VectorPy::Type), &start, - PARAM_REF(PARAM_FARG,AREA_PARAMS_ARC_PLANE), - PARAM_REF(PARAM_FARG,AREA_PARAMS_SORT))) - throw Py::Exception(); - - std::list shapes; - if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type))) - shapes.push_back(static_cast(pShapes)->getTopoShapePtr()->getShape()); - else if (PyObject_TypeCheck(pShapes, &(PyList_Type)) || - PyObject_TypeCheck(pShapes, &(PyTuple_Type))) { - Py::Sequence shapeSeq(pShapes); - for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { - PyObject* item = (*it).ptr(); - if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { - PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); - throw Py::Exception(); - } - shapes.push_back(static_cast(item)->getTopoShapePtr()->getShape()); - } - } - - gp_Pnt pstart,pend; - if(start) { - Base::Vector3d vec = static_cast(start)->value(); - pstart.SetCoord(vec.x, vec.y, vec.z); - } - - try { - bool need_arc_plane = arc_plane==Area::ArcPlaneAuto; - std::list wires = Area::sortWires(shapes,start!=0,&pstart, - &pend, 0, &arc_plane, PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SORT)); - PyObject *list = PyList_New(0); - for(auto &wire : wires) - PyList_Append(list,Py::new_reference_to( - Part::shape2pyshape(TopoDS::Wire(wire)))); - PyObject *ret = PyTuple_New(need_arc_plane?3:2); - PyTuple_SetItem(ret,0,list); - PyTuple_SetItem(ret,1,new Base::VectorPy( - Base::Vector3d(pend.X(),pend.Y(),pend.Z()))); - if(need_arc_plane) -#if PY_MAJOR_VERSION < 3 - PyTuple_SetItem(ret,2,PyInt_FromLong(arc_plane)); -#else - PyTuple_SetItem(ret,2,PyLong_FromLong(arc_plane)); -#endif - return Py::asObject(ret); - } PATH_CATCH - } -}; - -PyObject* initModule() -{ - return (new Module)->module().ptr(); -} - -} // namespace Path +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "CommandPy.h" +#include "PathPy.h" +#include "Path.h" +#include "FeaturePath.h" +#include "FeaturePathCompound.h" +#include "Area.h" + +#define PATH_CATCH catch (Standard_Failure &e) \ + { \ + std::string str; \ + Standard_CString msg = e.GetMessageString(); \ + str += typeid(e).name(); \ + str += " "; \ + if (msg) {str += msg;} \ + else {str += "No OCCT Exception Message";} \ + Base::Console().Error(str.c_str()); \ + PyErr_SetString(Part::PartExceptionOCCError,str.c_str()); \ + } \ + catch(Base::Exception &e) \ + { \ + std::string str; \ + str += "FreeCAD exception thrown ("; \ + str += e.what(); \ + str += ")"; \ + e.ReportException(); \ + PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());\ + } \ + catch(std::exception &e) \ + { \ + std::string str; \ + str += "STL exception thrown ("; \ + str += e.what(); \ + str += ")"; \ + Base::Console().Error(str.c_str()); \ + PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());\ + } \ + catch(const char *e) \ + { \ + PyErr_SetString(Base::BaseExceptionFreeCADError,e); \ + } throw Py::Exception(); + +namespace Path { +class Module : public Py::ExtensionModule +{ + +public: + + Module() : Py::ExtensionModule("Path") + { + add_varargs_method("write",&Module::write, + "write(object,filename): Exports a given path object to a GCode file" + ); + add_varargs_method("read",&Module::read, + "read(filename,[document]): Imports a GCode file into the given document" + ); + add_varargs_method("show",&Module::show, + "show(path,[string]): Add the path to the active document or create one if no document exists" + ); + add_varargs_method("fromShape",&Module::fromShape, + "fromShape(Shape): Returns a Path object from a Part Shape (deprecated - use fromShapes() instead)" + ); + add_keyword_method("fromShapes",&Module::fromShapes, + "fromShapes(shapes, start=Vector(), return_end=False" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_PATH) ")\n" + "\nReturns a Path object from a list of shapes\n" + "\n* shapes: input list of shapes.\n" + "\n* start (Vector()): feed start position, and also serves as a hint of path entry.\n" + "\n* return_end (False): if True, returns tuple (path, endPosition).\n" + PARAM_PY_DOC(ARG, AREA_PARAMS_PATH) + ); + add_keyword_method("sortWires",&Module::sortWires, + "sortWires(shapes, start=Vector(), " + PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_ARC_PLANE) + PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_SORT) ")\n" + "\nReturns (wires,end), where 'wires' is sorted across Z value and with optimized travel distance,\n" + "and 'end' is the ending position of the whole wires. If arc_plane==1, it returns (wires,end,arc_plane),\n" + "where arc_plane is the found plane if any, or unchanged.\n" + "\n* shapes: input shape list\n" + "\n* start (Vector()): optional start position.\n" + PARAM_PY_DOC(ARG, AREA_PARAMS_ARC_PLANE) + PARAM_PY_DOC(ARG, AREA_PARAMS_SORT) + ); + initialize("This module is the Path module."); // register with Python + } + + virtual ~Module() {} + +private: + + Py::Object write(const Py::Tuple& args) + { + char* Name; + PyObject* pObj; + if (!PyArg_ParseTuple(args.ptr(), "Oet",&pObj,"utf-8",&Name)) + throw Py::Exception(); + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + Base::FileInfo file(EncodedName.c_str()); + + if (PyObject_TypeCheck(pObj, &(App::DocumentObjectPy::Type))) { + App::DocumentObject* obj = static_cast(pObj)->getDocumentObjectPtr(); + if (obj->getTypeId().isDerivedFrom(Base::Type::fromName("Path::Feature"))) { + const Toolpath& path = static_cast(obj)->Path.getValue(); + std::string gcode = path.toGCode(); + std::ofstream ofile(EncodedName.c_str()); + ofile << gcode; + ofile.close(); + } + else { + throw Py::RuntimeError("The given file is not a path"); + } + } + + return Py::None(); + } + + + Py::Object read(const Py::Tuple& args) + { + char* Name; + const char* DocName=0; + if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName)) + throw Py::Exception(); + std::string EncodedName = std::string(Name); + PyMem_Free(Name); + + Base::FileInfo file(EncodedName.c_str()); + if (!file.exists()) + throw Py::RuntimeError("File doesn't exist"); + + App::Document *pcDoc; + if (DocName) + pcDoc = App::GetApplication().getDocument(DocName); + else + pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) + pcDoc = App::GetApplication().newDocument(DocName); + + try { + // read the gcode file + std::ifstream filestr(file.filePath().c_str()); + std::stringstream buffer; + buffer << filestr.rdbuf(); + std::string gcode = buffer.str(); + Toolpath path; + path.setFromGCode(gcode); + Path::Feature *object = static_cast(pcDoc->addObject("Path::Feature",file.fileNamePure().c_str())); + object->Path.setValue(path); + pcDoc->recompute(); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } + + return Py::None(); + } + + + Py::Object show(const Py::Tuple& args) + { + PyObject *pcObj; + char *name = "Path"; + if (!PyArg_ParseTuple(args.ptr(), "O!|s", &(PathPy::Type), &pcObj, &name)) + throw Py::Exception(); + + try { + App::Document *pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) + pcDoc = App::GetApplication().newDocument(); + PathPy* pPath = static_cast(pcObj); + Path::Feature *pcFeature = static_cast(pcDoc->addObject("Path::Feature", name)); + Path::Toolpath* pa = pPath->getToolpathPtr(); + if (!pa) { + throw Py::Exception(PyExc_ReferenceError, "object doesn't reference a valid path"); + } + + // copy the data + pcFeature->Path.setValue(*pa); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } + + return Py::None(); + } + + + Py::Object fromShape(const Py::Tuple& args) + { + PyObject *pcObj; + if (!PyArg_ParseTuple(args.ptr(), "O", &pcObj)) + throw Py::Exception(); + TopoDS_Shape shape; + try { + if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) { + shape = static_cast(pcObj)->getTopoShapePtr()->getShape(); + } else { + throw Py::TypeError("the given object is not a shape"); + } + if (!shape.IsNull()) { + if (shape.ShapeType() == TopAbs_WIRE) { + Path::Toolpath result; + bool first = true; + Base::Placement last; + + TopExp_Explorer ExpEdges (shape,TopAbs_EDGE); + while (ExpEdges.More()) { + const TopoDS_Edge& edge = TopoDS::Edge(ExpEdges.Current()); + TopExp_Explorer ExpVerts(edge,TopAbs_VERTEX); + bool vfirst = true; + while (ExpVerts.More()) { + const TopoDS_Vertex& vert = TopoDS::Vertex(ExpVerts.Current()); + gp_Pnt pnt = BRep_Tool::Pnt(vert); + Base::Placement tpl; + tpl.setPosition(Base::Vector3d(pnt.X(),pnt.Y(),pnt.Z())); + if (first) { + // add first point as a G0 move + Path::Command cmd; + std::ostringstream ctxt; + ctxt << "G0 X" << tpl.getPosition().x << " Y" << tpl.getPosition().y << " Z" << tpl.getPosition().z; + cmd.setFromGCode(ctxt.str()); + result.addCommand(cmd); + first = false; + vfirst = false; + } else { + if (vfirst) + vfirst = false; + else { + Path::Command cmd; + cmd.setFromPlacement(tpl); + + // write arc data if needed + BRepAdaptor_Curve adapt(edge); + if (adapt.GetType() == GeomAbs_Circle) { + gp_Circ circ = adapt.Circle(); + gp_Pnt c = circ.Location(); + bool clockwise = false; + gp_Dir n = circ.Axis().Direction(); + if (n.Z() < 0) + clockwise = true; + Base::Vector3d center = Base::Vector3d(c.X(),c.Y(),c.Z()); + // center coords must be relative to last point + center -= last.getPosition(); + cmd.setCenter(center,clockwise); + } + result.addCommand(cmd); + } + } + ExpVerts.Next(); + last = tpl; + } + ExpEdges.Next(); + } + return Py::asObject(new PathPy(new Path::Toolpath(result))); + } else { + throw Py::TypeError("the given shape must be a wire"); + } + } else { + throw Py::TypeError("the given shape is empty"); + } + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } + } + + Py::Object fromShapes(const Py::Tuple& args, const Py::Dict &kwds) + { + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_PATH) + PyObject *pShapes=NULL; + PyObject *start=NULL; + PyObject *return_end=Py_False; + static char* kwd_list[] = {"shapes", "start", "return_end", + PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_PATH), NULL}; + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), + "O|O!O" PARAM_PY_KWDS(AREA_PARAMS_PATH), + kwd_list, &pShapes, &(Base::VectorPy::Type), &start, &return_end, + PARAM_REF(PARAM_FARG,AREA_PARAMS_PATH))) + throw Py::Exception(); + + std::list shapes; + if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type))) + shapes.push_back(static_cast(pShapes)->getTopoShapePtr()->getShape()); + else if (PyObject_TypeCheck(pShapes, &(PyList_Type)) || + PyObject_TypeCheck(pShapes, &(PyTuple_Type))) + { + Py::Sequence shapeSeq(pShapes); + for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { + PyObject* item = (*it).ptr(); + if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { + PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); + throw Py::Exception(); + } + shapes.push_back(static_cast(item)->getTopoShapePtr()->getShape()); + } + } + + gp_Pnt pstart; + if(start) { + Base::Vector3d vec = static_cast(start)->value(); + pstart.SetCoord(vec.x, vec.y, vec.z); + } + + try { + gp_Pnt pend; + std::unique_ptr path(new Toolpath); + Area::toPath(*path,shapes,start?&pstart:0, &pend, + PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_PATH)); + if(!PyObject_IsTrue(return_end)) + return Py::asObject(new PathPy(path.release())); + Py::Tuple tuple(2); + tuple.setItem(0, Py::asObject(new PathPy(path.release()))); + tuple.setItem(1, Py::asObject(new Base::VectorPy(Base::Vector3d(pend.X(),pend.Y(),pend.Z())))); + return tuple; + } PATH_CATCH + } + + Py::Object sortWires(const Py::Tuple& args, const Py::Dict &kwds) + { + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_ARC_PLANE) + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_SORT) + PyObject *pShapes=NULL; + PyObject *start=NULL; + static char* kwd_list[] = {"shapes", "start", + PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_ARC_PLANE), + PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_SORT), NULL}; + if (!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), + "O|O!" + PARAM_PY_KWDS(AREA_PARAMS_ARC_PLANE) + PARAM_PY_KWDS(AREA_PARAMS_SORT), + kwd_list, &pShapes, &(Base::VectorPy::Type), &start, + PARAM_REF(PARAM_FARG,AREA_PARAMS_ARC_PLANE), + PARAM_REF(PARAM_FARG,AREA_PARAMS_SORT))) + throw Py::Exception(); + + std::list shapes; + if (PyObject_TypeCheck(pShapes, &(Part::TopoShapePy::Type))) + shapes.push_back(static_cast(pShapes)->getTopoShapePtr()->getShape()); + else if (PyObject_TypeCheck(pShapes, &(PyList_Type)) || + PyObject_TypeCheck(pShapes, &(PyTuple_Type))) { + Py::Sequence shapeSeq(pShapes); + for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { + PyObject* item = (*it).ptr(); + if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { + PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); + throw Py::Exception(); + } + shapes.push_back(static_cast(item)->getTopoShapePtr()->getShape()); + } + } + + gp_Pnt pstart,pend; + if(start) { + Base::Vector3d vec = static_cast(start)->value(); + pstart.SetCoord(vec.x, vec.y, vec.z); + } + + try { + bool need_arc_plane = arc_plane==Area::ArcPlaneAuto; + std::list wires = Area::sortWires(shapes,start!=0,&pstart, + &pend, 0, &arc_plane, PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SORT)); + PyObject *list = PyList_New(0); + for(auto &wire : wires) + PyList_Append(list,Py::new_reference_to( + Part::shape2pyshape(TopoDS::Wire(wire)))); + PyObject *ret = PyTuple_New(need_arc_plane?3:2); + PyTuple_SetItem(ret,0,list); + PyTuple_SetItem(ret,1,new Base::VectorPy( + Base::Vector3d(pend.X(),pend.Y(),pend.Z()))); + if(need_arc_plane) +#if PY_MAJOR_VERSION < 3 + PyTuple_SetItem(ret,2,PyInt_FromLong(arc_plane)); +#else + PyTuple_SetItem(ret,2,PyLong_FromLong(arc_plane)); +#endif + return Py::asObject(ret); + } PATH_CATCH + } +}; + +PyObject* initModule() +{ + return (new Module)->module().ptr(); +} + +} // namespace Path diff --git a/src/Mod/Path/App/AreaPy.xml b/src/Mod/Path/App/AreaPy.xml index 79b65ae177..6061a3976b 100644 --- a/src/Mod/Path/App/AreaPy.xml +++ b/src/Mod/Path/App/AreaPy.xml @@ -1,107 +1,107 @@ - - - - - - FreeCAD python wrapper of libarea\n -Path.Area(key=value ...)\n -The constructor accepts the same parameters as setParams(...) to configure the object -All arguments are optional. - - - - - - - - - setPlane(shape): Set the working plane.\n -The supplied shape does not need to be planar. Area will try to find planar -sub-shape (face, wire or edge). If more than one planar sub-shape is found, it -will prefer the top plane parallel to XY0 plane. If no working plane are set, -Area will try to find a working plane from the added children shape using the -same algorithm - - - - - getShape(index=-1,rebuild=False): Return the resulting shape\n -\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n -\n* rebuild: clean the internal cache and rebuild - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Get current algorithm parameters as a dictionary. - - - - - - - - - - List of sections in this area. - - - - - - The current workplane. If no plane is set, it is derived from the added shapes. - - - - - - A list of tuple: [(shape,op), ...] containing the added shapes together with their operation code - - - - - + + + + + + FreeCAD python wrapper of libarea\n +Path.Area(key=value ...)\n +The constructor accepts the same parameters as setParams(...) to configure the object +All arguments are optional. + + + + + + + + + setPlane(shape): Set the working plane.\n +The supplied shape does not need to be planar. Area will try to find planar +sub-shape (face, wire or edge). If more than one planar sub-shape is found, it +will prefer the top plane parallel to XY0 plane. If no working plane are set, +Area will try to find a working plane from the added children shape using the +same algorithm + + + + + getShape(index=-1,rebuild=False): Return the resulting shape\n +\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n +\n* rebuild: clean the internal cache and rebuild + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get current algorithm parameters as a dictionary. + + + + + + + + + + List of sections in this area. + + + + + + The current workplane. If no plane is set, it is derived from the added shapes. + + + + + + A list of tuple: [(shape,op), ...] containing the added shapes together with their operation code + + + + + diff --git a/src/Mod/Path/App/AreaPyImp.cpp b/src/Mod/Path/App/AreaPyImp.cpp index 9918db25f5..5f73d45648 100644 --- a/src/Mod/Path/App/AreaPyImp.cpp +++ b/src/Mod/Path/App/AreaPyImp.cpp @@ -1,488 +1,488 @@ -/**************************************************************************** - * Copyright (c) 2017 Zheng, Lei (realthunder) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#include "PreCompiled.h" - -#include -#include -#include - -#include "Area.h" - -// inclusion of the generated files (generated out of AreaPy.xml) -#include "AreaPy.h" -#include "AreaPy.cpp" - - -static PyObject * areaAbort(PyObject *, PyObject *args, PyObject *kwd) { - static char *kwlist[] = {"aborting", NULL}; - PyObject *pObj = Py_True; - if (!PyArg_ParseTupleAndKeywords(args,kwd,"|O",kwlist,&pObj)) - return 0; - Area::abort(PyObject_IsTrue(pObj)); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * areaSetParams(PyObject *, PyObject *args, PyObject *kwd) { - - static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_STATIC_CONF),NULL}; - - if(args && PySequence_Size(args)>0) - PyErr_SetString(PyExc_ValueError,"Non-keyword argument is not supported"); - - //Declare variables defined in the NAME field of the CONF parameter list - PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_STATIC_CONF); - - AreaStaticParams params = Area::getDefaultParams(); - -#define AREA_SET(_param) \ - PARAM_FNAME(_param) = \ - PARAM_TYPED(PARAM_PY_CAST_,_param)(params.PARAM_FNAME(_param)); - //populate the CONF variables with params - PARAM_FOREACH(AREA_SET,AREA_PARAMS_STATIC_CONF) - - //Parse arguments to overwrite CONF variables - if (!PyArg_ParseTupleAndKeywords(args, kwd, - "|" PARAM_PY_KWDS(AREA_PARAMS_STATIC_CONF), kwlist, - PARAM_REF(PARAM_FNAME,AREA_PARAMS_STATIC_CONF))) - return 0; - -#define AREA_GET(_param) \ - params.PARAM_FNAME(_param) = \ - PARAM_TYPED(PARAM_CAST_PY_,_param)(PARAM_FNAME(_param)); - //populate 'params' with the CONF variables - PARAM_FOREACH(AREA_GET,AREA_PARAMS_STATIC_CONF) - - Area::setDefaultParams(params); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject* areaGetParams(PyObject *, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) - return 0; - - const AreaStaticParams ¶ms = Area::getDefaultParams(); - - PyObject *dict = PyDict_New(); -#define AREA_SRC(_param) params.PARAM_FNAME(_param) - PARAM_PY_DICT_SET_VALUE(dict,NAME,AREA_SRC,AREA_PARAMS_STATIC_CONF) - return dict; -} - -static PyObject * areaGetParamsDesc(PyObject *, PyObject *args, PyObject *kwd) { - PyObject *pcObj = Py_False; - static char *kwlist[] = {"as_string", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O",kwlist,&pcObj)) - return 0; - -#if PY_MAJOR_VERSION < 3 - if(PyObject_IsTrue(pcObj)) - return PyString_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF)); -#else - if(PyObject_IsTrue(pcObj)) - return PyUnicode_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF)); -#endif - PyObject *dict = PyDict_New(); - PARAM_PY_DICT_SET_DOC(dict,NAME,AREA_PARAMS_STATIC_CONF) - return dict; -} - -static const PyMethodDef areaOverrides[] = { - { - "setParams",NULL,0, - "setParam(key=value...): Set algorithm parameters. You can call getParamsDesc() to \n" - "get a list of supported parameters and their descriptions.\n" - PARAM_PY_DOC(NAME,AREA_PARAMS_CONF) - }, - { - "add",NULL,0, - "add((shape...)," PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OPCODE) "):\n" - "Add TopoShape(s) with given operation code\n" - PARAM_PY_DOC(ARG,AREA_PARAMS_OPCODE) - "\nThe first shape's wires will be unioned together regardless of the op code given\n" - "(except for 'Compound'). Subsequent shape's wire will be combined using the op code.\n" - "All shape wires shall be coplanar, and are used to determine a working plane for face\n" - "making and offsetting. You can call setPlane() to supply a reference shape to determine\n" - "the workplane in case the added shapes are all colinear lines.\n", - }, - - { - "makeOffset",NULL,0, - "makeOffset(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OFFSET) "):\n" - "Make an 2D offset of the shape.\n" - "\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n" - PARAM_PY_DOC(ARG,AREA_PARAMS_OFFSET), - }, - { - "makePocket",NULL,0, - "makePocket(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_POCKET) "):\n" - "Generate pocket toolpath of the shape.\n" - "\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n" - PARAM_PY_DOC(ARG,AREA_PARAMS_POCKET), - }, - { - "makeSections",NULL,0, - "makeSections(" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_SECTION_EXTRA) ", heights=[], plane=None):\n" - "Make a list of area holding the sectioned children shapes on given heights\n" - PARAM_PY_DOC(ARG,AREA_PARAMS_SECTION_EXTRA) - "\n* heights ([]): a list of section heights, the meaning of the value is determined by 'mode'.\n" - "If not specified, the current SectionCount, and SectionOffset of this Area is used.\n" - "\n* plane (None): optional shape to specify a section plane. If not give, the current workplane\n" - "of this Area is used if section mode is 'Workplane'.", - }, - { - "setDefaultParams",reinterpret_cast(reinterpret_cast(areaSetParams)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, - "setDefaultParams(key=value...):\n" - "Static method to set the default parameters of all following Path.Area, plus the following\n" - "additional parameters.\n" - }, - { - "getDefaultParams",(PyCFunction)areaGetParams, METH_VARARGS|METH_STATIC, - "getDefaultParams(): Static method to return the current default parameters." - }, - { - "abort",reinterpret_cast(reinterpret_cast(areaAbort)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, - "abort(aborting=True): Static method to abort any ongoing operation\n" - "\nTo ensure no stray abortion is left in the previous operation, it is advised to manually clear\n" - "the aborting flag by calling abort(False) before starting a new operation.", - }, - { - "getParamsDesc",reinterpret_cast(reinterpret_cast(areaGetParamsDesc)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, - "getParamsDesc(as_string=False): Returns a list of supported parameters and their descriptions.\n" - "\n* as_string: if False, then return a dictionary of documents of all supported parameters." - }, -}; - -struct AreaPyModifier { - AreaPyModifier() { - for(auto &method : Path::AreaPy::Methods) { - if(!method.ml_name) continue; - for(auto &entry : areaOverrides) { - if(std::strcmp(method.ml_name,entry.ml_name)==0) { - if(entry.ml_doc) - method.ml_doc = entry.ml_doc; - if(entry.ml_meth) - method.ml_meth = entry.ml_meth; - if(entry.ml_flags) - method.ml_flags = entry.ml_flags; - break; - } - } - } - } -}; - -static AreaPyModifier mod; - -using namespace Path; - -// returns a string which represents the object e.g. when printed in python -std::string AreaPy::representation(void) const -{ - std::stringstream str; - str << ""; - return str.str(); -} - -PyObject *AreaPy::PyMake(struct _typeobject *, PyObject *args, PyObject *kwd) // Python wrapper -{ - AreaPy* ret = new AreaPy(new Area); - if(!ret->setParams(args,kwd)) { - Py_DecRef(ret); - return 0; - } - return ret; -} - -// constructor method -int AreaPy::PyInit(PyObject* , PyObject* ) -{ - return 0; -} - -PyObject* AreaPy::setPlane(PyObject *args) { - PyObject *pcObj; - if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj)) - return 0; - -#define GET_TOPOSHAPE(_p) static_cast(_p)->getTopoShapePtr()->getShape() - getAreaPtr()->setPlane(GET_TOPOSHAPE(pcObj)); - Py_INCREF(this); - return this; -} - -PyObject* AreaPy::getShape(PyObject *args, PyObject *keywds) -{ - PyObject *pcObj = Py_False; - short index=-1; - static char *kwlist[] = {"index","rebuild", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, keywds,"|hO",kwlist,&index,&pcObj)) - return 0; - - PY_TRY { - if(PyObject_IsTrue(pcObj)) - getAreaPtr()->clean(); - return Py::new_reference_to(Part::shape2pyshape(getAreaPtr()->getShape(index))); - } PY_CATCH_OCC -} - -PyObject* AreaPy::add(PyObject *args, PyObject *keywds) -{ - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_OPCODE) - PyObject *pcObj; - - //Strangely, PyArg_ParseTupleAndKeywords requires all arguments to be keyword based, - //even non-optional ones? That doesn't make sense in python. Seems only in python 3 - //they added '$' to address that issue. - static char *kwlist[] = {"shape",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OPCODE), NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "O|" PARAM_PY_KWDS(AREA_PARAMS_OPCODE), - kwlist,&pcObj,PARAM_REF(PARAM_FARG,AREA_PARAMS_OPCODE))) - return 0; - - PY_TRY { - if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) { - getAreaPtr()->add(GET_TOPOSHAPE(pcObj),op); - Py_INCREF(this); - return this; - } else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || - PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { - Py::Sequence shapeSeq(pcObj); - for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { - PyObject* item = (*it).ptr(); - if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { - PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); - return 0; - } - } - for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it){ - PyObject* item = (*it).ptr(); - getAreaPtr()->add(GET_TOPOSHAPE(item), - PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OPCODE)); - } - Py_INCREF(this); - return this; - } - } PY_CATCH_OCC - - PyErr_SetString(PyExc_TypeError, "shape must be 'TopoShape' or list of 'TopoShape'"); - return 0; -} - -PyObject* AreaPy::makeOffset(PyObject *args, PyObject *keywds) -{ - //Generate a keyword string defined in the ARG field of OFFSET parameter list - static char *kwlist[] = {"index",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OFFSET), NULL}; - short index = -1; - - //Declare variables defined in the ARG field of the OFFSET parameter list with - //initialization to defaults - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_OFFSET) - - //Parse arguments to overwrite the defaults - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "|h" PARAM_PY_KWDS(AREA_PARAMS_OFFSET), kwlist, - &index,PARAM_REF(PARAM_FARG,AREA_PARAMS_OFFSET))) - return 0; - - PY_TRY { - //Expand the variable as function call arguments - TopoDS_Shape resultShape = getAreaPtr()->makeOffset(index, - PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET)); - return Py::new_reference_to(Part::shape2pyshape(resultShape)); - } PY_CATCH_OCC -} - -PyObject* AreaPy::makePocket(PyObject *args, PyObject *keywds) -{ - static char *kwlist[] = {"index",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_POCKET), NULL}; - short index = -1; - - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_POCKET) - //Override pocket mode default - mode = Area::PocketModeZigZagOffset; - - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "|h" PARAM_PY_KWDS(AREA_PARAMS_POCKET), kwlist, - &index,PARAM_REF(PARAM_FARG,AREA_PARAMS_POCKET))) - return 0; - - PY_TRY { - TopoDS_Shape resultShape = getAreaPtr()->makePocket(index, - PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET)); - return Py::new_reference_to(Part::shape2pyshape(resultShape)); - } PY_CATCH_OCC -} - -PyObject* AreaPy::makeSections(PyObject *args, PyObject *keywds) -{ - static char *kwlist[] = {PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_SECTION_EXTRA), - "heights", "plane", NULL}; - PyObject *heights = NULL; - PyObject *plane = NULL; - - PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA) - - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "|" PARAM_PY_KWDS(AREA_PARAMS_SECTION_EXTRA) "OO!", kwlist, - PARAM_REF(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA), - &heights, &(Part::TopoShapePy::Type), &plane)) - return 0; - - PY_TRY { - std::vector h; - if(heights) { - if (PyObject_TypeCheck(heights, &(PyFloat_Type))) - h.push_back(PyFloat_AsDouble(heights)); - else if (PyObject_TypeCheck(heights, &(PyList_Type)) || - PyObject_TypeCheck(heights, &(PyTuple_Type))) { - Py::Sequence shapeSeq(heights); - h.reserve(shapeSeq.size()); - for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { - PyObject* item = (*it).ptr(); - if(!PyObject_TypeCheck(item, &(PyFloat_Type))) { - PyErr_SetString(PyExc_TypeError, "heights must only contain float type"); - return 0; - } - h.push_back(PyFloat_AsDouble(item)); - } - }else{ - PyErr_SetString(PyExc_TypeError, "heights must be of type float or list/tuple of float"); - return 0; - } - } - - std::vector > sections = getAreaPtr()->makeSections( - PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA), - h,plane?GET_TOPOSHAPE(plane):TopoDS_Shape()); - - Py::List ret; - for(auto &area : sections) - ret.append(Py::asObject(new AreaPy(new Area(*area,true)))); - return Py::new_reference_to(ret); - } PY_CATCH_OCC -} - -PyObject* AreaPy::setDefaultParams(PyObject *, PyObject *) -{ - return 0; -} - -PyObject* AreaPy::setParams(PyObject *args, PyObject *keywds) -{ - static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_CONF),NULL}; - - //Declare variables defined in the NAME field of the CONF parameter list - PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_CONF); - - AreaParams params = getAreaPtr()->getParams(); - - //populate the CONF variables with params - PARAM_FOREACH(AREA_SET,AREA_PARAMS_CONF) - - //Parse arguments to overwrite CONF variables - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, - PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) - return 0; - - PY_TRY { - //populate 'params' with the CONF variables - PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF) - - getAreaPtr()->setParams(params); - Py_INCREF(this); - return this; - } PY_CATCH_OCC -} - -PyObject* AreaPy::getParams(PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return 0; - - const AreaParams ¶ms =getAreaPtr()->getParams(); - - PyObject *dict = PyDict_New(); - PARAM_PY_DICT_SET_VALUE(dict,NAME,AREA_SRC,AREA_PARAMS_CONF) - return dict; -} - -PyObject* AreaPy::getDefaultParams(PyObject *) -{ - return 0; -} - -PyObject* AreaPy::abort(PyObject *, PyObject *) { - return 0; -} - -PyObject* AreaPy::getParamsDesc(PyObject *, PyObject *) -{ - return 0; -} - -Py::List AreaPy::getSections(void) const { - Py::List ret; - Area *area = getAreaPtr(); - for(size_t i=0,count=area->getSectionCount(); igetShape(i))); - return ret; -} - -Py::List AreaPy::getShapes(void) const { - Py::List ret; - Area *area = getAreaPtr(); - const std::list &shapes = area->getChildren(); - for(auto &s : shapes) - ret.append(Py::TupleN(Part::shape2pyshape(s.shape),Py::Int(s.op))); - return ret; -} - -Py::Object AreaPy::getWorkplane(void) const { - return Part::shape2pyshape(getAreaPtr()->getPlane()); -} - -void AreaPy::setWorkplane(Py::Object obj) { - PyObject* p = obj.ptr(); - if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) { - std::string error = std::string("type must be 'TopoShape', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - getAreaPtr()->setPlane(GET_TOPOSHAPE(p)); -} - -// custom attributes get/set - -PyObject *AreaPy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - -int AreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} +/**************************************************************************** + * Copyright (c) 2017 Zheng, Lei (realthunder) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ****************************************************************************/ + +#include "PreCompiled.h" + +#include +#include +#include + +#include "Area.h" + +// inclusion of the generated files (generated out of AreaPy.xml) +#include "AreaPy.h" +#include "AreaPy.cpp" + + +static PyObject * areaAbort(PyObject *, PyObject *args, PyObject *kwd) { + static char *kwlist[] = {"aborting", NULL}; + PyObject *pObj = Py_True; + if (!PyArg_ParseTupleAndKeywords(args,kwd,"|O",kwlist,&pObj)) + return 0; + Area::abort(PyObject_IsTrue(pObj)); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * areaSetParams(PyObject *, PyObject *args, PyObject *kwd) { + + static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_STATIC_CONF),NULL}; + + if(args && PySequence_Size(args)>0) + PyErr_SetString(PyExc_ValueError,"Non-keyword argument is not supported"); + + //Declare variables defined in the NAME field of the CONF parameter list + PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_STATIC_CONF); + + AreaStaticParams params = Area::getDefaultParams(); + +#define AREA_SET(_param) \ + PARAM_FNAME(_param) = \ + PARAM_TYPED(PARAM_PY_CAST_,_param)(params.PARAM_FNAME(_param)); + //populate the CONF variables with params + PARAM_FOREACH(AREA_SET,AREA_PARAMS_STATIC_CONF) + + //Parse arguments to overwrite CONF variables + if (!PyArg_ParseTupleAndKeywords(args, kwd, + "|" PARAM_PY_KWDS(AREA_PARAMS_STATIC_CONF), kwlist, + PARAM_REF(PARAM_FNAME,AREA_PARAMS_STATIC_CONF))) + return 0; + +#define AREA_GET(_param) \ + params.PARAM_FNAME(_param) = \ + PARAM_TYPED(PARAM_CAST_PY_,_param)(PARAM_FNAME(_param)); + //populate 'params' with the CONF variables + PARAM_FOREACH(AREA_GET,AREA_PARAMS_STATIC_CONF) + + Area::setDefaultParams(params); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject* areaGetParams(PyObject *, PyObject *args) { + if (!PyArg_ParseTuple(args, "")) + return 0; + + const AreaStaticParams ¶ms = Area::getDefaultParams(); + + PyObject *dict = PyDict_New(); +#define AREA_SRC(_param) params.PARAM_FNAME(_param) + PARAM_PY_DICT_SET_VALUE(dict,NAME,AREA_SRC,AREA_PARAMS_STATIC_CONF) + return dict; +} + +static PyObject * areaGetParamsDesc(PyObject *, PyObject *args, PyObject *kwd) { + PyObject *pcObj = Py_False; + static char *kwlist[] = {"as_string", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwd, "|O",kwlist,&pcObj)) + return 0; + +#if PY_MAJOR_VERSION < 3 + if(PyObject_IsTrue(pcObj)) + return PyString_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF)); +#else + if(PyObject_IsTrue(pcObj)) + return PyUnicode_FromString(PARAM_PY_DOC(NAME,AREA_PARAMS_STATIC_CONF)); +#endif + PyObject *dict = PyDict_New(); + PARAM_PY_DICT_SET_DOC(dict,NAME,AREA_PARAMS_STATIC_CONF) + return dict; +} + +static const PyMethodDef areaOverrides[] = { + { + "setParams",NULL,0, + "setParam(key=value...): Set algorithm parameters. You can call getParamsDesc() to \n" + "get a list of supported parameters and their descriptions.\n" + PARAM_PY_DOC(NAME,AREA_PARAMS_CONF) + }, + { + "add",NULL,0, + "add((shape...)," PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OPCODE) "):\n" + "Add TopoShape(s) with given operation code\n" + PARAM_PY_DOC(ARG,AREA_PARAMS_OPCODE) + "\nThe first shape's wires will be unioned together regardless of the op code given\n" + "(except for 'Compound'). Subsequent shape's wire will be combined using the op code.\n" + "All shape wires shall be coplanar, and are used to determine a working plane for face\n" + "making and offsetting. You can call setPlane() to supply a reference shape to determine\n" + "the workplane in case the added shapes are all colinear lines.\n", + }, + + { + "makeOffset",NULL,0, + "makeOffset(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_OFFSET) "):\n" + "Make an 2D offset of the shape.\n" + "\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n" + PARAM_PY_DOC(ARG,AREA_PARAMS_OFFSET), + }, + { + "makePocket",NULL,0, + "makePocket(index=-1, " PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_POCKET) "):\n" + "Generate pocket toolpath of the shape.\n" + "\n* index (-1): the index of the section. -1 means all sections. No effect on planar shape.\n" + PARAM_PY_DOC(ARG,AREA_PARAMS_POCKET), + }, + { + "makeSections",NULL,0, + "makeSections(" PARAM_PY_ARGS_DOC(ARG,AREA_PARAMS_SECTION_EXTRA) ", heights=[], plane=None):\n" + "Make a list of area holding the sectioned children shapes on given heights\n" + PARAM_PY_DOC(ARG,AREA_PARAMS_SECTION_EXTRA) + "\n* heights ([]): a list of section heights, the meaning of the value is determined by 'mode'.\n" + "If not specified, the current SectionCount, and SectionOffset of this Area is used.\n" + "\n* plane (None): optional shape to specify a section plane. If not give, the current workplane\n" + "of this Area is used if section mode is 'Workplane'.", + }, + { + "setDefaultParams",reinterpret_cast(reinterpret_cast(areaSetParams)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, + "setDefaultParams(key=value...):\n" + "Static method to set the default parameters of all following Path.Area, plus the following\n" + "additional parameters.\n" + }, + { + "getDefaultParams",(PyCFunction)areaGetParams, METH_VARARGS|METH_STATIC, + "getDefaultParams(): Static method to return the current default parameters." + }, + { + "abort",reinterpret_cast(reinterpret_cast(areaAbort)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, + "abort(aborting=True): Static method to abort any ongoing operation\n" + "\nTo ensure no stray abortion is left in the previous operation, it is advised to manually clear\n" + "the aborting flag by calling abort(False) before starting a new operation.", + }, + { + "getParamsDesc",reinterpret_cast(reinterpret_cast(areaGetParamsDesc)), METH_VARARGS|METH_KEYWORDS|METH_STATIC, + "getParamsDesc(as_string=False): Returns a list of supported parameters and their descriptions.\n" + "\n* as_string: if False, then return a dictionary of documents of all supported parameters." + }, +}; + +struct AreaPyModifier { + AreaPyModifier() { + for(auto &method : Path::AreaPy::Methods) { + if(!method.ml_name) continue; + for(auto &entry : areaOverrides) { + if(std::strcmp(method.ml_name,entry.ml_name)==0) { + if(entry.ml_doc) + method.ml_doc = entry.ml_doc; + if(entry.ml_meth) + method.ml_meth = entry.ml_meth; + if(entry.ml_flags) + method.ml_flags = entry.ml_flags; + break; + } + } + } + } +}; + +static AreaPyModifier mod; + +using namespace Path; + +// returns a string which represents the object e.g. when printed in python +std::string AreaPy::representation(void) const +{ + std::stringstream str; + str << ""; + return str.str(); +} + +PyObject *AreaPy::PyMake(struct _typeobject *, PyObject *args, PyObject *kwd) // Python wrapper +{ + AreaPy* ret = new AreaPy(new Area); + if(!ret->setParams(args,kwd)) { + Py_DecRef(ret); + return 0; + } + return ret; +} + +// constructor method +int AreaPy::PyInit(PyObject* , PyObject* ) +{ + return 0; +} + +PyObject* AreaPy::setPlane(PyObject *args) { + PyObject *pcObj; + if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapePy::Type), &pcObj)) + return 0; + +#define GET_TOPOSHAPE(_p) static_cast(_p)->getTopoShapePtr()->getShape() + getAreaPtr()->setPlane(GET_TOPOSHAPE(pcObj)); + Py_INCREF(this); + return this; +} + +PyObject* AreaPy::getShape(PyObject *args, PyObject *keywds) +{ + PyObject *pcObj = Py_False; + short index=-1; + static char *kwlist[] = {"index","rebuild", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, keywds,"|hO",kwlist,&index,&pcObj)) + return 0; + + PY_TRY { + if(PyObject_IsTrue(pcObj)) + getAreaPtr()->clean(); + return Py::new_reference_to(Part::shape2pyshape(getAreaPtr()->getShape(index))); + } PY_CATCH_OCC +} + +PyObject* AreaPy::add(PyObject *args, PyObject *keywds) +{ + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_OPCODE) + PyObject *pcObj; + + //Strangely, PyArg_ParseTupleAndKeywords requires all arguments to be keyword based, + //even non-optional ones? That doesn't make sense in python. Seems only in python 3 + //they added '$' to address that issue. + static char *kwlist[] = {"shape",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OPCODE), NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "O|" PARAM_PY_KWDS(AREA_PARAMS_OPCODE), + kwlist,&pcObj,PARAM_REF(PARAM_FARG,AREA_PARAMS_OPCODE))) + return 0; + + PY_TRY { + if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) { + getAreaPtr()->add(GET_TOPOSHAPE(pcObj),op); + Py_INCREF(this); + return this; + } else if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || + PyObject_TypeCheck(pcObj, &(PyTuple_Type))) { + Py::Sequence shapeSeq(pcObj); + for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { + PyObject* item = (*it).ptr(); + if(!PyObject_TypeCheck(item, &(Part::TopoShapePy::Type))) { + PyErr_SetString(PyExc_TypeError, "non-shape object in sequence"); + return 0; + } + } + for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it){ + PyObject* item = (*it).ptr(); + getAreaPtr()->add(GET_TOPOSHAPE(item), + PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OPCODE)); + } + Py_INCREF(this); + return this; + } + } PY_CATCH_OCC + + PyErr_SetString(PyExc_TypeError, "shape must be 'TopoShape' or list of 'TopoShape'"); + return 0; +} + +PyObject* AreaPy::makeOffset(PyObject *args, PyObject *keywds) +{ + //Generate a keyword string defined in the ARG field of OFFSET parameter list + static char *kwlist[] = {"index",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_OFFSET), NULL}; + short index = -1; + + //Declare variables defined in the ARG field of the OFFSET parameter list with + //initialization to defaults + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_OFFSET) + + //Parse arguments to overwrite the defaults + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|h" PARAM_PY_KWDS(AREA_PARAMS_OFFSET), kwlist, + &index,PARAM_REF(PARAM_FARG,AREA_PARAMS_OFFSET))) + return 0; + + PY_TRY { + //Expand the variable as function call arguments + TopoDS_Shape resultShape = getAreaPtr()->makeOffset(index, + PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_OFFSET)); + return Py::new_reference_to(Part::shape2pyshape(resultShape)); + } PY_CATCH_OCC +} + +PyObject* AreaPy::makePocket(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {"index",PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_POCKET), NULL}; + short index = -1; + + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_POCKET) + //Override pocket mode default + mode = Area::PocketModeZigZagOffset; + + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|h" PARAM_PY_KWDS(AREA_PARAMS_POCKET), kwlist, + &index,PARAM_REF(PARAM_FARG,AREA_PARAMS_POCKET))) + return 0; + + PY_TRY { + TopoDS_Shape resultShape = getAreaPtr()->makePocket(index, + PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_POCKET)); + return Py::new_reference_to(Part::shape2pyshape(resultShape)); + } PY_CATCH_OCC +} + +PyObject* AreaPy::makeSections(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {PARAM_FIELD_STRINGS(ARG,AREA_PARAMS_SECTION_EXTRA), + "heights", "plane", NULL}; + PyObject *heights = NULL; + PyObject *plane = NULL; + + PARAM_PY_DECLARE_INIT(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA) + + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|" PARAM_PY_KWDS(AREA_PARAMS_SECTION_EXTRA) "OO!", kwlist, + PARAM_REF(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA), + &heights, &(Part::TopoShapePy::Type), &plane)) + return 0; + + PY_TRY { + std::vector h; + if(heights) { + if (PyObject_TypeCheck(heights, &(PyFloat_Type))) + h.push_back(PyFloat_AsDouble(heights)); + else if (PyObject_TypeCheck(heights, &(PyList_Type)) || + PyObject_TypeCheck(heights, &(PyTuple_Type))) { + Py::Sequence shapeSeq(heights); + h.reserve(shapeSeq.size()); + for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { + PyObject* item = (*it).ptr(); + if(!PyObject_TypeCheck(item, &(PyFloat_Type))) { + PyErr_SetString(PyExc_TypeError, "heights must only contain float type"); + return 0; + } + h.push_back(PyFloat_AsDouble(item)); + } + }else{ + PyErr_SetString(PyExc_TypeError, "heights must be of type float or list/tuple of float"); + return 0; + } + } + + std::vector > sections = getAreaPtr()->makeSections( + PARAM_PY_FIELDS(PARAM_FARG,AREA_PARAMS_SECTION_EXTRA), + h,plane?GET_TOPOSHAPE(plane):TopoDS_Shape()); + + Py::List ret; + for(auto &area : sections) + ret.append(Py::asObject(new AreaPy(new Area(*area,true)))); + return Py::new_reference_to(ret); + } PY_CATCH_OCC +} + +PyObject* AreaPy::setDefaultParams(PyObject *, PyObject *) +{ + return 0; +} + +PyObject* AreaPy::setParams(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_CONF),NULL}; + + //Declare variables defined in the NAME field of the CONF parameter list + PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_CONF); + + AreaParams params = getAreaPtr()->getParams(); + + //populate the CONF variables with params + PARAM_FOREACH(AREA_SET,AREA_PARAMS_CONF) + + //Parse arguments to overwrite CONF variables + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, + PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) + return 0; + + PY_TRY { + //populate 'params' with the CONF variables + PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF) + + getAreaPtr()->setParams(params); + Py_INCREF(this); + return this; + } PY_CATCH_OCC +} + +PyObject* AreaPy::getParams(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + const AreaParams ¶ms =getAreaPtr()->getParams(); + + PyObject *dict = PyDict_New(); + PARAM_PY_DICT_SET_VALUE(dict,NAME,AREA_SRC,AREA_PARAMS_CONF) + return dict; +} + +PyObject* AreaPy::getDefaultParams(PyObject *) +{ + return 0; +} + +PyObject* AreaPy::abort(PyObject *, PyObject *) { + return 0; +} + +PyObject* AreaPy::getParamsDesc(PyObject *, PyObject *) +{ + return 0; +} + +Py::List AreaPy::getSections(void) const { + Py::List ret; + Area *area = getAreaPtr(); + for(size_t i=0,count=area->getSectionCount(); igetShape(i))); + return ret; +} + +Py::List AreaPy::getShapes(void) const { + Py::List ret; + Area *area = getAreaPtr(); + const std::list &shapes = area->getChildren(); + for(auto &s : shapes) + ret.append(Py::TupleN(Part::shape2pyshape(s.shape),Py::Int(s.op))); + return ret; +} + +Py::Object AreaPy::getWorkplane(void) const { + return Part::shape2pyshape(getAreaPtr()->getPlane()); +} + +void AreaPy::setWorkplane(Py::Object obj) { + PyObject* p = obj.ptr(); + if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) { + std::string error = std::string("type must be 'TopoShape', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + getAreaPtr()->setPlane(GET_TOPOSHAPE(p)); +} + +// custom attributes get/set + +PyObject *AreaPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int AreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Path/App/Command.cpp b/src/Mod/Path/App/Command.cpp index 6403f26eea..a175ec65c3 100644 --- a/src/Mod/Path/App/Command.cpp +++ b/src/Mod/Path/App/Command.cpp @@ -1,323 +1,323 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -# include -# include -# include -#endif - -#include -#include -#include -#include -#include -#include "Command.h" - -using namespace Base; -using namespace Path; - -TYPESYSTEM_SOURCE(Path::Command , Base::Persistence) - -// Constructors & destructors - -Command::Command(const char* name, - const std::map& parameters) -:Name(name),Parameters(parameters) -{ -} - -Command::Command() -{ -} - -Command::~Command() -{ -} - -// New methods - -Placement Command::getPlacement (const Base::Vector3d pos) const -{ - static const std::string x = "X"; - static const std::string y = "Y"; - static const std::string z = "Z"; - static const std::string a = "A"; - static const std::string b = "B"; - static const std::string c = "C"; - Vector3d vec(getParam(x, pos.x),getParam(y, pos.y),getParam(z, pos.z)); - Rotation rot; - rot.setYawPitchRoll(getParam(a),getParam(b),getParam(c)); - Placement plac(vec,rot); - return plac; -} - -Vector3d Command::getCenter (void) const -{ - static const std::string i = "I"; - static const std::string j = "J"; - static const std::string k = "K"; - Vector3d vec(getParam(i),getParam(j),getParam(k)); - return vec; -} - -double Command::getValue(const std::string& attr) const -{ - std::string a(attr); - boost::to_upper(a); - return getParam(a); -} - -bool Command::has(const std::string& attr) const -{ - std::string a(attr); - boost::to_upper(a); - return Parameters.count(a) > 0; -} - -std::string Command::toGCode (int precision, bool padzero) const -{ - std::stringstream str; - str.fill('0'); - str << Name; - if(precision<0) - precision = 0; - double scale = std::pow(10.0,precision+1); - std::int64_t iscale = static_cast(scale)/10; - for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { - if(i->first == "N") continue; - - str << " " << i->first; - - std::int64_t v = static_cast(i->second*scale); - if(v<0) { - v = -v; - str << '-'; //shall we allow -0 ? - } - v+=5; - v /= 10; - str << (v/iscale); - if(!precision) continue; - - int width = precision; - std::int64_t digits = v%iscale; - if(!padzero) { - if(!digits) continue; - while(digits%10 == 0) { - digits/=10; - --width; - } - } - str << '.' << std::setw(width) << std::right << digits; - } - return str.str(); -} - -void Command::setFromGCode (const std::string& str) -{ - Parameters.clear(); - std::string mode = "none"; - std::string key; - std::string value; - for (unsigned int i=0; i < str.size(); i++) { - if ( (isdigit(str[i])) || (str[i] == '-') || (str[i] == '.') ) { - value += str[i]; - } else if (isalpha(str[i])) { - if (mode == "command") { - if (!key.empty() && !value.empty()) { - std::string cmd = key + value; - boost::to_upper(cmd); - Name = cmd; - key = ""; - value = ""; - mode = "argument"; - } else { - throw Base::BadFormatError("Badly formatted GCode command"); - } - mode = "argument"; - } else if (mode == "none") { - mode = "command"; - } else if (mode == "argument") { - if (!key.empty() && !value.empty()) { - double val = std::atof(value.c_str()); - boost::to_upper(key); - Parameters[key] = val; - key = ""; - value = ""; - } else { - throw Base::BadFormatError("Badly formatted GCode argument"); - } - } else if (mode == "comment") { - value += str[i]; - } - key = str[i]; - } else if (str[i] == '(') { - mode = "comment"; - } else if (str[i] == ')') { - key = "("; - value += ")"; - } else { - // add non-ascii characters only if this is a comment - if (mode == "comment") { - value += str[i]; - } - } - } - if (!key.empty() && !value.empty()) { - if ( (mode == "command") || (mode == "comment") ) { - std::string cmd = key + value; - if (mode == "command") - boost::to_upper(cmd); - Name = cmd; - } else { - double val = std::atof(value.c_str()); - boost::to_upper(key); - Parameters[key] = val; - } - } else { - throw Base::BadFormatError("Badly formatted GCode argument"); - } -} - -void Command::setFromPlacement (const Base::Placement &plac) -{ - Name = "G1"; - Parameters.clear(); - static const std::string x = "X"; - static const std::string y = "Y"; - static const std::string z = "Z"; - static const std::string a = "A"; - static const std::string b = "B"; - static const std::string c = "C"; - double xval, yval, zval, aval, bval, cval; - xval = plac.getPosition().x; - yval = plac.getPosition().y; - zval = plac.getPosition().z; - plac.getRotation().getYawPitchRoll(aval,bval,cval); - if (xval != 0.0) - Parameters[x] = xval; - if (yval != 0.0) - Parameters[y] = yval; - if (zval != 0.0) - Parameters[z] = zval; - if (aval != 0.0) - Parameters[a] = aval; - if (bval != 0.0) - Parameters[b] = bval; - if (cval != 0.0) - Parameters[c] = cval; -} - -void Command::setCenter(const Base::Vector3d &pos, bool clockwise) -{ - if (clockwise) { - Name = "G2"; - } else { - Name = "G3"; - } - static const std::string i = "I"; - static const std::string j = "J"; - static const std::string k = "K"; - double ival, jval, kval; - ival = pos.x; - jval = pos.y; - kval = pos.z; - Parameters[i] = ival; - Parameters[j] = jval; - Parameters[k] = kval; -} - -Command Command::transform(const Base::Placement other) -{ - Base::Placement plac = getPlacement(); - plac *= other; - double xval, yval, zval, aval, bval, cval; - xval = plac.getPosition().x; - yval = plac.getPosition().y; - zval = plac.getPosition().z; - plac.getRotation().getYawPitchRoll(aval,bval,cval); - Command c = Command(); - c.Name = Name; - for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { - std::string k = i->first; - double v = i->second; - if (k == "X") - v = xval; - if (k == "Y") - v = yval; - if (k == "Z") - v = zval; - if (k == "A") - v = aval; - if (k == "B") - v = bval; - if (k == "C") - v = cval; - c.Parameters[k] = v; - } - return c; -} - -void Command::scaleBy(double factor) -{ - for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { - switch (i->first[0]) { - case 'X': - case 'Y': - case 'Z': - case 'I': - case 'J': - case 'R': - case 'Q': - case 'F': - Parameters[i->first] = i->second * factor; - break; - } - } -} - -// Reimplemented from base class - -unsigned int Command::getMemSize (void) const -{ - return toGCode().size(); -} - -void Command::Save (Writer &writer) const -{ - // this will only get used if saved as XML (probably never) - writer.Stream() << writer.ind() << ""; - writer.Stream()<< std::endl; -} - -void Command::Restore(XMLReader &reader) -{ - reader.readElement("Command"); - std::string gcode = reader.getAttribute("gcode"); - setFromGCode(gcode); -} - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include +#include "Command.h" + +using namespace Base; +using namespace Path; + +TYPESYSTEM_SOURCE(Path::Command , Base::Persistence) + +// Constructors & destructors + +Command::Command(const char* name, + const std::map& parameters) +:Name(name),Parameters(parameters) +{ +} + +Command::Command() +{ +} + +Command::~Command() +{ +} + +// New methods + +Placement Command::getPlacement (const Base::Vector3d pos) const +{ + static const std::string x = "X"; + static const std::string y = "Y"; + static const std::string z = "Z"; + static const std::string a = "A"; + static const std::string b = "B"; + static const std::string c = "C"; + Vector3d vec(getParam(x, pos.x),getParam(y, pos.y),getParam(z, pos.z)); + Rotation rot; + rot.setYawPitchRoll(getParam(a),getParam(b),getParam(c)); + Placement plac(vec,rot); + return plac; +} + +Vector3d Command::getCenter (void) const +{ + static const std::string i = "I"; + static const std::string j = "J"; + static const std::string k = "K"; + Vector3d vec(getParam(i),getParam(j),getParam(k)); + return vec; +} + +double Command::getValue(const std::string& attr) const +{ + std::string a(attr); + boost::to_upper(a); + return getParam(a); +} + +bool Command::has(const std::string& attr) const +{ + std::string a(attr); + boost::to_upper(a); + return Parameters.count(a) > 0; +} + +std::string Command::toGCode (int precision, bool padzero) const +{ + std::stringstream str; + str.fill('0'); + str << Name; + if(precision<0) + precision = 0; + double scale = std::pow(10.0,precision+1); + std::int64_t iscale = static_cast(scale)/10; + for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { + if(i->first == "N") continue; + + str << " " << i->first; + + std::int64_t v = static_cast(i->second*scale); + if(v<0) { + v = -v; + str << '-'; //shall we allow -0 ? + } + v+=5; + v /= 10; + str << (v/iscale); + if(!precision) continue; + + int width = precision; + std::int64_t digits = v%iscale; + if(!padzero) { + if(!digits) continue; + while(digits%10 == 0) { + digits/=10; + --width; + } + } + str << '.' << std::setw(width) << std::right << digits; + } + return str.str(); +} + +void Command::setFromGCode (const std::string& str) +{ + Parameters.clear(); + std::string mode = "none"; + std::string key; + std::string value; + for (unsigned int i=0; i < str.size(); i++) { + if ( (isdigit(str[i])) || (str[i] == '-') || (str[i] == '.') ) { + value += str[i]; + } else if (isalpha(str[i])) { + if (mode == "command") { + if (!key.empty() && !value.empty()) { + std::string cmd = key + value; + boost::to_upper(cmd); + Name = cmd; + key = ""; + value = ""; + mode = "argument"; + } else { + throw Base::BadFormatError("Badly formatted GCode command"); + } + mode = "argument"; + } else if (mode == "none") { + mode = "command"; + } else if (mode == "argument") { + if (!key.empty() && !value.empty()) { + double val = std::atof(value.c_str()); + boost::to_upper(key); + Parameters[key] = val; + key = ""; + value = ""; + } else { + throw Base::BadFormatError("Badly formatted GCode argument"); + } + } else if (mode == "comment") { + value += str[i]; + } + key = str[i]; + } else if (str[i] == '(') { + mode = "comment"; + } else if (str[i] == ')') { + key = "("; + value += ")"; + } else { + // add non-ascii characters only if this is a comment + if (mode == "comment") { + value += str[i]; + } + } + } + if (!key.empty() && !value.empty()) { + if ( (mode == "command") || (mode == "comment") ) { + std::string cmd = key + value; + if (mode == "command") + boost::to_upper(cmd); + Name = cmd; + } else { + double val = std::atof(value.c_str()); + boost::to_upper(key); + Parameters[key] = val; + } + } else { + throw Base::BadFormatError("Badly formatted GCode argument"); + } +} + +void Command::setFromPlacement (const Base::Placement &plac) +{ + Name = "G1"; + Parameters.clear(); + static const std::string x = "X"; + static const std::string y = "Y"; + static const std::string z = "Z"; + static const std::string a = "A"; + static const std::string b = "B"; + static const std::string c = "C"; + double xval, yval, zval, aval, bval, cval; + xval = plac.getPosition().x; + yval = plac.getPosition().y; + zval = plac.getPosition().z; + plac.getRotation().getYawPitchRoll(aval,bval,cval); + if (xval != 0.0) + Parameters[x] = xval; + if (yval != 0.0) + Parameters[y] = yval; + if (zval != 0.0) + Parameters[z] = zval; + if (aval != 0.0) + Parameters[a] = aval; + if (bval != 0.0) + Parameters[b] = bval; + if (cval != 0.0) + Parameters[c] = cval; +} + +void Command::setCenter(const Base::Vector3d &pos, bool clockwise) +{ + if (clockwise) { + Name = "G2"; + } else { + Name = "G3"; + } + static const std::string i = "I"; + static const std::string j = "J"; + static const std::string k = "K"; + double ival, jval, kval; + ival = pos.x; + jval = pos.y; + kval = pos.z; + Parameters[i] = ival; + Parameters[j] = jval; + Parameters[k] = kval; +} + +Command Command::transform(const Base::Placement other) +{ + Base::Placement plac = getPlacement(); + plac *= other; + double xval, yval, zval, aval, bval, cval; + xval = plac.getPosition().x; + yval = plac.getPosition().y; + zval = plac.getPosition().z; + plac.getRotation().getYawPitchRoll(aval,bval,cval); + Command c = Command(); + c.Name = Name; + for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { + std::string k = i->first; + double v = i->second; + if (k == "X") + v = xval; + if (k == "Y") + v = yval; + if (k == "Z") + v = zval; + if (k == "A") + v = aval; + if (k == "B") + v = bval; + if (k == "C") + v = cval; + c.Parameters[k] = v; + } + return c; +} + +void Command::scaleBy(double factor) +{ + for(std::map::const_iterator i = Parameters.begin(); i != Parameters.end(); ++i) { + switch (i->first[0]) { + case 'X': + case 'Y': + case 'Z': + case 'I': + case 'J': + case 'R': + case 'Q': + case 'F': + Parameters[i->first] = i->second * factor; + break; + } + } +} + +// Reimplemented from base class + +unsigned int Command::getMemSize (void) const +{ + return toGCode().size(); +} + +void Command::Save (Writer &writer) const +{ + // this will only get used if saved as XML (probably never) + writer.Stream() << writer.ind() << ""; + writer.Stream()<< std::endl; +} + +void Command::Restore(XMLReader &reader) +{ + reader.readElement("Command"); + std::string gcode = reader.getAttribute("gcode"); + setFromGCode(gcode); +} + diff --git a/src/Mod/Path/App/Command.h b/src/Mod/Path/App/Command.h index 850f5393ce..99a1fda269 100644 --- a/src/Mod/Path/App/Command.h +++ b/src/Mod/Path/App/Command.h @@ -1,76 +1,76 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_COMMAND_H -#define PATH_COMMAND_H - -#include -#include -#include -#include -#include - -namespace Path -{ - /** The representation of a cnc command in a path */ - class PathExport Command : public Base::Persistence - { - TYPESYSTEM_HEADER(); - - public: - //constructors - Command(); - Command(const char* name, - const std::map& parameters); - ~Command(); - // from base class - virtual unsigned int getMemSize (void) const; - virtual void Save (Base::Writer &/*writer*/) const; - virtual void Restore(Base::XMLReader &/*reader*/); - - // specific methods - Base::Placement getPlacement (const Base::Vector3d pos = Base::Vector3d()) const; // returns a placement from the x,y,z,a,b,c parameters - Base::Vector3d getCenter (void) const; // returns a 3d vector from the i,j,k parameters - void setCenter(const Base::Vector3d&, bool clockwise=true); // sets the center coordinates and the command name - std::string toGCode (int precision=6, bool padzero=true) const; // returns a GCode string representation of the command - void setFromGCode (const std::string&); // sets the parameters from the contents of the given GCode string - void setFromPlacement (const Base::Placement&); // sets the parameters from the contents of the given placement - bool has(const std::string&) const; // returns true if the given string exists in the parameters - Command transform(const Base::Placement); // returns a transformed copy of this command - double getValue(const std::string &name) const; // returns the value of a given parameter - void scaleBy(double factor); // scales the receiver - use for imperial/metric conversions - - // this assumes the name is upper case - inline double getParam(const std::string &name, double fallback = 0.0) const { - auto it = Parameters.find(name); - return it==Parameters.end() ? fallback : it->second; - } - - // attributes - std::string Name; - std::map Parameters; - }; - -} //namespace Path - -#endif // PATH_COMMAND_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_COMMAND_H +#define PATH_COMMAND_H + +#include +#include +#include +#include +#include + +namespace Path +{ + /** The representation of a cnc command in a path */ + class PathExport Command : public Base::Persistence + { + TYPESYSTEM_HEADER(); + + public: + //constructors + Command(); + Command(const char* name, + const std::map& parameters); + ~Command(); + // from base class + virtual unsigned int getMemSize (void) const; + virtual void Save (Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + + // specific methods + Base::Placement getPlacement (const Base::Vector3d pos = Base::Vector3d()) const; // returns a placement from the x,y,z,a,b,c parameters + Base::Vector3d getCenter (void) const; // returns a 3d vector from the i,j,k parameters + void setCenter(const Base::Vector3d&, bool clockwise=true); // sets the center coordinates and the command name + std::string toGCode (int precision=6, bool padzero=true) const; // returns a GCode string representation of the command + void setFromGCode (const std::string&); // sets the parameters from the contents of the given GCode string + void setFromPlacement (const Base::Placement&); // sets the parameters from the contents of the given placement + bool has(const std::string&) const; // returns true if the given string exists in the parameters + Command transform(const Base::Placement); // returns a transformed copy of this command + double getValue(const std::string &name) const; // returns the value of a given parameter + void scaleBy(double factor); // scales the receiver - use for imperial/metric conversions + + // this assumes the name is upper case + inline double getParam(const std::string &name, double fallback = 0.0) const { + auto it = Parameters.find(name); + return it==Parameters.end() ? fallback : it->second; + } + + // attributes + std::string Name; + std::map Parameters; + }; + +} //namespace Path + +#endif // PATH_COMMAND_H diff --git a/src/Mod/Path/App/CommandPy.xml b/src/Mod/Path/App/CommandPy.xml index 0da50518aa..14e6df4109 100644 --- a/src/Mod/Path/App/CommandPy.xml +++ b/src/Mod/Path/App/CommandPy.xml @@ -1,55 +1,55 @@ - - - - - - Command([name],[parameters]): Represents a basic Gcode command -name (optional) is the name of the command, ex. G1 -parameters (optional) is a dictionary containing string:number -pairs, or a placement, or a vector - - - - The name of the command - - - - - - The parameters of the command - - - - - - The coordinates of the endpoint of the command - - - - - - toGCode(): returns a GCode representation of the command - - - - - toGCode(): returns a GCode representation of the command - - - - - transform(Placement): returns a copy of this command transformed by the given placement - - - - + + + + + + Command([name],[parameters]): Represents a basic Gcode command +name (optional) is the name of the command, ex. G1 +parameters (optional) is a dictionary containing string:number +pairs, or a placement, or a vector + + + + The name of the command + + + + + + The parameters of the command + + + + + + The coordinates of the endpoint of the command + + + + + + toGCode(): returns a GCode representation of the command + + + + + toGCode(): returns a GCode representation of the command + + + + + transform(Placement): returns a copy of this command transformed by the given placement + + + + diff --git a/src/Mod/Path/App/CommandPyImp.cpp b/src/Mod/Path/App/CommandPyImp.cpp index 67418f880c..dfbb2448c2 100644 --- a/src/Mod/Path/App/CommandPyImp.cpp +++ b/src/Mod/Path/App/CommandPyImp.cpp @@ -1,317 +1,317 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#include "PreCompiled.h" - - -#ifndef _PreComp_ -# include -#endif - -#include -#include -#include -#include -#include "Mod/Path/App/Command.h" - -// files generated out of CommandPy.xml -#include "CommandPy.h" -#include "CommandPy.cpp" - -using namespace Path; - -// returns a string which represents the object e.g. when printed in python -std::string CommandPy::representation(void) const -{ - std::stringstream str; - str.precision(5); - str << "Command "; - str << getCommandPtr()->Name; - str << " ["; - for(std::map::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) { - std::string k = i->first; - double v = i->second; - str << " " << k << ":" << v; - } - str << " ]"; - return str.str(); -} - - -PyObject *CommandPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper -{ - // create a new instance of CommandPy and the Twin object - return new CommandPy(new Command); -} - -// constructor method -int CommandPy::PyInit(PyObject* args, PyObject* kwd) -{ - PyObject *parameters = NULL; - char *name = ""; - static char *kwlist[] = {"name", "parameters", NULL}; - if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &PyDict_Type, ¶meters) ) { - std::string sname(name); - boost::to_upper(sname); - try { - if (!sname.empty()) - getCommandPtr()->setFromGCode(name); - } - catch (const Base::Exception& e) { - PyErr_SetString(PyExc_ValueError, e.what()); - return -1; - } - - PyObject *key, *value; - Py_ssize_t pos = 0; - while (parameters && PyDict_Next(parameters, &pos, &key, &value)) { - std::string ckey; -#if PY_MAJOR_VERSION >= 3 - if (PyUnicode_Check(key)) { - ckey = PyUnicode_AsUTF8(key); -#else - if (PyString_Check(key)) { - ckey = PyString_AsString(key); -#endif - } - else { - PyErr_SetString(PyExc_TypeError, "The dictionary can only contain string keys"); - return -1; - } - - boost::to_upper(ckey); - double cvalue; -#if PY_MAJOR_VERSION >= 3 - if (PyObject_TypeCheck(value,&(PyLong_Type))) { - cvalue = (double)PyLong_AsLong(value); -#else - if (PyObject_TypeCheck(value,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(value); -#endif - } - else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { - cvalue = PyFloat_AsDouble(value); - } - else { - PyErr_SetString(PyExc_TypeError, "The dictionary can only contain number values"); - return -1; - } - getCommandPtr()->Parameters[ckey]=cvalue; - } - return 0; - } - PyErr_Clear(); // set by PyArg_ParseTuple() - - if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &(Base::PlacementPy::Type), ¶meters) ) { - std::string sname(name); - boost::to_upper(sname); - try { - if (!sname.empty()) - getCommandPtr()->setFromGCode(name); - } - catch (const Base::Exception& e) { - PyErr_SetString(PyExc_ValueError, e.what()); - return -1; - } - Base::PlacementPy *p = static_cast(parameters); - getCommandPtr()->setFromPlacement( *p->getPlacementPtr() ); - return 0; - } - return -1; -} - -// Name attribute - -Py::String CommandPy::getName(void) const -{ - return Py::String(getCommandPtr()->Name.c_str()); -} - -void CommandPy::setName(Py::String arg) -{ - std::string cmd = arg.as_std_string(); - boost::to_upper(cmd); - getCommandPtr()->Name = cmd; -} - -// Parameters attribute get/set - -Py::Dict CommandPy::getParameters(void) const -{ - PyObject *dict = PyDict_New(); - for(std::map::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) { -#if PY_MAJOR_VERSION >= 3 - PyDict_SetItem(dict,PyUnicode_FromString(i->first.c_str()),PyFloat_FromDouble(i->second)); -#else - PyDict_SetItem(dict,PyString_FromString(i->first.c_str()),PyFloat_FromDouble(i->second)); -#endif - } - return Py::Dict(dict); -} - -void CommandPy::setParameters(Py::Dict arg) -{ - PyObject* dict_copy = PyDict_Copy(arg.ptr()); - PyObject *key, *value; - Py_ssize_t pos = 0; - while (PyDict_Next(dict_copy, &pos, &key, &value)) { - std::string ckey; -#if PY_MAJOR_VERSION >= 3 - if (PyUnicode_Check(key)) { - ckey = PyUnicode_AsUTF8(key); -#else - if (PyString_Check(key)) { - ckey = PyString_AsString(key); -#endif - } - else { - throw Py::TypeError("The dictionary can only contain string keys"); - } - - boost::to_upper(ckey); - double cvalue; -#if PY_MAJOR_VERSION >= 3 - if (PyObject_TypeCheck(value,&(PyLong_Type))) { - cvalue = (double)PyLong_AsLong(value); -#else - if (PyObject_TypeCheck(value,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(value); -#endif - } - else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { - cvalue = PyFloat_AsDouble(value); - } - else { - throw Py::TypeError("The dictionary can only contain number values"); - } - getCommandPtr()->Parameters[ckey]=cvalue; - } -} - -// GCode methods - -PyObject* CommandPy::toGCode(PyObject *args) -{ - if (PyArg_ParseTuple(args, "")) { -#if PY_MAJOR_VERSION >= 3 - return PyUnicode_FromString(getCommandPtr()->toGCode().c_str()); -#else - return PyString_FromString(getCommandPtr()->toGCode().c_str()); -#endif - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* CommandPy::setFromGCode(PyObject *args) -{ - char *pstr=0; - if (PyArg_ParseTuple(args, "s", &pstr)) { - std::string gcode(pstr); - try { - getCommandPtr()->setFromGCode(gcode); - } - catch (const Base::Exception& e) { - PyErr_SetString(PyExc_ValueError, e.what()); - return nullptr; - } - - Py_INCREF(Py_None); - return Py_None; - } - throw Py::TypeError("Argument must be a string"); -} - -// Placement attribute get/set - -Py::Object CommandPy::getPlacement(void) const -{ - return Py::asObject(new Base::PlacementPy(new Base::Placement(getCommandPtr()->getPlacement()))); -} - -void CommandPy::setPlacement(Py::Object arg) -{ - union PyType_Object pyType = {&(Base::PlacementPy::Type)}; - Py::Type PlacementType(pyType.o); - if(arg.isType(PlacementType)) { - getCommandPtr()->setFromPlacement( *static_cast((*arg))->getPlacementPtr() ); - } else - throw Py::TypeError("Argument must be a placement"); -} - -PyObject* CommandPy::transform(PyObject *args) -{ - PyObject *placement; - if ( PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &placement) ) { - Base::PlacementPy *p = static_cast(placement); - Path::Command trCmd = getCommandPtr()->transform( *p->getPlacementPtr() ); - return new CommandPy(new Path::Command(trCmd)); - } else - throw Py::TypeError("Argument must be a placement"); -} - -// custom attributes get/set - -PyObject *CommandPy::getCustomAttributes(const char* attr) const -{ - std::string satt(attr); - if (satt.length() == 1) { - if (isalpha(satt[0])) { - boost::to_upper(satt); - if (getCommandPtr()->Parameters.count(satt)) { - return PyFloat_FromDouble(getCommandPtr()->Parameters[satt]); - } - Py_INCREF(Py_None); - return Py_None; - } - } - return 0; -} - -int CommandPy::setCustomAttributes(const char* attr, PyObject* obj) -{ - std::string satt(attr); - if (satt.length() == 1) { - if (isalpha(satt[0])) { - boost::to_upper(satt); - double cvalue; -#if PY_MAJOR_VERSION >= 3 - if (PyObject_TypeCheck(obj,&(PyLong_Type))) { - cvalue = (double)PyLong_AsLong(obj); -#else - if (PyObject_TypeCheck(obj,&(PyInt_Type))) { - cvalue = (double)PyInt_AsLong(obj); -#endif - } else if (PyObject_TypeCheck(obj,&(PyFloat_Type))) { - cvalue = PyFloat_AsDouble(obj); - } else { - return 0; - } - getCommandPtr()->Parameters[satt]=cvalue; - return 1; - } - } - return 0; -} - - - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include +#include "Mod/Path/App/Command.h" + +// files generated out of CommandPy.xml +#include "CommandPy.h" +#include "CommandPy.cpp" + +using namespace Path; + +// returns a string which represents the object e.g. when printed in python +std::string CommandPy::representation(void) const +{ + std::stringstream str; + str.precision(5); + str << "Command "; + str << getCommandPtr()->Name; + str << " ["; + for(std::map::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) { + std::string k = i->first; + double v = i->second; + str << " " << k << ":" << v; + } + str << " ]"; + return str.str(); +} + + +PyObject *CommandPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of CommandPy and the Twin object + return new CommandPy(new Command); +} + +// constructor method +int CommandPy::PyInit(PyObject* args, PyObject* kwd) +{ + PyObject *parameters = NULL; + char *name = ""; + static char *kwlist[] = {"name", "parameters", NULL}; + if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &PyDict_Type, ¶meters) ) { + std::string sname(name); + boost::to_upper(sname); + try { + if (!sname.empty()) + getCommandPtr()->setFromGCode(name); + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_ValueError, e.what()); + return -1; + } + + PyObject *key, *value; + Py_ssize_t pos = 0; + while (parameters && PyDict_Next(parameters, &pos, &key, &value)) { + std::string ckey; +#if PY_MAJOR_VERSION >= 3 + if (PyUnicode_Check(key)) { + ckey = PyUnicode_AsUTF8(key); +#else + if (PyString_Check(key)) { + ckey = PyString_AsString(key); +#endif + } + else { + PyErr_SetString(PyExc_TypeError, "The dictionary can only contain string keys"); + return -1; + } + + boost::to_upper(ckey); + double cvalue; +#if PY_MAJOR_VERSION >= 3 + if (PyObject_TypeCheck(value,&(PyLong_Type))) { + cvalue = (double)PyLong_AsLong(value); +#else + if (PyObject_TypeCheck(value,&(PyInt_Type))) { + cvalue = (double)PyInt_AsLong(value); +#endif + } + else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { + cvalue = PyFloat_AsDouble(value); + } + else { + PyErr_SetString(PyExc_TypeError, "The dictionary can only contain number values"); + return -1; + } + getCommandPtr()->Parameters[ckey]=cvalue; + } + return 0; + } + PyErr_Clear(); // set by PyArg_ParseTuple() + + if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &(Base::PlacementPy::Type), ¶meters) ) { + std::string sname(name); + boost::to_upper(sname); + try { + if (!sname.empty()) + getCommandPtr()->setFromGCode(name); + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_ValueError, e.what()); + return -1; + } + Base::PlacementPy *p = static_cast(parameters); + getCommandPtr()->setFromPlacement( *p->getPlacementPtr() ); + return 0; + } + return -1; +} + +// Name attribute + +Py::String CommandPy::getName(void) const +{ + return Py::String(getCommandPtr()->Name.c_str()); +} + +void CommandPy::setName(Py::String arg) +{ + std::string cmd = arg.as_std_string(); + boost::to_upper(cmd); + getCommandPtr()->Name = cmd; +} + +// Parameters attribute get/set + +Py::Dict CommandPy::getParameters(void) const +{ + PyObject *dict = PyDict_New(); + for(std::map::iterator i = getCommandPtr()->Parameters.begin(); i != getCommandPtr()->Parameters.end(); ++i) { +#if PY_MAJOR_VERSION >= 3 + PyDict_SetItem(dict,PyUnicode_FromString(i->first.c_str()),PyFloat_FromDouble(i->second)); +#else + PyDict_SetItem(dict,PyString_FromString(i->first.c_str()),PyFloat_FromDouble(i->second)); +#endif + } + return Py::Dict(dict); +} + +void CommandPy::setParameters(Py::Dict arg) +{ + PyObject* dict_copy = PyDict_Copy(arg.ptr()); + PyObject *key, *value; + Py_ssize_t pos = 0; + while (PyDict_Next(dict_copy, &pos, &key, &value)) { + std::string ckey; +#if PY_MAJOR_VERSION >= 3 + if (PyUnicode_Check(key)) { + ckey = PyUnicode_AsUTF8(key); +#else + if (PyString_Check(key)) { + ckey = PyString_AsString(key); +#endif + } + else { + throw Py::TypeError("The dictionary can only contain string keys"); + } + + boost::to_upper(ckey); + double cvalue; +#if PY_MAJOR_VERSION >= 3 + if (PyObject_TypeCheck(value,&(PyLong_Type))) { + cvalue = (double)PyLong_AsLong(value); +#else + if (PyObject_TypeCheck(value,&(PyInt_Type))) { + cvalue = (double)PyInt_AsLong(value); +#endif + } + else if (PyObject_TypeCheck(value, &(PyFloat_Type))) { + cvalue = PyFloat_AsDouble(value); + } + else { + throw Py::TypeError("The dictionary can only contain number values"); + } + getCommandPtr()->Parameters[ckey]=cvalue; + } +} + +// GCode methods + +PyObject* CommandPy::toGCode(PyObject *args) +{ + if (PyArg_ParseTuple(args, "")) { +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromString(getCommandPtr()->toGCode().c_str()); +#else + return PyString_FromString(getCommandPtr()->toGCode().c_str()); +#endif + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* CommandPy::setFromGCode(PyObject *args) +{ + char *pstr=0; + if (PyArg_ParseTuple(args, "s", &pstr)) { + std::string gcode(pstr); + try { + getCommandPtr()->setFromGCode(gcode); + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_ValueError, e.what()); + return nullptr; + } + + Py_INCREF(Py_None); + return Py_None; + } + throw Py::TypeError("Argument must be a string"); +} + +// Placement attribute get/set + +Py::Object CommandPy::getPlacement(void) const +{ + return Py::asObject(new Base::PlacementPy(new Base::Placement(getCommandPtr()->getPlacement()))); +} + +void CommandPy::setPlacement(Py::Object arg) +{ + union PyType_Object pyType = {&(Base::PlacementPy::Type)}; + Py::Type PlacementType(pyType.o); + if(arg.isType(PlacementType)) { + getCommandPtr()->setFromPlacement( *static_cast((*arg))->getPlacementPtr() ); + } else + throw Py::TypeError("Argument must be a placement"); +} + +PyObject* CommandPy::transform(PyObject *args) +{ + PyObject *placement; + if ( PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type), &placement) ) { + Base::PlacementPy *p = static_cast(placement); + Path::Command trCmd = getCommandPtr()->transform( *p->getPlacementPtr() ); + return new CommandPy(new Path::Command(trCmd)); + } else + throw Py::TypeError("Argument must be a placement"); +} + +// custom attributes get/set + +PyObject *CommandPy::getCustomAttributes(const char* attr) const +{ + std::string satt(attr); + if (satt.length() == 1) { + if (isalpha(satt[0])) { + boost::to_upper(satt); + if (getCommandPtr()->Parameters.count(satt)) { + return PyFloat_FromDouble(getCommandPtr()->Parameters[satt]); + } + Py_INCREF(Py_None); + return Py_None; + } + } + return 0; +} + +int CommandPy::setCustomAttributes(const char* attr, PyObject* obj) +{ + std::string satt(attr); + if (satt.length() == 1) { + if (isalpha(satt[0])) { + boost::to_upper(satt); + double cvalue; +#if PY_MAJOR_VERSION >= 3 + if (PyObject_TypeCheck(obj,&(PyLong_Type))) { + cvalue = (double)PyLong_AsLong(obj); +#else + if (PyObject_TypeCheck(obj,&(PyInt_Type))) { + cvalue = (double)PyInt_AsLong(obj); +#endif + } else if (PyObject_TypeCheck(obj,&(PyFloat_Type))) { + cvalue = PyFloat_AsDouble(obj); + } else { + return 0; + } + getCommandPtr()->Parameters[satt]=cvalue; + return 1; + } + } + return 0; +} + + + + diff --git a/src/Mod/Path/App/FeatureArea.cpp b/src/Mod/Path/App/FeatureArea.cpp index f3d9cce3fd..79b30b0c61 100644 --- a/src/Mod/Path/App/FeatureArea.cpp +++ b/src/Mod/Path/App/FeatureArea.cpp @@ -1,256 +1,256 @@ -/**************************************************************************** - * Copyright (c) 2017 Zheng, Lei (realthunder) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -# include -#endif - -#include "FeatureArea.h" -#include "FeatureAreaPy.h" -#include -#include -#include - -FC_LOG_LEVEL_INIT("Path.Area",true,true) - -using namespace Path; - -PROPERTY_SOURCE(Path::FeatureArea, Part::Feature) - -PARAM_ENUM_STRING_DECLARE(static const char *Enums,AREA_PARAMS_ALL) - -FeatureArea::FeatureArea() - :myInited(false) -{ - ADD_PROPERTY(Sources,(0)); - ADD_PROPERTY(WorkPlane,(TopoDS_Shape())); - - PARAM_PROP_ADD("Area",AREA_PARAMS_OPCODE); - PARAM_PROP_ADD("Area",AREA_PARAMS_BASE); - PARAM_PROP_ADD("Offset",AREA_PARAMS_OFFSET); - PARAM_PROP_ADD("Offset", AREA_PARAMS_OFFSET_CONF); - PARAM_PROP_ADD("Pocket",AREA_PARAMS_POCKET); - PARAM_PROP_ADD("Pocket",AREA_PARAMS_POCKET_CONF); - PARAM_PROP_ADD("Section",AREA_PARAMS_SECTION); - PARAM_PROP_ADD("libarea",AREA_PARAMS_CAREA); - - PARAM_PROP_SET_ENUM(Enums,AREA_PARAMS_ALL); - PocketMode.setValue((long)0); -} - -FeatureArea::~FeatureArea() -{ -} - -Area &FeatureArea::getArea() { - if(!myInited) execute(); - return myArea; -} - -App::DocumentObjectExecReturn *FeatureArea::execute(void) -{ - myInited = true; - - std::vector links = Sources.getValues(); - if (links.empty()) - return new App::DocumentObjectExecReturn("No shapes linked"); - - for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { - if (!(*it && (*it)->isDerivedFrom(Part::Feature::getClassTypeId()))) - return new App::DocumentObjectExecReturn("Linked object is not a Part object (has no Shape)."); - TopoDS_Shape shape = static_cast(*it)->Shape.getShape().getShape(); - if (shape.IsNull()) - return new App::DocumentObjectExecReturn("Linked shape object is empty"); - } - - FC_TIME_INIT(t); - - AreaParams params; - -#define AREA_PROP_GET(_param) \ - params.PARAM_FNAME(_param) = PARAM_FNAME(_param).getValue(); - PARAM_FOREACH(AREA_PROP_GET,AREA_PARAMS_CONF) - - myArea.clean(true); - myArea.setParams(params); - - TopoDS_Shape workPlane = WorkPlane.getShape().getShape(); - myArea.setPlane(workPlane); - - for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { - myArea.add(static_cast(*it)->Shape.getShape().getShape(), - PARAM_PROP_ARGS(AREA_PARAMS_OPCODE)); - } - - myShapes.clear(); - if(myArea.getSectionCount()==0) - myShapes.push_back(myArea.getShape(-1)); - else { - myShapes.reserve(myArea.getSectionCount()); - for(int i=0;i<(int)myArea.getSectionCount();++i) - myShapes.push_back(myArea.getShape(i)); - } - - bool hasShape = false; - if(myShapes.empty()) - Shape.setValue(TopoDS_Shape()); - else{ - // compound is built even if there is only one shape to save the - // trouble of messing around with placement - BRep_Builder builder; - TopoDS_Compound compound; - builder.MakeCompound(compound); - for(auto &shape : myShapes) { - if(shape.IsNull()) continue; - hasShape = true; - builder.Add(compound,shape); - } - Shape.setValue(compound); - } - - FC_TIME_LOG(t,"feature execute"); - - if(!hasShape) - return new App::DocumentObjectExecReturn("no output shape"); - - return DocumentObject::StdReturn; -} - -const std::vector &FeatureArea::getShapes() { - getArea(); - return myShapes; -} - -short FeatureArea::mustExecute(void) const -{ - if(myInited && !myArea.isBuilt()) - return 1; - return Part::Feature::mustExecute(); -} - -PyObject *FeatureArea::getPyObject() -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new FeatureAreaPy(this),true); - } - return Py::new_reference_to(PythonObject); -} - - -// FeatureAreaView ------------------------------------------------------------- -// -PROPERTY_SOURCE(Path::FeatureAreaView, Part::Feature) - -FeatureAreaView::FeatureAreaView() -{ - ADD_PROPERTY(Source,(0)); - ADD_PROPERTY_TYPE(SectionIndex,(0),"Section",App::Prop_None,"The start index of the section to show, negative value for reverse index from bottom"); - ADD_PROPERTY_TYPE(SectionCount,(1),"Section",App::Prop_None,"Number of sections to show, 0 to show all section starting from SectionIndex"); -} - -std::list FeatureAreaView::getShapes() { - std::list shapes; - App::DocumentObject* pObj = Source.getValue(); - if (!pObj) return shapes; - if(!pObj->isDerivedFrom(FeatureArea::getClassTypeId())) - return shapes; - - auto all_shapes = static_cast(pObj)->getShapes(); - - if(all_shapes.empty()) - return shapes; - - int index=SectionIndex.getValue(),count=SectionCount.getValue(); - if(index<0) { - index += ((int)all_shapes.size()); - if(index<0) return shapes; - if(count<=0 || index+1-count<0) { - count = index+1; - index = 0; - }else - index -= count-1; - }else if(index >= (int)all_shapes.size()) - return shapes; - - if(count<=0) count = all_shapes.size(); - count += index; - if(count>(int)all_shapes.size()) - count = all_shapes.size(); - for(int i=index;iisDerivedFrom(FeatureArea::getClassTypeId())) - return new App::DocumentObjectExecReturn("Linked object is not a FeatureArea"); - - bool hasShape = false; - std::list shapes = getShapes(); - if(shapes.empty()) - Shape.setValue(TopoDS_Shape()); - else{ - BRep_Builder builder; - TopoDS_Compound compound; - builder.MakeCompound(compound); - for(auto &shape : shapes) { - if(shape.IsNull()) continue; - hasShape = true; - builder.Add(compound,shape); - } - Shape.setValue(compound); - } - - if(!hasShape) - return new App::DocumentObjectExecReturn("no output shape"); - - return DocumentObject::StdReturn; -} - -// Python feature --------------------------------------------------------- - -namespace App { -/// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(Path::FeatureAreaPython, Path::FeatureArea) -PROPERTY_SOURCE_TEMPLATE(Path::FeatureAreaViewPython, Path::FeatureAreaView) - -template<> const char* Path::FeatureAreaPython::getViewProviderName(void) const { - return "PathGui::ViewProviderAreaPython"; -} -template<> const char* Path::FeatureAreaViewPython::getViewProviderName(void) const { - return "PathGui::ViewProviderAreaViewPython"; -} -/// @endcond - -// explicit template instantiation -template class PathExport FeaturePythonT; -} - +/**************************************************************************** + * Copyright (c) 2017 Zheng, Lei (realthunder) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ****************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +#endif + +#include "FeatureArea.h" +#include "FeatureAreaPy.h" +#include +#include +#include + +FC_LOG_LEVEL_INIT("Path.Area",true,true) + +using namespace Path; + +PROPERTY_SOURCE(Path::FeatureArea, Part::Feature) + +PARAM_ENUM_STRING_DECLARE(static const char *Enums,AREA_PARAMS_ALL) + +FeatureArea::FeatureArea() + :myInited(false) +{ + ADD_PROPERTY(Sources,(0)); + ADD_PROPERTY(WorkPlane,(TopoDS_Shape())); + + PARAM_PROP_ADD("Area",AREA_PARAMS_OPCODE); + PARAM_PROP_ADD("Area",AREA_PARAMS_BASE); + PARAM_PROP_ADD("Offset",AREA_PARAMS_OFFSET); + PARAM_PROP_ADD("Offset", AREA_PARAMS_OFFSET_CONF); + PARAM_PROP_ADD("Pocket",AREA_PARAMS_POCKET); + PARAM_PROP_ADD("Pocket",AREA_PARAMS_POCKET_CONF); + PARAM_PROP_ADD("Section",AREA_PARAMS_SECTION); + PARAM_PROP_ADD("libarea",AREA_PARAMS_CAREA); + + PARAM_PROP_SET_ENUM(Enums,AREA_PARAMS_ALL); + PocketMode.setValue((long)0); +} + +FeatureArea::~FeatureArea() +{ +} + +Area &FeatureArea::getArea() { + if(!myInited) execute(); + return myArea; +} + +App::DocumentObjectExecReturn *FeatureArea::execute(void) +{ + myInited = true; + + std::vector links = Sources.getValues(); + if (links.empty()) + return new App::DocumentObjectExecReturn("No shapes linked"); + + for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { + if (!(*it && (*it)->isDerivedFrom(Part::Feature::getClassTypeId()))) + return new App::DocumentObjectExecReturn("Linked object is not a Part object (has no Shape)."); + TopoDS_Shape shape = static_cast(*it)->Shape.getShape().getShape(); + if (shape.IsNull()) + return new App::DocumentObjectExecReturn("Linked shape object is empty"); + } + + FC_TIME_INIT(t); + + AreaParams params; + +#define AREA_PROP_GET(_param) \ + params.PARAM_FNAME(_param) = PARAM_FNAME(_param).getValue(); + PARAM_FOREACH(AREA_PROP_GET,AREA_PARAMS_CONF) + + myArea.clean(true); + myArea.setParams(params); + + TopoDS_Shape workPlane = WorkPlane.getShape().getShape(); + myArea.setPlane(workPlane); + + for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { + myArea.add(static_cast(*it)->Shape.getShape().getShape(), + PARAM_PROP_ARGS(AREA_PARAMS_OPCODE)); + } + + myShapes.clear(); + if(myArea.getSectionCount()==0) + myShapes.push_back(myArea.getShape(-1)); + else { + myShapes.reserve(myArea.getSectionCount()); + for(int i=0;i<(int)myArea.getSectionCount();++i) + myShapes.push_back(myArea.getShape(i)); + } + + bool hasShape = false; + if(myShapes.empty()) + Shape.setValue(TopoDS_Shape()); + else{ + // compound is built even if there is only one shape to save the + // trouble of messing around with placement + BRep_Builder builder; + TopoDS_Compound compound; + builder.MakeCompound(compound); + for(auto &shape : myShapes) { + if(shape.IsNull()) continue; + hasShape = true; + builder.Add(compound,shape); + } + Shape.setValue(compound); + } + + FC_TIME_LOG(t,"feature execute"); + + if(!hasShape) + return new App::DocumentObjectExecReturn("no output shape"); + + return DocumentObject::StdReturn; +} + +const std::vector &FeatureArea::getShapes() { + getArea(); + return myShapes; +} + +short FeatureArea::mustExecute(void) const +{ + if(myInited && !myArea.isBuilt()) + return 1; + return Part::Feature::mustExecute(); +} + +PyObject *FeatureArea::getPyObject() +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new FeatureAreaPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + + +// FeatureAreaView ------------------------------------------------------------- +// +PROPERTY_SOURCE(Path::FeatureAreaView, Part::Feature) + +FeatureAreaView::FeatureAreaView() +{ + ADD_PROPERTY(Source,(0)); + ADD_PROPERTY_TYPE(SectionIndex,(0),"Section",App::Prop_None,"The start index of the section to show, negative value for reverse index from bottom"); + ADD_PROPERTY_TYPE(SectionCount,(1),"Section",App::Prop_None,"Number of sections to show, 0 to show all section starting from SectionIndex"); +} + +std::list FeatureAreaView::getShapes() { + std::list shapes; + App::DocumentObject* pObj = Source.getValue(); + if (!pObj) return shapes; + if(!pObj->isDerivedFrom(FeatureArea::getClassTypeId())) + return shapes; + + auto all_shapes = static_cast(pObj)->getShapes(); + + if(all_shapes.empty()) + return shapes; + + int index=SectionIndex.getValue(),count=SectionCount.getValue(); + if(index<0) { + index += ((int)all_shapes.size()); + if(index<0) return shapes; + if(count<=0 || index+1-count<0) { + count = index+1; + index = 0; + }else + index -= count-1; + }else if(index >= (int)all_shapes.size()) + return shapes; + + if(count<=0) count = all_shapes.size(); + count += index; + if(count>(int)all_shapes.size()) + count = all_shapes.size(); + for(int i=index;iisDerivedFrom(FeatureArea::getClassTypeId())) + return new App::DocumentObjectExecReturn("Linked object is not a FeatureArea"); + + bool hasShape = false; + std::list shapes = getShapes(); + if(shapes.empty()) + Shape.setValue(TopoDS_Shape()); + else{ + BRep_Builder builder; + TopoDS_Compound compound; + builder.MakeCompound(compound); + for(auto &shape : shapes) { + if(shape.IsNull()) continue; + hasShape = true; + builder.Add(compound,shape); + } + Shape.setValue(compound); + } + + if(!hasShape) + return new App::DocumentObjectExecReturn("no output shape"); + + return DocumentObject::StdReturn; +} + +// Python feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Path::FeatureAreaPython, Path::FeatureArea) +PROPERTY_SOURCE_TEMPLATE(Path::FeatureAreaViewPython, Path::FeatureAreaView) + +template<> const char* Path::FeatureAreaPython::getViewProviderName(void) const { + return "PathGui::ViewProviderAreaPython"; +} +template<> const char* Path::FeatureAreaViewPython::getViewProviderName(void) const { + return "PathGui::ViewProviderAreaViewPython"; +} +/// @endcond + +// explicit template instantiation +template class PathExport FeaturePythonT; +} + diff --git a/src/Mod/Path/App/FeatureArea.h b/src/Mod/Path/App/FeatureArea.h index 6c97e12cc3..60c54438c0 100644 --- a/src/Mod/Path/App/FeatureArea.h +++ b/src/Mod/Path/App/FeatureArea.h @@ -1,100 +1,100 @@ -/**************************************************************************** - * Copyright (c) 2017 Zheng, Lei (realthunder) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#ifndef PATH_FeatureArea_H -#define PATH_FeatureArea_H - -#include -#include -#include -#include -#include "Mod/Part/App/PartFeature.h" - -#include "Area.h" - -namespace Path -{ - -class PathExport FeatureArea : public Part::Feature -{ - PROPERTY_HEADER(Path::FeatureArea); - -public: - /// Constructor - FeatureArea(void); - virtual ~FeatureArea(); - - Area &getArea(); - const std::vector &getShapes(); - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "PathGui::ViewProviderArea"; - } - virtual App::DocumentObjectExecReturn *execute(void); - virtual short mustExecute(void) const; - virtual PyObject *getPyObject(void); - - App::PropertyLinkList Sources; - Part::PropertyPartShape WorkPlane; - - PARAM_PROP_DECLARE(AREA_PARAMS_ALL) - - void setWorkPlane(const TopoDS_Shape &shape) { - WorkPlane.setValue(shape); - myArea.setPlane(shape); - } - -private: - Area myArea; - std::vector myShapes; - bool myInited; -}; - -typedef App::FeaturePythonT FeatureAreaPython; - -class PathExport FeatureAreaView : public Part::Feature -{ - PROPERTY_HEADER(Path::FeatureAreaView); - -public: - /// Constructor - FeatureAreaView(void); - - std::list getShapes(); - - virtual const char* getViewProviderName(void) const { - return "PathGui::ViewProviderAreaView"; - } - virtual App::DocumentObjectExecReturn *execute(void); - - App::PropertyLink Source; - App::PropertyInteger SectionIndex; - App::PropertyInteger SectionCount; -}; - -typedef App::FeaturePythonT FeatureAreaViewPython; - -} //namespace Path - - -#endif // PATH_FeaturePath_H +/**************************************************************************** + * Copyright (c) 2017 Zheng, Lei (realthunder) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ****************************************************************************/ + +#ifndef PATH_FeatureArea_H +#define PATH_FeatureArea_H + +#include +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +#include "Area.h" + +namespace Path +{ + +class PathExport FeatureArea : public Part::Feature +{ + PROPERTY_HEADER(Path::FeatureArea); + +public: + /// Constructor + FeatureArea(void); + virtual ~FeatureArea(); + + Area &getArea(); + const std::vector &getShapes(); + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "PathGui::ViewProviderArea"; + } + virtual App::DocumentObjectExecReturn *execute(void); + virtual short mustExecute(void) const; + virtual PyObject *getPyObject(void); + + App::PropertyLinkList Sources; + Part::PropertyPartShape WorkPlane; + + PARAM_PROP_DECLARE(AREA_PARAMS_ALL) + + void setWorkPlane(const TopoDS_Shape &shape) { + WorkPlane.setValue(shape); + myArea.setPlane(shape); + } + +private: + Area myArea; + std::vector myShapes; + bool myInited; +}; + +typedef App::FeaturePythonT FeatureAreaPython; + +class PathExport FeatureAreaView : public Part::Feature +{ + PROPERTY_HEADER(Path::FeatureAreaView); + +public: + /// Constructor + FeatureAreaView(void); + + std::list getShapes(); + + virtual const char* getViewProviderName(void) const { + return "PathGui::ViewProviderAreaView"; + } + virtual App::DocumentObjectExecReturn *execute(void); + + App::PropertyLink Source; + App::PropertyInteger SectionIndex; + App::PropertyInteger SectionCount; +}; + +typedef App::FeaturePythonT FeatureAreaViewPython; + +} //namespace Path + + +#endif // PATH_FeaturePath_H diff --git a/src/Mod/Path/App/FeatureAreaPyImp.cpp b/src/Mod/Path/App/FeatureAreaPyImp.cpp index e33f6a019b..4e7765b9b5 100644 --- a/src/Mod/Path/App/FeatureAreaPyImp.cpp +++ b/src/Mod/Path/App/FeatureAreaPyImp.cpp @@ -1,109 +1,109 @@ -/**************************************************************************** - * Copyright (c) 2017 Zheng, Lei (realthunder) * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#include "PreCompiled.h" - -#include -#include -#include "FeatureArea.h" - -// inclusion of the generated files (generated out of FeatureAreaPy.xml) -#include "FeatureAreaPy.h" -#include "FeatureAreaPy.cpp" - -#include "AreaPy.h" - -using namespace Path; - - -// returns a string which represent the object e.g. when printed in python -std::string FeatureAreaPy::representation(void) const -{ - return std::string(""); -} - - -PyObject* FeatureAreaPy::getArea(PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return NULL; - - return new AreaPy(new Area(getFeatureAreaPtr()->getArea())); -} - -PyObject* FeatureAreaPy::setParams(PyObject *args, PyObject *keywds) -{ - static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_CONF),NULL}; - - //Declare variables defined in the NAME field of the CONF parameter list - PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_CONF); - - FeatureArea *feature = getFeatureAreaPtr(); - -#define AREA_SET(_param) \ - PARAM_FNAME(_param) = \ - PARAM_TYPED(PARAM_PY_CAST_,_param)(feature->PARAM_FNAME(_param).getValue()); - //populate the CONF variables with values in properties - PARAM_FOREACH(AREA_SET,AREA_PARAMS_CONF) - - //Parse arguments to overwrite CONF variables - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, - PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) - return 0; - -#define AREA_GET(_param) \ - feature->PARAM_FNAME(_param).setValue(\ - PARAM_TYPED(PARAM_CAST_PY_,_param)(PARAM_FNAME(_param))); - //populate properties with the CONF variables - PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF) - - Py_INCREF(Py_None); - return Py_None; -} - -Py::Object FeatureAreaPy::getWorkPlane(void) const { - return Part::shape2pyshape(getFeatureAreaPtr()->getArea().getPlane()); -} - -void FeatureAreaPy::setWorkPlane(Py::Object obj) { - PyObject* p = obj.ptr(); - if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) { - std::string error = std::string("type must be 'TopoShape', not "); - error += p->ob_type->tp_name; - throw Py::TypeError(error); - } - getFeatureAreaPtr()->setWorkPlane( - static_cast(p)->getTopoShapePtr()->getShape()); -} - -PyObject *FeatureAreaPy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - - -int FeatureAreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} - +/**************************************************************************** + * Copyright (c) 2017 Zheng, Lei (realthunder) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ****************************************************************************/ + +#include "PreCompiled.h" + +#include +#include +#include "FeatureArea.h" + +// inclusion of the generated files (generated out of FeatureAreaPy.xml) +#include "FeatureAreaPy.h" +#include "FeatureAreaPy.cpp" + +#include "AreaPy.h" + +using namespace Path; + + +// returns a string which represent the object e.g. when printed in python +std::string FeatureAreaPy::representation(void) const +{ + return std::string(""); +} + + +PyObject* FeatureAreaPy::getArea(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + return new AreaPy(new Area(getFeatureAreaPtr()->getArea())); +} + +PyObject* FeatureAreaPy::setParams(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {PARAM_FIELD_STRINGS(NAME,AREA_PARAMS_CONF),NULL}; + + //Declare variables defined in the NAME field of the CONF parameter list + PARAM_PY_DECLARE(PARAM_FNAME,AREA_PARAMS_CONF); + + FeatureArea *feature = getFeatureAreaPtr(); + +#define AREA_SET(_param) \ + PARAM_FNAME(_param) = \ + PARAM_TYPED(PARAM_PY_CAST_,_param)(feature->PARAM_FNAME(_param).getValue()); + //populate the CONF variables with values in properties + PARAM_FOREACH(AREA_SET,AREA_PARAMS_CONF) + + //Parse arguments to overwrite CONF variables + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "|" PARAM_PY_KWDS(AREA_PARAMS_CONF), kwlist, + PARAM_REF(PARAM_FNAME,AREA_PARAMS_CONF))) + return 0; + +#define AREA_GET(_param) \ + feature->PARAM_FNAME(_param).setValue(\ + PARAM_TYPED(PARAM_CAST_PY_,_param)(PARAM_FNAME(_param))); + //populate properties with the CONF variables + PARAM_FOREACH(AREA_GET,AREA_PARAMS_CONF) + + Py_INCREF(Py_None); + return Py_None; +} + +Py::Object FeatureAreaPy::getWorkPlane(void) const { + return Part::shape2pyshape(getFeatureAreaPtr()->getArea().getPlane()); +} + +void FeatureAreaPy::setWorkPlane(Py::Object obj) { + PyObject* p = obj.ptr(); + if (!PyObject_TypeCheck(p, &(Part::TopoShapePy::Type))) { + std::string error = std::string("type must be 'TopoShape', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + getFeatureAreaPtr()->setWorkPlane( + static_cast(p)->getTopoShapePtr()->getShape()); +} + +PyObject *FeatureAreaPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + + +int FeatureAreaPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + diff --git a/src/Mod/Path/App/FeaturePath.cpp b/src/Mod/Path/App/FeaturePath.cpp index a391a4b1e2..171c0984dd 100644 --- a/src/Mod/Path/App/FeaturePath.cpp +++ b/src/Mod/Path/App/FeaturePath.cpp @@ -1,78 +1,78 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -#endif - -#include "FeaturePath.h" -#include -#include - -using namespace Path; - -PROPERTY_SOURCE(Path::Feature, App::GeoFeature) - - -Feature::Feature() -{ - ADD_PROPERTY_TYPE(Path,(Path::Toolpath()),"Base",App::Prop_None,"The path data of this feature"); -} - -Feature::~Feature() -{ -} - -short Feature::mustExecute(void) const -{ - return App::GeoFeature::mustExecute(); -} - -PyObject *Feature::getPyObject() -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new App::DocumentObjectPy(this),true); - } - return Py::new_reference_to(PythonObject); -} - -void Feature::onChanged(const App::Property* prop) -{ - App::GeoFeature::onChanged(prop); -} - -// Python Path feature --------------------------------------------------------- - -namespace App { -/// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(Path::FeaturePython, Path::Feature) -template<> const char* Path::FeaturePython::getViewProviderName(void) const { - return "PathGui::ViewProviderPathPython"; -} -/// @endcond - -// explicit template instantiation -template class PathExport FeaturePythonT; -} +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include "FeaturePath.h" +#include +#include + +using namespace Path; + +PROPERTY_SOURCE(Path::Feature, App::GeoFeature) + + +Feature::Feature() +{ + ADD_PROPERTY_TYPE(Path,(Path::Toolpath()),"Base",App::Prop_None,"The path data of this feature"); +} + +Feature::~Feature() +{ +} + +short Feature::mustExecute(void) const +{ + return App::GeoFeature::mustExecute(); +} + +PyObject *Feature::getPyObject() +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new App::DocumentObjectPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +void Feature::onChanged(const App::Property* prop) +{ + App::GeoFeature::onChanged(prop); +} + +// Python Path feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Path::FeaturePython, Path::Feature) +template<> const char* Path::FeaturePython::getViewProviderName(void) const { + return "PathGui::ViewProviderPathPython"; +} +/// @endcond + +// explicit template instantiation +template class PathExport FeaturePythonT; +} diff --git a/src/Mod/Path/App/FeaturePath.h b/src/Mod/Path/App/FeaturePath.h index 0cf587bddb..e8b8e89eaa 100644 --- a/src/Mod/Path/App/FeaturePath.h +++ b/src/Mod/Path/App/FeaturePath.h @@ -1,72 +1,72 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_FeaturePath_H -#define PATH_FeaturePath_H - -#include -#include -#include -#include -#include - -#include "Path.h" -#include "PropertyPath.h" - -namespace Path -{ - -class PathExport Feature : public App::GeoFeature -{ - PROPERTY_HEADER(Path::Feature); - -public: - /// Constructor - Feature(void); - virtual ~Feature(); - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "PathGui::ViewProviderPath"; - } - virtual App::DocumentObjectExecReturn *execute(void) { - return App::DocumentObject::StdReturn; - } - virtual short mustExecute(void) const; - virtual PyObject *getPyObject(void); - - PropertyPath Path; - - -protected: - /// get called by the container when a property has changed - virtual void onChanged (const App::Property* prop); - -}; - -typedef App::FeaturePythonT FeaturePython; - -} //namespace Path - - -#endif // PATH_FeaturePath_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_FeaturePath_H +#define PATH_FeaturePath_H + +#include +#include +#include +#include +#include + +#include "Path.h" +#include "PropertyPath.h" + +namespace Path +{ + +class PathExport Feature : public App::GeoFeature +{ + PROPERTY_HEADER(Path::Feature); + +public: + /// Constructor + Feature(void); + virtual ~Feature(); + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "PathGui::ViewProviderPath"; + } + virtual App::DocumentObjectExecReturn *execute(void) { + return App::DocumentObject::StdReturn; + } + virtual short mustExecute(void) const; + virtual PyObject *getPyObject(void); + + PropertyPath Path; + + +protected: + /// get called by the container when a property has changed + virtual void onChanged (const App::Property* prop); + +}; + +typedef App::FeaturePythonT FeaturePython; + +} //namespace Path + + +#endif // PATH_FeaturePath_H diff --git a/src/Mod/Path/App/FeaturePathCompound.cpp b/src/Mod/Path/App/FeaturePathCompound.cpp index 1c66ce14f2..957742da3d 100644 --- a/src/Mod/Path/App/FeaturePathCompound.cpp +++ b/src/Mod/Path/App/FeaturePathCompound.cpp @@ -1,131 +1,131 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -#endif - -#include "FeaturePathCompound.h" -#include "Command.h" -#include "Path.h" -#include "FeaturePathCompoundPy.h" -#include - -using namespace Path; -using namespace App; - -PROPERTY_SOURCE(Path::FeatureCompound, Path::Feature) - - -FeatureCompound::FeatureCompound() -{ - ADD_PROPERTY_TYPE( Group, (0), "Base",Prop_None,"Ordered list of paths to combine"); - ADD_PROPERTY_TYPE( UsePlacements, (false), "Base",Prop_None,"Specifies if the placements of children must be computed"); -} - -FeatureCompound::~FeatureCompound() -{ -} - -App::DocumentObjectExecReturn *FeatureCompound::execute(void) -{ - const std::vector &Paths = Group.getValues(); - Path::Toolpath result; - - for (std::vector::const_iterator it= Paths.begin();it!=Paths.end();++it) { - if ((*it)->getTypeId().isDerivedFrom(Path::Feature::getClassTypeId())){ - const std::vector &cmds = static_cast(*it)->Path.getValue().getCommands(); - const Base::Placement pl = static_cast(*it)->Placement.getValue(); - for (std::vector::const_iterator it2= cmds.begin();it2!=cmds.end();++it2) { - if (UsePlacements.getValue() == true) { - result.addCommand((*it2)->transform(pl)); - } else { - result.addCommand(**it2); - } - } - } else { - return new App::DocumentObjectExecReturn("Not all objects in group are paths!"); - } - } - - result.setCenter(Path.getValue().getCenter()); - Path.setValue(result); - - return App::DocumentObject::StdReturn; -} - -bool FeatureCompound::hasObject(const DocumentObject* obj) const -{ - const std::vector& grp = Group.getValues(); - for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { - if (*it == obj) - return true; - } - - return false; -} - -void FeatureCompound::addObject(DocumentObject* obj) -{ - if (!hasObject(obj)) { - std::vector grp = Group.getValues(); - grp.push_back(obj); - Group.setValues(grp); - } -} - -void FeatureCompound::removeObject(DocumentObject* obj) -{ - std::vector grp = Group.getValues(); - for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { - if (*it == obj) { - grp.erase(it); - Group.setValues(grp); - break; - } - } -} - -PyObject *FeatureCompound::getPyObject() -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new FeaturePathCompoundPy(this),true); - } - return Py::new_reference_to(PythonObject); -} - -// Python Path Compound feature --------------------------------------------------------- - -namespace App { -/// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(Path::FeatureCompoundPython, Path::FeatureCompound) -template<> const char* Path::FeatureCompoundPython::getViewProviderName(void) const { - return "PathGui::ViewProviderPathCompoundPython"; -} -/// @endcond - -// explicit template instantiation -template class PathExport FeaturePythonT; -} +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include "FeaturePathCompound.h" +#include "Command.h" +#include "Path.h" +#include "FeaturePathCompoundPy.h" +#include + +using namespace Path; +using namespace App; + +PROPERTY_SOURCE(Path::FeatureCompound, Path::Feature) + + +FeatureCompound::FeatureCompound() +{ + ADD_PROPERTY_TYPE( Group, (0), "Base",Prop_None,"Ordered list of paths to combine"); + ADD_PROPERTY_TYPE( UsePlacements, (false), "Base",Prop_None,"Specifies if the placements of children must be computed"); +} + +FeatureCompound::~FeatureCompound() +{ +} + +App::DocumentObjectExecReturn *FeatureCompound::execute(void) +{ + const std::vector &Paths = Group.getValues(); + Path::Toolpath result; + + for (std::vector::const_iterator it= Paths.begin();it!=Paths.end();++it) { + if ((*it)->getTypeId().isDerivedFrom(Path::Feature::getClassTypeId())){ + const std::vector &cmds = static_cast(*it)->Path.getValue().getCommands(); + const Base::Placement pl = static_cast(*it)->Placement.getValue(); + for (std::vector::const_iterator it2= cmds.begin();it2!=cmds.end();++it2) { + if (UsePlacements.getValue() == true) { + result.addCommand((*it2)->transform(pl)); + } else { + result.addCommand(**it2); + } + } + } else { + return new App::DocumentObjectExecReturn("Not all objects in group are paths!"); + } + } + + result.setCenter(Path.getValue().getCenter()); + Path.setValue(result); + + return App::DocumentObject::StdReturn; +} + +bool FeatureCompound::hasObject(const DocumentObject* obj) const +{ + const std::vector& grp = Group.getValues(); + for (std::vector::const_iterator it = grp.begin(); it != grp.end(); ++it) { + if (*it == obj) + return true; + } + + return false; +} + +void FeatureCompound::addObject(DocumentObject* obj) +{ + if (!hasObject(obj)) { + std::vector grp = Group.getValues(); + grp.push_back(obj); + Group.setValues(grp); + } +} + +void FeatureCompound::removeObject(DocumentObject* obj) +{ + std::vector grp = Group.getValues(); + for (std::vector::iterator it = grp.begin(); it != grp.end(); ++it) { + if (*it == obj) { + grp.erase(it); + Group.setValues(grp); + break; + } + } +} + +PyObject *FeatureCompound::getPyObject() +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new FeaturePathCompoundPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Path Compound feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Path::FeatureCompoundPython, Path::FeatureCompound) +template<> const char* Path::FeatureCompoundPython::getViewProviderName(void) const { + return "PathGui::ViewProviderPathCompoundPython"; +} +/// @endcond + +// explicit template instantiation +template class PathExport FeaturePythonT; +} diff --git a/src/Mod/Path/App/FeaturePathCompound.h b/src/Mod/Path/App/FeaturePathCompound.h index 0eec729b45..3e93daf7d2 100644 --- a/src/Mod/Path/App/FeaturePathCompound.h +++ b/src/Mod/Path/App/FeaturePathCompound.h @@ -1,72 +1,72 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_FeatureCompound_H -#define PATH_FeatureCompound_H - -#include -#include -#include -#include - -#include "Path.h" -#include "FeaturePath.h" -#include "PropertyPath.h" - -namespace Path -{ - -class PathExport FeatureCompound : public Path::Feature -{ - PROPERTY_HEADER(Path::Feature); - -public: - /// Constructor - FeatureCompound(void); - virtual ~FeatureCompound(); - - App::PropertyLinkList Group; - App::PropertyBool UsePlacements; - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "PathGui::ViewProviderPathCompound"; - } - virtual App::DocumentObjectExecReturn *execute(void); - - /// Checks whether the object \a obj is part of this group. - bool hasObject(const DocumentObject* obj) const; - /// Adds an object to this group. - void addObject(DocumentObject* obj); - /// Removes an object from this group. - void removeObject(DocumentObject* obj); - virtual PyObject *getPyObject(void); - -}; - -typedef App::FeaturePythonT FeatureCompoundPython; - -} //namespace Path - - -#endif // PATH_FeatureCompound_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_FeatureCompound_H +#define PATH_FeatureCompound_H + +#include +#include +#include +#include + +#include "Path.h" +#include "FeaturePath.h" +#include "PropertyPath.h" + +namespace Path +{ + +class PathExport FeatureCompound : public Path::Feature +{ + PROPERTY_HEADER(Path::Feature); + +public: + /// Constructor + FeatureCompound(void); + virtual ~FeatureCompound(); + + App::PropertyLinkList Group; + App::PropertyBool UsePlacements; + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "PathGui::ViewProviderPathCompound"; + } + virtual App::DocumentObjectExecReturn *execute(void); + + /// Checks whether the object \a obj is part of this group. + bool hasObject(const DocumentObject* obj) const; + /// Adds an object to this group. + void addObject(DocumentObject* obj); + /// Removes an object from this group. + void removeObject(DocumentObject* obj); + virtual PyObject *getPyObject(void); + +}; + +typedef App::FeaturePythonT FeatureCompoundPython; + +} //namespace Path + + +#endif // PATH_FeatureCompound_H diff --git a/src/Mod/Path/App/FeaturePathCompoundPy.xml b/src/Mod/Path/App/FeaturePathCompoundPy.xml index fae79f2c0b..58dcb7a10a 100644 --- a/src/Mod/Path/App/FeaturePathCompoundPy.xml +++ b/src/Mod/Path/App/FeaturePathCompoundPy.xml @@ -1,28 +1,28 @@ - - - - - - This class handles Path Compound features - - - - Add an object to the group - - - - - Remove an object from the group - - - - - + + + + + + This class handles Path Compound features + + + + Add an object to the group + + + + + Remove an object from the group + + + + + diff --git a/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp b/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp index 406e647e4d..33a410a155 100644 --- a/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp +++ b/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp @@ -1,139 +1,139 @@ -/*************************************************************************** - * Copyright (c) 2007 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#include "FeaturePathCompound.h" -#include - -// inclusion of the generated files (generated out of FeaturePathCompoundPy.xml) -#include "FeaturePathCompoundPy.h" -#include "FeaturePathCompoundPy.cpp" - -using namespace Path; - - -// returns a string which represents the object e.g. when printed in python -std::string FeaturePathCompoundPy::representation(void) const -{ - return std::string(""); -} - - -PyObject* FeaturePathCompoundPy::addObject(PyObject *args) -{ - PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObjectPy* docObj = static_cast(object); - if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { - PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an invalid object"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { - PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group"); - return NULL; - } - if (docObj->getDocumentObjectPtr() == this->getFeaturePathCompoundPtr()) { - PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself"); - return NULL; - } - - FeatureCompound* comp = getFeaturePathCompoundPtr(); - - if (comp->getTypeId().isDerivedFrom(Path::FeatureCompoundPython::getClassTypeId())) { - FeatureCompoundPython* comppy = static_cast(comp); - App::Property* proxy = comppy->getPropertyByName("Proxy"); - if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { - Py::Object vp = static_cast(proxy)->getValue(); - if (vp.hasAttr(std::string("addObject"))) { - Py::Callable method(vp.getAttr(std::string("addObject"))); - // check to which method this belongs to avoid an infinite recursion - if (method.getAttr(std::string("__self__")) != Py::Object(this)) { - Py::Tuple args(1); - args[0] = Py::Object(object); - method.apply(args); - Py_Return; - } - } - } - } - - comp->addObject(docObj->getDocumentObjectPtr()); - Py_Return; -} - - -PyObject* FeaturePathCompoundPy::removeObject(PyObject *args) -{ - PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception - - DocumentObjectPy* docObj = static_cast(object); - if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { - PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an invalid object"); - return NULL; - } - if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { - PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group"); - return NULL; - } - - FeatureCompound* comp = getFeaturePathCompoundPtr(); - - if (comp->getTypeId().isDerivedFrom(Path::FeatureCompoundPython::getClassTypeId())) { - FeatureCompoundPython* comppy = static_cast(comp); - App::Property* proxy = comppy->getPropertyByName("Proxy"); - if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { - Py::Object vp = static_cast(proxy)->getValue(); - if (vp.hasAttr(std::string("removeObject"))) { - Py::Callable method(vp.getAttr(std::string("removeObject"))); - // check to which method this belongs to avoid an infinite recursion - if (method.getAttr(std::string("__self__")) != Py::Object(this)) { - Py::Tuple args(1); - args[0] = Py::Object(object); - method.apply(args); - Py_Return; - } - } - } - } - - comp->removeObject(docObj->getDocumentObjectPtr()); - Py_Return; -} - - - -PyObject *FeaturePathCompoundPy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - - -int FeaturePathCompoundPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} +/*************************************************************************** + * Copyright (c) 2007 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "FeaturePathCompound.h" +#include + +// inclusion of the generated files (generated out of FeaturePathCompoundPy.xml) +#include "FeaturePathCompoundPy.h" +#include "FeaturePathCompoundPy.cpp" + +using namespace Path; + + +// returns a string which represents the object e.g. when printed in python +std::string FeaturePathCompoundPy::representation(void) const +{ + return std::string(""); +} + + +PyObject* FeaturePathCompoundPy::addObject(PyObject *args) +{ + PyObject *object; + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObjectPy* docObj = static_cast(object); + if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an invalid object"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group"); + return NULL; + } + if (docObj->getDocumentObjectPtr() == this->getFeaturePathCompoundPtr()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself"); + return NULL; + } + + FeatureCompound* comp = getFeaturePathCompoundPtr(); + + if (comp->getTypeId().isDerivedFrom(Path::FeatureCompoundPython::getClassTypeId())) { + FeatureCompoundPython* comppy = static_cast(comp); + App::Property* proxy = comppy->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("addObject"))) { + Py::Callable method(vp.getAttr(std::string("addObject"))); + // check to which method this belongs to avoid an infinite recursion + if (method.getAttr(std::string("__self__")) != Py::Object(this)) { + Py::Tuple args(1); + args[0] = Py::Object(object); + method.apply(args); + Py_Return; + } + } + } + } + + comp->addObject(docObj->getDocumentObjectPtr()); + Py_Return; +} + + +PyObject* FeaturePathCompoundPy::removeObject(PyObject *args) +{ + PyObject *object; + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C + return NULL; // NULL triggers exception + + DocumentObjectPy* docObj = static_cast(object); + if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an invalid object"); + return NULL; + } + if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { + PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group"); + return NULL; + } + + FeatureCompound* comp = getFeaturePathCompoundPtr(); + + if (comp->getTypeId().isDerivedFrom(Path::FeatureCompoundPython::getClassTypeId())) { + FeatureCompoundPython* comppy = static_cast(comp); + App::Property* proxy = comppy->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("removeObject"))) { + Py::Callable method(vp.getAttr(std::string("removeObject"))); + // check to which method this belongs to avoid an infinite recursion + if (method.getAttr(std::string("__self__")) != Py::Object(this)) { + Py::Tuple args(1); + args[0] = Py::Object(object); + method.apply(args); + Py_Return; + } + } + } + } + + comp->removeObject(docObj->getDocumentObjectPtr()); + Py_Return; +} + + + +PyObject *FeaturePathCompoundPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + + +int FeaturePathCompoundPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Path/App/FeaturePathShape.cpp b/src/Mod/Path/App/FeaturePathShape.cpp index 4a730341dd..906b237c05 100644 --- a/src/Mod/Path/App/FeaturePathShape.cpp +++ b/src/Mod/Path/App/FeaturePathShape.cpp @@ -1,110 +1,110 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ -/* - * Copyright (c) 2017 Zheng, Lei - */ - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -#endif - -#include "FeaturePathShape.h" -#include "Command.h" - -#include -#include -#include -#include - -#include "FeatureArea.h" - -using namespace Path; - -PROPERTY_SOURCE(Path::FeatureShape, Path::Feature) - -PARAM_ENUM_STRING_DECLARE(static const char *Enums,AREA_PARAMS_PATH) - -FeatureShape::FeatureShape() -{ - ADD_PROPERTY(Sources,(0)); - ADD_PROPERTY_TYPE(StartPoint,(Base::Vector3d()),"Path",App::Prop_None,"Feed start position"); - ADD_PROPERTY_TYPE(UseStartPoint,(false),"Path",App::Prop_None,"Enable feed start position"); - PARAM_PROP_ADD("Path",AREA_PARAMS_PATH); - PARAM_PROP_SET_ENUM(Enums,AREA_PARAMS_PATH); -} - -FeatureShape::~FeatureShape() -{ -} - -App::DocumentObjectExecReturn *FeatureShape::execute(void) -{ - Toolpath path; - std::vector links = Sources.getValues(); - if (links.empty()) { - Path.setValue(path); - return new App::DocumentObjectExecReturn("No shapes linked"); - } - - const Base::Vector3d &v = StartPoint.getValue(); - gp_Pnt pstart(v.x,v.y,v.z); - - std::list shapes; - for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { - if (!(*it && (*it)->isDerivedFrom(Part::Feature::getClassTypeId()))) - continue; - const TopoDS_Shape &shape = static_cast(*it)->Shape.getShape().getShape(); - if (shape.IsNull()) - continue; - shapes.push_back(shape); - } - - Area::toPath(path,shapes,UseStartPoint.getValue()?&pstart:0,0,PARAM_PROP_ARGS(AREA_PARAMS_PATH)); - - Path.setValue(path); - return App::DocumentObject::StdReturn; -} - -// Python Path Shape feature --------------------------------------------------------- - -namespace App { -/// @cond DOXERR -PROPERTY_SOURCE_TEMPLATE(Path::FeatureShapePython, Path::FeatureShape) -template<> const char* Path::FeatureShapePython::getViewProviderName(void) const { - return "PathGui::ViewProviderPathShape"; -} -/// @endcond - -// explicit template instantiation -template class PathExport FeaturePythonT; -} - - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ +/* + * Copyright (c) 2017 Zheng, Lei + */ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "FeaturePathShape.h" +#include "Command.h" + +#include +#include +#include +#include + +#include "FeatureArea.h" + +using namespace Path; + +PROPERTY_SOURCE(Path::FeatureShape, Path::Feature) + +PARAM_ENUM_STRING_DECLARE(static const char *Enums,AREA_PARAMS_PATH) + +FeatureShape::FeatureShape() +{ + ADD_PROPERTY(Sources,(0)); + ADD_PROPERTY_TYPE(StartPoint,(Base::Vector3d()),"Path",App::Prop_None,"Feed start position"); + ADD_PROPERTY_TYPE(UseStartPoint,(false),"Path",App::Prop_None,"Enable feed start position"); + PARAM_PROP_ADD("Path",AREA_PARAMS_PATH); + PARAM_PROP_SET_ENUM(Enums,AREA_PARAMS_PATH); +} + +FeatureShape::~FeatureShape() +{ +} + +App::DocumentObjectExecReturn *FeatureShape::execute(void) +{ + Toolpath path; + std::vector links = Sources.getValues(); + if (links.empty()) { + Path.setValue(path); + return new App::DocumentObjectExecReturn("No shapes linked"); + } + + const Base::Vector3d &v = StartPoint.getValue(); + gp_Pnt pstart(v.x,v.y,v.z); + + std::list shapes; + for (std::vector::iterator it = links.begin(); it != links.end(); ++it) { + if (!(*it && (*it)->isDerivedFrom(Part::Feature::getClassTypeId()))) + continue; + const TopoDS_Shape &shape = static_cast(*it)->Shape.getShape().getShape(); + if (shape.IsNull()) + continue; + shapes.push_back(shape); + } + + Area::toPath(path,shapes,UseStartPoint.getValue()?&pstart:0,0,PARAM_PROP_ARGS(AREA_PARAMS_PATH)); + + Path.setValue(path); + return App::DocumentObject::StdReturn; +} + +// Python Path Shape feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(Path::FeatureShapePython, Path::FeatureShape) +template<> const char* Path::FeatureShapePython::getViewProviderName(void) const { + return "PathGui::ViewProviderPathShape"; +} +/// @endcond + +// explicit template instantiation +template class PathExport FeaturePythonT; +} + + + diff --git a/src/Mod/Path/App/FeaturePathShape.h b/src/Mod/Path/App/FeaturePathShape.h index 1234402431..edb4169d8c 100644 --- a/src/Mod/Path/App/FeaturePathShape.h +++ b/src/Mod/Path/App/FeaturePathShape.h @@ -1,80 +1,80 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ -/* - * Copyright (c) 2017 Zheng, Lei - */ - - -#ifndef PATH_FeaturePathShape_H -#define PATH_FeaturePathShape_H - -#include -#include -#include -#include -#include "Mod/Part/App/PropertyTopoShape.h" - -#include "PropertyPath.h" -#include "FeaturePath.h" -#include "FeatureArea.h" -#include "Area.h" - -namespace Path -{ - -class PathExport FeatureShape : public Path::Feature -{ - PROPERTY_HEADER(Path::FeatureShape); - -public: - /// Constructor - FeatureShape(void); - virtual ~FeatureShape(); - - // Part::PropertyPartShape Shape; - App::PropertyLinkList Sources; - App::PropertyVector StartPoint; - App::PropertyBool UseStartPoint; - PARAM_PROP_DECLARE(AREA_PARAMS_PATH) - - //@{ - /// recalculate the feature - virtual App::DocumentObjectExecReturn *execute(void); - //@} - - /// returns the type name of the ViewProvider - virtual const char* getViewProviderName(void) const { - return "PathGui::ViewProviderPathShape"; - } - -protected: - /// get called by the container when a property has changed - //virtual void onChanged (const App::Property* prop); - -}; - -typedef App::FeaturePythonT FeatureShapePython; - -} //namespace Path - - -#endif // PATH_FeaturePathShape_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ +/* + * Copyright (c) 2017 Zheng, Lei + */ + + +#ifndef PATH_FeaturePathShape_H +#define PATH_FeaturePathShape_H + +#include +#include +#include +#include +#include "Mod/Part/App/PropertyTopoShape.h" + +#include "PropertyPath.h" +#include "FeaturePath.h" +#include "FeatureArea.h" +#include "Area.h" + +namespace Path +{ + +class PathExport FeatureShape : public Path::Feature +{ + PROPERTY_HEADER(Path::FeatureShape); + +public: + /// Constructor + FeatureShape(void); + virtual ~FeatureShape(); + + // Part::PropertyPartShape Shape; + App::PropertyLinkList Sources; + App::PropertyVector StartPoint; + App::PropertyBool UseStartPoint; + PARAM_PROP_DECLARE(AREA_PARAMS_PATH) + + //@{ + /// recalculate the feature + virtual App::DocumentObjectExecReturn *execute(void); + //@} + + /// returns the type name of the ViewProvider + virtual const char* getViewProviderName(void) const { + return "PathGui::ViewProviderPathShape"; + } + +protected: + /// get called by the container when a property has changed + //virtual void onChanged (const App::Property* prop); + +}; + +typedef App::FeaturePythonT FeatureShapePython; + +} //namespace Path + + +#endif // PATH_FeaturePathShape_H diff --git a/src/Mod/Path/App/Path.cpp b/src/Mod/Path/App/Path.cpp index e0451ff0a5..6287ec76a2 100644 --- a/src/Mod/Path/App/Path.cpp +++ b/src/Mod/Path/App/Path.cpp @@ -1,498 +1,498 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -#endif - -#include -#include -#include -#include -#include - -// KDL stuff - at the moment, not used -//#include "Mod/Robot/App/kdl_cp/path_line.hpp" -//#include "Mod/Robot/App/kdl_cp/path_circle.hpp" -//#include "Mod/Robot/App/kdl_cp/rotational_interpolation_sa.hpp" -//#include "Mod/Robot/App/kdl_cp/utilities/error.h" - -#include "Path.h" -#include - -using namespace Path; -using namespace Base; - -TYPESYSTEM_SOURCE(Path::Toolpath , Base::Persistence) - -Toolpath::Toolpath() -{ -} - -Toolpath::Toolpath(const Toolpath& otherPath) - : vpcCommands(otherPath.vpcCommands.size()) - , center(otherPath.center) -{ - *this = otherPath; - recalculate(); -} - -Toolpath::~Toolpath() -{ - clear(); -} - -Toolpath &Toolpath::operator=(const Toolpath& otherPath) -{ - if (this == &otherPath) - return *this; - - clear(); - vpcCommands.resize(otherPath.vpcCommands.size()); - int i = 0; - for (std::vector::const_iterator it=otherPath.vpcCommands.begin();it!=otherPath.vpcCommands.end();++it,i++) { - vpcCommands[i] = new Command(**it); - } - center = otherPath.center; - recalculate(); - return *this; -} - -void Toolpath::clear(void) -{ - for(std::vector::iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) - delete ( *it ); - vpcCommands.clear(); - recalculate(); -} - -void Toolpath::addCommand(const Command &Cmd) -{ - Command *tmp = new Command(Cmd); - vpcCommands.push_back(tmp); - recalculate(); -} - -void Toolpath::insertCommand(const Command &Cmd, int pos) -{ - if (pos == -1) { - addCommand(Cmd); - } else if (pos <= static_cast(vpcCommands.size())) { - Command *tmp = new Command(Cmd); - vpcCommands.insert(vpcCommands.begin()+pos,tmp); - } else { - throw Base::IndexError("Index not in range"); - } - recalculate(); -} - -void Toolpath::deleteCommand(int pos) -{ - if (pos == -1) { - //delete(*vpcCommands.rbegin()); // causes crash - vpcCommands.pop_back(); - } else if (pos <= static_cast(vpcCommands.size())) { - vpcCommands.erase (vpcCommands.begin()+pos); - } else { - throw Base::IndexError("Index not in range"); - } - recalculate(); -} - -double Toolpath::getLength() -{ - if(vpcCommands.size()==0) - return 0; - double l = 0; - Vector3d last(0,0,0); - Vector3d next; - for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { - std::string name = (*it)->Name; - next = (*it)->getPlacement(last).getPosition(); - if ( (name == "G0") || (name == "G00") || (name == "G1") || (name == "G01") ) { - // straight line - l += (next - last).Length(); - last = next; - } else if ( (name == "G2") || (name == "G02") || (name == "G3") || (name == "G03") ) { - // arc - Vector3d center = (*it)->getCenter(); - double radius = (last - center).Length(); - double angle = (next - center).GetAngle(last - center); - l += angle * radius; - last = next; - } - } - return l; -} - -double Toolpath::getCycleTime(double hFeed, double vFeed, double hRapid, double vRapid) -{ - // check the feedrates are set - if ((hFeed == 0) || (vFeed == 0)){ - Base::Console().Warning("Feed Rate Error: Check Tool Controllers have Feed Rates"); - return 0; - } - - if (hRapid == 0){ - hRapid = hFeed; - } - - if (vRapid == 0){ - vRapid = vFeed; - } - - if(vpcCommands.size()==0) - return 0; - double l = 0; - double time = 0; - bool verticalMove = false; - Vector3d last(0,0,0); - Vector3d next; - for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { - std::string name = (*it)->Name; - float feedrate = (*it)->getParam("F"); - - l = 0; - verticalMove = false; - feedrate = hFeed; - next = (*it)->getPlacement(last).getPosition(); - - if (last.z != next.z){ - verticalMove = true; - feedrate = vFeed; - } - - if ((name == "G0") || (name == "G00")){ - // Rapid Move - l += (next - last).Length(); - feedrate = hRapid; - if(verticalMove){ - feedrate = vRapid; - } - }else if ((name == "G1") || (name == "G01")) { - // Feed Move - l += (next - last).Length(); - }else if ((name == "G2") || (name == "G02") || (name == "G3") || (name == "G03") ) { - // Arc Move - Vector3d center = (*it)->getCenter(); - double radius = (last - center).Length(); - double angle = (next - center).GetAngle(last - center); - l += angle * radius; - } - - time += l / feedrate; - last = next; - } - return time; -} - -class BoundBoxSegmentVisitor : public PathSegmentVisitor -{ -public: - BoundBoxSegmentVisitor() - { } - - virtual void g0(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts) - { - (void)id; - processPt(last); - processPts(pts); - processPt(next); - } - virtual void g1(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts) - { - (void)id; - processPt(last); - processPts(pts); - processPt(next); - } - virtual void g23(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts, const Base::Vector3d ¢er) - { - (void)id; - (void)center; - processPt(last); - processPts(pts); - processPt(next); - } - virtual void g8x(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts, - const std::deque &p, const std::deque &q) - { - (void)id; - (void)q; // always within the bounds of p - processPt(last); - processPts(pts); - processPts(p); - processPt(next); - } - virtual void g38(int id, const Base::Vector3d &last, const Base::Vector3d &next) - { - (void)id; - processPt(last); - processPt(next); - } - - Base::BoundBox3d bb; - -private: - void processPts(const std::deque &pts) { - for (std::deque::const_iterator it=pts.begin(); pts.end() != it; ++it) { - processPt(*it); - } - } - void processPt(const Base::Vector3d &pt) { - bb.MaxX = std::max(bb.MaxX, pt.x); - bb.MinX = std::min(bb.MinX, pt.x); - bb.MaxY = std::max(bb.MaxY, pt.y); - bb.MinY = std::min(bb.MinY, pt.y); - bb.MaxZ = std::max(bb.MaxZ, pt.z); - bb.MinZ = std::min(bb.MinZ, pt.z); - } -}; - -Base::BoundBox3d Toolpath::getBoundBox() const -{ - BoundBoxSegmentVisitor visitor; - PathSegmentWalker walker(*this); - walker.walk(visitor, Vector3d(0, 0, 0)); - - return visitor.bb; -} - -static void bulkAddCommand(const std::string &gcodestr, std::vector &commands, bool &inches) -{ - Command *cmd = new Command(); - cmd->setFromGCode(gcodestr); - if ("G20" == cmd->Name) { - inches = true; - delete cmd; - } else if ("G21" == cmd->Name) { - inches = false; - delete cmd; - } else { - if (inches) { - cmd->scaleBy(25.4); - } - commands.push_back(cmd); - } -} - -void Toolpath::setFromGCode(const std::string instr) -{ - clear(); - - // remove comments - //boost::regex e("\\(.*?\\)"); - //std::string str = boost::regex_replace(instr, e, ""); - std::string str(instr); - - // split input string by () or G or M commands - std::string mode = "command"; - std::size_t found = str.find_first_of("(gGmM"); - int last = -1; - bool inches = false; - while (found != std::string::npos) - { - if (str[found] == '(') { - // start of comment - if ( (last > -1) && (mode == "command") ) { - // before opening a comment, add the last found command - std::string gcodestr = str.substr(last, found-last); - bulkAddCommand(gcodestr, vpcCommands, inches); - } - mode = "comment"; - last = found; - found = str.find_first_of(')', found+1); - } else if (str[found] == ')') { - // end of comment - std::string gcodestr = str.substr(last, found-last+1); - bulkAddCommand(gcodestr, vpcCommands, inches); - last = -1; - found = str.find_first_of("(gGmM", found+1); - mode = "command"; - } else if (mode == "command") { - // command - if (last > -1) { - std::string gcodestr = str.substr(last, found-last); - bulkAddCommand(gcodestr, vpcCommands, inches); - } - last = found; - found = str.find_first_of("(gGmM", found+1); - } - } - // add the last command found, if any - if (last > -1) { - if (mode == "command") { - std::string gcodestr = str.substr(last,std::string::npos); - bulkAddCommand(gcodestr, vpcCommands, inches); - } - } - recalculate(); -} - -std::string Toolpath::toGCode(void) const -{ - std::string result; - for (std::vector::const_iterator it=vpcCommands.begin();it!=vpcCommands.end();++it) { - result += (*it)->toGCode(); - result += "\n"; - } - return result; -} - -void Toolpath::recalculate(void) // recalculates the path cache -{ - - if(vpcCommands.size()==0) - return; - - // TODO recalculate the KDL stuff. At the moment, this is unused. - -#if 0 - // delete the old and create a new one - if(pcPath) - delete (pcPath); - - pcPath = new KDL::Path_Composite(); - - KDL::Path *tempPath; - KDL::Frame Last; - - try { - // handle the first waypoint differently - bool first=true; - - for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { - if(first){ - Last = toFrame((*it)->getPlacement()); - first = false; - }else{ - Base::Placement p = (*it)->getPlacement(); - KDL::Frame Next = toFrame(p); - std::string name = (*it)->Name; - Vector3d zaxis(0,0,1); - - if ( (name == "G0") || (name == "G1") || (name == "G01") ) { - // line segment - tempPath = new KDL::Path_Line(Last, Next, new KDL::RotationalInterpolation_SingleAxis(), 1.0, true); - pcPath->Add(tempPath); - Last = Next; - } else if ( (name == "G2") || (name == "G02") ) { - // clockwise arc - Vector3d fcenter = (*it)->getCenter(); - KDL::Vector center(fcenter.x,fcenter.y,fcenter.z); - Vector3d fnorm; - p.getRotation().multVec(zaxis,fnorm); - KDL::Vector norm(fnorm.x,fnorm.y,fnorm.z); - Vector3d fstart = toPlacement(Last).getPosition(); - Vector3d fend = toPlacement(Last).getPosition(); - Rotation frot(fstart-fcenter,fend-fcenter); - double q0,q1,q2,q3; - frot.getValue(q0,q1,q2,q3); - KDL::Rotation rot; - rot.Quaternion(q0,q1,q2,q3); - tempPath = new KDL::Path_Circle(Last, center, norm, rot, 0.0, new KDL::RotationalInterpolation_SingleAxis(), 1.0, true); - pcPath->Add(tempPath); - Last = Next; - } - } - } - } catch (KDL::Error &e) { - throw Base::RuntimeError(e.Description()); - } -#endif -} - -// reimplemented from base class - -unsigned int Toolpath::getMemSize (void) const -{ - return toGCode().size(); -} - -void Toolpath::setCenter(const Base::Vector3d &c) -{ - center = c; - recalculate(); -} - -static void saveCenter(Writer &writer, const Base::Vector3d ¢er) -{ - writer.Stream() << writer.ind() << "
" << std::endl; -} - -void Toolpath::Save (Writer &writer) const -{ - if (writer.isForceXML()) { - writer.Stream() << writer.ind() << "" << std::endl; - writer.incInd(); - saveCenter(writer, center); - for(unsigned int i = 0; i < getSize(); i++) { - vpcCommands[i]->Save(writer); - } - writer.decInd(); - } else { - writer.Stream() << writer.ind() - << "" << std::endl; - writer.incInd(); - saveCenter(writer, center); - writer.decInd(); - } - writer.Stream() << writer.ind() << "" << std::endl; -} - -void Toolpath::SaveDocFile (Base::Writer &writer) const -{ - if (toGCode().empty()) - return; - writer.Stream() << toGCode(); -} - -void Toolpath::Restore(XMLReader &reader) -{ - reader.readElement("Path"); - std::string file (reader.getAttribute("file") ); - - if (!file.empty()) { - // initiate a file read - reader.addFile(file.c_str(),this); - } -} - -void Toolpath::RestoreDocFile(Base::Reader &reader) -{ - std::string gcode; - std::string line; - while (reader >> line) { - gcode += line; - gcode += " "; - } - setFromGCode(gcode); - -} - - - - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include +#include + +// KDL stuff - at the moment, not used +//#include "Mod/Robot/App/kdl_cp/path_line.hpp" +//#include "Mod/Robot/App/kdl_cp/path_circle.hpp" +//#include "Mod/Robot/App/kdl_cp/rotational_interpolation_sa.hpp" +//#include "Mod/Robot/App/kdl_cp/utilities/error.h" + +#include "Path.h" +#include + +using namespace Path; +using namespace Base; + +TYPESYSTEM_SOURCE(Path::Toolpath , Base::Persistence) + +Toolpath::Toolpath() +{ +} + +Toolpath::Toolpath(const Toolpath& otherPath) + : vpcCommands(otherPath.vpcCommands.size()) + , center(otherPath.center) +{ + *this = otherPath; + recalculate(); +} + +Toolpath::~Toolpath() +{ + clear(); +} + +Toolpath &Toolpath::operator=(const Toolpath& otherPath) +{ + if (this == &otherPath) + return *this; + + clear(); + vpcCommands.resize(otherPath.vpcCommands.size()); + int i = 0; + for (std::vector::const_iterator it=otherPath.vpcCommands.begin();it!=otherPath.vpcCommands.end();++it,i++) { + vpcCommands[i] = new Command(**it); + } + center = otherPath.center; + recalculate(); + return *this; +} + +void Toolpath::clear(void) +{ + for(std::vector::iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) + delete ( *it ); + vpcCommands.clear(); + recalculate(); +} + +void Toolpath::addCommand(const Command &Cmd) +{ + Command *tmp = new Command(Cmd); + vpcCommands.push_back(tmp); + recalculate(); +} + +void Toolpath::insertCommand(const Command &Cmd, int pos) +{ + if (pos == -1) { + addCommand(Cmd); + } else if (pos <= static_cast(vpcCommands.size())) { + Command *tmp = new Command(Cmd); + vpcCommands.insert(vpcCommands.begin()+pos,tmp); + } else { + throw Base::IndexError("Index not in range"); + } + recalculate(); +} + +void Toolpath::deleteCommand(int pos) +{ + if (pos == -1) { + //delete(*vpcCommands.rbegin()); // causes crash + vpcCommands.pop_back(); + } else if (pos <= static_cast(vpcCommands.size())) { + vpcCommands.erase (vpcCommands.begin()+pos); + } else { + throw Base::IndexError("Index not in range"); + } + recalculate(); +} + +double Toolpath::getLength() +{ + if(vpcCommands.size()==0) + return 0; + double l = 0; + Vector3d last(0,0,0); + Vector3d next; + for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { + std::string name = (*it)->Name; + next = (*it)->getPlacement(last).getPosition(); + if ( (name == "G0") || (name == "G00") || (name == "G1") || (name == "G01") ) { + // straight line + l += (next - last).Length(); + last = next; + } else if ( (name == "G2") || (name == "G02") || (name == "G3") || (name == "G03") ) { + // arc + Vector3d center = (*it)->getCenter(); + double radius = (last - center).Length(); + double angle = (next - center).GetAngle(last - center); + l += angle * radius; + last = next; + } + } + return l; +} + +double Toolpath::getCycleTime(double hFeed, double vFeed, double hRapid, double vRapid) +{ + // check the feedrates are set + if ((hFeed == 0) || (vFeed == 0)){ + Base::Console().Warning("Feed Rate Error: Check Tool Controllers have Feed Rates"); + return 0; + } + + if (hRapid == 0){ + hRapid = hFeed; + } + + if (vRapid == 0){ + vRapid = vFeed; + } + + if(vpcCommands.size()==0) + return 0; + double l = 0; + double time = 0; + bool verticalMove = false; + Vector3d last(0,0,0); + Vector3d next; + for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { + std::string name = (*it)->Name; + float feedrate = (*it)->getParam("F"); + + l = 0; + verticalMove = false; + feedrate = hFeed; + next = (*it)->getPlacement(last).getPosition(); + + if (last.z != next.z){ + verticalMove = true; + feedrate = vFeed; + } + + if ((name == "G0") || (name == "G00")){ + // Rapid Move + l += (next - last).Length(); + feedrate = hRapid; + if(verticalMove){ + feedrate = vRapid; + } + }else if ((name == "G1") || (name == "G01")) { + // Feed Move + l += (next - last).Length(); + }else if ((name == "G2") || (name == "G02") || (name == "G3") || (name == "G03") ) { + // Arc Move + Vector3d center = (*it)->getCenter(); + double radius = (last - center).Length(); + double angle = (next - center).GetAngle(last - center); + l += angle * radius; + } + + time += l / feedrate; + last = next; + } + return time; +} + +class BoundBoxSegmentVisitor : public PathSegmentVisitor +{ +public: + BoundBoxSegmentVisitor() + { } + + virtual void g0(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts) + { + (void)id; + processPt(last); + processPts(pts); + processPt(next); + } + virtual void g1(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts) + { + (void)id; + processPt(last); + processPts(pts); + processPt(next); + } + virtual void g23(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts, const Base::Vector3d ¢er) + { + (void)id; + (void)center; + processPt(last); + processPts(pts); + processPt(next); + } + virtual void g8x(int id, const Base::Vector3d &last, const Base::Vector3d &next, const std::deque &pts, + const std::deque &p, const std::deque &q) + { + (void)id; + (void)q; // always within the bounds of p + processPt(last); + processPts(pts); + processPts(p); + processPt(next); + } + virtual void g38(int id, const Base::Vector3d &last, const Base::Vector3d &next) + { + (void)id; + processPt(last); + processPt(next); + } + + Base::BoundBox3d bb; + +private: + void processPts(const std::deque &pts) { + for (std::deque::const_iterator it=pts.begin(); pts.end() != it; ++it) { + processPt(*it); + } + } + void processPt(const Base::Vector3d &pt) { + bb.MaxX = std::max(bb.MaxX, pt.x); + bb.MinX = std::min(bb.MinX, pt.x); + bb.MaxY = std::max(bb.MaxY, pt.y); + bb.MinY = std::min(bb.MinY, pt.y); + bb.MaxZ = std::max(bb.MaxZ, pt.z); + bb.MinZ = std::min(bb.MinZ, pt.z); + } +}; + +Base::BoundBox3d Toolpath::getBoundBox() const +{ + BoundBoxSegmentVisitor visitor; + PathSegmentWalker walker(*this); + walker.walk(visitor, Vector3d(0, 0, 0)); + + return visitor.bb; +} + +static void bulkAddCommand(const std::string &gcodestr, std::vector &commands, bool &inches) +{ + Command *cmd = new Command(); + cmd->setFromGCode(gcodestr); + if ("G20" == cmd->Name) { + inches = true; + delete cmd; + } else if ("G21" == cmd->Name) { + inches = false; + delete cmd; + } else { + if (inches) { + cmd->scaleBy(25.4); + } + commands.push_back(cmd); + } +} + +void Toolpath::setFromGCode(const std::string instr) +{ + clear(); + + // remove comments + //boost::regex e("\\(.*?\\)"); + //std::string str = boost::regex_replace(instr, e, ""); + std::string str(instr); + + // split input string by () or G or M commands + std::string mode = "command"; + std::size_t found = str.find_first_of("(gGmM"); + int last = -1; + bool inches = false; + while (found != std::string::npos) + { + if (str[found] == '(') { + // start of comment + if ( (last > -1) && (mode == "command") ) { + // before opening a comment, add the last found command + std::string gcodestr = str.substr(last, found-last); + bulkAddCommand(gcodestr, vpcCommands, inches); + } + mode = "comment"; + last = found; + found = str.find_first_of(')', found+1); + } else if (str[found] == ')') { + // end of comment + std::string gcodestr = str.substr(last, found-last+1); + bulkAddCommand(gcodestr, vpcCommands, inches); + last = -1; + found = str.find_first_of("(gGmM", found+1); + mode = "command"; + } else if (mode == "command") { + // command + if (last > -1) { + std::string gcodestr = str.substr(last, found-last); + bulkAddCommand(gcodestr, vpcCommands, inches); + } + last = found; + found = str.find_first_of("(gGmM", found+1); + } + } + // add the last command found, if any + if (last > -1) { + if (mode == "command") { + std::string gcodestr = str.substr(last,std::string::npos); + bulkAddCommand(gcodestr, vpcCommands, inches); + } + } + recalculate(); +} + +std::string Toolpath::toGCode(void) const +{ + std::string result; + for (std::vector::const_iterator it=vpcCommands.begin();it!=vpcCommands.end();++it) { + result += (*it)->toGCode(); + result += "\n"; + } + return result; +} + +void Toolpath::recalculate(void) // recalculates the path cache +{ + + if(vpcCommands.size()==0) + return; + + // TODO recalculate the KDL stuff. At the moment, this is unused. + +#if 0 + // delete the old and create a new one + if(pcPath) + delete (pcPath); + + pcPath = new KDL::Path_Composite(); + + KDL::Path *tempPath; + KDL::Frame Last; + + try { + // handle the first waypoint differently + bool first=true; + + for(std::vector::const_iterator it = vpcCommands.begin();it!=vpcCommands.end();++it) { + if(first){ + Last = toFrame((*it)->getPlacement()); + first = false; + }else{ + Base::Placement p = (*it)->getPlacement(); + KDL::Frame Next = toFrame(p); + std::string name = (*it)->Name; + Vector3d zaxis(0,0,1); + + if ( (name == "G0") || (name == "G1") || (name == "G01") ) { + // line segment + tempPath = new KDL::Path_Line(Last, Next, new KDL::RotationalInterpolation_SingleAxis(), 1.0, true); + pcPath->Add(tempPath); + Last = Next; + } else if ( (name == "G2") || (name == "G02") ) { + // clockwise arc + Vector3d fcenter = (*it)->getCenter(); + KDL::Vector center(fcenter.x,fcenter.y,fcenter.z); + Vector3d fnorm; + p.getRotation().multVec(zaxis,fnorm); + KDL::Vector norm(fnorm.x,fnorm.y,fnorm.z); + Vector3d fstart = toPlacement(Last).getPosition(); + Vector3d fend = toPlacement(Last).getPosition(); + Rotation frot(fstart-fcenter,fend-fcenter); + double q0,q1,q2,q3; + frot.getValue(q0,q1,q2,q3); + KDL::Rotation rot; + rot.Quaternion(q0,q1,q2,q3); + tempPath = new KDL::Path_Circle(Last, center, norm, rot, 0.0, new KDL::RotationalInterpolation_SingleAxis(), 1.0, true); + pcPath->Add(tempPath); + Last = Next; + } + } + } + } catch (KDL::Error &e) { + throw Base::RuntimeError(e.Description()); + } +#endif +} + +// reimplemented from base class + +unsigned int Toolpath::getMemSize (void) const +{ + return toGCode().size(); +} + +void Toolpath::setCenter(const Base::Vector3d &c) +{ + center = c; + recalculate(); +} + +static void saveCenter(Writer &writer, const Base::Vector3d ¢er) +{ + writer.Stream() << writer.ind() << "
" << std::endl; +} + +void Toolpath::Save (Writer &writer) const +{ + if (writer.isForceXML()) { + writer.Stream() << writer.ind() << "" << std::endl; + writer.incInd(); + saveCenter(writer, center); + for(unsigned int i = 0; i < getSize(); i++) { + vpcCommands[i]->Save(writer); + } + writer.decInd(); + } else { + writer.Stream() << writer.ind() + << "" << std::endl; + writer.incInd(); + saveCenter(writer, center); + writer.decInd(); + } + writer.Stream() << writer.ind() << "" << std::endl; +} + +void Toolpath::SaveDocFile (Base::Writer &writer) const +{ + if (toGCode().empty()) + return; + writer.Stream() << toGCode(); +} + +void Toolpath::Restore(XMLReader &reader) +{ + reader.readElement("Path"); + std::string file (reader.getAttribute("file") ); + + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } +} + +void Toolpath::RestoreDocFile(Base::Reader &reader) +{ + std::string gcode; + std::string line; + while (reader >> line) { + gcode += line; + gcode += " "; + } + setFromGCode(gcode); + +} + + + + + diff --git a/src/Mod/Path/App/Path.h b/src/Mod/Path/App/Path.h index 9ad4381f7b..837d230566 100644 --- a/src/Mod/Path/App/Path.h +++ b/src/Mod/Path/App/Path.h @@ -1,105 +1,105 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_Path_H -#define PATH_Path_H - -#include "Command.h" -//#include "Mod/Robot/App/kdl_cp/path_composite.hpp" -//#include "Mod/Robot/App/kdl_cp/frames_io.hpp" -#include -#include -#include - -namespace Path -{ - - /** The representation of a CNC Toolpath */ - - class PathExport Toolpath : public Base::Persistence - { - TYPESYSTEM_HEADER(); - - public: - Toolpath(); - Toolpath(const Toolpath&); - ~Toolpath(); - - Toolpath &operator=(const Toolpath&); - - // from base class - virtual unsigned int getMemSize (void) const; - virtual void Save (Base::Writer &/*writer*/) const; - virtual void Restore(Base::XMLReader &/*reader*/); - void SaveDocFile (Base::Writer &writer) const; - void RestoreDocFile(Base::Reader &reader); - - // interface - void clear(void); // clears the internal data - void addCommand(const Command &Cmd); // adds a command at the end - void insertCommand(const Command &Cmd, int); // inserts a command - void deleteCommand(int); // deletes a command - double getLength(void); // return the Length (mm) of the Path - double getCycleTime(double, double, double, double); // return the Cycle Time (s) of the Path - void recalculate(void); // recalculates the points - void setFromGCode(const std::string); // sets the path from the contents of the given GCode string - std::string toGCode(void) const; // gets a gcode string representation from the Path - Base::BoundBox3d getBoundBox(void) const; - - // shortcut functions - unsigned int getSize(void) const { return vpcCommands.size(); } - const std::vector &getCommands(void) const { return vpcCommands; } - const Command &getCommand(unsigned int pos) const { return *vpcCommands[pos]; } - - // support for rotation - const Base::Vector3d& getCenter() const { return center; } - void setCenter(const Base::Vector3d &c); - - static const int SchemaVersion = 2; - - protected: - std::vector vpcCommands; - Base::Vector3d center; - //KDL::Path_Composite *pcPath; - - /* - inline KDL::Frame toFrame(const Base::Placement &To){ - return KDL::Frame(KDL::Rotation::Quaternion(To.getRotation()[0], - To.getRotation()[1], - To.getRotation()[2], - To.getRotation()[3]), - KDL::Vector(To.getPosition()[0], - To.getPosition()[1], - To.getPosition()[2])); - } - inline Base::Placement toPlacement(const KDL::Frame &To){ - double x,y,z,w; - To.M.GetQuaternion(x,y,z,w); - return Base::Placement(Base::Vector3d(To.p[0],To.p[1],To.p[2]),Base::Rotation(x,y,z,w)); - } */ - }; - -} //namespace Path - - -#endif // PATH_Path_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_Path_H +#define PATH_Path_H + +#include "Command.h" +//#include "Mod/Robot/App/kdl_cp/path_composite.hpp" +//#include "Mod/Robot/App/kdl_cp/frames_io.hpp" +#include +#include +#include + +namespace Path +{ + + /** The representation of a CNC Toolpath */ + + class PathExport Toolpath : public Base::Persistence + { + TYPESYSTEM_HEADER(); + + public: + Toolpath(); + Toolpath(const Toolpath&); + ~Toolpath(); + + Toolpath &operator=(const Toolpath&); + + // from base class + virtual unsigned int getMemSize (void) const; + virtual void Save (Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + void SaveDocFile (Base::Writer &writer) const; + void RestoreDocFile(Base::Reader &reader); + + // interface + void clear(void); // clears the internal data + void addCommand(const Command &Cmd); // adds a command at the end + void insertCommand(const Command &Cmd, int); // inserts a command + void deleteCommand(int); // deletes a command + double getLength(void); // return the Length (mm) of the Path + double getCycleTime(double, double, double, double); // return the Cycle Time (s) of the Path + void recalculate(void); // recalculates the points + void setFromGCode(const std::string); // sets the path from the contents of the given GCode string + std::string toGCode(void) const; // gets a gcode string representation from the Path + Base::BoundBox3d getBoundBox(void) const; + + // shortcut functions + unsigned int getSize(void) const { return vpcCommands.size(); } + const std::vector &getCommands(void) const { return vpcCommands; } + const Command &getCommand(unsigned int pos) const { return *vpcCommands[pos]; } + + // support for rotation + const Base::Vector3d& getCenter() const { return center; } + void setCenter(const Base::Vector3d &c); + + static const int SchemaVersion = 2; + + protected: + std::vector vpcCommands; + Base::Vector3d center; + //KDL::Path_Composite *pcPath; + + /* + inline KDL::Frame toFrame(const Base::Placement &To){ + return KDL::Frame(KDL::Rotation::Quaternion(To.getRotation()[0], + To.getRotation()[1], + To.getRotation()[2], + To.getRotation()[3]), + KDL::Vector(To.getPosition()[0], + To.getPosition()[1], + To.getPosition()[2])); + } + inline Base::Placement toPlacement(const KDL::Frame &To){ + double x,y,z,w; + To.M.GetQuaternion(x,y,z,w); + return Base::Placement(Base::Vector3d(To.p[0],To.p[1],To.p[2]),Base::Rotation(x,y,z,w)); + } */ + }; + +} //namespace Path + + +#endif // PATH_Path_H diff --git a/src/Mod/Path/App/PathPy.xml b/src/Mod/Path/App/PathPy.xml index 94a56ec172..7338401db4 100644 --- a/src/Mod/Path/App/PathPy.xml +++ b/src/Mod/Path/App/PathPy.xml @@ -1,91 +1,91 @@ - - - - - - Path([commands]): Represents a basic Gcode path -commands (optional) is a list of Path commands - - - - the total length of this path in mm - - - - - - the number of commands in this path - - - - - - the list of commands of this path - - - - - - the center position for all rotational parameters - - - - - - the extent of this path - - - - - - adds a command or a list of commands at the end of the path - - - - - insertCommand(Command,[int]): -adds a command at the given position or at the end of the path - - - - - deleteCommand([int]): -deletes the command found at the given position or from the end of the path - - - - - sets the contents of the path from a gcode string - - - - - returns a gcode string representing the path - - - - - returns a copy of this path - - - - - return the cycle time estimation for this path in s - - - - - - + + + + + + Path([commands]): Represents a basic Gcode path +commands (optional) is a list of Path commands + + + + the total length of this path in mm + + + + + + the number of commands in this path + + + + + + the list of commands of this path + + + + + + the center position for all rotational parameters + + + + + + the extent of this path + + + + + + adds a command or a list of commands at the end of the path + + + + + insertCommand(Command,[int]): +adds a command at the given position or at the end of the path + + + + + deleteCommand([int]): +deletes the command found at the given position or from the end of the path + + + + + sets the contents of the path from a gcode string + + + + + returns a gcode string representing the path + + + + + returns a copy of this path + + + + + return the cycle time estimation for this path in s + + + + + + diff --git a/src/Mod/Path/App/PathPyImp.cpp b/src/Mod/Path/App/PathPyImp.cpp index 39e91faa54..f0597b5d50 100644 --- a/src/Mod/Path/App/PathPyImp.cpp +++ b/src/Mod/Path/App/PathPyImp.cpp @@ -1,240 +1,240 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#include "Mod/Path/App/Path.h" - -// inclusion of the generated files (generated out of PathPy.xml) -#include "PathPy.h" -#include "PathPy.cpp" - -#include "Base/BoundBoxPy.h" -#include "Base/GeometryPyCXX.h" -#include "CommandPy.h" - -using namespace Path; - -// returns a string which represents the object e.g. when printed in python -std::string PathPy::representation(void) const -{ - std::stringstream str; - str.precision(5); - str << "Path [ "; - str << "size:" << getToolpathPtr()->getSize() << " "; - str << "length:" << getToolpathPtr()->getLength(); - str << " ]"; - - return str.str(); -} - -PyObject *PathPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper -{ - // create a new instance of PathPy and the Twin object - return new PathPy(new Toolpath); -} - -// constructor method -int PathPy::PyInit(PyObject* args, PyObject* /*kwd*/) -{ - PyObject *pcObj=0; - char *gcode; - if (PyArg_ParseTuple(args, "|O!", &(PyList_Type), &pcObj)) { - if (pcObj) { - Py::List list(pcObj); - for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { - Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); - getToolpathPtr()->addCommand(cmd); - } else { - PyErr_SetString(PyExc_TypeError, "The list must contain only Path Commands"); - return -1; - } - } - } - return 0; - } - PyErr_Clear(); // set by PyArg_ParseTuple() - if (PyArg_ParseTuple(args, "|s", &gcode)) { - getToolpathPtr()->setFromGCode(gcode); - return 0; - } - PyErr_SetString(PyExc_TypeError, "Argument must be a list of commands or a gcode string"); - return -1; -} - - -// Commands get/set - -Py::List PathPy::getCommands(void) const -{ - Py::List list; - for(unsigned int i = 0; i < getToolpathPtr()->getSize(); i++) - list.append(Py::asObject(new Path::CommandPy(new Path::Command(getToolpathPtr()->getCommand(i))))); - return list; -} - -void PathPy::setCommands(Py::List list) -{ - getToolpathPtr()->clear(); - for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { - Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); - getToolpathPtr()->addCommand(cmd); - } else { - throw Py::TypeError("The list can only contain Path Commands"); - } - } -} - -Py::Object PathPy::getCenter(void) const -{ - return Py::Vector(getToolpathPtr()->getCenter()); -} - -void PathPy::setCenter(Py::Object obj) -{ - getToolpathPtr()->setCenter(Py::Vector(obj).toVector()); -} - -// read-only attributes - -Py::Float PathPy::getLength(void) const -{ - return Py::Float(getToolpathPtr()->getLength()); -} - -Py::Long PathPy::getSize(void) const -{ - return Py::Long((long)getToolpathPtr()->getSize()); -} - -Py::Object PathPy::getBoundBox(void) const -{ - return Py::BoundingBox(getToolpathPtr()->getBoundBox()); -} - -// specific methods - -PyObject* PathPy::copy(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - return new PathPy(new Path::Toolpath(*getToolpathPtr())); - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* PathPy::addCommands(PyObject * args) -{ - PyObject* o; - if (PyArg_ParseTuple(args, "O!", &(Path::CommandPy::Type), &o)) { - Path::Command &cmd = *static_cast(o)->getCommandPtr(); - getToolpathPtr()->addCommand(cmd); - return new PathPy(new Path::Toolpath(*getToolpathPtr())); - //Py_Return; - } - PyErr_Clear(); - if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) { - Py::List list(o); - for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { - Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); - getToolpathPtr()->addCommand(cmd); - } - } - return new PathPy(new Path::Toolpath(*getToolpathPtr())); - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - command or list of commands expected"); -} - -PyObject* PathPy::insertCommand(PyObject * args) -{ - PyObject* o; - int pos = -1; - if (PyArg_ParseTuple(args, "O!|i", &(Path::CommandPy::Type), &o, &pos)) { - Path::Command &cmd = *static_cast(o)->getCommandPtr(); - getToolpathPtr()->insertCommand(cmd,pos); - return new PathPy(new Path::Toolpath(*getToolpathPtr())); - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected command and optional integer"); -} - -PyObject* PathPy::deleteCommand(PyObject * args) -{ - int pos = -1; - if (PyArg_ParseTuple(args, "|i", &pos)) { - getToolpathPtr()->deleteCommand(pos); - return new PathPy(new Path::Toolpath(*getToolpathPtr())); - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected an integer (optional)"); -} - -PyObject* PathPy::getCycleTime(PyObject * args) -{ - double hFeed, vFeed, hRapid, vRapid; - if (PyArg_ParseTuple(args, "dddd", &hFeed, &vFeed, &hRapid, &vRapid)){ - return PyFloat_FromDouble(getToolpathPtr()->getCycleTime(hFeed, vFeed, hRapid, vRapid)); - } - return 0; -} - -// GCode methods - -PyObject* PathPy::toGCode(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - std::string result = getToolpathPtr()->toGCode(); -#if PY_MAJOR_VERSION >= 3 - return PyUnicode_FromString(result.c_str()); -#else - return PyString_FromString(result.c_str()); -#endif - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* PathPy::setFromGCode(PyObject * args) -{ - char *pstr=0; - if (PyArg_ParseTuple(args, "s", &pstr)) { - std::string gcode(pstr); - getToolpathPtr()->setFromGCode(gcode); - Py_INCREF(Py_None); - return Py_None; - } - throw Py::TypeError("Argument must be a string"); -} - -// custom attributes get/set - -PyObject *PathPy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - -int PathPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "Mod/Path/App/Path.h" + +// inclusion of the generated files (generated out of PathPy.xml) +#include "PathPy.h" +#include "PathPy.cpp" + +#include "Base/BoundBoxPy.h" +#include "Base/GeometryPyCXX.h" +#include "CommandPy.h" + +using namespace Path; + +// returns a string which represents the object e.g. when printed in python +std::string PathPy::representation(void) const +{ + std::stringstream str; + str.precision(5); + str << "Path [ "; + str << "size:" << getToolpathPtr()->getSize() << " "; + str << "length:" << getToolpathPtr()->getLength(); + str << " ]"; + + return str.str(); +} + +PyObject *PathPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of PathPy and the Twin object + return new PathPy(new Toolpath); +} + +// constructor method +int PathPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + PyObject *pcObj=0; + char *gcode; + if (PyArg_ParseTuple(args, "|O!", &(PyList_Type), &pcObj)) { + if (pcObj) { + Py::List list(pcObj); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { + Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); + getToolpathPtr()->addCommand(cmd); + } else { + PyErr_SetString(PyExc_TypeError, "The list must contain only Path Commands"); + return -1; + } + } + } + return 0; + } + PyErr_Clear(); // set by PyArg_ParseTuple() + if (PyArg_ParseTuple(args, "|s", &gcode)) { + getToolpathPtr()->setFromGCode(gcode); + return 0; + } + PyErr_SetString(PyExc_TypeError, "Argument must be a list of commands or a gcode string"); + return -1; +} + + +// Commands get/set + +Py::List PathPy::getCommands(void) const +{ + Py::List list; + for(unsigned int i = 0; i < getToolpathPtr()->getSize(); i++) + list.append(Py::asObject(new Path::CommandPy(new Path::Command(getToolpathPtr()->getCommand(i))))); + return list; +} + +void PathPy::setCommands(Py::List list) +{ + getToolpathPtr()->clear(); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { + Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); + getToolpathPtr()->addCommand(cmd); + } else { + throw Py::TypeError("The list can only contain Path Commands"); + } + } +} + +Py::Object PathPy::getCenter(void) const +{ + return Py::Vector(getToolpathPtr()->getCenter()); +} + +void PathPy::setCenter(Py::Object obj) +{ + getToolpathPtr()->setCenter(Py::Vector(obj).toVector()); +} + +// read-only attributes + +Py::Float PathPy::getLength(void) const +{ + return Py::Float(getToolpathPtr()->getLength()); +} + +Py::Long PathPy::getSize(void) const +{ + return Py::Long((long)getToolpathPtr()->getSize()); +} + +Py::Object PathPy::getBoundBox(void) const +{ + return Py::BoundingBox(getToolpathPtr()->getBoundBox()); +} + +// specific methods + +PyObject* PathPy::copy(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + return new PathPy(new Path::Toolpath(*getToolpathPtr())); + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* PathPy::addCommands(PyObject * args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(Path::CommandPy::Type), &o)) { + Path::Command &cmd = *static_cast(o)->getCommandPtr(); + getToolpathPtr()->addCommand(cmd); + return new PathPy(new Path::Toolpath(*getToolpathPtr())); + //Py_Return; + } + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) { + Py::List list(o); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + if (PyObject_TypeCheck((*it).ptr(), &(Path::CommandPy::Type))) { + Path::Command &cmd = *static_cast((*it).ptr())->getCommandPtr(); + getToolpathPtr()->addCommand(cmd); + } + } + return new PathPy(new Path::Toolpath(*getToolpathPtr())); + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - command or list of commands expected"); +} + +PyObject* PathPy::insertCommand(PyObject * args) +{ + PyObject* o; + int pos = -1; + if (PyArg_ParseTuple(args, "O!|i", &(Path::CommandPy::Type), &o, &pos)) { + Path::Command &cmd = *static_cast(o)->getCommandPtr(); + getToolpathPtr()->insertCommand(cmd,pos); + return new PathPy(new Path::Toolpath(*getToolpathPtr())); + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected command and optional integer"); +} + +PyObject* PathPy::deleteCommand(PyObject * args) +{ + int pos = -1; + if (PyArg_ParseTuple(args, "|i", &pos)) { + getToolpathPtr()->deleteCommand(pos); + return new PathPy(new Path::Toolpath(*getToolpathPtr())); + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected an integer (optional)"); +} + +PyObject* PathPy::getCycleTime(PyObject * args) +{ + double hFeed, vFeed, hRapid, vRapid; + if (PyArg_ParseTuple(args, "dddd", &hFeed, &vFeed, &hRapid, &vRapid)){ + return PyFloat_FromDouble(getToolpathPtr()->getCycleTime(hFeed, vFeed, hRapid, vRapid)); + } + return 0; +} + +// GCode methods + +PyObject* PathPy::toGCode(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + std::string result = getToolpathPtr()->toGCode(); +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromString(result.c_str()); +#else + return PyString_FromString(result.c_str()); +#endif + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* PathPy::setFromGCode(PyObject * args) +{ + char *pstr=0; + if (PyArg_ParseTuple(args, "s", &pstr)) { + std::string gcode(pstr); + getToolpathPtr()->setFromGCode(gcode); + Py_INCREF(Py_None); + return Py_None; + } + throw Py::TypeError("Argument must be a string"); +} + +// custom attributes get/set + +PyObject *PathPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int PathPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/Mod/Path/App/PreCompiled.cpp b/src/Mod/Path/App/PreCompiled.cpp index a405fd9683..aaf58a3086 100644 --- a/src/Mod/Path/App/PreCompiled.cpp +++ b/src/Mod/Path/App/PreCompiled.cpp @@ -1,24 +1,24 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" diff --git a/src/Mod/Path/App/PreCompiled.h b/src/Mod/Path/App/PreCompiled.h index 005b716aa0..0de9902d9e 100644 --- a/src/Mod/Path/App/PreCompiled.h +++ b/src/Mod/Path/App/PreCompiled.h @@ -1,133 +1,133 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_PRECOMPILED_H -#define PATH_PRECOMPILED_H - -#include - -// Exporting of App classes -#ifdef FC_OS_WIN32 -# define PathExport __declspec(dllexport) -//# define RobotExport __declspec(dllexport) uncomment this to use KDL -# define PartExport __declspec(dllimport) -# define BaseExport __declspec(dllimport) -#else // for Linux -# define PathExport -//# define RobotExport uncomment this to use KDL -# define PartExport -# define BaseExport -#endif - -#ifdef _PreComp_ - -// standard -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -// Python -#include - -// Boost -#include -#include -#if defined(BOOST_MSVC) && (BOOST_VERSION == 105500) -// for fixing issue https://svn.boost.org/trac/boost/ticket/9332 -# include "boost_fix/intrusive/detail/memory_util.hpp" -# include "boost_fix/container/detail/memory_util.hpp" -#endif -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -//OCC -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#endif // _PreComp_ -#endif - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_PRECOMPILED_H +#define PATH_PRECOMPILED_H + +#include + +// Exporting of App classes +#ifdef FC_OS_WIN32 +# define PathExport __declspec(dllexport) +//# define RobotExport __declspec(dllexport) uncomment this to use KDL +# define PartExport __declspec(dllimport) +# define BaseExport __declspec(dllimport) +#else // for Linux +# define PathExport +//# define RobotExport uncomment this to use KDL +# define PartExport +# define BaseExport +#endif + +#ifdef _PreComp_ + +// standard +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +// Python +#include + +// Boost +#include +#include +#if defined(BOOST_MSVC) && (BOOST_VERSION == 105500) +// for fixing issue https://svn.boost.org/trac/boost/ticket/9332 +# include "boost_fix/intrusive/detail/memory_util.hpp" +# include "boost_fix/container/detail/memory_util.hpp" +#endif +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +//OCC +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#endif // _PreComp_ +#endif + diff --git a/src/Mod/Path/App/PropertyPath.cpp b/src/Mod/Path/App/PropertyPath.cpp index 8fcb988734..1f99071844 100644 --- a/src/Mod/Path/App/PropertyPath.cpp +++ b/src/Mod/Path/App/PropertyPath.cpp @@ -1,161 +1,161 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -#endif - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "PropertyPath.h" -#include "PathPy.h" - -using namespace Path; - -TYPESYSTEM_SOURCE(Path::PropertyPath, App::Property) - -PropertyPath::PropertyPath() -{ -} - -PropertyPath::~PropertyPath() -{ -} - -void PropertyPath::setValue(const Toolpath& pa) -{ - aboutToSetValue(); - _Path = pa; - hasSetValue(); -} - - -const Toolpath &PropertyPath::getValue(void)const -{ - return _Path; -} - -PyObject *PropertyPath::getPyObject(void) -{ - return new PathPy(new Toolpath(_Path)); -} - -void PropertyPath::setPyObject(PyObject *value) -{ - if (PyObject_TypeCheck(value, &(PathPy::Type))) { - PathPy *pcObject = static_cast(value); - setValue(*pcObject->getToolpathPtr()); - } - else { - std::string error = std::string("type must be 'Path', not "); - error += value->ob_type->tp_name; - throw Base::TypeError(error); - } -} - -App::Property *PropertyPath::Copy(void) const -{ - PropertyPath *prop = new PropertyPath(); - prop->_Path = this->_Path; - - return prop; -} - -void PropertyPath::Paste(const App::Property &from) -{ - aboutToSetValue(); - _Path = dynamic_cast(from)._Path; - hasSetValue(); -} - -unsigned int PropertyPath::getMemSize (void) const -{ - return _Path.getMemSize(); -} - -void PropertyPath::Save (Base::Writer &writer) const -{ - _Path.Save(writer); -} - -void PropertyPath::Restore(Base::XMLReader &reader) -{ - reader.readElement("Path"); - - std::string file (reader.getAttribute("file") ); - if (!file.empty()) { - // initiate a file read - reader.addFile(file.c_str(),this); - } - - if (reader.hasAttribute("version")) { - int version = reader.getAttributeAsInteger("version"); - if (version >= Toolpath::SchemaVersion) { - reader.readElement("Center"); - double x = reader.getAttributeAsFloat("x"); - double y = reader.getAttributeAsFloat("y"); - double z = reader.getAttributeAsFloat("z"); - Base::Vector3d center(x, y, z); - _Path.setCenter(center); - } - } -} - -void PropertyPath::SaveDocFile (Base::Writer &) const -{ - // does nothing -} - -void PropertyPath::RestoreDocFile(Base::Reader &reader) -{ - App::PropertyContainer *container = getContainer(); - App::DocumentObject *obj = 0; - if (container->isDerivedFrom(App::DocumentObject::getClassTypeId())) { - obj = static_cast(container); - } - - if (obj) { - obj->setStatus(App::ObjectStatus::Restore, true); - } - - aboutToSetValue(); - _Path.RestoreDocFile(reader); - hasSetValue(); - - if (obj) { - obj->setStatus(App::ObjectStatus::Restore, false); - } -} - - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PropertyPath.h" +#include "PathPy.h" + +using namespace Path; + +TYPESYSTEM_SOURCE(Path::PropertyPath, App::Property) + +PropertyPath::PropertyPath() +{ +} + +PropertyPath::~PropertyPath() +{ +} + +void PropertyPath::setValue(const Toolpath& pa) +{ + aboutToSetValue(); + _Path = pa; + hasSetValue(); +} + + +const Toolpath &PropertyPath::getValue(void)const +{ + return _Path; +} + +PyObject *PropertyPath::getPyObject(void) +{ + return new PathPy(new Toolpath(_Path)); +} + +void PropertyPath::setPyObject(PyObject *value) +{ + if (PyObject_TypeCheck(value, &(PathPy::Type))) { + PathPy *pcObject = static_cast(value); + setValue(*pcObject->getToolpathPtr()); + } + else { + std::string error = std::string("type must be 'Path', not "); + error += value->ob_type->tp_name; + throw Base::TypeError(error); + } +} + +App::Property *PropertyPath::Copy(void) const +{ + PropertyPath *prop = new PropertyPath(); + prop->_Path = this->_Path; + + return prop; +} + +void PropertyPath::Paste(const App::Property &from) +{ + aboutToSetValue(); + _Path = dynamic_cast(from)._Path; + hasSetValue(); +} + +unsigned int PropertyPath::getMemSize (void) const +{ + return _Path.getMemSize(); +} + +void PropertyPath::Save (Base::Writer &writer) const +{ + _Path.Save(writer); +} + +void PropertyPath::Restore(Base::XMLReader &reader) +{ + reader.readElement("Path"); + + std::string file (reader.getAttribute("file") ); + if (!file.empty()) { + // initiate a file read + reader.addFile(file.c_str(),this); + } + + if (reader.hasAttribute("version")) { + int version = reader.getAttributeAsInteger("version"); + if (version >= Toolpath::SchemaVersion) { + reader.readElement("Center"); + double x = reader.getAttributeAsFloat("x"); + double y = reader.getAttributeAsFloat("y"); + double z = reader.getAttributeAsFloat("z"); + Base::Vector3d center(x, y, z); + _Path.setCenter(center); + } + } +} + +void PropertyPath::SaveDocFile (Base::Writer &) const +{ + // does nothing +} + +void PropertyPath::RestoreDocFile(Base::Reader &reader) +{ + App::PropertyContainer *container = getContainer(); + App::DocumentObject *obj = 0; + if (container->isDerivedFrom(App::DocumentObject::getClassTypeId())) { + obj = static_cast(container); + } + + if (obj) { + obj->setStatus(App::ObjectStatus::Restore, true); + } + + aboutToSetValue(); + _Path.RestoreDocFile(reader); + hasSetValue(); + + if (obj) { + obj->setStatus(App::ObjectStatus::Restore, false); + } +} + + + diff --git a/src/Mod/Path/App/PropertyPath.h b/src/Mod/Path/App/PropertyPath.h index d27f4c1bc7..4318446b45 100644 --- a/src/Mod/Path/App/PropertyPath.h +++ b/src/Mod/Path/App/PropertyPath.h @@ -1,77 +1,77 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PROPERTYPATH_H -#define PROPERTYPATH_H - -#include "Path.h" -#include - -namespace Path -{ - - -/** The path property class. */ -class PathExport PropertyPath : public App::Property -{ - TYPESYSTEM_HEADER(); - -public: - PropertyPath(); - ~PropertyPath(); - - /** @name Getter/setter */ - //@{ - /// set the part shape - void setValue(const Toolpath&); - /// get the part shape - const Toolpath &getValue(void) const; - //@} - - /** @name Python interface */ - //@{ - PyObject* getPyObject(void); - void setPyObject(PyObject *value); - //@} - - /** @name Save/restore */ - //@{ - void Save (Base::Writer &writer) const; - void Restore(Base::XMLReader &reader); - void SaveDocFile (Base::Writer &writer) const; - void RestoreDocFile(Base::Reader &reader); - - App::Property *Copy(void) const; - void Paste(const App::Property &from); - unsigned int getMemSize (void) const; - //@} - -private: - Toolpath _Path; -}; - - -} //namespace Path - - -#endif // PROPERTYPATH_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PROPERTYPATH_H +#define PROPERTYPATH_H + +#include "Path.h" +#include + +namespace Path +{ + + +/** The path property class. */ +class PathExport PropertyPath : public App::Property +{ + TYPESYSTEM_HEADER(); + +public: + PropertyPath(); + ~PropertyPath(); + + /** @name Getter/setter */ + //@{ + /// set the part shape + void setValue(const Toolpath&); + /// get the part shape + const Toolpath &getValue(void) const; + //@} + + /** @name Python interface */ + //@{ + PyObject* getPyObject(void); + void setPyObject(PyObject *value); + //@} + + /** @name Save/restore */ + //@{ + void Save (Base::Writer &writer) const; + void Restore(Base::XMLReader &reader); + void SaveDocFile (Base::Writer &writer) const; + void RestoreDocFile(Base::Reader &reader); + + App::Property *Copy(void) const; + void Paste(const App::Property &from); + unsigned int getMemSize (void) const; + //@} + +private: + Toolpath _Path; +}; + + +} //namespace Path + + +#endif // PROPERTYPATH_H diff --git a/src/Mod/Path/App/PropertyTool.cpp b/src/Mod/Path/App/PropertyTool.cpp index 39fd026484..5c42e7cbc7 100644 --- a/src/Mod/Path/App/PropertyTool.cpp +++ b/src/Mod/Path/App/PropertyTool.cpp @@ -1,116 +1,116 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -#endif - - -#include -#include -#include -#include -#include -#include - -#include "PropertyTool.h" -#include "ToolPy.h" - -using namespace Path; - -TYPESYSTEM_SOURCE(Path::PropertyTool, App::Property) - -PropertyTool::PropertyTool() -{ -} - -PropertyTool::~PropertyTool() -{ -} - -void PropertyTool::setValue(const Tool& tt) -{ - aboutToSetValue(); - _Tool = tt; - hasSetValue(); -} - - -const Tool &PropertyTool::getValue(void)const -{ - return _Tool; -} - -PyObject *PropertyTool::getPyObject(void) -{ - return new ToolPy(new Tool(_Tool)); -} - -void PropertyTool::setPyObject(PyObject *value) -{ - if (PyObject_TypeCheck(value, &(ToolPy::Type))) { - ToolPy *pcObject = static_cast(value); - setValue(*pcObject->getToolPtr()); - } - else { - std::string error = std::string("type must be 'Tool', not "); - error += value->ob_type->tp_name; - throw Base::TypeError(error); - } -} - -App::Property *PropertyTool::Copy(void) const -{ - PropertyTool *prop = new PropertyTool(); - prop->_Tool = this->_Tool; - - return prop; -} - -void PropertyTool::Paste(const App::Property &from) -{ - aboutToSetValue(); - _Tool = dynamic_cast(from)._Tool; - hasSetValue(); -} - -unsigned int PropertyTool::getMemSize (void) const -{ - return _Tool.getMemSize(); -} - -void PropertyTool::Save (Base::Writer &writer) const -{ - _Tool.Save(writer); -} - -void PropertyTool::Restore(Base::XMLReader &reader) -{ - Path::Tool temp; - temp.Restore(reader); - setValue(temp); -} - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + + +#include +#include +#include +#include +#include +#include + +#include "PropertyTool.h" +#include "ToolPy.h" + +using namespace Path; + +TYPESYSTEM_SOURCE(Path::PropertyTool, App::Property) + +PropertyTool::PropertyTool() +{ +} + +PropertyTool::~PropertyTool() +{ +} + +void PropertyTool::setValue(const Tool& tt) +{ + aboutToSetValue(); + _Tool = tt; + hasSetValue(); +} + + +const Tool &PropertyTool::getValue(void)const +{ + return _Tool; +} + +PyObject *PropertyTool::getPyObject(void) +{ + return new ToolPy(new Tool(_Tool)); +} + +void PropertyTool::setPyObject(PyObject *value) +{ + if (PyObject_TypeCheck(value, &(ToolPy::Type))) { + ToolPy *pcObject = static_cast(value); + setValue(*pcObject->getToolPtr()); + } + else { + std::string error = std::string("type must be 'Tool', not "); + error += value->ob_type->tp_name; + throw Base::TypeError(error); + } +} + +App::Property *PropertyTool::Copy(void) const +{ + PropertyTool *prop = new PropertyTool(); + prop->_Tool = this->_Tool; + + return prop; +} + +void PropertyTool::Paste(const App::Property &from) +{ + aboutToSetValue(); + _Tool = dynamic_cast(from)._Tool; + hasSetValue(); +} + +unsigned int PropertyTool::getMemSize (void) const +{ + return _Tool.getMemSize(); +} + +void PropertyTool::Save (Base::Writer &writer) const +{ + _Tool.Save(writer); +} + +void PropertyTool::Restore(Base::XMLReader &reader) +{ + Path::Tool temp; + temp.Restore(reader); + setValue(temp); +} + + diff --git a/src/Mod/Path/App/PropertyTool.h b/src/Mod/Path/App/PropertyTool.h index 706e4fae6b..a209086e9a 100644 --- a/src/Mod/Path/App/PropertyTool.h +++ b/src/Mod/Path/App/PropertyTool.h @@ -1,75 +1,75 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PROPERTYTOOL_H -#define PROPERTYTOOL_H - -#include "Tool.h" -#include - -namespace Path -{ - - -/** The tool property class. */ -class PathExport PropertyTool : public App::Property -{ - TYPESYSTEM_HEADER(); - -public: - PropertyTool(); - ~PropertyTool(); - - /** @name Getter/setter */ - //@{ - /// set the part shape - void setValue(const Tool&); - /// get the part shape - const Tool &getValue(void) const; - //@} - - /** @name Python interface */ - //@{ - PyObject* getPyObject(void); - void setPyObject(PyObject *value); - //@} - - /** @name Save/restore */ - //@{ - void Save (Base::Writer &writer) const; - void Restore(Base::XMLReader &reader); - - App::Property *Copy(void) const; - void Paste(const App::Property &from); - unsigned int getMemSize (void) const; - //@} - -private: - Tool _Tool; -}; - - -} //namespace Path - - -#endif // PROPERTYTOOL_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PROPERTYTOOL_H +#define PROPERTYTOOL_H + +#include "Tool.h" +#include + +namespace Path +{ + + +/** The tool property class. */ +class PathExport PropertyTool : public App::Property +{ + TYPESYSTEM_HEADER(); + +public: + PropertyTool(); + ~PropertyTool(); + + /** @name Getter/setter */ + //@{ + /// set the part shape + void setValue(const Tool&); + /// get the part shape + const Tool &getValue(void) const; + //@} + + /** @name Python interface */ + //@{ + PyObject* getPyObject(void); + void setPyObject(PyObject *value); + //@} + + /** @name Save/restore */ + //@{ + void Save (Base::Writer &writer) const; + void Restore(Base::XMLReader &reader); + + App::Property *Copy(void) const; + void Paste(const App::Property &from); + unsigned int getMemSize (void) const; + //@} + +private: + Tool _Tool; +}; + + +} //namespace Path + + +#endif // PROPERTYTOOL_H diff --git a/src/Mod/Path/App/PropertyTooltable.cpp b/src/Mod/Path/App/PropertyTooltable.cpp index b471a82f8a..c33d932848 100644 --- a/src/Mod/Path/App/PropertyTooltable.cpp +++ b/src/Mod/Path/App/PropertyTooltable.cpp @@ -1,116 +1,116 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ -# include -#endif - - -#include -#include -#include -#include -#include -#include - -#include "PropertyTooltable.h" -#include "TooltablePy.h" - -using namespace Path; - -TYPESYSTEM_SOURCE(Path::PropertyTooltable, App::Property) - -PropertyTooltable::PropertyTooltable() -{ -} - -PropertyTooltable::~PropertyTooltable() -{ -} - -void PropertyTooltable::setValue(const Tooltable& tt) -{ - aboutToSetValue(); - _Tooltable = tt; - hasSetValue(); -} - - -const Tooltable &PropertyTooltable::getValue(void)const -{ - return _Tooltable; -} - -PyObject *PropertyTooltable::getPyObject(void) -{ - return new TooltablePy(new Tooltable(_Tooltable)); -} - -void PropertyTooltable::setPyObject(PyObject *value) -{ - if (PyObject_TypeCheck(value, &(TooltablePy::Type))) { - TooltablePy *pcObject = static_cast(value); - setValue(*pcObject->getTooltablePtr()); - } - else { - std::string error = std::string("type must be 'Tooltable', not "); - error += value->ob_type->tp_name; - throw Base::TypeError(error); - } -} - -App::Property *PropertyTooltable::Copy(void) const -{ - PropertyTooltable *prop = new PropertyTooltable(); - prop->_Tooltable = this->_Tooltable; - - return prop; -} - -void PropertyTooltable::Paste(const App::Property &from) -{ - aboutToSetValue(); - _Tooltable = dynamic_cast(from)._Tooltable; - hasSetValue(); -} - -unsigned int PropertyTooltable::getMemSize (void) const -{ - return _Tooltable.getMemSize(); -} - -void PropertyTooltable::Save (Base::Writer &writer) const -{ - _Tooltable.Save(writer); -} - -void PropertyTooltable::Restore(Base::XMLReader &reader) -{ - Path::Tooltable temp; - temp.Restore(reader); - setValue(temp); -} - - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + + +#include +#include +#include +#include +#include +#include + +#include "PropertyTooltable.h" +#include "TooltablePy.h" + +using namespace Path; + +TYPESYSTEM_SOURCE(Path::PropertyTooltable, App::Property) + +PropertyTooltable::PropertyTooltable() +{ +} + +PropertyTooltable::~PropertyTooltable() +{ +} + +void PropertyTooltable::setValue(const Tooltable& tt) +{ + aboutToSetValue(); + _Tooltable = tt; + hasSetValue(); +} + + +const Tooltable &PropertyTooltable::getValue(void)const +{ + return _Tooltable; +} + +PyObject *PropertyTooltable::getPyObject(void) +{ + return new TooltablePy(new Tooltable(_Tooltable)); +} + +void PropertyTooltable::setPyObject(PyObject *value) +{ + if (PyObject_TypeCheck(value, &(TooltablePy::Type))) { + TooltablePy *pcObject = static_cast(value); + setValue(*pcObject->getTooltablePtr()); + } + else { + std::string error = std::string("type must be 'Tooltable', not "); + error += value->ob_type->tp_name; + throw Base::TypeError(error); + } +} + +App::Property *PropertyTooltable::Copy(void) const +{ + PropertyTooltable *prop = new PropertyTooltable(); + prop->_Tooltable = this->_Tooltable; + + return prop; +} + +void PropertyTooltable::Paste(const App::Property &from) +{ + aboutToSetValue(); + _Tooltable = dynamic_cast(from)._Tooltable; + hasSetValue(); +} + +unsigned int PropertyTooltable::getMemSize (void) const +{ + return _Tooltable.getMemSize(); +} + +void PropertyTooltable::Save (Base::Writer &writer) const +{ + _Tooltable.Save(writer); +} + +void PropertyTooltable::Restore(Base::XMLReader &reader) +{ + Path::Tooltable temp; + temp.Restore(reader); + setValue(temp); +} + + diff --git a/src/Mod/Path/App/PropertyTooltable.h b/src/Mod/Path/App/PropertyTooltable.h index d4b62fd2d1..3953ca573d 100644 --- a/src/Mod/Path/App/PropertyTooltable.h +++ b/src/Mod/Path/App/PropertyTooltable.h @@ -1,75 +1,75 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PROPERTYTOOLTABLE_H -#define PROPERTYTOOLTABLE_H - -#include "Tooltable.h" -#include - -namespace Path -{ - - -/** The tooltable property class. */ -class PathExport PropertyTooltable : public App::Property -{ - TYPESYSTEM_HEADER(); - -public: - PropertyTooltable(); - ~PropertyTooltable(); - - /** @name Getter/setter */ - //@{ - /// set the part shape - void setValue(const Tooltable&); - /// get the part shape - const Tooltable &getValue(void) const; - //@} - - /** @name Python interface */ - //@{ - PyObject* getPyObject(void); - void setPyObject(PyObject *value); - //@} - - /** @name Save/restore */ - //@{ - void Save (Base::Writer &writer) const; - void Restore(Base::XMLReader &reader); - - App::Property *Copy(void) const; - void Paste(const App::Property &from); - unsigned int getMemSize (void) const; - //@} - -private: - Tooltable _Tooltable; -}; - - -} //namespace Path - - -#endif // PROPERTYTOOLTABLE_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PROPERTYTOOLTABLE_H +#define PROPERTYTOOLTABLE_H + +#include "Tooltable.h" +#include + +namespace Path +{ + + +/** The tooltable property class. */ +class PathExport PropertyTooltable : public App::Property +{ + TYPESYSTEM_HEADER(); + +public: + PropertyTooltable(); + ~PropertyTooltable(); + + /** @name Getter/setter */ + //@{ + /// set the part shape + void setValue(const Tooltable&); + /// get the part shape + const Tooltable &getValue(void) const; + //@} + + /** @name Python interface */ + //@{ + PyObject* getPyObject(void); + void setPyObject(PyObject *value); + //@} + + /** @name Save/restore */ + //@{ + void Save (Base::Writer &writer) const; + void Restore(Base::XMLReader &reader); + + App::Property *Copy(void) const; + void Paste(const App::Property &from); + unsigned int getMemSize (void) const; + //@} + +private: + Tooltable _Tooltable; +}; + + +} //namespace Path + + +#endif // PROPERTYTOOLTABLE_H diff --git a/src/Mod/Path/App/Tool.cpp b/src/Mod/Path/App/Tool.cpp index 9c8a33f9f4..9badd5924b 100644 --- a/src/Mod/Path/App/Tool.cpp +++ b/src/Mod/Path/App/Tool.cpp @@ -1,258 +1,258 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#include "PreCompiled.h" - -#ifndef _PreComp_ - -#endif -#include -#include -#include -#include "Tool.h" - -using namespace Base; -using namespace Path; - -TYPESYSTEM_SOURCE(Path::Tool , Base::Persistence) - -// Constructors & destructors - -Tool::Tool(const char* name, - ToolType type, - ToolMaterial /*material*/, - double diameter, - double lengthoffset, - double flatradius, - double cornerradius, - double cuttingedgeangle, - double cuttingedgeheight) -:Name(name),Type(type),Material(MATUNDEFINED),Diameter(diameter),LengthOffset(lengthoffset), -FlatRadius(flatradius),CornerRadius(cornerradius),CuttingEdgeAngle(cuttingedgeangle), -CuttingEdgeHeight(cuttingedgeheight) -{ -} - -Tool::Tool() -{ - Type = UNDEFINED; - Material = MATUNDEFINED; - Diameter = 0; - LengthOffset = 0; - FlatRadius = 0; - CornerRadius = 0; - CuttingEdgeAngle = 180; - CuttingEdgeHeight = 0; -} - -Tool::~Tool() -{ -} - -// Reimplemented from base class -unsigned int Tool::getMemSize (void) const -{ - return 0; -} - -void Tool::Save (Writer &writer) const -{ - writer.Stream() << writer.ind() << "" << std::endl; -} - -void Tool::Restore(XMLReader &reader) -{ - reader.readElement("Tool"); - Name = reader.getAttribute("name"); - 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") : 180.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") : ""; - - Type = getToolType(type); - Material = getToolMaterial(mat); - - -} - -const std::vector Tool::ToolTypes(void) -{ - std::vector toolTypes(13); - toolTypes[0] ="EndMill"; - toolTypes[1] ="Drill"; - toolTypes[2] ="CenterDrill"; - toolTypes[3] ="CounterSink"; - toolTypes[4] ="CounterBore"; - toolTypes[5] ="FlyCutter"; - toolTypes[6] ="Reamer"; - toolTypes[7] ="Tap"; - toolTypes[8] ="SlotCutter"; - toolTypes[9] ="BallEndMill"; - toolTypes[10] ="ChamferMill"; - toolTypes[11] ="CornerRound"; - toolTypes[12] ="Engraver"; - return toolTypes; - -} - -const std::vector Tool::ToolMaterials(void) -{ - std::vector toolMat(7); - toolMat[0] ="Carbide"; - toolMat[1] ="HighSpeedSteel"; - toolMat[2] ="HighCarbonToolSteel"; - toolMat[3] ="CastAlloy"; - toolMat[4] ="Ceramics"; - toolMat[5] ="Diamond"; - toolMat[6] ="Sialon"; - return toolMat; - -} - -Tool::ToolType Tool::getToolType(std::string type) -{ - Tool::ToolType Type; - if(type=="EndMill") - Type = Tool::ENDMILL; - else if(type=="Drill") - Type = Tool::DRILL; - else if(type=="CenterDrill") - Type = Tool::CENTERDRILL; - else if(type=="CounterSink") - Type = Tool::COUNTERSINK; - else if(type=="CounterBore") - Type = Tool::COUNTERBORE; - else if(type=="FlyCutter") - Type = Tool::FLYCUTTER; - else if(type=="Reamer") - Type = Tool::REAMER; - else if(type=="Tap") - Type = Tool::TAP; - else if(type=="SlotCutter") - Type = Tool::SLOTCUTTER; - else if(type=="BallEndMill") - Type = Tool::BALLENDMILL; - else if(type=="ChamferMill") - Type = Tool::CHAMFERMILL; - else if(type=="CornerRound") - Type = Tool::CORNERROUND; - else if(type=="Engraver") - Type = Tool::ENGRAVER; - else - Type = Tool::UNDEFINED; - - return Type; -} - -Tool::ToolMaterial Tool::getToolMaterial(std::string mat) -{ - Tool::ToolMaterial Material; - if(mat=="Carbide") - Material = Tool::CARBIDE; - else if(mat=="HighSpeedSteel") - Material = Tool::HIGHSPEEDSTEEL; - else if(mat=="HighCarbonToolSteel") - Material = Tool::HIGHCARBONTOOLSTEEL; - else if(mat=="CastAlloy") - Material = Tool::CASTALLOY; - else if(mat=="Ceramics") - Material = Tool::CERAMICS; - else if(mat=="Diamond") - Material = Tool::DIAMOND; - else if(mat=="Sialon") - Material = Tool::SIALON; - else - Material = Tool::MATUNDEFINED; - - return Material; -} - -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::FLYCUTTER: - return "FlyCutter"; - 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"; +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ + +#endif +#include +#include +#include +#include "Tool.h" + +using namespace Base; +using namespace Path; + +TYPESYSTEM_SOURCE(Path::Tool , Base::Persistence) + +// Constructors & destructors + +Tool::Tool(const char* name, + ToolType type, + ToolMaterial /*material*/, + double diameter, + double lengthoffset, + double flatradius, + double cornerradius, + double cuttingedgeangle, + double cuttingedgeheight) +:Name(name),Type(type),Material(MATUNDEFINED),Diameter(diameter),LengthOffset(lengthoffset), +FlatRadius(flatradius),CornerRadius(cornerradius),CuttingEdgeAngle(cuttingedgeangle), +CuttingEdgeHeight(cuttingedgeheight) +{ +} + +Tool::Tool() +{ + Type = UNDEFINED; + Material = MATUNDEFINED; + Diameter = 0; + LengthOffset = 0; + FlatRadius = 0; + CornerRadius = 0; + CuttingEdgeAngle = 180; + CuttingEdgeHeight = 0; +} + +Tool::~Tool() +{ +} + +// Reimplemented from base class +unsigned int Tool::getMemSize (void) const +{ + return 0; +} + +void Tool::Save (Writer &writer) const +{ + writer.Stream() << writer.ind() << "" << std::endl; +} + +void Tool::Restore(XMLReader &reader) +{ + reader.readElement("Tool"); + Name = reader.getAttribute("name"); + 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") : 180.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") : ""; + + Type = getToolType(type); + Material = getToolMaterial(mat); + + +} + +const std::vector Tool::ToolTypes(void) +{ + std::vector toolTypes(13); + toolTypes[0] ="EndMill"; + toolTypes[1] ="Drill"; + toolTypes[2] ="CenterDrill"; + toolTypes[3] ="CounterSink"; + toolTypes[4] ="CounterBore"; + toolTypes[5] ="FlyCutter"; + toolTypes[6] ="Reamer"; + toolTypes[7] ="Tap"; + toolTypes[8] ="SlotCutter"; + toolTypes[9] ="BallEndMill"; + toolTypes[10] ="ChamferMill"; + toolTypes[11] ="CornerRound"; + toolTypes[12] ="Engraver"; + return toolTypes; + +} + +const std::vector Tool::ToolMaterials(void) +{ + std::vector toolMat(7); + toolMat[0] ="Carbide"; + toolMat[1] ="HighSpeedSteel"; + toolMat[2] ="HighCarbonToolSteel"; + toolMat[3] ="CastAlloy"; + toolMat[4] ="Ceramics"; + toolMat[5] ="Diamond"; + toolMat[6] ="Sialon"; + return toolMat; + +} + +Tool::ToolType Tool::getToolType(std::string type) +{ + Tool::ToolType Type; + if(type=="EndMill") + Type = Tool::ENDMILL; + else if(type=="Drill") + Type = Tool::DRILL; + else if(type=="CenterDrill") + Type = Tool::CENTERDRILL; + else if(type=="CounterSink") + Type = Tool::COUNTERSINK; + else if(type=="CounterBore") + Type = Tool::COUNTERBORE; + else if(type=="FlyCutter") + Type = Tool::FLYCUTTER; + else if(type=="Reamer") + Type = Tool::REAMER; + else if(type=="Tap") + Type = Tool::TAP; + else if(type=="SlotCutter") + Type = Tool::SLOTCUTTER; + else if(type=="BallEndMill") + Type = Tool::BALLENDMILL; + else if(type=="ChamferMill") + Type = Tool::CHAMFERMILL; + else if(type=="CornerRound") + Type = Tool::CORNERROUND; + else if(type=="Engraver") + Type = Tool::ENGRAVER; + else + Type = Tool::UNDEFINED; + + return Type; +} + +Tool::ToolMaterial Tool::getToolMaterial(std::string mat) +{ + Tool::ToolMaterial Material; + if(mat=="Carbide") + Material = Tool::CARBIDE; + else if(mat=="HighSpeedSteel") + Material = Tool::HIGHSPEEDSTEEL; + else if(mat=="HighCarbonToolSteel") + Material = Tool::HIGHCARBONTOOLSTEEL; + else if(mat=="CastAlloy") + Material = Tool::CASTALLOY; + else if(mat=="Ceramics") + Material = Tool::CERAMICS; + else if(mat=="Diamond") + Material = Tool::DIAMOND; + else if(mat=="Sialon") + Material = Tool::SIALON; + else + Material = Tool::MATUNDEFINED; + + return Material; +} + +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::FLYCUTTER: + return "FlyCutter"; + 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"; } \ No newline at end of file diff --git a/src/Mod/Path/App/Tool.h b/src/Mod/Path/App/Tool.h index c8a5690fc3..7cceac3e2e 100644 --- a/src/Mod/Path/App/Tool.h +++ b/src/Mod/Path/App/Tool.h @@ -1,104 +1,104 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - -#ifndef PATH_TOOL_H -#define PATH_TOOL_H - -#include -#include -#include -#include - -namespace Path -{ - - /** The representation of a single tool */ - class PathExport Tool : public Base::Persistence - { - TYPESYSTEM_HEADER(); - - public: - enum ToolType { - UNDEFINED, - DRILL, - CENTERDRILL, - COUNTERSINK, - COUNTERBORE, - FLYCUTTER, - REAMER, - TAP, - ENDMILL, - SLOTCUTTER, - BALLENDMILL, - CHAMFERMILL, - CORNERROUND, - ENGRAVER }; - - enum ToolMaterial { - MATUNDEFINED, - HIGHSPEEDSTEEL, - HIGHCARBONTOOLSTEEL, - CASTALLOY, - CARBIDE, - CERAMICS, - DIAMOND, - SIALON }; - - //constructors - Tool(); - Tool(const char* name, - ToolType type=Tool::UNDEFINED, - ToolMaterial material=Tool::MATUNDEFINED, - double diameter=10.0, - double lengthoffset=100, - double flatradius=0, - double cornerradius=0, - double cuttingedgeangle=0, - double cuttingedgeheight=0); - ~Tool(); - - // from base class - virtual unsigned int getMemSize (void) const; - virtual void Save (Base::Writer &/*writer*/) const; - virtual void Restore(Base::XMLReader &/*reader*/); - - // attributes - std::string Name; - ToolType Type; - ToolMaterial Material; - double Diameter; - double LengthOffset; - double FlatRadius; - double CornerRadius; - double CuttingEdgeAngle; - double CuttingEdgeHeight; - - static const std::vector ToolTypes(void); - static const std::vector ToolMaterials(void); - static const char* TypeName(ToolType typ); - static ToolType getToolType(std::string type); - static ToolMaterial getToolMaterial(std::string mat); - static const char* MaterialName(ToolMaterial mat); - }; -} //namespace Path - -#endif // PATH_TOOL_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef PATH_TOOL_H +#define PATH_TOOL_H + +#include +#include +#include +#include + +namespace Path +{ + + /** The representation of a single tool */ + class PathExport Tool : public Base::Persistence + { + TYPESYSTEM_HEADER(); + + public: + enum ToolType { + UNDEFINED, + DRILL, + CENTERDRILL, + COUNTERSINK, + COUNTERBORE, + FLYCUTTER, + REAMER, + TAP, + ENDMILL, + SLOTCUTTER, + BALLENDMILL, + CHAMFERMILL, + CORNERROUND, + ENGRAVER }; + + enum ToolMaterial { + MATUNDEFINED, + HIGHSPEEDSTEEL, + HIGHCARBONTOOLSTEEL, + CASTALLOY, + CARBIDE, + CERAMICS, + DIAMOND, + SIALON }; + + //constructors + Tool(); + Tool(const char* name, + ToolType type=Tool::UNDEFINED, + ToolMaterial material=Tool::MATUNDEFINED, + double diameter=10.0, + double lengthoffset=100, + double flatradius=0, + double cornerradius=0, + double cuttingedgeangle=0, + double cuttingedgeheight=0); + ~Tool(); + + // from base class + virtual unsigned int getMemSize (void) const; + virtual void Save (Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + + // attributes + std::string Name; + ToolType Type; + ToolMaterial Material; + double Diameter; + double LengthOffset; + double FlatRadius; + double CornerRadius; + double CuttingEdgeAngle; + double CuttingEdgeHeight; + + static const std::vector ToolTypes(void); + static const std::vector ToolMaterials(void); + static const char* TypeName(ToolType typ); + static ToolType getToolType(std::string type); + static ToolMaterial getToolMaterial(std::string mat); + static const char* MaterialName(ToolMaterial mat); + }; +} //namespace Path + +#endif // PATH_TOOL_H diff --git a/src/Mod/Path/App/ToolPy.xml b/src/Mod/Path/App/ToolPy.xml index 94e56525d3..c174b7a20b 100644 --- a/src/Mod/Path/App/ToolPy.xml +++ b/src/Mod/Path/App/ToolPy.xml @@ -1,113 +1,113 @@ - - - - - - The Tool objects holds the properties of a CNC tool. -optional attributes: - name: a user-defined name for this tool - tooltype: Drill, CenterDrill, CounterSink, CounterBore, Reamer, Tap, EndMill, SlotCutter, BallEndMill, ChamferMill, CornerRound, Engraver or Undefined - material: HighSpeedSteel, HighCarbonToolSteel, Carbide, CastAlloy, Ceramics, Diamond, Sialon or Undefined - diameter : the diameter of this tool - lengthOffset - flatRadius - cornerRadius - cuttingEdgeAngle - cuttingEdgeHeight - - - - the name of this tool in mm - - - - - - the type of this tool: Drill, CenterDrill, CounterSink, CounterBore, Reamer, Tap, -EndMill, SlotCutter, BallEndMill, ChamferMill, CornerRound, Engraver or Undefined - - - - - - the material of this tool: Steel, Carbide, HighSpeedSteel, -HighCarbonToolSteel CastAlloy, Ceramics, Diamond, Sialon or Undefined - - - - - - the diameter of this tool in mm - - - - - - the length offset of this tool in mm - - - - - - the flat radius of this tool in mm - - - - - - the corner radius of this tool in mm - - - - - - the cutting edge angle of this tool - - - - - - the cutting edge height of this tool in mm - - - - - - returns a copy of this tool - - - - - returns all available tool types - - - - - returns all available tool materials - - - - - setFromTemplate(xmlString|dictionary) ... fills receiver with values from the template string or dictionary - - - - - templateAttrs() ... returns a dictionary with all attributes - - - - - + + + + + + The Tool objects holds the properties of a CNC tool. +optional attributes: + name: a user-defined name for this tool + tooltype: Drill, CenterDrill, CounterSink, CounterBore, Reamer, Tap, EndMill, SlotCutter, BallEndMill, ChamferMill, CornerRound, Engraver or Undefined + material: HighSpeedSteel, HighCarbonToolSteel, Carbide, CastAlloy, Ceramics, Diamond, Sialon or Undefined + diameter : the diameter of this tool + lengthOffset + flatRadius + cornerRadius + cuttingEdgeAngle + cuttingEdgeHeight + + + + the name of this tool in mm + + + + + + the type of this tool: Drill, CenterDrill, CounterSink, CounterBore, Reamer, Tap, +EndMill, SlotCutter, BallEndMill, ChamferMill, CornerRound, Engraver or Undefined + + + + + + the material of this tool: Steel, Carbide, HighSpeedSteel, +HighCarbonToolSteel CastAlloy, Ceramics, Diamond, Sialon or Undefined + + + + + + the diameter of this tool in mm + + + + + + the length offset of this tool in mm + + + + + + the flat radius of this tool in mm + + + + + + the corner radius of this tool in mm + + + + + + the cutting edge angle of this tool + + + + + + the cutting edge height of this tool in mm + + + + + + returns a copy of this tool + + + + + returns all available tool types + + + + + returns all available tool materials + + + + + setFromTemplate(xmlString|dictionary) ... fills receiver with values from the template string or dictionary + + + + + templateAttrs() ... returns a dictionary with all attributes + + + + + diff --git a/src/Mod/Path/App/ToolPyImp.cpp b/src/Mod/Path/App/ToolPyImp.cpp index c075d2c786..7e12bee485 100644 --- a/src/Mod/Path/App/ToolPyImp.cpp +++ b/src/Mod/Path/App/ToolPyImp.cpp @@ -1,302 +1,302 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#include "Base/Reader.h" -#include "Mod/Path/App/Tool.h" -#include "Mod/Path/App/Tooltable.h" - -// inclusion of the generated files (generated out of ToolPy.xml and TooltablePy.xml) -#include "ToolPy.h" -#include "ToolPy.cpp" - -using namespace Path; - -#if PY_MAJOR_VERSION >= 3 -# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) -# define PYINT_TYPE PyLong_Type -# define PYINT_FROMLONG(l) PyLong_FromLong(l) -# define PYINT_ASLONG(o) PyLong_AsLong(o) -#else -# define PYSTRING_FROMSTRING(str) PyString_FromString(str) -# define PYINT_TYPE PyInt_Type -# define PYINT_FROMLONG(l) PyInt_FromLong(l) -# define PYINT_ASLONG(o) PyInt_AsLong(o) -#endif - - -// returns a string which represents the object e.g. when printed in python -std::string ToolPy::representation(void) const -{ - std::stringstream str; - str.precision(5); - str << "Tool "; - str << getToolPtr()->Name; - return str.str(); -} - -PyObject *ToolPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper -{ - // create a new instance of ToolPy and the Twin object - return new ToolPy(new Tool); -} - -// constructor method -int ToolPy::PyInit(PyObject* args, PyObject* kwd) -{ - char *name="Default tool"; - char *type = "Undefined"; - char *mat = "Undefined"; - PyObject *dia = 0; - PyObject *len = 0; - PyObject *fla = 0; - PyObject *cor = 0; - PyObject *ang = 0; - PyObject *hei = 0; - int version = 1; - - static char *kwlist[] = {"name", "tooltype", "material", "diameter", "lengthOffset", "flatRadius", "cornerRadius", "cuttingEdgeAngle", "cuttingEdgeHeight" , "version", NULL}; - - PyObject *dict = 0; - if (!kwd && (PyObject_TypeCheck(args, &PyDict_Type) || PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))) { - static PyObject *arg = PyTuple_New(0); - if (PyObject_TypeCheck(args, &PyDict_Type)) { - dict = args; - } - if (!PyArg_ParseTupleAndKeywords(arg, dict, "|sssOOOOOOi", kwlist, &name, &type, &mat, &dia, &len, &fla, &cor, &ang, &hei, &version)) { - return -1; - } - } else { - PyErr_Clear(); - if (!PyArg_ParseTupleAndKeywords(args, kwd, "|sssOOOOOO", kwlist, &name, &type, &mat, &dia, &len, &fla, &cor, &ang, &hei)) { - return -1; - } - } - - if (1 != version) { - PyErr_SetString(PyExc_TypeError, "Unsupported Tool template version"); - return -1; - } - - getToolPtr()->Name = name; - - std::string typeStr(type); - getToolPtr()->Type = Tool::getToolType(typeStr); - - std::string matStr(mat); - getToolPtr()->Material = Tool::getToolMaterial(matStr); - - getToolPtr()->Diameter = dia ? PyFloat_AsDouble(dia) : 0.0; - getToolPtr()->LengthOffset = len ? PyFloat_AsDouble(len) : 0.0; - getToolPtr()->FlatRadius = fla ? PyFloat_AsDouble(fla) : 0.0; - getToolPtr()->CornerRadius = cor ? PyFloat_AsDouble(cor) : 0.0; - getToolPtr()->CuttingEdgeAngle = ang ? PyFloat_AsDouble(ang) : 180.0; - getToolPtr()->CuttingEdgeHeight = hei ? PyFloat_AsDouble(hei) : 0.0; - - return 0; -} - -// attributes get/setters - -Py::String ToolPy::getName(void) const -{ - return Py::String(getToolPtr()->Name.c_str()); -} - -void ToolPy::setName(Py::String arg) -{ - std::string name = arg.as_std_string(); - getToolPtr()->Name = name; -} - -Py::String ToolPy::getToolType(void) const -{ - return Py::String(Tool::TypeName(getToolPtr()->Type)); -} - -void ToolPy::setToolType(Py::String arg) -{ - std::string typeStr(arg.as_std_string()); - getToolPtr()->Type = Tool::getToolType(typeStr); - -} - -Py::String ToolPy::getMaterial(void) const -{ - return Py::String(Tool::MaterialName(getToolPtr()->Material)); -} - -void ToolPy::setMaterial(Py::String arg) -{ - std::string matStr(arg.as_std_string()); - getToolPtr()->Material = Tool::getToolMaterial(matStr); -} - -Py::Float ToolPy::getDiameter(void) const -{ - return Py::Float(getToolPtr()->Diameter); -} - -void ToolPy::setDiameter(Py::Float arg) -{ - getToolPtr()->Diameter = arg.operator double(); -} - -Py::Float ToolPy::getLengthOffset(void) const -{ - return Py::Float(getToolPtr()->LengthOffset); -} - -void ToolPy::setLengthOffset(Py::Float arg) -{ - getToolPtr()->LengthOffset = arg.operator double(); -} - -Py::Float ToolPy::getFlatRadius(void) const -{ - return Py::Float(getToolPtr()->FlatRadius); -} - -void ToolPy::setFlatRadius(Py::Float arg) -{ - getToolPtr()->FlatRadius = arg.operator double(); -} - -Py::Float ToolPy::getCornerRadius(void) const -{ - return Py::Float(getToolPtr()->CornerRadius); -} - -void ToolPy::setCornerRadius(Py::Float arg) -{ - getToolPtr()->CornerRadius = arg.operator double(); -} - -Py::Float ToolPy::getCuttingEdgeAngle(void) const -{ - return Py::Float(getToolPtr()->CuttingEdgeAngle); -} - -void ToolPy::setCuttingEdgeAngle(Py::Float arg) -{ - getToolPtr()->CuttingEdgeAngle = arg.operator double(); -} - -Py::Float ToolPy::getCuttingEdgeHeight(void) const -{ - return Py::Float(getToolPtr()->CuttingEdgeHeight); -} - -void ToolPy::setCuttingEdgeHeight(Py::Float arg) -{ - getToolPtr()->CuttingEdgeHeight = arg.operator double(); -} - -// custom attributes get/set - -PyObject *ToolPy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - -int ToolPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} - -PyObject* ToolPy::copy(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - return new ToolPy(new Path::Tool(*getToolPtr())); - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* ToolPy::setFromTemplate(PyObject * args) -{ - char *pstr = 0; - if (PyArg_ParseTuple(args, "s", &pstr)) { - // embed actual string in dummy tag so XMLReader can consume that on construction - std::ostringstream os; - os << "" << pstr << ""; - std::istringstream is(os.str()); - Base::XMLReader reader("", is); - getToolPtr()->Restore(reader); - Py_Return ; - } - - PyErr_Clear(); - if (!PyInit(args, 0)) { - Py_Return ; - } - - PyErr_SetString(PyExc_TypeError, "argument must be a string or dictionary"); - return 0; -} - -PyObject* ToolPy::templateAttrs(PyObject * args) -{ - if (!args || PyArg_ParseTuple(args, "")) { - PyObject *dict = PyDict_New(); - PyDict_SetItemString(dict, "version", PYINT_FROMLONG(1)); - 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::TypeError("This method accepts no argument"); -} - -PyObject* ToolPy::getToolTypes(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - std::vector toolTypes = Tool::ToolTypes(); - PyObject *list = PyList_New(0); - for(unsigned i = 0; i != toolTypes.size(); i++) { - - PyList_Append(list, PYSTRING_FROMSTRING(toolTypes[i].c_str())); - } - return list; - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* ToolPy::getToolMaterials(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - std::vector toolMaterials = Tool::ToolMaterials(); - PyObject *list = PyList_New(0); - for(unsigned i = 0; i != toolMaterials.size(); i++) { - - PyList_Append(list, PYSTRING_FROMSTRING(toolMaterials[i].c_str())); - } - return list; - } - throw Py::TypeError("This method accepts no argument"); +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#include "Base/Reader.h" +#include "Mod/Path/App/Tool.h" +#include "Mod/Path/App/Tooltable.h" + +// inclusion of the generated files (generated out of ToolPy.xml and TooltablePy.xml) +#include "ToolPy.h" +#include "ToolPy.cpp" + +using namespace Path; + +#if PY_MAJOR_VERSION >= 3 +# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) +# define PYINT_TYPE PyLong_Type +# define PYINT_FROMLONG(l) PyLong_FromLong(l) +# define PYINT_ASLONG(o) PyLong_AsLong(o) +#else +# define PYSTRING_FROMSTRING(str) PyString_FromString(str) +# define PYINT_TYPE PyInt_Type +# define PYINT_FROMLONG(l) PyInt_FromLong(l) +# define PYINT_ASLONG(o) PyInt_AsLong(o) +#endif + + +// returns a string which represents the object e.g. when printed in python +std::string ToolPy::representation(void) const +{ + std::stringstream str; + str.precision(5); + str << "Tool "; + str << getToolPtr()->Name; + return str.str(); +} + +PyObject *ToolPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ToolPy and the Twin object + return new ToolPy(new Tool); +} + +// constructor method +int ToolPy::PyInit(PyObject* args, PyObject* kwd) +{ + char *name="Default tool"; + char *type = "Undefined"; + char *mat = "Undefined"; + PyObject *dia = 0; + PyObject *len = 0; + PyObject *fla = 0; + PyObject *cor = 0; + PyObject *ang = 0; + PyObject *hei = 0; + int version = 1; + + static char *kwlist[] = {"name", "tooltype", "material", "diameter", "lengthOffset", "flatRadius", "cornerRadius", "cuttingEdgeAngle", "cuttingEdgeHeight" , "version", NULL}; + + PyObject *dict = 0; + if (!kwd && (PyObject_TypeCheck(args, &PyDict_Type) || PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))) { + static PyObject *arg = PyTuple_New(0); + if (PyObject_TypeCheck(args, &PyDict_Type)) { + dict = args; + } + if (!PyArg_ParseTupleAndKeywords(arg, dict, "|sssOOOOOOi", kwlist, &name, &type, &mat, &dia, &len, &fla, &cor, &ang, &hei, &version)) { + return -1; + } + } else { + PyErr_Clear(); + if (!PyArg_ParseTupleAndKeywords(args, kwd, "|sssOOOOOO", kwlist, &name, &type, &mat, &dia, &len, &fla, &cor, &ang, &hei)) { + return -1; + } + } + + if (1 != version) { + PyErr_SetString(PyExc_TypeError, "Unsupported Tool template version"); + return -1; + } + + getToolPtr()->Name = name; + + std::string typeStr(type); + getToolPtr()->Type = Tool::getToolType(typeStr); + + std::string matStr(mat); + getToolPtr()->Material = Tool::getToolMaterial(matStr); + + getToolPtr()->Diameter = dia ? PyFloat_AsDouble(dia) : 0.0; + getToolPtr()->LengthOffset = len ? PyFloat_AsDouble(len) : 0.0; + getToolPtr()->FlatRadius = fla ? PyFloat_AsDouble(fla) : 0.0; + getToolPtr()->CornerRadius = cor ? PyFloat_AsDouble(cor) : 0.0; + getToolPtr()->CuttingEdgeAngle = ang ? PyFloat_AsDouble(ang) : 180.0; + getToolPtr()->CuttingEdgeHeight = hei ? PyFloat_AsDouble(hei) : 0.0; + + return 0; +} + +// attributes get/setters + +Py::String ToolPy::getName(void) const +{ + return Py::String(getToolPtr()->Name.c_str()); +} + +void ToolPy::setName(Py::String arg) +{ + std::string name = arg.as_std_string(); + getToolPtr()->Name = name; +} + +Py::String ToolPy::getToolType(void) const +{ + return Py::String(Tool::TypeName(getToolPtr()->Type)); +} + +void ToolPy::setToolType(Py::String arg) +{ + std::string typeStr(arg.as_std_string()); + getToolPtr()->Type = Tool::getToolType(typeStr); + +} + +Py::String ToolPy::getMaterial(void) const +{ + return Py::String(Tool::MaterialName(getToolPtr()->Material)); +} + +void ToolPy::setMaterial(Py::String arg) +{ + std::string matStr(arg.as_std_string()); + getToolPtr()->Material = Tool::getToolMaterial(matStr); +} + +Py::Float ToolPy::getDiameter(void) const +{ + return Py::Float(getToolPtr()->Diameter); +} + +void ToolPy::setDiameter(Py::Float arg) +{ + getToolPtr()->Diameter = arg.operator double(); +} + +Py::Float ToolPy::getLengthOffset(void) const +{ + return Py::Float(getToolPtr()->LengthOffset); +} + +void ToolPy::setLengthOffset(Py::Float arg) +{ + getToolPtr()->LengthOffset = arg.operator double(); +} + +Py::Float ToolPy::getFlatRadius(void) const +{ + return Py::Float(getToolPtr()->FlatRadius); +} + +void ToolPy::setFlatRadius(Py::Float arg) +{ + getToolPtr()->FlatRadius = arg.operator double(); +} + +Py::Float ToolPy::getCornerRadius(void) const +{ + return Py::Float(getToolPtr()->CornerRadius); +} + +void ToolPy::setCornerRadius(Py::Float arg) +{ + getToolPtr()->CornerRadius = arg.operator double(); +} + +Py::Float ToolPy::getCuttingEdgeAngle(void) const +{ + return Py::Float(getToolPtr()->CuttingEdgeAngle); +} + +void ToolPy::setCuttingEdgeAngle(Py::Float arg) +{ + getToolPtr()->CuttingEdgeAngle = arg.operator double(); +} + +Py::Float ToolPy::getCuttingEdgeHeight(void) const +{ + return Py::Float(getToolPtr()->CuttingEdgeHeight); +} + +void ToolPy::setCuttingEdgeHeight(Py::Float arg) +{ + getToolPtr()->CuttingEdgeHeight = arg.operator double(); +} + +// custom attributes get/set + +PyObject *ToolPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int ToolPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + +PyObject* ToolPy::copy(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + return new ToolPy(new Path::Tool(*getToolPtr())); + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* ToolPy::setFromTemplate(PyObject * args) +{ + char *pstr = 0; + if (PyArg_ParseTuple(args, "s", &pstr)) { + // embed actual string in dummy tag so XMLReader can consume that on construction + std::ostringstream os; + os << "" << pstr << ""; + std::istringstream is(os.str()); + Base::XMLReader reader("", is); + getToolPtr()->Restore(reader); + Py_Return ; + } + + PyErr_Clear(); + if (!PyInit(args, 0)) { + Py_Return ; + } + + PyErr_SetString(PyExc_TypeError, "argument must be a string or dictionary"); + return 0; +} + +PyObject* ToolPy::templateAttrs(PyObject * args) +{ + if (!args || PyArg_ParseTuple(args, "")) { + PyObject *dict = PyDict_New(); + PyDict_SetItemString(dict, "version", PYINT_FROMLONG(1)); + 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::TypeError("This method accepts no argument"); +} + +PyObject* ToolPy::getToolTypes(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + std::vector toolTypes = Tool::ToolTypes(); + PyObject *list = PyList_New(0); + for(unsigned i = 0; i != toolTypes.size(); i++) { + + PyList_Append(list, PYSTRING_FROMSTRING(toolTypes[i].c_str())); + } + return list; + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* ToolPy::getToolMaterials(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + std::vector toolMaterials = Tool::ToolMaterials(); + PyObject *list = PyList_New(0); + for(unsigned i = 0; i != toolMaterials.size(); i++) { + + PyList_Append(list, PYSTRING_FROMSTRING(toolMaterials[i].c_str())); + } + return list; + } + throw Py::TypeError("This method accepts no argument"); } \ No newline at end of file diff --git a/src/Mod/Path/App/Tooltable.cpp b/src/Mod/Path/App/Tooltable.cpp index 699e93e8f2..ed79e2b87d 100644 --- a/src/Mod/Path/App/Tooltable.cpp +++ b/src/Mod/Path/App/Tooltable.cpp @@ -1,116 +1,116 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#ifndef _PreComp_ - -#endif -#include -#include -#include -#include "Tooltable.h" - -using namespace Base; -using namespace Path; - -TYPESYSTEM_SOURCE(Path::Tooltable , Base::Persistence) - -Tooltable::Tooltable() -{ -} - -Tooltable::~Tooltable() -{ -} - -void Tooltable::addTool(const Tool &tool) -{ - Tool *tmp = new Tool(tool); - if (!Tools.empty()) { - int max = 0; - for(std::map::const_iterator i = Tools.begin(); i != Tools.end(); ++i) { - int k = i->first; - if (k > max) - max = k; - } - Tools[max+1]= tmp; - } else - Tools[1] = tmp; -} - -void Tooltable::setTool(const Tool &tool, int pos) -{ - if (pos == -1) { - addTool(tool); - } else { - Tool *tmp = new Tool(tool); - Tools[pos] = tmp; - } -} - -void Tooltable::deleteTool(int pos) -{ - if (Tools.find(pos) != Tools.end()) { - Tools.erase(pos); - } else { - throw Base::IndexError("Index not found"); - } -} - -unsigned int Tooltable::getMemSize (void) const -{ - return 0; -} - -void Tooltable::Save (Writer &writer) const -{ - writer.Stream() << writer.ind() << "" << std::endl; - writer.incInd(); - for(std::map::const_iterator i = Tools.begin(); i != Tools.end(); ++i) { - int k = i->first; - Tool *v = i->second; - writer.Stream() << writer.ind() << "" << std::endl; - writer.incInd(); - v->Save(writer); - writer.decInd(); - writer.Stream() << writer.ind() << "" << std::endl; - } - writer.decInd(); - writer.Stream() << writer.ind() << "" << std::endl ; - -} - -void Tooltable::Restore (XMLReader &reader) -{ - Tools.clear(); - reader.readElement("Tooltable"); - int count = reader.getAttributeAsInteger("count"); - for (int i = 0; i < count; i++) { - reader.readElement("Toolslot"); - int id = reader.getAttributeAsInteger("number"); - Tool *tmp = new Tool(); - tmp->Restore(reader); - Tools[id] = tmp; - } -} +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ + +#endif +#include +#include +#include +#include "Tooltable.h" + +using namespace Base; +using namespace Path; + +TYPESYSTEM_SOURCE(Path::Tooltable , Base::Persistence) + +Tooltable::Tooltable() +{ +} + +Tooltable::~Tooltable() +{ +} + +void Tooltable::addTool(const Tool &tool) +{ + Tool *tmp = new Tool(tool); + if (!Tools.empty()) { + int max = 0; + for(std::map::const_iterator i = Tools.begin(); i != Tools.end(); ++i) { + int k = i->first; + if (k > max) + max = k; + } + Tools[max+1]= tmp; + } else + Tools[1] = tmp; +} + +void Tooltable::setTool(const Tool &tool, int pos) +{ + if (pos == -1) { + addTool(tool); + } else { + Tool *tmp = new Tool(tool); + Tools[pos] = tmp; + } +} + +void Tooltable::deleteTool(int pos) +{ + if (Tools.find(pos) != Tools.end()) { + Tools.erase(pos); + } else { + throw Base::IndexError("Index not found"); + } +} + +unsigned int Tooltable::getMemSize (void) const +{ + return 0; +} + +void Tooltable::Save (Writer &writer) const +{ + writer.Stream() << writer.ind() << "" << std::endl; + writer.incInd(); + for(std::map::const_iterator i = Tools.begin(); i != Tools.end(); ++i) { + int k = i->first; + Tool *v = i->second; + writer.Stream() << writer.ind() << "" << std::endl; + writer.incInd(); + v->Save(writer); + writer.decInd(); + writer.Stream() << writer.ind() << "" << std::endl; + } + writer.decInd(); + writer.Stream() << writer.ind() << "" << std::endl ; + +} + +void Tooltable::Restore (XMLReader &reader) +{ + Tools.clear(); + reader.readElement("Tooltable"); + int count = reader.getAttributeAsInteger("count"); + for (int i = 0; i < count; i++) { + reader.readElement("Toolslot"); + int id = reader.getAttributeAsInteger("number"); + Tool *tmp = new Tool(); + tmp->Restore(reader); + Tools[id] = tmp; + } +} diff --git a/src/Mod/Path/App/Tooltable.h b/src/Mod/Path/App/Tooltable.h index 873b943afd..28b69ece71 100644 --- a/src/Mod/Path/App/Tooltable.h +++ b/src/Mod/Path/App/Tooltable.h @@ -1,68 +1,68 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef PATH_TOOLTABLE_H -#define PATH_TOOLTABLE_H - -#include -#include -#include -#include -#include "Tool.h" - -namespace Path -{ /** The representation of a table of tools */ - class PathExport Tooltable : public Base::Persistence - { - TYPESYSTEM_HEADER(); - - public: - //constructors - Tooltable(); - ~Tooltable(); - - // from base class - virtual unsigned int getMemSize (void) const; - virtual void Save (Base::Writer &/*writer*/) const; - virtual void Restore(Base::XMLReader &/*reader*/); - - // new functions - void addTool(const Tool &tool); // adds a tool at the end - void setTool(const Tool &tool, int); // inserts a tool - void deleteTool(int); // deletes a tool - - // auto - unsigned int getSize(void) const {return Tools.size();} - const Tool &getTool(int pos) {return *Tools[pos];} - const std::map &getTools(void) const {return Tools;} - bool hasTool(int pos) const {return (Tools.count(pos) != 0);} - - // attributes - std::map Tools; - int Version; - std::string Name; - }; - -} //namespace Path - -#endif // PATH_TOOLTABLE_H +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef PATH_TOOLTABLE_H +#define PATH_TOOLTABLE_H + +#include +#include +#include +#include +#include "Tool.h" + +namespace Path +{ /** The representation of a table of tools */ + class PathExport Tooltable : public Base::Persistence + { + TYPESYSTEM_HEADER(); + + public: + //constructors + Tooltable(); + ~Tooltable(); + + // from base class + virtual unsigned int getMemSize (void) const; + virtual void Save (Base::Writer &/*writer*/) const; + virtual void Restore(Base::XMLReader &/*reader*/); + + // new functions + void addTool(const Tool &tool); // adds a tool at the end + void setTool(const Tool &tool, int); // inserts a tool + void deleteTool(int); // deletes a tool + + // auto + unsigned int getSize(void) const {return Tools.size();} + const Tool &getTool(int pos) {return *Tools[pos];} + const std::map &getTools(void) const {return Tools;} + bool hasTool(int pos) const {return (Tools.count(pos) != 0);} + + // attributes + std::map Tools; + int Version; + std::string Name; + }; + +} //namespace Path + +#endif // PATH_TOOLTABLE_H diff --git a/src/Mod/Path/App/TooltablePy.xml b/src/Mod/Path/App/TooltablePy.xml index 0480a83b03..3549a508e0 100644 --- a/src/Mod/Path/App/TooltablePy.xml +++ b/src/Mod/Path/App/TooltablePy.xml @@ -1,78 +1,78 @@ - - - - - - The Tooltable object holds a table of CNC tools - - - - the name of this tool table - - - - - - the version of this tooltable - - - - - - the dictionary of tools of this table - - - - - - returns a copy of this tooltable - - - - - adds a tool or a list of tools at the end of the table - - - - - getTool(int): -returns the tool found at the given position, or None - - - - - setTool(int,tool): -adds a tool at the given position - - - - - deleteTool(int): -deletes the tool found at the given position - - - - - - setFromTemplate(dict) ... restores receiver from given template attribute dictionary - - - - - templateAttrs() ... returns a dictionary representing the receivers attributes for a template - - - - + + + + + + The Tooltable object holds a table of CNC tools + + + + the name of this tool table + + + + + + the version of this tooltable + + + + + + the dictionary of tools of this table + + + + + + returns a copy of this tooltable + + + + + adds a tool or a list of tools at the end of the table + + + + + getTool(int): +returns the tool found at the given position, or None + + + + + setTool(int,tool): +adds a tool at the given position + + + + + deleteTool(int): +deletes the tool found at the given position + + + + + + setFromTemplate(dict) ... restores receiver from given template attribute dictionary + + + + + templateAttrs() ... returns a dictionary representing the receivers attributes for a template + + + + diff --git a/src/Mod/Path/App/TooltablePyImp.cpp b/src/Mod/Path/App/TooltablePyImp.cpp index 06efc3ec13..4b2118d2db 100644 --- a/src/Mod/Path/App/TooltablePyImp.cpp +++ b/src/Mod/Path/App/TooltablePyImp.cpp @@ -1,288 +1,288 @@ -/*************************************************************************** - * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#include "Base/Reader.h" -#include "Mod/Path/App/Tool.h" -#include "Mod/Path/App/Tooltable.h" - -// inclusion of the generated files (generated out of ToolPy.xml and TooltablePy.xml) -#include "ToolPy.h" -#include "TooltablePy.h" -#include "TooltablePy.cpp" - -using namespace Path; - -#if PY_MAJOR_VERSION >= 3 -# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) -# define PYINT_TYPE PyLong_Type -# define PYINT_FROMLONG(l) PyLong_FromLong(l) -# define PYINT_ASLONG(o) PyLong_AsLong(o) -#else -# define PYSTRING_FROMSTRING(str) PyString_FromString(str) -# define PYINT_TYPE PyInt_Type -# define PYINT_FROMLONG(l) PyInt_FromLong(l) -# define PYINT_ASLONG(o) PyInt_AsLong(o) -#endif - -// returns a string which represents the object e.g. when printed in python -std::string TooltablePy::representation(void) const -{ - std::stringstream str; - str.precision(5); - str << "Tooltable containing "; - str << getTooltablePtr()->getSize() << " tools"; - return str.str(); -} - -PyObject *TooltablePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper -{ - return new TooltablePy(new Tooltable); -} - -// constructor method -int TooltablePy::PyInit(PyObject* args, PyObject* /*kwd*/) -{ - //char *name="Tooltable"; - //int version = 1; - - if (PyArg_ParseTuple(args, "")) { - return 0; - } - PyErr_Clear(); // set by PyArg_ParseTuple() - - PyObject *pcObj; - if (PyArg_ParseTuple(args, "O!", &(PyDict_Type), &pcObj)) { - try { - Py::Dict dict(pcObj); - setTools(dict); - } catch(...) { - PyErr_SetString(PyExc_TypeError, "The dictionary can only contain int:tool pairs"); - return -1; - } - return 0; - } - PyErr_Clear(); // set by PyArg_ParseTuple() - - if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &pcObj)) { - Py::List list(pcObj); - for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - if (PyObject_TypeCheck((*it).ptr(), &(Path::ToolPy::Type))) { - Path::Tool &tool = *static_cast((*it).ptr())->getToolPtr(); - getTooltablePtr()->addTool(tool); - } - } - return 0; - } - - PyErr_SetString(PyExc_TypeError, "Argument must be either empty or a list or a dictionary"); - return -1; -} - -// Commands get/set - -Py::Dict TooltablePy::getTools(void) const -{ - PyObject *dict = PyDict_New(); - for(std::map::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) { - PyObject *tool = new Path::ToolPy(i->second); - PyDict_SetItem(dict,PYINT_FROMLONG(i->first),tool); - } - return Py::Dict(dict); -} - -void TooltablePy::setTools(Py::Dict arg) -{ - getTooltablePtr()->Tools.clear(); - PyObject* dict_copy = PyDict_Copy(arg.ptr()); - PyObject *key, *value; - Py_ssize_t pos = 0; - while (PyDict_Next(dict_copy, &pos, &key, &value)) { - if ( PyObject_TypeCheck(key,&(PYINT_TYPE)) && ((PyObject_TypeCheck(value, &(Path::ToolPy::Type))) || PyObject_TypeCheck(value, &PyDict_Type))) { - int ckey = (int)PYINT_ASLONG(key); - if (PyObject_TypeCheck(value, &(Path::ToolPy::Type))) { - Path::Tool &tool = *static_cast(value)->getToolPtr(); - getTooltablePtr()->setTool(tool, ckey); - } else { - PyErr_Clear(); - Path::Tool *tool = new Path::Tool; - // The 'pyTool' object must be created on the heap otherwise Python - // will fail to properly track the reference counts and aborts - // in debug mode. - Path::ToolPy* pyTool = new Path::ToolPy(tool); - PyObject* success = pyTool->setFromTemplate(value); - if (!success) { - Py_DECREF(pyTool); - throw Py::Exception(); - } - getTooltablePtr()->setTool(*tool, ckey); - Py_DECREF(pyTool); - Py_DECREF(success); - } - } else { - throw Py::TypeError("The dictionary can only contain int:tool pairs"); - } - } -} - -// specific methods - -PyObject* TooltablePy::copy(PyObject * args) -{ - if (PyArg_ParseTuple(args, "")) { - return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); - } - throw Py::TypeError("This method accepts no argument"); -} - -PyObject* TooltablePy::addTools(PyObject * args) -{ - PyObject* o; - if (PyArg_ParseTuple(args, "O!", &(Path::ToolPy::Type), &o)) { - Path::Tool &tool = *static_cast(o)->getToolPtr(); - getTooltablePtr()->addTool(tool); - //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); - Py_INCREF(Py_None); - return Py_None; - } - PyErr_Clear(); - if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) { - Py::List list(o); - for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { - if (PyObject_TypeCheck((*it).ptr(), &(Path::ToolPy::Type))) { - Path::Tool &tool = *static_cast((*it).ptr())->getToolPtr(); - getTooltablePtr()->addTool(tool); - } - } - //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); - Py_INCREF(Py_None); - return Py_None; - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - tool or list of tools expected"); -} - -PyObject* TooltablePy::setTool(PyObject * args) -{ - PyObject* o; - int pos = -1; - if (PyArg_ParseTuple(args, "iO!", &pos, &(Path::ToolPy::Type), &o)) { - Path::Tool &tool = *static_cast(o)->getToolPtr(); - getTooltablePtr()->setTool(tool,pos); - //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); - Py_INCREF(Py_None); - return Py_None; - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected tool and optional integer"); -} - -PyObject* TooltablePy::getTool(PyObject * args) -{ - int pos = -1; - if (PyArg_ParseTuple(args, "i", &pos)) { - if (getTooltablePtr()->hasTool(pos)) - { - Path::Tool tool = getTooltablePtr()->getTool(pos); - return new ToolPy(new Path::Tool(tool)); - } - else - { - Py_INCREF(Py_None); - return Py_None; - } - } - Py_Error(Base::BaseExceptionFreeCADError, "Argument must be integer"); -} - -PyObject* TooltablePy::deleteTool(PyObject * args) -{ - int pos = -1; - if (PyArg_ParseTuple(args, "|i", &pos)) { - getTooltablePtr()->deleteTool(pos); - //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); - Py_INCREF(Py_None); - return Py_None; - } - Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected an integer (optional)"); -} - -// custom attributes get/set - -PyObject *TooltablePy::getCustomAttributes(const char* /*attr*/) const -{ - return 0; -} - -int TooltablePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) -{ - return 0; -} - -Py::Int TooltablePy::getVersion(void) const -{ - return Py::Int(getTooltablePtr()->Version); -} - -void TooltablePy::setVersion(Py::Int version) { - getTooltablePtr()->Version = version; -} - -Py::String TooltablePy::getName(void) const -{ - return Py::String(getTooltablePtr()->Name.c_str()); -} - -void TooltablePy::setName(Py::String arg) -{ - std::string name = arg.as_std_string(); - getTooltablePtr()->Name = name; -} - -PyObject* TooltablePy::setFromTemplate(PyObject * args) -{ - PyObject *dict = 0; - if (PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) { - Py::Dict d(dict); - setTools(d); - Py_Return ; - } - - PyErr_SetString(PyExc_TypeError, "argument must be a dictionary returned from templateAttrs()"); - return 0; -} - -PyObject* TooltablePy::templateAttrs(PyObject * args) -{ - (void)args; - PyObject *dict = PyDict_New(); - for(std::map::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) { - // The 'tool' object must be created on the heap otherwise Python - // will fail to properly track the reference counts and aborts - // in debug mode. - Path::ToolPy* tool = new Path::ToolPy(new Path::Tool(*i->second)); - PyObject *attrs = tool->templateAttrs(0); - PyDict_SetItem(dict, PYINT_FROMLONG(i->first), attrs); - Py_DECREF(tool); - } - return dict; -} - +/*************************************************************************** + * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2014 * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library 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 library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#include "Base/Reader.h" +#include "Mod/Path/App/Tool.h" +#include "Mod/Path/App/Tooltable.h" + +// inclusion of the generated files (generated out of ToolPy.xml and TooltablePy.xml) +#include "ToolPy.h" +#include "TooltablePy.h" +#include "TooltablePy.cpp" + +using namespace Path; + +#if PY_MAJOR_VERSION >= 3 +# define PYSTRING_FROMSTRING(str) PyUnicode_FromString(str) +# define PYINT_TYPE PyLong_Type +# define PYINT_FROMLONG(l) PyLong_FromLong(l) +# define PYINT_ASLONG(o) PyLong_AsLong(o) +#else +# define PYSTRING_FROMSTRING(str) PyString_FromString(str) +# define PYINT_TYPE PyInt_Type +# define PYINT_FROMLONG(l) PyInt_FromLong(l) +# define PYINT_ASLONG(o) PyInt_AsLong(o) +#endif + +// returns a string which represents the object e.g. when printed in python +std::string TooltablePy::representation(void) const +{ + std::stringstream str; + str.precision(5); + str << "Tooltable containing "; + str << getTooltablePtr()->getSize() << " tools"; + return str.str(); +} + +PyObject *TooltablePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + return new TooltablePy(new Tooltable); +} + +// constructor method +int TooltablePy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + //char *name="Tooltable"; + //int version = 1; + + if (PyArg_ParseTuple(args, "")) { + return 0; + } + PyErr_Clear(); // set by PyArg_ParseTuple() + + PyObject *pcObj; + if (PyArg_ParseTuple(args, "O!", &(PyDict_Type), &pcObj)) { + try { + Py::Dict dict(pcObj); + setTools(dict); + } catch(...) { + PyErr_SetString(PyExc_TypeError, "The dictionary can only contain int:tool pairs"); + return -1; + } + return 0; + } + PyErr_Clear(); // set by PyArg_ParseTuple() + + if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &pcObj)) { + Py::List list(pcObj); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + if (PyObject_TypeCheck((*it).ptr(), &(Path::ToolPy::Type))) { + Path::Tool &tool = *static_cast((*it).ptr())->getToolPtr(); + getTooltablePtr()->addTool(tool); + } + } + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Argument must be either empty or a list or a dictionary"); + return -1; +} + +// Commands get/set + +Py::Dict TooltablePy::getTools(void) const +{ + PyObject *dict = PyDict_New(); + for(std::map::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) { + PyObject *tool = new Path::ToolPy(i->second); + PyDict_SetItem(dict,PYINT_FROMLONG(i->first),tool); + } + return Py::Dict(dict); +} + +void TooltablePy::setTools(Py::Dict arg) +{ + getTooltablePtr()->Tools.clear(); + PyObject* dict_copy = PyDict_Copy(arg.ptr()); + PyObject *key, *value; + Py_ssize_t pos = 0; + while (PyDict_Next(dict_copy, &pos, &key, &value)) { + if ( PyObject_TypeCheck(key,&(PYINT_TYPE)) && ((PyObject_TypeCheck(value, &(Path::ToolPy::Type))) || PyObject_TypeCheck(value, &PyDict_Type))) { + int ckey = (int)PYINT_ASLONG(key); + if (PyObject_TypeCheck(value, &(Path::ToolPy::Type))) { + Path::Tool &tool = *static_cast(value)->getToolPtr(); + getTooltablePtr()->setTool(tool, ckey); + } else { + PyErr_Clear(); + Path::Tool *tool = new Path::Tool; + // The 'pyTool' object must be created on the heap otherwise Python + // will fail to properly track the reference counts and aborts + // in debug mode. + Path::ToolPy* pyTool = new Path::ToolPy(tool); + PyObject* success = pyTool->setFromTemplate(value); + if (!success) { + Py_DECREF(pyTool); + throw Py::Exception(); + } + getTooltablePtr()->setTool(*tool, ckey); + Py_DECREF(pyTool); + Py_DECREF(success); + } + } else { + throw Py::TypeError("The dictionary can only contain int:tool pairs"); + } + } +} + +// specific methods + +PyObject* TooltablePy::copy(PyObject * args) +{ + if (PyArg_ParseTuple(args, "")) { + return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); + } + throw Py::TypeError("This method accepts no argument"); +} + +PyObject* TooltablePy::addTools(PyObject * args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", &(Path::ToolPy::Type), &o)) { + Path::Tool &tool = *static_cast(o)->getToolPtr(); + getTooltablePtr()->addTool(tool); + //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); + Py_INCREF(Py_None); + return Py_None; + } + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &(PyList_Type), &o)) { + Py::List list(o); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + if (PyObject_TypeCheck((*it).ptr(), &(Path::ToolPy::Type))) { + Path::Tool &tool = *static_cast((*it).ptr())->getToolPtr(); + getTooltablePtr()->addTool(tool); + } + } + //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); + Py_INCREF(Py_None); + return Py_None; + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - tool or list of tools expected"); +} + +PyObject* TooltablePy::setTool(PyObject * args) +{ + PyObject* o; + int pos = -1; + if (PyArg_ParseTuple(args, "iO!", &pos, &(Path::ToolPy::Type), &o)) { + Path::Tool &tool = *static_cast(o)->getToolPtr(); + getTooltablePtr()->setTool(tool,pos); + //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); + Py_INCREF(Py_None); + return Py_None; + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected tool and optional integer"); +} + +PyObject* TooltablePy::getTool(PyObject * args) +{ + int pos = -1; + if (PyArg_ParseTuple(args, "i", &pos)) { + if (getTooltablePtr()->hasTool(pos)) + { + Path::Tool tool = getTooltablePtr()->getTool(pos); + return new ToolPy(new Path::Tool(tool)); + } + else + { + Py_INCREF(Py_None); + return Py_None; + } + } + Py_Error(Base::BaseExceptionFreeCADError, "Argument must be integer"); +} + +PyObject* TooltablePy::deleteTool(PyObject * args) +{ + int pos = -1; + if (PyArg_ParseTuple(args, "|i", &pos)) { + getTooltablePtr()->deleteTool(pos); + //return new TooltablePy(new Path::Tooltable(*getTooltablePtr())); + Py_INCREF(Py_None); + return Py_None; + } + Py_Error(Base::BaseExceptionFreeCADError, "Wrong parameters - expected an integer (optional)"); +} + +// custom attributes get/set + +PyObject *TooltablePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int TooltablePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + +Py::Int TooltablePy::getVersion(void) const +{ + return Py::Int(getTooltablePtr()->Version); +} + +void TooltablePy::setVersion(Py::Int version) { + getTooltablePtr()->Version = version; +} + +Py::String TooltablePy::getName(void) const +{ + return Py::String(getTooltablePtr()->Name.c_str()); +} + +void TooltablePy::setName(Py::String arg) +{ + std::string name = arg.as_std_string(); + getTooltablePtr()->Name = name; +} + +PyObject* TooltablePy::setFromTemplate(PyObject * args) +{ + PyObject *dict = 0; + if (PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) { + Py::Dict d(dict); + setTools(d); + Py_Return ; + } + + PyErr_SetString(PyExc_TypeError, "argument must be a dictionary returned from templateAttrs()"); + return 0; +} + +PyObject* TooltablePy::templateAttrs(PyObject * args) +{ + (void)args; + PyObject *dict = PyDict_New(); + for(std::map::iterator i = getTooltablePtr()->Tools.begin(); i != getTooltablePtr()->Tools.end(); ++i) { + // The 'tool' object must be created on the heap otherwise Python + // will fail to properly track the reference counts and aborts + // in debug mode. + Path::ToolPy* tool = new Path::ToolPy(new Path::Tool(*i->second)); + PyObject *attrs = tool->templateAttrs(0); + PyDict_SetItem(dict, PYINT_FROMLONG(i->first), attrs); + Py_DECREF(tool); + } + return dict; +} + diff --git a/src/Mod/Path/App/boost_fix/container/detail/memory_util.hpp b/src/Mod/Path/App/boost_fix/container/detail/memory_util.hpp index 609536dcde..9b8cbe31dc 100644 --- a/src/Mod/Path/App/boost_fix/container/detail/memory_util.hpp +++ b/src/Mod/Path/App/boost_fix/container/detail/memory_util.hpp @@ -1,83 +1,83 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/container for documentation. -// -////////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP -#define BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP - -#if defined(_MSC_VER) -# pragma once -#endif - -#include -#include -#include -#include "../../intrusive/detail/has_member_function_callable_with.hpp" - - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME allocate -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 2, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME destroy -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 3, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME max_size -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME select_on_container_copy_construction -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME construct -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS+1, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME swap -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "../../intrusive/detail/has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -namespace boost { -namespace container { -namespace container_detail { - - -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_pointer) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reference) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(void_pointer) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_void_pointer) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_swap) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) - -} //namespace container_detail { -} //namespace container { -} //namespace boost { - -#include - -#endif // ! defined(BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP) +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/container for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP +#define BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include +#include +#include +#include "../../intrusive/detail/has_member_function_callable_with.hpp" + + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME allocate +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 2, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME destroy +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 3, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME max_size +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME select_on_container_copy_construction +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 0, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME construct +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS+1, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME swap +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace container { namespace container_detail { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} +#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "../../intrusive/detail/has_member_function_callable_with.hpp")) +#include BOOST_PP_ITERATE() + +namespace boost { +namespace container { +namespace container_detail { + + +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(pointer) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_pointer) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reference) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(void_pointer) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_void_pointer) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_copy_assignment) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_move_assignment) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(propagate_on_container_swap) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) + +} //namespace container_detail { +} //namespace container { +} //namespace boost { + +#include + +#endif // ! defined(BOOST_CONTAINER_ALLOCATOR_MEMORY_UTIL_HPP) diff --git a/src/Mod/Path/App/boost_fix/intrusive/detail/has_member_function_callable_with.hpp b/src/Mod/Path/App/boost_fix/intrusive/detail/has_member_function_callable_with.hpp index f118a2a369..b91ea75311 100644 --- a/src/Mod/Path/App/boost_fix/intrusive/detail/has_member_function_callable_with.hpp +++ b/src/Mod/Path/App/boost_fix/intrusive/detail/has_member_function_callable_with.hpp @@ -1,365 +1,365 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/intrusive for documentation. -// -////////////////////////////////////////////////////////////////////////////// - -// sample.h - -#if !defined(BOOST_PP_IS_ITERATING) - - #ifndef BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED - #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED - - #include - #include - #include - #include - #include - #include - - //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and - //wrong SFINAE for GCC 4.2/4.3 - #if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__*100 + __GNUC_MINOR__*10) >= 340) && ((__GNUC__*100 + __GNUC_MINOR__*10) <= 430) - #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED - #elif defined(BOOST_INTEL) && (BOOST_INTEL < 1200 ) - #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED - #endif - - namespace boost_intrusive_has_member_function_callable_with { - - struct dont_care - { - dont_care(...); - }; - - struct private_type - { - static private_type p; - private_type const &operator,(int) const; - }; - - typedef char yes_type; // sizeof(yes_type) == 1 - struct no_type{ char dummy[2]; }; // sizeof(no_type) == 2 - - template - no_type is_private_type(T const &); - yes_type is_private_type(private_type const &); - - } //boost_intrusive_has_member_function_callable_with - - #include - - #endif //BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED - -#else //!BOOST_PP_IS_ITERATING - - #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME not defined!" - #endif - - #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN not defined!" - #endif - - #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END not defined!" - #endif - - #if BOOST_PP_ITERATION_START() != 0 - #error "BOOST_PP_ITERATION_START() must be zero (0)" - #endif - - #if BOOST_PP_ITERATION() == 0 - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - - template - class BOOST_PP_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - struct BaseMixin - { - void BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(); - }; - - struct Base : public ::boost::intrusive::detail::remove_cv::type, public BaseMixin { Base(); }; - template class Helper{}; - - template - static boost_intrusive_has_member_function_callable_with::no_type deduce - (U*, Helper* = 0); - static boost_intrusive_has_member_function_callable_with::yes_type deduce(...); - - public: - static const bool value = - sizeof(boost_intrusive_has_member_function_callable_with::yes_type) == sizeof(deduce((Base*)(0))); - }; - - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl); - //! - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) - - { - static const bool value = false; - }; - //! - - #if !defined(_MSC_VER) || (_MSC_VER < 1600) - - #if defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and - //wrong SFINAE for GCC 4.2/4.3 - static const bool value = true; - }; - - #else //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - //Special case for 0 args - template< class F - , std::size_t N = - sizeof((boost::move_detail::declval(). - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - boost_intrusive_has_member_function_callable_with::yes_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not - //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. - template - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - boost_intrusive_has_member_function_callable_with::no_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - template - static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)*); - - template - static boost_intrusive_has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test< Fun >(0)) - == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); - }; - #endif //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - #else //#if !defined(_MSC_VER) || (_MSC_VER < 1600) - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - template - static decltype( boost::move_detail::declval().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() - , boost_intrusive_has_member_function_callable_with::yes_type()) - Test(Fun*); - - template - static boost_intrusive_has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test(0)) - == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); - }; - #endif //#if !defined(_MSC_VER) || (_MSC_VER < 1600) - - #else //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl); - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - static const bool value = false; - }; - - //Special case for 0 args - template< class F - , std::size_t N = - sizeof((boost::move_detail::declval(). - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - boost_intrusive_has_member_function_callable_with::yes_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not - //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. - template - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - boost_intrusive_has_member_function_callable_with::no_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - template - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - #ifdef BOOST_MSVC - template - static decltype( boost::move_detail::declval().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() - , boost_intrusive_has_member_function_callable_with::yes_type()) - Test(Fun*); - #else - template - static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)*); - #endif - - - template - static boost_intrusive_has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test< Fun >(0)) - == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); - }; - - template - struct BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) - : Fun - { - BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )(); - using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; - - boost_intrusive_has_member_function_callable_with::private_type - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( DontCares...) const; - }; - - template - struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) - - { - template - struct make_dontcare - { - typedef boost_intrusive_has_member_function_callable_with::dont_care type; - }; - - typedef BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) - ::type...> FunWrap; - - static bool const value = (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == - sizeof(boost_intrusive_has_member_function_callable_with::is_private_type - ( (::boost::move_detail::declval< FunWrap >(). - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( ::boost::move_detail::declval()... ), 0) ) - ) - ); - }; - - template - struct BOOST_PP_CAT( has_member_function_callable_with_ - , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - : public BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_ - , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - < Fun - , BOOST_PP_CAT( has_member_function_named_ - , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )::value - , Args... > - {}; - - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - - #else //BOOST_PP_ITERATION() == 0 - - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - - template - struct BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)) - : Fun - { - BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))(); - - using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; - boost_intrusive_has_member_function_callable_with::private_type - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( BOOST_PP_ENUM(BOOST_PP_ITERATION() - , BOOST_INTRUSIVE_PP_IDENTITY - , boost_intrusive_has_member_function_callable_with::dont_care)) const; - }; - - template - struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_ - , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - - { - typedef BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)) - FunWrap; - static bool const value = - (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == - sizeof(boost_intrusive_has_member_function_callable_with::is_private_type - ( (boost::move_detail::declval(). - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( BOOST_PP_ENUM( BOOST_PP_ITERATION(), BOOST_INTRUSIVE_PP_DECLVAL, _) ), 0 - ) - ) - ) - ); - }; - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - #endif //BOOST_PP_ITERATION() == 0 - - #if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH() - - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - - template - struct BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - : public BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) - ::value - BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION_FINISH(), P) > - {}; - - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - - #endif //#if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH() - -#endif //!BOOST_PP_IS_ITERATING +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +// sample.h + +#if !defined(BOOST_PP_IS_ITERATING) + + #ifndef BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED + #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED + + #include + #include + #include + #include + #include + #include + + //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and + //wrong SFINAE for GCC 4.2/4.3 + #if defined(__GNUC__) && !defined(__clang__) && ((__GNUC__*100 + __GNUC_MINOR__*10) >= 340) && ((__GNUC__*100 + __GNUC_MINOR__*10) <= 430) + #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED + #elif defined(BOOST_INTEL) && (BOOST_INTEL < 1200 ) + #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED + #endif + + namespace boost_intrusive_has_member_function_callable_with { + + struct dont_care + { + dont_care(...); + }; + + struct private_type + { + static private_type p; + private_type const &operator,(int) const; + }; + + typedef char yes_type; // sizeof(yes_type) == 1 + struct no_type{ char dummy[2]; }; // sizeof(no_type) == 2 + + template + no_type is_private_type(T const &); + yes_type is_private_type(private_type const &); + + } //boost_intrusive_has_member_function_callable_with + + #include + + #endif //BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED + +#else //!BOOST_PP_IS_ITERATING + + #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME not defined!" + #endif + + #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN not defined!" + #endif + + #ifndef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END not defined!" + #endif + + #if BOOST_PP_ITERATION_START() != 0 + #error "BOOST_PP_ITERATION_START() must be zero (0)" + #endif + + #if BOOST_PP_ITERATION() == 0 + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + + template + class BOOST_PP_CAT(has_member_function_named_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + struct BaseMixin + { + void BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(); + }; + + struct Base : public ::boost::intrusive::detail::remove_cv::type, public BaseMixin { Base(); }; + template class Helper{}; + + template + static boost_intrusive_has_member_function_callable_with::no_type deduce + (U*, Helper* = 0); + static boost_intrusive_has_member_function_callable_with::yes_type deduce(...); + + public: + static const bool value = + sizeof(boost_intrusive_has_member_function_callable_with::yes_type) == sizeof(deduce((Base*)(0))); + }; + + #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl); + //! + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) + + { + static const bool value = false; + }; + //! + + #if !defined(_MSC_VER) || (_MSC_VER < 1600) + + #if defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and + //wrong SFINAE for GCC 4.2/4.3 + static const bool value = true; + }; + + #else //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + //Special case for 0 args + template< class F + , std::size_t N = + sizeof((boost::move_detail::declval(). + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + boost_intrusive_has_member_function_callable_with::yes_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not + //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. + template + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + boost_intrusive_has_member_function_callable_with::no_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + template + static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)*); + + template + static boost_intrusive_has_member_function_callable_with::no_type Test(...); + + static const bool value = sizeof(Test< Fun >(0)) + == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); + }; + #endif //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + #else //#if !defined(_MSC_VER) || (_MSC_VER < 1600) + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + template + static decltype( boost::move_detail::declval().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() + , boost_intrusive_has_member_function_callable_with::yes_type()) + Test(Fun*); + + template + static boost_intrusive_has_member_function_callable_with::no_type Test(...); + + static const bool value = sizeof(Test(0)) + == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); + }; + #endif //#if !defined(_MSC_VER) || (_MSC_VER < 1600) + + #else //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl); + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + static const bool value = false; + }; + + //Special case for 0 args + template< class F + , std::size_t N = + sizeof((boost::move_detail::declval(). + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + boost_intrusive_has_member_function_callable_with::yes_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not + //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. + template + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + boost_intrusive_has_member_function_callable_with::no_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + template + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + #ifdef BOOST_MSVC + template + static decltype( boost::move_detail::declval().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() + , boost_intrusive_has_member_function_callable_with::yes_type()) + Test(Fun*); + #else + template + static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)*); + #endif + + + template + static boost_intrusive_has_member_function_callable_with::no_type Test(...); + + static const bool value = sizeof(Test< Fun >(0)) + == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); + }; + + template + struct BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) + : Fun + { + BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )(); + using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; + + boost_intrusive_has_member_function_callable_with::private_type + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( DontCares...) const; + }; + + template + struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) + + { + template + struct make_dontcare + { + typedef boost_intrusive_has_member_function_callable_with::dont_care type; + }; + + typedef BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) + ::type...> FunWrap; + + static bool const value = (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == + sizeof(boost_intrusive_has_member_function_callable_with::is_private_type + ( (::boost::move_detail::declval< FunWrap >(). + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( ::boost::move_detail::declval()... ), 0) ) + ) + ); + }; + + template + struct BOOST_PP_CAT( has_member_function_callable_with_ + , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + : public BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_ + , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + < Fun + , BOOST_PP_CAT( has_member_function_named_ + , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )::value + , Args... > + {}; + + #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + + #else //BOOST_PP_ITERATION() == 0 + + #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + + template + struct BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) + , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)) + : Fun + { + BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) + , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))(); + + using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; + boost_intrusive_has_member_function_callable_with::private_type + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( BOOST_PP_ENUM(BOOST_PP_ITERATION() + , BOOST_INTRUSIVE_PP_IDENTITY + , boost_intrusive_has_member_function_callable_with::dont_care)) const; + }; + + template + struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_ + , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + + { + typedef BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) + , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)) + FunWrap; + static bool const value = + (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == + sizeof(boost_intrusive_has_member_function_callable_with::is_private_type + ( (boost::move_detail::declval(). + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( BOOST_PP_ENUM( BOOST_PP_ITERATION(), BOOST_INTRUSIVE_PP_DECLVAL, _) ), 0 + ) + ) + ) + ); + }; + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + #endif //BOOST_PP_ITERATION() == 0 + + #if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH() + + #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + + template + struct BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + : public BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) + ::value + BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION_FINISH(), P) > + {}; + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + + #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + + #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + + #endif //#if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH() + +#endif //!BOOST_PP_IS_ITERATING diff --git a/src/Mod/Path/App/boost_fix/intrusive/detail/memory_util.hpp b/src/Mod/Path/App/boost_fix/intrusive/detail/memory_util.hpp index a2a48dcd87..9c4addfe12 100644 --- a/src/Mod/Path/App/boost_fix/intrusive/detail/memory_util.hpp +++ b/src/Mod/Path/App/boost_fix/intrusive/detail/memory_util.hpp @@ -1,292 +1,292 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Pablo Halpern 2009. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/intrusive for documentation. -// -////////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP -#define BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP - -#if (defined _MSC_VER) && (_MSC_VER >= 1200) -# pragma once -#endif - -#include -#include -#include -#include - -namespace boost { -namespace intrusive { -namespace detail { - -template -inline T* addressof(T& obj) -{ - return static_cast - (static_cast - (const_cast - (&reinterpret_cast(obj)) - ) - ); -} - -template struct unvoid { typedef T type; }; -template <> struct unvoid { struct type { }; }; -template <> struct unvoid { struct type { }; }; - -template struct unvoid_ref { typedef T &type; }; -template <> struct unvoid_ref { struct type_impl { }; typedef type_impl & type; }; -template <> struct unvoid_ref { struct type_impl { }; typedef type_impl & type; }; - -template -struct LowPriorityConversion -{ - // Convertible from T with user-defined-conversion rank. - LowPriorityConversion(const T&) { } -}; - -// Infrastructure for providing a default type for T::TNAME if absent. -#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \ - template \ - struct boost_intrusive_default_type_ ## TNAME \ - { \ - template \ - static char test(int, typename X::TNAME*); \ - \ - template \ - static int test(boost::intrusive::detail:: \ - LowPriorityConversion, void*); \ - \ - struct DefaultWrap { typedef DefaultType TNAME; }; \ - \ - static const bool value = (1 == sizeof(test(0, 0))); \ - \ - typedef typename \ - ::boost::intrusive::detail::if_c \ - ::type::TNAME type; \ - }; \ - \ - template \ - struct boost_intrusive_eval_default_type_ ## TNAME \ - { \ - template \ - static char test(int, typename X::TNAME*); \ - \ - template \ - static int test(boost::intrusive::detail:: \ - LowPriorityConversion, void*); \ - \ - struct DefaultWrap \ - { typedef typename DefaultType::type TNAME; }; \ - \ - static const bool value = (1 == sizeof(test(0, 0))); \ - \ - typedef typename \ - ::boost::intrusive::detail::eval_if_c \ - < value \ - , ::boost::intrusive::detail::identity \ - , ::boost::intrusive::detail::identity \ - >::type::TNAME type; \ - }; \ -// - -#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ - typename INSTANTIATION_NS_PREFIX \ - boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \ -// - -#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ - typename INSTANTIATION_NS_PREFIX \ - boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \ -// - -}}} //namespace boost::intrusive::detail - -#include "has_member_function_callable_with.hpp" - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME pointer_to -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME static_cast_from -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME const_cast_from -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME dynamic_cast_from -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { -#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, "has_member_function_callable_with.hpp")) -#include BOOST_PP_ITERATE() - -namespace boost { -namespace intrusive { -namespace detail { - -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(element_type) -BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) - -////////////////////// -//struct first_param -////////////////////// - -template struct first_param -{ typedef void type; }; - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - - template