Merge pull request #12804 from bgbsww/bgbsww-toponamingPartFeature
Toponaming/Part: methods in part feature and dependencies for correct elementMaps
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,11 @@
|
||||
class gp_Dir;
|
||||
class BRepBuilderAPI_MakeShape;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
struct HistoryItem;
|
||||
}
|
||||
|
||||
namespace Part
|
||||
{
|
||||
|
||||
@@ -67,6 +72,34 @@ public:
|
||||
std::pair<std::string,std::string> getElementName(
|
||||
const char *name, ElementNameType type=Normal) const override;
|
||||
|
||||
static std::list<Data::HistoryItem> getElementHistory(App::DocumentObject *obj,
|
||||
const char *name, bool recursive=true, bool sameType=false);
|
||||
|
||||
static QVector<Data::MappedElement>
|
||||
getRelatedElements(App::DocumentObject* obj,
|
||||
const char* name,
|
||||
HistoryTraceType sameType = HistoryTraceType::followTypeChange,
|
||||
bool withCache = true);
|
||||
|
||||
/** Obtain the element name from a feature based of the element name of its source feature
|
||||
*
|
||||
* @param obj: current feature
|
||||
* @param subname: sub-object/element reference
|
||||
* @param src: source feature
|
||||
* @param srcSub: sub-object/element reference of the source
|
||||
* @param single: if true, then return upon first match is found, or else
|
||||
* return all matches. Multiple matches are possible for
|
||||
* compound of multiple instances of the same source shape.
|
||||
*
|
||||
* @return Return a vector of pair of new style and old style element names.
|
||||
*/
|
||||
static QVector<Data::MappedElement>
|
||||
getElementFromSource(App::DocumentObject *obj,
|
||||
const char *subname,
|
||||
App::DocumentObject *src,
|
||||
const char *srcSub,
|
||||
bool single = false);
|
||||
|
||||
TopLoc_Location getLocation() const;
|
||||
|
||||
DocumentObject *getSubObject(const char *subname, PyObject **pyObj,
|
||||
@@ -113,6 +146,8 @@ public:
|
||||
static Feature*
|
||||
create(const TopoShape& shape, const char* name = nullptr, App::Document* document = nullptr);
|
||||
|
||||
static bool isElementMappingDisabled(App::PropertyContainer *container);
|
||||
|
||||
protected:
|
||||
/// recompute only this object
|
||||
App::DocumentObjectExecReturn *recompute() override;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "PartPyCXX.h"
|
||||
#include "PropertyTopoShape.h"
|
||||
#include "TopoShapePy.h"
|
||||
#include "PartFeature.h"
|
||||
|
||||
FC_LOG_LEVEL_INIT("App", true, true)
|
||||
|
||||
@@ -103,14 +104,15 @@ TopoShape PropertyPartShape::getShape() const
|
||||
{
|
||||
_Shape.initCache(-1);
|
||||
auto res = _Shape;
|
||||
// March, 2024 Toponaming project: There was originally an unused feature to disable elementMapping
|
||||
// that has not been kept:
|
||||
// March, 2024 Toponaming project: There was originally an unused feature to disable
|
||||
// elementMapping that has not been kept:
|
||||
// if (Feature::isElementMappingDisabled(getContainer()))
|
||||
if ( false )
|
||||
res.Tag = -1;
|
||||
else if (!res.Tag) {
|
||||
if (auto parent = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer()))
|
||||
// res.Tag = -1;
|
||||
// else if (!res.Tag) {
|
||||
if (!res.Tag) {
|
||||
if (auto parent = Base::freecad_dynamic_cast<App::DocumentObject>(getContainer())) {
|
||||
res.Tag = parent->getID();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -557,44 +557,44 @@ PyObject * TopoShape::getPyObject()
|
||||
{
|
||||
Base::PyObjectBase* prop = nullptr;
|
||||
if (_Shape.IsNull()) {
|
||||
prop = new TopoShapePy(new TopoShape(_Shape));
|
||||
prop = new TopoShapePy(new TopoShape(*this));
|
||||
}
|
||||
else {
|
||||
TopAbs_ShapeEnum type = _Shape.ShapeType();
|
||||
switch (type)
|
||||
{
|
||||
case TopAbs_COMPOUND:
|
||||
prop = new TopoShapeCompoundPy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeCompoundPy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_COMPSOLID:
|
||||
prop = new TopoShapeCompSolidPy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeCompSolidPy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_SOLID:
|
||||
prop = new TopoShapeSolidPy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeSolidPy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_SHELL:
|
||||
prop = new TopoShapeShellPy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeShellPy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_FACE:
|
||||
prop = new TopoShapeFacePy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeFacePy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_WIRE:
|
||||
prop = new TopoShapeWirePy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeWirePy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_EDGE:
|
||||
prop = new TopoShapeEdgePy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeEdgePy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_VERTEX:
|
||||
prop = new TopoShapeVertexPy(new TopoShape(_Shape));
|
||||
prop = new TopoShapeVertexPy(new TopoShape(*this));
|
||||
break;
|
||||
case TopAbs_SHAPE:
|
||||
default:
|
||||
prop = new TopoShapePy(new TopoShape(_Shape));
|
||||
prop = new TopoShapePy(new TopoShape(*this));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prop->setNotTracking();
|
||||
prop->setNotTracking(); // TODO: Does this still belong here?
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#endif
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
#include <App/StringHasherPy.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/MatrixPy.h>
|
||||
@@ -85,6 +86,7 @@
|
||||
#include <Mod/Part/App/TopoShapeCompSolidPy.h>
|
||||
#include <Mod/Part/App/TopoShapeEdgePy.h>
|
||||
#include <Mod/Part/App/TopoShapeFacePy.h>
|
||||
#include <Mod/Part/App/TopoShapeOpCode.h>
|
||||
#include <Mod/Part/App/TopoShapeShellPy.h>
|
||||
#include <Mod/Part/App/TopoShapeSolidPy.h>
|
||||
#include <Mod/Part/App/TopoShapeVertexPy.h>
|
||||
@@ -105,6 +107,26 @@ using namespace Part;
|
||||
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||
#endif
|
||||
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
static Py_hash_t _TopoShapeHash(PyObject *self) {
|
||||
if (!self) {
|
||||
PyErr_SetString(PyExc_TypeError, "descriptor 'hash' of 'Part.TopoShape' object needs an argument");
|
||||
return 0;
|
||||
}
|
||||
if (!static_cast<Base::PyObjectBase*>(self)->isValid()) {
|
||||
PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
|
||||
return 0;
|
||||
}
|
||||
return static_cast<TopoShapePy*>(self)->getTopoShapePtr()->getShape().HashCode(INT_MAX);
|
||||
}
|
||||
|
||||
struct TopoShapePyInit {
|
||||
TopoShapePyInit() {
|
||||
TopoShapePy::Type.tp_hash = _TopoShapeHash;
|
||||
}
|
||||
} _TopoShapePyInit;
|
||||
#endif
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string TopoShapePy::representation() const
|
||||
{
|
||||
@@ -120,18 +142,68 @@ PyObject *TopoShapePy::PyMake(struct _typeobject *, PyObject *, PyObject *) //
|
||||
return new TopoShapePy(new TopoShape);
|
||||
}
|
||||
|
||||
int TopoShapePy::PyInit(PyObject* args, PyObject*)
|
||||
int TopoShapePy::PyInit(PyObject* args, PyObject* keywds)
|
||||
{
|
||||
PyObject *pcObj=nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|O", &pcObj))
|
||||
#ifdef FC_USE_TNP_FIX
|
||||
static char* kwlist[] = {"shape", "op", "tag", "hasher", nullptr};
|
||||
long tag = 0;
|
||||
PyObject* pyHasher = nullptr;
|
||||
const char* op = nullptr;
|
||||
PyObject* pcObj = nullptr;
|
||||
if (!PyArg_ParseTupleAndKeywords(args,
|
||||
keywds,
|
||||
"|OsiO!",
|
||||
kwlist,
|
||||
&pcObj,
|
||||
&op,
|
||||
&tag,
|
||||
&App::StringHasherPy::Type,
|
||||
&pyHasher)) {
|
||||
return -1;
|
||||
}
|
||||
auto& self = *getTopoShapePtr();
|
||||
self.Tag = tag;
|
||||
if (pyHasher) {
|
||||
self.Hasher = static_cast<App::StringHasherPy*>(pyHasher)->getStringHasherPtr();
|
||||
}
|
||||
auto shapes = getPyShapes(pcObj);
|
||||
PY_TRY
|
||||
{
|
||||
if (shapes.size() == 1 && !op) {
|
||||
auto s = shapes.front();
|
||||
if (self.Tag) {
|
||||
if ((s.Tag && self.Tag != s.Tag)
|
||||
|| (self.Hasher && s.getElementMapSize() && self.Hasher != s.Hasher)) {
|
||||
s.reTagElementMap(self.Tag, self.Hasher);
|
||||
}
|
||||
else {
|
||||
s.Tag = self.Tag;
|
||||
s.Hasher = self.Hasher;
|
||||
}
|
||||
}
|
||||
self = s;
|
||||
}
|
||||
else if (shapes.size()) {
|
||||
if (!op) {
|
||||
op = Part::OpCodes::Fuse;
|
||||
}
|
||||
self.makeElementBoolean(op, shapes);
|
||||
}
|
||||
}
|
||||
_PY_CATCH_OCC(return (-1))
|
||||
#else
|
||||
PyObject* pcObj = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|O", &pcObj)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto shapes = getPyShapes(pcObj);
|
||||
|
||||
if (pcObj) {
|
||||
TopoShape shape;
|
||||
PY_TRY {
|
||||
if (PyObject_TypeCheck(pcObj,&TopoShapePy::Type)) {
|
||||
PY_TRY
|
||||
{
|
||||
if (PyObject_TypeCheck(pcObj, &TopoShapePy::Type)) {
|
||||
shape = *static_cast<TopoShapePy*>(pcObj)->getTopoShapePtr();
|
||||
}
|
||||
else {
|
||||
@@ -139,8 +211,8 @@ int TopoShapePy::PyInit(PyObject* args, PyObject*)
|
||||
bool first = true;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(Part::GeometryPy::Type))) {
|
||||
TopoDS_Shape sh = static_cast<GeometryPy*>((*it).ptr())->
|
||||
getGeometryPtr()->toShape();
|
||||
TopoDS_Shape sh =
|
||||
static_cast<GeometryPy*>((*it).ptr())->getGeometryPtr()->toShape();
|
||||
if (first) {
|
||||
first = false;
|
||||
shape.setShape(sh);
|
||||
@@ -152,11 +224,11 @@ int TopoShapePy::PyInit(PyObject* args, PyObject*)
|
||||
}
|
||||
}
|
||||
}
|
||||
_PY_CATCH_OCC(return(-1))
|
||||
_PY_CATCH_OCC(return (-1))
|
||||
|
||||
getTopoShapePtr()->setShape(shape.getShape());
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user