Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part: Create CompSolid/Compound/Shell if null before adding a sub-shape #13675

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef _PreComp_
# include <BRep_Builder.hxx>
# include <Standard_Failure.hxx>
# include <TopoDS.hxx>
# include <TopoDS_CompSolid.hxx>
#endif

Expand All @@ -33,7 +34,7 @@

// inclusion of the generated files (generated out of TopoShapeCompSolidPy.xml)
#include "TopoShapeCompSolidPy.h"
#include "TopoShapeCompSolidPy.cpp"

Check warning on line 37 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

suspicious #include of file with '.cpp' extension [bugprone-suspicious-include]
#include "TopoShapeSolidPy.h"
#include "TopoShapeOpCode.h"

Expand All @@ -49,22 +50,22 @@
return str.str();
}

PyObject *TopoShapeCompSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)

Check warning on line 53 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

all parameters should be named in a function [readability-named-parameter]
{
return new TopoShapeCompSolidPy(new TopoShape);
}

int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
if (PyArg_ParseTuple(args, "")) {

Check warning on line 60 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]

Check warning on line 60 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
// Undefined CompSolid
getTopoShapePtr()->setShape(TopoDS_CompSolid());
return 0;
}

PyErr_Clear();
PyObject* pcObj;

Check warning on line 67 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'pcObj' is not initialized [cppcoreguidelines-init-variables]
if (!PyArg_ParseTuple(args, "O", &pcObj)) {

Check warning on line 68 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]

Check warning on line 68 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
return -1;
}
#ifdef FC_USE_TNP_FIX
Expand All @@ -82,7 +83,7 @@
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapeSolidPy::Type))) {
const TopoDS_Shape& sh =
static_cast<TopoShapePy*>((*it).ptr())->getTopoShapePtr()->getShape();

Check warning on line 86 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class [cppcoreguidelines-pro-type-static-cast-downcast]
if (!sh.IsNull()) {
builder.Add(Comp, sh);
}
Expand All @@ -100,7 +101,7 @@
return 0;
}

PyObject* TopoShapeCompSolidPy::add(PyObject* args)

Check warning on line 104 in src/Mod/Part/App/TopoShapeCompSolidPyImp.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'add' can be made const [readability-make-member-function-const]
{
PyObject* obj;
if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj)) {
Expand All @@ -109,6 +110,9 @@

BRep_Builder builder;
TopoDS_Shape comp = getTopoShapePtr()->getShape();
if (comp.IsNull()) {
builder.MakeCompSolid(TopoDS::CompSolid(comp));
}
auto shapes = getPyShapes(obj);

try {
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Part/App/TopoShapeCompoundPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# include <ShapeAnalysis_FreeBounds.hxx>
# include <Standard_Failure.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Compound.hxx>
# include <TopTools_HSequenceOfShape.hxx>
#endif
Expand Down Expand Up @@ -103,6 +104,9 @@ PyObject* TopoShapeCompoundPy::add(PyObject *args)

BRep_Builder builder;
TopoDS_Shape comp = getTopoShapePtr()->getShape();
if (comp.IsNull()) {
builder.MakeCompound(TopoDS::Compound(comp));
}

try {
const TopoDS_Shape& sh = static_cast<TopoShapePy*>(obj)->
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Part/App/TopoShapeShellPyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ PyObject* TopoShapeShellPy::add(PyObject *args)

BRep_Builder builder;
TopoDS_Shape shell = getTopoShapePtr()->getShape();
if (shell.IsNull()) {
builder.MakeShell(TopoDS::Shell(shell));
}

try {
const TopoShape& shape = *static_cast<TopoShapeFacePy*>(obj)->getTopoShapePtr();
Expand Down