Skip to content

Commit

Permalink
Merge branch 'master' into openscadLinearExtrudeAngleFix
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Apr 16, 2021
2 parents 602fef2 + 47a41ae commit a601b58
Show file tree
Hide file tree
Showing 46 changed files with 795 additions and 776 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -34,7 +34,6 @@ install_manifest.txt
/src/Tools/offlinedoc/localwiki/
/src/Tools/offlinedoc/*.txt
OpenSCAD_rc.py
.subuser-dev
/\.idea/
.tags
tags
Expand Down
1 change: 0 additions & 1 deletion .subuser.json

This file was deleted.

9 changes: 5 additions & 4 deletions src/Base/GeometryPyCXX.h
Expand Up @@ -185,11 +185,12 @@ class GeometryT : public Object
}
operator T() const
{
// cast the PyObject pointer to the matching sub-class
// and call then the defined member function
return getValue();
}
PyT* getPy() const
{
PyT* py = static_cast<PyT*>(ptr());
T* v = (py->*valuePtr)();
return *v;
return py;
}

private:
Expand Down
48 changes: 6 additions & 42 deletions src/Base/PyObjectBase.cpp
Expand Up @@ -103,11 +103,7 @@ PyTypeObject PyObjectBase::Type = {
/* --- Functions to access object as input/output buffer ---------*/
0, /* tp_as_buffer */
/* --- Flags to define presence of optional/expanded features */
#if PY_MAJOR_VERSION >= 3
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_DEFAULT, /*tp_flags */
#else
Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS, /*tp_flags */
#endif
"The most base class for Python binding", /*tp_doc */
0, /*tp_traverse */
0, /*tp_clear */
Expand All @@ -134,10 +130,8 @@ PyTypeObject PyObjectBase::Type = {
0, /*tp_subclasses */
0, /*tp_weaklist */
0, /*tp_del */
0 /*tp_version_tag */
#if PY_MAJOR_VERSION >= 3
,0 /*tp_finalize */
#endif
0, /*tp_version_tag */
0 /*tp_finalize */
#if PY_VERSION_HEX >= 0x03090000
,0 /*tp_vectorcall */
#elif PY_VERSION_HEX >= 0x03080000
Expand All @@ -161,11 +155,7 @@ PyMethodDef PyObjectBase::Methods[] = {
PyObject* PyObjectBase::__getattro(PyObject * obj, PyObject *attro)
{
const char *attr;
#if PY_MAJOR_VERSION >= 3
attr = PyUnicode_AsUTF8(attro);
#else
attr = PyString_AsString(attro);
#endif

// For the __class__ attribute get it directly as with
// ExtensionContainerPy::getCustomAttributes we may get
Expand Down Expand Up @@ -204,7 +194,9 @@ PyObject* PyObjectBase::__getattro(PyObject * obj, PyObject *attro)
pyObj->trackAttribute(attr, value);
}
}
else if (value && PyCFunction_Check(value)) {
else
#endif
if (value && PyCFunction_Check(value)) {
// ExtensionContainerPy::initialization() transfers the methods of an
// extension object by creating PyCFunction objects.
// At this point no 'self' object is passed but is handled and determined
Expand All @@ -220,18 +212,14 @@ PyObject* PyObjectBase::__getattro(PyObject * obj, PyObject *attro)
PyErr_Format(PyExc_AttributeError, "<no object bound to built-in method %s>", attr);
}
}
#endif

return value;
}

int PyObjectBase::__setattro(PyObject *obj, PyObject *attro, PyObject *value)
{
const char *attr;
#if PY_MAJOR_VERSION >= 3
attr = PyUnicode_AsUTF8(attro);
#else
attr = PyString_AsString(attro);
#endif

//FIXME: In general we don't allow to delete attributes (i.e. value=0). However, if we want to allow
//we must check then in _setattr() of all subclasses whether value is 0.
Expand Down Expand Up @@ -294,11 +282,7 @@ PyObject *PyObjectBase::_getattr(const char *attr)
else {
// As fallback solution use Python's default method to get generic attributes
PyObject *w, *res;
#if PY_MAJOR_VERSION >= 3
w = PyUnicode_InternFromString(attr);
#else
w = PyString_InternFromString(attr);
#endif
if (w != NULL) {
res = PyObject_GenericGetAttr(this, w);
Py_XDECREF(w);
Expand All @@ -318,11 +302,7 @@ int PyObjectBase::_setattr(const char *attr, PyObject *value)
return -1; // filter out softspace
PyObject *w;
// As fallback solution use Python's default method to get generic attributes
#if PY_MAJOR_VERSION >= 3
w = PyUnicode_InternFromString(attr); // new reference
#else
w = PyString_InternFromString(attr); // new reference
#endif
if (w != NULL) {
// call methods from tp_getset if defined
int res = PyObject_GenericSetAttr(this, w, value);
Expand Down Expand Up @@ -354,13 +334,8 @@ void PyObjectBase::resetAttribute()
if (attrDict) {
// This is the attribute name to the parent structure
// which we search for in the dict
#if PY_MAJOR_VERSION < 3
PyObject* key1 = PyString_FromString("__attribute_of_parent__");
PyObject* key2 = PyString_FromString("__instance_of_parent__");
#else
PyObject* key1 = PyBytes_FromString("__attribute_of_parent__");
PyObject* key2 = PyBytes_FromString("__instance_of_parent__");
#endif
PyObject* attr = PyDict_GetItem(attrDict, key1);
PyObject* inst = PyDict_GetItem(attrDict, key2);
if (attr) {
Expand All @@ -379,15 +354,9 @@ void PyObjectBase::setAttributeOf(const char* attr, PyObject* par)
if (!attrDict) {
attrDict = PyDict_New();
}
#if PY_MAJOR_VERSION < 3
PyObject* key1 = PyString_FromString("__attribute_of_parent__");
PyObject* key2 = PyString_FromString("__instance_of_parent__");
PyObject* attro = PyString_FromString(attr);
#else
PyObject* key1 = PyBytes_FromString("__attribute_of_parent__");
PyObject* key2 = PyBytes_FromString("__instance_of_parent__");
PyObject* attro = PyUnicode_FromString(attr);
#endif
PyDict_SetItem(attrDict, key1, attro);
PyDict_SetItem(attrDict, key2, par);
Py_DECREF(attro);
Expand All @@ -403,13 +372,8 @@ void PyObjectBase::startNotify()
if (attrDict) {
// This is the attribute name to the parent structure
// which we search for in the dict
#if PY_MAJOR_VERSION < 3
PyObject* key1 = PyString_FromString("__attribute_of_parent__");
PyObject* key2 = PyString_FromString("__instance_of_parent__");
#else
PyObject* key1 = PyBytes_FromString("__attribute_of_parent__");
PyObject* key2 = PyBytes_FromString("__instance_of_parent__");
#endif
PyObject* attr = PyDict_GetItem(attrDict, key1);
PyObject* parent = PyDict_GetItem(attrDict, key2);
if (attr && parent) {
Expand Down
2 changes: 0 additions & 2 deletions src/Base/PyObjectBase.h
Expand Up @@ -463,12 +463,10 @@ BaseExport extern PyObject* BaseExceptionFreeCADAbort;
#define __PY_CATCH(R) \
catch(Base::AbortException &e) \
{ \
e.ReportException(); \
_Py_ErrorObj(R,Base::BaseExceptionFreeCADAbort,e.getPyObject());\
} \
catch(Base::Exception &e) \
{ \
e.ReportException(); \
auto pye = e.getPyExceptionType(); \
if(!pye) \
pye = Base::BaseExceptionFreeCADError; \
Expand Down
20 changes: 13 additions & 7 deletions src/Base/QuantityPyImp.cpp
Expand Up @@ -672,25 +672,31 @@ void QuantityPy::setFormat(Py::Dict arg)

PyObject *QuantityPy::getCustomAttributes(const char* attr) const
{
QuantityPy* py = nullptr;
if (strcmp(attr, "Torr") == 0) {
return new QuantityPy(new Quantity(Quantity::Torr));
py = new QuantityPy(new Quantity(Quantity::Torr));
}
else if (strcmp(attr, "mTorr") == 0) {
return new QuantityPy(new Quantity(Quantity::mTorr));
py = new QuantityPy(new Quantity(Quantity::mTorr));
}
else if (strcmp(attr, "yTorr") == 0) {
return new QuantityPy(new Quantity(Quantity::yTorr));
py = new QuantityPy(new Quantity(Quantity::yTorr));
}
else if (strcmp(attr, "PoundForce") == 0) {
return new QuantityPy(new Quantity(Quantity::PoundForce));
py = new QuantityPy(new Quantity(Quantity::PoundForce));
}
else if (strcmp(attr, "AngularMinute") == 0) {
return new QuantityPy(new Quantity(Quantity::AngMinute));
py = new QuantityPy(new Quantity(Quantity::AngMinute));
}
else if (strcmp(attr, "AngularSecond") == 0) {
return new QuantityPy(new Quantity(Quantity::AngSecond));
py = new QuantityPy(new Quantity(Quantity::AngSecond));
}
return 0;

if (py) {
py->setNotTracking();
}

return py;
}

int QuantityPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
Expand Down
8 changes: 0 additions & 8 deletions src/Gui/ApplicationPy.cpp
Expand Up @@ -737,11 +737,7 @@ PyObject* Application::sGetLocale(PyObject * /*self*/, PyObject *args)
return NULL;

std::string locale = Translator::instance()->activeLanguage();
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(locale.c_str());
#else
return PyString_FromString(locale.c_str());
#endif
}

PyObject* Application::sSetLocale(PyObject * /*self*/, PyObject *args)
Expand Down Expand Up @@ -819,11 +815,7 @@ PyObject* Application::sAddPreferencePage(PyObject * /*self*/, PyObject *args)

PyObject* dlg;
// old style classes
#if PY_MAJOR_VERSION >= 3
if (PyArg_ParseTuple(args, "O!s", &PyType_Type, &dlg, &grp)) {
#else
if (PyArg_ParseTuple(args, "O!s", &PyClass_Type, &dlg, &grp)) {
#endif
// add to the preferences dialog
new PrefPagePyProducer(Py::Object(dlg), grp);

Expand Down
21 changes: 0 additions & 21 deletions src/Gui/CommandPyImp.cpp
Expand Up @@ -77,11 +77,7 @@ PyObject* CommandPy::listAll(PyObject *args)
PyObject* pyList = PyList_New(cmds.size());
int i=0;
for ( std::vector<Command*>::iterator it = cmds.begin(); it != cmds.end(); ++it ) {
#if PY_MAJOR_VERSION >= 3
PyObject* str = PyUnicode_FromString((*it)->getName());
#else
PyObject* str = PyString_FromString((*it)->getName());
#endif
PyList_SetItem(pyList, i++, str);
}
return pyList;
Expand Down Expand Up @@ -123,11 +119,7 @@ PyObject* CommandPy::listByShortcut(PyObject *args)
PyObject* pyList = PyList_New(matches.size());
int i=0;
for (std::string match : matches) {
#if PY_MAJOR_VERSION >= 3
PyObject* str = PyUnicode_FromString(match.c_str());
#else
PyObject* str = PyString_FromString(match.c_str());
#endif
PyList_SetItem(pyList, i++, str);
}
return pyList;
Expand Down Expand Up @@ -178,11 +170,7 @@ PyObject* CommandPy::getShortcut(PyObject *args)

Command* cmd = this->getCommandPtr();
if (cmd) {
#if PY_MAJOR_VERSION >= 3
PyObject* str = PyUnicode_FromString(cmd->getAction() ? cmd->getAction()->shortcut().toString().toStdString().c_str() : "");
#else
PyObject* str = PyString_FromString(cmd->getAction() ? cmd->getAction()->shortcut().toString().toStdString().c_str() : "");
#endif
return str;
}
else {
Expand Down Expand Up @@ -283,21 +271,12 @@ PyObject* CommandPy::getInfo(PyObject *args)
if (action)
shortcutTxt = action->shortcut().toString().toStdString();

#if PY_MAJOR_VERSION >= 3
PyObject* strMenuTxt = PyUnicode_FromString(menuTxt ? menuTxt : "");
PyObject* strTooltipTxt = PyUnicode_FromString(tooltipTxt ? tooltipTxt : "");
PyObject* strWhatsThisTxt = PyUnicode_FromString(whatsThisTxt ? whatsThisTxt : "");
PyObject* strStatustipTxt = PyUnicode_FromString(statustipTxt ? statustipTxt : "");
PyObject* strPixMapTxt = PyUnicode_FromString(pixMapTxt ? pixMapTxt : "");
PyObject* strShortcutTxt = PyUnicode_FromString(!shortcutTxt.empty() ? shortcutTxt.c_str() : "");
#else
PyObject* strMenuTxt = PyString_FromString(menuTxt ? menuTxt : "");
PyObject* strTooltipTxt = PyString_FromString(tooltipTxt ? tooltipTxt : "");
PyObject* strWhatsThisTxt = PyString_FromString(whatsThisTxt ? whatsThisTxt : "");
PyObject* strStatustipTxt = PyString_FromString(statustipTxt ? statustipTxt : "");
PyObject* strPixMapTxt = PyString_FromString(pixMapTxt ? pixMapTxt : "");
PyObject* strShortcutTxt = PyString_FromString(!shortcutTxt.empty() ? shortcutTxt.c_str() : "");
#endif
PyList_SetItem(pyList, 0, strMenuTxt);
PyList_SetItem(pyList, 1, strTooltipTxt);
PyList_SetItem(pyList, 2, strWhatsThisTxt);
Expand Down
3 changes: 2 additions & 1 deletion src/Gui/FileDialog.cpp
Expand Up @@ -194,7 +194,8 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
FileDialog dlg(parent);
dlg.setWindowTitle(windowTitle);
dlg.setSidebarUrls(urls);
dlg.setIconProvider(new FileIconProvider());
auto iconprov = std::make_unique<FileIconProvider>();
dlg.setIconProvider(iconprov.get());
dlg.setFileMode(QFileDialog::AnyFile);
dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setDirectory(dirName);
Expand Down

0 comments on commit a601b58

Please sign in to comment.