| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <Mod/Measure/MeasureGlobal.h>
|
| |
|
| | #include <algorithm>
|
| | #include <string>
|
| |
|
| | #include <Python.h>
|
| |
|
| | #include <App/DocumentObject.h>
|
| | #include <App/DocumentObjectPy.h>
|
| | #include <Base/Console.h>
|
| | #include <Base/Exception.h>
|
| | #include <Base/Interpreter.h>
|
| | #include <Base/MatrixPy.h>
|
| | #include <Base/PlacementPy.h>
|
| | #include <Base/PyWrapParseTupleAndKeywords.h>
|
| |
|
| | #include <Mod/Part/App/TopoShapePy.h>
|
| | #include "Mod/Part/App/OCCError.h"
|
| |
|
| | #include "ShapeFinder.h"
|
| |
|
| |
|
| | namespace Measure
|
| | {
|
| |
|
| | }
|
| |
|
| | namespace Measure
|
| | {
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | template<typename OutputIt>
|
| | void copy(Py::Dict sourceRange, OutputIt targetIt)
|
| | {
|
| | std::string key;
|
| | std::string value;
|
| |
|
| | for (const auto& keyPy : sourceRange.keys()) {
|
| | key = Py::String(keyPy);
|
| | value = Py::String(sourceRange[keyPy]);
|
| | *targetIt = {key, value};
|
| | ++targetIt;
|
| | }
|
| | }
|
| |
|
| |
|
| | class Module: public Py::ExtensionModule<Module>
|
| | {
|
| | public:
|
| | Module()
|
| | : Py::ExtensionModule<Module>("Measure")
|
| | {
|
| | add_varargs_method(
|
| | "getLocatedTopoShape",
|
| | &Module::getLocatedTopoShape,
|
| | "Part.TopoShape = Measure.getLocatedTopoShape(DocumentObject, longSubElement) Resolves "
|
| | "the net placement of DocumentObject and returns the object's shape/subshape with the "
|
| | "net placement applied. Link scaling operations along the path are also applied."
|
| | );
|
| | initialize("This is a module for measuring");
|
| | }
|
| | ~Module() override
|
| | {}
|
| |
|
| | private:
|
| | Py::Object invoke_method_varargs(void* method_def, const Py::Tuple& args) override
|
| | {
|
| | try {
|
| | return Py::ExtensionModule<Module>::invoke_method_varargs(method_def, args);
|
| | }
|
| | catch (const 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("%s\n", str.c_str());
|
| | throw Py::Exception(Part::PartExceptionOCCError, str);
|
| | }
|
| | catch (const Base::Exception& e) {
|
| | std::string str;
|
| | str += "FreeCAD exception thrown (";
|
| | str += e.what();
|
| | str += ")";
|
| | e.reportException();
|
| | throw Py::RuntimeError(str);
|
| | }
|
| | catch (const std::exception& e) {
|
| | std::string str;
|
| | str += "C++ exception thrown (";
|
| | str += e.what();
|
| | str += ")";
|
| | Base::Console().error("%s\n", str.c_str());
|
| | throw Py::RuntimeError(str);
|
| | }
|
| | }
|
| |
|
| | Py::Object getLocatedTopoShape(const Py::Tuple& args)
|
| | {
|
| | PyObject* pyRootObject {nullptr};
|
| | PyObject* pyLeafSubName {nullptr};
|
| | App::DocumentObject* rootObject {nullptr};
|
| | std::string leafSub;
|
| | if (!PyArg_ParseTuple(args.ptr(), "OO", &pyRootObject, &pyLeafSubName)) {
|
| | throw Py::TypeError("expected (rootObject, subname");
|
| | }
|
| |
|
| | if (PyObject_TypeCheck(pyRootObject, &(App::DocumentObjectPy::Type))) {
|
| | rootObject = static_cast<App::DocumentObjectPy*>(pyRootObject)->getDocumentObjectPtr();
|
| | }
|
| |
|
| | if (PyUnicode_Check(pyLeafSubName)) {
|
| | leafSub = PyUnicode_AsUTF8(pyLeafSubName);
|
| | }
|
| |
|
| | if (!rootObject) {
|
| | return Py::None();
|
| | }
|
| |
|
| |
|
| | auto temp = ShapeFinder::getLocatedShape(*rootObject, leafSub);
|
| |
|
| | auto topoShapePy = new Part::TopoShapePy(new Part::TopoShape(temp));
|
| | return Py::asObject(topoShapePy);
|
| | }
|
| | };
|
| |
|
| | }
|
| |
|