modernize C++: use nullptr

This commit is contained in:
wmayer
2023-08-05 16:52:01 +02:00
committed by Chris Hennes
parent aa53596289
commit d244dcf2da
12 changed files with 242 additions and 137 deletions

View File

@@ -58,8 +58,9 @@ std::string SketchObjectPy::representation() const
PyObject* SketchObjectPy::solve(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
int ret = this->getSketchObjectPtr()->solve();
return Py_BuildValue("i", ret);
}
@@ -71,10 +72,12 @@ PyObject* SketchObjectPy::addGeometry(PyObject* args)
bool isConstruction;
if (!PyArg_ParseTuple(args, "OO!", &pcObj, &PyBool_Type, &construction)) {
PyErr_Clear();
if (!PyArg_ParseTuple(args, "O", &pcObj))
if (!PyArg_ParseTuple(args, "O", &pcObj)) {
return nullptr;
else
}
else {
isConstruction = false;
}
}
else {
isConstruction = Base::asBoolean(construction);
@@ -202,8 +205,9 @@ PyObject* SketchObjectPy::addGeometry(PyObject* args)
PyObject* SketchObjectPy::delGeometry(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
if (this->getSketchObjectPtr()->delGeometry(Index)) {
std::stringstream str;
@@ -219,16 +223,18 @@ PyObject* SketchObjectPy::delGeometries(PyObject* args)
{
PyObject* pcObj;
if (!PyArg_ParseTuple(args, "O", &pcObj))
if (!PyArg_ParseTuple(args, "O", &pcObj)) {
return nullptr;
}
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
if (this->getSketchObjectPtr()->delGeometries(geoIdList)) {
@@ -248,8 +254,9 @@ PyObject* SketchObjectPy::delGeometries(PyObject* args)
PyObject* SketchObjectPy::deleteAllGeometry(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
if (this->getSketchObjectPtr()->deleteAllGeometry()) {
std::stringstream str;
@@ -263,8 +270,9 @@ PyObject* SketchObjectPy::deleteAllGeometry(PyObject* args)
PyObject* SketchObjectPy::deleteAllConstraints(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
if (this->getSketchObjectPtr()->deleteAllConstraints()) {
std::stringstream str;
@@ -280,8 +288,9 @@ PyObject* SketchObjectPy::deleteAllConstraints(PyObject* args)
PyObject* SketchObjectPy::toggleConstruction(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
if (this->getSketchObjectPtr()->toggleConstruction(Index)) {
std::stringstream str;
@@ -297,8 +306,9 @@ PyObject* SketchObjectPy::setConstruction(PyObject* args)
{
int Index;
PyObject* Mode;
if (!PyArg_ParseTuple(args, "iO!", &Index, &PyBool_Type, &Mode))
if (!PyArg_ParseTuple(args, "iO!", &Index, &PyBool_Type, &Mode)) {
return nullptr;
}
if (this->getSketchObjectPtr()->setConstruction(Index, Base::asBoolean(Mode))) {
std::stringstream str;
@@ -313,13 +323,15 @@ PyObject* SketchObjectPy::setConstruction(PyObject* args)
PyObject* SketchObjectPy::getConstruction(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
auto gf = this->getSketchObjectPtr()->getGeometryFacade(Index);
if (gf)
if (gf) {
return Py::new_reference_to(Py::Boolean(gf->getConstruction()));
}
std::stringstream str;
str << "Not able to retrieve construction mode of a geometry with the given index: " << Index;
@@ -330,8 +342,9 @@ PyObject* SketchObjectPy::getConstruction(PyObject* args)
PyObject* SketchObjectPy::addConstraint(PyObject* args)
{
PyObject* pcObj;
if (!PyArg_ParseTuple(args, "O", &pcObj))
if (!PyArg_ParseTuple(args, "O", &pcObj)) {
return nullptr;
}
if (PyObject_TypeCheck(pcObj, &(Sketcher::ConstraintPy::Type))) {
Sketcher::Constraint* constr =
@@ -405,8 +418,9 @@ PyObject* SketchObjectPy::addConstraint(PyObject* args)
PyObject* SketchObjectPy::delConstraint(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
if (this->getSketchObjectPtr()->delConstraint(Index)) {
std::stringstream str;
@@ -422,8 +436,9 @@ PyObject* SketchObjectPy::renameConstraint(PyObject* args)
{
int Index;
char* utf8Name;
if (!PyArg_ParseTuple(args, "iet", &Index, "utf-8", &utf8Name))
if (!PyArg_ParseTuple(args, "iet", &Index, "utf-8", &utf8Name)) {
return nullptr;
}
std::string Name = utf8Name;
PyMem_Free(utf8Name);
@@ -462,8 +477,9 @@ PyObject* SketchObjectPy::renameConstraint(PyObject* args)
PyObject* SketchObjectPy::getIndexByName(PyObject* args)
{
char* utf8Name;
if (!PyArg_ParseTuple(args, "et", "utf-8", &utf8Name))
if (!PyArg_ParseTuple(args, "et", "utf-8", &utf8Name)) {
return nullptr;
}
std::string Name = utf8Name;
PyMem_Free(utf8Name);
@@ -488,8 +504,9 @@ PyObject* SketchObjectPy::carbonCopy(PyObject* args)
{
char* ObjectName;
PyObject* construction = Py_True;
if (!PyArg_ParseTuple(args, "s|O!:Give an object", &ObjectName, &PyBool_Type, &construction))
if (!PyArg_ParseTuple(args, "s|O!:Give an object", &ObjectName, &PyBool_Type, &construction)) {
return nullptr;
}
Sketcher::SketchObject* skObj = this->getSketchObjectPtr();
App::DocumentObject* Obj = skObj->getDocument()->getObject(ObjectName);
@@ -524,8 +541,9 @@ PyObject* SketchObjectPy::addExternal(PyObject* args)
{
char* ObjectName;
char* SubName;
if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName, &SubName))
if (!PyArg_ParseTuple(args, "ss:Give an object and subelement name", &ObjectName, &SubName)) {
return nullptr;
}
// get the target object for the external link
Sketcher::SketchObject* skObj = this->getSketchObjectPtr();
@@ -558,8 +576,9 @@ PyObject* SketchObjectPy::addExternal(PyObject* args)
PyObject* SketchObjectPy::delExternal(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
if (this->getSketchObjectPtr()->delExternal(Index)) {
std::stringstream str;
@@ -574,8 +593,9 @@ PyObject* SketchObjectPy::delExternal(PyObject* args)
PyObject* SketchObjectPy::delConstraintOnPoint(PyObject* args)
{
int Index, pos = -1;
if (!PyArg_ParseTuple(args, "i|i", &Index, &pos))
if (!PyArg_ParseTuple(args, "i|i", &Index, &pos)) {
return nullptr;
}
if (pos >= static_cast<int>(Sketcher::PointPos::none)
&& pos <= static_cast<int>(Sketcher::PointPos::mid)) {
@@ -703,23 +723,30 @@ PyObject* SketchObjectPy::setDatum(PyObject* args)
int err = this->getSketchObjectPtr()->setDatum(Index, Datum);
if (err) {
std::stringstream str;
if (err == -1)
if (err == -1) {
str << "Invalid constraint index: " << Index;
else if (err == -3)
}
else if (err == -3) {
str << "Cannot set the datum because the sketch contains conflicting constraints";
else if (err == -2)
}
else if (err == -2) {
str << "Datum " << (const char*)Quantity.getUserString().toUtf8()
<< " for the constraint with index " << Index << " is invalid";
else if (err == -4)
}
else if (err == -4) {
str << "Negative datum values are not valid for the constraint with index " << Index;
else if (err == -5)
}
else if (err == -5) {
str << "Zero is not a valid datum for the constraint with index " << Index;
else if (err == -6)
}
else if (err == -6) {
str << "Cannot set the datum because of invalid geometry";
else
}
else {
str << "Unexpected problem at setting datum "
<< (const char*)Quantity.getUserString().toUtf8()
<< " for the constraint with index " << Index;
}
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return nullptr;
}
@@ -797,8 +824,9 @@ PyObject* SketchObjectPy::setDriving(PyObject* args)
PyObject* driving;
int constrid;
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &driving))
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &driving)) {
return nullptr;
}
if (this->getSketchObjectPtr()->setDriving(constrid, Base::asBoolean(driving))) {
std::stringstream str;
@@ -814,8 +842,9 @@ PyObject* SketchObjectPy::setDatumsDriving(PyObject* args)
{
PyObject* driving;
if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &driving))
if (!PyArg_ParseTuple(args, "O!", &PyBool_Type, &driving)) {
return nullptr;
}
if (this->getSketchObjectPtr()->setDatumsDriving(Base::asBoolean(driving))) {
std::stringstream str;
@@ -829,8 +858,9 @@ PyObject* SketchObjectPy::setDatumsDriving(PyObject* args)
PyObject* SketchObjectPy::moveDatumsToEnd(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
if (this->getSketchObjectPtr()->moveDatumsToEnd()) {
std::stringstream str;
@@ -848,8 +878,9 @@ PyObject* SketchObjectPy::getDriving(PyObject* args)
int constrid;
bool driving;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->getDriving(constrid, driving)) {
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
@@ -863,8 +894,9 @@ PyObject* SketchObjectPy::toggleDriving(PyObject* args)
{
int constrid;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->toggleDriving(constrid)) {
std::stringstream str;
@@ -890,16 +922,18 @@ PyObject* SketchObjectPy::setVirtualSpace(PyObject* args)
std::vector<int> constrIds;
Py::Sequence list(id_or_ids);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
constrIds.push_back(PyLong_AsLong((*it).ptr()));
}
}
try {
int ret = this->getSketchObjectPtr()->setVirtualSpace(constrIds,
Base::asBoolean(invirtualspace));
if (ret == -1)
if (ret == -1) {
throw Py::TypeError("Impossible to set virtual space!");
}
}
catch (const Base::ValueError& e) {
throw Py::ValueError(e.getMessage());
@@ -930,8 +964,9 @@ PyObject* SketchObjectPy::getVirtualSpace(PyObject* args)
int constrid;
bool invirtualspace;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->getVirtualSpace(constrid, invirtualspace)) {
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
@@ -945,8 +980,9 @@ PyObject* SketchObjectPy::toggleVirtualSpace(PyObject* args)
{
int constrid;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->toggleVirtualSpace(constrid)) {
std::stringstream str;
@@ -963,8 +999,9 @@ PyObject* SketchObjectPy::setActive(PyObject* args)
PyObject* isactive;
int constrid;
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &isactive))
if (!PyArg_ParseTuple(args, "iO!", &constrid, &PyBool_Type, &isactive)) {
return nullptr;
}
if (this->getSketchObjectPtr()->setActive(constrid, Base::asBoolean(isactive))) {
std::stringstream str;
@@ -982,8 +1019,9 @@ PyObject* SketchObjectPy::getActive(PyObject* args)
int constrid;
bool isactive;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->getActive(constrid, isactive)) {
PyErr_SetString(PyExc_ValueError, "Invalid constraint id");
@@ -997,8 +1035,9 @@ PyObject* SketchObjectPy::toggleActive(PyObject* args)
{
int constrid;
if (!PyArg_ParseTuple(args, "i", &constrid))
if (!PyArg_ParseTuple(args, "i", &constrid)) {
return nullptr;
}
if (this->getSketchObjectPtr()->toggleActive(constrid)) {
std::stringstream str;
@@ -1017,8 +1056,9 @@ PyObject* SketchObjectPy::movePoint(PyObject* args)
int relative = 0;
if (!PyArg_ParseTuple(
args, "iiO!|i", &GeoId, &PointType, &(Base::VectorPy::Type), &pcObj, &relative))
args, "iiO!|i", &GeoId, &PointType, &(Base::VectorPy::Type), &pcObj, &relative)) {
return nullptr;
}
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pcObj)->value();
@@ -1037,8 +1077,9 @@ PyObject* SketchObjectPy::movePoint(PyObject* args)
PyObject* SketchObjectPy::getGeoVertexIndex(PyObject* args)
{
int index;
if (!PyArg_ParseTuple(args, "i", &index))
if (!PyArg_ParseTuple(args, "i", &index)) {
return nullptr;
}
SketchObject* obj = this->getSketchObjectPtr();
int geoId;
@@ -1053,8 +1094,9 @@ PyObject* SketchObjectPy::getGeoVertexIndex(PyObject* args)
PyObject* SketchObjectPy::getPoint(PyObject* args)
{
int GeoId, PointType;
if (!PyArg_ParseTuple(args, "ii", &GeoId, &PointType))
if (!PyArg_ParseTuple(args, "ii", &GeoId, &PointType)) {
return nullptr;
}
if (PointType < 0 || PointType > 3) {
PyErr_SetString(PyExc_ValueError, "Invalid point type");
@@ -1074,8 +1116,9 @@ PyObject* SketchObjectPy::getPoint(PyObject* args)
PyObject* SketchObjectPy::getAxis(PyObject* args)
{
int AxId;
if (!PyArg_ParseTuple(args, "i", &AxId))
if (!PyArg_ParseTuple(args, "i", &AxId)) {
return nullptr;
}
return new Base::AxisPy(new Base::Axis(this->getSketchObjectPtr()->getAxis(AxId)));
}
@@ -1149,8 +1192,9 @@ PyObject* SketchObjectPy::trim(PyObject* args)
PyObject* pcObj;
int GeoId;
if (!PyArg_ParseTuple(args, "iO!", &GeoId, &(Base::VectorPy::Type), &pcObj))
if (!PyArg_ParseTuple(args, "iO!", &GeoId, &(Base::VectorPy::Type), &pcObj)) {
return nullptr;
}
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pcObj)->value();
@@ -1193,8 +1237,9 @@ PyObject* SketchObjectPy::split(PyObject* args)
PyObject* pcObj;
int GeoId;
if (!PyArg_ParseTuple(args, "iO!", &GeoId, &(Base::VectorPy::Type), &pcObj))
if (!PyArg_ParseTuple(args, "iO!", &GeoId, &(Base::VectorPy::Type), &pcObj)) {
return nullptr;
}
Base::Vector3d v1 = static_cast<Base::VectorPy*>(pcObj)->value();
try {
@@ -1218,8 +1263,9 @@ PyObject* SketchObjectPy::join(PyObject* args)
int PosId1 = static_cast<int>(Sketcher::PointPos::none),
PosId2 = static_cast<int>(Sketcher::PointPos::none);
if (!PyArg_ParseTuple(args, "iiii", &GeoId1, &PosId1, &GeoId2, &PosId2))
return 0;
if (!PyArg_ParseTuple(args, "iiii", &GeoId1, &PosId1, &GeoId2, &PosId2)) {
return nullptr;
}
if (this->getSketchObjectPtr()->join(
GeoId1, (Sketcher::PointPos)PosId1, GeoId2, (Sketcher::PointPos)PosId2)) {
@@ -1227,7 +1273,7 @@ PyObject* SketchObjectPy::join(PyObject* args)
str << "Not able to join the curves with end points: (" << GeoId1 << ", " << PosId1
<< "), (" << GeoId2 << ", " << PosId2 << ")";
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0;
return nullptr;
}
Py_Return;
@@ -1239,23 +1285,26 @@ PyObject* SketchObjectPy::addSymmetric(PyObject* args)
int refGeoId;
int refPosId = static_cast<int>(Sketcher::PointPos::none);
if (!PyArg_ParseTuple(args, "Oi|i", &pcObj, &refGeoId, &refPosId))
if (!PyArg_ParseTuple(args, "Oi|i", &pcObj, &refGeoId, &refPosId)) {
return nullptr;
}
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
int ret = this->getSketchObjectPtr()->addSymmetric(
geoIdList, refGeoId, static_cast<Sketcher::PointPos>(refPosId))
+ 1;
if (ret == -1)
if (ret == -1) {
throw Py::TypeError("Symmetric operation unsuccessful!");
}
std::size_t numGeo = geoIdList.size();
Py::Tuple tuple(numGeo);
@@ -1278,8 +1327,9 @@ PyObject* SketchObjectPy::addCopy(PyObject* args)
PyObject* clone = Py_False;
if (!PyArg_ParseTuple(
args, "OO!|O!", &pcObj, &(Base::VectorPy::Type), &pcVect, &PyBool_Type, &clone))
args, "OO!|O!", &pcObj, &(Base::VectorPy::Type), &pcVect, &PyBool_Type, &clone)) {
return nullptr;
}
Base::Vector3d vect = static_cast<Base::VectorPy*>(pcVect)->value();
@@ -1287,8 +1337,9 @@ PyObject* SketchObjectPy::addCopy(PyObject* args)
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
try {
@@ -1296,8 +1347,9 @@ PyObject* SketchObjectPy::addCopy(PyObject* args)
this->getSketchObjectPtr()->addCopy(geoIdList, vect, false, Base::asBoolean(clone))
+ 1;
if (ret == -1)
if (ret == -1) {
throw Py::TypeError("Copy operation unsuccessful!");
}
std::size_t numGeo = geoIdList.size();
Py::Tuple tuple(numGeo);
@@ -1322,8 +1374,9 @@ PyObject* SketchObjectPy::addMove(PyObject* args)
{
PyObject *pcObj, *pcVect;
if (!PyArg_ParseTuple(args, "OO!", &pcObj, &(Base::VectorPy::Type), &pcVect))
if (!PyArg_ParseTuple(args, "OO!", &pcObj, &(Base::VectorPy::Type), &pcVect)) {
return nullptr;
}
Base::Vector3d vect = static_cast<Base::VectorPy*>(pcVect)->value();
@@ -1331,8 +1384,9 @@ PyObject* SketchObjectPy::addMove(PyObject* args)
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
this->getSketchObjectPtr()->addCopy(geoIdList, vect, true);
@@ -1364,8 +1418,9 @@ PyObject* SketchObjectPy::addRectangularArray(PyObject* args)
&cols,
&PyBool_Type,
&constraindisplacement,
&perpscale))
&perpscale)) {
return nullptr;
}
Base::Vector3d vect = static_cast<Base::VectorPy*>(pcVect)->value();
@@ -1373,8 +1428,9 @@ PyObject* SketchObjectPy::addRectangularArray(PyObject* args)
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
try {
@@ -1388,8 +1444,9 @@ PyObject* SketchObjectPy::addRectangularArray(PyObject* args)
perpscale)
+ 1;
if (ret == -1)
if (ret == -1) {
throw Py::TypeError("Copy operation unsuccessful!");
}
}
catch (const Base::ValueError& e) {
throw Py::ValueError(e.getMessage());
@@ -1407,21 +1464,24 @@ PyObject* SketchObjectPy::removeAxesAlignment(PyObject* args)
{
PyObject* pcObj;
if (!PyArg_ParseTuple(args, "O", &pcObj))
if (!PyArg_ParseTuple(args, "O", &pcObj)) {
return nullptr;
}
if (PyObject_TypeCheck(pcObj, &(PyList_Type)) || PyObject_TypeCheck(pcObj, &(PyTuple_Type))) {
std::vector<int> geoIdList;
Py::Sequence list(pcObj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyLong_Check((*it).ptr()))
if (PyLong_Check((*it).ptr())) {
geoIdList.push_back(PyLong_AsLong((*it).ptr()));
}
}
int ret = this->getSketchObjectPtr()->removeAxesAlignment(geoIdList) + 1;
if (ret == -1)
if (ret == -1) {
throw Py::TypeError("Operation unsuccessful!");
}
Py_Return;
}
@@ -1435,8 +1495,9 @@ PyObject* SketchObjectPy::calculateAngleViaPoint(PyObject* args)
{
int GeoId1 = 0, GeoId2 = 0;
double px = 0, py = 0;
if (!PyArg_ParseTuple(args, "iidd", &GeoId1, &GeoId2, &px, &py))
if (!PyArg_ParseTuple(args, "iidd", &GeoId1, &GeoId2, &px, &py)) {
return nullptr;
}
SketchObject* obj = this->getSketchObjectPtr();
if (GeoId1 > obj->getHighestCurveIndex() || -GeoId1 > obj->getExternalGeometryCount()
@@ -1453,8 +1514,9 @@ PyObject* SketchObjectPy::isPointOnCurve(PyObject* args)
{
int GeoId = GeoEnum::GeoUndef;
double px = 0, py = 0;
if (!PyArg_ParseTuple(args, "idd", &GeoId, &px, &py))
if (!PyArg_ParseTuple(args, "idd", &GeoId, &px, &py)) {
return nullptr;
}
SketchObject* obj = this->getSketchObjectPtr();
if (GeoId > obj->getHighestCurveIndex() || -GeoId > obj->getExternalGeometryCount()) {
@@ -1468,8 +1530,9 @@ PyObject* SketchObjectPy::isPointOnCurve(PyObject* args)
PyObject* SketchObjectPy::calculateConstraintError(PyObject* args)
{
int ic = -1;
if (!PyArg_ParseTuple(args, "i", &ic))
if (!PyArg_ParseTuple(args, "i", &ic)) {
return nullptr;
}
SketchObject* obj = this->getSketchObjectPtr();
if (ic >= obj->Constraints.getSize() || ic < 0) {
@@ -1484,8 +1547,9 @@ PyObject* SketchObjectPy::calculateConstraintError(PyObject* args)
PyObject* SketchObjectPy::changeConstraintsLocking(PyObject* args)
{
int bLock = 0;
if (!PyArg_ParseTuple(args, "i", &bLock))
if (!PyArg_ParseTuple(args, "i", &bLock)) {
return nullptr;
}
SketchObject* obj = this->getSketchObjectPtr();
@@ -1499,8 +1563,9 @@ PyObject* SketchObjectPy::ExposeInternalGeometry(PyObject* args)
{
int GeoId;
if (!PyArg_ParseTuple(args, "i", &GeoId))
if (!PyArg_ParseTuple(args, "i", &GeoId)) {
return nullptr;
}
if (this->getSketchObjectPtr()->exposeInternalGeometry(GeoId) == -1) {
std::stringstream str;
@@ -1517,8 +1582,9 @@ PyObject* SketchObjectPy::DeleteUnusedInternalGeometry(PyObject* args)
{
int GeoId;
if (!PyArg_ParseTuple(args, "i", &GeoId))
if (!PyArg_ParseTuple(args, "i", &GeoId)) {
return nullptr;
}
if (this->getSketchObjectPtr()->deleteUnusedInternalGeometry(GeoId) == -1) {
std::stringstream str;
@@ -1534,8 +1600,9 @@ PyObject* SketchObjectPy::exposeInternalGeometry(PyObject* args)
{
int GeoId;
if (!PyArg_ParseTuple(args, "i", &GeoId))
if (!PyArg_ParseTuple(args, "i", &GeoId)) {
return nullptr;
}
if (this->getSketchObjectPtr()->exposeInternalGeometry(GeoId) == -1) {
std::stringstream str;
@@ -1551,8 +1618,9 @@ PyObject* SketchObjectPy::deleteUnusedInternalGeometry(PyObject* args)
{
int GeoId;
if (!PyArg_ParseTuple(args, "i", &GeoId))
if (!PyArg_ParseTuple(args, "i", &GeoId)) {
return nullptr;
}
if (this->getSketchObjectPtr()->deleteUnusedInternalGeometry(GeoId) == -1) {
std::stringstream str;
@@ -1568,8 +1636,9 @@ PyObject* SketchObjectPy::convertToNURBS(PyObject* args)
{
int GeoId;
if (!PyArg_ParseTuple(args, "i", &GeoId))
if (!PyArg_ParseTuple(args, "i", &GeoId)) {
return nullptr;
}
if (!this->getSketchObjectPtr()->convertToNURBS(GeoId)) {
std::stringstream str;
@@ -1586,8 +1655,9 @@ PyObject* SketchObjectPy::increaseBSplineDegree(PyObject* args)
int GeoId;
int incr = 1;
if (!PyArg_ParseTuple(args, "i|i", &GeoId, &incr))
if (!PyArg_ParseTuple(args, "i|i", &GeoId, &incr)) {
return nullptr;
}
if (!this->getSketchObjectPtr()->increaseBSplineDegree(GeoId, incr)) {
std::stringstream str;
@@ -1604,8 +1674,9 @@ PyObject* SketchObjectPy::decreaseBSplineDegree(PyObject* args)
int GeoId;
int decr = 1;
if (!PyArg_ParseTuple(args, "i|i", &GeoId, &decr))
if (!PyArg_ParseTuple(args, "i|i", &GeoId, &decr)) {
return nullptr;
}
bool ok = this->getSketchObjectPtr()->decreaseBSplineDegree(GeoId, decr);
return Py_BuildValue("O", (ok ? Py_True : Py_False));
@@ -1617,8 +1688,9 @@ PyObject* SketchObjectPy::modifyBSplineKnotMultiplicity(PyObject* args)
int knotIndex;
int multiplicity = 1;
if (!PyArg_ParseTuple(args, "ii|i", &GeoId, &knotIndex, &multiplicity))
if (!PyArg_ParseTuple(args, "ii|i", &GeoId, &knotIndex, &multiplicity)) {
return nullptr;
}
if (!this->getSketchObjectPtr()->modifyBSplineKnotMultiplicity(
GeoId, knotIndex, multiplicity)) {
@@ -1637,8 +1709,9 @@ PyObject* SketchObjectPy::insertBSplineKnot(PyObject* args)
double knotParam;
int multiplicity = 1;
if (!PyArg_ParseTuple(args, "id|i", &GeoId, &knotParam, &multiplicity))
if (!PyArg_ParseTuple(args, "id|i", &GeoId, &knotParam, &multiplicity)) {
return nullptr;
}
if (!this->getSketchObjectPtr()->insertBSplineKnot(GeoId, knotParam, multiplicity)) {
std::stringstream str;
@@ -1658,8 +1731,9 @@ PyObject* SketchObjectPy::autoconstraint(PyObject* args)
if (!PyArg_ParseTuple(
args, "|ddO!", &precision, &angleprecision, &PyBool_Type, &includeconstruction))
args, "|ddO!", &precision, &angleprecision, &PyBool_Type, &includeconstruction)) {
return nullptr;
}
if (this->getSketchObjectPtr()->autoConstraint(
precision, angleprecision, Base::asBoolean(includeconstruction))) {
@@ -1677,8 +1751,9 @@ PyObject* SketchObjectPy::detectMissingPointOnPointConstraints(PyObject* args)
double precision = Precision::Confusion() * 1000;
PyObject* includeconstruction = Py_True;
if (!PyArg_ParseTuple(args, "|dO!", &precision, &PyBool_Type, &includeconstruction))
if (!PyArg_ParseTuple(args, "|dO!", &precision, &PyBool_Type, &includeconstruction)) {
return nullptr;
}
return Py::new_reference_to(
Py::Long(this->getSketchObjectPtr()->detectMissingPointOnPointConstraints(
@@ -1689,8 +1764,9 @@ PyObject* SketchObjectPy::detectMissingVerticalHorizontalConstraints(PyObject* a
{
double angleprecision = M_PI / 8;
if (!PyArg_ParseTuple(args, "|d", &angleprecision))
if (!PyArg_ParseTuple(args, "|d", &angleprecision)) {
return nullptr;
}
return Py::new_reference_to(Py::Long(
this->getSketchObjectPtr()->detectMissingVerticalHorizontalConstraints(angleprecision)));
@@ -1700,8 +1776,9 @@ PyObject* SketchObjectPy::detectMissingEqualityConstraints(PyObject* args)
{
double precision = Precision::Confusion() * 1000;
if (!PyArg_ParseTuple(args, "|d", &precision))
if (!PyArg_ParseTuple(args, "|d", &precision)) {
return nullptr;
}
return Py::new_reference_to(
Py::Long(this->getSketchObjectPtr()->detectMissingEqualityConstraints(precision)));
@@ -1711,8 +1788,9 @@ PyObject* SketchObjectPy::analyseMissingPointOnPointCoincident(PyObject* args)
{
double angleprecision = M_PI / 8;
if (!PyArg_ParseTuple(args, "|d", &angleprecision))
if (!PyArg_ParseTuple(args, "|d", &angleprecision)) {
return nullptr;
}
this->getSketchObjectPtr()->analyseMissingPointOnPointCoincident(angleprecision);
@@ -1724,8 +1802,9 @@ PyObject* SketchObjectPy::makeMissingPointOnPointCoincident(PyObject* args)
PyObject* onebyone = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone))
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone)) {
return nullptr;
}
this->getSketchObjectPtr()->makeMissingPointOnPointCoincident(Base::asBoolean(onebyone));
@@ -1736,8 +1815,9 @@ PyObject* SketchObjectPy::makeMissingVerticalHorizontal(PyObject* args)
{
PyObject* onebyone = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone))
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone)) {
return nullptr;
}
this->getSketchObjectPtr()->makeMissingVerticalHorizontal(Base::asBoolean(onebyone));
@@ -1748,8 +1828,9 @@ PyObject* SketchObjectPy::makeMissingEquality(PyObject* args)
{
PyObject* onebyone = Py_True;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone))
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &onebyone)) {
return nullptr;
}
this->getSketchObjectPtr()->makeMissingEquality(Base::asBoolean(onebyone));
@@ -1760,8 +1841,9 @@ PyObject* SketchObjectPy::autoRemoveRedundants(PyObject* args)
{
PyObject* updategeo = Py_True;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &updategeo))
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &updategeo)) {
return nullptr;
}
this->getSketchObjectPtr()->autoRemoveRedundants(Base::asBoolean(updategeo));
@@ -1770,8 +1852,9 @@ PyObject* SketchObjectPy::autoRemoveRedundants(PyObject* args)
PyObject* SketchObjectPy::toPythonCommands(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
auto sketch = this->getSketchObjectPtr();
@@ -2026,8 +2109,9 @@ void SketchObjectPy::setMissingRadiusConstraints(Py::List arg)
PyObject* SketchObjectPy::getGeometryWithDependentParameters(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
std::vector<std::pair<int, PointPos>> geometrymap;
@@ -2120,8 +2204,9 @@ void SketchObjectPy::setGeometryFacadeList(Py::List value)
PyObject* SketchObjectPy::getGeometryId(PyObject* args)
{
int Index;
if (!PyArg_ParseTuple(args, "i", &Index))
if (!PyArg_ParseTuple(args, "i", &Index)) {
return nullptr;
}
long Id;
@@ -2139,8 +2224,9 @@ PyObject* SketchObjectPy::setGeometryId(PyObject* args)
{
int Index;
long Id;
if (!PyArg_ParseTuple(args, "il", &Index, &Id))
if (!PyArg_ParseTuple(args, "il", &Index, &Id)) {
return nullptr;
}
if (this->getSketchObjectPtr()->setGeometryId(Index, Id)) {
std::stringstream str;
@@ -2231,8 +2317,9 @@ int SketchObjectPy::setCustomAttributes(const char* attr, PyObject* obj)
prop->setPyObject(obj);
if (strcmp(attr, "Geometry") == 0)
if (strcmp(attr, "Geometry") == 0) {
getSketchObjectPtr()->rebuildVertexIndex();
}
return 1;
}